mold icon indicating copy to clipboard operation
mold copied to clipboard

[ELF] implement -Y flag

Open rawoul opened this issue 3 years ago • 4 comments

Please consider supporting the -Y flag, which is supported by the bfd linker (but not gold):

       -Y path
           Add path to the default library search path.  This option exists for Solaris compatibility.

While this is a compatibility option in bfd, it is still very useful when you want to share a cross-toolchain to build binaries and libraries for different targets, without having to copy the full toolchain to their staging dir and using the --sysroot option.

rawoul avatar Aug 21 '22 12:08 rawoul

I think we should just handle it as an unknown flag to let people to stop using this old command line flag, if any.

rui314 avatar Aug 21 '22 13:08 rui314

As you wish, thanks for the quick reply. I'm fine maintaining this patch in my tree as I need it, feel free to close the PR.

rawoul avatar Aug 21 '22 13:08 rawoul

What program do you need the -Y flag to compile?

rui314 avatar Aug 21 '22 13:08 rui314

Not a specific program, I use it when cross compiling root filesystems for embedded targets. The standard way of doing this is:

  • copy the cross-toolchain from a common location to the embedded target staging build dir.
  • build libraries and programs using the cross-toolchain with the --sysroot flag pointing to the staging build dir, so that both the toolchain libraries and the built libraries can be resolved, and install those binaries in the staging dir.

But to avoid copying the toolchain you can do (with ld.bfd):

  • use the cross-toolchain directly from its common install location, without specifying the --sysroot flag (otherwise the toolchain libraries won't be found).
  • build libraries and programs with the -Y and -Wl,-rpath-link flags pointing to the staging build dir and install them there.

Using -L instead of -Y is not a good idea as it is hard to enforce the staging dir to be added first in the library search path with all the different build systems used by all the target packages (autotools, cmake, meson, etc...).

rawoul avatar Aug 21 '22 13:08 rawoul