Skip to content

Commit 3d5a656

Browse files
committed
Generate symbols.o for proc-macros too
To ensure used statics are functioning correctly for proc-macros too.
1 parent 55d4364 commit 3d5a656

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,8 +1817,13 @@ pub(crate) fn linked_symbols(
18171817
crate_type: CrateType,
18181818
) -> Vec<(String, SymbolExportKind)> {
18191819
match crate_type {
1820-
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib | CrateType::Sdylib => (),
1821-
CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
1820+
CrateType::Executable
1821+
| CrateType::ProcMacro
1822+
| CrateType::Cdylib
1823+
| CrateType::Dylib
1824+
| CrateType::Sdylib => (),
1825+
CrateType::Staticlib | CrateType::Rlib => {
1826+
// These are not linked, so no need to generate symbols.o for them.
18221827
return Vec::new();
18231828
}
18241829
}

tests/run-make/used-proc-macro/dep.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![crate_type = "lib"]
2+
3+
#[used]
4+
static VERY_IMPORTANT_SYMBOL: u32 = 12345;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![crate_type = "proc-macro"]
2+
3+
extern crate dep as _;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test that #[used] statics are included in the final dylib for proc-macros too.
2+
3+
use run_make_support::{dynamic_lib_name, llvm_readobj, rustc};
4+
5+
fn main() {
6+
rustc().input("dep.rs").run();
7+
rustc().input("proc_macro.rs").run();
8+
llvm_readobj()
9+
.input(dynamic_lib_name("proc_macro"))
10+
.arg("--all")
11+
.run()
12+
.assert_stdout_contains("VERY_IMPORTANT_SYMBOL");
13+
}

0 commit comments

Comments
 (0)