Skip to content

Commit 30d0a06

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.6-beta.1 [skip ci]
1 parent 4a64193 commit 30d0a06

File tree

6 files changed

+201
-108
lines changed

6 files changed

+201
-108
lines changed

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11751175
<< " cannot be used against ifunc symbol '" << &sym << "'";
11761176
printLocation(diag, *sec, sym, offset);
11771177
} else {
1178-
part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset,
1179-
DynamicReloc::AddendOnlyWithTargetVA, sym,
1180-
addend, R_ABS});
1178+
part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset, false,
1179+
sym, addend, R_ABS});
11811180
return;
11821181
}
11831182
}

llvm/docs/LangRef.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31200,14 +31200,14 @@ third argument is 1). When loading from the pointer, the inverse operation
3120031200
is done on the loaded pointer after it is loaded. Specifically, when the
3120131201
third argument is 1, the pointer is signed (using pointer authentication
3120231202
instructions or emulated PAC if not supported by the hardware) using
31203-
the struct address before being stored, and authenticated after being
31203+
the discriminator before being stored, and authenticated after being
3120431204
loaded. Note that it is currently unsupported to have the third argument
3120531205
be 1 on targets other than AArch64. When the third argument is 0, it is
3120631206
rotated left by 16 bits and the discriminator is subtracted before being
3120731207
stored, and the discriminator is added and the pointer is rotated right
3120831208
by 16 bits after being loaded.
3120931209

31210-
If the pointer is used otherwise than for loading or storing (e.g. its
31210+
If the pointer is used other than for loading or storing (e.g. its
3121131211
address escapes), that will disable all blending operations using
3121231212
the deactivation symbol specified in the intrinsic's operand bundle.
3121331213
The deactivation symbol operand bundle is copied onto any sign and auth

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#include "llvm/Transforms/Utils/LowerMemIntrinsics.h"
4040
#include "llvm/Transforms/Utils/LowerVectorIntrinsics.h"
4141

42-
#include <set>
43-
4442
using namespace llvm;
4543

4644
/// Threshold to leave statically sized memory intrinsic calls. Calls of known
@@ -476,8 +474,8 @@ enum class PointerEncoding {
476474
bool expandProtectedFieldPtr(Function &Intr) {
477475
Module &M = *Intr.getParent();
478476

479-
std::set<GlobalValue *> DSsToDeactivate;
480-
std::set<Instruction *> LoadsStores;
477+
SmallPtrSet<GlobalValue *, 2> DSsToDeactivate;
478+
SmallPtrSet<Instruction *, 2> LoadsStores;
481479

482480
Type *Int8Ty = Type::getInt8Ty(M.getContext());
483481
Type *Int64Ty = Type::getInt64Ty(M.getContext());
@@ -520,111 +518,75 @@ bool expandProtectedFieldPtr(Function &Intr) {
520518
for (User *U : Intr.users()) {
521519
auto *Call = cast<CallInst>(U);
522520
auto *DS = GetDeactivationSymbol(Call);
523-
std::set<PHINode *> VisitedPhis;
524-
525-
std::function<void(Instruction *)> FindLoadsStores;
526-
FindLoadsStores = [&](Instruction *I) {
527-
for (Use &U : I->uses()) {
528-
if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
529-
if (isa<PointerType>(LI->getType())) {
530-
LoadsStores.insert(LI);
531-
continue;
532-
}
533-
}
534-
if (auto *SI = dyn_cast<StoreInst>(U.getUser())) {
535-
if (U.getOperandNo() == 1 &&
536-
isa<PointerType>(SI->getValueOperand()->getType())) {
537-
LoadsStores.insert(SI);
538-
continue;
539-
}
540-
}
541-
if (auto *P = dyn_cast<PHINode>(U.getUser())) {
542-
if (VisitedPhis.insert(P).second)
543-
FindLoadsStores(P);
521+
522+
for (Use &U : Call->uses()) {
523+
if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
524+
if (isa<PointerType>(LI->getType())) {
525+
LoadsStores.insert(LI);
544526
continue;
545527
}
546-
// Comparisons against null cannot be used to recover the original
547-
// pointer so we allow them.
548-
if (auto *CI = dyn_cast<ICmpInst>(U.getUser())) {
549-
if (auto *Op = dyn_cast<Constant>(CI->getOperand(0)))
550-
if (Op->isNullValue())
551-
continue;
552-
if (auto *Op = dyn_cast<Constant>(CI->getOperand(1)))
553-
if (Op->isNullValue())
554-
continue;
555-
}
556-
if (DS)
557-
DSsToDeactivate.insert(DS);
558528
}
559-
};
560-
561-
FindLoadsStores(Call);
562-
}
563-
564-
for (Instruction *I : LoadsStores) {
565-
std::set<Value *> Pointers;
566-
std::set<Value *> Discs;
567-
std::set<GlobalValue *> DSs;
568-
std::set<PHINode *> VisitedPhis;
569-
bool UseHWEncoding = false;
570-
571-
std::function<void(Value *)> FindFields;
572-
FindFields = [&](Value *V) {
573-
if (auto *Call = dyn_cast<CallInst>(V)) {
574-
if (Call->getCalledOperand() == &Intr) {
575-
Pointers.insert(Call->getArgOperand(0));
576-
Discs.insert(Call->getArgOperand(1));
577-
if (cast<ConstantInt>(Call->getArgOperand(2))->getZExtValue())
578-
UseHWEncoding = true;
579-
DSs.insert(GetDeactivationSymbol(Call));
580-
return;
529+
if (auto *SI = dyn_cast<StoreInst>(U.getUser())) {
530+
if (U.getOperandNo() == 1 &&
531+
isa<PointerType>(SI->getValueOperand()->getType())) {
532+
LoadsStores.insert(SI);
533+
continue;
581534
}
582535
}
583-
if (auto *P = dyn_cast<PHINode>(V)) {
584-
if (VisitedPhis.insert(P).second)
585-
for (Value *V : P->incoming_values())
586-
FindFields(V);
587-
return;
536+
// Comparisons against null cannot be used to recover the original
537+
// pointer so we allow them.
538+
if (auto *CI = dyn_cast<ICmpInst>(U.getUser())) {
539+
if (auto *Op = dyn_cast<Constant>(CI->getOperand(0)))
540+
if (Op->isNullValue())
541+
continue;
542+
if (auto *Op = dyn_cast<Constant>(CI->getOperand(1)))
543+
if (Op->isNullValue())
544+
continue;
588545
}
589-
Pointers.insert(nullptr);
590-
};
591-
FindFields(isa<StoreInst>(I) ? cast<StoreInst>(I)->getPointerOperand()
592-
: cast<LoadInst>(I)->getPointerOperand());
593-
if (Pointers.size() != 1 || Discs.size() != 1 || DSs.size() != 1) {
594-
for (GlobalValue *DS : DSs)
595-
if (DS)
596-
DSsToDeactivate.insert(DS);
597-
continue;
546+
if (DS)
547+
DSsToDeactivate.insert(DS);
598548
}
549+
}
550+
551+
for (Instruction *I : LoadsStores) {
552+
auto *PointerOperand = isa<StoreInst>(I)
553+
? cast<StoreInst>(I)->getPointerOperand()
554+
: cast<LoadInst>(I)->getPointerOperand();
555+
auto *Call = cast<CallInst>(PointerOperand);
556+
557+
auto *Disc = Call->getArgOperand(1);
558+
bool UseHWEncoding = cast<ConstantInt>(Call->getArgOperand(2))->getZExtValue();
599559

600-
GlobalValue *DS = *DSs.begin();
560+
GlobalValue *DS = GetDeactivationSymbol(Call);
601561
OperandBundleDef DSBundle("deactivation-symbol", DS);
602562

603563
if (auto *LI = dyn_cast<LoadInst>(I)) {
604564
IRBuilder<> B(LI->getNextNode());
605565
auto *LIInt = cast<Instruction>(B.CreatePtrToInt(LI, B.getInt64Ty()));
606566
Value *Auth;
607567
if (UseHWEncoding) {
608-
Auth = CreateAuth(B, LIInt, *Discs.begin(), DSBundle);
568+
Auth = CreateAuth(B, LIInt, Disc, DSBundle);
609569
} else {
610-
Auth = B.CreateAdd(LIInt, *Discs.begin());
570+
Auth = B.CreateAdd(LIInt, Disc);
611571
Auth = B.CreateIntrinsic(
612572
Auth->getType(), Intrinsic::fshr,
613573
{Auth, Auth, ConstantInt::get(Auth->getType(), 16)});
614574
}
615575
LI->replaceAllUsesWith(B.CreateIntToPtr(Auth, B.getPtrTy()));
616576
LIInt->setOperand(0, LI);
617-
} else if (auto *SI = dyn_cast<StoreInst>(I)) {
577+
} else {
578+
auto *SI = cast<StoreInst>(I);
618579
IRBuilder<> B(SI);
619580
auto *SIValInt =
620581
B.CreatePtrToInt(SI->getValueOperand(), B.getInt64Ty());
621582
Value *Sign;
622583
if (UseHWEncoding) {
623-
Sign = CreateSign(B, SIValInt, *Discs.begin(), DSBundle);
584+
Sign = CreateSign(B, SIValInt, Disc, DSBundle);
624585
} else {
625586
Sign = B.CreateIntrinsic(
626587
SIValInt->getType(), Intrinsic::fshl,
627588
{SIValInt, SIValInt, ConstantInt::get(SIValInt->getType(), 16)});
589+
Sign = B.CreateSub(Sign, Disc);
628590
}
629591
SI->setOperand(0, B.CreateIntToPtr(Sign, B.getPtrTy()));
630592
}

llvm/lib/IR/Verifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,11 @@ void Verifier::visitConstantPtrAuth(const ConstantPtrAuth *CPA) {
26272627

26282628
Check(CPA->getDiscriminator()->getBitWidth() == 64,
26292629
"signed ptrauth constant discriminator must be i64 constant integer");
2630+
2631+
Check(isa<GlobalValue>(CPA->getDeactivationSymbol()) ||
2632+
CPA->getDeactivationSymbol()->isNullValue(),
2633+
"signed ptrauth constant deactivation symbol must be a global value "
2634+
"or null");
26302635
}
26312636

26322637
bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) {

0 commit comments

Comments
 (0)