aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/ELF/Object.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-03-24 13:31:08 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-03-24 13:31:08 +0000
commit0a5d4b84724395ae0522235db474e2dba4d9f6e4 (patch)
treef7b9c92a1d66ea754712303e6f899cd18d5fcb32 /llvm/tools/llvm-objcopy/ELF/Object.cpp
parent977934f00f7cac6476650db75f6497495908b486 (diff)
downloadllvm-0a5d4b84724395ae0522235db474e2dba4d9f6e4.zip
llvm-0a5d4b84724395ae0522235db474e2dba4d9f6e4.tar.gz
llvm-0a5d4b84724395ae0522235db474e2dba4d9f6e4.tar.bz2
[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 llvm-svn: 356853
Diffstat (limited to 'llvm/tools/llvm-objcopy/ELF/Object.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/ELF/Object.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp
index ccc6efa..39bee85 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -949,6 +949,9 @@ template <class ELFT> void ELFBuilder<ELFT>::readProgramHeaders() {
template <class ELFT>
void ELFBuilder<ELFT>::initGroupSection(GroupSection *GroupSec) {
+ if (GroupSec->Align % sizeof(ELF::Elf32_Word) != 0)
+ error("Invalid alignment " + Twine(GroupSec->Align) + " of group section " +
+ GroupSec->Name);
auto SecTable = Obj.sections();
auto SymTab = SecTable.template getSectionOfType<SymbolTableSection>(
GroupSec->Link,