Skip to content

fix(uki): correct malformed section layout in UKI - #137

Merged
imlk0 merged 1 commit into
openanolis:masterfrom
Just-do-st:master
Sep 18, 2026
Merged

imlk0 merged 1 commit into
openanolis:masterfrom
Just-do-st:master

Conversation

@Just-do-st

Copy link
Copy Markdown
Contributor

fix(uki): correct malformed section layout in UKIs generated by legacy dracut

Introduce the uki_reassemble function to recalculate and fix absolute VMA layouts for UKI sections.

Legacy dracut (< 059-3) hardcodes section VMAs assuming an ImageBase of 0. When paired with modern systemd stubs (>= v254, built with lld) that use a large ImageBase, objcopy's RVA calculation underflows. This causes SizeOfImage to bloat abnormally (e.g., ~2.9 GiB for ~0.12 GiB of data), leading to extremely slow boot times or outright rejection by strict UEFI firmware.

This commit resolves the issue by:

  • Dynamically deriving the first free VMA immediately after the stub's own sections, ensuring payload sections are placed contiguously without RVA underflow.
  • Invoking the reassembly function during the conversion pipeline to guarantee structurally sound UKI generation regardless of the host's dracut version.
  • Logging the final SizeOfImage versus file size, explicitly failing the conversion if a massive memory hole is still detected as a sanity check.
  • Adding comprehensive documentation detailing the root cause, the math behind the underflow, and the dynamic offset algorithm used for the fix.

…y dracut

Introduce the `uki_reassemble` function to recalculate and fix absolute VMA
layouts for UKI sections.

Legacy dracut (< 059-3) hardcodes section VMAs assuming an ImageBase of 0.
When paired with modern systemd stubs (>= v254, built with lld) that use a
large ImageBase, objcopy's RVA calculation underflows. This causes SizeOfImage
to bloat abnormally (e.g., ~2.9 GiB for ~0.12 GiB of data), leading to
extremely slow boot times or outright rejection by strict UEFI firmware.

This commit resolves the issue by:
- Dynamically deriving the first free VMA immediately after the stub's own
  sections, ensuring payload sections are placed contiguously without RVA
  underflow.
- Invoking the reassembly function during the conversion pipeline to guarantee
  structurally sound UKI generation regardless of the host's dracut version.
- Logging the final SizeOfImage versus file size, explicitly failing the
  conversion if a massive memory hole is still detected as a sanity check.
- Adding comprehensive documentation detailing the root cause, the math behind
  the underflow, and the dynamic offset algorithm used for the fix.
@ostest-bot

Copy link
Copy Markdown

@Just-do-st ,您好,您的请求已接收,请耐心等待结果。

@ostest-bot

Copy link
Copy Markdown

@Just-do-st ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。

@imlk0
imlk0 merged commit e1efa8d into openanolis:master Sep 18, 2026
41 of 42 checks passed
imlk0 added a commit that referenced this pull request Sep 20, 2026
CI never passed uki_stub_version, so every UKI job used the distro stub
(ImageBase=0, no SizeOfImage hole) and the reassembly fix from #137 was
never exercised against a real pinned stub that has the hole.

Plumb --uki-stub-version through test-convert.sh + the Makefile, and add
two targeted matrix rows (uki/noenc/disk on alinux3 and alinux4) that
carry uki_stub_version=258 + boot_matrix="2:4G 4:8G 4:16G". The 2:4G
entry is what surfaces the SizeOfImage hole on a pinned stub at low RAM;
the fix should make it boot.

The baseline 24 jobs no longer carry a boot matrix (single boot, distro
stub), cutting CI cost vs applying the 3-boot matrix to all rows. The
two new vars reach make via the step env + docker exec --env (make
imports them from the environment), avoiding inline quoting through
bash -c. zstd is installed in the test container for the host-side
Arch-Archive stub extraction.

Assisted-by: Claude:glm-5.2
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
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.

3 participants