Bug 105305 - ARM32: gcc does not pass all library directories to linker
Summary: ARM32: gcc does not pass all library directories to linker
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-19 06:01 UTC by Rui Ueyama
Modified: 2022-11-03 04:25 UTC (History)
0 users

See Also:
Host:
Target: arm*-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rui Ueyama 2022-04-19 06:01:19 UTC
I'm the author of the mold linker (https://github.com/rui314/mold).

As far as I know, gcc always passes all library paths to the linker by -L<dir>, but I got a bug report that that's not the case on ARM32. It is reported that gcc does not pass some obvious paths such as `-L/usr` or `-L/usr/lib`. The code to explicitly exclude "obvious" directories is here: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/gcc.cc;h=bb07cc244e30fbeccc701816db888f497d65eb08;hb=refs/heads/master#l7931

mold and LLVM lld don't have the notion of the default search paths for the sake of build reproducibility. They guarantee that as long as you pass the exact same command line options and input files, the linkers behave exactly the same regardless of the host machine (in LLD, that's guaranteed even across Unix and Windows.) That helps us a lot when we do cross compilation.

So, can gcc pass all library paths to the linker on ARM32?

https://github.com/rui314/mold/issues/336
Comment 1 Andrew Pinski 2022-04-19 06:11:29 UTC
Gold also didn't search any by default.
Comment 2 Andrew Pinski 2022-11-03 04:11:08 UTC
>The code to explicitly exclude "obvious" directories is here

That code has been there since before 1993. So I wonder if all other ld's always included /usr and /usr/lib by default. It is only the newer ones which don't.

Does POSIX say anything about ld behavior?
Comment 3 Rui Ueyama 2022-11-03 04:25:24 UTC
By other ld's, what linkers did you have in your mind? If lld, mold and gold don't hard code /usr and /usr/lib, then the only remaining linker is GNU ld.

It doesn't seem like POSIX says about the default library search paths. I don't believe POSIX even mandates the existence of /usr and /usr/lib. macOS doesn't have such directories, but IIUC macOS at least one point in the past certified as POSIX compliant.