[llvm] r337361 - [llvm-objdump] - Stop reporting bogus section IDs.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 18 01:34:35 PDT 2018


Author: grimar
Date: Wed Jul 18 01:34:35 2018
New Revision: 337361

URL: http://llvm.org/viewvc/llvm-project?rev=337361&view=rev
Log:
[llvm-objdump] - Stop reporting bogus section IDs.

Imagine we have a file with few sections, and one of them is .foo
with index N != 0.

Problem is that when llvm-objdump is given a -section=.foo parameter
it lists .foo as a section at index 0. That makes impossible to write
test cases which needs to find the index of the particular section,
while ignoring dumping of others.

The patch fixes that.

Differential revision: https://reviews.llvm.org/D49372

Added:
    llvm/trunk/test/tools/llvm-objdump/X86/section-index.s
Modified:
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp

Added: llvm/trunk/test/tools/llvm-objdump/X86/section-index.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/section-index.s?rev=337361&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/section-index.s (added)
+++ llvm/trunk/test/tools/llvm-objdump/X86/section-index.s Wed Jul 18 01:34:35 2018
@@ -0,0 +1,25 @@
+# RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t
+
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+# CHECK:     Idx Name
+# CHECK:      3  .foo
+# CHECK-NEXT: 4  .bar
+# CHECK-NEXT: 5  .zed
+
+## Check we report the valid section index
+## when requesting a specific section.
+# RUN: llvm-objdump -section-headers -section=.bar %t \
+# RUN:   | FileCheck %s --check-prefix=BAR
+# BAR:      Idx Name
+# BAR-NEXT:  4  .bar
+# BAR-NOT:  foo
+# BAR-NOT:  zed
+
+.section .foo, "ax", %progbits
+nop
+
+.section .bar, "ax", %progbits
+nop
+
+.section .zed, "ax", %progbits
+nop

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=337361&r1=337360&r2=337361&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jul 18 01:34:35 2018
@@ -1815,7 +1815,6 @@ void llvm::PrintDynamicRelocations(const
 void llvm::PrintSectionHeaders(const ObjectFile *Obj) {
   outs() << "Sections:\n"
             "Idx Name          Size      Address          Type\n";
-  unsigned i = 0;
   for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
     StringRef Name;
     error(Section.getName(Name));
@@ -1826,9 +1825,9 @@ void llvm::PrintSectionHeaders(const Obj
     bool BSS = Section.isBSS();
     std::string Type = (std::string(Text ? "TEXT " : "") +
                         (Data ? "DATA " : "") + (BSS ? "BSS" : ""));
-    outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n", i,
-                     Name.str().c_str(), Size, Address, Type.c_str());
-    ++i;
+    outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n",
+                     Section.getIndex(), Name.str().c_str(), Size, Address,
+                     Type.c_str());
   }
 }
 




More information about the llvm-commits mailing list