Skip to content

fix: zero-fill NOBITS sections in ELF loader#1379

Open
ludfjig wants to merge 1 commit intohyperlight-dev:mainfrom
ludfjig:elf-nobits-fix
Open

fix: zero-fill NOBITS sections in ELF loader#1379
ludfjig wants to merge 1 commit intohyperlight-dev:mainfrom
ludfjig:elf-nobits-fix

Conversation

@ludfjig
Copy link
Copy Markdown
Contributor

@ludfjig ludfjig commented Apr 15, 2026

Some linkers emit PT_LOAD segments where filesz == memsz but contain .bss sections whose VMA range overlaps with file bytes from unrelated sections. The loader copies the full segment verbatim, leaving .bss with stale data instead of zeros.

Collect NOBITS section ranges (excluding .tbss) during ELF parsing and zero-fill them after loading PT_LOAD segments.

This is needed for unikraft

Some linkers emit PT_LOAD segments where filesz == memsz but contain
.bss sections whose VMA range overlaps with file bytes from unrelated
sections. The loader copies the full segment verbatim, leaving .bss
with stale data instead of zeros.

Collect NOBITS section ranges (excluding .tbss) during ELF parsing and
zero-fill them after loading PT_LOAD segments.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>

Co-authored-by: danbugs <danilochiarlone@gmail.com>
@ludfjig ludfjig added the kind/bugfix For PRs that fix bugs label Apr 15, 2026
@ludfjig ludfjig marked this pull request as ready for review April 15, 2026 03:07
This was referenced Apr 15, 2026
// Zero-fill NOBITS sections (e.g. .bss) that were not already
// covered by the filesz < memsz zeroing above.
for &(addr, size) in &self.nobits_ranges {
let sh_start = (addr - base_va) as usize;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I am not sure if it can happen, but is this guaranteed to not fail? Maybe a checked sub is better here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix For PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants