This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho][test] Make reloc-subtractor.s robust
ClosedPublic

Authored by MaskRay on Jun 20 2023, 3:24 PM.

Details

Summary

The test requires that LLVM integreated assembler generates
SUBTRACTOR/UNSIGNED relocations for .long _minuend_1 - _subtrahend_1.
This currently works by luck because:

  • _minuend_1 and _subtrahend_1 are in different fragments (separated by a MCFillFragment)
  • and the result is known to be negative at parsing time.

D153096 will change the assembler to fold .long _minuend_1 - _subtrahend_1 to
a constant, giving ld -order_file no chance to change the result.

To fix the test, move the referenced labels after the label differences to block
constant folding.

Note: you may think the model is somewhat broken and it is. The
.subsections_via_symbols mechanism does not block such constant folding. In
reality SUBTRACTOR/UNSIGNED is for references to another section, which does not
have the problem.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 20 2023, 3:24 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 20 2023, 3:24 PM
MaskRay requested review of this revision.Jun 20 2023, 3:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2023, 3:24 PM
smeenai accepted this revision.Jun 20 2023, 4:16 PM

LGTM

lld/test/MachO/reloc-subtractor.s
52

Is it important to repeat the .section directive?

This revision is now accepted and ready to land.Jun 20 2023, 4:16 PM
MaskRay added inline comments.Jun 20 2023, 8:48 PM
lld/test/MachO/reloc-subtractor.s
52

Yes, the above check lines test this...
# CHECK: {{0*}}[[#%x, SUB1ADDR:]] l {{.*}} __DATA,bar _sub1

This revision was automatically updated to reflect the committed changes.
smeenai added inline comments.Jun 21 2023, 11:05 AM
lld/test/MachO/reloc-subtractor.s
52

I meant that we already have a .section __DATA,bar above _sub1, so do we need to issue that directive again here?

MaskRay added inline comments.Jun 21 2023, 11:09 AM
lld/test/MachO/reloc-subtractor.s
52

Sorry, I missed this. I think this .section __DATA,bar directive can be removed.

smeenai added inline comments.Jun 21 2023, 4:17 PM
lld/test/MachO/reloc-subtractor.s
52

Thanks, I pushed rGb1dadab3d9e3