ldc-developers/ldc — pull request #620 by duralog (2014-06-03 22:52:18+00:00)
Title: WIP: compiling ldc trunk llvm-3.5

hey guys,
so, for a week or so now, I have been trying to get ldc compiling on my mac (OSX 10.9.3). I finally got it (compiling)! previously I had used D quite a bit and wanted to get back into it and also I wanted to learn how to use llvm at the same time, so I figured this is a perfect opportunity. I managed to get llvm compiling, however it's still not linking yet. this is largely a WIP but I'd like to contribute my changes so you don't have to spend a weekend to get ldc compiling with the bazillion name changes that llvm does on a regular basis.. hehe

for starters, I compile with this script: (I have gcc-4.8 installed with homebrew)
1. clang is symlinked to tools/clang -> ~/Projects/clang (origin: https://github.com/llvm-mirror/clang.git - cea7244 + changes)
2. I've had some strange bugs with clang - notably, lib/CodeGen/BackendUtil.cpp.. I fix them manually to get the latest llvm compiling, but I'm not 100% sure I'm doing it right. however, I don't think these are related to the linking problem
3. make is run until it exits successfully because of a race condition in llvm between libLLVMSupport.a and fpcmp (however this is an infinite loop if llvm is broken, lol - so after your cigarette hopefully your computer hasn't caught fire before you return... lol)
```
cd ~/Projects/llvm/build
git pull
CC=/usr/local/Cellar/gcc/4.8.3/bin/gcc-4.8 CXX=/usr/local/Cellar/gcc/4.8.3/bin/g++-4.8 ../configure --disable-cxx1y --enable-debug-runtime --enable-debug-symbols --disable-assertions --enable-optimized --enable-targets=x86_64 --with-gcc-toolchain
make -j8; until !!; do :; done
# make -j8 || make -j1
# make -j8 || make -j8 || make -j8
cd ~/Projects/clang
git pull
cd ~/Projects/ldc/build
git pull
cmake .. -DCMAKE_CXX_FLAGS=-std=c++11 -DLLVM_ROOT_DIR=../../llvm/build/ -DLLVM_CONFIG=../../llvm/build/bin/llvm-config
make -j8
```

more notes:
1. I ran into this bug here: https://www.bountysource.com/issues/1133554-errors-with-clang-in-c-11-mode (so, I patched the dmd frontend sources. you can see those changes in the dmd2 paths... I basically made the relevant `size_t` into `unsigned long` - please give feedback, as I'm not even sure that's right and can't run the tests yet to find out either... :(
2. in some places I altered the order of the header inclusion to make the #ifdef look nicer. I don't believe this will break older versions of llvm, however please say something if it matters.

finally, my linking error is this:
```
Undefined symbols for architecture x86_64:
"_AnnotateHappensAfter", referenced from:
llvm::Statistic::init() in libldc.a(StripExternals.cpp.o)
llvm::Statistic::init() in libldc.a(GarbageCollect2Stack.cpp.o)
llvm::Statistic::init() in libldc.a(SimplifyDRuntimeCalls.cpp.o)
llvm::ManagedStatic > >::operator->() in libldc.a(structs.cpp.o)
"llvm::isCurrentDebugType(char const*)", referenced from:
(anonymous namespace)::StripExternals::runOnModule(llvm::Module&) in libldc.a(StripExternals.cpp.o)
(anonymous namespace)::GarbageCollect2Stack::runOnFunction(llvm::Function&) in libldc.a(GarbageCollect2Stack.cpp.o)
mayBeUsedAfterRealloc(llvm::Instruction*, llvm::Instruction*, llvm::DominatorTree&) in libldc.a(GarbageCollect2Stack.cpp.o)
(anonymous namespace)::SimplifyDRuntimeCalls::runOnce(llvm::Function&, llvm::DataLayout const&, llvm::AliasAnalysis&) in libldc.a(SimplifyDRuntimeCalls.cpp.o)
"llvm::DebugFlag", referenced from:
(anonymous namespace)::StripExternals::runOnModule(llvm::Module&) in libldc.a(StripExternals.cpp.o)
(anonymous namespace)::GarbageCollect2Stack::runOnFunction(llvm::Function&) in libldc.a(GarbageCollect2Stack.cpp.o)
mayBeUsedAfterRealloc(llvm::Instruction*, llvm::Instruction*, llvm::DominatorTree&) in libldc.a(GarbageCollect2Stack.cpp.o)
(anonymous namespace)::SimplifyDRuntimeCalls::runOnce(llvm::Function&, llvm::DataLayout const&, llvm::AliasAnalysis&) in libldc.a(SimplifyDRuntimeCalls.cpp.o)
"_compress2", referenced from:
llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl&, llvm::zlib::CompressionLevel) in libLLVMSupport.a(Compression.cpp.o)
"_compressBound", referenced from:
llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl&, llvm::zlib::CompressionLevel) in libLLVMSupport.a(Compression.cpp.o)
"_crc32", referenced from:
llvm::zlib::crc32(llvm::StringRef) in libLLVMSupport.a(Compression.cpp.o)
"_uncompress", referenced from:
llvm::zlib::uncompress(llvm::StringRef, llvm::SmallVectorImpl&, unsigned long) in libLLVMSupport.a(Compression.cpp.o)
```

any help? I tried recompiling llvm *without* the configure options `--disable-cxx1y --disable-assertions --enable-optimized` to see if it make any difference. it didn't. I have the configure option `--enable-debug-runtime` set too, so I don't understand why it can't find `llvm::isCurrentDebugType` -- and I'm totally confused about the zlib `_compress2` and `_crc32` ones... I think that may be a ldc cmake config thing.

I have to get back to my real work now, so I'll leave it here for now...
cheers!