Skip to content

Commit b9501ba

Browse files
committed
Move exported_symbols_for_lto out of CodegenContext
1 parent 097a84f commit b9501ba

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
@@ -341,7 +341,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
341341
pub opts: Arc<config::Options>,
342342
pub crate_types: Vec<CrateType>,
343343
pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>,
344-
pub exported_symbols_for_lto: Arc<Vec<String>>,
345344
pub output_filenames: Arc<OutputFilenames>,
346345
pub invocation_temp: Option<String>,
347346
pub regular_module_config: Arc<ModuleConfig>,
@@ -396,13 +395,15 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
396395

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

404404
let (lto_modules, copy_jobs) =
405-
B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules).unwrap_or_else(|e| e.raise());
405+
B::run_thin_lto(cgcx, exported_symbols_for_lto, needs_thin_lto, import_only_modules)
406+
.unwrap_or_else(|e| e.raise());
406407
lto_modules
407408
.into_iter()
408409
.map(|module| {
@@ -718,6 +719,7 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
718719
CopyPostLtoArtifacts(CachedModuleCodegen),
719720
/// Performs fat LTO on the given module.
720721
FatLto {
722+
exported_symbols_for_lto: Arc<Vec<String>>,
721723
needs_fat_lto: Vec<FatLtoInput<B>>,
722724
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
723725
autodiff: Vec<AutoDiffItem>,
@@ -990,6 +992,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
990992

991993
fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
992994
cgcx: &CodegenContext<B>,
995+
exported_symbols_for_lto: &[String],
993996
mut needs_fat_lto: Vec<FatLtoInput<B>>,
994997
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
995998
autodiff: Vec<AutoDiffItem>,
@@ -999,7 +1002,8 @@ fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
9991002
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, buffer: module })
10001003
}
10011004

1002-
let module = B::run_and_optimize_fat_lto(cgcx, needs_fat_lto, autodiff)?;
1005+
let module =
1006+
B::run_and_optimize_fat_lto(cgcx, exported_symbols_for_lto, needs_fat_lto, autodiff)?;
10031007
let module = B::codegen(cgcx, module, module_config)?;
10041008
Ok(WorkItemResult::Finished(module))
10051009
}
@@ -1160,7 +1164,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
11601164
let cgcx = CodegenContext::<B> {
11611165
crate_types: tcx.crate_types().to_vec(),
11621166
each_linked_rlib_for_lto,
1163-
exported_symbols_for_lto,
11641167
lto: sess.lto(),
11651168
fewer_names: sess.fewer_names(),
11661169
save_temps: sess.opts.cg.save_temps,
@@ -1441,6 +1444,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14411444

14421445
work_items.push((
14431446
WorkItem::FatLto {
1447+
exported_symbols_for_lto: Arc::clone(&exported_symbols_for_lto),
14441448
needs_fat_lto,
14451449
import_only_modules,
14461450
autodiff: autodiff_items.clone(),
@@ -1456,9 +1460,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
14561460
dcx.handle().emit_fatal(AutodiffWithoutLto {});
14571461
}
14581462

1459-
for (work, cost) in
1460-
generate_thin_lto_work(&cgcx, needs_thin_lto, import_only_modules)
1461-
{
1463+
for (work, cost) in generate_thin_lto_work(
1464+
&cgcx,
1465+
&exported_symbols_for_lto,
1466+
needs_thin_lto,
1467+
import_only_modules,
1468+
) {
14621469
let insertion_index = work_items
14631470
.binary_search_by_key(&cost, |&(_, cost)| cost)
14641471
.unwrap_or_else(|e| e);
@@ -1797,12 +1804,18 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17971804
);
17981805
Ok(execute_copy_from_cache_work_item(&cgcx, m, module_config))
17991806
}
1800-
WorkItem::FatLto { needs_fat_lto, import_only_modules, autodiff } => {
1807+
WorkItem::FatLto {
1808+
exported_symbols_for_lto,
1809+
needs_fat_lto,
1810+
import_only_modules,
1811+
autodiff,
1812+
} => {
18011813
let _timer = cgcx
18021814
.prof
18031815
.generic_activity_with_arg("codegen_module_perform_lto", "everything");
18041816
execute_fat_lto_work_item(
18051817
&cgcx,
1818+
&exported_symbols_for_lto,
18061819
needs_fat_lto,
18071820
import_only_modules,
18081821
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)