Skip to content

Commit 88ae5bd

Browse files
authored
[PAC] Make ValueMapper handle ConstantPtrAuth values (llvm#129088)
Fix assertion failure when building PAuth-hardened code with LTO. W/o assertions we end with invalid codegen.
1 parent f9b2497 commit 88ae5bd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/Transforms/Utils/ValueMapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ Value *Mapper::mapValue(const Value *V) {
525525
return getVM()[V] = ConstantStruct::get(cast<StructType>(NewTy), Ops);
526526
if (isa<ConstantVector>(C))
527527
return getVM()[V] = ConstantVector::get(Ops);
528+
if (isa<ConstantPtrAuth>(C))
529+
return getVM()[V] = ConstantPtrAuth::get(Ops[0], cast<ConstantInt>(Ops[1]),
530+
cast<ConstantInt>(Ops[2]), Ops[3]);
528531
// If this is a no-operand constant, it must be because the type was remapped.
529532
if (isa<PoisonValue>(C))
530533
return getVM()[V] = PoisonValue::get(NewTy);

llvm/unittests/Transforms/Utils/ValueMapperTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,34 @@ TEST(ValueMapperTest, mapValueConstantTargetNoneToLayoutTypeNullValue) {
436436
EXPECT_EQ(NewConstant, Mapper.mapValue(*OldConstant));
437437
}
438438

439+
TEST(ValueMapperTest, mapValuePtrAuth) {
440+
LLVMContext C;
441+
Type *PtrTy = PointerType::get(C, 0);
442+
IntegerType *Int32Ty = Type::getInt32Ty(C);
443+
IntegerType *Int64Ty = Type::getInt64Ty(C);
444+
445+
std::unique_ptr<GlobalVariable> Var0 = std::make_unique<GlobalVariable>(
446+
PtrTy, false, GlobalValue::ExternalLinkage, nullptr, "Var0");
447+
std::unique_ptr<GlobalVariable> Var1 = std::make_unique<GlobalVariable>(
448+
PtrTy, false, GlobalValue::ExternalLinkage, nullptr, "Var1");
449+
std::unique_ptr<GlobalVariable> Storage0 = std::make_unique<GlobalVariable>(
450+
PtrTy, false, GlobalValue::ExternalLinkage, nullptr, "Storage0");
451+
std::unique_ptr<GlobalVariable> Storage1 = std::make_unique<GlobalVariable>(
452+
PtrTy, false, GlobalValue::ExternalLinkage, nullptr, "Storage1");
453+
454+
ConstantInt *ConstKey = ConstantInt::get(Int32Ty, 1);
455+
ConstantInt *ConstDisc = ConstantInt::get(Int64Ty, 1234);
456+
457+
ValueToValueMapTy VM;
458+
VM[Var0.get()] = Var1.get();
459+
VM[Storage0.get()] = Storage1.get();
460+
461+
ConstantPtrAuth *Value =
462+
ConstantPtrAuth::get(Var0.get(), ConstKey, ConstDisc, Storage0.get());
463+
ConstantPtrAuth *MappedValue =
464+
ConstantPtrAuth::get(Var1.get(), ConstKey, ConstDisc, Storage1.get());
465+
466+
EXPECT_EQ(ValueMapper(VM).mapValue(*Value), MappedValue);
467+
}
468+
439469
} // end namespace

0 commit comments

Comments
 (0)