-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add default sanitizers to TargetOptions #147043
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
base: master
Are you sure you want to change the base?
Conversation
These commits modify compiler targets. |
rustbot has assigned @petrochenkov. Use |
This comment has been minimized.
This comment has been minimized.
2fa7a35
to
9ee9c2f
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Note: Some targets, like Android, may also want to set this option, but I'm not sure who's handling rustc integration for them ATM. |
) -> SmallVec<[&'ll Attribute; 4]> { | ||
let mut attrs = SmallVec::new(); | ||
let enabled = cx.tcx.sess.opts.unstable_opts.sanitizer - no_sanitize; | ||
let enabled = (cx.sess().target.default_sanitizers | cx.tcx.sess.opts.unstable_opts.sanitizer) |
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.
There are many places in the compiler in which unstable_opts.sanitizer
is used, but only here that list is extended with default_sanitizers
.
If the intent for default_sanitizers
to work as if one more -C sanitizer
was passed implicitly, then the sanitizer list should always be extended.
If for Fuchsia the sanitizers actually only need to be added here in codegen, and not e.g. on linker command line or for #[cfg(sanitize)]
, then it's probably better to just make a special case for Fuchsia targets here in sanitize_attrs
.
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.
For SCS, the only thing that happens is to add an attribute during code generation, and the backend handles the rest when doing frame lowering. But yeah, that's not quite right for other sanitizers. Clang has the notion of default sanitizers and IIRC a few targets set them. My understanding is that's mostly for SCS, but I think some may set particular flavors of UBSAN to always be on, e.g. for overflows, etc.
Probably adding them in rustc_session is more preferable. I have a vague memory that's what I initially tried but let me try that again, since you're right it should just affect the list from the start.
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.
Let me know about the new approach. I worked out what blocked my last time. I had misunderstood something about the way options were plumbed into session. Thanks for making me take a second look.
Some sanitizers are part of a system's ABI, like the shadow call stack on Aarch64 and RISC-V Fuchsia. Typically ABI options have other spellings, but LLVM has, for historical reasons, marked this as a sanitizer instead of an alternate ABI option. As a result, Fuchsia targets may not be compiled against the correct ABI unless this option is set. This hasn't caused correctness problems, since the backend reserves the SCS register, and thus preserves its value. But this is an issue for unwinding, as the SCS will not be an array of PCs describing the call complete call chain, and will have gaps from callers that don't use the correct ABI. In the long term, I'd like to see all the sanitizer configs that all frontends copy from clang moved into llvm's libFrontend, and exposed so that frontend consumers can use a small set of simple APIs to use sanitizers in a consistent way across the LLVM ecosystem, but that work is not yet ready today.
9ee9c2f
to
b003810
Compare
Some sanitizers are part of a system's ABI, like the shadow call stack on Aarch64 and RISC-V Fuchsia. Typically ABI options have other spellings, but LLVM has, for historical reasons, marked this as a sanitizer instead of an alternate ABI option. As a result, Fuchsia targets may not be compiled against the correct ABI unless this option is set. This hasn't caused correctness problems, since the backend reserves the SCS register, and thus preserves its value. But this is an issue for unwinding, as the SCS will not be an array of PCs describing the call complete call chain, and will have gaps from callers that don't use the correct ABI.
In the long term, I'd like to see all the sanitizer configs that all frontends copy from clang moved into llvm's libFrontend, and exposed so that frontend consumers can use a small set of simple APIs to use sanitizers in a consistent way across the LLVM ecosystem, but that work is not yet ready today.