Skip to content

rustc::back::link: redo symbol mangling #6956

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,26 +633,37 @@ pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {

// Name sanitation. LLVM will happily accept identifiers with weird names, but
// gas doesn't!
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
pub fn sanitize(s: &str) -> ~str {
let mut result = ~"";
for str::each_char(s) |c| {
match c {
'@' => result += "_sbox_",
'~' => result += "_ubox_",
'*' => result += "_ptr_",
'&' => result += "_ref_",
',' => result += "_",

'{' | '(' => result += "_of_",
'a' .. 'z'
| 'A' .. 'Z'
| '0' .. '9'
| '_' => result.push_char(c),
_ => {
if c > 'z' && char::is_XID_continue(c) {
result.push_char(c);
// Escape these with $ sequences
'@' => result += "$SP$",
'~' => result += "$UP$",
'*' => result += "$RP$",
'&' => result += "$BP$",
'<' => result += "$LT$",
'>' => result += "$GT$",
'(' => result += "$LP$",
')' => result += "$RP$",
',' => result += "$C$",

// '.' doesn't occur in types and functions, so reuse it
// for ':'
':' => result.push_char('.'),

// These are legal symbols
'a' .. 'z'
| 'A' .. 'Z'
| '0' .. '9'
| '_' => result.push_char(c),

_ => {
if c > 'z' && char::is_XID_continue(c) {
result.push_char(c);
}
}
}
}
}

Expand Down