Skip to content

Commit 83ca9cf

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 acf2437 commit 83ca9cf

11 files changed

+24
-24
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ impl Options {
15201520
}
15211521

15221522
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
1523-
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
1523+
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::V0)
15241524
}
15251525

15261526
#[inline]

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/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
}

tests/codegen-llvm/sanitizer/kcfi/naked-function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl MyTrait for Thing {}
2929
// the shim calls the real function
3030
// CHECK-LABEL: define
3131
// CHECK-SAME: my_naked_function
32-
// CHECK-SAME: reify.shim.fnptr
32+
// CHECK-SAME: reify_fnptr
3333

3434
// CHECK-LABEL: main
3535
#[unsafe(no_mangle)]
@@ -40,7 +40,7 @@ pub fn main() {
4040
// main calls the shim function
4141
// CHECK: call void
4242
// CHECK-SAME: my_naked_function
43-
// CHECK-SAME: reify.shim.fnptr
43+
// CHECK-SAME: reify_fnptr
4444
(F)(&Thing);
4545
}
4646

tests/codegen-llvm/sanitizer/sanitize-off.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub trait MyTrait {
6666
fn unsanitized(&self, b: &mut u8) -> u8;
6767
fn sanitized(&self, b: &mut u8) -> u8;
6868

69-
// CHECK-LABEL: ; sanitize_off::MyTrait::unsanitized_default
69+
// CHECK-LABEL: ; <() as sanitize_off::MyTrait>::unsanitized_default
7070
// CHECK-NEXT: ; Function Attrs:
7171
// CHECK-NOT: sanitize_address
7272
// CHECK: start:
@@ -77,7 +77,7 @@ pub trait MyTrait {
7777
*b
7878
}
7979

80-
// CHECK-LABEL: ; sanitize_off::MyTrait::sanitized_default
80+
// CHECK-LABEL: ; <() as sanitize_off::MyTrait>::sanitized_default
8181
// CHECK-NEXT: ; Function Attrs:
8282
// CHECK: sanitize_address
8383
// CHECK: start:

tests/debuginfo/no_mangle-info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// lldb-command:v TEST
1414
// lldb-check:(unsigned long) TEST = 3735928559
1515
// lldb-command:v OTHER_TEST
16-
// lldb-check:(unsigned long) no_mangle_info::namespace::OTHER_TEST::[...] = 42
16+
// lldb-check:(unsigned long) no_mangle_info::namespace::OTHER_TEST = 42
1717

1818
// === CDB TESTS ==================================================================================
1919
// cdb-command: g

tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ debug!!!
44
stack backtrace:
55
0: std::panicking::begin_panic
66
1: short_ice_remove_middle_frames_2::eight
7-
2: short_ice_remove_middle_frames_2::seven::{{closure}}
7+
2: short_ice_remove_middle_frames_2::seven::{closure#0}
88
[... omitted 3 frames ...]
99
3: short_ice_remove_middle_frames_2::fifth
10-
4: short_ice_remove_middle_frames_2::fourth::{{closure}}
10+
4: short_ice_remove_middle_frames_2::fourth::{closure#0}
1111
[... omitted 4 frames ...]
1212
5: short_ice_remove_middle_frames_2::first
1313
6: short_ice_remove_middle_frames_2::main
14-
7: core::ops::function::FnOnce::call_once
14+
7: <fn() as core::ops::function::FnOnce<()>>::call_once
1515
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

0 commit comments

Comments
 (0)