Skip to content

Conversation

encounter
Copy link
Contributor

@encounter encounter commented Sep 25, 2025

This is very much a work-in-progress, but opening a draft PR to get early feedback.

Open questions:

  • OMF's segment data is strange and doesn't map cleanly to the existing API. Right now, data() will attempt to return a contiguous &'data [u8] chunk if it can, but errors if the data is non-contiguous or requires expansion (LIDATA). Instead, I use the uncompressed_data API to expose the expanded/contiguous data.
    • Side note: This also doesn't map well to the CompressedData struct, which expects a contiguous, compressed data chunk as the source. The impl of uncompressed_data simply does self.compressed_data()?.decompress(), so I had to add a with_inner! for uncompressed_data so that it calls my overridden version in OmfFile.

To-do:

  • Open a separate PR to object-testfiles. (Done)
  • Improve fixup (relocation) support. The logic to map fixups into generic Absolute/Relative relocation kinds needs rethinking.
  • Add support for backpatches (possibly as a separate RelocationFlags variant?)
  • Tests need improvement; they don't really test details like certain symbols getting parsed as the correct kind, etc

Resources:

Resolves #736

@philipc
Copy link
Contributor

philipc commented Sep 26, 2025

Instead, I use the uncompressed_data API to expose the expanded/contiguous data.

That's logically what I would expect that API to return, so I think this is ok.

I don't want to change the data and compressed_data APIs to allow disjoint data just for OMF. We could add methods to OmfSection if that information is required (or maybe even add a new ObjectSection method). Do you have a need in objdiff for more than what uncompressed_data gives you?

@philipc
Copy link
Contributor

philipc commented Sep 26, 2025

I don't have any major feedback, this looks sane to me. Thanks for working on it.

For testing, the preferred approach is to run objdump on the test files and record the expected output in crates/examples/testfiles. Handwritten tests are fine for things that doesn't cover. Also readobj support in the future might help too, but it's not needed immediately.

@philipc
Copy link
Contributor

philipc commented Sep 26, 2025

For example, you can add a test using:

touch crates/examples/testfiles/omf/comprehensive_test.obj.objdump
cargo xtask test-update

then manually verify comprehensive_test.obj.objdump before adding it to git.

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.

Support OMF format object files.

2 participants