rustwasm / twiggy

Twiggy🌱 is a code size profiler
https://rustwasm.github.io/twiggy
Apache License 2.0
1.28k stars 69 forks source link

Strip hashes from Rust mangled symbols? #377

Open fitzgen opened 4 years ago

fitzgen commented 4 years ago

🐛 Bug Description

Rust symbols have hashes in them. Both the old symbol mangling format and the new one.

(Note, you can enable the new symbol format with RUSTFLAGS=-Zsymbol-mangling-version=v0 when building with cargo)

In the old format, the hash is the only thing differentiating between different monomorphizations of the same generic function. Therefore, it might make sense to keep the hash for the old symbol format.

The new format has the type parameters mangled into the symbol's name (eg Foo in the symbol above). In this case, it should be fine to strip the hash all the time (but perhaps with an option to disable the stripping?)

twiggy version: master

🌍 Test Case

fn my_generic<T: Default>() -> T { T::default() }

#[no_mangle]
pub extern fn foo() -> *mut u8 {
    my_generic::<usize> as fn() -> usize as *mut _
}

#[no_mangle]
pub extern fn bar() -> *mut u8 {
    my_generic::<i8> as fn() -> i8 as *mut _
}

👟 Steps to Reproduce

Precise steps describing how to reproduce the issue, including commands and flags run. For example:

😲 Actual Behavior

Function names have hashes

🤔 Expected Behavior

New symbols have hashes removed

(TBD exactly what to do with old symbols' hashes)

bjorn3 commented 4 years ago

I think the hash should remain when there are two versions of the same crate.

fitzgen commented 4 years ago

Good point, it should probably only be stripped if it is a unique monomorphization. Even within the same crate, we can have multiple duplicate monomorphizations in different codegen units, IIUC.

bjorn3 commented 4 years ago

I believe duplicate monomorphizations have the same symbol, they are just private to their own codegen unit.