Fix to forward lto_supported and lto_mode where needed

This commit is contained in:
Antoni Boucher 2025-06-15 09:43:44 -04:00
parent b0777f2c07
commit 2f2a834507
2 changed files with 10 additions and 4 deletions

View file

@ -21,6 +21,7 @@ use std::ffi::{CStr, CString};
use std::fs::{self, File};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::Ordering;
use gccjit::{Context, OutputKind};
use object::read::archive::ArchiveFile;
@ -38,7 +39,7 @@ use tempfile::{TempDir, tempdir};
use crate::back::write::save_temp_bitcode;
use crate::errors::LtoBitcodeFromRlib;
use crate::{GccCodegenBackend, GccContext, LtoMode, SyncContext, to_gcc_opt_level};
use crate::{GccCodegenBackend, GccContext, LTO_SUPPORTED, LtoMode, SyncContext, to_gcc_opt_level};
struct LtoData {
// TODO(antoyo): use symbols_below_threshold.
@ -559,12 +560,13 @@ pub fn optimize_thin_module(
Arc::new(SyncContext::new(context))
}
};
let lto_supported = LTO_SUPPORTED.load(Ordering::SeqCst);
let module = ModuleCodegen::new_regular(
thin_module.name().to_string(),
GccContext {
context,
lto_mode,
lto_supported: false, // TODO(antoyo): check if this is correct to use this value.
lto_supported,
// TODO(antoyo): use the correct relocation model here.
relocation_model: RelocModel::Pic,
temp_dir: None,

View file

@ -177,6 +177,8 @@ pub struct GccCodegenBackend {
lto_supported: Arc<AtomicBool>,
}
static LTO_SUPPORTED: AtomicBool = AtomicBool::new(false);
impl CodegenBackend for GccCodegenBackend {
fn locale_resource(&self) -> &'static str {
crate::DEFAULT_LOCALE_RESOURCE
@ -200,7 +202,7 @@ impl CodegenBackend for GccCodegenBackend {
**self.target_info.info.lock().expect("lock") = context.get_target_info();
}
// TODO: try the LTO frontend and check if it errors out. If so, do not embed the bitcode.
// NOTE: try the LTO frontend and check if it errors out. If so, do not embed the bitcode.
{
let temp_dir = TempDir::new().expect("cannot create temporary directory");
let temp_file = temp_dir.into_path().join("result.asm");
@ -220,6 +222,7 @@ impl CodegenBackend for GccCodegenBackend {
check_context.compile();
let error = check_context.get_last_error();
let lto_supported = error == Ok(None);
LTO_SUPPORTED.store(lto_supported, Ordering::SeqCst);
self.lto_supported.store(lto_supported, Ordering::SeqCst);
}
@ -308,11 +311,12 @@ impl ExtraBackendMethods for GccCodegenBackend {
kind: AllocatorKind,
alloc_error_handler_kind: AllocatorKind,
) -> Self::Module {
let lto_supported = self.lto_supported.load(Ordering::SeqCst);
let mut mods = GccContext {
context: Arc::new(SyncContext::new(new_context(tcx))),
relocation_model: tcx.sess.relocation_model(),
lto_mode: LtoMode::None,
lto_supported: false,
lto_supported,
temp_dir: None,
};