[PATCH] D100489: [llvm-readobj] Fix dumping dynamic relative relocations for SHT_REL
Alexander Richardson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 15 02:38:45 PDT 2021
arichardson updated this revision to Diff 337676.
arichardson marked an inline comment as done.
arichardson added a comment.
Improve test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100489/new/
https://reviews.llvm.org/D100489
Files:
llvm/test/tools/llvm-objdump/X86/elf-dynamic-relocs-rel.test
llvm/tools/llvm-objdump/ELFDump.cpp
Index: llvm/tools/llvm-objdump/ELFDump.cpp
===================================================================
--- llvm/tools/llvm-objdump/ELFDump.cpp
+++ llvm/tools/llvm-objdump/ELFDump.cpp
@@ -74,7 +74,10 @@
const typename ELFT::Rela *ERela = Obj->getRela(Rel);
Addend = ERela->r_addend;
Undef = ERela->getSymbol(false) == 0;
- } else if ((*SecOrErr)->sh_type != ELF::SHT_REL) {
+ } else if ((*SecOrErr)->sh_type == ELF::SHT_REL) {
+ const typename ELFT::Rel *ERel = Obj->getRel(Rel);
+ Undef = ERel->getSymbol(false) == 0;
+ } else {
return make_error<BinaryError>();
}
Index: llvm/test/tools/llvm-objdump/X86/elf-dynamic-relocs-rel.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/X86/elf-dynamic-relocs-rel.test
@@ -0,0 +1,67 @@
+## Show that llvm-objdump can dump dynamic relocations for Elf_Rel relocations
+## Previously printing the R_386_RELATIVE relocations would trigger
+## error: can't read an entry at 0x40: it goes past the end of the section (0x40)
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf --section-headers --section-mapping --program-headers -r %t
+# RUN: llvm-objdump --dynamic-reloc %t | FileCheck %s
+# RUN: llvm-objdump -R %t | FileCheck %s
+
+# CHECK: file format elf32-i386
+# CHECK-LABEL: DYNAMIC RELOCATION RECORDS
+# CHECK-NEXT: 00000030 R_386_RELATIVE *ABS*
+# CHECK-NEXT: 00000010 R_386_NONE foo
+# CHECK-EMPTY:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_386
+ProgramHeaders:
+ - Type: PT_LOAD
+ FirstSec: .rel.dyn
+ LastSec: .data
+ - Type: PT_DYNAMIC
+ VAddr: 0x10
+ FirstSec: .dynamic
+ LastSec: .dynamic
+Sections:
+ - Name: .rel.dyn
+ Type: SHT_REL
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x4
+ Relocations:
+ - Offset: 0x30
+ Type: R_386_RELATIVE
+ - Offset: 0x10
+ Symbol: foo
+ Type: R_386_NONE
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Flags: [ SHF_ALLOC ]
+ Link: .dynstr
+ AddressAlign: 0x4
+ Entries:
+ - Tag: DT_REL
+ Value: 0x0
+ - Tag: DT_RELSZ
+ Value: 0x10
+ - Tag: DT_RELENT
+ Value: 0x8
+ - Tag: DT_RELCOUNT
+ Value: 0x1
+ - Tag: DT_NULL
+ Value: 0x0
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x4
+ Content: '80110000'
+Symbols:
+ - Name: foo
+ Section: .data
+DynamicSymbols:
+ - Name: foo
+ Section: .data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100489.337676.patch
Type: text/x-patch
Size: 2873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210415/4ac7e580/attachment.bin>
More information about the llvm-commits
mailing list