commit f130c58e5121f3834c72ffe33510c8401dc538ed
parent 7218210c398cd6d35860f378b1d4140459ae4acb
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Thu, 16 Jul 2026 10:59:49 -0700
test: cover linked Mach-O and PE images
Diffstat:
2 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/doc/RELEASE_AUDIT_2026_6_0.md b/doc/RELEASE_AUDIT_2026_6_0.md
@@ -501,7 +501,7 @@ Implementation checkpoint (updated 2026-07-16):
| KIT-P1-015 | **Complete** | 21 multi-source dependency assertions pass within `test-driver-cc`: 162 pass, 0 fail |
| KIT-P2-003 | **Complete** | `test-driver-diagnostics`: 15 pass, 0 fail |
| KIT-P1-007 | **Complete** | `test-driver-strip`: object API 26/0, relocatable/archive 5/0, linked ELF/Mach-O/PE matrix 91/0 |
-| KIT-P1-017 | **Complete** | relocatable/linked ELF, Mach-O, COFF, and Wasm image cases included in `test-driver-tools`: 251 pass, 0 fail |
+| KIT-P1-017 | **Complete** | relocatable ELF/Mach-O/COFF/Wasm-module and linked ELF/Mach-O/PE image cases, including loader-segment vs section spans and `objcopy` parity: `test-driver-tools` 284 pass, 0 fail; Wasm v1 has no distinct linked-image path |
| KIT-P2-002 | **Complete** | 32-bit boundary/overflow, negative bias, entry records, metadata, and transactional cases included in `test-driver-tools`: 251 pass, 0 fail |
| KIT-P3-003 | **Complete** | `test-link-macho-symbols` passes aarch64 and x86-64 Kit/platform oracles |
| KIT-P1-016 | **Complete** | conventional ar/as/linker spellings and direct/installed dash-path cases pass: ar 8/0, tools 253/0, strip 6/0 |
@@ -1194,7 +1194,9 @@ expanded cwd, environment, and argv used for the recorded result.
- **Impact/remediation:** common binary conversion appears supported but fails.
Implement relocatable conversion or document/use a clear alternative.
- **Acceptance/regression:** binary/IHEX/SREC from relocatable and linked inputs
- across supported formats.
+ across supported formats. Wasm v1 modules are section containers and the
+ driver rejects object/archive linking, so there is no distinct linked-Wasm
+ image path to claim or test.
### KIT-P2-001 — common stack-protector selection blocks cJSON
diff --git a/test/tools/run.sh b/test/tools/run.sh
@@ -445,6 +445,95 @@ same_file image-paddr-matches-vaddr "$work/kernel.bin" "$work/kernel.paddr.bin"
run_ok objcopy-binary "$KIT" objcopy -O binary "$work/kernel.elf" \
"$work/kernel.objcopy.bin"
same_file image-objcopy-binary "$work/kernel.bin" "$work/kernel.objcopy.bin"
+
+# Linked Mach-O and PE inputs must take the loader-segment path. Keep the
+# segment-selected output beside an explicitly section-selected output: the
+# former includes loader-owned bytes/alignment and is therefore observably
+# larger than the logical text section. Default objcopy raw output is required
+# to agree byte-for-byte with the image command over the same linked image.
+cat > "$work/linked-cross.c" <<'EOF'
+volatile unsigned long linked_data = 0x11223344UL;
+const unsigned char linked_rodata[] = { 0x55, 0x66, 0x77, 0x88 };
+void _start(void) {
+ linked_data += linked_rodata[0];
+ for (;;) {}
+}
+EOF
+
+run_ok image-linked-macho-build "$KIT" cc -target x86_64-macos \
+ -ffreestanding -fno-stack-protector -nostdlib -Wl,-e,_start \
+ "$work/linked-cross.c" -o "$work/linked.macho"
+run_ok image-linked-macho "$KIT" image --format bin \
+ --metadata "$work/linked.macho.json" "$work/linked.macho" \
+ -o "$work/linked.macho.bin"
+contains image-linked-macho-source "$work/linked.macho.json" \
+ '"source": "segments"'
+contains image-linked-macho-format "$work/linked.macho.json" \
+ '"object_format": "macho"'
+run_ok image-linked-macho-objcopy "$KIT" objcopy -O binary \
+ "$work/linked.macho" "$work/linked.macho.objcopy.bin"
+same_file image-linked-macho-objcopy-bytes "$work/linked.macho.bin" \
+ "$work/linked.macho.objcopy.bin"
+run_ok image-linked-macho-text-segment "$KIT" image --format bin \
+ --segment __TEXT --metadata "$work/linked.macho.text.json" \
+ "$work/linked.macho" -o "$work/linked.macho.text.bin"
+contains image-linked-macho-text-selection "$work/linked.macho.text.json" \
+ '"selection": ["__TEXT"]'
+contains image-linked-macho-text-load-address \
+ "$work/linked.macho.text.json" '"base_is_load_address": true'
+run_ok image-linked-macho-text-section "$KIT" image --format bin \
+ --only-section __TEXT,__text "$work/linked.macho" \
+ -o "$work/linked.macho.section.bin"
+macho_segment_size=$(wc -c < "$work/linked.macho.text.bin" | tr -d ' ')
+macho_section_size=$(wc -c < "$work/linked.macho.section.bin" | tr -d ' ')
+if [ "$macho_segment_size" -gt "$macho_section_size" ]; then
+ ok image-linked-macho-segment-span
+else
+ printf 'segment=%s section=%s\n' "$macho_segment_size" \
+ "$macho_section_size" > "$work/image-linked-macho-segment-span.diag"
+ not_ok image-linked-macho-segment-span \
+ "$work/image-linked-macho-segment-span.diag"
+fi
+head -c 4 "$work/linked.macho.text.bin" > "$work/linked.macho.magic"
+"$KIT" xxd -p "$work/linked.macho.magic" > "$work/linked.macho.magic.hex"
+contains image-linked-macho-segment-header "$work/linked.macho.magic.hex" \
+ "cffaedfe"
+
+run_ok image-linked-pe-build "$KIT" cc -target x86_64-windows \
+ -ffreestanding -fno-stack-protector -nostdlib -Wl,-e,_start \
+ "$work/linked-cross.c" -o "$work/linked.exe"
+run_ok image-linked-pe "$KIT" image --format bin \
+ --metadata "$work/linked.pe.json" "$work/linked.exe" \
+ -o "$work/linked.pe.bin"
+contains image-linked-pe-source "$work/linked.pe.json" \
+ '"source": "segments"'
+contains image-linked-pe-format "$work/linked.pe.json" \
+ '"object_format": "coff"'
+run_ok image-linked-pe-objcopy "$KIT" objcopy -O binary \
+ "$work/linked.exe" "$work/linked.pe.objcopy.bin"
+same_file image-linked-pe-objcopy-bytes "$work/linked.pe.bin" \
+ "$work/linked.pe.objcopy.bin"
+run_ok image-linked-pe-text-segment "$KIT" image --format bin \
+ --segment .text --metadata "$work/linked.pe.text.json" \
+ "$work/linked.exe" -o "$work/linked.pe.text.bin"
+contains image-linked-pe-text-selection "$work/linked.pe.text.json" \
+ '"selection": [".text"]'
+contains image-linked-pe-text-load-address "$work/linked.pe.text.json" \
+ '"base_is_load_address": true'
+run_ok image-linked-pe-text-section "$KIT" image --format bin \
+ --only-section .text "$work/linked.exe" \
+ -o "$work/linked.pe.section.bin"
+pe_segment_size=$(wc -c < "$work/linked.pe.text.bin" | tr -d ' ')
+pe_section_size=$(wc -c < "$work/linked.pe.section.bin" | tr -d ' ')
+if [ "$pe_segment_size" -gt "$pe_section_size" ]; then
+ ok image-linked-pe-segment-span
+else
+ printf 'segment=%s section=%s\n' "$pe_segment_size" \
+ "$pe_section_size" > "$work/image-linked-pe-segment-span.diag"
+ not_ok image-linked-pe-segment-span \
+ "$work/image-linked-pe-segment-span.diag"
+fi
+
run_ok image-ihex "$KIT" image --format ihex "$work/kernel.elf" \
-o "$work/kernel.hex"
run_ok objcopy-ihex "$KIT" objcopy -O ihex "$work/kernel.elf" \