[PATCH] D15965: Add support for dumping relocations in non-relocatable files

Colin LeMahieu via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 7 12:22:19 PST 2016


colinl created this revision.
colinl added a reviewer: rafael.
colinl added a subscriber: llvm-commits.
colinl set the repository for this revision to rL LLVM.

Relocations can be in non-relocatable files by linking with --emit-relocs.  This removes the associated violated assertion in ELFObjectFile and removes the short-circuit return in llvm-objdump.  The comment says objdump doesn't print out these relocations though this isn't correct.  Using the associated test file it's seen GNU objdump indeed prints out these relocations.

Repository:
  rL LLVM

http://reviews.llvm.org/D15965

Files:
  include/llvm/Object/ELFObjectFile.h
  test/tools/llvm-objdump/Inputs/relocations-in-nonrelocatable.elf-hexagon
  test/tools/llvm-objdump/relocations-in-nonrelocatable.test
  tools/llvm-objdump/llvm-objdump.cpp

Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -1154,11 +1154,6 @@
 void llvm::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;
-
   for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
     if (Section.relocation_begin() == Section.relocation_end())
       continue;
Index: test/tools/llvm-objdump/relocations-in-nonrelocatable.test
===================================================================
--- test/tools/llvm-objdump/relocations-in-nonrelocatable.test
+++ test/tools/llvm-objdump/relocations-in-nonrelocatable.test
@@ -0,0 +1,4 @@
+// This test checks that relocation in nonrelocatable files are printed
+// RUN: llvm-objdump -r %p/Inputs/relocations-in-nonrelocatable.elf-hexagon | FileCheck %s
+
+CHECK: 00000080 R_HEX_HI16 hexagon_pre_main
Index: include/llvm/Object/ELFObjectFile.h
===================================================================
--- include/llvm/Object/ELFObjectFile.h
+++ include/llvm/Object/ELFObjectFile.h
@@ -683,8 +683,6 @@
 
 template <class ELFT>
 uint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const {
-  assert(EF.getHeader()->e_type == ELF::ET_REL &&
-         "Only relocatable object files have relocation offsets");
   const Elf_Shdr *sec = getRelSection(Rel);
   if (sec->sh_type == ELF::SHT_REL)
     return getRel(Rel)->r_offset;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15965.44248.patch
Type: text/x-patch
Size: 1717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160107/00b688d8/attachment.bin>


More information about the llvm-commits mailing list