From 2f55acf8e1106ff31da3f714a8516e95edbc0d6d Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Sat, 9 Mar 2019 05:17:35 -0800 Subject: [PATCH] [sledge] Improve build of model/cxxabi.bc Summary: Make could get confused and use both the $(MODEL_DIR)/cxxabi.bc and %.bc rules, leading to build failure. Reviewed By: jvillard Differential Revision: D14385600 fbshipit-source-id: 05f0ac6e1 --- sledge/model/Makefile | 27 +++++++++++++++++++++++++++ sledge/model/cxxabi.cpp | 3 --- sledge/model/llair_intrinsics.h | 7 +++++++ sledge/test/Makefile | 8 +++++--- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 sledge/model/Makefile diff --git a/sledge/model/Makefile b/sledge/model/Makefile new file mode 100644 index 000000000..dfb68652c --- /dev/null +++ b/sledge/model/Makefile @@ -0,0 +1,27 @@ +# Copyright (c) 2019-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# additional arguments to pass to clang +OPT_ARGS?=-Os +CLANG_ARGS?=-g $(OPT_ARGS) + +# select llvm and clang +SWITCH?=$(shell opam switch show) +LLVM?=../llvm/_install/$(SWITCH) + +LIBCXXABI=../llvm/projects/libcxxabi + +cxxabi.bc : cxxabi.cpp + $(LLVM)/bin/clang $(CLANG_ARGS) -I$(LLVM)/include/c++/v1 -I$(LIBCXXABI)/include -I$(LIBCXXABI)/src -c -emit-llvm cxxabi.cpp + +clean: + rm cxxabi.bc + +fmt: + clang-format -i *.h *.c *.cpp + +# print any variable for Makefile debugging +print-%: + @printf '$*='; printf '$($*)'; printf '\n' diff --git a/sledge/model/cxxabi.cpp b/sledge/model/cxxabi.cpp index 156863fa3..5b7ff466b 100644 --- a/sledge/model/cxxabi.cpp +++ b/sledge/model/cxxabi.cpp @@ -5,9 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -/* A simple implementation of the Itanium Base ABI for analysis purposes. - See http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html */ - #include "abort_message.cpp" #include "cxa_exception.cpp" #include "cxa_exception_storage.cpp" diff --git a/sledge/model/llair_intrinsics.h b/sledge/model/llair_intrinsics.h index 6338a940c..967a1d07e 100644 --- a/sledge/model/llair_intrinsics.h +++ b/sledge/model/llair_intrinsics.h @@ -5,7 +5,14 @@ * LICENSE file in the root directory of this source tree. */ +#include + +#ifdef __cplusplus extern "C" { +#endif __attribute__((noreturn)) void __llair_throw(void* thrown_exception); + +#ifdef __cplusplus } +#endif diff --git a/sledge/test/Makefile b/sledge/test/Makefile index 84b9ac310..c445a4012 100644 --- a/sledge/test/Makefile +++ b/sledge/test/Makefile @@ -38,19 +38,21 @@ Outs:=$(patsubst %.bc,%.bc.out,$(TestBCs)) $(patsubst %.ll,%.ll.out,$(TestLLs)) default: test -$(MODEL_DIR)/cxxabi.bc: $(MODEL_DIR)/cxxabi.cpp - @(cd $(MODEL_DIR) && clang $(CLANG_ARGS) -I../llvm/projects/libcxxabi/include -I../llvm/projects/libcxxabi/src -c -emit-llvm cxxabi.cpp) +$(MODEL_DIR)/cxxabi.bc : $(MODEL_DIR)/cxxabi.cpp + @(cd $(dir $@) && clang $(CLANG_ARGS) -I../llvm/projects/libcxxabi/include -I../llvm/projects/libcxxabi/src -c -emit-llvm cxxabi.cpp) # compile c to llvm bitcode %.bc : %.c $(MODEL_DIR)/cxxabi.bc @(cd $(dir $*) && clang $(CLANG_ARGS) -c -emit-llvm $(notdir $*).c -o - | opt $(OPT_ARGS) -o $(notdir $*).bc) +# $(MODEL_DIR)/cxxabi.bc # @(cd $(dir $*) && clang $(CLANG_ARGS) -c -emit-llvm $(notdir $*).c -o - | llvm-link $(MODEL_DIR)/cxxabi.bc - | opt $(OPT_ARGS) -o $(notdir $*).bc) # compile c++ to llvm bitcode -%.bc : %.cpp $(MODEL_DIR)/cxxabi.bc +%.bc : %.cpp @(cd $(dir $*) && clang $(CLANG_ARGS) -c -emit-llvm $(notdir $*).cpp -o - | opt $(OPT_ARGS) -o $(notdir $*).bc) +# $(MODEL_DIR)/cxxabi.bc # @(cd $(dir $*) && clang $(CLANG_ARGS) -c -emit-llvm $(notdir $*).cpp -o - | llvm-link $(MODEL_DIR)/cxxabi.bc - | opt $(OPT_ARGS) -o $(notdir $*).bc) # disassemble bitcode to llvm assembly