Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,8 @@ supported_targets! {
("x86_64-lynx-lynxos178", x86_64_lynx_lynxos178),

("x86_64-pc-cygwin", x86_64_pc_cygwin),

("x86_64-asan-linux-gnu", x86_64_asan_linux_gnu),
}

/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_target/src/spec/targets/x86_64_asan_linux_gnu.rs
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
}
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ fn supported_sanitizers(
"x86_64",
&["asan", "dfsan", "lsan", "msan", "safestack", "tsan", "rtsan"],
),
"x86_64-asan-linux-gnu" => common_libs("linux", "x86_64", &["asan"]),
"x86_64-unknown-linux-musl" => {
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
}
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
// just a dummy comment so the list doesn't get onelined
"riscv64gc-unknown-redox",
"hexagon-unknown-qurt",
"x86_64-asan-linux-gnu",
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@
- [x86_64-pc-cygwin](platform-support/x86_64-pc-cygwin.md)
- [x86_64-unknown-linux-none](platform-support/x86_64-unknown-linux-none.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
- [x86_64-asan-linux-gnu](platform-support/x86_64-asan-linux-gnu.md)
- [xtensa-\*-none-elf](platform-support/xtensa.md)
- [\*-nuttx-\*](platform-support/nuttx.md)
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ target | std | host | notes
[`x86_64-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | ✓ | 64-bit Windows 7 support
[`x86_64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | |
[`x86_64h-apple-darwin`](platform-support/x86_64h-apple-darwin.md) | ✓ | ✓ | macOS with late-gen Intel (at least Haswell)
[`x86_64-asan-linux-gnu`](platform-support/x86_64-asan-linux-gnu.md) | ✓ | | 64-bit Linux (kernel 3.2+, glibc 2.17+) with ASAN enabled by default
[`xtensa-esp32-espidf`](platform-support/esp-idf.md) | ✓ | | Xtensa ESP32
[`xtensa-esp32-none-elf`](platform-support/xtensa.md) | * | | Xtensa ESP32
[`xtensa-esp32s2-espidf`](platform-support/esp-idf.md) | ✓ | | Xtensa ESP32-S2
Expand Down
55 changes: 55 additions & 0 deletions src/doc/rustc/src/platform-support/x86_64-asan-linux-gnu.md
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).
Comment on lines +7 to +9
Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

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:

  • tier 1
  • tier 2 w/ host tools
  • tier 2 w/o host tools
  • tier 3

So, going to tier 2 without host tools would be just a next step on that ladder.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

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
`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`.
3 changes: 3 additions & 0 deletions tests/assembly-llvm/targets/targets-elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@
//@ revisions: x86_64_unknown_linux_gnux32
//@ [x86_64_unknown_linux_gnux32] compile-flags: --target x86_64-unknown-linux-gnux32
//@ [x86_64_unknown_linux_gnux32] needs-llvm-components: x86
//@ revisions: x86_64_asan_linux_gnu
//@ [x86_64_asan_linux_gnu] compile-flags: --target x86_64-asan-linux-gnu
//@ [x86_64_asan_linux_gnu] needs-llvm-components: x86
//@ revisions: x86_64_unknown_linux_musl
//@ [x86_64_unknown_linux_musl] compile-flags: --target x86_64-unknown-linux-musl
//@ [x86_64_unknown_linux_musl] needs-llvm-components: x86
Expand Down
Loading