loader path when using a custom glibc

Richard Sandiford richard.sandiford@arm.com
Mon May 11 10:11:28 GMT 2020

Liviu Ionescu <ilg@livius.net> writes:
> Hi,
> I tried to build a standalone gcc in a separate sysroot folder, including a custom glibc.
> The build went fine, but the result is not as standalone as I would like, because the resulting elfs still invoke the system loader, and thus use the system libraries, instead of the new glibc.
> If I patch the resulting elf and change the loader, it runs properly, with the new glibc shared libraries, but this is not really an option, since I need to use the new compiler in automated builds, where I cannot insert the extra patchelf line.
> A -v at link time revealed that gcc still calls collect2 with the system loader `-dynamic-linker /lib64/ld-linux-x86-64.so.2`, and this is passed into the elf.
> I tried to apply some patches to gcc, to change the loader path, and I also tried to apply some patches to binutils/ld, to adjust the path to the loader, but they were not very fortunate, since they triggered other errors.
> In my opinion, when gcc invokes collect2, if in a sysroot configuration, it should concatenate the sysroot path with the current system loader path, and adjust -dynamic-linker accordingly.
> Any thoughts on this?

The reason this isn't done is that the sysroot is often intended to be
deployed as the real "/" sysroot on a separate target machine.  (At least,
that's a common use case for embedded targets.)  Using things like
/lib64/ld-linux-x86-64.so.2 is correct for that use case.

I don't know of any easy off-the-shelf way of doing what you want to do,
sorry.  Maybe one option would be to use "gcc -dumpspecs" to get the
built-in specs, edit the dynamic-linker paths, and install the edited
file as "specs" in the lib/gcc/<target>/<version> directory of the
GCC installation.


More information about the Gcc-help mailing list