Make ELF loading respect program header virtual addresses for non-PIE binaries#1530
Make ELF loading respect program header virtual addresses for non-PIE binaries#1530cshung wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds support for running and testing non-PIE Rust guest binaries, including updating snapshot virtual-address mapping so non-PIE guests execute at their declared ELF virtual addresses.
Changes:
- Add a helper in
hyperlight_testingto locate the non-PIEsimpleguestbinary. - Update snapshot mapping/entrypoint calculation to support non-identity VA mappings for non-PIE code regions.
- Add a new integration test and build automation (Justfile) to produce and run a non-PIE guest.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/hyperlight_testing/src/lib.rs | Adds path helper(s) for locating non-PIE Rust guest binaries. |
| src/hyperlight_host/tests/integration_test.rs | Adds an integration test that boots and calls into a non-PIE guest. |
| src/hyperlight_host/src/sandbox/snapshot/mod.rs | Adjusts snapshot mappings and entrypoint VA calculation to support non-PIE guests. |
| Justfile | Adds tasks to build and stage non-PIE Rust guest artifacts. |
For non-PIE binaries (ET_EXEC), the page table now maps the code region at the ELF's declared virtual address rather than identity mapping at the GPA. The entrypoint is computed correctly as a GVA. PIE binaries (base_va == 0) continue to use identity mapping, preserving existing behavior. Also adds build infrastructure and integration test for non-PIE guests: - Justfile: build-rust-guests-non-pie target builds simpleguest with static relocation model and --image-base=0x200000 - hyperlight_testing: add simple_guest_non_pie_as_string() path helper - integration_test: non_pie_guest_hello_world exercises full guest lifecycle (init, COW, function call) with absolute addresses Contributes to: hyperlight-dev#1408 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
7468e06 to
40c43be
Compare
|
Addressed Copilot review feedback:
|
Summary
For non-PIE (ET_EXEC) ELF binaries, the guest page table now maps the code region at the ELF's declared virtual address rather than identity-mapping it at the GPA. This allows statically-linked binaries with a fixed load address (e.g.,
--image-base=0x200000) to execute correctly.Problem
Previously, Hyperlight assumed code GVA == code GPA (identity mapping). Non-PIE binaries that declare a non-zero base virtual address (via program header
p_vaddr) would triple-fault because the guest CPU jumped to the ELF's declared entrypoint VA, which wasn't mapped in the page tables.Solution
code_virt_basefrom the ELF's lowest LOAD segmentp_vaddrbase_va > 0): map code at the declared VA in the guest page tablesbase_va == 0): preserve existing identity mapping behavior (with assertion to guard the invariant)code_virt_base + (entrypoint_va - base_va)The fix leverages the existing
Mappingstruct's support forphys_base != virt_base— no changes to the page table code itself.Testing
non_pie_guest_hello_worldintegration test exercises full guest lifecycle (init, COW, function call, return value) with a non-PIE simpleguest built at--image-base=0x200000Build infrastructure
build-rust-guests-non-pieJustfile targetsguestsrecipe to avoid clobbering normal guest binariessimple_guest_non_pie_as_string()test helperContributes to: #1408