Skip to content

Commit

Permalink
Rollup merge of rust-lang#92877 - Amanieu:remove_llvm_nounwind, r=Mar…
Browse files Browse the repository at this point in the history
…k-Simulacrum

Remove LLVMRustMarkAllFunctionsNounwind

This was originally introduced in rust-lang#10916 as a way to remove all landing
pads when performing LTO. However this is no longer necessary today
since rustc properly marks all functions and call-sites as nounwind
where appropriate.

In fact this is incorrect in the presence of `extern "C-unwind"` which
must create a landing pad when compiled with `-C panic=abort` so that
foreign exceptions are caught and properly turned into aborts.
  • Loading branch information
matthiaskrgr authored Jan 17, 2022
2 parents 6acb704 + 606d9c0 commit 7f02604
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 40 deletions.
17 changes: 0 additions & 17 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,6 @@ fn fat_lto(
);
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
}

if cgcx.no_landing_pads {
unsafe {
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
}
save_temp_bitcode(cgcx, &module, "lto.after-nounwind");
}
}

Ok(LtoModuleCodegen::Fat { module: Some(module), _serialized_bitcode: serialized_bitcode })
Expand Down Expand Up @@ -770,16 +763,6 @@ pub unsafe fn optimize_thin_module(
return Err(write::llvm_err(&diag_handler, msg));
}

// Like with "fat" LTO, get some better optimizations if landing pads
// are disabled by removing all landing pads.
if cgcx.no_landing_pads {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_thin_lto_remove_landing_pads", thin_module.name());
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
save_temp_bitcode(cgcx, &module, "thin-lto-after-nounwind");
}

// Up next comes the per-module local analyses that we do for Thin LTO.
// Each of these functions is basically copied from the LLVM
// implementation and then tailored to suit this implementation. Ideally
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,6 @@ extern "C" {
pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);

pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use rustc_session::Session;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, FileName, InnerSpan, Pos, Span};
use rustc_target::spec::{MergeFunctions, PanicStrategy, SanitizerSet};
use rustc_target::spec::{MergeFunctions, SanitizerSet};

use std::any::Any;
use std::fs;
Expand Down Expand Up @@ -313,7 +313,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
pub backend: B,
pub prof: SelfProfilerRef,
pub lto: Lto,
pub no_landing_pads: bool,
pub save_temps: bool,
pub fewer_names: bool,
pub time_trace: bool,
Expand Down Expand Up @@ -1039,7 +1038,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
crate_types: sess.crate_types().to_vec(),
each_linked_rlib_for_lto,
lto: sess.lto(),
no_landing_pads: sess.panic_strategy() == PanicStrategy::Abort,
fewer_names: sess.fewer_names(),
save_temps: sess.opts.cg.save_temps,
time_trace: sess.opts.debugging_opts.llvm_time_trace,
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,25 +1168,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
passes.run(*unwrap(M));
}

extern "C" void LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
for (Module::iterator GV = unwrap(M)->begin(), E = unwrap(M)->end(); GV != E;
++GV) {
GV->setDoesNotThrow();
Function *F = dyn_cast<Function>(GV);
if (F == nullptr)
continue;

for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
if (isa<InvokeInst>(I)) {
InvokeInst *CI = cast<InvokeInst>(I);
CI->setDoesNotThrow();
}
}
}
}
}

extern "C" void
LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
LLVMTargetMachineRef TMR) {
Expand Down

0 comments on commit 7f02604

Please sign in to comment.