Skip to content

read/wasm: Expose data segments and linking SegmentInfo#901

Draft
lapla-cogito wants to merge 2 commits into
gimli-rs:mainfrom
lapla-cogito:wasm_seg
Draft

read/wasm: Expose data segments and linking SegmentInfo#901
lapla-cogito wants to merge 2 commits into
gimli-rs:mainfrom
lapla-cogito:wasm_seg

Conversation

@lapla-cogito

Copy link
Copy Markdown
Contributor

Object::segments() previously returned nothing for wasm files because WasmSegment and WasmSegmentIterator were stubs, and the SegmentInfo subsection of the linking custom section was never parsed.

Flags: None
Relative Address Base: 0
Entry Address: 0
Segment { name: ".rodata..L.str", address: 0, size: d, permissions: RW- }

@philipc philipc May 15, 2026

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.

My expectation is that a relocatable object file wouldn't have any segments, and the name given here looks more like a section name to me. Maybe this should be a section instead?

@philipc

philipc commented May 16, 2026

Copy link
Copy Markdown
Contributor

I'm starting to realise that the Wasm support in this crate is a little flawed. The problem is that the Wasm file structure is quite different from other file formats, and doesn't fit cleanly in the unified API. We currently treat a Wasm section as the same thing as a section in other file formats, but I don't think we should. Semantically, a Wasm section is closer to a Mach-O load command or a PE data directory entry.

In particular, for data I don't think that a Wasm data section should be exposed in the unified API. It's merely a file format container for the data segments, and it is those data segments which are closer in meaning to an object::read::ObjectSection. For a linked Wasm file, those data segments should also be an ObjectSegment (similar to what we do for PE).

For the purposes of reading a relocatable object file, ObjectSegment should never be used. A linker should only be interested in the ObjectSections; it's the job of the linker to create the segments from the sections.

So if your goal with this PR is read the Wasm data segments from a relocatable object file, then I think a different change is needed. Exposing the Wasm data segments as ObjectSegment is still good, I'm just not sure that it is solving your problem.

@lapla-cogito lapla-cogito marked this pull request as draft May 26, 2026 05:25
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.

2 participants