This is an archive of the discontinued LLVM Phabricator instance.

Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
ClosedPublic

Authored by silvas on Feb 4 2016, 1:21 PM.

Details

Summary

LLVM3.3 (and earlier) would fail to include a relocation section in
the group that the section it was relocating is in. Object files
affected by this issue have been encountered in the wild when using LLD.

This would result in a siutation like:

Section {
  Index: 5
  Name: .text._Z3fooIiEvv (6)
  Type: SHT_PROGBITS (0x1)
  Flags [ (0x206)
    SHF_ALLOC (0x2)
    SHF_EXECINSTR (0x4)
    SHF_GROUP (0x200)
  ]
  Address: 0x0
  Offset: 0x48
  Size: 5
  Link: 0
  Info: 0
  AddressAlignment: 1
  EntrySize: 0
}
Section {
  Index: 6
  Name: .rela.text._Z3fooIiEvv (1)
  Type: SHT_RELA (0x4)
  Flags [ (0x0)
  ]
  Address: 0x0
  Offset: 0x3F0
  Size: 24
  Link: 8
  Info: 5
  AddressAlignment: 8
  EntrySize: 24
}

In LLD, during symbol resolution, we discard the section containing the
weak symbol, but this amounts to replacing it with
InputSection<ELFT>::Discarded.
When we later saw the corresponding relocation section, we would then
end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is
bogus.

Diff Detail

Repository
rL LLVM

Event Timeline

silvas updated this revision to Diff 46954.Feb 4 2016, 1:21 PM
silvas retitled this revision from to Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections.
silvas updated this object.
silvas added reviewers: ruiu, rafael.
silvas added a subscriber: Bigcheese.
ruiu accepted this revision.Feb 4 2016, 1:29 PM
ruiu edited edge metadata.

LGTM

ELF/InputFiles.cpp
217–218 ↗(On Diff #46954)

It is better to add a brief comment saying that relocations and relocated sections must be in the same section group, so this is strictly speaking bogus file, but we want to handle that because LLVM 3.3 and earlier creates such file.

This revision is now accepted and ready to land.Feb 4 2016, 1:29 PM
This revision was automatically updated to reflect the committed changes.