我使用的是Ubuntu 16.04版本,它随gcc 5.3.1一起安装。我在自定义目录(/build/gcc-4.8.2
和/build/glibc-2.18
)中安装了gcc 4.8和glibc 2.18,我想使用这个gcc和glibc工具链来构建clang 3.9(而不是系统安装的gcc和glibc的)。我正在使用以下命令构建clang:
$ HOST_GCC=/build/gcc-4.8.2
$ cmake -DCMAKE_C_COMPILER=${HOST_GCC}/bin/gcc -DCMAKE_CXX_COMPILER=${HOST_GCC}/bin/g++ -DGCC_INSTALL_PREFIX=${HOST_GCC} -DCMAKE_CXX_LINK_FLAGS="-L${HOST_GCC}/lib64 -Wl,-rpath,${HOST_GCC}/lib64" -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD="X86" ../llvm
$ make
如您所见,我已经指定了我想要使用的自定义gcc编译器和工具链。 Clang构建正常,但是当我尝试使用这个clang编译器构建程序时,我发现它正在从crt*.o
传递/usr/lib/
文件,而不是从/build/glibc-2.18
中的glibc安装传递给链接器。它还将/lib64/ld-linux-x86-64.so.2
(它是/lib/x86_64-linux-gnu/ld-2.23.so
的符号链接)作为-dynamic-linker标志而不是/build/glibc-2.18
$ /home/mark/tmp/build/clang/trunk/bin/clang -v test.cc
clang version 3.9.0 (trunk 274380)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/mark/tmp/build/clang/trunk/bin
Found candidate GCC installation: /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2
Found candidate GCC installation: /build/gcc-4.8.2/lib/x86_64-unknown-linux-gnu/4.8.2
Selected GCC installation: /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/home/mark/tmp/build/clang/trunk/bin/clang-3.9" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name test.cc -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /home/mark/tmp/build/clang/trunk/bin/../lib/clang/3.9.0 -internal-isystem /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++ -internal-isystem /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/x86_64-unknown-linux-gnu -internal-isystem /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/backward -internal-isystem /usr/local/include -internal-isystem /home/mark/tmp/build/clang/trunk/bin/../lib/clang/3.9.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/mark/workspace/main -ferror-limit 19 -fmessage-length 274 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-cd461e.o -x c++ test.cc
clang -cc1 version 3.9.0 based upon LLVM 3.9.0svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++
/build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/x86_64-unknown-linux-gnu
/build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/backward
/usr/local/include
/home/mark/tmp/build/clang/trunk/bin/../lib/clang/3.9.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/crtbegin.o -L/build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2 -L/build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../.. -L/home/mark/tmp/build/clang/trunk/bin/../lib -L/lib -L/usr/lib /tmp/test-cd461e.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /build/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o
/usr/bin/ld: error: /usr/lib/x86_64-linux-gnu/crti.o: unsupported reloc 42 against global symbol __gmon_start__
/usr/lib/x86_64-linux-gnu/crti.o(.init+0x7): error: unsupported reloc 42
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
由于链接的目标文件不匹配,链接似乎失败了。如何让clang指示链接器使用我的自定义glibc目录中的crt*.o
文件?
答案 0 :(得分:0)
此解决方案对我有用: https://bbs.archlinux.org/viewtopic.php?pid=1610715#p1610715
它至少为我解决了这个问题: https://github.com/ry/v8worker/issues/41