Skip to content

Commit 9c34473

Browse files
committed
Special-case .llvm in mangler to fix segfaults
This commit special cases `.llvm` in the mangler to print `.llvm$6d$` instead. This will avoid segfaults when names in a user's Rust code are `llvm`.
1 parent 02f5786 commit 9c34473

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

src/librustc_codegen_utils/symbol_names.rs

+3
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,9 @@ impl fmt::Write for SymbolPrinter<'_, '_> {
613613
// for ':' and '-'
614614
'-' | ':' => self.path.temp_buf.push('.'),
615615

616+
// Avoid segmentation fault on some platforms, see #60925.
617+
'm' if self.path.temp_buf.ends_with(".llv") => self.path.temp_buf.push_str("$6d$"),
618+
616619
// These are legal symbols
617620
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => self.path.temp_buf.push(c),
618621

src/test/ui/issue-53912.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// compile-pass
2+
3+
// This test is the same code as in ui/symbol-names/issue-60925.rs but this checks that the
4+
// reproduction compiles successfully and doesn't segfault, whereas that test just checks that the
5+
// symbol mangling fix produces the correct result.
6+
7+
fn dummy() {}
8+
9+
mod llvm {
10+
pub(crate) struct Foo;
11+
}
12+
mod foo {
13+
pub(crate) struct Foo<T>(T);
14+
15+
impl Foo<::llvm::Foo> {
16+
pub(crate) fn foo() {
17+
for _ in 0..0 {
18+
for _ in &[::dummy()] {
19+
::dummy();
20+
::dummy();
21+
::dummy();
22+
}
23+
}
24+
}
25+
}
26+
27+
pub(crate) fn foo() {
28+
Foo::foo();
29+
Foo::foo();
30+
}
31+
}
32+
33+
pub fn foo() {
34+
foo::foo();
35+
}
36+
37+
fn main() {}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#![feature(rustc_attrs)]
2+
3+
// This test is the same code as in ui/issue-53912.rs but this test checks that the symbol mangling
4+
// fix produces the correct result, whereas that test just checks that the reproduction compiles
5+
// successfully and doesn't segfault
6+
7+
fn dummy() {}
8+
9+
mod llvm {
10+
pub(crate) struct Foo;
11+
}
12+
mod foo {
13+
pub(crate) struct Foo<T>(T);
14+
15+
impl Foo<::llvm::Foo> {
16+
#[rustc_symbol_name]
17+
//~^ ERROR _ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo17h059a991a004536adE
18+
pub(crate) fn foo() {
19+
for _ in 0..0 {
20+
for _ in &[::dummy()] {
21+
::dummy();
22+
::dummy();
23+
::dummy();
24+
}
25+
}
26+
}
27+
}
28+
29+
pub(crate) fn foo() {
30+
Foo::foo();
31+
Foo::foo();
32+
}
33+
}
34+
35+
pub fn foo() {
36+
foo::foo();
37+
}
38+
39+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: symbol-name(_ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo17h059a991a004536adE)
2+
--> $DIR/issue-60925.rs:16:9
3+
|
4+
LL | #[rustc_symbol_name]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)