Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
536c80a797 | ||
|
|
8c1468978a | ||
|
|
537ed27d26 | ||
|
|
dfd13ab1c1 | ||
|
|
7fcae6e520 | ||
|
|
7fada4d9d7 | ||
|
|
d705e43d41 | ||
|
|
9916bbce92 | ||
|
|
12fa71d394 | ||
|
|
c6b437b738 | ||
|
|
28779e1800 | ||
|
|
20789d07f3 | ||
|
|
41c30eee99 | ||
|
|
e17c28a5d5 | ||
|
|
a7bbefad47 | ||
|
|
48091850e1 | ||
|
|
9694497548 | ||
|
|
e609a4b84e | ||
|
|
abbee9f42f | ||
|
|
d73dc9c020 | ||
|
|
5daf528128 | ||
|
|
48eb9bd248 | ||
|
|
f4442e8f6f | ||
|
|
848a570b4f | ||
|
|
16a7244bf6 | ||
|
|
2a95b71509 | ||
|
|
98eea9feb0 | ||
|
|
41ff4f68d2 | ||
|
|
55a0991529 | ||
|
|
d91785457f | ||
|
|
4a9636690f | ||
|
|
95b55dec97 | ||
|
|
739e48d8dd | ||
|
|
24eca1c080 | ||
|
|
b2dd323e71 | ||
|
|
8711dee37b | ||
|
|
8b6eed2510 | ||
|
|
b005cd13c4 | ||
|
|
30f0dd688e | ||
|
|
9700b5c44f | ||
|
|
8f28483868 | ||
|
|
4d2c2dce5c | ||
|
|
dd8c5ea3ce | ||
|
|
f340d74472 | ||
|
|
2a2efd61d7 | ||
|
|
66d21ebc35 | ||
|
|
1315df5548 | ||
|
|
af0c5cb617 | ||
|
|
bb78a97313 | ||
|
|
e55287f218 | ||
|
|
f9b51667c4 | ||
|
|
5214938b6b | ||
|
|
dc7de6f3a7 | ||
|
|
29c30ddcc6 | ||
|
|
dc94931eca |
No files matched your search
+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.
|
||||
@@ -0,0 +1,515 @@
|
||||
# TMS34010 M10 (Phase 2) — Native clang Pipeline Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Make `clang --target=tms34010 -c` semantically correct for pointer code at `-O0` and `-O2` with no extra flags, by moving the bit-address barrier, the post-optimizer scaling and the barrier lowering into the TMS34010 target's own pass pipeline.
|
||||
|
||||
**Architecture:** A minimal clang `ToolChain` supplies this target's compile defaults (freestanding, no builtins, no system includes, `-replexitval=never`). The transform logic from `tools/tms-bitaddr/bitscale.cpp` is ported to new-PM module passes in `llvm/lib/Target/TMS34010/` and registered from `TMS34010TargetMachine::registerPassBuilderCallbacks`: the barrier on the pipeline-start extension point (which also lowers immediately at `-O0`), scale/lower/final-InstCombine on optimizer-last. A `"tms.bitaddr"` module flag makes repeated application impossible, and a legacy pass in `addISelPrepare` lowers any barrier calls that still reach codegen. `llc`'s IR contract is untouched because `llc` builds no new-PM pipeline.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`), `llvm/lib/Target/TMS34010`, clang driver `ToolChains`, new pass manager (`PassBuilder` EP callbacks), module flags, lit/FileCheck, shell gates, MAME for runtime gates.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md` (§7 and §7.8 are this milestone; §8 is M11, which gets its own plan after M10 is promoted because it extends the same `ToolChain` file).
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Baseline: project `m9`/`55a0991`, compiler `m9`/`4e7d48d2717e`. Cut `m10` in both repos before Task 1; never force-push.
|
||||
- LLVM/Clang stay pinned at 23.1.5. Export the driver change as `patches/llvm/0005-*.patch`.
|
||||
- No new user-visible flag may be required for correctness: `clang --target=tms34010 -O2 -c` works with no extra arguments.
|
||||
- `llc`'s IR contract is unchanged: for `i8` GEPs the byte offset is the bit offset (`m2-late-gep.ll` → `ADDI 24`).
|
||||
- `opt` behaviour is unchanged: it builds no `TargetMachine`, so no target hook fires there.
|
||||
- `clang -O0 -c` objects must be **byte-identical** to the M9 path (`scripts/tms-clang` + `llc -O0`) across the corpus. `-O2` is gated on behaviour, not bytes.
|
||||
- Existing gates stay green: lit **129/129**, clang **5/5**, the M2–M9 gate list, the two-tier full suite **1,618 pass / 294 skip / 0 fail / 0 crash**, i64div **88/3302/221/120** with checksums `000000011E6F9AB4` / `00000000007512AE` / `F56810CFEDA9D656` / `00002C61C63842EE`.
|
||||
- TI ABI, the all-stack convention, GSPLNK as the byte/symbol oracle and the two-tier harness are unchanged.
|
||||
- `-O0` and `-O2` are both first-class. A change that only holds at one level is incomplete.
|
||||
- Debug locations survive every new pass: the M9.2 gates (`scripts/tests/m9/dwarf-ranges.sh`, `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`) must pass unchanged.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **`clang -emit-llvm` output fed to `llc`** — a user's normal two-step flow must not double-transform; llc must accept the emitted IR and produce the same code as `-c` (Task 3).
|
||||
2. **Hand-written IR through `llc`** — `getelementptr i8, ptr %p, i32 24` must still be `ADDI 24`; a barrier inside llc would silently redefine every existing fixture (Task 2).
|
||||
3. **`-O0` parity with the legacy path** — byte drift here means a hidden semantic change (optnone, always-inline, an extra InstCombine) rather than a benign optimization difference (Task 4).
|
||||
4. **Ordinary loop code at `-O2`** — `IndVarSimplify`'s i33 exit-value rewrite must not resurface as a compile failure once the shell wrapper stops passing `-replexitval=never` (Task 1, Task 5).
|
||||
5. **Debug info through the port** — barrier/lower must copy `!dbg`, or `-g -c` objects lose their line table and the DWARF gates go red (Task 2, Task 6).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: TMS34010 `ToolChain` with the target's compile defaults
|
||||
|
||||
**Files:**
|
||||
- Create: `clang/lib/Driver/ToolChains/TMS34010.h`
|
||||
- Create: `clang/lib/Driver/ToolChains/TMS34010.cpp`
|
||||
- Modify: `clang/lib/Driver/ToolChains/CMakeLists.txt`
|
||||
- Modify: `clang/lib/Driver/Driver.cpp` (arch switch in `Driver::getToolChain`, after the `msp430` case at ~line 7286)
|
||||
- Test: `clang/test/Driver/tms34010-defaults.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `toolchains::BareMetal` (`clang/lib/Driver/ToolChains/BareMetal.h`), whose ctor is `BareMetal(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)`.
|
||||
- Produces: `class TMS34010ToolChain : public BareMetal` with the same ctor, overriding `void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, BoundArch BA, Action::OffloadKind DeviceOffloadKind) const`, which appends `-ffreestanding`, `-fno-builtin`, `-mllvm`, `-replexitval=never` and then calls `BareMetal::addClangTargetOptions`.
|
||||
|
||||
- [ ] **Step 1: Write the failing driver test**
|
||||
|
||||
```c
|
||||
// clang/test/Driver/tms34010-defaults.c
|
||||
// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=FLAGS
|
||||
// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=NOSYS
|
||||
// FLAGS: "-cc1" {{.*}}-ffreestanding
|
||||
// FLAGS-SAME: -fno-builtin
|
||||
// FLAGS-SAME: "-mllvm" "-replexitval=never"
|
||||
// NOSYS-NOT: "-internal-isystem"
|
||||
int f(int n) { return n + 1; }
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: FAIL — the `-###` line has no `-ffreestanding` / `-mllvm -replexitval=never`.
|
||||
|
||||
- [ ] **Step 3: Implement the ToolChain**
|
||||
|
||||
`TMS34010.h` subclasses `BareMetal` with the forwarding ctor and the `addClangTargetOptions` override. `TMS34010.cpp` pushes the four default arguments in this order (`-ffreestanding`, `-fno-builtin`, `-mllvm`, `-replexitval=never`) before delegating to the base. In `Driver.cpp`, insert after the `msp430` case:
|
||||
|
||||
```cpp
|
||||
case llvm::Triple::tms34010:
|
||||
TC = std::make_unique<toolchains::TMS34010ToolChain>(*this, Target, Args);
|
||||
break;
|
||||
```
|
||||
|
||||
Add the header to `Driver.cpp`'s include block and `TMS34010.cpp` to `ToolChains/CMakeLists.txt` (`add_clang_library(clangDriver ...)`).
|
||||
|
||||
- [ ] **Step 4: Run it green, plus the loop case**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: PASS.
|
||||
|
||||
Then compile the shape that fails today, with no extra flags:
|
||||
|
||||
```sh
|
||||
printf 'int sumto(int n){int s=0;for(int i=0;i<=n;i++)s+=i;return s;}\n' > /tmp/opencode/m10-loop.c
|
||||
build/llvm-clean-build/bin/clang --target=tms34010 -O2 -c /tmp/opencode/m10-loop.c -o /tmp/opencode/m10-loop.o
|
||||
```
|
||||
Expected: exit 0, object written (before this task: `fatal error: TMS34010: i33 multiply (umul_lohi shape) reached code generation`).
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add clang/lib/Driver/ToolChains/TMS34010.h \
|
||||
clang/lib/Driver/ToolChains/TMS34010.cpp \
|
||||
clang/lib/Driver/ToolChains/CMakeLists.txt \
|
||||
clang/lib/Driver/Driver.cpp clang/test/Driver/tms34010-defaults.c
|
||||
git -C build/llvm-clean commit -m "tms34010: add the driver ToolChain with the target compile defaults"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: Bit-address passes and pipeline hooks (`-O0` and `-O2` correct)
|
||||
|
||||
**Files:**
|
||||
- Create: `llvm/lib/Target/TMS34010/TMS34010BitAddr.h`
|
||||
- Create: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp`
|
||||
- Modify: `llvm/lib/Target/TMS34010/CMakeLists.txt`
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.h`
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp`
|
||||
- Test: `clang/test/CodeGen/TMS34010/bitaddr-o0.c`, `clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `tools/tms-bitaddr/bitscale.cpp` as the behavioural reference (modes `--bitptr`, `--scale`, `--lower-bitptr`); `OptimizationLevel` from the pipeline-start callback.
|
||||
- Produces: free functions `bool tms34010BitPtr(Module &M, OptimizationLevel Level)`, `bool tms34010ScaleGEP(Module &M)`, `bool tms34010LowerBitPtr(Module &M)`; new-PM passes `TMS34010BitPtrPass(OptimizationLevel)`, `TMS34010ScaleGEPPass`, `TMS34010LowerBitPtrPass`, each `PassInfoMixin` with `PreservedAnalyses run(Module &M, ModuleAnalysisManager &)`; `void TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) override`.
|
||||
|
||||
- [ ] **Step 1: Write the failing asm tests**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
struct S { char c; int i; };
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int load_s(struct S *p) { return p[1].i; }
|
||||
int load_b(char *p) { return p[4]; }
|
||||
// CHECK-LABEL: _load_i:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
// CHECK-NOT: ADDI 4, A
|
||||
// CHECK-LABEL: _load_s:
|
||||
// CHECK: ADDI 40, A{{[0-9]+}}
|
||||
// CHECK-LABEL: _load_b:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
```
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -S -o - %s | FileCheck %s
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int sumto(int n) { int s = 0; for (int i = 0; i <= n; i++) s += i; return s; }
|
||||
// CHECK-LABEL: _load_i:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
// CHECK-NOT: ADDI 4, A
|
||||
// CHECK-LABEL: _sumto:
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o0.c build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
Expected: FAIL — `ADDI 4` instead of `ADDI 32` (`_load_s` likewise off by the scale factor).
|
||||
|
||||
- [ ] **Step 3: Port the barrier pass**
|
||||
|
||||
In `TMS34010BitAddr.cpp`, implement `tms34010BitPtr` and `TMS34010BitPtrPass` by porting the `--bitptr` mode of `tools/tms-bitaddr/bitscale.cpp` **verbatim in behaviour**: the same `@__tms_bitptr(i32 bitoff, ptr base)` declaration with `nounwind readnone`, the same constant-expression-GEP rewrite to `inttoptr(add(ptrtoint, 8*off))`, the same declaration/body validation error, and every replaced instruction copies its `!dbg` location. Keep the `--normalize` mode out (nothing calls it).
|
||||
|
||||
- [ ] **Step 4: Port the lowering pass**
|
||||
|
||||
Implement `tms34010LowerBitPtr` and `TMS34010LowerBitPtrPass` from the `--lower-bitptr` mode: replace each call with `inttoptr(add(ptrtoint base, bitoff))` and drop the declaration; copy `!dbg` from the call. Then confirm the port compiles and is reachable (registration comes in Step 6):
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang llc FileCheck`
|
||||
Expected: clean build, no new warnings in the target.
|
||||
|
||||
- [ ] **Step 5: Port the scaling pass**
|
||||
|
||||
Implement `tms34010ScaleGEP`: multiply only the indices of GEPs that reach it (optimizer-created byte GEPs), keep the `switch.table.` special case (`isSwitchTableBase` → shift 3 even when `GepShift == 0`), and keep the `0 + x` / `x * 1` folding.
|
||||
|
||||
- [ ] **Step 6: Register the pipeline hooks**
|
||||
|
||||
In `TMS34010TargetMachine.cpp`:
|
||||
|
||||
```cpp
|
||||
void TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
|
||||
PB.registerPipelineStartEPCallback(
|
||||
[](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||
MPM.addPass(TMS34010BitPtrPass(Level));
|
||||
if (Level == OptimizationLevel::O0) {
|
||||
MPM.addPass(TMS34010LowerBitPtrPass());
|
||||
}
|
||||
});
|
||||
PB.registerOptimizerLastEPCallback(
|
||||
[](ModulePassManager &MPM, OptimizationLevel,
|
||||
ThinOrFullLTOPhase) {
|
||||
MPM.addPass(TMS34010ScaleGEPPass());
|
||||
MPM.addPass(TMS34010LowerBitPtrPass());
|
||||
MPM.addPass(InstCombinePass(InstCombineOptions()
|
||||
.setVerifyFixpoint(false)));
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
`-O0` deliberately adds no `scale` (no optimizer runs, so no optimizer-created GEPs) and no `InstCombine` — that is what keeps `-O0` byte-identical to the legacy path (Task 4). Declare the override in `TMS34010TargetMachine.h` and add `TMS34010BitAddr.cpp` to the target's `CMakeLists.txt`.
|
||||
|
||||
- [ ] **Step 7: Run both asm tests green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang llc FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o0.c build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
Expected: PASS at both levels.
|
||||
|
||||
- [ ] **Step 8: Prove `llc`'s contract is unchanged**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m2-late-gep.ll`
|
||||
Expected: PASS — still `ADDI 24`, not `ADDI 192`.
|
||||
|
||||
- [ ] **Step 9: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
llvm/lib/Target/TMS34010/CMakeLists.txt \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-o0.c \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
git -C build/llvm-clean commit -m "tms34010: move the bit-address barrier into the clang pipeline"
|
||||
```
|
||||
|
||||
End-to-end native proof (compile → link → MAME) lands in Task 5, when
|
||||
`tms-clang` routes every harness through native clang; at this point only the
|
||||
asm-level tests can observe the pipeline directly.
|
||||
|
||||
---
|
||||
|
||||
### Task 3: State machine, idempotency and the codegen safety net
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp` (module-flag transitions)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (`addISelPrepare` legacy pass)
|
||||
- Create: `scripts/tests/m10/bitaddr-idempotent.sh`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the passes from Task 2.
|
||||
- Produces: module flag `"tms.bitaddr"` with values `1` (barriered, not lowered) and `2` (lowered/final); `class TMS34010LowerBitPtrLegacyPass : public ModulePass` in `TMS34010BitAddr.h` for the legacy codegen pipeline; `TMS34010PassConfig::addISelPrepare()` override that adds it before `TargetPassConfig::addISelPrepare()`.
|
||||
|
||||
- [ ] **Step 1: Write the failing state-1 test**
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m10-state1-lower.ll
|
||||
; RUN: llc -march=tms34010 -O0 -filetype=asm < %s | FileCheck %s
|
||||
@__tms_bitptr = external nounwind readnone
|
||||
!llvm.module.flags = !{!0}
|
||||
!0 = !{i32 4, !"tms.bitaddr", i32 1}
|
||||
define ptr @advance(ptr %p) {
|
||||
%q = call ptr @__tms_bitptr(i32 32, ptr %p)
|
||||
ret ptr %q
|
||||
}
|
||||
; CHECK-LABEL: _advance:
|
||||
; CHECK: ADDI 32, A{{[0-9]+}}
|
||||
; CHECK-NOT: CALLA
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
Expected: FAIL — the call is not lowered, so the asm contains `CALLA __tms_bitptr`.
|
||||
|
||||
- [ ] **Step 3: Implement the flag transitions**
|
||||
|
||||
`TMS34010BitPtrPass` sets `"tms.bitaddr"` to `1` when absent and does nothing when the value is `1` or `2` (module-level check first, before touching any instruction). `TMS34010LowerBitPtrPass` lowers only when the value is `1`, then sets it to `2`; with no flag it is a no-op. Write the value with `M.addModuleFlag(ModFlagBehavior::Override, "tms.bitaddr", ConstantInt::get(Type::getInt32Ty(M.getContext()), 1))` — `Override` so a second write replaces the value instead of erroring.
|
||||
|
||||
- [ ] **Step 4: Implement the codegen safety net**
|
||||
|
||||
Add `class TMS34010LowerBitPtrLegacyPass : public ModulePass` (in `TMS34010BitAddr.h`, defined in the `.cpp`) whose `runOnModule` calls `tms34010LowerBitPtr`. In `TMS34010PassConfig`, override:
|
||||
|
||||
```cpp
|
||||
void addISelPrepare() override {
|
||||
addPass(new TMS34010LowerBitPtrLegacyPass());
|
||||
TargetPassConfig::addISelPrepare();
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Run the state-1 test green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build llc clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
Expected: PASS.
|
||||
|
||||
- [ ] **Step 6: Write the end-to-end idempotency gate**
|
||||
|
||||
`scripts/tests/m10/bitaddr-idempotent.sh` (shell, `set -eu`, `ROOT=$(cd "$(dirname "$0")/../../.." && pwd)`):
|
||||
|
||||
1. Compile a pointer file at `-O0` to IR: `clang --target=tms34010 -O0 -S -emit-llvm -o run1.ll src.c`.
|
||||
2. Assert `run1.ll` contains `"tms.bitaddr", i32 2` and no `__tms_bitptr`.
|
||||
3. Re-run the same command to `run2.ll` and `cmp` — identical.
|
||||
4. `llc -march=tms34010 -O0 -filetype=asm run1.ll` and assert `ADDI 32` for `p[1]`.
|
||||
5. Compile the same source with `clang --target=tms34010 -O0 -c` and validate the object: `python3 scripts/m4/coff-check.py native.o` must exit 0 (magic and section table valid).
|
||||
|
||||
- [ ] **Step 7: Run the idempotency gate**
|
||||
|
||||
Run: `scripts/tests/m10/bitaddr-idempotent.sh`
|
||||
Expected: `m10 bitaddr idempotent: PASS`.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp \
|
||||
llvm/test/CodeGen/TMS34010/m10-state1-lower.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: make the bit-address pipeline idempotent"
|
||||
git add scripts/tests/m10/bitaddr-idempotent.sh
|
||||
git commit -m "m10: gate bit-address pipeline idempotency"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: Static-variadic guard and the `-O0` equivalence gate
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp` (guard inside the barrier pass)
|
||||
- Create: `scripts/tests/m10/legacy-tms-clang` (exact copy of the M9 script, `git show m9:scripts/tms-clang`)
|
||||
- Create: `scripts/tests/m10/equivalence.sh`
|
||||
- Test: `clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `TMS34010BitPtrPass(OptimizationLevel Level)` from Task 2.
|
||||
- Produces: the diagnostic `error: static variadic definition '<name>' loses its '...' arguments at -O2 (dead argument elimination); remove 'static' or compile with -O0` emitted at `-O2` only; `scripts/tests/m10/equivalence.sh` returning non-zero with a per-file diff list.
|
||||
|
||||
- [ ] **Step 1: Write the failing guard test**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
// RUN: not %clang_cc1 -triple tms34010-unknown-none -O2 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -emit-obj %s -o /dev/null
|
||||
// CHECK: static variadic definition 'sum' loses its '...' arguments
|
||||
static int sum(int n, ...) { int *p = &n; return p[0] + p[1]; }
|
||||
int call(void) { return sum(1, 2); }
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
Expected: FAIL — compiles silently (the guard still lives in the shell script).
|
||||
|
||||
- [ ] **Step 3: Move the guard into the barrier pass**
|
||||
|
||||
Port the `awk` guard's condition exactly: at `Level != O0`, scan each function definition; if it has `internal`/`private` linkage AND a variadic signature AND no `llvm.va_start`/`va_arg` use, report that diagnostic with the function's name and fail compilation (`report_fatal_error` or a diagnostic the driver prints as `error:`). Keep the `-O0` exemption.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
Expected: PASS (both RUN lines).
|
||||
|
||||
- [ ] **Step 5: Create the legacy reference copy**
|
||||
|
||||
Run: `git show m9:scripts/tms-clang > scripts/tests/m10/legacy-tms-clang && chmod +x scripts/tests/m10/legacy-tms-clang`
|
||||
Expected: byte-identical to the M9 script; it is the oracle for the rest of the milestone.
|
||||
|
||||
- [ ] **Step 6: Write the equivalence gate**
|
||||
|
||||
`scripts/tests/m10/equivalence.sh` compiles each corpus file twice and compares objects:
|
||||
|
||||
- native: `clang --target=tms34010 -O0 -c "$f" -o native.o`
|
||||
- legacy: `scripts/tests/m10/legacy-tms-clang -O0 -o legacy.ll "$f"` then `llc -march=tms34010 -O0 -filetype=obj legacy.ll -o legacy.o`
|
||||
- require `cmp native.o legacy.o`.
|
||||
|
||||
Corpus: every `*.c` in `scripts/m4`, `scripts/m5`, `scripts/m6` plus `scripts/tests/m5/conformance/shim.c` and `heap.c`. Run the whole set at `-O0`, then at `-O0 -g`, and report per-file pass/fail with a summary line `m10 equivalence: pass=<n> fail=<n>`.
|
||||
|
||||
Then a second phase in the same script covers `-O2`, where byte identity is not
|
||||
expected: compile a heredoc fixture at `-O2` and FileCheck its asm shapes —
|
||||
`p[1]` for `int*` (`ADDI 32`), a struct-array stride, a `switch` table load and
|
||||
an aggregate return — so the scaling pass is pinned on optimizer-created GEPs.
|
||||
|
||||
- [ ] **Step 7: Run the gate, then prove it discriminates**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh`
|
||||
Expected: `fail=0`.
|
||||
|
||||
Then temporarily run the native side at `-O2` (edit a copy, not the gate) and confirm the comparison reports failures — proving the gate is not vacuous. Revert the copy.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
git -C build/llvm-clean commit -m "tms34010: reject static variadics in the pre-optimizer barrier"
|
||||
git add scripts/tests/m10/legacy-tms-clang scripts/tests/m10/equivalence.sh
|
||||
git commit -m "m10: gate native/legacy object equivalence at -O0"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: `tms-clang` becomes a wrapper; gates move to the new seam
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tms-clang` (replace the body with the flag mapper)
|
||||
- Modify: `scripts/tests/m4/mul.sh:29`
|
||||
- Modify: `scripts/tests/m5/jr.sh:114-120`
|
||||
- Modify: `scripts/tests/m5/policy.sh:51-70`
|
||||
- Modify: `scripts/tests/m3/run.sh` (the `TMS_OPT` wrapper it installs)
|
||||
- Test: those four gates plus `scripts/tests/m10/equivalence.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the `ToolChain` defaults (Task 1) and the pipeline hooks (Task 2, Task 3).
|
||||
- Produces: `scripts/tms-clang` with the unchanged CLI (`-O0|-O2|-g|-I dir -o OUT.ll IN.c`) that maps to `clang --target=tms34010 [-O0|-O2] [-g] [-I dir] -S -emit-llvm -o OUT.ll IN.c` and no longer invokes `$TMS_OPT` or `$TMS_BITADDR`.
|
||||
|
||||
- [ ] **Step 1: Record the current gate behaviour as the baseline**
|
||||
|
||||
Run: `scripts/tests/m4/mul.sh && scripts/tests/m5/jr.sh && scripts/tests/m5/policy.sh && scripts/tests/m3/run.sh`
|
||||
Expected: all PASS on the pre-rewrite script (this is the behaviour that must survive).
|
||||
|
||||
- [ ] **Step 2: Rewrite `scripts/tms-clang`**
|
||||
|
||||
Keep the argument parser, `set -eu`, and the `TMS_CLANG`/`TMS_CLANG_EXTRA_FLAGS` overrides; delete the temp-dir pipeline, the awk guard (now in the pass), the `run_bitaddr` calls and both `opt` invocations. The whole script becomes the argument parse plus one `exec` of clang with `-S -emit-llvm`.
|
||||
|
||||
- [ ] **Step 3: Repoint the four gates**
|
||||
|
||||
- `m4/mul.sh`: replace the `grep -q -- '-replexitval=never' scripts/tms-clang` check with an assertion on the driver seam, e.g. `"$TMS_CLANG" -### --target=tms34010 -O2 -c ... 2>&1 | grep -q -- '-replexitval=never'`.
|
||||
- `m5/jr.sh`: drop the `OPT_NOREPLEXIT` wrapper and call `tms-clang -O2` directly; keep the same final assertion on the emitted IR/asm.
|
||||
- `m5/policy.sh`: replace the `opt-trace` harness with the `-###` check plus the existing final-IR/asm assertions for the switch-table and loop shapes.
|
||||
- `m3/run.sh`: same treatment for whatever `TMS_OPT` wrapper it installs.
|
||||
|
||||
Each edit must assert the same invariant, just observed at the driver seam instead of inside the script.
|
||||
|
||||
- [ ] **Step 4: Run the four gates green**
|
||||
|
||||
Run: `scripts/tests/m4/mul.sh && scripts/tests/m5/jr.sh && scripts/tests/m5/policy.sh && scripts/tests/m3/run.sh`
|
||||
Expected: all PASS, with the `-replexitval=never` policy still asserted.
|
||||
|
||||
- [ ] **Step 5: Prove native end-to-end**
|
||||
|
||||
With `tms-clang` now mapping to clang, the conformance harness compiles with
|
||||
native clang. Write a small pointer program and run it through the harness:
|
||||
|
||||
```sh
|
||||
cat > /tmp/opencode/m10-ptr.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
int a[3] = {10, 20, 30};
|
||||
int *p = a;
|
||||
printf("%d %d\n", p[2], (int)(p + 2 - p));
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
scripts/tests/m5/conformance/run.sh --id m10-ptr --mode native \
|
||||
--expect 'status=0;stdout=30 2\n' /tmp/opencode/m10-ptr.c
|
||||
```
|
||||
|
||||
Expected: `PASS m10-ptr` (status 0, stdout `30 2`). The full breadth proof is the
|
||||
suite in Task 6, which now also compiles through native clang.
|
||||
|
||||
- [ ] **Step 6: Re-run the equivalence gate against the new wrapper**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh`
|
||||
Expected: `fail=0` — the oracle copy is unchanged, so this proves the wrapper
|
||||
produces the same IR the old script did.
|
||||
|
||||
- [ ] **Step 7: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/tms-clang scripts/tests/m4/mul.sh scripts/tests/m5/jr.sh \
|
||||
scripts/tests/m5/policy.sh scripts/tests/m3/run.sh
|
||||
git commit -m "m10: tms-clang maps to clang; gates assert the driver seam"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Full gate sweep, docs, patch export, promote `m10`
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md` (M10 status, `tms-clang` description, gate list)
|
||||
- Modify: `build/llvm-clean/TMS34010.md` (M10 section, pipeline description)
|
||||
- Modify: `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (M10 acceptance met)
|
||||
- Create: `patches/llvm/0005-tms34010-toolchain.patch`
|
||||
- Test: the full M0–M10 gate list
|
||||
|
||||
- [ ] **Step 1: Export the driver patch**
|
||||
|
||||
Run: `git -C build/llvm-clean diff m9..m10 -- clang/ > patches/llvm/0005-tms34010-toolchain.patch`
|
||||
Expected: the patch contains only `ToolChains/TMS34010.{h,cpp}`, `ToolChains/CMakeLists.txt`, `Driver.cpp` and the driver test.
|
||||
|
||||
- [ ] **Step 2: Run the compiler tests**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010 build/llvm-clean/llvm/test/MC/TMS34010 build/llvm-clean/clang/test/CodeGen/TMS34010 build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: 129 TMS34010 lit tests plus the new ones, and 5 clang tests plus the new ones, all PASS.
|
||||
|
||||
- [ ] **Step 3: Run the M9/M10 behaviour gates**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh && scripts/tests/m10/bitaddr-idempotent.sh && tools/tms-bitaddr/tests/run.sh && scripts/tests/m9/dwarf-ranges.sh && scripts/tests/m8/dwarf-multi.sh && scripts/tests/m7/debug.sh`
|
||||
Expected: all PASS; DWARF output unchanged.
|
||||
|
||||
- [ ] **Step 4: Run the full suite and the divide measurement**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus all --work build/m10-bare`
|
||||
Expected: `all total=1912 pass=1618 skip=294 fail=0 crash=0`.
|
||||
Every row now compiles through native clang, because `tms-clang` is the thin
|
||||
wrapper — so this run is the breadth proof for the new pipeline, not just a
|
||||
regression check.
|
||||
Run: `scripts/tests/m7/i64div.sh`
|
||||
Expected: `fast=88 slow=3302 wide=221 div32=120`, ratios 37.5/14.9/1.8, all four checksums exact.
|
||||
|
||||
- [ ] **Step 5: Run the remaining M0–M8 gates**
|
||||
|
||||
Run the serial list from `README.md`'s gate section (M0, M2–M8 native/object/JR/MMTM/policy/robust/spike/i64/float/varargs/bitfield/aggregate/runtime, the curated c-torture and c-testsuite tiers, `hardware.sh` → `HARDWARE: DEFERRED`).
|
||||
Expected: every gate PASS; hardware DEFERRED.
|
||||
|
||||
- [ ] **Step 6: Update the docs**
|
||||
|
||||
Record in `README.md`, `TMS34010.md` and the spec: M10 complete, `clang --target=tms34010 -c` now correct with no flags, the ToolChain defaults, the pipeline hooks and state flag, the `-O0` byte-identity result, the new gates, and the M10/M11 boundary (M11 = CRT/headers/`libtms.a`/sysroot/link job).
|
||||
|
||||
- [ ] **Step 7: Commit, review, push, promote**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "docs: record the M10 native pipeline"
|
||||
git add README.md docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md \
|
||||
patches/llvm/0005-tms34010-toolchain.patch
|
||||
git commit -m "m10: document the native clang pipeline"
|
||||
```
|
||||
|
||||
Then run the M10 whole-branch review. Only after it is clean: push `m10` in both repositories, set it as the default branch on both remotes, and update the README's default-branch language. `m9` stays as the previous snapshot.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M10 ends with `clang --target=tms34010 -O2 -c` correct for pointer code and for ordinary loops, `-O0` objects byte-identical to the M9 path, and every existing gate green. M11 (Phase 3: CRT, headers, `libtms.a`, sysroot, `tms-link` link job) is planned separately once M10 is promoted, because it extends the `ToolChain` file created in Task 1.
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
# TMS34010 M9 — Conformance Classes, Debug Depth and Performance 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:** Raise the full-suite pass rate with the highest-value remaining classes, close the M8 DWARF/linker caveats, add a measured 64/32 divide fast path, and close M9 with the hardware status and boundary.
|
||||
|
||||
**Architecture:** Vector `.data` becomes another recursive aggregate in both the raw and object emitters; the target supplies an inline-asm register resolver for the A-register classes. The linker gains a form-aware DWARF input check (or walker) plus `.debug_rnglists` merging. The i64 outliner adds a single-DIVU 64/32 path when the quotient fits. The bare conformance tier and the full-loader list remain the two-tier harness.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m9`), `tms-clang`, `llc`, `tms-link`, TI COFF, the dwt loader, MAME, `llvm-dwarfdump`, Python 3, the M8 two-tier harness and pins.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M9.1–M9.4); the M8 README/ledger boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- M9 baseline: compiler `m8`/`e3ad91edd130`, project `m8`/`f340d74`; work on `m9`. The default is promoted to `m9` only after the final review.
|
||||
- Keep every M2–M8.4 gate green, the TI all-stack ABI, the asm/GSPLNK oracle, the native loader contract, and the two-tier harness.
|
||||
- `M5_CONFORMANCE_BARE=1` remains the conformance default; full-loader exceptions need a reason in `full-suite.full-loader`.
|
||||
- Vector and inline-asm changes must be tested at `-O0` and `-O2`; unsupported shapes stay loud.
|
||||
- DWARF merging must stay section-relative and stripped-image compatible; single-TU output remains byte-compatible with M8.
|
||||
- Full-suite accounting remains one row per file; no crash/unclassified result; skips always carry a reason.
|
||||
- No push until the M9 final review is clean; then push `m9`, promote it, and update the README.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Vector bytes:** exact element order/padding for integer/fp vectors, packed widths, aggregate zero, raw and object paths; no over-read/write; existing scalar/record output unchanged.
|
||||
2. **Inline asm:** constraint mapping for i16/i32, clobbers, output/input ties, unsupported constraints loud; `-O0`/`-O2`.
|
||||
3. **DWARF:** form walker completeness, rnglists merging, offset rehoming, single-TU compatibility, dwarfdump and stripped MAME.
|
||||
4. **Divide:** 64/32 condition and quotient-fit, magnitudes/sign, `INT64_MIN`, divide-by-zero, measured frames/checksums, no M8 path regression.
|
||||
5. **No M2–M8.4 regression**, two-tier counts, and the final boundary.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Vector `.data` and inline-asm `r` constraints
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010AsmPrinter.cpp` (raw/object vector initializers)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelLowering.{h,cpp}` (inline-asm register resolver)
|
||||
- Create/modify: `llvm/test/CodeGen/TMS34010/m9-vector-data.ll`, `m9-inline-asm.ll`
|
||||
- Test: `scripts/tests/m7/data.sh`, the full-suite vector/inline-asm rows, M6/M5 gates
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the recursive `.data` emitter and the A-register classes (`ARegs`, `ARegsEven`, …).
|
||||
- Produces: exact vector initializer bytes (integer/fp element vectors, aggregate zero, byte-multiple only) in raw and object modes; `getRegForInlineAsmConstraint` mapping `r`/`=r` (and documented accepted subsets) to the target register classes; unsupported vectors/constraints loud.
|
||||
|
||||
- [ ] **Step 1: Write failing tests.** `m9-vector-data.ll` with `<2 x i32>`, `<4 x i16>`, an fp vector if supported, and a vector zero; `data.sh` raw/object bytes. `m9-inline-asm.ll` with `r` input/output at `-O0`/`-O2`. Current emitter rejects vectors; inline asm fails to allocate.
|
||||
- [ ] **Step 2: Run red.**
|
||||
- [ ] **Step 3: Implement.** Vector constants as ordered element bytes with exact alloc size; `ConstantAggregateZero` vector zero; keep unsupported widths/types loud. Implement the inline-asm resolver and clobber handling; reject unsupported constraints with a named error.
|
||||
- [ ] **Step 4: Run green.** Lit, data.sh, and the affected full-suite rows (bare/full-loader as appropriate); record flips.
|
||||
- [ ] **Step 5: Commit** (compiler + project gates/tests).
|
||||
|
||||
### Task 2: DWARF form walker and `.debug_rnglists`
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tms-link`, `tools/tms-link/tmscoff.py`
|
||||
- Create: `scripts/tests/m9/dwarf-ranges.sh`, fixtures
|
||||
- Test: `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`, `llvm-dwarfdump`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: M8's multi-TU debug merge and the current CU-abbrev-only raw patch.
|
||||
- Produces: a form-aware check/walker that rejects (or correctly patches) unrelocated section-relative fields, and `.debug_rnglists` concatenation/rehoming with a fixture; single-TU bytes unchanged.
|
||||
|
||||
- [ ] **Step 1: Write failing tests.** A synthetic object with an unrelocated `DW_AT_stmt_list`/`strp` (or a documented rejection), and a multi-TU `.debug_rnglists` fixture; current code silently assumes relocations.
|
||||
- [ ] **Step 2: Run red.**
|
||||
- [ ] **Step 3: Implement** the form walk (or input gate) and rnglists merge; keep the loud paths.
|
||||
- [ ] **Step 4: Run green.** `dwarf-ranges.sh`, `dwarf-multi.sh`, `m7/debug.sh`, stripped MAME.
|
||||
- [ ] **Step 5: Commit.**
|
||||
|
||||
### Task 3: 64/32 single-DIVU fast path
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (`lowerDivRem`)
|
||||
- Create/modify: `llvm/test/CodeGen/TMS34010/m9-i64div-64-32.ll`
|
||||
- Modify: `scripts/m7/i64div-perf.c`, `scripts/tests/m7/i64div.sh`
|
||||
- Test: `scripts/tests/m6/i64.sh`, `m6/runtime.sh`, `i64div.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M8 fast/wide/loop CFG and the target `DIVU` 64-bit pair.
|
||||
- Produces: when the divisor's high word is zero and the quotient fits 32 bits (e.g. `hi(N) < D`), a single even-destination `DIVU` fast path; otherwise the M8 two-DIVU/loop path. Signed normalization and fixups unchanged.
|
||||
|
||||
- [ ] **Step 1: Write failing tests.** A 64/32 case with `hi(N) < D` requiring one `DIVU`; the M8 wide cases still two; perf phase measured.
|
||||
- [ ] **Step 2: Run red.**
|
||||
- [ ] **Step 3: Implement** the single-DIVU branch; preserve `INT64_MIN`, divide-by-zero UB and signs.
|
||||
- [ ] **Step 4: Run green.** Lit, M6 i64/runtime, i64div measurements; record frames/checksums.
|
||||
- [ ] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Hardware status, final M9 docs, full gates, review, promote
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, spec (M9 status)
|
||||
- Test: the full M0–M9 list
|
||||
|
||||
- [ ] **Step 1: Hardware.** Run `VT1200_HOST=… scripts/tests/m7/hardware.sh` if a unit is available; otherwise keep `HARDWARE: DEFERRED`.
|
||||
- [ ] **Step 2: Docs.** Record M9.1/M9.2/M9.3 results, flips, perf, the final two-tier counts and the M9/M10 boundary; update the gate commands.
|
||||
- [ ] **Step 3: Gates and review.** Run the full serial list, commit, final whole-branch review, then push `m9`.
|
||||
- [ ] **Step 4: Promote.** Set `m9` as the repository default on both remotes (per the standing policy), update the README/docs default language, and verify `refs/heads/m9` is HEAD.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M9 closes the highest-value conformance classes, the DWARF future-producer and rnglists caveats, and adds a measured 64/32 divide fast path. The remaining classes (`blockaddress`, nested functions, VLAs, sret/aggregate/variadic/float returns, libm), broader hardware/link depth and any further performance work are M10. The compiler repo is canonical; the project holds the linker, harness, plans and gates.
|
||||
@@ -0,0 +1,311 @@
|
||||
# TMS34010 M11 (Phase 3) — Conventional Toolchain Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Make `clang --target=tms34010 hello.c -o hello` build a loader-valid image that `tms-run` can execute — CRT, headers and `libtms` found through a resource-directory sysroot, linked by `tms-link` through a real driver link job, with no wrapper and no project variables.
|
||||
|
||||
**Architecture:** `sdk/` holds the sources (CRT IR, shim, heap, headers, committed vendor archives); `scripts/tms-sdk` builds `crt0.o` with `llc` and `libtms.a` with `llvm-ar`, then installs everything plus the `tms-link`/`tmscoff.py` pair into `<resource-dir>/tms34010-unknown-none/{include,lib,bin}`. `TMS34010ToolChain` grows sysroot discovery and a `TMS34010Linker` Tool that maps driver flags onto `tms-link`. `tms-link` must emit loader-valid COFF on its own, because the production path no longer runs `coff-check.py --repair`.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`), clang driver `ToolChains/TMS34010.*`, `llc`, `llvm-ar`, `tools/tms-link` (Python + `tmscoff.py`), TMS34010 GSPA assembly, TI-COFF, MAME + the dwt loader, shell gates.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-18-tms34010-m11-conventional-toolchain-design.md` (§8 is this milestone; §11 is the roadmap, not this plan).
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Baseline: project `m10`/`a7bbefa`, compiler `m10`/`7fc2ac37b5ad`. Cut `m11` in both repos before Task 1; never force-push.
|
||||
- LLVM/Clang stay pinned at 23.1.5. All driver work stays inside `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` plus its two registration lines; patch `0005` grows, nothing else.
|
||||
- The driver must never bake in a checkout path: discovery is `--tms-sysroot=`, then `--sysroot`/`-isysroot`, then `<resource-dir>/tms34010-unknown-none`.
|
||||
- M10's contract must not regress: `clang --target=tms34010 -c` stays correct at `-O0`/`-O2`, and `-O0` objects stay byte-identical to the M9 path (`scripts/tests/m10/equivalence.sh` is the gate).
|
||||
- The CRT/runtime contract is fixed: status `01B00000`, out-len `01B00020`, magic `01B00040` = `0x434F4E46`, err-len `01B00060`, output `01B10000`, error `01B30000` (16 KiB each), `_cstack` 32768 bits (4096 bytes) at 16-bit alignment, `_conformance_argv` 64 bits, `_start` entry; `libtms`'s `exit`/`abort` publish and spin.
|
||||
- Link defaults: `--entry _start --text 018A0000 --bss 01A00000 --prog-len 40000h --ram-len 80000h`.
|
||||
- `coff-check.py --repair` leaves the production path; `tms-link` emits valid images unaided.
|
||||
- Vendor `flib.lib`/`rts.lib` are committed and gated against freshly extracted copies.
|
||||
- Existing gates stay green: lit suites, the serial M0–M10 list, the two-tier suite **1,618 pass / 294 skip / 0 fail / 0 crash**, i64div `88/3302/221/120` with the same four checksums, `HARDWARE: DEFERRED`.
|
||||
- No force-push, no default-branch change before the whole-branch review.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **A fresh shell after one setup command** — `clang --target=tms34010 hello.c -o hello` must work with no `M4_*`, `TMS_*`, `PATH` or include entries, from a directory outside the repo (Task 5).
|
||||
2. **Link-reduction knobs** — `-nostdlib`, `-nostartfiles`, `-nodefaultlibs` must each drop exactly their part and still link (Task 4).
|
||||
3. **Missing pieces are diagnosed, not guessed** — no sysroot, no installed `tms-link`, no `python3` must each name the cause and `scripts/tms-sdk`, never a raw linker error (Task 4).
|
||||
4. **CRT contract** — argv vector, 4 KiB stack, result-block addresses, `_start`, and `exit`/`abort` publishing must survive the assembly rewrite, because `tms-run` and the harness read them (Task 2).
|
||||
5. **M10 is untouched** — `clang -c` at `-O0`/`-O2` and the `-O0` byte-identity gate stay exactly as they were; the link work must not perturb codegen (Task 6).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: `tms-link` emits loader-valid images unaided
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tmscoff.py` (`write_coff`, only if the header is defective)
|
||||
- Modify: `tools/tms-link/tms-link` (only if the writer needs input)
|
||||
- Modify: `tools/tms-link/tests/{run.sh,linktest.py}`
|
||||
- Test: a new case in `tools/tms-link/tests/`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `tmscoff.write_coff(path, sections, symbols, *, entry, text_size, data_size, …)` and the existing `scripts/m4/coff-check.py [--repair] [--entry HEX] FILE` validator.
|
||||
- Produces: whatever the linker emits today must pass `coff-check.py` **without** `--repair`, including an odd-length `.bss`.
|
||||
|
||||
- [ ] **Step 1: Write the failing gate case**
|
||||
|
||||
Add to `tools/tms-link/tests/run.sh` a case that links a small object (reuse an existing fixture) and then runs
|
||||
`python3 scripts/m4/coff-check.py OUT.coff` expecting exit 0, plus a fixture whose `.bss` length is odd (e.g. one 8-bit symbol) checked the same way.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `tools/tms-link/tests/run.sh`
|
||||
Expected: FAIL on the new case with the validator's magic/size complaint (or on the odd-`.bss` case).
|
||||
|
||||
- [ ] **Step 3: Fix the writer**
|
||||
|
||||
If the file/optional header or section table is defective, fix `write_coff`. If an odd `.bss` is emitted unrounded, round only `.bss` to a whole 16-bit word, as `coff-check.py --repair` does. Do not change `.text`/`.data` contents, relocation handling, or the entry point.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `tools/tms-link/tests/run.sh`
|
||||
Expected: PASS, including the two new cases.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add tools/tms-link/tmscoff.py tools/tms-link/tms-link tools/tms-link/tests/
|
||||
git commit -m "m11: tms-link emits loader-valid COFF without repair"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: `sdk/crt0.ll` — the CRT as IR with a naked `_start`
|
||||
|
||||
**Files:**
|
||||
- Create: `sdk/crt0.ll`
|
||||
- Create: `scripts/tests/m11/crt.sh`
|
||||
- Test: `scripts/tests/m11/crt.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `llc -march=tms34010 -filetype=obj`, `tools/tms-link/tms-link`, `scripts/tms-run`, and the result-block contract in Global Constraints.
|
||||
- Produces: `sdk/crt0.ll`, a `naked` `_start` built by `llc`, defining `_start`, `_conformance_name` (12 bytes, `"conformance\0"`), `_conformance_argv` (64 bits), `_cstack` (32768 bits, 16-bit alignment), and preserving the register/stack setup of `scripts/tests/m5/conformance/entry.asm`.
|
||||
|
||||
- [ ] **Step 1: Write the failing contract test**
|
||||
|
||||
`scripts/tests/m11/crt.sh` builds `sdk/crt0.ll` with `llc`, compiles a heredoc `main.c` (`int main(int argc, char **argv) { printf("%d %s\n", argc, argv[0]); return 7; }`), links them with `tms-link` (`--entry _start --text 018A0000 --bss 01A00000 --prog-len 40000h --ram-len 80000h`) plus the existing conformance `shim.o`, and runs `scripts/tms-run`. Expected: status 7, stdout `1 conformance`.
|
||||
|
||||
- [ ] **Step 2: Record the red state**
|
||||
|
||||
Run: `scripts/tests/m11/crt.sh`
|
||||
Expected: FAIL — `sdk/crt0.ll` does not exist. Also record the known fact that `llvm-mc` emits ELF for this triple (and rejects `scripts/tests/m5/conformance/entry.asm`'s `.bss` operands, `h`-suffixed hex, `.even`), so this is an IR rewrite built with `llc`, not a copy.
|
||||
|
||||
- [ ] **Step 3: Write `sdk/crt0.ll`**
|
||||
|
||||
Express the CRT as IR (`sdk/crt0.ll`) with a `naked` `@start` whose single inline-asm block carries the instruction sequence, plus module globals for `_conformance_name`, `_conformance_argv` and `_cstack`. Keep the contract: `setf 16,1,0`/`setf 32,0,1`, clear the four result cells, point `A14` at `_cstack` and `A13` at it, build `argv = { _conformance_name, NULL }`, push `argv` then `1`, `calla _main`, store `A8` as the status and `0x434F4E46` as the magic, `rets`. Build it with `llc -march=tms34010 -filetype=obj`: `llvm-mc` emits ELF for this triple, so only CodeGen reaches the TI-COFF writer.
|
||||
|
||||
- [ ] **Step 4: Run the contract test**
|
||||
|
||||
Run: `scripts/tests/m11/crt.sh`
|
||||
Expected: `m11 crt: PASS` (status 7, stdout `1 conformance`).
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add sdk/crt0.ll scripts/tests/m11/crt.sh
|
||||
git commit -m "m11: add the llc CRT with the conformance runtime contract"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: `sdk/` sources and `scripts/tms-sdk`
|
||||
|
||||
**Files:**
|
||||
- Create: `sdk/include/` (moved from `scripts/tests/m5/conformance/include`, 10 headers)
|
||||
- Create: `sdk/shim.c`, `sdk/heap.c` (moved from `scripts/tests/m5/conformance/`)
|
||||
- Create: `sdk/lib/flib.lib`, `sdk/lib/rts.lib` (committed copies of `build/m6-sdk/{flib,rts}.lib`)
|
||||
- Create: `scripts/tms-sdk`
|
||||
- Create: `scripts/tests/m11/sdk.sh`
|
||||
- Modify: `scripts/tests/m5/conformance/run.sh` (point at `sdk/include`)
|
||||
- Test: `scripts/tests/m11/sdk.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `sdk/crt0.ll` (Task 2), `llc`, `clang --target=tms34010 -c`, `llvm-ar`, `tools/tms-link/{tms-link,tmscoff.py}`.
|
||||
- Produces: `scripts/tms-sdk [--sysroot DIR]`, which installs `<sysroot>/{include,lib,bin}` with `include/*.h`, `lib/{crt0.o,libtms.a,flib.lib,rts.lib}`, `bin/{tms-link,tmscoff.py}`. Default sysroot: `$(clang -print-resource-dir)/tms34010-unknown-none`.
|
||||
|
||||
- [ ] **Step 1: Write the failing gate**
|
||||
|
||||
`scripts/tests/m11/sdk.sh` runs `scripts/tms-sdk --sysroot "$TMP/sysroot"` and asserts: the seven expected layout entries exist; `llvm-ar t libtms.a` lists `shim.o` and `heap.o`; a second run is idempotent; `cmp` of `crt0.o` against a fresh `llc` build is identical; `cmp` of `libtms.a` against a fresh `llvm-ar rcsD` build is identical; `sdk/lib/{flib,rts}.lib` match `build/m6-sdk/{flib,rts}.lib` when those exist.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m11/sdk.sh`
|
||||
Expected: FAIL — `scripts/tms-sdk` does not exist.
|
||||
|
||||
- [ ] **Step 3: Move the sources and commit the archives**
|
||||
|
||||
Move the headers, `shim.c` and `heap.c` into `sdk/`; copy `build/m6-sdk/{flib,rts}.lib` to `sdk/lib/`; update the conformance runner and any harness path that referenced `scripts/tests/m5/conformance/include` so exactly one copy exists.
|
||||
|
||||
- [ ] **Step 4: Implement `scripts/tms-sdk`**
|
||||
|
||||
Build `crt0.o` with `llc`, `shim.o`/`heap.o` with `clang --target=tms34010 -O2 -c`, `libtms.a` with `llvm-ar rcsD`, then install the layout above (copying the linker pair and marking `tms-link` executable). Rebuild `llvm-ar` if missing: `ninja -C build/llvm-clean-build llvm-ar`.
|
||||
|
||||
- [ ] **Step 5: Run it green**
|
||||
|
||||
Run: `scripts/tests/m11/sdk.sh`
|
||||
Expected: `m11 sdk: PASS`.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git add sdk scripts/tms-sdk scripts/tests/m11/sdk.sh scripts/tests/m5/conformance/run.sh
|
||||
git commit -m "m11: add the sdk sources and the sysroot installer"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: ToolChain sysroot discovery and the link job
|
||||
|
||||
**Files:**
|
||||
- Modify: `clang/lib/Driver/ToolChains/TMS34010.h`, `TMS34010.cpp`
|
||||
- Create: `clang/test/Driver/TMS34010-link.c`
|
||||
- Test: that driver test plus `clang/test/Driver/tms34010-defaults.c` (unchanged)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the installed sysroot from Task 3 and `tms-link`'s CLI (`--entry --text --bss --prog-len --ram-len --map --keep-debug -L -l`).
|
||||
- Produces: `class TMS34010Linker final : public Tool` with `ConstructJob`; `TMS34010ToolChain::buildLinker()`; sysroot-derived include/lib paths; `--tms-linker=PATH`; `-nostartfiles`/`-nodefaultlibs`/`-nostdlib`; `-g` → `--keep-debug`; `-Wl,` passthrough.
|
||||
|
||||
- [ ] **Step 1: Write the failing driver tests**
|
||||
|
||||
`clang/test/Driver/TMS34010-link.c` (model on `avr-link-nostdlib-nodefaultlibs.c`), using `-###`:
|
||||
- default link: `tms-link`, `--entry _start`, `--text 018A0000`, `--bss 01A00000`, the objects, `libtms.a`, `flib.lib`, `rts.lib`;
|
||||
- `-nostdlib`: none of `crt0.o`, `libtms.a`, `flib.lib`, `rts.lib`;
|
||||
- `-nostartfiles`: no `crt0.o`, libraries still present;
|
||||
- `-nodefaultlibs`: `crt0.o` present, no libraries;
|
||||
- `-g`: `--keep-debug`;
|
||||
- `-Wl,--prog-len=80000h`: appears verbatim;
|
||||
- `--tms-linker=/tmp/x`: that path replaces the sysroot linker;
|
||||
- `-l tms`: accepted, and `libtms.a` appears once;
|
||||
- a nonexistent `--tms-sysroot=/nope` and a sysroot without `bin/tms-link`: each produces the named "run scripts/tms-sdk" diagnostic, not a linker error;
|
||||
- `-c`: no link job at all.
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/TMS34010-link.c`
|
||||
Expected: FAIL — clang emits no link job for this target.
|
||||
|
||||
- [ ] **Step 3: Implement discovery and the linker Tool**
|
||||
|
||||
Search order `--tms-sysroot=`, `--sysroot`/`-isysroot`, `<resource-dir>/tms34010-unknown-none`. Add `<sysroot>/include` as a system include and `<sysroot>/lib` as a library path, without touching the M10 freestanding defaults. Implement `ConstructJob` with the argument order in the spec §8.2, and make a missing sysroot, missing `tms-link` or missing `python3` a `Diag` naming `scripts/tms-sdk` (check `python3` with `llvm::sys::findProgramByName`).
|
||||
|
||||
- [ ] **Step 4: Run them green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/TMS34010-link.c build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: PASS for both files.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add clang/lib/Driver/ToolChains/TMS34010.h \
|
||||
clang/lib/Driver/ToolChains/TMS34010.cpp clang/test/Driver/TMS34010-link.c
|
||||
git -C build/llvm-clean commit -m "tms34010: add sysroot discovery and the tms-link job"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: Single-command build end to end
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m11/e2e.sh`
|
||||
- Test: `scripts/tests/m11/e2e.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `scripts/tms-sdk` (Task 3), the link job (Task 4), `scripts/tms-run`.
|
||||
- Produces: the acceptance gate for the milestone's headline command.
|
||||
|
||||
- [ ] **Step 1: Write the failing gate**
|
||||
|
||||
`scripts/tests/m11/e2e.sh` (run from a temp directory outside the repo, with `env -u M4_WORK -u TMS_CLANG …`): install the sysroot into a temp dir with `scripts/tms-sdk --sysroot`, export `CLANG` and pass `--tms-sysroot` once, then:
|
||||
- `clang --target=tms34010 hello.c -o hello` (a heredoc `hello.c` printing one line) and `tms-run hello` → status 0, stdout matches, and `hello.map` exists;
|
||||
- a two-TU build (`add.c` + `main.c`) → `add=42`;
|
||||
- `-c`, `-S`, `-E` produce an object, assembly and preprocessed source respectively;
|
||||
- `-O0` and `-O2` both run correctly;
|
||||
- `-g` links and the image keeps `.debug_*` while a default link is stripped;
|
||||
- `-nostdlib` with a user `_start` links;
|
||||
- `clang -### --target=tms34010 hello.c -o hello` contains no checkout path.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m11/e2e.sh`
|
||||
Expected: FAIL at the first link with the missing-sysroot/link-job diagnostic.
|
||||
|
||||
- [ ] **Step 3: Fix what the gate exposes**
|
||||
|
||||
Only driver/ToolToolchain or `tms-sdk` changes belong here; if a defect is in `tms-link`, note it and fix it with its own test.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `scripts/tests/m11/e2e.sh`
|
||||
Expected: `m11 e2e: PASS`.
|
||||
|
||||
- [ ] **Step 5: Verify one existing harness program and the compatibility alias**
|
||||
|
||||
Run the M4 harness with `M4_NATIVE=1 M4_LINKER=tms-link` on one program (e.g. `scripts/m4/unsigned.c`) and confirm its MAME markers still pass. Then run `scripts/tms-cc hello.c -o hello` and `scripts/tms-run hello` to confirm the Phase 1 alias still works after the sysroot change.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/tests/m11/e2e.sh
|
||||
git commit -m "m11: gate the single-command build end to end"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Docs, full sweep, patch export, promote `m11`
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md`
|
||||
- Modify: `patches/llvm/0005-*.patch`
|
||||
- Test: the full M0–M11 gate list
|
||||
|
||||
- [ ] **Step 1: Re-export the driver patch**
|
||||
|
||||
Run: `git -C build/llvm-clean diff m9..m11 -- clang/ > patches/llvm/0005-tms34010-toolchain.patch`
|
||||
Expected: only `ToolChains/TMS34010.{h,cpp}`, the two registration edits and the M10/M11 clang tests.
|
||||
|
||||
- [ ] **Step 2: Run the compiler and toolchain tests**
|
||||
|
||||
Run: lit for `llvm/test/CodeGen/TMS34010`, `llvm/test/MC/TMS34010`, `clang/test/CodeGen/TMS34010`, `clang/test/Driver/TMS34010*`; `tools/tms-link/tests/run.sh`; `tools/tms-bitaddr/tests/run.sh`.
|
||||
Expected: all PASS.
|
||||
|
||||
- [ ] **Step 3: Run the M11 gates and the M10 regressions**
|
||||
|
||||
Run: `scripts/tests/m11/{sdk,crt,e2e}.sh`, `scripts/tests/m10/equivalence.sh` (`pass=46 fail=0`), `scripts/tests/m10/bitaddr-idempotent.sh`, `scripts/tests/m9/dwarf-ranges.sh`, `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`.
|
||||
Expected: all PASS.
|
||||
|
||||
- [ ] **Step 4: Run the suite and the divide measurement**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus all --work build/m11-final`
|
||||
Expected: `all total=1912 pass=1618 skip=294 fail=0 crash=0`.
|
||||
Run: `scripts/tests/m7/i64div.sh`
|
||||
Expected: `88/3302/221/120`, ratios 37.5/14.9/1.8, the same four checksums.
|
||||
|
||||
- [ ] **Step 5: Run the remaining M0–M10 gate list**
|
||||
|
||||
The serial list from `README.md`'s gate section, including `hardware.sh` → `HARDWARE: DEFERRED`.
|
||||
Expected: every gate PASS.
|
||||
|
||||
- [ ] **Step 6: Update the docs**
|
||||
|
||||
Record M11 complete: the single command, the sysroot layout and `scripts/tms-sdk`, `python3` as a link-time dependency, the link-reduction knobs, the CRT dialect rewrite and its preserved contract, the `tms-link` validity fix, `tms-cc` as a compatibility alias, and the M11/M12 boundary with a pointer to the roadmap (§11 of the design).
|
||||
|
||||
- [ ] **Step 7: Commit, review, push, promote**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "docs: record the M11 toolchain"
|
||||
git add README.md docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md \
|
||||
patches/llvm/0005-tms34010-toolchain.patch
|
||||
git commit -m "m11: document the conventional toolchain"
|
||||
```
|
||||
|
||||
Then run the whole-branch review, and only when it is clean: push `m11` in both repositories, set it as the default on both remotes, and update the README's default-branch wording. `m10` stays as the previous snapshot.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M11 ends with `clang --target=tms34010 hello.c -o hello` working from a clean shell after one `scripts/tms-sdk`, every M0–M10 gate still green, and the suite unchanged at 1,618 passes. M12 (conformance classes) is the next milestone per the roadmap; it gets its own design and plan.
|
||||
@@ -574,6 +574,288 @@ 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. At M8 the three-phase gate measured the 64/32 i64 divide path at
|
||||
**218** frames versus **2,440** for the 64-step loop (11.2×) and the fits-32
|
||||
path at **87** (28.0×), status `600D600D`, checksums
|
||||
`000000011E6F9AB4`/`00000000007512AE`/`00025AF70AF974E0`; M9.3 makes the gate
|
||||
four-phase, narrows the wide input to force the two-`DIVU` helper, and re-pins
|
||||
the wide checksum (see the M9 acceptance). 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 closed vector
|
||||
`.data` and inline-asm `r`, the DWARF future-producer/`.debug_rnglists`
|
||||
caveats and the 64/32 divide path; M10 owns the remaining classes
|
||||
(`blockaddress`, vector runtime, inline-asm memory 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.
|
||||
|
||||
### M9 — conformance classes, debug depth, performance
|
||||
|
||||
M9 builds on the M8 baseline (`m8`, default) and uses the same plan,
|
||||
subagent-driven loop, review and push discipline. Work is on `m9`; the default
|
||||
is promoted to `m9` only after the final review, per the repository policy.
|
||||
|
||||
- **M9.1 — conformance classes.** Remove the highest-value remaining M8 skips:
|
||||
vector `.data` initializers (integer/fp vector constants emitted as their
|
||||
exact element bytes in the raw and object paths) and inline-asm `r`/`=r`
|
||||
register constraints (map the target's A-register classes; reject
|
||||
unsupported constraints loudly). The affected full-suite rows must flip to
|
||||
pass and be recorded; `blockaddress`, nested functions, VLAs, sret/
|
||||
aggregate/variadic/float returns and libm remain explicit M10 boundaries.
|
||||
- **M9.2 — debug/linker depth.** Replace the M8 raw-offset assumption with a
|
||||
form-aware DWARF walker (or an input gate that rejects any unrelocated
|
||||
section-relative field), add a `.debug_rnglists` fixture and merged-range
|
||||
validation, and keep the single-TU output byte-compatible. The default load
|
||||
image stays stripped; `--keep-debug` remains the tool image.
|
||||
- **M9.3 — performance.** Add a single `DIVU` 64/32 fast path when the divisor
|
||||
fits 32 bits and the quotient fits (or another equally justified path),
|
||||
measured against the M8 64/32 two-DIVU path and the 64-step loop. The bare
|
||||
conformance tier remains the default; no test-accounting regression.
|
||||
- **M9.4 — hardware and close-out.** Run the real VT1200 harness when the unit
|
||||
is available; otherwise keep `HARDWARE: DEFERRED` explicit. Produce the final
|
||||
M9 docs/counts/limitations and the M9/M10 boundary.
|
||||
|
||||
M9 acceptance (met, M9 complete): vector `.data` and inline-asm `r`/`=r`
|
||||
constraints are fixed with **22** recorded flips (20 inline-asm `r`, `simd-5`
|
||||
and `pr123625-2`), and the five remaining candidates stay curated with
|
||||
corrected reasons (i64 `r` pair, timeout, two vector runtime aborts, memory
|
||||
operand). Lit is **129/129** (125 CodeGen + 4 MC). The multi-object
|
||||
`--keep-debug` path walks every form and refuses pre-v5 producers and any
|
||||
unrelocated section-relative field loudly; the two-TU `.debug_rnglists`
|
||||
fixture and a real `-O2 -g` producer both validate with `llvm-dwarfdump`, the
|
||||
single-TU bytes keep the M8 layout, and the stripped image still runs. The
|
||||
four-phase i64 gate measures fast **88**, slow **3,302**, wide **221** and
|
||||
div32 **120** frames — **37.5×** (fast) and **14.9×** (wide) versus the loop,
|
||||
and **1.8×** for div32 versus the two-DIVU wide phase — with
|
||||
status `600D600D` and checksums `000000011E6F9AB4`/`00000000007512AE`/
|
||||
`F56810CFEDA9D656`/`00002C61C63842EE`; the new path is correct for
|
||||
signed/unsigned, divide-by-zero UB, and `INT64_MIN` (which never fits 32 bits:
|
||||
it keeps the two-step helper for a divisor of at most `2^31` and takes the
|
||||
single-`DIVU` path for a divisor in `(2^31, 2^32)`). The fresh two-tier full
|
||||
suite accounts for every file: **1,912 = 1,618 pass / 294 skip / 0 fail / 0
|
||||
crash** (c-torture **1,408 / 284**, c-testsuite **210 / 10**), with every skip
|
||||
carrying a reason and the 10 full-loader exceptions explicit. Every M2–M8.4
|
||||
gate stays green and the new M9 lit/DWARF gates pass, while the real VT1200
|
||||
run remains **DEFERRED**. M9 is complete; the remaining classes are the M9/M10
|
||||
boundary.
|
||||
|
||||
### M10 — the native clang pipeline (Phase 2)
|
||||
|
||||
M10 moves the bit-address transform and this target's compile defaults into
|
||||
the target, so native `clang --target=tms34010 -c` is correct for pointer code
|
||||
at `-O0` and `-O2` with **no extra flags
|
||||
and no wrapper**. `m10` is the repository default (the promotion lands with this
|
||||
push; `m9` is the previous snapshot). The binding design is
|
||||
`2026-11-17-tms34010-phase-2-3-design.md` §7.
|
||||
|
||||
- **The `ToolChain`.** A minimal `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}`
|
||||
(`BareMetal` subclass, registered in `CMakeLists.txt`/`Driver.cpp`) supplies
|
||||
`-ffreestanding`, `-fno-builtin`, `-mllvm -replexitval=never`,
|
||||
`-disable-O0-optnone` and no system includes; `-c`/`-S` are the surface (no
|
||||
link job yet).
|
||||
- **The pipeline.** `registerPassBuilderCallbacks` runs the
|
||||
`@__tms_bitptr` barrier at pipeline start (plus lowering at `-O0`) and
|
||||
scale → lower → final InstCombine at optimizer-last (gated to `Level != O0`);
|
||||
a `"tms.bitaddr"` module flag (absent → `1` → `2`) makes it idempotent, and a
|
||||
legacy lowering pass in `addISelPrepare` is the codegen safety net.
|
||||
- **`tms-clang`** becomes a thin flag mapper; the four gates that traced its
|
||||
internals assert the same invariants at the driver seam.
|
||||
|
||||
M10 acceptance (met, M10 complete): native
|
||||
`clang/test/CodeGen/TMS34010/bitaddr-o0.c`/`bitaddr-o2.c` pin `p[1]` → `ADDI
|
||||
32` (i32), `ADDI 16` (`short`), `ADDI 32` (`char p[4]`) at `-O0` and `-O2`, and
|
||||
an ordinary `sumto` loop compiles at `-O2` with no extra flags;
|
||||
`bitaddr-static-vararg.c` pins the guard at `-O0`/`-O1`/`-O2`,
|
||||
`float-const-o2.c` pins the pre-optimizer f32/f64 constant protection, and
|
||||
`tms34010-defaults.c` pins the `ToolChain` defaults. Native `-O0` (and `-O0
|
||||
-g`) objects are **byte-identical** to the M9 path across the 23-file corpus
|
||||
(`scripts/tests/m10/equivalence.sh`, **46/46** at `-O0` and `-O0 -g`);
|
||||
idempotency is
|
||||
`scripts/tests/m10/bitaddr-idempotent.sh`. TMS34010 lit is **132/132** (128
|
||||
CodeGen + 4 MC) and clang is **10** (8 CodeGen + the driver
|
||||
`tms34010-defaults.c` + the Sema subbyte-stride test), for **142** lit in
|
||||
total; the serial M0–M8 gate list is **56/56 PASS** with `HARDWARE: DEFERRED`.
|
||||
The fresh two-tier full
|
||||
suite is unchanged at **1,912 = 1,618 pass / 294 skip / 0 fail / 0 crash**, the
|
||||
four-phase i64 gate is unchanged at fast **88** / slow **3,302** / wide **221** /
|
||||
div32 **120** frames (37.5× / 14.9× / 1.8×, checksums
|
||||
`000000011E6F9AB4`/`00000000007512AE`/`F56810CFEDA9D656`/`00002C61C63842EE`),
|
||||
and the hardware run remains **DEFERRED**. `m5/jr.sh` re-pins the linked
|
||||
`.text` to **910** bytes (the first M10 pin of 850 was measured through the
|
||||
pre-fix `-O2` bit-offset-aliasing and float-constant-folding hazards; the
|
||||
correctness fixes below cost instructions and restore the M9 legacy value;
|
||||
the JR count is unchanged).
|
||||
|
||||
The `-O2` bit-address aliasing gap is fixed with three changes. (1)
|
||||
DAGCombiner's `BaseIndexOffset` aliasing reads address offsets in **bytes**, so
|
||||
every target-computed bit offset now routes through a `TMS34010ISD::BITADDR`
|
||||
node (selected straight to `ADDI`) for the f64/i64/aggregate return-slot and
|
||||
hidden-return reads; `BaseIndexOffset` does not match the custom node, so
|
||||
aliasing falls back to the byte-accurate `MachinePointerInfo` and the
|
||||
program-order chain is kept, and a zero offset stays the base itself so `-O0`
|
||||
objects remain byte-identical. (2) `f32`/`f64` literals are protected
|
||||
**before** the optimizer: `TMS34010LowerFloatConstantsPass` runs at clang
|
||||
pipeline start for `-O1`+ and replaces each literal store/return/argument with
|
||||
a volatile load from a GSP-initialised global, so the middle-end cannot fold
|
||||
`bitcast(float C to i32)` to IEEE bits (the late llc pass keeps plain loads and
|
||||
still covers `-O0`). (3) Closing those two exposed the underlying class: any
|
||||
address built as `inttoptr(add(ptrtoint, bits))` folds to a plain `ISD::ADD` on
|
||||
this 32-bit-pointer target, so ordinary source pointer arithmetic was still
|
||||
miscompiled at `-O2` (reproducer `p[0]=v; p[1]=w; ((char*)p)[5]=0x7f;` stored
|
||||
the byte before the word store). This is the bit-address aliasing mechanism,
|
||||
fixed by a target intrinsic `llvm.tms34010.bitaddr` that lowers to `BITADDR` and
|
||||
is now used by **every** runtime pointer-offset emitter — the barrier lowering,
|
||||
the aggregate/i64/narrow-mem leaves and both GEP-scaling passes (regression
|
||||
tests `m10-bitaddr-chain-i64.ll`, `bitaddr-chain-o2.c`). The residual is
|
||||
documented: `scaleConstantGep` emits a compile-time `ConstantExpr` address,
|
||||
which cannot hold a call, so it folds to a `GlobalAddress+offset` and no
|
||||
runtime `ADD` exists to mis-decompose (not reachable at `-O2`). With
|
||||
these, `m6/float.sh` (8 float markers), `m6/aggregate.sh` (2 markers),
|
||||
`m6/i64.sh`, `m6/bitfield.sh`, `m6/varargs.sh` and `m6/runtime.sh` all pass at
|
||||
`-O0` and `-O2`. `scripts/m3/run.sh` compiles `branch` with `-fno-inline` at
|
||||
`-O2` (chosen over `-O0` to keep the pinned condition codes), so
|
||||
`m3/dis-roundtrip.sh` keeps its `_sumto`/`_max2`/`_lt` calls to check. The
|
||||
**M10/M11 boundary** is Phase 3: a committed CRT
|
||||
(`crt0.o` via `llvm-mc`), headers, `libtms.a`, a sysroot and a `tms-link` link
|
||||
job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper.
|
||||
(The M11 design corrected the CRT build path: `llc -filetype=obj`, not
|
||||
`llvm-mc` — see the M11 section below.)
|
||||
|
||||
### M11 — the conventional toolchain (Phase 3)
|
||||
|
||||
M11 closes the gap between "a compiler that emits objects" and "a toolchain you
|
||||
can use": `clang --target=tms34010 hello.c -o hello` links a loader-valid TI-COFF
|
||||
image through `tms-link`, with a CRT, headers and a C library discovered through
|
||||
a sysroot — after one `scripts/tms-sdk`. The binding design is
|
||||
`2026-11-18-tms34010-m11-conventional-toolchain-design.md` §8.
|
||||
|
||||
- **The sysroot.** `scripts/tms-sdk [--sysroot DIR]` builds `sdk/crt0.ll` with
|
||||
`llc -march=tms34010 -filetype=obj` and `sdk/{shim,heap}.c` with
|
||||
`clang --target=tms34010 -O2 -c` plus `llvm-ar rcsD` into `libtms.a`, then
|
||||
installs `<sysroot>/{include,lib,bin}`: the **10** headers (`assert, limits,
|
||||
math, stdarg, stdbool, stddef, stdint, stdio, stdlib, string` — there is no
|
||||
`ctype.h`), `lib/{crt0.o,libtms.a,flib.lib,rts.lib}` and the
|
||||
`tms-link`/`tmscoff.py` pair. The default sysroot is
|
||||
`<clang -print-resource-dir>/tms34010-unknown-none`; `--sysroot DIR` installs
|
||||
elsewhere (the driver then needs `--tms-sysroot=DIR`). Installing is
|
||||
idempotent: `llc` and `llvm-ar rcsD` rebuild byte-identically.
|
||||
- **The CRT.** `sdk/crt0.ll` is a `naked` `_start` with inline asm blocks, built
|
||||
by `llc -filetype=obj`: `llvm-mc` emits ELF for this triple (and the generic
|
||||
COFF path refuses a non-Windows triple), so the target's TI-COFF writer is
|
||||
reachable only through CodeGen. The rewrite preserves the contract, not the
|
||||
text: `setf 16/32`, the 4 KiB `_cstack`, the `{"conformance", NULL}` argv, the
|
||||
result block at `01B00000`/`40`/`60`, the output buffers `01B10000`/`01B30000`,
|
||||
and the `_start` symbol for `--entry`.
|
||||
- **The link job.** `TMS34010Linker` invokes `<sysroot>/bin/tms-link` (or
|
||||
`--tms-linker=PATH`) with `--entry _start --text 018A0000 --bss 01A00000
|
||||
--prog-len 40000h --ram-len 80000h`, a default `--map`, `-g` → `--keep-debug`
|
||||
(not `-g0`/`-ggdb0`), `-Wl,` passthrough (with `-Map=`/`-Map,<file>`
|
||||
translated to `--map=<file>`), the CRT, the user objects, `libtms.a flib.lib
|
||||
rts.lib`, `-L <sysroot>/lib` and the user `-L`/`-l`. A missing
|
||||
sysroot/linker/`python3` is a named diagnostic pointing at `scripts/tms-sdk`
|
||||
(except `python3`, which names installing `python3`) — `python3` is a
|
||||
link-time dependency because `tms-link` is a Python program. A sysroot
|
||||
directory that exists but lacks `crt0.o`/`libtms.a`/`flib.lib`/`rts.lib`
|
||||
names the missing artifact instead of handing `tms-link` a bare name.
|
||||
- **Link-reduction knobs.** `-nostartfiles` drops `crt0.o`, `-nodefaultlibs`
|
||||
drops `libtms`/`flib`/`rts`, `-nostdlib` implies both. `-l tms` links
|
||||
`libtms.a` once per request (a repeated `-l tms` links the archive again).
|
||||
- **`tms-cc`** stays as a compatibility alias; new documentation points at
|
||||
`clang --target=tms34010`.
|
||||
|
||||
M11 acceptance: `scripts/tests/m11/{sdk,crt,e2e}.sh` PASS — the headline
|
||||
command from a clean shell, two TUs, `-c`/`-S`/`-E`, `-O0`/`-O2`, `-g` vs
|
||||
stripped, `-nostdlib`, and the no-checkout-path assertion. TMS34010 lit is
|
||||
**132/132** (128 CodeGen + 4 MC), clang **13** (10 CodeGen + 2 Driver + 1 Sema),
|
||||
`tools/tms-link`/`tools/tms-bitaddr` tests PASS, the two-tier suite is unchanged
|
||||
at **1,912 = 1,618 pass / 294 skip / 0 fail / 0 crash**, the four-phase i64
|
||||
gate is unchanged at fast **88** / slow **3,302** / wide **221** / div32 **120**
|
||||
frames (37.5× / 14.9× / 1.8×, checksums `000000011E6F9AB4` /
|
||||
`00000000007512AE` / `F56810CFEDA9D656` / `00002C61C63842EE`), and
|
||||
`HARDWARE: DEFERRED`. The linker emits images that pass
|
||||
`scripts/m4/coff-check.py` unaided: M11 moved the `.bss` rounding into
|
||||
`tms-link`, so `coff-check.py --repair` is no longer on the production path (it
|
||||
survives only for the legacy GSPLNK harness). Known limitations: a bare
|
||||
`-Wl,-Map` sets an explicit-map request but names no file, so it suppresses the
|
||||
default map and produces none (use `-Wl,-Map=<file>`) — and a repeated `-l tms`
|
||||
under `-nodefaultlibs` duplicates the archive. The Task 6
|
||||
sweep's one stale M7 gate check was fixed in `7fcae6e`: `m7/debug.sh` now
|
||||
asserts the `llvm.tms34010.bitaddr` spelling (the M10 aliasing fix replaced the
|
||||
`add i32` lowering) and still requires `!dbg` on the barrier instructions.
|
||||
**The M11/M12 boundary** is M12 (conformance classes) per the roadmap (§11 of
|
||||
the M11 design).
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
| risk | mitigation |
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
# TMS34010 Phase 2 and Phase 3 — native clang pipeline and conventional toolchain
|
||||
|
||||
Status: proposed, revised after the builder check. Phase 1 (`tms-cc` usability
|
||||
driver) is complete and pushed on `m9` (project `55a0991`, compiler
|
||||
`4e7d48d2717e`).
|
||||
|
||||
Decisions already taken by the human partner:
|
||||
|
||||
| Decision | Choice |
|
||||
|---|---|
|
||||
| Phase 2 mechanism | Target-level pass hooks (Approach A) |
|
||||
| Phase 3 library scope | Freestanding, conventional UX (shim + SDK runtimes behind CRT/headers/ToolChain) |
|
||||
| clang-level defaults (`-replexitval=never`, `-ffreestanding`, …) | A minimal `ToolChain` lands in Phase 2 |
|
||||
| M10 success criterion | Runtime and suite equivalence, not byte-identical objects |
|
||||
| Vendor `flib`/`rts` archives | Committed to the repository |
|
||||
|
||||
## 1. Intent and why
|
||||
|
||||
Phase 1 gave a working one-command build (`scripts/tms-cc hello.c -o hello.coff`)
|
||||
but it hides a pipeline only the wrapper script knows about. Native
|
||||
`clang --target=tms34010 -c` still **miscompiles pointer code**. Verified on
|
||||
`m9`:
|
||||
|
||||
```c
|
||||
int load(int *p) { return p[1]; }
|
||||
```
|
||||
|
||||
- `clang --target=tms34010 -O0 -S` → `ADDI 4, A0` (byte offset — wrong; a 32-bit
|
||||
element is 32 bit-addresses away)
|
||||
- `scripts/tms-clang` + `llc` → `ADDI 32, A0` (bit offset — correct)
|
||||
|
||||
The cause is structural: LLVM GEP indices are byte units, TMS34010 pointers are
|
||||
bit addresses, and the optimizer re-forms byte GEPs from
|
||||
`inttoptr(add(ptrtoint, …))` unless an opaque barrier blocks it. Correctness
|
||||
needs three ordered steps — **pre-optimizer barrier → middle-end →
|
||||
post-optimizer scale, lower, final InstCombine**.
|
||||
|
||||
The builder check also showed the wrapper hides more than the barrier. Native
|
||||
`clang -O2 -c` fails on an ordinary loop because `IndVarSimplify` rewrites the
|
||||
loop's exit value into an i33 multiply that the target rejects;
|
||||
`scripts/tms-clang` avoids it with `-replexitval=never`, a pass option no
|
||||
`TargetMachine` can set. The wrapper additionally supplies `-ffreestanding`,
|
||||
`-fno-builtin`, `-nostdinc`, `-Xclang -disable-O0-optnone`, a pre-optimizer
|
||||
static-variadic guard, and `instcombine<no-verify-fixpoint>`. So Phase 2 is "the
|
||||
target owns the transform **and** the target's compile defaults", not the
|
||||
transform alone.
|
||||
|
||||
Phase 3 then makes the whole flow conventional: a CRT, headers, a library and a
|
||||
link job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper
|
||||
and no project variables.
|
||||
|
||||
These are projects, not small changes. They map onto the repository's milestone
|
||||
pattern as **M10 (Phase 2)** and **M11 (Phase 3)**.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
### Phase 2 (M10)
|
||||
|
||||
1. `clang --target=tms34010 -c` is semantically correct for pointer code at
|
||||
`-O0` and `-O2`, with **no extra flags** and no wrapper script.
|
||||
2. `clang --target=tms34010 -O2 -c` compiles ordinary loop code (the i33 /
|
||||
`-replexitval` class) without the user passing anything.
|
||||
3. The transform lives in the target: `llvm/lib/Target/TMS34010/`, registered
|
||||
through `TMS34010TargetMachine::registerPassBuilderCallbacks`.
|
||||
4. A **minimal `ToolChain`** supplies this target's compile defaults
|
||||
(freestanding, no builtins, no system includes, `-replexitval=never`).
|
||||
5. `scripts/tms-clang` keeps its command-line contract but becomes a thin
|
||||
`clang` wrapper.
|
||||
6. Gates that observe the wrapper's internals are re-pointed at the new seam.
|
||||
7. Every M2–M9 gate, lit test and the 1,618-pass full suite stays green.
|
||||
|
||||
### Phase 3 (M11)
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` produces a loadable TI-COFF image
|
||||
that runs under `tms-run`, with no project wrapper and no `M4_*` variables.
|
||||
2. A committed, reproducible **CRT** (`crt0`), **headers** and **library**
|
||||
(`libtms.a`), plus the committed vendor `flib.lib`/`rts.lib`, resolved
|
||||
through a sysroot.
|
||||
3. The driver owns the link step: `tms-link` is the linker job, with `-l`, `-L`,
|
||||
`-nostdlib`, `-Wl,` and layout options passed through.
|
||||
4. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multiple TUs and `-nostdlib` behave the
|
||||
way they do for any freestanding clang target.
|
||||
5. Phase 1's user-visible behaviour (`printf` output via `tms-run`) is preserved.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- **Hosted C library.** No file I/O, no console/terminal driver, no `libm`, no
|
||||
locale. `printf` continues to write the conformance result block.
|
||||
- **lld.** TI-COFF is not an lld flavour; `tms-link` remains the linker.
|
||||
- **LTO.** Bitcode leaving a completed pipeline is final; re-optimizing it is
|
||||
unsupported.
|
||||
- **Changing the TI ABI, the all-stack convention, the GSPA/GSPLNK oracle, or
|
||||
the pointer model.**
|
||||
- **Replacing `llc`'s IR contract.** Hand-written IR passed straight to `llc`
|
||||
keeps the M9 meaning (§7.4).
|
||||
- **Byte-identical objects.** Explicitly dropped: native `-O2` IRGen differs
|
||||
from M9's `clang -O0` IRGen + `opt`, and `-O2` codegen differs from `llc -O0`
|
||||
(measured 424 vs 416 bytes on an integer-only file, different block layout).
|
||||
- Real VT1200 hardware validation (still deferred; no unit).
|
||||
|
||||
## 4. Anti-goals
|
||||
|
||||
- A user-visible flag that must be remembered for correctness. Correctness and
|
||||
this target's compile defaults are properties of the target.
|
||||
- Divergence in generic clang/LLVM beyond (a) the new
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` and (b) its two registration
|
||||
edits. Exported as patch `0005`, extended by Phase 3.
|
||||
- Two implementations of the transform that can drift. `tools/tms-bitaddr`
|
||||
becomes a **test oracle**, not a second production path.
|
||||
- Silently changing what a gate measures. Any gate edit must preserve the
|
||||
invariant it was asserting.
|
||||
|
||||
## 5. Current state (verified on `m9`)
|
||||
|
||||
| Fact | Evidence |
|
||||
|---|---|
|
||||
| The transform is a standalone IR rewriter, not a pass | `tools/tms-bitaddr/bitscale.cpp` parses IR, mutates it, writes it; modes `--bitptr --scale --normalize --lower-bitptr` |
|
||||
| `clang -O2` fails on ordinary loops | `IndVarSimplify` exit-value rewrite → i33 multiply → `TMS34010RejectUnsupportedIR` fatal |
|
||||
| M9 avoids it with a pass option | `scripts/tms-clang`: `opt -passes='default<O2>' -replexitval=never` |
|
||||
| The wrapper carries freestanding defaults | `clang --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone -ffreestanding -fno-builtin -nostdinc` (always `-O0` IRGen) |
|
||||
| A pre-optimizer guard lives in the wrapper | awk scan rejecting `internal` variadic definitions with no `llvm.va_start` (DAE would drop `...`) |
|
||||
| A final InstCombine needs an option | `instcombine<no-verify-fixpoint>` for the shim's `emit_uint64` `zext … nneg` fixpoint |
|
||||
| Gates observe the wrapper's internals | `m3/run.sh` and `m5/jr.sh` inject `opt` wrappers; `m5/policy.sh` traces `opt` arguments; `m4/mul.sh` greps `scripts/tms-clang` for the flag |
|
||||
| The target already assumes bit offsets in codegen | `TMS34010PassConfig::addIRPasses()` hosts `ScaleMemExpansionGEPs`, `ExpandAggMem`, `LowerI64`, `ExpandNarrowMem` |
|
||||
| clang builds a `PassBuilder` **with** the `TargetMachine` | `clang/lib/CodeGen/BackendUtil.cpp:937` |
|
||||
| so target pass callbacks are reachable from clang | `PassBuilder::PassBuilder` calls `TM->registerPassBuilderCallbacks(*this)` (`llvm/lib/Passes/PassBuilder.cpp:581`) |
|
||||
| Pipeline-start callbacks run at `-O0` | `PassBuilderPipelines.cpp:2438`, inside `buildO0DefaultPipeline` |
|
||||
| Optimizer-last callbacks do **not** run at `-O0` | `invokeOptimizerLastEPCallbacks` only at `:1692`, `:1933`, `:2524` |
|
||||
| `llc` runs no new-PM pipeline | `llc.cpp:839` only calls `Target->addPassesToEmitFile` |
|
||||
| `opt` builds no `TargetMachine` | `tools/opt/NewPMDriver.cpp` registers plugin callbacks only |
|
||||
| The driver has no TMS34010 `ToolChain` | no `tms34010` under `clang/lib/Driver/` |
|
||||
| The native link needs a repair step today | `scripts/m4/run.sh` runs `coff-check.py --repair --entry 018A0000` on every linked image |
|
||||
| SDK `flib`/`rts` are generated, not committed | `build/m6-sdk/{flib,rts}.lib`, extracted from the 1987 vendor image |
|
||||
| A TMS34010 MC assembler exists | `llvm/test/MC/TMS34010` (4 tests) — usable for a committed CRT |
|
||||
| `tms-link` reads System V `ar` archives | M8.1 (`scripts/tests/m8/native-lib.sh`) |
|
||||
|
||||
## 6. Approaches considered
|
||||
|
||||
### Phase 2
|
||||
|
||||
**A. Target-level pass hooks (chosen).** Barrier on the pipeline-start extension
|
||||
point; scale/lower/final-InstCombine on optimizer-last (`-O0` handles both in
|
||||
the start callback, §7.3); registered from
|
||||
`TMS34010TargetMachine::registerPassBuilderCallbacks`. No user flag, and the
|
||||
transform stays inside the target directory.
|
||||
|
||||
**B. In-tree clang frontend patch.** Insert the passes in
|
||||
`clang/lib/CodeGen/BackendUtil.cpp`. Explicit ordering, but the fork's first
|
||||
divergence in generic clang code, re-carried on every LLVM bump. Rejected: A
|
||||
covers every clang path because clang passes its `TargetMachine` to the
|
||||
`PassBuilder`.
|
||||
|
||||
**C. Out-of-tree pass plugin plus an opt-in flag.** Smallest divergence, but
|
||||
correctness becomes flag-dependent and forgettable. Rejected: it does not
|
||||
satisfy "plain clang is correct".
|
||||
|
||||
**Rejected outright: bit units in `DataLayout`.** LLVM's addressing unit is the
|
||||
byte and `getTypeAllocSize` is byte-quantised; a bit-unit GEP cannot be
|
||||
expressed. That is why the barrier exists.
|
||||
|
||||
**Amendment after the builder check.** A alone is not sufficient: the
|
||||
`-replexitval`, freestanding and include defaults cannot come from a
|
||||
`TargetMachine`. They come from a minimal `ToolChain`, which is also the natural
|
||||
home for Phase 3's sysroot and link job. This keeps one driver file rather than
|
||||
two phases of driver surgery, and it means Phase 3 extends a file instead of
|
||||
introducing one.
|
||||
|
||||
### Phase 3
|
||||
|
||||
**A. Dedicated `ToolChain` + sysroot + CRT + `libtms.a` (chosen).** Follows how
|
||||
freestanding clang targets work, gives conventional `-I`/`-l`/`-L`/`-nostdlib`
|
||||
behaviour, and keeps `tms-link` behind a normal link job.
|
||||
|
||||
**B. Keep `tms-cc` and only rename it.** Cheapest, but it keeps a project script
|
||||
as the interface and cannot satisfy `clang hello.c -o hello`.
|
||||
|
||||
**C. Target the vendor 2ine/VT1200 OS environment.** Real OS applications, but a
|
||||
different runtime contract and acceptance path. Rejected: the chosen scope is
|
||||
freestanding with conventional UX.
|
||||
|
||||
## 7. Phase 2 (M10) design
|
||||
|
||||
### 7.1 Pass inventory
|
||||
|
||||
Port `tools/tms-bitaddr/bitscale.cpp` into new-PM passes under
|
||||
`llvm/lib/Target/TMS34010/`:
|
||||
|
||||
| New pass | Source mode | Responsibility |
|
||||
|---|---|---|
|
||||
| `TMS34010BitPtrPass` | `--bitptr` | Replace every GEP (and `inttoptr` of a bit addend over `ptrtoint`) with `@__tms_bitptr(i32 bitoff, ptr base)`; rewrite constant-expression GEPs as `inttoptr(add(ptrtoint, 8*off))`; copy `!dbg`; run the static-variadic guard (§7.6) |
|
||||
| `TMS34010ScaleGEPPass` | `--scale` | Multiply optimizer-created byte-GEP indices by 8; keep the `switch.table.*` special case |
|
||||
| `TMS34010LowerBitPtrPass` | `--lower-bitptr` | Replace each call with `inttoptr(add(ptrtoint base, bitoff))`, then drop the declaration |
|
||||
|
||||
`--normalize` is not ported: nothing in the shipped pipeline calls it, and its
|
||||
input contract is what `llc` does natively. The tool keeps the mode for its own
|
||||
tests and stays the equivalence oracle.
|
||||
|
||||
The port is a rewrite into `PassInfoMixin` form, not a move: the current code is
|
||||
a `main()`-driven module mutator.
|
||||
|
||||
### 7.2 Pipeline registration
|
||||
|
||||
`TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB)`:
|
||||
|
||||
```
|
||||
PB.registerPipelineStartEPCallback(<level L: append barrier; if L == O0 also
|
||||
append lower>);
|
||||
PB.registerOptimizerLastEPCallback(<append scale → lower → instcombine>);
|
||||
```
|
||||
|
||||
At `-O0` no optimizer runs, so there are no optimizer-created GEPs to scale and
|
||||
no InstCombine is needed; adding one would move `-O0` output away from the M9
|
||||
path. `-O0` therefore runs barrier + lower only, which is what makes the
|
||||
byte-identity check possible.
|
||||
|
||||
`TMS34010PassConfig::addISelPrepare()` prepends `<lower → instcombine>` for IR
|
||||
that reaches codegen still holding barrier calls (hand-written or intermediate
|
||||
IR). It is placed before `TargetPassConfig::addISelPrepare()` so it runs before
|
||||
`PreISelIntrinsicLowering`/`CodeGenPrepare`, matching M9's "lower before the
|
||||
backend sees it". `TMS34010PassConfig::addIRPasses()` is unchanged.
|
||||
|
||||
The final InstCombine is constructed with
|
||||
`InstCombineOptions().setVerifyFixpoint(false)` — the in-tree equivalent of the
|
||||
wrapper's `instcombine<no-verify-fixpoint>`.
|
||||
|
||||
Consequences that make this safe:
|
||||
|
||||
- `clang` reaches the hooks because it builds `PassBuilder PB(TM.get(), …)`.
|
||||
- `llc` never builds a new-PM pipeline, so **direct `llc` on IR keeps the M9
|
||||
contract** and the 129 lit tests are unaffected.
|
||||
- `opt` builds no `TargetMachine`, so `opt` never fires the hooks.
|
||||
|
||||
### 7.3 State machine (idempotency)
|
||||
|
||||
A module flag carries the state so the barrier cannot run twice:
|
||||
|
||||
| Flag `"tms.bitaddr"` | Meaning | Pipeline start | Optimizer last | Codegen (`addISelPrepare`) |
|
||||
|---|---|---|---|---|
|
||||
| absent | not ours / hand-written IR | apply barrier → `1`; at `-O0` immediately lower → `2` | skip | skip |
|
||||
| `1` | barriered, not lowered | skip | scale, lower, instcombine → `2` | lower, instcombine → `2` |
|
||||
| `2` | lowered / final | skip | skip | skip |
|
||||
|
||||
Flag: `Module::addModuleFlag(ModFlagBehavior::Override, "tms.bitaddr", i32)`, set
|
||||
only by the pass performing the transition.
|
||||
|
||||
Because `-O0` lowers inside the start callback, **clang never emits state-1
|
||||
IR**, which closes the previous hole where `clang -O0 -emit-llvm` → `opt -O2` →
|
||||
`llc` would have lowered unscaled optimizer GEPs.
|
||||
|
||||
Scenario check:
|
||||
|
||||
| Command | Result |
|
||||
|---|---|
|
||||
| `clang -O2 -c` | barrier → optimize → scale/lower/instcombine → codegen skips |
|
||||
| `clang -O0 -c` | barrier + lower + instcombine in the start callback |
|
||||
| `clang -O0 -S -emit-llvm` then `llc` | state 2; `llc` skips |
|
||||
| `clang -O2 -S -emit-llvm` then `llc` | state 2; `llc` skips |
|
||||
| `clang -O2` on state-1 IR | barrier skipped, optimization + lowering run once |
|
||||
| `llc` on hand-written IR | no flag → untouched (M9 meaning) |
|
||||
| `opt` on state-2 IR | hooks never fire; optimizing final IR is unsupported (§7.5) |
|
||||
|
||||
### 7.4 Why `llc`'s contract must not change
|
||||
|
||||
`m2-late-gep.ll` pins `getelementptr i8, ptr %p, i32 24` → `ADDI 24`: for `i8`
|
||||
GEPs the byte offset *is* the bit offset. A barrier inside `llc` would turn every
|
||||
such test into `ADDI 192` and redefine the IR contract the gate suite is built
|
||||
on. The hooks therefore live only in the new-PM pipeline, which `llc` does not
|
||||
build. This is a design invariant.
|
||||
|
||||
### 7.5 Limitations to document
|
||||
|
||||
- IR emitted by a completed `clang` pipeline (`-emit-llvm`) is **final**;
|
||||
re-optimizing it with `clang`/`opt -O2` is unsupported.
|
||||
- LTO is unsupported for this target (bitcode is already lowered).
|
||||
- The barrier must preserve `!dbg`; this keeps `-g -c` DWARF correct (M9.2
|
||||
depends on it).
|
||||
|
||||
### 7.6 Minimal `ToolChain` (new in M10)
|
||||
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}`, registered in
|
||||
`clang/lib/Driver/ToolChains/CMakeLists.txt` and the driver's target selection so
|
||||
`tms34010-unknown-none` (and plain `--target=tms34010`) resolve to it.
|
||||
|
||||
M10 responsibilities (the whole file is ~150 lines):
|
||||
|
||||
- `addClangTargetOptions`: append `-ffreestanding`, `-fno-builtin`,
|
||||
`-mllvm -replexitval=never`, and `-disable-O0-optnone` (the last because the
|
||||
legacy M9 path ran `-O0` without the `optnone` attribute, so the flag keeps
|
||||
native `-O0 -c` objects byte-identical to the M9 path).
|
||||
- Include behaviour: no system include directories (`-nostdinc` semantics
|
||||
without the flag); `-I` still works.
|
||||
- Keep object emission as today (integrated TI-COFF writer, no external
|
||||
assembler).
|
||||
- No link job yet: `-c`/`-S` are the M10 surface; linking stays with `tms-cc`
|
||||
until M11.
|
||||
|
||||
The static-variadic guard moves into `TMS34010BitPtrPass` as a pre-optimizer
|
||||
rejection: an `internal`/`private` variadic definition with no
|
||||
`llvm.va_start`/`va_arg` in the body is diagnosed with the same message the
|
||||
wrapper prints today.
|
||||
|
||||
### 7.7 What `tms-clang` becomes, and the gates that must change
|
||||
|
||||
`scripts/tms-clang` becomes a flag mapper:
|
||||
|
||||
| `tms-clang` flag | becomes |
|
||||
|---|---|
|
||||
| `-O0` / `-O2` | `clang --target=tms34010 -O0` / `-O2` |
|
||||
| `-g` | `-g` |
|
||||
| `-I dir` | `-I dir` |
|
||||
| `-o OUT.ll` | `-S -emit-llvm -o OUT.ll` |
|
||||
| `$TMS_CLANG_EXTRA_FLAGS` | passed through unchanged |
|
||||
| `$TMS_OPT` / `$TMS_BITADDR` | no longer used |
|
||||
|
||||
Gate edits required (same invariant, new seam):
|
||||
|
||||
| Gate | Today | M10 |
|
||||
|---|---|---|
|
||||
| `scripts/tests/m3/run.sh`, `scripts/tests/m5/jr.sh` | inject an `opt` wrapper to add `-replexitval=never` | pass nothing; assert the compile succeeds and the loop shape survives in the emitted IR |
|
||||
| `scripts/tests/m5/policy.sh` | traces `opt` arguments, asserts the flag and no `-switch-to-lookup` | asserts `-replexitval=never` appears in `clang -###` output (the ToolChain seam) and inspects the final IR/asm for the same shapes |
|
||||
| `scripts/tests/m4/mul.sh` | greps `scripts/tms-clang` for the flag | greps the ToolChain source/defaults, or asserts via `clang -###` |
|
||||
|
||||
### 7.8 Acceptance (M10)
|
||||
|
||||
1. **Native correctness:** `clang/test/CodeGen/TMS34010/` tests for `p[1]`
|
||||
(i32 → `ADDI 32`), byte/struct pointers, array indexing and pointer
|
||||
difference at `-O0` and `-O2`; an ordinary `for` loop compiles at `-O2`
|
||||
without extra flags.
|
||||
2. **Native end-to-end:** the pointer programs run correctly end to end
|
||||
(compile with native clang, link with the existing `tms-cc`/`tms-link` path,
|
||||
run under MAME) at `-O0` and `-O2`.
|
||||
3. **Equivalence (chosen criterion):** the full suite stays **1,618 pass / 294
|
||||
skip / 0 fail / 0 crash**; suite markers and checksums are unchanged; i64div
|
||||
stays 88/3302/221/120 with the same four checksums; a curated asm-shape set
|
||||
(pointer arithmetic, struct offsets, switch tables, aggregate returns)
|
||||
matches M9's shapes.
|
||||
4. **Pass equivalence:** proven end-to-end, because individual new-PM passes are
|
||||
not addressable from `opt` (it builds no `TargetMachine`): `clang -O0 -c`
|
||||
objects must be byte-identical to the M9 path, which exercises the barrier
|
||||
and lowering port directly, while the scaling pass is pinned by the M5 policy
|
||||
gate (switch table) and an `-O2` asm-shape set.
|
||||
5. **Unchanged gates:** lit 129/129 plus the new tests, clang 5/5 plus driver
|
||||
tests, every M2–M9 gate green after the §7.7 edits, which are reviewed as
|
||||
part of the milestone.
|
||||
6. **No user flags:** `clang --target=tms34010 -O2 -c` with nothing else.
|
||||
|
||||
## 8. Phase 3 (M11) design
|
||||
|
||||
### 8.1 Driver link job
|
||||
|
||||
Extend the M10 `ToolChain` with a link job invoking `tms-link`: `-o`,
|
||||
`--entry _start`, `--text`, `--bss`, `--prog-len`, `--ram-len`, libraries,
|
||||
optional `--map`. `-Wl,…` passes through; `-nostdlib` removes CRT and default
|
||||
libraries; `-g` maps to `--keep-debug` (and the default stays stripped).
|
||||
|
||||
**Linker prerequisite:** the production path must not depend on
|
||||
`coff-check.py --repair`. `tms-link` must emit a loader-valid image unaided
|
||||
(valid file/optional header, even `.bss`), and `coff-check.py` stays a *checker*
|
||||
in the gates. This is small linker work added to M11.1.
|
||||
|
||||
### 8.2 CRT, headers, library, sysroot
|
||||
|
||||
| Artifact | Source | Build |
|
||||
|---|---|---|
|
||||
| `crt0.o` | `sdk/crt0.asm`, generalised from `conformance/entry.asm`: `setf`, stack setup, call `main`, write status/magic | `llvm-mc -triple=tms34010 -filetype=obj`, reproducible |
|
||||
| headers | `sdk/include/` (moved from `scripts/tests/m5/conformance/include`) | installed into the sysroot |
|
||||
| `libtms.a` | `sdk/shim.c`, `sdk/heap.c` (printf family, `malloc`/`free`, `mem*`/`str*`) | System V `ar`, which `tms-link` reads |
|
||||
| `flib.lib`, `rts.lib` | committed copies of the extracted 1987 vendor archives | linked by default for the shim's `%f` path |
|
||||
|
||||
The sysroot layout is `lib/clang/<ver>/tms34010-unknown-none/{include,lib}` plus
|
||||
a `--tms-sysroot=` override. Because the vendor archives are committed and the
|
||||
CRT is reproducible, `clang --target=tms34010 hello.c -o hello` needs no
|
||||
project variables and no SDK extraction step.
|
||||
|
||||
The conformance harness and `tms-cc` point at the relocated headers rather than
|
||||
keeping a second copy.
|
||||
|
||||
### 8.3 Command surface after Phase 3
|
||||
|
||||
```
|
||||
clang --target=tms34010 hello.c -o hello # CRT + libtms + flib/rts + tms-link
|
||||
clang --target=tms34010 -c hello.c -o hello.o # TI-COFF object
|
||||
clang --target=tms34010 -S hello.c -o hello.s # GSPA assembly
|
||||
clang --target=tms34010 -O2 -g a.c b.c -o app # multi-TU, debug kept
|
||||
clang --target=tms34010 -nostdlib -Wl,--entry=_start ...
|
||||
tms-run hello # unchanged
|
||||
```
|
||||
|
||||
`scripts/tms-cc` stays as a compatibility alias adding `--run` and the project's
|
||||
default layout; it is no longer the recommended interface.
|
||||
|
||||
### 8.4 Acceptance (M11)
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` then `tms-run hello` prints
|
||||
`hello` with status 0, from a shell with no project variables set.
|
||||
2. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multi-TU and `-nostdlib` behave
|
||||
conventionally; `clang/test/Driver/TMS34010*.c` pins the link and include
|
||||
command lines.
|
||||
3. The CRT rebuilds byte-identically from source with no DOSBox/2ine dependency,
|
||||
and the committed vendor archives match the extracted originals.
|
||||
4. The single-command flow builds one M4/M5/M6 harness program unchanged.
|
||||
5. M2–M10 gates, lit, the conformance full suite and the i64div numbers are
|
||||
unchanged.
|
||||
|
||||
## 9. Constraints
|
||||
|
||||
- Branch `m10` from `m9`; `m11` from `m10` after Phase 2 is promoted. Default
|
||||
promotion only after a clean whole-branch review, per standing policy.
|
||||
- LLVM/Clang stay pinned at 23.1.5. `patches/llvm/0001..0004` stay as they are;
|
||||
Phase 2 adds `0005` (the `ToolChain` and its registration), extended in
|
||||
Phase 3.
|
||||
- Every existing gate, the TI ABI, the all-stack convention, GSPLNK as the
|
||||
byte/symbol oracle and the two-tier conformance harness stay intact.
|
||||
- No force-push, no default-branch change, no history rewrite.
|
||||
- `-O0` and `-O2` are both first-class.
|
||||
|
||||
## 10. Risks and mitigations
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Barrier applied twice | Module-flag state machine (§7.3) with the scenario table as tests |
|
||||
| `llc`'s IR contract silently changes | Hooks only in the new-PM pipeline; `m2-late-gep.ll` and the 129 lit tests guard it |
|
||||
| Codegen-created late GEPs after lowering | Lowering in `addISelPrepare` before `CodeGenPrepare`, matching M9 order; `addrSinkUsingGEPs` stays disabled |
|
||||
| Debug info lost in the port | Barrier copies `!dbg`; M9.2 gates (`m9/dwarf-ranges.sh`, `m8/dwarf-multi.sh`, `m7/debug.sh`) must pass unchanged |
|
||||
| Pass port drifts from the oracle | `tools/tms-bitaddr` retained as the oracle (§7.8.4) |
|
||||
| Gate edits weaken coverage | Each §7.7 edit must assert the same invariant at the new seam and be reviewed |
|
||||
| `-replexitval` regresses on other loop shapes | Full suite plus the M3/M5 loop gates; the flag is a compile-time policy, not codegen |
|
||||
| Native `-O2` differs from M9 in size | Accepted by decision; behaviour gates (§7.8.3) replace byte identity |
|
||||
| Driver file grows into two phases of surgery | One file from M10, extended rather than rewritten in M11 |
|
||||
| `coff-check --repair` hides a tms-link defect | M11.1 fixes `tms-link`; the checker stays in the gate with `--repair` removed from production |
|
||||
| Committed vendor archives drift | Gate compares the committed copies against freshly extracted ones |
|
||||
| Two copies of headers/CRT | Phase 3 relocates the single source and regenerates harness paths |
|
||||
|
||||
## 11. Sequencing and what is left to the builder
|
||||
|
||||
**M10.0** minimal `ToolChain` (defaults + include behaviour) → **M10.1** pass
|
||||
port + oracle equivalence → **M10.2** pipeline hooks + state machine →
|
||||
**M10.3** `tms-clang` rewrite, gate edits, equivalence sweep → **M10.4**
|
||||
docs/gates/promote.
|
||||
|
||||
**M11.1** link job + `tms-link` header fix → **M11.2** `crt0` via `llvm-mc` →
|
||||
**M11.3** headers, `libtms.a`, committed vendor archives, sysroot → **M11.4**
|
||||
single-command end-to-end, docs, gates, promote.
|
||||
|
||||
Left to the builder (verify during implementation, do not re-litigate):
|
||||
|
||||
1. Exact pass signatures; whether InstCombine is added via
|
||||
`createInstructionCombiningPass`/`InstCombinePass(InstCombineOptions...)`.
|
||||
2. Whether `addISelPrepare` prepending is sufficient or `addIRPasses` also needs
|
||||
the safety-net lowering (measure both `-O0` outputs).
|
||||
3. Module-flag name/behaviour enum (`"tms.bitaddr"` / `Override` proposed).
|
||||
4. Whether the static-variadic guard belongs in the barrier pass or a separate
|
||||
pre-opt pass in the same callback.
|
||||
5. Sysroot resolution order (`-resource-dir` relative versus `--tms-sysroot`).
|
||||
6. Whether `libtms.a` is always linked or gated on `-l tms`, and how `flib`/`rts`
|
||||
are selected (`%f` needs them; `-nostdlib` must not).
|
||||
7. Whether `tms-cc`'s `--run` stays in the script.
|
||||
|
||||
## 12. Decisions log
|
||||
|
||||
| Decision | Choice | By |
|
||||
|---|---|---|
|
||||
| Phase 2 mechanism | Target-level pass hooks (Approach A) | user |
|
||||
| clang-level defaults (`replexitval`, freestanding, includes) | Minimal `ToolChain` in Phase 2, extended in Phase 3 | user |
|
||||
| M10 success criterion | Runtime + suite equivalence | user |
|
||||
| Vendor `flib`/`rts` | Committed to the repo | user |
|
||||
| Phase 3 library scope | Freestanding, conventional UX (no hosted libc/file I/O/libm) | user |
|
||||
| Milestone mapping | Phase 2 = M10, Phase 3 = M11 | this doc |
|
||||
| `-O0` pipeline | Barrier + lower in the start callback; no state-1 IR from clang | this doc |
|
||||
| `tms-bitaddr` fate | Test oracle, not a production path | this doc |
|
||||
| `llc` IR contract | Unchanged (bit offsets by definition) | this doc |
|
||||
| `-g` at link | Maps to `--keep-debug`; default stays stripped | this doc |
|
||||
| `coff-check.py --repair` | Leaves the production path; `tms-link` emits valid images | this doc |
|
||||
| Gate edits for the new seam | Required and reviewed (§7.7) | this doc |
|
||||
@@ -0,0 +1,306 @@
|
||||
# TMS34010 M11 (Phase 3) — Conventional Toolchain Design
|
||||
|
||||
Status: proposed. M10 is complete and `m10` is the default on both repositories
|
||||
(project `4809185`, compiler `7fc2ac37b5ad`). This document also carries the
|
||||
short roadmap for M12 and later.
|
||||
|
||||
Decision already taken by the human partner: M11 is Phase 3 of
|
||||
`docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md` §8 — a
|
||||
freestanding toolchain with conventional UX — and its artifacts are discovered
|
||||
through a resource-directory sysroot built and installed by a script
|
||||
(approach A below).
|
||||
|
||||
## 1. Intent and why
|
||||
|
||||
M10 made `clang --target=tms34010 -c` correct. M11 closes the remaining gap
|
||||
between "a compiler that emits objects" and "a toolchain you can use": a
|
||||
single command that produces a runnable image.
|
||||
|
||||
Today the pieces exist but only the project knows how to wire them:
|
||||
|
||||
- `scripts/tms-cc` compiles each TU through `scripts/tms-clang` and `llc`, then
|
||||
drives `scripts/m4/run.sh` with `M4_*` environment variables, which assembles
|
||||
`entry.asm` with the 1987 tools and links with `tools/tms-link`.
|
||||
- Headers live in `scripts/tests/m5/conformance/include`; the runtime is
|
||||
`shim.c` + `heap.c` compiled on every invocation; the SDK archives come from
|
||||
`build/m6-sdk`.
|
||||
- Nothing tells `clang` where a CRT, headers or a library are.
|
||||
|
||||
The goal is that a user with a built compiler and one setup command can run:
|
||||
|
||||
```sh
|
||||
clang --target=tms34010 hello.c -o hello
|
||||
tms-run hello
|
||||
```
|
||||
|
||||
and see `hello`, with no project variables, no wrapper script, and no DOSBox.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` links to a loader-valid TI-COFF
|
||||
image through `tms-link`, with a CRT, headers and a C library found through
|
||||
a sysroot.
|
||||
2. The sysroot is produced from in-repo sources by one documented command and
|
||||
installed at a relocatable, conventional location.
|
||||
3. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multiple TUs, `-I`, `-L`, `-l` and
|
||||
`-nostdlib` behave the way they do for any freestanding clang target, and
|
||||
`-###` shows the real compile and link jobs.
|
||||
4. The CRT is reproducible from source with `llc` — no DOSBox, no 2ine, no
|
||||
vendor assembler. (`llvm-mc` cannot be used: it emits ELF for this triple, and
|
||||
the generic COFF path refuses a non-Windows triple. The target's TI-COFF
|
||||
writer is reachable only through CodeGen, so the CRT is an IR file whose
|
||||
`_start` is `naked` with inline assembly.)
|
||||
5. `libtms.a` is built from `shim.c` + `heap.c` with `llvm-ar`; the committed
|
||||
vendor `flib.lib`/`rts.lib` supply the `%f` formatting path.
|
||||
6. `tms-link` emits a loader-valid image on its own, so the production path no
|
||||
longer needs `coff-check.py --repair`.
|
||||
7. Every M0–M10 gate, the lit suites and the 1,912-row conformance suite stay
|
||||
unchanged.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- **Hosted C library.** No file I/O, no console driver, no `libm`, no locale.
|
||||
`printf` keeps writing the conformance result block that `tms-run` reads.
|
||||
- **A new linker.** `tms-link` stays the linker; M11 only calls it correctly.
|
||||
- **lld.** TI-COFF is not an lld flavour.
|
||||
- **Changing the TI ABI, the all-stack convention, the pointer model, or the
|
||||
M10 pipeline.** M11 adds no codegen behaviour.
|
||||
- **Bare-metal debugger integration** beyond `-g` → `--keep-debug`.
|
||||
- **Removing `tms-cc`.** It stays as a compatibility alias.
|
||||
|
||||
## 4. Anti-goals
|
||||
|
||||
- A driver that shells out to project scripts or bakes a checkout path into
|
||||
`clang`. Both break the "conventional toolchain" property.
|
||||
- Committing built `crt0.o`/`libtms.a`. Sources are the truth; a drift gate is
|
||||
still cheaper than a checked-in binary.
|
||||
- Growing the driver patch into generic clang code. The fork's driver change
|
||||
stays inside `clang/lib/Driver/ToolChains/TMS34010.*` plus its two
|
||||
registration lines, exported as an extension of patch `0005`.
|
||||
- Making the conformance harness depend on the installed sysroot in a way that
|
||||
breaks its hermetic MAME runs.
|
||||
|
||||
## 5. Constraints
|
||||
|
||||
- LLVM/Clang stay pinned at 23.1.5; the fork's exported patches remain
|
||||
`patches/llvm/0001..0005`.
|
||||
- Branch `m11` from `m10`; promote only after a clean whole-branch review, per
|
||||
standing repository policy.
|
||||
- Every existing gate and the two-tier harness stay green; `HARDWARE` stays
|
||||
`DEFERRED` until a unit exists.
|
||||
- No force-push, no history rewrite.
|
||||
- `clang --target=tms34010 -c` (M10's contract) must not regress, including
|
||||
`-O0` byte identity with the M9 path.
|
||||
|
||||
## 6. Current state (verified on `m10`)
|
||||
|
||||
| Fact | Evidence |
|
||||
|---|---|
|
||||
| CodeGen emits TI-COFF; `llvm-mc` does not | `llc -march=tms34010 -filetype=obj` writes the target's COFF object; `llvm-mc -triple=tms34010 -filetype=obj` writes ELF (`7f 45 4c 46`), and `-triple=tms34010-unknown-none-coff` aborts with "cannot initialize MC for non-Windows COFF object files" |
|
||||
| A `naked` function keeps inline asm verbatim | `llc` on a `naked` `_start` with `setf`/`movi`/`move`/`rets` inline asm emits no prologue and no epilogue |
|
||||
| `tms-link` already has the driver's surface | `--entry --text --data --cinit --bss --prog-len --ram-len --map --keep-debug -L -l` |
|
||||
| A working `_start` exists | `scripts/tests/m5/conformance/entry.asm`: `setf` 16/32, 4 KiB `_cstack`, argv vector `{"conformance", NULL}`, result block at `01B00000`/`20`/`40`/`60`, output buffers `01B10000`/`01B30000`, `exit`/`abort` publish status themselves |
|
||||
| Headers exist but uninstalled | 10 headers in `scripts/tests/m5/conformance/include` (`assert, limits, math, stdarg, stdbool, stddef, stdint, stdio, stdlib, string`) |
|
||||
| Runtime sources exist | `scripts/tests/m5/conformance/{shim.c,heap.c}` |
|
||||
| SDK archives are extracted, not committed | `build/m6-sdk/{flib,rts}.lib`; the design commits them in M11 |
|
||||
| The link path needs a repair step today | `scripts/m4/run.sh` always runs `coff-check.py --repair --entry 018A0000` |
|
||||
| The driver file exists | `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` from M10, patched by `0005` |
|
||||
| No sysroot or link job exists | `clang -###` shows compile jobs only |
|
||||
|
||||
## 7. Approaches considered
|
||||
|
||||
**A. Resource-directory sysroot, built and installed by a script (chosen).**
|
||||
`sdk/` holds the sources; `scripts/tms-sdk` builds `crt0.o` and `libtms.a` and
|
||||
installs them, with the headers and the committed vendor archives, into
|
||||
`<resource-dir>/tms34010-unknown-none/{include,lib}`. The `ToolChain` searches
|
||||
there. Sources stay authoritative, the location is the conventional one for
|
||||
cross targets, and clang stays relocatable. Cost: one setup command after a
|
||||
compiler build.
|
||||
|
||||
**B. Repo-relative `sdk/` with committed prebuilt artifacts.** No setup step,
|
||||
but it bakes a checkout path into the driver, breaks when clang moves, and puts
|
||||
binaries in git that can drift. Rejected: it trades a real property
|
||||
(relocatable clang) for skipping one command.
|
||||
|
||||
**C. Explicit `--tms-sysroot` only.** Most predictable, worst UX, and it fails
|
||||
goal 1 (working from a shell with no flags). Rejected.
|
||||
|
||||
**Why A.** It is the only option that keeps both properties the milestone is
|
||||
for: a single conventional command, and a clang that can be moved or installed
|
||||
anywhere.
|
||||
|
||||
## 8. Design
|
||||
|
||||
### 8.1 Artifacts and layout
|
||||
|
||||
| Source | Built by | Installed to |
|
||||
|---|---|---|
|
||||
| `sdk/crt0.ll` (a `naked` `_start` with inline asm) | `llc -march=tms34010 -filetype=obj` | `<sysroot>/lib/crt0.o` |
|
||||
| `sdk/shim.c`, `sdk/heap.c` | `clang --target=tms34010 -c` + `llvm-ar` | `<sysroot>/lib/libtms.a` |
|
||||
| `sdk/include/*.h` (moved from the conformance harness) | — | `<sysroot>/include/` |
|
||||
| `sdk/lib/{flib,rts}.lib` (committed copies of the extracted 1987 archives) | — | `<sysroot>/lib/` |
|
||||
| `tools/tms-link/{tms-link,tmscoff.py}` | copied as a pair (the script imports its sibling) | `<sysroot>/bin/` |
|
||||
|
||||
The installed linker is a Python program: `python3` is a documented runtime
|
||||
dependency of the toolchain, and the driver reports its absence by name rather
|
||||
than as a bare link failure.
|
||||
|
||||
`<resource-dir>` is `clang -print-resource-dir` (for this fork,
|
||||
`build/llvm-clean-build/lib/clang/23`), so the sysroot defaults to
|
||||
`<resource-dir>/tms34010-unknown-none`.
|
||||
|
||||
`scripts/tms-sdk` performs all four steps, is idempotent, and accepts
|
||||
`--sysroot DIR` to install elsewhere (the driver then needs
|
||||
`--tms-sysroot=DIR`). The conformance harness points at `sdk/` for its headers
|
||||
so there is exactly one copy.
|
||||
|
||||
### 8.2 Driver discovery and the link job
|
||||
|
||||
`TMS34010ToolChain` gains:
|
||||
|
||||
- **Sysroot search order:** `--tms-sysroot=DIR`, then `--sysroot`/`-isysroot`,
|
||||
then `<resource-dir>/tms34010-unknown-none`. Headers come from
|
||||
`<sysroot>/include`; libraries from `<sysroot>/lib` plus `-L` paths.
|
||||
- **A link `Tool`** (`TMS34010Linker`) that invokes the installed
|
||||
`tms-link`. **Linker discovery:** `--tms-linker=PATH` first, otherwise
|
||||
`<sysroot>/bin/tms-link` — the same sysroot the headers and libraries come
|
||||
from, so one setup command covers everything and nothing is baked into the
|
||||
driver. A missing sysroot, a missing linker or a missing `python3` is a named
|
||||
diagnostic, never a bare link error; the first two point at `scripts/tms-sdk`
|
||||
and the `python3` one says to install `python3`.
|
||||
|
||||
Arguments: `-o <output>`, `--entry _start`, `--text 018A0000`,
|
||||
`--bss 01A00000`, `--prog-len 40000h`, `--ram-len 80000h`,
|
||||
`--map <output>.map` when `-Wl,-Map` is absent, the objects, then
|
||||
`libtms.a`, `flib.lib`, `rts.lib` (unless `-nostdlib`/`-nodefaultlibs`), then
|
||||
user `-L`/`-l`. `-Wl,` arguments pass through verbatim.
|
||||
- **`-g`** also passes `--keep-debug` to the link so the image keeps its DWARF;
|
||||
the default stays stripped.
|
||||
- **`-###`** shows both jobs, and `clang/test/Driver/TMS34010-link.c` pins the
|
||||
link command line and the include path.
|
||||
|
||||
Compile jobs are unchanged from M10.
|
||||
|
||||
### 8.3 CRT contract
|
||||
|
||||
`sdk/crt0.ll` expresses the CRT as LLVM IR: `_start` is a `naked` function whose
|
||||
body is a sequence of `call void asm sideeffect "…"` blocks (`setf`, `movi`,
|
||||
`move`, `calla _main`, the status/magic stores, `rets`), plus globals for
|
||||
`_conformance_name` (`"conformance\0"`), `_conformance_argv` and `_cstack`.
|
||||
`llc -filetype=obj` lowers it through CodeGen and the target's TI-COFF writer,
|
||||
which is the only path that emits this object format; `llvm-mc` is not usable
|
||||
(see the current-state table). `naked` is required so no prologue touches the
|
||||
stack before `_start` sets it.
|
||||
|
||||
What the rewrite must preserve is the **contract**, not the text:
|
||||
|
||||
- `setf 16,1,0` / `setf 32,0,1`, and a 4 KiB `_cstack` at 16-bit alignment;
|
||||
- the two-element argv vector `{"conformance", NULL}` so `main(int, char**)`
|
||||
keeps working (`main(void)` is unaffected);
|
||||
- the result block exactly as today: status at `01B00000`, magic at
|
||||
`01B00040` set after `main` returns, and `libtms`'s output/error buffers at
|
||||
`01B10000`/`01B30000` with their length cells;
|
||||
- the `_start` symbol that `--entry _start` names;
|
||||
- `exit`/`abort` in `libtms` still publish status and spin.
|
||||
|
||||
Those addresses and sizes are the interface `tms-run` and the conformance
|
||||
harness already rely on.
|
||||
|
||||
### 8.4 Library policy
|
||||
|
||||
`libtms.a` always links when the CRT does. `flib.lib`/`rts.lib` are needed by
|
||||
`libtms`'s `%f` path, so they link by default. The conventional knobs are
|
||||
independent: `-nostartfiles` drops `crt0.o` but keeps the libraries,
|
||||
`-nodefaultlibs` keeps `crt0.o` but drops `libtms`/`flib`/`rts`, and
|
||||
`-nostdlib` implies both. `-l tms` is accepted and is a no-op beyond ensuring
|
||||
the archive is present once. Order is fixed: CRT, user objects, `libtms`,
|
||||
`flib`, `rts`, user `-l` archives.
|
||||
|
||||
### 8.5 `tms-link` prerequisite
|
||||
|
||||
`coff-check.py --repair` leaves the production path. `tms-link` must emit a
|
||||
valid file header, optional header and section table, and round `.bss` to whole
|
||||
16-bit words itself; `coff-check.py` stays in the gates as a checker (`--repair`
|
||||
becomes test-only). This is small linker work and it is the reason the link job
|
||||
can stay clean.
|
||||
|
||||
### 8.6 `tms-cc`
|
||||
|
||||
Kept as a compatibility alias documented as such: it adds `--run` and the
|
||||
project's M4 defaults. New documentation points at `clang --target=tms34010`.
|
||||
It is not deleted in M11.
|
||||
|
||||
### 8.7 Acceptance
|
||||
|
||||
1. From a clean shell after `scripts/tms-sdk`:
|
||||
`clang --target=tms34010 hello.c -o hello` then `tms-run hello` prints
|
||||
`hello` with status 0. No `M4_*`, `TMS_*`, or include paths set.
|
||||
2. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, two-TU linking and `-nostdlib` all
|
||||
behave conventionally; `clang/test/Driver/TMS34010-link.c` pins the jobs.
|
||||
3. `crt0.o` and `libtms.a` rebuild byte-identically from `sdk/` (`llc`
|
||||
self-consistency, not parity with the 1987 assembler), and a gate compares
|
||||
the committed `flib.lib`/`rts.lib` against the extracted originals.
|
||||
4. One existing M4/M5/M6 harness program builds through the new path and still
|
||||
passes its MAME markers. (M11 adds no separate harness-program-through-driver
|
||||
case: `scripts/tests/m11/e2e.sh` plus the unchanged full suite cover that
|
||||
risk.)
|
||||
5. The conformance suite stays `1,912 = 1,618 / 294 / 0 / 0`; lit and every
|
||||
M0–M10 gate stay green; `HARDWARE: DEFERRED`.
|
||||
|
||||
## 9. What is left to the builder
|
||||
|
||||
1. Whether `scripts/tms-sdk` is a shell script, a CMake custom target, or both
|
||||
(a `make sdk` shim is likely enough).
|
||||
2. The exact `Tool` subclass shape (`GnuTool`-style vs plain `Tool`), and
|
||||
whether `-Wl,` parsing belongs in the Tool or the ToolChain.
|
||||
3. Whether `libtms` also carries `__tms_bitptr`-adjacent helpers or stays
|
||||
purely C.
|
||||
4. The precise `clang -###` line splits the driver test pins.
|
||||
5. Whether `-Map` defaults on or only on `-Wl,-Map` (leaning: default on, next
|
||||
to the output, because the map is the debugging surface this toolchain has).
|
||||
6. How the installed `tms-link` should signal a missing interpreter (shebang
|
||||
plus the driver's pre-flight check), and whether `tms-sdk` normalises the
|
||||
copied pair's permissions.
|
||||
|
||||
## 10. Risks and mitigations
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Sysroot drift from sources | `scripts/tms-sdk` is the only writer; a gate rebuilds and compares the CRT and library |
|
||||
| Committed vendor archives drift | A gate compares them against freshly extracted copies |
|
||||
| Installed linker drifts from `tools/tms-link` | `scripts/tms-sdk` copies it; a gate compares the installed pair against the sources |
|
||||
| `python3` missing at link time | The driver detects it and names `scripts/tms-sdk` and `python3` in the diagnostic |
|
||||
| The IR CRT shifts the runtime contract | The contract list in §8.3 is the test: `tms-run` output, argv, status and buffer addresses |
|
||||
| `naked` + inline asm is fragile across LLVM bumps | The CRT gate pins the emitted bytes and `llc`'s no-prologue output |
|
||||
| Driver bakes in a checkout path | Discovery is resource-dir relative; the driver test asserts it |
|
||||
| Link failures from an uninstalled sysroot | A missing sysroot is a named diagnostic telling the user to run `scripts/tms-sdk`, not a link error |
|
||||
| `tms-link` header defects surface late | M11.1 fixes the linker first and `coff-check` gates it |
|
||||
| Conformance harness forks its headers | Harness and sysroot share `sdk/include` |
|
||||
| `-g` silently stripped | Driver test pins `--keep-debug`; an M8-style dwarfdump check confirms the linked image |
|
||||
| Driver patch grows into generic clang | All new code stays in `ToolChains/TMS34010.*`; patch `0005` grows, nothing else |
|
||||
|
||||
## 11. Roadmap after M11
|
||||
|
||||
| Milestone | Scope | Why this order |
|
||||
|---|---|---|
|
||||
| **M12 — conformance classes** | inline-asm memory constraints (`m`/`o`/`V`), the `ST` clobber, `blockaddress`, nested functions, VLAs, sret/aggregate/variadic/float returns, runtime aborts, `pr63843` | Raises the suite's pass rate from 1,618 and removes the largest remaining silent-failure classes |
|
||||
| **M13 — performance and hardware** | attribute the slow-phase 2,440 → 3,302-frame delta; further divide/loop work; the real VT1200 run when a unit exists | Needs a stable correctness baseline (M10–M12) before measuring |
|
||||
| **M14 — hosted I/O (optional)** | real console/serial output, then file APIs; a terminal `printf` instead of the result block | Largest scope and the least certain requirement; deliberately last |
|
||||
|
||||
Each milestone gets its own design and plan; this table only fixes the order.
|
||||
|
||||
## 12. Decisions log
|
||||
|
||||
| Decision | Choice | By |
|
||||
|---|---|---|
|
||||
| M11 scope | Phase 3: freestanding toolchain with conventional UX | user (earlier) |
|
||||
| Artifact discovery | Resource-directory sysroot built and installed by `scripts/tms-sdk` (approach A) | user |
|
||||
| Linker discovery | `scripts/tms-sdk` installs `tms-link` + `tmscoff.py` into `<sysroot>/bin/`; the driver resolves it relative to the sysroot, `--tms-linker=` overrides | user |
|
||||
| CRT source/build | `sdk/crt0.ll` (naked `_start` + inline asm) built by `llc`; acceptance is `llc` self-consistency | this doc (corrected during M11 execution: `llvm-mc` emits ELF) |
|
||||
| Link-reduction knobs | `-nostartfiles`, `-nodefaultlibs`, `-nostdlib` all supported | this doc |
|
||||
| `libtms.a` fidelity | Rebuild-and-compare against `sdk/`, plus the suite | this doc |
|
||||
| Vendor archives | Committed to the repo, compared by a gate | user (earlier) |
|
||||
| Hosted libc | Out of scope | user (earlier) |
|
||||
| `tms-cc` | Kept as a compatibility alias | this doc |
|
||||
| `coff-check --repair` | Leaves the production path; `tms-link` emits valid images | this doc |
|
||||
| Milestone order | M11 → M12 (conformance) → M13 (performance/hardware) → M14 (hosted I/O, optional) | this doc |
|
||||
@@ -0,0 +1,731 @@
|
||||
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
index ae3eecc60fc7..eef40fc1306d 100644
|
||||
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
@@ -787,6 +787,14 @@ def warn_drv_darwin_sdk_invalid_settings : Warning<
|
||||
InGroup<DiagGroup<"darwin-sdk-settings">>;
|
||||
|
||||
def err_missing_sysroot : Error<"no such sysroot directory: '%0'">;
|
||||
+def err_drv_tms34010_missing_sysroot : Error<
|
||||
+ "TMS34010 sysroot not found: '%0'; run 'scripts/tms-sdk' to build and install it">;
|
||||
+def err_drv_tms34010_missing_linker : Error<
|
||||
+ "TMS34010 linker not found: '%0'; run 'scripts/tms-sdk' to install it">;
|
||||
+def err_drv_tms34010_missing_python3 : Error<
|
||||
+ "python3 not found on PATH; the TMS34010 linker requires it (install python3)">;
|
||||
+def err_drv_tms34010_missing_artifact : Error<
|
||||
+ "TMS34010 sysroot is incomplete: '%0' is missing; run 'scripts/tms-sdk' to install it">;
|
||||
def err_drv_darwin_sdk_missing_arclite : Error<
|
||||
"SDK does not contain 'libarclite' at the path '%0'; try increasing the minimum deployment target">;
|
||||
|
||||
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
|
||||
index f893d858d526..5ada0996811e 100644
|
||||
--- a/clang/include/clang/Options/Options.td
|
||||
+++ b/clang/include/clang/Options/Options.td
|
||||
@@ -6981,6 +6981,14 @@ def _help_hidden : Flag<["--"], "help-hidden">,
|
||||
HelpText<"Display help for hidden options">;
|
||||
def _sysroot_EQ : Joined<["--"], "sysroot=">, Visibility<[ClangOption, FlangOption]>;
|
||||
def _sysroot : Separate<["--"], "sysroot">, Alias<_sysroot_EQ>;
|
||||
+def tms_sysroot_EQ : Joined<["--"], "tms-sysroot=">,
|
||||
+ Visibility<[ClangOption, FlangOption]>,
|
||||
+ HelpText<"Use the given directory as the TMS34010 sysroot (default: "
|
||||
+ "<resource-dir>/tms34010-unknown-none)">;
|
||||
+def tms_linker_EQ : Joined<["--"], "tms-linker=">,
|
||||
+ Visibility<[ClangOption, FlangOption]>,
|
||||
+ HelpText<"Use the given executable as the TMS34010 linker (default: "
|
||||
+ "<sysroot>/bin/tms-link)">;
|
||||
def no_xcselect : Flag<["--"], "no-xcselect">,
|
||||
HelpText<"Disable xcselect SDK injection on macOS">;
|
||||
|
||||
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
|
||||
index 506536cdc04f..71ce08e3e5b6 100644
|
||||
--- a/clang/lib/Driver/CMakeLists.txt
|
||||
+++ b/clang/lib/Driver/CMakeLists.txt
|
||||
@@ -91,6 +91,7 @@ add_clang_library(clangDriver
|
||||
ToolChains/SPIRVOpenMP.cpp
|
||||
ToolChains/SYCL.cpp
|
||||
ToolChains/TCE.cpp
|
||||
+ ToolChains/TMS34010.cpp
|
||||
ToolChains/UEFI.cpp
|
||||
ToolChains/VEToolchain.cpp
|
||||
ToolChains/WebAssembly.cpp
|
||||
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
|
||||
index e606cdc4c1cf..8a36e6a29fae 100644
|
||||
--- a/clang/lib/Driver/Driver.cpp
|
||||
+++ b/clang/lib/Driver/Driver.cpp
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "ToolChains/Serenity.h"
|
||||
#include "ToolChains/Solaris.h"
|
||||
#include "ToolChains/TCE.h"
|
||||
+#include "ToolChains/TMS34010.h"
|
||||
#include "ToolChains/UEFI.h"
|
||||
#include "ToolChains/VEToolchain.h"
|
||||
#include "ToolChains/WebAssembly.h"
|
||||
@@ -7287,6 +7288,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
|
||||
case llvm::Triple::msp430:
|
||||
TC = std::make_unique<toolchains::MSP430ToolChain>(*this, Target, Args);
|
||||
break;
|
||||
+ case llvm::Triple::tms34010:
|
||||
+ TC = std::make_unique<toolchains::TMS34010ToolChain>(*this, Target, Args);
|
||||
+ break;
|
||||
case llvm::Triple::riscv32:
|
||||
case llvm::Triple::riscv64:
|
||||
case llvm::Triple::riscv32be:
|
||||
diff --git a/clang/lib/Driver/ToolChains/TMS34010.cpp b/clang/lib/Driver/ToolChains/TMS34010.cpp
|
||||
new file mode 100644
|
||||
index 000000000000..238913e830b0
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/TMS34010.cpp
|
||||
@@ -0,0 +1,264 @@
|
||||
+//===--- TMS34010.cpp - TMS34010 ToolChain ----------------------*- C++ -*-===//
|
||||
+//
|
||||
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
+// See https://llvm.org/LICENSE.txt for license information.
|
||||
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
+//
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+#include "TMS34010.h"
|
||||
+
|
||||
+#include "clang/Driver/Compilation.h"
|
||||
+#include "clang/Driver/Driver.h"
|
||||
+#include "clang/Driver/InputInfo.h"
|
||||
+#include "clang/Driver/Tool.h"
|
||||
+#include "clang/Options/Options.h"
|
||||
+#include "llvm/Option/ArgList.h"
|
||||
+#include "llvm/Support/FileSystem.h"
|
||||
+#include "llvm/Support/Path.h"
|
||||
+#include "llvm/Support/Program.h"
|
||||
+
|
||||
+using namespace clang;
|
||||
+using namespace clang::driver;
|
||||
+using namespace clang::driver::toolchains;
|
||||
+using namespace clang::driver::tools;
|
||||
+using namespace llvm::opt;
|
||||
+
|
||||
+TMS34010ToolChain::TMS34010ToolChain(const Driver &D, const llvm::Triple &Triple,
|
||||
+ const ArgList &Args)
|
||||
+ : BareMetal(D, Triple, Args) {
|
||||
+ // Sysroot search order: --tms-sysroot=DIR, then --sysroot/-isysroot, then the
|
||||
+ // resource directory. Nothing here bakes a checkout path: the resource-dir
|
||||
+ // fallback is derived from the clang binary, so the toolchain stays
|
||||
+ // relocatable.
|
||||
+ if (const Arg *A = Args.getLastArg(options::OPT_tms_sysroot_EQ))
|
||||
+ SysRoot = A->getValue();
|
||||
+ else if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ,
|
||||
+ options::OPT_isysroot))
|
||||
+ SysRoot = A->getValue();
|
||||
+ else {
|
||||
+ SmallString<128> P(D.ResourceDir);
|
||||
+ llvm::sys::path::append(P, "tms34010-unknown-none");
|
||||
+ SysRoot = std::string(P.str());
|
||||
+ }
|
||||
+
|
||||
+ // Objects and libraries come from <sysroot>/lib.
|
||||
+ SmallString<128> LibDir(SysRoot);
|
||||
+ llvm::sys::path::append(LibDir, "lib");
|
||||
+ getFilePaths().push_back(std::string(LibDir.str()));
|
||||
+ getLibraryPaths().push_back(std::string(LibDir.str()));
|
||||
+}
|
||||
+
|
||||
+void TMS34010ToolChain::addClangTargetOptions(
|
||||
+ const ArgList &DriverArgs, ArgStringList &CC1Args, BoundArch BA,
|
||||
+ Action::OffloadKind DeviceOffloadKind) const {
|
||||
+ // The TMS34010 backend has no native 33-bit multiply, so IndVarSimplify's
|
||||
+ // i33 exit-value rewrite would otherwise reach code generation and abort on
|
||||
+ // an ordinary loop. Disable that rewrite, and compile freestanding with no
|
||||
+ // builtins (there is no libc for this target yet).
|
||||
+ CC1Args.push_back("-ffreestanding");
|
||||
+ CC1Args.push_back("-fno-builtin");
|
||||
+ CC1Args.push_back("-mllvm");
|
||||
+ CC1Args.push_back("-replexitval=never");
|
||||
+ // The legacy tms-clang path ran the -O0 pipeline without the `optnone`
|
||||
+ // attribute (it passed -disable-O0-optnone), so its -O0 objects carry the
|
||||
+ // mem2reg'd shape and no per-parameter spill slot. Match that so native
|
||||
+ // `clang --target=tms34010 -O0 -c` stays byte-identical to the M9 path.
|
||||
+ CC1Args.push_back("-disable-O0-optnone");
|
||||
+
|
||||
+ BareMetal::addClangTargetOptions(DriverArgs, CC1Args, BA, DeviceOffloadKind);
|
||||
+}
|
||||
+
|
||||
+void TMS34010ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
||||
+ ArgStringList &CC1Args) const {
|
||||
+ if (DriverArgs.hasArg(options::OPT_nostdinc))
|
||||
+ return;
|
||||
+
|
||||
+ // The target's headers live in <sysroot>/include; the builtin headers keep
|
||||
+ // being found through -resource-dir, matching the M10 freestanding defaults.
|
||||
+ if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
|
||||
+ SmallString<128> IncDir(SysRoot);
|
||||
+ llvm::sys::path::append(IncDir, "include");
|
||||
+ addSystemInclude(DriverArgs, CC1Args, IncDir.str());
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+Tool *TMS34010ToolChain::buildLinker() const {
|
||||
+ return new tools::tms34010::TMS34010Linker(*this);
|
||||
+}
|
||||
+
|
||||
+void tms34010::TMS34010Linker::ConstructJob(
|
||||
+ Compilation &C, const JobAction &JA, const InputInfo &Output,
|
||||
+ const InputInfoList &Inputs, const ArgList &Args,
|
||||
+ const char *LinkingOutput) const {
|
||||
+ const auto &TC =
|
||||
+ static_cast<const toolchains::TMS34010ToolChain &>(getToolChain());
|
||||
+ const Driver &D = TC.getDriver();
|
||||
+ const std::string &SysRoot = TC.getTMS34010SysRoot();
|
||||
+
|
||||
+ // Linker discovery: --tms-linker=PATH first, else <sysroot>/bin/tms-link.
|
||||
+ const bool UseDefaultLinker = !Args.hasArg(options::OPT_tms_linker_EQ);
|
||||
+ std::string Linker;
|
||||
+ if (const Arg *A = Args.getLastArg(options::OPT_tms_linker_EQ)) {
|
||||
+ Linker = A->getValue();
|
||||
+ } else {
|
||||
+ SmallString<128> DefaultLinker(SysRoot);
|
||||
+ llvm::sys::path::append(DefaultLinker, "bin", "tms-link");
|
||||
+ Linker = std::string(DefaultLinker.str());
|
||||
+ }
|
||||
+
|
||||
+ // A missing sysroot, a missing linker or a missing python3 is a named
|
||||
+ // diagnostic telling the user to run scripts/tms-sdk -- never a bare link
|
||||
+ // error. The explicit --tms-linker path is trusted verbatim, so neither the
|
||||
+ // linker-existence nor the python3 check applies to it.
|
||||
+ if (!llvm::sys::fs::exists(SysRoot)) {
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_sysroot) << SysRoot;
|
||||
+ return;
|
||||
+ }
|
||||
+ if (UseDefaultLinker && !llvm::sys::fs::exists(Linker)) {
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_linker) << Linker;
|
||||
+ return;
|
||||
+ }
|
||||
+ // The installed tms-link is a Python program; name python3 if it is missing.
|
||||
+ if (UseDefaultLinker && !llvm::sys::findProgramByName("python3")) {
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_python3);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ // Fixed link order: CRT, user objects, the three default libraries, then
|
||||
+ // user -L/-l archives.
|
||||
+ const bool WantStartFiles =
|
||||
+ !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
|
||||
+ const bool WantDefaultLibs =
|
||||
+ !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs);
|
||||
+
|
||||
+ // A sysroot directory can exist while the artifacts the default link needs
|
||||
+ // are absent (a partial install). Name the missing file instead of handing
|
||||
+ // tms-link a bare name it will fail to open.
|
||||
+ bool MissingArtifact = false;
|
||||
+ auto CheckArtifact = [&](StringRef Name) {
|
||||
+ SmallString<128> P(SysRoot);
|
||||
+ llvm::sys::path::append(P, "lib", Name);
|
||||
+ if (llvm::sys::fs::exists(P))
|
||||
+ return;
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_artifact) << std::string(P.str());
|
||||
+ MissingArtifact = true;
|
||||
+ };
|
||||
+ if (WantStartFiles)
|
||||
+ CheckArtifact("crt0.o");
|
||||
+ if (WantDefaultLibs) {
|
||||
+ CheckArtifact("libtms.a");
|
||||
+ CheckArtifact("flib.lib");
|
||||
+ CheckArtifact("rts.lib");
|
||||
+ }
|
||||
+ if (MissingArtifact)
|
||||
+ return;
|
||||
+
|
||||
+ ArgStringList CmdArgs;
|
||||
+
|
||||
+ CmdArgs.push_back("-o");
|
||||
+ CmdArgs.push_back(Output.getFilename());
|
||||
+
|
||||
+ CmdArgs.push_back("--entry");
|
||||
+ CmdArgs.push_back("_start");
|
||||
+ CmdArgs.push_back("--text");
|
||||
+ CmdArgs.push_back("018A0000");
|
||||
+ CmdArgs.push_back("--bss");
|
||||
+ CmdArgs.push_back("01A00000");
|
||||
+ CmdArgs.push_back("--prog-len");
|
||||
+ CmdArgs.push_back("40000h");
|
||||
+ CmdArgs.push_back("--ram-len");
|
||||
+ CmdArgs.push_back("80000h");
|
||||
+
|
||||
+ // -Wl,-Map suppresses the default --map; -Wl,-Map=<file> and the
|
||||
+ // -Wl,-Map,<file> comma form select an explicit map file. tms-link spells
|
||||
+ // its map option --map, so both forms become --map=<file> below.
|
||||
+ auto WlValues = Args.getAllArgValues(options::OPT_Wl_COMMA);
|
||||
+ bool HasExplicitMap = false;
|
||||
+ for (const std::string &Value : WlValues) {
|
||||
+ StringRef V(Value);
|
||||
+ if (V == "-Map" || V.starts_with("-Map="))
|
||||
+ HasExplicitMap = true;
|
||||
+ }
|
||||
+
|
||||
+ // The map is this toolchain's debugging surface: default it next to the
|
||||
+ // output unless the user asked for a -Wl,-Map* form.
|
||||
+ if (!HasExplicitMap) {
|
||||
+ std::string MapFile = std::string(Output.getFilename()) + ".map";
|
||||
+ CmdArgs.push_back("--map");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(MapFile));
|
||||
+ }
|
||||
+
|
||||
+ // -g keeps the DWARF in the linked image; the default stays stripped. -g0
|
||||
+ // (and -ggdb0) request no debug info, so they must not add --keep-debug.
|
||||
+ if (Arg *A = Args.getLastArg(options::OPT_g_Group))
|
||||
+ if (!A->getOption().matches(options::OPT_g0) &&
|
||||
+ !A->getOption().matches(options::OPT_ggdb0))
|
||||
+ CmdArgs.push_back("--keep-debug");
|
||||
+
|
||||
+ // Pass the remaining -Wl, arguments through verbatim, translating the map
|
||||
+ // requests. -Wl,-Map,<file> keeps the path in the following comma element.
|
||||
+ for (size_t I = 0, E = WlValues.size(); I != E; ++I) {
|
||||
+ StringRef V(WlValues[I]);
|
||||
+ if (V == "-Map") {
|
||||
+ // A bare -Wl,-Map has no path and produces no map (it still suppresses
|
||||
+ // the default map, as above); a following element is the map path.
|
||||
+ if (I + 1 != E) {
|
||||
+ std::string MapArg = "--map=" + std::string(WlValues[++I]);
|
||||
+ CmdArgs.push_back(Args.MakeArgString(MapArg));
|
||||
+ }
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (V.starts_with("-Map=")) {
|
||||
+ std::string MapArg = "--map=" + std::string(V.drop_front(5));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(MapArg));
|
||||
+ continue;
|
||||
+ }
|
||||
+ CmdArgs.push_back(Args.MakeArgString(V));
|
||||
+ }
|
||||
+
|
||||
+ // Fixed link order: CRT, user objects, the three default libraries, then
|
||||
+ // user -L/-l archives.
|
||||
+ if (WantStartFiles)
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
|
||||
+
|
||||
+ for (const auto &II : Inputs) {
|
||||
+ if (II.isFilename())
|
||||
+ CmdArgs.push_back(II.getFilename());
|
||||
+ }
|
||||
+
|
||||
+ if (WantDefaultLibs) {
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("libtms.a")));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("flib.lib")));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("rts.lib")));
|
||||
+ }
|
||||
+
|
||||
+ // Make the sysroot's own library directory reachable for -l lookups before
|
||||
+ // any user -L paths.
|
||||
+ SmallString<128> SysRootLib(SysRoot);
|
||||
+ llvm::sys::path::append(SysRootLib, "lib");
|
||||
+ CmdArgs.push_back("-L");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(SysRootLib.str()));
|
||||
+
|
||||
+ for (const std::string &LibPath : Args.getAllArgValues(options::OPT_L)) {
|
||||
+ CmdArgs.push_back("-L");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(LibPath));
|
||||
+ }
|
||||
+ for (const std::string &Lib : Args.getAllArgValues(options::OPT_l)) {
|
||||
+ // -l tms means "ensure libtms.a is linked". With the defaults it is already
|
||||
+ // a positional input, so it is a no-op; with -nodefaultlibs/-nostdlib the
|
||||
+ // user's -l tms is the only request, so resolve it to the archive so it is
|
||||
+ // linked once per request (repeating -l tms links the archive again).
|
||||
+ if (StringRef(Lib) == "tms") {
|
||||
+ if (!WantDefaultLibs)
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("libtms.a")));
|
||||
+ continue;
|
||||
+ }
|
||||
+ CmdArgs.push_back("-l");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(Lib));
|
||||
+ }
|
||||
+
|
||||
+ C.addCommand(std::make_unique<Command>(
|
||||
+ JA, *this, ResponseFileSupport::None(),
|
||||
+ Args.MakeArgString(Linker), CmdArgs, Inputs, Output));
|
||||
+}
|
||||
diff --git a/clang/lib/Driver/ToolChains/TMS34010.h b/clang/lib/Driver/ToolChains/TMS34010.h
|
||||
new file mode 100644
|
||||
index 000000000000..e69011479677
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/TMS34010.h
|
||||
@@ -0,0 +1,68 @@
|
||||
+//===--- TMS34010.h - TMS34010 ToolChain ------------------------*- C++ -*-===//
|
||||
+//
|
||||
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
+// See https://llvm.org/LICENSE.txt for license information.
|
||||
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
+//
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
+
|
||||
+#include "BareMetal.h"
|
||||
+#include "clang/Driver/Tool.h"
|
||||
+
|
||||
+namespace clang {
|
||||
+namespace driver {
|
||||
+namespace toolchains {
|
||||
+
|
||||
+class LLVM_LIBRARY_VISIBILITY TMS34010ToolChain : public BareMetal {
|
||||
+public:
|
||||
+ TMS34010ToolChain(const Driver &D, const llvm::Triple &Triple,
|
||||
+ const llvm::opt::ArgList &Args);
|
||||
+
|
||||
+ void
|
||||
+ addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
|
||||
+ llvm::opt::ArgStringList &CC1Args, BoundArch BA,
|
||||
+ Action::OffloadKind DeviceOffloadKind) const override;
|
||||
+
|
||||
+ void
|
||||
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
||||
+ llvm::opt::ArgStringList &CC1Args) const override;
|
||||
+
|
||||
+ /// The sysroot this target's headers, libraries and linker come from,
|
||||
+ /// resolved from --tms-sysroot=, --sysroot/-isysroot, or the resource dir.
|
||||
+ std::string getTMS34010SysRoot() const { return SysRoot; }
|
||||
+
|
||||
+protected:
|
||||
+ Tool *buildLinker() const override;
|
||||
+
|
||||
+private:
|
||||
+ std::string SysRoot;
|
||||
+};
|
||||
+
|
||||
+} // namespace toolchains
|
||||
+
|
||||
+namespace tools {
|
||||
+namespace tms34010 {
|
||||
+
|
||||
+class LLVM_LIBRARY_VISIBILITY TMS34010Linker final : public Tool {
|
||||
+public:
|
||||
+ TMS34010Linker(const ToolChain &TC)
|
||||
+ : Tool("tms34010::Linker", "tms-link", TC) {}
|
||||
+
|
||||
+ bool isLinkJob() const override { return true; }
|
||||
+ bool hasIntegratedCPP() const override { return false; }
|
||||
+
|
||||
+ void ConstructJob(Compilation &C, const JobAction &JA,
|
||||
+ const InputInfo &Output, const InputInfoList &Inputs,
|
||||
+ const llvm::opt::ArgList &TCArgs,
|
||||
+ const char *LinkingOutput) const override;
|
||||
+};
|
||||
+
|
||||
+} // namespace tms34010
|
||||
+} // namespace tools
|
||||
+} // namespace driver
|
||||
+} // namespace clang
|
||||
+
|
||||
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-chain-o2.c b/clang/test/CodeGen/TMS34010/bitaddr-chain-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..8d4a838ac157
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-chain-o2.c
|
||||
@@ -0,0 +1,24 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// Source-level pointer arithmetic goes through the pre-optimizer barrier
|
||||
+// (@__tms_bitptr) and is lowered back by tms34010LowerBitPtr. If that lowering
|
||||
+// emitted the foldable `inttoptr(add(ptrtoint base, off))` form, the already-bit
|
||||
+// offsets would fold to a plain ISD::ADD on `p:32` and DAGCombiner's
|
||||
+// BaseIndexOffset aliasing would read them as *bytes*: the word store to p+32
|
||||
+// bits and the byte store to p+40 bits would be misread as +32 and +40 bytes
|
||||
+// and reported non-aliasing, and parallelizeChainedStores would hoist the byte
|
||||
+// store ahead of the word store (the word store then overwrites the byte).
|
||||
+//
|
||||
+// The lowering emits llvm.tms34010.bitaddr instead, which lowers to a
|
||||
+// TMS34010ISD::BITADDR node that BaseIndexOffset cannot decompose, so the byte
|
||||
+// store keeps its program-order position after the word store.
|
||||
+
|
||||
+void f(int *p, int v, int w) { p[0] = v; p[1] = w; ((char *)p)[5] = 0x7f; }
|
||||
+
|
||||
+// The word store to p+32 bits (MOVE ..., *..., 1 after ADDI 32) must be
|
||||
+// scheduled before the byte store to p+40 bits (MOVB after ADDI 40).
|
||||
+// CHECK-LABEL: _f:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK: MOVE A{{[0-9]+}}, *A{{[0-9]+}}, 1
|
||||
+// CHECK: ADDI 40, A{{[0-9]+}}
|
||||
+// CHECK: MOVB A{{[0-9]+}}, *A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o0.c b/clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
new file mode 100644
|
||||
index 000000000000..e62cab807aa3
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
@@ -0,0 +1,18 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// The bit-address barrier hides each source GEP behind an opaque
|
||||
+// @__tms_bitptr(i32 bitoff, ptr base) call before the optimizer, and -O0
|
||||
+// lowers it straight back to the bit-addressed inttoptr(add) form, so a
|
||||
+// byte-indexed GEP must reach codegen as an 8x bit offset.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+short load_h(short *p) { return p[1]; }
|
||||
+int load_b(char *p) { return p[4]; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _load_h:
|
||||
+// CHECK: ADDI 16, A{{[0-9]+}}
|
||||
+// CHECK-LABEL: _load_b:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o1.c b/clang/test/CodeGen/TMS34010/bitaddr-o1.c
|
||||
new file mode 100644
|
||||
index 000000000000..acefd9de2af6
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o1.c
|
||||
@@ -0,0 +1,20 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O1 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// The -O0 sibling (bitaddr-o0.c) pins the byte-indexed-GEP bit-address shape
|
||||
+// on the no-optimizer path. -O1 takes the optimizer-last path instead: the
|
||||
+// bit-address barrier hides each source GEP before the optimizer, the post-opt
|
||||
+// scale rescales the byte GEPs the optimizer creates, and lowering undoes the
|
||||
+// barrier. This test pins the same shape on that path, which is otherwise
|
||||
+// covered only indirectly by the static-variadic guard test.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+short load_h(short *p) { return p[1]; }
|
||||
+int load_b(char *p) { return p[4]; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _load_h:
|
||||
+// CHECK: ADDI 16, A{{[0-9]+}}
|
||||
+// CHECK-LABEL: _load_b:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o2.c b/clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..39b0f38ce948
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
@@ -0,0 +1,17 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// At -O2 the barrier hides source GEPs before the optimizer, the post-opt
|
||||
+// scale rescales the byte GEPs the optimizer creates, lowering undoes the
|
||||
+// barrier, and a final instcombine canonicalizes the result, so a byte-indexed
|
||||
+// GEP must still reach codegen as an 8x bit offset. `-replexitval=never` is
|
||||
+// the ToolChain default (Task 1); %clang_cc1 bypasses the driver, so it is
|
||||
+// passed explicitly to keep the `sumto` loop below the i33 closed-form
|
||||
+// rewrite.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+int sumto(int n) { int s = 0; for (int i = 0; i <= n; i++) s += i; return s; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _sumto:
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c b/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
new file mode 100644
|
||||
index 000000000000..fc6867b143b4
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
@@ -0,0 +1,6 @@
|
||||
+// RUN: not %clang_cc1 -triple tms34010-unknown-none -O1 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
+// RUN: not %clang_cc1 -triple tms34010-unknown-none -O2 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -emit-obj %s -o /dev/null
|
||||
+// CHECK: static variadic definition 'sum' loses its '...' arguments when optimizing
|
||||
+static int sum(int n, ...) { int *p = &n; return p[0] + p[1]; }
|
||||
+int call(void) { return sum(1, 2); }
|
||||
diff --git a/clang/test/CodeGen/TMS34010/float-const-o2.c b/clang/test/CodeGen/TMS34010/float-const-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..4f244591b61a
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/float-const-o2.c
|
||||
@@ -0,0 +1,26 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// A float literal stored to memory through a union (or returned by a helper
|
||||
+// whose constant result IPSCCP propagates) must be materialised from a
|
||||
+// GSP-initialised global. The early float-constant protection keeps the
|
||||
+// constant a load before the optimizer can fold it through the union bitcast
|
||||
+// to its IEEE bits; the AsmPrinter then emits the GSP words.
|
||||
+
|
||||
+typedef unsigned int u32;
|
||||
+typedef union { float f; u32 u; } fu;
|
||||
+extern volatile u32 markers[];
|
||||
+
|
||||
+static void mark_f(u32 n, float v) { fu x; x.f = v; markers[n] = x.u; }
|
||||
+float fnegzero(void) { return -0.0f; }
|
||||
+
|
||||
+void run(void) {
|
||||
+ mark_f(0, 7.0f); // GSP 41700000h, never IEEE 40E00000h
|
||||
+ mark_f(1, fnegzero()); // GSP +0, never IEEE -0 (80000000h)
|
||||
+}
|
||||
+
|
||||
+// 7.0f is GSP 41700000h and -0.0f canonicalises to +0 (all zeroes); the IEEE
|
||||
+// bits (40E00000h / 80000000h) must never be stored anywhere.
|
||||
+// CHECK-DAG: .long 41700000h
|
||||
+// CHECK-DAG: .long 00000000h
|
||||
+// CHECK-NOT: .long 40E00000h
|
||||
+// CHECK-NOT: .long 80000000h
|
||||
diff --git a/clang/test/Driver/TMS34010-link.c b/clang/test/Driver/TMS34010-link.c
|
||||
new file mode 100644
|
||||
index 000000000000..3b067d9eb3b6
|
||||
--- /dev/null
|
||||
+++ b/clang/test/Driver/TMS34010-link.c
|
||||
@@ -0,0 +1,147 @@
|
||||
+// Check that the TMS34010 driver discovers its sysroot and turns a link into a
|
||||
+// real tms-link job, and that the link-reduction knobs, -g and -Wl, behave.
|
||||
+//
|
||||
+// The link cases below use a fake sysroot so the test is hermetic and does
|
||||
+// not depend on `scripts/tms-sdk` having been run: the CRT and the three
|
||||
+// libraries are empty placeholders under <sysroot>/lib, and the linker is the
|
||||
+// touched placeholder under <sysroot>/bin.
|
||||
+
|
||||
+// RUN: rm -rf %t.sysroot && mkdir -p %t.sysroot/bin %t.sysroot/lib %t.sysroot/include
|
||||
+// RUN: touch %t.sysroot/bin/tms-link %t.sysroot/lib/crt0.o %t.sysroot/lib/libtms.a %t.sysroot/lib/flib.lib %t.sysroot/lib/rts.lib
|
||||
+
|
||||
+// Default link: the sysroot linker, the fixed flags, the CRT, the object and
|
||||
+// the three default libraries, plus the sysroot include path and a default map.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot %s -o %t.out 2>&1 | FileCheck %s --check-prefix=DEFAULT
|
||||
+// DEFAULT: "-internal-isystem" "{{.*}}sysroot{{/|\\}}include"
|
||||
+// DEFAULT: "{{.*}}tms-link"
|
||||
+// DEFAULT-SAME: "-o" "{{.*}}.out"
|
||||
+// DEFAULT-SAME: "--entry" "_start"
|
||||
+// DEFAULT-SAME: "--text" "018A0000"
|
||||
+// DEFAULT-SAME: "--bss" "01A00000"
|
||||
+// DEFAULT-SAME: "--prog-len" "40000h"
|
||||
+// DEFAULT-SAME: "--ram-len" "80000h"
|
||||
+// DEFAULT-SAME: "--map" "{{.*}}.out.map"
|
||||
+// DEFAULT-SAME: crt0.o
|
||||
+// DEFAULT-SAME: libtms.a
|
||||
+// DEFAULT-SAME: flib.lib
|
||||
+// DEFAULT-SAME: rts.lib
|
||||
+// DEFAULT-SAME: "-L" "{{.*}}sysroot{{/|\\}}lib"
|
||||
+
|
||||
+// -nostdlib drops the CRT and all three libraries.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nostdlib %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOSTDLIB
|
||||
+// NOSTDLIB: "{{.*}}tms-link"
|
||||
+// NOSTDLIB-NOT: crt0.o
|
||||
+// NOSTDLIB-NOT: libtms.a
|
||||
+// NOSTDLIB-NOT: flib.lib
|
||||
+// NOSTDLIB-NOT: rts.lib
|
||||
+
|
||||
+// -nostartfiles drops only the CRT; the libraries remain.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nostartfiles %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOSTART
|
||||
+// NOSTART: "{{.*}}tms-link"
|
||||
+// NOSTART-NOT: crt0.o
|
||||
+// NOSTART-SAME: libtms.a
|
||||
+// NOSTART-SAME: flib.lib
|
||||
+// NOSTART-SAME: rts.lib
|
||||
+
|
||||
+// -nodefaultlibs keeps the CRT but drops the three libraries.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nodefaultlibs %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NODEFLTLIBS
|
||||
+// NODEFLTLIBS: "{{.*}}tms-link"
|
||||
+// NODEFLTLIBS-SAME: crt0.o
|
||||
+// NODEFLTLIBS-NOT: libtms.a
|
||||
+// NODEFLTLIBS-NOT: flib.lib
|
||||
+// NODEFLTLIBS-NOT: rts.lib
|
||||
+
|
||||
+// With -nodefaultlibs, -l tms is the user's only way to ask for the archive;
|
||||
+// it must resolve to libtms.a exactly once, with no flib/rts.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nodefaultlibs -l tms %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NODEFL_LTMS
|
||||
+// NODEFL_LTMS: "{{.*}}tms-link"
|
||||
+// NODEFL_LTMS-SAME: crt0.o
|
||||
+// NODEFL_LTMS-SAME: libtms.a
|
||||
+// NODEFL_LTMS-NOT: libtms.a
|
||||
+// NODEFL_LTMS-NOT: flib.lib
|
||||
+// NODEFL_LTMS-NOT: rts.lib
|
||||
+// NODEFL_LTMS-NOT: "-l" "tms"
|
||||
+
|
||||
+// -g adds --keep-debug.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -g %s -o %t.out 2>&1 | FileCheck %s --check-prefix=G
|
||||
+// G: "{{.*}}tms-link"
|
||||
+// G-SAME: "--keep-debug"
|
||||
+
|
||||
+// -g0 and -ggdb0 request no debug info, so no --keep-debug.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -g0 %s -o %t.out 2>&1 | FileCheck %s --check-prefix=G0
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -ggdb0 %s -o %t.out 2>&1 | FileCheck %s --check-prefix=G0
|
||||
+// G0: "{{.*}}tms-link"
|
||||
+// G0-NOT: "--keep-debug"
|
||||
+
|
||||
+// -Wl, arguments pass through verbatim.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -Wl,--prog-len=80000h %s -o %t.out 2>&1 | FileCheck %s --check-prefix=WL
|
||||
+// WL: "{{.*}}tms-link"
|
||||
+// WL-SAME: "--prog-len=80000h"
|
||||
+
|
||||
+// -Wl,-Map=<file> selects that map file and suppresses the default --map.
|
||||
+// The NOT range starts at the linker token so a stray default map (which
|
||||
+// would be emitted before the translated --map=) is caught too.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -Wl,-Map=foo.map %s -o %t.out 2>&1 | FileCheck %s --check-prefix=MAPEQ
|
||||
+// MAPEQ: "{{.*}}tms-link"
|
||||
+// MAPEQ-NOT: "--map" "{{.*}}.out.map"
|
||||
+// MAPEQ: "--map=foo.map"
|
||||
+// MAPEQ-NOT: "foo.map"
|
||||
+
|
||||
+// -Wl,-Map,<file> (the comma form) consumes the next element as the map path
|
||||
+// instead of forwarding the filename as a linker input.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -Wl,-Map,foo.map %s -o %t.out 2>&1 | FileCheck %s --check-prefix=MAPCOMMA
|
||||
+// MAPCOMMA: "{{.*}}tms-link"
|
||||
+// MAPCOMMA-NOT: "--map" "{{.*}}.out.map"
|
||||
+// MAPCOMMA: "--map=foo.map"
|
||||
+// MAPCOMMA-NOT: "foo.map"
|
||||
+
|
||||
+// --tms-linker=PATH replaces the sysroot linker.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot --tms-linker=/tmp/x %s -o %t.out 2>&1 | FileCheck %s --check-prefix=LINKER
|
||||
+// LINKER: "/tmp/x"
|
||||
+// LINKER-SAME: "--entry" "_start"
|
||||
+
|
||||
+// -l tms is accepted and does not duplicate libtms.a.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -l tms %s -o %t.out 2>&1 | FileCheck %s --check-prefix=LTMS
|
||||
+// LTMS: "{{.*}}tms-link"
|
||||
+// LTMS-SAME: libtms.a
|
||||
+// LTMS-NOT: "-l" "tms"
|
||||
+
|
||||
+// A nonexistent sysroot is a named diagnostic, not a link error.
|
||||
+// RUN: not %clang -### --target=tms34010 --tms-sysroot=/nope %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOSYSROOT
|
||||
+// NOSYSROOT: error: TMS34010 sysroot not found
|
||||
+// NOSYSROOT-SAME: run 'scripts/tms-sdk'
|
||||
+// NOSYSROOT-NOT: "tms-link"
|
||||
+
|
||||
+// A sysroot without bin/tms-link is a named diagnostic, not a link error.
|
||||
+// RUN: rm -rf %t.nolink && mkdir -p %t.nolink
|
||||
+// RUN: not %clang -### --target=tms34010 --tms-sysroot=%t.nolink %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOLINKER
|
||||
+// NOLINKER: error: TMS34010 linker not found
|
||||
+// NOLINKER-SAME: run 'scripts/tms-sdk'
|
||||
+// NOLINKER-NOT: "tms-link"
|
||||
+
|
||||
+// A sysroot directory that exists but lacks the artifacts the default link
|
||||
+// needs names each missing file and points at scripts/tms-sdk, instead of
|
||||
+// handing tms-link bare names.
|
||||
+// RUN: rm -rf %t.partial && mkdir -p %t.partial/bin %t.partial/lib %t.partial/include
|
||||
+// RUN: touch %t.partial/bin/tms-link
|
||||
+// RUN: not %clang -### --target=tms34010 --tms-sysroot=%t.partial %s -o %t.out 2>&1 | FileCheck %s --check-prefix=PARTIAL
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}crt0.o' is missing
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}libtms.a' is missing
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}flib.lib' is missing
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}rts.lib' is missing
|
||||
+// PARTIAL-DAG: run 'scripts/tms-sdk'
|
||||
+
|
||||
+// With -nostdlib nothing is needed from the sysroot's lib directory, so the
|
||||
+// same partial sysroot still reaches the (placeholder) linker.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.partial -nostdlib %s -o %t.out 2>&1 | FileCheck %s --check-prefix=PARTIALNOSTDLIB
|
||||
+// PARTIALNOSTDLIB: "{{.*}}tms-link"
|
||||
+// PARTIALNOSTDLIB-NOT: sysroot is incomplete
|
||||
+
|
||||
+// Compile-only modes emit no link job.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -c %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -S %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -E %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -S -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// NOLINK-NOT: tms-link
|
||||
+
|
||||
+int f(int n) { return n + 1; }
|
||||
diff --git a/clang/test/Driver/tms34010-defaults.c b/clang/test/Driver/tms34010-defaults.c
|
||||
new file mode 100644
|
||||
index 000000000000..568a4a0b3434
|
||||
--- /dev/null
|
||||
+++ b/clang/test/Driver/tms34010-defaults.c
|
||||
@@ -0,0 +1,9 @@
|
||||
+// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=FLAGS
|
||||
+// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=NOSYS
|
||||
+// FLAGS: "-cc1" {{.*}}-ffreestanding
|
||||
+// FLAGS-SAME: -fno-builtin
|
||||
+// FLAGS-SAME: "-mllvm" "-replexitval=never"
|
||||
+// FLAGS-SAME: "-disable-O0-optnone"
|
||||
+// NOSYS: "-internal-isystem" "{{.*}}tms34010-unknown-none{{/|\\}}include"
|
||||
+// NOSYS-NOT: "-internal-isystem" "/usr/"
|
||||
+int f(int n) { return n + 1; }
|
||||
+16
-15
@@ -25,7 +25,7 @@
|
||||
# (250,200) inside the mapped window. A markers-only or root-window bit is a
|
||||
# failure.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# Overridable: TMS_CLANG TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# SDK_IMG M3_WORK M3_COFF M3_SDK LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
@@ -34,8 +34,6 @@ DIR=$ROOT/scripts/m3
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
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_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
@@ -59,7 +57,7 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
@@ -68,19 +66,22 @@ mkdir -p "$(dirname "$COFF")"
|
||||
|
||||
# IndVarSimplify's exit-value replacement turns sumto's loop into an i33
|
||||
# multiply (n*(n+1)/2), and this target has no multiply or i64 support: llc
|
||||
# then dies selecting umul_lohi. Keep the loop (which is the point of the M3
|
||||
# branch test) by disabling only that rewrite, and only for branch.c; xhello
|
||||
# and layout use the normal optimizer pipeline. branch.c itself is unchanged.
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
# then dies selecting umul_lohi. The TMS34010 ToolChain passes
|
||||
# -mllvm -replexitval=never, so the ordinary tms-clang -O2 pipeline keeps the
|
||||
# loop (the point of the M3 branch test) with no local opt wrapper.
|
||||
echo "== compile and select"
|
||||
export TMS_CLANG TMS_BITADDR
|
||||
export TMS_CLANG
|
||||
for name in xhello branch layout; do
|
||||
opt=$TMS_OPT
|
||||
[ "$name" = branch ] && opt=$OPT_NOREPLEXIT
|
||||
TMS_OPT=$opt "$ROOT/scripts/tms-clang" -O2 -I "$DIR" -o "$ASM/$name.ll" "$DIR/$name.c"
|
||||
# branch.c needs -fno-inline: at -O2 clang inlines sumto/max2/lt into
|
||||
# branch_test and constant-folds sumto(10), so the disassembler round-trip
|
||||
# would have no _sumto/_max2/_lt calls to check. -O0 would stop the inlining
|
||||
# too, but it also changes the branch condition codes the round-trip pins
|
||||
# (sumto LT/EQ, max2 GT); -fno-inline keeps the -O2 shapes and just leaves
|
||||
# the calls in place.
|
||||
extra=
|
||||
[ "$name" = branch ] && extra=-fno-inline
|
||||
TMS_CLANG_EXTRA_FLAGS=$extra "$ROOT/scripts/tms-clang" -O2 -I "$DIR" \
|
||||
-o "$ASM/$name.ll" "$DIR/$name.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$ASM/$name.ll" -o "$ASM/$name.s" \
|
||||
|| fail "llc failed for $name.c"
|
||||
|
||||
+48
-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,20 @@ 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 "$lib" ]; then
|
||||
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $lib"
|
||||
elif [ -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 +335,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 +388,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 +416,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 +471,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,8 +7,8 @@ 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
|
||||
(bits) and bound .text/.data to prog and .bss/the markers to ram.
|
||||
uses up to 16 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
|
||||
could not be parsed.
|
||||
@@ -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 + 16 * 0x20
|
||||
regions = None
|
||||
if len(sys.argv) == 7:
|
||||
prog_origin, prog_len, ram_origin, ram_len = (
|
||||
|
||||
@@ -9,40 +9,61 @@
|
||||
-- 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, 32-bit divisor
|
||||
-- and hi(N) >= D -> two even-destination DIVUs (the M8.3 64/32
|
||||
-- path, quotient needs 33+ bits);
|
||||
-- div32 phase: 16384 iterations, nonzero dividend high word, 32-bit divisor
|
||||
-- and hi(N) < D -> one even-destination DIVU plus the low-word
|
||||
-- N - q*D reconstruction (the M9.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).
|
||||
-- The div32 phase must be measurable and materially faster than the M8.3
|
||||
-- two-DIVU wide phase: wide_frames*4 >= div32_frames*5 (1.25x).
|
||||
--
|
||||
-- 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 four 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 = 0xF56810CFEDA9D656, div32 = 0x00002C61C63842EE.
|
||||
-- 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, INT64_MIN (both the small-divisor two-step case and the
|
||||
-- 0xFFFFFFFF single-DIVU case, signed and unsigned magnitude) and the M9.3
|
||||
-- single-DIVU cases (0x1_00000000/3, 0x1_FFFFFFFF/0x10000, -2^32/3 and
|
||||
-- 2^32/-3), 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
|
||||
-- 11 div32 done 0x6432D0E5 | 12/13 div32 checksum
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "4000")
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "5000")
|
||||
local BASE = 0x01A20000
|
||||
local START = 0x51A47A11
|
||||
local FAST_DONE = 0xFA57D01E
|
||||
local SLOW_DONE = 0x5104D0E5
|
||||
local WIDE_DONE = 0x81DE0D0E
|
||||
local DIV32_DONE = 0x6432D0E5
|
||||
local STATUS_OK = 0x600D600D
|
||||
local FAST_HI, FAST_LO = 0x00000001, 0x1E6F9AB4
|
||||
local SLOW_HI, SLOW_LO = 0x00000000, 0x007512AE
|
||||
local WIDE_HI, WIDE_LO = 0xF56810CF, 0xEDA9D656
|
||||
local DIV32_HI, DIV32_LO = 0x00002C61, 0xC63842EE
|
||||
|
||||
local frames = 0
|
||||
local start_f, fast_f, slow_f
|
||||
local start_f, fast_f, slow_f, wide_f, div32_f
|
||||
local reported = false
|
||||
|
||||
local function rd(n)
|
||||
@@ -62,34 +83,67 @@ 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 wide_f ~= nil and div32_f == nil and rd(11) == DIV32_DONE then
|
||||
div32_f = frames
|
||||
end
|
||||
|
||||
if slow_f ~= nil and not reported then
|
||||
if div32_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 div32_frames = div32_f - wide_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 div32_basis = div32_frames
|
||||
if div32_basis < 1 then
|
||||
div32_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 cs_div32_hi, cs_div32_lo = rd(13), rd(12)
|
||||
local ratio = slow_frames / basis
|
||||
local wide_ratio = slow_frames / wide_basis
|
||||
local div32_ratio = wide_frames / div32_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
|
||||
and cs_div32_hi == DIV32_HI and cs_div32_lo == DIV32_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
|
||||
and div32_frames >= 2
|
||||
and wide_frames * 4 >= div32_basis * 5
|
||||
|
||||
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 div32_done=%d fast_frames=%d "
|
||||
.. "slow_frames=%d wide_frames=%d div32_frames=%d "
|
||||
.. "ratio=%.1f wide_ratio=%.1f div32_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_div32=%08X%08X "
|
||||
.. "cs_expected=%08X%08X/%08X%08X/%08X%08X/%08X%08X cs=%s",
|
||||
start_f, fast_f, slow_f, wide_f, div32_f, fast_frames,
|
||||
slow_frames, wide_frames, div32_frames, ratio, wide_ratio,
|
||||
div32_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, cs_div32_hi, cs_div32_lo,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO, WIDE_HI, WIDE_LO,
|
||||
DIV32_HI, DIV32_LO,
|
||||
cs_ok and "ok" or "BAD"))
|
||||
|
||||
if ok then
|
||||
@@ -97,18 +151,28 @@ 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 "
|
||||
.. "div32_frames=%d; "
|
||||
.. "want status %08X, fast %08X%08X, slow %08X%08X, "
|
||||
.. "wide %08X%08X, div32 %08X%08X, "
|
||||
.. "slow_frames >= 20 and >= 8*max(fast_frames,1), "
|
||||
.. "wide_frames >= 2 and "
|
||||
.. "slow_frames >= 4*max(wide_frames,1), "
|
||||
.. "div32_frames >= 2 and "
|
||||
.. "4*wide_frames >= 5*max(div32_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, div32_frames,
|
||||
STATUS_OK,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO,
|
||||
WIDE_HI, WIDE_LO, DIV32_HI, DIV32_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 "
|
||||
.. "div32_done=%s",
|
||||
tostring(start_f), tostring(fast_f), tostring(slow_f),
|
||||
tostring(wide_f), tostring(div32_f))
|
||||
print(string.format(
|
||||
"M7: i64div perf: incomplete at frame %d at marker 0x%08X",
|
||||
frames, BASE))
|
||||
|
||||
+168
-7
@@ -1,14 +1,22 @@
|
||||
/* M7.4 i64 divide/remainder fast-path performance driver.
|
||||
/* M7.4/M8.3/M9.3 i64 divide/remainder fast-path performance driver.
|
||||
*
|
||||
* Two equal-iteration workloads exercise the two paths of
|
||||
* Four 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 and the quotient needs 33+ bits (hi(N) >= D), so
|
||||
* the M8.3 64/32 path emits two even-destination DIVUs (q1/r1
|
||||
* then q0/r0) instead of the 64-step loop;
|
||||
* div32 phase: the dividend has a nonzero high word but the quotient fits
|
||||
* 32 bits (hi(N) < D), so the M9.3 path emits one
|
||||
* even-destination DIVU plus the low-word N - q*D remainder
|
||||
* reconstruction.
|
||||
*
|
||||
* 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 +33,12 @@
|
||||
* 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
|
||||
* 11 div32 phase done 0x6432D0E5
|
||||
* 12 div32 checksum low (printed evidence)
|
||||
* 13 div32 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
|
||||
@@ -33,7 +47,8 @@
|
||||
* the markers once per MAME frame, turns the frame numbers into the gate's
|
||||
* cycle proxy, and requires the exact phase checksums. With the 16384
|
||||
* iterations above the deterministic LCG workloads produce
|
||||
* fast = 0x000000011E6F9AB4, slow = 0x00000000007512AE
|
||||
* fast = 0x000000011E6F9AB4, slow = 0x00000000007512AE,
|
||||
* wide = 0xF56810CFEDA9D656, div32 = 0x00002C61C63842EE
|
||||
* (checked against an independent host implementation of this file; the
|
||||
* target compiler must produce the same integer results).
|
||||
*/
|
||||
@@ -48,12 +63,14 @@ 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_DIV32_DONE 0x6432D0E5u
|
||||
#define PERF_STATUS_OK 0x600D600Du
|
||||
#define PERF_STATUS_BAD 0xBAD0BAD0u
|
||||
|
||||
/* 16384 iterations put the fast phase at a few frames and the slow phase at a
|
||||
* few hundred frames on the emulated 50 MHz part, with a wide margin under
|
||||
* the 4000-frame loader budget. The count is volatile so the optimizer keeps
|
||||
* the gate-local loader budget (5000 frames by default). The count is volatile so the optimizer keeps
|
||||
* a real loop and does not unroll it into a folded constant. */
|
||||
static volatile u32 perf_iters = 16384u;
|
||||
|
||||
@@ -78,6 +95,33 @@ static volatile u64 sc_seven = 7ull;
|
||||
static volatile s64 sc_neg123 = -123ll;
|
||||
static volatile s64 sc_int32min = -2147483648ll;
|
||||
static volatile s64 sc_three = 3ll;
|
||||
static volatile s64 sc_three_neg = -3ll;
|
||||
|
||||
/* M8.3/M9.3 64/32-path cases: nonzero dividend high word, 32-bit divisor.
|
||||
* The first, second and unsigned INT64_MIN-magnitude cases exercise the
|
||||
* two-step form where the quotient needs 33+ bits (hi >= d), so q1 is nonzero
|
||||
* and both even-destination divides run. The third has hi < d and takes the
|
||||
* M9.3 single-DIVU path. INT64_MIN never fits 32 bits (magnitude high word
|
||||
* 0x80000000): divisors <= 2^31 keep it on the two-step helper, while a
|
||||
* divisor in (2^31, 2^32), e.g. 0xFFFFFFFF, has hi(|N|) < d and takes the
|
||||
* single-DIVU path; the self-check below covers both. */
|
||||
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;
|
||||
|
||||
/* M9.3 single-DIVU 64/32 cases: a nonzero dividend high word with hi < d so
|
||||
* the whole quotient fits 32 bits. 0x1_00000000 / 3 is the canonical
|
||||
* q = 0x55555555, r = 1 case; the negative form exercises the shared signed
|
||||
* fixup on the new path. */
|
||||
static volatile u64 sc_div32_n = 0x0000000100000000ull;
|
||||
static volatile u64 sc_div32_d = 3ull;
|
||||
static volatile u64 sc_div32_n2 = 0x00000001FFFFFFFFull;
|
||||
static volatile u64 sc_div32_d2 = 0x0000000000010000ull;
|
||||
static volatile s64 sc_div32_neg = -4294967296ll;
|
||||
|
||||
static u32 lcg(u32 x)
|
||||
{
|
||||
@@ -124,11 +168,67 @@ 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: it now takes the M9.3 single divide. */
|
||||
q = sc_wide3 / sc_wide_d2;
|
||||
r = sc_wide3 % sc_wide_d2;
|
||||
ok &= (q == 2ull) && (r == 1ull);
|
||||
|
||||
/* M9.3 single-DIVU 64/32 path: hi < d (0x1 < 3 and 0x1 < 0x10000). */
|
||||
q = sc_div32_n / sc_div32_d;
|
||||
r = sc_div32_n % sc_div32_d;
|
||||
ok &= (q == 0x55555555ull) && (r == 1ull);
|
||||
|
||||
q = sc_div32_n2 / sc_div32_d2;
|
||||
r = sc_div32_n2 % sc_div32_d2;
|
||||
ok &= (q == 0x1FFFFull) && (r == 0xFFFFull);
|
||||
|
||||
sq = sc_div32_neg / sc_three;
|
||||
sr = sc_div32_neg % sc_three;
|
||||
ok &= (sq == -1431655765ll) && (sr == -1ll);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* INT64_MIN magnitude with a divisor above 2^31: hi(|N|) = 0x80000000
|
||||
* < 0xFFFFFFFF, so it takes the M9.3 single-DIVU path (unsigned and
|
||||
* signed). q = r = 2^31 in magnitude; the signed remainder keeps the
|
||||
* dividend's sign. */
|
||||
q = sc_wide4 / sc_max32;
|
||||
r = sc_wide4 % sc_max32;
|
||||
ok &= (q == 0x80000000ull) && (r == 0x80000000ull);
|
||||
|
||||
sq = sc_int64min / (s64)sc_max32;
|
||||
sr = sc_int64min % (s64)sc_max32;
|
||||
ok &= (sq == -2147483648ll) && (sr == -2147483648ll);
|
||||
|
||||
/* M9.3 single-DIVU 64/32 path with a negative 32-bit-magnitude divisor:
|
||||
* 2^32 / -3 = -1431655765 r 1 (the quotient sign is the sign XOR, the
|
||||
* remainder follows the dividend). */
|
||||
sq = (s64)sc_div32_n / (s64)sc_three_neg;
|
||||
sr = (s64)sc_div32_n % (s64)sc_three_neg;
|
||||
ok &= (sq == -1431655765ll) && (sr == 1ll);
|
||||
|
||||
return ok ? PERF_STATUS_OK : PERF_STATUS_BAD;
|
||||
}
|
||||
|
||||
@@ -184,10 +284,71 @@ static void run_slow(void)
|
||||
MARK(6) = PERF_SLOW_DONE;
|
||||
}
|
||||
|
||||
/* Nonzero dividend high word, 32-bit divisor, hi(N) >= D: 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 mask 0x80000000|(lcg & 0x7FFEFFFF) keeps
|
||||
* hi(N) in [0x80000000, 0xFFFEFFFF] and the divisor at most 0x10000, so the
|
||||
* unsigned high word is at least 0x10000. For the signed forms the
|
||||
* magnitude's high word is 0xFFFFFFFF - hi(N), i.e. in [0x10000, 0x7FFFFFFF],
|
||||
* so the negated magnitude is also >= 2^32 and every signed division takes
|
||||
* the same two-step helper. */
|
||||
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)(0x80000000u
|
||||
| (lcg((u32)(a >> 32)) & 0x7FFEFFFFu)) << 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;
|
||||
}
|
||||
|
||||
/* Nonzero dividend high word, 32-bit divisor, hi(N) < D: all four forms take
|
||||
* the M9.3 single-even-destination-DIVU path. The dividend high word is at
|
||||
* most 0x10000 and the divisor is at least 0x10001, so the quotient always
|
||||
* fits 32 bits and the single divide produces it. */
|
||||
static void run_div32(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)(0x10001u + (lcg((u32)b) & 0x0000FFFFu));
|
||||
acc += a / b;
|
||||
acc ^= a % b;
|
||||
acc += (u64)((s64)a / (s64)b);
|
||||
acc ^= (u64)((s64)a % (s64)b);
|
||||
}
|
||||
|
||||
MARK(12) = (u32)acc;
|
||||
MARK(13) = (u32)(acc >> 32);
|
||||
MARK(11) = PERF_DIV32_DONE;
|
||||
}
|
||||
|
||||
void i64div_perf_run(void)
|
||||
{
|
||||
MARK(7) = selfcheck();
|
||||
MARK(0) = PERF_START;
|
||||
run_fast();
|
||||
run_slow();
|
||||
run_wide();
|
||||
run_div32();
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,24 @@
|
||||
/* M9.2 range-list fixture A: -O2 -g loop/inlining shape that makes LLVM emit
|
||||
* a non-contiguous DW_TAG_inlined_subroutine and therefore .debug_rnglists.
|
||||
* Compiled by scripts/tests/m9/dwarf-ranges.sh; not a runtime test. */
|
||||
static inline __attribute__((always_inline)) int m9_inc(int x) {
|
||||
if (x & 1)
|
||||
return x + 1;
|
||||
return x + 3;
|
||||
}
|
||||
|
||||
int m9_range_one(int a) {
|
||||
int sum = 0;
|
||||
int i;
|
||||
for (i = 0; i < a; i++)
|
||||
sum += m9_inc(i);
|
||||
return sum;
|
||||
}
|
||||
|
||||
static int m9_helper(int q) {
|
||||
return q * 5;
|
||||
}
|
||||
|
||||
int m9_range_two(int a) {
|
||||
return m9_helper(a) + m9_range_one(a);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/* M9.2 range-list fixture B: a second TU with the same loop/inlining shape so
|
||||
* the multi-TU merge has two .debug_rnglists contributions to rehome. */
|
||||
static inline __attribute__((always_inline)) int m9_dec(int x) {
|
||||
if (x & 2)
|
||||
return x - 1;
|
||||
return x - 3;
|
||||
}
|
||||
|
||||
int m9_range_three(int a) {
|
||||
int sum = 1;
|
||||
for (int i = 0; i < a; i++)
|
||||
sum += m9_dec(i);
|
||||
return sum;
|
||||
}
|
||||
|
||||
int m9_range_four(int a) {
|
||||
return m9_range_three(a) * 3;
|
||||
}
|
||||
Executable
+276
@@ -0,0 +1,276 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Write two TI-COFF objects that actually emit DWARF v5 `.debug_rnglists`.
|
||||
|
||||
The M8 fixtures (-O0 and a straight-line -O2 shape) never emitted a range list,
|
||||
so the merge's `.debug_rnglists` whitelist was untested. This helper emits the
|
||||
section directly: a well-formed CU per object with
|
||||
|
||||
* ``DW_AT_rnglists_base`` (``DW_FORM_sec_offset`` into .debug_rnglists),
|
||||
* ``DW_AT_addr_base`` (``DW_FORM_sec_offset`` into .debug_addr),
|
||||
* ``DW_AT_ranges`` (``DW_FORM_rnglistx`` index 0),
|
||||
* a range list with one ``DW_RLE_start_end`` (absolute, relocated .text
|
||||
addresses) and one ``DW_RLE_startx_length`` (index into .debug_addr),
|
||||
* a subprogram DIE with a relocated ``DW_FORM_addr`` low PC.
|
||||
|
||||
Every section-relative field carries an R-RELLONG relocation, so the objects
|
||||
also pass the form-aware input gate. ``scripts/tests/m9/dwarf-ranges.sh``
|
||||
links them, wraps the result in the M7 ELF container and validates the ranges
|
||||
with ``llvm-dwarfdump``. The same gate also has a real `-O2 -g` producer case
|
||||
(loop/inline shapes can make LLVM emit non-contiguous inlined ranges); this
|
||||
synthetic fixture keeps the `start_end`/`startx_length` and offset-rehoming
|
||||
forms deterministic.
|
||||
|
||||
Usage: dwarf-ranges-fixture.py OUTDIR [--tag AB]
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
MAGIC = 0x0090
|
||||
R_RELLONG = 0x11
|
||||
S_TEXT = 0x20
|
||||
S_DATA = 0x40
|
||||
S_BSS = 0x80
|
||||
C_EXT = 2
|
||||
C_STAT = 3
|
||||
|
||||
TEXT_ORIGIN = 0x018A0000
|
||||
TEXT_BYTES = 16
|
||||
|
||||
|
||||
def uleb(value):
|
||||
out = bytearray()
|
||||
while True:
|
||||
byte = value & 0x7F
|
||||
value >>= 7
|
||||
if value:
|
||||
out.append(byte | 0x80)
|
||||
else:
|
||||
out.append(byte)
|
||||
return bytes(out)
|
||||
|
||||
|
||||
class Section:
|
||||
def __init__(self, name, flags, data=b"", bits=None):
|
||||
self.name = name
|
||||
self.flags = flags
|
||||
self.data = bytearray(data)
|
||||
self.bits = len(self.data) * 8 if bits is None else bits
|
||||
self.relocs = [] # (byte offset, symbol name)
|
||||
|
||||
def reloc(self, offset, symbol):
|
||||
self.relocs.append((offset, symbol))
|
||||
return offset
|
||||
|
||||
|
||||
def debug_abbrev():
|
||||
return (
|
||||
b"\x01\x11\x01" # 1: DW_TAG_compile_unit, children
|
||||
b"\x03\x0e" # DW_AT_name, DW_FORM_strp
|
||||
b"\x73\x17" # DW_AT_addr_base, DW_FORM_sec_offset
|
||||
b"\x74\x17" # DW_AT_rnglists_base, sec_offset
|
||||
b"\x55\x23" # DW_AT_ranges, DW_FORM_rnglistx
|
||||
b"\x00\x00"
|
||||
b"\x02\x2e\x00" # 2: DW_TAG_subprogram, no children
|
||||
b"\x03\x0e" # DW_AT_name, DW_FORM_strp
|
||||
b"\x11\x01" # DW_AT_low_pc, DW_FORM_addr
|
||||
b"\x12\x06" # DW_AT_high_pc, DW_FORM_data4
|
||||
b"\x00\x00"
|
||||
b"\x00")
|
||||
|
||||
|
||||
def build(tag):
|
||||
"""One object whose single function sits at .text offset 0."""
|
||||
cu_name = ("rng-%s.c" % tag).encode("ascii")
|
||||
fn_name = ("rng_" + tag).encode("ascii")
|
||||
strings = cu_name + b"\0" + fn_name + b"\0"
|
||||
cu_off = 0
|
||||
fn_off = len(cu_name) + 1
|
||||
|
||||
sections = [
|
||||
Section(".text", S_TEXT, b"\0" * TEXT_BYTES),
|
||||
Section(".data", S_DATA),
|
||||
Section(".bss", S_BSS, bits=0),
|
||||
]
|
||||
abbrev = Section(".debug_abbrev", 0, debug_abbrev())
|
||||
sections.append(abbrev)
|
||||
|
||||
# .debug_info: v5 CU header + root DIE (code 1) + subprogram (2).
|
||||
info_section = Section(".debug_info", 0, b"\0\0\0\0")
|
||||
info = info_section.data
|
||||
info += struct.pack("<HBB", 5, 1, 4) # version, DW_UT_compile, addrsize
|
||||
info += b"\0\0\0\0" # abbrev offset (relocated)
|
||||
info_section.reloc(8, ".debug_abbrev")
|
||||
|
||||
info += b"\x01" # root DIE
|
||||
info += struct.pack("<I", cu_off) # DW_AT_name -> .debug_str
|
||||
info_section.reloc(len(info) - 4, ".debug_str")
|
||||
info += struct.pack("<I", 8) # DW_AT_addr_base -> .debug_addr
|
||||
info_section.reloc(len(info) - 4, ".debug_addr")
|
||||
info += struct.pack("<I", 12) # DW_AT_rnglists_base -> header end
|
||||
info_section.reloc(len(info) - 4, ".debug_rnglists")
|
||||
info += uleb(0) # DW_AT_ranges, rnglistx index 0
|
||||
info += b"\x02" # subprogram DIE
|
||||
info += struct.pack("<I", fn_off) # DW_AT_name
|
||||
info_section.reloc(len(info) - 4, ".debug_str")
|
||||
info += struct.pack("<I", 0) # DW_AT_low_pc, linked .text
|
||||
info_section.reloc(len(info) - 4, ".text")
|
||||
info += struct.pack("<I", 4) # DW_AT_high_pc (byte size)
|
||||
info += b"\x00" # end of the root's children
|
||||
struct.pack_into("<I", info, 0, len(info) - 4)
|
||||
sections.append(info_section)
|
||||
|
||||
sections.append(Section(".debug_str", 0, strings))
|
||||
|
||||
# .debug_addr: unit header + two 4-byte addresses (text+8, text+12).
|
||||
addr_section = Section(".debug_addr", 0, b"\0\0\0\0")
|
||||
addr = addr_section.data
|
||||
addr += struct.pack("<HBB", 5, 4, 0)
|
||||
for value in (8, 12):
|
||||
addr += struct.pack("<I", value)
|
||||
addr_section.reloc(len(addr) - 4, ".text")
|
||||
struct.pack_into("<I", addr, 0, len(addr) - 4)
|
||||
sections.append(addr_section)
|
||||
|
||||
# .debug_rnglists: header (12 bytes) + one offset entry (base = 12).
|
||||
rng_section = Section(".debug_rnglists", 0, b"\0\0\0\0")
|
||||
rng = rng_section.data
|
||||
rng += struct.pack("<HBB", 5, 4, 0)
|
||||
rng += struct.pack("<I", 1) # offset_entry_count
|
||||
rng += struct.pack("<I", 4) # offset[0]: list at base + 4
|
||||
assert len(rng) == 16, len(rng)
|
||||
rng += b"\x06" # DW_RLE_start_end
|
||||
rng += struct.pack("<I", 0) # start = text + 0
|
||||
rng_section.reloc(len(rng) - 4, ".text")
|
||||
rng += struct.pack("<I", 4) # end = text + 4
|
||||
rng_section.reloc(len(rng) - 4, ".text")
|
||||
rng += b"\x03" + uleb(0) + uleb(4) # DW_RLE_startx_length: addr[0] .. +4
|
||||
rng += b"\x00" # DW_RLE_end_of_list
|
||||
struct.pack_into("<I", rng, 0, len(rng) - 4)
|
||||
sections.append(rng_section)
|
||||
|
||||
# Section sizes were captured at construction; the unit builders above
|
||||
# append to the byte arrays afterwards.
|
||||
for sec in sections:
|
||||
if sec.name != ".bss":
|
||||
sec.bits = len(sec.data) * 8
|
||||
|
||||
return sections
|
||||
|
||||
|
||||
def short_name(name):
|
||||
return len(name.encode("latin1")) <= 8
|
||||
|
||||
|
||||
def write_object(path, sections, tag):
|
||||
"""Serialise one relocatable TI-COFF object.
|
||||
|
||||
Relocation targets are section symbols (matching the LLVM producer), plus
|
||||
an external ``_rng_<tag>`` in .text so the linked image names the function.
|
||||
"""
|
||||
section_symbols = {}
|
||||
symbols = [] # (name, value, secno, class, naux, aux)
|
||||
record = 0
|
||||
for index, sec in enumerate(sections, start=1):
|
||||
section_symbols[sec.name] = record
|
||||
aux = struct.pack("<III", sec.bits, 0, 0).ljust(18, b"\0")
|
||||
symbols.append((sec.name, 0, index, C_STAT, 1, aux))
|
||||
record += 2 # main record + one aux record
|
||||
symbols.append(("_rng_" + tag, 0, 1, C_EXT, 0, b""))
|
||||
record += 1
|
||||
|
||||
string_table = bytearray(b"\0\0\0\0")
|
||||
sec_name_offsets = {}
|
||||
for sec in sections:
|
||||
if not short_name(sec.name):
|
||||
sec_name_offsets[sec.name] = len(string_table)
|
||||
string_table.extend(sec.name.encode("latin1") + b"\0")
|
||||
sym_name_offsets = {}
|
||||
for name, _value, _secno, _class, _naux, _aux in symbols:
|
||||
if not short_name(name):
|
||||
sym_name_offsets[name] = len(string_table)
|
||||
string_table.extend(name.encode("latin1") + b"\0")
|
||||
struct.pack_into("<I", string_table, 0, len(string_table))
|
||||
|
||||
nsyms = sum(1 + naux for _n, _v, _s, _c, naux, _a in symbols)
|
||||
if nsyms != record:
|
||||
raise SystemExit("internal: symbol record count mismatch")
|
||||
header_size = 20 + 40 * len(sections)
|
||||
cursor = header_size
|
||||
payload = []
|
||||
for sec in sections:
|
||||
if sec.bits and sec.name != ".bss":
|
||||
payload.append(cursor)
|
||||
cursor += len(sec.data)
|
||||
else:
|
||||
payload.append(0)
|
||||
relptr = []
|
||||
for sec in sections:
|
||||
if sec.relocs:
|
||||
relptr.append(cursor)
|
||||
cursor += 10 * len(sec.relocs)
|
||||
else:
|
||||
relptr.append(0)
|
||||
symptr = cursor
|
||||
cursor += nsyms * 18 + len(string_table)
|
||||
|
||||
out = bytearray()
|
||||
out.extend(struct.pack("<HHIIIHH", MAGIC, len(sections), 0, symptr,
|
||||
nsyms, 0, 0))
|
||||
for sec, ptr, rptr in zip(sections, payload, relptr):
|
||||
if short_name(sec.name):
|
||||
raw_name = sec.name.encode("latin1").ljust(8, b"\0")
|
||||
else:
|
||||
raw_name = ("/%d" % sec_name_offsets[sec.name]).encode("ascii")
|
||||
out.extend(raw_name.ljust(8, b"\0"))
|
||||
out.extend(struct.pack("<IIIIIIHHI", 0, 0, sec.bits, ptr, rptr, 0,
|
||||
len(sec.relocs), 0, sec.flags))
|
||||
for sec, ptr in zip(sections, payload):
|
||||
if ptr:
|
||||
out.extend(sec.data)
|
||||
for sec, rptr in zip(sections, relptr):
|
||||
if not rptr:
|
||||
continue
|
||||
for offset, name in sec.relocs:
|
||||
out.extend(struct.pack("<IIH", offset * 8,
|
||||
section_symbols[name], R_RELLONG))
|
||||
for name, value, secno, sclass, naux, aux in symbols:
|
||||
if short_name(name):
|
||||
raw_name = name.encode("latin1").ljust(8, b"\0")
|
||||
else:
|
||||
raw_name = b"\0\0\0\0" + struct.pack("<I", sym_name_offsets[name])
|
||||
out.extend(raw_name)
|
||||
out.extend(struct.pack("<IhHBB", value, secno, 0, sclass, naux))
|
||||
out.extend(aux)
|
||||
out.extend(string_table)
|
||||
|
||||
if len(out) != cursor:
|
||||
raise SystemExit("internal: %s size %d != planned %d"
|
||||
% (path, len(out), cursor))
|
||||
with open(path, "wb") as fh:
|
||||
fh.write(out)
|
||||
return len(out)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("outdir", metavar="OUTDIR")
|
||||
parser.add_argument("--tag", default="ab",
|
||||
help="the two single-letter tags")
|
||||
args = parser.parse_args(argv)
|
||||
if len(args.tag) != 2:
|
||||
parser.error("--tag must be two characters (one per object)")
|
||||
os.makedirs(args.outdir, exist_ok=True)
|
||||
for tag in args.tag:
|
||||
path = os.path.join(args.outdir, "rng-%s.o" % tag)
|
||||
size = write_object(path, build(tag), tag)
|
||||
print("dwarf-ranges-fixture: %s (%d bytes, .text %d bits)"
|
||||
% (path, size, TEXT_BYTES * 8))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
#!/bin/sh
|
||||
# M10 Task 3 gate: bit-address pipeline idempotency and the codegen safety net.
|
||||
#
|
||||
# scripts/tests/m10/bitaddr-idempotent.sh
|
||||
#
|
||||
# Task 3 records the bit-address barrier/lowering lifecycle in the module flag
|
||||
# "tms.bitaddr" (1 = barriered, not lowered; 2 = lowered/final) and adds a
|
||||
# legacy codegen pass so a module that still holds an @__tms_bitptr call when it
|
||||
# reaches llc is lowered instead of emitted as a CALLA. This gate checks:
|
||||
#
|
||||
# 1. clang --target=tms34010 -O0 -S -emit-llvm on a pointer file leaves the
|
||||
# module flagged "tms.bitaddr" = 2 (lowered) with no @__tms_bitptr call;
|
||||
# 2. re-running the identical command produces byte-identical IR (idempotent);
|
||||
# 3. llc emits ADDI 32 for p[1] (a bit offset, not the byte offset 4);
|
||||
# 4. clang -c produces a TI-COFF object starting with the 0x0090 magic.
|
||||
#
|
||||
# Step 4 asserts the TI-COFF magic directly rather than running
|
||||
# scripts/m4/coff-check.py: that validator is linked-image specific (it requires
|
||||
# GSPLNK's optional header) and rejects a plain object ("invalid header
|
||||
# nscns=... opthdr=0").
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC M10_BITADDR_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
WORK=${M10_BITADDR_WORK:-$ROOT/build/m10-bitaddr-idempotent}
|
||||
|
||||
fail() {
|
||||
echo "m10 bitaddr idempotent: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$CLANG" ] || fail "missing clang: $CLANG (build the fork or set CLANG=...)"
|
||||
[ -x "$LLC" ] || fail "missing llc: $LLC (build the fork or set LLC=...)"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
cat > "$WORK/src.c" <<'EOF'
|
||||
int load_i(int *p) { return p[1]; }
|
||||
EOF
|
||||
|
||||
echo "== clang -O0 -S -emit-llvm (run1) -> flag 2, no barrier"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -o "$WORK/run1.ll" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -S -emit-llvm failed"
|
||||
grep -q '"tms.bitaddr", i32 2' "$WORK/run1.ll" \
|
||||
|| { grep -n 'tms.bitaddr\|__tms_bitptr' "$WORK/run1.ll" >&2 || true; \
|
||||
fail "run1.ll does not carry tms.bitaddr = 2"; }
|
||||
if grep -q '__tms_bitptr' "$WORK/run1.ll"; then
|
||||
fail "run1.ll still contains @__tms_bitptr (the barrier was not lowered)"
|
||||
fi
|
||||
|
||||
echo "== re-run the identical command -> byte-identical IR"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -o "$WORK/run2.ll" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -S -emit-llvm (run2) failed"
|
||||
cmp "$WORK/run1.ll" "$WORK/run2.ll" \
|
||||
|| fail "the second compile is not byte-identical (not idempotent)"
|
||||
|
||||
# Re-entry: feed the already-lowered IR back through clang as IR input. The
|
||||
# barrier must see "tms.bitaddr" = 2 and skip, and the lowering must see a value
|
||||
# other than 1 and skip, so the re-entered module keeps flag 2, has no
|
||||
# @__tms_bitptr call, and is unchanged except for the ModuleID (which is the
|
||||
# input file's path, not the original source's).
|
||||
echo "== re-enter the lowered IR through clang -x ir -> still flag 2, unchanged"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -x ir \
|
||||
-o "$WORK/reentered.ll" "$WORK/run1.ll" \
|
||||
|| fail "clang -O0 -S -emit-llvm -x ir failed on run1.ll"
|
||||
grep -q '"tms.bitaddr", i32 2' "$WORK/reentered.ll" \
|
||||
|| fail "reentered.ll does not carry tms.bitaddr = 2"
|
||||
if grep -q '__tms_bitptr' "$WORK/reentered.ll"; then
|
||||
fail "reentered.ll still contains @__tms_bitptr (the barrier was re-applied)"
|
||||
fi
|
||||
grep -v '^; ModuleID' "$WORK/run1.ll" > "$WORK/run1.noid"
|
||||
grep -v '^; ModuleID' "$WORK/reentered.ll" > "$WORK/reentered.noid"
|
||||
cmp "$WORK/run1.noid" "$WORK/reentered.noid" \
|
||||
|| fail "the re-entered IR differs beyond the ModuleID line"
|
||||
|
||||
echo "== llc emits ADDI 32 for p[1] from the flagged IR"
|
||||
"$LLC" -march=tms34010 -O0 -filetype=asm -o "$WORK/run1.s" "$WORK/run1.ll" \
|
||||
|| fail "llc -filetype=asm failed on run1.ll"
|
||||
grep -Eq '^[[:space:]]*ADDI[[:space:]]+32([^0-9]|$)' "$WORK/run1.s" \
|
||||
|| { cat "$WORK/run1.s" >&2; fail "run1.s lacks ADDI 32 for p[1]"; }
|
||||
if grep -Eq '^[[:space:]]*ADDI[[:space:]]+4([^0-9]|$)' "$WORK/run1.s"; then
|
||||
cat "$WORK/run1.s" >&2
|
||||
fail "run1.s emits ADDI 4 (a byte offset, not the bit offset 32)"
|
||||
fi
|
||||
|
||||
echo "== clang -c produces a TI-COFF object with the 0x0090 magic"
|
||||
"$CLANG" --target=tms34010 -O0 -c -o "$WORK/native.o" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -c failed"
|
||||
python3 - "$WORK/native.o" <<'PY' || fail "native.o magic is wrong"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if not data:
|
||||
sys.exit("native.o is empty")
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
print(" native.o: %d bytes, TI-COFF magic 90 00" % len(data))
|
||||
PY
|
||||
|
||||
echo "m10 bitaddr idempotent: PASS"
|
||||
Executable
+179
@@ -0,0 +1,179 @@
|
||||
#!/bin/sh
|
||||
# M10 Task 4 gate: native/legacy object equivalence at -O0, and -O2 shape pinning.
|
||||
#
|
||||
# scripts/tests/m10/equivalence.sh
|
||||
#
|
||||
# Phase 1 (byte identity): every corpus translation unit is compiled twice and
|
||||
# the objects must be byte-identical:
|
||||
#
|
||||
# native: clang --target=tms34010 -O0 [-g] -c "$f" -o native.o
|
||||
# legacy: scripts/tests/m10/legacy-tms-clang -O0 [-g] -o legacy.ll "$f"
|
||||
# then llc -march=tms34010 -O0 -filetype=obj legacy.ll -o legacy.o
|
||||
#
|
||||
# The frozen legacy-tms-clang (byte-identical to the m9 tms-clang) is the oracle;
|
||||
# native clang must reproduce it exactly. The corpus is every *.c in scripts/m4,
|
||||
# scripts/m5 and scripts/m6 plus the M5 conformance shim and heap. layout-ti.c is
|
||||
# excluded: it is the 1987 TI compiler's reference source (a union/struct tag
|
||||
# reuse modern clang rejects) whose output layout-ti.s is the golden for
|
||||
# scripts/tests/m4/layout.sh; it is not a clang-compilable input.
|
||||
#
|
||||
# Phase 2 (behaviour): a heredoc fixture is compiled at -O2 and its asm shapes are
|
||||
# FileChecked to pin the post-optimizer scaling pass on optimizer-created GEPs
|
||||
# (SROA aggregate strides, switch tables, aggregate-return .fca.N.gep loads).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC FILECHECK M10_EQUIV_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
FILECHECK=${FILECHECK:-$LLVM_BIN/FileCheck}
|
||||
LEGACY=$ROOT/scripts/tests/m10/legacy-tms-clang
|
||||
WORK=${M10_EQUIV_WORK:-$ROOT/build/m10-equivalence}
|
||||
INC=$ROOT/sdk/include
|
||||
|
||||
# The frozen legacy script derives its ROOT from its own path
|
||||
# (scripts/tests/m10), so its default tool paths are wrong. Point it at the real
|
||||
# build tools explicitly. TMS_OPT is only consulted for the -O2 branch the
|
||||
# gate never uses, but the script's tool check requires it to exist.
|
||||
export TMS_CLANG=$CLANG
|
||||
export TMS_OPT=$LLVM_BIN/opt
|
||||
export TMS_BITADDR=$ROOT/tools/tms-bitaddr/tms-bitaddr
|
||||
|
||||
fail() {
|
||||
echo "m10 equivalence: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$CLANG" ] || fail "missing clang: $CLANG (build the fork or set CLANG=...)"
|
||||
[ -x "$LLC" ] || fail "missing llc: $LLC (build the fork or set LLC=...)"
|
||||
[ -x "$FILECHECK" ] || fail "missing FileCheck: $FILECHECK"
|
||||
[ -x "$LEGACY" ] || fail "missing legacy oracle: $LEGACY"
|
||||
[ -x "$TMS_BITADDR" ] || fail "missing tms-bitaddr: $TMS_BITADDR"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Emit one corpus path per line. layout-ti.c is the TI-compiler golden source.
|
||||
corpus() {
|
||||
for f in "$ROOT"/scripts/m4/*.c "$ROOT"/scripts/m5/*.c "$ROOT"/scripts/m6/*.c; do
|
||||
case "$f" in
|
||||
*layout-ti.c) ;;
|
||||
*) printf '%s\n' "$f" ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$ROOT/sdk/shim.c"
|
||||
printf '%s\n' "$ROOT/sdk/heap.c"
|
||||
}
|
||||
|
||||
# compare_mode MODE -- compile every corpus file native vs legacy and cmp.
|
||||
# Prints a per-mode summary and sets TOTPASS/TOTFAIL (global).
|
||||
compare_mode() {
|
||||
mode=$1
|
||||
pass=0
|
||||
failn=0
|
||||
echo "== equivalence at $mode"
|
||||
for f in $(corpus); do
|
||||
base=$(basename "$f")
|
||||
native=$WORK/$base.native.o
|
||||
legacy=$WORK/$base.legacy.ll
|
||||
legacyobj=$WORK/$base.legacy.o
|
||||
# shellcheck disable=SC2086
|
||||
if ! "$CLANG" --target=tms34010 $mode -I "$INC" -c "$f" -o "$native" \
|
||||
2> "$WORK/$base.native.err"; then
|
||||
echo "FAIL (native compile) $base"
|
||||
sed 's/^/ /' "$WORK/$base.native.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if ! "$LEGACY" $mode -I "$INC" -o "$legacy" "$f" \
|
||||
2> "$WORK/$base.legacy.err"; then
|
||||
echo "FAIL (legacy compile) $base"
|
||||
sed 's/^/ /' "$WORK/$base.legacy.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
if ! "$LLC" -march=tms34010 -O0 -filetype=obj "$legacy" -o "$legacyobj" \
|
||||
2>> "$WORK/$base.legacy.err"; then
|
||||
echo "FAIL (llc) $base"
|
||||
sed 's/^/ /' "$WORK/$base.legacy.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
if cmp -s "$native" "$legacyobj"; then
|
||||
pass=$((pass + 1))
|
||||
echo "OK $base"
|
||||
else
|
||||
echo "DIFF $base"
|
||||
failn=$((failn + 1))
|
||||
fi
|
||||
done
|
||||
echo "m10 equivalence [$mode]: pass=$pass fail=$failn"
|
||||
TOTPASS=$((TOTPASS + pass))
|
||||
TOTFAIL=$((TOTFAIL + failn))
|
||||
}
|
||||
|
||||
TOTPASS=0
|
||||
TOTFAIL=0
|
||||
|
||||
compare_mode "-O0"
|
||||
compare_mode "-O0 -g"
|
||||
|
||||
echo "m10 equivalence: pass=$TOTPASS fail=$TOTFAIL"
|
||||
|
||||
if [ "$TOTFAIL" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Phase 2: pin the post-optimizer scaling pass on optimizer-created GEPs at -O2.
|
||||
echo "== -O2 shape pinning"
|
||||
cat > "$WORK/o2.c" <<'EOF'
|
||||
struct S { int a; int b; };
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int stride(struct S *p) { return p[3].b; }
|
||||
int sw_tab(int c) {
|
||||
switch (c) {
|
||||
case 10: return 7;
|
||||
case 11: return 3;
|
||||
case 12: return 9;
|
||||
case 13: return 1;
|
||||
case 14: return 5;
|
||||
case 15: return 2;
|
||||
case 16: return 8;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
__attribute__((noinline)) struct S mk(int a, int b) { struct S s; s.a = a; s.b = b; return s; }
|
||||
int use_mk(int a, int b) { return mk(a, b).b; }
|
||||
EOF
|
||||
"$CLANG" --target=tms34010 -O2 -S -o "$WORK/o2.s" "$WORK/o2.c" \
|
||||
|| fail "clang -O2 -S failed on the shape fixture"
|
||||
cat > "$WORK/o2.checks" <<'EOF'
|
||||
CHECK-LABEL: _load_i:
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
CHECK-NOT: ADDI 4, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _stride:
|
||||
; The p[3] and .b offsets are now llvm.tms34010.bitaddr (BITADDR) nodes, so
|
||||
; the field offset stays relative instead of folding to the absolute 224.
|
||||
CHECK: ADDI 192, A{{[0-9]+}}
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
CHECK-NOT: ADDI 28, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _sw_tab:
|
||||
CHECK: SLL 3, A{{[0-9]+}}
|
||||
CHECK: MOVB {{.*}}A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _mk:
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _use_mk:
|
||||
CHECK: CALLA _mk
|
||||
CHECK: ADDI -32, A{{[0-9]+}}
|
||||
EOF
|
||||
"$FILECHECK" "$WORK/o2.checks" < "$WORK/o2.s" \
|
||||
|| fail "-O2 shape pinning failed"
|
||||
|
||||
echo "m10 equivalence: PASS"
|
||||
Executable
+178
@@ -0,0 +1,178 @@
|
||||
#!/bin/sh
|
||||
# tms-clang -- C IR pipeline: clang IR, the --bitptr semantic barrier, optimize,
|
||||
# scale the late byte-indexed GEPs, lower the barrier, and restore the M0
|
||||
# pointer-difference folding.
|
||||
#
|
||||
# Usage: tms-clang [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c
|
||||
#
|
||||
# -O0: clang IR -> --bitptr -> --lower-bitptr -> OUT (bit-addressed).
|
||||
# -O2 (the default): clang IR -> --bitptr -> opt -> --scale -> --lower-bitptr
|
||||
# -> opt -passes=instcombine -> OUT.
|
||||
#
|
||||
# -g passes clang -g through to the IR; the barrier passes copy !dbg
|
||||
# locations, so llc -filetype=obj emits the DWARF `.debug_*` sections. The
|
||||
# asm path still has no GSPA-assemblable debug directives.
|
||||
#
|
||||
# The barrier is required by the M0/M2 pointer model: pointers are bit
|
||||
# addresses, so `(int)(p + n) - (int)p` must be 8n at run time (the optimizer's
|
||||
# DataLayout would otherwise fold it to n). `--bitptr` replaces every GEP (and
|
||||
# an inttoptr of a bit addend over a ptrtoint base) with an opaque
|
||||
# @__tms_bitptr(i32 bitoff, ptr base) call, so InstCombine cannot canonicalize
|
||||
# the already-scaled bit offset back into a byte-indexed GEP; the M6 post-opt
|
||||
# `--scale` then multiplied that index by 8 again (the `p += n` over-scale, and
|
||||
# the reason the shim's memmove used constant end-pointer steps).
|
||||
#
|
||||
# The optimizer still creates genuinely byte-indexed GEPs (SROA aggregate
|
||||
# splits, switch tables), so the post-opt `--scale` is needed for those. By
|
||||
# then every original GEP is a call, so the pass only sees optimizer-created
|
||||
# byte GEPs. `--normalize` is not used there: it would treat those byte
|
||||
# offsets as already-scaled bits, which an aggregate return's `.fca.N.gep`
|
||||
# load (+4 bytes, not +4 bits) turns into an 8x address bug.
|
||||
#
|
||||
# `--lower-bitptr` then replaces each call with inttoptr(add(ptrtoint base,
|
||||
# bitoff)) and the final instcombine restores the M0 pointer-difference folding
|
||||
# (`int_diff` 8/32, the pointer-difference divide) and canonicalizes the
|
||||
# lowered bit GEPs, which llc already treats as bit offsets.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# The fork build (TMS34010 target + clang bit-address changes). The older
|
||||
# `build/llvm-build` tree is a stock clang without the target and has no
|
||||
# matching opt, so it is not a usable default.
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/build/llvm-clean-build/bin/clang}
|
||||
TMS_OPT=${TMS_OPT:-$ROOT/build/llvm-clean-build/bin/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
# Extra language flags from the caller (M4_EXTRA_CFLAGS). The conformance
|
||||
# c-torture sweep uses this for -std=gnu89; shipped gates leave it empty.
|
||||
TMS_CLANG_EXTRA_FLAGS=${TMS_CLANG_EXTRA_FLAGS:-}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
if [ ! -x "$tool" ]; then
|
||||
echo "tms-clang: missing tool: $tool" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG/TMS_OPT/TMS_BITADDR" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
OPTIMIZE=1
|
||||
DEBUG_FLAGS=
|
||||
INCLUDES=
|
||||
OUT=
|
||||
IN=
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-O0) OPTIMIZE=0; shift ;;
|
||||
-O2) OPTIMIZE=1; shift ;;
|
||||
-g) DEBUG_FLAGS=-g; shift ;;
|
||||
-I) [ $# -ge 2 ] || usage; INCLUDES="$INCLUDES -I $2"; shift 2 ;;
|
||||
-I*) INCLUDES="$INCLUDES $1"; shift ;;
|
||||
-o) [ $# -ge 2 ] || usage; OUT=$2; shift 2 ;;
|
||||
-*) usage ;;
|
||||
*) [ -z "$IN" ] || usage; IN=$1; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$IN" ] || usage
|
||||
[ -n "$OUT" ] || usage
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/tms-clang.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
$DEBUG_FLAGS -S -emit-llvm -ffreestanding -fno-builtin -nostdinc $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS \
|
||||
-o "$TMP/step1.ll" "$IN"
|
||||
|
||||
# A `static` variadic definition is local, so DeadArgumentElimination removes
|
||||
# its `...` when nothing keeps the varargs alive and rewrites every call site
|
||||
# to drop the extra arguments. The M4 contiguous-stack walk in the body still
|
||||
# reads those slots, so -O2 silently miscompiles it. Reject that shape before
|
||||
# opt, but leave a definition that genuinely uses a va_list alone (M6):
|
||||
# llvm.va_start/va_arg keep `...` through DAE, and the target lowers the walk
|
||||
# from the named argument area rather than the last fixed parameter. -O0
|
||||
# (which M4's varargs gate uses) and external definitions such as sprintf are
|
||||
# unaffected.
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
STATIC_VARARG=$(awk '
|
||||
/^define / {
|
||||
in_def = 1
|
||||
sig = $0
|
||||
va_start = 0
|
||||
next
|
||||
}
|
||||
in_def && /llvm\.va_start|va_arg ptr/ { va_start = 1 }
|
||||
in_def && /^}/ {
|
||||
if (!va_start &&
|
||||
sig ~ /[^A-Za-z0-9_](internal|private)[^A-Za-z0-9_]/ &&
|
||||
sig ~ /\.\.\./) {
|
||||
print sig
|
||||
exit
|
||||
}
|
||||
in_def = 0
|
||||
}
|
||||
' "$TMP/step1.ll")
|
||||
if [ -n "$STATIC_VARARG" ]; then
|
||||
NAME=$(printf '%s\n' "$STATIC_VARARG" |
|
||||
sed -n 's/.*@\([A-Za-z0-9_.$-]*\)(.*/\1/p')
|
||||
echo "tms-clang: error: static variadic definition '${NAME:-?}' loses its" \
|
||||
"'...' arguments at -O2 (dead argument elimination); remove 'static'" \
|
||||
"or compile with -O0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Hide every source GEP (and source pointer-int arithmetic) behind the opaque
|
||||
# bit-pointer barrier before the optimizer, so the bit-addressed model survives
|
||||
# without being re-canonicalized into byte GEPs.
|
||||
run_bitaddr() { # run_bitaddr MODE IN OUT
|
||||
if ! "$TMS_BITADDR" "$1" "$2" "$3" 2> "$TMP/bitaddr.err"; then
|
||||
cat "$TMP/bitaddr.err" >&2
|
||||
echo "tms-clang: error: tms-bitaddr $1 failed on $2" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$TMP/bitaddr.err" "$TMP/bitaddr-$1.log"
|
||||
}
|
||||
|
||||
run_bitaddr --bitptr "$TMP/step1.ll" "$TMP/bitptr.ll"
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
# i64 exists since M6, but IndVarSimplify's exit-value replacement still
|
||||
# rewrites a loop's final value into a closed-form i33 multiply (e.g.
|
||||
# n*(n+1)/2 for sumto), which is an unsupported shape for this 32-bit
|
||||
# target. -replexitval is an option of IndVarSimplify; disabling only that
|
||||
# rewrite keeps the loop, which is what ordinary -O2 code needs. This is a
|
||||
# driver policy, not a target TTI policy: opt runs without a target machine
|
||||
# here. llc diagnoses the raw i33 shape reached by an opt run that omits
|
||||
# this flag (m5-policy.ll).
|
||||
"$TMS_OPT" -passes='default<O2>' -replexitval=never \
|
||||
-S "$TMP/bitptr.ll" -o "$TMP/opt.ll"
|
||||
# The optimizer may create new byte-indexed GEPs (SROA aggregate splits,
|
||||
# switch tables), so scale those. Every source GEP is still an opaque call,
|
||||
# so this pass cannot see (and re-scale) an already-bit offset.
|
||||
run_bitaddr --scale "$TMP/opt.ll" "$TMP/scaled.ll"
|
||||
# Lower the barrier and restore the M0 pointer-difference folding. The
|
||||
# lowered inttoptr(add) shapes canonicalize to GEPs whose index is already
|
||||
# a bit count; llc treats a GEP index as a bit offset, and no scale follows.
|
||||
# `no-verify-fixpoint` suppresses only InstCombine's idempotence check: the
|
||||
# M6 shim's emit_uint64 has a `zext i32 %base to i64` that a second run
|
||||
# would re-mark `nneg`, which the verifier reports as "did not reach a
|
||||
# fixpoint". The first run's output is the intended IR and all gates pass
|
||||
# with it; the flag is the documented escape for this known shape.
|
||||
run_bitaddr --lower-bitptr "$TMP/scaled.ll" "$TMP/lowered.ll"
|
||||
"$TMS_OPT" -passes='instcombine<no-verify-fixpoint>' \
|
||||
-S "$TMP/lowered.ll" -o "$OUT"
|
||||
else
|
||||
# No optimizer, so no byte GEPs can be created; lower the barrier directly
|
||||
# back to the historical bit-addressed inttoptr(add) form.
|
||||
run_bitaddr --lower-bitptr "$TMP/bitptr.ll" "$OUT"
|
||||
fi
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
#!/bin/sh
|
||||
# M11 Task 2 gate: the CRT built with llc, linked and run end to end.
|
||||
#
|
||||
# scripts/tests/m11/crt.sh
|
||||
#
|
||||
# Builds sdk/crt0.ll with llc -march=tms34010 -filetype=obj (the TI-COFF
|
||||
# object path; llvm-mc's MC path emits ELF, which tms-link cannot read),
|
||||
# compiles a heredoc main.c and the existing conformance shim with
|
||||
# clang --target=tms34010 -O2 -c, links everything with tools/tms-link, and
|
||||
# runs the image with scripts/tms-run. The CRT contract is the result block
|
||||
# the conformance shim and tms-run already share: main returns 7, so the run
|
||||
# must report `status: 7` and stdout exactly `1 conformance`
|
||||
# (argv = { "conformance", NULL }). It also pins the CRT object size and
|
||||
# asserts the emitted `_start` has no frame prologue before its inline-asm
|
||||
# block (the `naked` attribute must survive).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC TMS_LINK M11_CRT_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
WORK=${M11_CRT_WORK:-$ROOT/build/m11-crt}
|
||||
|
||||
CRT0=$ROOT/sdk/crt0.ll
|
||||
SHIM=$ROOT/sdk/shim.c
|
||||
CONF_INCLUDE=$ROOT/sdk/include
|
||||
# The shim's %f path pulls FD$* float-library symbols; link the committed
|
||||
# 1990 flib/rts archives from sdk/lib (the same files a production install
|
||||
# places in <sysroot>/lib) to satisfy them.
|
||||
FLIB=$ROOT/sdk/lib/flib.lib
|
||||
RTS=$ROOT/sdk/lib/rts.lib
|
||||
|
||||
fail() {
|
||||
echo "m11 crt: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$CLANG" "$LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$TMS_LINK" ] || fail "missing linker: $TMS_LINK"
|
||||
[ -f "$CRT0" ] || fail "missing CRT source: $CRT0"
|
||||
[ -f "$SHIM" ] || fail "missing conformance shim: $SHIM"
|
||||
[ -f "$FLIB" ] || fail "missing flib.lib: $FLIB"
|
||||
[ -f "$RTS" ] || fail "missing rts.lib: $RTS"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
echo "== build $CRT0 with llc (TI-COFF object)"
|
||||
"$LLC" -march=tms34010 -filetype=obj "$CRT0" -o "$WORK/crt0.o" \
|
||||
|| fail "llc could not build $CRT0"
|
||||
python3 - "$WORK/crt0.o" <<'PY' || fail "crt0.o is not TI-COFF"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
print(" crt0.o: %d bytes, TI-COFF magic 90 00" % len(data))
|
||||
PY
|
||||
|
||||
# Pin the CRT's size: the naked _start's code must not grow a frame.
|
||||
SIZE=$(wc -c < "$WORK/crt0.o")
|
||||
[ "$SIZE" -eq 540 ] \
|
||||
|| fail "crt0.o size changed: $SIZE bytes (want the pinned 540)"
|
||||
|
||||
echo "== check _start has no prologue before its inline-asm block"
|
||||
"$LLC" -march=tms34010 -filetype=asm "$CRT0" -o "$WORK/crt0.s" \
|
||||
|| fail "llc could not emit assembly for $CRT0"
|
||||
# Everything from the _start label up to the first inline-asm block (;APP).
|
||||
awk '/^_start:/{f=1} f&&/;APP/{exit} f' "$WORK/crt0.s" > "$WORK/start-pre.s"
|
||||
# A non-naked function starts with the frame setup (push A13, save registers,
|
||||
# point A14 past the frame). Any of those before the asm block means the
|
||||
# `naked` attribute was lost.
|
||||
if grep -Eq 'MMTM[[:space:]]+SP|MOVE[[:space:]]+A13,[[:space:]]*-\*SP|ADDI[[:space:]]+-?[0-9]+,[[:space:]]*A14' "$WORK/start-pre.s"; then
|
||||
fail "naked _start gained a frame prologue: $(tr '\n' ' ' < "$WORK/start-pre.s")"
|
||||
fi
|
||||
|
||||
cat > "$WORK/main.c" <<'EOF'
|
||||
int main(int argc, char **argv) { printf("%d %s\n", argc, argv[0]); return 7; }
|
||||
EOF
|
||||
|
||||
echo "== compile main.c and shim.c"
|
||||
# The heredoc main.c calls printf without a declaration; force-include the
|
||||
# conformance stdio.h so it compiles as written.
|
||||
"$CLANG" --target=tms34010 -O2 -c -include stdio.h -I "$CONF_INCLUDE" \
|
||||
"$WORK/main.c" -o "$WORK/main.o" \
|
||||
|| fail "clang -c main.c failed"
|
||||
"$CLANG" --target=tms34010 -O2 -c "$SHIM" -o "$WORK/shim.o" \
|
||||
|| fail "clang -c shim.c failed"
|
||||
|
||||
echo "== link with tms-link"
|
||||
"$TMS_LINK" -o "$WORK/crt.coff" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 --prog-len 40000h --ram-len 80000h \
|
||||
"$WORK/crt0.o" "$WORK/main.o" "$WORK/shim.o" "$FLIB" "$RTS" \
|
||||
|| fail "tms-link failed"
|
||||
|
||||
echo "== run with tms-run"
|
||||
# tms-run exits nonzero for a nonzero status (it is built for status 0), so
|
||||
# capture its stdout and check the contract ourselves.
|
||||
"$ROOT/scripts/tms-run" "$WORK/crt.coff" > "$WORK/run.out" 2> "$WORK/run.err" \
|
||||
|| true
|
||||
if [ -s "$WORK/run.err" ]; then
|
||||
cat "$WORK/run.err" >&2
|
||||
fail "tms-run failed (see stderr above)"
|
||||
fi
|
||||
|
||||
python3 - "$WORK/run.out" <<'PY' || fail "contract check failed"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
fields = {}
|
||||
for line in data.split(b"\n"):
|
||||
for key in (b"status: ", b"magic: "):
|
||||
if line.startswith(key):
|
||||
fields[key] = line[len(key):].split(b" ", 1)[0]
|
||||
|
||||
status = fields.get(b"status: ")
|
||||
magic = fields.get(b"magic: ")
|
||||
if status != b"7":
|
||||
sys.exit("expected `status: 7`, got %r (full output: %r)"
|
||||
% (status, data))
|
||||
if magic != b"434F4E46":
|
||||
sys.exit("expected `magic: 434F4E46`, got %r (full output: %r)"
|
||||
% (magic, data))
|
||||
|
||||
marker = b"stdout:\n"
|
||||
if marker not in data:
|
||||
sys.exit("tms-run printed no stdout (full output: %r)" % (data,))
|
||||
out = data.split(marker, 1)[1]
|
||||
# tms-run appends a newline when the captured stream did not end with one;
|
||||
# the contract is the 12 bytes `1 conformance` with no trailing newline.
|
||||
if out.endswith(b"\n"):
|
||||
out = out[:-1]
|
||||
if out != b"1 conformance":
|
||||
sys.exit("stdout is not exactly `1 conformance` (got %r, full output: %r)"
|
||||
% (out, data))
|
||||
|
||||
sys.stdout.write(" status 7, magic 434F4E46, stdout `1 conformance`\n")
|
||||
PY
|
||||
|
||||
echo "m11 crt: PASS"
|
||||
Executable
+265
@@ -0,0 +1,265 @@
|
||||
#!/bin/sh
|
||||
# M11 Task 5 gate: the single-command build, end to end.
|
||||
#
|
||||
# scripts/tests/m11/e2e.sh
|
||||
#
|
||||
# The milestone's headline acceptance: after one `scripts/tms-sdk` (no
|
||||
# arguments), a plain `clang --target=tms34010 hello.c -o hello` from a
|
||||
# directory outside the repo links a loader-valid image that `tms-run`
|
||||
# executes, with no project variables and no sysroot flag. The isolated
|
||||
# sub-cases (two TUs, -I with a custom header and -L/-l with a user archive,
|
||||
# -c, -S, -E, -O0/-O2, -g vs stripped, -nostdlib with a
|
||||
# user _start, and the -### no-checkout-path assertion) run against a temp
|
||||
# sysroot installed with `scripts/tms-sdk --sysroot`, so the default
|
||||
# discovery path is exercised exactly once and nothing depends on a repo
|
||||
# source tree.
|
||||
#
|
||||
# The compiler, the installer and the runner are invoked through absolute
|
||||
# repo paths; the only environment the compile/link sees is a scrubbed one
|
||||
# (no M4_*/TMS_*/CPATH/LIBRARY_PATH/COMPILER_PATH), so PATH (which tms-link
|
||||
# needs to find python3) is the sole inherited convenience.
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC LLVM_AR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
LLVM_AR=${LLVM_AR:-$LLVM_BIN/llvm-ar}
|
||||
TMS_SDK=$ROOT/scripts/tms-sdk
|
||||
TMS_RUN=$ROOT/scripts/tms-run
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/m11-e2e.XXXXXX")
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
SYSROOT=$WORK/sysroot
|
||||
|
||||
fail() {
|
||||
echo "m11 e2e: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Scrub the environment the compile/link sees: the toolchain must need no
|
||||
# M4_*/TMS_* variable, no host include/library path and no tool-search
|
||||
# override. PATH survives (tms-link's shebang and the driver's python3
|
||||
# pre-flight both search it).
|
||||
clean() {
|
||||
env -u M4_WORK -u M4_SDK -u M4_COFF -u M4_SOURCES -u M4_ENTRY \
|
||||
-u M4_NATIVE -u M4_LINKER -u M4_SKIP_MAME -u M4_CLANG_OPT \
|
||||
-u M4_LLC_OPT -u M4_EXTRA_INCLUDES -u M4_EXTRA_CFLAGS \
|
||||
-u M4_NATIVE_PROG_LEN -u M4_NATIVE_RAM_LEN -u M4_NATIVE_LIBS \
|
||||
-u M4_OS2 -u M4_OS2_LX \
|
||||
-u TMS_CLANG -u TMS_LLC -u TMS_OPT -u TMS_BITADDR \
|
||||
-u TMS_CLANG_EXTRA_FLAGS -u TMS_LINKER \
|
||||
-u CLANG -u LLC -u LLVM_AR -u LLVM_BIN \
|
||||
-u CPATH -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
|
||||
-u OBJC_INCLUDE_PATH -u LIBRARY_PATH \
|
||||
-u COMPILER_PATH -u GCC_EXEC_PREFIX \
|
||||
"$@"
|
||||
}
|
||||
|
||||
# run_check IMAGE WANT DESC -- run the image with tms-run and assert the
|
||||
# result contract: status 0, magic 434F4E46, and stdout exactly WANT.
|
||||
run_check() {
|
||||
img=$1
|
||||
want=$2
|
||||
desc=$3
|
||||
"$TMS_RUN" "$img" > "$WORK/run.out" 2> "$WORK/run.err" \
|
||||
|| { cat "$WORK/run.err" >&2; fail "$desc: tms-run failed"; }
|
||||
python3 - "$WORK/run.out" "$want" <<'PY' || fail "$desc: output mismatch"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
want = sys.argv[2].encode()
|
||||
status = magic = None
|
||||
for line in data.split(b"\n"):
|
||||
if line.startswith(b"status: "):
|
||||
status = line[len(b"status: "):].split(b" ", 1)[0]
|
||||
elif line.startswith(b"magic: "):
|
||||
magic = line[len(b"magic: "):].split(b" ", 1)[0]
|
||||
if status != b"0":
|
||||
sys.exit("status %r != 0 (full: %r)" % (status, data))
|
||||
if magic != b"434F4E46":
|
||||
sys.exit("magic %r != 434F4E46 (full: %r)" % (magic, data))
|
||||
marker = b"stdout:\n"
|
||||
if want == b"":
|
||||
if marker in data:
|
||||
sys.exit("unexpected stdout in %r" % (data,))
|
||||
else:
|
||||
if marker not in data:
|
||||
sys.exit("no stdout marker in %r" % (data,))
|
||||
out = data.split(marker, 1)[1]
|
||||
if out.endswith(b"\n"):
|
||||
out = out[:-1]
|
||||
if out != want:
|
||||
sys.exit("stdout %r != want %r (full: %r)" % (out, want, data))
|
||||
PY
|
||||
}
|
||||
|
||||
[ -x "$TMS_SDK" ] || fail "missing installer: $TMS_SDK"
|
||||
[ -x "$TMS_RUN" ] || fail "missing runner: $TMS_RUN"
|
||||
for tool in "$CLANG" "$LLC" "$LLVM_AR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
cd "$WORK"
|
||||
|
||||
# --- Part A: the headline command through the default discovery path ------
|
||||
# Install the real resource-dir sysroot (no --sysroot argument), then run the
|
||||
# plain command with no sysroot flag and no project environment.
|
||||
echo "== install the default resource-dir sysroot (tms-sdk, no arguments)"
|
||||
clean "$TMS_SDK" || fail "default tms-sdk install failed"
|
||||
|
||||
cat > hello.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int main(void) { printf("hello\n"); return 0; }
|
||||
EOF
|
||||
|
||||
echo "== clang --target=tms34010 hello.c -o hello (no flags, no env)"
|
||||
clean "$CLANG" --target=tms34010 hello.c -o hello \
|
||||
|| fail "headline command failed"
|
||||
[ -f hello ] || fail "headline command produced no image"
|
||||
[ -f hello.map ] || fail "headline command produced no hello.map"
|
||||
|
||||
run_check hello "hello" "headline" || fail "headline run failed"
|
||||
# The default link is stripped: the map has no .debug_* sections.
|
||||
grep -q '\.debug_' hello.map \
|
||||
&& fail "default link keeps .debug_* sections (should be stripped)" || true
|
||||
|
||||
# --- Part B: isolated sub-cases against a temp sysroot --------------------
|
||||
echo "== install a temp sysroot for the isolated sub-cases"
|
||||
clean "$TMS_SDK" --sysroot "$SYSROOT" || fail "temp sysroot install failed"
|
||||
|
||||
# 1. two TUs link and run.
|
||||
cat > add.c <<'EOF'
|
||||
int add(int a, int b) { return a + b; }
|
||||
EOF
|
||||
cat > main.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int add(int, int);
|
||||
int main(void) { printf("add=%d\n", add(20, 22)); return 0; }
|
||||
EOF
|
||||
echo "== two-TU link (add.c + main.c)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" add.c main.c -o add42 \
|
||||
|| fail "two-TU link failed"
|
||||
run_check add42 "add=42" "two-TU" || fail "two-TU run failed"
|
||||
|
||||
# 1b. -I, -L and -l end to end: a header from a custom include directory and a
|
||||
# small user archive whose member main calls.
|
||||
mkdir -p inc libsrc libdir
|
||||
cat > inc/answer.h <<'EOF'
|
||||
#define ANSWER 42
|
||||
int user_answer(void);
|
||||
EOF
|
||||
cat > libsrc/user.c <<'EOF'
|
||||
#include "answer.h"
|
||||
int user_answer(void) { return ANSWER; }
|
||||
EOF
|
||||
cat > uselib.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
#include "answer.h"
|
||||
int main(void) { printf("user=%d\n", user_answer()); return 0; }
|
||||
EOF
|
||||
echo "== -I header and -L/-l user archive"
|
||||
clean "$CLANG" --target=tms34010 -c -I inc libsrc/user.c -o user.o \
|
||||
|| fail "-I compile of the user library failed"
|
||||
clean "$LLVM_AR" rcsD libdir/libuser.a user.o \
|
||||
|| fail "building the user archive failed"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" \
|
||||
-I inc uselib.c -L libdir -l user -o uselib \
|
||||
|| fail "-I/-L/-l link failed"
|
||||
run_check uselib "user=42" "-I/-L/-l" || fail "-I/-L/-l run failed"
|
||||
|
||||
# 2. -c produces a TI-COFF object.
|
||||
echo "== -c (object)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -c hello.c -o hello.o \
|
||||
|| fail "-c failed"
|
||||
python3 - hello.o <<'PY' || fail "hello.o is not TI-COFF"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
PY
|
||||
|
||||
# 3. -S produces GSPA assembly naming main and the printf call.
|
||||
echo "== -S (assembly)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -S hello.c -o hello.s \
|
||||
|| fail "-S failed"
|
||||
grep -q '_main' hello.s || fail "hello.s has no _main symbol"
|
||||
grep -q '_printf' hello.s || fail "hello.s has no _printf call"
|
||||
|
||||
# 4. -E produces preprocessed source (headers resolved, source present).
|
||||
echo "== -E (preprocessed)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -E hello.c -o hello.i \
|
||||
|| fail "-E failed"
|
||||
grep -q 'int printf(const char \*fmt, ...);' hello.i \
|
||||
|| fail "hello.i did not expand the stdio.h printf declaration"
|
||||
grep -q 'printf("hello\\n")' hello.i \
|
||||
|| fail "hello.i lost the hello.c source line"
|
||||
|
||||
# 5. -O0 and -O2 both run correctly.
|
||||
for opt in -O0 -O2; do
|
||||
tag=$(echo "$opt" | tr -d -)
|
||||
echo "== $opt"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" \
|
||||
"$opt" hello.c -o "hello_$tag" || fail "$opt link failed"
|
||||
run_check "hello_$tag" "hello" "$opt" || fail "$opt run failed"
|
||||
done
|
||||
|
||||
# 6. -g keeps the .debug_* sections in the linked image; the default link
|
||||
# (hello_O0/hello_O2 above, and hello in Part A) is stripped.
|
||||
echo "== -g keeps .debug_* (vs stripped default)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -g hello.c -o hello_g \
|
||||
|| fail "-g link failed"
|
||||
grep -q '\.debug_' hello_g.map || fail "-g link has no .debug_* sections"
|
||||
grep -q '\.debug_' hello_O0.map \
|
||||
&& fail "default link keeps .debug_* sections (should be stripped)" || true
|
||||
|
||||
# 7. -nostdlib drops the CRT and the user supplies _start.
|
||||
cat > nostdlib.c <<'EOF'
|
||||
/* On this target C globals gain a leading underscore, so a C function named
|
||||
* `start` lands on the `_start` symbol the link job uses as its entry. */
|
||||
__attribute__((naked)) void start(void) {
|
||||
__asm__ volatile(
|
||||
"setf 16, 1, 0\n\t"
|
||||
"setf 32, 0, 1\n\t"
|
||||
"movi 0x01B00000, a1\n\t"
|
||||
"sub a0, a0\n\t"
|
||||
"move a0, *a1, 1\n\t"
|
||||
"movi 0x01B00040, a1\n\t"
|
||||
"movi 0x434F4E46, a0\n\t"
|
||||
"move a0, *a1, 1\n"
|
||||
"1: jruc 1b\n\t");
|
||||
}
|
||||
EOF
|
||||
echo "== -nostdlib with a user _start"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" \
|
||||
-nostdlib nostdlib.c -o nostdlib_img || fail "-nostdlib link failed"
|
||||
grep -q '"_start"' nostdlib_img.map \
|
||||
|| fail "-nostdlib image has no _start entry"
|
||||
run_check nostdlib_img "" "-nostdlib" || fail "-nostdlib run failed"
|
||||
|
||||
# 8. -### must show the sysroot-derived linker/include/CRT/libraries and
|
||||
# never a repo source path (the driver shells out only to the installed
|
||||
# sysroot; it never bakes in the checkout's sdk/tools/scripts trees).
|
||||
echo "== -### contains no checkout path"
|
||||
clean "$CLANG" -### --target=tms34010 --tms-sysroot="$SYSROOT" hello.c -o hello \
|
||||
> "$WORK/verbose.txt" 2>&1
|
||||
grep -Fq "$SYSROOT/bin/tms-link" "$WORK/verbose.txt" \
|
||||
|| fail "-### does not invoke the sysroot linker"
|
||||
grep -Fq "$SYSROOT/include" "$WORK/verbose.txt" \
|
||||
|| fail "-### does not use the sysroot include path"
|
||||
for src in "$SYSROOT/lib/crt0.o" "$SYSROOT/lib/libtms.a" \
|
||||
"$SYSROOT/lib/flib.lib" "$SYSROOT/lib/rts.lib"; do
|
||||
grep -Fq "$src" "$WORK/verbose.txt" \
|
||||
|| fail "-### does not reference $src"
|
||||
done
|
||||
for leak in "$ROOT/sdk" "$ROOT/tools/tms-link" "$ROOT/scripts" \
|
||||
"$ROOT/build/m6-sdk"; do
|
||||
grep -Fq "$leak" "$WORK/verbose.txt" \
|
||||
&& fail "-### leaks a repo source path: $leak" || true
|
||||
done
|
||||
|
||||
echo "m11 e2e: PASS"
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
#!/bin/sh
|
||||
# M11 Task 3 gate: the sysroot installer and its installed layout.
|
||||
#
|
||||
# scripts/tests/m11/sdk.sh
|
||||
#
|
||||
# Runs scripts/tms-sdk --sysroot "$TMP/sysroot" and asserts:
|
||||
# - the seven expected layout entries exist (include/, lib/{crt0.o,libtms.a,
|
||||
# flib.lib,rts.lib}, bin/{tms-link,tmscoff.py}) and every sdk/include/*.h
|
||||
# is installed;
|
||||
# - the installed tms-link is executable;
|
||||
# - `llvm-ar t libtms.a` lists exactly shim.o and heap.o;
|
||||
# - a second install is idempotent (crt0.o and libtms.a are byte-identical);
|
||||
# - the installed crt0.o matches a fresh llc build of sdk/crt0.ll;
|
||||
# - the installed libtms.a matches a fresh llvm-ar rcsD build of the same
|
||||
# shim.o/heap.o objects;
|
||||
# - the installed tms-link/tmscoff.py match tools/tms-link/*;
|
||||
# - a directory that is not an M11 sysroot (no marker) is refused before its
|
||||
# include/ is touched;
|
||||
# - reinstalling removes a header deleted from sdk/include;
|
||||
# - sdk/lib/{flib,rts}.lib match build/m6-sdk/{flib,rts}.lib when those exist
|
||||
# (otherwise the comparison prints SKIP (vendor tree absent)).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC LLVM_AR M11_SDK_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
LLVM_AR=${LLVM_AR:-$LLVM_BIN/llvm-ar}
|
||||
TMS_SDK=$ROOT/scripts/tms-sdk
|
||||
WORK=${M11_SDK_WORK:-$ROOT/build/m11-sdk}
|
||||
SYSROOT=$WORK/sysroot
|
||||
# A temporary header used to prove that a reinstall removes deleted headers.
|
||||
EXTRA_HEADER=$ROOT/sdk/include/zz-m11-sdk-gate.h
|
||||
|
||||
fail() {
|
||||
echo "m11 sdk: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
rm -f "$EXTRA_HEADER"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
[ -x "$TMS_SDK" ] || fail "missing installer: $TMS_SDK"
|
||||
for tool in "$CLANG" "$LLC" "$LLVM_AR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$ROOT/sdk/crt0.ll" ] || fail "missing CRT source: $ROOT/sdk/crt0.ll"
|
||||
[ -f "$ROOT/sdk/shim.c" ] || fail "missing shim source: $ROOT/sdk/shim.c"
|
||||
[ -f "$ROOT/sdk/heap.c" ] || fail "missing heap source: $ROOT/sdk/heap.c"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# A non-empty directory without the install marker is not ours to overwrite.
|
||||
echo "== refuse a non-M11 sysroot directory"
|
||||
FOREIGN=$WORK/foreign
|
||||
mkdir -p "$FOREIGN/include"
|
||||
echo keep > "$FOREIGN/include/keepme.h"
|
||||
if "$TMS_SDK" --sysroot "$FOREIGN" > "$WORK/foreign.log" 2>&1; then
|
||||
fail "tms-sdk overwrote a directory that is not an M11 sysroot"
|
||||
fi
|
||||
grep -q "not an M11 sysroot" "$WORK/foreign.log" \
|
||||
|| fail "refusal did not explain that the directory is not an M11 sysroot"
|
||||
[ -f "$FOREIGN/include/keepme.h" ] \
|
||||
|| fail "refused install deleted include/keepme.h"
|
||||
[ ! -e "$FOREIGN/.tms-sdk" ] \
|
||||
|| fail "refused install wrote an install marker"
|
||||
|
||||
echo "== install to $SYSROOT"
|
||||
"$TMS_SDK" --sysroot "$SYSROOT" || fail "first install failed"
|
||||
|
||||
# 1. the seven layout entries.
|
||||
for f in \
|
||||
"$SYSROOT/lib/crt0.o" \
|
||||
"$SYSROOT/lib/libtms.a" \
|
||||
"$SYSROOT/lib/flib.lib" \
|
||||
"$SYSROOT/lib/rts.lib" \
|
||||
"$SYSROOT/bin/tms-link" \
|
||||
"$SYSROOT/bin/tmscoff.py"; do
|
||||
[ -f "$f" ] || fail "missing installed file: $f"
|
||||
done
|
||||
[ -d "$SYSROOT/include" ] || fail "missing installed include directory"
|
||||
[ -x "$SYSROOT/bin/tms-link" ] || fail "installed tms-link is not executable"
|
||||
[ -f "$SYSROOT/.tms-sdk" ] || fail "missing install marker: $SYSROOT/.tms-sdk"
|
||||
for h in "$ROOT"/sdk/include/*.h; do
|
||||
[ -f "$SYSROOT/include/$(basename "$h")" ] \
|
||||
|| fail "missing installed header: $(basename "$h")"
|
||||
done
|
||||
|
||||
# The installed linker pair must be the project sources (a real
|
||||
# installed-vs-source check, not a copy of the destination onto itself).
|
||||
cmp "$SYSROOT/bin/tms-link" "$ROOT/tools/tms-link/tms-link" \
|
||||
|| fail "installed tms-link differs from tools/tms-link/tms-link"
|
||||
cmp "$SYSROOT/bin/tmscoff.py" "$ROOT/tools/tms-link/tmscoff.py" \
|
||||
|| fail "installed tmscoff.py differs from tools/tms-link/tmscoff.py"
|
||||
|
||||
# 2. libtms.a members are exactly shim.o and heap.o.
|
||||
"$LLVM_AR" t "$SYSROOT/lib/libtms.a" > "$WORK/ar-t.txt" \
|
||||
|| fail "llvm-ar t libtms.a failed"
|
||||
for m in shim.o heap.o; do
|
||||
grep -qx "$m" "$WORK/ar-t.txt" || fail "libtms.a has no $m member"
|
||||
done
|
||||
if [ "$(wc -l < "$WORK/ar-t.txt")" -ne 2 ]; then
|
||||
fail "libtms.a has unexpected members: $(tr '\n' ' ' < "$WORK/ar-t.txt")"
|
||||
fi
|
||||
|
||||
# Snapshot the build outputs before the idempotency re-install.
|
||||
cp "$SYSROOT/lib/crt0.o" "$WORK/crt0.first.o"
|
||||
cp "$SYSROOT/lib/libtms.a" "$WORK/libtms.first.a"
|
||||
|
||||
# 3. a second install is idempotent (byte-identical rebuilds), and a third
|
||||
# install after deleting a source header removes the stale installed one.
|
||||
echo "== re-install (idempotency)"
|
||||
printf '/* gate-only header */\n' > "$EXTRA_HEADER"
|
||||
"$TMS_SDK" --sysroot "$SYSROOT" || fail "second install failed"
|
||||
cmp "$SYSROOT/lib/crt0.o" "$WORK/crt0.first.o" \
|
||||
|| fail "crt0.o changed across reinstall"
|
||||
cmp "$SYSROOT/lib/libtms.a" "$WORK/libtms.first.a" \
|
||||
|| fail "libtms.a changed across reinstall"
|
||||
[ -f "$SYSROOT/include/$(basename "$EXTRA_HEADER")" ] \
|
||||
|| fail "install did not copy $(basename "$EXTRA_HEADER")"
|
||||
|
||||
echo "== re-install after deleting a header (stale header removal)"
|
||||
rm -f "$EXTRA_HEADER"
|
||||
"$TMS_SDK" --sysroot "$SYSROOT" || fail "third install failed"
|
||||
[ ! -e "$SYSROOT/include/$(basename "$EXTRA_HEADER")" ] \
|
||||
|| fail "stale header survived a reinstall: $(basename "$EXTRA_HEADER")"
|
||||
|
||||
# 4. the installed crt0.o matches a fresh llc build.
|
||||
echo "== fresh crt0.o (llc)"
|
||||
"$LLC" -march=tms34010 -filetype=obj "$ROOT/sdk/crt0.ll" -o "$WORK/crt0.fresh.o" \
|
||||
|| fail "fresh llc build of sdk/crt0.ll failed"
|
||||
cmp "$SYSROOT/lib/crt0.o" "$WORK/crt0.fresh.o" \
|
||||
|| fail "installed crt0.o differs from a fresh llc build"
|
||||
|
||||
# 5. the installed libtms.a matches a fresh llvm-ar rcsD build.
|
||||
echo "== fresh libtms.a (llvm-ar rcsD)"
|
||||
"$CLANG" --target=tms34010 -O2 -c -I "$ROOT/sdk/include" \
|
||||
"$ROOT/sdk/shim.c" -o "$WORK/shim.o" || fail "fresh shim.o build failed"
|
||||
"$CLANG" --target=tms34010 -O2 -c -I "$ROOT/sdk/include" \
|
||||
"$ROOT/sdk/heap.c" -o "$WORK/heap.o" || fail "fresh heap.o build failed"
|
||||
( cd "$WORK" && "$LLVM_AR" rcsD libtms.fresh.a shim.o heap.o ) \
|
||||
|| fail "fresh llvm-ar build failed"
|
||||
cmp "$SYSROOT/lib/libtms.a" "$WORK/libtms.fresh.a" \
|
||||
|| fail "installed libtms.a differs from a fresh llvm-ar build"
|
||||
|
||||
# 6. the committed vendor archives match the extracted originals.
|
||||
echo "== vendor archive comparison"
|
||||
if [ -f "$ROOT/build/m6-sdk/flib.lib" ]; then
|
||||
cmp "$ROOT/sdk/lib/flib.lib" "$ROOT/build/m6-sdk/flib.lib" \
|
||||
|| fail "sdk/lib/flib.lib differs from build/m6-sdk/flib.lib"
|
||||
else
|
||||
echo " SKIP (vendor tree absent): no build/m6-sdk/flib.lib to compare"
|
||||
fi
|
||||
if [ -f "$ROOT/build/m6-sdk/rts.lib" ]; then
|
||||
cmp "$ROOT/sdk/lib/rts.lib" "$ROOT/build/m6-sdk/rts.lib" \
|
||||
|| fail "sdk/lib/rts.lib differs from build/m6-sdk/rts.lib"
|
||||
else
|
||||
echo " SKIP (vendor tree absent): no build/m6-sdk/rts.lib to compare"
|
||||
fi
|
||||
|
||||
echo "m11 sdk: PASS"
|
||||
@@ -27,12 +27,14 @@
|
||||
# elsewhere in the body (an unrelated local at *FP(64), the constant 0x400,
|
||||
# an 0x4800 that merely shares a prefix) is not evidence.
|
||||
#
|
||||
# Our branch.c is built exactly like the M3 gate: tms-clang -O2 with the
|
||||
# -replexitval=never optimizer (that rewrite would turn sumto's loop into an
|
||||
# i33 multiply, which the target cannot select), then llc -O0. Dropping
|
||||
# -replexitval=never makes this check fail to compile the loop, not pass.
|
||||
# Our branch.c is built exactly like the M3 gate: tms-clang -O2 then llc -O0.
|
||||
# The TMS34010 ToolChain passes -mllvm -replexitval=never (IndVarSimplify's
|
||||
# exit-value replacement would otherwise turn sumto's loop into an i33
|
||||
# multiply, which the target cannot select), so the ordinary -O2 pipeline
|
||||
# keeps the loop with no local opt wrapper. Removing that default makes this
|
||||
# check fail to compile the loop, not pass.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TI_BRANCH TI_XHELLO
|
||||
# Overridable: TMS_CLANG TMS_LLC TI_BRANCH TI_XHELLO
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
@@ -41,19 +43,17 @@ SRC=$ROOT/scripts/m3
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
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_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TI_BRANCH=${TI_BRANCH:-$DIR/ti-branch.s}
|
||||
TI_XHELLO=${TI_XHELLO:-$DIR/ti-xhello.s}
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
export TMS_CLANG
|
||||
|
||||
fail() {
|
||||
echo "M3 diff: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$TI_BRANCH" ] || fail "stored TI golden missing: $TI_BRANCH"
|
||||
@@ -62,13 +62,8 @@ done
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m3-diff.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# branch.c is generated through a wrapper so only this file keeps its loop.
|
||||
OPT_NOREPLEXIT=$TMP/opt-noreplexit
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
echo "== compile our branch.s and xhello.s"
|
||||
TMS_OPT=$OPT_NOREPLEXIT "$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
-o "$TMP/branch.ll" "$SRC/branch.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$TMP/branch.ll" -o "$TMP/branch.s"
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
|
||||
@@ -9,6 +9,9 @@ ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_MUL_WORK:-$ROOT/build/m4-mul}
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
|
||||
fail() {
|
||||
echo "m4 mul: FAIL: $*" >&2
|
||||
exit 1
|
||||
@@ -24,10 +27,12 @@ M4_WORK="$WORK" \
|
||||
ASM=$WORK/m4.asm
|
||||
[ -f "$ASM" ] || fail "linked assembly not found: $ASM"
|
||||
|
||||
# The loop source must compile with the ordinary driver -O2 pipeline: no local
|
||||
# -replexitval flag and no i33/i64 multiply in the emitted IR.
|
||||
grep -q -- '-replexitval=never' "$ROOT/scripts/tms-clang" \
|
||||
|| fail "scripts/tms-clang does not disable IndVarSimplify exit-value replacement"
|
||||
# The loop source must compile with the ordinary driver -O2 pipeline: the
|
||||
# TMS34010 ToolChain passes -mllvm -replexitval=never (asserted at the driver
|
||||
# seam), and no i33/i64 multiply may appear in the emitted IR.
|
||||
"$TMS_CLANG" -### --target=tms34010 -O2 -c "$DIR/loop.c" 2>&1 \
|
||||
| grep -q -- '-replexitval=never' \
|
||||
|| fail "the TMS34010 driver does not disable IndVarSimplify exit-value replacement"
|
||||
if grep -Eq '\bmul i(33|64)\b' "$WORK/asm/loop.ll"; then
|
||||
sed 's/^/ /' "$WORK/asm/loop.ll" >&2
|
||||
fail "loop.ll still contains an i33/i64 multiply"
|
||||
|
||||
@@ -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,9 +338,11 @@ 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"
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
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 "$ROOT/sdk/shim.c" ] || fail "missing shim: $ROOT/sdk/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
|
||||
rm -rf "$WORK"
|
||||
@@ -356,9 +377,9 @@ cp "$SRC" "$COMPILE_SRC"
|
||||
# Link the optional heap object only when the test actually references the
|
||||
# allocator surface. Keeping it out of the common shim preserves the code
|
||||
# layout (and the shipped 300/600-frame gate timing) for non-heap tests.
|
||||
TEST_SOURCES="$COMPILE_SRC $HERE/shim.c"
|
||||
TEST_SOURCES="$COMPILE_SRC $ROOT/sdk/shim.c"
|
||||
if grep -Eq '(malloc|calloc|free)[[:space:]]*\(' "$COMPILE_SRC"; then
|
||||
TEST_SOURCES="$TEST_SOURCES $HERE/heap.c"
|
||||
TEST_SOURCES="$TEST_SOURCES $ROOT/sdk/heap.c"
|
||||
fi
|
||||
|
||||
link_once() {
|
||||
@@ -369,13 +390,14 @@ link_once() {
|
||||
M4_CLANG_OPT="$CLANG_OPT" \
|
||||
M4_LLC_OPT="$LLC_OPT" \
|
||||
M4_EXTRA_CFLAGS="${M5_CONFORMANCE_EXTRA_CFLAGS:-}" \
|
||||
M4_EXTRA_INCLUDES="-I $HERE/include -I $SRC_DIR" \
|
||||
M4_EXTRA_INCLUDES="-I $ROOT/sdk/include -I $SRC_DIR" \
|
||||
M4_WORK="$WORK/m4" \
|
||||
M4_COFF="$WORK/m4/m4.coff" \
|
||||
M4_SDK="$M4_SDK" \
|
||||
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 \
|
||||
|
||||
@@ -47,7 +47,7 @@ fail() {
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -x "$RUN" ] || fail "runner is not executable: $RUN"
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
[ -f "$ROOT/sdk/shim.c" ] || fail "missing shim: $ROOT/sdk/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
# 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. M9.1's inline-asm `r` support lets two x86-asm Generic
|
||||
# tests reach the target asm parser, so their reason is the new "inline asm
|
||||
# text is not TMS34010 assembly" (still unsupported, never counted as a pass).
|
||||
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-InlineAsm-X-Dest inline asm text is not TMS34010 assembly
|
||||
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
|
||||
@@ -44,10 +47,9 @@ fpowi-promote target rejection: M2 supports only void/integer(<=64)/pointer retu
|
||||
half target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
half-op missing libcall lowering (floats/vectors are deferred to M6)
|
||||
icmp-illegal target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
inline-asm-mem-clobber inline asm register constraint cannot be allocated
|
||||
inline-asm-mem-clobber inline asm text is not TMS34010 assembly
|
||||
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
|
||||
|
||||
@@ -98,6 +98,8 @@ failure_reason() {
|
||||
printf 'inline asm register constraint cannot be allocated\n'
|
||||
elif grep -Fq 'error: unexpected token' "$err"; then
|
||||
printf 'inline asm syntax is not supported by the TMS34010 parser\n'
|
||||
elif grep -Fq 'error: invalid instruction mnemonic' "$err"; then
|
||||
printf 'inline asm text is not TMS34010 assembly\n'
|
||||
elif grep -Fq 'fast-math-flags specified for call' "$err"; then
|
||||
printf 'IR verifier rejects the input (fast-math flags on an integer call)\n'
|
||||
fi
|
||||
|
||||
+15
-11
@@ -21,7 +21,7 @@
|
||||
#
|
||||
# scripts/tests/m5/jr.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TMS_LLVM_MC
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_LLC TMS_LLVM_MC
|
||||
# DIS34 M5_JR_WORK DOSBOX MAME MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
@@ -29,8 +29,6 @@ ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
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_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
@@ -44,7 +42,7 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
@@ -109,14 +107,12 @@ PY
|
||||
}
|
||||
|
||||
# The M3 gate keeps the loop in branch.c (IndVarSimplify would otherwise turn
|
||||
# sumto into an i33 multiply that this target cannot select).
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
# sumto into an i33 multiply that this target cannot select). The TMS34010
|
||||
# ToolChain passes -mllvm -replexitval=never, so tms-clang -O2 keeps the loop
|
||||
# without the local opt wrapper this gate used to install.
|
||||
|
||||
echo "== compile the M3 branch.c loop"
|
||||
TMS_OPT=$OPT_NOREPLEXIT TMS_CLANG="$TMS_CLANG" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
-o "$WORK/branch.ll" "$SRC/branch.c" || fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/branch.ll" \
|
||||
-o "$WORK/branch.s" || fail "llc -filetype=asm failed"
|
||||
@@ -229,7 +225,15 @@ echo "== linked .text size"
|
||||
# bytes, so re-measure after changing the ABI. M7.3 grew the v2.2 table from
|
||||
# 30 to 36 entries; scripts/m3/run.sh generates a 6-byte JAUC stub for every
|
||||
# entry, so the linked image gained 6*6 = 36 bytes (874 -> 910). The stub set
|
||||
# is part of this fixture, not target code.
|
||||
# is part of this fixture, not target code. M10's native clang -O2 pipeline
|
||||
# (the driver seam now supplies -replexitval=never) tightens the -O2 codegen
|
||||
# across all three M3 TUs (branch.c, layout.c and xhello.c). The earlier M10
|
||||
# pin of 850 was measured while the -O2 path still misread bit offsets as byte
|
||||
# offsets (DAGCombiner re-chained a memcpy source load and the f64 MSW store
|
||||
# past the stores producing them) and folded f32/f64 constants to IEEE bits;
|
||||
# closing those hazards in the debug cycle costs instructions, and the correct
|
||||
# size returns to 910 — the same value the M9 legacy path produced. The JR
|
||||
# count is unchanged.
|
||||
EXPECTED_TEXT_BYTES=910
|
||||
EXPECTED_JR=14
|
||||
TEXT_BITS=$(awk '$1 == ".text" && $2 == "0" { print $4; exit }' "$M3_WORK/m3.map")
|
||||
|
||||
@@ -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)
|
||||
|
||||
+24
-35
@@ -18,8 +18,7 @@
|
||||
#
|
||||
# scripts/tests/m5/policy.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_LLC TMS_BITADDR TMS_DRIVER
|
||||
# M5_POLICY_WORK
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_LLC TMS_DRIVER M5_POLICY_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
@@ -28,7 +27,6 @@ LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
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_DRIVER=${TMS_DRIVER:-$ROOT/scripts/tms-clang}
|
||||
WORK=${M5_POLICY_WORK:-$ROOT/build/m5-policy}
|
||||
|
||||
@@ -37,38 +35,30 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_DRIVER"; do
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_DRIVER"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
export TMS_CLANG TMS_OPT TMS_LLC TMS_BITADDR
|
||||
export TMS_CLANG TMS_OPT TMS_LLC
|
||||
|
||||
# 1. The switch-to-lookup workaround is gone and the ordinary -O2 path still
|
||||
# produces a table that is indexed in bits. Trace the real opt invocation
|
||||
# rather than grepping the driver source.
|
||||
OPT_REAL=$TMS_OPT
|
||||
TRACE=$WORK/opt-switch.args
|
||||
cat > "$WORK/opt-trace" <<EOF
|
||||
#!/bin/sh
|
||||
printf '%s\n' "\$*" >> "$TRACE"
|
||||
exec "$OPT_REAL" "\$@"
|
||||
EOF
|
||||
chmod +x "$WORK/opt-trace"
|
||||
export TRACE
|
||||
: > "$TRACE"
|
||||
|
||||
TMS_OPT=$WORK/opt-trace "$TMS_DRIVER" -O2 -o "$WORK/switch.ll" \
|
||||
"$ROOT/scripts/m4/switch.c" \
|
||||
|| fail "default -O2 could not compile the M4 switch"
|
||||
grep -q -- '-replexitval=never' "$TRACE" \
|
||||
|| { sed 's/^/ /' "$TRACE" >&2; \
|
||||
fail "the opt invocation does not pass -replexitval=never"; }
|
||||
if grep -q -- '-switch-to-lookup' "$TRACE"; then
|
||||
sed 's/^/ /' "$TRACE" >&2
|
||||
fail "the opt invocation still passes -switch-to-lookup"
|
||||
# produces a table that is indexed in bits. tms-clang is now a flag mapper
|
||||
# over clang, so assert the driver policy at the driver seam (-###) instead
|
||||
# of tracing an opt invocation that no longer happens.
|
||||
"$TMS_CLANG" -### --target=tms34010 -O2 -c "$ROOT/scripts/m4/switch.c" \
|
||||
> "$WORK/driver.args" 2>&1 \
|
||||
|| fail "the driver seam could not be queried"
|
||||
grep -q -- '-replexitval=never' "$WORK/driver.args" \
|
||||
|| { sed 's/^/ /' "$WORK/driver.args" >&2; \
|
||||
fail "the driver does not pass -replexitval=never"; }
|
||||
if grep -q -- '-switch-to-lookup' "$WORK/driver.args"; then
|
||||
sed 's/^/ /' "$WORK/driver.args" >&2
|
||||
fail "the driver still passes -switch-to-lookup"
|
||||
fi
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/switch.ll" "$ROOT/scripts/m4/switch.c" \
|
||||
|| fail "default -O2 could not compile the M4 switch"
|
||||
grep -q 'switch.table' "$WORK/switch.ll" \
|
||||
|| fail "the M4 switch produced no lookup table (the test is not exercising the fix)"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/switch.ll" \
|
||||
@@ -86,8 +76,8 @@ if ! grep -Eq '^[[:space:]]*MOVB[[:space:]]+\*A[0-9]+' "$WORK/sw_tile.s"; then
|
||||
fi
|
||||
echo " ok default -O2 switch table is indexed in bits"
|
||||
|
||||
# 2. The driver keeps its documented -replexitval policy (traced above) and the
|
||||
# loop is not rewritten into an unsupported closed form.
|
||||
# 2. The driver keeps its documented -replexitval policy (asserted at the -###
|
||||
# seam above) and the loop is not rewritten into an unsupported closed form.
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/loop.ll" "$ROOT/scripts/m4/loop.c" \
|
||||
|| fail "default -O2 could not compile the M4 loop"
|
||||
if grep -Eq '\bmul i(33|64)\b' "$WORK/loop.ll"; then
|
||||
@@ -100,14 +90,13 @@ echo " ok driver -O2 keeps the loop and passes -replexitval=never"
|
||||
|
||||
# 3. The raw opt+llc path (no -replexitval) reaches the closed-form i33
|
||||
# multiply. It must fail with the target's clear diagnostic, not a
|
||||
# SelectionDAG "Cannot select" or an assertion.
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
-S -emit-llvm -ffreestanding -fno-builtin -nostdinc \
|
||||
# SelectionDAG "Cannot select" or an assertion. The native clang -O0 emit
|
||||
# is fed straight to opt without -replexitval; the barrier/lowering has
|
||||
# already run inside clang, so no tms-bitaddr step is needed.
|
||||
"$TMS_CLANG" --target=tms34010 -O0 -S -emit-llvm \
|
||||
-o "$WORK/loop.step1.ll" "$ROOT/scripts/m4/loop.c" \
|
||||
|| fail "clang could not emit the raw loop IR"
|
||||
"$TMS_BITADDR" --scale "$WORK/loop.step1.ll" "$WORK/loop.scaled.ll" 2>/dev/null \
|
||||
|| fail "tms-bitaddr --scale failed"
|
||||
"$TMS_OPT" -passes='default<O2>' -S "$WORK/loop.scaled.ll" \
|
||||
"$TMS_OPT" -passes='default<O2>' -S "$WORK/loop.step1.ll" \
|
||||
-o "$WORK/loop.opt.ll" || fail "opt failed on the raw loop"
|
||||
grep -Eq '\bmul i(33|64)\b' "$WORK/loop.opt.ll" \
|
||||
|| fail "the raw opt pipeline did not produce the i33 multiply"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+53
-10
@@ -5,7 +5,7 @@
|
||||
# scripts/tests/m6/runtime.sh
|
||||
#
|
||||
# Compiles the C driver scripts/m6/runtime-main.c and the shared conformance
|
||||
# shim scripts/tests/m5/conformance/shim.c (a separate translation unit),
|
||||
# shim sdk/shim.c (a separate translation unit),
|
||||
# assembles/links them with GSPA/GSPLNK 2.00 and the 1990 flib.lib/rts.lib
|
||||
# under DOSBox, loads the COFF with the existing dwt loader and runs it in
|
||||
# MAME. Both -O0 and -O2 run by default; RUNTIME_OPT=-O0 (or -O2) selects one.
|
||||
@@ -30,20 +30,27 @@
|
||||
# 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)
|
||||
DIR=$ROOT/scripts/m6
|
||||
SHIM=$ROOT/scripts/tests/m5/conformance/shim.c
|
||||
SHIM=$ROOT/sdk/shim.c
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
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"
|
||||
|
||||
+172
-5
@@ -114,11 +114,99 @@ WIDE_LL=${WIDE_LL:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m7-data-ini
|
||||
-o "$WORK/wide.o" > "$WORK/wide.log" 2>&1 \
|
||||
|| { cat "$WORK/wide.log" >&2; fail "object-mode wide-integer compile failed"; }
|
||||
|
||||
echo "== M9 vector initializers in the raw and object paths"
|
||||
# Integer and floating vector constants are emitted as their exact
|
||||
# little-endian element bytes (the f32 elements are target GSP words, not
|
||||
# IEEE). The asm arm is pinned here as text and the object arm below as
|
||||
# bytes; llvm/test/CodeGen/TMS34010/m9-vector-data.ll covers the same module.
|
||||
VECTOR_LL=${VECTOR_LL:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m9-vector-data.ll}
|
||||
[ -f "$VECTOR_LL" ] || fail "missing vector fixture $VECTOR_LL"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$VECTOR_LL" \
|
||||
-o "$WORK/vector.s" > "$WORK/vector.log" 2>&1 \
|
||||
|| { cat "$WORK/vector.log" >&2; fail "raw vector compile failed"; }
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj "$VECTOR_LL" \
|
||||
-o "$WORK/vector.o" > "$WORK/vector-obj.log" 2>&1 \
|
||||
|| { cat "$WORK/vector-obj.log" >&2; fail "object vector compile failed"; }
|
||||
"$TMS_LLC" -march=tms34010 -O2 -filetype=obj "$VECTOR_LL" \
|
||||
-o "$WORK/vector-o2.o" > "$WORK/vector-obj-o2.log" 2>&1 \
|
||||
|| { cat "$WORK/vector-obj-o2.log" >&2; \
|
||||
fail "object vector -O2 compile failed"; }
|
||||
|
||||
# A padded zero vector (<3 x i32>: 12 store / 16 alloc) is supported because
|
||||
# the emitter writes store bytes and the callers/trailer add the allocation
|
||||
# padding. Its record member offset and .data size are byte-checked below.
|
||||
PADDED_LL=${PADDED_LL:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m9-vector-data-padded-zero.ll}
|
||||
[ -f "$PADDED_LL" ] || fail "missing padded-zero vector fixture $PADDED_LL"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj "$PADDED_LL" \
|
||||
-o "$WORK/vector-padded-zero.o" > "$WORK/vector-padded-zero.log" 2>&1 \
|
||||
|| { cat "$WORK/vector-padded-zero.log" >&2; \
|
||||
fail "object padded-zero vector compile failed"; }
|
||||
|
||||
python3 - "$WORK/vector.s" <<'PY' \
|
||||
|| fail "raw vector .data directives do not match"
|
||||
import sys
|
||||
|
||||
lines = [line.strip() for line in open(sys.argv[1])]
|
||||
|
||||
|
||||
def block(label):
|
||||
try:
|
||||
start = lines.index(label + ":")
|
||||
except ValueError:
|
||||
sys.exit(f"raw vector asm: missing {label}:")
|
||||
out = []
|
||||
for line in lines[start + 1:]:
|
||||
if not line:
|
||||
continue
|
||||
if (line.endswith(":") or line.startswith(".globl") or
|
||||
line == ".even" or line.startswith(".data") or
|
||||
line.startswith(".text")):
|
||||
break
|
||||
out.append(line)
|
||||
return out
|
||||
|
||||
|
||||
want = {
|
||||
# <2 x i32>: two little-endian .long values.
|
||||
"_v2i32": [".long 287454020", ".long 3735928559"],
|
||||
# <4 x i16>: four 16-bit elements, in order.
|
||||
"_v4i16": [".word 01234h", ".word 0FFFFh", ".word 05566h", ".word 0ABCDh"],
|
||||
# <2 x float>: GSP 1.0 = 40400000h, GSP 2.5 = 40D00000h.
|
||||
"_v2f32": [".long 40400000h", ".long 40D00000h"],
|
||||
# Vector aggregate zero: exactly the 8-byte allocation.
|
||||
"_vzero": [".byte 0, 0, 0, 0, 0, 0, 0, 0"],
|
||||
# Array of vector: element order, then a zero vector element.
|
||||
"_vaggarr": [".word 00001h", ".word 00002h", ".byte 0, 0, 0, 0"],
|
||||
# Record member vector at its DataLayout offset (3 pad bytes first).
|
||||
"_vrec": [".byte 011h", ".byte 0, 0, 0", ".word 01234h",
|
||||
".word 0ABCDh", ".long 195948557"],
|
||||
# <8 x i8>: one .byte per element in order.
|
||||
"_v8i8": [".byte 001h", ".byte 002h", ".byte 003h", ".byte 004h",
|
||||
".byte 005h", ".byte 006h", ".byte 007h", ".byte 008h"],
|
||||
# <2 x i64>: LSW-first words per element.
|
||||
"_v2i64": [".long 55667788h", ".long 11223344h",
|
||||
".long 0DDEEFF00h", ".long 99AABBCCh"],
|
||||
# <2 x f64>: GSP doubles, LSW-first (1.5 / 2.5).
|
||||
"_v2f64": [".long 00000000h", ".long 400C0000h",
|
||||
".long 00000000h", ".long 401A0000h"],
|
||||
}
|
||||
for label, want_lines in want.items():
|
||||
got = block(label)
|
||||
if got != want_lines:
|
||||
sys.exit(f"raw vector asm: {label} {got}, want {want_lines}")
|
||||
|
||||
print("m7-data-raw-vector: <2 x i32>/<4 x i16>/<2 x float>/<8 x i8>/"
|
||||
"<2 x i64>/<2 x f64>/zero/nested bytes exact")
|
||||
PY
|
||||
|
||||
echo "== parse the native objects' .data before linking"
|
||||
python3 - "$WORK/native/asm/m7data.o" \
|
||||
"$WORK/native/asm/i64arr.o" \
|
||||
"$WORK/native/asm/oddptr.o" \
|
||||
"$WORK/wide.o" <<'PY' \
|
||||
"$WORK/wide.o" \
|
||||
"$WORK/vector.o" \
|
||||
"$WORK/vector-o2.o" \
|
||||
"$WORK/vector-padded-zero.o" <<'PY' \
|
||||
|| fail "native .data bytes/symbols/relocations do not match"
|
||||
import struct
|
||||
import sys
|
||||
@@ -181,7 +269,8 @@ def at(symbols, name, raw, hexbytes, field_off=0, path=""):
|
||||
sys.exit(f"{path}: {name} bytes {got.hex()}, want {hexbytes}")
|
||||
|
||||
|
||||
base_path, i64_path, odd_path, wide_path = sys.argv[1:5]
|
||||
base_path, i64_path, odd_path, wide_path, vector_path, vector_o2_path, \
|
||||
padded_path = sys.argv[1:8]
|
||||
|
||||
# The original .data set: exactly 72 bytes and the three literal relocation
|
||||
# addresses for _pp, _cp and _pt.p.
|
||||
@@ -245,12 +334,90 @@ wide_want = {
|
||||
for name, hexbytes in wide_want.items():
|
||||
at(symbols, name, raw, hexbytes, path=wide_path)
|
||||
|
||||
# M9 vector initializers in TI-COFF: every element is its exact little-endian
|
||||
# bytes, the f32/f64 elements are GSP words, and the vector zero is the full
|
||||
# allocation. Symbol values are section-relative bit addresses. Both the
|
||||
# alloc==store fixture and the padded-zero fixture are gated, including the
|
||||
# total .data size and the inter-symbol offsets (so extra bytes emitted
|
||||
# between symbols cannot hide).
|
||||
def check_vector(path):
|
||||
raw, size, symbols, relocs = parse(path)
|
||||
if size != 96 * 8:
|
||||
sys.exit(f"{path}: .data size {size} bits, want 96 bytes (768)")
|
||||
if relocs:
|
||||
sys.exit(f"{path}: unexpected relocations "
|
||||
f"{[hex(r) for r in relocs]}")
|
||||
offsets = {
|
||||
"_v2i32": 0, "_v4i16": 8, "_v2f32": 16, "_vzero": 24,
|
||||
"_vaggarr": 32, "_vrec": 40, "_v8i8": 56, "_v2i64": 64,
|
||||
"_v2f64": 80,
|
||||
}
|
||||
for name, off in offsets.items():
|
||||
if name not in symbols:
|
||||
sys.exit(f"{path}: missing symbol {name}")
|
||||
if symbols[name] // 8 != off:
|
||||
sys.exit(f"{path}: {name} at byte {symbols[name] // 8}, "
|
||||
f"want {off}")
|
||||
vector_want = {
|
||||
"_v2i32": "44332211efbeadde",
|
||||
"_v4i16": "3412ffff6655cdab",
|
||||
"_v2f32": "000040400000d040",
|
||||
"_vzero": "0000000000000000",
|
||||
"_vaggarr": "0100020000000000",
|
||||
"_vrec": "110000003412cdab0df0ad0b",
|
||||
"_v8i8": "0102030405060708",
|
||||
"_v2i64": "887766554433221100ffeeddccbbaa99",
|
||||
"_v2f64": "0000000000000c400000000000001a40",
|
||||
}
|
||||
for name, hexbytes in vector_want.items():
|
||||
at(symbols, name, raw, hexbytes, path=path)
|
||||
return raw
|
||||
|
||||
|
||||
vector_o0 = check_vector(vector_path)
|
||||
vector_o2 = check_vector(vector_o2_path)
|
||||
if vector_o0 != vector_o2:
|
||||
sys.exit("vector object bytes differ between -O0 and -O2")
|
||||
|
||||
# Padded aggregate-zero vectors: <3 x i32> is 12 store / 16 alloc and the
|
||||
# record is 20 store / 32 alloc. Offsets prove the following member lands at
|
||||
# its DataLayout offset (record i32 at byte 16) and the total proves the
|
||||
# emitter does not over-write or double-pad.
|
||||
raw, size, symbols, relocs = parse(padded_path)
|
||||
if size != 116 * 8:
|
||||
sys.exit(f"{padded_path}: .data size {size} bits, want 116 bytes (928)")
|
||||
if relocs:
|
||||
sys.exit(f"{padded_path}: unexpected relocations "
|
||||
f"{[hex(r) for r in relocs]}")
|
||||
padded_offsets = {
|
||||
"_z3i32": 0, "_z3i32_next": 16, "_z3rec": 32,
|
||||
"_z3rec_next": 64, "_z3arr": 80, "_z3arr_next": 112,
|
||||
}
|
||||
for name, off in padded_offsets.items():
|
||||
if name not in symbols:
|
||||
sys.exit(f"{padded_path}: missing symbol {name}")
|
||||
if symbols[name] // 8 != off:
|
||||
sys.exit(f"{padded_path}: {name} at byte {symbols[name] // 8}, "
|
||||
f"want {off}")
|
||||
padded_want = {
|
||||
"_z3i32": "00" * 16,
|
||||
"_z3rec": "00" * 16 + "07000000" + "00" * 12,
|
||||
"_z3arr": "00" * 32,
|
||||
}
|
||||
for name, hexbytes in padded_want.items():
|
||||
at(symbols, name, raw, hexbytes, path=padded_path)
|
||||
|
||||
print("m7-data-object: own .data=72 bytes relocs=0x1b0/0x1d0/0x210; "
|
||||
"i64arr .data=16 bytes; oddptr .data=6 bytes reloc=0x8; "
|
||||
"wide i24/i40/i48/i56 + [2 x i24] bytes exact")
|
||||
"wide i24/i40/i48/i56 + [2 x i24] bytes exact; "
|
||||
"vector .data=96 bytes at -O0 and -O2, symbol offsets and "
|
||||
"<2 x i32>/<4 x i16>/<2 x f32>/<8 x i8>/<2 x i64>/<2 x f64>/zero/"
|
||||
"nested bytes exact; padded zero .data=116 bytes with record member at "
|
||||
"byte 16")
|
||||
PY
|
||||
|
||||
echo "m7 data: PASS (i64 LSW-first in asm and object mode, i64 array, i24/i40/"
|
||||
echo " i48/i56 and [2 x i24] bytes in asm and object mode, packed "
|
||||
echo " records, bitfields, union, pointer relocations, and the "
|
||||
echo " native-only odd-offset pointer in TI-COFF/MAME)"
|
||||
echo " records, bitfields, union, pointer relocations, the "
|
||||
echo " native-only odd-offset pointer in TI-COFF/MAME, and M9 "
|
||||
echo " integer/fp vector .data bytes in asm and object mode)"
|
||||
@@ -7,12 +7,14 @@
|
||||
# bit-pointer barrier) and `llc -filetype=obj`; require the object's
|
||||
# long-named `.debug_*` sections and assert, in the final IR, that the
|
||||
# `@debug_ptr` body's barrier-synthesized instructions (`mul`, `shl i32`,
|
||||
# `ptrtoint ptr`, `add i32`, `inttoptr i32`) plus its loads/stores carry
|
||||
# `ptrtoint ptr`, `llvm.tms34010.bitaddr`, `inttoptr i32`) plus its
|
||||
# loads/stores carry
|
||||
# `!dbg`. The TU has three functions: debug_mul (int arithmetic),
|
||||
# debug_add (int arithmetic), and debug_ptr (`p += debug_index; return *p`,
|
||||
# a runtime GEP the barrier rewrites).
|
||||
# 2. Also build the same TU with `tms-clang -g -O2` (the full
|
||||
# --bitptr -> opt -> --scale -> --lower-bitptr -> instcombine path), require
|
||||
# 2. Also build the same TU with `tms-clang -g -O2` (the native M10 new-PM
|
||||
# pipeline: `TMS34010BitPtrPass` -> optimizer -> `TMS34010ScaleGEPPass` ->
|
||||
# `TMS34010LowerBitPtrPass` -> instcombine), require
|
||||
# the six core `.debug_*` sections, link it with `--keep-debug`, wrap it and
|
||||
# smoke-check `debug.c`, a subprogram name and the linked base address with
|
||||
# llvm-dwarfdump. The optimized layout is not stable, so the exact
|
||||
@@ -88,7 +90,7 @@ echo "== compile scripts/m7/debug.c with tms-clang -g and llc -filetype=obj"
|
||||
grep -q '!dbg' "$WORK/debug.ll" || fail "debug.ll has no !dbg metadata"
|
||||
|
||||
# The barrier-synthesized instructions must carry !dbg, not just the ordinary
|
||||
# loads/stores. Extract @debug_ptr and check the --bitptr / --lower-bitptr
|
||||
# loads/stores. Extract @debug_ptr and check the llvm.tms34010.bitaddr
|
||||
# chain plus the load/store through the computed pointer. This is the
|
||||
# attribution the line-table rows alone cannot prove.
|
||||
awk '
|
||||
@@ -116,7 +118,7 @@ check_dbg_line() { # check_dbg_line LABEL ERE
|
||||
check_dbg_line "GEP index multiply" 'mul i32 .*'
|
||||
check_dbg_line "bit-offset shl" 'shl i32 .* 3'
|
||||
check_dbg_line "ptrtoint base" 'ptrtoint ptr .* to i32'
|
||||
check_dbg_line "bit-address add" 'add i32 .*'
|
||||
check_dbg_line "bit-address intrinsic" 'call i32 @llvm\.tms34010\.bitaddr'
|
||||
check_dbg_line "lowered inttoptr" 'inttoptr i32 .* to ptr'
|
||||
for op in store load; do
|
||||
grep -E "^[[:space:]]*${op} |^[[:space:]]*%[^ ]+ = ${op} " \
|
||||
@@ -129,7 +131,7 @@ for op in store load; do
|
||||
fail "@debug_ptr has a $op without !dbg"
|
||||
fi
|
||||
done
|
||||
echo " @debug_ptr barrier IR: mul/shl/ptrtoint/add/inttoptr + loads/stores"
|
||||
echo " @debug_ptr barrier IR: mul/shl/ptrtoint/bitaddr/inttoptr + loads/stores"
|
||||
echo " all carry !dbg"
|
||||
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
@@ -153,8 +155,9 @@ print(" object debug sections: " + " ".join(debug))
|
||||
PY
|
||||
|
||||
echo "== build the same TU at -O2 -g (full barrier/optimizer pipeline)"
|
||||
# -O2 runs clang -> --bitptr -> opt -> --scale -> --lower-bitptr ->
|
||||
# instcombine. Requiring the object's .debug_* sections from this build (and
|
||||
# -O2 runs clang's native M10 new-PM pipeline: TMS34010BitPtrPass (barrier) ->
|
||||
# optimizer -> TMS34010ScaleGEPPass -> TMS34010LowerBitPtrPass -> instcombine.
|
||||
# Requiring the object's .debug_* sections from this build (and
|
||||
# the dwarfdump check below) proves !dbg survives the barrier and the
|
||||
# optimizer, not just the -O0 path.
|
||||
( cd "$DIR" && "$TMS_CLANG" -g -O2 -o "$WORK/debug-o2.ll" debug.c ) \
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
# 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
|
||||
# M9.4 full-suite report
|
||||
# generated: 2026-11-17T05:18:25Z
|
||||
# work: build/m9-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=bec449573fe3c42eb213d5316f2078e89b6009b0 bin=54359ac53db46558 loader=200/1000
|
||||
# provenance: fresh end-to-end --redo run with the final M9 compiler; no retained rows. 294 skips = 64 classifier + 230 curated, every one with a reason.
|
||||
# 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/m9-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 1408 284 0 0 1692 0
|
||||
c-testsuite 220 210 10 0 0 220 0
|
||||
all 1912 1576 336 0 0 1912 0
|
||||
all 1912 1618 294 0 0 1912 0
|
||||
|
||||
# fail categories (per selected corpus)
|
||||
# c-torture
|
||||
@@ -27,18 +30,17 @@ abi-return 10
|
||||
abi-sret 9
|
||||
abi-varargs-return 3
|
||||
builtin 11
|
||||
codegen 19
|
||||
codegen 2
|
||||
codegen-float 2
|
||||
compile 8
|
||||
compiler-crash 6
|
||||
corpus 5
|
||||
data-init 14
|
||||
data-odd-pointer 1
|
||||
data-vector 5
|
||||
extension 1
|
||||
file-io 18
|
||||
float-constant 1
|
||||
inline-asm 33
|
||||
inline-asm 13
|
||||
int128 15
|
||||
libc 1
|
||||
memory 15
|
||||
@@ -50,11 +52,11 @@ runtime-abort-bitfield 9
|
||||
runtime-abort-float 5
|
||||
runtime-abort-i64 10
|
||||
runtime-abort-varargs 6
|
||||
runtime-abort-vector 3
|
||||
runtime-abort-vector 5
|
||||
runtime-bitfield 2
|
||||
setjmp 6
|
||||
signal 4
|
||||
timeout 23
|
||||
timeout 21
|
||||
vector 2
|
||||
vla 9
|
||||
wide-char 16
|
||||
@@ -78,7 +80,6 @@ c-testsuite 00204 skip:format-unsupported: printf %n, positional $, %e/%g/%a/%F,
|
||||
c-testsuite 00208 skip:wide-char: wide characters are unsupported 0
|
||||
c-testsuite 00220 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture 20000822-1 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture 20001009-2 skip:inline-asm: could not allocate input reg for constraint 'r' at line 105 0
|
||||
c-torture 20001111-1 skip:builtin: use of unknown builtin '__builtin_exit' [-Wimplicit-function-declaration] 0
|
||||
c-torture 20001124-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture 20010122-1 skip:compiler-crash: unexpected TMS34010 custom lowering operation (return address) 0
|
||||
@@ -90,19 +91,16 @@ c-torture 20010904-1 skip:runtime-abort-alignment: test abort (status 0x86) 0
|
||||
c-torture 20010904-2 skip:runtime-abort-alignment: test abort (status 0x86) 0
|
||||
c-torture 20010924-1 skip:data-odd-pointer: pointer field at an odd .data byte offset 0
|
||||
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
|
||||
c-torture 20030209-1 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture 20030222-1 skip:inline-asm: could not allocate output register for constraint 'r' at line 495 0
|
||||
c-torture 20030222-1 skip:inline-asm: a 64-bit "0" input tied to a 32-bit 'r' output has no allocatable register pair 0
|
||||
c-torture 20030323-1 skip:compiler-crash: unexpected TMS34010 custom lowering operation 0
|
||||
c-torture 20030501-1 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture 20030811-1 skip:compiler-crash: unexpected TMS34010 custom lowering operation 0
|
||||
@@ -115,7 +113,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 +132,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
|
||||
@@ -173,13 +168,11 @@ c-torture 931004-4 skip:runtime-abort-bitfield: test abort (status 0x86) 0
|
||||
c-torture 931004-6 skip:runtime-abort-bitfield: test abort (status 0x86) 0
|
||||
c-torture 931004-8 skip:runtime-abort-bitfield: test abort (status 0x86) 0
|
||||
c-torture 941202-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture 960312-1 skip:inline-asm: could not allocate input reg for constraint 'r' at line 218 0
|
||||
c-torture 960512-1 skip:abi-sret: aggregate return via an sret pointer is unsupported 0
|
||||
c-torture 960521-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture 970214-1 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture 970214-2 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture 980709-1 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture 990130-1 skip:inline-asm: could not allocate output register for constraint 'r' at line 152 0
|
||||
c-torture 990208-1 skip:codegen: t5: i32 = BlockAddress<@doit, %here> 0 0
|
||||
c-torture 990413-2 skip:inline-asm: invalid output constraint '=t' 0
|
||||
c-torture 991112-1 skip:runtime-abort: test abort (status 0x86) 0
|
||||
@@ -189,10 +182,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,11 +194,9 @@ 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-2 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 1
|
||||
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
|
||||
@@ -230,28 +219,23 @@ c-torture nestfunc-6 skip:nested-function: nested function definitions are unsup
|
||||
c-torture nestfunc-7 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture pr103052 skip:builtin: use of unknown builtin '__builtin_exit' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr103255 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
c-torture pr103376 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr103376 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr103405 skip:nested-function: nested function definitions are unsupported 0
|
||||
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
|
||||
c-torture pr109938 skip:corpus: references a gcc.dg source absent from the pinned execute tree 0
|
||||
c-torture pr109986 skip:corpus: references a gcc.dg source absent from the pinned execute tree 0
|
||||
c-torture pr110252-2 skip:inline-asm: could not allocate output register for constraint 'r' at line 155 0
|
||||
c-torture pr111469-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 0
|
||||
c-torture pr111469-1 skip:file-io: stdio/POSIX file I/O is unavailable under the bare loader 1
|
||||
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
|
||||
c-torture pr123753 skip:vector: cannot decrement a vector value 0
|
||||
c-torture pr123864 skip:builtin: use of unknown builtin '__builtin_mul_overflow_p' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr125291 skip:abi-indirect-call: indirect call through a non-function value 0
|
||||
@@ -263,7 +247,7 @@ c-torture pr20621-1 skip:timeout: compilation did not finish within the 210s out
|
||||
c-torture pr22061-1 skip:compile: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion] 0
|
||||
c-torture pr22061-3 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture pr22061-4 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture pr23135 skip:data-vector: vector constants in .data are unsupported 0
|
||||
c-torture pr23135 skip:timeout: vector test does not finish within LOADER_END=1000 (LOADER_END=20000 also timed out) 0
|
||||
c-torture pr23324 skip:data-init: unsupported .data initializer 0
|
||||
c-torture pr24135 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture pr28865 skip:vla: variable-length array in a struct is unsupported 0
|
||||
@@ -274,35 +258,26 @@ 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
|
||||
c-torture pr38969 skip:abi-sret: aggregate return via an sret pointer is unsupported 0
|
||||
c-torture pr39228 skip:builtin: use of unknown builtin '__builtin_isinff' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr40022 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr40657 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr40022 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr40657 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 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
|
||||
c-torture pr44575 skip:runtime-abort-varargs: test abort (status 0x86) 0
|
||||
c-torture pr44683 skip:runtime-abort-float: test abort (status 0x86) 0
|
||||
c-torture pr45695 skip:inline-asm: could not allocate output register for constraint 'r' at line 121 0
|
||||
c-torture pr47237 skip:builtin: use of unknown builtin '__builtin_apply' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr49218 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr49279 skip:inline-asm: could not allocate output register for constraint 'r' at line 199 0
|
||||
c-torture pr49390 skip:inline-asm: could not allocate output register for constraint 'r' at line 1508 0
|
||||
c-torture pr51447 skip:nested-function: nested function definitions are unsupported 0
|
||||
c-torture pr51581-1 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture pr51581-2 skip:memory: linked image exceeds the 45 KiB program / 64 KiB RAM region 0
|
||||
c-torture pr52286 skip:inline-asm: could not allocate output register for constraint 'r' at line 119 0
|
||||
c-torture pr53645 skip:data-init: unsupported .data initializer 0
|
||||
c-torture pr53645-2 skip:data-init: unsupported .data initializer 0
|
||||
c-torture pr54471 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr56866 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr56866 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr56982 skip:setjmp: setjmp/longjmp need non-local jumps, which are unsupported 0
|
||||
c-torture pr57344-3 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
c-torture pr57344-4 skip:runtime-abort-i64: test abort (status 0x86) 0
|
||||
@@ -312,20 +287,15 @@ 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 pr65053-2 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
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
|
||||
c-torture pr65956 skip:inline-asm: could not allocate output register for constraint 'r' at line 285 0
|
||||
c-torture pr67037 skip:timeout: did not finish within LOADER_END=1000 0
|
||||
c-torture pr68328 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr68328 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr68390 skip:abi-varargs-return: float/double/i64/aggregate return from a variadic definition is unsupported 0
|
||||
c-torture pr68532 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture pr70460 skip:data-init: unsupported .data initializer 0
|
||||
@@ -338,34 +308,27 @@ c-torture pr78622 skip:file-io: stdio/POSIX file I/O is unavailable under the ba
|
||||
c-torture pr78791 skip:data-init: unsupported .data initializer 0
|
||||
c-torture pr79327 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr79737-2 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr80421 skip:inline-asm: could not allocate input reg for constraint 'r' at line 113 0
|
||||
c-torture pr80692 skip:extension: GNU decimal float type is unsupported 0
|
||||
c-torture pr81588 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr81588 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr82210 skip:vla: variable-length array in a struct is unsupported 0
|
||||
c-torture pr82954 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr82954 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr84169 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr84521 skip:setjmp: __builtin_longjmp is unsupported 0
|
||||
c-torture pr84524 skip:inline-asm: could not allocate output register for constraint 'r' at line 468 0
|
||||
c-torture pr84748 skip:int128: 128-bit integers are unsupported 0
|
||||
c-torture pr85156 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr85156 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
c-torture pr85169 skip:runtime-abort: test abort (status 0x86) 0
|
||||
c-torture pr85331 skip:builtin: use of unknown builtin '__builtin_shuffle' [-Wimplicit-function-declaration] 0
|
||||
c-torture pr85582-2 skip:int128: 128-bit integers are unsupported 0
|
||||
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
|
||||
c-torture pr94130 skip:inline-asm: Could not match memory address. Inline asm failure! 0
|
||||
c-torture pr94130 skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 0
|
||||
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
|
||||
@@ -374,14 +337,12 @@ c-torture ptr-arith-1 skip:wide-char: wide characters are unsupported 0
|
||||
c-torture scal-to-vec1 skip:runtime-abort-vector: test abort (status 0x86) 0
|
||||
c-torture scal-to-vec2 skip:runtime-abort-vector: test abort (status 0x86) 0
|
||||
c-torture scal-to-vec3 skip:runtime-abort-vector: test abort (status 0x86) 0
|
||||
c-torture simd-1 skip:data-vector: vector constants in .data are unsupported 0
|
||||
c-torture simd-2 skip:data-vector: vector constants in .data are unsupported 0
|
||||
c-torture simd-1 skip:runtime-abort-vector: test abort (status 0x86) 0
|
||||
c-torture simd-2 skip:runtime-abort-vector: test abort (status 0x86) 0
|
||||
c-torture simd-4 skip:abi-float-args: float/double arguments are unsupported 0
|
||||
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 stkalign skip:inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher) 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 +356,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 +365,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/m9-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 "# M9.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,24 @@
|
||||
# M7.4 full-suite curated skips.
|
||||
# M7.4/M9.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/M9.4 re-ran the whole corpus end-to-end with the final
|
||||
# compiler (`--redo`, build/m8-full-suite and build/m9-bare-full); 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.
|
||||
# M9.1 removed the 22 inline-asm `r` and vector `.data` rows that now pass
|
||||
# (20 `r` constraint rows plus simd-5 and pr123625-2). The five remaining
|
||||
# rows from that class now carry an accurate reason: 20030222-1 ties a 64-bit
|
||||
# input to a 32-bit `r` output, pr23135 compiles but does not finish, simd-1/
|
||||
# simd-2 compile but abort during vector arithmetic, and stkalign still needs
|
||||
# an unsupported memory operand.
|
||||
#
|
||||
# Categories: compiler-crash, codegen, inline-asm, nested-function, vla,
|
||||
# data-init, data-vector, data-odd-pointer, abi-*, builtin, libm, memory,
|
||||
@@ -14,7 +27,6 @@
|
||||
c-testsuite/00040 timeout: did not finish within LOADER_END=1000
|
||||
c-testsuite/00174 libm: sin/float formatting differs from the expected libm output
|
||||
c-torture/20000822-1 nested-function: nested function definitions are unsupported
|
||||
c-torture/20001009-2 inline-asm: could not allocate input reg for constraint 'r' at line 105
|
||||
c-torture/20001111-1 builtin: use of unknown builtin '__builtin_exit' [-Wimplicit-function-declaration]
|
||||
c-torture/20010122-1 compiler-crash: unexpected TMS34010 custom lowering operation (return address)
|
||||
c-torture/20010209-1 nested-function: nested function definitions are unsupported
|
||||
@@ -23,17 +35,14 @@ c-torture/20010605-2 libc: call to undeclared function 'exit'; ISO C99 and later
|
||||
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
|
||||
c-torture/20030222-1 inline-asm: could not allocate output register for constraint 'r' at line 495
|
||||
c-torture/20030222-1 inline-asm: a 64-bit "0" input tied to a 32-bit 'r' output has no allocatable register pair
|
||||
c-torture/20030323-1 compiler-crash: unexpected TMS34010 custom lowering operation
|
||||
c-torture/20030501-1 nested-function: nested function definitions are unsupported
|
||||
c-torture/20030811-1 compiler-crash: unexpected TMS34010 custom lowering operation
|
||||
@@ -46,7 +55,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 +74,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)
|
||||
@@ -98,11 +104,9 @@ c-torture/931004-4 runtime-abort-bitfield: test abort (status 0x86)
|
||||
c-torture/931004-6 runtime-abort-bitfield: test abort (status 0x86)
|
||||
c-torture/931004-8 runtime-abort-bitfield: test abort (status 0x86)
|
||||
c-torture/941202-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/960312-1 inline-asm: could not allocate input reg for constraint 'r' at line 218
|
||||
c-torture/960512-1 abi-sret: aggregate return via an sret pointer is unsupported
|
||||
c-torture/960521-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/980709-1 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/990130-1 inline-asm: could not allocate output register for constraint 'r' at line 152
|
||||
c-torture/990208-1 codegen: t5: i32 = BlockAddress<@doit, %here> 0
|
||||
c-torture/990413-2 inline-asm: invalid output constraint '=t'
|
||||
c-torture/991112-1 runtime-abort: test abort (status 0x86)
|
||||
@@ -112,10 +116,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 +127,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
|
||||
@@ -145,23 +145,18 @@ c-torture/nestfunc-6 nested-function: nested function definitions are unsupporte
|
||||
c-torture/nestfunc-7 nested-function: nested function definitions are unsupported
|
||||
c-torture/pr103052 builtin: use of unknown builtin '__builtin_exit' [-Wimplicit-function-declaration]
|
||||
c-torture/pr103255 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/pr103376 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr103376 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
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
|
||||
c-torture/pr109938 corpus: references a gcc.dg source absent from the pinned execute tree
|
||||
c-torture/pr109986 corpus: references a gcc.dg source absent from the pinned execute tree
|
||||
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
|
||||
c-torture/pr123864 builtin: use of unknown builtin '__builtin_mul_overflow_p' [-Wimplicit-function-declaration]
|
||||
c-torture/pr125291 abi-indirect-call: indirect call through a non-function value
|
||||
@@ -172,7 +167,7 @@ c-torture/pr20621-1 timeout: compilation did not finish within the 210s outer wa
|
||||
c-torture/pr22061-1 compile: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
|
||||
c-torture/pr22061-3 nested-function: nested function definitions are unsupported
|
||||
c-torture/pr22061-4 nested-function: nested function definitions are unsupported
|
||||
c-torture/pr23135 data-vector: vector constants in .data are unsupported
|
||||
c-torture/pr23135 timeout: vector test does not finish within LOADER_END=1000 (LOADER_END=20000 also timed out)
|
||||
c-torture/pr23324 data-init: unsupported .data initializer
|
||||
c-torture/pr24135 nested-function: nested function definitions are unsupported
|
||||
c-torture/pr28865 vla: variable-length array in a struct is unsupported
|
||||
@@ -182,31 +177,22 @@ 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
|
||||
c-torture/pr38969 abi-sret: aggregate return via an sret pointer is unsupported
|
||||
c-torture/pr39228 builtin: use of unknown builtin '__builtin_isinff' [-Wimplicit-function-declaration]
|
||||
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/pr40022 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
c-torture/pr40657 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
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)
|
||||
c-torture/pr44683 runtime-abort-float: test abort (status 0x86)
|
||||
c-torture/pr45695 inline-asm: could not allocate output register for constraint 'r' at line 121
|
||||
c-torture/pr47237 builtin: use of unknown builtin '__builtin_apply' [-Wimplicit-function-declaration]
|
||||
c-torture/pr49279 inline-asm: could not allocate output register for constraint 'r' at line 199
|
||||
c-torture/pr49390 inline-asm: could not allocate output register for constraint 'r' at line 1508
|
||||
c-torture/pr51447 nested-function: nested function definitions are unsupported
|
||||
c-torture/pr51581-1 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/pr51581-2 memory: linked image exceeds the 45 KiB program / 64 KiB RAM region
|
||||
c-torture/pr52286 inline-asm: could not allocate output register for constraint 'r' at line 119
|
||||
c-torture/pr53645 data-init: unsupported .data initializer
|
||||
c-torture/pr53645-2 data-init: unsupported .data initializer
|
||||
c-torture/pr56866 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr56866 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
c-torture/pr57344-3 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/pr57344-4 runtime-abort-i64: test abort (status 0x86)
|
||||
c-torture/pr58209 runtime-abort: test abort (status 0x86)
|
||||
@@ -214,18 +200,13 @@ 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/pr65053-2 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
c-torture/pr65401 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr65427 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr65648 inline-asm: could not allocate input reg for constraint 'r' at line 225
|
||||
c-torture/pr65956 inline-asm: could not allocate output register for constraint 'r' at line 285
|
||||
c-torture/pr67037 timeout: did not finish within LOADER_END=1000
|
||||
c-torture/pr68328 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr68328 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
c-torture/pr68390 abi-varargs-return: float/double/i64/aggregate return from a variadic definition is unsupported
|
||||
c-torture/pr70460 data-init: unsupported .data initializer
|
||||
c-torture/pr70566 timeout: did not finish within LOADER_END=1000
|
||||
@@ -236,40 +217,31 @@ c-torture/pr71626-2 abi-return: unsupported aggregate/variadic return shape
|
||||
c-torture/pr78791 data-init: unsupported .data initializer
|
||||
c-torture/pr79327 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr79737-2 runtime-abort: test abort (status 0x86)
|
||||
c-torture/pr80421 inline-asm: could not allocate input reg for constraint 'r' at line 113
|
||||
c-torture/pr80692 extension: GNU decimal float type is unsupported
|
||||
c-torture/pr81588 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr81588 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
c-torture/pr82210 vla: variable-length array in a struct is unsupported
|
||||
c-torture/pr82954 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr82954 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
c-torture/pr84521 setjmp: __builtin_longjmp is unsupported
|
||||
c-torture/pr84524 inline-asm: could not allocate output register for constraint 'r' at line 468
|
||||
c-torture/pr85156 inline-asm: Could not match memory address. Inline asm failure!
|
||||
c-torture/pr85156 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
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/pr94130 inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
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)
|
||||
c-torture/scal-to-vec2 runtime-abort-vector: test abort (status 0x86)
|
||||
c-torture/scal-to-vec3 runtime-abort-vector: test abort (status 0x86)
|
||||
c-torture/simd-1 data-vector: vector constants in .data are unsupported
|
||||
c-torture/simd-2 data-vector: vector constants in .data are unsupported
|
||||
c-torture/simd-1 runtime-abort-vector: test abort (status 0x86)
|
||||
c-torture/simd-2 runtime-abort-vector: test abort (status 0x86)
|
||||
c-torture/simd-4 abi-float-args: float/double arguments are unsupported
|
||||
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/stkalign inline-asm: TMS34010 memory constraints ('m'/'o'/'V') are unsupported (no addressing-mode matcher)
|
||||
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 +251,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)
|
||||
+49
-21
@@ -5,41 +5,58 @@
|
||||
#
|
||||
# Compiles scripts/m7/i64div-perf.c with tms-clang/llc, assembles and links
|
||||
# it with GSPA/GSPLNK 2.00 under DOSBox through scripts/m4/run.sh, loads the
|
||||
# COFF with the dwt loader and runs it in MAME. The driver runs two
|
||||
# COFF with the dwt loader and runs it in MAME. The driver runs four
|
||||
# equal-iteration workloads:
|
||||
#
|
||||
# - 16384 iterations with both operands fitting 32 bits after the signed
|
||||
# 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, a 32-bit divisor
|
||||
# and hi(N) >= D: each i64 div/rem takes the M8.3 two-step 64/32 path
|
||||
# (two even-destination DIVUs) instead of the loop;
|
||||
# - 16384 iterations with a nonzero dividend high word, a 32-bit divisor
|
||||
# and hi(N) < D: each i64 div/rem takes the M9.3 single-DIVU 64/32 path
|
||||
# (one even-destination DIVU plus the low-word N - q*D reconstruction).
|
||||
#
|
||||
# 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). The
|
||||
# div32 phase must be measurable (>= 2 frames) and materially faster than the
|
||||
# M8.3 two-DIVU wide phase (4 * wide_frames >= 5 * div32_frames, 1.25x). All
|
||||
# four 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), the 64/32
|
||||
# shapes (hi >= d, hi == d, hi < d, INT64_MIN) and the single-DIVU cases
|
||||
# (0x1_00000000/3, 0x1_FFFFFFFF/0x10000, -2^32/3, 2^32/-3) and the
|
||||
# INT64_MIN-magnitude single-DIVU cases (0x8000000000000000 and INT64_MIN with
|
||||
# divisor 0xFFFFFFFF, q = r = 0x80000000 / -0x80000000).
|
||||
#
|
||||
# The markers 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
|
||||
# The fourteen marker cells (a 16-cell window) 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
|
||||
# GSPLNK maps that the marker cells do not overlap any section. The GSPA link
|
||||
# phase runs before MAME as a fail-fast check. The loader budget is widened
|
||||
# from the M6 default (LOADER_AT=200, LOADER_END=4000) to leave room for the
|
||||
# from the M6 default (LOADER_AT=200, LOADER_END=4000) to 5000 to leave room for the
|
||||
# slow phase; the M7 full-suite loader settings keep 200/1000 and are
|
||||
# unaffected.
|
||||
#
|
||||
# The compile-only preflight (tms-clang + llc asm and obj, no DOSBox/MAME)
|
||||
# checks that the driver asm has both the fast blocks (i64div.fast, DIVU) and
|
||||
# the slow loop (i64div.loop), and I64DIV_PERF_LINK_ONLY=1 also checks the
|
||||
# checks that the driver asm has the fast blocks (i64div.fast, DIVU), the
|
||||
# wide blocks (i64div.wide) and the slow loop (i64div.loop), and
|
||||
# I64DIV_PERF_LINK_ONLY=1 also checks the
|
||||
# marker cells against a host tms-link map. I64DIV_PERF_COMPILE_ONLY=1 stops
|
||||
# after the asm checks.
|
||||
# after the asm checks. The preflight also requires the M9.3 i64div.div32
|
||||
# block in the driver asm, so the single-DIVU phase is compiled even when the
|
||||
# MAME timing run is deferred.
|
||||
#
|
||||
# I64DIV_PERF_OPT=-O2 is an optimizer-level baseline, not the i64 fast-path
|
||||
# measurement: at -O2 instcombine narrows some of the fast phase's divisions to
|
||||
@@ -68,10 +85,10 @@ TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
WORK=${I64DIV_PERF_WORK:-$ROOT/build/m7-i64div-perf}
|
||||
OPT=${I64DIV_PERF_OPT:--O0}
|
||||
LOADER_AT=${LOADER_AT:-200}
|
||||
LOADER_END=${LOADER_END:-4000}
|
||||
LOADER_END=${LOADER_END:-5000}
|
||||
|
||||
# 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 16 cells at 0x20 bits apart are outside every linked section.
|
||||
MARKERS=01A20000
|
||||
PROG_ORIGIN=018A0000
|
||||
PROG_LEN=40000
|
||||
@@ -93,7 +110,7 @@ done
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
echo "== compile-only preflight ($OPT): both paths in the driver asm"
|
||||
echo "== compile-only preflight ($OPT): all four paths in the driver asm"
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
"$ROOT/scripts/tms-clang" "$OPT" -o "$WORK/i64div-perf.ll" "$SRC" \
|
||||
|| fail "tms-clang failed for i64div-perf.c"
|
||||
@@ -102,15 +119,19 @@ 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)
|
||||
div32=$(grep -c '; %i64div.div32' "$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"
|
||||
[ "$div32" -ge 1 ] || fail "no M9.3 i64div.div32 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 div32 blocks=$div32 DIVU=$divu markers=$MARKERS"
|
||||
echo " i64div-perf.s: $(grep -c . "$WORK/i64div-perf.s") lines"
|
||||
|
||||
if [ "${I64DIV_PERF_COMPILE_ONLY:-0}" = 1 ]; then
|
||||
@@ -142,28 +163,35 @@ fi
|
||||
run_m4() {
|
||||
skip=$1
|
||||
shift
|
||||
# GSPA/GSPLNK 8.3 object names: use a short copy of the driver source.
|
||||
[ -f "$WORK/prf.c" ] || cp "$SRC" "$WORK/prf.c"
|
||||
M4_WORK="$WORK" \
|
||||
M4_SDK="$WORK/sdk" \
|
||||
M4_COFF="$WORK/i64div-perf.coff" \
|
||||
M4_SOURCES="$SRC" \
|
||||
M4_SOURCES="$WORK/prf.c" \
|
||||
M4_ENTRY="$DIR/i64div-perf-entry.asm" \
|
||||
M4_CHECK_LUA="$CHECK_LUA" \
|
||||
M4_LINK_CMD="$LINK_CMD" \
|
||||
M4_CLANG_OPT="$OPT" \
|
||||
M4_LLC_OPT="$OPT" \
|
||||
M4_NATIVE=1 \
|
||||
M4_LINKER=tms-link \
|
||||
M4_OS2=1 \
|
||||
M4_NATIVE_PROG_LEN="${PROG_LEN}h" \
|
||||
M4_NATIVE_RAM_LEN="${RAM_LEN}h" \
|
||||
M4_SKIP_MAME="$skip" \
|
||||
LOADER_AT="$LOADER_AT" \
|
||||
LOADER_END="$LOADER_END" \
|
||||
"$ROOT/scripts/m4/run.sh" "$@"
|
||||
}
|
||||
|
||||
echo "== GSPA/GSPLNK link phase: assert the complete image map"
|
||||
echo "== native tms-link phase: assert the complete image map"
|
||||
run_m4 1 > "$WORK/link.log" 2>&1 \
|
||||
|| { tail -60 "$WORK/link.log" >&2; fail "GSPA/GSPLNK link failed"; }
|
||||
|| { tail -60 "$WORK/link.log" >&2; fail "native tms-link failed"; }
|
||||
python3 "$MAP_CHECK" "$WORK/m4.map" "$MARKERS" \
|
||||
"$PROG_ORIGIN" "$PROG_LEN" "$RAM_ORIGIN" "$RAM_LEN" \
|
||||
|| { tail -40 "$WORK/link.log" >&2; \
|
||||
fail "marker cells overlap a GSPLNK section"; }
|
||||
fail "marker cells overlap a linked section"; }
|
||||
|
||||
echo "== MAME run"
|
||||
run_m4 '' > "$WORK/run.log" 2>&1 \
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -108,8 +108,10 @@ grep -A8 'define.*@narrow8(' "$IR" | grep -Eq 'and i32 .*, 255' \
|
||||
|| { grep -A8 'define.*@narrow8(' "$IR" >&2 || true; \
|
||||
fail "narrow8 lost its (p & 0xff) mask"; }
|
||||
for fn in late64 late64s; do
|
||||
# The 24-bit addend now spells llvm.tms34010.bitaddr(base, 24) instead of
|
||||
# the foldable add; still reject the byte-scaled 192 below.
|
||||
grep -A8 "define.*@$fn(" "$IR" \
|
||||
| grep -Eq 'getelementptr i8, ptr %p, i32 24|add i32 %bit[.a-z0-9]*, 24' \
|
||||
| grep -Eq 'getelementptr i8, ptr %p, i32 24|add i32 %bit[.a-z0-9]*, 24|llvm\.tms34010\.bitaddr\(i32 %bit[.a-z0-9]*, i32 24\)' \
|
||||
|| { grep -A8 "define.*@$fn(" "$IR" >&2 || true; \
|
||||
fail "$fn does not carry the 24-bit addend"; }
|
||||
if grep -A8 "define.*@$fn(" "$IR" | grep -Eq 'i32 192'; then
|
||||
|
||||
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)"
|
||||
Executable
+510
@@ -0,0 +1,510 @@
|
||||
#!/bin/sh
|
||||
# M9.2 .debug_rnglists merge gate: two synthetic TUs that actually emit
|
||||
# DWARF v5 range lists through tms-link --keep-debug.
|
||||
#
|
||||
# scripts/tests/m9/dwarf-ranges.sh
|
||||
#
|
||||
# The M8 fixtures (-O0, and a straight-line -O2 shape) never emitted a range
|
||||
# list, so its whitelist entry was never exercised. The fixture helper
|
||||
# `scripts/m9/dwarf-ranges-fixture.py` builds two relocatable TI-COFF objects,
|
||||
# each with
|
||||
# .debug_abbrev/.debug_info/.debug_str/.debug_addr/.debug_rnglists,
|
||||
# a CU with DW_AT_rnglists_base, DW_AT_addr_base and DW_AT_ranges
|
||||
# (DW_FORM_rnglistx), a range list containing DW_RLE_start_end (absolute,
|
||||
# relocated .text addresses) and DW_RLE_startx_length (index into .debug_addr),
|
||||
# and a subprogram with a relocated DW_FORM_addr low PC.
|
||||
#
|
||||
# The gate:
|
||||
# 1. links the two objects with --keep-debug and with the default strip;
|
||||
# 2. checks the merged section sizes, the second TU's rehomed
|
||||
# abbrev/addr/rnglists bases and the .debug_addr/.debug_rnglists entries
|
||||
# with the independent M7 COFF reader;
|
||||
# 3. checks that a single-object --keep-debug link reproduces the M8
|
||||
# single-TU byte layout (only relocation fields differ from the input);
|
||||
# 4. wraps the kept sections in the M7 ELF32 container and requires
|
||||
# llvm-dwarfdump to show both TUs' CUs, ranges and address tables;
|
||||
# 5. checks the default strip has exactly .text/.data/.bss with the same
|
||||
# allocated bytes as the kept image.
|
||||
#
|
||||
# It is hermetic (no compiler, GSPA, DOSBox or MAME required).
|
||||
#
|
||||
# Overridable: LLVM_BIN DWARFDUMP TMS_LINK M7COFF ELF_WRAP FIXTURE
|
||||
# M9_DWARF_RANGES_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
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}
|
||||
DWARFDUMP=${DWARFDUMP:-$LLVM_BIN/llvm-dwarfdump}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
M7COFF=${M7COFF:-$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m7coff.py}
|
||||
ELF_WRAP=${ELF_WRAP:-$ROOT/scripts/m7/elf-debug-wrap.py}
|
||||
FIXTURE=${FIXTURE:-$ROOT/scripts/m9/dwarf-ranges-fixture.py}
|
||||
WORK=${M9_DWARF_RANGES_WORK:-$ROOT/build/m9-dwarf-ranges}
|
||||
|
||||
fail() {
|
||||
echo "M9 dwarf-ranges: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -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 (set M7COFF=...)"
|
||||
[ -f "$ELF_WRAP" ] || fail "missing ELF wrapper: $ELF_WRAP"
|
||||
[ -f "$FIXTURE" ] || fail "missing range-list fixture: $FIXTURE"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
WORK=$(cd "$WORK" && pwd)
|
||||
|
||||
echo "== write the two .debug_rnglists TUs"
|
||||
python3 "$FIXTURE" "$WORK" \
|
||||
|| fail "could not write the .debug_rnglists fixture objects"
|
||||
|
||||
echo "== link --keep-debug, single-TU keep, and the default strip"
|
||||
"$TMS_LINK" -o "$WORK/keep.coff" --keep-debug --entry _rng_a \
|
||||
--text 018A0000 "$WORK/rng-a.o" "$WORK/rng-b.o" \
|
||||
|| fail "tms-link --keep-debug failed"
|
||||
"$TMS_LINK" -o "$WORK/single.coff" --keep-debug --entry _rng_a \
|
||||
--text 018A0000 "$WORK/rng-a.o" \
|
||||
|| fail "tms-link --keep-debug (single TU) failed"
|
||||
"$TMS_LINK" -o "$WORK/strip.coff" --entry _rng_a \
|
||||
--text 018A0000 "$WORK/rng-a.o" "$WORK/rng-b.o" \
|
||||
|| fail "tms-link (strip) failed"
|
||||
|
||||
echo "== inspect the merged range/address sections and single-TU bytes"
|
||||
python3 - "$M7COFF" "$WORK/rng-a.o" "$WORK/rng-b.o" "$WORK/keep.coff" \
|
||||
"$WORK/single.coff" "$WORK/strip.coff" "$WORK/ranges.env" <<'PY' \
|
||||
|| fail "merged .debug_rnglists/.debug_addr layout is wrong"
|
||||
import os
|
||||
import struct
|
||||
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, single_path, strip_path, env_path = sys.argv[2:8]
|
||||
a = m7coff.parse(a_path)
|
||||
b = m7coff.parse(b_path)
|
||||
keep = m7coff.parse(keep_path)
|
||||
single = m7coff.parse(single_path)
|
||||
strip = m7coff.parse(strip_path)
|
||||
|
||||
names = [s["name"] for s in keep["sections"]]
|
||||
want = [".text", ".data", ".bss", ".debug_abbrev", ".debug_info",
|
||||
".debug_str", ".debug_addr", ".debug_rnglists"]
|
||||
if names != want:
|
||||
sys.exit("kept image sections %r, want %r" % (names, want))
|
||||
for sec in keep["sections"]:
|
||||
if sec["nreloc"]:
|
||||
sys.exit("%s still has %d relocation(s)"
|
||||
% (sec["name"], sec["nreloc"]))
|
||||
if sec["name"].startswith(".debug_"):
|
||||
if (sec["paddr"], sec["vaddr"], sec["flags"]) != (0, 0, 0):
|
||||
sys.exit("%s paddr/vaddr/flags %#x/%#x/%#x, want 0/0/0"
|
||||
% (sec["name"], sec["paddr"], sec["vaddr"], sec["flags"]))
|
||||
|
||||
def raw(coff, name):
|
||||
return m7coff.section(coff, name)["raw"]
|
||||
|
||||
a_info, b_info = raw(a, ".debug_info"), raw(b, ".debug_info")
|
||||
a_abbrev = raw(a, ".debug_abbrev")
|
||||
a_addr, b_addr = raw(a, ".debug_addr"), raw(b, ".debug_addr")
|
||||
a_rng, b_rng = raw(a, ".debug_rnglists"), raw(b, ".debug_rnglists")
|
||||
a_str, b_str = raw(a, ".debug_str"), raw(b, ".debug_str")
|
||||
|
||||
for name, parts in ((".debug_info", (a_info, b_info)),
|
||||
(".debug_str", (a_str, b_str)),
|
||||
(".debug_addr", (a_addr, b_addr)),
|
||||
(".debug_rnglists", (a_rng, b_rng)),
|
||||
(".debug_abbrev", (a_abbrev, raw(b, ".debug_abbrev")))):
|
||||
got = raw(keep, name)
|
||||
concat = b"".join(parts)
|
||||
if len(got) != len(concat):
|
||||
sys.exit("%s merged size %d bytes, want %d"
|
||||
% (name, len(got), len(concat)))
|
||||
if len(got) * 8 != m7coff.section(keep, name)["size"]:
|
||||
sys.exit("%s merged size does not match its bytes" % name)
|
||||
skip = set()
|
||||
base = 0
|
||||
for src in (a, b):
|
||||
for raddr, _symidx, _rtype in m7coff.section(src, name)["relocs"]:
|
||||
field = base + raddr // 8
|
||||
skip.update(range(field, field + 4))
|
||||
base += len(m7coff.section(src, name)["raw"])
|
||||
diff = [i for i in range(len(concat))
|
||||
if concat[i] != got[i] and i not in skip]
|
||||
if diff:
|
||||
sys.exit("%s differs from the object-order concatenation outside "
|
||||
"relocation fields at %r" % (name, diff[:8]))
|
||||
|
||||
text = m7coff.section(keep, ".text")
|
||||
origin = text["paddr"] // 8
|
||||
if origin != 0x314000:
|
||||
sys.exit("text origin byte address %#x, want 0x314000" % origin)
|
||||
if text["size"] != len(a["sections"][0]["raw"]) * 8 * 2:
|
||||
sys.exit(".text merged size %d bits" % text["size"])
|
||||
|
||||
def u32(data, off):
|
||||
return struct.unpack_from("<I", data, off)[0]
|
||||
|
||||
# Every range/address this fixture emits, by merged contribution. The second
|
||||
# TU's .text contribution starts 16 bytes into the merged section.
|
||||
base_a, base_b = origin, origin + len(raw(a, ".text"))
|
||||
|
||||
# First .debug_rnglists unit: start_end addresses, then a startx_length index.
|
||||
if u32(raw(keep, ".debug_rnglists"), 17) != base_a:
|
||||
sys.exit("first range-list start %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_rnglists"), 17), base_a))
|
||||
if u32(raw(keep, ".debug_rnglists"), 21) != base_a + 4:
|
||||
sys.exit("first range-list end %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_rnglists"), 21), base_a + 4))
|
||||
if u32(raw(keep, ".debug_addr"), 8) != base_a + 8:
|
||||
sys.exit("first addr[0] %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_addr"), 8), base_a + 8))
|
||||
if u32(raw(keep, ".debug_addr"), 12) != base_a + 12:
|
||||
sys.exit("first addr[1] %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_addr"), 12), base_a + 12))
|
||||
|
||||
# Second .debug_rnglists/.debug_addr units are rehomed past the first
|
||||
# object's whole contributions; their address fields are the linked B .text.
|
||||
rng_base_b = len(a_rng) + 12
|
||||
addr_base_b = len(a_addr) + 8
|
||||
if u32(raw(keep, ".debug_rnglists"), len(a_rng) + 17) != base_b:
|
||||
sys.exit("second range-list start %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_rnglists"), len(a_rng) + 17), base_b))
|
||||
if u32(raw(keep, ".debug_rnglists"), len(a_rng) + 21) != base_b + 4:
|
||||
sys.exit("second range-list end %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_rnglists"), len(a_rng) + 21),
|
||||
base_b + 4))
|
||||
if u32(raw(keep, ".debug_addr"), len(a_addr) + 8) != base_b + 8:
|
||||
sys.exit("second addr[0] %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_addr"), len(a_addr) + 8), base_b + 8))
|
||||
if u32(raw(keep, ".debug_addr"), len(a_addr) + 12) != base_b + 12:
|
||||
sys.exit("second addr[1] %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_addr"), len(a_addr) + 12), base_b + 12))
|
||||
|
||||
# Second CU header/root DIE: abbrev offset, strp names, addr_base and
|
||||
# rnglists_base are rehomed; the rnglistx index stays 0.
|
||||
info_b = len(a_info)
|
||||
if info_b != 40:
|
||||
sys.exit("first CU contribution %d bytes, want 40" % info_b)
|
||||
if struct.unpack_from("<I", raw(keep, ".debug_info"), info_b)[0] != \
|
||||
len(b_info) - 4:
|
||||
sys.exit("second CU unit length is wrong")
|
||||
if u32(raw(keep, ".debug_info"), info_b + 8) != len(a_abbrev):
|
||||
sys.exit("second CU abbrev offset %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_info"), info_b + 8), len(a_abbrev)))
|
||||
if u32(raw(keep, ".debug_info"), info_b + 13) != len(a_str):
|
||||
sys.exit("second CU name strp %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_info"), info_b + 13), len(a_str)))
|
||||
if u32(raw(keep, ".debug_info"), info_b + 17) != addr_base_b:
|
||||
sys.exit("second CU addr_base %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_info"), info_b + 17), addr_base_b))
|
||||
if u32(raw(keep, ".debug_info"), info_b + 21) != rng_base_b:
|
||||
sys.exit("second CU rnglists_base %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_info"), info_b + 21), rng_base_b))
|
||||
if raw(keep, ".debug_info")[info_b + 25] != 0:
|
||||
sys.exit("second CU DW_AT_ranges index is not 0")
|
||||
if u32(raw(keep, ".debug_info"), info_b + 31) != base_b:
|
||||
sys.exit("second CU subprogram low_pc %#x, want %#x"
|
||||
% (u32(raw(keep, ".debug_info"), info_b + 31), base_b))
|
||||
|
||||
# First CU's bases are unchanged from the object (single-TU/M8 layout); only
|
||||
# its absolute low PC becomes the linked text address.
|
||||
info_a = raw(keep, ".debug_info")
|
||||
if (u32(info_a, 8), u32(info_a, 13), u32(info_a, 17), u32(info_a, 21)) != \
|
||||
(0, 0, 8, 12):
|
||||
sys.exit("first CU bases are not (0, 0, 8, 12)")
|
||||
if u32(info_a, 31) != base_a:
|
||||
sys.exit("first CU subprogram low_pc %#x, want %#x"
|
||||
% (u32(info_a, 31), base_a))
|
||||
|
||||
# The single-object link must reproduce the M8 single-TU byte layout: every
|
||||
# debug section equals the input with only its relocation fields rewritten to
|
||||
# "target section base + addend" (bases are 0 for a single object).
|
||||
def expected_single(sec):
|
||||
out = bytearray(sec["raw"])
|
||||
by_record = {sym["index"]: sym for sym in a["symbols"]}
|
||||
for raddr, symidx, _rtype in sec["relocs"]:
|
||||
sym = by_record[symidx]
|
||||
target = a["sections"][sym["secno"] - 1]
|
||||
addend = struct.unpack_from("<i", out, raddr // 8)[0]
|
||||
base = 0 if target["name"].startswith(".debug_") else origin
|
||||
struct.pack_into("<I", out, raddr // 8, base + addend)
|
||||
return bytes(out)
|
||||
|
||||
single_names = [s["name"] for s in single["sections"]]
|
||||
if single_names != want:
|
||||
sys.exit("single-TU keep sections %r" % single_names)
|
||||
for name in (".debug_abbrev", ".debug_info", ".debug_str", ".debug_addr",
|
||||
".debug_rnglists"):
|
||||
want_bytes = expected_single(m7coff.section(a, name))
|
||||
got = raw(single, name)
|
||||
if got != want_bytes:
|
||||
sys.exit("single-TU %s bytes differ from the M8 layout" % name)
|
||||
|
||||
# Default strip: exactly the allocated sections, same bytes as keep.
|
||||
if [s["name"] for s in strip["sections"]] != [".text", ".data", ".bss"]:
|
||||
sys.exit("default strip has sections %r"
|
||||
% [s["name"] for s in strip["sections"]])
|
||||
for kept, stripped in zip(keep["sections"][:3], strip["sections"]):
|
||||
if (kept["paddr"], kept["size"], kept["flags"]) != \
|
||||
(stripped["paddr"], stripped["size"], stripped["flags"]):
|
||||
sys.exit("%s keep/strip layout differs" % kept["name"])
|
||||
if kept["name"] != ".bss" and kept["raw"] != stripped["raw"]:
|
||||
sys.exit("%s keep/strip bytes differ" % kept["name"])
|
||||
|
||||
with open(env_path, "w", encoding="ascii") as fh:
|
||||
fh.write("A_RNGLISTS_BITS=%d\n" % (len(a_rng) * 8))
|
||||
fh.write("B_RNGLISTS_BASE=%d\n" % rng_base_b)
|
||||
fh.write("B_ADDR_BASE=%d\n" % addr_base_b)
|
||||
fh.write("TEXT_ORIGIN=%d\n" % origin)
|
||||
print(" merged: .debug_info=%dB .debug_addr=%dB .debug_rnglists=%dB"
|
||||
% (len(raw(keep, ".debug_info")), len(raw(keep, ".debug_addr")),
|
||||
len(raw(keep, ".debug_rnglists"))))
|
||||
print(" second CU: abbrev=%d strp=%d addr_base=%#x rnglists_base=%#x"
|
||||
% (len(a_abbrev), len(a_str), addr_base_b, rng_base_b))
|
||||
print(" ranges: A [%#x,%#x) [%#x,%#x), B [%#x,%#x) [%#x,%#x)"
|
||||
% (base_a, base_a + 4, base_a + 8, base_a + 12,
|
||||
base_b, base_b + 4, base_b + 8, base_b + 12))
|
||||
print(" single TU: M8 byte layout reproduced; strip: .text/.data/.bss")
|
||||
PY
|
||||
|
||||
. "$WORK/ranges.env"
|
||||
|
||||
echo "== wrap the kept .debug_* sections in the M7 ELF32 container"
|
||||
"$ELF_WRAP" -o "$WORK/keep.elf" "$WORK/keep.coff" \
|
||||
|| fail "elf-debug-wrap failed"
|
||||
"$ELF_WRAP" -o "$WORK/single.elf" "$WORK/single.coff" >/dev/null \
|
||||
|| fail "elf-debug-wrap failed for the single-TU link"
|
||||
|
||||
echo "== llvm-dwarfdump: both TUs' ranges and address tables"
|
||||
"$DWARFDUMP" --debug-info --debug-rnglists --debug-addr "$WORK/keep.elf" \
|
||||
> "$WORK/dwarf.txt" 2> "$WORK/dwarf.err" \
|
||||
|| { cat "$WORK/dwarf.err" >&2; \
|
||||
fail "llvm-dwarfdump failed on the merged range lists"; }
|
||||
if grep -qi 'error' "$WORK/dwarf.err"; then
|
||||
cat "$WORK/dwarf.err" >&2
|
||||
fail "llvm-dwarfdump reported an error"
|
||||
fi
|
||||
|
||||
python3 - "$WORK/dwarf.txt" "$TEXT_ORIGIN" <<'PY' \
|
||||
|| fail "merged DWARF range/address content is wrong"
|
||||
import re
|
||||
import sys
|
||||
|
||||
text = open(sys.argv[1], encoding="latin1").read()
|
||||
origin = int(sys.argv[2])
|
||||
base_a = origin
|
||||
base_b = origin + 16
|
||||
|
||||
# Parse the CUs from the .debug_info dump only; the raw .debug_rnglists dump
|
||||
# later in the file also prints ranges, without a CU context.
|
||||
info_part = text.split(".debug_rnglists contents:")[0]
|
||||
blocks = info_part.split("Compile Unit:")[1:]
|
||||
if len(blocks) != 2:
|
||||
sys.exit("saw %d compile units, want 2" % len(blocks))
|
||||
cu_names = []
|
||||
for block in blocks:
|
||||
m = re.search(r'DW_AT_name\t\("([^"]+)"\)', block)
|
||||
if not m:
|
||||
sys.exit("a compile unit has no DW_AT_name")
|
||||
cu_names.append(m.group(1))
|
||||
if cu_names != ["rng-a.c", "rng-b.c"]:
|
||||
sys.exit("compile unit names %r, want ['rng-a.c', 'rng-b.c']" % cu_names)
|
||||
|
||||
def ranges(block):
|
||||
return [(int(a, 16), int(b, 16))
|
||||
for a, b in re.findall(r"\[0x([0-9a-fA-F]+), 0x([0-9a-fA-F]+)\)",
|
||||
block)]
|
||||
|
||||
want = {
|
||||
"rng-a.c": [(base_a, base_a + 4), (base_a + 8, base_a + 12)],
|
||||
"rng-b.c": [(base_b, base_b + 4), (base_b + 8, base_b + 12)],
|
||||
}
|
||||
for block in blocks:
|
||||
name = re.search(r'DW_AT_name\t\("([^"]+)"\)', block).group(1)
|
||||
got = ranges(block)
|
||||
if got != want[name]:
|
||||
sys.exit("%s ranges %r, want %r"
|
||||
% (name, [(hex(a), hex(b)) for a, b in got],
|
||||
[(hex(a), hex(b)) for a, b in want[name]]))
|
||||
m = re.search(r"DW_AT_rnglists_base\t\(0x([0-9a-fA-F]+)\)", block)
|
||||
if not m:
|
||||
sys.exit("%s has no DW_AT_rnglists_base" % name)
|
||||
if name == "rng-a.c" and int(m.group(1), 16) != 12:
|
||||
sys.exit("first CU rnglists_base %s, want 0xc" % m.group(1))
|
||||
if name == "rng-b.c":
|
||||
# The second TU's base must sit past the first contribution + header.
|
||||
if int(m.group(1), 16) <= 12:
|
||||
sys.exit("second CU rnglists_base was not rehomed: %s"
|
||||
% m.group(1))
|
||||
|
||||
addr_part = text.split(".debug_addr contents:")[1].split(
|
||||
".debug_rnglists contents:")[0]
|
||||
addr_entries = [int(v, 16) for v in
|
||||
re.findall(r"^0x([0-9a-fA-F]{8})$", addr_part,
|
||||
re.MULTILINE)]
|
||||
if addr_entries != [base_a + 8, base_a + 12, base_b + 8, base_b + 12]:
|
||||
sys.exit("address table entries %r, want %r"
|
||||
% ([hex(v) for v in addr_entries],
|
||||
[hex(v) for v in (base_a + 8, base_a + 12,
|
||||
base_b + 8, base_b + 12)]))
|
||||
if text.count("range list header:") != 2:
|
||||
sys.exit("saw %d range-list units, want 2"
|
||||
% text.count("range list header:"))
|
||||
if text.count("<End of list>") != 2:
|
||||
sys.exit("range lists did not terminate cleanly")
|
||||
print(" dwarfdump: rng-a.c [%#x,%#x) [%#x,%#x), rng-b.c [%#x,%#x) "
|
||||
"[%#x,%#x)" % (base_a, base_a + 4, base_a + 8, base_a + 12,
|
||||
base_b, base_b + 4, base_b + 8, base_b + 12))
|
||||
print(" dwarfdump: two range-list units, address table %r"
|
||||
% [hex(v) for v in addr_entries])
|
||||
PY
|
||||
|
||||
echo "== llvm-dwarfdump: single-TU range list"
|
||||
"$DWARFDUMP" --debug-info --debug-rnglists --debug-addr "$WORK/single.elf" \
|
||||
> "$WORK/single.txt" 2> "$WORK/single.err" \
|
||||
|| { cat "$WORK/single.err" >&2; \
|
||||
fail "llvm-dwarfdump failed on the single-TU range list"; }
|
||||
python3 - "$WORK/single.txt" "$TEXT_ORIGIN" <<'PY' \
|
||||
|| fail "single-TU range list is wrong"
|
||||
import re
|
||||
import sys
|
||||
|
||||
text = open(sys.argv[1], encoding="latin1").read()
|
||||
origin = int(sys.argv[2])
|
||||
if text.count("Compile Unit:") != 1:
|
||||
sys.exit("single-TU link has %d compile units"
|
||||
% text.count("Compile Unit:"))
|
||||
for want in ("[0x%08x, 0x%08x)" % (origin, origin + 4),
|
||||
"[0x%08x, 0x%08x)" % (origin + 8, origin + 12)):
|
||||
if want not in text:
|
||||
sys.exit("single-TU range list lacks %s" % want)
|
||||
m = re.search(r"DW_AT_rnglists_base\t\(0x([0-9a-fA-F]+)\)", text)
|
||||
if not m or int(m.group(1), 16) != 12:
|
||||
sys.exit("single-TU rnglists_base %r, want 0xc"
|
||||
% (m.group(1) if m else None))
|
||||
print(" dwarfdump: one CU, ranges [%#x,%#x) [%#x,%#x), base 0xc"
|
||||
% (origin, origin + 4, origin + 8, origin + 12))
|
||||
PY
|
||||
|
||||
echo "== real producer: -O2 -g loop/inline shapes emit .debug_rnglists"
|
||||
if [ -x "$TMS_CLANG" ] && [ -x "$TMS_LLC" ]; then
|
||||
for tu in a b; do
|
||||
( cd "$ROOT/scripts/m9" \
|
||||
&& "$TMS_CLANG" -g -O2 -o "$WORK/ranges-$tu.ll" \
|
||||
"dwarf-ranges-$tu.c" ) \
|
||||
|| fail "tms-clang -g -O2 failed for dwarf-ranges-$tu.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$WORK/ranges-$tu.ll" -o "$WORK/ranges-$tu.o" \
|
||||
|| fail "llc -filetype=obj failed for ranges-$tu"
|
||||
done
|
||||
rc=0
|
||||
python3 - "$M7COFF" "$WORK/ranges-a.o" "$WORK/ranges-b.o" <<'PY' \
|
||||
|| rc=$?
|
||||
import os
|
||||
import sys
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(sys.argv[1]))
|
||||
import m7coff # noqa: E402
|
||||
missing = []
|
||||
for path in sys.argv[2:]:
|
||||
names = [s["name"] for s in m7coff.parse(path)["sections"]]
|
||||
for want in (".debug_rnglists", ".debug_loclists", ".debug_addr",
|
||||
".debug_info"):
|
||||
if want not in names:
|
||||
missing.append("%s:%s" % (os.path.basename(path), want))
|
||||
if missing:
|
||||
print(" missing producer sections: " + " ".join(missing))
|
||||
sys.exit(3)
|
||||
print(" both TUs emit .debug_rnglists and .debug_loclists")
|
||||
PY
|
||||
if [ "$rc" -eq 3 ]; then
|
||||
echo " SKIP: this producer emitted no .debug_rnglists for the shape"
|
||||
elif [ "$rc" -ne 0 ]; then
|
||||
fail "could not read/parse the real-producer objects (rc=$rc)"
|
||||
else
|
||||
"$TMS_LINK" -o "$WORK/real-keep.coff" --keep-debug --entry _m9_range_one \
|
||||
--text 018A0000 "$WORK/ranges-a.o" "$WORK/ranges-b.o" \
|
||||
|| fail "tms-link --keep-debug failed for the real producer objects"
|
||||
"$ELF_WRAP" -o "$WORK/real.elf" "$WORK/real-keep.coff" >/dev/null \
|
||||
|| fail "elf-debug-wrap failed for the real producer link"
|
||||
"$DWARFDUMP" --debug-info --debug-rnglists --debug-loclists \
|
||||
"$WORK/real.elf" > "$WORK/real.txt" 2> "$WORK/real.err" \
|
||||
|| { cat "$WORK/real.err" >&2; \
|
||||
fail "llvm-dwarfdump failed on the real producer range lists"; }
|
||||
if grep -qi 'error' "$WORK/real.err"; then
|
||||
cat "$WORK/real.err" >&2
|
||||
fail "llvm-dwarfdump reported an error for the real producer"
|
||||
fi
|
||||
python3 - "$M7COFF" "$WORK/real-keep.coff" "$WORK/real.txt" <<'PY' \
|
||||
|| fail "real-producer range lists did not merge correctly"
|
||||
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
|
||||
|
||||
coff = m7coff.parse(sys.argv[2])
|
||||
text = m7coff.section(coff, ".text")
|
||||
lo, hi = text["paddr"] // 8, (text["paddr"] + text["size"]) // 8
|
||||
text_info = open(sys.argv[3], encoding="latin1").read()
|
||||
info_part = text_info.split(".debug_rnglists contents:")[0]
|
||||
blocks = info_part.split("Compile Unit:")[1:]
|
||||
if len(blocks) != 2:
|
||||
sys.exit("saw %d compile units, want 2" % len(blocks))
|
||||
names = []
|
||||
for block in blocks:
|
||||
m = re.search(r'DW_AT_name\t\("([^"]+)"\)', block)
|
||||
if not m:
|
||||
sys.exit("a real-producer CU has no name")
|
||||
names.append(m.group(1))
|
||||
if names != ["dwarf-ranges-a.c", "dwarf-ranges-b.c"]:
|
||||
sys.exit("real-producer CU names %r" % names)
|
||||
for block, name in zip(blocks, names):
|
||||
if not re.search(r"DW_AT_ranges\t\(indexed .*rangelist = 0x",
|
||||
block):
|
||||
sys.exit("%s has no resolved DW_AT_ranges" % name)
|
||||
ranges = [(int(a, 16), int(b, 16))
|
||||
for a, b in re.findall(
|
||||
r"\[0x([0-9a-fA-F]+), 0x([0-9a-fA-F]+)\)", block)]
|
||||
if not ranges:
|
||||
sys.exit("%s has no range entries" % name)
|
||||
for start, end in ranges:
|
||||
if not (lo <= start < end <= hi):
|
||||
sys.exit("%s range [%#x, %#x) is outside the linked .text "
|
||||
"[%#x, %#x)" % (name, start, end, lo, hi))
|
||||
m = re.search(r"DW_AT_rnglists_base\t\(0x([0-9a-fA-F]+)\)", block)
|
||||
if not m:
|
||||
sys.exit("%s has no DW_AT_rnglists_base" % name)
|
||||
base = int(m.group(1), 16)
|
||||
if name == "dwarf-ranges-b.c" and base <= 0x0C:
|
||||
sys.exit("second real-producer CU rnglists_base was not rehomed: %#x"
|
||||
% base)
|
||||
if ".debug_loclists" in text_info:
|
||||
m = re.search(r"DW_AT_loclists_base\t\(0x([0-9a-fA-F]+)\)", block)
|
||||
if not m:
|
||||
sys.exit("%s has no DW_AT_loclists_base" % name)
|
||||
if name == "dwarf-ranges-b.c" and int(m.group(1), 16) <= 0x0C:
|
||||
sys.exit("second real-producer CU loclists_base was not rehomed")
|
||||
if text_info.count("range list header:") < 2:
|
||||
sys.exit("the real-producer link has %d range-list units, want >= 2"
|
||||
% text_info.count("range list header:"))
|
||||
print(" real producer: 2 CUs, ranges inside [%#x, %#x), rnglists/loclists "
|
||||
"bases rehomed" % (lo, hi))
|
||||
PY
|
||||
fi
|
||||
else
|
||||
echo " SKIP: no tms-clang/llc ($TMS_CLANG, $TMS_LLC)"
|
||||
fi
|
||||
|
||||
echo "M9 dwarf-ranges: PASS (two TUs' .debug_rnglists units concatenated with"
|
||||
echo " rehomed rnglists/addr bases, dwarfdump resolves every"
|
||||
echo " TU's ranges and address entries, single-TU bytes keep"
|
||||
echo " the M8 layout, and the default strip is unchanged)"
|
||||
Executable
+249
@@ -0,0 +1,249 @@
|
||||
#!/usr/bin/env python3
|
||||
"""tms-cc -- a small C driver for the TMS34010 toolchain.
|
||||
|
||||
This is the Phase 1 usability driver: it hides the bit-address IR barrier,
|
||||
llc, the OS/2/GSPA entry assembly and tms-link behind a conventional
|
||||
compile/link interface.
|
||||
|
||||
tms-cc hello.c -o hello.coff # link with the conformance shim + entry
|
||||
tms-cc -c hello.c -o hello.o # relocatable TI-COFF object
|
||||
tms-cc -S hello.c -o hello.s # GSPA assembly
|
||||
|
||||
The default link uses the freestanding conformance shim (printf/sprintf/
|
||||
malloc/free/string) and its entry, so `tms-run hello.coff` can display the
|
||||
output. `-nostdlib` omits the shim; `-l NAME`/`-L DIR` add SDK archives.
|
||||
The compiler pipeline itself remains `scripts/tms-clang` + `llc`; GSPLNK is
|
||||
still the byte/symbol oracle for the gates.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
TMS_CLANG = ROOT / "scripts/tms-clang"
|
||||
LLC = Path(os.environ.get("TMS_LLC", ROOT / "build/llvm-clean-build/bin/llc"))
|
||||
RUN_SH = ROOT / "scripts/m4/run.sh"
|
||||
CONF = ROOT / "scripts/tests/m5/conformance"
|
||||
ENTRY = CONF / "entry.asm"
|
||||
SDK = ROOT / "sdk"
|
||||
SHIM = SDK / "shim.c"
|
||||
HEAP = SDK / "heap.c"
|
||||
INCLUDE = SDK / "include"
|
||||
TMS_LINK = ROOT / "tools/tms-link/tms-link"
|
||||
|
||||
|
||||
def fail(msg: str, code: int = 1):
|
||||
print(f"tms-cc: error: {msg}", file=sys.stderr)
|
||||
raise SystemExit(code)
|
||||
|
||||
|
||||
def tool(path: Path) -> Path:
|
||||
if not path.is_file():
|
||||
fail(f"missing tool: {path}")
|
||||
return path
|
||||
|
||||
|
||||
def opt_level(args) -> str:
|
||||
if args.O0:
|
||||
return "-O0"
|
||||
if args.opt in ("0",):
|
||||
return "-O0"
|
||||
return "-O2"
|
||||
|
||||
|
||||
def compile_ir(src: Path, dst: Path, opt: str, args):
|
||||
cmd = [str(TMS_CLANG), opt]
|
||||
if args.g:
|
||||
cmd.append("-g")
|
||||
for inc in [str(INCLUDE)] + list(args.includes):
|
||||
cmd += ["-I", inc]
|
||||
cmd += ["-o", str(dst), str(src)]
|
||||
if args.verbose:
|
||||
print("+", " ".join(cmd), file=sys.stderr)
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
|
||||
def llc_obj(ir: Path, dst: Path, args):
|
||||
cmd = [str(LLC), "-march=tms34010", "-O0", "-filetype=obj",
|
||||
str(ir), "-o", str(dst)]
|
||||
if args.verbose:
|
||||
print("+", " ".join(cmd), file=sys.stderr)
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
|
||||
def llc_asm(ir: Path, dst: Path, args):
|
||||
cmd = [str(LLC), "-march=tms34010", "-O0", "-filetype=asm",
|
||||
str(ir), "-o", str(dst)]
|
||||
if args.verbose:
|
||||
print("+", " ".join(cmd), file=sys.stderr)
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
|
||||
def resolve_lib(name: str, dirs: list[Path]) -> Path:
|
||||
candidates = []
|
||||
for d in dirs:
|
||||
for fmt in (f"{name}", f"lib{name}.a", f"{name}.lib",
|
||||
f"{name}.LIB", f"lib{name}.lib"):
|
||||
candidates.append(d / fmt)
|
||||
base = Path(name)
|
||||
if base.is_file():
|
||||
return base.resolve()
|
||||
for c in candidates:
|
||||
if c.is_file():
|
||||
return c.resolve()
|
||||
# Default SDK archives.
|
||||
for d in (ROOT / "build/m6-sdk", ROOT / "build/m4-sdk"):
|
||||
for fmt in (f"{name}", f"{name}.lib", f"{name}.LIB",
|
||||
f"lib{name}.a", f"lib{name}.lib"):
|
||||
c = d / fmt
|
||||
if c.is_file():
|
||||
return c.resolve()
|
||||
fail(f"cannot resolve library '{name}' (use -L DIR)")
|
||||
|
||||
|
||||
def link_mode(sources: list[Path], out: Path, args):
|
||||
work = Path(tempfile.mkdtemp(prefix="tms-cc-"))
|
||||
try:
|
||||
copied = []
|
||||
for i, src in enumerate(sources):
|
||||
dst = work / f"c{i}.c"
|
||||
shutil.copyfile(src, dst)
|
||||
copied.append(dst)
|
||||
if not args.nostdlib:
|
||||
copied += [SHIM, HEAP]
|
||||
# Including the source directories preserves quoted headers.
|
||||
incs = ["-I", str(INCLUDE)]
|
||||
for d in sorted({str(s.parent) for s in sources} | set(args.includes)):
|
||||
if d not in incs:
|
||||
incs += ["-I", d]
|
||||
libs = [str(resolve_lib(n, [Path(x) for x in args.libdirs]))
|
||||
for n in args.libs]
|
||||
if not args.nostdlib:
|
||||
# The shim's %f path references flib's FD$* entries; link the SDK
|
||||
# runtimes by default, as the conformance harness does.
|
||||
for default in (ROOT / "build/m6-sdk/flib.lib",
|
||||
ROOT / "build/m6-sdk/rts.lib"):
|
||||
if default.is_file():
|
||||
libs.append(str(default))
|
||||
env = dict(os.environ)
|
||||
env.update({
|
||||
"M4_WORK": str(work),
|
||||
"M4_SDK": os.environ.get("M4_SDK", str(ROOT / "build/m4-sdk")),
|
||||
"M4_COFF": str(out),
|
||||
"M4_SOURCES": " ".join(str(s) for s in copied),
|
||||
"M4_ENTRY": str(ENTRY),
|
||||
"M4_NATIVE": "1",
|
||||
"M4_LINKER": "tms-link",
|
||||
"M4_SKIP_MAME": "1",
|
||||
"M4_CLANG_OPT": opt_level(args),
|
||||
"M4_LLC_OPT": "-O0",
|
||||
"M4_EXTRA_INCLUDES": " ".join(incs),
|
||||
"M4_NATIVE_PROG_LEN": args.prog_len,
|
||||
"M4_NATIVE_RAM_LEN": args.ram_len,
|
||||
})
|
||||
if args.g:
|
||||
env["M4_EXTRA_CFLAGS"] = "-g"
|
||||
if libs:
|
||||
env["M4_NATIVE_LIBS"] = " ".join(libs)
|
||||
# Prefer the direct 2ine assembler; fall back to DOSBox.
|
||||
lx = Path(os.environ.get(
|
||||
"M4_OS2_LX", Path.home() / "os2-work/2ine-tms34010/build/lx_loader"))
|
||||
if lx.is_file():
|
||||
env["M4_OS2"] = "1"
|
||||
env["M4_OS2_LX"] = str(lx)
|
||||
else:
|
||||
env["M4_OS2"] = "0"
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [str(RUN_SH)]
|
||||
if args.verbose:
|
||||
print("+", " ".join(cmd), file=sys.stderr)
|
||||
r = subprocess.run(cmd, env=env)
|
||||
if r.returncode != 0:
|
||||
fail("link failed", r.returncode)
|
||||
# Keep a map next to the image.
|
||||
map_src = work / "m4.map"
|
||||
map_dst = Path(args.map) if args.map else out.with_suffix(".map")
|
||||
if map_src.is_file():
|
||||
shutil.copyfile(map_src, map_dst)
|
||||
if args.run:
|
||||
subprocess.run([str(ROOT / "scripts/tms-run"), str(out)], check=False)
|
||||
finally:
|
||||
if not args.keep:
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
|
||||
|
||||
def main(argv):
|
||||
ap = argparse.ArgumentParser(
|
||||
prog="tms-cc", description="Compile/link C for the TMS34010/VT1200 "
|
||||
"(freestanding; the conformance shim is the default runtime).")
|
||||
ap.add_argument("sources", nargs="+", help=".c source files")
|
||||
ap.add_argument("-o", "--output", help="output file")
|
||||
ap.add_argument("-c", action="store_true", help="compile to TI-COFF objects")
|
||||
ap.add_argument("-S", action="store_true", help="compile to GSPA assembly")
|
||||
ap.add_argument("-O0", dest="O0", action="store_true")
|
||||
ap.add_argument("-O", dest="opt", default="2")
|
||||
ap.add_argument("-g", action="store_true")
|
||||
ap.add_argument("-I", dest="includes", action="append", default=[])
|
||||
ap.add_argument("-L", dest="libdirs", action="append", default=[])
|
||||
ap.add_argument("-l", dest="libs", action="append", default=[])
|
||||
ap.add_argument("-nostdlib", action="store_true",
|
||||
help="omit the shim/heap (user provides all symbols)")
|
||||
ap.add_argument("--text", default="018A0000")
|
||||
ap.add_argument("--bss", default="01A00000")
|
||||
ap.add_argument("--prog-len", default="40000h")
|
||||
ap.add_argument("--ram-len", default="80000h")
|
||||
ap.add_argument("--map", help="map output path")
|
||||
ap.add_argument("--run", action="store_true", help="run with tms-run")
|
||||
ap.add_argument("-v", "--verbose", action="store_true")
|
||||
ap.add_argument("--keep", action="store_true", help="keep the work directory")
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
sources = [Path(s) for s in args.sources]
|
||||
for s in sources:
|
||||
if not s.is_file():
|
||||
fail(f"source not found: {s}")
|
||||
if s.suffix not in (".c", ".C"):
|
||||
fail(f"not a C source: {s}")
|
||||
|
||||
if args.c or args.S:
|
||||
if args.output and len(sources) > 1:
|
||||
outdir = Path(args.output)
|
||||
if not outdir.is_dir():
|
||||
fail("-o with multiple sources must be a directory")
|
||||
for src in sources:
|
||||
ext = ".o" if args.c else ".s"
|
||||
if args.output and len(sources) == 1:
|
||||
dst = Path(args.output)
|
||||
elif args.output:
|
||||
dst = Path(args.output) / (src.stem + ext)
|
||||
else:
|
||||
dst = src.with_suffix(ext)
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix="tms-cc-") as td:
|
||||
ir = Path(td) / "unit.ll"
|
||||
compile_ir(src, ir, opt_level(args), args)
|
||||
(llc_obj if args.c else llc_asm)(ir, dst, args)
|
||||
if args.verbose:
|
||||
print(dst)
|
||||
return 0
|
||||
|
||||
if not TMS_LINK.is_file():
|
||||
fail(f"missing linker: {TMS_LINK}")
|
||||
if not ENTRY.is_file() or not SHIM.is_file():
|
||||
fail("missing conformance runtime files")
|
||||
out = Path(args.output or "a.coff")
|
||||
link_mode(sources, out, args)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise SystemExit(e.returncode)
|
||||
+29
-135
@@ -1,61 +1,44 @@
|
||||
#!/bin/sh
|
||||
# tms-clang -- C IR pipeline: clang IR, the --bitptr semantic barrier, optimize,
|
||||
# scale the late byte-indexed GEPs, lower the barrier, and restore the M0
|
||||
# pointer-difference folding.
|
||||
# tms-clang -- thin flag mapper onto the fork's clang driver.
|
||||
#
|
||||
# Usage: tms-clang [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c
|
||||
#
|
||||
# -O0: clang IR -> --bitptr -> --lower-bitptr -> OUT (bit-addressed).
|
||||
# -O2 (the default): clang IR -> --bitptr -> opt -> --scale -> --lower-bitptr
|
||||
# -> opt -passes=instcombine -> OUT.
|
||||
# The TMS34010 ToolChain now supplies this target's compile defaults
|
||||
# (`-ffreestanding`, `-fno-builtin`, no system includes,
|
||||
# `-mllvm -replexitval=never`, `-disable-O0-optnone`), and the bit-pointer
|
||||
# barrier / lowering pipeline runs inside clang's own pipeline (guarded by the
|
||||
# `"tms.bitaddr"` module flag), so this script no longer drives `tms-bitaddr`
|
||||
# or `opt`. It maps its historical CLI onto a single clang invocation:
|
||||
#
|
||||
# -g passes clang -g through to the IR; the barrier passes copy !dbg
|
||||
# locations, so llc -filetype=obj emits the DWARF `.debug_*` sections. The
|
||||
# asm path still has no GSPA-assemblable debug directives.
|
||||
# clang --target=tms34010 [-O0|-O2] [-g] [-I dir] -S -emit-llvm -o OUT.ll IN.c
|
||||
#
|
||||
# The barrier is required by the M0/M2 pointer model: pointers are bit
|
||||
# addresses, so `(int)(p + n) - (int)p` must be 8n at run time (the optimizer's
|
||||
# DataLayout would otherwise fold it to n). `--bitptr` replaces every GEP (and
|
||||
# an inttoptr of a bit addend over a ptrtoint base) with an opaque
|
||||
# @__tms_bitptr(i32 bitoff, ptr base) call, so InstCombine cannot canonicalize
|
||||
# the already-scaled bit offset back into a byte-indexed GEP; the M6 post-opt
|
||||
# `--scale` then multiplied that index by 8 again (the `p += n` over-scale, and
|
||||
# the reason the shim's memmove used constant end-pointer steps).
|
||||
# `-disable-O0-optnone` keeps the -O0 pipeline running the barrier/lowering
|
||||
# passes, so `-O0` objects stay byte-identical to the M9 tms-clang + opt path
|
||||
# (proven by scripts/tests/m10/equivalence.sh against the frozen
|
||||
# legacy-tms-clang oracle). `-g` passes through to the IR; the barrier passes
|
||||
# copy !dbg locations, so llc -filetype=obj emits the DWARF `.debug_*` sections.
|
||||
#
|
||||
# The optimizer still creates genuinely byte-indexed GEPs (SROA aggregate
|
||||
# splits, switch tables), so the post-opt `--scale` is needed for those. By
|
||||
# then every original GEP is a call, so the pass only sees optimizer-created
|
||||
# byte GEPs. `--normalize` is not used there: it would treat those byte
|
||||
# offsets as already-scaled bits, which an aggregate return's `.fca.N.gep`
|
||||
# load (+4 bytes, not +4 bits) turns into an 8x address bug.
|
||||
#
|
||||
# `--lower-bitptr` then replaces each call with inttoptr(add(ptrtoint base,
|
||||
# bitoff)) and the final instcombine restores the M0 pointer-difference folding
|
||||
# (`int_diff` 8/32, the pointer-difference divide) and canonicalizes the
|
||||
# lowered bit GEPs, which llc already treats as bit offsets.
|
||||
# The `static` variadic rejection that used to live here (the awk guard) is now
|
||||
# owned by the barrier pass, which rejects the shape at every non-`-O0` level.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# The fork build (TMS34010 target + clang bit-address changes). The older
|
||||
# `build/llvm-build` tree is a stock clang without the target and has no
|
||||
# matching opt, so it is not a usable default.
|
||||
# `build/llvm-build` tree is a stock clang without the target and is not a
|
||||
# usable default.
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/build/llvm-clean-build/bin/clang}
|
||||
TMS_OPT=${TMS_OPT:-$ROOT/build/llvm-clean-build/bin/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
# Extra language flags from the caller (M4_EXTRA_CFLAGS). The conformance
|
||||
# c-torture sweep uses this for -std=gnu89; shipped gates leave it empty.
|
||||
TMS_CLANG_EXTRA_FLAGS=${TMS_CLANG_EXTRA_FLAGS:-}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
if [ ! -x "$tool" ]; then
|
||||
echo "tms-clang: missing tool: $tool" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG/TMS_OPT/TMS_BITADDR" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ ! -x "$TMS_CLANG" ]; then
|
||||
echo "tms-clang: missing tool: $TMS_CLANG" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPTIMIZE=1
|
||||
OPT_FLAGS=-O2
|
||||
DEBUG_FLAGS=
|
||||
INCLUDES=
|
||||
OUT=
|
||||
@@ -68,8 +51,8 @@ usage() {
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-O0) OPTIMIZE=0; shift ;;
|
||||
-O2) OPTIMIZE=1; shift ;;
|
||||
-O0) OPT_FLAGS=-O0; shift ;;
|
||||
-O2) OPT_FLAGS=-O2; shift ;;
|
||||
-g) DEBUG_FLAGS=-g; shift ;;
|
||||
-I) [ $# -ge 2 ] || usage; INCLUDES="$INCLUDES -I $2"; shift 2 ;;
|
||||
-I*) INCLUDES="$INCLUDES $1"; shift ;;
|
||||
@@ -82,97 +65,8 @@ done
|
||||
[ -n "$IN" ] || usage
|
||||
[ -n "$OUT" ] || usage
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/tms-clang.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
$DEBUG_FLAGS -S -emit-llvm -ffreestanding -fno-builtin -nostdinc $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS \
|
||||
-o "$TMP/step1.ll" "$IN"
|
||||
|
||||
# A `static` variadic definition is local, so DeadArgumentElimination removes
|
||||
# its `...` when nothing keeps the varargs alive and rewrites every call site
|
||||
# to drop the extra arguments. The M4 contiguous-stack walk in the body still
|
||||
# reads those slots, so -O2 silently miscompiles it. Reject that shape before
|
||||
# opt, but leave a definition that genuinely uses a va_list alone (M6):
|
||||
# llvm.va_start/va_arg keep `...` through DAE, and the target lowers the walk
|
||||
# from the named argument area rather than the last fixed parameter. -O0
|
||||
# (which M4's varargs gate uses) and external definitions such as sprintf are
|
||||
# unaffected.
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
STATIC_VARARG=$(awk '
|
||||
/^define / {
|
||||
in_def = 1
|
||||
sig = $0
|
||||
va_start = 0
|
||||
next
|
||||
}
|
||||
in_def && /llvm\.va_start|va_arg ptr/ { va_start = 1 }
|
||||
in_def && /^}/ {
|
||||
if (!va_start &&
|
||||
sig ~ /[^A-Za-z0-9_](internal|private)[^A-Za-z0-9_]/ &&
|
||||
sig ~ /\.\.\./) {
|
||||
print sig
|
||||
exit
|
||||
}
|
||||
in_def = 0
|
||||
}
|
||||
' "$TMP/step1.ll")
|
||||
if [ -n "$STATIC_VARARG" ]; then
|
||||
NAME=$(printf '%s\n' "$STATIC_VARARG" |
|
||||
sed -n 's/.*@\([A-Za-z0-9_.$-]*\)(.*/\1/p')
|
||||
echo "tms-clang: error: static variadic definition '${NAME:-?}' loses its" \
|
||||
"'...' arguments at -O2 (dead argument elimination); remove 'static'" \
|
||||
"or compile with -O0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Hide every source GEP (and source pointer-int arithmetic) behind the opaque
|
||||
# bit-pointer barrier before the optimizer, so the bit-addressed model survives
|
||||
# without being re-canonicalized into byte GEPs.
|
||||
run_bitaddr() { # run_bitaddr MODE IN OUT
|
||||
if ! "$TMS_BITADDR" "$1" "$2" "$3" 2> "$TMP/bitaddr.err"; then
|
||||
cat "$TMP/bitaddr.err" >&2
|
||||
echo "tms-clang: error: tms-bitaddr $1 failed on $2" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$TMP/bitaddr.err" "$TMP/bitaddr-$1.log"
|
||||
}
|
||||
|
||||
run_bitaddr --bitptr "$TMP/step1.ll" "$TMP/bitptr.ll"
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
# i64 exists since M6, but IndVarSimplify's exit-value replacement still
|
||||
# rewrites a loop's final value into a closed-form i33 multiply (e.g.
|
||||
# n*(n+1)/2 for sumto), which is an unsupported shape for this 32-bit
|
||||
# target. -replexitval is an option of IndVarSimplify; disabling only that
|
||||
# rewrite keeps the loop, which is what ordinary -O2 code needs. This is a
|
||||
# driver policy, not a target TTI policy: opt runs without a target machine
|
||||
# here. llc diagnoses the raw i33 shape reached by an opt run that omits
|
||||
# this flag (m5-policy.ll).
|
||||
"$TMS_OPT" -passes='default<O2>' -replexitval=never \
|
||||
-S "$TMP/bitptr.ll" -o "$TMP/opt.ll"
|
||||
# The optimizer may create new byte-indexed GEPs (SROA aggregate splits,
|
||||
# switch tables), so scale those. Every source GEP is still an opaque call,
|
||||
# so this pass cannot see (and re-scale) an already-bit offset.
|
||||
run_bitaddr --scale "$TMP/opt.ll" "$TMP/scaled.ll"
|
||||
# Lower the barrier and restore the M0 pointer-difference folding. The
|
||||
# lowered inttoptr(add) shapes canonicalize to GEPs whose index is already
|
||||
# a bit count; llc treats a GEP index as a bit offset, and no scale follows.
|
||||
# `no-verify-fixpoint` suppresses only InstCombine's idempotence check: the
|
||||
# M6 shim's emit_uint64 has a `zext i32 %base to i64` that a second run
|
||||
# would re-mark `nneg`, which the verifier reports as "did not reach a
|
||||
# fixpoint". The first run's output is the intended IR and all gates pass
|
||||
# with it; the flag is the documented escape for this known shape.
|
||||
run_bitaddr --lower-bitptr "$TMP/scaled.ll" "$TMP/lowered.ll"
|
||||
"$TMS_OPT" -passes='instcombine<no-verify-fixpoint>' \
|
||||
-S "$TMP/lowered.ll" -o "$OUT"
|
||||
else
|
||||
# No optimizer, so no byte GEPs can be created; lower the barrier directly
|
||||
# back to the historical bit-addressed inttoptr(add) form.
|
||||
run_bitaddr --lower-bitptr "$TMP/bitptr.ll" "$OUT"
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
exec "$TMS_CLANG" --target=tms34010 $OPT_FLAGS $DEBUG_FLAGS $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS -S -emit-llvm -o "$OUT" "$IN"
|
||||
Executable
+118
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
"""tms-run -- load a tms-cc COFF with the dwt loader in MAME and show the result.
|
||||
|
||||
tms-run hello.coff
|
||||
|
||||
The image must use the conformance entry/shim (the tms-cc default) for the
|
||||
status/stdout result block. This is the same loader/MAME acceptance path as
|
||||
the gates; it does not use the real unit (see scripts/tests/m7/hardware.sh).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
MAME = Path(os.environ.get("MAME", ROOT / "build/mame-src/vt1200"))
|
||||
LOADER_LUA = ROOT / "vendor/vt1200/dwt/loader/loader.lua"
|
||||
LOADER_BIN = ROOT / "vendor/vt1200/dwt/loader/build/loader.bin"
|
||||
CHECK_LUA = ROOT / "scripts/tests/m5/conformance/conformance-check.lua"
|
||||
ROMS = ROOT / "vendor/vt1200/harness/mame/roms"
|
||||
|
||||
|
||||
def fail(msg: str, code: int = 1):
|
||||
print(f"tms-run: error: {msg}", file=sys.stderr)
|
||||
raise SystemExit(code)
|
||||
|
||||
|
||||
def main(argv):
|
||||
ap = argparse.ArgumentParser(prog="tms-run")
|
||||
ap.add_argument("coff")
|
||||
ap.add_argument("--at", default=os.environ.get("LOADER_AT", "200"))
|
||||
ap.add_argument("--end", default=os.environ.get("LOADER_END", "1000"))
|
||||
ap.add_argument("--timeout", default="120")
|
||||
ap.add_argument("-v", "--verbose", action="store_true")
|
||||
ap.add_argument("--keep", action="store_true")
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
coff = Path(args.coff)
|
||||
if not coff.is_file():
|
||||
fail(f"missing COFF: {coff}")
|
||||
for p in (MAME, LOADER_LUA, LOADER_BIN, CHECK_LUA):
|
||||
if not p.is_file():
|
||||
fail(f"missing required file: {p}")
|
||||
work = Path(tempfile.mkdtemp(prefix="tms-run-"))
|
||||
try:
|
||||
(work / "run/nvram").mkdir(parents=True)
|
||||
(work / "run/cfg").mkdir(parents=True)
|
||||
result = work / "result.txt"
|
||||
env = dict(os.environ)
|
||||
env.update({
|
||||
"M4_LOADER_LUA": str(LOADER_LUA),
|
||||
"VT1200_MONITOR": "VR319",
|
||||
"VT1200_SKIP_LEVEL1": "1",
|
||||
"LOADER_AT": args.at,
|
||||
"LOADER_END": args.end,
|
||||
"LOADER_BIN": str(LOADER_BIN),
|
||||
"LOADER_COFF": str(coff),
|
||||
"LOADER_OUT": str(work / "evidence"),
|
||||
"CONF_RESULT": str(result),
|
||||
})
|
||||
cmd = [str(MAME), "vt1200",
|
||||
"-rompath", str(ROMS),
|
||||
"-video", "none", "-sound", "none", "-nothrottle",
|
||||
"-skip_gameinfo",
|
||||
"-nvram_directory", str(work / "run/nvram"),
|
||||
"-cfg_directory", str(work / "run/cfg"),
|
||||
"-debug", "-debugger", "none",
|
||||
"-autoboot_script", str(CHECK_LUA), "-autoboot_delay", "0"]
|
||||
if args.verbose:
|
||||
print("+", " ".join(cmd), file=sys.stderr)
|
||||
try:
|
||||
with open(work / "mame.log", "wb") as log:
|
||||
r = subprocess.run(cmd, env=env, timeout=float(args.timeout),
|
||||
stdout=log, stderr=subprocess.STDOUT)
|
||||
except subprocess.TimeoutExpired:
|
||||
fail(f"MAME timed out after {args.timeout}s")
|
||||
if r.returncode != 0:
|
||||
tail = (work / "mame.log").read_text(errors="replace")[-2000:]
|
||||
fail(f"MAME exited {r.returncode}\n{tail}")
|
||||
if not result.is_file():
|
||||
tail = (work / "mame.log").read_text(errors="replace")[-2000:]
|
||||
fail("no result block (image did not use the conformance entry/shim)"
|
||||
+ (f"\n{tail}" if args.verbose else ""))
|
||||
vals = {}
|
||||
for line in result.read_text(errors="replace").splitlines():
|
||||
if "=" in line:
|
||||
k, v = line.split("=", 1)
|
||||
vals[k] = v
|
||||
status = int(vals.get("status", "FFFFFFFF"), 16)
|
||||
magic = vals.get("magic", "")
|
||||
out = bytes.fromhex(vals.get("out", ""))
|
||||
err = bytes.fromhex(vals.get("err", ""))
|
||||
print(f"status: {status} (0x{status:08X})")
|
||||
print(f"magic: {magic}")
|
||||
sys.stdout.flush()
|
||||
if out:
|
||||
sys.stdout.buffer.write(b"stdout:\n" + out)
|
||||
if not out.endswith(b"\n"):
|
||||
sys.stdout.buffer.write(b"\n")
|
||||
if err:
|
||||
sys.stdout.buffer.write(b"stderr:\n" + err)
|
||||
if not err.endswith(b"\n"):
|
||||
sys.stdout.buffer.write(b"\n")
|
||||
sys.stdout.buffer.flush()
|
||||
ok = status == 0 and magic == "434F4E46"
|
||||
return 0 if ok else 1
|
||||
finally:
|
||||
if not args.keep:
|
||||
import shutil
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
Executable
+140
@@ -0,0 +1,140 @@
|
||||
#!/bin/sh
|
||||
# tms-sdk -- build and install the TMS34010 freestanding sysroot.
|
||||
#
|
||||
# scripts/tms-sdk [--sysroot DIR]
|
||||
#
|
||||
# Builds sdk/crt0.ll with llc and sdk/{shim,heap}.c with clang into libtms.a,
|
||||
# then installs a sysroot the M11 driver searches:
|
||||
#
|
||||
# <sysroot>/include/*.h (from sdk/include)
|
||||
# <sysroot>/lib/crt0.o (llc -filetype=obj)
|
||||
# <sysroot>/lib/libtms.a (llvm-ar rcsD of shim.o + heap.o)
|
||||
# <sysroot>/lib/{flib,rts}.lib (the committed 1990 vendor archives)
|
||||
# <sysroot>/bin/{tms-link,tmscoff.py} (the linker and its sibling module)
|
||||
#
|
||||
# The default sysroot is <clang -print-resource-dir>/tms34010-unknown-none;
|
||||
# --sysroot DIR installs elsewhere (the driver then needs --tms-sysroot=DIR).
|
||||
# Installing is idempotent: llc and llvm-ar rcsD rebuild byte-identically.
|
||||
# A successful install writes <sysroot>/.tms-sdk; an existing non-empty
|
||||
# directory without that marker is refused, so include/ is never replaced in
|
||||
# a directory this script did not create (and `/` is rejected outright).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC LLVM_AR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
LLVM_AR=${LLVM_AR:-$LLVM_BIN/llvm-ar}
|
||||
|
||||
SYSROOT=
|
||||
|
||||
fail() {
|
||||
echo "tms-sdk: error: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--sysroot)
|
||||
[ $# -ge 2 ] || fail "--sysroot needs an argument"
|
||||
SYSROOT=$2
|
||||
shift 2
|
||||
;;
|
||||
--sysroot=*)
|
||||
SYSROOT=${1#--sysroot=}
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
fail "unknown argument: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for tool in "$CLANG" "$LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
# llvm-ar is not part of the default ninja target set the other gates build;
|
||||
# rebuild it on demand so a fresh checkout still installs.
|
||||
if [ ! -x "$LLVM_AR" ]; then
|
||||
echo "tms-sdk: llvm-ar missing; running: ninja -C $ROOT/build/llvm-clean-build llvm-ar"
|
||||
ninja -C "$ROOT/build/llvm-clean-build" llvm-ar || fail "ninja llvm-ar failed"
|
||||
[ -x "$LLVM_AR" ] || fail "llvm-ar still missing after ninja: $LLVM_AR"
|
||||
fi
|
||||
|
||||
if [ -z "$SYSROOT" ]; then
|
||||
RESOURCE_DIR=$("$CLANG" -print-resource-dir) \
|
||||
|| fail "clang -print-resource-dir failed"
|
||||
SYSROOT=$RESOURCE_DIR/tms34010-unknown-none
|
||||
fi
|
||||
|
||||
MARKER=.tms-sdk
|
||||
MARKER_TEXT="tms-sdk M11 tms34010-unknown-none"
|
||||
|
||||
# SYSROOT is user-supplied, so never treat an arbitrary directory as
|
||||
# disposable. Only an absent/empty target or one this script installed (it
|
||||
# carries the marker) may have its include/ replaced.
|
||||
case $SYSROOT in
|
||||
/) fail "refusing unsafe sysroot '/'" ;;
|
||||
esac
|
||||
BASE=$(basename "$SYSROOT")
|
||||
[ -n "$BASE" ] || fail "refusing sysroot with an empty basename: '$SYSROOT'"
|
||||
if [ -e "$SYSROOT" ]; then
|
||||
[ -d "$SYSROOT" ] || fail "sysroot is not a directory: $SYSROOT"
|
||||
if [ -n "$(ls -A "$SYSROOT" 2>/dev/null)" ] && [ ! -f "$SYSROOT/$MARKER" ]; then
|
||||
fail "refusing to overwrite $SYSROOT: not an M11 sysroot (no $MARKER file); pass an empty directory or use the default"
|
||||
fi
|
||||
fi
|
||||
|
||||
[ -f "$ROOT/sdk/crt0.ll" ] || fail "missing CRT source: $ROOT/sdk/crt0.ll"
|
||||
[ -f "$ROOT/sdk/shim.c" ] || fail "missing shim source: $ROOT/sdk/shim.c"
|
||||
[ -f "$ROOT/sdk/heap.c" ] || fail "missing heap source: $ROOT/sdk/heap.c"
|
||||
[ -d "$ROOT/sdk/include" ] || fail "missing header directory: $ROOT/sdk/include"
|
||||
[ -f "$ROOT/sdk/lib/flib.lib" ] || fail "missing vendor archive: $ROOT/sdk/lib/flib.lib"
|
||||
[ -f "$ROOT/sdk/lib/rts.lib" ] || fail "missing vendor archive: $ROOT/sdk/lib/rts.lib"
|
||||
[ -f "$ROOT/tools/tms-link/tms-link" ] || fail "missing linker: $ROOT/tools/tms-link/tms-link"
|
||||
[ -f "$ROOT/tools/tms-link/tmscoff.py" ] || fail "missing linker module: $ROOT/tools/tms-link/tmscoff.py"
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/tms-sdk.XXXXXX")
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
echo "== build crt0.o from sdk/crt0.ll (llc)"
|
||||
"$LLC" -march=tms34010 -filetype=obj "$ROOT/sdk/crt0.ll" -o "$WORK/crt0.o" \
|
||||
|| fail "llc could not build sdk/crt0.ll"
|
||||
|
||||
echo "== build shim.o and heap.o (clang --target=tms34010 -O2 -c)"
|
||||
"$CLANG" --target=tms34010 -O2 -c -I "$ROOT/sdk/include" \
|
||||
"$ROOT/sdk/shim.c" -o "$WORK/shim.o" || fail "clang -c shim.c failed"
|
||||
"$CLANG" --target=tms34010 -O2 -c -I "$ROOT/sdk/include" \
|
||||
"$ROOT/sdk/heap.c" -o "$WORK/heap.o" || fail "clang -c heap.c failed"
|
||||
|
||||
echo "== archive libtms.a (llvm-ar rcsD)"
|
||||
( cd "$WORK" && "$LLVM_AR" rcsD libtms.a shim.o heap.o ) \
|
||||
|| fail "llvm-ar rcsD failed"
|
||||
|
||||
echo "== install into $SYSROOT"
|
||||
# Replace the installed header set so a header deleted from sdk/include is
|
||||
# removed here too (copying would leave stale headers behind).
|
||||
rm -rf "$SYSROOT/include"
|
||||
mkdir -p "$SYSROOT/include" "$SYSROOT/lib" "$SYSROOT/bin"
|
||||
|
||||
for h in "$ROOT"/sdk/include/*.h; do
|
||||
cp "$h" "$SYSROOT/include/"
|
||||
done
|
||||
|
||||
cp "$WORK/crt0.o" "$SYSROOT/lib/crt0.o"
|
||||
cp "$WORK/libtms.a" "$SYSROOT/lib/libtms.a"
|
||||
cp "$ROOT/sdk/lib/flib.lib" "$SYSROOT/lib/flib.lib"
|
||||
cp "$ROOT/sdk/lib/rts.lib" "$SYSROOT/lib/rts.lib"
|
||||
|
||||
cp "$ROOT/tools/tms-link/tms-link" "$SYSROOT/bin/tms-link"
|
||||
cp "$ROOT/tools/tms-link/tmscoff.py" "$SYSROOT/bin/tmscoff.py"
|
||||
chmod +x "$SYSROOT/bin/tms-link"
|
||||
|
||||
# Mark the directory as ours so a later install may replace its include/.
|
||||
printf '%s\n' "$MARKER_TEXT" > "$SYSROOT/$MARKER"
|
||||
|
||||
NHEADERS=$(find "$SYSROOT/include" -name '*.h' | wc -l)
|
||||
echo "tms-sdk: installed $NHEADERS headers, crt0.o, libtms.a, flib.lib, rts.lib, and the tms-link pair into $SYSROOT"
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
; crt0.ll -- the TMS34010 CRT, expressed as LLVM IR and built with llc.
|
||||
;
|
||||
; The CRT's machine code is a `naked` `_start` whose body is one inline-asm
|
||||
; block; llc -filetype=obj routes it through the target's TI-COFF writer (the
|
||||
; MC llvm-mc path emits ELF, which tms-link cannot read). The instruction
|
||||
; sequence is byte-identical to the reference in
|
||||
; scripts/tests/m5/conformance/entry.asm; only the carrier changed.
|
||||
;
|
||||
; Runtime contract (unchanged from entry.asm):
|
||||
; 01B00000 status main's return value (A8), cleared on entry
|
||||
; 01B00020 out_len maintained by the conformance shim
|
||||
; 01B00040 magic 0x434F4E46 written after main returns
|
||||
; 01B00060 err_len maintained by the conformance shim
|
||||
;
|
||||
; A14 (the program stack) and A13 (the frame pointer) start at _cstack, a
|
||||
; 4 KiB / 32768-bit stack at 16-bit alignment. main is called as
|
||||
; main(1, argv) with argv = { _conformance_name, NULL }, where
|
||||
; _conformance_name is the 12 bytes "conformance\0" and _conformance_argv is
|
||||
; 64 bits (8 bytes). argv is filled at runtime in the asm block rather than
|
||||
; with a pointer initialiser, so the CRT needs no pointer-initialiser
|
||||
; relocation.
|
||||
;
|
||||
; LLVM prefixes global symbols with `_` on this target, so the IR names here
|
||||
; carry no leading underscore and the inline asm refers to the final names
|
||||
; (_cstack, _conformance_argv, _conformance_name, _main).
|
||||
|
||||
target triple = "tms34010"
|
||||
|
||||
@conformance_name = constant [12 x i8] c"conformance\00", align 1
|
||||
@conformance_argv = global [2 x i32] zeroinitializer, align 2
|
||||
@cstack = global [4096 x i8] zeroinitializer, align 2
|
||||
|
||||
; `_main` is referenced by name inside the inline-asm block below (calla _main);
|
||||
; the MC parser creates the undefined symbol, so no IR declaration is needed.
|
||||
|
||||
define void @start() #0 {
|
||||
entry:
|
||||
; setf 16,1,0 / setf 32,0,1; clear the four result cells; point A14/A13 at
|
||||
; _cstack; build argv = { _conformance_name, NULL }; push argv then 1 and
|
||||
; calla _main; publish A8 as the status and 0x434F4E46 as the magic. The
|
||||
; trailing `rets` is the function's own `ret`.
|
||||
call void asm sideeffect "setf 16, 1, 0\0A\09setf 32, 0, 1\0A\09movi 0x01B00000, a1\0A\09sub a0, a0\0A\09move a0, *a1, 1\0A\09movi 0x01B00020, a1\0A\09move a0, *a1, 1\0A\09movi 0x01B00040, a1\0A\09move a0, *a1, 1\0A\09movi 0x01B00060, a1\0A\09move a0, *a1, 1\0A\09movi _cstack, a14\0A\09move a14, a13\0A\09movi _conformance_argv, a0\0A\09movi _conformance_name, a1\0A\09move a1, *a0, 1\0A\09sub a1, a1\0A\09move a1, *a0(32), 1\0A\09move a14, -*sp, 1\0A\09move a0, *a14+, 1\0A\09movi 1, a1\0A\09move a1, *a14+, 1\0A\09calla _main\0A\09setf 16, 1, 0\0A\09setf 32, 0, 1\0A\09movi 0x01B00000, a1\0A\09move a8, *a1, 1\0A\09movi 0x01B00040, a1\0A\09movi 0x434F4E46, a0\0A\09move a0, *a1, 1", ""()
|
||||
ret void
|
||||
}
|
||||
|
||||
attributes #0 = { naked }
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
File renamed without changes.
+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,200 @@ 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 make_unrelocated_debug(work, kind):
|
||||
"""Write one otherwise-valid object that the input gate must refuse.
|
||||
|
||||
Each kind leaves one reference raw (no relocation) or uses a producer
|
||||
shape the merge cannot represent, so only the form-aware input gate can
|
||||
notice that concatenating it would produce silently wrong DWARF.
|
||||
"""
|
||||
base = [(".text", 0x20, b""), (".data", 0x40, b""),
|
||||
(".bss", 0x80, b"")]
|
||||
|
||||
def cu(version, abbrev_attrs, die_payload, header_tail=b""):
|
||||
abbrev = (b"\x01\x11\x00" + abbrev_attrs +
|
||||
b"\x00\x00" + b"\x00")
|
||||
if version >= 5:
|
||||
body = (struct.pack("<HBB", version, 1, 4) +
|
||||
struct.pack("<I", 0) + header_tail + b"\x01" +
|
||||
die_payload)
|
||||
else:
|
||||
body = (struct.pack("<H", version) + struct.pack("<I", 0) +
|
||||
b"\x04" + b"\x01" + die_payload)
|
||||
return [(".debug_abbrev", 0x00, abbrev),
|
||||
(".debug_info", 0x00,
|
||||
struct.pack("<I", len(body)) + body)]
|
||||
|
||||
if kind == "stmt":
|
||||
extra = cu(5, b"\x03\x08" + b"\x10\x17",
|
||||
b"bad.c\0" + struct.pack("<I", 0))
|
||||
elif kind == "addr":
|
||||
# DW_AT_low_pc as DW_FORM_addr with no relocation.
|
||||
extra = cu(5, b"\x03\x08" + b"\x11\x01",
|
||||
b"addr.c\0" + struct.pack("<I", 0))
|
||||
elif kind == "dwarf4":
|
||||
# Pre-v5 CU: DW_AT_stmt_list is a data4 constant, so a raw value is
|
||||
# accepted by a form-only check but is still rehomed by concatenation.
|
||||
extra = cu(4, b"\x03\x08" + b"\x10\x06",
|
||||
b"v4.c\0" + struct.pack("<I", 0))
|
||||
elif kind == "line":
|
||||
# A DWARF v5 line header whose file path is a raw line_strp.
|
||||
header = bytearray(struct.pack("<HBB", 5, 4, 0))
|
||||
header += b"\0\0\0\0" # header_length (filled below)
|
||||
header += bytes([1, 1, 1, 0xFB, 14, 13])
|
||||
header += bytes(12) # standard_opcode_lengths
|
||||
header += bytes([0]) # directory format count
|
||||
header += bytes([0]) # directory count
|
||||
header += bytes([1, 1, 0x1F]) # file format: path, line_strp
|
||||
header += bytes([1]) # file count
|
||||
header += struct.pack("<I", 0) # raw line_strp, no relocation
|
||||
struct.pack_into("<I", header, 4, len(header) - 8)
|
||||
extra = [(".debug_line", 0x00,
|
||||
struct.pack("<I", len(header)) + header)]
|
||||
elif kind == "rnglists":
|
||||
unit = bytearray(b"\0\0\0\0")
|
||||
unit += struct.pack("<HBB", 5, 4, 0)
|
||||
unit += struct.pack("<I", 1) # offset_entry_count
|
||||
unit += struct.pack("<I", 4) # offset[0]
|
||||
unit += b"\x06" # DW_RLE_start_end
|
||||
unit += struct.pack("<II", 0, 0) # raw addresses, no relocation
|
||||
unit += b"\x00"
|
||||
struct.pack_into("<I", unit, 0, len(unit) - 4)
|
||||
extra = [(".debug_rnglists", 0x00, bytes(unit))]
|
||||
elif kind == "debug_addr":
|
||||
unit = bytearray(b"\0\0\0\0")
|
||||
unit += struct.pack("<HBB", 5, 4, 0)
|
||||
unit += struct.pack("<I", 0) # raw address entry
|
||||
struct.pack_into("<I", unit, 0, len(unit) - 4)
|
||||
extra = [(".debug_addr", 0x00, bytes(unit))]
|
||||
elif kind == "str_offsets":
|
||||
unit = bytearray(b"\0\0\0\0")
|
||||
unit += struct.pack("<HH", 5, 0)
|
||||
unit += struct.pack("<I", 0) # raw .debug_str offset
|
||||
struct.pack_into("<I", unit, 0, len(unit) - 4)
|
||||
extra = [(".debug_str_offsets", 0x00, bytes(unit))]
|
||||
else:
|
||||
fail("unknown unrelocated-debug kind %s" % kind)
|
||||
|
||||
write_minimal_object(
|
||||
os.path.join(work, "unrelocated-debug-%s.o" % kind),
|
||||
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_odd_bss(work):
|
||||
"""Write a minimal input whose .bss is an odd 8-bit size (one byte).
|
||||
|
||||
llc rounds .bss up to a whole 16-bit word, but GSPA can emit a single
|
||||
8-bit .bss symbol and GSPLNK forwards that odd size, which the dwt loader
|
||||
rejects. tms-link must accept the odd .bss and round it up on output.
|
||||
"""
|
||||
write_minimal_object(os.path.join(work, "odd-bss.o"), [
|
||||
(".text", 0x20, b"\x00\x00\x00\x00"),
|
||||
(".data", 0x40, b""),
|
||||
(".bss", 0x80, b"\x00"),
|
||||
])
|
||||
|
||||
|
||||
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 +1028,65 @@ def empty_cinit(work):
|
||||
% [s.name for s in out.sections])
|
||||
|
||||
|
||||
def odd_bss(work):
|
||||
"""An 8-bit .bss input must be rounded up to a whole 16-bit word."""
|
||||
out = read_object(os.path.join(work, "oddbss.out"), relocatable=False)
|
||||
bss = out.section_by_name[".bss"]
|
||||
check(bss.size == 16,
|
||||
".bss size %d bits, want 16 (rounded up from 8)" % bss.size)
|
||||
check(all(s.nreloc == 0 for s in out.sections),
|
||||
"odd-.bss output has relocations")
|
||||
globals_out = {s.name: s.value for s in out.symbols if s.sclass == C_EXT}
|
||||
check(globals_out.get("end") == bss.paddr + bss.size,
|
||||
"end symbol %#x, want .bss end %#x"
|
||||
% (globals_out.get("end"), bss.paddr + bss.size))
|
||||
print(" odd .bss: 8-bit input rounded to %d bits" % bss.size)
|
||||
|
||||
|
||||
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 +1114,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 +1157,44 @@ 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-odd-bss":
|
||||
make_odd_bss(work)
|
||||
elif mode == "odd-bss":
|
||||
odd_bss(work)
|
||||
elif mode == "make-raw-debug":
|
||||
make_raw_debug(work)
|
||||
elif mode == "make-bad-debug":
|
||||
make_bad_debug(work, argv[3])
|
||||
elif mode == "make-unrelocated-debug":
|
||||
make_unrelocated_debug(work, argv[3] if len(argv) > 3 else "stmt")
|
||||
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:
|
||||
|
||||
+203
-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,88 @@ echo "== positive link: two TUs, .cinit, long name, map"
|
||||
python3 "$DIR/linktest.py" positive "$WORK" \
|
||||
|| fail "positive assertions failed"
|
||||
|
||||
echo "== loader validity: emitted COFF passes coff-check unaided"
|
||||
"$TMS_LINK" -o "$WORK/coffcheck.out" --entry _shared_fn "$WORK/defs.o" \
|
||||
|| fail "coffcheck link failed"
|
||||
python3 "$ROOT/scripts/m4/coff-check.py" "$WORK/coffcheck.out" \
|
||||
|| fail "coff-check rejected the default image"
|
||||
|
||||
echo "== loader validity: odd-length .bss is rounded to a whole word"
|
||||
python3 "$DIR/linktest.py" make-odd-bss "$WORK" >/dev/null
|
||||
"$TMS_LINK" -o "$WORK/oddbss.out" "$WORK/odd-bss.o" \
|
||||
|| fail "odd-.bss link failed"
|
||||
python3 "$DIR/linktest.py" odd-bss "$WORK" \
|
||||
|| fail "odd-.bss rounding assertions failed"
|
||||
python3 "$ROOT/scripts/m4/coff-check.py" "$WORK/oddbss.out" \
|
||||
|| fail "coff-check rejected the odd-.bss image"
|
||||
|
||||
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 +191,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 +273,53 @@ 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 "== debug merge: unrelocated/unsupported producer fields fail loudly"
|
||||
while IFS='|' read -r kind pattern; do
|
||||
python3 "$DIR/linktest.py" make-unrelocated-debug "$WORK" "$kind" \
|
||||
>/dev/null
|
||||
expect_fail "unrelocated-$kind" "$pattern" \
|
||||
"$TMS_LINK" -o "$WORK/unrelocated-$kind.out" --keep-debug \
|
||||
"$WORK/debug.o" "$WORK/unrelocated-debug-$kind.o"
|
||||
done <<'EOF'
|
||||
stmt|unrelocated DW_FORM_sec_offset for DW_AT_stmt_list
|
||||
addr|unrelocated DW_FORM_addr for DW_AT_low_pc
|
||||
line|unrelocated DW_FORM_line_strp for line-table file entry 0 content 0x1
|
||||
rnglists|unrelocated absolute address for DW_RLE_start_end
|
||||
debug_addr|unrelocated address entry
|
||||
str_offsets|unrelocated entry offset into .debug_str
|
||||
dwarf4|requires DWARF v5
|
||||
EOF
|
||||
|
||||
echo "tms-link tests: PASS"
|
||||
+1037
-49
File diff suppressed because it is too large.
Load diff
+315
-8
@@ -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
|
||||
@@ -81,6 +92,17 @@ class Section:
|
||||
def is_allocated(self):
|
||||
return self.name in (".text", ".data", ".cinit", ".bss")
|
||||
|
||||
@property
|
||||
def reloc_offsets(self):
|
||||
"""Byte offsets of this section's 4-byte R-RELLONG fields.
|
||||
|
||||
The DWARF input gate uses this to decide whether a section-relative
|
||||
field is actually covered by a relocation. Every relocation record is
|
||||
validated as R-RELLONG with a byte-aligned, in-section field by
|
||||
``read_object``, so the address alone identifies the covered bytes.
|
||||
"""
|
||||
return {rel.raddr // 8 for rel in (self.relocs or ())}
|
||||
|
||||
def __repr__(self):
|
||||
return "Section(%d, %r, size=%d bits)" % (self.index, self.name,
|
||||
self.size)
|
||||
@@ -172,18 +194,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)
|
||||
@@ -302,7 +336,13 @@ def read_object(path, relocatable=True):
|
||||
"number of bytes" % (path, name, size))
|
||||
|
||||
if name in ALLOCATED_NAMES:
|
||||
if size % 16:
|
||||
# .text/.data/.cinit carry whole 16-bit words; .bss is a virtual
|
||||
# section whose trailing byte is a legal TMS34010 bit address.
|
||||
# GSPA emits a single 8-bit .bss symbol and GSPLNK forwards it
|
||||
# unrounded, which the dwt loader rejects, so tms-link accepts the
|
||||
# odd .bss here and rounds it up on output (see write_coff's
|
||||
# caller and scripts/m4/coff-check.py).
|
||||
if size % 16 and name != ".bss":
|
||||
raise CoffError("%s: section %r size %d bits is not a whole "
|
||||
"number of 16-bit words"
|
||||
% (path, name, size))
|
||||
@@ -311,7 +351,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 +479,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