Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-print-search-dirs does not take -stdlib into account when printing library search directories #76614

Closed
boris-kolpackov opened this issue Dec 30, 2023 · 4 comments
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@boris-kolpackov
Copy link
Contributor

On my Debian with Clang 18 snapshot:

$ clang-18 -print-search-dirs
programs: =/usr/bin:/usr/lib/llvm-18/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/bin
libraries: =/usr/lib/llvm-18/lib/clang/18:/usr/bin/../lib/gcc/x86_64-linux-gnu/13:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../lib64:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/../lib64:/lib:/usr/lib
$ clang-18 -stdlib=libc++ -print-search-dirs
programs: =/usr/bin:/usr/lib/llvm-18/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/bin
libraries: =/usr/lib/llvm-18/lib/clang/18:/usr/bin/../lib/gcc/x86_64-linux-gnu/13:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../lib64:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/../lib64:/lib:/usr/lib

Notice how in the second invocation the library search directories still point to GCC's libstdc++ rather than libc++.

@EugeneZelenko EugeneZelenko added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' and removed new issue labels Dec 30, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 30, 2023

@llvm/issue-subscribers-clang-driver

Author: Boris Kolpackov (boris-kolpackov)

On my Debian with Clang 18 snapshot:
$ clang-18 -print-search-dirs
programs: =/usr/bin:/usr/lib/llvm-18/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/bin
libraries: =/usr/lib/llvm-18/lib/clang/18:/usr/bin/../lib/gcc/x86_64-linux-gnu/13:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../lib64:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/../lib64:/lib:/usr/lib
$ clang-18 -stdlib=libc++ -print-search-dirs
programs: =/usr/bin:/usr/lib/llvm-18/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/bin
libraries: =/usr/lib/llvm-18/lib/clang/18:/usr/bin/../lib/gcc/x86_64-linux-gnu/13:/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../lib64:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/../lib64:/lib:/usr/lib

Notice how in the second invocation the library search directories still point to GCC's libstdc++ rather than libc++.

@MaskRay
Copy link
Member

MaskRay commented Feb 4, 2024

Clang's behavior is expected. -stdlib=libc++ does not change library paths. Many ELF OSes detect GCC installations by default, and even if libstdc++ is unused, crtbeginS.o, libgomp.a, libatomic.a may be used. --gcc-triple= disables GCC installation detection. For Clang<18, specify a dummy --gcc-toolchain=donotexist (the option is deprecated).

% /tmp/Rel/bin/clang -print-search-dirs | sed -n -e '/^libraries: =/ {s/.*: =//; s/:/\n/g; p}' | xargs realpath -q | sort -u
/tmp/Rel/lib/clang/19
/tmp/Rel/lib/clang/19/lib/x86_64-unknown-linux-gnu
/tmp/Rel/lib/x86_64-unknown-linux-gnu
/usr/lib
/usr/lib64
/usr/lib/gcc/x86_64-linux-gnu/13
/usr/lib/x86_64-linux-gnu
% /tmp/Rel/bin/clang --gcc-triple= -print-search-dirs | sed -n -e '/^libraries: =/ {s/.*: =//; s/:/\n/g; p}' | xargs realpath -q | sort -u
/tmp/Rel/lib/clang/19
/tmp/Rel/lib/clang/19/lib/x86_64-unknown-linux-gnu
/tmp/Rel/lib/x86_64-unknown-linux-gnu
/usr/lib
/usr/lib64
/usr/lib/x86_64-linux-gnu

@MaskRay MaskRay closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
@MaskRay MaskRay added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Feb 4, 2024
@boris-kolpackov
Copy link
Contributor Author

@MaskRay Thanks for the clarification.

I guess what is still unclear to me is in which directories Clang searches for a library that is specified as, say, -lfoo on the command line when -stdlib=libc++ is specified. Is the list the same as printed with just -print-search-dirs or as --gcc-triple= -print-search-dirs? I think the answer is the former (so that libatomic.a, etc., can be found) but if you could confirm my understand, that would be great. Thanks!

@MaskRay
Copy link
Member

MaskRay commented Feb 6, 2024

I have an alias fclang to /tmp/Rel/bin/clang.

% COMPILER_PATH=/tmp/c fclang -B/tmp --gcc-toolchain=donotexist -print-search-dirs
programs: =/tmp:/tmp/c:/tmp/Rel/bin
libraries: =/tmp/Rel/lib/clang/19:/tmp/Rel/bin/../lib/x86_64-unknown-linux-gnu:/tmp/Rel/lib/clang/19/lib/x86_64-unknown-linux-gnu:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/../lib64:/lib:/usr/lib

programs includes -B, COMPILER_PATH, and the installation directory.
libraries includes the resource directory (fa9771f, to support --print-file-name=include), the libc++/libc++abi/libunwind lib directory, sanitizer/builtins/crt/etc lib directory, GCC lib dir, system lib dirs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

4 participants