llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.55k stars 11.8k forks source link

Clang bootstrap should work with LLVM_ENABLE_LIBCXX #18943

Open llvmbot opened 10 years ago

llvmbot commented 10 years ago
Bugzilla Link 18569
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @chandlerc,@eugenis,@belkadan,@kcc,@mclow

Extended Description

Currently, the following process doesn't work: (1) Build LLVM/Clang/libc++ using a host compiler (e.g. some version of gcc). (2) Build Clang again with just-built Clang and -DLLVM_ENABLE_LIBCXX=ON.

I see a number of problems: (1) Clang doesn't find libc++ if it's not installed in the system, but is instead located in Clang build directory (or is a part of Clang installation). See Chandler's comments in r199632 thread. tl;dr libc++ was always thought to be a part of OS or system root, but not a part of compiler distribution. But we still want to locate it somehow if it's built together with the compiler.

(2) Configuration problem. $ cat cxxabi_test.cc

include

$ clang++ cxxabi_test.cc -c -o a.o $ clang++ cxxabi_test.cc -c -o a.o -stdlib=libc++ cxxabi_test.cc:1:10: fatal error: 'cxxabi.h' file not found

As a result at configuration time we find cxxabi.h header, but we can't locate it when we actually compile the project sources with -stdlib=libc++

belkadan commented 10 years ago

Fixed in r200811.

belkadan commented 10 years ago

I think r200744 broke the Clang standalone build.

llvmbot commented 10 years ago

FTR, after r199769 Clang is able to locate libc++ in the Clang build directory. However, problems with missing "-lsupc++" remain, see my latest comment.

llvmbot commented 10 years ago

Looks like I can't use libcxx on Linux, because the main executable can't locate ABI symbols properly:

$ cat foo.cc

include

struct Foo { Foo() { printf("zzz\n"); } };

void bar() { static Foo foo; }

int main() { bar(); }

$ /usr/local/google/llvm_build_gcc/bin/clang++ foo.cc -stdlib=libc++ /tmp/foo-1fc334.o:foo.cc:function bar(): error: undefined reference to 'cxa_guard_acquire' /tmp/foo-1fc334.o:foo.cc:function bar(): error: undefined reference to 'cxa_guard_release' /tmp/foo-1fc334.o:foo.cc:function bar(): error: undefined reference to '__cxa_guard_abort' /tmp/foo-1fc334.o(.eh_frame+0xd3): error: undefined reference to '__gxx_personality_v0'

If I manually specify "-lsupc++", the link steps succeeds: $ /usr/local/google/llvm_build_gcc/bin/clang++ foo.cc -stdlib=libc++ -lsupc++ Note that adding "-lstdc++" doesn't work, as Clang driver rewrites "-lstdc++" into "-lc++".

I wonder why isn't "-lsupc++" added automatically in presence of "-stdlib=libc++" and did it ever work. The page http://libcxx.llvm.org/ tells that "clang is set up to link for libc++ linked to libsupc++.", but I don't see this reflected in sources.

llvmbot commented 10 years ago

Side note: I have a tentative fix for cxxabi.h problem, but I still get link errors in bootstrapped build tree like:

function llvm::BitRecTy::convertValue(llvm::IntInit*): error: undefined reference to '__cxa_guard_release'

looks like relevant parts from libsupc++ are not picked up properly, although I did follow the instructions in http://libcxx.llvm.org/ (Build on Linux using CMake and libsupc++).