about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-05-31 17:10:11 +0000
committerbors <bors@rust-lang.org>2019-05-31 17:10:11 +0000
commit7840a0b753a065a41999f1fb6028f67d33e3fdd5 (patch)
tree9cbd890e3a5d1ec24a358581e8f4e0d449dde7f3 /src/test/codegen
parent75f464481ed8c924086fc0b9a2d31841bbdbcabd (diff)
parent3652ea4594918d5f4c7e7a073d3e3105c726d1ef (diff)
downloadrust-7840a0b753a065a41999f1fb6028f67d33e3fdd5.tar.gz
rust-7840a0b753a065a41999f1fb6028f67d33e3fdd5.zip
Auto merge of #57967 - eddyb:rmangle, r=michaelwoerister
Introduce Rust symbol mangling scheme.

This is an implementation of a "feature-complete" Rust mangling scheme, in the vein of rust-lang/rfcs#2603 ~~- but with some differences, see https://github.com/rust-lang/rfcs/pull/2603#issuecomment-458410463 for details~~ (@michaelwoerister integrated my proposed changes into the RFC itself).

On nightly, you can now control the mangling scheme with `-Z symbol-mangling-version`, which can be:
* `legacy`: the older mangling version, still the default currently
* `v0`: the new RFC mangling version, as implemented by this PR

To test the new mangling, set `RUSTFLAGS=-Zsymbol-mangling-version=v0` (or change [`rustflags` in `.cargo/config.toml`](https://doc.rust-lang.org/cargo/reference/config.html#configuration-keys)). Please note that only symbols from crates built with that flag will use the new mangling, and that tool support (e.g. debuggers) will be limited initially, and it may take a while for everything to be upstreamed. However, `RUST_BACKTRACE` should work out of the box with either mangling version.

<hr/>

The demangling implementation PR is https://github.com/alexcrichton/rustc-demangle/pull/23
~~(this PR already uses it via a git dependency, to allow testing)~~.

Discussion of the *design* of the mangling scheme should still happen on the RFC, but this PR's specific implementation details can be reviewed in parallel.

*Notes for reviewers*:
* ~~only the last 6 commits are specific to this branch, if necessary I can open a separate PR for everything else (it was meant to be its own small refactoring, but it got a bit out of hand)~~
~~based on #58140~~
* the "harness" commit is only there because it does some extra validation (comparing the demangling from `rustc-demangle` to the compiler's pretty-printing, adjusted slightly to produce the same output), that I would like to try on crater
* ~~there is the question of whether we should turn on the new mangling now, wait for tools to support it (I'm working on that), and/or have it under a `-Z` flag for now~~ (we're gating this on `-Z symbol-mangling-version=v0`, see above)

r? @nikomatsakis / @michaelwoerister cc @rust-lang/compiler
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/drop.rs21
-rw-r--r--src/test/codegen/external-no-mangle-fns.rs4
-rw-r--r--src/test/codegen/external-no-mangle-statics.rs4
-rw-r--r--src/test/codegen/internalize-closures.rs6
-rw-r--r--src/test/codegen/link-dead-code.rs12
-rw-r--r--src/test/codegen/local-generics-in-exe-internalized.rs4
-rw-r--r--src/test/codegen/target-cpu-on-functions.rs4
7 files changed, 38 insertions, 17 deletions
diff --git a/src/test/codegen/drop.rs b/src/test/codegen/drop.rs
index 7e6f8eaaa30..307c4e2c1e2 100644
--- a/src/test/codegen/drop.rs
+++ b/src/test/codegen/drop.rs
@@ -19,15 +19,18 @@ pub fn droppy() {
 // that's one new drop call per call to possibly_unwinding(), and finally 3 drop calls for the
 // regular function exit. We used to have problems with quadratic growths of drop calls in such
 // functions.
-// CHECK-NOT: invoke{{.*}}drop{{.*}}SomeUniqueName
-// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
-// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
-// CHECK-NOT: call{{.*}}drop{{.*}}SomeUniqueName
-// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
-// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
-// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
-// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
-// CHECK-NOT: {{(call|invoke).*}}drop{{.*}}SomeUniqueName
+// FIXME(eddyb) the `void @` forces a match on the instruction, instead of the
+// comment, that's `; call core::ptr::real_drop_in_place::<drop::SomeUniqueName>`
+// for the `v0` mangling, should switch to matching on that once `legacy` is gone.
+// CHECK-NOT: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK-NOT: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
+// CHECK-NOT: {{(call|invoke) void @.*}}drop_in_place{{.*}}SomeUniqueName
 // The next line checks for the } that ends the function definition
 // CHECK-LABEL: {{^[}]}}
     let _s = SomeUniqueName;
diff --git a/src/test/codegen/external-no-mangle-fns.rs b/src/test/codegen/external-no-mangle-fns.rs
index 79d5dc2400c..90288214499 100644
--- a/src/test/codegen/external-no-mangle-fns.rs
+++ b/src/test/codegen/external-no-mangle-fns.rs
@@ -33,7 +33,9 @@ const HIDDEN: () = {
 };
 
 // The surrounding item should not accidentally become external
-// CHECK: define internal{{.*}} void @_ZN22external_no_mangle_fns1x
+// CHECK-LABEL: ; external_no_mangle_fns::x
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define internal
 #[inline(never)]
 fn x() {
     // CHECK: define void @g()
diff --git a/src/test/codegen/external-no-mangle-statics.rs b/src/test/codegen/external-no-mangle-statics.rs
index 2998000180e..e44373926b7 100644
--- a/src/test/codegen/external-no-mangle-statics.rs
+++ b/src/test/codegen/external-no-mangle-statics.rs
@@ -75,4 +75,6 @@ fn x() {
     #[no_mangle]
     pub static mut P: u8 = 0;
 }
-// CHECK: define internal void @_ZN26external_no_mangle_statics1x{{.*$}}
+// CHECK-LABEL: ; external_no_mangle_statics::x
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define internal
diff --git a/src/test/codegen/internalize-closures.rs b/src/test/codegen/internalize-closures.rs
index 3434820aa8a..8d9192c6fa0 100644
--- a/src/test/codegen/internalize-closures.rs
+++ b/src/test/codegen/internalize-closures.rs
@@ -4,7 +4,11 @@ pub fn main() {
 
     // We want to make sure that closures get 'internal' linkage instead of
     // 'weak_odr' when they are not shared between codegen units
-    // CHECK: define internal {{.*}}_ZN20internalize_closures4main{{.*}}$u7b$$u7b$closure$u7d$$u7d$
+    // FIXME(eddyb) `legacy` mangling uses `{{closure}}`, while `v0`
+    // uses `{closure#0}`, switch to the latter once `legacy` is gone.
+    // CHECK-LABEL: ; internalize_closures::main::{{.*}}closure
+    // CHECK-NEXT: ; Function Attrs:
+    // CHECK-NEXT: define internal
     let c = |x:i32| { x + 1 };
     let _ = c(1);
 }
diff --git a/src/test/codegen/link-dead-code.rs b/src/test/codegen/link-dead-code.rs
index cb3dd07a2a7..de5a237c5f8 100644
--- a/src/test/codegen/link-dead-code.rs
+++ b/src/test/codegen/link-dead-code.rs
@@ -5,12 +5,18 @@
 // This test makes sure that, when -Clink-dead-code is specified, we generate
 // code for functions that would otherwise be skipped.
 
-// CHECK-LABEL: define hidden i32 @_ZN14link_dead_code8const_fn
+// CHECK-LABEL: ; link_dead_code::const_fn
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define hidden
 const fn const_fn() -> i32 { 1 }
 
-// CHECK-LABEL: define hidden i32 @_ZN14link_dead_code9inline_fn
+// CHECK-LABEL: ; link_dead_code::inline_fn
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define hidden
 #[inline]
 fn inline_fn() -> i32 { 2 }
 
-// CHECK-LABEL: define hidden i32 @_ZN14link_dead_code10private_fn
+// CHECK-LABEL: ; link_dead_code::private_fn
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define hidden
 fn private_fn() -> i32 { 3 }
diff --git a/src/test/codegen/local-generics-in-exe-internalized.rs b/src/test/codegen/local-generics-in-exe-internalized.rs
index 6bdbf929193..e5430fbf17a 100644
--- a/src/test/codegen/local-generics-in-exe-internalized.rs
+++ b/src/test/codegen/local-generics-in-exe-internalized.rs
@@ -2,7 +2,9 @@
 
 // Check that local generics are internalized if they are in the same CGU
 
-// CHECK: define internal {{.*}} @_ZN34local_generics_in_exe_internalized3foo{{.*}}
+// CHECK-LABEL: ; local_generics_in_exe_internalized::foo
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define internal
 pub fn foo<T>(x: T, y: T) -> (T, T) {
     (x, y)
 }
diff --git a/src/test/codegen/target-cpu-on-functions.rs b/src/test/codegen/target-cpu-on-functions.rs
index 3fdf6ab6d00..523216deb84 100644
--- a/src/test/codegen/target-cpu-on-functions.rs
+++ b/src/test/codegen/target-cpu-on-functions.rs
@@ -13,7 +13,9 @@ pub extern fn exported() {
     not_exported();
 }
 
-// CHECK-LABEL: define {{.*}} @_ZN23target_cpu_on_functions12not_exported{{.*}}() {{.*}} #0
+// CHECK-LABEL: ; target_cpu_on_functions::not_exported
+// CHECK-NEXT: ; Function Attrs:
+// CHECK-NEXT: define {{.*}}() {{.*}} #0
 fn not_exported() {}
 
 // CHECK: attributes #0 = {{.*}} "target-cpu"="{{.*}}"