[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
Tue Apr 16 03:03:11 PDT 2019
PkmX updated this revision to Diff 195346.
PkmX marked an inline comment as done.
PkmX added a comment.
- Use `ET_NONE` as `e_type` in tests.
- Drop the unnecessary `dyn` suffix in test name.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60250/new/
https://reviews.llvm.org/D60250
Files:
llvm/include/llvm/Object/ELFObjectFile.h
llvm/test/tools/llvm-objdump/dynamic-reloc-no-dynamic.test
llvm/test/tools/llvm-objdump/dynamic-reloc.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1475,13 +1475,19 @@
}
}
+static bool hasDynamicSection(const ELFObjectFileBase &Elf) {
+ return llvm::any_of(Elf.sections(), [](const ELFSectionRef Sec) {
+ return Sec.getType() == ELF::SHT_DYNAMIC;
+ });
+}
+
void llvm::printDynamicRelocations(const ObjectFile *Obj) {
// For the moment, this option is for ELF only
if (!Obj->isELF())
return;
const auto *Elf = dyn_cast<ELFObjectFileBase>(Obj);
- if (!Elf || Elf->getEType() != ELF::ET_DYN) {
+ if (!Elf || !hasDynamicSection(*Elf)) {
error("not a dynamic object");
return;
}
Index: llvm/test/tools/llvm-objdump/dynamic-reloc.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/dynamic-reloc.test
@@ -0,0 +1,31 @@
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objdump -R %t | FileCheck %s
+#
+# CHECK: DYNAMIC RELOCATION RECORDS
+# CHECK-NEXT: 0000000000000000 R_X86_64_RELATIVE *ABS*
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_NONE
+ Machine: EM_X86_64
+Sections:
+ - Name: .rela.dyn
+ Type: SHT_RELA
+ Info: 0
+ Flags: [ SHF_ALLOC ]
+ Address: 0x1000
+ Relocations:
+ - Offset: 0x0
+ Type: R_X86_64_RELATIVE
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x2000
+ Entries:
+ - Tag: DT_RELA
+ Value: 0x1000
+ - Tag: DT_NULL
+ Value: 0x0
+...
Index: llvm/test/tools/llvm-objdump/dynamic-reloc-no-dynamic.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/dynamic-reloc-no-dynamic.test
@@ -0,0 +1,13 @@
+# Check that -R errors out if there is no dynamic section.
+#
+# RUN: yaml2obj %s > %t
+# RUN: not llvm-objdump -R %t 2>&1 | FileCheck %s
+# CHECK: error: not a dynamic object
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_NONE
+ Machine: EM_X86_64
+...
Index: llvm/include/llvm/Object/ELFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/ELFObjectFile.h
+++ llvm/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.195346.patch
Type: text/x-patch
Size: 2844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/9aecb098/attachment.bin>
More information about the llvm-commits
mailing list