Skip to content

aura-raw.ld: fit the SPTM_VIRT ESP Stage 2 below _file_limit again - #252

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/sptm-virt-esp-stage2-fit
Nov 14, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/sptm-virt-esp-stage2-fit

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What

Since #70, an ESP Stage 2 built with SPTM_VIRT=1 but without SPTM_VIRT_ESP no longer links:

make USE_CLANG=1 BUILDSTD=1 CHAINLOADING=1 SPTM_VIRT=1 ESP_STAGE2=1 DEBUGUSB_PROXY=1
ld.lld: error: Code and data reach the DCP log buffer after stage 1!

_file_vital_end lands at 0x13bcc8, 113864 B past _file_limit. .text crossed one 64 KiB step, and the read-only segment (which now also holds the virtualized SPTM's code) crossed another. The CI jobs build this code only at -Oz or with SPTM_VIRT_ESP, so they didn't catch it. Moving code into .init no longer helps, because .init and .text now share their steps.

Changes

  • Logos back past _file_vital_end. c5c5b35 linked the compressed boot logos with the fonts after _file_vital_end. 21a2a83 (written against a limit that still covered the whole file part) renamed their section to .rodata, so the *_48.o(.data) lines in aura-raw.ld stopped matching and 42 KiB of logos went back into the vital region. They're now linked with the fonts again. A logo the DCP overwrites fails its gzip CRC in fb.c and is left blank, as c5c5b35 intended. aura.ld (the Mach-O) is unchanged.
  • Size over speed for setup and development code. The kboot_*.o handoff objects and the sptm_virt*.o objects build at -Oz, as kboot.o and sptm_virt_cl4.o already do. aura's own Rust crate builds at opt-level = "z", as ed25519-compact already does: it's ADT lookups, GPU init data and the ESP/chainload paths, with nothing in an exception or I/O path. sha2, which hashes every measured kernel, keeps the default, and so do nv2.c and the other dependencies.
  • sptm_virt_s2r.o's code goes in .text, using the room the above frees, so .text and the read-only segment each stay below their step. Both are inside the one executable mapping, [_base, _rodata_end) (memory.c).

_file_limit is unchanged.

Result

Cold builds, clang 23, rustc 1.99:

Build Before After
SPTM_VIRT=1 ESP_STAGE2=1 DEBUGUSB_PROXY=1 (flags above) does not link (0x13bcc8) _file_vital_end 0x11bcc0: 23608 B left in .text, 16120 B in .rodata, 17216 B data
Stage 1, RELEASE=1 CHAINLOADING=1 BUILTIN_LOGO=aurora links, headroom 18424 B
esp-stage2-size, SPTM_VIRT_ESP=1 at -Oz links, ESP vital margin 435272 B
esp-stage2-size, plain at -Oz links, headroom 83920 B

The image is also 64 KiB smaller. Both builds carry the logos (verify-logo). Everything moved stays in the same segment lifetime: nothing frees or remaps part of [_base, _rodata_end), and start.S still copies the file part up to _file_end, logos included.

🤖 Generated with Claude Code

Since #70, an ESP Stage 2 built with SPTM_VIRT=1 but without
SPTM_VIRT_ESP (USE_CLANG=1 BUILDSTD=1 CHAINLOADING=1 SPTM_VIRT=1
ESP_STAGE2=1 DEBUGUSB_PROXY=1) no longer links: _file_vital_end is at
0x13bcc8, 113864 B past _file_limit. .text crossed one 64 KiB step and
the read-only segment, which now also holds the virtualized SPTM's
code, crossed another. Moving code into .init no longer helps, as .init
and .text share their steps.

- Link the compressed boot logos past _file_vital_end again, with the
  fonts. c5c5b35 put them there; 21a2a83, from a tree whose limit
  still covered the whole file part, linked them as .rodata, so the
  *_48.o(.data) lines in aura-raw.ld stopped matching and 42 KiB of
  logos went back into the vital region. A logo the DCP overwrites
  fails its gzip CRC in fb.c and is left blank, as c5c5b35 intended.
  aura.ld (the Mach-O) keeps them in .rodata.
- Build the kboot_*.o handoff objects and the sptm_virt objects at -Oz,
  as kboot.o and sptm_virt_cl4.o already are, and aura's own Rust crate
  at opt-level "z", as ed25519-compact already is. All of it is setup
  or development code; sha2, which hashes each measured kernel, nv2.c
  and the dependencies keep their levels.
- Put sptm_virt_s2r.o's code in .text with the room that frees, so
  .text and the read-only segment each stay below their step. Both are
  in the one executable mapping, [_base, _rodata_end).

_file_limit is unchanged. With the flags above (clang 23, rustc 1.99,
cold build) _file_vital_end is now 0x11bcc0: 23608 B left in .text,
16120 B in .rodata and 17216 B of data room. The image is 64 KiB
smaller. A Stage 1 (RELEASE=1 CHAINLOADING=1 BUILTIN_LOGO=aurora) has
18424 B of headroom.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr merged commit be94691 into main Nov 14, 2026
16 checks passed
@RyanTheTide
RyanTheTide deleted the fix/sptm-virt-esp-stage2-fit branch November 16, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant