Skip to content

Commit 1427199

Browse files
authored
Avoid linker symbol de-duplication in 'failureBreakpoint()' marker function (#498)
This fixes an issue where the setting a debugger breakpoint on the special `failureBreakpoint()` marker function (which is used to break on test failures) may cause the debugger to resolve to the incorrect symbol in release builds due to linker de-duplication. See code comment for additional details. ### Result: Confirmed this resolved the issue in a manually built release build of the testing library. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated. Resolves rdar://129872111
1 parent 8983930 commit 1427199

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/Testing/Issues/Issue+Recording.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,17 @@ extension Issue {
259259
@inline(never) @_optimize(none)
260260
@usableFromInline
261261
func failureBreakpoint() {
262-
// Empty.
262+
// This function's body cannot be completely empty or else linker symbol
263+
// de-duplication will cause its symbol to be consolidated with that of
264+
// another, arbitrarily chosen empty function in this module. This linker
265+
// behavior can be disabled by passing the `-no_deduplicate` flag described in
266+
// ld(1), but that would disable it module-wide and sacrifice optimization
267+
// opportunities elsewhere. Instead, this function performs a trivial
268+
// function call, passing it a sufficiently unique value to avoid
269+
// de-duplication.
270+
struct NoOp {
271+
nonisolated(unsafe) static var ignored: Int = 0
272+
static func perform(_: inout Int) {}
273+
}
274+
NoOp.perform(&NoOp.ignored)
263275
}

0 commit comments

Comments
 (0)