This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] - Allow relocation sections to appear before their target sections.
ClosedPublic

Authored by grimar on Jul 9 2020, 3:16 AM.

Details

Summary

It allows handling cases when we have SHT_REL[A] sections before target
sections in objects.

This fixes https://bugs.llvm.org/show_bug.cgi?id=46632

which says: "Normally it is not what compilers would emit. We have to support it,
because some custom tools might want to use this feature, which is not restricted by ELF gABI"
GNU ld supports this as well.

Diff Detail

Event Timeline

grimar created this revision.Jul 9 2020, 3:16 AM
grimar planned changes to this revision.Jul 9 2020, 3:23 AM

Going to update. I've missed a failture in a test.

grimar updated this revision to Diff 276690.Jul 9 2020, 3:28 AM
  • Remove outdated test.
  • Test SHT_REL case too.

Looks fine to me, just comments that need updating.

lld/ELF/InputFiles.cpp
644–650

the -> a

646

I would say "create SHT_REL[A} sections. In some cases relocated sections may follow the corresponding relocation section. In such a case, the relocation section would attempt to reference a target section that has not yet been created. For simplicity, delay creation of relocation sections until now."

656

I think this comment is probably superfluous - the code is simple enough to show it.

660

I think you can delete this comment. It's fairly obvious that the rest is to do with SHF_LINK_ORDER, owing to the if statement.

grimar updated this revision to Diff 276703.Jul 9 2020, 4:35 AM
grimar marked 4 inline comments as done.
  • Addressed review comments.
jhenderson accepted this revision.Jul 9 2020, 4:39 AM

LGTM (with nits), but I'd like a second opinion from somebody with fresher LLD knowledge.

lld/ELF/InputFiles.cpp
646

Typo? '}' -> ']'

647

Oops, my bad: "a case" -> "cases"

This revision is now accepted and ready to land.Jul 9 2020, 4:39 AM

Looks good. Some comment suggestions.

lld/ELF/InputFiles.cpp
646

... the section header index of a relocation section may be smaller than that of the relocated section

lld/test/ELF/reloc-sec-before-target.test
1

If the section header index of a SHT_REL[A] section is smaller than the section header index of the relocated section

1

reloc-sec-before-relocated.test might be a better name.

(target -> relocated)

3

We have to support it, because some custom tools might want to use this feature, which is not restricted by ELF gABI.

Worth mentioning that GNU ld supports this as well.

MaskRay added inline comments.Jul 9 2020, 10:09 AM
lld/test/ELF/reloc-sec-before-target.test
3

This should also be mentioned in the description.

grimar updated this revision to Diff 276957.Jul 10 2020, 2:12 AM
grimar marked 7 inline comments as done.
grimar edited the summary of this revision. (Show Details)
  • Addressed review comments.
MaskRay accepted this revision.Jul 10 2020, 8:34 AM

Thanks!

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2020, 4:00 AM
lld/ELF/InputFiles.cpp