Skip to content

Commit b40d1de

Browse files
committed
Rust for Linux project goals: compiler features
Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 0d0f95d commit b40d1de

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

src/2025h2/Rust-for-Linux-compiler.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Getting Rust for Linux into stable Rust: compiler features
2+
3+
| Metadata | |
4+
|:-----------------|----------------------------------------------------------------------------------|
5+
| Point of contact | @ojeda |
6+
| Teams | <!-- TEAMS WITH ASKS --> |
7+
| Task owners | <!-- TASK OWNERS --> |
8+
| Status | Proposed |
9+
| Tracking issue | [rust-lang/rust-project-goals#116] |
10+
| Zulip channel | [#t-compiler][channel-t-compiler], [#rust-for-linux][channel-rust-for-linux] |
11+
12+
[channel-t-compiler]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler
13+
[channel-rust-for-linux]: https://rust-lang.zulipchat.com/#narrow/channel/425075-rust-for-linux
14+
15+
## Summary
16+
17+
Continue working towards Rust for Linux on stable. In particular, this goal is focused on the compiler features.
18+
19+
## Motivation
20+
21+
Getting the Linux kernel to build with stable Rust and, more generally, supporting the needs of the Linux kernel to make Rust a success there, has been a priority for the Rust project and a previous flagship goal: [2024H2](https://rust-lang.github.io/rust-project-goals/2024h2/rfl_stable.html), [2025H1](https://rust-lang.github.io/rust-project-goals/2025h1/rfl.html).
22+
23+
One of the key areas are compiler features, which encompass a wide range of topics: architecture/target-related flags, sanitizers, mitigations, performance/optimization-oriented flags, and so on.
24+
25+
Thus, this project goal focuses on continuing the work that has been done in the last year around compiler features.
26+
27+
### The status quo
28+
29+
The Linux kernel, at the time of writing, relies on some Rust compiler unstable features such as:
30+
31+
- [`-Zbranch-protection`](https://github.com/rust-lang/rust/issues/113369) (arm64).
32+
- [`-Zcf-protection`](https://github.com/rust-lang/rust/issues/93754) (x86_64).
33+
- [`-Zcrate-attr`](https://github.com/rust-lang/rust/issues/138287).
34+
- [`-Zdebuginfo-compression`](https://github.com/rust-lang/rust/issues/120953).
35+
- [`-Zdirect-access-external-data`](https://github.com/rust-lang/rust/issues/127488) (loongarch).
36+
- `-Zfixed-x18` (arm64).
37+
- [`-Zfunction-return`](https://github.com/rust-lang/rust/issues/116853) (x86).
38+
- `-Zfunction-sections`.
39+
- [`-Zno-jump-tables`](https://github.com/rust-lang/rust/issues/116592) (x86_64).
40+
- [`-Zunpretty=expanded`](https://github.com/rust-lang/rust/issues/43364).
41+
- [`-Zsanitizer=kernel-address`](https://github.com/rust-lang/rust/issues/123615) (arm64, riscv64).
42+
- [`-Zsanitizer=shadow-call-stack`](https://github.com/rust-lang/rust/issues/123615) (arm64, riscv64).
43+
- [`-Zsanitizer=kcfi` and `-Zsanitizer-cfi-normalize-integers`](https://github.com/rust-lang/rust/issues/123479) (arm64, riscv64, x86_64).
44+
45+
There are others that we will want to start using in the future, such as:
46+
47+
- [`-Zharden-sls`](https://github.com/rust-lang/rust/issues/116851) (x86_64).
48+
- [`-Zindirect-branch-cs-prefix`](https://github.com/rust-lang/rust/pull/140740) (x86).
49+
- [`-Zmin-function-alignment`](https://github.com/rust-lang/rust/issues/82232).
50+
- [`-Zrandomize-layout`](https://github.com/rust-lang/rust/issues/106764).
51+
- [`-Zregparm`](https://github.com/rust-lang/rust/issues/131749) (x86_32).
52+
- [`-Zreg-struct-return`](https://github.com/rust-lang/rust/issues/116973) (x86_32).
53+
- [`-Zretpoline` and `-Zretpoline-external-thunk`](https://github.com/rust-lang/rust/pull/135927) (x86).
54+
- [`-Zsanitizer=kernel-hwaddress` and `-Zsanitizer-recover=kernel-hwaddress`](https://github.com/rust-lang/rust/issues/123615) (arm64).
55+
- [`-Zsanitize-kcfi-arity`](https://github.com/rust-lang/rust/issues/138311) (x86_64).
56+
57+
Relatedly, there is also the [`build-std` project goal](https://github.com/rust-lang/rust-project-goals/pull/331) support that we need as well (or, rather, only "`build-core`" for the Linux kernel), and the [sanitizers project goal](https://github.com/rust-lang/rust-project-goals/pull/337).
58+
59+
### The next 6 months
60+
61+
Ideally, the Linux kernel would not need to rely on any of the existing compiler unstable features by the time the period is over, but that is fairly unlikely. Thus, any progress on any feature (or an alternative to using a given unstable feature) would be welcome.
62+
63+
In particular, finishing the work and stabilizing the features that the kernel is already using upstream would be considered a major success.
64+
65+
### The "shiny future" we are working towards
66+
67+
Longer-term, the Linux kernel does not rely on any compiler-related unstable feature anymore, except for those that may need to be added in the future for different reasons, such as:
68+
69+
- New hardware features.
70+
- New mitigations.
71+
- New sanitizers.
72+
- New architectures.
73+
74+
For that reason, this goal is conceptually never ending, even if we may reach points where no unstable compiler feature is actually used.
75+
76+
## Design axioms
77+
78+
An important design axiom that still applies from previous iterations is "**Don't let perfect be the enemy of good**". The primary goal is to offer stable support for the particular use cases that the Linux kernel requires. Wherever possible we aim to stabilize features completely, but if necessary, we can try to stabilize a subset of functionality that meets the kernel developers' needs while leaving other aspects unstable.
79+
80+
## Ownership and team asks
81+
82+
| Task | Owner(s) or team(s) | Notes |
83+
|------------------------------|----------------------|--------------------------------------------|
84+
| Discussion and moral support | ![Team][] [compiler] | Continue the Rust for Linux <-> Rust calls |
85+
86+
Which flags get finished and stabilized depends on bandwidth and other constraints on both the Rust and the Rust for Linux sides, but generally we expect they will follow the usual pattern as we have done before.
87+
88+
### Finish and stabilize a given `-Z...` flag
89+
90+
| Task | Owner(s) or team(s) | Notes |
91+
|------------------------------|-------------------------|-------|
92+
| Discussion and moral support | ![Team][] [compiler] | |
93+
| Finalize remaining work | (depending on the flag) | |
94+
| Author stabilization report | (depending on the flag) | |
95+
| Author stabilization PR | (depending on the flag) | |
96+
| Stabilization decision | ![Team][] [compiler] | |
97+
98+
## Frequently asked questions

0 commit comments

Comments
 (0)