Skip to content

[AUTOMATED] importdata: a Mach-O data import slot read as a value prints &<import> - #1871

Merged
mahaloz merged 3 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/gotfold
Nov 22, 2026
Merged

mahaloz merged 3 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/gotfold

Conversation

@coleleavitt

Copy link
Copy Markdown
Contributor

[AUTOMATED]

A Mach-O __got slot of a data import holds the import's address. When code passes that address on, as Swift does with witness tables, type metadata and conformance descriptors, or Objective-C with a class object, kuna prints the slot as an anonymous global. Build the fixture added here (the two commands from its README entry) and decompile it:

$ clang -target arm64-apple-macos11 -O1 -c macho_dataslotaddr.c -o m.o
$ ld64.lld -arch arm64 -platform_version macos 11.0 11.0 -undefined dynamic_lookup -e _main -o macho_dataslotaddr_arm64 m.o
$ kuna decompile macho_dataslotaddr_arm64 _pass_addresses
  use_addresses(dat_100004008,dat_100004000); // tail-call

After: use_addresses(&OBJC_CLASS_$_NSObject,&<SwiftUI.Color:SwiftUI.View>.protocol_witness_table);. On a 72 MB iOS app, swift_getWitnessTable(dat_103f7d4e8,v2,&v1) becomes swift_getWitnessTable(&<SwiftUI.ModifiedContent<A,B>:SwiftUI.View>.protocol_conformance_descriptor,v2,&v1) and objc_msgSend$numberWithLongLong:(dat_103f79168,...) becomes objc_msgSend$numberWithLongLong:(&OBJC_CLASS_$_NSNumber,...).

The fix

  • machodataslots already tells a data import from its mangling and names the slot. It now also hands the engine the list of those slots.
  • Under importdata (default on), a read of such a slot's own value prints &<import>. A read through it (*slot) still prints the import, as before.
  • Only the value the loader put there counts: the slot read at entry, or carried across calls and joins. A value the function stored into the slot keeps the slot name.
  • Function-import slots are not touched, so a test of a weak function's address (if (dat_<slot>), pinned by the nullable-relocations and mipsgot-weak stage tests) reads as before.

Tests

kuna-console/tests/verify_machodataslots.rs gets one case on the new fixture, checking dat_ with importdata off and &<import> with it on; it fails without the change. Stage and datatest corpora are unchanged. On 390 sampled functions of the app, 74 change, and 119 dat_ references become &<import> (33 type metadata, 21 witness tables, 35 conformance descriptors, 29 OBJC_CLASS_$_*); every changed line differs only in those tokens.

Model: anthropic/claude-opus-5-5:high

…ort's address

A Mach-O __got slot of a data import (a Swift witness table, type metadata or conformance descriptor, an Objective-C class object) holds the import's address. Code that passes that address on, to swift_getWitnessTable or as a message receiver, printed the slot as dat_<slot>. With importdata on, a read of the value the loader put in a slot machodataslots marks as data now renders &<import>; function-import slots and values the function stored are unchanged.

[AUTOMATED]
mahaloz and others added 2 commits November 22, 2026 09:58
A data-import slot's value read by a mask, shift, multiply or division
printed `&OBJC_CLASS_$_NSObject >> 0x20` and `&Swift.Int.type_metadata | 1`,
which C rejects. Such a read, and a read narrower than the slot, keep
`dat_<slot>` as before; an addition still reads `&<import> + 8`. The check
returns early when the image marked no data-import slot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
@mahaloz

mahaloz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed 71ed27e on top of your head: a clean merge of current main, plus one small guard in import_slot_address.

Repro: long hi(void){ return (long)&objc_class >> 32; } and long tag(void){ return (long)&meta | 1; }, built like macho_dataslotaddr.c, printed return &OBJC_CLASS_$_NSObject >> 0x20; and return &Swift.Int.type_metadata | 1;. C rejects both. A read by a mask, shift, multiply or division now keeps dat_<slot>, and so does a read narrower than the slot. Additions still read &<import> + 8. The check also returns early when the image marks no data-import slot. The spec paragraph in 09-emission.md says the same.

@mahaloz
mahaloz merged commit 394ecc1 into Noelo-Lab:main Nov 22, 2026
2 checks passed
@coleleavitt
coleleavitt deleted the fix/gotfold branch November 22, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants