This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][MachO] Avoid accidental invalid relocations in tests
ClosedPublic

Authored by alexander-shaposhnikov on Apr 26 2020, 11:58 PM.

Details

Summary

Until recently yaml2obj didn't properly support relocations for MachO and whenever it saw nreloc != 0 and reloff != 0 it was populating those bytes with 0s. This behavior results in binaries having invalid relocations, e.g. if r_extern == 0 then r_symbolnum should be >= 1 (because in this case r_symbolnum is supposed to be an index of a section and for MachO section indices start from 1), but it's equal to 0.
In this diff we adjust the existing tests (for the tests which don't actually look at any relocations at all - we remove them
(this causes the binary to shrink a little bit), for the tests which essentially depend on relocations - we fix them).
This change is a preparation to unblock https://reviews.llvm.org/D71647 .

Test plan: make check-all

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: abrachet. · View Herald Transcript
alexander-shaposhnikov edited the summary of this revision. (Show Details)Apr 26 2020, 11:59 PM
alexander-shaposhnikov edited the summary of this revision. (Show Details)Apr 27 2020, 12:06 AM

This seems reasonable to me, although without a fuller Mach-O understanding, I can't verify what you're describing makes sense, so I'll leave somebody else to review.

smeenai accepted this revision.Apr 27 2020, 2:23 PM

LGTM

llvm/test/tools/llvm-objcopy/MachO/Inputs/strip-all-with-dwarf.yaml
46

I don't think it makes much difference for this test, but would it be better/more realistic to have some of these pointing to different symbols?

This revision is now accepted and ready to land.Apr 27 2020, 2:23 PM
alexander-shaposhnikov marked an inline comment as done.Apr 27 2020, 2:26 PM
alexander-shaposhnikov added inline comments.
llvm/test/tools/llvm-objcopy/MachO/Inputs/strip-all-with-dwarf.yaml
46

sure, we can do that

This revision was automatically updated to reflect the committed changes.