Skip to content

Commit 683dd08

Browse files
committed
Auto merge of #89917 - davidtwco:issue-60705-stabilize-rust-symbol-mangling-scheme, r=wesleywiser
sess: default to v0 symbol mangling on nightly cc #60705 rust-lang/compiler-team#938 Rust's current mangling scheme depends on compiler internals; loses information about generic parameters (and other things) which makes for a worse experience when using external tools that need to interact with Rust symbol names; is inconsistent; and can contain `.` characters which aren't universally supported. Therefore, Rust has defined its own symbol mangling scheme which is defined in terms of the Rust language, not the compiler implementation; encodes information about generic parameters in a reversible way; has a consistent definition; and generates symbols that only use the characters `A-Z`, `a-z`, `0-9`, and `_`. Support for the new Rust symbol mangling scheme has been added to upstream tools that will need to interact with Rust symbols (e.g. debuggers). This pull request changes the default symbol mangling scheme from the legacy scheme to the new Rust mangling scheme on nightly. The following pull requests implemented v0 mangling in rustc (if I'm missing any, let me know): - #57967 - #63559 - #75675 - #77452 - #77554 - #83767 - #87194 - #87789 Rust's symbol mangling scheme has support in the following external tools: - `binutils`/`gdb` (GNU `libiberty`) - [[PATCH] Move rust_{is_mangled,demangle_sym} to a private libiberty header. ](https://gcc.gnu.org/pipermail/gcc-patches/2019-June/523011.html) committed as gcc-mirror/gcc@979526c - [[PATCH] Simplify and generalize rust-demangle's unescaping logic. ](https://gcc.gnu.org/pipermail/gcc-patches/2019-August/527835.html) committed as gcc-mirror/gcc@42bf58b - [[PATCH] Remove some restrictions from rust-demangle. ](https://gcc.gnu.org/pipermail/gcc-patches/2019-September/530445.html) committed as gcc-mirror/gcc@e1cb00d - [[PATCH] Refactor rust-demangle to be independent of C++ demangling. ](https://gcc.gnu.org/pipermail/gcc-patches/2019-November/533719.html) ([original submission](https://gcc.gnu.org/pipermail/gcc-patches/2019-October/532388.html)) committed as gcc-mirror/gcc@32fc371 - [[PATCH] Support the new ("v0") mangling scheme in rust-demangle. ](https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558905.html) ([original submission](https://gcc.gnu.org/pipermail/gcc-patches/2020-March/542012.html)) committed as gcc-mirror/gcc@8409649 - `lldb`/`llvm-objdump`/`llvm-nm`/`llvm-symbolizer`/`llvm-cxxfilt`/etc - llvm/llvm-project@7310403 - llvm/llvm-project@c8c2b46 - llvm/llvm-project@0a2d4f3 - Linux `perf` - `valgrind` - [Update demangler to support Rust v0 name mangling.](https://bugs.kde.org/show_bug.cgi?id=431306) #85530 (comment) contains a summary of the most recent crater run of the v0 mangling, and the remaining issues from that were fixed by #87194 (confirmed by follow-up crater run, #85530 (comment)). `@rustbot` label +T-compiler r? `@michaelwoerister`
2 parents d2f8873 + ff00110 commit 683dd08

20 files changed

+61
-55
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,11 @@ impl Options {
15301530
}
15311531

15321532
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
1533-
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
1533+
self.cg.symbol_mangling_version.unwrap_or(if self.unstable_features.is_nightly_build() {
1534+
SymbolManglingVersion::V0
1535+
} else {
1536+
SymbolManglingVersion::Legacy
1537+
})
15341538
}
15351539

15361540
#[inline]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ foo::example_function
4747
## Mangling versions
4848

4949
`rustc` supports different mangling versions which encode the names in different ways.
50-
The legacy version (which is currently the default) is not described here.
50+
The legacy version (which is currently the default on beta/stable) is not described here.
5151
The "v0" mangling scheme addresses several limitations of the legacy format,
5252
and is described in the [v0 Symbol Format](v0.md) chapter.

tests/assembly-llvm/closure-inherit-target-feature.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::arch::x86_64::{__m128, _mm_blend_ps};
1313
pub unsafe fn sse41_blend_nofeature(x: __m128, y: __m128, ret: *mut __m128) {
1414
let f = {
1515
// check that _mm_blend_ps is not being inlined into the closure
16-
// CHECK-LABEL: {{sse41_blend_nofeature.*closure.*:}}
16+
// CHECK-LABEL: {{sse41_blend_nofeature:}}
1717
// CHECK-NOT: blendps
1818
// CHECK: {{call .*_mm_blend_ps.*}}
1919
// CHECK-NOT: blendps
@@ -29,7 +29,7 @@ pub unsafe fn sse41_blend_nofeature(x: __m128, y: __m128, ret: *mut __m128) {
2929
pub fn sse41_blend_noinline(x: __m128, y: __m128) -> __m128 {
3030
let f = {
3131
// check that _mm_blend_ps is being inlined into the closure
32-
// CHECK-LABEL: {{sse41_blend_noinline.*closure.*:}}
32+
// CHECK-LABEL: {{sse41_blend_noinline:}}
3333
// CHECK-NOT: _mm_blend_ps
3434
// CHECK: blendps
3535
// CHECK-NOT: _mm_blend_ps
@@ -45,10 +45,10 @@ pub fn sse41_blend_noinline(x: __m128, y: __m128) -> __m128 {
4545
pub fn sse41_blend_doinline(x: __m128, y: __m128) -> __m128 {
4646
// check that the closure and _mm_blend_ps are being inlined into the function
4747
// CHECK-LABEL: sse41_blend_doinline:
48-
// CHECK-NOT: {{sse41_blend_doinline.*closure.*}}
48+
// CHECK-NOT: {{sse41_blend_doinline:}}
4949
// CHECK-NOT: _mm_blend_ps
5050
// CHECK: blendps
51-
// CHECK-NOT: {{sse41_blend_doinline.*closure.*}}
51+
// CHECK-NOT: {{sse41_blend_doinline.*}}
5252
// CHECK-NOT: _mm_blend_ps
5353
// CHECK: ret
5454
let f = {

tests/assembly-llvm/nvptx-safe-naming.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern crate breakpoint_panic_handler;
1313

1414
// Verify function name doesn't contain unacceaptable characters.
15-
// CHECK: .func (.param .b32 func_retval0) [[IMPL_FN:[a-zA-Z0-9$_]+square[a-zA-Z0-9$_]+]]
15+
// CHECK: .func (.param .b32 func_retval0) [[IMPL_FN:[a-zA-Z0-9$_]+square]]
1616

1717
// CHECK-LABEL: .visible .entry top_kernel(
1818
#[no_mangle]

tests/codegen-llvm/array-from_fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#[no_mangle]
99
pub fn iota() -> [u8; 16] {
10-
// OPT-NOT: core..array..Guard
11-
// NORMAL: core..array..Guard
10+
// OPT-NOT: core::array::Guard
11+
// NORMAL: core::array::Guard
1212
std::array::from_fn(|i| i as _)
1313
}

tests/codegen-llvm/binary-heap-peek-mut-pop-no-panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Copt-level=3
1+
//@ compile-flags: -Copt-level=3 --crate-name=test
22
//@ ignore-std-debug-assertions
33
#![crate_type = "lib"]
44

tests/codegen-llvm/cold-attribute.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn async_block() {
2020
f.await;
2121
}
2222
x(
23-
// CHECK-LABEL: ; cold_attribute::async_block::{{{{closure}}}}::{{{{closure}}}}
23+
// CHECK-LABEL: ; cold_attribute::async_block::{closure#0}::{closure#0}
2424
// CHECK-NEXT: Function Attrs: cold {{.*}}
2525
#[cold]
2626
async {},
@@ -33,7 +33,7 @@ pub fn closure() {
3333
f()
3434
}
3535
x(
36-
// CHECK-LABEL: ; cold_attribute::closure::{{{{closure}}}}
36+
// CHECK-LABEL: ; cold_attribute::closure::{closure#0}
3737
// CHECK-NEXT: Function Attrs: cold {{.*}}
3838
#[cold]
3939
|| {},
@@ -43,14 +43,14 @@ pub fn closure() {
4343
pub struct S;
4444

4545
impl S {
46-
// CHECK-LABEL: ; cold_attribute::S::method
46+
// CHECK-LABEL: ; <cold_attribute::S>::method
4747
// CHECK-NEXT: Function Attrs: cold {{.*}}
4848
#[cold]
4949
pub fn method(&self) {}
5050
}
5151

5252
pub trait Trait {
53-
// CHECK-LABEL: ; cold_attribute::Trait::trait_fn
53+
// CHECK-LABEL: ; <cold_attribute::S as cold_attribute::Trait>::trait_fn
5454
// CHECK-NEXT: Function Attrs: cold {{.*}}
5555
#[cold]
5656
fn trait_fn(&self) {}

tests/codegen-llvm/issues/iter-max-no-unwrap-failed-129583.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The iterator may unroll for values smaller than a certain threshold so we
33
// use a larger value to prevent unrolling.
44

5-
//@ compile-flags: -Copt-level=3
5+
//@ compile-flags: -Copt-level=3 --crate-name=test
66

77
#![crate_type = "lib"]
88

tests/codegen-llvm/naked-fn/generics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ fn test(x: u64) {
2020
}
2121

2222
// CHECK: .balign 4
23-
// CHECK: add rax, 2
23+
// CHECK: add rax, 1
2424
// CHECK: add rax, 42
2525

2626
// CHECK: .balign 4
27-
// CHECK: add rax, 1
27+
// CHECK: add rax, 2
2828
// CHECK: add rax, 42
2929

3030
#[unsafe(naked)]

tests/codegen-llvm/no-alloca-inside-if-false.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
#[inline(never)]
99
fn test<const SIZE: usize>() {
10-
// CHECK-LABEL: no_alloca_inside_if_false::test
10+
// CHECK-LABEL: no_alloca_inside_if_false::test::<8192>
1111
// CHECK: start:
12-
// CHECK-NEXT: alloca [{{12|24}} x i8]
13-
// CHECK-NOT: alloca
12+
// CHECK-NEXT: = alloca [{{12|24}} x i8]
13+
// CHECK-NOT: = alloca
1414
if const { SIZE < 4096 } {
1515
let arr = [0u8; SIZE];
1616
std::hint::black_box(&arr);

0 commit comments

Comments
 (0)