Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip hashes from Rust mangled symbols? #377

Open
fitzgen opened this issue Nov 11, 2019 · 3 comments
Open

Strip hashes from Rust mangled symbols? #377

fitzgen opened this issue Nov 11, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@fitzgen
Copy link
Member

fitzgen commented Nov 11, 2019

🐛 Bug Description

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

  • old format, demangled: wee_alloc::alloc_first_fit::h6af2b7fe0cb0a62f
  • new format, demangled: core[369c8b9e1df8da3a]::slice::sort::recurse::<Foo, <[Foo]>::sort_unstable::{closure#0}>

(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:

  • rustc --target wasm32-unknown-unknown --crate-type cdylib -C opt-level=3 -C lto=fat test_case.rs -o test_case_old_symbols.wasm
  • rustc -Zsymbol-mangling-version=v0 --target wasm32-unknown-unknown --crate-type cdylib -C opt-level=3 -C lto=fat test_case.rs -o test_case_new_symbols.wasm
  • twiggy top test_case_old_symbols.wasm
  • twiggy top test_case_new_symbols.wasm

😲 Actual Behavior

Function names have hashes

🤔 Expected Behavior

New symbols have hashes removed

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

@bjorn3
Copy link

bjorn3 commented Nov 11, 2019

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

@fitzgen
Copy link
Member Author

fitzgen commented Nov 11, 2019

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
Copy link

bjorn3 commented Nov 11, 2019

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

@AlexEne AlexEne added the enhancement New feature or request label Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants