[llvm] r334147 - llvm-readobj: fix printing number of relocations in Android packed format.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 6 17:02:07 PDT 2018
Author: pcc
Date: Wed Jun 6 17:02:07 2018
New Revision: 334147
URL: http://llvm.org/viewvc/llvm-project?rev=334147&view=rev
Log:
llvm-readobj: fix printing number of relocations in Android packed format.
With '-elf-output-style=GNU -relocations', a header containing the number
of entries is printed before all the relocation entries in the section.
For Android packed format, we need to perform the unpacking first before
we can get the actual number of relocations in the section.
Patch by Rahul Chaudhry!
Differential Revision: https://reviews.llvm.org/D47800
Modified:
llvm/trunk/test/tools/llvm-readobj/elf-packed-relocs.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/elf-packed-relocs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-packed-relocs.test?rev=334147&r1=334146&r2=334147&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-packed-relocs.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-packed-relocs.test Wed Jun 6 17:02:07 2018
@@ -14,6 +14,7 @@
# LLVM1-NEXT: }
# RUN: yaml2obj -docnum 1 %s | llvm-readobj -elf-output-style=GNU -relocations - | FileCheck --check-prefix=GNU1 %s
+# GNU1: Relocation section '.rela.dyn' at offset 0x180 contains 8 entries:
# GNU1: 0000000000001100 0000000000000008 R_X86_64_RELATIVE 0
# GNU1-NEXT: 0000000000001180 0000000000000008 R_X86_64_RELATIVE 0
# GNU1-NEXT: 0000000000001188 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0
@@ -60,6 +61,7 @@ Symbols:
# LLVM2-NEXT: }
# RUN: yaml2obj -docnum 2 %s | llvm-readobj -elf-output-style=GNU -relocations - | FileCheck --check-prefix=GNU2 %s
+# GNU2: Relocation section '.rel.dyn' at offset 0xfc contains 10 entries:
# GNU2: 00001008 00000101 R_386_32 00000000 sym1
# GNU2-NEXT: 00001010 00000203 R_386_GOT32 00000000 sym2
# GNU2-NEXT: 0000100c 00000008 R_386_RELATIVE
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=334147&r1=334146&r2=334147&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Wed Jun 6 17:02:07 2018
@@ -2641,6 +2641,14 @@ template <class ELFT> void GNUStyle<ELFT
HasRelocSections = true;
StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
unsigned Entries = Sec.getEntityCount();
+ std::vector<Elf_Rela> AndroidRelas;
+ if (Sec.sh_type == ELF::SHT_ANDROID_REL ||
+ Sec.sh_type == ELF::SHT_ANDROID_RELA) {
+ // Android's packed relocation section needs to be unpacked first
+ // to get the actual number of entries.
+ AndroidRelas = unwrapOrError(Obj->android_relas(&Sec));
+ Entries = AndroidRelas.size();
+ }
uintX_t Offset = Sec.sh_offset;
OS << "\nRelocation section '" << Name << "' at offset 0x"
<< to_hexString(Offset, false) << " contains " << Entries
@@ -2665,7 +2673,7 @@ template <class ELFT> void GNUStyle<ELFT
break;
case ELF::SHT_ANDROID_REL:
case ELF::SHT_ANDROID_RELA:
- for (const auto &R : unwrapOrError(Obj->android_relas(&Sec)))
+ for (const auto &R : AndroidRelas)
printRelocation(Obj, SymTab, R, Sec.sh_type == ELF::SHT_ANDROID_RELA);
break;
}
More information about the llvm-commits
mailing list