[llvm] r362596 - [llvm-objdump] - Disassemble non-executable sections if specifically requested.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 5 04:37:53 PDT 2019
Author: grimar
Date: Wed Jun 5 04:37:53 2019
New Revision: 362596
URL: http://llvm.org/viewvc/llvm-project?rev=362596&view=rev
Log:
[llvm-objdump] - Disassemble non-executable sections if specifically requested.
This is https://bugs.llvm.org/show_bug.cgi?id=41897.
Previously -d + -j .data had no effect, that wasn't consistent with GNU,
which proccesses .data in that case. With this patch we follow this behavior.
Diffeential revision: https://reviews.llvm.org/D62848
Added:
llvm/trunk/test/tools/llvm-objdump/X86/section-filter-disasm.test
Modified:
llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Added: llvm/trunk/test/tools/llvm-objdump/X86/section-filter-disasm.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/section-filter-disasm.test?rev=362596&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/section-filter-disasm.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/X86/section-filter-disasm.test Wed Jun 5 04:37:53 2019
@@ -0,0 +1,43 @@
+# RUN: yaml2obj %s -o %t.o
+
+## By default, only executable sections are disassembled,
+## but with the use of the --section flag, we can change this behavior.
+## Show that llvm-objdump can disassemble the specified sections.
+
+# RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefix=TEXT \
+# RUN: --implicit-check-not=.rodata --implicit-check-not=.data
+
+# RUN: llvm-objdump -d %t.o --section=.rodata \
+# RUN: | FileCheck %s --check-prefix=RODATA \
+# RUN: --implicit-check-not=.text --implicit-check-not=.data
+
+# RUN: llvm-objdump -d %t.o --section=.rodata --section=.text \
+# RUN: | FileCheck %s --check-prefixes=RODATA,TEXT \
+# RUN: --implicit-check-not=.data
+
+# RUN: llvm-objdump -d %t.o --section=.rodata --section=.text --section=.data \
+# RUN: | FileCheck %s --check-prefixes=RODATA,TEXT,DATA
+
+# RODATA: Disassembly of section .rodata
+# TEXT: Disassembly of section .text
+# DATA: Disassembly of section .data
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC]
+ Content: '00'
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ Content: '00'
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_WRITE]
+ Content: '00'
Modified: llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test?rev=362596&r1=362595&r2=362596&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test Wed Jun 5 04:37:53 2019
@@ -1,16 +1,11 @@
## Test that --section works correctly for -d with -r.
# RUN: yaml2obj %s -o %t.o
-## Show non-executable sections are not disassembled even if specified,
-## and that only the specified executable sections are disassembled.
+## Show that only the specified sections are disassembled.
## Also show that no relocation sections are dumped because none are
## specified.
-## FIXME: This is different behaviour to GNU objdump, which dumps the non-
-## executable sections if requested explicitly.
-## See https://bugs.llvm.org/show_bug.cgi?id=41897.
# RUN: llvm-objdump -d -r %t.o --section=.text --section=.rodata \
-# RUN: | FileCheck %s --check-prefixes=DISASM,RELOC --implicit-check-not=.text2 \
-# RUN: --implicit-check-not=.rodata
+# RUN: | FileCheck %s --check-prefixes=DISASM,RELOC --implicit-check-not=.text2
# DISASM: Disassembly of section .text:
# DISASM-EMPTY:
@@ -18,6 +13,12 @@
# DISASM-NEXT: 400: e8 00 00 00 00 callq 0 <.text+0x5>
# RELOC-NEXT: 00000401: R_X86_64_PC32 foo+1
# RELOC-NEXT: 00000401: R_X86_64_GOT32 foo
+# DISASM: Disassembly of section .rodata:
+# DISASM-EMPTY:
+# DISASM-NEXT: 0000000000000000 .rodata:
+# DISASM-NEXT: 0: 00 00 addb %al, (%rax)
+# RELOC-NEXT: 0000000000000000: R_X86_64_NONE foo
+# DISASM-NEXT: 2: 00 00 addb %al, (%rax)
--- !ELF
FileHeader:
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=362596&r1=362595&r2=362596&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jun 5 04:37:53 2019
@@ -1095,7 +1095,8 @@ static void disassembleObject(const Targ
array_pod_sort(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
- if (!DisassembleAll && (!Section.isText() || Section.isVirtual()))
+ if (FilterSections.empty() && !DisassembleAll &&
+ (!Section.isText() || Section.isVirtual()))
continue;
uint64_t SectionAddr = Section.getAddress();
More information about the llvm-commits
mailing list