Skip to content

Commit 27ab8da

Browse files
Rollup merge of rust-lang#151994 - davidtwco:v0-mangling-on-stable, r=wesleywiser
switch to v0 mangling by default on stable Following rust-lang#89117, rustc has defaulted to the v0 mangling scheme by default (since Nov 20th 2025). This surfaced two bugs: - rust-lang#138261 was a small ICE (found via fuzzing) where an implementation-internal namespace was missing for global assembly - this occurs with names instantiated within global assembly (that can happen inside constants) - rust-lang#134479 only occurs with unstable `generic_const_exprs` Since there have been three-to-four months for users to find bugs with this mangling scheme on nightly, that the scheme has been waiting many years to be stabilised, and has been used successfully internally at Microsoft, Meta and Google for many years, this patch proposes stabilising the v0 mangling scheme on stable. This patch does not propose removing the legacy mangling, it will remain usable on nightly as an escape-hatch if there are remaining bugs (though admittedly it would require switching to nightly for those on stable) - it is anticipated that this would be unlikely given current testing undergone by v0. Legacy mangling can be removed in another follow-up. r? @wesleywiser
2 parents 03c609a + a4c0bf5 commit 27ab8da

4 files changed

Lines changed: 7 additions & 21 deletions

File tree

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,11 +1487,7 @@ impl Options {
14871487
}
14881488

14891489
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
1490-
self.cg.symbol_mangling_version.unwrap_or(if self.unstable_features.is_nightly_build() {
1491-
SymbolManglingVersion::V0
1492-
} else {
1493-
SymbolManglingVersion::Legacy
1494-
})
1490+
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::V0)
14951491
}
14961492

14971493
#[inline]

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@ options! {
21662166
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
21672167
symbol_mangling_version: Option<SymbolManglingVersion> = (None,
21682168
parse_symbol_mangling_version, [TRACKED],
2169-
"which mangling version to use for symbol names ('legacy' (default), 'v0', or 'hashed')"),
2169+
"which mangling version to use for symbol names ('legacy', 'v0' (default), or 'hashed')"),
21702170
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
21712171
"select target processor (`rustc --print target-cpus` for details)"),
21722172
target_feature: String = (String::new(), parse_target_feature, [TRACKED],

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,6 @@ impl Builder<'_> {
687687
rustflags.arg(sysroot_str);
688688
}
689689

690-
let use_new_symbol_mangling = self.config.rust_new_symbol_mangling.or_else(|| {
691-
if mode != Mode::Std {
692-
// The compiler and tools default to the new scheme
693-
Some(true)
694-
} else {
695-
// std follows the flag's default, which per compiler-team#938 is v0 on nightly
696-
None
697-
}
698-
});
699-
700690
// By default, windows-rs depends on a native library that doesn't get copied into the
701691
// sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
702692
// library unnecessary. This can be removed when windows-rs enables raw-dylib
@@ -706,7 +696,8 @@ impl Builder<'_> {
706696
rustflags.arg("--cfg=windows_raw_dylib");
707697
}
708698

709-
if let Some(usm) = use_new_symbol_mangling {
699+
// When unset, follow the default of the compiler flag - the compiler, tools and std use v0
700+
if let Some(usm) = self.config.rust_new_symbol_mangling {
710701
rustflags.arg(if usm {
711702
"-Csymbol-mangling-version=v0"
712703
} else {

src/doc/rustc/src/symbol-mangling/index.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ foo::example_function
4646

4747
## Mangling versions
4848

49-
`rustc` supports different mangling versions which encode the names in different ways.
50-
The legacy version (which is currently the default on beta/stable) is not described here.
51-
The "v0" mangling scheme addresses several limitations of the legacy format,
52-
and is described in the [v0 Symbol Format](v0.md) chapter.
49+
There is currently one stable mangling scheme version - `v0`. On nightly builds, rustc supports
50+
switching back to the `legacy` mangling scheme using [`-C symbol-mangling-version`]. The `v0`
51+
mangling scheme is described in the [v0 Symbol Format](v0.md) chapter.

0 commit comments

Comments
 (0)