Skip to content

Commit e68f13c

Browse files
authored
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.
2 parents e5bd07a + 2bb98e2 commit e68f13c

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-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
@@ -1870,8 +1870,13 @@ pub(crate) fn linked_symbols(
18701870
crate_type: CrateType,
18711871
) -> Vec<(String, SymbolExportKind)> {
18721872
match crate_type {
1873-
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib | CrateType::Sdylib => (),
1874-
CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
1873+
CrateType::Executable
1874+
| CrateType::ProcMacro
1875+
| CrateType::Cdylib
1876+
| CrateType::Dylib
1877+
| CrateType::Sdylib => (),
1878+
CrateType::Staticlib | CrateType::Rlib => {
1879+
// These are not linked, so no need to generate symbols.o for them.
18751880
return Vec::new();
18761881
}
18771882
}

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that #[used] statics are included in the final dylib for proc-macros too.
2+
3+
//@ ignore-cross-compile
4+
//@ ignore-windows llvm-readobj --all doesn't show local symbols on Windows
5+
//@ needs-crate-type: proc-macro
6+
//@ ignore-musl (FIXME: can't find `-lunwind`)
7+
8+
use run_make_support::{dynamic_lib_name, llvm_readobj, rustc};
9+
10+
fn main() {
11+
rustc().input("dep.rs").run();
12+
rustc().input("proc_macro.rs").run();
13+
llvm_readobj()
14+
.input(dynamic_lib_name("proc_macro"))
15+
.arg("--all")
16+
.run()
17+
.assert_stdout_contains("VERY_IMPORTANT_SYMBOL");
18+
}

0 commit comments

Comments
 (0)