Commit 1d610bf
committed
pack.binfmt: a Mach-O reader for needed_names (#630 §4)
`needed_names` returned "not implemented" for Mach-O; `elf_needed` and
`pe_needed` already read a dependency list without executing anything.
Mach-O gets the same treatment:
- `detail::macho_thin_needed` walks a thin object's load commands:
`LC_LOAD_DYLIB`, `LC_LOAD_WEAK_DYLIB`, `LC_REEXPORT_DYLIB` and
`LC_LOAD_UPWARD_DYLIB` contribute names, `LC_RPATH` contributes search
entries, in load-command order. Both widths (`mach_header`/
`mach_header_64`) and both endiannesses (the CIGAM magics) are handled.
- `detail::macho_needed` / the exported `macho_needed(path, arch)` add the
FAT (universal) case: a slice is selected by `cputype` against the
caller's `arch` (mcpp's canonical spelling), defaulting to the first
slice when none is given -- which is what `needed_names` does, since it
has no triple to pass. `FAT_MAGIC` and `FAT_MAGIC_64` are both handled;
FAT headers are always big-endian on disk regardless of a slice's own
endianness.
- `needed_names` completes for Mach-O by delegating to `macho_needed`, and
`is_system_lib` gains a Mach-O row: `/usr/lib/` and `/System/Library/`
are the operating system's, case-sensitively (`@rpath/...` is a search,
not a root, so it is never system).
- `resolve_macho_names` is a pure resolver: `@executable_path`,
`@loader_path` and `@rpath/<x>` (tried against every rpath entry, in
order, with the same two substitutions) resolve to the first path that
exists; a name that resolves nowhere is reported as `unresolved`, not
dropped.
NOT wired into `pack::run`'s Mach-O closure step. Bundling a resolved
dylib beside the program and rewriting its `LC_RPATH` needs a load-command
editor -- a load command has no free space to grow a longer path into --
and the record (§4.2) designs that editor after resolution is measured on
a real macOS build, not before. `pack::run`'s Mach-O branch still reports
"not-walked" (see the sibling #630 §3 commit); this reader and resolver
are exposed for that measurement and for whoever wires them in next.
Tests: unit fixtures built in-process (a tiny Mach-O/fat-Mach-O byte
writer, no external tools, same shape the ELF/PE fixtures already use) --
a thin arm64 object with two `LC_LOAD_DYLIB`, one `LC_LOAD_WEAK_DYLIB` and
two `LC_RPATH`; a fat x86_64+arm64 object whose slices carry different
names, asserting the wrong slice is never read; a big-endian-magic thin
object; the wrong-arch request on a thin file (ignored, as documented);
`is_system_lib`'s Mach-O row; and the resolver's rpath-order and
unresolved-reporting behavior.
Docs: docs/10-pack-and-release.md and the zh mirror note that the closure
is read now, and narrow the "planned" gap to bundling + the `LC_RPATH`
rewrite.1 parent ed28442 commit 1d610bf
4 files changed
Lines changed: 633 additions & 17 deletions
File tree
- docs
- zh
- src/pack
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
485 | 498 | | |
486 | 499 | | |
487 | 500 | | |
| |||
513 | 526 | | |
514 | 527 | | |
515 | 528 | | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
521 | 535 | | |
522 | 536 | | |
523 | 537 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
411 | 422 | | |
412 | 423 | | |
413 | 424 | | |
| |||
435 | 446 | | |
436 | 447 | | |
437 | 448 | | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
442 | 454 | | |
443 | 455 | | |
444 | 456 | | |
| |||
0 commit comments