From 62e4fc48a58a8e1cc85d6059a380012f91da0b9c Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 15 Aug 2018 17:58:22 +0000 Subject: llvm-readobj: Fix addend in relocations for android packed format If a relocation group doesn't have the RELOCATION_GROUP_HAS_ADDEND_FLAG set, then this implies the group's addend equals zero. In this case android packed format won't encode an explicit addend delta, instead we need to set Addend, the "previous addend" variable, to zero by ourself. Patch by Yi-Yo Chiang! Differential Revision: https://reviews.llvm.org/D50601 llvm-svn: 339799 --- llvm/lib/Object/ELF.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'llvm/lib/Object/ELF.cpp') diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index 2eefb7ef13a..da56d97c4bc 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -393,20 +393,17 @@ ELFFile::android_relas(const Elf_Shdr *Sec) const { if (GroupedByAddend && GroupHasAddend) Addend += ReadSLEB(); + if (!GroupHasAddend) + Addend = 0; + for (uint64_t I = 0; I != NumRelocsInGroup; ++I) { Elf_Rela R; Offset += GroupedByOffsetDelta ? GroupOffsetDelta : ReadSLEB(); R.r_offset = Offset; R.r_info = GroupedByInfo ? GroupRInfo : ReadSLEB(); - - if (GroupHasAddend) { - if (!GroupedByAddend) - Addend += ReadSLEB(); - R.r_addend = Addend; - } else { - R.r_addend = 0; - } - + if (GroupHasAddend && !GroupedByAddend) + Addend += ReadSLEB(); + R.r_addend = Addend; Relocs.push_back(R); if (ErrStr) -- cgit v1.2.3