From 47ea57feadb6d05241fad064434c28c48e31b7fc Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 5 Dec 2011 14:56:11 +0800 Subject: [PATCH] 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 --- src/comp/middle/trans.rs | 13 ++++++++++++- src/test/run-pass/issue-1251.rs | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/issue-1251.rs diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 7d52316d9a8a..3ea355d2cb9d 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -6059,7 +6059,18 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, -> ModuleRef { let sha = std::sha1::mk_sha1(); let link_meta = link::build_link_meta(sess, *crate, output, sha); - let llmod = str::as_buf(link_meta.name, {|buf| + + // Append ".rc" to crate name as LLVM module identifier. + // + // LLVM code generator emits a ".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. + // 1. http://llvm.org/bugs/show_bug.cgi?id=11479 + let llmod_id = link_meta.name + ".rc"; + + let llmod = str::as_buf(llmod_id, {|buf| llvm::LLVMModuleCreateWithNameInContext (buf, llvm::LLVMGetGlobalContext()) }); diff --git a/src/test/run-pass/issue-1251.rs b/src/test/run-pass/issue-1251.rs new file mode 100644 index 000000000000..69e54f4a95d7 --- /dev/null +++ b/src/test/run-pass/issue-1251.rs @@ -0,0 +1,7 @@ +#[link(name = "unsupervise")]; + +native mod rustrt { + fn unsupervise(); +} + +fn main() { }