about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
diff options
context:
space:
mode:
authorcynecx <me@cynecx.net>2021-11-22 13:14:54 +0100
committercynecx <me@cynecx.net>2022-02-06 20:23:23 +0100
commit03733ca65a09a9b54b2c2a674e4145b165bd1cab (patch)
tree0a8b39ca2a3a516049004c9023ad73ac8d7c50c7 /compiler/rustc_codegen_llvm
parentf624427f8771c00819684c783bb841bf72095704 (diff)
downloadrust-03733ca65a09a9b54b2c2a674e4145b165bd1cab.tar.gz
rust-03733ca65a09a9b54b2c2a674e4145b165bd1cab.zip
`#[used(linker)]` attribute (https://github.com/dtolnay/linkme/issues/41)
Diffstat (limited to 'compiler/rustc_codegen_llvm')
-rw-r--r--compiler/rustc_codegen_llvm/src/consts.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs
index d43c7c60651..6707de93352 100644
--- a/compiler/rustc_codegen_llvm/src/consts.rs
+++ b/compiler/rustc_codegen_llvm/src/consts.rs
@@ -522,6 +522,9 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
             }
 
             if attrs.flags.contains(CodegenFnAttrFlags::USED) {
+                // `USED` and `USED_LINKER` can't be used together.
+                assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER));
+
                 // The semantics of #[used] in Rust only require the symbol to make it into the
                 // object file. It is explicitly allowed for the linker to strip the symbol if it
                 // is dead. As such, use llvm.compiler.used instead of llvm.used.
@@ -530,6 +533,12 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
                 // in some versions of the gold linker.
                 self.add_compiler_used_global(g);
             }
+            if attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) {
+                // `USED` and `USED_LINKER` can't be used together.
+                assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED));
+
+                self.add_used_global(g);
+            }
         }
     }