Skip to content

Commit af86f4e

Browse files
committed
Fix to do LTO when requested
1 parent b70b304 commit af86f4e

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/back/lto.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use tempfile::{TempDir, tempdir};
3838

3939
use crate::back::write::save_temp_bitcode;
4040
use crate::errors::LtoBitcodeFromRlib;
41-
use crate::{GccCodegenBackend, GccContext, SyncContext, to_gcc_opt_level};
41+
use crate::{GccCodegenBackend, GccContext, LtoMode, SyncContext, to_gcc_opt_level};
4242

4343
struct LtoData {
4444
// TODO(antoyo): use symbols_below_threshold.
@@ -228,7 +228,7 @@ fn fat_lto(
228228
info!("linking {:?}", name);
229229
match bc_decoded {
230230
SerializedModule::Local(ref module_buffer) => {
231-
module.module_llvm.should_combine_object_files = true;
231+
module.module_llvm.lto_mode = LtoMode::Fat;
232232
module
233233
.module_llvm
234234
.context
@@ -533,7 +533,7 @@ pub fn optimize_thin_module(
533533
// that LLVM Context and Module.
534534
//let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
535535
//let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &dcx)? as *const _;
536-
let mut should_combine_object_files = false;
536+
let mut lto_mode = LtoMode::None;
537537
let context = match thin_module.shared.thin_buffers.get(thin_module.idx) {
538538
Some(thin_buffer) => Arc::clone(&thin_buffer.context),
539539
None => {
@@ -544,7 +544,7 @@ pub fn optimize_thin_module(
544544
SerializedModule::Local(ref module_buffer) => {
545545
let path = module_buffer.0.to_str().expect("path");
546546
context.add_driver_option(path);
547-
should_combine_object_files = true;
547+
lto_mode = LtoMode::Thin;
548548
/*module.module_llvm.should_combine_object_files = true;
549549
module
550550
.module_llvm
@@ -563,7 +563,7 @@ pub fn optimize_thin_module(
563563
thin_module.name().to_string(),
564564
GccContext {
565565
context,
566-
should_combine_object_files,
566+
lto_mode,
567567
// TODO(antoyo): use the correct relocation model here.
568568
relocation_model: RelocModel::Pic,
569569
temp_dir: None,

src/back/write.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_target::spec::SplitDebuginfo;
1010

1111
use crate::base::add_pic_option;
1212
use crate::errors::CopyBitcode;
13-
use crate::{GccCodegenBackend, GccContext};
13+
use crate::{GccCodegenBackend, GccContext, LtoMode};
1414

1515
pub(crate) fn codegen(
1616
cgcx: &CodegenContext<GccCodegenBackend>,
@@ -24,7 +24,7 @@ pub(crate) fn codegen(
2424
{
2525
let context = &module.module_llvm.context;
2626

27-
let should_combine_object_files = module.module_llvm.should_combine_object_files;
27+
let lto_mode = module.module_llvm.lto_mode;
2828

2929
let bc_out = cgcx.output_filenames.temp_path_for_cgu(
3030
OutputType::Bitcode,
@@ -124,8 +124,8 @@ pub(crate) fn codegen(
124124
context.set_debug_info(true);
125125
context.dump_to_file(path, true);
126126
}
127-
if should_combine_object_files {
128-
let fat_lto = config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full);
127+
if lto_mode != LtoMode::None {
128+
let fat_lto = lto_mode == LtoMode::Fat;
129129
// We need to check if we're doing LTO since this code is also used for the
130130
// dummy ThinLTO implementation to combine the object files.
131131
if fat_lto {

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_target::spec::SymbolVisibility;
2121

2222
use crate::builder::Builder;
2323
use crate::context::CodegenCx;
24-
use crate::{GccContext, LockedTargetInfo, SyncContext, gcc_util, new_context};
24+
use crate::{GccContext, LockedTargetInfo, LtoMode, SyncContext, gcc_util, new_context};
2525

2626
#[cfg(feature = "master")]
2727
pub fn visibility_to_gcc(visibility: Visibility) -> gccjit::Visibility {
@@ -247,7 +247,7 @@ pub fn compile_codegen_unit(
247247
GccContext {
248248
context: Arc::new(SyncContext::new(context)),
249249
relocation_model: tcx.sess.relocation_model(),
250-
should_combine_object_files: false,
250+
lto_mode: LtoMode::None,
251251
temp_dir: None,
252252
},
253253
)

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
290290
let mut mods = GccContext {
291291
context: Arc::new(SyncContext::new(new_context(tcx))),
292292
relocation_model: tcx.sess.relocation_model(),
293-
should_combine_object_files: false,
293+
lto_mode: LtoMode::None,
294294
temp_dir: None,
295295
};
296296

@@ -319,12 +319,19 @@ impl ExtraBackendMethods for GccCodegenBackend {
319319
}
320320
}
321321

322+
#[derive(Clone, Copy, PartialEq)]
323+
pub enum LtoMode {
324+
None,
325+
Thin,
326+
Fat,
327+
}
328+
322329
pub struct GccContext {
323330
context: Arc<SyncContext>,
324331
/// This field is needed in order to be able to set the flag -fPIC when necessary when doing
325332
/// LTO.
326333
relocation_model: RelocModel,
327-
should_combine_object_files: bool,
334+
lto_mode: LtoMode,
328335
// Temporary directory used by LTO. We keep it here so that it's not removed before linking.
329336
temp_dir: Option<TempDir>,
330337
}

0 commit comments

Comments
 (0)