arm64e: Workaround ptrauth-returns failure for swifttailcc

The current code generation will emit an autibsp after adjusting the
stack pointe for the tail call. If callee and caller argument area does
not match this would fail.
This commit is contained in:
Arnold Schwaighofer
2021-03-11 06:39:22 -08:00
parent f75fbb7594
commit 3c125a74f0
6 changed files with 28 additions and 11 deletions

View File

@@ -1111,11 +1111,18 @@ void IRGenModule::setHasNoFramePointer(llvm::Function *F) {
}
/// Construct initial function attributes from options.
void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
OptimizationMode FuncOptMode) {
void IRGenModule::constructInitialFnAttributes(
llvm::AttrBuilder &Attrs, bool disablePtrAuthReturns,
OptimizationMode FuncOptMode) {
// Add the default attributes for the Clang configuration.
clang::CodeGen::addDefaultFunctionDefinitionAttributes(getClangCGM(), Attrs);
// Disable `ptrauth-returns`. It does not work for swifttailcc lowering atm.
// The `autibsp` instruction executed before a tail call that adjust the stack
// will currently fail.
if (disablePtrAuthReturns)
Attrs.removeAttribute("ptrauth-returns");
// Add/remove MinSize based on the appropriate setting.
if (FuncOptMode == OptimizationMode::NotSet)
FuncOptMode = IRGen.Opts.OptMode;
@@ -1128,9 +1135,10 @@ void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
}
}
llvm::AttributeList IRGenModule::constructInitialAttributes() {
llvm::AttributeList
IRGenModule::constructInitialAttributes(bool disablePtrAuthReturns) {
llvm::AttrBuilder b;
constructInitialFnAttributes(b);
constructInitialFnAttributes(b, disablePtrAuthReturns);
return llvm::AttributeList::get(getLLVMContext(),
llvm::AttributeList::FunctionIndex, b);
}