From 32c31c9bb170317183fd84945e769c0920352fa8 Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sat, 19 Sep 2015 09:45:06 +0100 Subject: [PATCH 1/2] Debian multarch compatibility. Includes changes that mean the x86_64 compile will correctly run on a 32bit system with suitable library and kernel support. If you have a multiarch aware llvm-dev and clang-dev the Makefile changes will allow you to build Terra on a mostly 32bit host using: make TARGET_ARCH=-m64 The robustness of the Makefile has also been improved slightly so that a compile that is started on a 32bit environment without the required setup should fail early enough so it does not require a "make purge" to successfully complete a 64bit compile. To run the 64bit application on a 32bit user space you can use multiarch, but you actually only need "gcc-multilib". The 32bit packages needed to run terra can be installed using the Debian/Ubuntu packages: apt-get install gcc-multilib lib64ncurses5 lib64z1 Note: Running 64bit applications on a 32bit system also requires that the kernel be the "amd64" variant. --- Makefile | 19 +++++++++++-------- src/tcompiler.cpp | 5 +++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7b200d7e..6f2f8a8b 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,9 @@ CLANG ?= $(CLANG_PREFIX)/bin/clang #path to the compiler you want to use to compile libterra #can be any c/c++ compiler -TERRA_CXX ?= $(CLANG)++ -TERRA_CC ?= $(CLANG) -TERRA_LINK ?= $(CLANG)++ +TERRA_CXX ?= $(CLANG)++ $(TARGET_ARCH) +TERRA_CC ?= $(CLANG) $(TARGET_ARCH) +TERRA_LINK ?= $(CLANG)++ $(TARGET_ARCH) CUDA_HOME ?= /usr/local/cuda ENABLE_CUDA ?= $(shell test -e /usr/local/cuda && echo 1 || echo 0) @@ -137,10 +137,10 @@ BIN2C = build/bin2c #put any install-specific stuff in here -include Makefile.inc -.PHONY: all clean purge test release +.PHONY: all clean purge test release tests all: $(EXECUTABLE) $(DYNLIBRARY) -test: $(EXECUTABLE) +test tests: $(EXECUTABLE) (cd tests; ./run) build/%.o: src/%.cpp $(PACKAGE_DEPS) @@ -158,16 +158,19 @@ endif $(LUAJIT_LIB): build/$(LUAJIT_TAR) (cd build; tar -xf $(LUAJIT_TAR)) - (cd $(LUAJIT_DIR); make CC=$(CC) STATIC_CC="$(CC) -fPIC") + # Terra does not work on x86 32bit. + (cd $(LUAJIT_DIR); test ! -n "`$(CC) -E -dM src/lj_arch.h | grep '\'`" ) + (cd $(LUAJIT_DIR); make CC="$(CC)" STATIC_CC="$(CC) -fPIC") cp $(addprefix $(LUAJIT_DIR)/src/,$(LUAHEADERS)) release/include/terra build/dep_objects/llvm_list: $(LUAJIT_LIB) $(addprefix build/, $(LIBOBJS)) mkdir -p build/dep_objects/luajit - $(TERRA_LINK) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t | egrep "lib(LLVM|clang)" > build/dep_objects/llvm_list + $(TERRA_LINK) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t | egrep "lib(LLVM|clang)" > build/dep_objects/llvm_list.tmp # extract needed LLVM objects based on a dummy linker invocation - < build/dep_objects/llvm_list $(LUAJIT_DIR)/src/luajit src/unpacklibraries.lua build/dep_objects + < build/dep_objects/llvm_list.tmp $(LUAJIT_DIR)/src/luajit src/unpacklibraries.lua build/dep_objects # include all luajit objects, since the entire lua interface is used in terra cd build/dep_objects/luajit; ar x ../../../$(LUAJIT_LIB) + mv build/dep_objects/llvm_list.tmp build/dep_objects/llvm_list $(LIBRARY): $(addprefix build/, $(LIBOBJS)) build/dep_objects/llvm_list mkdir -p release/lib diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index 1882d7a2..c75ca9af 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -2694,6 +2694,11 @@ static bool SaveAndLink(TerraCompilationUnit * CU, Module * M, std::vectorbegin(),linkargs->end()); #ifndef _WIN32 +#if defined(__amd64__) + cmd.push_back("-m64"); +#elif defined(__i386__) + #error "Only AMD64 target currently supported on x86" +#endif cmd.push_back("-o"); cmd.push_back(filename); #else From 94eb760fe02d48e990466e64cc483120af8866f2 Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sat, 19 Sep 2015 10:17:27 +0100 Subject: [PATCH 2/2] Add build and test debris to .gitignore files. --- .gitignore | 5 ++++- build/.gitignore | 2 ++ tests/.gitignore | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/.gitignore diff --git a/.gitignore b/.gitignore index 567609b1..55211d45 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -build/ +*.o +*.a +*.so +terra diff --git a/build/.gitignore b/build/.gitignore index e69de29b..d6b7ef32 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..d879cb74 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,13 @@ +add.bc +afile.txt +benchmark_fannkuchredux +benchmark_nbody +dynlib +hello +hello.c +output +output.ll +output2 +output2.bc +renamed +speed