Skip to content

Commit 9ed0d11

Browse files
committed
Avoid adding compiler-used functions to symbols.o
1 parent 7ceaf19 commit 9ed0d11

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn prepare_lto(
6060
};
6161

6262
let symbol_filter = &|&(ref name, info): &(String, SymbolExportInfo)| {
63-
if info.level.is_below_threshold(export_threshold) || info.used {
63+
if info.level.is_below_threshold(export_threshold) || info.used || info.used_compiler {
6464
Some(CString::new(name.as_str()).unwrap())
6565
} else {
6666
None

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
111111
let is_builtin_fn = is_compiler_builtins
112112
&& symbol_export_level(tcx, def_id.to_def_id())
113113
.is_below_threshold(SymbolExportLevel::C);
114-
let used = is_builtin_fn || name == "rust_eh_personality";
114+
let used = name == "rust_eh_personality";
115115

116116
let export_level = if special_runtime_crate {
117117
SymbolExportLevel::Rust
@@ -138,6 +138,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
138138
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
139139
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
140140
|| used,
141+
used_compiler: is_builtin_fn,
141142
};
142143
(def_id.to_def_id(), info)
143144
})
@@ -150,6 +151,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
150151
level: SymbolExportLevel::C,
151152
kind: SymbolExportKind::Data,
152153
used: false,
154+
used_compiler: false,
153155
},
154156
);
155157
}
@@ -198,6 +200,7 @@ fn exported_symbols_provider_local(
198200
level: info.level,
199201
kind: SymbolExportKind::Text,
200202
used: info.used,
203+
used_compiler: false,
201204
},
202205
)
203206
})
@@ -214,6 +217,7 @@ fn exported_symbols_provider_local(
214217
level: SymbolExportLevel::C,
215218
kind: SymbolExportKind::Text,
216219
used: false,
220+
used_compiler: false,
217221
},
218222
));
219223
}
@@ -233,6 +237,7 @@ fn exported_symbols_provider_local(
233237
level: SymbolExportLevel::Rust,
234238
kind: SymbolExportKind::Text,
235239
used: false,
240+
used_compiler: false,
236241
},
237242
));
238243
}
@@ -245,6 +250,7 @@ fn exported_symbols_provider_local(
245250
level: SymbolExportLevel::Rust,
246251
kind: SymbolExportKind::Data,
247252
used: false,
253+
used_compiler: false,
248254
},
249255
))
250256
}
@@ -264,6 +270,7 @@ fn exported_symbols_provider_local(
264270
level: SymbolExportLevel::C,
265271
kind: SymbolExportKind::Data,
266272
used: false,
273+
used_compiler: false,
267274
},
268275
)
269276
}));
@@ -289,6 +296,7 @@ fn exported_symbols_provider_local(
289296
level: SymbolExportLevel::C,
290297
kind: SymbolExportKind::Data,
291298
used: false,
299+
used_compiler: false,
292300
},
293301
)
294302
}));
@@ -306,6 +314,7 @@ fn exported_symbols_provider_local(
306314
level: SymbolExportLevel::C,
307315
kind: SymbolExportKind::Data,
308316
used: true,
317+
used_compiler: false,
309318
},
310319
));
311320
}
@@ -346,6 +355,7 @@ fn exported_symbols_provider_local(
346355
level: SymbolExportLevel::Rust,
347356
kind: SymbolExportKind::Text,
348357
used: false,
358+
used_compiler: false,
349359
},
350360
));
351361
}
@@ -362,6 +372,7 @@ fn exported_symbols_provider_local(
362372
level: SymbolExportLevel::Rust,
363373
kind: SymbolExportKind::Text,
364374
used: false,
375+
used_compiler: false,
365376
},
366377
));
367378
}

compiler/rustc_middle/src/middle/exported_symbols.rs

+5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ pub enum SymbolExportKind {
3535
pub struct SymbolExportInfo {
3636
pub level: SymbolExportLevel,
3737
pub kind: SymbolExportKind,
38+
/// Used to mark these symbols not to be internalized by LTO. These symbols
39+
/// are also added to `symbols.o` to avoid circular dependencies when linking.
3840
pub used: bool,
41+
/// Also used to mark these symbols not to be internalized by LTO. But will
42+
/// not be added to `symbols.o`. Currently there are only builtin functions.
43+
pub used_compiler: bool,
3944
}
4045

4146
#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]

src/tools/miri/src/bin/miri.rs

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
165165
level: SymbolExportLevel::C,
166166
kind: SymbolExportKind::Text,
167167
used: false,
168+
used_compiler: false,
168169
},
169170
))
170171
}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include ../tools.mk
2+
3+
# only-x86_64-unknown-linux-gnu
4+
5+
all:
6+
$(RUSTC) main.rs -o $(TMPDIR)/main
7+
[ "$$("$(LLVM_BIN_DIR)"/llvm-nm -U $(TMPDIR)/main | grep -c __fixunssfti)" -eq "0" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

0 commit comments

Comments
 (0)