]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Add suffix ".rc" to LLVM module identifier
authorHaitao Li <lihaitao@gmail.com>
Mon, 5 Dec 2011 06:56:11 +0000 (14:56 +0800)
committerHaitao Li <lihaitao@gmail.com>
Mon, 5 Dec 2011 09:21:20 +0000 (17:21 +0800)
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
src/test/run-pass/issue-1251.rs [new file with mode: 0644]

index 7d52316d9a8a8c16d0404657d67af472e362e871..3ea355d2cb9dae0157ba0d6fac7e15ee7b6822b3 100644 (file)
@@ -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 (file)
index 0000000..69e54f4
--- /dev/null
@@ -0,0 +1,7 @@
+#[link(name = "unsupervise")];
+
+native mod rustrt {
+      fn unsupervise();
+}
+
+fn main() { }