Skip to content

Commit 6317608

Browse files
committed
Don't re-emit _cmd, Fix pointer auth emission in CGLogos
1 parent dc3cff3 commit 6317608

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

clang/lib/CodeGen/CGLogos.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,21 @@ void CodeGenFunction::EmitMessageHook(llvm::CallInst *_class,
534534
"MSHookMessageEx");
535535

536536
cast<llvm::Function>(msHookMsgExFn.getCallee())->setLinkage(llvm::Function::ExternalWeakLinkage);
537-
538537
llvm::Value *msHookMsgExArgs[4];
538+
539+
llvm::Value *targetValue = Builder.CreateBitCast(hook, Int8PtrTy);
540+
if (auto &schema =
541+
CGM.getCodeGenOpts().PointerAuth.FunctionPointers)
542+
{
543+
auto authInfo = EmitPointerAuthInfo(schema, targetValue,
544+
GlobalDecl(), QualType());
545+
msHookMsgExArgs[2] = EmitPointerAuthSign(authInfo, targetValue);
546+
}
547+
else
548+
msHookMsgExArgs[2] = Builder.CreateBitCast(hook, Int8PtrTy);
549+
539550
msHookMsgExArgs[0] = Builder.CreateBitCast(_class, Int8PtrTy);
540551
msHookMsgExArgs[1] = Builder.CreateBitCast(message, Int8PtrTy);
541-
msHookMsgExArgs[2] = Builder.CreateBitCast(hook, Int8PtrTy);
542552
msHookMsgExArgs[3] = Builder.CreateBitCast(old, Int8PtrTy);
543553

544554
EmitRuntimeCallOrInvoke(msHookMsgExFn, msHookMsgExArgs);
@@ -843,7 +853,13 @@ llvm::Value* CodeGenFunction::EmitObjCOrigExpr(const ObjCOrigExpr *E) {
843853

844854
// Emit self, _cmd
845855
Args.add(RValue::get(LoadObjCSelf()), getContext().getObjCIdType());
846-
Args.add(RValue::get(Runtime.GetSelector(*this, OMD->getSelector())),
856+
857+
// instead of re-emitting the method decl, we can just pass through the existing arg we got
858+
VarDecl *Sel = cast<ObjCMethodDecl>(CurFuncDecl)->getCmdDecl();
859+
DeclRefExpr DRE(getContext(), Sel,
860+
/*is enclosing local*/ (CurFuncDecl != CurCodeDecl),
861+
getContext().getObjCSelType(), VK_LValue, SourceLocation());
862+
Args.add(RValue::get(EmitLoadOfScalar(EmitDeclRefLValue(&DRE), SourceLocation())),
847863
getContext().getObjCSelType());
848864

849865
// Emit arguments
@@ -869,7 +885,13 @@ llvm::Value* CodeGenFunction::EmitObjCOrigExpr(const ObjCOrigExpr *E) {
869885

870886
llvm::Value *Fn = Builder.CreateAlignedLoad(VoidPtrTy, OHD->GetOrigPointer(OMD), getPointerAlign());
871887
llvm::Value* FnV = Builder.CreateBitCast(Fn, MSI.MessengerType);
872-
CGCallee Callee = CGCallee(CGCalleeInfo(), FnV, CGPointerAuthInfo());
888+
889+
CGPointerAuthInfo pointerAuth = CGPointerAuthInfo();
890+
if (auto &schema =
891+
CGM.getCodeGenOpts().PointerAuth.FunctionPointers) {
892+
pointerAuth = EmitPointerAuthInfo(schema, FnV,GlobalDecl(), QualType());
893+
}
894+
CGCallee Callee = CGCallee(CGCalleeInfo(), FnV, pointerAuth);
873895

874896
RValue rvalue = EmitCall(MSI.CallInfo, Callee, ReturnValueSlot(), Args);
875897

0 commit comments

Comments
 (0)