From f80a4321ef1bafcd8041884bcb85d9ba24335adb Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 1 Jul 2022 09:08:42 -0700 Subject: [llvm-objdump] -r: print non-SHF_ALLOC relocations for non-ET_REL files ET_EXEC and ET_DYN files may contain non-SHF_ALLOC relocation sections (e.g. ld --emit-relocs). Match GNU objdump by dumping them. * Remove Object/dynamic-reloc.test. Replace it with a -r RUN line in dynamic-relocs.test * Update relocations-in-nonreloc.test to set sh_link/sh_info. GNU objdump seems to ignore a SHT_REL/SHT_RELA section not linking to SHT_SYMTAB. The test did not test what it intended to test. Fix https://github.com/llvm/llvm-project/issues/41246 Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D128959 --- llvm/tools/llvm-objdump/llvm-objdump.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp') diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 132320a..dc7083b 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1780,10 +1780,6 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { void objdump::printRelocations(const ObjectFile *Obj) { StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; - // Regular objdump doesn't print relocations in non-relocatable object - // files. - if (!Obj->isRelocatableObject()) - return; // Build a mapping from relocation target to a vector of relocation // sections. Usually, there is an only one relocation section for @@ -1791,6 +1787,8 @@ void objdump::printRelocations(const ObjectFile *Obj) { MapVector> SecToRelSec; uint64_t Ndx; for (const SectionRef &Section : ToolSectionFilter(*Obj, &Ndx)) { + if (Obj->isELF() && (ELFSectionRef(Section).getFlags() & ELF::SHF_ALLOC)) + continue; if (Section.relocation_begin() == Section.relocation_end()) continue; Expected SecOrErr = Section.getRelocatedSection(); -- cgit v1.1