about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorColin Pronovost <colin.pron@live.com>2018-05-23 15:19:07 -0400
committerColin Pronovost <colin.pron@live.com>2018-07-31 23:45:18 -0400
commit02190f397ecb32bca42e5b631dc235381d01b377 (patch)
treed160894619868dd7116a5bfdff9fef44e2c8a042 /src/librustc_codegen_llvm
parente94df4acb4c3f42fdc224a7164b63a99240add1e (diff)
downloadrust-02190f397ecb32bca42e5b631dc235381d01b377.tar.gz
rust-02190f397ecb32bca42e5b631dc235381d01b377.zip
Make globals with private linkage unnamed. Fixes #50862.
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/consts.rs20
-rw-r--r--src/librustc_codegen_llvm/declare.rs10
-rw-r--r--src/librustc_codegen_llvm/llvm/ffi.rs1
-rw-r--r--src/librustc_codegen_llvm/meth.rs2
-rw-r--r--src/librustc_codegen_llvm/mir/block.rs4
-rw-r--r--src/librustc_codegen_llvm/mir/constant.rs4
-rw-r--r--src/librustc_codegen_llvm/mir/place.rs2
7 files changed, 29 insertions, 14 deletions
diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs
index 72ff65361ca..21bf490beb0 100644
--- a/src/librustc_codegen_llvm/consts.rs
+++ b/src/librustc_codegen_llvm/consts.rs
@@ -66,16 +66,22 @@ pub fn addr_of_mut(
     cx: &CodegenCx<'ll, '_>,
     cv: &'ll Value,
     align: Align,
-    kind: &str,
+    kind: Option<&str>,
 ) -> &'ll Value {
     unsafe {
-        let name = cx.generate_local_symbol_name(kind);
-        let gv = declare::define_global(cx, &name[..], val_ty(cv)).unwrap_or_else(||{
-            bug!("symbol `{}` is already defined", name);
-        });
+        let gv = match kind {
+            Some(kind) if !cx.tcx.sess.fewer_names() => {
+                let name = cx.generate_local_symbol_name(kind);
+                let gv = declare::define_global(cx, &name[..], val_ty(cv)).unwrap_or_else(||{
+                    bug!("symbol `{}` is already defined", name);
+                });
+                llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage);
+                gv
+            },
+            _ => declare::define_private_global(cx, val_ty(cv)),
+        };
         llvm::LLVMSetInitializer(gv, cv);
         set_global_alignment(cx, gv, align);
-        llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage);
         SetUnnamedAddr(gv, true);
         gv
     }
@@ -85,7 +91,7 @@ pub fn addr_of(
     cx: &CodegenCx<'ll, '_>,
     cv: &'ll Value,
     align: Align,
-    kind: &str,
+    kind: Option<&str>,
 ) -> &'ll Value {
     if let Some(&gv) = cx.const_globals.borrow().get(&cv) {
         unsafe {
diff --git a/src/librustc_codegen_llvm/declare.rs b/src/librustc_codegen_llvm/declare.rs
index 9812d7f9a41..a0310eecd59 100644
--- a/src/librustc_codegen_llvm/declare.rs
+++ b/src/librustc_codegen_llvm/declare.rs
@@ -35,7 +35,6 @@ use value::Value;
 
 use std::ffi::CString;
 
-
 /// Declare a global value.
 ///
 /// If there’s a value with the same name already declared, the function will
@@ -170,6 +169,15 @@ pub fn define_global(cx: &CodegenCx<'ll, '_>, name: &str, ty: &'ll Type) -> Opti
     }
 }
 
+/// Declare a private global
+///
+/// Use this function when you intend to define a global without a name.
+pub fn define_private_global(cx: &CodegenCx<'ll, '_>, ty: &'ll Type) -> &'ll Value {
+    unsafe {
+        llvm::LLVMRustInsertPrivateGlobal(cx.llmod, ty)
+    }
+}
+
 /// Declare a Rust function with an intention to define it.
 ///
 /// Use this function when you intend to define a function. This function will
diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs
index 898d3d67353..71304453134 100644
--- a/src/librustc_codegen_llvm/llvm/ffi.rs
+++ b/src/librustc_codegen_llvm/llvm/ffi.rs
@@ -622,6 +622,7 @@ extern "C" {
     pub fn LLVMAddGlobal(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
     pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
     pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, T: &'a Type) -> &'a Value;
+    pub fn LLVMRustInsertPrivateGlobal(M: &'a Module, T: &'a Type) -> &'a Value;
     pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
     pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
     pub fn LLVMDeleteGlobal(GlobalVar: &Value);
diff --git a/src/librustc_codegen_llvm/meth.rs b/src/librustc_codegen_llvm/meth.rs
index 9c0dd0dc3d8..8a1159bc477 100644
--- a/src/librustc_codegen_llvm/meth.rs
+++ b/src/librustc_codegen_llvm/meth.rs
@@ -106,7 +106,7 @@ pub fn get_vtable(
 
     let vtable_const = C_struct(cx, &components, false);
     let align = cx.data_layout().pointer_align;
-    let vtable = consts::addr_of(cx, vtable_const, align, "vtable");
+    let vtable = consts::addr_of(cx, vtable_const, align, Some("vtable"));
 
     debuginfo::create_vtable_metadata(cx, ty, vtable);
 
diff --git a/src/librustc_codegen_llvm/mir/block.rs b/src/librustc_codegen_llvm/mir/block.rs
index 684ecfaeec8..4e389c3b915 100644
--- a/src/librustc_codegen_llvm/mir/block.rs
+++ b/src/librustc_codegen_llvm/mir/block.rs
@@ -377,7 +377,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
                         let file_line_col = consts::addr_of(bx.cx,
                                                             file_line_col,
                                                             align,
-                                                            "panic_bounds_check_loc");
+                                                            Some("panic_bounds_check_loc"));
                         (lang_items::PanicBoundsCheckFnLangItem,
                          vec![file_line_col, index, len])
                     }
@@ -391,7 +391,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
                         let msg_file_line_col = consts::addr_of(bx.cx,
                                                                 msg_file_line_col,
                                                                 align,
-                                                                "panic_loc");
+                                                                Some("panic_loc"));
                         (lang_items::PanicFnLangItem,
                          vec![msg_file_line_col])
                     }
diff --git a/src/librustc_codegen_llvm/mir/constant.rs b/src/librustc_codegen_llvm/mir/constant.rs
index 341ed9df64b..e414af07c9c 100644
--- a/src/librustc_codegen_llvm/mir/constant.rs
+++ b/src/librustc_codegen_llvm/mir/constant.rs
@@ -56,9 +56,9 @@ pub fn scalar_to_llvm(
                 Some(AllocType::Memory(alloc)) => {
                     let init = const_alloc_to_llvm(cx, alloc);
                     if alloc.runtime_mutability == Mutability::Mutable {
-                        consts::addr_of_mut(cx, init, alloc.align, "byte_str")
+                        consts::addr_of_mut(cx, init, alloc.align, None)
                     } else {
-                        consts::addr_of(cx, init, alloc.align, "byte_str")
+                        consts::addr_of(cx, init, alloc.align, None)
                     }
                 }
                 Some(AllocType::Function(fn_instance)) => {
diff --git a/src/librustc_codegen_llvm/mir/place.rs b/src/librustc_codegen_llvm/mir/place.rs
index abc3dbdab2f..6fa0845dd0c 100644
--- a/src/librustc_codegen_llvm/mir/place.rs
+++ b/src/librustc_codegen_llvm/mir/place.rs
@@ -63,7 +63,7 @@ impl PlaceRef<'ll, 'tcx> {
         offset: Size,
     ) -> PlaceRef<'ll, 'tcx> {
         let init = const_alloc_to_llvm(bx.cx, alloc);
-        let base_addr = consts::addr_of(bx.cx, init, layout.align, "byte_str");
+        let base_addr = consts::addr_of(bx.cx, init, layout.align, None);
 
         let llval = unsafe { LLVMConstInBoundsGEP(
             consts::bitcast(base_addr, Type::i8p(bx.cx)),