Skip to content

Commit 73feaad

Browse files
committed
Fix to forward lto_supported and lto_mode where needed
1 parent 03f8fe8 commit 73feaad

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
@@ -182,6 +182,8 @@ pub struct GccCodegenBackend {
182182
lto_supported: Arc<AtomicBool>,
183183
}
184184

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

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

@@ -305,11 +308,12 @@ impl ExtraBackendMethods for GccCodegenBackend {
305308
kind: AllocatorKind,
306309
alloc_error_handler_kind: AllocatorKind,
307310
) -> Self::Module {
311+
let lto_supported = self.lto_supported.load(Ordering::SeqCst);
308312
let mut mods = GccContext {
309313
context: Arc::new(SyncContext::new(new_context(tcx))),
310314
relocation_model: tcx.sess.relocation_model(),
311315
lto_mode: LtoMode::None,
312-
lto_supported: false,
316+
lto_supported,
313317
temp_dir: None,
314318
};
315319

0 commit comments

Comments
 (0)