Skip to content

Commit b2948eb

Browse files
committed
Move exported_symbols_for_lto out of CodegenContext
1 parent 162db89 commit b2948eb

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ fn prepare_lto(
5151
cgcx: &CodegenContext<GccCodegenBackend>,
5252
dcx: DiagCtxtHandle<'_>,
5353
) -> Result<LtoData, FatalError> {
54-
// FIXME(bjorn3): Limit LTO exports to these symbols
55-
let _symbols_below_threshold = &cgcx.exported_symbols_for_lto;
56-
5754
let tmp_path = match tempdir() {
5855
Ok(tmp_path) => tmp_path,
5956
Err(error) => {

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ impl WriteBackendMethods for GccCodegenBackend {
355355

356356
fn run_and_optimize_fat_lto(
357357
cgcx: &CodegenContext<Self>,
358+
// FIXME(bjorn3): Limit LTO exports to these symbols
359+
_exported_symbols_for_lto: &[String],
358360
modules: Vec<FatLtoInput<Self>>,
359361
diff_fncs: Vec<AutoDiffItem>,
360362
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
@@ -367,6 +369,8 @@ impl WriteBackendMethods for GccCodegenBackend {
367369

368370
fn run_thin_lto(
369371
cgcx: &CodegenContext<Self>,
372+
// FIXME(bjorn3): Limit LTO exports to these symbols
373+
_exported_symbols_for_lto: &[String],
370374
modules: Vec<(String, Self::ThinBuffer)>,
371375
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
372376
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError> {

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const THIN_LTO_KEYS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-keys.bin";
3333

3434
fn prepare_lto(
3535
cgcx: &CodegenContext<LlvmCodegenBackend>,
36+
exported_symbols_for_lto: &[String],
3637
dcx: DiagCtxtHandle<'_>,
3738
) -> Result<(Vec<CString>, Vec<(SerializedModule<ModuleBuffer>, CString)>), FatalError> {
38-
let mut symbols_below_threshold = cgcx
39-
.exported_symbols_for_lto
39+
let mut symbols_below_threshold = exported_symbols_for_lto
4040
.iter()
4141
.map(|symbol| CString::new(symbol.to_owned()).unwrap())
4242
.collect::<Vec<CString>>();
@@ -135,11 +135,13 @@ fn get_bitcode_slice_from_object_data<'a>(
135135
/// for further optimization.
136136
pub(crate) fn run_fat(
137137
cgcx: &CodegenContext<LlvmCodegenBackend>,
138+
exported_symbols_for_lto: &[String],
138139
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
139140
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
140141
let dcx = cgcx.create_dcx();
141142
let dcx = dcx.handle();
142-
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, dcx)?;
143+
let (symbols_below_threshold, upstream_modules) =
144+
prepare_lto(cgcx, exported_symbols_for_lto, dcx)?;
143145
let symbols_below_threshold =
144146
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
145147
fat_lto(cgcx, dcx, modules, upstream_modules, &symbols_below_threshold)
@@ -150,12 +152,14 @@ pub(crate) fn run_fat(
150152
/// can simply be copied over from the incr. comp. cache.
151153
pub(crate) fn run_thin(
152154
cgcx: &CodegenContext<LlvmCodegenBackend>,
155+
exported_symbols_for_lto: &[String],
153156
modules: Vec<(String, ThinBuffer)>,
154157
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
155158
) -> Result<(Vec<ThinModule<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
156159
let dcx = cgcx.create_dcx();
157160
let dcx = dcx.handle();
158-
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, dcx)?;
161+
let (symbols_below_threshold, upstream_modules) =
162+
prepare_lto(cgcx, exported_symbols_for_lto, dcx)?;
159163
let symbols_below_threshold =
160164
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
161165
if cgcx.opts.cg.linker_plugin_lto.enabled() {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ impl WriteBackendMethods for LlvmCodegenBackend {
176176
}
177177
fn run_and_optimize_fat_lto(
178178
cgcx: &CodegenContext<Self>,
179+
exported_symbols_for_lto: &[String],
179180
modules: Vec<FatLtoInput<Self>>,
180181
diff_fncs: Vec<AutoDiffItem>,
181182
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
182-
let mut module = back::lto::run_fat(cgcx, modules)?;
183+
let mut module = back::lto::run_fat(cgcx, exported_symbols_for_lto, modules)?;
183184

184185
if !diff_fncs.is_empty() {
185186
builder::autodiff::differentiate(&module, cgcx, diff_fncs)?;
@@ -193,10 +194,11 @@ impl WriteBackendMethods for LlvmCodegenBackend {
193194
}
194195
fn run_thin_lto(
195196
cgcx: &CodegenContext<Self>,
197+
exported_symbols_for_lto: &[String],
196198
modules: Vec<(String, Self::ThinBuffer)>,
197199
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
198200
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError> {
199-
back::lto::run_thin(cgcx, modules, cached_modules)
201+
back::lto::run_thin(cgcx, exported_symbols_for_lto, modules, cached_modules)
200202
}
201203
fn optimize(
202204
cgcx: &CodegenContext<Self>,

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
340340
pub opts: Arc<config::Options>,
341341
pub crate_types: Vec<CrateType>,
342342
pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>,
343-
pub exported_symbols_for_lto: Arc<Vec<String>>,
344343
pub output_filenames: Arc<OutputFilenames>,
345344
pub invocation_temp: Option<String>,
346345
pub regular_module_config: Arc<ModuleConfig>,
@@ -395,13 +394,15 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
395394

396395
fn generate_thin_lto_work<B: ExtraBackendMethods>(
397396
cgcx: &CodegenContext<B>,
397+
exported_symbols_for_lto: &[String],
398398
needs_thin_lto: Vec<(String, B::ThinBuffer)>,
399399
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
400400
) -> Vec<(WorkItem<B>, u64)> {
401401
let _prof_timer = cgcx.prof.generic_activity("codegen_thin_generate_lto_work");
402402

403403
let (lto_modules, copy_jobs) =
404-
B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules).unwrap_or_else(|e| e.raise());
404+
B::run_thin_lto(cgcx, exported_symbols_for_lto, needs_thin_lto, import_only_modules)
405+
.unwrap_or_else(|e| e.raise());
405406
lto_modules
406407
.into_iter()
407408
.map(|module| {
@@ -717,6 +718,7 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
717718
CopyPostLtoArtifacts(CachedModuleCodegen),
718719
/// Performs fat LTO on the given module.
719720
FatLto {
721+
exported_symbols_for_lto: Arc<Vec<String>>,
720722
needs_fat_lto: Vec<FatLtoInput<B>>,
721723
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
722724
autodiff: Vec<AutoDiffItem>,
@@ -989,6 +991,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
989991

990992
fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
991993
cgcx: &CodegenContext<B>,
994+
exported_symbols_for_lto: &[String],
992995
mut needs_fat_lto: Vec<FatLtoInput<B>>,
993996
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
994997
autodiff: Vec<AutoDiffItem>,
@@ -998,7 +1001,8 @@ fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
9981001
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, buffer: module })
9991002
}
10001003

1001-
let module = B::run_and_optimize_fat_lto(cgcx, needs_fat_lto, autodiff)?;
1004+
let module =
1005+
B::run_and_optimize_fat_lto(cgcx, exported_symbols_for_lto, needs_fat_lto, autodiff)?;
10021006
let module = B::codegen(cgcx, module, module_config)?;
10031007
Ok(WorkItemResult::Finished(module))
10041008
}
@@ -1159,7 +1163,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
11591163
let cgcx = CodegenContext::<B> {
11601164
crate_types: tcx.crate_types().to_vec(),
11611165
each_linked_rlib_for_lto,
1162-
exported_symbols_for_lto,
11631166
lto: sess.lto(),
11641167
fewer_names: sess.fewer_names(),
11651168
save_temps: sess.opts.cg.save_temps,
@@ -1438,6 +1441,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14381441

14391442
work_items.push((
14401443
WorkItem::FatLto {
1444+
exported_symbols_for_lto: Arc::clone(&exported_symbols_for_lto),
14411445
needs_fat_lto,
14421446
import_only_modules,
14431447
autodiff: autodiff_items.clone(),
@@ -1453,9 +1457,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
14531457
dcx.handle().emit_fatal(AutodiffWithoutLto {});
14541458
}
14551459

1456-
for (work, cost) in
1457-
generate_thin_lto_work(&cgcx, needs_thin_lto, import_only_modules)
1458-
{
1460+
for (work, cost) in generate_thin_lto_work(
1461+
&cgcx,
1462+
&exported_symbols_for_lto,
1463+
needs_thin_lto,
1464+
import_only_modules,
1465+
) {
14591466
let insertion_index = work_items
14601467
.binary_search_by_key(&cost, |&(_, cost)| cost)
14611468
.unwrap_or_else(|e| e);
@@ -1794,12 +1801,18 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17941801
);
17951802
Ok(execute_copy_from_cache_work_item(&cgcx, m, module_config))
17961803
}
1797-
WorkItem::FatLto { needs_fat_lto, import_only_modules, autodiff } => {
1804+
WorkItem::FatLto {
1805+
exported_symbols_for_lto,
1806+
needs_fat_lto,
1807+
import_only_modules,
1808+
autodiff,
1809+
} => {
17981810
let _timer = cgcx
17991811
.prof
18001812
.generic_activity_with_arg("codegen_module_perform_lto", "everything");
18011813
execute_fat_lto_work_item(
18021814
&cgcx,
1815+
&exported_symbols_for_lto,
18031816
needs_fat_lto,
18041817
import_only_modules,
18051818
autodiff,

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub trait WriteBackendMethods: Clone + 'static {
2424
/// if necessary and running any further optimizations
2525
fn run_and_optimize_fat_lto(
2626
cgcx: &CodegenContext<Self>,
27+
exported_symbols_for_lto: &[String],
2728
modules: Vec<FatLtoInput<Self>>,
2829
diff_fncs: Vec<AutoDiffItem>,
2930
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
@@ -32,6 +33,7 @@ pub trait WriteBackendMethods: Clone + 'static {
3233
/// can simply be copied over from the incr. comp. cache.
3334
fn run_thin_lto(
3435
cgcx: &CodegenContext<Self>,
36+
exported_symbols_for_lto: &[String],
3537
modules: Vec<(String, Self::ThinBuffer)>,
3638
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
3739
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError>;

0 commit comments

Comments
 (0)