Skip to content

Revert "arm64e: Workaround ptrauth-returns failure for swifttailcc" #36496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4863,9 +4863,8 @@ IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) {
auto *fnTy = llvm::FunctionType::get(
IGM.VoidTy, {IGM.Int8PtrTy},
false /*vaargs*/);
auto signature = Signature(
fnTy, IGM.constructInitialAttributes(true /*disable ptrauth-returns*/),
IGM.SwiftAsyncCC);
auto signature =
Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftAsyncCC);
auto fnPtr = FunctionPointer(
FunctionPointer::Kind::Function,
Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()),
Expand Down
8 changes: 2 additions & 6 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,11 +2100,7 @@ llvm::Function *irgen::createFunction(IRGenModule &IGM,
.to(fn, linkInfo.isForDefinition());

llvm::AttrBuilder initialAttrs;
// Workaround an llvm bug that does not handle this case correctly.
bool disablePtrAuthReturns =
signature.getCallingConv() == llvm::CallingConv::SwiftTail;
IGM.constructInitialFnAttributes(initialAttrs, disablePtrAuthReturns,
FuncOptMode);
IGM.constructInitialFnAttributes(initialAttrs, FuncOptMode);
// Merge initialAttrs with attrs.
auto updatedAttrs =
signature.getAttributes().addAttributes(IGM.getLLVMContext(),
Expand Down Expand Up @@ -2815,7 +2811,7 @@ llvm::Constant *swift::irgen::emitCXXConstructorThunkIfNeeded(
thunk->setCallingConv(llvm::CallingConv::C);

llvm::AttrBuilder attrBuilder;
IGM.constructInitialFnAttributes(attrBuilder, false /*disablePtrAuthReturns*/);
IGM.constructInitialFnAttributes(attrBuilder);
attrBuilder.addAttribute(llvm::Attribute::AlwaysInline);
llvm::AttributeList attr = signature.getAttributes().addAttributes(
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, attrBuilder);
Expand Down
4 changes: 1 addition & 3 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,7 @@ static llvm::Value *emitPartialApplicationForwarder(IRGenModule &IGM,
fwd->setAttributes(outAttrs);
// Merge initial attributes with outAttrs.
llvm::AttrBuilder b;
bool disablePtrAuthReturns =
outSig.getCallingConv() == llvm::CallingConv::SwiftTail;
IGM.constructInitialFnAttributes(b, disablePtrAuthReturns);
IGM.constructInitialFnAttributes(b);
fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);

IRGenFunction subIGF(IGM, fwd);
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
fwd->setAttributes(attrs);
// Merge initial attributes with attrs.
llvm::AttrBuilder b;
IGM.constructInitialFnAttributes(b, false /*disable ptr auth returns*/);
IGM.constructInitialFnAttributes(b);
fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);

IRGenFunction subIGF(IGM, fwd);
Expand Down
16 changes: 4 additions & 12 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,18 +1111,11 @@ void IRGenModule::setHasNoFramePointer(llvm::Function *F) {
}

/// Construct initial function attributes from options.
void IRGenModule::constructInitialFnAttributes(
llvm::AttrBuilder &Attrs, bool disablePtrAuthReturns,
OptimizationMode FuncOptMode) {
void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
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;
Expand All @@ -1135,10 +1128,9 @@ void IRGenModule::constructInitialFnAttributes(
}
}

llvm::AttributeList
IRGenModule::constructInitialAttributes(bool disablePtrAuthReturns) {
llvm::AttributeList IRGenModule::constructInitialAttributes() {
llvm::AttrBuilder b;
constructInitialFnAttributes(b, disablePtrAuthReturns);
constructInitialFnAttributes(b);
return llvm::AttributeList::get(getLLVMContext(),
llvm::AttributeList::FunctionIndex, b);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1362,13 +1362,11 @@ private: \
bool finalize();

void constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
bool disablePtrAuthReturns,
OptimizationMode FuncOptMode =
OptimizationMode::NotSet);
void setHasNoFramePointer(llvm::AttrBuilder &Attrs);
void setHasNoFramePointer(llvm::Function *F);
llvm::AttributeList
constructInitialAttributes(bool disablePtrAuthReturns = false);
llvm::AttributeList constructInitialAttributes();

void emitProtocolDecl(ProtocolDecl *D);
void emitEnumDecl(EnumDecl *D);
Expand Down