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,62 @@ 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 0x90 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: .rel.dyn + Type: SHT_REL + 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 +## 0x18 == offset of .rel.dyn == size of .rela.dyn section. + - Tag: DT_REL + Value: 0x18 + - 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: .rel.dyn + - Section: .dynamic Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -6401,14 +6401,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; @@ -6416,6 +6416,8 @@ Rela.r_addend = 0; printDynamicRelocation(Obj, Rela); } + } + if (DynRelrRegion.Size > 0) { Elf_Relr_Range Relrs = this->dumper()->dyn_relrs(); std::vector RelrRelas =