-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Create x86_64-asan-linux-gnu target which enables ASAN by default #149644
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
Open
jakos-sec
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
jakos-sec:create-asan-target
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
compiler/rustc_target/src/spec/targets/x86_64_asan_linux_gnu.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| use crate::spec::{SanitizerSet, Target, TargetMetadata}; | ||
|
|
||
| pub(crate) fn target() -> Target { | ||
| let mut base = super::x86_64_unknown_linux_gnu::target(); | ||
| base.metadata = TargetMetadata { | ||
| description: Some( | ||
| "64-bit Linux (kernel 3.2+, glibc 2.17+) with ASAN enabled by default".into(), | ||
| ), | ||
| tier: Some(3), | ||
| host_tools: Some(false), | ||
| std: Some(true), | ||
| }; | ||
| base.supported_sanitizers = SanitizerSet::ADDRESS; | ||
| base.default_sanitizers = SanitizerSet::ADDRESS; | ||
| base | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/doc/rustc/src/platform-support/x86_64-asan-linux-gnu.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # `x86_64-asan-linux-gnu` | ||
|
|
||
| **Tier: 3** | ||
|
|
||
| Target mirroring `x86_64-unknown-linux-gnu` with AddressSanitizer enabled by | ||
| default. | ||
| The goal of this target is to allow shipping ASAN-instrumented standard | ||
| libraries through rustup, enabling a fully instrumented binary without requiring | ||
| nightly features (build-std). | ||
| Once build-std stabilizes, we will likely no longer need this target. | ||
|
|
||
| ## Target maintainers | ||
|
|
||
| - [@jakos-sec](https://github.com/jakos-sec) | ||
| - [@1c3t3a](https://github.com/1c3t3a) | ||
| - [@rust-lang/project-exploit-mitigations][project-exploit-mitigations] | ||
|
|
||
| ## Requirements | ||
|
|
||
| The target is for cross-compilation only. Host tools are not supported, since | ||
| there is no need to have the host tools instrumented with ASAN. std is fully | ||
| supported. | ||
|
|
||
| In all other aspects the target is equivalent to `x86_64-unknown-linux-gnu`. | ||
|
|
||
| ## Building the target | ||
|
|
||
| The target can be built by enabling it for a rustc build: | ||
|
|
||
| ```toml | ||
| [build] | ||
| target = ["x86_64-asan-linux-gnu"] | ||
| ``` | ||
|
|
||
| ## Building Rust programs | ||
|
|
||
| Rust does not yet ship pre-compiled artifacts for this target. To compile for | ||
| this target, you will either need to build Rust with the target enabled (see | ||
| "Building the target" above), or build your own copy of `core` by using | ||
mati865 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `build-std` or similar. | ||
|
|
||
| Compilation can be done with: | ||
|
|
||
| ```text | ||
| rustc --target x86_64-asan-linux-gnu your-code.rs | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| Created binaries will run on Linux without any external requirements. | ||
|
|
||
| ## Cross-compilation toolchains and C code | ||
|
|
||
| The target supports C code and should use the same toolchain target as | ||
| `x86_64-unknown-linux-gnu`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a note, to ship libstd this will have to become a tier 2 target (without host tools).
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.
Thank you for pointing this out! I removed host-tools since there is no good reason to have them (nobody needs ASAN within the host tools). But I'll look into what tier 2 changes for this PR.
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 mean, the tiers are:
So, going to tier 2 without host tools would be just a next step on that ladder.
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.
Does this mean, we should merge this PR as tier 3 and then promote it or is it possible to merge it directly as tier 2 w/o host tools?
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 up to you. I think in this case tier 3 target won't be much better than just using -Zbuild-std, but won't hurt.
Tier 2 target will require MCP.
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 think it'd be best to simply wait and merge it as Tier 2 instead of going through the process to promote it later.