Generate symbols.o for proc-macros too

To ensure used statics are functioning correctly for proc-macros too.
This commit is contained in:
bjorn3
2025-06-17 20:31:16 +00:00
parent ae2fc9722f
commit 2bb98e2c48
4 changed files with 32 additions and 2 deletions

View File

@@ -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();
}
}

View File

@@ -0,0 +1,4 @@
#![crate_type = "lib"]
#[used]
static VERY_IMPORTANT_SYMBOL: u32 = 12345;

View File

@@ -0,0 +1,3 @@
#![crate_type = "proc-macro"]
extern crate dep as _;

View File

@@ -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");
}