This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Fix a padding bug in the old Mach-O backend in LLD.
ClosedPublic

Authored by sheredom on Jul 5 2021, 5:22 AM.

Details

Reviewers
lhames
int3
Group Reviewers
Restricted Project
Summary

This commit fixes a bug with the old Mach-O backend, where it is
possible for a header to be written that does not contain enough
space for the UUID and codesign sections to be present.

To fix it, we simply add a padding to the header to ensure there is
always enough space.

Note: this bug is not present in the new Mach-O backend, but
we couldn't use that for other reasons.

Diff Detail

Event Timeline

sheredom created this revision.Jul 5 2021, 5:22 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptJul 5 2021, 5:22 AM
sheredom requested review of this revision.Jul 5 2021, 5:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2021, 5:22 AM
tschuett added inline comments.
lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
264

could that be something like headerPad = sizeof(xxx) + sizeof(yyy)?

sheredom added inline comments.Jul 5 2021, 8:02 AM
lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
264

I can't find anything in LLD that states the size of these sections (although from binary inspecting we could tell we needed 16 + 24 bytes).

thakis added a subscriber: thakis.Jul 5 2021, 4:52 PM

Can you share the other reasons? From what I understand, the plan is to delete the old backend eventually, so it'd be good to fix problems in the new one :)

Can you share the other reasons? From what I understand, the plan is to delete the old backend eventually, so it'd be good to fix problems in the new one :)

Sure! It was all Apple Silicon related -> I just assumed that whatever was broken was being worked on as the new backend was spun up, and it'd automagically be fixed by the time we needed to use it!

thakis added a comment.Jul 6 2021, 8:22 PM

Is it still broken on master? Apple Silicon should work fairly well by now.

lhames accepted this revision.Jul 7 2021, 5:37 AM

@thakis is right that we should make sure this works in the new MachO LLD.

That said I have no problem with this being added to the old one in the interim. LGTM.

This revision is now accepted and ready to land.Jul 7 2021, 5:37 AM

@smeenai and I were discussing the possibility of deleting the old Mach-O backend soon, now that the new one is more or less ready. Will that be an issue for you @sheredom? (I don't know what Apple Silicon issues you were running into, so I'm not sure if they're fixed in the new one...)

@sheredom Following up on here. Any plans to migrate off the old MachO port over to the new port? I would also love to learn more about what some of the problems are for migrating over to the new MachO port. Part of doing this is also out of selfish reasons as it's been messing up with my IDE and harder for newer devs to ramp up on the new LLD for Mach-O.

int3 resigned from this revision.Jan 31 2022, 1:08 PM

we've deleted the old mach-o backend, so this can probably be abandoned

MaskRay closed this revision.Jan 31 2022, 1:40 PM