diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-06-29 06:59:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-29 06:59:28 +0200 |
| commit | e68f13c9d434c96fbe9cda6ed8f8eba8dabd3519 (patch) | |
| tree | 5bc158fcdd8571aee5408fe15a58d11ea3bc1d18 | |
| parent | e5bd07ac2e1fc2a9c97f87403432c27a702fc556 (diff) | |
| parent | 2bb98e2c48ed454635c9d64bcce186c68be383b7 (diff) | |
| download | rust-e68f13c9d434c96fbe9cda6ed8f8eba8dabd3519.tar.gz rust-e68f13c9d434c96fbe9cda6ed8f8eba8dabd3519.zip | |
Rollup merge of #142641 - bjorn3:proc_macro_symbols_o, r=jieyouxu
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.rs | 9 | ||||
| -rw-r--r-- | tests/run-make/used-proc-macro/dep.rs | 4 | ||||
| -rw-r--r-- | tests/run-make/used-proc-macro/proc_macro.rs | 3 | ||||
| -rw-r--r-- | tests/run-make/used-proc-macro/rmake.rs | 18 |
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 fba84dec097..ede11495503 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -1870,8 +1870,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"); +} |
