Repository navigation
Pack the relative relocations (RELR) to free ESP Stage 2 room - #609
Conversation
Every image carried one 24-byte .rela.dyn entry per aligned pointer: about 74 KiB in the ESP Stage 2, inside the region that must end below the DCP log buffer (_file_limit). It had 6 KiB of headroom left, too little for the pending T8152 DCP handoff. Link with -z pack-relative-relocs (lld and GNU ld 2.38+). The aligned pointers go to .relr.dyn, about 10 KiB, and keep their link-time value in the file; apply_relr() adds the base once after apply_rela(), which still handles what the linker does not pack (unaligned words). Both linker scripts place .relr.dyn at the end of the read-execute region, and the proxyclient sanity check compares both tables. fedora:44 stage1_size: ESP Stage 2 headroom 6192 -> 77088 B, Stage 1 44592 -> 110128 B; nothing is dropped, every flavour keeps its code. test_relr_apply links an image with address and bitmap entries, a gap and an unaligned pointer with both linkers, relocates it with the production apply_rela()/apply_relr() on the host and checks it against the unpacked link. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: HOLD at f4c24747
Blockers:
- Pending CI at head
f4c24747:8checks are still queued/in-progress (build,ESP stage 2 vital size,format-check,gcc,Pytest (ubuntu-latest + gcc),Pytest (ubuntu-latest + llvm),Pytest (macos-26 + llvm-brew),Pytest (macos-15 + llvm-brew)).12checks have already passed, includingPytest (ubuntu-24.04-arm, native start.S),fedora,alarm,nix,clang-macos,selftest,policy,pr-text, andreadiness. - Exact-head hardware boot rows at
f4c24747: As noted in the PR description, record the Stage 1 + ESP Stage 2 boot-to-Linux row on J615 (exercising the M3 relocate-after-move path) and the second-family regression row (J473) atf4c24747. Code and tests are clean; ready to approve once CI and the hardware rows land.
Checked:
src/startup.c(apply_relr()) &src/start.S: implements ELFSHT_RELRdecoding accurately — even entries setwhere = (uint64_t *)(base + *e)and relocate*where++ += base; odd entries iterate bits1..63(bits = *e >> 1) overword = whereand unconditionally advancewhere += 63regardless of trailing zero bits. Leaf function with no globals or stack, called once in_startright afterapply_rela()using callee-savedx20(_base) after any M3 image move and I-cache invalidation.Makefile,aura-raw.ld,aura.ld,tools/stage1_room.py:-z pack-relative-relocsadded alongside existingLDFLAGS;.relr.dyn(_relr_start/_relr_end) placed immediately after.rela.dyninside the RX region (:textinaura-raw.ld,:rodatainaura.ld), moving_rodata_content_endand the closingALIGN(_layout_step)/ALIGN(0x10000)cleanly to.relr.dynwhile keeping*(.rela.init)outside[_rela_start, _rela_end).proxyclient/aura/loadobjs.py: compares both.rela.dynand.relr.dynagainst the target when present (if start not in addrs: continuepreserves compatibility with older images;proxy.readmem(addr, 0)handles empty.rela.dynsafely).tests/python/test_relr_apply.py&tests/python/test_rela_layout.py: links with both GNUldandlldusing the exactMakefileLDFLAGS(--no-apply-dynamic-relocs+-z pack-relative-relocs), covering multi-bitmap runs (140 words), sparse addresses, intra-bitmap gaps, and unaligned.rela.dynfallback, verifying exact word values and zero unintended byte mutations.
Evidence
- Diff reviewed:
aura#609atf4c24747dd005c5dc035ee96ce4316125661bb28(+286/-23, 9 files, 1 commit,MERGEABLEonmain). - Verified
proxyclient/tools/validate_legacy_boot.pyloadsPT_LOADat link-timep_vaddr(base = 0), where RELR-packed words already carry their link-time values in the file and.rela.dynremains present as an output section. - Nit (non-blocking):
tests/python/test_relr_apply.pydefinesBASE = 0x40000000ULLand silences it with(void)BASE;since the harness relocates directly to(uint64_t)mem.
There was a problem hiding this comment.
Verdict: FINISH at f4c24747.
Blocker: proxyclient/aura/loadobjs.py, in _load_base_symbols(), accepts a mismatched ELF when a packed relocation's addend changes but its slot stays put. RELR stores the slots. The addends moved from the table into the words being relocated, so checking both table byte ranges no longer catches this case. The client then uses the accepted ELF's addresses for symbol calls and injected object references.
Checked: Linked the PR's layout fixture twice with its raw linker script and Makefile flags, changing only the aligned .quad _start + 8 to .quad _start + 12. With both GNU ld and lld the packed .rela.dyn and .relr.dyn bytes matched while the relocated word differed. The unpacked .rela.dyn bytes differed on both linkers and would have tripped the old check. Preserve the match check with a stable image identity or by comparing packed relocation values against their live rebased equivalents where those values remain immutable. Please add a host regression with matching tables and different addends.
Keep the pending hosted checks and exact-head boot evidence from the earlier review as separate landing gates.
GNU ld before 2.43 (Ubuntu 24.04 has 2.42) ignores -z pack-relative-relocs on AArch64 with a warning and keeps every pointer in .rela.dyn. The image is still right (apply_relr() has nothing to do), but test_rela_layout and test_relr_apply expected packed entries. They now accept that case when the linker printed the warning, and test_relr_apply still relocates the image and checks every word. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: FINISH at 5820fe17.
Checked: Reviewed the linker-test follow-up and ran both focused test files at this head. All six cases passed locally with GNU ld 2.46.1 and lld 22.1.6. The older GNU ld warning path still needs the hosted toolchain result.
Blocker: The proxyclient code is unchanged from the previous review. The test follow-up accepts an empty RELR table on older linkers, while the packed images can still pass the identity check with different pointer addends and matching relocation tables. Preserve that check and cover the mismatched-ELF case in a host test. Hosted checks and the exact-head boot evidence still apply.
loadobjs.py refused an ELF that was not the running image by comparing .rela.dyn, which held every pointer's addend. A packed relocation keeps its addend in the word it relocates, and the image may change that word at run time, so two builds can now have the same tables and different pointers. Link with --build-id=sha1 and keep the note in the read-only region (.note.gnu.build-id, _build_id_start/_end, 36 bytes) in both linker scripts. image_mismatch() compares the relocation tables and the build ID; an older image without the symbols is compared as before. test_relr_apply links two images that differ only in one packed pointer's addend: their tables match, and image_mismatch() still tells them apart (with GNU ld before 2.43, by .rela.dyn as before). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
|
Fixed in 649298b: the App's
Full host pytest: 1505 passed, 28 skipped. The fedora:44 |
There was a problem hiding this comment.
Verdict: HOLD at 649298bc for hosted checks and boot evidence. The packed-pointer identity blocker is resolved.
Checked: Ran eight focused relocation and identity tests at this head with GNU ld and lld. Both linkers produce identical relocation tables for the two different packed pointer values, and the production proxyclient check now rejects the mismatch at the build ID. The note is in the raw file-backed load region and inside the Mach-O read-only file range. I also checked older fixtures without a build ID on both linkers. A matching ELF is accepted and a mismatched RELA table is rejected.
Please retain the exact-head boot rows and the owner disposition for the affected boot paths before landing.
|
Boot rows at 649298b. Tested:
Not run yet: the J473 (T8112) second-family regression row. The J473 has been reserved by another lab task since 19:50. This row is queued for it: an ESP Stage 2 aura-try one-shot plus a method-T chain, on the same scripts. Risk: the J615 rows cover one family (T8122) on both the move-then-relocate path and the proxy chainload path. Until the J473 row runs, the other families rely on the host tests ( |
There was a problem hiding this comment.
Verdict: HOLD at 649298bc for pending hosted checks and the J473 second-family row.
Checked: The J615 one-shot reached Linux with the exact Stage 1 and ESP Stage 2 after the move-and-relocate path. The same-machine base control preserved the display and console behavior. The live proxy accepted its matching ELF and rejected all three mismatches, including the same-head build with one changed string. The restoration receipt shows the saved boot returned with the trial markers cleared.
The J615 boot and live proxy checks are satisfied. Keep the J473 regression or an explicit maintainer disposition, plus the current ESP vital-size and format checks.
|
Second-family row: MacBook Neo (J700, T8140), built together with #611. PASS. Tested:
Evidence: traces/boot/20261130-609-611-neo (README, per-boot logs). With the J615 row this covers both requested families |
|
Maintainer decision on the second-family row (closeout, at The Neo row booted this PR's code (combined with #611) through the same one-shot ESP Stage 2 path: Stage 1 chainloads the trial image, which moves to its run base and then applies the packed relocations. It came up with all 6 CPUs, passed three CPU offline/online cycles, one s2idle and two deep-sleep resumes, Enforcing with 0 failed units, and the same kernel error lines as baseline. Together with the J615 method-T chain and the proxy The J473 row is still welcome as an extra check after merge; its kit is ready in |
There was a problem hiding this comment.
Verdict: MERGE at 649298bc
Blockers:
- None. All 22 hosted CI checks at
649298bchave passed and both SoC families' hardware rows (J615 T8122 + Neo T8140 per maintainer closeout disposition) are in.
Checked:
- Hosted CI at
649298bc: 22/22 passed (build,ESP stage 2 vital size,format-check,gcc,clang-macos, allPytestmatrices including native ARMstart.S,fedora,alarm,nix,selftest,pr-text,policy,readiness), 0 failed, 0 queued. - Two-family hardware verification at
649298bc:- J615 (M3, T8122): Method-T chain one-shot with both Stage 1 and ESP Stage 2 linked with empty
.rela.dynand all relative relocations in.relr.dyn(both moved to run base and relocated; Linux Enforcing, 0 failed units, 0 AVC, A/B control againsta3824954matches line-for-line), plus proxyloadobjsbuild-ID checks accepting the matching ELF (1,213 symbols) and rejecting modified/release/base ELFs. - Neo (T8140): Accepted by maintainer closeout disposition as the second-family regression row (one-shot ESP Stage 2 move + packed relocations, 6 CPUs up, 3 CPU offline/online cycles, 1 s2idle + 2 deep-sleep resumes, Enforcing, 0 failed units, baseline-identical kernel errors).
- J615 (M3, T8122): Method-T chain one-shot with both Stage 1 and ESP Stage 2 linked with empty
- Prior code audit (
+376/-23, 9 files): RELR decoder, linker scripts, GNU ld compatibility test, and build-ID check inproxyclientremain clean.
Evidence
- Hosted CI at
649298bc: 22/22 passed, 0 failed, 0 queued. - Post-merge note (non-blocking): J473 row remains optional post-merge verification as noted in the maintainer comment.
|
Merging at |
The state a core reads with its MMU off or uncached (reset stacks, spin table, S2R mailbox, kernel park slots) had a 16 KiB page of its own in .data. Every byte of it but three initial values is zero, yet the page sat in the file part of every image, before _file_vital_end, where the ESP Stage 2 has to end below the panel DCP's log buffer. Put it on its own pages at the start of .bss (.bss.smp_shared) in both linker scripts. memory.c still maps exactly those pages uncached and smp.c still cleans them to PoC; S2R cleans [_data_start, _bss_end) as before. _start_c clears .bss and then calls smp_shared_init(), which sets the three values that do not start as zero: boot_cpu_idx -1, spin_table at spin_table_image, and an MPIDR of ~0 in every smp_reset_stacks entry. Nothing reads them earlier: no secondary runs and no reset can come back to this image before smp_init(). This frees 16 KiB of the file on every toolchain. Packed relocations (aura#609) free more, but only with lld or GNU ld 2.43 and later; the release workflow and the installer's UEFI-only build link with Ubuntu 24.04's GNU ld 2.42, which ignores -z pack-relative-relocs on AArch64. gcc + GNU ld 2.42, ESP Stage 2 headroom: main 4160 B, this 27392 B; main + this + aurora-silicon#601 + aurora-silicon#604 (with or without aurora-silicon#609) 10424 B. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
The ESP Stage 2 on main (a382495) has 6192 B of headroom before
_file_limit(fedora:44tools/stage1_size.sh, floor 4096, warning 8192). #601 (T8152 DCP handoff) needs about 2.8 KB, so main + #601 fails the floor at 3496 B, and #113 and #604 add more.About 74 KiB of that region was
.rela.dyn: one 24-byteR_AARCH64_RELATIVEentry per aligned pointer (2900 in the ESP Stage 2, 2816 in Stage 1). This links with-z pack-relative-relocs(lld; GNU ld 2.38+), so those pointers go to.relr.dyn(about 10 KiB) and keep their link-time value in the file. Nothing is dropped: same code, same data, same pointers, and no flavour or SoC is gated.Makefile:-z pack-relative-relocsinLDFLAGS.aura-raw.ld,aura.ld: a.relr.dynoutput section (_relr_start/_relr_end) after.rela.dyn, at the end of the read-execute region._rodata_content_endand the step padding move to it.src/startup.c,src/start.S:apply_relr()runs right afterapply_rela(), once, after any move torun_base/top_of_kernel_data. It is a leaf function with no globals and no stack, likeapply_rela().apply_rela()still handles what the linker doesn't pack (unaligned words). It still stops on anything that isn't a relative relocation.proxyclient/aura/loadobjs.py: the check that the ELF is the running image (image_mismatch()) compares.rela.dyn,.relr.dynand the linker's build ID. Packed words carry their addends, so the tables alone can match across builds. The build ID is linked with--build-id=sha1and kept as.note.gnu.build-id(_build_id_start/_end, 36 bytes) in both scripts.tools/stage1_room.py: comments only. The room is still measured to_rodata_content_endand_file_vital_end.Numbers (headroom before
_file_limit)fedora:44
sh tools/stage1_size.sh fedora USE_CLANG=1 BUILTIN_LOGO=aurora BUILDSTD=1(the CI RUSTFLAGS):Freed: +70896 B ESP Stage 2 headroom, +65536 B for every Stage 1 flavour. The headroom is the data room once that is a step or more, so the jump is in 16 KiB steps.
GNU ld before 2.43 (Ubuntu 24.04 ships 2.42, which the
gcclegs use) ignores-z pack-relative-relocson AArch64. It prints-z pack-relative-relocs ignoredand keeps every pointer in.rela.dyn. The image is still correct (apply_relr()gets an empty table, and the layout checks pass), but those builds don't gain anything.stage1_size.shwith aurora-s1gcc (GNU ld 2.42):So with a 2.42 toolchain #601 still doesn't fit. That needs a toolchain-independent follow-up or a newer binutils on those legs. The candidate follow-up moves the 16 KiB
.data.smp_sharedpage out of the file into.bss: its only non-zero initialisers aresmp_reset_stacks[].mpidr = ~0,boot_cpu_idx = -1andspin_table = spin_table_image. The data must stay correct for every SMP path, which needs its own row. GNU ld 2.43+ (tested with 2.46) packs like lld.Buildbox clang 22 (
make USE_CLANG=1 BUILDSTD=1, headroom main -> this):RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1): 6800 -> 77088DEBUGUSB_PROXY=1: 6680 -> 77080SPTM_VIRT=1 SPTM_VIRT_ESP=1 AURACTL=1 EXTRA_CFLAGS=-Oz(ESP): 499008 -> 531776The relocation count is the same in every image: main's
.rela.dynentries match the words the packed.relr.dyndecodes to (ESP Stage 2 2900, Stage 1 2816, SPTM-virt 1345), with no duplicates.Tested:
test_relr_apply/test_rela_layoutalso pass with GNU ld 2.42 in aurora-s1gcc: the unpacked case, still relocated and checked word by word. The two new cases aretests/python/test_relr_apply.py(GNU ld and lld). It links an image throughaura-raw.ldwith address entries, two bitmap entries in a run, a gap inside a bitmap and an unaligned pointer. Then it relocates that image on the host with the productionapply_rela()/apply_relr()fromstartup.cand checks every word against the unpacked link, and that no other byte changed. Three mutations ofapply_relr()(bitmap stride 64, bit shift, no post-increment) each fail it.test_relr_apply.pyalso links two images that differ only in one packed pointer's addend: their relocation tables match, andimage_mismatch()must still refuse the other one. Without the build ID it fails.test_rela_layout.pynow also checks the.relr.dynplacement and that the unaligned pointer stays in.rela.dyn.stage1_size.shon this PR, on this + kboot: T8152: hand the running internal-panel DCP to Linux (successor of #289) #601 (pull/601/head c8124aa), and on this + kboot: T8152: hand the running internal-panel DCP to Linux (successor of #289) #601 + kboot: T8132 USB3 calibration, AOP handoff and absent-ISP rule by ADT property #113 + kboot: default the display on the J504, J514C, J514M and J516M, admitted from the ADT #604: all flavours pass (table above).apply_relrin the ESP Stage 2 release image is a 27-instruction leaf: noadrp, no literal loads, no calls, no stack.Row needed before merge: this changes how every image relocates itself at boot (Stage 1 and ESP Stage 2), so it needs a one-shot boot on one lab Mac. Proposed: J615 (M3 Air, T8122). There the ESP Stage 2 moves above the DCP log buffer before relocating, which is the most sensitive path. A method-T chain one-shot of Stage 1 + ESP Stage 2 built at this head (kits/aura/20261123-stage1-signoff/s1so.sh) should boot to Linux with the logo and the console. A second family (J473) is the regression row. It has not been run yet.
Risk: two-way · all Macs (ESP Stage 2 layout)
@DjDeveloperr: code-owner ping. This is the room for #601/#113/#604.