Skip to content

Commit 1d0fcdd

Browse files
committed
sess: default to v0 symbol mangling
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 commit changes the default symbol mangling scheme from the legacy scheme to the new Rust mangling scheme. Signed-off-by: David Wood <[email protected]>
1 parent c8f22ca commit 1d0fcdd

16 files changed

+57
-51
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/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/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/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);

tests/codegen-llvm/precondition-checks.rs

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

1414
use std::ptr::NonNull;
1515

16-
// CHECK-LABEL: ; core::ptr::non_null::NonNull<T>::new_unchecked
16+
// CHECK-LABEL: ; <core::ptr::non_null::NonNull<u8>>::new_unchecked
1717
// CHECK-NOT: call
1818
// CHECK: }
1919

2020
// CHECK-LABEL: @nonnull_new
2121
#[no_mangle]
2222
pub unsafe fn nonnull_new(ptr: *mut u8) -> NonNull<u8> {
23-
// CHECK: ; call core::ptr::non_null::NonNull<T>::new_unchecked
23+
// CHECK: ; call <core::ptr::non_null::NonNull<u8>>::new_unchecked
2424
unsafe { NonNull::new_unchecked(ptr) }
2525
}

tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs

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

1010
#![crate_type = "lib"]
1111

12-
// CHECK-LABEL: define{{.*}}4core3ptr47drop_in_place$LT$dyn$u20$core..marker..Send$GT$
12+
// CHECK-LABEL: define{{.*}}4core3ptr13drop_in_placeDNtNtB4_6marker4Send
1313
// CHECK-SAME: {{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
1414
// CHECK: call i1 @llvm.type.test(ptr {{%.+}}, metadata !"_ZTSFvPu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops4drop4Dropu6regionEE")
1515

@@ -20,7 +20,7 @@ struct PresentDrop;
2020

2121
impl Drop for PresentDrop {
2222
fn drop(&mut self) {}
23-
// CHECK: define{{.*}}4core3ptr{{[0-9]+}}drop_in_place$LT${{.*}}PresentDrop$GT${{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
23+
// CHECK: define{{.*}}4core3ptr{{[0-9]+}}drop_in_place{{.*}}PresentDrop{{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
2424
}
2525

2626
pub fn foo() {

tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ pub fn main() {
5454
// `DynCompatible` is indeed dyn-compatible.
5555
let _: &dyn DynCompatible = &s;
5656

57-
// CHECK: call <fn_ptr_reify_shim::S as fn_ptr_reify_shim::DynCompatible>::dyn_name{{.*}}reify.shim.fnptr
57+
// CHECK: call <fn_ptr_reify_shim::S as fn_ptr_reify_shim::DynCompatible>::dyn_name::{shim:reify_fnptr#0}
5858
let dyn_name = S::dyn_name as fn(&S) -> &str;
5959
let _unused = dyn_name(&s);
6060

61-
// CHECK: call fn_ptr_reify_shim::DynCompatible::dyn_name_default{{.*}}reify.shim.fnptr
61+
// CHECK: call <fn_ptr_reify_shim::S as fn_ptr_reify_shim::DynCompatible>::dyn_name_default::{shim:reify_fnptr#0}
6262
let dyn_name_default = S::dyn_name_default as fn(&S) -> &str;
6363
let _unused = dyn_name_default(&s);
6464

@@ -68,7 +68,7 @@ pub fn main() {
6868
let not_dyn_name = S::not_dyn_name as fn() -> &'static str;
6969
let _unused = not_dyn_name();
7070

71-
// CHECK: call fn_ptr_reify_shim::NotDynCompatible::not_dyn_name_default{{$}}
71+
// CHECK: call <fn_ptr_reify_shim::S as fn_ptr_reify_shim::NotDynCompatible>::not_dyn_name_default{{$}}
7272
let not_dyn_name_default = S::not_dyn_name_default as fn() -> &'static str;
7373
let _unused = not_dyn_name_default();
7474
}

0 commit comments

Comments
 (0)