问题描述:

I'm using a Ubuntu 16.04 release, which comes installed with gcc 5.3.1. I have an installation of gcc 4.8 and glibc 2.18 installed in custom directories (/build/gcc-4.8.2 and /build/glibc-2.18), and I would like to build clang 3.9 using this gcc and glibc toolchain (instead of the system installed gcc and glibc). I'm building clang using the following command:

$ 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

As you can see, I have specified the custom gcc compiler and toolchain that I want to use. Clang builds fine, but when I try to build a program with this clang compiler, I see that it is passing crt*.o files from /usr/lib/ instead of from my glibc installation in /build/glibc-2.18 to the linker. Its also passing /lib64/ld-linux-x86-64.so.2 (which is a symlink to /lib/x86_64-linux-gnu/ld-2.23.so) as the -dynamic-linker flag instead of the corresponding file in /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)

The linking seems to fail due to this mismatch of object files that are being linked. How can I get clang to instruct the linker to use the crt*.o files from my custom glibc directory ?

网友答案:

This solution worked for me: https://bbs.archlinux.org/viewtopic.php?pid=1610715#p1610715

It solved this problem for me, at least: https://github.com/ry/v8worker/issues/41

相关阅读:
Top