Skip to content

Commit 47ea57f

Browse files
committed
rustc: Add suffix ".rc" to LLVM module identifier
LLVM code generator emits the ".file filename" directive for ELF backends. Value of the "filename" is set as the LLVM module identifier. Due to a LLVM MC bug[1], LLVM crashes if the module identifer is same as other symbols such as a function name in the module. This patch adds a ".rc" suffix (means crates) to LLVM module identifier to workaround the bug. Fixes issue #1251. 1. http://llvm.org/bugs/show_bug.cgi?id=11479
1 parent 52d7dc5 commit 47ea57f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6059,7 +6059,18 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
60596059
-> ModuleRef {
60606060
let sha = std::sha1::mk_sha1();
60616061
let link_meta = link::build_link_meta(sess, *crate, output, sha);
6062-
let llmod = str::as_buf(link_meta.name, {|buf|
6062+
6063+
// Append ".rc" to crate name as LLVM module identifier.
6064+
//
6065+
// LLVM code generator emits a ".file filename" directive
6066+
// for ELF backends. Value of the "filename" is set as the
6067+
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
6068+
// crashes if the module identifer is same as other symbols
6069+
// such as a function name in the module.
6070+
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
6071+
let llmod_id = link_meta.name + ".rc";
6072+
6073+
let llmod = str::as_buf(llmod_id, {|buf|
60636074
llvm::LLVMModuleCreateWithNameInContext
60646075
(buf, llvm::LLVMGetGlobalContext())
60656076
});

src/test/run-pass/issue-1251.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[link(name = "unsupervise")];
2+
3+
native mod rustrt {
4+
fn unsupervise();
5+
}
6+
7+
fn main() { }

0 commit comments

Comments
 (0)