[PATCH] D83232: [llvm-readobj] - Don't abort when dumping dynamic relocations when an object has both REL and RELA.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 12:54:13 PDT 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Currently, llvm-readobj calls `report_fatal_error` when an object has
both REL and RELA dynamic relocations.
llvm-readelf is able to handle this case properly. This patch adds such a test case
and adjusts the llvm-readobj code to follow (and be consistent with its own RELR and PLTREL cases).
https://reviews.llvm.org/D83232
Files:
llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6362,14 +6362,14 @@
const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion();
const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion();
const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion();
- if (DynRelRegion.Size && DynRelaRegion.Size)
- report_fatal_error("There are both REL and RELA dynamic relocations");
+
W.startLine() << "Dynamic Relocations {\n";
W.indent();
- if (DynRelaRegion.Size > 0)
+ if (DynRelaRegion.Size > 0) {
for (const Elf_Rela &Rela : this->dumper()->dyn_relas())
printDynamicRelocation(Obj, Rela);
- else
+ }
+ if (DynRelRegion.Size > 0) {
for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) {
Elf_Rela Rela;
Rela.r_offset = Rel.r_offset;
@@ -6377,6 +6377,8 @@
Rela.r_addend = 0;
printDynamicRelocation(Obj, Rela);
}
+ }
+
if (DynRelrRegion.Size > 0) {
Elf_Relr_Range Relrs = this->dumper()->dyn_relrs();
std::vector<Elf_Rela> RelrRelas =
Index: llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
+++ llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
@@ -463,3 +463,56 @@
Sections:
- Section: .rela.dyn
- Section: .dynamic
+
+## Show that when we have both REL and RELA relocations, we dump both sets.
+# RUN: yaml2obj --docnum=13 %s -o %t13
+# RUN: llvm-readobj --dyn-relocations %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=BOTH-RELA-REL-LLVM
+# RUN: llvm-readelf --dyn-relocations %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=BOTH-RELA-REL-GNU
+
+# BOTH-RELA-REL-LLVM: Dynamic Relocations {
+# BOTH-RELA-REL-LLVM-NEXT: 0x0 R_X86_64_NONE - 0x0
+# BOTH-RELA-REL-LLVM-NEXT: 0x0 R_X86_64_NONE - 0x0
+# BOTH-RELA-REL-LLVM-NEXT: }
+
+# BOTH-RELA-REL-GNU: 'RELA' relocation section at offset 0x78 contains 24 bytes:
+# BOTH-RELA-REL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
+# BOTH-RELA-REL-GNU-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 0
+# BOTH-RELA-REL-GNU-EMPTY:
+# BOTH-RELA-REL-GNU: 'REL' relocation section at offset 0x78 contains 16 bytes:
+# BOTH-RELA-REL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
+# BOTH-RELA-REL-GNU-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .rela.dyn
+ Type: SHT_RELA
+ Relocations:
+ - Type: R_X86_64_NONE
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Entries:
+ - Tag: DT_RELA
+ Value: 0x0
+ - Tag: DT_RELASZ
+ Value: 0x18
+ - Tag: DT_RELAENT
+ Value: 0x18
+ - Tag: DT_REL
+ Value: 0x0
+ - Tag: DT_RELSZ
+ Value: 0x10
+ - Tag: DT_RELENT
+ Value: 0x10
+ - Tag: DT_NULL
+ Value: 0x0
+DynamicSymbols: []
+ProgramHeaders:
+ - Type: PT_LOAD
+ Sections:
+ - Section: .rela.dyn
+ - Section: .dynamic
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83232.275722.patch
Type: text/x-patch
Size: 3421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200706/de43f380/attachment-0001.bin>
More information about the llvm-commits
mailing list