Skip to content

Make std.elf usable at comptime by removing *File.Reader dependency #24666

@GiuseppeCesarano

Description

@GiuseppeCesarano

As things stand, std.elf could be used to parse ELF files at comptime, if not for the argument types of std.elf.Header.iterateSectionHeaders and std.elf.Header.iterateProgramHeaders. Both functions require a *std.fs.File.Reader, which can only be created from an actual file. This prevents their use in comptime contexts.

The only real blocker is the seekTo requirement. If the code accepted a generic reader instead, it could be used independently of files and work at comptime as well.

I have a concrete use case: I'm writing a BPF program loader where the BPF program itself is written and compiled in Zig. If the loader could read the resulting ELF at comptime, it could extract BTF info and generate types from it during compilation.

I'm willing to submit a PR if this change is accepted, but I’d need guidance, mainly on whether a generic seekable reader abstraction exists, or how that should be represented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions