Skip to content

Add GOFF read/write support - #969

Open
dalvescb wants to merge 24 commits into
gimli-rs:mainfrom
dalvescb:goff-support
Open

Add GOFF read/write support#969
dalvescb wants to merge 24 commits into
gimli-rs:mainfrom
dalvescb:goff-support

Conversation

@dalvescb

@dalvescb dalvescb commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This PR adds read and write support for GOFF

Read Support

  • Sections: GOFF Element Definitions (ED) and Section Definitions (SD) are mapped to sections
  • Symbols: A subset of symbol types are exposed in ObjectSymbolTable (LD, PR, ER), this matches what we are doing in our LLVM tooling
  • Non-contiguous data: Since section/segment data is split across non-contiguous TXT records, data() returns an error directing users to uncompressed_data(), which assembles the complete section data from all contributing records.
  • Symbol Names: GOFF uses EBCDIC encoding and supports long names via continuation records. To avoid ASCII/EBCDIC conversions and lifetime issues with non-contiguous data, name() returns an error in favor of name_parts(), which returns a vec of raw byte slices that can be assembled by the caller.
  • Relocations: RLD (Relocation Directory) records are parsed and exposed as relocations with full R-pointer/P-pointer information preserved in RelocationFlags::Goff. Generic RelocationKind mapping is best-effort based on relocation flags.

Write Support

  • Complete write implementation supporting sections, symbols, relocations, and all GOFF record types (HDR, ESD, TXT, RLD, LEN, END).
  • Expects raw bytes for EBCDIC-encoded symbol names (no conversion provided)

Testing

  • Round-trip tests in tests/round_trip/goff.rs verify write/read consistency for sections, symbols, and basic relocations.
  • Relocation tests in tests/round_trip/goff_relocation.rs verify relocation parsing and reconstruction.
  • I have read tests with sample object files and objdump output, but are not included in this PR. I'll open a separate PR in testfiles to add those first

Note: you can refer to the spec here IBM z/OS GOFF Specification

@philipc

philipc commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR. I probably won't get to review this for a few days or more. You may have noticed I moved the GOFF support to an unstable feature in #962. My plan is to do an object release first, and then get this merged and do any followup work. Once that is done, we can remove the unstable requirement for GOFF and if it didn't require any breaking changes in the non-GOFF code then we can do a patch release.

However, if there is anywhere that you think it would be beneficial to have a breaking change in the non-GOFF code in order to accommodate GOFF then now is the time to do it. I didn't notice anything from a quick look through this PR. name_parts is currently only on GoffSymbol, and it may be beneficial to add that to ObjectSymbol too, but that won't be a breaking change.

It would be useful to have the fixtures in testfiles before I review this so that I can try running on some real files.

@dalvescb

Copy link
Copy Markdown
Contributor Author

Thanks for your consideration

My plan is to do an object release first, and then get this merged and do any followup work. Once that is done, we can remove the unstable requirement for GOFF and if it didn't require any breaking changes in the non-GOFF code then we can do a patch release.

Sounds good, I'll make sure to update this PR to reflect any changes that are made if necessary inbetween this and the next release

However, if there is anywhere that you think it would be beneficial to have a breaking change in the non-GOFF code in order to accommodate GOFF then now is the time to do it.

Noted, I don't believe we'll require any breaking changes to satisfy our needs. I don't see any issue with leaving name_parts as a GoffSymbol only method for our purposes.

It would be useful to have the fixtures in testfiles before I review this so that I can try running on some real files.

I've opened a PR to add sample testfiles here gimli-rs/object-testfiles#45 . If that lands ahead of time, I'll update this PR to bump the submodule and add my read tests

@philipc philipc left a comment

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.

Some comments from a quick read through, I haven't looked at anything in detail yet.

Also, there doesn't appear to be any testing of continuation records, either here or in the object-testfiles additions.

GOFF is still new and foreign to me, so please push back if I make any suggestions that don't make sense to you.

Comment thread src/read/goff/file.rs
ObjectKind::Unknown
}

fn segments(&self) -> GoffSegmentIterator<'data, '_, R> {

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.

The segments API in this crate is intended for executable files, so we probably shouldn't be returning any segments here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, I switched GoffSegmentIterator::next() to always return None (same approach currently used in xcoff)

@philipc philipc Aug 11, 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.

The ObjectSegment implementation should be changed to unreachable!(); stubs too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, stubbed

Comment thread src/read/goff/file.rs
Comment thread src/read/goff/file.rs Outdated
Comment thread src/read/goff/symbol.rs Outdated
Comment thread src/read/goff/symbol.rs Outdated
Comment thread src/goff.rs Outdated
Comment thread src/goff.rs Outdated
Comment thread src/goff.rs Outdated
Comment thread src/read/goff/file.rs Outdated
Comment thread src/read/goff/relocation.rs
@dalvescb
dalvescb requested a review from philipc August 10, 2026 21:11
Comment thread tests/round_trip/goff.rs
Comment thread tests/round_trip/goff.rs Outdated
Comment thread src/read/goff/file.rs Outdated

let goffsymbol = GoffSymbol {
symbol_index: symbolindex,
esdid: esdid,

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.

Suggested change
esdid: esdid,
esdid,

There's a few other clippy warnings too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All clippy warnings warnings are fixed now

Comment thread tests/round_trip/goff.rs
}

#[test]
fn goff_relocation_multiple() {

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.

It would be good to test continuation records for these too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a new test specifically for triggering continuation records for relocations here, and a small fix in the writer

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.

Needs fmt.

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.

What testing have you done besides what is in this PR? I'm guessing the relocation writing code path isn't actually used for your purposes (which is fine, I just need know where things stand).

Comment thread src/common.rs Outdated
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