Page MenuHomePhabricator

[llvm-objcopy] - Report SHT_GROUP sections with invalid alignment.
ClosedPublic

Authored by grimar on Mar 22 2019, 6:56 AM.

Details

Summary

This patch fixes the reason of ubsan failure happened after landing the D59638 (I had to revert it).
(http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/11760/steps/check-llvm%20ubsan/logs/stdio)

Problem is the following. Our implementation of GroupSection assumes that
its address is 4 bytes aligned when writes it:

template <class ELFT>
void ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) {
  ELF::Elf32_Word *Buf =
      reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset);
...

But the test case for D59638 did not set AddressAlign in YAML. So address was
not aligned because Sec.Offset was odd. That triggered the issue.

Since such group sections should not be met in reality (I think), I would suggest to ban them.
This patch does that.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Mar 22 2019, 6:56 AM
rupprecht accepted this revision.Mar 22 2019, 11:54 AM

Since such group sections should not be met in reality (I think), I would suggest to ban them.
This patch does that.

Given the code snippet you included in ELFSectionWriter, it sounds like even if they *are* met in reality, llvm-objcopy is already broken. Having a specific error instead of a cryptic misaligned write crash seems more useful.

This revision is now accepted and ready to land.Mar 22 2019, 11:54 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2019, 6:31 AM