Skip to content

Commit 2c65e2e

Browse files
committed
auto merge of #6956 : Blei/rust/fix-symbol-mangling, r=catamorphism
Handle more characters that appear in types, most notably <>): were missing. Also the new scheme takes care that no two different input strings result in the same mangled string, which was not the case before. Fixes #6921
2 parents 0409f86 + eb62781 commit 2c65e2e

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/librustc/back/link.rs

+26-15
Original file line numberDiff line numberDiff line change
@@ -633,26 +633,37 @@ pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
633633

634634
// Name sanitation. LLVM will happily accept identifiers with weird names, but
635635
// gas doesn't!
636+
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
636637
pub fn sanitize(s: &str) -> ~str {
637638
let mut result = ~"";
638639
for str::each_char(s) |c| {
639640
match c {
640-
'@' => result += "_sbox_",
641-
'~' => result += "_ubox_",
642-
'*' => result += "_ptr_",
643-
'&' => result += "_ref_",
644-
',' => result += "_",
645-
646-
'{' | '(' => result += "_of_",
647-
'a' .. 'z'
648-
| 'A' .. 'Z'
649-
| '0' .. '9'
650-
| '_' => result.push_char(c),
651-
_ => {
652-
if c > 'z' && char::is_XID_continue(c) {
653-
result.push_char(c);
641+
// Escape these with $ sequences
642+
'@' => result += "$SP$",
643+
'~' => result += "$UP$",
644+
'*' => result += "$RP$",
645+
'&' => result += "$BP$",
646+
'<' => result += "$LT$",
647+
'>' => result += "$GT$",
648+
'(' => result += "$LP$",
649+
')' => result += "$RP$",
650+
',' => result += "$C$",
651+
652+
// '.' doesn't occur in types and functions, so reuse it
653+
// for ':'
654+
':' => result.push_char('.'),
655+
656+
// These are legal symbols
657+
'a' .. 'z'
658+
| 'A' .. 'Z'
659+
| '0' .. '9'
660+
| '_' => result.push_char(c),
661+
662+
_ => {
663+
if c > 'z' && char::is_XID_continue(c) {
664+
result.push_char(c);
665+
}
654666
}
655-
}
656667
}
657668
}
658669

0 commit comments

Comments
 (0)