[PATCH] D75631: [test] Fix reliability of disassemble-functions.test

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 24 15:43:12 PDT 2020


thopre updated this revision to Diff 252446.
thopre added a comment.
Herald added a subscriber: emaste.
Herald added a reviewer: espindola.

Fix source of variability in test


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/test/tools/llvm-objdump/X86/disassemble-functions.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
@@ -1208,6 +1208,12 @@
     SectionAddresses.emplace_back(Sec.getAddress(), Sec);
   array_pod_sort(SectionAddresses.begin(), SectionAddresses.end());
 
+  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)) {
@@ -1483,13 +1489,20 @@
             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];
+                if (It != CodeSectionAddresses.begin()) {
+                  uint64_t SelectedSectionAddr = It->first;
+                  --It;
+                  assert(It->first + It->second.getSize() - 1 <
+                             SelectedSectionAddr &&
+                         "Found two code sections with call target in range");
+                }
               } else {
                 TargetSectionSymbols = &AbsoluteSymbols;
               }
Index: llvm/test/tools/llvm-objdump/X86/disassemble-functions.test
===================================================================
--- llvm/test/tools/llvm-objdump/X86/disassemble-functions.test
+++ llvm/test/tools/llvm-objdump/X86/disassemble-functions.test
@@ -3,9 +3,9 @@
 
 # RUN: yaml2obj -o %t.out %p/Inputs/simple-executable-x86_64.yaml
 # RUN: llvm-objdump -d %t.out --disassemble-functions=main \
-# RUN:   | FileCheck %s --check-prefix=MAIN --implicit-check-not=foo --implicit-check-not=somedata
+# RUN:   | FileCheck %s --check-prefix=MAIN --implicit-check-not="<foo>:" --implicit-check-not="<somedata>:"
 # RUN: llvm-objdump -d %t.out --disassemble-functions=main,foo \
-# RUN:   | FileCheck %s --check-prefixes=MAIN,FOO --implicit-check-not=somedata
+# RUN:   | FileCheck %s --check-prefixes=MAIN,FOO --implicit-check-not="<somedata>:"
 
 # FOO: <foo>:
 # MAIN: <main>:
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
@@ -137,9 +137,9 @@
 // CHECK-NEXT: }
 
 // 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   {{.*}} <_start+{{.*}}>
+// DISASM-NEXT:   callq   {{.*}} <_start+{{.*}}>
+// DISASM-NEXT:   callq   {{.*}} <_start+{{.*}}>
+// DISASM-NEXT:   callq   {{.*}} <_start+{{.*}}>
+// DISASM-NEXT:   callq   {{.*}} <_start+{{.*}}>
+// DISASM-NEXT:   callq   {{.*}} <_start+{{.*}}>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75631.252446.patch
Type: text/x-patch
Size: 3627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200324/315c74e6/attachment.bin>


More information about the llvm-commits mailing list