mold
mold copied to clipboard
[ELF] implement -Y flag
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.
I think we should just handle it as an unknown flag to let people to stop using this old command line flag, if any.
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.
What program do you need the -Y flag to compile?
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
--sysrootflag 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
--sysrootflag (otherwise the toolchain libraries won't be found). - build libraries and programs with the
-Yand-Wl,-rpath-linkflags 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...).