Disable all unwinding on -Z no-landing-pads LTO
When performing LTO, the rust compiler has an opportunity to completely strip all landing pads in all dependent libraries. I've modified the LTO pass to recognize the -Z no-landing-pads option when also running an LTO pass to flag everything in LLVM as nothrow. I've verified that this prevents any and all invoke instructions from being emitted. I believe that this is one of our best options for moving forward with accomodating use-cases where unwinding doesn't really make sense. This will allow libraries to be built with landing pads by default but allow usage of them in contexts where landing pads aren't necessary. cc #10780
This commit is contained in:
parent
b8b16ae099
commit
667d114f47
6 changed files with 34 additions and 6 deletions
|
@ -219,3 +219,24 @@ LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
|
|||
passes.add(llvm::createInternalizePass(ref));
|
||||
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 == NULL)
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue