Skip to content

Commit 3b7ee43

Browse files
committed
Fix to forward lto_supported and lto_mode where needed
1 parent 466fb8a commit 3b7ee43

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;
@@ -41,7 +42,7 @@ use tempfile::{TempDir, tempdir};
4142

4243
use crate::back::write::save_temp_bitcode;
4344
use crate::errors::{DynamicLinkingWithLTO, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib};
44-
use crate::{GccCodegenBackend, GccContext, LtoMode, SyncContext, to_gcc_opt_level};
45+
use crate::{GccCodegenBackend, GccContext, LTO_SUPPORTED, LtoMode, SyncContext, to_gcc_opt_level};
4546

4647
pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
4748
match crate_type {
@@ -637,12 +638,13 @@ pub fn optimize_thin_module(
637638
Arc::new(SyncContext::new(context))
638639
}
639640
};
641+
let lto_supported = LTO_SUPPORTED.load(Ordering::SeqCst);
640642
let module = ModuleCodegen::new_regular(
641643
thin_module.name().to_string(),
642644
GccContext {
643645
context,
644646
lto_mode,
645-
lto_supported: false, // TODO(antoyo): check if this is correct to use this value.
647+
lto_supported,
646648
// TODO(antoyo): use the correct relocation model here.
647649
relocation_model: RelocModel::Pic,
648650
temp_dir: None,

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ pub struct GccCodegenBackend {
183183
lto_supported: Arc<AtomicBool>,
184184
}
185185

186+
static LTO_SUPPORTED: AtomicBool = AtomicBool::new(false);
187+
186188
impl CodegenBackend for GccCodegenBackend {
187189
fn locale_resource(&self) -> &'static str {
188190
crate::DEFAULT_LOCALE_RESOURCE
@@ -202,7 +204,7 @@ impl CodegenBackend for GccCodegenBackend {
202204
**self.target_info.info.lock().expect("lock") = context.get_target_info();
203205
}
204206

205-
// TODO: try the LTO frontend and check if it errors out. If so, do not embed the bitcode.
207+
// NOTE: try the LTO frontend and check if it errors out. If so, do not embed the bitcode.
206208
{
207209
let temp_dir = TempDir::new().expect("cannot create temporary directory");
208210
let temp_file = temp_dir.into_path().join("result.asm");
@@ -222,6 +224,7 @@ impl CodegenBackend for GccCodegenBackend {
222224
check_context.compile();
223225
let error = check_context.get_last_error();
224226
let lto_supported = error == Ok(None);
227+
LTO_SUPPORTED.store(lto_supported, Ordering::SeqCst);
225228
self.lto_supported.store(lto_supported, Ordering::SeqCst);
226229
}
227230

@@ -317,11 +320,12 @@ impl ExtraBackendMethods for GccCodegenBackend {
317320
kind: AllocatorKind,
318321
alloc_error_handler_kind: AllocatorKind,
319322
) -> Self::Module {
323+
let lto_supported = self.lto_supported.load(Ordering::SeqCst);
320324
let mut mods = GccContext {
321325
context: Arc::new(SyncContext::new(new_context(tcx))),
322326
relocation_model: tcx.sess.relocation_model(),
323327
lto_mode: LtoMode::None,
324-
lto_supported: false,
328+
lto_supported,
325329
temp_dir: None,
326330
};
327331

0 commit comments

Comments
 (0)