Skip to content

Add ELF loading support for aarch64 and riscv64#234

Open
Gelbpunkt wants to merge 5 commits into
rust-vmm:mainfrom
Gelbpunkt:elf-aarch64-riscv64
Open

Add ELF loading support for aarch64 and riscv64#234
Gelbpunkt wants to merge 5 commits into
rust-vmm:mainfrom
Gelbpunkt:elf-aarch64-riscv64

Conversation

@Gelbpunkt

@Gelbpunkt Gelbpunkt commented May 15, 2026

Copy link
Copy Markdown

Summary of the PR

This adds support for loading ELF files on aarch64 and riscv64. The reason why I'm adding it is because we want to be able to boot Hermit unikernel images (which are ELF files) without having to wrap them in the Linux kernel Image format on these architectures. Booting kernels in ELF format isn't completely unheard of, e.g. U-Boot supports it via the bootelf command and QEMU can boot both ELF and Linux Image files via -kernel on ARM and RISC-V. Linux' vmlinux on aarch64 will not work, they are not meant to be the final bootable kernel executable.

The example testcase I added is the qemu_el1 example from aarch64-rt.

aarch64 and riscv64 lack PVH support, so the code for that needs to be conditionally compiled out, but that's very straightforward.

Since aarch64 can technically also be big-endian, I also extended the code to not check for little endian, but rather native endian. I have however not run the testsuite on aarch64_be, only on aarch64. I only compile-tested aarch64_be.

The testing was done with a slightly modified version of cloud-hypervisor on aarch64. I don't have access to riscv64 hardware with the hypervisor extension.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

@Gelbpunkt Gelbpunkt force-pushed the elf-aarch64-riscv64 branch 3 times, most recently from 1beb80f to 70cb872 Compare May 16, 2026 22:24
Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
@Gelbpunkt Gelbpunkt force-pushed the elf-aarch64-riscv64 branch 3 times, most recently from f112d60 to b612883 Compare June 24, 2026 00:41
These lack PVH support, so we conditionally don't compile the code
related to that.

Since aarch64 can technically also be big-endian, I also extended the
code to not check for little endian, but rather native endian. I have
however not run the testsuite on aarch64_be, only on aarch64.

Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
This method can also be used when loading ELF files, hence move it to
the loader module level.

Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
The test file is the qemu_el1 example from aarch64-rt:
https://github.com/google/aarch64-rt/blob/main/examples/qemu_el1.rs

Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
@Gelbpunkt Gelbpunkt force-pushed the elf-aarch64-riscv64 branch from b612883 to efb9127 Compare June 24, 2026 00:43
@Gelbpunkt Gelbpunkt marked this pull request as ready for review June 24, 2026 00:56
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