This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Mangle names #7
Comments
Name Mangling SchemeThe hash values below are made up, but should eventually come from some decent algorithm for short hashes.
The extra string included in the hash is because different namespaces can contain the same names. That is, you can technically have a type and a function named Short Hashesuse std::io::Read;
use adler32::adler32;
fn mangle_function_name(mod_mangled_name: &str, name: &str) -> String {
let prefix = "fn".as_bytes();
// https://doc.rust-lang.org/nightly/std/io/trait.Read.html#method.chain
let mangle_input = prefix.chain(name.as_bytes());
// unwrap() is safe because Read for &[u8] can never result in an error.
let hash = adler32(mangle_input).unwrap();
format!("{}__{}_{:x}", mod_mangled_name, name, hash)
} Update: Apparently adler32 isn't great for short strings. Might just want to truncate md5 to 32-bits. This may have issues too. |
Even simpler scheme that just uses the length and not a hash: https://rust-lang.github.io/rfcs/2603-symbol-name-mangling-v2.html#the-mangling-scheme-by-example |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Function names (except for main) and even variable names should all be managed to prevent accidental name clashes. E.g. If we don't do this someone could define a function
__disco__DInt__operator_add
(or whatever) and mess everything up.https://internals.rust-lang.org/t/pre-rfc-a-new-symbol-mangling-scheme/8501
The text was updated successfully, but these errors were encountered: