Page MenuHomePhabricator

[lld-macho] Fix segment filesize calculation
ClosedPublic

Authored by int3 on Jul 24 2020, 6:22 PM.

Details

Reviewers
compnerd
Group Reviewers
Restricted Project
Commits
rGd32e32500f92: [lld-macho] Fix segment filesize calculation
Summary

The previous approach of adding up the file sizes of the
component sections ignored the fact that the sections did not have to be
contiguous in the file. As such, it was underestimating the true size.

I discovered this issue because codesign checks whether __LINKEDIT
extends to the end of the file. Since we were underestimating segment
sizes, this check failed.

Diff Detail

Event Timeline

int3 created this revision.Jul 24 2020, 6:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2020, 6:22 PM
pcc added a subscriber: pcc.Jul 24 2020, 6:39 PM

I think you can use wc -c. See e.g. clang/test/Modules/rebuild.m.

int3 updated this revision to Diff 280651.Jul 24 2020, 7:40 PM

add test for total file size

int3 marked an inline comment as done.Jul 24 2020, 7:41 PM

Thanks @pcc!

lld/test/MachO/segments.s
9–15

I should have made these CHECK-NEXT from the start...

int3 edited the summary of this revision. (Show Details)Jul 24 2020, 7:41 PM
compnerd accepted this revision.Jul 27 2020, 3:14 PM
compnerd added a subscriber: compnerd.

I think that the assert would be better than the comment, but not worth blocking on.

lld/MachO/Writer.cpp
137–141

I wonder if that should just be an assert instead.

This revision is now accepted and ready to land.Jul 27 2020, 3:14 PM
int3 updated this revision to Diff 281095.Jul 27 2020, 6:17 PM
int3 marked 2 inline comments as done.

use assert

lld/MachO/Writer.cpp
137–141

Agreed :)

This revision was landed with ongoing or failed builds.Jul 28 2020, 10:02 AM
This revision was automatically updated to reflect the committed changes.