Skip to content

Don't keep generic versions of PtrAuth functions alive #69373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/SIL/IR/SILFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ bool SILFunction::shouldBePreservedForDebugger() const {
if (getEffectiveOptimizationMode() != OptimizationMode::NoOptimization)
return false;

if (hasSemanticsAttr("no.preserve.debugger"))
return false;

// Only keep functions defined in this module.
if (!isDefinition())
return false;
Expand Down
5 changes: 5 additions & 0 deletions stdlib/public/core/PtrAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal enum _PtrAuth {
}

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

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

/// Get the type-specific discriminator for a function type.
@_semantics("no.preserve.debugger") // Don't keep the generic version alive
@_transparent
static func discriminator<T>(for type: T.Type) -> UInt64 {
return UInt64(Builtin.typePtrAuthDiscriminator(type))
Expand Down Expand Up @@ -175,6 +178,7 @@ internal enum _PtrAuth {
extension UnsafeRawPointer {
/// Load a function pointer from memory that has been authenticated
/// specifically for its given address.
@_semantics("no.preserve.debugger") // Don't keep the generic version alive
@_transparent
internal func _loadAddressDiscriminatedFunctionPointer<T>(
fromByteOffset offset: Int = 0,
Expand All @@ -196,6 +200,7 @@ extension UnsafeRawPointer {
return unsafeBitCast(resigned, to: type)
}

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