Skip to content

Commit 2f2a834

Browse files
committed
Fix to forward lto_supported and lto_mode where needed
1 parent b0777f2 commit 2f2a834

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/back/lto.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::ffi::{CStr, CString};
2121
use std::fs::{self, File};
2222
use std::path::{Path, PathBuf};
2323
use std::sync::Arc;
24+
use std::sync::atomic::Ordering;
2425

2526
use gccjit::{Context, OutputKind};
2627
use object::read::archive::ArchiveFile;
@@ -38,7 +39,7 @@ use tempfile::{TempDir, tempdir};
3839

3940
use crate::back::write::save_temp_bitcode;
4041
use crate::errors::LtoBitcodeFromRlib;
41-
use crate::{GccCodegenBackend, GccContext, LtoMode, SyncContext, to_gcc_opt_level};
42+
use crate::{GccCodegenBackend, GccContext, LTO_SUPPORTED, LtoMode, SyncContext, to_gcc_opt_level};
4243

4344
struct LtoData {
4445
// TODO(antoyo): use symbols_below_threshold.
@@ -559,12 +560,13 @@ pub fn optimize_thin_module(
559560
Arc::new(SyncContext::new(context))
560561
}
561562
};
563+
let lto_supported = LTO_SUPPORTED.load(Ordering::SeqCst);
562564
let module = ModuleCodegen::new_regular(
563565
thin_module.name().to_string(),
564566
GccContext {
565567
context,
566568
lto_mode,
567-
lto_supported: false, // TODO(antoyo): check if this is correct to use this value.
569+
lto_supported,
568570
// TODO(antoyo): use the correct relocation model here.
569571
relocation_model: RelocModel::Pic,
570572
temp_dir: None,

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ pub struct GccCodegenBackend {
177177
lto_supported: Arc<AtomicBool>,
178178
}
179179

180+
static LTO_SUPPORTED: AtomicBool = AtomicBool::new(false);
181+
180182
impl CodegenBackend for GccCodegenBackend {
181183
fn locale_resource(&self) -> &'static str {
182184
crate::DEFAULT_LOCALE_RESOURCE
@@ -200,7 +202,7 @@ impl CodegenBackend for GccCodegenBackend {
200202
**self.target_info.info.lock().expect("lock") = context.get_target_info();
201203
}
202204

203-
// TODO: try the LTO frontend and check if it errors out. If so, do not embed the bitcode.
205+
// NOTE: try the LTO frontend and check if it errors out. If so, do not embed the bitcode.
204206
{
205207
let temp_dir = TempDir::new().expect("cannot create temporary directory");
206208
let temp_file = temp_dir.into_path().join("result.asm");
@@ -220,6 +222,7 @@ impl CodegenBackend for GccCodegenBackend {
220222
check_context.compile();
221223
let error = check_context.get_last_error();
222224
let lto_supported = error == Ok(None);
225+
LTO_SUPPORTED.store(lto_supported, Ordering::SeqCst);
223226
self.lto_supported.store(lto_supported, Ordering::SeqCst);
224227
}
225228

@@ -308,11 +311,12 @@ impl ExtraBackendMethods for GccCodegenBackend {
308311
kind: AllocatorKind,
309312
alloc_error_handler_kind: AllocatorKind,
310313
) -> Self::Module {
314+
let lto_supported = self.lto_supported.load(Ordering::SeqCst);
311315
let mut mods = GccContext {
312316
context: Arc::new(SyncContext::new(new_context(tcx))),
313317
relocation_model: tcx.sess.relocation_model(),
314318
lto_mode: LtoMode::None,
315-
lto_supported: false,
319+
lto_supported,
316320
temp_dir: None,
317321
};
318322

0 commit comments

Comments
 (0)