Skip to content

Commit

Permalink
Don't re-emit _cmd, Fix pointer auth emission in CGLogos
Browse files Browse the repository at this point in the history
  • Loading branch information
vr1s committed Apr 2, 2023
1 parent dc3cff3 commit 6317608
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions clang/lib/CodeGen/CGLogos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,21 @@ void CodeGenFunction::EmitMessageHook(llvm::CallInst *_class,
"MSHookMessageEx");

cast<llvm::Function>(msHookMsgExFn.getCallee())->setLinkage(llvm::Function::ExternalWeakLinkage);

llvm::Value *msHookMsgExArgs[4];

llvm::Value *targetValue = Builder.CreateBitCast(hook, Int8PtrTy);
if (auto &schema =
CGM.getCodeGenOpts().PointerAuth.FunctionPointers)
{
auto authInfo = EmitPointerAuthInfo(schema, targetValue,
GlobalDecl(), QualType());
msHookMsgExArgs[2] = EmitPointerAuthSign(authInfo, targetValue);
}
else
msHookMsgExArgs[2] = Builder.CreateBitCast(hook, Int8PtrTy);

msHookMsgExArgs[0] = Builder.CreateBitCast(_class, Int8PtrTy);
msHookMsgExArgs[1] = Builder.CreateBitCast(message, Int8PtrTy);
msHookMsgExArgs[2] = Builder.CreateBitCast(hook, Int8PtrTy);
msHookMsgExArgs[3] = Builder.CreateBitCast(old, Int8PtrTy);

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

// Emit self, _cmd
Args.add(RValue::get(LoadObjCSelf()), getContext().getObjCIdType());
Args.add(RValue::get(Runtime.GetSelector(*this, OMD->getSelector())),

// instead of re-emitting the method decl, we can just pass through the existing arg we got
VarDecl *Sel = cast<ObjCMethodDecl>(CurFuncDecl)->getCmdDecl();
DeclRefExpr DRE(getContext(), Sel,
/*is enclosing local*/ (CurFuncDecl != CurCodeDecl),
getContext().getObjCSelType(), VK_LValue, SourceLocation());
Args.add(RValue::get(EmitLoadOfScalar(EmitDeclRefLValue(&DRE), SourceLocation())),
getContext().getObjCSelType());

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

llvm::Value *Fn = Builder.CreateAlignedLoad(VoidPtrTy, OHD->GetOrigPointer(OMD), getPointerAlign());
llvm::Value* FnV = Builder.CreateBitCast(Fn, MSI.MessengerType);
CGCallee Callee = CGCallee(CGCalleeInfo(), FnV, CGPointerAuthInfo());

CGPointerAuthInfo pointerAuth = CGPointerAuthInfo();
if (auto &schema =
CGM.getCodeGenOpts().PointerAuth.FunctionPointers) {
pointerAuth = EmitPointerAuthInfo(schema, FnV,GlobalDecl(), QualType());
}
CGCallee Callee = CGCallee(CGCalleeInfo(), FnV, pointerAuth);

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

Expand Down

0 comments on commit 6317608

Please sign in to comment.