mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[IRGen] Address-discriminate these ptrauth ents.
They are stored at an address so that address should be used to strengthen auth.
This commit is contained in:
@@ -801,17 +801,24 @@ struct Allocator {
|
||||
Allocator(llvm::Value *address, IRGenFunction &IGF)
|
||||
: address(address), IGF(IGF) {}
|
||||
|
||||
llvm::Value *getField(Field field) {
|
||||
struct FieldLoad {
|
||||
llvm::Value *address;
|
||||
llvm::Value *value;
|
||||
};
|
||||
|
||||
FieldLoad loadField(Field field) {
|
||||
auto *fieldAddress = IGF.Builder.CreateInBoundsGEP(
|
||||
IGF.IGM.CoroAllocatorTy, address,
|
||||
{llvm::ConstantInt::get(IGF.IGM.Int32Ty, 0),
|
||||
llvm::ConstantInt::get(IGF.IGM.Int32Ty, field.kind)});
|
||||
return IGF.Builder.CreateLoad(Address(fieldAddress, field.getType(IGF.IGM),
|
||||
field.getAlignment(IGF.IGM)),
|
||||
field.getName());
|
||||
auto *value =
|
||||
IGF.Builder.CreateLoad(Address(fieldAddress, field.getType(IGF.IGM),
|
||||
field.getAlignment(IGF.IGM)),
|
||||
field.getName());
|
||||
return {fieldAddress, value};
|
||||
}
|
||||
|
||||
llvm::Value *getFlags() { return getField(Field::Flags); }
|
||||
llvm::Value *getFlags() { return loadField(Field::Flags).value; }
|
||||
|
||||
FunctionPointer getAllocate(AllocationKind kind) {
|
||||
switch (kind) {
|
||||
@@ -862,10 +869,11 @@ private:
|
||||
}
|
||||
|
||||
FunctionPointer getFunctionPointer(Field field) {
|
||||
llvm::Value *callee = getField(field);
|
||||
auto fieldValues = loadField(field);
|
||||
auto *callee = fieldValues.value;
|
||||
if (auto &schema = field.getSchema(IGF.IGM)) {
|
||||
auto info =
|
||||
PointerAuthInfo::emit(IGF, schema, nullptr, PointerAuthEntity());
|
||||
auto info = PointerAuthInfo::emit(IGF, schema, fieldValues.address,
|
||||
field.getEntity(IGF.IGM));
|
||||
callee = emitPointerAuthAuth(IGF, callee, info);
|
||||
}
|
||||
return FunctionPointer::createUnsigned(
|
||||
|
||||
@@ -1087,19 +1087,19 @@ static void setPointerAuthOptions(PointerAuthOptions &opts,
|
||||
PointerAuthSchema(nonABIDataKey, /*address*/ true, Discrimination::Decl);
|
||||
|
||||
opts.CoroAllocationFunction = PointerAuthSchema(
|
||||
codeKey, /*address*/ false, Discrimination::Constant,
|
||||
codeKey, /*address*/ true, Discrimination::Constant,
|
||||
SpecialPointerAuthDiscriminators::CoroAllocationFunction);
|
||||
|
||||
opts.CoroDeallocationFunction = PointerAuthSchema(
|
||||
codeKey, /*address*/ false, Discrimination::Constant,
|
||||
codeKey, /*address*/ true, Discrimination::Constant,
|
||||
SpecialPointerAuthDiscriminators::CoroDeallocationFunction);
|
||||
|
||||
opts.CoroFrameAllocationFunction = PointerAuthSchema(
|
||||
codeKey, /*address*/ false, Discrimination::Constant,
|
||||
codeKey, /*address*/ true, Discrimination::Constant,
|
||||
SpecialPointerAuthDiscriminators::CoroFrameAllocationFunction);
|
||||
|
||||
opts.CoroFrameDeallocationFunction = PointerAuthSchema(
|
||||
codeKey, /*address*/ false, Discrimination::Constant,
|
||||
codeKey, /*address*/ true, Discrimination::Constant,
|
||||
SpecialPointerAuthDiscriminators::CoroFrameDeallocationFunction);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,28 +26,52 @@
|
||||
// CHECK-arm64e-LABEL: _swift_coro_malloc.ptrauth = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_malloc,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_malloc_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 1
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 24469 }
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth"
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
// CHECK-arm64e-LABEL: _swift_coro_free.ptrauth = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_free,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_malloc_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 2
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 40879 },
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth",
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
// CHECK-arm64e-LABEL: _swift_coro_malloc.ptrauth.1 = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_malloc,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_malloc_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 3
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 53841 }
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth"
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
// CHECK-arm64e-LABEL: _swift_coro_free.ptrauth.2 = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_free,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_malloc_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 4
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 23464 },
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth",
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
@@ -65,28 +89,52 @@
|
||||
// CHECK-arm64e-LABEL: _swift_coro_task_alloc.ptrauth = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_task_alloc,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_async_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 1
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 24469 }
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth"
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
// CHECK-arm64e-LABEL: @_swift_coro_task_dealloc.ptrauth = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_task_dealloc,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_async_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 2
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 40879 },
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth",
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
// CHECK-arm64e-LABEL: _swift_coro_task_alloc.ptrauth.3 = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_task_alloc,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_async_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 3
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 53841 }
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth"
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
// CHECK-arm64e-LABEL: @_swift_coro_task_dealloc.ptrauth.4 = private constant {
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_task_dealloc,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i64 0,
|
||||
// CHECK-arm64e-SAME: i64 ptrtoint (
|
||||
// CHECK-arm64e-SAME: ptr getelementptr inbounds (
|
||||
// CHECK-arm64e-SAME: ptr @_swift_coro_async_allocator,
|
||||
// CHECK-arm64e-SAME: i32 0,
|
||||
// CHECK-arm64e-SAME: i32 4
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: )
|
||||
// CHECK-arm64e-SAME: i64 23464 },
|
||||
// CHECK-arm64e-SAME: section "llvm.ptrauth",
|
||||
// CHECK-arm64e-SAME: align 8
|
||||
@@ -114,8 +162,10 @@
|
||||
// CHECK-SAME: i32 0
|
||||
// CHECK-SAME: i32 1
|
||||
// CHECK: [[ALLOCATE_FN:%[^,]+]] = load ptr, ptr [[ALLOCATE_FN_PTR]]
|
||||
// CHECK-arm64e: [[ALLOCATE_FN_PTR_BITS:%[^,]+]] = ptrtoint ptr [[ALLOCATE_FN_PTR]] to i64
|
||||
// CHECK-arm64e: [[ALLOCATE_FN_DISCRIMINATOR:%[^,]+]] = call i64 @llvm.ptrauth.blend(i64 [[ALLOCATE_FN_PTR_BITS]], i64 24469)
|
||||
// CHECK-arm64e: [[ALLOCATE_FN_BITS:%[^,]+]] = ptrtoint ptr [[ALLOCATE_FN]] to i64
|
||||
// CHECK-arm64e: [[ALLOCATE_FN_BITS_AUTHED:%[^,]+]] = call i64 @llvm.ptrauth.auth(i64 [[ALLOCATE_FN_BITS]], i32 0, i64 24469)
|
||||
// CHECK-arm64e: [[ALLOCATE_FN_BITS_AUTHED:%[^,]+]] = call i64 @llvm.ptrauth.auth(i64 [[ALLOCATE_FN_BITS]], i32 0, i64 [[ALLOCATE_FN_DISCRIMINATOR]])
|
||||
// CHECK-arm64e: [[ALLOCATE_FN:%[^,]+]] = inttoptr i64 [[ALLOCATE_FN_BITS_AUTHED]]
|
||||
// CHECK: [[ALLOCATION:%[^,]+]] = call swiftcc ptr [[ALLOCATE_FN]](ptr [[FRAME]], ptr swiftcoro [[ALLOCATOR]], [[INT]] [[SIZE]])
|
||||
// CHECK: ret ptr [[ALLOCATION]]
|
||||
@@ -146,8 +196,10 @@
|
||||
// CHECK-SAME: i32 0
|
||||
// CHECK-SAME: i32 2
|
||||
// CHECK: [[DEALLOCATE_FN:%[^,]+]] = load ptr, ptr [[DEALLOCATE_FN_PTR]]
|
||||
// CHECK-arm64e: [[DEALLOCATE_FN_PTR_BITS:%[^,]+]] = ptrtoint ptr [[DEALLOCATE_FN_PTR]] to i64
|
||||
// CHECK-arm64e: [[DEALLOCATE_FN_DISCRIMINATOR:%[^,]+]] = call i64 @llvm.ptrauth.blend(i64 [[DEALLOCATE_FN_PTR_BITS]], i64 40879)
|
||||
// CHECK-arm64e: [[DEALLOCATE_FN_BITS:%[^,]+]] = ptrtoint ptr [[DEALLOCATE_FN]] to i64
|
||||
// CHECK-arm64e: [[DEALLOCATE_FN_BITS_AUTHED:%[^,]+]] = call i64 @llvm.ptrauth.auth(i64 [[DEALLOCATE_FN_BITS]], i32 0, i64 40879)
|
||||
// CHECK-arm64e: [[DEALLOCATE_FN_BITS_AUTHED:%[^,]+]] = call i64 @llvm.ptrauth.auth(i64 [[DEALLOCATE_FN_BITS]], i32 0, i64 [[DEALLOCATE_FN_DISCRIMINATOR]])
|
||||
// CHECK-arm64e: [[DEALLOCATE_FN:%[^,]+]] = inttoptr i64 [[DEALLOCATE_FN_BITS_AUTHED]]
|
||||
// CHECK: call swiftcc void [[DEALLOCATE_FN]](ptr [[FRAME]], ptr swiftcoro [[ALLOCATOR]], ptr [[ADDRESS]])
|
||||
// CHECK: ret void
|
||||
|
||||
Reference in New Issue
Block a user