Skip to content

Commit 235c27b

Browse files
committed
Don't keep generic versions of PtrAuth functions alive
We don't support generating code for ptrauth builtins with generic inputs (or non-constant inputs). We rely on specialization/inlining for such code to work. After a recent commit (#68843 ) code in IRGen keeps internal unreferenced functions alive for debugging purposes. This is a problem for the generic functions in PtrAuth.swift using ptrauth builtins. Opt out of this new behavior by sprinkling some pixie dust. Fixes debug swift standard library builds targeting arm64e. rdar://117411740
1 parent 7c6dacb commit 235c27b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/SIL/IR/SILFunction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,9 @@ bool SILFunction::shouldBePreservedForDebugger() const {
881881
if (getEffectiveOptimizationMode() != OptimizationMode::NoOptimization)
882882
return false;
883883

884+
if (hasSemanticsAttr("no.preserve.debugger"))
885+
return false;
886+
884887
// Only keep functions defined in this module.
885888
if (!isDefinition())
886889
return false;

stdlib/public/core/PtrAuth.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ internal enum _PtrAuth {
9595
}
9696

9797
/// Sign an unauthenticated pointer.
98+
@_semantics("no.preserve.debugger") // Relies on inlining this function.
9899
@_transparent
99100
static func sign(pointer: UnsafeRawPointer,
100101
key: Key,
@@ -110,6 +111,7 @@ internal enum _PtrAuth {
110111

111112
/// Authenticate a pointer using one scheme and resign it using another.
112113
@_transparent
114+
@_semantics("no.preserve.debugger") // Relies on inlining this function.
113115
static func authenticateAndResign(pointer: UnsafeRawPointer,
114116
oldKey: Key,
115117
oldDiscriminator: UInt64,
@@ -127,6 +129,7 @@ internal enum _PtrAuth {
127129
}
128130

129131
/// Get the type-specific discriminator for a function type.
132+
@_semantics("no.preserve.debugger") // Don't keep the generic version alive
130133
@_transparent
131134
static func discriminator<T>(for type: T.Type) -> UInt64 {
132135
return UInt64(Builtin.typePtrAuthDiscriminator(type))
@@ -175,6 +178,7 @@ internal enum _PtrAuth {
175178
extension UnsafeRawPointer {
176179
/// Load a function pointer from memory that has been authenticated
177180
/// specifically for its given address.
181+
@_semantics("no.preserve.debugger") // Don't keep the generic version alive
178182
@_transparent
179183
internal func _loadAddressDiscriminatedFunctionPointer<T>(
180184
fromByteOffset offset: Int = 0,
@@ -196,6 +200,7 @@ extension UnsafeRawPointer {
196200
return unsafeBitCast(resigned, to: type)
197201
}
198202

203+
@_semantics("no.preserve.debugger") // Don't keep the generic version alive
199204
@_transparent
200205
internal func _loadAddressDiscriminatedFunctionPointer<T>(
201206
fromByteOffset offset: Int = 0,

0 commit comments

Comments
 (0)