This is an archive of the discontinued LLVM Phabricator instance.

[clang][Driver][Linux] fix regression issue when define LIBCXX_LIBDIR_SUFFIX=64
ClosedPublic

Authored by sunlin on Aug 18 2021, 3:52 AM.

Details

Summary

Clang failed to compile c++ when LIBCXX_LIBDIR_SUFFIX=64 is defeined for the lib
path "../lib64" are not be included.

Diff Detail

Event Timeline

sunlin created this revision.Aug 18 2021, 3:52 AM
sunlin requested review of this revision.Aug 18 2021, 3:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2021, 3:52 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sunlin updated this revision to Diff 367167.Aug 18 2021, 4:03 AM

[clang][Driver][Linux] fix regression issue when define LIBCXX_LIBDIR_SUFFIX=64

remove unrelated files

sunlin added a subscriber: MaskRay.EditedAug 18 2021, 4:18 AM

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.

MaskRay added inline comments.Aug 18 2021, 9:21 AM
clang/lib/Driver/ToolChains/Linux.cpp
309–312

Is D.Dir + "/../lib" still needed?

sunlin added a comment.EditedAug 18 2021, 5:16 PM

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.

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

sunlin added inline comments.Aug 18 2021, 5:20 PM
clang/lib/Driver/ToolChains/Linux.cpp
309–312

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.

@MaskRay Any more questions for this line change? Thanks : )

MaskRay accepted this revision.Aug 25 2021, 9:42 PM

LGTM.

clang/lib/Driver/ToolChains/Linux.cpp
310

Add if (OSLibDir != "lib")

This revision is now accepted and ready to land.Aug 25 2021, 9:42 PM
sunlin added inline comments.Aug 25 2021, 10:50 PM
clang/lib/Driver/ToolChains/Linux.cpp
310

thumbs up.

sunlin updated this revision to Diff 368812.Aug 25 2021, 11:07 PM

Update for do not add duplicate path

sunlin marked an inline comment as done.Aug 25 2021, 11:10 PM

Hi @MaskRay ,
The patch is updated as your comment.
Please review again. Thanks.

sunlin marked an inline comment as done.Aug 25 2021, 11:10 PM
MaskRay accepted this revision.Aug 25 2021, 11:36 PM
MaskRay added inline comments.
clang/lib/Driver/ToolChains/Linux.cpp
310

drop redundant braces around one-line simple statement

This revision was landed with ongoing or failed builds.Aug 25 2021, 11:50 PM
This revision was automatically updated to reflect the committed changes.

Thanks all of you!