diff options
author | George Rimar <grimar@accesssoftek.com> | 2018-07-18 08:34:35 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2018-07-18 08:34:35 +0000 |
commit | 10c3b3d15ed6a788ac12221b784caf81fb8248b5 (patch) | |
tree | 5eef9f13fb7a464710a5320db6882754d1024c52 | |
parent | 8b80d4ecc24c2a3155131a54125c0daf78f7624d (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337361 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/tools/llvm-objdump/X86/section-index.s | 25 | ||||
-rw-r--r-- | tools/llvm-objdump/llvm-objdump.cpp | 7 |
2 files changed, 28 insertions, 4 deletions
diff --git a/test/tools/llvm-objdump/X86/section-index.s b/test/tools/llvm-objdump/X86/section-index.s new file mode 100644 index 00000000000..6ca86ea19b5 --- /dev/null +++ b/test/tools/llvm-objdump/X86/section-index.s @@ -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 diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index d1a765b1af5..987f565a9b7 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -1815,7 +1815,6 @@ void llvm::PrintDynamicRelocations(const ObjectFile *Obj) { 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 ObjectFile *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()); } } |