Skip to content

Add ELF loading support for aarch64 and riscv64#234

Draft
Gelbpunkt wants to merge 4 commits into
rust-vmm:mainfrom
Gelbpunkt:elf-aarch64-riscv64
Draft

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

Conversation

@Gelbpunkt
Copy link
Copy Markdown

@Gelbpunkt Gelbpunkt commented May 15, 2026

Summary of the PR

This adds support for loading ELF files on aarch64 and riscv64. While this should work just fine for Linux vmlinux images, 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.

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.

I'm opening the PR a bit unfinished to get some early feedback on whether this is functionality that is desired.

Still TODO:

  • Test booting a Linux vmlinux
  • Extend the tests
  • Write a changelog entry

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 from f121622 to 308eedc Compare May 16, 2026 22:10
Gelbpunkt added 3 commits May 17, 2026 00:22
Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
Signed-off-by: Aelin Reidel <aelin@travitia.xyz>
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>
@Gelbpunkt Gelbpunkt force-pushed the elf-aarch64-riscv64 branch from 308eedc to 1beb80f Compare May 16, 2026 22:22
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>
@Gelbpunkt Gelbpunkt force-pushed the elf-aarch64-riscv64 branch from 1beb80f to 70cb872 Compare May 16, 2026 22:24
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