[PATCH] D60250: [llvm-objdump] Allow -dynamic-reloc on ET_EXEC files

Chih-Mao Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 3 22:42:05 PDT 2019


PkmX created this revision.
PkmX added reviewers: jhenderson, paulsemel, echristo.
Herald added subscribers: llvm-commits, rupprecht.
Herald added a project: LLVM.

Don't exclude `ET_EXEC` files for `-dynamic-reloc`/`-R` as they may also contain dynamic relocations. This matches the behavior of objdump from binutils.

As `sh_offset` is usually different from `sh_addr` in `ET_EXEC` files, this also fixes a bug where section lookup was done by matching the value of `DT_REL*`/`DT_JMPREL` (which is a VMA) and the section's file offset.


Repository:
  rL LLVM

https://reviews.llvm.org/D60250

Files:
  include/llvm/Object/ELFObjectFile.h
  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
@@ -1530,7 +1530,8 @@
     return;
 
   const auto *Elf = dyn_cast<ELFObjectFileBase>(Obj);
-  if (!Elf || Elf->getEType() != ELF::ET_DYN) {
+  if (!Elf ||
+      (Elf->getEType() != ELF::ET_DYN && Elf->getEType() != ELF::ET_EXEC)) {
     error("not a dynamic object");
     return;
   }
Index: include/llvm/Object/ELFObjectFile.h
===================================================================
--- include/llvm/Object/ELFObjectFile.h
+++ include/llvm/Object/ELFObjectFile.h
@@ -771,7 +771,7 @@
     }
   }
   for (const Elf_Shdr &Sec : *SectionsOrErr) {
-    if (is_contained(Offsets, Sec.sh_offset))
+    if (is_contained(Offsets, Sec.sh_addr))
       Res.emplace_back(toDRI(&Sec), this);
   }
   return Res;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60250.193658.patch
Type: text/x-patch
Size: 906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190404/0172ea53/attachment.bin>


More information about the llvm-commits mailing list