about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-06-17 20:31:16 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-06-27 10:03:29 +0000
commit2bb98e2c48ed454635c9d64bcce186c68be383b7 (patch)
tree2d99c374e14bdd5ba9ba694953aec4d4c8bb6f23
parentae2fc9722f08ef131407c1dc8057768868f65e8e (diff)
downloadrust-2bb98e2c48ed454635c9d64bcce186c68be383b7.tar.gz
rust-2bb98e2c48ed454635c9d64bcce186c68be383b7.zip
Generate symbols.o for proc-macros too
To ensure used statics are functioning correctly for proc-macros too.
-rw-r--r--compiler/rustc_codegen_ssa/src/back/linker.rs9
-rw-r--r--tests/run-make/used-proc-macro/dep.rs4
-rw-r--r--tests/run-make/used-proc-macro/proc_macro.rs3
-rw-r--r--tests/run-make/used-proc-macro/rmake.rs18
4 files changed, 32 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs
index 8fc83908efb..025e7b7ff88 100644
--- a/compiler/rustc_codegen_ssa/src/back/linker.rs
+++ b/compiler/rustc_codegen_ssa/src/back/linker.rs
@@ -1817,8 +1817,13 @@ pub(crate) fn linked_symbols(
     crate_type: CrateType,
 ) -> Vec<(String, SymbolExportKind)> {
     match crate_type {
-        CrateType::Executable | CrateType::Cdylib | CrateType::Dylib | CrateType::Sdylib => (),
-        CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
+        CrateType::Executable
+        | CrateType::ProcMacro
+        | CrateType::Cdylib
+        | CrateType::Dylib
+        | CrateType::Sdylib => (),
+        CrateType::Staticlib | CrateType::Rlib => {
+            // These are not linked, so no need to generate symbols.o for them.
             return Vec::new();
         }
     }
diff --git a/tests/run-make/used-proc-macro/dep.rs b/tests/run-make/used-proc-macro/dep.rs
new file mode 100644
index 00000000000..9f881d926d6
--- /dev/null
+++ b/tests/run-make/used-proc-macro/dep.rs
@@ -0,0 +1,4 @@
+#![crate_type = "lib"]
+
+#[used]
+static VERY_IMPORTANT_SYMBOL: u32 = 12345;
diff --git a/tests/run-make/used-proc-macro/proc_macro.rs b/tests/run-make/used-proc-macro/proc_macro.rs
new file mode 100644
index 00000000000..af592ea0c7e
--- /dev/null
+++ b/tests/run-make/used-proc-macro/proc_macro.rs
@@ -0,0 +1,3 @@
+#![crate_type = "proc-macro"]
+
+extern crate dep as _;
diff --git a/tests/run-make/used-proc-macro/rmake.rs b/tests/run-make/used-proc-macro/rmake.rs
new file mode 100644
index 00000000000..58b2760e64d
--- /dev/null
+++ b/tests/run-make/used-proc-macro/rmake.rs
@@ -0,0 +1,18 @@
+// Test that #[used] statics are included in the final dylib for proc-macros too.
+
+//@ ignore-cross-compile
+//@ ignore-windows llvm-readobj --all doesn't show local symbols on Windows
+//@ needs-crate-type: proc-macro
+//@ ignore-musl (FIXME: can't find `-lunwind`)
+
+use run_make_support::{dynamic_lib_name, llvm_readobj, rustc};
+
+fn main() {
+    rustc().input("dep.rs").run();
+    rustc().input("proc_macro.rs").run();
+    llvm_readobj()
+        .input(dynamic_lib_name("proc_macro"))
+        .arg("--all")
+        .run()
+        .assert_stdout_contains("VERY_IMPORTANT_SYMBOL");
+}