Skip to content

Commit 7d49787

Browse files
committed
Attempt to fix Thin LTO
1 parent 7501f0c commit 7d49787

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

src/back/write.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{env, fs};
22

3-
use gccjit::{Context, OutputKind};
3+
use gccjit::OutputKind;
44
use rustc_codegen_ssa::back::link::ensure_removed;
55
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
66
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
@@ -11,7 +11,6 @@ use rustc_log::tracing::debug;
1111
use rustc_session::config::OutputType;
1212
use rustc_target::spec::SplitDebuginfo;
1313

14-
use crate::base::add_pic_option;
1514
use crate::errors::CopyBitcode;
1615
use crate::{GccContext, LtoMode};
1716

@@ -148,7 +147,6 @@ pub(crate) fn codegen(
148147
let path = obj_out.to_str().expect("path to str");
149148

150149
if fat_lto {
151-
let lto_path = format!("{}.lto", path);
152150
// cSpell:disable
153151
// FIXME(antoyo): The LTO frontend generates the following warning:
154152
// ../build_sysroot/sysroot_src/library/core/src/num/dec2flt/lemire.rs:150:15: warning: type of ‘_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ does not match original declaration [-Wlto-type-mismatch]
@@ -159,27 +157,6 @@ pub(crate) fn codegen(
159157
// This option is to mute it to make the UI tests pass with LTO enabled.
160158
// cSpell:enable
161159
context.add_driver_option("-Wno-lto-type-mismatch");
162-
// NOTE: this doesn't actually generate an executable. With the above
163-
// flags, it combines the .o files together in another .o.
164-
context.compile_to_file(OutputKind::Executable, &lto_path);
165-
166-
let context = Context::default();
167-
if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" {
168-
// NOTE: it seems we need to use add_driver_option instead of
169-
// add_command_line_option here because we use the LTO frontend via gcc.
170-
context.add_driver_option("-masm=intel");
171-
}
172-
173-
// NOTE: these two options are needed to invoke LTO to produce an object file.
174-
// We need to initiate a second compilation because the arguments "-x lto"
175-
// needs to be at the very beginning.
176-
context.add_driver_option("-x");
177-
context.add_driver_option("lto");
178-
add_pic_option(&context, module.module_llvm.relocation_model);
179-
context.add_driver_option(lto_path);
180-
181-
context.compile_to_file(OutputKind::ObjectFile, path);
182-
} else {
183160
// NOTE: this doesn't actually generate an executable. With the above
184161
// flags, it combines the .o files together in another .o.
185162
context.compile_to_file(OutputKind::Executable, path);

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ pub struct GccContext {
384384
context: Arc<SyncContext>,
385385
/// This field is needed in order to be able to set the flag -fPIC when necessary when doing
386386
/// LTO.
387+
#[allow(dead_code)]
387388
relocation_model: RelocModel,
388389
lto_mode: LtoMode,
389390
lto_supported: bool,

0 commit comments

Comments
 (0)