Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a272583
test: keep the projected opaque member fixture building on Xcode 27
Mx-Iris Sep 26, 2026
2a398f8
build(deps): raise the MachOKitExtensions floor to 0.1.2
Mx-Iris Sep 26, 2026
5a916b7
Merge branch 'fix/image-cache-membership' into next
Mx-Iris Sep 26, 2026
3b6672e
Merge remote-tracking branch 'origin/main' into merge/main-into-next
Mx-Iris Sep 27, 2026
28c0e6c
feat: print @objc(Name) on classes renamed for the ObjC runtime
Mx-Iris Sep 27, 2026
a951036
test: pin renamed-class recovery with an on-the-fly fixture
Mx-Iris Sep 27, 2026
b521c33
docs: document renamed-class recovery (evolution objc-custom-class-name)
Mx-Iris Sep 27, 2026
1791515
docs: add evolution proposal draft-shared-cache-composition-and-evict…
Mx-Iris Sep 28, 2026
c1508c9
fix(MachOCaches): trap on same-thread re-entrant builds instead of ha…
Mx-Iris Sep 28, 2026
cecf914
perf(MachOCaches): key cache entries on SharedCacheKey instead of a b…
Mx-Iris Sep 28, 2026
f07d238
refactor(MachOCaches): compose SharedCache instead of subclassing it
Mx-Iris Sep 28, 2026
3842897
refactor(MachOCaches): move per-image eviction into SharedCacheRegist…
Mx-Iris Sep 28, 2026
deec176
test(MachOCaches): prove distinct-key overlap with two builds, not eight
Mx-Iris Sep 28, 2026
d4b4d29
docs: document the per-image cache primitive and its eviction registry
Mx-Iris Sep 28, 2026
8e2aea7
refactor(MachOCaches): make SharedCacheEvictionGroup an open type dec…
Mx-Iris Sep 28, 2026
30bf459
test(MachOCaches): run the distinct-key rendezvous on dedicated threads
Mx-Iris Sep 28, 2026
500f3cc
fix(printing): read initializer failability off the initializer's own…
Mx-Iris Sep 28, 2026
15313ae
feat(interface): build class vtable members from their method descrip…
Mx-Iris Sep 28, 2026
04f3d73
chore(scripts): point the rendering A/B harness at the 26.6.2 archive…
Mx-Iris Sep 28, 2026
284b39b
docs: document descriptor-only vtable members (evolution interface-de…
Mx-Iris Sep 28, 2026
c5433fc
build(deps): raise the swift-capstone floor to 6.0.1
Mx-Iris Sep 28, 2026
05eb8f5
docs: record the local-type context names gap as a roadmap item
Mx-Iris Sep 28, 2026
e9ad5bb
docs: drop a duplicated 0050 decision row and fix a stale proposal link
Mx-Iris Sep 28, 2026
ac9da4c
Merge remote-tracking branch 'origin/feature/shared-cache-composition…
Mx-Iris Sep 28, 2026
1437925
Merge remote-tracking branch 'origin/feature/interface-vtable-members…
Mx-Iris Sep 28, 2026
8fb9deb
docs: number the three landed proposals for 0.21.0
Mx-Iris Sep 29, 2026
3303cbf
release: 0.21.0
Mx-Iris Sep 29, 2026
8de6062
Merge branch 'release/0.21.0' into next
Mx-Iris Sep 29, 2026
e473b89
ci(diagnostics): capture where the macOS test run stalls
Mx-Iris Sep 29, 2026
b6743bd
test(MachOCaches): stop three SharedCache tests from freezing a 3-thr…
Mx-Iris Sep 29, 2026
bc96700
ci(diagnostics): enable testability for the release build; add the on…
Mx-Iris Sep 29, 2026
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
115 changes: 111 additions & 4 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
macos_test:
name: Execute tests on macOS
runs-on: ${{ matrix.os }}
# DIAGNOSTICS BRANCH — not for merging. Fail a stalled run instead of
# letting it sit until GitHub's 360-minute default.
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -99,8 +102,10 @@ jobs:
path: Tests/Projects/SymbolTests/DerivedData/Logs
if-no-files-found: ignore

- name: Cache SwiftPM build directory
uses: actions/cache@v4
- name: Restore SwiftPM build directory
# Restore only: a diagnostics PR must not save another 2.5 GB
# PR-scoped cache and push main's caches out of the 10 GB quota.
uses: actions/cache/restore@v4
with:
path: .build-test-${{ matrix.configuration }}
# This step runs after `swift package update`, so the key hashes the
Expand All @@ -111,10 +116,112 @@ jobs:
restore-keys: |
spm-build-${{ matrix.os }}-${{ matrix.xcode-version }}-${{ matrix.configuration }}-

- name: Build and run tests (${{ matrix.configuration }})
- name: Build tests (${{ matrix.configuration }})
run: |
# `swift test -c release` turns testability on by itself;
# `swift build` does not, and `@testable import` then fails.
swift build --build-tests \
-c ${{ matrix.configuration }} \
--enable-experimental-prebuilts \
--build-path .build-test-${{ matrix.configuration }} \
${{ matrix.configuration == 'release' && '-Xswiftc -enable-testing' || '' }}

- name: Run tests under a hang watchdog (${{ matrix.configuration }})
env:
# A healthy test phase takes 2-7 minutes; past this the run is stalled.
WATCHDOG_SECONDS: 720
run: |
set +e
diagnostics="$RUNNER_TEMP/hang-diagnostics"
mkdir -p "$diagnostics"
events="$diagnostics/events.jsonl"
echo "Runner: $(sysctl -n hw.activecpu) active CPUs, $(( $(sysctl -n hw.memsize) / 1073741824 )) GB memory"

# The event stream is written per event, unlike the console output,
# which reaches the log in buffered chunks and hides where a stall is.
swift test \
-c ${{ matrix.configuration }} \
--skip-build \
--enable-experimental-prebuilts \
--build-path .build-test-${{ matrix.configuration }} \
--filter '\.(SymbolTestsCoreDumpSnapshotTests|SymbolTestsCoreInterfaceSnapshotTests|SymbolTestsCoreCoverageInvariantTests|STCoreE2ETests|STCoreTests|GenericSpecializationTests|MultiPayloadEnumTests|SymbolicDemanglerDemanglingTests|MalformedSymbolValueTests|ContinuousIntegrationTestFilterTests|DependencyLoadNameTests|DependencyClosureTests|FileDependencyLocatorTests|SwiftInterfaceBuilderDependenciesTests|ManglingPrefixTests|MethodDescriptorTests|MethodOverrideDescriptorTests|MethodDefaultOverrideDescriptorTests|ProtocolRequirementTests|ResilientWitnessTests|LargeStackTaskExecutionTests|BoundedConcurrentMapTests|SwiftEvolutionInterfaceBuilderTests|EvolutionCommandValidationTests|DiffCommandValidationTests|ObjCSectionCommandTests|ObjCAPICommandParsingTests|ObjCDumpDiagnosticsTests)(/|$)'
--event-stream-output-path "$events" \
--event-stream-version 0 \
--filter '\.(SymbolTestsCoreDumpSnapshotTests|SymbolTestsCoreInterfaceSnapshotTests|SymbolTestsCoreCoverageInvariantTests|STCoreE2ETests|STCoreTests|GenericSpecializationTests|MultiPayloadEnumTests|SymbolicDemanglerDemanglingTests|MalformedSymbolValueTests|ContinuousIntegrationTestFilterTests|MachOImageCacheMembershipTests|SharedCacheResolveTests|SharedCacheResolveSwiftConcurrencyTests|SharedCacheKeyTests|SharedCacheRegistryTests|DependencyLoadNameTests|DependencyClosureTests|FileDependencyLocatorTests|SwiftInterfaceBuilderDependenciesTests|ManglingPrefixTests|MethodDescriptorTests|MethodOverrideDescriptorTests|MethodDefaultOverrideDescriptorTests|ProtocolRequirementTests|ResilientWitnessTests|LargeStackTaskExecutionTests|BoundedConcurrentMapTests|SwiftEvolutionInterfaceBuilderTests|EvolutionCommandValidationTests|DiffCommandValidationTests|ObjCSectionCommandTests|ObjCAPICommandParsingTests|ObjCDumpDiagnosticsTests)(/|$)' > "$diagnostics/test-output.log" 2>&1 &
test_pid=$!

started_at=$SECONDS
while kill -0 "$test_pid" 2>/dev/null && (( SECONDS - started_at < WATCHDOG_SECONDS )); do
sleep 15
done

if kill -0 "$test_pid" 2>/dev/null; then
echo "::error::swift test still running after ${WATCHDOG_SECONDS}s; capturing diagnostics"

echo "::group::Memory"
vm_stat
sysctl vm.swapusage
memory_pressure -Q
echo "::endgroup::"

echo "::group::Top processes"
top -l 1 -o cpu -n 20 -stats pid,command,cpu,th,mem,state
echo "::endgroup::"

echo "::group::Tests started but never ended (start time, test ID)"
jq -r 'select(.kind == "event") | .payload
| select(.kind == "testStarted" or .kind == "testEnded")
| [.kind, (.instant.since1970 | tostring), .testID] | @tsv' "$events" \
| awk -F'\t' '$1 == "testStarted" { started[$3] = $2 } $1 == "testEnded" { delete started[$3] } END { for (id in started) print started[id], id }' \
| sort -n
echo "::endgroup::"

echo "::group::Last 40 events"
tail -n 40 "$events" | jq -c '.payload | {kind, testID, since1970: .instant.since1970}'
echo "::endgroup::"

for pid in $(pgrep -f swiftpm-testing-helper) $(pgrep -x xctest); do
echo "::group::Thread stacks of $pid ($(ps -o command= -p "$pid" | cut -c1-160))"
if sample "$pid" 5 -mayDie -file "$diagnostics/sample-$pid.txt" >/dev/null 2>&1; then
cat "$diagnostics/sample-$pid.txt"
else
sudo spindump "$pid" 5 -file "$diagnostics/spindump-$pid.txt" >/dev/null 2>&1
sudo cat "$diagnostics/spindump-$pid.txt"
fi
echo "::endgroup::"
done

kill -TERM "$test_pid"
sleep 5
pkill -KILL -f swiftpm-testing-helper
test_status=124
else
wait "$test_pid"
test_status=$?
fi

echo "::group::swift test output"
cat "$diagnostics/test-output.log"
echo "::endgroup::"
exit "$test_status"

- name: Run the SharedCache suites on a one-thread cooperative pool (${{ matrix.configuration }})
# Same step as the fix branch adds to the real workflow.
timeout-minutes: 5
env:
LIBDISPATCH_COOPERATIVE_POOL_STRICT: 1
run: |
swift test \
-c ${{ matrix.configuration }} \
--skip-build \
--enable-experimental-prebuilts \
--build-path .build-test-${{ matrix.configuration }} \
--filter '\.(SharedCacheResolveTests|SharedCacheResolveSwiftConcurrencyTests)/' \
--skip 'differentKeysParallelVia'

- name: Upload hang diagnostics
if: always()
uses: actions/upload-artifact@v4
with:
name: hang-diagnostics-${{ matrix.configuration }}
path: ${{ runner.temp }}/hang-diagnostics
if-no-files-found: ignore
17 changes: 14 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ One or two lines each; the linked document is the authority.

- **Demangling** (upstream package) — mangled symbol → `Node` AST → printed Swift, plus the remangler. `Node.Kind` covers ~200 mangling node kinds.
- **MachOSwiftSection** — the ABI model: the `__swift5_*` sections, every descriptor shape in them, and Swift's position-independent relative pointers. Self-contained — `MachOBase` only, no symbol index, no demangler; a descriptor exposes an implementation's *offset* and `SwiftInspection` attributes the name ([SelfContainedABILayer.md](Documentations/Internal/SelfContainedABILayer.md)).
- **SwiftInspection** — runtime metadata analysis, and where ABI-layer symbol attribution lives: `SymbolicDemangler` (names carrying symbolic references; also demanglings built straight from descriptors), `SymbolicManglingIndex` (each symbolic reference in the mangled names the image's `_symbolic` symbols name, paired with the referent the compiler spelled for it — where a system image's private discriminators come from; [SymbolicManglingSymbols.md](Documentations/Internal/SymbolicManglingSymbols.md)), `RuntimeMetadataTypeBuilder` (node → live metadata), `EnumLayoutCalculator` + `RuntimeEnumCaseProjector`, `ClassHierarchyDumper`, `ObjCImplementationClassIndex` (SE-0436 `@objc @implementation` classes, recognized from `__objc_classlist` joined with the symbol table — [ObjCImplementationClassRecognition.md](Documentations/Internal/ObjCImplementationClassRecognition.md)), `ObjCClassHierarchy` + `ObjCClassHierarchyProviding` / `ObjCClassHierarchyProviderStore` (the per-image seam through which a host hands over the ObjC class hierarchies it already indexed — RuntimeViewer's indexer, or `SwiftIndexing`'s adapter over `ObjCIndexing.ObjCInterfaceIndexer`) with `ObjCClassMethodIndex` as the library's own lazy reader behind it (class, metaclass and same-image category method lists, the ancestor chain, the adopted protocols' selectors) and `ObjCAncestorResolver` / `ObjCAncestorResolverStore` following a standalone file's bound superclass or category target by name into its dependency closure (export trie first, then the class list; the indexer and `dump` register one per image over the configured search paths, an unregistered file defaults to the system cache, an in-process image needs none — so a file's chain reaches libobjc's `NSObject` like a cache image's does), `ObjCMember` / `ObjCMemberTable` (the per-class ObjC member table: every method-table entry tied to its Swift member — the `@objc`, `override` and explicit-selector facts in one place) and `ObjCMemberShape` (a member's selector shape: the importer's naming rules applied as a forward CHECK, and the compiler's own selector derivation ported for the explicit-selector verdict) — [ObjCMemberRecovery.md](Documentations/Internal/ObjCMemberRecovery.md).
- **SwiftInspection** — runtime metadata analysis, and where ABI-layer symbol attribution lives: `SymbolicDemangler` (names carrying symbolic references; also demanglings built straight from descriptors), `SymbolicManglingIndex` (each symbolic reference in the mangled names the image's `_symbolic` symbols name, paired with the referent the compiler spelled for it — where a system image's private discriminators come from; [SymbolicManglingSymbols.md](Documentations/Internal/SymbolicManglingSymbols.md)), `RuntimeMetadataTypeBuilder` (node → live metadata), `EnumLayoutCalculator` + `RuntimeEnumCaseProjector`, `ClassHierarchyDumper`, `ObjCImplementationClassIndex` (SE-0436 `@objc @implementation` classes, recognized from `__objc_classlist` joined with the symbol table — [ObjCImplementationClassRecognition.md](Documentations/Internal/ObjCImplementationClassRecognition.md)), `SwiftClassObjectIndex` (the Swift classes a source renamed for the ObjC runtime — `@objc(NSScrollPocket)` — joined to their descriptor through the class metadata, since their runtime name demangles to nothing; every name-keyed ObjC-side lookup of a Swift class falls back to it on a miss — [CustomObjCClassNames.md](Documentations/Internal/CustomObjCClassNames.md)), `ObjCClassHierarchy` + `ObjCClassHierarchyProviding` / `ObjCClassHierarchyProviderStore` (the per-image seam through which a host hands over the ObjC class hierarchies it already indexed — RuntimeViewer's indexer, or `SwiftIndexing`'s adapter over `ObjCIndexing.ObjCInterfaceIndexer`) with `ObjCClassMethodIndex` as the library's own lazy reader behind it (class, metaclass and same-image category method lists, the ancestor chain, the adopted protocols' selectors) and `ObjCAncestorResolver` / `ObjCAncestorResolverStore` following a standalone file's bound superclass or category target by name into its dependency closure (export trie first, then the class list; the indexer and `dump` register one per image over the configured search paths, an unregistered file defaults to the system cache, an in-process image needs none — so a file's chain reaches libobjc's `NSObject` like a cache image's does), `ObjCMember` / `ObjCMemberTable` (the per-class ObjC member table: every method-table entry tied to its Swift member — the `@objc`, `override` and explicit-selector facts in one place) and `ObjCMemberShape` (a member's selector shape: the importer's naming rules applied as a forward CHECK, and the compiler's own selector derivation ported for the explicit-selector verdict) — [ObjCMemberRecovery.md](Documentations/Internal/ObjCMemberRecovery.md).
- **SwiftDump** — high-level wrappers (`Struct`, `Enum`, `Class`, `Protocol`, `ProtocolConformance`, `AssociatedType`, `ObjCImplementationClass`) and the `dump` output path.
- **SwiftDeclaration** — the shared declaration model every higher module reads and writes, plus the `SwiftIndexEvents` namespace. [Modules/SwiftDeclaration.md](Documentations/Internal/Modules/SwiftDeclaration.md).
- **SwiftDeclarationRendering** — the comment engine shared by dump and interface (`FieldLayoutRenderer`, opaque-type rewriting, specialized-metadata substitution), reader-specialized: live metadata in-process, SwiftLayout offline ([FieldLayoutRendererReaderSpecialization.md](Documentations/Internal/FieldLayoutRendererReaderSpecialization.md)).
Expand All @@ -64,9 +64,9 @@ One or two lines each; the linked document is the authority.
- **MachOReading / MachOResolving** — reading abstractions; address/offset resolution. `MachOResolving` also holds the symbol *value* types (`Symbol`, `Symbols`, `SymbolOrElement`), which carry no lookup behavior — "the symbols at this offset" is a query, not a read.
- **MachOPointers** — relative and indirect pointer types, plus `SymbolOrElementPointer`.
- **MachOSymbols** — the symbol *index*: table parsing, demangling, the per-image node stores, and `LargeStackTaskExecution`; also collects the image's `_symbolic` symbols into a table of their own that no offset or name query sees (`symbolicManglingSymbols(in:)`). [Modules/MachOSymbols.md](Documentations/Internal/Modules/MachOSymbols.md).
- **MachOCaches** — dyld shared cache support.
- **MachOCaches** — the per-image cache primitive, NOT dyld shared cache support (that is `MachOKitExtensions` and `MachODependencies`): `SharedCache` (get-or-build per image, one build shared by concurrent callers, the build closure supplied at the call site), `SharedCacheKey` (hashes a file on its UUID alone) and `SharedCacheRegistry` + `SharedCacheEvictionGroup` (which caches an indexer claims for an image and what its last live instance evicts). [Modules/MachOCaches.md](Documentations/Internal/Modules/MachOCaches.md).
- **MachODependencies** — the one dependency-resolution implementation every feature shares (`DependencyClosure`, the in-process and file locators, `DependencySearchPath`, `SharedDependencyClosure` for consumers of one root that resolve lazily). The file locator filters dyld-cache candidates by platform (`DependencyPlatforms`, from `LC_BUILD_VERSION`): the host's macOS cache is every root's default search path and carries Mac Catalyst UIKit / SwiftUI under `/System/iOSSupport`, which an iOS root used to resolve to by bare name. [Modules/MachODependencies.md](Documentations/Internal/Modules/MachODependencies.md).
- **MachOKitExtensions** (external sibling, `../MachOKitExtensions`) — MachOKit extensions. Two behaviors this repo's tests still pin live there: legacy `LC_DYLD_INFO` bind resolution (`LegacyDyldInfoBindTests`) and ranked dyld-cache image name lookup (`DyldCacheImageSearchTests`). It cannot move back in-repo — `MachOObjCSection` depends on it, which would make a package-level cycle.
- **MachOKitExtensions** (external sibling, `../MachOKitExtensions`) — MachOKit extensions. Three behaviors this repo's tests still pin live there: legacy `LC_DYLD_INFO` bind resolution (`LegacyDyldInfoBindTests`), ranked dyld-cache image name lookup (`DyldCacheImageSearchTests`), and whether an in-process image is in the shared cache — read from its header flag, never from its load address (`MachOImageCacheMembershipTests`). It cannot move back in-repo — `MachOObjCSection` depends on it, which would make a package-level cycle.

Printing and indexing are peers; neither depends on the other.

Expand Down Expand Up @@ -197,6 +197,17 @@ Detail: [Modules/MachOSymbols.md](Documentations/Internal/Modules/MachOSymbols.m

</important>

<important if="you are adding a per-image cache, evicting one, or handling memory pressure">

- **Every per-image cache is a `SharedCache` with a `SharedCacheEvictionGroup`, held by composition** — never a hand-written lock plus `[key: value]` dictionary, never a subclass. The build closure goes at the call site; re-type the reader once through `swiftSectionReader` / `objcImplementationClassReader` (SwiftInspection) instead of an `as? MachOFile` / `as? MachOImage` split.
- **A build closure must not query the entry it is building.** On the builder's own thread that traps with the key; after a thread hop (`withLargeStack`) it hangs, undetected.
- **Eviction belongs to the registry**: the indexer claims what its `prepare()` found absent and its last live instance evicts it plus every group that `follows` it. `MachOCaches` declares no group: a module declares its own in a `SharedCacheEvictionGroup+<Module>.swift` extension, and a cache whose entries point into another group's storage says `follows:` at creation. The three `removeCache` helpers are the explicit form and forward to `SharedCacheRegistry.evict(groups:for:)`.
- **The library never reacts to memory pressure.** The per-instance monitors that used to `removeAll()` bypassed the ownership rules and freed nothing (live `NodeReference`s pin the storage). A host sheds state by calling `SharedCacheRegistry.shared.evictImagesWithoutLiveOwners()`.

[Modules/MachOCaches.md](Documentations/Internal/Modules/MachOCaches.md).

</important>

<important if="you are reading offsets in an image inside a dyld shared cache">

Every offset in `MachOSwiftSection` is `unslidVirtualAddress - sharedRegionStart`, **not a file offset**. Three other accountings coexist and mixing them fails silently — `adrp` computes its page base from the instruction's own address, so a sub-page error still yields a computable, plausible-looking address pointing into a neighbouring image:
Expand Down
2 changes: 1 addition & 1 deletion AgentPlugins/swift-section/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swift-section",
"version": "0.20.0",
"version": "0.21.0",
"description": "Teaches coding agents to drive the swift-section CLI: Swift and Objective-C declarations, memory layout and ABI diffs recovered from a Mach-O binary or a dyld shared cache.",
"author": {
"name": "MxIris-Reverse-Engineering",
Expand Down
2 changes: 1 addition & 1 deletion AgentPlugins/swift-section/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swift-section",
"version": "0.20.0",
"version": "0.21.0",
"description": "Teaches coding agents to drive the swift-section CLI: Swift and Objective-C declarations, memory layout and ABI diffs recovered from a Mach-O binary or a dyld shared cache.",
"author": {
"name": "MxIris-Reverse-Engineering",
Expand Down
Loading
Loading