Skip to content

Commit 6366a69

Browse files
committed
Remove -Zemit-thin-lto flag
As far as I can tell it was introduced to allow fat LTO with -Clinker-plugin-lto. Later a change was made to automatically disable ThinLTO summary generation when -Clinker-plugin-lto -Clto=fat is used, so we can safely remove it.
1 parent 59fd4ef commit 6366a69

7 files changed

Lines changed: 11 additions & 21 deletions

File tree

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ pub(crate) unsafe fn llvm_optimize(
786786
config.verify_llvm_ir,
787787
config.lint_llvm_ir,
788788
thin_lto_buffer,
789-
config.emit_thin_lto,
790789
config.emit_thin_lto_summary,
791790
merge_functions,
792791
unroll_loops,
@@ -1033,7 +1032,7 @@ pub(crate) fn codegen(
10331032
"LLVM_module_codegen_make_bitcode",
10341033
&*module.name,
10351034
);
1036-
ThinBuffer::new(llmod, config.emit_thin_lto)
1035+
ThinBuffer::new(llmod, cgcx.lto != Lto::Fat)
10371036
};
10381037
let data = thin.data();
10391038
let _timer = prof

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,6 @@ unsafe extern "C" {
23762376
VerifyIR: bool,
23772377
LintIR: bool,
23782378
ThinLTOBuffer: Option<&mut *mut ThinLTOBuffer>,
2379-
EmitThinLTO: bool,
23802379
EmitThinLTOSummary: bool,
23812380
MergeFunctions: bool,
23822381
UnrollLoops: bool,

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ pub struct ModuleConfig {
101101
pub emit_ir: bool,
102102
pub emit_asm: bool,
103103
pub emit_obj: EmitObj,
104-
pub emit_thin_lto: bool,
105104
pub emit_thin_lto_summary: bool,
106105

107106
// Miscellaneous flags. These are mostly copied from command-line
@@ -212,9 +211,6 @@ impl ModuleConfig {
212211
false
213212
),
214213
emit_obj,
215-
// thin lto summaries prevent fat lto, so do not emit them if fat
216-
// lto is requested. See PR #136840 for background information.
217-
emit_thin_lto: sess.opts.unstable_opts.emit_thin_lto && sess.lto() != Lto::Fat,
218214
emit_thin_lto_summary: if_regular!(
219215
sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode),
220216
false

compiler/rustc_interface/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ fn test_unstable_options_tracking_hash() {
796796
tracked!(dwarf_version, Some(5));
797797
tracked!(embed_metadata, false);
798798
tracked!(embed_source, true);
799-
tracked!(emit_thin_lto, false);
800799
tracked!(emscripten_wasm_eh, false);
801800
tracked!(export_executable_symbols, true);
802801
tracked!(fewer_names, Some(true));

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
566566
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
567567
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
568568
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
569-
bool LintIR, LLVMRustThinLTOBuffer **ThinLTOBufferRef, bool EmitThinLTO,
569+
bool LintIR, LLVMRustThinLTOBuffer **ThinLTOBufferRef,
570570
bool EmitThinLTOSummary, bool MergeFunctions, bool UnrollLoops,
571571
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
572572
bool EmitLifetimeMarkers, registerEnzymeAndPassPipelineFn EnzymePtr,
@@ -808,7 +808,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
808808
}
809809

810810
ModulePassManager MPM;
811-
bool NeedThinLTOBufferPasses = EmitThinLTO;
811+
bool NeedThinLTOBufferPasses = true;
812812
auto ThinLTOBuffer = std::make_unique<LLVMRustThinLTOBuffer>();
813813
raw_string_ostream ThinLTODataOS(ThinLTOBuffer->data);
814814
raw_string_ostream ThinLinkDataOS(ThinLTOBuffer->thin_link_data);
@@ -840,12 +840,8 @@ extern "C" LLVMRustResult LLVMRustOptimize(
840840
// bitcode for embedding is obtained after performing
841841
// `ThinLTOPreLinkDefaultPipeline`.
842842
MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(OptLevel));
843-
if (EmitThinLTO) {
844-
MPM.addPass(ThinLTOBitcodeWriterPass(
845-
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
846-
} else {
847-
MPM.addPass(BitcodeWriterPass(ThinLTODataOS));
848-
}
843+
MPM.addPass(ThinLTOBitcodeWriterPass(
844+
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
849845
*ThinLTOBufferRef = ThinLTOBuffer.release();
850846
MPM.addPass(PB.buildModuleOptimizationPipeline(
851847
OptLevel, ThinOrFullLTOPhase::None));
@@ -870,6 +866,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
870866
break;
871867
case LLVMRustOptStage::FatLTO:
872868
MPM = PB.buildLTODefaultPipeline(OptLevel, nullptr);
869+
NeedThinLTOBufferPasses = false;
873870
break;
874871
}
875872
}
@@ -895,9 +892,11 @@ extern "C" LLVMRustResult LLVMRustOptimize(
895892
MPM.addPass(CanonicalizeAliasesPass());
896893
MPM.addPass(NameAnonGlobalPass());
897894
}
898-
// For `-Copt-level=0`, ThinLTO, or LTO.
895+
// For `-Copt-level=0`, and the pre-link fat/thin LTO stages.
899896
if (ThinLTOBufferRef && *ThinLTOBufferRef == nullptr) {
900-
if (EmitThinLTO) {
897+
// thin lto summaries prevent fat lto, so do not emit them if fat
898+
// lto is requested. See PR #136840 for background information.
899+
if (OptStage != LLVMRustOptStage::PreLinkFatLTO) {
901900
MPM.addPass(ThinLTOBitcodeWriterPass(
902901
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
903902
} else {

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,8 +2335,6 @@ options! {
23352335
"embed source text in DWARF debug sections (default: no)"),
23362336
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
23372337
"emit a section containing stack size metadata (default: no)"),
2338-
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
2339-
"emit the bc module with thin LTO info (default: yes)"),
23402338
emscripten_wasm_eh: bool = (true, parse_bool, [TRACKED],
23412339
"Use WebAssembly error handling for wasm32-unknown-emscripten"),
23422340
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],

tests/run-make/issue-84395-lto-embed-bitcode/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
.arg("-Clinker-plugin-lto")
1919
.arg(format!("-Clinker={}", env_var("CLANG")))
2020
.arg("-Clink-arg=-Wl,--plugin-opt=-lto-embed-bitcode=optimized")
21-
.arg("-Zemit-thin-lto=no")
21+
.arg("-Clto=fat")
2222
.run();
2323

2424
llvm_objcopy().dump_section(".llvmbc", "test.bc").arg("test").run();

0 commit comments

Comments
 (0)