-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement RFC 2951: Native link modifiers #83507
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Do you want to file a bug for the features that you need on OSX with LLD: |
// Even though we pass `whole-archive` (or similar) to the linker here, | ||
// gc-sections (or similar) may end up stripping away any unreferenced | ||
// symbols. So let's try explicitly disabling that. | ||
cmd.no_gc_sections(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this is necessary and linker doesn't disable --gc-sections
automatically when it sees --whole-archive
? If it's necessary, then that's unfortunate.
Anyway, if it's necessary and --gc-sections
is disabled before link_whole_staticlib
, then it should be re-enabled after it.
Or not, because --gc-sections
is not always enabled by default. (Pehaps --push-state
/--pop-state
can help here, although https://sourceware.org/binutils/docs/ld/Options.html doesn't list --gc-sections
among the saved/restored flags.)
What is worse, /OPT:NOREF,NOICF
on MSVC is global and applies to all libraries, not to this specific one. (But again, maybe it's not even necessary?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading LLD sources it looks like --gc-sections
is a global flag affecting all files regardless of order in ld-like linkers as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I did some quick testing and it seemed like --whole-archive
by itself isn't enough unfortunately. And like you said, it's a global flag. :/
There are two cases here.
Anyway, I think we should keep the status quo behavior for now, i.e.
Unfortunately, I don't know anything about Apple targets. |
I don't really see any alternative ways to implement this compared to what this PR does. |
This comment has been minimized.
This comment has been minimized.
06c4359
to
1d559ec
Compare
@petrochenkov I rebased and addressed most of the review comments. Feel free to pick out any parts you needed. |
I thinks this PR as a whole is pretty much ready for landing. Remaining issues:
|
This comment has been minimized.
This comment has been minimized.
r=me, but it would be nice to cleanup the git history a bit to avoid back and forth changes (or just squash everything). |
This commit implements both the native linking modifiers infrastructure as well as an initial attempt at the individual modifiers from the RFC. It also introduces a feature flag for the general syntax along with individual feature flags for each modifier.
71b5ccb
to
db555e1
Compare
@bors r+ |
📌 Commit db555e1 has been approved by |
Rollup of 8 pull requests Successful merges: - rust-lang#83507 (Implement RFC 2951: Native link modifiers) - rust-lang#84328 (Stablize {HashMap,BTreeMap}::into_{keys,values}) - rust-lang#84712 (Simplify chdir implementation and minimize unsafe block) - rust-lang#84851 (:arrow_up: rust-analyzer) - rust-lang#84923 (Only compute Obligation `cache_key` once in `register_obligation_at`) - rust-lang#84945 (E0583: Include secondary path in error message) - rust-lang#84949 (Fix typo in `MaybeUninit::array_assume_init` safety comment) - rust-lang#84950 (Revert PR 83866) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
remove native_link_modifiers from the list of incomplete features. These features are fully implemented and not incomplete. The tracking issue of them is rust-lang#81490. The implement PR is rust-lang#83507.
Is the Relative order of -l and -Clink-arg(s) options part of the RFC implemented? |
No, it's not yet implemented. |
A first attempt at implementing rust-lang/rfcs#2951 / rust-lang/compiler-team#356.
Tracking Issue: #81490
Introduces feature flags for the general syntax (
native_link_modifiers
) and each modifier (native_link_modifiers_{as_needed,bundle,verbatim,whole_archive}
).r? @petrochenkov