Skip to content

Fix mach-o file vs segment size#124985

Closed
jkoritzinsky wants to merge 2 commits intodotnet:mainfrom
jkoritzinsky:macho-file-size
Closed

Fix mach-o file vs segment size#124985
jkoritzinsky wants to merge 2 commits intodotnet:mainfrom
jkoritzinsky:macho-file-size

Conversation

@jkoritzinsky
Copy link
Member

Make sure that segment vmsize is never smaller than segment file size

Fixes #124982

cc: @filipnavara

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Mach-O validity issues in Crossgen2 composite R2R output by ensuring the first LC_SEGMENT_64 load command reports consistent segment sizes so Mach-O inspection tools (e.g., llvm-objdump, otool) don’t reject the file.

Changes:

  • Updates Mach-O section layout logic to ensure the segment vmsize is not smaller than the segment filesize.

@filipnavara
Copy link
Member

filipnavara commented Feb 27, 2026

This doesn't look right. However, I admit that the calculation for segmentFileSize also doesn't look right to me since it never subtracts the initial file offset (of the first section that is marked as InFile).

@filipnavara
Copy link
Member

filipnavara commented Feb 27, 2026

I suppose the correct fix would look something like this:
filipnavara@3bbbd9c229a

(on second thought, maybe the initial offset should be the aligned one, so maybe more like filipnavara@c48520c4d77)

@jkoritzinsky
Copy link
Member Author

I suppose the correct fix would look something like this: filipnavara@3bbbd9c229a

(on second thought, maybe the initial offset should be the aligned one, so maybe more like filipnavara@c48520c4d77)

I took your second fix

@filipnavara
Copy link
Member

This is almost correct. I just forgot that now we also need to update the segmentFileOffset (https://github.com/jkoritzinsky/runtime/blob/6b21a40967681ec4cb792600d80e0f0943cb1928/src/coreclr/tools/Common/Compiler/ObjectWriter/MachObjectWriter.cs#L205) with the correctly aligned value that we computed in the initialFileOffset variable.

I can submit a full tested fix tomorrow unless you beat me to it. Sorry for the hassle and not catching this right away.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Crossgen2 Mach-O R2R output has LC_SEGMENT_64 filesize > vmsize, rejected by llvm-objdump/otool

3 participants