Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f340d74472 | ||
|
|
2a2efd61d7 | ||
|
|
66d21ebc35 | ||
|
|
1315df5548 | ||
|
|
af0c5cb617 | ||
|
|
bb78a97313 | ||
|
|
e55287f218 | ||
|
|
f9b51667c4 | ||
|
|
5214938b6b | ||
|
|
dc7de6f3a7 | ||
|
|
29c30ddcc6 | ||
|
|
dc94931eca |
No files matched your search
@@ -3,31 +3,35 @@
|
||||
A modern C toolchain for the DEC VT1200 / TI TMS34010, built as a small fork of
|
||||
upstream LLVM.
|
||||
|
||||
**Status: M7 complete (M7.4).** Branch `m7` is the repository default on both
|
||||
repositories. The M7.4 code state is project `1eaabaa` and compiler
|
||||
`f552070c7c65`; this documentation update rides on top of it. M7.4 closes the milestone with
|
||||
the full pinned external suites, an i64 divide/remainder fast path with MAME
|
||||
frame evidence, and the final M7/M8 boundary. The full sweep accounts for **1,912** files:
|
||||
c-torture **1,692 = 1,366 pass / 326 skip / 0 fail / 0 crash** and
|
||||
c-testsuite **220 = 210 pass / 10 skip / 0 fail / 0 crash** (**all 1,912 =
|
||||
1,576 pass / 336 skip / 0 fail / 0 crash**). Every skip carries a classifier
|
||||
or curation reason; the 272 curated rows were re-run with an empty skip file
|
||||
and **272/272 still failed**, so curation hides no passing test. The shipped
|
||||
tiers now report lit **118/118** (114 CodeGen + 4 MC; M7.4 adds
|
||||
`m7-i64div-fast.ll`), clang **5/5**, M5 c-torture **79/79** at `-O0` and
|
||||
**Status: M8 complete (M8.4).** Branch `m8` is the current milestone branch and
|
||||
the repository default on both repositories. The M8 code state is project
|
||||
`e55287f` and compiler `ab6017a8b41f`; this documentation update rides on top
|
||||
of it. Repository policy: each milestone branch is promoted to the default
|
||||
immediately after its clean final review, and the previous default stays as a
|
||||
snapshot.
|
||||
M8.1 makes the native path library-complete: `tms-link` reads the SDK System V
|
||||
`ar` archives (1987 `FLIB.LIB`/`RTS.LIB` in the M4 SDK; 1990 copies in the M6
|
||||
SDK), extracts only members that define needed
|
||||
symbols (iterated to a fixpoint), supports `-l`/`-L`, and links the M4/M5/M6
|
||||
library programs with GSPLNK as the permanent byte/symbol oracle. M8.2 merges
|
||||
DWARF from multiple translation units: per-object section bases are rehomed,
|
||||
relocations and the raw CU abbreviation offset are rewritten, and
|
||||
`llvm-dwarfdump` validates every TU. M8.3 fixes the rotate/count/byte-swap
|
||||
lowering and adds a 64/32 i64 divide fast path; 20 curated rows flip to pass,
|
||||
lifting the full sweep to **1,912 = 1,596 pass / 316 skip / 0 fail / 0 crash**
|
||||
(c-torture **1,692 = 1,386 / 306 / 0 / 0**, c-testsuite **220 = 210 / 10 / 0 /
|
||||
0**). The 64/32 wide phase is **218** frames versus **2,440** for the 64-step
|
||||
loop (11.2×), and the 32-bit fast path is **87** versus **2,440** (28.0×), with
|
||||
status `600D600D` and the three pinned checksums. The shipped tiers report lit
|
||||
**120/120** (116 CodeGen + 4 MC; M8 adds `m8-bitops.ll` and
|
||||
`m8-i64div-wide.ll`), clang **5/5**, M5 c-torture **79/79** at `-O0` and
|
||||
`-O2`, M6 c-torture **79** at `-O0` plus the **20**-test bounded `-O2` subset,
|
||||
c-testsuite **48 pass / 172 skip / 220** (the curated shipped tier; the
|
||||
full-corpus result is 210 pass / 10 skip), and Generic **197 = 149 pass / 48
|
||||
unsupported / 0 crash**. `TMS34010LowerI64` now checks the normalized
|
||||
operands' high words and emits one 32-bit `DIVU` instead of the 64-step
|
||||
restoring loop when both are zero. MAME measures the same 16,384-iteration
|
||||
workload at **90** fast frames versus **2,424** slow frames, ratio **26.9**,
|
||||
status `600D600D`, checksums `000000011E6F9AB4`/`00000000007512AE`. The
|
||||
conformance loader validates every linked COFF and repairs the observed
|
||||
GSPLNK zero file/optional-header (and odd `.bss`) shapes post-link
|
||||
(`scripts/m4/coff-check.py`); one of the 11 former loader failures is repaired
|
||||
in the final tree and the 11 now pass. M7 is the repository default branch
|
||||
(`m7`); `m6` remains the previous snapshot.
|
||||
shipped c-testsuite **48 pass / 172 skip / 220**, and Generic **197 = 151 pass
|
||||
/ 46 unsupported / 0 crash** (two former ctlz/count entries now compile). The
|
||||
real VT1200 run remains **DEFERRED** (`VT1200_HOST` is unset;
|
||||
`scripts/tests/m7/hardware.sh` prints `HARDWARE: DEFERRED` and passes on the
|
||||
MAME-equivalent acceptance). M8 is the milestone branch and the repository
|
||||
default; `m7` is the previous snapshot.
|
||||
|
||||
M7.3 widened the validated VT1200 Xlib surface, added real
|
||||
stderr capture to the conformance runtime, and shipped the real-hardware
|
||||
@@ -84,8 +88,9 @@ returns through the hidden slot (explicit `sret` is rejected), the linked
|
||||
tiers. M7.2 did not change the default branch or the ABI. M7.3 added the wider
|
||||
Xlib surface, stderr capture and the deferred hardware harness. M7.4 added the
|
||||
full-corpus accounting, the i64 divide/remainder fast path and the
|
||||
conformance-loader COFF repair; M8 owns the remaining object/debug,
|
||||
`.lib`-linking, hardware and conformance work.
|
||||
conformance-loader COFF repair. M8 then delivered native `.lib` linking,
|
||||
multi-TU DWARF merging, the bit-op/64-32 divide work and the final M8/M9
|
||||
boundary; the hardware run is still deferred.
|
||||
|
||||
> **M7.1 correctness.** The M6 `-O2` `p += n` over-scale is fixed: a source
|
||||
> `p += n` derived pointer is correct at the default `-O2`, and the
|
||||
@@ -94,10 +99,11 @@ conformance-loader COFF repair; M8 owns the remaining object/debug,
|
||||
> the M0 pointer shapes: `int_diff` returns 8 and `int_diff4` returns 32,
|
||||
> and `late` carries the 24-bit addend (never 192).
|
||||
|
||||
Branch `m7` is the current milestone snapshot and the repository default
|
||||
(promoted from `m6` after the clean M7.4 final review). Branch `m6` is the
|
||||
previous snapshot,
|
||||
`m5` the one before that, `m4` before that, `m3` the M3 snapshot, `m2` the M2
|
||||
Branch `m8` is the current milestone snapshot (M8.4) and the repository
|
||||
default (promoted after the clean M8 final review; `m7` is the previous
|
||||
default). Branch
|
||||
`m7` is the previous snapshot, `m6` the one before that,
|
||||
`m5` before that, `m4` before that, `m3` the M3 snapshot, `m2` the M2
|
||||
tip and `m1` the reproducible M1 snapshot.
|
||||
|
||||
- Design: [`docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md`](docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md)
|
||||
@@ -112,30 +118,147 @@ tip and `m1` the reproducible M1 snapshot.
|
||||
- M7.2 plan: [`docs/superpowers/plans/2026-11-14-tms34010-m7-2-object-debug-and-native-linker.md`](docs/superpowers/plans/2026-11-14-tms34010-m7-2-object-debug-and-native-linker.md)
|
||||
- M7.3 plan: [`docs/superpowers/plans/2026-11-15-tms34010-m7-3-runtime-and-hardware.md`](docs/superpowers/plans/2026-11-15-tms34010-m7-3-runtime-and-hardware.md)
|
||||
- M7.4 plan: [`docs/superpowers/plans/2026-11-15-tms34010-m7-4-conformance-performance-and-boundary.md`](docs/superpowers/plans/2026-11-15-tms34010-m7-4-conformance-performance-and-boundary.md)
|
||||
- M8 plan: [`docs/superpowers/plans/2026-11-16-tms34010-m8-archives-dwarf-conformance-and-hardware.md`](docs/superpowers/plans/2026-11-16-tms34010-m8-archives-dwarf-conformance-and-hardware.md)
|
||||
- Spike: [`spike/REPORT-23.md`](spike/REPORT-23.md) (current, LLVM 23.1.5);
|
||||
[`spike/REPORT.md`](spike/REPORT.md) (historical, 19.1.7)
|
||||
|
||||
## Repositories
|
||||
|
||||
- **Compiler fork:** <https://git.wut.ee/opencode.siil.arti.ee/llvm-tms34010>
|
||||
(branch `m7`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2–M7.4 backend.
|
||||
Branch `m7` is the current milestone snapshot and the repository default
|
||||
(promoted from `m6`). Branch `m6` is the previous snapshot, `m5` is before
|
||||
(branch `m8`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2–M8 backend.
|
||||
Branch `m8` is the current milestone snapshot and the repository default
|
||||
(promoted after the clean M8 final review; `m7` is the previous default).
|
||||
Branch `m6` is the previous snapshot,
|
||||
`m5` is before
|
||||
that, `m4` is before that, branch `m3` is before that, branch `m2` is the M2
|
||||
tip and branch `tms34010` is the M1 tip and keeps the original M1 backend
|
||||
and suite.
|
||||
- **This project:** <https://git.wut.ee/opencode.siil.arti.ee/tms-c-compiler>
|
||||
(branch `m7`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2–M7.4 harnesses and the conformance tier.
|
||||
Branch `m7` is the current milestone snapshot and the repository default
|
||||
(promoted from `m6`). Branch `m6` is the previous snapshot, `m5` is before
|
||||
(branch `m8`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2–M8 harnesses and the conformance tier.
|
||||
Branch `m8` is the current milestone snapshot and the repository default
|
||||
(promoted after the clean M8 final review; `m7` is the previous default).
|
||||
Branch `m6` is the previous snapshot, `m5` is before
|
||||
that, `m4` is before that, `m3` is before that, `m2` is the M2 snapshot and
|
||||
`m1` is the reproducible M1 snapshot, including the retired M1 harness.
|
||||
|
||||
The compiler fork is the canonical source for all target code. `patches/llvm`
|
||||
here is a **frozen M0 mirror** used by the default upstream+patches build;
|
||||
M2–M7.4 do not change it.
|
||||
M2–M8 do not change it.
|
||||
|
||||
## What M8 provides
|
||||
|
||||
M8 is the object/link-completeness, conformance-depth and hardware close-out.
|
||||
It adds native archive linking and multi-TU DWARF to `tms-link`, fixes the
|
||||
remaining rotate/count/byte-swap lowering class, adds a 64/32 i64 divide fast
|
||||
path, and records the final M8/M9 boundary. It changes no TI ABI rule, no
|
||||
language semantics and no default branch. Full target rules are in
|
||||
[`build/llvm-clean/TMS34010.md`](build/llvm-clean/TMS34010.md) ("M8 state").
|
||||
|
||||
- **M8.1 — native `.lib` linking.** `tools/tms-link` reads System V `ar`
|
||||
archives (`!<arch>` with TI-COFF members; the 1990 `FLIB.LIB`/`RTS.LIB` are
|
||||
this shape). It validates the 60-byte headers, decimal sizes, even padding,
|
||||
`/` symbol index and `//`/`/N` long names; a malformed archive or index is
|
||||
loud. Members are candidates only: a member is extracted when it defines a
|
||||
still-undefined symbol, scanned in the archive's index order (which matches
|
||||
GSPLNK's member layout), never extracted twice, and the archive sequence is
|
||||
iterated to a fixpoint. Duplicate definitions and unresolved externals fail
|
||||
with member/object labels (member labels include the offset, so same-named
|
||||
members stay distinct). `-l LIB`/`-lLIB` and `-L DIR` resolve `LIB`,
|
||||
`LIB.lib`, `LIB.LIB` and `libLIB.a`; explicit objects and archives may be
|
||||
mixed in any order, with explicit objects laid out first. TI-COFF relocation
|
||||
addends are read as signed 32-bit values (the termtris link exposed a -160
|
||||
`.bss` addend). GSPLNK remains the default linker and the permanent oracle:
|
||||
`M4_LINKER=tms-link` (with `M4_NATIVE_LIBS`/`M4_NATIVE_RTS`),
|
||||
`M5_NATIVE_LINKER=tms-link` and `M6_LINKER=tms-link` are opt-ins, and the
|
||||
native library gate (`scripts/tests/m8/native-lib.sh`) requires the same
|
||||
allocated bytes, section origins/flags, optional header and **16** public
|
||||
`C_EXT` addresses as GSPLNK, plus the MAME markers. Limits: an empty
|
||||
`.cinit` is omitted (GSPLNK emits a listed empty one), an indexed archive
|
||||
parses a member only when needed (so an irrelevant unsupported member is
|
||||
harmless), a no-index archive must be scanned member by member, and a
|
||||
second archive that redefines an already-satisfied symbol is not pulled in
|
||||
or flagged, matching traditional archive semantics.
|
||||
- **M8.2 — multi-TU DWARF merging.** `tms-link --keep-debug` concatenates the
|
||||
debug sections of every debug-bearing object in object order and rehomes
|
||||
every section-relative contribution: the CU `debug_abbrev_offset` (raw
|
||||
fallback when no relocation covers it), `str_offsets_base`,
|
||||
`stmt_list`, `addr_base`, `loclists_base`/`rnglists_base`, `.debug_str` and
|
||||
`.debug_line_str` string offsets, `.debug_addr` entries and `.debug_line`
|
||||
addresses. Supported multi-object sections are `.debug_info`,
|
||||
`.debug_abbrev`, `.debug_str`, `.debug_str_offsets`, `.debug_addr`,
|
||||
`.debug_line`, `.debug_line_str`, `.debug_loclists` and `.debug_rnglists`;
|
||||
any other `.debug_*` shape (`.debug_frame`, aranges, types, macros, …) is
|
||||
refused loudly in a multi-object keep link. LLVM 23.1.5 `-g` objects use
|
||||
the supported shapes; DWARF64 is refused. The gate
|
||||
(`scripts/tests/m8/dwarf-multi.sh`) links two `-g` TUs, wraps the kept
|
||||
sections in the M7 ELF container and requires `llvm-dwarfdump` to show both
|
||||
CU names, both line tables, every subprogram name/low-high PC/line, and the
|
||||
second CU's bases shifted to the first object's merged contribution sizes
|
||||
(e.g. `abbr_offset=0x5a`, `str_offsets_base=0x34`, `stmt_list=0x80`,
|
||||
`addr_base=0x1c`). It also links the same TUs as an archive member and runs
|
||||
the stripped image in MAME with all four markers. The single-TU link is
|
||||
byte-identical to M7, and the stripped load image is unchanged. Caveats: a
|
||||
future producer that emits an unrelocated section-relative field other than
|
||||
the CU abbreviation offset is not silently rewritten (it needs a form-aware
|
||||
DIE walker; this compiler relocates every such field), and
|
||||
`.debug_rnglists` is in the concat set but this compiler's fixtures do not
|
||||
emit it (non-contiguous ranges), so it is supported but unexercised.
|
||||
- **M8.3 — conformance depth and performance.** The M7.4 classifier stopped on
|
||||
`Cannot select` for rotates, `cttz`, `ctpop`/`ctlz` and `bswap`. They now
|
||||
lower without inventing instructions: `rotl`/`rotr` are `Expand`ed and
|
||||
SelectionDAG masks both counts with `ANDI 31` (rotate by 0/32 is the
|
||||
identity); `cttz` is the custom `popcount(~x & (x-1))` sequence (the generic
|
||||
expander would need a constant-pool table this target cannot emit);
|
||||
`ctpop`/`ctlz` use the stock legal shift/mask/add/multiply bit-hacks; and
|
||||
`bswap` is a shift/mask/or byte-lane sequence. `m8-bitops.ll` pins both
|
||||
`-O0` and `-O2`, the zero-poison forms and the literal rotate-by-0/32
|
||||
identities. The new `i64div.wide` path handles "dividend wider than 32 bits,
|
||||
divisor fits 32 bits" with two even-destination `DIVU`s
|
||||
(`q1 = hi/d`, `r1 < d`, `q0 = (r1:lo)/d`, `q = q1<<32 | q0`,
|
||||
`r = lo - q0*d`), shared with the existing signed magnitude/sign fixup; it
|
||||
is outlined into `__tms34010_i64_udiv32`/`..._urem32` so the 64-step loop
|
||||
stays spill-free. The existing one-`DIVU` fits-32 path is unchanged.
|
||||
`scripts/tests/m7/i64div.sh` now measures three equal 16,384-iteration
|
||||
phases: fast **87** frames, slow **2,440** (28.0×) and wide **218** (11.2×),
|
||||
status `600D600D`, checksums `000000011E6F9AB4`, `00000000007512AE` and
|
||||
`00025AF70AF974E0`.
|
||||
- **M8.3 flips and loader budgets.** Twenty curated rows flipped to pass: six
|
||||
rotates (`20020226-1`, `20020508-1`, `20100805-1`, `20180112-1`, `pr119428`,
|
||||
`pr97386-2`), six `cttz` (`builtin-bitops-1`, `ffs-1`, `ffs-2`, `pr37780`,
|
||||
`pr61725`, `pr97325`), four `bswap` (`bswap-1`, `pr108064`, `pr64718`,
|
||||
`pr90025`) and four frame-limited runtime rows (`20040811-1`, `pr43220`,
|
||||
`strcmp-1`, `vla-dealloc-1`). The last four carry a validated per-test
|
||||
`LOADER_END=2000` in `scripts/tests/m7/full-suite.loader-end`; the shipped
|
||||
default stays 1000, and a table row may be above or below an explicit global
|
||||
`LOADER_END` because it records the budget the row was validated at (1000
|
||||
floor, 20000 sanity cap). `pr63843` remains a skip: the M7.4 pin failed its
|
||||
`bar` with a bswap `Cannot select`, the M8 base already compiled it to
|
||||
shifts, and it then reaches a pre-existing runtime hang (status 1, no
|
||||
completion magic). The reduced `bar()`-only reproducer and both logs are
|
||||
retained under `build/m8-task3-pr63843/reduced/`.
|
||||
- **M8.4 — hardware.** The real VT1200 run remains **DEFERRED**:
|
||||
`VT1200_HOST` is unset and no unit is available. `scripts/tests/m7/hardware.sh`
|
||||
still builds the marker COFF at the proven hardware origins, validates it in
|
||||
MAME through the dwt loader and prints `HARDWARE: DEFERRED`; setting
|
||||
`VT1200_HOST` additionally runs `hostload.py --marker` over rdebug. No
|
||||
hardware pass is claimed.
|
||||
- **Counts at M8.** lit **120/120** (116 CodeGen: 34 `m2-*`, 8 `m3-*`, 18
|
||||
`m4-*`, 15 `m5-*`, 28 `m6-*`, 11 `m7-*`, 2 `m8-*`; plus 4 MC), clang
|
||||
Sema/CodeGen **5/5**, M5 c-torture **79/79** at `-O0` and `-O2`, M6
|
||||
c-torture **79** at `-O0` + **20** bounded `-O2`, shipped c-testsuite
|
||||
**48 pass / 172 skip / 220**, Generic **197 = 151 pass / 46 unsupported /
|
||||
0 crash** (M8.3 removed the `2008-02-04-Ctlz` and `llvm-ct-intrinsics`
|
||||
expected-fails). The fresh end-to-end full suite is **1,912 = 1,596 pass / 316
|
||||
skip / 0 fail / 0 crash**; the 316 skips are 64 classifier and 252 curated
|
||||
rows, every one with a reason. The M7.1–M7.4 counts are otherwise unchanged.
|
||||
- **Boundary.** M8 is complete. The remaining genuine conformance classes are
|
||||
`blockaddress`, vector `.data`, inline-asm constraints, nested functions,
|
||||
VLAs, sret/aggregate/variadic/float returns, libm and the remaining runtime
|
||||
aborts; the pre-existing `pr63843` hang and further performance work are
|
||||
also open. The real VT1200 run remains deferred until the unit is available.
|
||||
M9 owns those classes and the hardware run.
|
||||
|
||||
## What M7.4 provides
|
||||
|
||||
@@ -166,6 +289,18 @@ language semantics and no default branch. Full target rules are in
|
||||
0 crash**; c-testsuite **220 = 210 pass / 10 skip / 0 fail / 0 crash**;
|
||||
**all 1,912 = 1,576 pass / 336 skip / 0 fail / 0 crash**. Nothing is
|
||||
unclassified and no crash is counted as a pass.
|
||||
- **Two-tier conformance harness.** The suite defaults to a bare-metal MAME
|
||||
tier: the COFF sections are mapped at their paddrs, `.bss` is zeroed,
|
||||
`PC`/`SP` are set, and the test runs without the VT1200 firmware or COFF
|
||||
loader. The M8 totals are unchanged (**1,596 / 316 / 0 / 0**), but the run
|
||||
is ~35 minutes (2,133 test-seconds) instead of ~2 h 52 m. The bare tier uses
|
||||
the 1990 r5.01 OS/2 assembler through 2ine (direct loader; qemu-i386
|
||||
fallback) and the host `tms-link`; `scripts/m8/setup-os2.sh` provisions it.
|
||||
The full-loader tier remains for the curated M5/M6 gates, X11/runtime/loader
|
||||
and hardware, plus an explicit 10-test
|
||||
`scripts/tests/m7/full-suite.full-loader` list (each with a reason);
|
||||
`M5_CONFORMANCE_BARE=0` selects it, and `M5_CONFORMANCE_BARE=1` is the
|
||||
default for the corpus driver.
|
||||
- **Skip classes.** The 336 skips are 64 classifier skips and 272 curated
|
||||
rows, each with a reason. The main classes (with c-torture counts) are
|
||||
inline-asm register/memory constraints **33**, nested functions **30**,
|
||||
@@ -230,16 +365,17 @@ language semantics and no default branch. Full target rules are in
|
||||
c-torture **79** at `-O0` + **20** bounded `-O2`, shipped c-testsuite
|
||||
**48 pass / 172 skip / 220**, Generic **197 = 149 pass / 48 unsupported /
|
||||
0 crash**. The M7.1/M7.2/M7.3 counts are otherwise unchanged.
|
||||
- **Boundary.** M7 is complete. The known limitations carried into M8 are:
|
||||
one debug-bearing TU per link (multi-TU DWARF merging is loud), `.lib`
|
||||
archives are not readable by `tms-link` and the native-link/CONFORMANCE
|
||||
path keeps GSPLNK, a kept-debug image is not a load image, and the real
|
||||
VT1200 hardware run is still **DEFERRED**. M8 owns multi-TU DWARF merging,
|
||||
`.lib` linking under `tms-link`, the real unit run, the remaining
|
||||
conformance classes (sret/varargs/float returns, nested functions, VLAs,
|
||||
inline-asm constraints, vector/rotate/bit-reverse/`blockaddress`/`bswap`/
|
||||
`cttz` codegen, the recorded compiler crashes, larger images, libm and the
|
||||
frame-limited timeouts) and further performance work.
|
||||
- **Boundary.** M7 is complete. The limitations carried into M8 were: one
|
||||
debug-bearing TU per link (multi-TU DWARF merging is loud), `.lib` archives
|
||||
not readable by `tms-link` and the native-link/CONFORMANCE path keeping
|
||||
GSPLNK, a kept-debug image not being a load image, and the real VT1200
|
||||
hardware run still **DEFERRED**. M8 delivered native archive linking,
|
||||
multi-TU DWARF merging, the rotate/count/byte-swap lowering and the 64/32
|
||||
i64 divide path. The remaining classes (sret/varargs/float returns, nested
|
||||
functions, VLAs, inline-asm constraints, vector data,
|
||||
`blockaddress`, libm and the runtime aborts), the pre-existing `pr63843`
|
||||
hang, further performance work and the real unit run are the M8/M9
|
||||
boundary.
|
||||
|
||||
## What M7.3 provides
|
||||
|
||||
@@ -596,17 +732,22 @@ sub-byte stride itself (diagnostic only), and the odd-offset raw-GSPA pointer
|
||||
shape. The M6 native-linker/`.cinit` gap is closed by M7.2 (see "What M7.2
|
||||
provides").
|
||||
|
||||
**M7/M8 boundary.** M7 is complete. M7.1 delivered the `-O2` bit-pointer
|
||||
barrier, the sub-byte stride diagnostic and the `.data` aggregate-initializer
|
||||
extension; M7.2 the debug object sections, `.cinit` and `tools/tms-link`
|
||||
(including public long names); M7.3 the six wider Xlib entries, `xmore`, the
|
||||
stderr stream and the deferred hardware harness; and M7.4 the full external
|
||||
suites, the i64 divide/remainder fast path and the conformance-loader COFF
|
||||
repair. Real-hardware confirmation is still **deferred** (the unit is away);
|
||||
MAME plus the existing dwt loader is the acceptance environment, and
|
||||
`VT1200_HOST` enables the real run without changing the gate. M8 owns
|
||||
multi-TU DWARF merging, `.lib` linking under `tms-link`, the real VT1200 run,
|
||||
the remaining conformance classes and further performance work.
|
||||
**M8/M9 boundary.** M7 is complete and M8 is complete. M7.1 delivered the `-O2`
|
||||
bit-pointer barrier, the sub-byte stride diagnostic and the `.data`
|
||||
aggregate-initializer extension; M7.2 the debug object sections, `.cinit` and
|
||||
`tools/tms-link` (including public long names); M7.3 the six wider Xlib
|
||||
entries, `xmore`, the stderr stream and the deferred hardware harness; M7.4
|
||||
the full external suites, the i64 divide/remainder fast path and the
|
||||
conformance-loader COFF repair. M8.1 added native `ar` archive linking with
|
||||
GSPLNK parity; M8.2 multi-TU DWARF merging; M8.3 the bit-op lowering, the
|
||||
64/32 i64 divide path, 20 full-suite flips and per-test loader budgets; M8.4
|
||||
the final docs and boundary. Real-hardware confirmation is still **deferred**
|
||||
(the unit is away); MAME plus the existing dwt loader is the acceptance
|
||||
environment, and `VT1200_HOST` enables the real run without changing the gate.
|
||||
M9 owns the remaining conformance classes (`blockaddress`, vector data,
|
||||
inline-asm constraints, nested functions, VLAs, sret/aggregate/variadic/float
|
||||
returns, libm, runtime aborts), the pre-existing `pr63843` hang, further
|
||||
performance work and the real VT1200 run once the unit is available.
|
||||
|
||||
## What M5 provides
|
||||
|
||||
@@ -721,15 +862,15 @@ surface on top. The M5 state below is the baseline.
|
||||
under the ignored `vendor/conformance` (test-only; GCC is GPL and
|
||||
c-testsuite keeps its own per-test licenses; neither is distributed). The
|
||||
GCC version is only the c-torture corpus source; the compiler under test is
|
||||
`tms-clang`. The shipped tiers at the M7.4 head are
|
||||
LLVM `CodeGen/Generic` (197 `.ll`: 149 pass / 48 unsupported / 0 crash, plus
|
||||
`tms-clang`. The shipped tiers at the M8 head are
|
||||
LLVM `CodeGen/Generic` (197 `.ll`: 151 pass / 46 unsupported / 0 crash, plus
|
||||
a 24-file curated allowlist), GCC c-torture `execute` (curated 79/79 at
|
||||
`-O0` and `-O2`; M6 Task 8 expanded the shared list from 59 to 79), and
|
||||
c-testsuite `single-exec` (curated 48 pass / 172 skip / 220, with exact
|
||||
`.c.expected` output). M7.4 additionally runs the **full** corpora through
|
||||
the classifier and runner: c-torture 1,692 = **1,366 pass / 326 skip / 0
|
||||
`.c.expected` output). M8 re-runs the **full** corpora end-to-end through
|
||||
the classifier and runner: c-torture 1,692 = **1,386 pass / 306 skip / 0
|
||||
fail / 0 crash**, c-testsuite 220 = **210 pass / 10 skip / 0 fail / 0
|
||||
crash**. The shim provides `printf`/`sprintf` with a
|
||||
crash** (all 1,912 = 1,596 / 316 / 0 / 0). The shim provides `printf`/`sprintf` with a
|
||||
real `va_list` walk and `%ld`/`%lld`/`%f` plus width/precision,
|
||||
`putchar`/`puts`, `exit`/`abort`, a 16 KiB stdout buffer, a distinct 16 KiB
|
||||
stderr stream (`fprintf`/`vfprintf`/`fputs`/`fputc`/`fwrite`, length at
|
||||
@@ -901,7 +1042,7 @@ M2 replaces the M1 test convention with the TI ABI and stops at assembly:
|
||||
|
||||
## The TI ABI
|
||||
|
||||
| | M1 test convention (branch `m1`) | TI ABI (M2–M7.4) |
|
||||
| | M1 test convention (branch `m1`) | TI ABI (M2–M8) |
|
||||
|---|---|---|
|
||||
| Integer/pointer arguments | `A0`–`A3`, four maximum | program stack via `A14` (STK), pushed in reverse |
|
||||
| Argument slots | registers | first at `FP(-32)`, second at `FP(-64)`, … |
|
||||
@@ -920,20 +1061,22 @@ sign-extending) and `FS1` must be 32 at function entry and immediately after
|
||||
every `CALLA` (`SETF 16,1,0` then `SETF 32,0,1`), because ROM code may change
|
||||
either field size. FS0 drives `short` loads/stores and FS1 drives 32-bit words.
|
||||
|
||||
## Run the M7.4 gates
|
||||
## Run the M8 gates
|
||||
|
||||
These are the documented commands on branch `m7`; all must pass. The MAME and
|
||||
These are the documented commands on branch `m8`; all must pass. The MAME and
|
||||
conformance gates are slow, share the M4 SDK image, and must run **serially**
|
||||
(no two gates at once). The M7.4 gate list is the M7.1/M7.2/M7.3/M5/M6 list
|
||||
plus the full-suite accounting and i64 performance gates in step 3e. The only
|
||||
count change is lit **117 → 118** from the new `m7-i64div-fast.ll`.
|
||||
(no two gates at once). The M8 gate list is the M7.1/M7.2/M7.3/M5/M6 list
|
||||
plus the M8.1/M8.2 library and multi-TU DWARF gates (step 3e), the fresh
|
||||
end-to-end full suite and the i64 performance gate (step 3f). The count change
|
||||
is lit **118 → 120** from `m8-bitops.ll` and `m8-i64div-wide.ll`; the fresh
|
||||
full-suite total is **1,596 pass / 316 skip / 0 fail / 0 crash**.
|
||||
|
||||
```sh
|
||||
# 1. Build llc, the assembler/disassembler driver and dwarfdump
|
||||
ninja -C build/llvm-clean-build llc clang opt llvm-mc llvm-dwarfdump
|
||||
|
||||
# 2. LLVM codegen tests: 114 passed
|
||||
# (34 m2-* + 8 m3-* + 18 m4-* + 15 m5-* + 28 m6-* + 11 m7-*)
|
||||
# 2. LLVM codegen tests: 116 passed
|
||||
# (34 m2-* + 8 m3-* + 18 m4-* + 15 m5-* + 28 m6-* + 11 m7-* + 2 m8-*)
|
||||
build/llvm-clean-build/bin/llvm-lit -v \
|
||||
build/llvm-clean/llvm/test/CodeGen/TMS34010
|
||||
|
||||
@@ -968,19 +1111,29 @@ scripts/tests/m7/hardware.sh # marker COFF (tms-link + GSPLNK oracle)
|
||||
VT1200_HOST=100.103.100.103 scripts/tests/m7/hardware.sh
|
||||
# -> runs hostload.py --marker --coff ... --tag hwmark and propagates failure
|
||||
|
||||
# 3e. M7.4 full external suites (accounting/resume; no MAME once all rows are
|
||||
# retained) and the i64 fast-path performance gate (MAME; serial)
|
||||
LLVM_BIN=/tmp/opencode/m74-llvm/bin \
|
||||
scripts/tests/m7/full-suite.sh --corpus all --work build/m7-full-suite
|
||||
# -> c-torture 1692 = 1366 pass / 326 skip / 0 fail / 0 crash
|
||||
# 3e. M8.1 native archive/library and M8.2 multi-TU DWARF gates (MAME; serial)
|
||||
scripts/tests/m8/native-lib.sh # FLIB/RTS through tms-link, GSPLNK parity
|
||||
scripts/tests/m8/dwarf-multi.sh # two -g TUs, dwarfdump, stripped MAME
|
||||
M5_NATIVE_LINKER=tms-link scripts/tests/m5/native.sh
|
||||
M6_LINKER=tms-link scripts/tests/m6/runtime.sh
|
||||
M6_LINKER=tms-link scripts/tests/m6/i64.sh
|
||||
# -> the M5/M6 library links accept tms-link; GSPLNK stays the default/oracle
|
||||
|
||||
# 3f. M8.3 full external suites (two-tier: bare default ~35 min; serial) and
|
||||
# the i64 fast/wide performance gate (MAME; serial)
|
||||
scripts/m8/setup-os2.sh # once: direct 2ine + qemu-i386 fallback
|
||||
LLVM_BIN=$PWD/build/llvm-clean-build/bin \
|
||||
scripts/tests/m7/full-suite.sh --corpus all --redo --work build/m8-bare-full
|
||||
# -> c-torture 1692 = 1386 pass / 306 skip / 0 fail / 0 crash
|
||||
# c-testsuite 220 = 210 pass / 10 skip / 0 fail / 0 crash
|
||||
# all 1912 = 1576 pass / 336 skip / 0 fail / 0 crash
|
||||
# The retained work directory pins that isolated 74e58126 snapshot (source
|
||||
# rev 7c44990a6c8d); a resume with a different clang/llc binary is refused.
|
||||
# Use a fresh --work (with --record-compiler) to measure the current build.
|
||||
scripts/tests/m7/i64div.sh # fast DIVU vs the 64-step loop in MAME
|
||||
# -> M7 I64DIV PERF: PASS; fast_frames=90 slow_frames=2424 ratio=26.9,
|
||||
# status=600D600D cs_fast=000000011E6F9AB4 cs_slow=00000000007512AE
|
||||
# all 1912 = 1596 pass / 316 skip / 0 fail / 0 crash
|
||||
# The 10 full-loader exceptions are in scripts/tests/m7/full-suite.full-loader.
|
||||
# The fresh TSV/report are in build/m8-bare-full and
|
||||
# scripts/tests/m7/full-suite-report.txt.
|
||||
scripts/tests/m7/i64div.sh # 32-bit DIVU and the 64/32 wide path in MAME
|
||||
# -> M7 I64DIV PERF: PASS; fast_frames=87 slow_frames=2440 wide_frames=218,
|
||||
# ratio=28.0 wide_ratio=11.2 status=600D600D
|
||||
# cs_fast=000000011E6F9AB4 cs_slow=00000000007512AE cs_wide=00025AF70AF974E0
|
||||
|
||||
# 4. M6 language/runtime gates (MAME; run serially)
|
||||
scripts/tests/m6/spike.sh # hand-written flib/rts ABI probe
|
||||
@@ -1019,6 +1172,7 @@ scripts/tests/m6/c-testsuite.sh # 48 exact-output tests at -O0
|
||||
|
||||
# 9. M4, M3 and M2 regressions and the GEP tool
|
||||
scripts/tests/m4/run.sh
|
||||
M4_NATIVE=1 M4_LINKER=tms-link scripts/tests/m4/run.sh
|
||||
scripts/tests/m4/dis-roundtrip.sh
|
||||
scripts/tests/m4/layout.sh
|
||||
scripts/tests/m4/symbols.sh
|
||||
@@ -1049,10 +1203,10 @@ The gate log prints each tier's counts; skipped tests carry a feature reason
|
||||
and are never counted as passes. The conformance tiers run serially because
|
||||
`M4_SDK` is shared; the MAME boot dominates the runtime.
|
||||
|
||||
## Run the M4 gates (branch `m4`; also green on `m5`/`m6`/`m7`)
|
||||
## Run the M4 gates (branch `m4`; also green on `m5`–`m8`)
|
||||
|
||||
These are the documented commands on branch `m4`; all must pass. On branches
|
||||
`m5`/`m6`/`m7`, use the M7.2 list above (it includes `llvm-mc`,
|
||||
`m5`–`m8`, use the M8 list above (it includes `llvm-mc`,
|
||||
`llvm-dwarfdump`, the M7.2 gates and the M5/M6 gates); the M4
|
||||
commands below remain the historical regression set and use the `m4` test
|
||||
counts. The MAME gates are slow and are run once.
|
||||
@@ -1461,7 +1615,7 @@ gates are likewise test/runtime inputs, extracted from the SDK into
|
||||
## Repository layout
|
||||
|
||||
```text
|
||||
build/llvm-clean/ compiler fork checkout used for M2–M7.4 (ignored)
|
||||
build/llvm-clean/ compiler fork checkout used for M2–M8 (ignored)
|
||||
build/llvm-clean-build/ its Ninja build tree (ignored)
|
||||
build/m6-sdk/ extracted 1990 flib.lib/rts.lib (ignored, not vendored)
|
||||
build/llvm-src/ M0 working fork (ignored)
|
||||
@@ -1490,6 +1644,8 @@ scripts/tests/m6/ M6 gates (spike/i64/float/varargs/bitfield/aggregate/ru
|
||||
scripts/tests/m7/ M7.1/M7.2/M7.3/M7.4 gates and drivers (pointer-o2/stride/data;
|
||||
link/oracle/cinit/longname/debug/xlib/hardware;
|
||||
full-suite/i64div)
|
||||
scripts/m8/ M8 archive/library and multi-TU DWARF fixtures/checkers
|
||||
scripts/tests/m8/ M8.1 native-lib and M8.2 dwarf-multi gates (+ COFF parity)
|
||||
scripts/m1/ M1 harness (historical; also on branch `m1`, not an M2 gate)
|
||||
scripts/tests/m1/ M1 gates (historical; also on branch `m1`, not an M2 gate)
|
||||
scripts/tests/m0/ M0 integration tests
|
||||
@@ -1504,7 +1660,7 @@ docs/ design and plans
|
||||
## Prerequisites
|
||||
|
||||
`cmake`, `ninja-build`, `ccache`, a C++17 host compiler (GCC 14 is used here),
|
||||
Python 3, and about 20 GB of disk for the LLVM source and build. The M2–M7.4
|
||||
Python 3, and about 20 GB of disk for the LLVM source and build. The M2–M8
|
||||
MAME and dis34 gates additionally need `dosbox`, `mtools` (`mcopy`), the
|
||||
VT1200 SDK image, the `dwt` COFF loader, `dis34`, and a built MAME `vt1200`
|
||||
binary (`build/mame-src/vt1200`). The termtris gate also needs the pinned
|
||||
@@ -1529,13 +1685,14 @@ Xlib call sequence, `as34`, `dis34`, SDKs, manuals). It is not vendored:
|
||||
|
||||
## Build the compiler
|
||||
|
||||
### Compiler fork (M7.4, the normal path)
|
||||
### Compiler fork (M8, the normal path)
|
||||
|
||||
The fork checkout already exists at `build/llvm-clean` on `m7`. Build it in
|
||||
The fork checkout already exists at `build/llvm-clean` on `m8` (the current
|
||||
milestone branch and repository default). Build it in
|
||||
place:
|
||||
|
||||
```sh
|
||||
LLVM_SRC=$PWD/build/llvm-clean LLVM_BRANCH=m7 ./scripts/build-llvm.sh
|
||||
LLVM_SRC=$PWD/build/llvm-clean LLVM_BRANCH=m8 ./scripts/build-llvm.sh
|
||||
# binaries: build/llvm-clean-build/bin/{llc,llvm-mc,clang,opt,llvm-config,FileCheck}
|
||||
# lit driver: build/llvm-clean-build/bin/llvm-lit
|
||||
```
|
||||
@@ -1544,7 +1701,7 @@ To clone the fork first instead of using an existing checkout:
|
||||
|
||||
```sh
|
||||
LLVM_REPO=gitea@git.wut.ee:opencode.siil.arti.ee/llvm-tms34010.git \
|
||||
LLVM_BRANCH=m7 ./scripts/build-llvm.sh
|
||||
LLVM_BRANCH=m8 ./scripts/build-llvm.sh
|
||||
```
|
||||
|
||||
Fork mode **never** checks out, resets, cleans or patches the source tree; it
|
||||
@@ -1570,7 +1727,7 @@ M1–M6.
|
||||
|
||||
## Build the M0 support tools
|
||||
|
||||
The M2–M7.4 pipeline uses `tms-bitaddr` (`--scale`, `--normalize`, `--bitptr`,
|
||||
The M2–M8 pipeline uses `tms-bitaddr` (`--scale`, `--normalize`, `--bitptr`,
|
||||
`--lower-bitptr`) and `tms-clang`:
|
||||
|
||||
```sh
|
||||
@@ -1578,7 +1735,7 @@ LLVM_CONFIG=$PWD/build/llvm-clean-build/bin/llvm-config \
|
||||
tools/tms-bitaddr/build.sh
|
||||
```
|
||||
|
||||
M0 regression test (optional in M2–M7.4):
|
||||
M0 regression test (optional in M2–M8):
|
||||
|
||||
```sh
|
||||
TMS_CLANG=$PWD/build/llvm-clean-build/bin/clang \
|
||||
@@ -1704,9 +1861,12 @@ oracle. M7.3 is complete: the wider validated Xlib surface and `xmore` client,
|
||||
exact stderr capture, and the hardware marker harness with MAME-equivalent
|
||||
acceptance (the real-unit run is **deferred**; set `VT1200_HOST` to run it).
|
||||
M7.4 is complete: the full external suites, the i64 divide/remainder fast
|
||||
path and the final M7/M8 boundary. M8 owns multi-TU DWARF merging, `.lib`
|
||||
linking under `tms-link`, the real VT1200 hardware run while still deferred,
|
||||
the remaining conformance classes and further performance work.
|
||||
path and the final M7/M8 boundary. M8 is complete: native `.lib` archive
|
||||
linking in `tms-link`, multi-TU DWARF merging, the rotate/count/byte-swap
|
||||
lowering and 64/32 i64 divide path, 20 conformance flips and the final
|
||||
M8/M9 boundary. M9 owns the remaining conformance classes, the pre-existing
|
||||
`pr63843` hang, further performance work and the real VT1200 run when the
|
||||
unit is available (the run remains **deferred**).
|
||||
2ine r5.01 is a later speed-up for the GSPA/GSPLNK step. The compiler fork is
|
||||
canonical for target code; this project holds the plan, harness, pins and
|
||||
integration tests.
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
# TMS34010 M8 — Native Archives, Multi-TU DWARF, Conformance Depth and Hardware Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Close the M7/M8 boundary: make `tms-link` read the 1990 TI-COFF archives so the native path no longer needs GSPLNK for `flib`/`rts`, merge debug information from multiple translation units, deepen the conformance pass rate and performance evidence, and close out M8 with the hardware status and boundary.
|
||||
|
||||
**Architecture:** `tms-link` gains an `ar` reader with iterative selective extraction over its existing TI-COFF object model, then a DWARF merge stage that rehomes section-relative offsets and relocations across objects. The conformance/perf work uses the existing full-suite driver and the i64 measurement harness. The hardware harness already exists; M8.4 only runs it if the unit is available and records the result.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m8`), `tms-clang`, `llc`, `tms-link`, TI COFF and `ar` archives, the dwt loader, MAME, `dis34`, `llvm-dwarfdump`, Python 3, the conformance harness, GCC 16.2.0/c-testsuite pins.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M8.1–M8.4); the M7 README/ledger boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- M8 baseline: compiler `llvm-tms34010` `m7` at `e924e0c86343`, project `tms-c-compiler` `m7` at `0f7353c`; work on `m8` in both repos. `m7` remains the repository default unless the user asks; no force-push and no merge into `m0`–`m7`.
|
||||
- Keep every M2–M7.4 gate green, the TI all-stack ABI, the asm/GSPLNK oracle, and the native loader contract (`nreloc=0` linked image).
|
||||
- `.lib` archives are test/runtime inputs; do not vendor them. The 1990 `flib.lib`/`rts.lib` are System V `ar` (`!<arch>`) with TI-COFF members.
|
||||
- Debug merging must keep section-relative DWARF offsets correct; the default load image stays debug-stripped and `--keep-debug` is the tool image.
|
||||
- Full-suite accounting remains one row per file; no crash/unclassified result; skips always carry a reason.
|
||||
- No push until the M8 final review is clean; then push `m8`.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Archive correctness:** `ar` header/member parsing, long names, symbol resolution, iterative extraction, duplicate/undefined behavior, determinism, GSPLNK parity.
|
||||
2. **DWARF merge correctness:** CU/abbrev/str/line/addr offset rehoming, relocations, section-relative values, dwarfdump validation, single-TU compatibility, stripped load image unchanged.
|
||||
3. **Conformance honesty:** full accounting, flipped classes recorded, no hidden passes, performance measurement causal.
|
||||
4. **No regression** and the final boundary accurate.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Native `.lib` linking in `tms-link`
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tms-link`, `tools/tms-link/tmscoff.py`
|
||||
- Create: `tools/tms-link/tests/` archive fixtures/cases
|
||||
- Modify: `scripts/m4/run.sh` (`M4_LINKER=tms-link` accepts `M4_NATIVE_LIBS`/`M4_NATIVE_RTS`)
|
||||
- Test: `tools/tms-link/tests/run.sh`, `scripts/tests/m7/link.sh`, `scripts/tests/m5/native.sh`, `scripts/tests/m6/runtime.sh`, `scripts/tests/m6/i64.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ar` archives with TI-COFF members (`build/m4-sdk/FLIB.LIB`, `RTS.LIB`), the existing object reader/linker, and the M4 hook.
|
||||
- Produces: archive detection/reader; selective extraction of members that define currently-undefined symbols (iterated to a fixpoint); `-l`/path CLI support; duplicate definitions/undefined symbols/unsupported members loud; a linked image with the same section/loader contract.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** A tiny archive fixture (2–3 members, one symbol each) linked by `tms-link`; a missing-symbol and a duplicate-definition negative; a `flib`-only program (e.g. `FD$ADD`) linked without GSPLNK; the current CLI does not read archives.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Parse `!<arch>\n`, 60-byte member headers, decimal sizes, even-byte padding, `/` and `//` special members, and `/N`/name forms; reject malformed archives loudly.
|
||||
- Add archive members to the link as candidate objects; extract only members that define an undefined symbol, iterating (archive semantics), never re-extracting a member; duplicate/undefined symbols fail with names.
|
||||
- CLI: accept `-l LIB` and archive paths; preserve object inputs, `--entry`, layout, map, debug strip/keep.
|
||||
- `scripts/m4/run.sh`: allow `M4_LINKER=tms-link` with `M4_NATIVE_LIBS`/`M4_NATIVE_RTS`; pass library paths; keep GSPLNK the default and the oracle.
|
||||
- [x] **Step 4: Run green.** Unit/archive tests; the M5 native and M6 runtime/i64 links with `tms-link` + libs; GSPLNK byte/symbol parity; MAME markers; one full native run. Do not regress non-library links.
|
||||
- [x] **Step 5: Commit** (project; compiler unchanged unless a target bug appears).
|
||||
|
||||
### Task 2: Multi-TU DWARF merging
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tms-link`, `tools/tms-link/tmscoff.py`
|
||||
- Create: `scripts/tests/m8/dwarf-multi.sh`, fixtures (`scripts/m8/debug-a.c`, `debug-b.c`, entry)
|
||||
- Test: `scripts/tests/m7/debug.sh` (single-TU compatibility), `llvm-dwarfdump`, MAME
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: multiple `--keep-debug`-capable debug-bearing objects from Task 1's linker and the M7 debug sections.
|
||||
- Produces: merged `.debug_info`/`.debug_abbrev`/`.debug_str`/`.debug_str_offsets`/`.debug_line`/`.debug_addr` (and related) sections with rehomed section-relative offsets/relocations across CUs; single-TU output unchanged; loud failure on unsupported shapes.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** Two TUs with functions/lines, linked `--keep-debug`; the current linker refuses >1 debug object. Wrap the sections in the test ELF container and require `llvm-dwarfdump` to show both TUs' files/functions/lines/addresses.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Concatenate `.debug_info`/`.debug_line`/etc. while relocating each object's section-relative contributions: `.debug_abbrev` offsets in CU headers, `.debug_str_offsets` bases, `.debug_addr` bases, `.debug_line`/`.debug_line_str` offsets, and cross-section relocations to allocated sections.
|
||||
- Resolve relocations against the linked section layout; keep debug sections section-relative (paddr 0), `nreloc=0`.
|
||||
- Preserve the single-debug-TU output; refuse unsupported DWARF shapes loudly.
|
||||
- [x] **Step 4: Run green.** Multi-TU dwarfdump, single-TU `m7/debug.sh`, the stripped image in MAME, the M7.2 gates.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 3: Conformance depth and performance
|
||||
|
||||
**Files:**
|
||||
- Modify: the relevant target lowering/tests for fixed classes; the full-suite skip file; the perf driver if extending it
|
||||
- Test: `scripts/tests/m7/full-suite.sh` (accounting), `scripts/tests/m7/c-torture.sh`/`c-testsuite.sh`, `scripts/tests/m7/i64div.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M7.4 full-suite baseline (1,576 pass / 336 skip / 0 fail / 0 crash).
|
||||
- Produces: additional fixed classes with flipped counts, an updated honest skip list, and at least one new measured performance path (e.g. 64/32 i64 division when the divisor fits 32 bits).
|
||||
|
||||
- [x] **Step 1: Pick the highest-value classes** from the retained skip classes (rotates/`cttz`/`bswap`/`blockaddress`; inline-asm constraints; one ABI return shape; one timeout/image-size case) and write failing lit/runtime tests.
|
||||
- [x] **Step 2: Implement** the fixes, update the skip curation only where the class remains a genuine M8/M9 boundary, and re-run the affected full-suite rows.
|
||||
- [x] **Step 3: Performance:** implement and measure the 64/32 fast path (or an equally justified path) against the existing slow path; record frames/checksums.
|
||||
- [x] **Step 4: Run green** and record the new exact counts/flips.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Hardware status, final M8 docs, full gates, final review, push
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, the spec (M8 status)
|
||||
- Test: the full M0–M8 list
|
||||
|
||||
- [x] **Step 1: Hardware.** If the VT1200 is available, run `VT1200_HOST=… scripts/tests/m7/hardware.sh` and record the real-unit evidence; otherwise keep `HARDWARE: DEFERRED` explicit. Do not fake a pass.
|
||||
- [x] **Step 2: Docs.** Record M8.1/M8.2/M8.3 results, the final full-suite/perf counts, the remaining limitations, and the M8/M9 boundary.
|
||||
- [x] **Step 3: Gates and review.** Run the full serial list, commit, final whole-branch review, then push `m8` (default stays `m7` unless asked).
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M8.1 makes the native path library-complete; M8.2 makes debug info multi-TU; M8.3 raises the conformance/performance surface; M8.4 closes the milestone with the hardware status and boundary. The compiler repo remains canonical for target code; the project holds the linker, harness, plans and gates.
|
||||
@@ -574,6 +574,88 @@ and not for byte-multiple records; `.data` i64/aggregate/bitfield globals
|
||||
assemble/link/load with exact bytes; every M2–M6 gate stays green; MAME and
|
||||
the dwt loader are the acceptance environment.
|
||||
|
||||
### M8 — object/link completeness, conformance depth, hardware
|
||||
|
||||
M8 closes the M7/M8 boundary in four workstreams, using the same plan,
|
||||
subagent-driven execution, review and push discipline as M7. The `m7` branch
|
||||
is the M8 baseline and the repository default; M8 work is on `m8` and does not
|
||||
change the default unless the user asks.
|
||||
|
||||
- **M8.1 — native `.lib` linking.** `tools/tms-link` reads System V/`ar`
|
||||
archives (the 1990 `flib.lib`/`rts.lib` are `!<arch>` with TI-COFF members),
|
||||
performs iterative selective extraction of members that define needed
|
||||
symbols, resolves duplicate/undefined symbols loudly, and exposes the
|
||||
libraries through the CLI and the `M4_LINKER=tms-link` path. GSPLNK remains
|
||||
the oracle; the M5/M6 native and runtime gates must produce the same
|
||||
allocated bytes/symbol addresses (and MAME markers) with either linker.
|
||||
Acceptance: M4/M5/M6 native links that need `flib`/`rts` link with
|
||||
`tms-link`, produce a loader-accepted image with the expected markers, and
|
||||
match GSPLNK on the allocated image; unmatched/duplicate archive symbols
|
||||
fail loudly.
|
||||
- **M8.2 — multi-TU DWARF merging.** The native linker merges debug
|
||||
information from multiple debug-bearing objects: concatenate `.debug_info`
|
||||
CUs while adjusting `.debug_abbrev`/`.debug_str_offsets`/`.debug_addr`/
|
||||
`.debug_line` section-relative contributions and their relocations; keep
|
||||
section-relative offsets correct, resolve line/file tables, and validate the
|
||||
result with `llvm-dwarfdump`. The default load image remains debug-stripped;
|
||||
`--keep-debug` is the tool image. Acceptance: a two- or three-TU program
|
||||
built with debug info links with `--keep-debug`, `llvm-dwarfdump` reports
|
||||
every TU's functions/lines/addresses, and the stripped image still runs in
|
||||
MAME; a single-TU link remains byte-compatible with M7.
|
||||
- **M8.3 — conformance depth and performance.** Raise the full-suite pass
|
||||
rate by fixing or honestly re-curating the remaining classes (codegen
|
||||
rotates/`cttz`/`bswap`/`blockaddress`/vectors, inline-asm constraints,
|
||||
sret/aggregate/variadic/float returns, VLAs, nested functions, libm and the
|
||||
frame-limited timeouts), and extend performance work beyond the 32-bit i64
|
||||
fast path (e.g. a 64/32 path when the divisor fits 32 bits) with measured
|
||||
evidence. Acceptance: the full pinned corpora still account for every file
|
||||
with 0 unclassified crashes and an honest skip list; the newly fixed classes
|
||||
flip to pass and are recorded; any new performance path is measured against
|
||||
the existing slow path.
|
||||
- **M8.4 — hardware and close-out.** Run the real VT1200 hardware harness when
|
||||
the unit is available (the harness and MAME-equivalent acceptance already
|
||||
exist), record the real-unit evidence, and produce the final M8 docs/counts/
|
||||
limitations and the M8/M9 boundary. The hardware run remains deferred and
|
||||
does not block M8.1–M8.3; if it is still unavailable, mark it deferred and
|
||||
state that explicitly.
|
||||
|
||||
M8.3 also runs the corpora on a bare-metal MAME tier by default (sections
|
||||
mapped, `.bss` zeroed, PC/SP set, no firmware/loader), using the 2ine-hosted
|
||||
1990 OS/2 assembler and `tms-link`; the curated M5/M6 loader gates, X11/runtime
|
||||
and an explicit full-loader exception list keep the loader tier. The accounting
|
||||
and acceptance counts are unchanged.
|
||||
|
||||
M8.1 acceptance: a library-only link (no GSPLNK) resolves the needed members
|
||||
and runs; M8.2 acceptance: multi-TU debug links and validates; M8.3
|
||||
acceptance: the full corpora remain fully accounted with the recorded flips;
|
||||
M8.4 acceptance: the final docs/boundary are accurate and the hardware status
|
||||
is explicit.
|
||||
|
||||
M8 acceptance (met, M8 complete): `tms-link` reads the System V `ar`
|
||||
`FLIB.LIB`/`RTS.LIB`, extracts needed members iteratively and links the M4/M5/
|
||||
M6 library programs with allocated bytes, section metadata and public symbols
|
||||
equal to GSPLNK 2.00 (`scripts/tests/m8/native-lib.sh`, 3 sections, 16 public
|
||||
`C_EXT` addresses, MAME markers). Multi-TU `--keep-debug` concatenates and
|
||||
rehomes the supported DWARF5 sections; `llvm-dwarfdump` shows both TUs'
|
||||
functions, lines and linked PCs, the stripped image runs in MAME, and the
|
||||
single-TU link is byte-identical to M7 (`scripts/tests/m8/dwarf-multi.sh`).
|
||||
The bit-op class (rotate/`cttz`/`ctpop`/`ctlz`/`bswap`) lowers without invented
|
||||
instructions, and the 64/32 i64 divide path measures **218** frames versus
|
||||
**2,440** for the 64-step loop (11.2×), while the fits-32 path measures **87**
|
||||
(28.0×), status `600D600D`, checksums `000000011E6F9AB4`/
|
||||
`00000000007512AE`/`00025AF70AF974E0`. The fresh end-to-end full suite
|
||||
accounts for **1,912 = 1,596 pass / 316 skip / 0 fail / 0 crash** (c-torture
|
||||
**1,386 / 306**, c-testsuite **210 / 10**), with 64 classifier plus 252
|
||||
curated skips, each with a reason; the 20 flipped rows are the six rotates,
|
||||
six `cttz`, four `bswap` and four per-test `LOADER_END=2000` runtime rows.
|
||||
Lit is **120/120** (116 CodeGen + 4 MC) and clang Sema/CodeGen **5/5**. The
|
||||
real VT1200 run remains **DEFERRED** (`VT1200_HOST` unset; the hardware gate
|
||||
prints `HARDWARE: DEFERRED` on the MAME-equivalent acceptance). M9 owns the
|
||||
remaining conformance classes (`blockaddress`, vector `.data`, inline-asm
|
||||
constraints, nested functions, VLAs, sret/aggregate/variadic/float returns,
|
||||
libm, runtime aborts), the pre-existing `pr63843` hang, further performance
|
||||
work and the real VT1200 run when the unit is available.
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
| risk | mitigation |
|
||||
|
||||
+46
-13
@@ -32,9 +32,16 @@
|
||||
# M4_NATIVE_RAM_LEN=80000h native RAM region length (bits)
|
||||
# M4_LINK_CMD=/path/link.cmd asm-path GSPLNK command file (default link.cmd)
|
||||
# M4_LINKER=tms-link native-mode opt-in: link the GSPA entry/extras
|
||||
# objects with tools/tms-link instead of GSPLNK
|
||||
# (default: gsplnk). Requires M4_NATIVE=1 and no
|
||||
# M4_NATIVE_LIBS/M4_NATIVE_RTS yet.
|
||||
# objects and any M4_NATIVE_LIBS/M4_NATIVE_RTS
|
||||
# archives with tools/tms-link instead of GSPLNK
|
||||
# (default: gsplnk, which remains the oracle).
|
||||
# Requires M4_NATIVE=1.
|
||||
# M4_OS2=1 assemble/link with the 1990 r5.01 OS/2 tools
|
||||
# under 2ine+qemu-i386 instead of DOSBox (run
|
||||
# scripts/m8/setup-os2.sh first; the 1987
|
||||
# GSPA/GSPLNK oracle is still the default)
|
||||
# M4_OS2_LX=/path ../../2ine-tms34010/build-qemu/lx_loader
|
||||
# M4_OS2_SDK=/path extracted r5.01 tree (bin/ and lib/)
|
||||
# M4_SKIP_MAME=1 stop after a clean GSPA/GSPLNK link
|
||||
# M4_COFF_REPAIR=1 validate the linked COFF magic/section sizes and
|
||||
# repair GSPLNK's observed zero-header and
|
||||
@@ -79,6 +86,7 @@ LLC_OPT=${M4_LLC_OPT:--O0}
|
||||
EXTRA_INCLUDES=${M4_EXTRA_INCLUDES:-}
|
||||
EXTRA_CFLAGS=${M4_EXTRA_CFLAGS:-}
|
||||
NATIVE=${M4_NATIVE:-0}
|
||||
OS2=${M4_OS2:-0}
|
||||
NATIVE_SKIP_ASM=${M4_NATIVE_SKIP_ASM:-0}
|
||||
NATIVE_RTS=${M4_NATIVE_RTS:-0}
|
||||
NATIVE_LIBS=${M4_NATIVE_LIBS:-}
|
||||
@@ -103,8 +111,6 @@ esac
|
||||
if [ "$LINKER" = tms-link ]; then
|
||||
[ "$NATIVE" = 1 ] || fail "M4_LINKER=tms-link requires M4_NATIVE=1"
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
[ -z "$NATIVE_LIBS" ] && [ "$NATIVE_RTS" != 1 ] \
|
||||
|| fail "M4_LINKER=tms-link does not read libraries yet; unset M4_NATIVE_LIBS/M4_NATIVE_RTS"
|
||||
fi
|
||||
[ -f "$ENTRY" ] || fail "missing entry: $ENTRY"
|
||||
|
||||
@@ -197,6 +203,12 @@ strip_end() {
|
||||
sed '/^[[:space:]]*\.end[[:space:]]*$/d' "$1"
|
||||
}
|
||||
|
||||
# Optional host-side 1990 OS/2 r5.01 assembler/linker path (2ine + qemu-i386).
|
||||
if [ "$OS2" = 1 ]; then
|
||||
. "$ROOT/scripts/m8/os2-toolchain.sh"
|
||||
os2_init
|
||||
fi
|
||||
|
||||
EXTRAS=
|
||||
if [ -n "${M4_EXTRA_ASM:-}" ]; then
|
||||
for extra in $M4_EXTRA_ASM; do
|
||||
@@ -249,10 +261,18 @@ if [ "$NATIVE" = 1 ]; then
|
||||
[ -f "$SDK/RTS.LIB" ] || fail "RTS.LIB not extracted into $SDK"
|
||||
NATIVE_LIBS="$NATIVE_LIBS rts.lib"
|
||||
fi
|
||||
# Resolve the library names to SDK paths for tms-link. GSPLNK keeps
|
||||
# consuming the -l lines in M4.CMD; the order is identical.
|
||||
NATIVE_LIB_PATHS=
|
||||
for lib in $NATIVE_LIBS; do
|
||||
dos=$(printf '%s' "$lib" | tr '[:lower:]' '[:upper:]')
|
||||
[ -f "$SDK/$dos" ] || [ -f "$SDK/$lib" ] \
|
||||
|| fail "$lib not extracted into $SDK"
|
||||
if [ -f "$SDK/$dos" ]; then
|
||||
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $SDK/$dos"
|
||||
elif [ -f "$SDK/$lib" ]; then
|
||||
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $SDK/$lib"
|
||||
else
|
||||
fail "$lib not extracted into $SDK"
|
||||
fi
|
||||
done
|
||||
{
|
||||
printf '%s\n' '-a' '-o M4.OUT' '-m M4.MAP' '-e _start'
|
||||
@@ -313,7 +333,16 @@ run_dosbox() {
|
||||
-noprimaryconf -nolocalconf "$@" > "$WORK/dosbox.log" 2>&1
|
||||
}
|
||||
|
||||
if [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
||||
if [ "$OS2" = 1 ]; then
|
||||
os2_gspa M4
|
||||
if [ -f "$SDK/M4EXT.ASM" ]; then
|
||||
os2_gspa M4EXT
|
||||
fi
|
||||
# tms-link is a host tool and runs below; the asm/GSPLNK path links here.
|
||||
if [ "$NATIVE" != 1 ] || [ "$LINKER" != tms-link ]; then
|
||||
os2_gsplnk
|
||||
fi
|
||||
elif [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
||||
# tms-link is a host tool: GSPA still assembles the entry/extras objects,
|
||||
# but GSPLNK is not run.
|
||||
if [ -n "$EXTRAS" ]; then
|
||||
@@ -357,8 +386,11 @@ if [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
||||
"$TMS_LINK" -o "$SDK/M4.OUT" --map "$SDK/M4.MAP" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
--prog-len "$NATIVE_PROG_LEN" --ram-len "$NATIVE_RAM_LEN" \
|
||||
$TMSLINK_INPUTS \
|
||||
$TMSLINK_INPUTS $NATIVE_LIB_PATHS \
|
||||
|| fail "tms-link failed"
|
||||
# Keep the pre-coff-check image so parity gates can compare tms-link's
|
||||
# raw output; the repaired $COFF below remains the loader image.
|
||||
cp "$SDK/M4.OUT" "$WORK/M4.RAW.OUT"
|
||||
fi
|
||||
|
||||
check_lst() {
|
||||
@@ -382,7 +414,7 @@ cp "$SDK/M4.OUT" "$COFF"
|
||||
cp "$SDK/M4.ASM" "$WORK/m4.asm"
|
||||
[ ! -f "$SDK/M4EXT.ASM" ] || cp "$SDK/M4EXT.ASM" "$WORK/m4ext.asm"
|
||||
|
||||
ENTRY_ADDR=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m4.map")
|
||||
ENTRY_ADDR=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m4.map" | tr 'a-f' 'A-F')
|
||||
[ "$ENTRY_ADDR" = "018A0000" ] || fail "linker entry _start is '$ENTRY_ADDR', want 018A0000"
|
||||
grep -q 'ENTRY POINT SYMBOL: "_start"' "$WORK/m4.map" \
|
||||
|| fail "linker map has no _start entry point"
|
||||
@@ -437,18 +469,19 @@ timeout "${MAME_TIMEOUT:-900}" "$MAME" vt1200 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
MARKERS=$(grep -E '^(M4|M7): ' "$WORK/mame.log" | tail -1 || true)
|
||||
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; fail "MAME produced no M4/M7 markers"; }
|
||||
MARKERS=$(grep -E '^(M4|M7|M8 LIB): ' "$WORK/mame.log" | tail -1 || true)
|
||||
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; fail "MAME produced no M4/M7/M8 LIB markers"; }
|
||||
echo " $MARKERS"
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; fail "COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -qE '^M[47] MAME: PASS' "$WORK/mame.log" \
|
||||
grep -qE '^M[47] MAME: PASS|^M8 LIB MAME: PASS' "$WORK/mame.log" \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "marker check failed"; }
|
||||
|
||||
case "$MARKERS" in
|
||||
M7:*) echo "M7 MAME: PASS" ;;
|
||||
M8\ LIB:*) echo "M8 LIB MAME: PASS" ;;
|
||||
*) echo "M4 MAME: PASS" ;;
|
||||
esac
|
||||
@@ -13,7 +13,11 @@
|
||||
# M4_NATIVE=1, links them with GSPLNK and runs the M4 image/event MAME check.
|
||||
# The asm/GSPA path remains the default of run.sh.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC LLVM_BIN
|
||||
# M5_NATIVE_LINKER=tms-link runs the same native builds through tools/tms-link
|
||||
# (the termtris run also exercises the rts.lib archive path); the default is
|
||||
# GSPLNK, which remains the oracle.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC LLVM_BIN M5_NATIVE_LINKER
|
||||
# M5_XSHOW_WORK TERMTRIS_WORK TERMTRIS_SDK VT1200_TERMTRIS
|
||||
# M4_SDK DOSBOX DOSBOX_CONF SDK_IMG MAME LOADER_AT LOADER_END
|
||||
set -eu
|
||||
@@ -23,6 +27,7 @@ MODE=${1:-termtris}
|
||||
DIR=$ROOT/scripts/m4
|
||||
TERMTRIS_DIR=$DIR/termtris
|
||||
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
||||
LINKER=${M5_NATIVE_LINKER:-gsplnk}
|
||||
|
||||
fail() {
|
||||
echo "M5 native driver: $*" >&2
|
||||
@@ -33,6 +38,7 @@ case $MODE in
|
||||
xshow)
|
||||
WORK=${M5_XSHOW_WORK:-$ROOT/build/m5-native-xshow}
|
||||
M4_NATIVE=1 \
|
||||
M4_LINKER="$LINKER" \
|
||||
M4_SOURCES="xshow xgfix" \
|
||||
M4_ENTRY="$DIR/xshow-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/xshow-check.lua" \
|
||||
@@ -61,6 +67,7 @@ termtris)
|
||||
# section non-empty, so the empty cinit.asm is sufficient (the asm gate's
|
||||
# CINITZ fallback is only needed when no library contributes .cinit).
|
||||
M4_NATIVE=1 \
|
||||
M4_LINKER="$LINKER" \
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_SOURCES="$SRC/vt1200/main.c $SRC/game.c $SRC/vt1200/scoredb.c $SRC/vt1200/x11.c $SRC/vt1200/compat.c $SRC/vt1200/xgfix.c" \
|
||||
M4_EXTRA_INCLUDES="-I $SRC -I $SRC/vt1200 -I $TERMTRIS_DIR/include" \
|
||||
|
||||
@@ -7,7 +7,7 @@ Usage:
|
||||
MAP is a GSPLNK 2.00 map (the SECTION ALLOCATION MAP has origin/length in
|
||||
bits) or a tms-link map (the symbol addresses give .text/etext,
|
||||
.data/edata, .bss/end). MARKER_HEX is the marker base bit address; the gate
|
||||
uses 8 cells 0x20 bits apart. The optional region arguments are also in hex
|
||||
uses 12 cells 0x20 bits apart. The optional region arguments are also in hex
|
||||
(bits) and bound .text/.data to prog and .bss/the markers to ram.
|
||||
|
||||
Exit status: 0 = every check passed, 1 = overlap/out-of-region, 2 = the map
|
||||
@@ -60,7 +60,7 @@ def main():
|
||||
return 2
|
||||
map_path = sys.argv[1]
|
||||
marker = int(sys.argv[2], 16)
|
||||
marker_end = marker + 8 * 0x20
|
||||
marker_end = marker + 12 * 0x20
|
||||
regions = None
|
||||
if len(sys.argv) == 7:
|
||||
prog_origin, prog_len, ram_origin, ram_len = (
|
||||
|
||||
@@ -9,26 +9,33 @@
|
||||
-- workloads in scripts/m7/i64div-perf.c:
|
||||
--
|
||||
-- fast phase: 16384 iterations, every divide fits 32 bits -> one DIVU each;
|
||||
-- slow phase: 16384 iterations, nonzero high words -> the 64-step loop.
|
||||
-- slow phase: 16384 iterations, both high words nonzero -> the 64-step loop;
|
||||
-- wide phase: 16384 iterations, nonzero dividend high word but a 32-bit
|
||||
-- divisor -> two even-destination DIVUs (the M8.3 64/32 path).
|
||||
--
|
||||
-- The gate requires the fast phase to complete in materially fewer frames
|
||||
-- (slow_frames >= 8 * max(fast_frames, 1)) and the slow phase to be long
|
||||
-- enough to measure (>= 20 frames). A sub-frame fast phase is reported as
|
||||
-- fast_frames=0 and compared as one frame, which can only make the check
|
||||
-- harder.
|
||||
-- harder. The wide phase must also be materially faster than the loop
|
||||
-- (slow_frames >= 4 * max(wide_frames, 1)) and measurable (>= 2 frames).
|
||||
--
|
||||
-- Both phase checksums are required to equal the deterministic values below.
|
||||
-- They were computed from the same LCG/arithmetic with an independent host
|
||||
-- implementation of scripts/m7/i64div-perf.c (see the header comment there):
|
||||
-- fast = 0x000000011E6F9AB4, slow = 0x00000000007512AE.
|
||||
-- All three phase checksums are required to equal the deterministic values
|
||||
-- below. They were computed from the same LCG/arithmetic with an independent
|
||||
-- host implementation of scripts/m7/i64div-perf.c (see the header comment
|
||||
-- there):
|
||||
-- fast = 0x000000011E6F9AB4, slow = 0x00000000007512AE,
|
||||
-- wide = 0x00025AF70AF974E0.
|
||||
-- The in-image self-check (marker 7) also covers large 32-bit magnitudes
|
||||
-- (0xFFFFFFFF/7, -123/7 and INT32_MIN/3), so a wrong fast quotient or
|
||||
-- remainder fails before the timing comparison.
|
||||
-- (0xFFFFFFFF/7, -123/7 and INT32_MIN/3) plus the 64/32 shapes with hi >= d,
|
||||
-- hi == d, hi < d and INT64_MIN, so a wrong quotient or remainder fails before
|
||||
-- the timing comparison.
|
||||
--
|
||||
-- Markers at 01A20000h, 0x20 bits apart (free RAM above the 4 KiB entry stack;
|
||||
-- scripts/m7/i64div-map-check.py asserts they are outside .text/.data/.bss):
|
||||
-- 0 start 0x51A47A11 | 1/2 fast checksum | 3 fast done 0xFA57D01E
|
||||
-- 4/5 slow checksum | 6 slow done 0x5104D0E5 | 7 status 0x600D600D
|
||||
-- 8 wide done 0x81DE0D0E | 9/10 wide checksum
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
@@ -37,12 +44,14 @@ local BASE = 0x01A20000
|
||||
local START = 0x51A47A11
|
||||
local FAST_DONE = 0xFA57D01E
|
||||
local SLOW_DONE = 0x5104D0E5
|
||||
local WIDE_DONE = 0x81DE0D0E
|
||||
local STATUS_OK = 0x600D600D
|
||||
local FAST_HI, FAST_LO = 0x00000001, 0x1E6F9AB4
|
||||
local SLOW_HI, SLOW_LO = 0x00000000, 0x007512AE
|
||||
local WIDE_HI, WIDE_LO = 0x00025AF7, 0x0AF974E0
|
||||
|
||||
local frames = 0
|
||||
local start_f, fast_f, slow_f
|
||||
local start_f, fast_f, slow_f, wide_f
|
||||
local reported = false
|
||||
|
||||
local function rd(n)
|
||||
@@ -62,34 +71,51 @@ emu.register_frame_done(function()
|
||||
if fast_f ~= nil and slow_f == nil and rd(6) == SLOW_DONE then
|
||||
slow_f = frames
|
||||
end
|
||||
if slow_f ~= nil and wide_f == nil and rd(8) == WIDE_DONE then
|
||||
wide_f = frames
|
||||
end
|
||||
|
||||
if slow_f ~= nil and not reported then
|
||||
if wide_f ~= nil and not reported then
|
||||
reported = true
|
||||
local fast_frames = fast_f - start_f
|
||||
local slow_frames = slow_f - fast_f
|
||||
local wide_frames = wide_f - slow_f
|
||||
local basis = fast_frames
|
||||
if basis < 1 then
|
||||
basis = 1
|
||||
end
|
||||
local wide_basis = wide_frames
|
||||
if wide_basis < 1 then
|
||||
wide_basis = 1
|
||||
end
|
||||
local status = rd(7)
|
||||
local cs_fast_hi, cs_fast_lo = rd(2), rd(1)
|
||||
local cs_slow_hi, cs_slow_lo = rd(5), rd(4)
|
||||
local cs_wide_hi, cs_wide_lo = rd(10), rd(9)
|
||||
local ratio = slow_frames / basis
|
||||
local wide_ratio = slow_frames / wide_basis
|
||||
|
||||
local cs_ok = cs_fast_hi == FAST_HI and cs_fast_lo == FAST_LO
|
||||
and cs_slow_hi == SLOW_HI and cs_slow_lo == SLOW_LO
|
||||
and cs_wide_hi == WIDE_HI and cs_wide_lo == WIDE_LO
|
||||
local ok = status == STATUS_OK and cs_ok
|
||||
and slow_frames >= 20
|
||||
and slow_frames >= 8 * basis
|
||||
and wide_frames >= 2
|
||||
and slow_frames >= 4 * wide_basis
|
||||
|
||||
print(string.format(
|
||||
"M7: i64div perf: start=%d fast_done=%d slow_done=%d "
|
||||
.. "fast_frames=%d slow_frames=%d ratio=%.1f "
|
||||
.. "wide_done=%d fast_frames=%d slow_frames=%d "
|
||||
.. "wide_frames=%d ratio=%.1f wide_ratio=%.1f "
|
||||
.. "status=%08X cs_fast=%08X%08X cs_slow=%08X%08X "
|
||||
.. "cs_expected=%08X%08X/%08X%08X cs=%s",
|
||||
start_f, fast_f, slow_f, fast_frames, slow_frames, ratio,
|
||||
.. "cs_wide=%08X%08X "
|
||||
.. "cs_expected=%08X%08X/%08X%08X/%08X%08X cs=%s",
|
||||
start_f, fast_f, slow_f, wide_f, fast_frames, slow_frames,
|
||||
wide_frames, ratio, wide_ratio,
|
||||
status, cs_fast_hi, cs_fast_lo, cs_slow_hi, cs_slow_lo,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO,
|
||||
cs_wide_hi, cs_wide_lo,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO, WIDE_HI, WIDE_LO,
|
||||
cs_ok and "ok" or "BAD"))
|
||||
|
||||
if ok then
|
||||
@@ -97,18 +123,22 @@ emu.register_frame_done(function()
|
||||
else
|
||||
print(string.format(
|
||||
"M7 MAME: FAIL (status=%08X checksums=%s "
|
||||
.. "fast_frames=%d slow_frames=%d; want status %08X, "
|
||||
.. "fast %08X%08X, slow %08X%08X, slow_frames >= 20 "
|
||||
.. "and >= 8*max(fast_frames,1))",
|
||||
.. "fast_frames=%d slow_frames=%d wide_frames=%d; "
|
||||
.. "want status %08X, fast %08X%08X, slow %08X%08X, "
|
||||
.. "wide %08X%08X, slow_frames >= 20 and "
|
||||
.. ">= 8*max(fast_frames,1), wide_frames >= 2 and "
|
||||
.. "slow_frames >= 4*max(wide_frames,1))",
|
||||
status, cs_ok and "ok" or "BAD",
|
||||
fast_frames, slow_frames, STATUS_OK,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO))
|
||||
fast_frames, slow_frames, wide_frames, STATUS_OK,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO,
|
||||
WIDE_HI, WIDE_LO))
|
||||
end
|
||||
elseif frames == ENDF - 1 and not reported then
|
||||
reported = true
|
||||
local seen = string.format(
|
||||
"start=%s fast_done=%s slow_done=%s",
|
||||
tostring(start_f), tostring(fast_f), tostring(slow_f))
|
||||
"start=%s fast_done=%s slow_done=%s wide_done=%s",
|
||||
tostring(start_f), tostring(fast_f), tostring(slow_f),
|
||||
tostring(wide_f))
|
||||
print(string.format(
|
||||
"M7: i64div perf: incomplete at frame %d at marker 0x%08X",
|
||||
frames, BASE))
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
/* M7.4 i64 divide/remainder fast-path performance driver.
|
||||
/* M7.4/M8.3 i64 divide/remainder fast-path performance driver.
|
||||
*
|
||||
* Two equal-iteration workloads exercise the two paths of
|
||||
* Three equal-iteration workloads exercise the paths of
|
||||
* TMS34010LowerI64::lowerDivRem:
|
||||
*
|
||||
* fast phase: both operands fit 32 bits after the signed magnitude
|
||||
* normalization, so the compiler emits one 32-bit DIVU (plus
|
||||
* the div/mul/sub remainder reconstruction) instead of the
|
||||
* 64-step restoring loop;
|
||||
* slow phase: the operands have nonzero high words, so the 64-step loop
|
||||
* runs for each of the four i64 div/rem forms.
|
||||
* slow phase: both operands have nonzero high words, so the 64-step loop
|
||||
* runs for each of the four i64 div/rem forms;
|
||||
* wide phase: the dividend has a nonzero high word but the divisor fits
|
||||
* 32 bits, so the M8.3 64/32 path emits two even-destination
|
||||
* DIVUs (q1/r1 then q0/r0) instead of the 64-step loop.
|
||||
*
|
||||
* The loop bodies are driven by a volatile iteration count and volatile
|
||||
* seeds, and every result feeds a volatile accumulator that is published in
|
||||
@@ -25,6 +28,9 @@
|
||||
* 5 slow checksum high
|
||||
* 6 slow phase done 0x5104D0E5
|
||||
* 7 self-check status 0x600D600D on success
|
||||
* 8 wide phase done 0x81DE0D0E
|
||||
* 9 wide checksum low (printed evidence)
|
||||
* 10 wide checksum high
|
||||
*
|
||||
* The self-check runs known i64 divisions first (fast and slow, unsigned and
|
||||
* signed, including full-width low words and the INT32_MIN magnitude), so the
|
||||
@@ -48,6 +54,7 @@ typedef long long s64;
|
||||
#define PERF_START 0x51A47A11u
|
||||
#define PERF_FAST_DONE 0xFA57D01Eu
|
||||
#define PERF_SLOW_DONE 0x5104D0E5u
|
||||
#define PERF_WIDE_DONE 0x81DE0D0Eu
|
||||
#define PERF_STATUS_OK 0x600D600Du
|
||||
#define PERF_STATUS_BAD 0xBAD0BAD0u
|
||||
|
||||
@@ -79,6 +86,19 @@ static volatile s64 sc_neg123 = -123ll;
|
||||
static volatile s64 sc_int32min = -2147483648ll;
|
||||
static volatile s64 sc_three = 3ll;
|
||||
|
||||
/* M8.3 64/32-path cases: nonzero dividend high word, 32-bit divisor. The
|
||||
* first, second and INT64_MIN cases exercise the two-step form where the
|
||||
* quotient needs 33+ bits (hi >= d); the third has hi < d, so q1 is zero and
|
||||
* the second even-destination divide produces the whole quotient. The helper
|
||||
* still executes both divides in every case. */
|
||||
static volatile u64 sc_wide1 = 0xFEDCBA9876543210ull;
|
||||
static volatile u64 sc_wide_d1 = 0x12345678ull;
|
||||
static volatile u64 sc_wide2 = 0xFFFFFFFFFFFFFFFFull;
|
||||
static volatile u64 sc_wide_d2 = 0xFFFFFFFFull;
|
||||
static volatile u64 sc_wide3 = 0x00000001FFFFFFFFull;
|
||||
static volatile u64 sc_wide4 = 0x8000000000000000ull;
|
||||
static volatile s64 sc_int64min = -9223372036854775807ll - 1ll;
|
||||
|
||||
static u32 lcg(u32 x)
|
||||
{
|
||||
return x * 1103515245u + 12345u;
|
||||
@@ -124,11 +144,35 @@ static u32 selfcheck(void)
|
||||
sr = sc_int32min % sc_three;
|
||||
ok &= (sq == -715827882ll) && (sr == -2ll);
|
||||
|
||||
/* A large signed dividend: the signed slow path. */
|
||||
/* A large signed dividend: the signed wide path (32-bit divisor 7). */
|
||||
sq = sc_n3 / sc_d3;
|
||||
sr = sc_n3 % sc_d3;
|
||||
ok &= (sq == -142857142857ll) && (sr == -1ll);
|
||||
|
||||
/* M8.3 64/32 path with hi >= d: the quotient needs 36 bits. */
|
||||
q = sc_wide1 / sc_wide_d1;
|
||||
r = sc_wide1 % sc_wide_d1;
|
||||
ok &= (q == 0x0000000E00000077ull) && (r == 0x48ull);
|
||||
|
||||
/* M8.3 64/32 path with hi == d: the quotient needs 33 bits. */
|
||||
q = sc_wide2 / sc_wide_d2;
|
||||
r = sc_wide2 % sc_wide_d2;
|
||||
ok &= (q == 0x0000000100000001ull) && (r == 0ull);
|
||||
|
||||
/* M8.3 64/32 path with hi < d: the quotient fits in one divide. */
|
||||
q = sc_wide3 / sc_wide_d2;
|
||||
r = sc_wide3 % sc_wide_d2;
|
||||
ok &= (q == 2ull) && (r == 1ull);
|
||||
|
||||
/* M8.3 unsigned INT64_MIN magnitude and signed INT64_MIN / 3. */
|
||||
q = sc_wide4 / sc_three;
|
||||
r = sc_wide4 % sc_three;
|
||||
ok &= (q == 0x2AAAAAAAAAAAAAAAull) && (r == 2ull);
|
||||
|
||||
sq = sc_int64min / sc_three;
|
||||
sr = sc_int64min % sc_three;
|
||||
ok &= (sq == -3074457345618258602ll) && (sr == -2ll);
|
||||
|
||||
return ok ? PERF_STATUS_OK : PERF_STATUS_BAD;
|
||||
}
|
||||
|
||||
@@ -184,10 +228,38 @@ static void run_slow(void)
|
||||
MARK(6) = PERF_SLOW_DONE;
|
||||
}
|
||||
|
||||
/* Nonzero dividend high word, 32-bit divisor: all four forms take the M8.3
|
||||
* two-step 64/32 path (two even-destination DIVUs) instead of the 64-step
|
||||
* loop. The high word is capped at 16 bits and the divisor at 16 bits so the
|
||||
* values stay in the tested range while still covering hi >= d and hi < d. */
|
||||
static void run_wide(void)
|
||||
{
|
||||
u64 acc = 0;
|
||||
u64 a = seed_a;
|
||||
u64 b = seed_b;
|
||||
u32 n = perf_iters;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
a = ((u64)(1u + (lcg((u32)(a >> 32)) & 0xFFFFu)) << 32)
|
||||
| (u64)(lcg((u32)a) | 1u);
|
||||
b = (u64)(1u + (lcg((u32)b) & 0x0000FFFFu));
|
||||
acc += a / b;
|
||||
acc ^= a % b;
|
||||
acc += (u64)((s64)a / (s64)b);
|
||||
acc ^= (u64)((s64)a % (s64)b);
|
||||
}
|
||||
|
||||
MARK(9) = (u32)acc;
|
||||
MARK(10) = (u32)(acc >> 32);
|
||||
MARK(8) = PERF_WIDE_DONE;
|
||||
}
|
||||
|
||||
void i64div_perf_run(void)
|
||||
{
|
||||
MARK(7) = selfcheck();
|
||||
MARK(0) = PERF_START;
|
||||
run_fast();
|
||||
run_slow();
|
||||
run_wide();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
int debug_a_base = 3;
|
||||
|
||||
int debug_a_mul(void) {
|
||||
int product = debug_a_base * 7;
|
||||
return product + 1;
|
||||
}
|
||||
|
||||
int debug_a_add(void) {
|
||||
int sum = debug_a_base + 4;
|
||||
return sum * 2;
|
||||
}
|
||||
|
||||
/* M8.2 multi-TU debug gate, first translation unit.
|
||||
*
|
||||
* Two functions with distinct source lines; debug_a_mul returns 22 and
|
||||
* debug_a_add returns 14. debug-b.c is the second debug-bearing TU, and
|
||||
* debug-entry.asm calls all four functions so the linked image exercises both
|
||||
* units at runtime. The comment is after the code so the line numbers used by
|
||||
* dwarf-multi.sh stay stable.
|
||||
*/
|
||||
@@ -0,0 +1,19 @@
|
||||
int debug_b_base = 5;
|
||||
|
||||
int debug_b_sub(void) {
|
||||
int diff = debug_b_base - 2;
|
||||
return diff * 3;
|
||||
}
|
||||
|
||||
int debug_b_mul(void) {
|
||||
int factor = debug_b_base + 1;
|
||||
return factor * factor;
|
||||
}
|
||||
|
||||
/* M8.2 multi-TU debug gate, second translation unit.
|
||||
*
|
||||
* debug_b_sub returns 9 and debug_b_mul returns 36. The TU's `.text` is
|
||||
* concatenated after debug-a.c's, so its functions and DWARF addresses are at
|
||||
* nonzero text offsets; dwarf-multi.sh asserts the rehomed CU/section bases
|
||||
* and the linked low PCs.
|
||||
*/
|
||||
@@ -0,0 +1,31 @@
|
||||
; debug-entry.asm -- M8.2 multi-TU debug gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; debug-a.o is linked first and debug-b.o second, so debug_a_mul is the text
|
||||
; origin function (DWARF low PC 0x314000), debug-b's functions are at nonzero
|
||||
; text offsets, and _start follows both TUs. The entry calls all four
|
||||
; functions and stores their results (22, 14, 9, 36) at 018A8000, 018A8020,
|
||||
; 018A8040 and 018A8060; debug-multi-check.lua reads them after the stripped
|
||||
; image loads.
|
||||
.ref _debug_a_mul
|
||||
.ref _debug_a_add
|
||||
.ref _debug_b_sub
|
||||
.ref _debug_b_mul
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16,1,0
|
||||
setf 32,0,1
|
||||
movi _cstack,a14
|
||||
move a14,a13
|
||||
calla _debug_a_mul
|
||||
move a8,@018A8000h,1
|
||||
calla _debug_a_add
|
||||
move a8,@018A8020h,1
|
||||
calla _debug_b_sub
|
||||
move a8,@018A8040h,1
|
||||
calla _debug_b_mul
|
||||
move a8,@018A8060h,1
|
||||
rets
|
||||
|
||||
.bss _cstack,32768,16
|
||||
.end
|
||||
@@ -0,0 +1,19 @@
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
local frames = 0
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == tonumber(os.getenv("LOADER_END") or "2700") - 1 then
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local a_mul = prog:read_u32(0x018A8000)
|
||||
local a_add = prog:read_u32(0x018A8020)
|
||||
local b_sub = prog:read_u32(0x018A8040)
|
||||
local b_mul = prog:read_u32(0x018A8060)
|
||||
print(string.format("DEBUG MULTI: a_mul=%d a_add=%d b_sub=%d b_mul=%d",
|
||||
a_mul, a_add, b_sub, b_mul))
|
||||
if a_mul == 22 and a_add == 14 and b_sub == 9 and b_mul == 36 then
|
||||
print("DEBUG MULTI MAME: PASS")
|
||||
else
|
||||
print("DEBUG MULTI MAME: FAIL (want 22/14/9/36)")
|
||||
end
|
||||
end
|
||||
end, "debug-multi-check")
|
||||
@@ -0,0 +1,34 @@
|
||||
-- lib-check.lua -- read the M8 native-library gate marker words.
|
||||
--
|
||||
-- The driver writes five words at 018A8000 + n*0x20:
|
||||
-- 0: (int)(1.5 + 2.5) == 4 (flib FD$ADD + FD$DTOI)
|
||||
-- 1: (int)(1.5 * 2.5) == 3 (flib FD$MUL + FD$DTOI)
|
||||
-- 2: isascii('A') != 0 (rts.lib _isascii)
|
||||
-- 3: isascii(0xC8) == 0 (rts.lib _isascii)
|
||||
-- 4: 0x4C494231 ("LIB1" sentinel)
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "3400")
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
for i = 0, 4 do
|
||||
got[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format("M8 LIB: sum=%d product=%d asciiA=%d asciiC8=%d sentinel=%08X",
|
||||
got[0], got[1], got[2], got[3], got[4]))
|
||||
if got[0] == 4 and got[1] == 3 and got[2] ~= 0 and
|
||||
got[3] == 0 and got[4] == 0x4C494231 then
|
||||
print("M8 LIB MAME: PASS")
|
||||
else
|
||||
print("M8 LIB MAME: FAIL (want 4 3 nonzero 0 4C494231)")
|
||||
end
|
||||
end
|
||||
end, "m8-lib-check")
|
||||
@@ -0,0 +1,16 @@
|
||||
; lib-entry.asm -- M8 native-library gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the compiled driver libcheck_test(), which uses flib.lib doubles and
|
||||
; rts.lib _isascii. Marker words live at 018A8000 + n*0x20 and are checked by
|
||||
; lib-check.lua.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _libcheck_test
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,26 @@
|
||||
/* M8 native-library gate driver.
|
||||
*
|
||||
* The double operations lower to flib.lib's FD$ADD/FD$MUL and the fptosi
|
||||
* conversions to FD$DTOI; isascii is the rts.lib member. The markers are
|
||||
* fixed bit addresses in the prog region because the linker map's symbol
|
||||
* values are not needed by this tiny check.
|
||||
*/
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n) * 0x20u))
|
||||
|
||||
extern int isascii(int);
|
||||
|
||||
static volatile double fa = 1.5;
|
||||
static volatile double fb = 2.5;
|
||||
|
||||
int libcheck_test(void)
|
||||
{
|
||||
double sum = fa + fb;
|
||||
double product = fa * fb;
|
||||
|
||||
MARK(0) = (unsigned)(int)sum; /* 4: FD$ADD + FD$DTOI */
|
||||
MARK(1) = (unsigned)(int)product; /* 3: FD$MUL + FD$DTOI */
|
||||
MARK(2) = (unsigned)isascii('A'); /* 1: rts.lib _isascii */
|
||||
MARK(3) = (unsigned)isascii(0xC8); /* 0: rts.lib _isascii */
|
||||
MARK(4) = 0x4C494231u; /* "LIB1" sentinel */
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#!/bin/sh
|
||||
# os2-toolchain.sh -- run the 1990 TI r5.01 OS/2 tools under 2ine/qemu-i386.
|
||||
#
|
||||
# Sourced by scripts/m4/run.sh when M4_OS2=1. The 1990 tools are 16-bit OS/2
|
||||
# 1.x NE programs; the patched 2ine loader runs them on a 64-bit Linux host
|
||||
# via qemu-i386 (the plain lx_loader needs a kernel with 16-bit LDT support).
|
||||
#
|
||||
# Environment:
|
||||
# M4_OS2=1 enable this path
|
||||
# M4_OS2_2INE=PATH 2ine checkout (default /home/arti/os2-work/2ine-tms34010)
|
||||
# M4_OS2_LX=PATH lx_loader (default $2ine/build/lx_loader; the
|
||||
# build-qemu wrapper is the fallback)
|
||||
# M4_OS2_SDK=PATH extracted r5.01 tree with bin/ and lib/
|
||||
# M4_OS2_ROOT=PATH parent of the default 2ine/os2-501 (default /home/arti/os2-work)
|
||||
#
|
||||
# The functions expect run.sh globals: WORK, SDK, fail, NATIVE_OBJS,
|
||||
# NATIVE_LIBS. Outputs are copied back with the uppercase names run.sh uses.
|
||||
|
||||
os2_init() {
|
||||
OS2_2INE=${M4_OS2_2INE:-${M4_OS2_ROOT:-/home/arti/os2-work}/2ine-tms34010}
|
||||
OS2_LX=${M4_OS2_LX:-$OS2_2INE/build/lx_loader}
|
||||
if [ ! -x "$OS2_LX" ] && [ -x "$OS2_2INE/build-qemu/lx_loader" ]; then
|
||||
OS2_LX=$OS2_2INE/build-qemu/lx_loader
|
||||
fi
|
||||
OS2_SDK=${M4_OS2_SDK:-${M4_OS2_ROOT:-/home/arti/os2-work}/os2-501}
|
||||
|
||||
[ -x "$OS2_LX" ] || fail "M4_OS2=1: missing 2ine lx_loader: $OS2_LX (run scripts/m8/setup-os2.sh)"
|
||||
[ -f "$OS2_SDK/bin/gspa.exe" ] \
|
||||
|| fail "M4_OS2=1: missing OS/2 gspa.exe under $OS2_SDK/bin (run scripts/m8/setup-os2.sh)"
|
||||
case $OS2_LX in
|
||||
*/build-qemu/*)
|
||||
command -v qemu-i386 >/dev/null 2>&1 \
|
||||
|| fail "M4_OS2=1: qemu-i386 is required for the build-qemu wrapper" ;;
|
||||
esac
|
||||
|
||||
OS2_QEMU=$OS2_2INE/build-qemu/lx_loader
|
||||
OS2_DIR=$WORK/os2
|
||||
rm -rf "$OS2_DIR"
|
||||
mkdir -p "$OS2_DIR"
|
||||
# 2ine loads its OS/2 import modules from the working directory.
|
||||
for so in "$OS2_2INE"/build/lib*.so; do
|
||||
[ -e "$so" ] && ln -sf "$so" "$OS2_DIR/"
|
||||
done
|
||||
cp "$OS2_SDK/bin/gspa.exe" "$OS2_DIR/"
|
||||
cp "$OS2_SDK/bin/gsplnk.exe" "$OS2_DIR/"
|
||||
cp "$OS2_SDK/lib/rts.lib" "$OS2_SDK/lib/flib.lib" "$OS2_DIR/" 2>/dev/null || true
|
||||
}
|
||||
|
||||
os2_gspa() { # os2_gspa NAME (M4 or M4EXT)
|
||||
_name=$1
|
||||
[ -f "$SDK/$_name.ASM" ] || fail "M4_OS2: missing $SDK/$_name.ASM"
|
||||
cp "$SDK/$_name.ASM" "$OS2_DIR/$_name.ASM"
|
||||
|
||||
_gspa() { # _gspa LX
|
||||
( cd "$OS2_DIR" && \
|
||||
"$1" ./gspa.exe "$_name.ASM" "$_name.obj" "$_name.lst" -l \
|
||||
) > "$OS2_DIR/$_name.gspa.log" 2>&1 || true
|
||||
}
|
||||
rm -f "$OS2_DIR/$_name.lst" "$OS2_DIR/$_name.obj"
|
||||
_gspa "$OS2_LX"
|
||||
if ! grep -q 'No Errors' "$OS2_DIR/$_name.lst" 2>/dev/null; then
|
||||
# The direct 2ine loader can hit its segment assertion on some large
|
||||
# inputs; qemu-i386 is the reliable fallback.
|
||||
if [ -x "$OS2_QEMU" ] && [ "$OS2_LX" != "$OS2_QEMU" ]; then
|
||||
echo " note: direct 2ine gspa failed; retrying under qemu" >&2
|
||||
_gspa "$OS2_QEMU"
|
||||
fi
|
||||
fi
|
||||
grep -q 'No Errors' "$OS2_DIR/$_name.lst" 2>/dev/null || {
|
||||
cat "$OS2_DIR/$_name.gspa.log" >&2
|
||||
fail "OS/2 gspa failed for $_name"
|
||||
}
|
||||
cp "$OS2_DIR/$_name.obj" "$SDK/$_name.OBJ"
|
||||
cp "$OS2_DIR/$_name.lst" "$SDK/$_name.LST"
|
||||
}
|
||||
|
||||
os2_gsplnk() {
|
||||
# Copy every object the linker command may reference, plus the lowercase
|
||||
# library names the 5.01 command file uses.
|
||||
for obj in "$SDK"/*.OBJ "$SDK"/*.obj; do
|
||||
[ -e "$obj" ] && cp "$obj" "$OS2_DIR/"
|
||||
done
|
||||
# Copy every library the command file may reference; the 1987/1990 files
|
||||
# are uppercase on disk while the linker command uses lowercase names.
|
||||
for lib in "$SDK"/*.LIB "$SDK"/*.lib; do
|
||||
[ -e "$lib" ] || continue
|
||||
_low=$(basename "$lib" | tr '[:upper:]' '[:lower:]')
|
||||
cp "$lib" "$OS2_DIR/$_low"
|
||||
done
|
||||
cp "$SDK/M4.CMD" "$OS2_DIR/M4.CMD"
|
||||
rm -f "$OS2_DIR/M4.OUT" "$OS2_DIR/M4.MAP"
|
||||
_gsplnk() {
|
||||
( cd "$OS2_DIR" && "$1" ./gsplnk.exe M4.CMD ) \
|
||||
> "$OS2_DIR/M4.gsplnk.log" 2>&1 || true
|
||||
}
|
||||
_gsplnk "$OS2_LX"
|
||||
if [ ! -f "$OS2_DIR/M4.OUT" ] && [ -x "$OS2_QEMU" ] \
|
||||
&& [ "$OS2_LX" != "$OS2_QEMU" ]; then
|
||||
echo " note: direct 2ine gsplnk failed; retrying under qemu" >&2
|
||||
_gsplnk "$OS2_QEMU"
|
||||
fi
|
||||
[ -f "$OS2_DIR/M4.OUT" ] || {
|
||||
cat "$OS2_DIR/M4.gsplnk.log" >&2
|
||||
fail "OS/2 gsplnk failed"
|
||||
}
|
||||
cp "$OS2_DIR/M4.OUT" "$SDK/M4.OUT"
|
||||
cp "$OS2_DIR/M4.MAP" "$SDK/M4.MAP"
|
||||
}
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
#!/bin/sh
|
||||
# setup-os2.sh -- provision the 1990 TI r5.01 OS/2 toolchain for the harness.
|
||||
#
|
||||
# The r5.01 tools are 16-bit OS/2 1.x NE console programs. They run on a
|
||||
# 64-bit Linux host through the patched 2ine loader under qemu-i386 (the plain
|
||||
# lx_loader needs a kernel with 16-bit LDT support; qemu-i386 provides it).
|
||||
#
|
||||
# scripts/m8/setup-os2.sh
|
||||
#
|
||||
# Environment:
|
||||
# M4_OS2_ROOT install root (default $HOME/os2-work)
|
||||
# M4_OS2_2INE 2ine checkout (default $M4_OS2_ROOT/2ine-tms34010)
|
||||
# M4_OS2_SDK extracted r5.01 tree (default $M4_OS2_ROOT/os2-501)
|
||||
#
|
||||
# Then run gates with M4_OS2=1 (and optionally M4_LINKER=tms-link). The
|
||||
# default harness remains the 1987 DOSBox GSPA/GSPLNK oracle.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
OS2_ROOT=${M4_OS2_ROOT:-$HOME/os2-work}
|
||||
TWOINE=${M4_OS2_2INE:-$OS2_ROOT/2ine-tms34010}
|
||||
SDK=${M4_OS2_SDK:-$OS2_ROOT/os2-501}
|
||||
SDK_SRC="$ROOT/vendor/vt1200/tools/tms34010-sdk/1990-11 TMS340 Family SDK"
|
||||
|
||||
fail() { echo "setup-os2: FAIL: $*" >&2; exit 1; }
|
||||
|
||||
command -v git >/dev/null 2>&1 || fail "git is required"
|
||||
command -v cmake >/dev/null 2>&1 || fail "cmake is required"
|
||||
command -v unzip >/dev/null 2>&1 || fail "unzip is required"
|
||||
# The direct loader is preferred; qemu-i386 is only needed as a fallback on
|
||||
# kernels without 16-bit LDT support.
|
||||
|
||||
|
||||
if [ ! -x "$TWOINE/build/lx_loader" ]; then
|
||||
echo "== clone and build 2ine-tms34010 into $TWOINE"
|
||||
mkdir -p "$(dirname "$TWOINE")"
|
||||
[ -d "$TWOINE/.git" ] || \
|
||||
git clone https://git.wut.ee/opencode.energia.arti.ee/2ine-tms34010.git "$TWOINE"
|
||||
cmake -S "$TWOINE" -B "$TWOINE/build" -DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||
cmake --build "$TWOINE/build" -j"${JOBS:-$(nproc)}"
|
||||
fi
|
||||
|
||||
LX=${M4_OS2_LX:-$TWOINE/build/lx_loader}
|
||||
if [ ! -x "$LX" ]; then
|
||||
# Kernel fallback: wrap the loader in qemu-i386 (which provides 16-bit LDT
|
||||
# support even when CONFIG_X86_16BIT is off).
|
||||
command -v qemu-i386 >/dev/null 2>&1 \
|
||||
|| fail "lx_loader is missing and qemu-i386 is unavailable"
|
||||
mkdir -p "$TWOINE/build-qemu"
|
||||
cat > "$TWOINE/build-qemu/lx_loader" <<EOF
|
||||
#!/bin/sh
|
||||
exec qemu-i386 "$TWOINE/build/lx_loader" "\$@"
|
||||
EOF
|
||||
chmod +x "$TWOINE/build-qemu/lx_loader"
|
||||
LX=$TWOINE/build-qemu/lx_loader
|
||||
fi
|
||||
|
||||
if [ ! -f "$SDK/bin/gspa.exe" ]; then
|
||||
echo "== extract the r5.01 tools into $SDK"
|
||||
[ -f "$SDK_SRC/1990-11-19 TMS340 Family Code Generation Tools (1 of 2) r5.01 rev2564062-1641.zip" ] \
|
||||
|| fail "missing the r5.01 tools zip under $SDK_SRC"
|
||||
mkdir -p "$SDK/bin" "$SDK/lib" "$SDK/work"
|
||||
unzip -oq "$SDK_SRC/1990-11-19 TMS340 Family Code Generation Tools (1 of 2) r5.01 rev2564062-1641.zip" -d "$SDK/bin"
|
||||
unzip -oq "$SDK_SRC/1990-11-19 TMS340 Family Code Generation Tools (2 of 2) r5.01 rev2564062-1641.zip" -d "$SDK/lib"
|
||||
fi
|
||||
|
||||
[ -f "$SDK/bin/gspa.exe" ] || fail "gspa.exe missing after extraction"
|
||||
[ -x "$LX" ] || fail "lx_loader missing: $LX"
|
||||
|
||||
# Smoke test: assemble an empty source in a throw-away work dir.
|
||||
TMP=$(mktemp -d "$OS2_ROOT/os2-smoke.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
for so in "$TWOINE"/build/lib*.so; do [ -e "$so" ] && ln -sf "$so" "$TMP/"; done
|
||||
cp "$SDK/bin/gspa.exe" "$TMP/"
|
||||
: > "$TMP/t.asm"
|
||||
( cd "$TMP" && "$LX" ./gspa.exe t.asm > gspa.log 2>&1 ) || true
|
||||
if ! grep -q 'No Errors' "$TMP/gspa.log"; then
|
||||
# Retry through qemu if the direct loader cannot allocate 16-bit LDTs.
|
||||
if [ "$LX" = "$TWOINE/build/lx_loader" ] && command -v qemu-i386 >/dev/null 2>&1; then
|
||||
mkdir -p "$TWOINE/build-qemu"
|
||||
cat > "$TWOINE/build-qemu/lx_loader" <<EOF
|
||||
#!/bin/sh
|
||||
exec qemu-i386 "$TWOINE/build/lx_loader" "\$@"
|
||||
EOF
|
||||
chmod +x "$TWOINE/build-qemu/lx_loader"
|
||||
LX=$TWOINE/build-qemu/lx_loader
|
||||
( cd "$TMP" && "$LX" ./gspa.exe t.asm > gspa.log 2>&1 ) || true
|
||||
fi
|
||||
grep -q 'No Errors' "$TMP/gspa.log" \
|
||||
|| { cat "$TMP/gspa.log" >&2; fail "gspa smoke test failed"; }
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
|
||||
OS/2 r5.01 toolchain ready:
|
||||
M4_OS2_ROOT=$OS2_ROOT
|
||||
M4_OS2_2INE=$TWOINE
|
||||
M4_OS2_LX=$LX
|
||||
M4_OS2_SDK=$SDK
|
||||
|
||||
Use it with:
|
||||
M4_OS2=1 scripts/tests/m7/full-suite.sh --corpus all --work build/m8-os2-full
|
||||
M4_OS2=1 M4_LINKER=tms-link scripts/tests/m5/c-torture.sh
|
||||
M4_OS2=1 scripts/m4/run.sh # asm path: OS/2 gspa + OS/2 gsplnk
|
||||
|
||||
The default harness still uses the 1987 DOSBox GSPA/GSPLNK oracle.
|
||||
EOF
|
||||
@@ -29,6 +29,11 @@
|
||||
# M5_C_TESTSUITE_WORK M5_CONFORMANCE_DIR M5_CONFORMANCE_MODE
|
||||
set -eu
|
||||
|
||||
# The curated gates are the full-loader acceptance tier; the bare tier is
|
||||
# exercised by scripts/tests/m7/full-suite.sh.
|
||||
M5_CONFORMANCE_BARE=${M5_CONFORMANCE_BARE:-0}
|
||||
export M5_CONFORMANCE_BARE
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$HERE/conformance}
|
||||
|
||||
@@ -31,6 +31,11 @@
|
||||
# M5_CONFORMANCE_CLANG_OPT M5_CONFORMANCE_LLC_OPT (per pass)
|
||||
set -eu
|
||||
|
||||
# The curated gates are the full-loader acceptance tier; the bare tier is
|
||||
# exercised by scripts/tests/m7/full-suite.sh.
|
||||
M5_CONFORMANCE_BARE=${M5_CONFORMANCE_BARE:-0}
|
||||
export M5_CONFORMANCE_BARE
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$HERE/conformance}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
-- bare-check.lua -- run a freestanding conformance COFF on the VT1200 CPU
|
||||
-- without booting the firmware or using the COFF loader.
|
||||
--
|
||||
-- The test harness maps the image itself: each section is copied to its COFF
|
||||
-- paddr, .bss is zeroed, the result block is cleared, and PC/SP are set. This
|
||||
-- is the fast tier for codegen/semantics tests; the full loader/X11/runtime
|
||||
-- tiers still use loader.lua.
|
||||
--
|
||||
-- Required env: BARE_COFF, BARE_ENTRY, BARE_SP (bit addresses), CONF_RESULT.
|
||||
-- Optional: BARE_END (frame budget, default 1000).
|
||||
|
||||
local machine = manager.machine
|
||||
local cpu = machine.devices[':maincpu']
|
||||
local prog = cpu.spaces['program']
|
||||
|
||||
local COFF = os.getenv("BARE_COFF") or ""
|
||||
local ENTRY = tonumber(os.getenv("BARE_ENTRY") or "0", 16)
|
||||
local SP = tonumber(os.getenv("BARE_SP") or "0", 16)
|
||||
local ENDF = tonumber(os.getenv("BARE_END") or "1000")
|
||||
local RESULT = os.getenv("CONF_RESULT") or "conformance-result.txt"
|
||||
|
||||
local STATUS = 0x01B00000
|
||||
local LEN = 0x01B00020
|
||||
local MAGIC = 0x01B00040
|
||||
local ERRLEN = 0x01B00060
|
||||
local OUT = 0x01B10000
|
||||
local ERR = 0x01B30000
|
||||
local CAP = 16384
|
||||
local MAGIC_VAL = 0x434F4E46
|
||||
local ST_IE = 0x200000
|
||||
|
||||
local function slurp(path)
|
||||
local f = io.open(path, "rb")
|
||||
if not f then error("cannot open " .. path) end
|
||||
local d = f:read("*a")
|
||||
f:close()
|
||||
return d
|
||||
end
|
||||
|
||||
local function u16(d, o) return string.unpack("<I2", d, o + 1) end
|
||||
local function u32(d, o) return string.unpack("<I4", d, o + 1) end
|
||||
|
||||
local function parse_coff(d)
|
||||
local c = {}
|
||||
c.magic = u16(d, 0)
|
||||
c.nscns = u16(d, 2)
|
||||
c.opthdr = u16(d, 16)
|
||||
c.entry = c.opthdr ~= 0 and u32(d, 20 + 16) or 0
|
||||
c.sections = {}
|
||||
local base = 20 + c.opthdr
|
||||
for i = 0, c.nscns - 1 do
|
||||
local o = base + i * 40
|
||||
local name = d:sub(o + 1, o + 8):gsub("%z", "")
|
||||
c.sections[#c.sections + 1] = {
|
||||
name = name,
|
||||
paddr = u32(d, o + 8),
|
||||
size = u32(d, o + 16),
|
||||
scnptr = u32(d, o + 20),
|
||||
flags = u32(d, o + 36),
|
||||
}
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local function poke_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local function zero_bytes(bitaddr, nbytes)
|
||||
for i = 0, math.floor((nbytes + 1) / 2) - 1 do
|
||||
prog:write_u16(bitaddr + i * 16, 0)
|
||||
end
|
||||
end
|
||||
|
||||
local function rd32(a)
|
||||
local ok, v = pcall(function() return prog:read_u32(a) end)
|
||||
if ok then return v end
|
||||
return 0xDEADBEEF
|
||||
end
|
||||
|
||||
local function rd8(a)
|
||||
local ok, v = pcall(function() return prog:read_u8(a) end)
|
||||
if ok then return v end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function dump(tag)
|
||||
local status = rd32(STATUS)
|
||||
local raw_len = rd32(LEN)
|
||||
local magic = rd32(MAGIC)
|
||||
local raw_errlen = rd32(ERRLEN)
|
||||
local bytes, n = {}, 0
|
||||
local nread = (raw_len >= 0 and raw_len <= CAP) and raw_len or 0
|
||||
for i = 0, nread - 1 do
|
||||
bytes[#bytes + 1] = string.format("%02X", rd8(OUT + i * 8))
|
||||
n = n + 1
|
||||
end
|
||||
local errbytes = {}
|
||||
local erread = (raw_errlen >= 0 and raw_errlen <= CAP) and raw_errlen or 0
|
||||
for i = 0, erread - 1 do
|
||||
errbytes[#errbytes + 1] = string.format("%02X", rd8(ERR + i * 8))
|
||||
end
|
||||
print(string.format(
|
||||
"CONF: %s status=%08X len=%d magic=%08X loader=%08X out=%s errlen=%d err=%s",
|
||||
tag, status, raw_len, magic, 0, table.concat(bytes),
|
||||
raw_errlen, table.concat(errbytes)))
|
||||
local f = io.open(RESULT, "w")
|
||||
if f then
|
||||
f:write(string.format("status=%08X\n", status))
|
||||
f:write(string.format("len=%d\n", raw_len))
|
||||
f:write(string.format("magic=%08X\n", magic))
|
||||
f:write("loader=00000000\n")
|
||||
f:write("out=" .. table.concat(bytes) .. "\n")
|
||||
f:write(string.format("errlen=%d\n", raw_errlen))
|
||||
f:write("err=" .. table.concat(errbytes) .. "\n")
|
||||
f:close()
|
||||
end
|
||||
if magic == MAGIC_VAL then
|
||||
print("BARE MAME: PASS")
|
||||
else
|
||||
print("BARE MAME: FAIL")
|
||||
end
|
||||
end
|
||||
|
||||
local frames = 0
|
||||
local started = false
|
||||
local done = false
|
||||
|
||||
local function setup()
|
||||
local d = slurp(COFF)
|
||||
local c = parse_coff(d)
|
||||
if c.magic ~= 0x0090 then
|
||||
print(string.format("BARE: bad COFF magic %04X", c.magic))
|
||||
machine:exit()
|
||||
return
|
||||
end
|
||||
for _, s in ipairs(c.sections) do
|
||||
if s.name == ".bss" then
|
||||
zero_bytes(s.paddr, math.floor((s.size + 7) / 8))
|
||||
elseif s.size > 0 then
|
||||
local nb = math.floor((s.size + 7) / 8)
|
||||
poke_bytes(s.paddr, d:sub(s.scnptr + 1, s.scnptr + nb))
|
||||
end
|
||||
end
|
||||
-- Clear the result block; the entry also does it, but this is idempotent.
|
||||
prog:write_u32(STATUS, 0); prog:write_u32(LEN, 0)
|
||||
prog:write_u32(MAGIC, 0); prog:write_u32(ERRLEN, 0)
|
||||
cpu.state['SP'].value = SP
|
||||
local st = cpu.state['ST'].value
|
||||
cpu.state['ST'].value = st & ~ST_IE
|
||||
cpu.state['PC'].value = (ENTRY ~= 0) and ENTRY or c.entry
|
||||
print(string.format("BARE: entry=%08X sp=%08X sections=%d", cpu.state['PC'].value, SP, c.nscns))
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if not started then
|
||||
started = true
|
||||
setup()
|
||||
return
|
||||
end
|
||||
if done then return end
|
||||
if rd32(MAGIC) == MAGIC_VAL or frames >= ENDF then
|
||||
done = true
|
||||
dump(frames >= ENDF and "timeout" or "result")
|
||||
machine:exit()
|
||||
end
|
||||
end, "m5-bare-check")
|
||||
@@ -73,6 +73,25 @@ WORK_BASE=${M5_CONFORMANCE_WORK:-$ROOT/build/m5-conformance}
|
||||
CLANG_OPT=${M5_CONFORMANCE_CLANG_OPT:--O0}
|
||||
LLC_OPT=${M5_CONFORMANCE_LLC_OPT:--O0}
|
||||
MODE=${M5_CONFORMANCE_MODE:-auto}
|
||||
BARE=${M5_CONFORMANCE_BARE:-1}
|
||||
|
||||
# The OS/2 r5.01 tools (2ine) are preferred for assembly/linking when present;
|
||||
# the 1987 DOSBox GSPA/GSPLNK remains the fallback and the byte oracle.
|
||||
case ${M4_OS2:-auto} in
|
||||
auto)
|
||||
# The fast bare tier prefers the 2ine OS/2 assembler; the full-loader tier
|
||||
# stays on the 1987 GSPA/GSPLNK oracle.
|
||||
if [ "$BARE" = 1 ] \
|
||||
&& [ -x "${M4_OS2_LX:-$HOME/os2-work/2ine-tms34010/build/lx_loader}" ]; then
|
||||
M4_OS2=1
|
||||
else
|
||||
M4_OS2=0
|
||||
fi
|
||||
export M4_OS2
|
||||
;;
|
||||
0|1) export M4_OS2 ;;
|
||||
*) fail "M4_OS2 must be 0, 1 or auto" ;;
|
||||
esac
|
||||
|
||||
# Shim contract constants (keep in sync with shim.c and conformance-check.lua).
|
||||
OUT_CAP=16384
|
||||
@@ -319,8 +338,10 @@ for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$MAME" ] || fail "missing MAME: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
if [ "$BARE" != 1 ]; then
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
fi
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
|
||||
@@ -376,6 +397,7 @@ link_once() {
|
||||
M4_NATIVE_PROG_LEN=58000h \
|
||||
M4_NATIVE_RAM_LEN=80000h \
|
||||
M4_NATIVE_LIBS="m6flib.lib m6rts.lib" \
|
||||
M4_LINKER="${M4_LINKER:-$([ "$BARE" = 1 ] && echo tms-link || echo gsplnk)}" \
|
||||
M4_LINK_CMD="$HERE/link.cmd" \
|
||||
M4_EXTRA_ASM="$HERE/data-pad.asm" \
|
||||
M4_SKIP_MAME=1 \
|
||||
@@ -384,6 +406,10 @@ link_once() {
|
||||
}
|
||||
|
||||
check_map() {
|
||||
# The bare tier maps the COFF itself and validates placement by execution;
|
||||
# the tms-link map has a different shape, so the GSPLNK map check is only
|
||||
# for the full-loader tier.
|
||||
[ "$BARE" = 1 ] && return 0
|
||||
map=$WORK/m4/m4.map
|
||||
[ -f "$map" ] || fail "linker produced no map: $map"
|
||||
for sec in .text .data .bss; do
|
||||
@@ -428,9 +454,82 @@ check_link() {
|
||||
echo " linked $COFF ($LINK_MODE)"
|
||||
}
|
||||
|
||||
bare_sp() {
|
||||
if [ -n "${M5_BARE_SP:-}" ]; then
|
||||
printf '%s' "$M5_BARE_SP"
|
||||
return 0
|
||||
fi
|
||||
_map=$WORK/m4/m4.map
|
||||
_origin=$(awk '$1 == ".bss" { print $3; exit }' "$_map")
|
||||
_length=$(awk '$1 == ".bss" { print $4; exit }' "$_map")
|
||||
if [ -z "$_origin" ]; then
|
||||
# tms-link map: "01A00000 .bss" (no length). Use the top of the
|
||||
# loader's 64 KiB RAM region for the stack; the bare tier has no
|
||||
# create_process stack.
|
||||
printf '01A80000'
|
||||
return 0
|
||||
fi
|
||||
[ -n "$_origin" ] && [ -n "$_length" ] \
|
||||
|| fail "bare mode: linker map has no .bss origin/length"
|
||||
_origin=$((0x$_origin))
|
||||
_length=$((0x$_length))
|
||||
# Place the stack above .bss (the loader gives create_process a separate
|
||||
# 0x6000-bit stack); cap at the end of the 0x80000-bit RAM region.
|
||||
_sp=$((_origin + _length + 0x6000))
|
||||
[ "$_sp" -le 0x01A80000 ] || _sp=0x01A80000
|
||||
printf '%08X' "$_sp"
|
||||
}
|
||||
|
||||
run_mame() {
|
||||
echo "== run the COFF in MAME ($LINK_MODE)"
|
||||
echo "== run the COFF in MAME ($LINK_MODE${BARE:+ bare})"
|
||||
rm -f "$WORK/result.txt"
|
||||
if [ "$BARE" = 1 ]; then
|
||||
BARE_SP=$(bare_sp) || exit 1
|
||||
set +e
|
||||
BARE_COFF="$COFF" BARE_ENTRY=018A0000 BARE_SP="$BARE_SP" \
|
||||
BARE_END="${BARE_END:-1000}" CONF_RESULT="$WORK/result.txt" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$HERE/bare-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1
|
||||
MAME_RC=$?
|
||||
set +e
|
||||
if [ "$MAME_RC" -ne 0 ]; then
|
||||
tail -40 "$WORK/mame.log" >&2 || true
|
||||
fail "MAME exited $MAME_RC"
|
||||
fi
|
||||
grep -q 'CONF: .* status=' "$WORK/mame.log" \
|
||||
|| { tail -40 "$WORK/mame.log" >&2; fail "bare MAME produced no CONF result"; }
|
||||
RESULT=$WORK/result.txt
|
||||
[ -f "$RESULT" ] || fail "bare MAME wrote no result file: $RESULT"
|
||||
STATUS_HEX=$(sed -n 's/^status=//p' "$RESULT" | tr -d '\r')
|
||||
LEN=$(sed -n 's/^len=//p' "$RESULT" | tr -d '\r')
|
||||
MAGIC_HEX=$(sed -n 's/^magic=//p' "$RESULT" | tr -d '\r')
|
||||
LOADER_HEX=$(sed -n 's/^loader=//p' "$RESULT" | tr -d '\r')
|
||||
ACTUAL_HEX=$(sed -n 's/^out=//p' "$RESULT" | tr -d '\r')
|
||||
ERRLEN=$(sed -n 's/^errlen=//p' "$RESULT" | tr -d '\r')
|
||||
ACTUAL_ERR_HEX=$(sed -n 's/^err=//p' "$RESULT" | tr -d '\r')
|
||||
[ -n "$STATUS_HEX" ] || fail "result file has no status"
|
||||
[ -n "$MAGIC_HEX" ] || fail "result file has no magic"
|
||||
[ -n "$LOADER_HEX" ] || fail "result file has no loader status"
|
||||
ACTUAL_HEX=$(printf '%s' "$ACTUAL_HEX" | tr '[:lower:]' '[:upper:]')
|
||||
ACTUAL_ERR_HEX=$(printf '%s' "$ACTUAL_ERR_HEX" | tr '[:lower:]' '[:upper:]')
|
||||
if [ "$MAGIC_HEX" != "434F4E46" ]; then
|
||||
tail -40 "$WORK/mame.log" >&2 || true
|
||||
fail "no completion magic (got $MAGIC_HEX): test did not finish"
|
||||
fi
|
||||
[ -n "$LEN" ] || fail "result file has no output length"
|
||||
case $LEN in *[!0-9]*) fail "result output length is not decimal: '$LEN'" ;; esac
|
||||
[ "$LEN" -lt "$OUT_CAP" ] || fail "output truncated: length $LEN reached the $OUT_CAP-byte shim cap"
|
||||
[ -n "$ERRLEN" ] || fail "result file has no stderr length"
|
||||
case $ERRLEN in *[!0-9]*) fail "result stderr length is not decimal: '$ERRLEN'" ;; esac
|
||||
[ "$ERRLEN" -lt "$OUT_CAP" ] || fail "stderr truncated: length $ERRLEN reached the $OUT_CAP-byte shim cap"
|
||||
return 0
|
||||
fi
|
||||
set +e
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
VT1200_MONITOR=VR319 \
|
||||
|
||||
@@ -13,12 +13,13 @@
|
||||
# aggregates, GC). i64 is implemented by M6 Task 2; its former entries were
|
||||
# removed from this manifest when they started compiling. M7.1 removed
|
||||
# 2004-05-09-LiveVarPartialRegister, gc-lowering and shadow-stack-gc-lowering
|
||||
# when the recursive .data initializer extension made them compile.
|
||||
# when the recursive .data initializer extension made them compile. M8.3
|
||||
# removed 2008-02-04-Ctlz and llvm-ct-intrinsics when the ctlz/ctpop/cttz
|
||||
# lowering landed.
|
||||
2007-04-08-MultipleFrameIndices inline asm register constraint cannot be allocated
|
||||
2007-04-27-InlineAsm-X-Dest inline asm register constraint cannot be allocated
|
||||
2007-04-27-LargeMemObject inline asm memory constraint is not supported
|
||||
2007-12-17-InvokeAsm inline asm memory constraint is not supported
|
||||
2008-02-04-Ctlz target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
2008-02-20-MatchingMem inline asm memory constraint is not supported
|
||||
2008-08-07-PtrToInt-SmallerInt target rejection: unsupported .data initializer
|
||||
2010-ZeroSizedArg target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
@@ -47,7 +48,6 @@ icmp-illegal target rejection: TMS34010 supports only integer (<=64 bit) and poi
|
||||
inline-asm-mem-clobber inline asm register constraint cannot be allocated
|
||||
inline-asm-special-strings inline asm syntax is not supported by the TMS34010 parser
|
||||
intrinsics target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
llvm-ct-intrinsics target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
nested-select target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
overloaded-intrinsic-name gc.statepoint calls are not supported
|
||||
pr12507 target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
|
||||
@@ -17,7 +17,11 @@
|
||||
# the decoded instruction streams. Layouts are allowed to differ; a raw
|
||||
# byte compare is not used.
|
||||
#
|
||||
# Overridable: M5_NATIVE_WORK MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
# M5_NATIVE_LINKER=tms-link runs both native builds through tools/tms-link
|
||||
# instead of GSPLNK (termtris then exercises the rts.lib archive path); the
|
||||
# GSPLNK default remains the oracle.
|
||||
#
|
||||
# Overridable: M5_NATIVE_WORK MAME_TIMEOUT DOSBOX_TIMEOUT M5_NATIVE_LINKER
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
# M5_CONFORMANCE_DIR
|
||||
set -eu
|
||||
|
||||
# The curated gates are the full-loader acceptance tier; the bare tier is
|
||||
# exercised by scripts/tests/m7/full-suite.sh.
|
||||
M5_CONFORMANCE_BARE=${M5_CONFORMANCE_BARE:-0}
|
||||
export M5_CONFORMANCE_BARE
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$ROOT/scripts/tests/m5/conformance}
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
# M5_CONFORMANCE_DIR
|
||||
set -eu
|
||||
|
||||
# The curated gates are the full-loader acceptance tier; the bare tier is
|
||||
# exercised by scripts/tests/m7/full-suite.sh.
|
||||
M5_CONFORMANCE_BARE=${M5_CONFORMANCE_BARE:-0}
|
||||
export M5_CONFORMANCE_BARE
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$ROOT/scripts/tests/m5/conformance}
|
||||
|
||||
+50
-9
@@ -18,9 +18,13 @@
|
||||
# - no 64-bit runtime helper: rts.lib has none and the compiler must not
|
||||
# invent one (the map/asm are checked for the common libgcc names).
|
||||
#
|
||||
# M6_LINKER=tms-link optionally links the GSPA-assembled M6.OBJ with the 1990
|
||||
# flib.lib/rts.lib through tools/tms-link instead of GSPLNK; the GSPLNK default
|
||||
# remains the oracle.
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_CLANG TMS_OPT TMS_BITADDR MAME DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG I64_WORK I64_COFF I64_SDK LOADER_AT
|
||||
# LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
# LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT M6_LINKER TMS_LINK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
@@ -32,6 +36,8 @@ TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
M7COFF=${M7COFF:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m7coff.py}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
@@ -48,6 +54,7 @@ LOADER_END=${LOADER_END:-3400}
|
||||
# -O0 by default (like the M2 gate). I64_OPT=-O2 runs the same program with
|
||||
# the codegen optimizer on; the driver also runs its IR optimizer then.
|
||||
I64_OPT=${I64_OPT:--O0}
|
||||
LINKER=${M6_LINKER:-gsplnk}
|
||||
|
||||
fail() {
|
||||
echo "m6 i64: FAIL: $*" >&2
|
||||
@@ -57,6 +64,14 @@ fail() {
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
case $LINKER in
|
||||
gsplnk|tms-link) ;;
|
||||
*) fail "M6_LINKER must be 'gsplnk' or 'tms-link', got '$LINKER'" ;;
|
||||
esac
|
||||
if [ "$LINKER" = tms-link ]; then
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
[ -f "$M7COFF" ] || fail "missing independent COFF reader: $M7COFF"
|
||||
fi
|
||||
|
||||
mkdir -p "$WORK" "$SDK" "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
||||
|
||||
@@ -103,14 +118,40 @@ cat "$DIR/i64-entry.asm" "$WORK/i64-funcs.s" "$WORK/i64-main.s" > "$SDK/M6.ASM"
|
||||
sed 's/\r$//' "$DIR/i64-link.cmd" | sed 's/$/\r/' > "$SDK/M6.CMD"
|
||||
rm -f "$SDK/M6.OBJ" "$SDK/M6.OUT" "$SDK/M6.MAP" "$SDK/M6.LST" "$SDK/M6.LNK"
|
||||
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
if [ "$LINKER" = tms-link ]; then
|
||||
# GSPLNK oracle and tms-link from the same M6.OBJ and libraries.
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
[ -f "$SDK/M6.OUT" ] \
|
||||
|| { if [ -f "$SDK/M6.LNK" ]; then cat "$SDK/M6.LNK" >&2; fi; \
|
||||
fail "GSPLNK oracle produced no M6.OUT"; }
|
||||
mv "$SDK/M6.OUT" "$SDK/M6.GSP.OUT"
|
||||
mv "$SDK/M6.MAP" "$SDK/M6.GSP.MAP"
|
||||
echo "== link M6.OBJ + flib.lib/rts.lib with tools/tms-link"
|
||||
"$TMS_LINK" -o "$SDK/M6.OUT" --map "$SDK/M6.MAP" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
--prog-len 40000h --ram-len 80000h \
|
||||
"$SDK/M6.OBJ" "$SDK/flib.lib" "$SDK/rts.lib" \
|
||||
|| fail "tms-link failed"
|
||||
python3 "$ROOT/scripts/tests/m8/coff-parity.py" \
|
||||
"$M7COFF" "$SDK/M6.GSP.OUT" "$SDK/M6.OUT" \
|
||||
|| fail "tms-link image differs from the GSPLNK oracle"
|
||||
else
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
fi
|
||||
|
||||
[ -f "$SDK/M6.LST" ] || fail "GSPA produced no listing (see $WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$SDK/M6.LST" > "$WORK/m6.lst"
|
||||
|
||||
@@ -30,9 +30,14 @@
|
||||
# at 01B10000h) and the checker compares those bytes exactly with the expected
|
||||
# text.
|
||||
#
|
||||
# M6_LINKER=tms-link optionally links the GSPA-assembled M6.OBJ with the 1990
|
||||
# flib.lib/rts.lib through tools/tms-link instead of GSPLNK; the GSPLNK default
|
||||
# remains the oracle.
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_CLANG TMS_OPT TMS_BITADDR MAME DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG RUNTIME_WORK RUNTIME_COFF RUNTIME_SDK
|
||||
# LOADER_AT LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT RUNTIME_OPT
|
||||
# M6_LINKER TMS_LINK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
@@ -44,6 +49,8 @@ TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
M7COFF=${M7COFF:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m7coff.py}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
@@ -57,6 +64,7 @@ LOADER_BIN=${LOADER_BIN:-$ROOT/vendor/vt1200/dwt/loader/build/loader.bin}
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-3400}
|
||||
RUNTIME_OPTS=${RUNTIME_OPT:--O0 -O2}
|
||||
LINKER=${M6_LINKER:-gsplnk}
|
||||
|
||||
fail() {
|
||||
echo "m6 runtime: FAIL: $*" >&2
|
||||
@@ -66,6 +74,14 @@ fail() {
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
case $LINKER in
|
||||
gsplnk|tms-link) ;;
|
||||
*) fail "M6_LINKER must be 'gsplnk' or 'tms-link', got '$LINKER'" ;;
|
||||
esac
|
||||
if [ "$LINKER" = tms-link ]; then
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
[ -f "$M7COFF" ] || fail "missing independent COFF reader: $M7COFF"
|
||||
fi
|
||||
[ -f "$SHIM" ] || fail "missing shared shim: $SHIM"
|
||||
[ -x "$MAME" ] || fail "MAME binary not built: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "COFF loader missing: $LOADER_LUA"
|
||||
@@ -144,14 +160,41 @@ run_one() {
|
||||
sed 's/\r$//' "$DIR/runtime-link.cmd" | sed 's/$/\r/' > "$SDK/M6.CMD"
|
||||
rm -f "$SDK/M6.OBJ" "$SDK/M6.OUT" "$SDK/M6.MAP" "$SDK/M6.LST" "$SDK/M6.LNK"
|
||||
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "$opt: DOSBox failed"; }
|
||||
if [ "$LINKER" = tms-link ]; then
|
||||
# Produce the GSPLNK oracle from the same M6.OBJ and libraries, then
|
||||
# link the same inputs with tms-link and compare the allocated image.
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "$opt: DOSBox failed"; }
|
||||
[ -f "$SDK/M6.OUT" ] \
|
||||
|| { if [ -f "$SDK/M6.LNK" ]; then cat "$SDK/M6.LNK" >&2; fi; \
|
||||
fail "$opt: GSPLNK oracle produced no M6.OUT"; }
|
||||
mv "$SDK/M6.OUT" "$SDK/M6.GSP.OUT"
|
||||
mv "$SDK/M6.MAP" "$SDK/M6.GSP.MAP"
|
||||
echo "== [$opt] link M6.OBJ + flib.lib/rts.lib with tools/tms-link"
|
||||
"$TMS_LINK" -o "$SDK/M6.OUT" --map "$SDK/M6.MAP" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
--prog-len 40000h --ram-len 80000h \
|
||||
"$SDK/M6.OBJ" "$SDK/flib.lib" "$SDK/rts.lib" \
|
||||
|| fail "$opt: tms-link failed"
|
||||
python3 "$ROOT/scripts/tests/m8/coff-parity.py" \
|
||||
"$M7COFF" "$SDK/M6.GSP.OUT" "$SDK/M6.OUT" \
|
||||
|| fail "$opt: tms-link image differs from the GSPLNK oracle"
|
||||
else
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "$opt: DOSBox failed"; }
|
||||
fi
|
||||
|
||||
[ -f "$SDK/M6.LST" ] || fail "$opt: GSPA produced no listing (see $WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$SDK/M6.LST" > "$WORK/m6.lst"
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
# M7.4 full-suite report
|
||||
# generated: 2026-11-15T13:17:18Z
|
||||
# work: build/m7-full-suite
|
||||
# settings: -O0, mode=native, LOADER_AT=200, LOADER_END=1000, per-test MAME timeout=120s, outer wall=210s
|
||||
# M8.4 full-suite report
|
||||
# generated: 2026-11-16T17:41:34Z
|
||||
# work: build/m8-bare-full
|
||||
# settings: -O0, bare conformance (2ine+tms-link) with a full-loader list; LOADER_AT=200, LOADER_END=1000 (default), per-test MAME timeout=120s, outer wall=210s
|
||||
# full-loader list: /home/arti/code/tms-c-compiler/scripts/tests/m7/full-suite.full-loader
|
||||
# loader-end overrides: /home/arti/code/tms-c-compiler/scripts/tests/m7/full-suite.loader-end (4 rows)
|
||||
# c-torture: /home/arti/code/tms-c-compiler/vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute (1692 files)
|
||||
# c-testsuite: /home/arti/code/tms-c-compiler/vendor/conformance/c-testsuite/tests/single-exec (220 files)
|
||||
# compiler: rev=7c44990a6c8dea25bfe40925cb56144faad393d1 bin=dffe094d68675eb9 loader=200/1000
|
||||
# compiler: rev=774df1e6941f583822e09291c8becf73bada4005 bin=13cfe98909313a71 loader=200/1000
|
||||
# dialect: explicit dg -std= wins; otherwise -std=gnu89 only for full-suite.gnu89 names; c-testsuite default
|
||||
# results: build/m7-full-suite/full-suite-results.tsv
|
||||
# results: build/m8-bare-full/full-suite-results.tsv
|
||||
# accounting: every row has 5 fields, a legal result and a pinned name; no duplicate ids
|
||||
#
|
||||
# corpus total pass skip fail crash corpus_files remaining
|
||||
c-torture 1692 1366 326 0 0 1692 0
|
||||
c-torture 1692 1386 306 0 0 1692 0
|
||||
c-testsuite 220 210 10 0 0 220 0
|
||||
all 1912 1576 336 0 0 1912 0
|
||||
all 1912 1596 316 0 0 1912 0
|
||||
|
||||
# fail categories (per selected corpus)
|
||||
# c-torture
|
||||
@@ -27,7 +29,7 @@ abi-return 10
|
||||
abi-sret 9
|
||||
abi-varargs-return 3
|
||||
builtin 11
|
||||
codegen 19
|
||||
codegen 2
|
||||
codegen-float 2
|
||||
compile 8
|
||||
compiler-crash 6
|
||||
@@ -54,7 +56,7 @@ runtime-abort-vector 3
|
||||
runtime-bitfield 2
|
||||
setjmp 6
|
||||
signal 4
|
||||
timeout 23
|
||||
timeout 20
|
||||
vector 2
|
||||
vla 9
|
||||
wide-char 16
|
||||
@@ -92,12 +94,10 @@ c-torture 20010924-1 skip:data-odd-pointer: pointer field at an odd .data byte o
|
||||
c-torture 20011008-3 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture 20020107-1 skip:inline-asm: could not allocate output register for constraint 'r' at line 336 0
|
||||
c-torture 20020108-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture 20020226-1 skip:codegen: t25: i32 = rotr t4, t6 0
|
||||
c-torture 20020314-1 skip:compile: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion] 0
|
||||
c-torture 20020411-1 skip:abi-sret: aggregate return via an sret pointer is unsupported 0
|
||||
c-torture 20020412-1 skip:vla: variable-length array in a struct is unsupported 0
|
||||
c-torture 20020418-1 skip:abi-indirect-call: indirect call through a non-function value 0
|
||||
c-torture 20020508-1 skip:codegen: t25: i32 = rotr t4, t6 0
|
||||
c-torture 20021010-2 skip:data-init: unsupported .data initializer 0
|
||||
c-torture 20021127-1 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
c-torture 20030120-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
@@ -115,7 +115,6 @@ c-torture 20040520-1 skip:nested-function: nested function definitions are unsup
|
||||
c-torture 20040709-1 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture 20040709-2 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture 20040709-3 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture 20040811-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture 20041214-1 skip:data-init: unsupported .data initializer 0
|
||||
c-torture 20041218-2 skip:vla: variable-length array in a struct is unsupported 0
|
||||
c-torture 20050121-1 skip:abi-sret: aggregate return via an sret pointer is unsupported 0
|
||||
@@ -135,10 +134,8 @@ c-torture 20071220-1 skip:data-init: unsupported .data initializer 0
|
||||
c-torture 20071220-2 skip:data-init: unsupported .data initializer 0
|
||||
c-torture 20080502-1 skip:runtime-abort-float: test abort (status 0x86) 0
|
||||
c-torture 20090219-1 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture 20100805-1 skip:codegen: t13: i32 = rotl t4, Constant:i32<1> 0
|
||||
c-torture 20101011-1 skip:signal: signals are unavailable under the bare loader 0
|
||||
c-torture 20111208-1 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture 20180112-1 skip:codegen: t49: i32 = rotl t23, Constant:i32<1> 0
|
||||
c-torture 20180921-1 skip:compile: chained comparison 'X < Y <= Z' does not behave the same as a mathematical expression [-Wparentheses] 0
|
||||
c-torture 20210505-1 skip:setjmp: setjmp/longjmp need non-local jumps, which are unsupported 0
|
||||
c-torture 20230630-1 skip:runtime-abort: test abort (status 0x86) 0
|
||||
@@ -189,10 +186,8 @@ c-torture bitfld-3 skip:runtime-abort-bitfield: test abort (status 0x86) 0
|
||||
c-torture bitfld-5 skip:runtime-abort-bitfield: test abort (status 0x86) 0
|
||||
c-torture bitfld-6 skip:runtime-bitfield: wrong bitfield result (status 0x33333) 0
|
||||
c-torture bitfld-7 skip:runtime-bitfield: wrong bitfield result (status 0x222222) 0
|
||||
c-torture bswap-1 skip:codegen: t44: i32 = bswap t42 0
|
||||
c-torture bswap-2 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture built-in-setjmp skip:setjmp: __builtin_longjmp is unsupported 0
|
||||
c-torture builtin-bitops-1 skip:codegen: t90: i32 = cttz t68 0
|
||||
c-torture builtin-prefetch-2 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture cmpsf-1 skip:float-constant: out-of-range constant in the GSP floating-point format 0
|
||||
c-torture comp-goto-1 skip:data-init: unsupported .data initializer 0
|
||||
@@ -203,15 +198,13 @@ c-torture complex-5 skip:abi-sret: aggregate return via an sret pointer is unsup
|
||||
c-torture complex-6 skip:abi-sret: aggregate return via an sret pointer is unsupported 0
|
||||
c-torture conversion skip:codegen-float: only 32-bit integer sources are supported for float/double conversions 0
|
||||
c-torture eeprof-1 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture ffs-1 skip:codegen: t27: i32 = cttz t4 0
|
||||
c-torture ffs-2 skip:codegen: t43: i32 = cttz t11 0
|
||||
c-torture floatunsisf-1 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
c-torture fprintf-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture fprintf-2 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture fprintf-chk-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture frame-address skip:compiler-crash: unexpected TMS34010 custom lowering operation (frame address) 0
|
||||
c-torture gofast skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture loop-2f skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture loop-2f skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 1
|
||||
c-torture loop-2g skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture memchr-1 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture memclr skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
@@ -236,7 +229,6 @@ c-torture pr105613 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr105777 skip:corpus: references a gcc.dg source absent from the pinned execute tree 0
|
||||
c-torture pr105984 skip:builtin: use of unknown builtin '__builtin_mul_overflow_p' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr107881-1 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture pr108064 skip:codegen: t32: i32 = bswap t30 0
|
||||
c-torture pr108292 skip:vector: address of vector element requested 0
|
||||
c-torture pr108498-1 skip:inline-asm: could not allocate input reg for constraint 'r' at line 1233 0
|
||||
c-torture pr109040 skip:abi-float-args: float/double arguments are unsupported 0
|
||||
@@ -248,7 +240,6 @@ c-torture pr114396 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture pr115033 skip:builtin: use of unknown builtin '__builtin_exit' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr117095 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr117432 skip:compile: ISO C requires a named parameter before '...' 0
|
||||
c-torture pr119428 skip:codegen: t43: i32 = rotl Constant:i32<-2>, t22 0
|
||||
c-torture pr122943 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr123625 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr123625-2 skip:data-vector: vector constants in .data are unsupported 0
|
||||
@@ -274,7 +265,6 @@ c-torture pr34456 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture pr34971 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
c-torture pr35456 skip:runtime-abort-float: test abort (status 0x86) 0
|
||||
c-torture pr35800 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture pr37780 skip:codegen: t10: i32 = cttz t4 0
|
||||
c-torture pr38051 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
c-torture pr38151 skip:runtime-abort-varargs: test abort (status 0x86) 0
|
||||
c-torture pr38533 skip:inline-asm: could not allocate output register for constraint 'r' at line 2147513642 0
|
||||
@@ -284,7 +274,6 @@ c-torture pr40022 skip:inline-asm: Could not match memory address. Inline asm fa
|
||||
c-torture pr40657 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr41239 skip:setjmp: setjmp/longjmp need non-local jumps, which are unsupported 0
|
||||
c-torture pr41935 skip:vla: variable-length array in a struct is unsupported 0
|
||||
c-torture pr43220 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture pr43385 skip:inline-asm: could not allocate output register for constraint 'r' at line 328 0
|
||||
c-torture pr43560 skip:inline-asm: could not allocate output register for constraint 'r' at line 298 0
|
||||
c-torture pr43987 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
@@ -312,14 +301,12 @@ c-torture pr60003 skip:compile: incompatible pointer types passing 'unsigned lon
|
||||
c-torture pr60822 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture pr60960 skip:abi-return: unsupported aggregate/variadic return shape 0
|
||||
c-torture pr61375 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr61725 skip:codegen: t31: i32 = cttz t4 0
|
||||
c-torture pr63302 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr63843 skip:codegen: t74: i32 = bswap t58 0
|
||||
c-torture pr63843 skip:timeout: codegen fixed at the M7.4 pin; already compiled at the M8 base and hangs identically (status 1, no completion magic) 0
|
||||
c-torture pr64242 skip:setjmp: __builtin_longjmp is unsupported 0
|
||||
c-torture pr64718 skip:codegen: t33: i32 = bswap t27 0
|
||||
c-torture pr65053-1 skip:inline-asm: could not allocate output register for constraint 'r' at line 281 0
|
||||
c-torture pr65053-2 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr65170 skip:int128: 128-bit integers are unsupported 1
|
||||
c-torture pr65170 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr65401 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr65427 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr65648 skip:inline-asm: could not allocate input reg for constraint 'r' at line 225 0
|
||||
@@ -355,7 +342,6 @@ c-torture pr85582-3 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr85756 skip:inline-asm: could not allocate input reg for constraint 'r' at line 204 0
|
||||
c-torture pr88693 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture pr88904 skip:inline-asm: could not allocate output register for constraint 'r' at line 174 0
|
||||
c-torture pr90025 skip:codegen: t47: i32 = bswap t46 0
|
||||
c-torture pr92618 skip:abi-return: unsupported aggregate/variadic return shape 0
|
||||
c-torture pr92904 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr93213 skip:int128: 128-bit integers are unsupported 0
|
||||
@@ -364,8 +350,6 @@ c-torture pr94412 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr94524-1 skip:abi-return: unsupported aggregate/variadic return shape 0
|
||||
c-torture pr94524-2 skip:abi-return: unsupported aggregate/variadic return shape 0
|
||||
c-torture pr94591 skip:builtin: use of unknown builtin '__builtin_shuffle' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr97325 skip:codegen: t39: i32 = cttz t15 0
|
||||
c-torture pr97386-2 skip:codegen: t46: i32 = rotl t35, Constant:i32<24> 0
|
||||
c-torture pr98304-2 skip:corpus: references a gcc.dg source absent from the pinned execute tree 0
|
||||
c-torture pr98474 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture printf-2 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
@@ -381,7 +365,6 @@ c-torture simd-5 skip:data-vector: vector constants in .data are unsupported 0
|
||||
c-torture simd-6 skip:abi-return: unsupported aggregate/variadic return shape 0
|
||||
c-torture stdarg-3 skip:runtime-abort-varargs: test abort (status 0x86) 0
|
||||
c-torture stkalign skip:inline-asm: could not allocate output register for constraint 'r' at line 344 0
|
||||
c-torture strcmp-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture strct-stdarg-1 skip:runtime-abort-varargs: test abort (status 0x86) 0
|
||||
c-torture strct-varg-1 skip:runtime-abort-varargs: test abort (status 0x86) 0
|
||||
c-torture string-opt-18 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
@@ -395,7 +378,6 @@ c-torture va-arg-22 skip:abi-byval: byval argument has zero size 0
|
||||
c-torture va-arg-26 skip:abi-varargs-return: float/double/i64/aggregate return from a variadic definition is unsupported 0
|
||||
c-torture va-arg-pack-1 skip:builtin: use of unknown builtin '__builtin_va_arg_pack' [-Wimplicit-function-declaration] 0
|
||||
c-torture vfprintf-chk-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture vla-dealloc-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture vprintf-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture vprintf-chk-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture wchar_t-1 skip:wide-char: wide characters are unsupported 0
|
||||
@@ -405,4 +387,4 @@ c-torture widechar-3 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture zerolen-2 skip:runtime-abort: test abort (status 0x86) 0
|
||||
|
||||
# resume
|
||||
scripts/tests/m7/full-suite.sh --corpus all --work build/m7-full-suite
|
||||
scripts/tests/m7/full-suite.sh --corpus all --work build/m8-bare-full
|
||||
@@ -0,0 +1,20 @@
|
||||
# Tests that need the full VT1200 loader tier.
|
||||
#
|
||||
# The conformance driver runs the corpus bare-metal (map sections, zero .bss,
|
||||
# set PC/SP, no firmware boot). A few tests are unstable in that tier or rely
|
||||
# on the GSPLNK/loader behavior, but pass through the real loader. They are
|
||||
# listed here explicitly, with a reason and the linker tier, so only these
|
||||
# boot the full ROM.
|
||||
#
|
||||
# name<TAB>reason<TAB>linker (os2|1987; default os2)
|
||||
|
||||
20141125-1 bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
20230630-2 bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
float-floor bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
medce-1 linker: 5.01 gsplnk leaves _link_error undefined; 1987 GSPLNK passes 1987
|
||||
multi-ix bare-mame: MAME did not exit after the result; full loader passes os2
|
||||
pr44828 bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
pr70005 bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
pr79286 linker: tms-link rejects a negative relocation; 2ine GSPLNK passes os2
|
||||
pr93945 bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
strlen-3 bare-mame: MAME host segfault in the bare tier; full loader passes os2
|
||||
@@ -0,0 +1,16 @@
|
||||
# M8.3 per-test full-suite loader budgets.
|
||||
#
|
||||
# Rows are <corpus>/<test><TAB><LOADER_END>. The shipped default remains
|
||||
# LOADER_END=1000; a row here only sets the budget for a test whose
|
||||
# corrected/fixed workload is frame-limited at the default, not wrong or
|
||||
# hung. A row may be below an explicit larger global LOADER_END. The M8.3
|
||||
# rerun with LOADER_END=2000 flipped exactly these four rows to pass; every
|
||||
# other runtime timeout in full-suite.skip still timed out at 2000 (and the
|
||||
# two compile-time timeouts are unrelated to the loader).
|
||||
#
|
||||
# Keep this list tied to the same pinned tree as full-suite.skip.
|
||||
#
|
||||
c-torture/20040811-1 2000
|
||||
c-torture/pr43220 2000
|
||||
c-torture/strcmp-1 2000
|
||||
c-torture/vla-dealloc-1 2000
|
||||
@@ -61,7 +61,11 @@
|
||||
# the outer wall bound is +90 s)
|
||||
# -h, --help this help (exit 0)
|
||||
#
|
||||
# Overridable: M7_FULL_SUITE_WORK M7_FULL_SUITE_TIMEOUT
|
||||
# A per-test loader budget can be listed in full-suite.loader-end
|
||||
# (<corpus>/<test><TAB><LOADER_END>). The shipped default stays 1000; the file
|
||||
# only widens tests whose fixed workload is frame-limited rather than wrong.
|
||||
#
|
||||
# Overridable: M7_FULL_SUITE_WORK M7_FULL_SUITE_TIMEOUT M7_FULL_SUITE_LOADER_END
|
||||
# C_TORTURE_DIR C_TESTSUITE_DIR M5_CONFORMANCE_DIR
|
||||
# LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME
|
||||
# MAME_TIMEOUT (per test) LOADER_AT LOADER_END
|
||||
@@ -76,6 +80,8 @@ C_TORTURE_DIR=${C_TORTURE_DIR:-$ROOT/vendor/conformance/gcc-16.2.0/gcc/testsuite
|
||||
C_TESTSUITE_DIR=${C_TESTSUITE_DIR:-$ROOT/vendor/conformance/c-testsuite/tests/single-exec}
|
||||
SKIP_FILE=${M7_FULL_SUITE_SKIP:-$HERE/full-suite.skip}
|
||||
DIALECT_FILE=${M7_FULL_SUITE_DIALECT:-$HERE/full-suite.gnu89}
|
||||
FULL_LOADER_FILE=${M7_FULL_SUITE_FULL_LOADER:-$HERE/full-suite.full-loader}
|
||||
LOADER_FILE=${M7_FULL_SUITE_LOADER_END:-$HERE/full-suite.loader-end}
|
||||
|
||||
C_TORTURE_EXPECTED=1692
|
||||
C_TESTSUITE_EXPECTED=220
|
||||
@@ -321,6 +327,49 @@ curated_reason() {
|
||||
}' "$CURATED"
|
||||
}
|
||||
|
||||
# Validate and flatten the per-test loader-end table. A row names an existing
|
||||
# test and the budget it was validated at; that budget may be below an explicit
|
||||
# larger global LOADER_END (the row is applied verbatim). The shipped default
|
||||
# stays 1000, with a 1000 floor and a 20000 sanity cap for table rows.
|
||||
LOADER_OVERRIDES=$WORK/lists/loader-end.tsv
|
||||
: > "$LOADER_OVERRIDES"
|
||||
if [ -f "$LOADER_FILE" ]; then
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
id=${line%% *}
|
||||
budget=${line#* }
|
||||
[ "$id" != "$line" ] || fail "malformed loader-end row (no tab): $line"
|
||||
case $budget in
|
||||
''|*[!0-9]*) fail "loader-end budget is not an integer: $line" ;;
|
||||
esac
|
||||
# A row may be below an explicit larger global LOADER_END: it is the
|
||||
# budget the row was validated at. Keep the shipped 1000 floor and a
|
||||
# sanity cap so a typo cannot turn into a multi-hour run.
|
||||
[ "$budget" -ge 1000 ] \
|
||||
|| fail "loader-end budget $budget is below the shipped default 1000: $id"
|
||||
[ "$budget" -le 20000 ] \
|
||||
|| fail "loader-end budget $budget is above the sanity cap 20000: $id"
|
||||
corpus=${id%%/*}
|
||||
name=${id#*/}
|
||||
[ "$corpus" != "$id" ] || fail "malformed loader-end id (no corpus/name): $id"
|
||||
case $corpus in
|
||||
c-torture|c-testsuite) ;;
|
||||
*) fail "loader-end row has an unknown corpus: $id" ;;
|
||||
esac
|
||||
grep -Fxq "$name" "$WORK/lists/$corpus.txt" \
|
||||
|| fail "loader-end row names a missing $corpus test: $id"
|
||||
grep -Fq "$id " "$LOADER_OVERRIDES" 2>/dev/null \
|
||||
&& fail "duplicate loader-end row for $id"
|
||||
printf '%s\t%s\n' "$id" "$budget" >> "$LOADER_OVERRIDES"
|
||||
done < "$LOADER_FILE"
|
||||
fi
|
||||
|
||||
loader_end_for() {
|
||||
awk -F '\t' -v id="$1" '$1 == id { print $2; exit }' "$LOADER_OVERRIDES"
|
||||
}
|
||||
|
||||
already_recorded() {
|
||||
awk -F '\t' -v c="$1" -v n="$2" \
|
||||
'$1 == c && $2 == n { found = 1 } END { exit !found }' "$RESULTS"
|
||||
@@ -455,6 +504,18 @@ dialect_flags() {
|
||||
printf '%s' "$flags"
|
||||
}
|
||||
|
||||
full_loader_reason() {
|
||||
[ -f "$FULL_LOADER_FILE" ] || return 0
|
||||
awk -F '\t' -v n="$1" '$1 == n && $1 !~ /^#/ { print $2; exit }' "$FULL_LOADER_FILE"
|
||||
}
|
||||
|
||||
full_loader_linker() {
|
||||
[ -f "$FULL_LOADER_FILE" ] || { echo os2; return 0; }
|
||||
_l=$(awk -F '\t' -v n="$1" '$1 == n && $1 !~ /^#/ { print $3; exit }' "$FULL_LOADER_FILE")
|
||||
[ -n "$_l" ] || _l=os2
|
||||
printf '%s' "$_l"
|
||||
}
|
||||
|
||||
run_one() {
|
||||
corpus=$1
|
||||
name=$2
|
||||
@@ -494,25 +555,38 @@ run_one() {
|
||||
safe_id=$(printf '%s' "$id" | tr -c 'A-Za-z0-9._-' '_')
|
||||
runwork=$WORK/run/$safe_id
|
||||
extra_cflags=$(dialect_flags "$corpus" "$name" "$src")
|
||||
test_loader_end=$(loader_end_for "$id")
|
||||
[ -n "$test_loader_end" ] || test_loader_end=$LOADER_END
|
||||
bare=1
|
||||
full_reason=$(full_loader_reason "$name")
|
||||
full_linker=os2
|
||||
if [ -n "$full_reason" ]; then
|
||||
bare=0
|
||||
full_linker=$(full_loader_linker "$name")
|
||||
fi
|
||||
start=$(date +%s)
|
||||
set +e
|
||||
if [ "$corpus" = c-torture ]; then
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$LOADER_END \
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$test_loader_end \
|
||||
MAME_TIMEOUT=$TIME_LIMIT \
|
||||
M5_CONFORMANCE_WORK=$WORK/run \
|
||||
M5_CONFORMANCE_CLANG_OPT=-O0 M5_CONFORMANCE_LLC_OPT=-O0 \
|
||||
M5_CONFORMANCE_MODE=native \
|
||||
M5_CONFORMANCE_BARE="$bare" \
|
||||
M4_OS2="$([ "$bare" = 1 ] && echo auto || { [ "$full_linker" = 1987 ] && echo 0 || echo 1; })" \
|
||||
M5_CONFORMANCE_EXTRA_CFLAGS="$extra_cflags" \
|
||||
timeout --kill-after=10 "$((TIME_LIMIT + 90))" \
|
||||
"$RUN" --id "$id" --classify --mode native \
|
||||
--expect-status 0 --ignore-output --timeout "$TIME_LIMIT" \
|
||||
"$src" > "$log" 2>&1
|
||||
else
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$LOADER_END \
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$test_loader_end \
|
||||
MAME_TIMEOUT=$TIME_LIMIT \
|
||||
M5_CONFORMANCE_WORK=$WORK/run \
|
||||
M5_CONFORMANCE_CLANG_OPT=-O0 M5_CONFORMANCE_LLC_OPT=-O0 \
|
||||
M5_CONFORMANCE_MODE=native \
|
||||
M5_CONFORMANCE_BARE="$bare" \
|
||||
M4_OS2="$([ "$bare" = 1 ] && echo auto || { [ "$full_linker" = 1987 ] && echo 0 || echo 1; })" \
|
||||
M5_CONFORMANCE_EXTRA_CFLAGS= \
|
||||
timeout --kill-after=10 "$((TIME_LIMIT + 90))" \
|
||||
"$RUN" --id "$id" --classify --mode native \
|
||||
@@ -528,7 +602,11 @@ run_one() {
|
||||
case $rc in
|
||||
0)
|
||||
result=pass
|
||||
detail=link=native
|
||||
if [ "$bare" = 1 ]; then
|
||||
detail=link=native
|
||||
else
|
||||
detail="link=full-loader: $full_reason"
|
||||
fi
|
||||
printf 'PASS %-44s %3ss\n' "$id" "$elapsed"
|
||||
;;
|
||||
2)
|
||||
@@ -717,10 +795,12 @@ summary_row() {
|
||||
}
|
||||
|
||||
{
|
||||
echo "# M7.4 full-suite report"
|
||||
echo "# M8.4 full-suite report"
|
||||
echo "# generated: $(date -u '+%Y-%m-%dT%H:%M:%SZ')"
|
||||
echo "# work: $WORK"
|
||||
echo "# settings: -O0, mode=native, LOADER_AT=$LOADER_AT, LOADER_END=$LOADER_END, per-test MAME timeout=${TIME_LIMIT}s, outer wall=$((TIME_LIMIT + 90))s"
|
||||
echo "# settings: -O0, bare conformance (2ine+tms-link) with a full-loader list; LOADER_AT=$LOADER_AT, LOADER_END=$LOADER_END (default), per-test MAME timeout=${TIME_LIMIT}s, outer wall=$((TIME_LIMIT + 90))s"
|
||||
echo "# full-loader list: $FULL_LOADER_FILE"
|
||||
echo "# loader-end overrides: $LOADER_FILE ($(wc -l < "$LOADER_OVERRIDES" | tr -d ' ') rows)"
|
||||
echo "# c-torture: $C_TORTURE_DIR ($(corpus_files c-torture) files)"
|
||||
echo "# c-testsuite: $C_TESTSUITE_DIR ($(corpus_files c-testsuite) files)"
|
||||
echo "# compiler: $compiler_id"
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
# M7.4 full-suite curated skips.
|
||||
# M7.4/M8.4 full-suite curated skips.
|
||||
#
|
||||
# Rows are <corpus>/<test><TAB><reason>. A row here is recorded as
|
||||
# skip:<reason> without running the test, so it is never counted as a pass.
|
||||
# The corpus/name must exist in the pinned tree; a stale row is a driver error.
|
||||
# Classifier skips are reported by classify.sh and are not duplicated here;
|
||||
# every row below was classifier-supported and re-run after the Task 3 fixes.
|
||||
# Reasons are tab-free; the retained per-test log is under build/m7-full-suite.
|
||||
# every row below was classifier-supported and re-run after the task that
|
||||
# added it. M8.4 re-ran the whole corpus end-to-end with the final compiler
|
||||
# (`--redo`, build/m8-full-suite); the retained M7.4/M8.3 evidence is history.
|
||||
# M8.3 removed the rotates/cttz/bswap codegen class and the four frame-limited
|
||||
# rows in full-suite.loader-end (per-test LOADER_END=2000); pr63843 now
|
||||
# compiles and hits a pre-existing runtime hang. Reasons are tab-free; the
|
||||
# retained per-test log is under build/m8-task3-full-suite-final and the
|
||||
# timeout sweep under build/m8-task3-timeouts.
|
||||
#
|
||||
# Categories: compiler-crash, codegen, inline-asm, nested-function, vla,
|
||||
# data-init, data-vector, data-odd-pointer, abi-*, builtin, libm, memory,
|
||||
@@ -24,12 +30,10 @@ c-torture/20010904-1 runtime-abort-alignment: test abort (status 0x86)
|
||||
c-torture/20010904-2 runtime-abort-alignment: test abort (status 0x86)
|
||||
c-torture/20010924-1 data-odd-pointer: pointer field at an odd .data byte offset
|
||||
c-torture/20020107-1 inline-asm: could not allocate output register for constraint 'r' at line 336
|
||||
c-torture/20020226-1 codegen: t25: i32 = rotr t4, t6
|
||||
c-torture/20020314-1 compile: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
|
||||
c-torture/20020411-1 abi-sret: aggregate return via an sret pointer is unsupported
|
||||
c-torture/20020412-1 vla: variable-length array in a struct is unsupported
|
||||
c-torture/20020418-1 abi-indirect-call: indirect call through a non-function value
|
||||
c-torture/20020508-1 codegen: t25: i32 = rotr t4, t6
|
||||
c-torture/20021010-2 data-init: unsupported .data initializer
|
||||
c-torture/20021127-1 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/20030209-1 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
@@ -46,7 +50,6 @@ c-torture/20040520-1 nested-function: nested function definitions are unsupporte
|
||||
c-torture/20040709-1 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/20040709-2 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/20040709-3 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/20040811-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/20041214-1 data-init: unsupported .data initializer
|
||||
c-torture/20041218-2 vla: variable-length array in a struct is unsupported
|
||||
c-torture/20050121-1 abi-sret: aggregate return via an sret pointer is unsupported
|
||||
@@ -66,8 +69,6 @@ c-torture/20071220-1 data-init: unsupported .data initializer
|
||||
c-torture/20071220-2 data-init: unsupported .data initializer
|
||||
c-torture/20080502-1 runtime-abort-float: test abort (status 0x86)
|
||||
c-torture/20090219-1 nested-function: nested function definitions are unsupported
|
||||
c-torture/20100805-1 codegen: t13: i32 = rotl t4, Constant:i32<1>
|
||||
c-torture/20180112-1 codegen: t49: i32 = rotl t23, Constant:i32<1>
|
||||
c-torture/20180921-1 compile: chained comparison 'X < Y <= Z' does not behave the same as a mathematical expression [-Wparentheses]
|
||||
c-torture/20230630-1 runtime-abort: test abort (status 0x86)
|
||||
c-torture/20230630-3 runtime-abort: test abort (status 0x86)
|
||||
@@ -112,10 +113,8 @@ c-torture/bitfld-3 runtime-abort-bitfield: test abort (status 0x86)
|
||||
c-torture/bitfld-5 runtime-abort-bitfield: test abort (status 0x86)
|
||||
c-torture/bitfld-6 runtime-bitfield: wrong bitfield result (status 0x33333)
|
||||
c-torture/bitfld-7 runtime-bitfield: wrong bitfield result (status 0x222222)
|
||||
c-torture/bswap-1 codegen: t44: i32 = bswap t42
|
||||
c-torture/bswap-2 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/built-in-setjmp setjmp: __builtin_longjmp is unsupported
|
||||
c-torture/builtin-bitops-1 codegen: t90: i32 = cttz t68
|
||||
c-torture/cmpsf-1 float-constant: out-of-range constant in the GSP floating-point format
|
||||
c-torture/comp-goto-1 data-init: unsupported .data initializer
|
||||
c-torture/comp-goto-2 nested-function: nested function definitions are unsupported
|
||||
@@ -125,8 +124,6 @@ c-torture/complex-5 abi-sret: aggregate return via an sret pointer is unsupporte
|
||||
c-torture/complex-6 abi-sret: aggregate return via an sret pointer is unsupported
|
||||
c-torture/conversion codegen-float: only 32-bit integer sources are supported for float/double conversions
|
||||
c-torture/eeprof-1 runtime-abort: test abort (status 0x86)
|
||||
c-torture/ffs-1 codegen: t27: i32 = cttz t4
|
||||
c-torture/ffs-2 codegen: t43: i32 = cttz t11
|
||||
c-torture/floatunsisf-1 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/frame-address compiler-crash: unexpected TMS34010 custom lowering operation (frame address)
|
||||
c-torture/memclr memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
@@ -150,7 +147,6 @@ c-torture/pr103405 nested-function: nested function definitions are unsupported
|
||||
c-torture/pr105777 corpus: references a gcc.dg source absent from the pinned execute tree
|
||||
c-torture/pr105984 builtin: use of unknown builtin '__builtin_mul_overflow_p' [-Wimplicit-function-declaration]
|
||||
c-torture/pr107881-1 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/pr108064 codegen: t32: i32 = bswap t30
|
||||
c-torture/pr108292 vector: address of vector element requested
|
||||
c-torture/pr108498-1 inline-asm: could not allocate input reg for constraint 'r' at line 1233
|
||||
c-torture/pr109040 abi-float-args: float/double arguments are unsupported
|
||||
@@ -159,7 +155,6 @@ c-torture/pr109986 corpus: references a gcc.dg source absent from the pinned exe
|
||||
c-torture/pr110252-2 inline-asm: could not allocate output register for constraint 'r' at line 155
|
||||
c-torture/pr115033 builtin: use of unknown builtin '__builtin_exit' [-Wimplicit-function-declaration]
|
||||
c-torture/pr117432 compile: ISO C requires a named parameter before '...'
|
||||
c-torture/pr119428 codegen: t43: i32 = rotl Constant:i32<-2>, t22
|
||||
c-torture/pr123625 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr123625-2 data-vector: vector constants in .data are unsupported
|
||||
c-torture/pr123753 vector: cannot decrement a vector value
|
||||
@@ -182,7 +177,6 @@ c-torture/pr32244-1 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/pr34456 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/pr34971 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/pr35456 runtime-abort-float: test abort (status 0x86)
|
||||
c-torture/pr37780 codegen: t10: i32 = cttz t4
|
||||
c-torture/pr38051 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/pr38151 runtime-abort-varargs: test abort (status 0x86)
|
||||
c-torture/pr38533 inline-asm: could not allocate output register for constraint 'r' at line 2147513642
|
||||
@@ -191,7 +185,6 @@ c-torture/pr39228 builtin: use of unknown builtin '__builtin_isinff' [-Wimplicit
|
||||
c-torture/pr40022 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr40657 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr41935 vla: variable-length array in a struct is unsupported
|
||||
c-torture/pr43220 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/pr43385 inline-asm: could not allocate output register for constraint 'r' at line 328
|
||||
c-torture/pr43560 inline-asm: could not allocate output register for constraint 'r' at line 298
|
||||
c-torture/pr44575 runtime-abort-varargs: test abort (status 0x86)
|
||||
@@ -214,10 +207,8 @@ c-torture/pr58574 memory: linked image exceeds the 45 KiB program / 64 KiB RAM r
|
||||
c-torture/pr60003 compile: incompatible pointer types passing 'unsigned long long (*)[5]' to parameter of type 'void **' [-Wincompatible-pointer-types]
|
||||
c-torture/pr60822 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/pr60960 abi-return: unsupported aggregate/variadic return shape
|
||||
c-torture/pr61725 codegen: t31: i32 = cttz t4
|
||||
c-torture/pr63843 codegen: t74: i32 = bswap t58
|
||||
c-torture/pr63843 timeout: codegen fixed at the M7.4 pin; already compiled at the M8 base and hangs identically (status 1, no completion magic)
|
||||
c-torture/pr64242 setjmp: __builtin_longjmp is unsupported
|
||||
c-torture/pr64718 codegen: t33: i32 = bswap t27
|
||||
c-torture/pr65053-1 inline-asm: could not allocate output register for constraint 'r' at line 281
|
||||
c-torture/pr65053-2 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr65401 runtime-abort: test abort (status 0x86)
|
||||
@@ -248,15 +239,12 @@ c-torture/pr85169 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr85331 builtin: use of unknown builtin '__builtin_shuffle' [-Wimplicit-function-declaration]
|
||||
c-torture/pr85756 inline-asm: could not allocate input reg for constraint 'r' at line 204
|
||||
c-torture/pr88904 inline-asm: could not allocate output register for constraint 'r' at line 174
|
||||
c-torture/pr90025 codegen: t47: i32 = bswap t46
|
||||
c-torture/pr92618 abi-return: unsupported aggregate/variadic return shape
|
||||
c-torture/pr94130 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr94412 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr94524-1 abi-return: unsupported aggregate/variadic return shape
|
||||
c-torture/pr94524-2 abi-return: unsupported aggregate/variadic return shape
|
||||
c-torture/pr94591 builtin: use of unknown builtin '__builtin_shuffle' [-Wimplicit-function-declaration]
|
||||
c-torture/pr97325 codegen: t39: i32 = cttz t15
|
||||
c-torture/pr97386-2 codegen: t46: i32 = rotl t35, Constant:i32<24>
|
||||
c-torture/pr98304-2 corpus: references a gcc.dg source absent from the pinned execute tree
|
||||
c-torture/printf-chk-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/scal-to-vec1 runtime-abort-vector: test abort (status 0x86)
|
||||
@@ -269,7 +257,6 @@ c-torture/simd-5 data-vector: vector constants in .data are unsupported
|
||||
c-torture/simd-6 abi-return: unsupported aggregate/variadic return shape
|
||||
c-torture/stdarg-3 runtime-abort-varargs: test abort (status 0x86)
|
||||
c-torture/stkalign inline-asm: could not allocate output register for constraint 'r' at line 344
|
||||
c-torture/strcmp-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/strct-stdarg-1 runtime-abort-varargs: test abort (status 0x86)
|
||||
c-torture/strct-varg-1 runtime-abort-varargs: test abort (status 0x86)
|
||||
c-torture/string-opt-18 timeout: did not finish within LOADER_END=1000
|
||||
@@ -279,7 +266,6 @@ c-torture/va-arg-21 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/va-arg-22 abi-byval: byval argument has zero size
|
||||
c-torture/va-arg-26 abi-varargs-return: float/double/i64/aggregate return from a variadic definition is unsupported
|
||||
c-torture/va-arg-pack-1 builtin: use of unknown builtin '__builtin_va_arg_pack' [-Wimplicit-function-declaration]
|
||||
c-torture/vla-dealloc-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/vprintf-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/vprintf-chk-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/zerolen-2 runtime-abort: test abort (status 0x86)
|
||||
@@ -12,20 +12,26 @@
|
||||
# magnitude normalization: each i64 div/rem takes the M7.4 fast path and
|
||||
# the target's single 32-bit DIVU;
|
||||
# - 16384 iterations with nonzero high words: each i64 div/rem takes the
|
||||
# 64-step restoring loop.
|
||||
# 64-step restoring loop;
|
||||
# - 16384 iterations with a nonzero dividend high word and a 32-bit
|
||||
# divisor: each i64 div/rem takes the M8.3 two-step 64/32 path (two
|
||||
# even-destination DIVUs) instead of the loop.
|
||||
#
|
||||
# scripts/m7/i64div-perf-check.lua polls the start and per-phase completion
|
||||
# markers once per MAME frame. A frame is a fixed number of emulated 50 MHz
|
||||
# cycles, so the frame counts are a reproducible cycle proxy. The gate
|
||||
# requires the fast phase to complete in materially fewer frames for the same
|
||||
# iteration count (slow_frames >= 8 * max(fast_frames,1), with the slow phase
|
||||
# at least 20 frames so it is measurable) and both phase checksums to equal
|
||||
# the deterministic values computed from the same LCG (the driver header and
|
||||
# the Lua pin them). The driver's self-check status word proves both paths
|
||||
# first produced the known M6 values, including full-width 32-bit magnitudes
|
||||
# (0xFFFFFFFF/7, -123/7, INT32_MIN/3).
|
||||
# at least 20 frames so it is measurable) and the wide phase to beat the loop
|
||||
# (slow_frames >= 4 * max(wide_frames,1), wide phase at least 2 frames). All
|
||||
# three phase checksums must equal the deterministic values computed from the
|
||||
# same LCG (the driver header and the Lua pin them). The driver's self-check
|
||||
# status word proves every path first produced the known values, including
|
||||
# full-width 32-bit magnitudes (0xFFFFFFFF/7, -123/7, INT32_MIN/3) and the
|
||||
# 64/32 shapes (hi >= d, hi == d, hi < d, INT64_MIN).
|
||||
#
|
||||
# The markers live at 01A20000h, free RAM above the 4 KiB entry stack, outside
|
||||
# The twelve marker cells live at 01A20000h, free RAM above the 4 KiB entry
|
||||
# stack, outside
|
||||
# .text/.data/.bss. The gate-local scripts/m7/i64div-link.cmd widens the prog
|
||||
# region to 40000h (the M4 default 8000h is 4 KiB and the driver's .text is
|
||||
# larger), and scripts/m7/i64div-map-check.py asserts on both the tms-link and
|
||||
@@ -71,7 +77,7 @@ LOADER_AT=${LOADER_AT:-200}
|
||||
LOADER_END=${LOADER_END:-4000}
|
||||
|
||||
# The marker base in i64div-perf.c and i64div-perf-check.lua; the map check
|
||||
# asserts these 8 cells at 0x20 bits apart are outside every linked section.
|
||||
# asserts these 12 cells at 0x20 bits apart are outside every linked section.
|
||||
MARKERS=01A20000
|
||||
PROG_ORIGIN=018A0000
|
||||
PROG_LEN=40000
|
||||
@@ -102,15 +108,17 @@ export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
|
||||
fast=$(grep -c '; %i64div.fast' "$WORK/i64div-perf.s" || true)
|
||||
loop=$(grep -c '; %i64div.loop' "$WORK/i64div-perf.s" || true)
|
||||
wide=$(grep -c '; %i64div.wide' "$WORK/i64div-perf.s" || true)
|
||||
divu=$(grep -c 'DIVU ' "$WORK/i64div-perf.s" || true)
|
||||
[ "$fast" -ge 1 ] || fail "no i64div.fast block in the driver asm"
|
||||
[ "$loop" -ge 1 ] || fail "no i64div.loop block in the driver asm"
|
||||
[ "$wide" -ge 1 ] || fail "no i64div.wide block in the driver asm"
|
||||
[ "$divu" -ge 1 ] || fail "no 32-bit DIVU in the driver asm"
|
||||
grep -q "0x${MARKERS}" "$SRC" \
|
||||
|| fail "i64div-perf.c does not use the marker base 0x$MARKERS"
|
||||
grep -q "0x${MARKERS}" "$CHECK_LUA" \
|
||||
|| fail "i64div-perf-check.lua does not use the marker base 0x$MARKERS"
|
||||
echo " fast blocks=$fast loop blocks=$loop DIVU=$divu markers=$MARKERS"
|
||||
echo " fast blocks=$fast loop blocks=$loop wide blocks=$wide DIVU=$divu markers=$MARKERS"
|
||||
echo " i64div-perf.s: $(grep -c . "$WORK/i64div-perf.s") lines"
|
||||
|
||||
if [ "${I64DIV_PERF_COMPILE_ONLY:-0}" = 1 ]; then
|
||||
|
||||
@@ -98,6 +98,40 @@ echo "== link the same objects with tms-link"
|
||||
"$DOS/NATIVE.O" "$DOS/ENTRY.O" \
|
||||
|| fail "tms-link failed"
|
||||
|
||||
# Cheap archive check: wrap the entry object as a small no-index ar member and
|
||||
# require the same image through both the archive path and -l/. The archive is
|
||||
# built here rather than with GNU ar so the gate does not depend on whether the
|
||||
# host ar can index TI-COFF (it cannot).
|
||||
echo "== archive the entry object and link it with tms-link"
|
||||
python3 - "$DOS/ENTRY.O" "$WORK/entry.lib" <<'PY'
|
||||
import sys
|
||||
|
||||
src, dst = sys.argv[1:]
|
||||
data = open(src, "rb").read()
|
||||
header = (b"ENTRY.O/".ljust(16, b" ") + b"0".ljust(12, b" ") +
|
||||
b"0".ljust(6, b" ") + b"0".ljust(6, b" ") +
|
||||
b"644".ljust(8, b" ") +
|
||||
str(len(data)).encode().ljust(10, b" ") + b"`\n")
|
||||
out = bytearray(b"!<arch>\n")
|
||||
out.extend(header)
|
||||
out.extend(data)
|
||||
if len(data) & 1:
|
||||
out.append(0x0A)
|
||||
open(dst, "wb").write(out)
|
||||
PY
|
||||
"$TMS_LINK" -o "$WORK/tms-link-archive.coff" --entry _native_entry \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
"$DOS/NATIVE.O" "$WORK/entry.lib" \
|
||||
|| fail "tms-link archive link failed"
|
||||
"$TMS_LINK" -o "$WORK/tms-link-lib.coff" --entry _native_entry \
|
||||
--text 018A0000 --bss 01A00000 -L "$WORK" -l entry \
|
||||
"$DOS/NATIVE.O" \
|
||||
|| fail "tms-link -l link failed"
|
||||
cmp -s "$WORK/tms-link.coff" "$WORK/tms-link-archive.coff" \
|
||||
|| fail "archive input changed the tms-link image"
|
||||
cmp -s "$WORK/tms-link.coff" "$WORK/tms-link-lib.coff" \
|
||||
|| fail "-l input changed the tms-link image"
|
||||
|
||||
python3 - "$M7COFF" "$WORK/oracle.coff" "$WORK/tms-link.coff" \
|
||||
"$WORK/tms-link.map" "$DOS/NATIVE.O" "$DOS/ENTRY.O" <<'PY' \
|
||||
|| fail "tms-link output differs from GSPLNK"
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare a GSPLNK oracle image with a tms-link image.
|
||||
|
||||
Usage: coff-parity.py M7COFF ORACLE OURS
|
||||
|
||||
GSPLNK emits a listed-but-empty .cinit for some library links; tms-link
|
||||
deliberately omits it (the section has no bytes and the loader ignores it), so
|
||||
zero-size .cinit sections are dropped before the comparison. Everything that
|
||||
is allocated must match byte-for-byte, and the public C_EXT symbol addresses
|
||||
must be identical. The reader is the independent M7 test-local m7coff.py, not
|
||||
the linker's own tmscoff.py.
|
||||
"""
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 4:
|
||||
sys.exit("usage: coff-parity.py M7COFF ORACLE OURS")
|
||||
reader_path, oracle_path, ours_path = argv[1:]
|
||||
sys.path.insert(0, os.path.dirname(reader_path))
|
||||
import m7coff # noqa: E402
|
||||
|
||||
oracle = m7coff.parse(oracle_path)
|
||||
ours = m7coff.parse(ours_path)
|
||||
|
||||
def allocated(obj):
|
||||
return [s for s in obj["sections"] if s["size"] != 0]
|
||||
|
||||
a_secs = allocated(oracle)
|
||||
b_secs = allocated(ours)
|
||||
if [s["name"] for s in a_secs] != [s["name"] for s in b_secs]:
|
||||
sys.exit("section names %r != %r"
|
||||
% ([s["name"] for s in a_secs],
|
||||
[s["name"] for s in b_secs]))
|
||||
for a, b in zip(a_secs, b_secs):
|
||||
for field in ("paddr", "vaddr", "size", "flags"):
|
||||
if a[field] != b[field]:
|
||||
sys.exit("%s %s %#x != %#x"
|
||||
% (a["name"], field, a[field], b[field]))
|
||||
if a["raw"] != b["raw"]:
|
||||
limit = min(len(a["raw"]), len(b["raw"]))
|
||||
bad = [i for i in range(limit) if a["raw"][i] != b["raw"][i]]
|
||||
sys.exit("%s bytes differ: %d byte(s), first %r"
|
||||
% (a["name"],
|
||||
len(bad) + abs(len(a["raw"]) - len(b["raw"])),
|
||||
[(hex(i), a["raw"][i], b["raw"][i]) for i in bad[:8]]))
|
||||
if b["nreloc"]:
|
||||
sys.exit("%s still has %d relocations"
|
||||
% (b["name"], b["nreloc"]))
|
||||
|
||||
if oracle["flags"] != ours["flags"]:
|
||||
sys.exit("file flags %#x != %#x"
|
||||
% (oracle["flags"], ours["flags"]))
|
||||
opt_a = struct.unpack_from("<HHIIIIII", oracle["data"], 20)
|
||||
opt_b = struct.unpack_from("<HHIIIIII", ours["data"], 20)
|
||||
if opt_a != opt_b:
|
||||
sys.exit("optional header %r != %r" % (opt_a, opt_b))
|
||||
|
||||
def externals(obj):
|
||||
return {s["name"]: s["value"] for s in obj["symbols"]
|
||||
if s["sclass"] == 2 and s["secno"] > 0}
|
||||
|
||||
expected = externals(oracle)
|
||||
actual = externals(ours)
|
||||
if expected != actual:
|
||||
missing = sorted(set(expected) - set(actual))
|
||||
extra = sorted(set(actual) - set(expected))
|
||||
wrong = sorted((n, expected[n], actual[n])
|
||||
for n in set(expected) & set(actual)
|
||||
if expected[n] != actual[n])
|
||||
sys.exit("C_EXT mismatch: missing=%r extra=%r wrong=%r"
|
||||
% (missing, extra,
|
||||
[(n, hex(a), hex(b)) for n, a, b in wrong]))
|
||||
|
||||
ignored = [s["name"] for s in oracle["sections"] if s["size"] == 0]
|
||||
print(" parity: %s, %d allocated sections, %d public symbols%s"
|
||||
% (os.path.basename(ours_path), len(b_secs), len(actual),
|
||||
" (oracle zero-size %s dropped)" % ",".join(ignored)
|
||||
if ignored else ""))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
Executable
+648
@@ -0,0 +1,648 @@
|
||||
#!/bin/sh
|
||||
# M8.2 multi-TU DWARF gate: two `-g` objects through tms-link --keep-debug.
|
||||
#
|
||||
# scripts/tests/m8/dwarf-multi.sh
|
||||
#
|
||||
# 1. Compile scripts/m8/debug-a.c and debug-b.c with `tms-clang -g -O0` and
|
||||
# `llc -filetype=obj`; both objects must carry the DWARF v5 sections
|
||||
# (.debug_info/.debug_abbrev/.debug_line/.debug_str/.debug_str_offsets/
|
||||
# .debug_addr/.debug_line_str).
|
||||
# 2. GSPA assembles scripts/m8/debug-entry.asm; tms-link links
|
||||
# debug-a.o debug-b.o entry.o twice, --keep-debug and the default strip.
|
||||
# 3. The kept .debug_* sections are wrapped in the M7 ELF32 container and read
|
||||
# by llvm-dwarfdump. The gate asserts, for every TU:
|
||||
# - both compile-unit names and both .debug_line file tables;
|
||||
# - every subprogram name and its linked low PC (text origin / 8 +
|
||||
# protocol offset), high PC byte size and declaration line;
|
||||
# - line rows at every linked function low PC with the first body line;
|
||||
# - the second CU's debug_abbrev_offset/str_offsets_base/stmt_list/
|
||||
# addr_base are rehomed to the first object's merged section sizes,
|
||||
# proving section-relative offsets were shifted (not just copied).
|
||||
# 4. The stripped image still runs in MAME: the four markers are 22, 14, 9
|
||||
# and 36 and the loader reports status 0 with 0 differing .text bytes.
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_LLC TMS_LINK M7COFF M8_DWARF_WORK
|
||||
# M8_DWARF_SDK SDK_IMG DOSBOX DOSBOX_CONF MAME MAME_TIMEOUT
|
||||
# LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m8
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/scripts/tms-clang}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
DWARFDUMP=${DWARFDUMP:-$LLVM_BIN/llvm-dwarfdump}
|
||||
M7COFF=${M7COFF:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m7coff.py}
|
||||
WORK=${M8_DWARF_WORK:-$ROOT/build/m8-dwarf}
|
||||
SDK=${M8_DWARF_SDK:-$WORK/sdk}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
MAME_TIMEOUT=${MAME_TIMEOUT:-900}
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
|
||||
fail() {
|
||||
echo "M8 dwarf-multi: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_CLANG" ] || fail "missing tms-clang: $TMS_CLANG"
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
[ -x "$DWARFDUMP" ] || fail "missing llvm-dwarfdump: $DWARFDUMP"
|
||||
[ -f "$M7COFF" ] \
|
||||
|| fail "independent TI-COFF reader not found: $M7COFF"
|
||||
[ -f "$DOSBOX_CONF" ] || fail "missing DOSBox config: $DOSBOX_CONF"
|
||||
command -v "$DOSBOX" >/dev/null 2>&1 || fail "missing DOSBox: $DOSBOX"
|
||||
[ -x "$MAME" ] || fail "missing MAME binary: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing loader payload: $LOADER_BIN"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK/obj" "$WORK/dos" "$WORK/run/nvram" "$WORK/run/cfg" \
|
||||
"$WORK/evidence"
|
||||
WORK=$(cd "$WORK" && pwd)
|
||||
DOS=$WORK/dos
|
||||
|
||||
echo "== compile two TUs with tms-clang -g -O0 and llc -filetype=obj"
|
||||
# Compile from scripts/m8 with relative names so DW_AT_name and the line-table
|
||||
# file names are exactly debug-a.c / debug-b.c.
|
||||
( cd "$DIR" && "$TMS_CLANG" -g -O0 -o "$WORK/obj/debug-a.ll" debug-a.c ) \
|
||||
|| fail "tms-clang -g failed for debug-a.c"
|
||||
( cd "$DIR" && "$TMS_CLANG" -g -O0 -o "$WORK/obj/debug-b.ll" debug-b.c ) \
|
||||
|| fail "tms-clang -g failed for debug-b.c"
|
||||
grep -q '!dbg' "$WORK/obj/debug-a.ll" \
|
||||
|| fail "debug-a.ll has no !dbg metadata"
|
||||
grep -q '!dbg' "$WORK/obj/debug-b.ll" \
|
||||
|| fail "debug-b.ll has no !dbg metadata"
|
||||
for name in debug-a debug-b; do
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$WORK/obj/$name.ll" -o "$WORK/obj/$name.o" \
|
||||
|| fail "llc -filetype=obj failed for $name"
|
||||
done
|
||||
python3 - "$M7COFF" "$WORK/obj/debug-a.o" "$WORK/obj/debug-b.o" <<'PY' \
|
||||
|| fail "a TU is missing the DWARF v5 sections"
|
||||
import os
|
||||
import sys
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[1]))
|
||||
import m7coff # noqa: E402
|
||||
want = (".debug_info", ".debug_abbrev", ".debug_line", ".debug_str",
|
||||
".debug_str_offsets", ".debug_addr", ".debug_line_str")
|
||||
for path in sys.argv[2:]:
|
||||
c = m7coff.parse(path)
|
||||
debug = [s["name"] for s in c["sections"]
|
||||
if s["name"].startswith(".debug_")]
|
||||
for name in want:
|
||||
if name not in debug:
|
||||
sys.exit("%s missing %s; got %r" % (path, name, debug))
|
||||
print(" %s: %s" % (os.path.basename(path), " ".join(debug)))
|
||||
PY
|
||||
|
||||
echo "== extract the GSPA/GSPLNK toolchain"
|
||||
if [ ! -f "$SDK/GSPA.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "SDK image not found: $SDK_IMG"
|
||||
mkdir -p "$SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE is not extracted in $SDK"
|
||||
|
||||
cp "$SDK/GSPA.EXE" "$DOS/"
|
||||
cp "$WORK/obj/debug-a.o" "$DOS/DBGA.O"
|
||||
cp "$WORK/obj/debug-b.o" "$DOS/DBGB.O"
|
||||
sed 's/\r$//' "$DIR/debug-entry.asm" | sed 's/$/\r/' > "$DOS/DENTRY.ASM"
|
||||
|
||||
echo "== assemble debug-entry.asm with GSPA 2.00"
|
||||
rm -f "$DOS/DENTRY.O" "$DOS/DENTRY.LST"
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $DOS" -c "c:" \
|
||||
-c "gspa DENTRY DENTRY.O DENTRY.LST -l" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
[ -f "$DOS/DENTRY.LST" ] || fail "GSPA produced no DENTRY.LST"
|
||||
sed 's/\r$//' "$DOS/DENTRY.LST" > "$WORK/dentry.lst"
|
||||
grep -q 'No Errors' "$WORK/dentry.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/dentry.lst" >&2 || true; \
|
||||
fail "GSPA reported errors"; }
|
||||
grep -q 'No Warnings' "$WORK/dentry.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$WORK/dentry.lst" >&2 || true; \
|
||||
fail "GSPA reported warnings"; }
|
||||
|
||||
echo "== link --keep-debug and the default strip"
|
||||
"$TMS_LINK" -o "$WORK/keep.coff" --keep-debug \
|
||||
--map "$WORK/keep.map" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
"$WORK/obj/debug-a.o" "$WORK/obj/debug-b.o" "$DOS/DENTRY.O" \
|
||||
|| fail "tms-link --keep-debug failed"
|
||||
"$TMS_LINK" -o "$WORK/strip.coff" \
|
||||
--map "$WORK/strip.map" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
"$WORK/obj/debug-a.o" "$WORK/obj/debug-b.o" "$DOS/DENTRY.O" \
|
||||
|| fail "tms-link (strip) failed"
|
||||
|
||||
echo "== inspect the merged sections and write the expected offsets"
|
||||
python3 - "$M7COFF" "$WORK/obj/debug-a.o" "$WORK/obj/debug-b.o" \
|
||||
"$WORK/keep.coff" "$WORK/strip.coff" "$WORK/merge.env" <<'PY' \
|
||||
|| fail "merged debug layout is wrong"
|
||||
import os
|
||||
import sys
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[1]))
|
||||
import m7coff # noqa: E402
|
||||
|
||||
a_path, b_path, keep_path, strip_path, env_path = sys.argv[2:7]
|
||||
a = m7coff.parse(a_path)
|
||||
b = m7coff.parse(b_path)
|
||||
keep = m7coff.parse(keep_path)
|
||||
strip = m7coff.parse(strip_path)
|
||||
keep_sections = [s["name"] for s in keep["sections"]]
|
||||
strip_sections = [s["name"] for s in strip["sections"]]
|
||||
if strip_sections != [".text", ".data", ".bss"]:
|
||||
sys.exit("default strip has sections %r, want .text/.data/.bss"
|
||||
% strip_sections)
|
||||
if keep_sections[:3] != [".text", ".data", ".bss"]:
|
||||
sys.exit("kept image leading sections %r" % keep_sections[:3])
|
||||
debug = [n for n in keep_sections[3:] if n.startswith(".debug_")]
|
||||
if debug != keep_sections[3:] or not debug:
|
||||
sys.exit("kept image sections after .bss are %r" % keep_sections[3:])
|
||||
for name in (".debug_info", ".debug_abbrev", ".debug_line", ".debug_str",
|
||||
".debug_str_offsets", ".debug_addr", ".debug_line_str"):
|
||||
if name not in debug:
|
||||
sys.exit("kept image missing %s; got %r" % (name, debug))
|
||||
|
||||
for sa, sb in zip(keep["sections"][:3], strip["sections"]):
|
||||
if sa["paddr"] != sb["paddr"] or sa["size"] != sb["size"]:
|
||||
sys.exit("%s keep/strip paddr/size %#x/%d != %#x/%d"
|
||||
% (sa["name"], sa["paddr"], sa["size"], sb["paddr"],
|
||||
sb["size"]))
|
||||
if sa["flags"] != sb["flags"]:
|
||||
sys.exit("%s keep/strip flags differ" % sa["name"])
|
||||
if sa["name"] == ".bss":
|
||||
continue
|
||||
if sa["raw"] != sb["raw"]:
|
||||
sys.exit("%s keep/strip bytes differ" % sa["name"])
|
||||
for sec in keep["sections"]:
|
||||
if sec["name"].startswith(".debug_"):
|
||||
if sec["paddr"] != 0 or sec["vaddr"] != 0:
|
||||
sys.exit("%s paddr/vaddr %#x/%#x, want 0/0"
|
||||
% (sec["name"], sec["paddr"], sec["vaddr"]))
|
||||
if sec["flags"] != 0:
|
||||
sys.exit("%s flags %#x, want 0" % (sec["name"], sec["flags"]))
|
||||
if sec["nreloc"]:
|
||||
sys.exit("%s still has %d relocations"
|
||||
% (sec["name"], sec["nreloc"]))
|
||||
elif sec["nreloc"]:
|
||||
sys.exit("%s still has %d relocations" % (sec["name"], sec["nreloc"]))
|
||||
|
||||
# Every merged section is exactly the two inputs' contributions in order,
|
||||
# except for the 4-byte relocation fields that tms-link intentionally rewrites
|
||||
# to rehome section-relative references.
|
||||
for name in debug:
|
||||
want = 0
|
||||
raw = b""
|
||||
for c in (a, b):
|
||||
sec = m7coff.section(c, name)
|
||||
want += sec["size"]
|
||||
raw += sec["raw"]
|
||||
got = m7coff.section(keep, name)
|
||||
if got["size"] != want:
|
||||
sys.exit("%s merged size %d bits, want %d" % (name, got["size"], want))
|
||||
skip = set()
|
||||
bases = {id(a): 0, id(b): len(m7coff.section(a, name)["raw"])}
|
||||
for c in (a, b):
|
||||
sec = m7coff.section(c, name)
|
||||
for raddr, _symidx, _rtype in sec["relocs"]:
|
||||
field = bases[id(c)] + raddr // 8
|
||||
skip.update(range(field, field + 4))
|
||||
if got["raw"] != raw:
|
||||
diff = [i for i in range(len(raw))
|
||||
if raw[i] != got["raw"][i] and i not in skip]
|
||||
if diff:
|
||||
sys.exit("%s merged bytes differ from the object-order "
|
||||
"concatenation outside relocation fields: %r"
|
||||
% (name, diff[:8]))
|
||||
if not any(raw[i] != got["raw"][i] for i in range(len(raw))):
|
||||
sys.exit("%s has no rewritten relocation fields" % name)
|
||||
|
||||
syms = {s["name"]: s for s in keep["symbols"]}
|
||||
for name in ("_debug_a_mul", "_debug_a_add", "_debug_b_sub", "_debug_b_mul",
|
||||
"_start", "_debug_a_base", "_debug_b_base"):
|
||||
if name not in syms:
|
||||
sys.exit("kept image missing symbol %s" % name)
|
||||
a_mul = syms["_debug_a_mul"]["value"]
|
||||
a_add = syms["_debug_a_add"]["value"]
|
||||
b_sub = syms["_debug_b_sub"]["value"]
|
||||
b_mul = syms["_debug_b_mul"]["value"]
|
||||
start = syms["_start"]["value"]
|
||||
text = m7coff.section(keep, ".text")
|
||||
text_end = text["paddr"] + text["size"]
|
||||
if not (text["paddr"] <= a_mul < a_add < b_sub < b_mul < start < text_end):
|
||||
sys.exit("functions are not at increasing text offsets: "
|
||||
"%#x %#x %#x %#x %#x %#x %#x"
|
||||
% (text["paddr"], a_mul, a_add, b_sub, b_mul, start,
|
||||
text_end))
|
||||
if b_sub == a_mul:
|
||||
sys.exit("second TU has no nonzero text offset")
|
||||
|
||||
# Rehoming expectations: the second CU's section-relative bases are the first
|
||||
# object's merged contribution sizes (plus the DWARF5 unit header where the
|
||||
# attribute points past it).
|
||||
def raw_len(c, name):
|
||||
return len(m7coff.section(c, name)["raw"])
|
||||
|
||||
expect = {
|
||||
"B_ABBREV": raw_len(a, ".debug_abbrev"),
|
||||
"B_STR_OFFSETS": raw_len(a, ".debug_str_offsets") + 8,
|
||||
"B_STMT_LIST": raw_len(a, ".debug_line"),
|
||||
"B_ADDR": raw_len(a, ".debug_addr") + 8,
|
||||
}
|
||||
|
||||
with open(env_path, "w", encoding="ascii") as fh:
|
||||
for key, value in (
|
||||
("A_MUL_BITS", a_mul), ("A_ADD_BITS", a_add),
|
||||
("B_SUB_BITS", b_sub), ("B_MUL_BITS", b_mul),
|
||||
("START_BITS", start), ("TEXT_ORIGIN", text["paddr"]),
|
||||
("TEXT_END", text_end)):
|
||||
fh.write("%s=%d\n" % (key, value))
|
||||
for key, value in expect.items():
|
||||
fh.write("%s=%d\n" % (key, value))
|
||||
print(" keep sections: %s" % " ".join(keep_sections))
|
||||
print(" functions: a_mul=%#x a_add=%#x b_sub=%#x b_mul=%#x _start=%#x "
|
||||
"(bits)" % (a_mul, a_add, b_sub, b_mul, start))
|
||||
print(" second-CU bases: abbrev=%d str_offsets=%d stmt_list=%d addr=%d"
|
||||
% (expect["B_ABBREV"], expect["B_STR_OFFSETS"],
|
||||
expect["B_STMT_LIST"], expect["B_ADDR"]))
|
||||
PY
|
||||
|
||||
. "$WORK/merge.env"
|
||||
A_MUL_SIZE=$(((A_ADD_BITS - A_MUL_BITS) / 8))
|
||||
A_ADD_SIZE=$(((B_SUB_BITS - A_ADD_BITS) / 8))
|
||||
B_SUB_SIZE=$(((B_MUL_BITS - B_SUB_BITS) / 8))
|
||||
B_MUL_SIZE=$(((START_BITS - B_MUL_BITS) / 8))
|
||||
|
||||
echo "== wrap the kept .debug_* sections in a minimal ELF32 container"
|
||||
"$ROOT/scripts/m7/elf-debug-wrap.py" -o "$WORK/keep.elf" "$WORK/keep.coff" \
|
||||
|| fail "elf-debug-wrap failed"
|
||||
|
||||
echo "== llvm-dwarfdump"
|
||||
"$DWARFDUMP" --debug-info --verbose "$WORK/keep.elf" \
|
||||
> "$WORK/info.txt" 2> "$WORK/info.err" \
|
||||
|| { cat "$WORK/info.err" >&2; fail "llvm-dwarfdump --debug-info failed"; }
|
||||
"$DWARFDUMP" --debug-line "$WORK/keep.elf" \
|
||||
> "$WORK/line.txt" 2> "$WORK/line.err" \
|
||||
|| { cat "$WORK/line.err" >&2; fail "llvm-dwarfdump --debug-line failed"; }
|
||||
|
||||
python3 - "$WORK/info.txt" "$WORK/line.txt" "$A_MUL_BITS" "$A_ADD_BITS" \
|
||||
"$B_SUB_BITS" "$B_MUL_BITS" "$START_BITS" "$TEXT_ORIGIN" \
|
||||
"$A_MUL_SIZE" "$A_ADD_SIZE" "$B_SUB_SIZE" "$B_MUL_SIZE" \
|
||||
"$B_ABBREV" "$B_STR_OFFSETS" "$B_STMT_LIST" "$B_ADDR" <<'PY' \
|
||||
|| fail "merged DWARF compile units/subprograms/line rows are wrong"
|
||||
import re
|
||||
import sys
|
||||
|
||||
(info_path, line_path) = sys.argv[1], sys.argv[2]
|
||||
a_mul_bits, a_add_bits, b_sub_bits, b_mul_bits, start_bits, origin_bits = \
|
||||
[int(v) for v in sys.argv[3:9]]
|
||||
a_mul_size, a_add_size, b_sub_size, b_mul_size = \
|
||||
[int(v) for v in sys.argv[9:13]]
|
||||
b_abbrev, b_str_offsets, b_stmt_list, b_addr = \
|
||||
[int(v) for v in sys.argv[13:17]]
|
||||
origin = origin_bits // 8
|
||||
lows = {
|
||||
"debug_a_mul": a_mul_bits // 8,
|
||||
"debug_a_add": a_add_bits // 8,
|
||||
"debug_b_sub": b_sub_bits // 8,
|
||||
"debug_b_mul": b_mul_bits // 8,
|
||||
"_start": start_bits // 8,
|
||||
}
|
||||
if origin != 0x314000:
|
||||
sys.exit("text origin byte address %#x, want 0x314000" % origin)
|
||||
if lows["debug_a_mul"] != origin:
|
||||
sys.exit("debug_a_mul low %#x, want text origin %#x"
|
||||
% (lows["debug_a_mul"], origin))
|
||||
|
||||
cus = []
|
||||
subs = []
|
||||
cu = None
|
||||
cur = None
|
||||
mode = None
|
||||
for raw in open(info_path, encoding="latin1"):
|
||||
line = raw.rstrip("\n")
|
||||
m = re.search(r"Compile Unit: .*abbr_offset = 0x([0-9a-fA-F]+)", line)
|
||||
if m:
|
||||
cu = {"name": None, "low": None, "high": None, "high_form": None,
|
||||
"abbr": int(m.group(1), 16), "str_offsets": None,
|
||||
"stmt_list": None, "addr_base": None}
|
||||
cus.append(cu)
|
||||
cur = None
|
||||
mode = None
|
||||
continue
|
||||
if "DW_TAG_compile_unit" in line:
|
||||
cur = cu
|
||||
mode = "cu"
|
||||
continue
|
||||
if "DW_TAG_subprogram" in line:
|
||||
cur = {"name": None, "low": None, "high": None, "high_form": None,
|
||||
"line": None, "cu": cu}
|
||||
subs.append(cur)
|
||||
mode = "sub"
|
||||
continue
|
||||
if "DW_TAG_" in line:
|
||||
mode = None
|
||||
continue
|
||||
if mode is None or cur is None:
|
||||
continue
|
||||
m = re.search(r"DW_AT_low_pc.*address = 0x([0-9a-fA-F]+)", line)
|
||||
if m:
|
||||
cur["low"] = int(m.group(1), 16)
|
||||
continue
|
||||
m = re.search(r"DW_AT_high_pc \[([A-Za-z0-9_]+)\]\s+\(0x([0-9a-fA-F]+)\)",
|
||||
line)
|
||||
if m:
|
||||
cur["high_form"] = m.group(1)
|
||||
cur["high"] = int(m.group(2), 16)
|
||||
continue
|
||||
m = re.search(r'DW_AT_name.*string = "([^"]+)"', line)
|
||||
if m:
|
||||
cur["name"] = m.group(1)
|
||||
continue
|
||||
m = re.search(r"DW_AT_decl_line \[[A-Za-z0-9_]+\]\s+\((\d+)\)", line)
|
||||
if m:
|
||||
cur["line"] = int(m.group(1))
|
||||
continue
|
||||
if mode == "cu":
|
||||
for attr, key in (("str_offsets_base", "str_offsets"),
|
||||
("stmt_list", "stmt_list"),
|
||||
("addr_base", "addr_base")):
|
||||
m = re.search(r"DW_AT_%s .*\(0x([0-9a-fA-F]+)\)" % attr, line)
|
||||
if m:
|
||||
cur[key] = int(m.group(1), 16)
|
||||
|
||||
if len(cus) != 2:
|
||||
sys.exit("saw %d compile units, want 2" % len(cus))
|
||||
by_cu = {c["name"]: c for c in cus if c["name"]}
|
||||
if set(by_cu) != {"debug-a.c", "debug-b.c"}:
|
||||
sys.exit("compile unit names %r, want debug-a.c and debug-b.c"
|
||||
% sorted(by_cu))
|
||||
cua, cub = by_cu["debug-a.c"], by_cu["debug-b.c"]
|
||||
if (cua["abbr"], cua["str_offsets"], cua["stmt_list"], cua["addr_base"]) != \
|
||||
(0, 8, 0, 8):
|
||||
sys.exit("first CU bases abbr/str_offsets/stmt_list/addr = %r, want "
|
||||
"(0, 8, 0, 8)"
|
||||
% ((cua["abbr"], cua["str_offsets"], cua["stmt_list"],
|
||||
cua["addr_base"]),))
|
||||
want_b = (b_abbrev, b_str_offsets, b_stmt_list, b_addr)
|
||||
got_b = (cub["abbr"], cub["str_offsets"], cub["stmt_list"], cub["addr_base"])
|
||||
if got_b != want_b:
|
||||
sys.exit("second CU bases abbr/str_offsets/stmt_list/addr = %r, want %r "
|
||||
"(merged first-object contributions)" % (got_b, want_b))
|
||||
if cub["abbr"] == 0 or cub["str_offsets"] == 8 or cub["addr_base"] == 8:
|
||||
sys.exit("second CU bases were not rehomed: %r" % (got_b,))
|
||||
|
||||
cus_by_name = {c["name"]: c for c in cus}
|
||||
for name, low in (("debug-a.c", lows["debug_a_mul"]),
|
||||
("debug-b.c", lows["debug_b_sub"])):
|
||||
c = cus_by_name[name]
|
||||
if c["low"] != low:
|
||||
sys.exit("%s CU low_pc %#x, want %#x" % (name, c["low"], low))
|
||||
if c["high_form"] != "DW_FORM_data4":
|
||||
sys.exit("%s CU high_pc form %r, want DW_FORM_data4"
|
||||
% (name, c["high_form"]))
|
||||
size_a = (b_sub_bits - a_mul_bits) // 8
|
||||
size_b = (start_bits - b_sub_bits) // 8
|
||||
if cus_by_name["debug-a.c"]["high"] != size_a:
|
||||
sys.exit("debug-a.c CU high_pc %#x, want %#x"
|
||||
% (cus_by_name["debug-a.c"]["high"], size_a))
|
||||
if cus_by_name["debug-b.c"]["high"] != size_b:
|
||||
sys.exit("debug-b.c CU high_pc %#x, want %#x"
|
||||
% (cus_by_name["debug-b.c"]["high"], size_b))
|
||||
|
||||
by_name = {s["name"]: s for s in subs if s["name"]}
|
||||
for name, low, size, decl, tu in (
|
||||
("debug_a_mul", lows["debug_a_mul"], a_mul_size, 3,
|
||||
"debug-a.c"),
|
||||
("debug_a_add", lows["debug_a_add"], a_add_size, 8,
|
||||
"debug-a.c"),
|
||||
("debug_b_sub", lows["debug_b_sub"], b_sub_size, 3,
|
||||
"debug-b.c"),
|
||||
("debug_b_mul", lows["debug_b_mul"], b_mul_size, 8,
|
||||
"debug-b.c")):
|
||||
if name not in by_name:
|
||||
sys.exit("no DW_TAG_subprogram named %s (saw %r)"
|
||||
% (name, sorted(by_name)))
|
||||
s = by_name[name]
|
||||
if s["cu"] is not cus_by_name[tu]:
|
||||
sys.exit("%s is not attributed to the %s compile unit" % (name, tu))
|
||||
if s["low"] != low:
|
||||
sys.exit("%s low_pc %#x, want linked %#x" % (name, s["low"], low))
|
||||
if s["high_form"] != "DW_FORM_data4" or s["high"] != size:
|
||||
sys.exit("%s high_pc %r/%#x, want DW_FORM_data4/%#x"
|
||||
% (name, s["high_form"], s["high"], size))
|
||||
if s["line"] != decl:
|
||||
sys.exit("%s DW_AT_decl_line %r, want %d" % (name, s["line"], decl))
|
||||
|
||||
# .debug_line: two units, each with its own file table and rows at its TU's
|
||||
# linked function low PCs. The first body line is 4 in both sources and the
|
||||
# second function's first body line is 9 in both sources.
|
||||
units = []
|
||||
unit = None
|
||||
for raw in open(line_path, encoding="latin1"):
|
||||
line = raw.rstrip("\n")
|
||||
m = re.match(r"^debug_line\[0x([0-9a-fA-F]+)\]", line)
|
||||
if m:
|
||||
unit = {"off": int(m.group(1), 16), "names": [], "rows": {}}
|
||||
units.append(unit)
|
||||
continue
|
||||
if unit is None:
|
||||
continue
|
||||
m = re.match(r'^\s+name: "([^"]+)"$', line)
|
||||
if m:
|
||||
unit["names"].append(m.group(1))
|
||||
continue
|
||||
m = re.match(r"^(0x[0-9a-fA-F]+)\s+(\d+)\s+(\d+)\s+(\d+)\s",
|
||||
line.strip() + " ")
|
||||
if m:
|
||||
unit["rows"][int(m.group(1), 16)] = int(m.group(2))
|
||||
if len(units) != 2:
|
||||
sys.exit("saw %d .debug_line units, want 2" % len(units))
|
||||
if units[0]["names"] != ["debug-a.c"]:
|
||||
sys.exit("first line unit file table %r, want [debug-a.c]"
|
||||
% units[0]["names"])
|
||||
if units[1]["names"] != ["debug-b.c"]:
|
||||
sys.exit("second line unit file table %r, want [debug-b.c]"
|
||||
% units[1]["names"])
|
||||
for unit, low, body in ((units[0], lows["debug_a_mul"], 4),
|
||||
(units[0], lows["debug_a_add"], 9),
|
||||
(units[1], lows["debug_b_sub"], 4),
|
||||
(units[1], lows["debug_b_mul"], 9)):
|
||||
if unit["rows"].get(low) != body:
|
||||
sys.exit("no line row at %#x with line %d (rows %r)"
|
||||
% (low, body, unit["rows"]))
|
||||
if any(low in units[1]["rows"] for low in (lows["debug_a_mul"],
|
||||
lows["debug_a_add"])):
|
||||
sys.exit("debug-a functions appear in the debug-b line unit")
|
||||
|
||||
print(" compile units: debug-a.c low=%#x high=%#x, debug-b.c low=%#x "
|
||||
"high=%#x" % (cua["low"], cua["high"], cub["low"], cub["high"]))
|
||||
print(" subprograms: " + ", ".join(
|
||||
"%s@%#x+%#x line=%d" % (s["name"], s["low"], s["high"], s["line"])
|
||||
for s in subs if s["name"] in by_name))
|
||||
print(" line units: debug-a.c rows at a_mul/a_add, debug-b.c rows at "
|
||||
"b_sub/b_mul (body lines 4/9)")
|
||||
PY
|
||||
|
||||
echo "== -O2 -g multi-TU merge (location lists)"
|
||||
( cd "$DIR" && "$TMS_CLANG" -g -O2 -o "$WORK/obj/debug-a-o2.ll" debug-a.c ) \
|
||||
|| fail "tms-clang -g -O2 failed for debug-a.c"
|
||||
( cd "$DIR" && "$TMS_CLANG" -g -O2 -o "$WORK/obj/debug-b-o2.ll" debug-b.c ) \
|
||||
|| fail "tms-clang -g -O2 failed for debug-b.c"
|
||||
for name in debug-a-o2 debug-b-o2; do
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$WORK/obj/$name.ll" -o "$WORK/obj/$name.o" \
|
||||
|| fail "llc -filetype=obj failed for $name"
|
||||
done
|
||||
"$TMS_LINK" -o "$WORK/keep-o2.coff" --keep-debug \
|
||||
--entry _start --text 018A0000 --bss 01A00000 \
|
||||
"$WORK/obj/debug-a-o2.o" "$WORK/obj/debug-b-o2.o" "$DOS/DENTRY.O" \
|
||||
|| fail "tms-link --keep-debug failed for the -O2 objects"
|
||||
"$ROOT/scripts/m7/elf-debug-wrap.py" -o "$WORK/keep-o2.elf" \
|
||||
"$WORK/keep-o2.coff" >/dev/null \
|
||||
|| fail "elf-debug-wrap failed for the -O2 link"
|
||||
"$DWARFDUMP" --debug-info --verbose "$WORK/keep-o2.elf" \
|
||||
> "$WORK/info-o2.txt" 2> "$WORK/info-o2.err" \
|
||||
|| { cat "$WORK/info-o2.err" >&2; \
|
||||
fail "llvm-dwarfdump --debug-info failed for -O2"; }
|
||||
"$DWARFDUMP" --debug-line "$WORK/keep-o2.elf" \
|
||||
> "$WORK/line-o2.txt" 2> "$WORK/line-o2.err" \
|
||||
|| { cat "$WORK/line-o2.err" >&2; \
|
||||
fail "llvm-dwarfdump --debug-line failed for -O2"; }
|
||||
python3 - "$M7COFF" "$WORK/obj/debug-a-o2.o" "$WORK/info-o2.txt" \
|
||||
"$WORK/line-o2.txt" <<'PY' || fail "-O2 multi-TU DWARF is wrong"
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[1]))
|
||||
import m7coff # noqa: E402
|
||||
|
||||
obj = m7coff.parse(sys.argv[2])
|
||||
first_loclists = len(m7coff.section(obj, ".debug_loclists")["raw"])
|
||||
info = open(sys.argv[3], encoding="latin1").read()
|
||||
line = open(sys.argv[4], encoding="latin1").read()
|
||||
|
||||
blocks = info.split("Compile Unit:")[1:]
|
||||
if len(blocks) != 2:
|
||||
sys.exit("saw %d compile units at -O2, want 2" % len(blocks))
|
||||
cus = []
|
||||
for block in blocks:
|
||||
name = re.search(r'DW_AT_name.*string = "([^"]+)"', block)
|
||||
loc = re.search(r"DW_AT_loclists_base .*\(0x([0-9a-fA-F]+)\)", block)
|
||||
if not name or not loc:
|
||||
sys.exit("-O2 CU lacks a name or DW_AT_loclists_base")
|
||||
cus.append((name.group(1), int(loc.group(1), 16)))
|
||||
if {n for n, _ in cus} != {"debug-a.c", "debug-b.c"}:
|
||||
sys.exit("-O2 CU names %r" % [n for n, _ in cus])
|
||||
by_name = {n: b for n, b in cus}
|
||||
if by_name["debug-a.c"] != 12:
|
||||
sys.exit("-O2 first CU loclists_base %#x, want 12 (unit header)"
|
||||
% by_name["debug-a.c"])
|
||||
want = first_loclists + 12
|
||||
if by_name["debug-b.c"] != want:
|
||||
sys.exit("-O2 second CU loclists_base %#x, want %#x (first object's "
|
||||
".debug_loclists contribution + header)"
|
||||
% (by_name["debug-b.c"], want))
|
||||
for name in ("debug_a_mul", "debug_a_add", "debug_b_sub", "debug_b_mul"):
|
||||
if 'string = "%s"' % name not in info:
|
||||
sys.exit("-O2 DWARF has no subprogram %s" % name)
|
||||
for name in ("debug-a.c", "debug-b.c"):
|
||||
if 'name: "%s"' % name not in line:
|
||||
sys.exit("-O2 .debug_line has no %s file table" % name)
|
||||
print(" -O2: both CUs, loclists_base %#x/%#x (first contribution %d B)"
|
||||
% (by_name["debug-a.c"], by_name["debug-b.c"], first_loclists))
|
||||
PY
|
||||
|
||||
if command -v ar >/dev/null 2>&1; then
|
||||
echo "== archive-member debug sections are merged, not dropped"
|
||||
ar rcs "$WORK/dwarf.lib" "$WORK/obj/debug-a.o" "$WORK/obj/debug-b.o" \
|
||||
|| fail "ar could not create the debug archive"
|
||||
"$TMS_LINK" -o "$WORK/keep-archive.coff" --keep-debug \
|
||||
--entry _start --text 018A0000 --bss 01A00000 \
|
||||
"$DOS/DENTRY.O" "$WORK/dwarf.lib" \
|
||||
|| fail "tms-link --keep-debug from an archive failed"
|
||||
python3 - "$M7COFF" "$WORK/keep-archive.coff" <<'PY' \
|
||||
|| fail "archive-member debug sections are missing"
|
||||
import os
|
||||
import sys
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[1]))
|
||||
import m7coff # noqa: E402
|
||||
c = m7coff.parse(sys.argv[2])
|
||||
names = [s["name"] for s in c["sections"]]
|
||||
for name in (".debug_info", ".debug_abbrev", ".debug_line", ".debug_str",
|
||||
".debug_str_offsets", ".debug_addr", ".debug_line_str"):
|
||||
if name not in names:
|
||||
sys.exit("archive link dropped %s; sections %r" % (name, names))
|
||||
if any(s["nreloc"] for s in c["sections"]):
|
||||
sys.exit("archive debug link still has relocations")
|
||||
print(" archive link sections: %s" % " ".join(names))
|
||||
PY
|
||||
"$ROOT/scripts/m7/elf-debug-wrap.py" -o "$WORK/archive.elf" \
|
||||
"$WORK/keep-archive.coff" >/dev/null \
|
||||
|| fail "elf-debug-wrap failed for the archive link"
|
||||
"$DWARFDUMP" --debug-info --verbose --debug-line "$WORK/archive.elf" \
|
||||
> "$WORK/archive-dwarf.txt" 2> "$WORK/archive-dwarf.err" \
|
||||
|| { cat "$WORK/archive-dwarf.err" >&2; \
|
||||
fail "llvm-dwarfdump failed on the archive link"; }
|
||||
for want in 'string = "debug-a.c"' 'string = "debug-b.c"' \
|
||||
'string = "debug_a_mul"' 'string = "debug_b_mul"'; do
|
||||
grep -q "$want" "$WORK/archive-dwarf.txt" \
|
||||
|| fail "archive-link DWARF has no $want"
|
||||
done
|
||||
echo " archive link DWARF: both CUs and both TU functions present"
|
||||
else
|
||||
echo "== archive-member debug merge: SKIP (no ar command)"
|
||||
fi
|
||||
|
||||
echo "== run the stripped image in MAME"
|
||||
rm -rf "$WORK/run/nvram"
|
||||
mkdir -p "$WORK/run/nvram"
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$WORK/strip.coff" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/debug-multi-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; \
|
||||
fail "COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -q '^DEBUG MULTI: a_mul=22 a_add=14 b_sub=9 b_mul=36$' "$WORK/mame.log" \
|
||||
|| { grep '^DEBUG MULTI:' "$WORK/mame.log" >&2 || true; \
|
||||
fail "multi-TU debug markers are wrong"; }
|
||||
grep -q '^DEBUG MULTI MAME: PASS$' "$WORK/mame.log" \
|
||||
|| fail "MAME marker check failed"
|
||||
|
||||
echo "M8 dwarf-multi: PASS (two TUs merged with rehomed CU/abbrev/str/line/"
|
||||
echo " addr bases, dwarfdump sees both files/functions/lines/"
|
||||
echo " addresses, and the stripped image runs in MAME)"
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
# M8 native-library gate: link a real driver against the 1987 FLIB.LIB and
|
||||
# RTS.LIB through tools/tms-link, run it in MAME, and compare the allocated
|
||||
# image and public symbols with the GSPLNK 2.00 oracle.
|
||||
#
|
||||
# The driver uses flib FD$ADD/FD$MUL/FD$DTOI (double arithmetic and fptosi)
|
||||
# and rts.lib _isascii. The GSPLNK run never reaches MAME; the tms-link run
|
||||
# must report the loader status, place .text with 0 differing bytes, and pass
|
||||
# the marker check.
|
||||
#
|
||||
# scripts/tests/m8/native-lib.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_CLANG MAME DOSBOX DOSBOX_CONF SDK_IMG
|
||||
# M8_NATIVE_LIB_WORK M8_NATIVE_LIB_SDK M7COFF
|
||||
# LOADER_AT LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m8
|
||||
WORK=${M8_NATIVE_LIB_WORK:-$ROOT/build/m8-native-lib}
|
||||
SDK=${M8_NATIVE_LIB_SDK:-$ROOT/build/m4-sdk}
|
||||
M7COFF=${M7COFF:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m7coff.py}
|
||||
|
||||
fail() {
|
||||
echo "M8 native lib: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$DIR/libcheck.c" ] || fail "missing driver: $DIR/libcheck.c"
|
||||
[ -f "$DIR/lib-entry.asm" ] || fail "missing entry: $DIR/lib-entry.asm"
|
||||
[ -f "$DIR/lib-check.lua" ] || fail "missing checker: $DIR/lib-check.lua"
|
||||
[ -f "$M7COFF" ] || fail "independent TI-COFF reader not found: $M7COFF"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
RUN_ENV="M4_NATIVE=1
|
||||
M4_SOURCES=$DIR/libcheck.c
|
||||
M4_ENTRY=$DIR/lib-entry.asm
|
||||
M4_CHECK_LUA=$DIR/lib-check.lua
|
||||
M4_SDK=$SDK
|
||||
M4_NATIVE_LIBS=FLIB.LIB
|
||||
M4_NATIVE_RTS=1"
|
||||
|
||||
echo "== GSPLNK oracle link (no MAME)"
|
||||
# shellcheck disable=SC2086
|
||||
env $RUN_ENV \
|
||||
M4_WORK="$WORK/gsplnk" \
|
||||
M4_COFF="$WORK/gsplnk/m4.coff" \
|
||||
M4_SKIP_MAME=1 \
|
||||
"$ROOT/scripts/m4/run.sh" > "$WORK/gsplnk.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/gsplnk.log" >&2; fail "GSPLNK oracle link failed"; }
|
||||
grep -q '^M4 LINK: PASS' "$WORK/gsplnk.log" \
|
||||
|| { tail -30 "$WORK/gsplnk.log" >&2; fail "GSPLNK oracle did not pass"; }
|
||||
[ -f "$WORK/gsplnk/m4.coff" ] || fail "GSPLNK produced no image"
|
||||
|
||||
echo "== tms-link archive link and MAME"
|
||||
# shellcheck disable=SC2086
|
||||
env $RUN_ENV \
|
||||
M4_LINKER=tms-link \
|
||||
M4_WORK="$WORK/tmslink" \
|
||||
M4_COFF="$WORK/tmslink/m4.coff" \
|
||||
LOADER_AT="${LOADER_AT:-2500}" \
|
||||
LOADER_END="${LOADER_END:-3400}" \
|
||||
"$ROOT/scripts/m4/run.sh" > "$WORK/tmslink.log" 2>&1 \
|
||||
|| { tail -40 "$WORK/tmslink.log" >&2; fail "tms-link archive run failed"; }
|
||||
grep -q '^M8 LIB MAME: PASS' "$WORK/tmslink/mame.log" \
|
||||
|| { tail -40 "$WORK/tmslink/mame.log" >&2; \
|
||||
fail "tms-link MAME markers failed"; }
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/tmslink/mame.log" \
|
||||
|| fail "loader did not accept the tms-link image"
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/tmslink/mame.log" \
|
||||
|| fail "loader did not verify the placed .text bytes"
|
||||
|
||||
echo "== GSPLNK vs raw tms-link allocated bytes and symbols"
|
||||
[ -f "$WORK/tmslink/M4.RAW.OUT" ] \
|
||||
|| fail "tms-link did not preserve its pre-repair image"
|
||||
cmp -s "$WORK/tmslink/M4.RAW.OUT" "$WORK/tmslink/m4.coff" \
|
||||
|| fail "tms-link image changed during coff-check repair"
|
||||
python3 "$ROOT/scripts/tests/m8/coff-parity.py" \
|
||||
"$M7COFF" "$WORK/gsplnk/m4.coff" "$WORK/tmslink/M4.RAW.OUT" \
|
||||
|| fail "raw tms-link image differs from GSPLNK"
|
||||
|
||||
# The library members are visible in the map, and no unrelated member was
|
||||
# pulled in. (The marker check already proved the actual calls ran.)
|
||||
MAP=$WORK/tmslink/m4.map
|
||||
for sym in FD\$ADD FD\$MUL FD\$DTOI _isascii _fp_error; do
|
||||
grep -q " ${sym}\$" "$MAP" || fail "tms-link map has no $sym"
|
||||
done
|
||||
for sym in FD\$DIV FD\$NEG FD\$EQ FS\$ADD _printf; do
|
||||
if grep -q " ${sym}\$" "$MAP"; then
|
||||
fail "tms-link map has an unneeded member symbol: $sym"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "M8 native lib: PASS (FD\$ADD/FD\$MUL/FD\$DTOI + _isascii, GSPLNK parity)"
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
; Linker unit fixture: a second translation unit that references the cinit
|
||||
; member. Used with refs.ll to require two same-named archive members.
|
||||
declare i32 @cinit_get()
|
||||
|
||||
define i32 @start2() {
|
||||
entry:
|
||||
%v = call i32 @cinit_get()
|
||||
ret i32 %v
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
; Linker unit fixture: one reference into the 1990 flib.lib archive.
|
||||
; A double add lowers to a call to FD$ADD, whose member also references
|
||||
; _fp_error, so selective extraction must iterate to a fixpoint.
|
||||
define double @start(double %a, double %b) {
|
||||
entry:
|
||||
%r = fadd double %a, %b
|
||||
ret double %r
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from tmscoff import C_EXT, align16, read_object # noqa: E402
|
||||
from tmscoff import C_EXT, align16, read_archive, read_object # noqa: E402
|
||||
|
||||
|
||||
def fail(msg):
|
||||
@@ -28,12 +28,396 @@ def u32(data, off):
|
||||
return struct.unpack_from("<I", data, off)[0]
|
||||
|
||||
|
||||
def s32(data, off):
|
||||
return struct.unpack_from("<i", data, off)[0]
|
||||
|
||||
|
||||
def file_flags(path):
|
||||
with open(path, "rb") as fh:
|
||||
head = fh.read(20)
|
||||
return struct.unpack_from("<H", head, 18)[0]
|
||||
|
||||
|
||||
def ar_header(name_field, size):
|
||||
"""One 60-byte System V ar member header."""
|
||||
return (name_field.ljust(16, b" ") +
|
||||
b"0".ljust(12, b" ") +
|
||||
b"0".ljust(6, b" ") +
|
||||
b"0".ljust(6, b" ") +
|
||||
b"644".ljust(8, b" ") +
|
||||
str(size).encode("ascii").ljust(10, b" ") +
|
||||
b"`\n")
|
||||
|
||||
|
||||
def write_archive(path, members, index=True, long_names=True,
|
||||
empty_index=False):
|
||||
"""Write a System V ar archive with an optional / index and // table.
|
||||
|
||||
``members`` is a list of (name, bytes). The writer is deliberately
|
||||
independent of the linker's extraction logic; it only shares the COFF
|
||||
reader to collect each member's external definitions. ``empty_index``
|
||||
writes a present-but-empty / table (count 0).
|
||||
"""
|
||||
long_blob = bytearray()
|
||||
long_offsets = {}
|
||||
if long_names:
|
||||
for name, _data in members:
|
||||
if len(name.encode("latin1")) > 15:
|
||||
long_offsets[name] = len(long_blob)
|
||||
long_blob.extend(name.encode("latin1"))
|
||||
long_blob.extend(b"/\n")
|
||||
|
||||
symbols = []
|
||||
if index and not empty_index:
|
||||
for member_index, (name, data) in enumerate(members):
|
||||
obj = read_object(data=data, label="<fixture member %s>" % name)
|
||||
defs = [sym.name for sym in obj.symbols
|
||||
if sym.is_global and not sym.is_section and
|
||||
(sym.secno > 0 or sym.is_absolute)]
|
||||
symbols.extend((sym, member_index) for sym in defs)
|
||||
if empty_index:
|
||||
index_size = 4
|
||||
else:
|
||||
index_size = 4 + 4 * len(symbols) + sum(
|
||||
len(name.encode("latin1")) + 1 for name, _member in symbols)
|
||||
|
||||
offset = 8
|
||||
index_offset = None
|
||||
long_offset = None
|
||||
if index:
|
||||
index_offset = offset
|
||||
offset += 60 + index_size + (index_size & 1)
|
||||
if long_blob:
|
||||
long_offset = offset
|
||||
offset += 60 + len(long_blob) + (len(long_blob) & 1)
|
||||
member_offsets = []
|
||||
for name, data in members:
|
||||
member_offsets.append(offset)
|
||||
offset += 60 + len(data) + (len(data) & 1)
|
||||
|
||||
index_blob = bytearray(
|
||||
struct.pack(">I", 0 if empty_index else len(symbols)))
|
||||
if not empty_index:
|
||||
for _symbol, member_index in symbols:
|
||||
index_blob.extend(struct.pack(">I", member_offsets[member_index]))
|
||||
for symbol, _member_index in symbols:
|
||||
index_blob.extend(symbol.encode("latin1"))
|
||||
index_blob.append(0)
|
||||
check(len(index_blob) == index_size,
|
||||
"archive index size %d != planned %d"
|
||||
% (len(index_blob), index_size))
|
||||
|
||||
out = bytearray(b"!<arch>\n")
|
||||
|
||||
def add(name_field, body):
|
||||
out.extend(ar_header(name_field, len(body)))
|
||||
out.extend(body)
|
||||
if len(body) & 1:
|
||||
out.append(0x0A)
|
||||
|
||||
if index:
|
||||
add(b"/", index_blob)
|
||||
if long_blob:
|
||||
add(b"//", long_blob)
|
||||
for (name, data), member_offset in zip(members, member_offsets):
|
||||
check(len(out) == member_offset,
|
||||
"member %s header offset %d != planned %d"
|
||||
% (name, len(out), member_offset))
|
||||
if name in long_offsets:
|
||||
field = ("/%d" % long_offsets[name]).encode("ascii")
|
||||
else:
|
||||
field = name.encode("latin1") + b"/"
|
||||
check(len(field) <= 16, "member name field %r does not fit" % field)
|
||||
add(field, data)
|
||||
|
||||
with open(path, "wb") as fh:
|
||||
fh.write(out)
|
||||
return {
|
||||
"index_offset": index_offset,
|
||||
"index_size": index_size if index else None,
|
||||
"long_offset": long_offset,
|
||||
"long_size": len(long_blob) if long_blob else None,
|
||||
"member_offsets": member_offsets,
|
||||
"index_symbols": [(sym, member_offsets[member_index])
|
||||
for sym, member_index in symbols],
|
||||
}
|
||||
|
||||
|
||||
def make_archive(work):
|
||||
"""Build the tiny archive fixtures used by tests/run.sh."""
|
||||
defs = open(os.path.join(work, "defs.o"), "rb").read()
|
||||
refs = open(os.path.join(work, "refs.o"), "rb").read()
|
||||
cinit = open(os.path.join(work, "cinit.o"), "rb").read()
|
||||
del refs
|
||||
|
||||
write_archive(os.path.join(work, "basic.lib"),
|
||||
[("defs.o", defs), ("unused-cinit.obj", cinit)])
|
||||
write_archive(os.path.join(work, "basic-noindex.lib"),
|
||||
[("defs.o", defs), ("unused-cinit.obj", cinit)],
|
||||
index=False)
|
||||
write_archive(os.path.join(work, "emptyindex.lib"),
|
||||
[("defs.o", defs), ("unused-cinit.obj", cinit)],
|
||||
empty_index=True)
|
||||
write_archive(os.path.join(work, "duplicate.lib"),
|
||||
[("first.obj", defs), ("second.obj", defs)])
|
||||
write_archive(os.path.join(work, "dupnamed.lib"),
|
||||
[("dup.o", defs), ("dup.o", cinit)])
|
||||
write_archive(os.path.join(work, "unused.lib"),
|
||||
[("unused-cinit.obj", cinit)])
|
||||
write_archive(os.path.join(work, "longnames.lib"),
|
||||
[("defs_with_a_long_member_name.o", defs)])
|
||||
|
||||
# Point every defs.o index entry at the cinit member: the index then
|
||||
# claims that member defines symbols it does not, and the only way to
|
||||
# satisfy refs.o is through the lie.
|
||||
meta = write_archive(os.path.join(work, "liar.lib"),
|
||||
[("defs.o", defs), ("unused-cinit.obj", cinit)])
|
||||
data = bytearray(open(os.path.join(work, "liar.lib"), "rb").read())
|
||||
for entry, (_symbol, offset) in enumerate(meta["index_symbols"]):
|
||||
if offset == meta["member_offsets"][0]:
|
||||
struct.pack_into(">I", data,
|
||||
meta["index_offset"] + 60 + 4 + 4 * entry,
|
||||
meta["member_offsets"][1])
|
||||
open(os.path.join(work, "liar.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "dupsymtab.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = bytearray(open(os.path.join(work, "dupsymtab.lib"), "rb").read())
|
||||
special = data[8:8 + 60 + meta["index_size"] +
|
||||
(meta["index_size"] & 1)]
|
||||
data.extend(special)
|
||||
open(os.path.join(work, "dupsymtab.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "duplong.lib"),
|
||||
[("defs_with_a_long_member_name.o", defs)])
|
||||
data = bytearray(open(os.path.join(work, "duplong.lib"), "rb").read())
|
||||
special = data[meta["long_offset"]:meta["long_offset"] + 60 +
|
||||
meta["long_size"] + (meta["long_size"] & 1)]
|
||||
data.extend(special)
|
||||
open(os.path.join(work, "duplong.lib"), "wb").write(data)
|
||||
|
||||
# A BSD #1/ name is unsupported and must be loud.
|
||||
body = b"name\0data"
|
||||
header = (b"#1/20".ljust(16, b" ") + b"0".ljust(12, b" ") +
|
||||
b"0".ljust(6, b" ") + b"0".ljust(6, b" ") +
|
||||
b"644".ljust(8, b" ") +
|
||||
str(len(body)).encode().ljust(10, b" ") + b"`\n")
|
||||
open(os.path.join(work, "bsd.lib"), "wb").write(
|
||||
b"!<arch>\n" + header + body + b"\n")
|
||||
|
||||
# An odd-size member with a bad pad byte.
|
||||
odd = defs + b"\0"
|
||||
meta = write_archive(os.path.join(work, "bad-pad.lib"),
|
||||
[("odd.o", odd)], index=False)
|
||||
data = bytearray(open(os.path.join(work, "bad-pad.lib"), "rb").read())
|
||||
pad = meta["member_offsets"][0] + 60 + len(odd)
|
||||
data[pad] = 0x55
|
||||
open(os.path.join(work, "bad-pad.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "missing-pad.lib"),
|
||||
[("odd.o", odd)], index=False)
|
||||
data = open(os.path.join(work, "missing-pad.lib"), "rb").read()
|
||||
open(os.path.join(work, "missing-pad.lib"), "wb").write(data[:-1])
|
||||
|
||||
meta = write_archive(os.path.join(work, "bad-magic.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = bytearray(open(os.path.join(work, "bad-magic.lib"), "rb").read())
|
||||
header = meta["member_offsets"][0]
|
||||
data[header + 58:header + 60] = b"XX"
|
||||
open(os.path.join(work, "bad-magic.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "bad-size.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = bytearray(open(os.path.join(work, "bad-size.lib"), "rb").read())
|
||||
header = meta["member_offsets"][0]
|
||||
data[header + 48:header + 58] = b"not-a-num "
|
||||
open(os.path.join(work, "bad-size.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "unicode-size.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = bytearray(open(os.path.join(work, "unicode-size.lib"), "rb").read())
|
||||
header = meta["member_offsets"][0]
|
||||
data[header + 48:header + 58] = b"\xb2" * 10
|
||||
open(os.path.join(work, "unicode-size.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "truncated.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = open(os.path.join(work, "truncated.lib"), "rb").read()
|
||||
data = data[:meta["member_offsets"][0] + 60 + 100]
|
||||
open(os.path.join(work, "truncated.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "truncated-header.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = open(os.path.join(work, "truncated-header.lib"), "rb").read()
|
||||
data = data[:meta["member_offsets"][0] + 20]
|
||||
open(os.path.join(work, "truncated-header.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "bad-index.lib"),
|
||||
[("defs.o", defs)])
|
||||
data = bytearray(open(os.path.join(work, "bad-index.lib"), "rb").read())
|
||||
index = meta["index_offset"] + 60
|
||||
struct.pack_into(">I", data, index + 4, 0xDEADBEEF)
|
||||
open(os.path.join(work, "bad-index.lib"), "wb").write(data)
|
||||
|
||||
meta = write_archive(os.path.join(work, "bad-longoffset.lib"),
|
||||
[("defs_with_a_long_member_name.o", defs)])
|
||||
data = bytearray(
|
||||
open(os.path.join(work, "bad-longoffset.lib"), "rb").read())
|
||||
header = meta["member_offsets"][0]
|
||||
data[header:header + 16] = b"/9999".ljust(16, b" ")
|
||||
open(os.path.join(work, "bad-longoffset.lib"), "wb").write(data)
|
||||
print("archive fixtures written")
|
||||
|
||||
|
||||
def archive_basic(work):
|
||||
refs = read_object(os.path.join(work, "refs.o"))
|
||||
archive = read_archive(os.path.join(work, "basic.lib"))
|
||||
defs_member = next(m for m in archive.members if m.name == "defs.o")
|
||||
cinit_member = next(m for m in archive.members
|
||||
if m.name == "unused-cinit.obj")
|
||||
defs = read_object(data=defs_member.data, label="<basic defs.o>")
|
||||
out = read_object(os.path.join(work, "basic.out"), relocatable=False)
|
||||
|
||||
check([s.name for s in out.sections] == [".text", ".data", ".bss"],
|
||||
"archive output sections %r" % [s.name for s in out.sections])
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"archive output still has relocations")
|
||||
text = (refs.section_by_name[".text"].size +
|
||||
defs.section_by_name[".text"].size)
|
||||
data_size = (refs.section_by_name[".data"].size +
|
||||
defs.section_by_name[".data"].size)
|
||||
check(out.sections[0].size == text,
|
||||
".text size %d includes a member that was not needed (want %d)"
|
||||
% (out.sections[0].size, text))
|
||||
check(out.sections[1].size == data_size, ".data size")
|
||||
check(cinit_member.size > 0, "fixture member is empty")
|
||||
names = {sym.name for sym in out.symbols}
|
||||
for name in ("_start", "_shared_fn", "_shared_data",
|
||||
"_this_is_a_very_long_public_symbol_name"):
|
||||
check(name in names, "archive link lost symbol %s" % name)
|
||||
check("_cinit_get" not in names,
|
||||
"an unused archive member was extracted")
|
||||
print(" archive basic: .text=%d bits, unused member left out"
|
||||
% out.sections[0].size)
|
||||
|
||||
|
||||
def archive_long(work):
|
||||
out = read_object(os.path.join(work, "longnames.out"),
|
||||
relocatable=False)
|
||||
names = {sym.name for sym in out.symbols}
|
||||
check("_shared_fn" in names, "long-name archive member was not linked")
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"long-name archive output has relocations")
|
||||
print(" archive long name: linked %d sections"
|
||||
% len(out.sections))
|
||||
|
||||
|
||||
def _check_defs_only(out, work, archive_name, refs_name="refs.o"):
|
||||
"""The defs member is extracted; the unused cinit member is not."""
|
||||
archive = read_archive(os.path.join(work, archive_name))
|
||||
check(archive.symbols is None,
|
||||
"%s should have no usable / index" % archive_name)
|
||||
refs = read_object(os.path.join(work, refs_name))
|
||||
defs_member = next(m for m in archive.members if m.name == "defs.o")
|
||||
defs = read_object(data=defs_member.data, label="<%s defs.o>"
|
||||
% archive_name)
|
||||
text = (refs.section_by_name[".text"].size +
|
||||
defs.section_by_name[".text"].size)
|
||||
data_size = (refs.section_by_name[".data"].size +
|
||||
defs.section_by_name[".data"].size)
|
||||
check(out.sections[0].size == text,
|
||||
"%s .text size %d extracted an unneeded member (want %d)"
|
||||
% (archive_name, out.sections[0].size, text))
|
||||
check(out.sections[1].size == data_size, "%s .data size" % archive_name)
|
||||
names = {sym.name for sym in out.symbols}
|
||||
check("_shared_fn" in names, "%s did not link defs.o" % archive_name)
|
||||
check("_cinit_get" not in names,
|
||||
"%s extracted the unused cinit member" % archive_name)
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"%s output has relocations" % archive_name)
|
||||
|
||||
|
||||
def archive_noindex(work):
|
||||
out = read_object(os.path.join(work, "noindex.out"),
|
||||
relocatable=False)
|
||||
_check_defs_only(out, work, "basic-noindex.lib")
|
||||
print(" archive without / index: defs linked, unused member excluded")
|
||||
|
||||
|
||||
def archive_emptyindex(work):
|
||||
out = read_object(os.path.join(work, "emptyindex.out"),
|
||||
relocatable=False)
|
||||
_check_defs_only(out, work, "emptyindex.lib")
|
||||
print(" empty / index treated as absent: defs linked, unused excluded")
|
||||
|
||||
|
||||
def archive_dupnamed(work):
|
||||
archive = read_archive(os.path.join(work, "dupnamed.lib"))
|
||||
members = [read_object(data=m.data, label="dup.o@%#x" % m.offset)
|
||||
for m in archive.members]
|
||||
defs = next(o for o in members
|
||||
if any(s.name == "_shared_fn" for s in o.symbols))
|
||||
cinit = next(o for o in members
|
||||
if any(s.name == "_cinit_get" for s in o.symbols))
|
||||
refs = read_object(os.path.join(work, "refs.o"))
|
||||
cinitref = read_object(os.path.join(work, "cinitref.o"))
|
||||
objects = [refs, cinitref, defs, cinit]
|
||||
out = read_object(os.path.join(work, "dupnamed.out"),
|
||||
relocatable=False)
|
||||
|
||||
paddr = out_paddrs(objects)
|
||||
place = placements(objects)
|
||||
globals_ = collect_globals(objects)
|
||||
sizes = {name: sum(o.section_by_name[name].size for o in objects
|
||||
if name in o.section_by_name)
|
||||
for name in (".text", ".data", ".cinit", ".bss")}
|
||||
check(out.sections[0].size == sizes[".text"], "dupnamed .text size")
|
||||
check(out.sections[1].size == sizes[".data"], "dupnamed .data size")
|
||||
check(out.sections[2].size == sizes[".cinit"], "dupnamed .cinit size")
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"dupnamed output has relocations")
|
||||
|
||||
out_globals = {s.name: s.value for s in out.symbols
|
||||
if s.sclass == C_EXT and s.secno > 0}
|
||||
for name in ("_shared_fn", "_shared_data", "_cinit_get", "_cinit_target"):
|
||||
dobj, dsym = globals_[name]
|
||||
want = definition_bits(dobj, dsym, paddr, place)
|
||||
check(out_globals.get(name) == want,
|
||||
"dupnamed %s value %r, want %#x"
|
||||
% (name, out_globals.get(name), want))
|
||||
check(out_globals["_shared_fn"] != out_globals["_cinit_get"],
|
||||
"same-named members resolved into the same address range")
|
||||
print(" duplicate member names: _shared_fn=%#x _cinit_get=%#x"
|
||||
% (out_globals["_shared_fn"], out_globals["_cinit_get"]))
|
||||
|
||||
|
||||
def archive_flib(work, flib_path):
|
||||
archive = read_archive(flib_path)
|
||||
wanted = ("fd_add.obj", "fd_error.obj")
|
||||
members = {m.name: read_object(data=m.data, label=m.name)
|
||||
for m in archive.members if m.name in wanted}
|
||||
check(set(members) == set(wanted),
|
||||
"flib archive members %r missing" % (set(wanted) - set(members)))
|
||||
out = read_object(os.path.join(work, "flib.out"), relocatable=False)
|
||||
text = (members["fd_add.obj"].section_by_name[".text"].size +
|
||||
members["fd_error.obj"].section_by_name[".text"].size)
|
||||
check(out.sections[0].size > text,
|
||||
"flib .text does not include the explicit object")
|
||||
names = {sym.name for sym in out.symbols}
|
||||
for name in ("_start", "FD$ADD", "FD$SUB", "FD$SUB_R", "_fp_error"):
|
||||
check(name in names, "flib link lost %s" % name)
|
||||
for name in ("FD$MUL", "FD$NEG", "FD$DIV", "FD$DTOI", "FD$DTOF"):
|
||||
check(name not in names,
|
||||
"flib link extracted an unrelated member for %s" % name)
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"flib output has relocations")
|
||||
opt = out.opt
|
||||
check(opt is not None and opt[0] == 0x0108 and opt[1] == 199,
|
||||
"flib output optional header is wrong")
|
||||
print(" archive flib: FD$ADD + _fp_error extracted from %s"
|
||||
% os.path.basename(flib_path))
|
||||
|
||||
|
||||
def placements(objects):
|
||||
"""(id(obj), section name) -> bit offset in the concatenated output."""
|
||||
out = {}
|
||||
@@ -45,12 +429,16 @@ def placements(objects):
|
||||
continue
|
||||
out[(id(obj), name)] = off
|
||||
off += sec.size
|
||||
# Debug sections are copied one-for-one into section-relative output
|
||||
# sections; only one debug-bearing object is supported in M7.2.
|
||||
# Debug sections are concatenated in object order too; the single-object
|
||||
# base is 0, which keeps the M7 single-TU output section-relative.
|
||||
debug_off = {}
|
||||
for obj in objects:
|
||||
for sec in obj.sections:
|
||||
if sec.is_debug:
|
||||
out[(id(obj), sec.name)] = 0
|
||||
if not sec.is_debug:
|
||||
continue
|
||||
off = debug_off.get(sec.name, 0)
|
||||
out[(id(obj), sec.name)] = off
|
||||
debug_off[sec.name] = off + sec.size
|
||||
return out
|
||||
|
||||
|
||||
@@ -89,7 +477,7 @@ def definition_bits(obj, sym, paddr, place):
|
||||
|
||||
|
||||
def expected_alloc_value(obj, sec, rel, paddr, place, globals_):
|
||||
addend = u32(sec.data, rel.raddr // 8)
|
||||
addend = s32(sec.data, rel.raddr // 8)
|
||||
if rel.symidx == 0xFFFF:
|
||||
return paddr[sec.name] + place[(id(obj), sec.name)] + addend
|
||||
sym = obj.symbols_by_index[rel.symidx]
|
||||
@@ -106,21 +494,26 @@ def expected_alloc_value(obj, sec, rel, paddr, place, globals_):
|
||||
|
||||
|
||||
def expected_debug_value(obj, sec, rel, paddr, place, globals_):
|
||||
addend = u32(sec.data, rel.raddr // 8)
|
||||
addend = s32(sec.data, rel.raddr // 8)
|
||||
base = place[(id(obj), sec.name)] // 8
|
||||
if rel.symidx == 0xFFFF:
|
||||
return addend
|
||||
return base + addend
|
||||
sym = obj.symbols_by_index[rel.symidx]
|
||||
if sym.is_section:
|
||||
tsec = obj.section_by_no[sym.secno]
|
||||
if tsec.is_debug:
|
||||
return addend
|
||||
check(sym.value % 8 == 0,
|
||||
"debug target symbol is not byte aligned")
|
||||
return place[(id(obj), tsec.name)] // 8 + sym.value // 8 + addend
|
||||
bits = paddr[tsec.name] + place[(id(obj), tsec.name)]
|
||||
check(bits % 8 == 0, "debug target section is not byte aligned")
|
||||
return bits // 8 + addend
|
||||
if sym.is_defined:
|
||||
tsec = obj.section_by_no[sym.secno]
|
||||
if tsec.is_debug:
|
||||
return addend
|
||||
check(sym.value % 8 == 0,
|
||||
"debug target symbol is not byte aligned")
|
||||
return place[(id(obj), tsec.name)] // 8 + sym.value // 8 + addend
|
||||
bits = definition_bits(obj, sym, paddr, place)
|
||||
check(bits % 8 == 0, "debug target symbol is not byte aligned")
|
||||
return bits // 8 + addend
|
||||
@@ -130,7 +523,8 @@ def expected_debug_value(obj, sec, rel, paddr, place, globals_):
|
||||
dobj, dsym = globals_[sym.name]
|
||||
tsec = dobj.section_by_no[dsym.secno]
|
||||
if tsec.is_debug:
|
||||
return addend
|
||||
check(dsym.value % 8 == 0, "debug external is not byte aligned")
|
||||
return place[(id(dobj), tsec.name)] // 8 + dsym.value // 8 + addend
|
||||
bits = definition_bits(dobj, dsym, paddr, place)
|
||||
check(bits % 8 == 0, "debug external is not byte aligned")
|
||||
return bits // 8 + addend
|
||||
@@ -323,6 +717,76 @@ def debug(work):
|
||||
% (len(out.sections), u32(addr, 8), u32(addr, 12)))
|
||||
|
||||
|
||||
def debug_multi(work):
|
||||
"""Two debug-bearing objects: concat sections, rehome every reference."""
|
||||
objects = read_inputs(work, ["debug.o", "debug-other.o"])
|
||||
out = read_object(os.path.join(work, "debug.multi.o"), relocatable=False)
|
||||
debug_names = []
|
||||
for obj in objects:
|
||||
for sec in obj.sections:
|
||||
if sec.is_debug and sec.name not in debug_names:
|
||||
debug_names.append(sec.name)
|
||||
want = [".text", ".data", ".bss"] + debug_names
|
||||
check([s.name for s in out.sections] == want,
|
||||
"merged debug sections %r, want %r"
|
||||
% ([s.name for s in out.sections], want))
|
||||
for name in debug_names:
|
||||
want_size = sum(o.section_by_name[name].size for o in objects
|
||||
if name in o.section_by_name)
|
||||
got = out.section_by_name[name].size
|
||||
check(got == want_size,
|
||||
"%s merged size %d, want %d" % (name, got, want_size))
|
||||
sec = out.section_by_name[name]
|
||||
check(sec.paddr == 0 and sec.vaddr == 0 and sec.flags == 0,
|
||||
"%s merged paddr/vaddr/flags are not 0/0/0" % name)
|
||||
check(sec.nreloc == 0, "%s still has relocations" % name)
|
||||
|
||||
paddr = out_paddrs(objects)
|
||||
place = placements(objects)
|
||||
globals_ = collect_globals(objects)
|
||||
outdata = {s.name: s.data for s in out.sections}
|
||||
for obj in objects:
|
||||
for sec in obj.sections:
|
||||
if not sec.is_debug:
|
||||
continue
|
||||
for rel in sec.relocs:
|
||||
wantv = expected_debug_value(obj, sec, rel, paddr, place,
|
||||
globals_)
|
||||
off = place[(id(obj), sec.name)] // 8 + rel.raddr // 8
|
||||
got = u32(outdata[sec.name], off)
|
||||
check(got == wantv,
|
||||
"%s %s+%#x: got %#x, want %#x"
|
||||
% (obj.path, sec.name, rel.raddr, got, wantv))
|
||||
|
||||
second = objects[1]
|
||||
abbrev_base = place[(id(second), ".debug_abbrev")] // 8
|
||||
info_base = place[(id(second), ".debug_info")] // 8
|
||||
check(abbrev_base > 0, "second object has no merged abbreviation base")
|
||||
check(u32(outdata[".debug_info"], info_base + 8) == abbrev_base,
|
||||
"second CU abbrev offset %#x, want %#x"
|
||||
% (u32(outdata[".debug_info"], info_base + 8), abbrev_base))
|
||||
check(u32(outdata[".debug_info"], 8) == 0,
|
||||
"first CU abbrev offset is not 0")
|
||||
# The first CU's .debug_str_offsets/.debug_addr bases are their object
|
||||
# bases + the 8-byte unit header; the second CU's are shifted by the first
|
||||
# object's contribution. The relocation loop above already checks these
|
||||
# values, so just show the second CU is not at 0.
|
||||
second_str = place[(id(second), ".debug_str_offsets")] // 8
|
||||
check(second_str > 0, "second object's .debug_str_offsets base is 0")
|
||||
print(" debug merge: %d debug sections, second CU abbrev=%#x "
|
||||
"str_offsets=%#x" % (len(debug_names), abbrev_base, second_str))
|
||||
|
||||
stripped = read_object(os.path.join(work, "debug.multi.strip.o"),
|
||||
relocatable=False)
|
||||
check([s.name for s in stripped.sections] == [".text", ".data", ".bss"],
|
||||
"two-debug-object strip link has sections %r"
|
||||
% [s.name for s in stripped.sections])
|
||||
check(all(s.nreloc == 0 for s in stripped.sections),
|
||||
"two-debug-object strip output has relocations")
|
||||
print(" debug merge strip: sections %r"
|
||||
% [s.name for s in stripped.sections])
|
||||
|
||||
|
||||
def explicit_layout(work):
|
||||
out = read_object(os.path.join(work, "explicit.o"), relocatable=False)
|
||||
got = {s.name: s.paddr for s in out.sections}
|
||||
@@ -335,6 +799,106 @@ def explicit_layout(work):
|
||||
% (got[".text"], got[".data"], got[".cinit"], got[".bss"]))
|
||||
|
||||
|
||||
def write_minimal_object(path, sections):
|
||||
"""Write a TI-COFF object with the given (name, flags, bytes) sections."""
|
||||
names = [name for name, _flags, _blob in sections]
|
||||
string_table = bytearray(b"\0\0\0\0")
|
||||
name_offsets = {}
|
||||
for name in names:
|
||||
if len(name) > 8:
|
||||
name_offsets[name] = len(string_table)
|
||||
string_table.extend(name.encode("latin1") + b"\0")
|
||||
struct.pack_into("<I", string_table, 0, len(string_table))
|
||||
header_size = 20 + 40 * len(sections)
|
||||
cursor = header_size
|
||||
pointers = []
|
||||
for name, _flags, blob in sections:
|
||||
if blob:
|
||||
pointers.append(cursor)
|
||||
cursor += len(blob)
|
||||
else:
|
||||
pointers.append(0)
|
||||
symptr = cursor
|
||||
cursor += 18 + len(string_table)
|
||||
out = bytearray(struct.pack("<HHIIIHH", 0x0090, len(sections), 0,
|
||||
symptr, 1, 0, 0))
|
||||
for (name, flags, blob), ptr in zip(sections, pointers):
|
||||
if name in name_offsets:
|
||||
raw_name = ("/%d" % name_offsets[name]).encode("ascii")
|
||||
else:
|
||||
raw_name = name.encode("latin1")
|
||||
size = len(blob) * 8
|
||||
scnptr = ptr if name != ".bss" else 0
|
||||
out.extend(raw_name.ljust(8, b"\0"))
|
||||
out.extend(struct.pack("<IIIIIIHHI", 0, 0, size, scnptr, 0, 0,
|
||||
0, 0, flags))
|
||||
for _name, _flags, blob in sections:
|
||||
out.extend(blob)
|
||||
# One local symbol so the reader keeps the string table.
|
||||
out.extend(b"dummy\0\0\0" + struct.pack("<IhHBB", 0, 0, 0, 0, 0))
|
||||
out.extend(string_table)
|
||||
check(len(out) == cursor, "minimal fixture size mismatch %d != %d"
|
||||
% (len(out), cursor))
|
||||
with open(path, "wb") as fh:
|
||||
fh.write(out)
|
||||
|
||||
|
||||
def make_raw_debug(work):
|
||||
"""Write two minimal objects with a raw (non-relocated) CU abbrev
|
||||
offset."""
|
||||
def sections(abbrev):
|
||||
return [
|
||||
(".text", 0x20, b""),
|
||||
(".data", 0x40, b""),
|
||||
(".bss", 0x80, b""),
|
||||
(".debug_abbrev", 0x00, abbrev),
|
||||
(".debug_info", 0x00,
|
||||
struct.pack("<I", 9) + struct.pack("<HBB", 5, 1, 4) +
|
||||
struct.pack("<I", 0) + b"\0"),
|
||||
]
|
||||
|
||||
write_minimal_object(os.path.join(work, "raw-debug-a.o"),
|
||||
sections(b"\x01\x11\x01\x00\x00\x00"))
|
||||
write_minimal_object(os.path.join(work, "raw-debug-b.o"),
|
||||
sections(b"\x02\x11\x01\x00\x00\x00"))
|
||||
|
||||
|
||||
def make_bad_debug(work, mode):
|
||||
"""Write a second debug object with an intentionally unsupported shape."""
|
||||
base = [(".text", 0x20, b""), (".data", 0x40, b""),
|
||||
(".bss", 0x80, b"")]
|
||||
if mode == "unknown":
|
||||
extra = [(".debug_weird", 0x00, b"\0\0\0\0")]
|
||||
elif mode == "dwarf64":
|
||||
extra = [(".debug_info", 0x00,
|
||||
struct.pack("<I", 0xFFFFFFFF) + b"\0" * 8)]
|
||||
elif mode == "strnul":
|
||||
extra = [(".debug_str", 0x00, b"no-terminator")]
|
||||
else:
|
||||
fail("unknown bad-debug mode %s" % mode)
|
||||
write_minimal_object(os.path.join(work, "bad-debug-%s.o" % mode),
|
||||
base + extra)
|
||||
|
||||
|
||||
def raw_debug(work):
|
||||
out = read_object(os.path.join(work, "raw-debug.out"),
|
||||
relocatable=False)
|
||||
info = out.section_by_name[".debug_info"]
|
||||
abbrev = out.section_by_name[".debug_abbrev"]
|
||||
check(abbrev.size == (6 + 6) * 8,
|
||||
"raw-debug merged .debug_abbrev size %d" % abbrev.size)
|
||||
check(info.size == 13 * 2 * 8, "raw-debug merged .debug_info size %d"
|
||||
% info.size)
|
||||
data = info.data
|
||||
check(u32(data, 8) == 0, "first raw CU abbrev offset %#x, want 0"
|
||||
% u32(data, 8))
|
||||
check(u32(data, 13 + 8) == 6,
|
||||
"second raw CU abbrev offset %#x, want 6 (first .debug_abbrev size)"
|
||||
% u32(data, 13 + 8))
|
||||
print(" raw CU abbrev offsets: %#x, %#x (merged base applied)"
|
||||
% (u32(data, 8), u32(data, 13 + 8)))
|
||||
|
||||
|
||||
def make_empty_cinit(work):
|
||||
"""Write a minimal 4-section input with a listed-but-empty .cinit."""
|
||||
path = os.path.join(work, "empty-cinit.o")
|
||||
@@ -370,6 +934,50 @@ def empty_cinit(work):
|
||||
% [s.name for s in out.sections])
|
||||
|
||||
|
||||
def libflags(work):
|
||||
"""1990 metadata section bits are accepted; output stays classic."""
|
||||
obj = read_object(os.path.join(work, "patched-libflags.o"))
|
||||
check(obj.section_by_name[".text"].flags == 0x420,
|
||||
"libflags fixture .text flags are not 0x420")
|
||||
check(obj.section_by_name[".bss"].flags == 0x580,
|
||||
"libflags fixture .bss flags are not 0x580")
|
||||
out = read_object(os.path.join(work, "libflags.out"), relocatable=False)
|
||||
want = {".text": 0x20, ".data": 0x40, ".bss": 0x80}
|
||||
for sec in out.sections:
|
||||
check(sec.flags == want[sec.name],
|
||||
"%s output flags %#x, want %#x"
|
||||
% (sec.name, sec.flags, want[sec.name]))
|
||||
check(sec.nreloc == 0, "%s output has relocations" % sec.name)
|
||||
print(" library section flags 0x420/0x580 accepted")
|
||||
|
||||
|
||||
def negaddend(work):
|
||||
"""A two's-complement negative relocation addend is applied signed."""
|
||||
defs = read_object(os.path.join(work, "defs.o"))
|
||||
patched = read_object(os.path.join(work, "patched-negaddend.o"))
|
||||
out = read_object(os.path.join(work, "negaddend.out"), relocatable=False)
|
||||
objects = [defs, patched]
|
||||
paddr = out_paddrs(objects)
|
||||
place = placements(objects)
|
||||
globals_ = collect_globals(objects)
|
||||
|
||||
sec = patched.section_by_name[".text"]
|
||||
check(sec.relocs, "negaddend fixture has no .text relocation")
|
||||
rel = sec.relocs[0]
|
||||
addend = s32(sec.data, rel.raddr // 8)
|
||||
check(addend == -8, "patched addend is %d, want -8" % addend)
|
||||
sym = patched.symbols_by_index[rel.symidx]
|
||||
dobj, dsym = globals_[sym.name]
|
||||
want = definition_bits(dobj, dsym, paddr, place) + addend
|
||||
off = place[(id(patched), ".text")] // 8 + rel.raddr // 8
|
||||
got = u32(out.section_by_name[".text"].data, off)
|
||||
check(got == want, "signed addend: got %#x, want %#x" % (got, want))
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"negaddend output has relocations")
|
||||
print(" signed addend: %s%+d -> %#08X"
|
||||
% (sym.name, addend, got))
|
||||
|
||||
|
||||
def patch(work, mode):
|
||||
src = os.path.join(work, "refs.o")
|
||||
dst = os.path.join(work, "patched-%s.o" % mode)
|
||||
@@ -397,6 +1005,20 @@ def patch(work, mode):
|
||||
off = next(o for n, o in targets if n == ".text")
|
||||
size = struct.unpack_from("<I", data, off + 16)[0]
|
||||
struct.pack_into("<I", data, off + 16, size + 8)
|
||||
elif mode == "libflags":
|
||||
# The 1990 tools set metadata bits 0x100/0x400 on allocated sections.
|
||||
off = next(o for n, o in targets if n == ".text")
|
||||
struct.pack_into("<I", data, off + 36, 0x420)
|
||||
off = next(o for n, o in targets if n == ".bss")
|
||||
struct.pack_into("<I", data, off + 36, 0x580)
|
||||
elif mode == "negaddend":
|
||||
off = next(o for n, o in targets if n == ".text")
|
||||
scnptr = struct.unpack_from("<I", data, off + 20)[0]
|
||||
relptr = struct.unpack_from("<I", data, off + 24)[0]
|
||||
nreloc = struct.unpack_from("<H", data, off + 32)[0]
|
||||
check(nreloc > 0, "patch negaddend: .text has no relocation")
|
||||
raddr = struct.unpack_from("<I", data, relptr)[0]
|
||||
struct.pack_into("<I", data, scnptr + raddr // 8, 0xFFFFFFF8)
|
||||
elif mode == "strtab":
|
||||
symptr, nsyms = struct.unpack_from("<II", data, 8)
|
||||
i = 0
|
||||
@@ -426,12 +1048,38 @@ def main(argv):
|
||||
positive(work)
|
||||
elif mode == "debug":
|
||||
debug(work)
|
||||
elif mode == "debug-multi":
|
||||
debug_multi(work)
|
||||
elif mode == "layout":
|
||||
explicit_layout(work)
|
||||
elif mode == "make-empty-cinit":
|
||||
make_empty_cinit(work)
|
||||
elif mode == "make-raw-debug":
|
||||
make_raw_debug(work)
|
||||
elif mode == "make-bad-debug":
|
||||
make_bad_debug(work, argv[3])
|
||||
elif mode == "raw-debug":
|
||||
raw_debug(work)
|
||||
elif mode == "emptycinit":
|
||||
empty_cinit(work)
|
||||
elif mode == "make-archive":
|
||||
make_archive(work)
|
||||
elif mode == "archive-basic":
|
||||
archive_basic(work)
|
||||
elif mode == "archive-long":
|
||||
archive_long(work)
|
||||
elif mode == "archive-noindex":
|
||||
archive_noindex(work)
|
||||
elif mode == "archive-emptyindex":
|
||||
archive_emptyindex(work)
|
||||
elif mode == "archive-dupnamed":
|
||||
archive_dupnamed(work)
|
||||
elif mode == "archive-flib":
|
||||
archive_flib(work, argv[3])
|
||||
elif mode == "negaddend":
|
||||
negaddend(work)
|
||||
elif mode == "libflags":
|
||||
libflags(work)
|
||||
elif mode == "patch":
|
||||
patch(work, argv[3])
|
||||
else:
|
||||
|
||||
+171
-6
@@ -1,10 +1,17 @@
|
||||
#!/bin/sh
|
||||
# tms-link unit gate: layout, symbol resolution, R-RELLONG math, .cinit
|
||||
# placement, long public names, debug strip/keep, map, and loud failures.
|
||||
# placement, long public names, debug strip/keep, map, archive extraction,
|
||||
# and loud failures.
|
||||
#
|
||||
# tools/tms-link/tests/run.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_LINK_WORK
|
||||
# The synthetic archive fixtures are hermetic. The real-LIB case is optional:
|
||||
# it uses build/m4-sdk/FLIB.LIB by default (override FLIB_LIB=... or M4_SDK=...)
|
||||
# and prints a skip reason when that library is absent. To produce it, run
|
||||
# scripts/m4/run.sh once (it extracts the 1987 SDK image), or
|
||||
# scripts/m6/flib-extract.sh for the 1990 build/m6-sdk/flib.lib.
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_LINK_WORK FLIB_LIB M4_SDK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
@@ -12,6 +19,8 @@ DIR=$ROOT/tools/tms-link/tests
|
||||
TMS_LINK=$ROOT/tools/tms-link/tms-link
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
M4_SDK=${M4_SDK:-$ROOT/build/m4-sdk}
|
||||
FLIB=${FLIB_LIB:-$M4_SDK/FLIB.LIB}
|
||||
WORK=${TMS_LINK_WORK:-$ROOT/build/tms-link-tests}
|
||||
|
||||
fail() {
|
||||
@@ -21,12 +30,14 @@ fail() {
|
||||
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
HAVE_FLIB=1
|
||||
[ -f "$FLIB" ] || HAVE_FLIB=0
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
echo "== build llc TI-COFF fixtures"
|
||||
for fixture in defs refs cinit debug; do
|
||||
for fixture in defs refs cinit cinitref debug flib; do
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$DIR/fixtures/$fixture.ll" -o "$WORK/$fixture.o" \
|
||||
|| fail "llc failed for $fixture.ll"
|
||||
@@ -39,6 +50,73 @@ echo "== positive link: two TUs, .cinit, long name, map"
|
||||
python3 "$DIR/linktest.py" positive "$WORK" \
|
||||
|| fail "positive assertions failed"
|
||||
|
||||
echo "== archives: selective extraction to a fixpoint"
|
||||
python3 "$DIR/linktest.py" make-archive "$WORK" >/dev/null \
|
||||
|| fail "could not write archive fixtures"
|
||||
"$TMS_LINK" -o "$WORK/basic.out" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/basic.lib" \
|
||||
|| fail "archive link failed"
|
||||
python3 "$DIR/linktest.py" archive-basic "$WORK" \
|
||||
|| fail "archive assertions failed"
|
||||
|
||||
"$TMS_LINK" -o "$WORK/mixed.out" --entry _start \
|
||||
"$WORK/basic.lib" "$WORK/refs.o" \
|
||||
|| fail "archive-before-object link failed"
|
||||
cmp -s "$WORK/basic.out" "$WORK/mixed.out" \
|
||||
|| fail "archive position changed the linked image"
|
||||
|
||||
"$TMS_LINK" -o "$WORK/libflag.out" --entry _start -L "$WORK" -l basic \
|
||||
"$WORK/refs.o" \
|
||||
|| fail "-l LIB link failed"
|
||||
"$TMS_LINK" -o "$WORK/libflag2.out" --entry _start -L "$WORK" -lbasic \
|
||||
"$WORK/refs.o" \
|
||||
|| fail "-lLIB link failed"
|
||||
cmp -s "$WORK/basic.out" "$WORK/libflag.out" \
|
||||
|| fail "-l LIB changed the linked image"
|
||||
cmp -s "$WORK/basic.out" "$WORK/libflag2.out" \
|
||||
|| fail "-lLIB changed the linked image"
|
||||
|
||||
"$TMS_LINK" -o "$WORK/noindex.out" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/basic-noindex.lib" \
|
||||
|| fail "archive without a / index failed"
|
||||
python3 "$DIR/linktest.py" archive-noindex "$WORK" \
|
||||
|| fail "no-index archive assertions failed"
|
||||
|
||||
"$TMS_LINK" -o "$WORK/emptyindex.out" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/emptyindex.lib" \
|
||||
|| fail "archive with an empty / index failed"
|
||||
python3 "$DIR/linktest.py" archive-emptyindex "$WORK" \
|
||||
|| fail "empty-index archive assertions failed"
|
||||
|
||||
"$TMS_LINK" -o "$WORK/dupnamed.out" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/cinitref.o" "$WORK/dupnamed.lib" \
|
||||
|| fail "duplicate member-name archive failed"
|
||||
python3 "$DIR/linktest.py" archive-dupnamed "$WORK" \
|
||||
|| fail "duplicate member-name assertions failed"
|
||||
|
||||
"$TMS_LINK" -o "$WORK/longnames.out" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/longnames.lib" \
|
||||
|| fail "long-member-name archive failed"
|
||||
python3 "$DIR/linktest.py" archive-long "$WORK" \
|
||||
|| fail "long-name archive assertions failed"
|
||||
|
||||
if [ "$HAVE_FLIB" = 1 ]; then
|
||||
echo "== archives: real flib.lib member extraction"
|
||||
"$TMS_LINK" -o "$WORK/flib.out" --map "$WORK/flib.map" \
|
||||
--entry _start "$WORK/flib.o" "$FLIB" \
|
||||
|| fail "flib archive link failed"
|
||||
python3 "$DIR/linktest.py" archive-flib "$WORK" "$FLIB" \
|
||||
|| fail "flib archive assertions failed"
|
||||
"$TMS_LINK" -o "$WORK/flib-before.out" --entry _start \
|
||||
"$FLIB" "$WORK/flib.o" \
|
||||
|| fail "flib-before-object link failed"
|
||||
cmp -s "$WORK/flib.out" "$WORK/flib-before.out" \
|
||||
|| fail "flib archive position changed the linked image"
|
||||
else
|
||||
echo "== archives: SKIP real flib.lib (missing $FLIB; set" \
|
||||
"FLIB_LIB=... or M4_SDK=... and run scripts/m4/run.sh once)"
|
||||
fi
|
||||
|
||||
echo "== explicit layout origins and region bounds"
|
||||
"$TMS_LINK" -o "$WORK/explicit.o" --map "$WORK/explicit.map" \
|
||||
--entry _start --text 018A0000 --data 018A0800 --cinit 018A0A00 \
|
||||
@@ -98,6 +176,65 @@ expect_fail regionoverlap "overlaps ram region" \
|
||||
"$TMS_LINK" -o "$WORK/regionoverlap.o" --prog-len 200000h \
|
||||
--ram-len 100h "$WORK/defs.o" "$WORK/refs.o"
|
||||
|
||||
echo "== loud archive failures"
|
||||
expect_fail archive-duplicate "duplicate definition of '_shared_" \
|
||||
"$TMS_LINK" -o "$WORK/archive-dup.o" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/duplicate.lib"
|
||||
grep -q 'first.obj' "$WORK/archive-duplicate.err" \
|
||||
|| fail "duplicate archive error does not name first.obj"
|
||||
grep -q 'second.obj' "$WORK/archive-duplicate.err" \
|
||||
|| fail "duplicate archive error does not name second.obj"
|
||||
expect_fail archive-undefined "undefined external '_shared_data'" \
|
||||
"$TMS_LINK" -o "$WORK/archive-undef.o" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/unused.lib"
|
||||
grep -q 'refs.o' "$WORK/archive-undefined.err" \
|
||||
|| fail "undefined archive error does not name the referencing object"
|
||||
|
||||
expect_fail badmagic "bad magic" \
|
||||
"$TMS_LINK" -o "$WORK/badmagic.o" "$WORK/bad-magic.lib"
|
||||
expect_fail badsize "non-decimal size" \
|
||||
"$TMS_LINK" -o "$WORK/badsize.o" "$WORK/bad-size.lib"
|
||||
expect_fail truncated "runs past EOF" \
|
||||
"$TMS_LINK" -o "$WORK/truncated.o" "$WORK/truncated.lib"
|
||||
expect_fail truncatedheader "truncated member header" \
|
||||
"$TMS_LINK" -o "$WORK/truncatedheader.o" \
|
||||
"$WORK/truncated-header.lib"
|
||||
expect_fail badindex "not a member header" \
|
||||
"$TMS_LINK" -o "$WORK/badindex.o" "$WORK/bad-index.lib"
|
||||
expect_fail badlong "outside the" \
|
||||
"$TMS_LINK" -o "$WORK/badlong.o" "$WORK/bad-longoffset.lib"
|
||||
expect_fail liarlib "symbol table says member defines" \
|
||||
"$TMS_LINK" -o "$WORK/liarlib.o" --entry _start \
|
||||
"$WORK/refs.o" "$WORK/liar.lib"
|
||||
expect_fail bsdname "BSD #1/" \
|
||||
"$TMS_LINK" -o "$WORK/bsdname.o" "$WORK/bsd.lib"
|
||||
expect_fail dupsymtab "duplicate archive symbol table" \
|
||||
"$TMS_LINK" -o "$WORK/dupsymtab.o" "$WORK/dupsymtab.lib"
|
||||
expect_fail duplong "duplicate archive long-name table" \
|
||||
"$TMS_LINK" -o "$WORK/duplong.o" "$WORK/duplong.lib"
|
||||
expect_fail unicodesize "non-decimal size" \
|
||||
"$TMS_LINK" -o "$WORK/unicodesize.o" "$WORK/unicode-size.lib"
|
||||
expect_fail badpad "bad padding byte" \
|
||||
"$TMS_LINK" -o "$WORK/badpad.o" "$WORK/bad-pad.lib"
|
||||
expect_fail missingpad "no padding byte at EOF" \
|
||||
"$TMS_LINK" -o "$WORK/missingpad.o" "$WORK/missing-pad.lib"
|
||||
expect_fail missinglib "cannot find library" \
|
||||
"$TMS_LINK" -o "$WORK/missinglib.o" -l no-such-library "$WORK/refs.o"
|
||||
|
||||
python3 "$DIR/linktest.py" patch "$WORK" negaddend >/dev/null
|
||||
"$TMS_LINK" -o "$WORK/negaddend.out" --entry _start \
|
||||
"$WORK/defs.o" "$WORK/patched-negaddend.o" \
|
||||
|| fail "signed-addend link failed"
|
||||
python3 "$DIR/linktest.py" negaddend "$WORK" \
|
||||
|| fail "signed-addend assertions failed"
|
||||
|
||||
python3 "$DIR/linktest.py" patch "$WORK" libflags >/dev/null
|
||||
"$TMS_LINK" -o "$WORK/libflags.out" --entry _start \
|
||||
"$WORK/defs.o" "$WORK/patched-libflags.o" \
|
||||
|| fail "1990 section-flag link failed"
|
||||
python3 "$DIR/linktest.py" libflags "$WORK" \
|
||||
|| fail "1990 section-flag assertions failed"
|
||||
|
||||
python3 "$DIR/linktest.py" patch "$WORK" strtab >/dev/null
|
||||
expect_fail strtab "inside the 4-byte size field" \
|
||||
"$TMS_LINK" -o "$WORK/strtab.o" "$WORK/defs.o" \
|
||||
@@ -121,8 +258,36 @@ sed -e 's/dbg_add/dbg_add_other/g' -e 's/dbg_sub/dbg_sub_other/g' \
|
||||
"$DIR/fixtures/debug.ll" > "$WORK/debug-other.ll"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj "$WORK/debug-other.ll" \
|
||||
-o "$WORK/debug-other.o" || fail "llc failed for debug-other.ll"
|
||||
expect_fail twodebug "one debug-bearing object" \
|
||||
"$TMS_LINK" -o "$WORK/twodebug.o" --keep-debug \
|
||||
"$WORK/debug.o" "$WORK/debug-other.o"
|
||||
|
||||
echo "== debug merge: two debug-bearing objects"
|
||||
"$TMS_LINK" -o "$WORK/debug.multi.o" --keep-debug \
|
||||
"$WORK/debug.o" "$WORK/debug-other.o" \
|
||||
|| fail "multi-object --keep-debug link failed"
|
||||
"$TMS_LINK" -o "$WORK/debug.multi.strip.o" \
|
||||
"$WORK/debug.o" "$WORK/debug-other.o" \
|
||||
|| fail "multi-object strip link failed"
|
||||
python3 "$DIR/linktest.py" debug-multi "$WORK" \
|
||||
|| fail "merged-debug assertions failed"
|
||||
|
||||
echo "== debug merge: raw CU debug_abbrev_offset is patched"
|
||||
python3 "$DIR/linktest.py" make-raw-debug "$WORK" >/dev/null
|
||||
"$TMS_LINK" -o "$WORK/raw-debug.out" --keep-debug \
|
||||
"$WORK/raw-debug-a.o" "$WORK/raw-debug-b.o" \
|
||||
|| fail "raw-abbrev debug link failed"
|
||||
python3 "$DIR/linktest.py" raw-debug "$WORK" \
|
||||
|| fail "raw-abbrev assertions failed"
|
||||
|
||||
echo "== debug merge: unsupported shapes fail loudly"
|
||||
for case in unknown dwarf64 strnul; do
|
||||
python3 "$DIR/linktest.py" make-bad-debug "$WORK" "$case" >/dev/null
|
||||
case $case in
|
||||
unknown) pattern="cannot merge debug section .debug_weird" ;;
|
||||
dwarf64) pattern="64-bit DWARF .debug_info" ;;
|
||||
strnul) pattern="does not end with NUL" ;;
|
||||
esac
|
||||
expect_fail "bad-debug-$case" "$pattern" \
|
||||
"$TMS_LINK" -o "$WORK/bad-debug-$case.out" --keep-debug \
|
||||
"$WORK/debug.o" "$WORK/bad-debug-$case.o"
|
||||
done
|
||||
|
||||
echo "tms-link tests: PASS"
|
||||
+410
-48
@@ -11,7 +11,21 @@ Usage:
|
||||
tms-link -o OUT [--map MAP] [--entry SYM]
|
||||
[--text ADDR] [--data ADDR] [--cinit ADDR] [--bss ADDR]
|
||||
[--prog-len BITS] [--ram-len BITS]
|
||||
[--keep-debug|--strip-debug] OBJ...
|
||||
[--keep-debug|--strip-debug] [-L DIR] [-l LIB] OBJ|LIB...
|
||||
|
||||
Inputs may be relocatable TI-COFF objects or System V ``ar`` archives
|
||||
(``!<arch>``) of such objects. Archive members are pulled in only when they
|
||||
define a symbol that is still undefined, iterating to a fixpoint; a member is
|
||||
never extracted twice. ``-l LIB`` searches ``.``, ``-L`` directories and the
|
||||
directories of the other inputs for ``LIB``, ``LIB.lib``, ``LIB.LIB`` or
|
||||
``libLIB.a``.
|
||||
|
||||
Ordering: all explicit positional objects are read first, in command order;
|
||||
archive members (from positional archives and ``-l`` libraries) are appended
|
||||
after them in extraction order. Archive position relative to objects therefore
|
||||
does not change the image.
|
||||
|
||||
TI-COFF relocation fields are signed 32-bit addends.
|
||||
|
||||
All addresses and section sizes are in BITS. Defaults:
|
||||
.text 018A0000
|
||||
@@ -22,10 +36,11 @@ All addresses and section sizes are in BITS. Defaults:
|
||||
``--prog-len``/``--ram-len`` optionally bound the prog (.text/.data/.cinit)
|
||||
and ram (.bss) regions in bits; overflow and region overlap are loud errors.
|
||||
|
||||
Debug sections are stripped by default. ``--keep-debug`` keeps the single
|
||||
debug-bearing object's ``.debug_*`` sections with their relocations resolved to
|
||||
byte addresses (the DWARF space). More than one debug-bearing object is loud in
|
||||
M7.2.
|
||||
Debug sections are stripped by default. ``--keep-debug`` keeps the
|
||||
``.debug_*`` sections from every debug-bearing object, concatenated in object
|
||||
order, with their section-relative offsets and relocations rehomed across the
|
||||
merged sections. A single debug-bearing object is copied byte-for-byte
|
||||
(placements start at 0), so the M7 single-TU output is unchanged.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -37,14 +52,34 @@ import sys
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from tmscoff import ( # noqa: E402
|
||||
C_EXT, C_FILE, C_STAT, SEC_ABS, CoffError, OutSection, OutSymbol,
|
||||
S_BSS, S_DATA, S_TEXT, align16, read_object, write_coff,
|
||||
Archive, C_EXT, C_FILE, C_STAT, SEC_ABS, CoffError, OutSection,
|
||||
OutSymbol, S_BSS, S_DATA, S_TEXT, align16, read_input, read_object,
|
||||
write_coff,
|
||||
)
|
||||
|
||||
DEFAULT_TEXT = 0x018A0000
|
||||
DEFAULT_BSS = 0x01A00000
|
||||
R_RELLONG = 0x11
|
||||
|
||||
# Debug sections that are safe to concatenate by appending one object's whole
|
||||
# contribution to the next. Each is a sequence of self-contained units (or a
|
||||
# plain NUL-terminated string pool), and every section-relative reference is
|
||||
# carried by a relocation or by the one raw field handled in
|
||||
# _patch_raw_debug_offsets (the CU header's debug_abbrev_offset). LLVM 23.1.5
|
||||
# `-g` objects use exactly these shapes; anything else is refused in a
|
||||
# multi-TU link rather than silently mis-merged.
|
||||
DEBUG_CONCAT_SECTIONS = frozenset((
|
||||
".debug_abbrev",
|
||||
".debug_info",
|
||||
".debug_str",
|
||||
".debug_str_offsets",
|
||||
".debug_addr",
|
||||
".debug_line",
|
||||
".debug_line_str",
|
||||
".debug_loclists",
|
||||
".debug_rnglists",
|
||||
))
|
||||
|
||||
|
||||
class LinkError(Exception):
|
||||
"""A loud link failure (bad input, layout, or unresolved symbol)."""
|
||||
@@ -65,8 +100,9 @@ def parse_addr(text):
|
||||
"invalid hexadecimal bit address %r" % text) from exc
|
||||
|
||||
|
||||
def _u32(data, offset):
|
||||
return struct.unpack_from("<I", data, offset)[0]
|
||||
def _s32(data, offset):
|
||||
"""A relocation addend field: two's-complement signed 32-bit."""
|
||||
return struct.unpack_from("<i", data, offset)[0]
|
||||
|
||||
|
||||
def _put_u32(data, offset, value):
|
||||
@@ -80,36 +116,210 @@ class Linker:
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.objects = []
|
||||
self.libraries = []
|
||||
self.global_defs = {}
|
||||
self.out_sections = []
|
||||
self.out_index = {}
|
||||
# (object path, section name) -> (OutSection, bit offset in it)
|
||||
self.placements = {}
|
||||
self._extracted = set() # (archive path, member offset)
|
||||
self._member_objects = {} # same key -> parsed ObjectFile
|
||||
|
||||
# -- loading ---------------------------------------------------------
|
||||
|
||||
def load(self):
|
||||
def _resolve_library(self, name):
|
||||
"""Resolve a -l argument to an existing archive path."""
|
||||
if os.path.isfile(name):
|
||||
return name
|
||||
candidates = [name]
|
||||
lower = name.lower()
|
||||
if not (lower.endswith(".lib") or lower.endswith(".a")):
|
||||
candidates.extend([name + ".lib", name + ".LIB",
|
||||
"lib" + name + ".a"])
|
||||
search = list(self.args.lib_dirs or [])
|
||||
search.append(".")
|
||||
for path in self.args.objects:
|
||||
directory = os.path.dirname(path)
|
||||
if directory and directory not in search:
|
||||
search.append(directory)
|
||||
for directory in search:
|
||||
for candidate in candidates:
|
||||
path = os.path.join(directory, candidate)
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
raise LinkError("cannot find library '%s' (searched %s)"
|
||||
% (name, ", ".join(search)))
|
||||
|
||||
def _input_paths(self):
|
||||
paths = list(self.args.objects)
|
||||
for lib in self.args.libraries:
|
||||
paths.append(self._resolve_library(lib))
|
||||
return paths
|
||||
|
||||
def load(self):
|
||||
for path in self._input_paths():
|
||||
try:
|
||||
obj = read_object(path)
|
||||
item = read_input(path)
|
||||
except CoffError as exc:
|
||||
raise LinkError(str(exc)) from exc
|
||||
self.objects.append(obj)
|
||||
if isinstance(item, Archive):
|
||||
self.libraries.append(item)
|
||||
else:
|
||||
self.objects.append(item)
|
||||
|
||||
def _collect_object_globals(self, obj):
|
||||
for sym in obj.symbols:
|
||||
if not sym.is_global or sym.is_section:
|
||||
continue
|
||||
if sym.secno > 0 or sym.is_absolute:
|
||||
if sym.name in self.global_defs:
|
||||
other_obj, other_sym = self.global_defs[sym.name]
|
||||
raise LinkError(
|
||||
"duplicate definition of '%s' in %s (record %d) "
|
||||
"and %s (record %d)"
|
||||
% (sym.name, other_obj.path, other_sym.index,
|
||||
obj.path, sym.index))
|
||||
self.global_defs[sym.name] = (obj, sym)
|
||||
|
||||
def _collect_globals(self):
|
||||
for obj in self.objects:
|
||||
self._collect_object_globals(obj)
|
||||
|
||||
# -- archive extraction ----------------------------------------------
|
||||
|
||||
def _undefined_names(self):
|
||||
"""Undefined external names in first-reference order."""
|
||||
seen = set()
|
||||
names = []
|
||||
for obj in self.objects:
|
||||
for sym in obj.symbols:
|
||||
if not sym.is_global or sym.is_section:
|
||||
continue
|
||||
if sym.secno > 0 or sym.is_absolute:
|
||||
if sym.name in self.global_defs:
|
||||
other_obj, other_sym = self.global_defs[sym.name]
|
||||
raise LinkError(
|
||||
"duplicate definition of '%s' in %s (record %d) "
|
||||
"and %s (record %d)"
|
||||
% (sym.name, other_obj.path, other_sym.index,
|
||||
obj.path, sym.index))
|
||||
self.global_defs[sym.name] = (obj, sym)
|
||||
if sym.is_defined or sym.is_absolute:
|
||||
continue
|
||||
if sym.name in self.global_defs or sym.name in seen:
|
||||
continue
|
||||
seen.add(sym.name)
|
||||
names.append(sym.name)
|
||||
return names
|
||||
|
||||
@staticmethod
|
||||
def _member_label(archive, member):
|
||||
# The offset makes labels unique even when an archive contains two
|
||||
# members with the same name; placement keys use this label.
|
||||
return "%s(%s@%#x)" % (archive.path, member.name, member.offset)
|
||||
|
||||
def _member_object(self, archive, member):
|
||||
key = (archive.path, member.offset)
|
||||
obj = self._member_objects.get(key)
|
||||
if obj is None:
|
||||
try:
|
||||
obj = read_object(data=member.data,
|
||||
label=self._member_label(archive, member))
|
||||
except CoffError as exc:
|
||||
raise LinkError(str(exc)) from exc
|
||||
self._member_objects[key] = obj
|
||||
return obj
|
||||
|
||||
@staticmethod
|
||||
def _defines(obj, name):
|
||||
for sym in obj.symbols:
|
||||
if (sym.name == name and sym.is_global and not sym.is_section and
|
||||
(sym.secno > 0 or sym.is_absolute)):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _archive_candidates(self, archive, name):
|
||||
if archive.symbols is not None:
|
||||
candidates = []
|
||||
seen = set()
|
||||
for member in archive.symbols.get(name, ()):
|
||||
if member.offset in seen:
|
||||
continue
|
||||
seen.add(member.offset)
|
||||
candidates.append(member)
|
||||
else:
|
||||
# A no-index archive has to be scanned member by member.
|
||||
candidates = []
|
||||
for member in archive.members:
|
||||
if self._defines(self._member_object(archive, member), name):
|
||||
candidates.append(member)
|
||||
if not candidates:
|
||||
return []
|
||||
# Validate the index before choosing, so a corrupt table is loud.
|
||||
for member in candidates:
|
||||
if not self._defines(self._member_object(archive, member), name):
|
||||
raise LinkError(
|
||||
"%s: symbol table says member defines '%s' but it does "
|
||||
"not" % (self._member_label(archive, member), name))
|
||||
return candidates
|
||||
|
||||
def _check_duplicate_candidates(self, archive, names):
|
||||
for name in names:
|
||||
candidates = self._archive_candidates(archive, name)
|
||||
if len(candidates) > 1:
|
||||
labels = ", ".join(self._member_label(archive, m)
|
||||
for m in candidates)
|
||||
raise LinkError("duplicate definition of '%s' in %s"
|
||||
% (name, labels))
|
||||
|
||||
def _process_archive(self, archive):
|
||||
"""Scan the archive in its index order, pulling needed members.
|
||||
|
||||
This is the GSPLNK 2.00 behaviour: the library's own symbol-table
|
||||
order (which is member order for the 1990 TI archives) drives the
|
||||
layout, not the caller's symbol-table order. A pass may add new
|
||||
undefined names; repeat until a pass extracts nothing.
|
||||
"""
|
||||
progress = False
|
||||
while True:
|
||||
extracted = False
|
||||
undefined = set(self._undefined_names())
|
||||
for member in archive.scan_members():
|
||||
key = (archive.path, member.offset)
|
||||
if key in self._extracted:
|
||||
continue
|
||||
if archive.symbols is not None:
|
||||
names = archive.member_symbols.get(member.offset, ())
|
||||
needed = [name for name in names if name in undefined]
|
||||
if not needed:
|
||||
continue
|
||||
obj = self._member_object(archive, member)
|
||||
for name in needed:
|
||||
if not self._defines(obj, name):
|
||||
raise LinkError(
|
||||
"%s: symbol table says member defines '%s' "
|
||||
"but it does not"
|
||||
% (self._member_label(archive, member), name))
|
||||
else:
|
||||
# No index: every member has to be inspected to learn
|
||||
# its definitions.
|
||||
obj = self._member_object(archive, member)
|
||||
needed = [name for name in self._undefined_names()
|
||||
if self._defines(obj, name)]
|
||||
if not needed:
|
||||
continue
|
||||
self._check_duplicate_candidates(archive, needed)
|
||||
self.objects.append(obj)
|
||||
self._extracted.add(key)
|
||||
self._collect_object_globals(obj)
|
||||
extracted = True
|
||||
progress = True
|
||||
undefined = set(self._undefined_names())
|
||||
if not extracted:
|
||||
return progress
|
||||
|
||||
def _extract_archive_members(self):
|
||||
for archive in self.libraries:
|
||||
self._process_archive(archive)
|
||||
# Backward references between libraries (and references discovered
|
||||
# after a later archive was scanned) still reach a fixpoint.
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for archive in self.libraries:
|
||||
if self._process_archive(archive):
|
||||
changed = True
|
||||
|
||||
# -- layout ----------------------------------------------------------
|
||||
|
||||
@@ -205,14 +415,12 @@ class Linker:
|
||||
|
||||
debug_objects = [obj for obj in self.objects
|
||||
if any(s.is_debug for s in obj.sections)]
|
||||
if len(debug_objects) > 1:
|
||||
names = ", ".join(obj.path for obj in debug_objects)
|
||||
raise LinkError(
|
||||
"--keep-debug supports one debug-bearing object in M7.2; "
|
||||
"got %d: %s" % (len(debug_objects), names))
|
||||
self.debug_object = debug_objects[0] if debug_objects else None
|
||||
if self.args.keep_debug and self.debug_object is not None:
|
||||
self._add_debug(self.debug_object)
|
||||
if debug_objects:
|
||||
# Build the merged debug sections (and their placements) in every
|
||||
# mode: with --strip-debug the relocation pass still resolves the
|
||||
# debug references so a dangling one stays loud, it just does not
|
||||
# write the discarded section bytes.
|
||||
self._add_debug(debug_objects)
|
||||
|
||||
def _add_alloc(self, name, paddr, flags):
|
||||
data = bytearray()
|
||||
@@ -256,14 +464,137 @@ class Linker:
|
||||
if bitoff != self.bss_size:
|
||||
raise LinkError("internal: .bss size mismatch")
|
||||
|
||||
def _add_debug(self, obj):
|
||||
for sec in obj.sections:
|
||||
if not sec.is_debug:
|
||||
def _add_debug(self, objects):
|
||||
"""Merge every debug-bearing object's ``.debug_*`` sections.
|
||||
|
||||
Each output section is the concatenation of the inputs' same-named
|
||||
sections in object order. The placement recorded for an object is its
|
||||
byte base inside the merged section (in bits), which is what
|
||||
``_reloc_value`` adds to a section-relative debug reference. With one
|
||||
object every base is 0, so the M7 single-TU bytes are unchanged.
|
||||
"""
|
||||
merged = {}
|
||||
order = []
|
||||
multi = len(objects) > 1
|
||||
validate = multi and self.args.keep_debug
|
||||
for obj in objects:
|
||||
for sec in obj.sections:
|
||||
if not sec.is_debug or sec.name in merged:
|
||||
continue
|
||||
if validate and sec.name not in DEBUG_CONCAT_SECTIONS:
|
||||
raise LinkError(
|
||||
"%s: cannot merge debug section %s from multiple "
|
||||
"objects (unsupported shape)" % (obj.path, sec.name))
|
||||
out = OutSection(sec.name, 0, b"", size=0, flags=0, vaddr=0,
|
||||
debug=True)
|
||||
merged[sec.name] = out
|
||||
order.append(out)
|
||||
for obj in objects:
|
||||
for sec in obj.sections:
|
||||
if not sec.is_debug:
|
||||
continue
|
||||
if validate and sec.name in (".debug_str",
|
||||
".debug_line_str") \
|
||||
and sec.data and not sec.data.endswith(b"\0"):
|
||||
raise LinkError(
|
||||
"%s: %s does not end with NUL; concatenating it "
|
||||
"would merge strings" % (obj.path, sec.name))
|
||||
out = merged[sec.name]
|
||||
if len(out.data) * 8 != out.size:
|
||||
raise LinkError("internal: %s merge size mismatch"
|
||||
% sec.name)
|
||||
base = len(out.data)
|
||||
self.placements[(obj.path, sec.name)] = (out, base * 8)
|
||||
out.data.extend(sec.data)
|
||||
out.size = len(out.data) * 8
|
||||
if validate:
|
||||
for obj in objects:
|
||||
for sec in obj.sections:
|
||||
if sec.is_debug and sec.name in (
|
||||
".debug_info", ".debug_line", ".debug_str_offsets",
|
||||
".debug_addr", ".debug_loclists",
|
||||
".debug_rnglists"):
|
||||
self._check_debug_unit_chain(obj, sec)
|
||||
self._patch_raw_debug_offsets(objects)
|
||||
if self.args.keep_debug:
|
||||
for out in order:
|
||||
self._register(out)
|
||||
|
||||
@staticmethod
|
||||
def _check_debug_unit_chain(obj, sec):
|
||||
"""Every unit in a concatenated debug section must be self-contained."""
|
||||
data = sec.data
|
||||
pos = 0
|
||||
while pos < len(data):
|
||||
if pos + 4 > len(data):
|
||||
raise LinkError("%s: %s has a truncated unit header at %#x"
|
||||
% (obj.path, sec.name, pos))
|
||||
unit_length = struct.unpack_from("<I", data, pos)[0]
|
||||
if unit_length == 0xFFFFFFFF:
|
||||
raise LinkError(
|
||||
"%s: 64-bit DWARF %s is not supported in a multi-object "
|
||||
"link" % (obj.path, sec.name))
|
||||
unit_end = pos + 4 + unit_length
|
||||
if unit_end > len(data):
|
||||
raise LinkError(
|
||||
"%s: %s unit at %#x has length %d, past the %d-byte "
|
||||
"section" % (obj.path, sec.name, pos, unit_length,
|
||||
len(data)))
|
||||
pos = unit_end
|
||||
|
||||
def _patch_raw_debug_offsets(self, objects):
|
||||
"""Patch raw (non-relocated) CU debug_abbrev_offset fields.
|
||||
|
||||
LLVM 23.1.5 objects relocate the field, but a producer may leave it
|
||||
raw as the section-relative offset 0. When a CU header field has no
|
||||
relocation covering it, add the object's merged .debug_abbrev base.
|
||||
DWARF64 units are refused: they are not the inspected shape.
|
||||
"""
|
||||
for obj in objects:
|
||||
info = obj.section_by_name.get(".debug_info")
|
||||
if info is None:
|
||||
continue
|
||||
out = OutSection(sec.name, 0, bytearray(sec.data), size=sec.size,
|
||||
flags=0, vaddr=0, debug=True)
|
||||
self._register(out)
|
||||
self.placements[(obj.path, sec.name)] = (out, 0)
|
||||
info_out, info_base = self.placements[(obj.path, ".debug_info")]
|
||||
abbrev = obj.section_by_name.get(".debug_abbrev")
|
||||
if abbrev is None:
|
||||
continue
|
||||
_, abbrev_base = self.placements[(obj.path, ".debug_abbrev")]
|
||||
if info_base % 8 or abbrev_base % 8:
|
||||
raise LinkError("internal: debug section base is not byte "
|
||||
"aligned")
|
||||
relocated = {rel.raddr // 8 for rel in info.relocs}
|
||||
data = info.data
|
||||
pos = 0
|
||||
while pos < len(data):
|
||||
if pos + 4 > len(data):
|
||||
raise LinkError("%s: .debug_info unit header is truncated"
|
||||
% obj.path)
|
||||
unit_length = struct.unpack_from("<I", data, pos)[0]
|
||||
if unit_length == 0xFFFFFFFF:
|
||||
raise LinkError(
|
||||
"%s: 64-bit DWARF .debug_info is not supported in a "
|
||||
"multi-object link" % obj.path)
|
||||
unit_end = pos + 4 + unit_length
|
||||
if unit_length < 6 or unit_end > len(data):
|
||||
raise LinkError("%s: .debug_info unit at %#x has invalid "
|
||||
"length %d" % (obj.path, pos, unit_length))
|
||||
version = struct.unpack_from("<H", data, pos + 4)[0]
|
||||
if version >= 5:
|
||||
field = pos + 8 # unit_type, address_size first
|
||||
elif version >= 2:
|
||||
field = pos + 6
|
||||
else:
|
||||
raise LinkError("%s: .debug_info unit at %#x has "
|
||||
"unsupported DWARF version %d"
|
||||
% (obj.path, pos, version))
|
||||
if field + 4 > unit_end:
|
||||
raise LinkError("%s: .debug_info unit at %#x is too short "
|
||||
"for its CU header" % (obj.path, pos))
|
||||
if field not in relocated and abbrev_base:
|
||||
old = struct.unpack_from("<I", data, field)[0]
|
||||
_put_u32(info_out.data, info_base // 8 + field,
|
||||
old + abbrev_base // 8)
|
||||
pos = unit_end
|
||||
|
||||
def _register(self, sec):
|
||||
self.out_sections.append(sec)
|
||||
@@ -284,7 +615,13 @@ class Linker:
|
||||
return ("absolute", sym.value)
|
||||
sec = self._section_of(obj, sym)
|
||||
if sec.is_debug:
|
||||
return ("debug", sym.value)
|
||||
key = (obj.path, sec.name)
|
||||
if key not in self.placements:
|
||||
raise LinkError(
|
||||
"symbol '%s' is in debug section %s, which has no merged "
|
||||
"placement (was it stripped?)" % (sym.name, sec.name))
|
||||
_out, base = self.placements[key]
|
||||
return ("debug", base + sym.value)
|
||||
key = (obj.path, sec.name)
|
||||
if key not in self.placements:
|
||||
raise LinkError(
|
||||
@@ -300,9 +637,15 @@ class Linker:
|
||||
raise LinkError(
|
||||
"allocated relocation cannot target debug symbol '%s' in "
|
||||
"%s" % (sym.name, obj.path))
|
||||
# Debug sections are section-relative; the relocation field already
|
||||
# carries the byte addend, including any symbol offset.
|
||||
return addend
|
||||
# Debug sections are section-relative: the target's merged base
|
||||
# (0 for the first/single object) plus the field's byte addend,
|
||||
# which already includes any symbol offset.
|
||||
if base % 8:
|
||||
raise LinkError(
|
||||
"cannot represent bit offset %#x of debug symbol '%s' "
|
||||
"in a debug section (not byte aligned)"
|
||||
% (base, sym.name))
|
||||
return base // 8 + addend
|
||||
bits = base
|
||||
if containing_debug:
|
||||
if bits % 8:
|
||||
@@ -320,10 +663,13 @@ class Linker:
|
||||
return self._resolve_definition(dobj, dsym, containing_debug, addend)
|
||||
|
||||
def _reloc_value(self, obj, sec, rel, containing_debug):
|
||||
addend = _u32(sec.data, rel.raddr // 8)
|
||||
# TI-COFF relocation fields carry a signed 32-bit addend; negative
|
||||
# offsets occur for e.g. a pointer to an array element before a symbol.
|
||||
addend = _s32(sec.data, rel.raddr // 8)
|
||||
if rel.symidx == 0xFFFF:
|
||||
if containing_debug:
|
||||
return addend
|
||||
_out, off = self.placements[(obj.path, sec.name)]
|
||||
return off // 8 + addend
|
||||
out, off = self.placements[(obj.path, sec.name)]
|
||||
return out.paddr + off + addend
|
||||
|
||||
@@ -336,7 +682,13 @@ class Linker:
|
||||
tsec = self._section_of(obj, sym)
|
||||
if containing_debug:
|
||||
if tsec.is_debug:
|
||||
return addend
|
||||
_out, off = self.placements[(obj.path, tsec.name)]
|
||||
if off % 8 or sym.value % 8:
|
||||
raise LinkError(
|
||||
"cannot represent debug target section %s at "
|
||||
"bit offset %#x (not byte aligned)"
|
||||
% (tsec.name, off + sym.value))
|
||||
return off // 8 + sym.value // 8 + addend
|
||||
out, off = self.placements[(obj.path, tsec.name)]
|
||||
base = out.paddr + off
|
||||
if base % 8:
|
||||
@@ -429,7 +781,6 @@ class Linker:
|
||||
if sec.is_debug and not self.args.keep_debug:
|
||||
continue
|
||||
if sec.is_debug:
|
||||
value = sym.value
|
||||
outsec = None
|
||||
for cand in self.out_sections:
|
||||
if cand.name == sec.name:
|
||||
@@ -438,6 +789,8 @@ class Linker:
|
||||
if outsec is None:
|
||||
continue
|
||||
secno = self.out_index[outsec.name]
|
||||
_osc, base = self.placements[(obj.path, sec.name)]
|
||||
value = base + sym.value
|
||||
else:
|
||||
key = (obj.path, sec.name)
|
||||
if key not in self.placements:
|
||||
@@ -524,6 +877,7 @@ class Linker:
|
||||
def run(self):
|
||||
self.load()
|
||||
self._collect_globals()
|
||||
self._extract_archive_members()
|
||||
self.layout()
|
||||
self.apply_relocations()
|
||||
self.build_symbols()
|
||||
@@ -572,13 +926,21 @@ def build_parser():
|
||||
"(bounds .bss)")
|
||||
dbg = p.add_mutually_exclusive_group()
|
||||
dbg.add_argument("--keep-debug", dest="keep_debug", action="store_true",
|
||||
help="keep the single debug-bearing object's .debug_* "
|
||||
"sections")
|
||||
help="keep .debug_* sections from every debug-bearing "
|
||||
"object, merged in object order")
|
||||
dbg.add_argument("--strip-debug", dest="keep_debug", action="store_false",
|
||||
help="strip .debug_* sections (default)")
|
||||
p.set_defaults(keep_debug=False)
|
||||
p.add_argument("objects", nargs="+", metavar="OBJ",
|
||||
help="relocatable TI-COFF input objects")
|
||||
p.add_argument("-L", dest="lib_dirs", action="append", default=[],
|
||||
metavar="DIR", help="add DIR to the -l library search path")
|
||||
p.add_argument("-l", dest="libraries", action="append", default=[],
|
||||
metavar="LIB",
|
||||
help="link archive LIB (also -lLIB); searched in ., -L "
|
||||
"directories and beside the other inputs. Archives "
|
||||
"and libraries are processed after all explicit "
|
||||
"positional objects, whatever their order")
|
||||
p.add_argument("objects", nargs="+", metavar="OBJ|LIB",
|
||||
help="relocatable TI-COFF objects or ar archives")
|
||||
return p
|
||||
|
||||
|
||||
|
||||
+297
-7
@@ -26,9 +26,17 @@ OPTHDR_VSTAMP = 199
|
||||
R_RELWORD = 0x10
|
||||
R_RELLONG = 0x11
|
||||
|
||||
AR_MAGIC = b"!<arch>\n"
|
||||
AR_HEADER_SIZE = 60
|
||||
|
||||
S_TEXT = 0x20
|
||||
S_DATA = 0x40
|
||||
S_BSS = 0x80
|
||||
# The 1990 r5.01 tools set metadata bits 0x100/0x400 on some allocated
|
||||
# sections (observed: .text 0x420/0x520, .bss 0x580). They do not change the
|
||||
# section's text/data/bss class or its load image, so accept them alongside
|
||||
# the exact class bit. Output images always use the classic 0x20/0x40/0x80.
|
||||
S_ALLOC_EXTRA = 0x500
|
||||
|
||||
C_EXT = 2
|
||||
C_STAT = 3
|
||||
@@ -71,6 +79,9 @@ class Section:
|
||||
|
||||
@property
|
||||
def is_debug(self):
|
||||
# tms-link concatenates same-named .debug_* inputs in object order and
|
||||
# rehomes their section-relative offsets/relocations; this reader only
|
||||
# classifies them (they are non-allocated and carry no load address).
|
||||
return self.name.startswith(".debug_")
|
||||
|
||||
@property
|
||||
@@ -172,18 +183,30 @@ def _read_name(raw, table, path, what):
|
||||
return raw[:end].decode("latin1")
|
||||
|
||||
|
||||
def read_object(path, relocatable=True):
|
||||
def read_object(path=None, relocatable=True, *, data=None, label=None):
|
||||
"""Parse one TI-COFF object, validating the M7.2 contract.
|
||||
|
||||
``relocatable`` is true for linker inputs (no optional header, relocation
|
||||
records allowed) and false for a linked output (optional header permitted,
|
||||
no relocations expected but not required here).
|
||||
|
||||
The bytes may also be supplied directly (``data=...``) with a diagnostic
|
||||
``label``; archive members use that path so the linker never writes
|
||||
temporary files.
|
||||
"""
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
data = fh.read()
|
||||
except OSError as exc:
|
||||
raise CoffError("%s: cannot read: %s" % (path, exc)) from exc
|
||||
if data is None:
|
||||
if path is None:
|
||||
raise CoffError("read_object: no path or data")
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
data = fh.read()
|
||||
except OSError as exc:
|
||||
raise CoffError("%s: cannot read: %s" % (path, exc)) from exc
|
||||
if label is None:
|
||||
label = path
|
||||
elif label is None:
|
||||
label = path if path is not None else "<memory>"
|
||||
path = label
|
||||
|
||||
if len(data) < 20:
|
||||
raise CoffError("%s: shorter than a COFF file header" % path)
|
||||
@@ -311,7 +334,8 @@ def read_object(path, relocatable=True):
|
||||
# GSPLNK (and GSPA for an empty section) emits a listed-but-empty
|
||||
# .cinit with flags 0. It contributes no bytes or relocations.
|
||||
empty_cinit = (name == ".cinit" and size == 0 and sflags == 0)
|
||||
if sflags != want_flags and not empty_cinit:
|
||||
if (sflags != want_flags and not empty_cinit and
|
||||
(sflags & ~S_ALLOC_EXTRA) != want_flags):
|
||||
raise CoffError("%s: section %r flags %#x, expected %#x"
|
||||
% (path, name, sflags, want_flags))
|
||||
elif name.startswith(".debug_"):
|
||||
@@ -438,6 +462,272 @@ def read_object(path, relocatable=True):
|
||||
symptr, string_table, opt=opt)
|
||||
|
||||
|
||||
class ArchiveMember:
|
||||
"""One real (non-special) member of a System V ``ar`` archive."""
|
||||
|
||||
__slots__ = ("name", "offset", "size", "data")
|
||||
|
||||
def __init__(self, name, offset, size, data):
|
||||
self.name = name
|
||||
self.offset = offset
|
||||
self.size = size
|
||||
self.data = data
|
||||
|
||||
def __repr__(self):
|
||||
return "ArchiveMember(%r, offset=%d, size=%d)" % (
|
||||
self.name, self.offset, self.size)
|
||||
|
||||
|
||||
class Archive:
|
||||
"""A parsed ``!<arch>`` archive.
|
||||
|
||||
``symbols`` maps an external symbol name to the member(s) whose ``/``
|
||||
table entry claims it, or is ``None`` when the archive has no symbol
|
||||
table. ``index_entries`` preserves that table's entry order;
|
||||
``member_symbols`` maps a member offset to the names it contributes, so
|
||||
the linker can decide whether a member is needed without parsing every
|
||||
(possibly unsupported) module in the archive. Members are kept in file
|
||||
order; special ``/`` and ``//`` members are not part of ``members``.
|
||||
"""
|
||||
|
||||
__slots__ = ("path", "members", "by_offset", "symbols", "symbol_table",
|
||||
"long_names", "index_entries", "member_symbols")
|
||||
|
||||
def __init__(self, path, members, symbols, symbol_table, long_names,
|
||||
index_entries=None, member_symbols=None):
|
||||
self.path = path
|
||||
self.members = members
|
||||
self.by_offset = {m.offset: m for m in members}
|
||||
self.symbols = symbols
|
||||
self.symbol_table = symbol_table
|
||||
self.long_names = long_names
|
||||
self.index_entries = index_entries or []
|
||||
self.member_symbols = member_symbols or {}
|
||||
|
||||
def scan_members(self):
|
||||
"""Members in ``/`` index order (or file order without an index)."""
|
||||
if not self.index_entries:
|
||||
return self.members
|
||||
seen = set()
|
||||
ordered = []
|
||||
for _name, member in self.index_entries:
|
||||
if member.offset in seen:
|
||||
continue
|
||||
seen.add(member.offset)
|
||||
ordered.append(member)
|
||||
return ordered
|
||||
|
||||
def __repr__(self):
|
||||
return "Archive(%r, %d members)" % (self.path, len(self.members))
|
||||
|
||||
|
||||
def _archive_name(raw, path, offset):
|
||||
"""Decode a short member name field (trailing spaces/NULs stripped)."""
|
||||
field = raw.rstrip(b" \0")
|
||||
if not field:
|
||||
raise CoffError("%s: member header at offset %d has an empty name"
|
||||
% (path, offset))
|
||||
if field.startswith(b"#1/"):
|
||||
raise CoffError("%s: member header at offset %d uses unsupported "
|
||||
"BSD #1/ long names" % (path, offset))
|
||||
if field.endswith(b"/"):
|
||||
field = field[:-1]
|
||||
if not field:
|
||||
raise CoffError("%s: member header at offset %d has an empty name"
|
||||
% (path, offset))
|
||||
if b"/" in field:
|
||||
raise CoffError("%s: member header at offset %d has an invalid "
|
||||
"short name %r" % (path, offset, field))
|
||||
return field.decode("latin1")
|
||||
|
||||
|
||||
def _parse_archive(data, path):
|
||||
if not data.startswith(AR_MAGIC):
|
||||
raise CoffError("%s: not an ar archive (missing !<arch> magic)"
|
||||
% path)
|
||||
|
||||
specials = {}
|
||||
pending = [] # (raw "/N" field, offset, size, bytes)
|
||||
members = []
|
||||
offset = len(AR_MAGIC)
|
||||
while offset < len(data):
|
||||
if len(data) - offset < AR_HEADER_SIZE:
|
||||
# Some ar implementations leave a final newline after the last
|
||||
# member; anything else here is a truncated header.
|
||||
tail = data[offset:]
|
||||
if tail.strip(b"\r\n") == b"":
|
||||
break
|
||||
raise CoffError(
|
||||
"%s: truncated member header at offset %d (%d byte(s) "
|
||||
"remain)" % (path, offset, len(data) - offset))
|
||||
header = data[offset:offset + AR_HEADER_SIZE]
|
||||
if header[58:60] != b"`\n":
|
||||
raise CoffError(
|
||||
"%s: member header at offset %d has bad magic %r"
|
||||
% (path, offset, header[58:60]))
|
||||
size_text = header[48:58].decode("latin1").strip()
|
||||
# isdigit() also accepts Latin-1 superscripts, which int() rejects;
|
||||
# require ASCII digits and still catch a conversion failure.
|
||||
if not size_text.isascii() or not size_text.isdigit():
|
||||
raise CoffError(
|
||||
"%s: member header at offset %d has a non-decimal size "
|
||||
"field %r" % (path, offset, header[48:58]))
|
||||
try:
|
||||
size = int(size_text)
|
||||
except ValueError as exc: # pragma: no cover - guarded above
|
||||
raise CoffError(
|
||||
"%s: member header at offset %d has a non-decimal size "
|
||||
"field %r" % (path, offset, header[48:58])) from exc
|
||||
start = offset + AR_HEADER_SIZE
|
||||
end = start + size
|
||||
if end > len(data):
|
||||
raise CoffError(
|
||||
"%s: member at offset %d (%r) data runs past EOF "
|
||||
"(size %d, %d byte(s) remain)"
|
||||
% (path, offset, header[:16].rstrip(b" \0"), size,
|
||||
len(data) - start))
|
||||
body = data[start:end]
|
||||
raw_name = header[:16].rstrip(b" \0")
|
||||
if raw_name == b"/":
|
||||
if "index" in specials:
|
||||
raise CoffError("%s: duplicate archive symbol table at "
|
||||
"offset %d" % (path, offset))
|
||||
specials["index"] = body
|
||||
elif raw_name == b"//":
|
||||
if "longnames" in specials:
|
||||
raise CoffError("%s: duplicate archive long-name table at "
|
||||
"offset %d" % (path, offset))
|
||||
specials["longnames"] = body
|
||||
elif raw_name.startswith(b"/") and raw_name[1:].isdigit():
|
||||
pending.append((raw_name[1:], offset, size, body))
|
||||
else:
|
||||
name = _archive_name(header[:16], path, offset)
|
||||
members.append(ArchiveMember(name, offset, size, body))
|
||||
offset = end
|
||||
if size & 1:
|
||||
if offset >= len(data):
|
||||
raise CoffError(
|
||||
"%s: member at offset %d has odd size %d but no "
|
||||
"padding byte at EOF" % (path, offset - size - 60, size))
|
||||
pad = data[offset]
|
||||
if pad not in (0x0A, 0x00):
|
||||
raise CoffError(
|
||||
"%s: member at offset %d has bad padding byte %#x "
|
||||
"(want newline or NUL)" % (path, offset - size - 60, pad))
|
||||
offset += 1
|
||||
|
||||
long_names = specials.get("longnames")
|
||||
for text, member_offset, size, body in pending:
|
||||
if long_names is None:
|
||||
raise CoffError(
|
||||
"%s: member at offset %d uses a /%s long name but the "
|
||||
"archive has no // table"
|
||||
% (path, member_offset, text.decode("latin1")))
|
||||
try:
|
||||
name_offset = int(text)
|
||||
except ValueError as exc: # isdigit() above makes this unreachable
|
||||
raise CoffError("%s: member at offset %d has an invalid "
|
||||
"long-name reference /%s"
|
||||
% (path, member_offset, text.decode("latin1"))
|
||||
) from exc
|
||||
if name_offset >= len(long_names):
|
||||
raise CoffError(
|
||||
"%s: member at offset %d has long-name offset %d outside "
|
||||
"the %d-byte // table"
|
||||
% (path, member_offset, name_offset, len(long_names)))
|
||||
end = long_names.find(b"\n", name_offset)
|
||||
if end < 0:
|
||||
raise CoffError(
|
||||
"%s: member at offset %d long-name entry at %d is not "
|
||||
"newline-terminated" % (path, member_offset, name_offset))
|
||||
name = long_names[name_offset:end].rstrip(b"\r")
|
||||
if name.endswith(b"/"):
|
||||
name = name[:-1]
|
||||
if not name:
|
||||
raise CoffError(
|
||||
"%s: member at offset %d long-name entry at %d is empty"
|
||||
% (path, member_offset, name_offset))
|
||||
members.append(ArchiveMember(name.decode("latin1"), member_offset,
|
||||
size, body))
|
||||
|
||||
members.sort(key=lambda m: m.offset)
|
||||
by_offset = {m.offset: m for m in members}
|
||||
symbols = None
|
||||
index_entries = []
|
||||
member_symbols = {}
|
||||
symbol_table = specials.get("index")
|
||||
if symbol_table is not None:
|
||||
if len(symbol_table) < 4:
|
||||
raise CoffError("%s: archive symbol table is shorter than its "
|
||||
"4-byte count" % path)
|
||||
count = struct.unpack_from(">I", symbol_table, 0)[0]
|
||||
if count > (len(symbol_table) - 4) // 4:
|
||||
raise CoffError("%s: archive symbol table declares %d entries, "
|
||||
"which does not fit in %d bytes"
|
||||
% (path, count, len(symbol_table)))
|
||||
if count == 0:
|
||||
# A present-but-empty index cannot resolve anything. Treat it as
|
||||
# absent so the members are scanned directly; this is the same
|
||||
# behaviour as an archive without a / member.
|
||||
symbols = None
|
||||
else:
|
||||
offsets = struct.unpack_from(">%dI" % count, symbol_table, 4)
|
||||
blob = symbol_table[4 + count * 4:]
|
||||
names = blob.split(b"\0")
|
||||
if len(names) < count:
|
||||
raise CoffError("%s: archive symbol table has %d entries but "
|
||||
"only %d name(s)" % (path, count, len(names)))
|
||||
symbols = {}
|
||||
for i, member_offset in enumerate(offsets):
|
||||
member = by_offset.get(member_offset)
|
||||
if member is None:
|
||||
raise CoffError(
|
||||
"%s: archive symbol table entry %d points at %#x, "
|
||||
"which is not a member header"
|
||||
% (path, i, member_offset))
|
||||
name = names[i].decode("latin1")
|
||||
if not name:
|
||||
raise CoffError("%s: archive symbol table entry %d has "
|
||||
"an empty name" % (path, i))
|
||||
entries = symbols.setdefault(name, [])
|
||||
if not any(m.offset == member.offset for m in entries):
|
||||
entries.append(member)
|
||||
index_entries.append((name, member))
|
||||
member_symbols.setdefault(member.offset, []).append(name)
|
||||
|
||||
return Archive(path, members, symbols, symbol_table, long_names,
|
||||
index_entries, member_symbols)
|
||||
|
||||
|
||||
def read_archive(path=None, *, data=None, label=None):
|
||||
"""Read and parse a System V ``ar`` archive (``!<arch>``)."""
|
||||
if data is None:
|
||||
if path is None:
|
||||
raise CoffError("read_archive: no path or data")
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
data = fh.read()
|
||||
except OSError as exc:
|
||||
raise CoffError("%s: cannot read: %s" % (path, exc)) from exc
|
||||
if label is None:
|
||||
label = path
|
||||
elif label is None:
|
||||
label = path if path is not None else "<memory>"
|
||||
return _parse_archive(data, label)
|
||||
|
||||
|
||||
def read_input(path):
|
||||
"""Read a link input, dispatching on the ``!<arch>`` magic."""
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
data = fh.read()
|
||||
except OSError as exc:
|
||||
raise CoffError("%s: cannot read: %s" % (path, exc)) from exc
|
||||
if data.startswith(AR_MAGIC):
|
||||
return read_archive(path, data=data)
|
||||
return read_object(path, data=data)
|
||||
|
||||
|
||||
def _align16(value):
|
||||
return (value + 15) & ~15
|
||||
|
||||
|
||||
Reference in new issue
Block a user