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

[ELF] implement -Y flag #652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[ELF] implement -Y flag #652

wants to merge 1 commit into from

Conversation

rawoul
Copy link

@rawoul rawoul commented Aug 21, 2022

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.

@rui314
Copy link
Owner

rui314 commented Aug 21, 2022

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

@rawoul
Copy link
Author

rawoul commented Aug 21, 2022

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.

@rui314
Copy link
Owner

rui314 commented Aug 21, 2022

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

@rawoul
Copy link
Author

rawoul commented Aug 21, 2022

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...).

@@ -998,6 +1002,10 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
}
}

ctx.arg.library_paths.insert(ctx.arg.library_paths.end(),
default_library_paths.begin(),
default_library_paths.end());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully getting what is difference between -Y and -L options -- at the end, we are just concatenating them.

Copy link
Author

@rawoul rawoul Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same difference as -isystem and -I, one prepends while the other appends. It's important because build systems usually append your global CFLAGS to the package CFLAGS, so as a distribution or embedded system maintainer, you need a reliable way to know how the system includes will be used. Using a sysroot is sometimes to much of a constraint (because you need to merge the toolchain and the staging rootfs build).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now. It does make sense, thanks.

Copy link

@david-alvarez-rosa david-alvarez-rosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants