I recently modified my compiler’s build files to use clang if it detects its available, however I’m running into a number of problems with this. I’m having one set of problems on OS X, and a different set of problems under Ubuntu.
In both cases I’m attempting to link my frontend - compiled with clang - against the LLVM libraries - compiled with gcc. (I thought about compiling LLVM with clang, but then I’d have to compile it twice to bootstrap.)
Under OS X, I get the following error when I try to link:
Undefined symbols:
“___eprintf”, referenced from:
___eprintf$non_lazy_ptr in libLLVMSupport.a(SearchForAddressOfSpecialSymbol.cpp.o)
ld: symbol(s) not found
clang-3: error: linker command failed with exit code 1 (use -v to see invocation)
As you can see the reference is coming from the LLVM libs.
Under Ubuntu, the problem I get is a crash when calling a method in DIBuilder. The problem appears to be in the StringRef param, which looks like it’s full of junk when I examine it in the debugger, even though my code is just passing in the default value for the parameter, which is an empty StringRef(). I’m guessing there is some incompatibility in the calling conventions, but I’m passing virtually the same command-line arguments to clang as I would normally pass to gcc. (With some minor differences having to do with warning suppression).
I recently modified my compiler's build files to use clang if it detects
its available, however I'm running into a number of problems with this.
I'm having one set of problems on OS X, and a different set of problems
under Ubuntu.
In both cases I'm attempting to link my frontend - compiled with clang -
against the LLVM libraries - compiled with gcc. (I thought about
compiling LLVM with clang, but then I'd have to compile it twice to
bootstrap.)
Under OS X, I get the following error when I try to link:
Undefined symbols:
"___eprintf", referenced from:
___eprintf$non_lazy_ptr in
libLLVMSupport.a(SearchForAddressOfSpecialSymbol.cpp.o)
ld: symbol(s) not found
clang-3: error: linker command failed with exit code 1 (use -v to
see invocation)
Interesting. A coworker had exactly the same problem trying to build rust with clang after having built llvm with gcc.
The problem comes from SearchForAddressOfSpecialSymbol.cpp:
// FIXME: Currently disabled when using Clang, as we don't always have our
// runtime support libraries available. #ifndef __clang__ #ifdef __i386__
EXPLICIT_SYMBOL(__eprintf); #endif
Now, exactly what runtime library is not available is something that someone more familiar with OS X will have to answer
The runtime support library the comment talks about is none other than
compiler-rt. (Specifically, libclang_rt.eprintf.a.) If you check out
compiler-rt into <llvm-src>/projects/compiler-rt, clang will pick it up
and build it automatically.
The problem comes from SearchForAddressOfSpecialSymbol.cpp:
// FIXME: Currently disabled when using Clang, as we don’t always
have our
// runtime support libraries available. #ifndefclang #ifdefi386
EXPLICIT_SYMBOL(__eprintf); #endif #endif
Now, exactly what runtime library is not available is something that
someone more familiar with OS X will have to answer
The runtime support library the comment talks about is none other than
compiler-rt. (Specifically, libclang_rt.eprintf.a.) If you check out
compiler-rt into /projects/compiler-rt, clang will pick it up
and build it automatically.
Well, I was hoping to have my build script automatically use clang if it was available, but it sounds like that is going to break people who check out my code unless they have the compiler-rt stuff - and I suspect that not very many people will have that.