From 83ca9cf11e76721ee7b9c5ffbe829620aa4817fe Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 15 Oct 2021 15:20:21 +0000 Subject: [PATCH] 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 --- compiler/rustc_session/src/config.rs | 2 +- tests/codegen-llvm/array-from_fn.rs | 4 ++-- tests/codegen-llvm/no-alloca-inside-if-false.rs | 6 +++--- tests/codegen-llvm/precondition-checks.rs | 4 ++-- .../emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs | 4 ++-- tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs | 6 +++--- tests/codegen-llvm/sanitizer/kcfi/naked-function.rs | 4 ++-- tests/codegen-llvm/sanitizer/sanitize-off.rs | 4 ++-- tests/debuginfo/no_mangle-info.rs | 2 +- tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr | 6 +++--- tests/ui/panics/short-ice-remove-middle-frames.run.stderr | 6 +++--- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index d1426ff55fbd6..8c0e5533423fa 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1520,7 +1520,7 @@ impl Options { } pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion { - self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy) + self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::V0) } #[inline] diff --git a/tests/codegen-llvm/array-from_fn.rs b/tests/codegen-llvm/array-from_fn.rs index 7202d0c67e690..0a6d5aec4b652 100644 --- a/tests/codegen-llvm/array-from_fn.rs +++ b/tests/codegen-llvm/array-from_fn.rs @@ -7,7 +7,7 @@ #[no_mangle] pub fn iota() -> [u8; 16] { - // OPT-NOT: core..array..Guard - // NORMAL: core..array..Guard + // OPT-NOT: core::array::Guard + // NORMAL: core::array::Guard std::array::from_fn(|i| i as _) } diff --git a/tests/codegen-llvm/no-alloca-inside-if-false.rs b/tests/codegen-llvm/no-alloca-inside-if-false.rs index a231c7e808a39..d2458d0a9ab29 100644 --- a/tests/codegen-llvm/no-alloca-inside-if-false.rs +++ b/tests/codegen-llvm/no-alloca-inside-if-false.rs @@ -7,10 +7,10 @@ #[inline(never)] fn test() { - // CHECK-LABEL: no_alloca_inside_if_false::test + // CHECK-LABEL: no_alloca_inside_if_false::test::<8192> // CHECK: start: - // CHECK-NEXT: alloca [{{12|24}} x i8] - // CHECK-NOT: alloca + // CHECK-NEXT: = alloca [{{12|24}} x i8] + // CHECK-NOT: = alloca if const { SIZE < 4096 } { let arr = [0u8; SIZE]; std::hint::black_box(&arr); diff --git a/tests/codegen-llvm/precondition-checks.rs b/tests/codegen-llvm/precondition-checks.rs index 16812ca17207c..df8d6ff4c2ef0 100644 --- a/tests/codegen-llvm/precondition-checks.rs +++ b/tests/codegen-llvm/precondition-checks.rs @@ -13,13 +13,13 @@ use std::ptr::NonNull; -// CHECK-LABEL: ; core::ptr::non_null::NonNull::new_unchecked +// CHECK-LABEL: ; >::new_unchecked // CHECK-NOT: call // CHECK: } // CHECK-LABEL: @nonnull_new #[no_mangle] pub unsafe fn nonnull_new(ptr: *mut u8) -> NonNull { - // CHECK: ; call core::ptr::non_null::NonNull::new_unchecked + // CHECK: ; call >::new_unchecked unsafe { NonNull::new_unchecked(ptr) } } diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs index 279350d20c5f0..a5ec3a9ab7183 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs @@ -9,7 +9,7 @@ #![crate_type = "lib"] -// CHECK-LABEL: define{{.*}}4core3ptr47drop_in_place$LT$dyn$u20$core..marker..Send$GT$ +// CHECK-LABEL: define{{.*}}4core3ptr13drop_in_placeDNtNtB4_6marker4Send // CHECK-SAME: {{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} // CHECK: call i1 @llvm.type.test(ptr {{%.+}}, metadata !"_ZTSFvPu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops4drop4Dropu6regionEE") @@ -20,7 +20,7 @@ struct PresentDrop; impl Drop for PresentDrop { fn drop(&mut self) {} - // CHECK: define{{.*}}4core3ptr{{[0-9]+}}drop_in_place$LT${{.*}}PresentDrop$GT${{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + // CHECK: define{{.*}}4core3ptr{{[0-9]+}}drop_in_place{{.*}}PresentDrop{{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} } pub fn foo() { diff --git a/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs b/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs index 604b4c8c2f8a5..ac8a7d81a590e 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs @@ -54,11 +54,11 @@ pub fn main() { // `DynCompatible` is indeed dyn-compatible. let _: &dyn DynCompatible = &s; - // CHECK: call ::dyn_name{{.*}}reify.shim.fnptr + // CHECK: call ::dyn_name::{shim:reify_fnptr#0} let dyn_name = S::dyn_name as fn(&S) -> &str; let _unused = dyn_name(&s); - // CHECK: call fn_ptr_reify_shim::DynCompatible::dyn_name_default{{.*}}reify.shim.fnptr + // CHECK: call ::dyn_name_default::{shim:reify_fnptr#0} let dyn_name_default = S::dyn_name_default as fn(&S) -> &str; let _unused = dyn_name_default(&s); @@ -68,7 +68,7 @@ pub fn main() { let not_dyn_name = S::not_dyn_name as fn() -> &'static str; let _unused = not_dyn_name(); - // CHECK: call fn_ptr_reify_shim::NotDynCompatible::not_dyn_name_default{{$}} + // CHECK: call ::not_dyn_name_default{{$}} let not_dyn_name_default = S::not_dyn_name_default as fn() -> &'static str; let _unused = not_dyn_name_default(); } diff --git a/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs b/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs index 31f59ee01decb..1237d5150eff1 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs @@ -29,7 +29,7 @@ impl MyTrait for Thing {} // the shim calls the real function // CHECK-LABEL: define // CHECK-SAME: my_naked_function -// CHECK-SAME: reify.shim.fnptr +// CHECK-SAME: reify_fnptr // CHECK-LABEL: main #[unsafe(no_mangle)] @@ -40,7 +40,7 @@ pub fn main() { // main calls the shim function // CHECK: call void // CHECK-SAME: my_naked_function - // CHECK-SAME: reify.shim.fnptr + // CHECK-SAME: reify_fnptr (F)(&Thing); } diff --git a/tests/codegen-llvm/sanitizer/sanitize-off.rs b/tests/codegen-llvm/sanitizer/sanitize-off.rs index 9f3f7cd9df781..ac7c49322c6d8 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off.rs @@ -66,7 +66,7 @@ pub trait MyTrait { fn unsanitized(&self, b: &mut u8) -> u8; fn sanitized(&self, b: &mut u8) -> u8; - // CHECK-LABEL: ; sanitize_off::MyTrait::unsanitized_default + // CHECK-LABEL: ; <() as sanitize_off::MyTrait>::unsanitized_default // CHECK-NEXT: ; Function Attrs: // CHECK-NOT: sanitize_address // CHECK: start: @@ -77,7 +77,7 @@ pub trait MyTrait { *b } - // CHECK-LABEL: ; sanitize_off::MyTrait::sanitized_default + // CHECK-LABEL: ; <() as sanitize_off::MyTrait>::sanitized_default // CHECK-NEXT: ; Function Attrs: // CHECK: sanitize_address // CHECK: start: diff --git a/tests/debuginfo/no_mangle-info.rs b/tests/debuginfo/no_mangle-info.rs index 06c65a71b2e91..41e36706c6692 100644 --- a/tests/debuginfo/no_mangle-info.rs +++ b/tests/debuginfo/no_mangle-info.rs @@ -13,7 +13,7 @@ // lldb-command:v TEST // lldb-check:(unsigned long) TEST = 3735928559 // lldb-command:v OTHER_TEST -// lldb-check:(unsigned long) no_mangle_info::namespace::OTHER_TEST::[...] = 42 +// lldb-check:(unsigned long) no_mangle_info::namespace::OTHER_TEST = 42 // === CDB TESTS ================================================================================== // cdb-command: g diff --git a/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr b/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr index 584b477f3a7c1..a652eb2112853 100644 --- a/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr +++ b/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr @@ -4,12 +4,12 @@ debug!!! stack backtrace: 0: std::panicking::begin_panic 1: short_ice_remove_middle_frames_2::eight - 2: short_ice_remove_middle_frames_2::seven::{{closure}} + 2: short_ice_remove_middle_frames_2::seven::{closure#0} [... omitted 3 frames ...] 3: short_ice_remove_middle_frames_2::fifth - 4: short_ice_remove_middle_frames_2::fourth::{{closure}} + 4: short_ice_remove_middle_frames_2::fourth::{closure#0} [... omitted 4 frames ...] 5: short_ice_remove_middle_frames_2::first 6: short_ice_remove_middle_frames_2::main - 7: core::ops::function::FnOnce::call_once + 7: >::call_once note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. diff --git a/tests/ui/panics/short-ice-remove-middle-frames.run.stderr b/tests/ui/panics/short-ice-remove-middle-frames.run.stderr index 1efcb7d530409..31fcda89a1bfe 100644 --- a/tests/ui/panics/short-ice-remove-middle-frames.run.stderr +++ b/tests/ui/panics/short-ice-remove-middle-frames.run.stderr @@ -5,11 +5,11 @@ stack backtrace: 0: std::panicking::begin_panic 1: short_ice_remove_middle_frames::seven 2: short_ice_remove_middle_frames::sixth - 3: short_ice_remove_middle_frames::fifth::{{closure}} + 3: short_ice_remove_middle_frames::fifth::{closure#0} [... omitted 4 frames ...] 4: short_ice_remove_middle_frames::second - 5: short_ice_remove_middle_frames::first::{{closure}} + 5: short_ice_remove_middle_frames::first::{closure#0} 6: short_ice_remove_middle_frames::first 7: short_ice_remove_middle_frames::main - 8: core::ops::function::FnOnce::call_once + 8: >::call_once note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.