Clang failed to compile c++ when LIBCXX_LIBDIR_SUFFIX=64 is defeined for the lib
path "../lib64" are not be included.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
[clang][Driver][Linux] fix regression issue when define LIBCXX_LIBDIR_SUFFIX=64
remove unrelated files
Hi @MaskRay Please help to review this change.
I compiled clang with "-DLLVM_LIBDIR_SUFFIX=64" "-DLIBCXX_LIBDIR_SUFFIX=64" "-DLIBCXXABI_LIBDIR_SUFFIX=64" and the clang 12 work as expected.
But after I compiled clang 13 with same CMake options and comiple a cpp with clang 13, it's failed for can not find "-lc++".
After debuging the clang, I find the "../lib64" is not in the libraries path list in clang 13.0.
Here is the key line in clang 12:
https://github.com/llvm/llvm-project/blob/fed41342a82f5a3a9201819a82bf7a48313e296b/clang/lib/Driver/ToolChains/Linux.cpp#L309
This patch can resolve the regression issue.
Please provide more information: the platform name and the output of g++ empty.cc '-###' |& sed -E 's/ "?-[LiIr]/\n&/g'
Note that there is a FIXME. It's unclear why your platform needs the specific rule.
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
307 | Is D.Dir + "/../lib" still needed? |
The root cause of this regression issue is clang13 lost the ".../bin/../lib64" in LIBRARY_PATH conparing to clang12 source code.
This patch is try to add the line back from clang 12 https://github.com/llvm/llvm-project/blob/fed41342a82f5a3a9201819a82bf7a48313e296b/clang/lib/Driver/ToolChains/Linux.cpp#L309.
Anyway, the g++ output are list as below.
$ g++ empty.cc '-###' |& sed -E 's/ "?-[LiIr]/\n&/g'
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
COLLECT_GCC_OPTIONS='-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1plus -quiet -D_GNU_SOURCE empty.cc -quiet -dumpbase empty.cc "-mtune=generic" "-march=x86-64" -auxbase empty -o /tmp/ccaC9lqH.s
COLLECT_GCC_OPTIONS='-shared-libgcc' '-mtune=generic' '-march=x86-64'
as --64 -o /tmp/cctILs46.o /tmp/ccaC9lqH.s
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr "--hash-style=gnu" -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64
-L/lib/../lib64
-L/usr/lib/../lib64
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/cctILs46.o "-lstdc++" -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
307 | Yes, it's still usefull. When running the clang from compiled folder (eg: .../build.debug/bin/clang), it will try to access the .../build.debug/bin/../lib. |
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
308 | thumbs up. |
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
308 | drop redundant braces around one-line simple statement |
Is D.Dir + "/../lib" still needed?