]> granicus.if.org Git - llvm/commit
[llvm-objcopy] - Report SHT_GROUP sections with invalid alignment.
authorGeorge Rimar <grimar@accesssoftek.com>
Sun, 24 Mar 2019 13:31:08 +0000 (13:31 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Sun, 24 Mar 2019 13:31:08 +0000 (13:31 +0000)
commit8b8a0a78353b4378d7ddb0d586da3436e3fb2a54
treee8cfc80bf260ca38abfc0c2db9ae46d884b84e67
parent61d184be59671c4ff5395a6a3c0704323a000938
[llvm-objcopy] - Report SHT_GROUP sections with invalid alignment.

This patch fixes the reason of ubsan failure (UB detected)
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 4 bytes aligned since Sec.Offset was odd. That triggered the issue.

This patch teaches llvm-objcopy to report an error for such sections (which should
not met in reality), what is better than having UB.

Differential revision: https://reviews.llvm.org/D59695

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356853 91177308-0d34-0410-b5e6-96231b3b80d8
test/tools/llvm-objcopy/ELF/group-addr-misaligned.test [new file with mode: 0644]
tools/llvm-objcopy/ELF/Object.cpp