[PATCH] D75631: [llvm-objdump] Fix reliability of call target disassembling

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 07:33:39 PDT 2020


thopre updated this revision to Diff 252834.
thopre marked 3 inline comments as done.
thopre added a comment.

Cross-check address of call targets in lld/test/ELF/pre_init_fini_array.s against section address with --syms


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75631/new/

https://reviews.llvm.org/D75631

Files:
  lld/test/ELF/pre_init_fini_array.s
  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
@@ -1210,6 +1210,12 @@
     SectionAddresses.emplace_back(Sec.getAddress(), Sec);
   stable_sort(SectionAddresses);
 
+  std::vector<std::pair<uint64_t, SectionRef>> CodeSectionAddresses;
+  for (std::pair<uint64_t, SectionRef> SectionAddress : SectionAddresses) {
+    if (SectionAddress.second.isText())
+      CodeSectionAddresses.emplace_back(SectionAddress);
+  }
+
   // Linked executables (.exe and .dll files) typically don't include a real
   // symbol table but they might contain an export table.
   if (const auto *COFFObj = dyn_cast<COFFObjectFile>(Obj)) {
@@ -1486,11 +1492,11 @@
             auto *TargetSectionSymbols = &Symbols;
             if (!Obj->isRelocatableObject()) {
               auto It = partition_point(
-                  SectionAddresses,
+                  CodeSectionAddresses,
                   [=](const std::pair<uint64_t, SectionRef> &O) {
                     return O.first <= Target;
                   });
-              if (It != SectionAddresses.begin()) {
+              if (It != CodeSectionAddresses.begin()) {
                 --It;
                 TargetSectionSymbols = &AllSymbols[It->second];
               } else {
Index: lld/test/ELF/pre_init_fini_array.s
===================================================================
--- lld/test/ELF/pre_init_fini_array.s
+++ lld/test/ELF/pre_init_fini_array.s
@@ -4,16 +4,16 @@
 // RUN: ld.lld %t2 -o %t2.so -shared -soname=so
 // RUN: ld.lld %t %t2.so -o %t2
 // RUN: llvm-readobj -r --symbols --sections --dynamic-table %t2 | FileCheck %s
-// RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=DISASM %s
+// RUN: llvm-objdump -d --syms %t2 | FileCheck --check-prefix=DISASM %s
 
 .globl _start
 _start:
-  call __preinit_array_start
-  call __preinit_array_end
-  call __init_array_start
-  call __init_array_end
-  call __fini_array_start
-  call __fini_array_end
+  call *__preinit_array_start
+  call *__preinit_array_end
+  call *__init_array_start
+  call *__init_array_end
+  call *__fini_array_start
+  call *__fini_array_end
 
 
 .section .init_array,"aw", at init_array
@@ -136,10 +136,18 @@
 // CHECK-NEXT:   Section: .preinit_array
 // CHECK-NEXT: }
 
+// DISASM:      SYMBOL TABLE:
+// DISASM-DAG: {{0*}}[[#%x, PREINIT_ARRAY_START:]]  l  .preinit_array  {{0+}}  .hidden  __preinit_array_start
+// DISASM-DAG: {{0*}}[[#%x, PREINIT_ARRAY_END:]]    l  .preinit_array  {{0+}}  .hidden  __preinit_array_end
+// DISASM-DAG: {{0*}}[[#%x, INIT_ARRAY_START:]]     l  .init_array  {{0+}}  .hidden  __init_array_start
+// DISASM-DAG: {{0*}}[[#%x, INIT_ARRAY_END:]]       l  .init_array  {{0+}}  .hidden  __init_array_end
+// DISASM-DAG: {{0*}}[[#%x, FINI_ARRAY_START:]]     l  .fini_array  {{0+}}  .hidden  __fini_array_start
+// DISASM-DAG: {{0*}}[[#%x, FINI_ARRAY_END:]]       l  .fini_array  {{0+}}  .hidden  __fini_array_end
+
 // DISASM:      <_start>:
-// DISASM-NEXT:   callq   {{.*}} <__preinit_array_start>
-// DISASM-NEXT:   callq   {{.*}} <__fini_array_start>
-// DISASM-NEXT:   callq   {{.*}} <__init_array_start>
-// DISASM-NEXT:   callq   {{.*}} <__preinit_array_start>
-// DISASM-NEXT:   callq   {{.*}} <__fini_array_start>
-// DISASM-NEXT:   callq   {{.*}} <__fini_array_end>
+// DISASM-NEXT:   callq   *[[#%u, PREINIT_ARRAY_START]]
+// DISASM-NEXT:   callq   *[[#%u, PREINIT_ARRAY_END]]
+// DISASM-NEXT:   callq   *[[#%u, INIT_ARRAY_START]]
+// DISASM-NEXT:   callq   *[[#%u, INIT_ARRAY_END]]
+// DISASM-NEXT:   callq   *[[#%u, FINI_ARRAY_START]]
+// DISASM-NEXT:   callq   *[[#%u, FINI_ARRAY_END]]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75631.252834.patch
Type: text/x-patch
Size: 3724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200326/da2a2d68/attachment.bin>


More information about the llvm-commits mailing list