Skip to content

Commit b9df37a

Browse files
committed
Create x86_64-unknown-linux-gnu{m,t}san target which enables {M,T}SAN by default
Similar like we've done it for `x86_64-unknown-linux-gnuasan`, in order to distribute sanitizer instrumented standard libraries without introducing new rustc flags, this adds a new dedicated target. With the target, we can distribute the instrumented standard libraries through a separate rustup component.
1 parent 71e0027 commit b9df37a

11 files changed

Lines changed: 162 additions & 0 deletions

File tree

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,8 @@ supported_targets! {
18151815
("x86_64-pc-cygwin", x86_64_pc_cygwin),
18161816

18171817
("x86_64-unknown-linux-gnuasan", x86_64_unknown_linux_gnuasan),
1818+
("x86_64-unknown-linux-gnumsan", x86_64_unknown_linux_gnumsan),
1819+
("x86_64-unknown-linux-gnutsan", x86_64_unknown_linux_gnutsan),
18181820
}
18191821

18201822
/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::spec::{SanitizerSet, Target, TargetMetadata};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = super::x86_64_unknown_linux_gnu::target();
5+
base.metadata = TargetMetadata {
6+
description: Some(
7+
"64-bit Linux (kernel 3.2+, glibc 2.17+) with MSAN enabled by default".into(),
8+
),
9+
tier: Some(2),
10+
host_tools: Some(false),
11+
std: Some(true),
12+
};
13+
base.supported_sanitizers = SanitizerSet::MEMORY;
14+
base.default_sanitizers = SanitizerSet::MEMORY;
15+
base
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::spec::{SanitizerSet, Target, TargetMetadata};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = super::x86_64_unknown_linux_gnu::target();
5+
base.metadata = TargetMetadata {
6+
description: Some(
7+
"64-bit Linux (kernel 3.2+, glibc 2.17+) with TSAN enabled by default".into(),
8+
),
9+
tier: Some(2),
10+
host_tools: Some(false),
11+
std: Some(true),
12+
};
13+
base.supported_sanitizers = SanitizerSet::LEAK;
14+
base.default_sanitizers = SanitizerSet::LEAK;
15+
base
16+
}

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,8 @@ fn supported_sanitizers(
15361536
&["asan", "dfsan", "lsan", "msan", "safestack", "tsan", "rtsan"],
15371537
),
15381538
"x86_64-unknown-linux-gnuasan" => common_libs("linux", "x86_64", &["asan"]),
1539+
"x86_64-unknown-linux-gnumsan" => common_libs("linux", "x86_64", &["msan"]),
1540+
"x86_64-unknown-linux-gnutsan" => common_libs("linux", "x86_64", &["tsan"]),
15391541
"x86_64-unknown-linux-musl" => {
15401542
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
15411543
}

src/bootstrap/src/core/sanity.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct Finder {
3838
const STAGE0_MISSING_TARGETS: &[&str] = &[
3939
// just a dummy comment so the list doesn't get onelined
4040
"x86_64-unknown-linux-gnuasan",
41+
"x86_64-unknown-linux-gnumsan",
42+
"x86_64-unknown-linux-gnutsan",
4143
"thumbv7a-none-eabi",
4244
"thumbv7a-none-eabihf",
4345
"thumbv7r-none-eabi",

src/ci/docker/host-x86_64/dist-various-2/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ ENV TARGETS=$TARGETS,x86_64-unknown-uefi
126126
ENV TARGETS=$TARGETS,riscv64gc-unknown-linux-musl
127127

128128
ENV TARGETS_SANITIZERS=x86_64-unknown-linux-gnuasan
129+
ENV TARGETS_SANITIZERS=$TARGETS_SANITIZERS,x86_64-unknown-linux-gnumsan
130+
ENV TARGETS_SANITIZERS=$TARGETS_SANITIZERS,x86_64-unknown-linux-gnutsan
129131

130132
# As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211
131133
# we need asm in the search path for gcc-9 (for gnux32) but not in the search path of the

src/doc/rustc/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,7 @@
155155
- [x86_64-unknown-linux-none](platform-support/x86_64-unknown-linux-none.md)
156156
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
157157
- [x86_64-unknown-linux-gnuasan](platform-support/x86_64-unknown-linux-gnuasan.md)
158+
- [x86_64-unknown-linux-gnumsan](platform-support/x86_64-unknown-linux-gnumsan.md)
159+
- [x86_64-unknown-linux-gnutsan](platform-support/x86_64-unknown-linux-gnutsan.md)
158160
- [xtensa-\*-none-elf](platform-support/xtensa.md)
159161
- [\*-nuttx-\*](platform-support/nuttx.md)

src/doc/rustc/src/platform-support.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ target | std | notes
216216
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
217217
[`x86_64-linux-android`](platform-support/android.md) | ✓ | 64-bit x86 Android
218218
[`x86_64-unknown-linux-gnuasan`](platform-support/x86_64-unknown-linux-gnuasan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with ASAN enabled by default
219+
[`x86_64-unknown-linux-gnumsan`](platform-support/x86_64-unknown-linux-gnumsan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with MSAN enabled by default
220+
[`x86_64-unknown-linux-gnutsan`](platform-support/x86_64-unknown-linux-gnutsan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with TSAN enabled by default
219221
[`x86_64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | 64-bit x86 Fuchsia
220222
`x86_64-unknown-linux-gnux32` | ✓ | 64-bit Linux (x32 ABI) (kernel 4.15+, glibc 2.27)
221223
[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | Freestanding/bare-metal x86_64, softfloat
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# `x86_64-unknown-linux-gnumsan`
2+
3+
**Tier: 2**
4+
5+
Target mirroring `x86_64-unknown-linux-gnu` with MemorySanitizer enabled by
6+
default.
7+
The goal of this target is to allow shipping MSAN-instrumented standard
8+
libraries through rustup, enabling a fully instrumented binary without requiring
9+
nightly features (build-std).
10+
Once build-std stabilizes, this target is no longer needed and will be removed.
11+
12+
## Target maintainers
13+
14+
- [@jakos-sec](https://github.com/jakos-sec)
15+
- [@1c3t3a](https://github.com/1c3t3a)
16+
- [@rust-lang/project-exploit-mitigations][project-exploit-mitigations]
17+
18+
## Requirements
19+
20+
The target is for cross-compilation only. Host tools are not supported, since
21+
there is no need to have the host tools instrumented with MSAN. std is fully
22+
supported.
23+
24+
In all other aspects the target is equivalent to `x86_64-unknown-linux-gnu`.
25+
26+
## Building the target
27+
28+
The target can be built by enabling it for a rustc build:
29+
30+
```toml
31+
[build]
32+
target = ["x86_64-unknown-linux-gnumsan"]
33+
```
34+
35+
## Building Rust programs
36+
37+
Rust programs can be compiled by adding this target via rustup:
38+
39+
```sh
40+
$ rustup target add x86_64-unknown-linux-gnumsan
41+
```
42+
43+
and then compiling with the target:
44+
45+
```sh
46+
$ rustc foo.rs --target x86_64-unknown-linux-gnumsan
47+
```
48+
49+
## Testing
50+
51+
Created binaries will run on Linux without any external requirements.
52+
53+
## Cross-compilation toolchains and C code
54+
55+
The target supports C code and should use the same toolchain target as
56+
`x86_64-unknown-linux-gnu`.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# `x86_64-unknown-linux-gnutsan`
2+
3+
**Tier: 2**
4+
5+
Target mirroring `x86_64-unknown-linux-gnu` with ThreadSanitizer enabled by
6+
default.
7+
The goal of this target is to allow shipping TSAN-instrumented standard
8+
libraries through rustup, enabling a fully instrumented binary without requiring
9+
nightly features (build-std).
10+
Once build-std stabilizes, this target is no longer needed and will be removed.
11+
12+
## Target maintainers
13+
14+
- [@jakos-sec](https://github.com/jakos-sec)
15+
- [@1c3t3a](https://github.com/1c3t3a)
16+
- [@rust-lang/project-exploit-mitigations][project-exploit-mitigations]
17+
18+
## Requirements
19+
20+
The target is for cross-compilation only. Host tools are not supported, since
21+
there is no need to have the host tools instrumented with TSAN. std is fully
22+
supported.
23+
24+
In all other aspects the target is equivalent to `x86_64-unknown-linux-gnu`.
25+
26+
## Building the target
27+
28+
The target can be built by enabling it for a rustc build:
29+
30+
```toml
31+
[build]
32+
target = ["x86_64-unknown-linux-gnutsan"]
33+
```
34+
35+
## Building Rust programs
36+
37+
Rust programs can be compiled by adding this target via rustup:
38+
39+
```sh
40+
$ rustup target add x86_64-unknown-linux-gnutsan
41+
```
42+
43+
and then compiling with the target:
44+
45+
```sh
46+
$ rustc foo.rs --target x86_64-unknown-linux-gnutsan
47+
```
48+
49+
## Testing
50+
51+
Created binaries will run on Linux without any external requirements.
52+
53+
## Cross-compilation toolchains and C code
54+
55+
The target supports C code and should use the same toolchain target as
56+
`x86_64-unknown-linux-gnu`.

0 commit comments

Comments
 (0)