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
add safe compilation options #117966
add safe compilation options #117966
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @onur-ozkan (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This PR modifies This PR changes |
This comment has been minimized.
This comment has been minimized.
2477a5f
to
241ed37
Compare
This comment has been minimized.
This comment has been minimized.
241ed37
to
8c064e6
Compare
This comment has been minimized.
This comment has been minimized.
8c064e6
to
107d565
Compare
This comment has been minimized.
This comment has been minimized.
107d565
to
e2122c1
Compare
Some context: these options are useful to us at Huawei to imply with some internal requirements, if we can configure them via |
@@ -603,6 +603,13 @@ change-id = 116881 | |||
# desired in distributions, for example. | |||
#rpath = true | |||
|
|||
# Indicates whether `rustc` should be stripped of symbols using `-Cstrip=symbols`. | |||
#strip = false |
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.
When is this necessary, if debuginfo is not enabled in the first place? Do we really need another option here?
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.
-Cstrip=symbols
will strip all symbols, not only the debuginfo. The artifacts will be smaller and have fewer symbols if we use strip = true
.
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 compare the size of binary artifacts, it will be smaller if use -Cstrip=symbols
compare to not using. For example, the size of librustc_driver.so
is 194.5MB without using -Cstrip=symbols
, but 141.3MB when using -Cstrip=symbols
.
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 see. Thanks!
"none" => Ok(StackProtector::None), | ||
"basic" => Ok(StackProtector::Basic), | ||
"strong" => Ok(StackProtector::Strong), | ||
"all" => Ok(StackProtector::All), |
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'd prefer to avoid duplicating the names of the values for this unstable option here from rustc. Can we just pass this through as an opaque string?
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.
Modified according to comments.
@rustbot author |
e2122c1
to
68462e3
Compare
This comment has been minimized.
This comment has been minimized.
68462e3
to
5f4c094
Compare
config.example.toml
Outdated
# Indicates whether stack protectors should be used | ||
# via the unstable option `-Zstack-protector`. | ||
# Valid options are : `none`(default),`basic`,`strong`, or `all`. | ||
# But `strong` and `basic` options may be buggy and are not suggested here.(rust-lang/rust #114903) | ||
#stack-protector = "none" |
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.
# Indicates whether stack protectors should be used | |
# via the unstable option `-Zstack-protector`. | |
# Valid options are : `none`(default),`basic`,`strong`, or `all`. | |
# But `strong` and `basic` options may be buggy and are not suggested here.(rust-lang/rust #114903) | |
#stack-protector = "none" | |
# Indicates whether stack protectors should be used | |
# via the unstable option `-Zstack-protector`. | |
# | |
# Valid options are: `none`(default), `basic`, `strong`, or `all`. | |
# `strong` and `basic` may be buggy and are not recommended, see rust-lang/rust#114903. | |
#stack-protector = "none" |
src/bootstrap/src/core/builder.rs
Outdated
match self.config.rust_stack_protector.as_str() { | ||
"none" => rustflags.arg("-Zstack-protector=none"), | ||
"basic" => rustflags.arg("-Zstack-protector=basic"), | ||
"strong" => rustflags.arg("-Zstack-protector=strong"), | ||
"all" => rustflags.arg("-Zstack-protector=all"), | ||
other => unreachable!("{:?} is not recognized as valid stack protectors", other), | ||
}; |
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.
Something like this might have been more what Mark had in mind, assuming that rust_stack_protector
is made an Option
.
match self.config.rust_stack_protector.as_str() { | |
"none" => rustflags.arg("-Zstack-protector=none"), | |
"basic" => rustflags.arg("-Zstack-protector=basic"), | |
"strong" => rustflags.arg("-Zstack-protector=strong"), | |
"all" => rustflags.arg("-Zstack-protector=all"), | |
other => unreachable!("{:?} is not recognized as valid stack protectors", other), | |
}; | |
if let Some(stack_protector) = self.config.rust_stack_protector { | |
rustflags.arg(format!("-Zstack-protector={stack_protector}"))); | |
} |
5f4c094
to
0cd4e18
Compare
This comment has been minimized.
This comment has been minimized.
0cd4e18
to
8dd6817
Compare
This comment has been minimized.
This comment has been minimized.
8dd6817
to
1aea4b1
Compare
This comment has been minimized.
This comment has been minimized.
1aea4b1
to
33f35b5
Compare
This comment has been minimized.
This comment has been minimized.
Add two options when building rust: strip and stack protector. If set `strip = true`, symbols will be stripped using `-Cstrip=symbols`. Also can set `stack-protector` and stack protectors will be used.
33f35b5
to
3f8487a
Compare
This is in my queue to review, I just haven't had the chance to do so yet. |
@bors r+ rollup |
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#117966 (add safe compilation options) - rust-lang#118747 (Remove extra check cfg handled by libc directly) - rust-lang#118774 (add test for inductive cycle hangs) - rust-lang#118775 (chore: add test case for type with generic) - rust-lang#118782 (use `&` instead of start-process in x.ps1) r? `@ghost` `@rustbot` modify labels: rollup
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#117966 (add safe compilation options) - rust-lang#118747 (Remove extra check cfg handled by libc directly) - rust-lang#118774 (add test for inductive cycle hangs) - rust-lang#118775 (chore: add test case for type with generic) - rust-lang#118782 (use `&` instead of start-process in x.ps1) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117966 - lxy19980601:safe_compilation_options, r=Mark-Simulacrum add safe compilation options Add two options when building rustc : strip and stack protector. If set `strip = true`, `rustc` will be stripped of symbols using `-Cstrip=symbols`. Also can set `stack-protector` and then `rustc` will be compiled with stack protectors.
Add two options when building rustc : strip and stack protector.
If set
strip = true
,rustc
will be stripped of symbols using-Cstrip=symbols
.Also can set
stack-protector
and thenrustc
will be compiled with stack protectors.