-
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 -C link-self-contained=(+/-)sanitizers
#121420
Implement -C link-self-contained=(+/-)sanitizers
#121420
Conversation
1e73bef
to
16b7e12
Compare
@@ -1192,6 +1192,8 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d | |||
// are currently distributed as static libraries which should be linked to | |||
// executables only. | |||
let needs_runtime = !sess.target.is_like_android | |||
&& (!sess.opts.cg.link_self_contained.is_sanitizers_disabled() | |||
|| sess.opts.cg.link_self_contained.is_sanitizers_enabled()) |
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.
This condition is getting a bit too unreadable, I think. Can we split it into multiple guard clauses, each with a separate comment?
if sess.target.is_like_android {
// sanitizer runtime libraries are provided dynamically
// on Android targets.
return;
}
if /* disabled via link_self_contained */ {
// ...
return;
}
if /* disabled for crate type */ {
// ...
return
}
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.
Also, it looks like this should also take the settings from the target spec into account (see fn self_contained_components
in this file). Maybe that could also be used to remove the special case for Android?
Although, it looks to me like this check against what the target allows should happen much earlier in the process and not shortly before the linker is invoked. @lqd, what do you think (since this was added by #116035)? Or maybe I'm overlooking something?
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.
It's likely we could move some of the checks earlier in some cases, but other checks/features do depend on the inferred linker flavor and thus couldn't all be moved that much earlier (IIRC sanitizers support is not long after the flavor has been inferred, and does depend on it a bit). Some other components can themselves also be inferred -- e.g. some variants in LinkSelfContainedDefault
-- and also currently happen quite "late".
I don't myself have yet a good clear vision on how to structure all these concerns in the future, whether by splitting the currently-tightly-grouped checks into different early and late groups, or something else, but maybe @petrochenkov does?
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.
I'm happy to make any requested changes.
183428a
to
59b91ae
Compare
This comment has been minimized.
This comment has been minimized.
59b91ae
to
a1a3a21
Compare
This comment has been minimized.
This comment has been minimized.
a1a3a21
to
20d8e3c
Compare
This looks good to me. Thanks, @chriswailes! @lqd, I think I'm a bit confused by the self_contained_components function. It seems to take the CLI arguments into account, but only if it is |
Is there anything more you'd like me to do for this change? |
I didn't have a chance to look at the changes yet, I'll do it later this week, most likely. |
I think we mainly need to clarify how this interacts with the defaults specified by the target (I'm not sure these are always "defaults", some parts of the code seem to treat that as restrictions on what options are allowed) -- or decide that we don't need to do this now because the feature isn't stable yet. In both cases, I don't want to approve this without feedback from @petrochenkov or @lqd, who have more ownership of the link-self-contained feature. |
@michaelwoerister yeah that could eventually be part of the whole story
Here are a couple questions I had reading this PR:
Exactly. I know this PR is only about CLI support, but some similar questions could be discussed about the target specs, e.g. they could enable the sanitizer component but I don't believe there's an easy |
So it looks like
And the effect of both #121420 and this PR is that the linking part is skipped entirely. If the linking part is just skipped, then it doesn't look like
@chriswailes (Also is there some convergence on the names of sanitizer libraries, or they can be named differently?) |
Yes, we link the libraries in explicitly with absolute paths.
The Android build system uses absolute paths in all possible cases when passing arguments to compilers. While adjusting the search path to find our desired
I'm not sure if the naming of the sanitizer libraries is stabilized and being able to link in different sanitizer runtimes might be helpful to researchers and developers. |
It looks like this use-case is different from Maybe something like |
Alright, given the above discussion I'll approve #121207 and close this PR. |
This PR adds support for enabling/disabling self-contained sanitizer runtimes.
This is an alternative to #121207.
r? @michaelwoerister