|
1 |
| -// This test checks that --section works correctly. |
2 |
| -// RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \ |
3 |
| -// RUN: --section=.bss | FileCheck %s |
4 |
| - |
5 |
| -// CHECK: .text |
6 |
| -// CHECK-NOT: .data |
7 |
| -// CHECK: .bss |
8 |
| - |
9 |
| -// Test that the -j alias can be used flexibly. Create a baseline and ensure |
10 |
| -// all other combinations are identical. |
11 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s --section .symtab > %t.full |
12 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j .symtab > %t.1 |
13 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j=.symtab > %t.2 |
14 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j.symtab > %t.3 |
15 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj .symtab > %t.4 |
16 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj=.symtab > %t.5 |
17 |
| -// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj.symtab > %t.6 |
18 |
| - |
19 |
| -// RUN: cmp %t.full %t.1 |
20 |
| -// RUN: cmp %t.full %t.2 |
21 |
| -// RUN: cmp %t.full %t.3 |
22 |
| -// RUN: cmp %t.full %t.4 |
23 |
| -// RUN: cmp %t.full %t.5 |
24 |
| -// RUN: cmp %t.full %t.6 |
| 1 | +## Test that --section works correctly for -h. |
| 2 | +## We test the LMA here too, because the code at the time of writing uses the |
| 3 | +## value of --section when looking up section LMAs. |
| 4 | +# RUN: yaml2obj %s --docnum=1 -o %t.h.elf |
| 5 | +# RUN: llvm-objdump -h %t.h.elf -j=.text --section=.bss \ |
| 6 | +# RUN: | FileCheck %s --check-prefix=SHDRS --implicit-check-not=.data --implicit-check-not=.text2 |
| 7 | + |
| 8 | +# SHDRS: Name Size VMA LMA |
| 9 | +# SHDRS: .text 00000001 0000000000000400 0000000000001000 |
| 10 | +# SHDRS: .bss 00000001 0000000000000420 0000000000003000 |
| 11 | + |
| 12 | +--- !ELF |
| 13 | +FileHeader: |
| 14 | + Class: ELFCLASS64 |
| 15 | + Data: ELFDATA2LSB |
| 16 | + Type: ET_EXEC |
| 17 | + Machine: EM_X86_64 |
| 18 | +Sections: |
| 19 | + - Name: .text |
| 20 | + Type: SHT_PROGBITS |
| 21 | + Flags: [SHF_ALLOC, SHF_EXECINSTR] |
| 22 | + Address: 0x400 |
| 23 | + AddressAlign: 0x10 |
| 24 | + Content: 'c3' |
| 25 | + - Name: .text2 |
| 26 | + Type: SHT_PROGBITS |
| 27 | + Flags: [SHF_ALLOC, SHF_EXECINSTR] |
| 28 | + Address: 0x401 |
| 29 | + Content: '90' |
| 30 | + - Name: .data |
| 31 | + Type: SHT_PROGBITS |
| 32 | + Flags: [SHF_ALLOC, SHF_WRITE] |
| 33 | + Address: 0x410 |
| 34 | + AddressAlign: 0x10 |
| 35 | + Content: '42' |
| 36 | + - Name: .bss |
| 37 | + Type: SHT_NOBITS |
| 38 | + Flags: [SHF_ALLOC, SHF_WRITE] |
| 39 | + Address: 0x420 |
| 40 | + AddressAlign: 0x10 |
| 41 | + Size: 1 |
| 42 | +ProgramHeaders: |
| 43 | + - Type: PT_LOAD |
| 44 | + VAddr: 0x400 |
| 45 | + PAddr: 0x1000 |
| 46 | + Sections: |
| 47 | + - Section: .text |
| 48 | + - Section: .text2 |
| 49 | + - Type: PT_LOAD |
| 50 | + VAddr: 0x410 |
| 51 | + PAddr: 0x2000 |
| 52 | + Sections: |
| 53 | + - Section: .data |
| 54 | + - Type: PT_LOAD |
| 55 | + VAddr: 0x420 |
| 56 | + PAddr: 0x3000 |
| 57 | + Sections: |
| 58 | + - Section: .bss |
| 59 | + |
| 60 | +## Test that --section works correctly for -d with -r. |
| 61 | +## FIXME: Inline relocations are only printed if the relocation section itself is |
| 62 | +## specified with --section. This test just characterizes the existing behavior. |
| 63 | +## See https://bugs.llvm.org/show_bug.cgi?id=41886 |
| 64 | +# RUN: yaml2obj %s --docnum=2 -o %t.o |
| 65 | + |
| 66 | +## Show non-executable sections are not disassembled even if specified, |
| 67 | +## and that only the specified executable sections are disassembled. |
| 68 | +## Also show that no relocation sections are dumped because none are |
| 69 | +## specified. |
| 70 | +## FIXME: This is different behaviour to GNU objdump, which dumps the non- |
| 71 | +## executable sections if requested explicitly. |
| 72 | +## See https://bugs.llvm.org/show_bug.cgi?id=41897. |
| 73 | +# RUN: llvm-objdump -d -r %t.o --section=.text --section=.rodata \ |
| 74 | +# RUN: | FileCheck %s --check-prefix=DISASM --implicit-check-not=.text2 \ |
| 75 | +# RUN: --implicit-check-not=.rodata --implicit-check-not=R_X86_64 |
| 76 | + |
| 77 | +## Show that only the specified relocation sections that patch the |
| 78 | +## disassembled sections are dumped. |
| 79 | +# RUN: llvm-objdump -d -r %t.o --section=.text \ |
| 80 | +# RUN: --section=.rela.text --section=.rela.text2 \ |
| 81 | +# RUN: | FileCheck %s --check-prefixes=DISASM,RELOC --implicit-check-not=.text2 \ |
| 82 | +# RUN: --implicit-check-not=R_X86_64 |
| 83 | + |
| 84 | +# DISASM: Disassembly of section .text: |
| 85 | +# DISASM-EMPTY: |
| 86 | +# DISASM-NEXT: 0000000000000400 .text: |
| 87 | +# DISASM-NEXT: 400: e8 00 00 00 00 callq 0 <.text+0x5> |
| 88 | +# RELOC-NEXT: 00000401: R_X86_64_PC32 foo+1 |
| 89 | + |
| 90 | +--- !ELF |
| 91 | +FileHeader: |
| 92 | + Class: ELFCLASS64 |
| 93 | + Data: ELFDATA2LSB |
| 94 | + Type: ET_REL |
| 95 | + Machine: EM_X86_64 |
| 96 | +Sections: |
| 97 | + - Name: .text |
| 98 | + Type: SHT_PROGBITS |
| 99 | + Flags: [SHF_ALLOC, SHF_EXECINSTR] |
| 100 | + Address: 0x400 |
| 101 | + AddressAlign: 0x10 |
| 102 | + Content: 'e800000000' |
| 103 | + - Name: .text2 |
| 104 | + Type: SHT_PROGBITS |
| 105 | + Flags: [SHF_ALLOC, SHF_EXECINSTR] |
| 106 | + Address: 0x401 |
| 107 | + Content: '90e800000000' |
| 108 | + - Name: .rela.text |
| 109 | + Type: SHT_RELA |
| 110 | + Info: .text |
| 111 | + Relocations: |
| 112 | + - Offset: 1 |
| 113 | + Symbol: foo |
| 114 | + Addend: 1 |
| 115 | + Type: R_X86_64_PC32 |
| 116 | + - Name: .another.rela.text |
| 117 | + Type: SHT_RELA |
| 118 | + Info: .text |
| 119 | + Relocations: |
| 120 | + - Offset: 1 |
| 121 | + Symbol: foo |
| 122 | + Type: R_X86_64_GOT32 |
| 123 | + - Name: .rela.text2 |
| 124 | + Type: SHT_RELA |
| 125 | + Info: .text2 |
| 126 | + Relocations: |
| 127 | + - Offset: 1 |
| 128 | + Symbol: foo |
| 129 | + Addend: 2 |
| 130 | + Type: R_X86_64_PLT32 |
| 131 | + - Name: .rodata |
| 132 | + Type: SHT_PROGBITS |
| 133 | + Flags: [SHF_ALLOC] |
| 134 | + Size: 4 |
| 135 | + - Name: .rela.rodata |
| 136 | + Type: SHT_RELA |
| 137 | + Info: .rodata |
| 138 | + Relocations: |
| 139 | + - Offset: 0 |
| 140 | + Symbol: foo |
| 141 | + Type: R_X86_64_NONE |
| 142 | +Symbols: |
| 143 | + - Name: foo |
| 144 | + |
| 145 | +## Test that --section works when dumping relocation sections. |
| 146 | +# RUN: llvm-objdump -r %t.o --section=.another.rela.text --section=.rela.rodata \ |
| 147 | +# RUN: | FileCheck %s --check-prefix=DUMP-RELOCS --implicit-check-not=R_X86_64 \ |
| 148 | +# RUN: --implicit-check-not="RELOCATION RECORDS" |
| 149 | + |
| 150 | +# DUMP-RELOCS: RELOCATION RECORDS FOR [.text]: |
| 151 | +# DUMP-RELOCS: 00000001 R_X86_64_GOT32 foo |
| 152 | +# DUMP-RELOCS: RELOCATION RECORDS FOR [.rodata]: |
| 153 | +# DUMP-RELOCS: 00000000 R_X86_64_NONE foo |
| 154 | + |
| 155 | +## Test that --section works with --full-contents. |
| 156 | +# RUN: llvm-objdump -s %t.o --section=.text --section=.rela.text2 \ |
| 157 | +# RUN: | FileCheck %s --check-prefix=CONTENTS \ |
| 158 | +# RUN: --implicit-check-not=.text \ |
| 159 | +# RUN: --implicit-check-not=.rodata |
| 160 | + |
| 161 | +# CONTENTS: Contents of section .text: |
| 162 | +# CONTENTS: Contents of section .rela.text2: |
| 163 | + |
| 164 | +## Test that --section works with --fault-map-section. |
| 165 | +# RUN: yaml2obj %s --docnum=3 -o %t2.o |
| 166 | +# RUN: llvm-objdump %t2.o --fault-map-section -j __clangast \ |
| 167 | +# RUN: | FileCheck %s --check-prefixes=FAULTMAP,NO-FAULTMAP |
| 168 | +# RUN: llvm-objdump %t2.o --fault-map-section -j .llvm_faultmaps \ |
| 169 | +# RUN: | FileCheck %s --check-prefixes=FAULTMAP,WITH-FAULTMAP |
| 170 | + |
| 171 | +# FAULTMAP: FaultMap table: |
| 172 | +# NO-FAULTMAP-NEXT: <not found> |
| 173 | +# WITH-FAULTMAP-NEXT: Version: 0x1 |
| 174 | +# WITH-FAULTMAP-NEXT: NumFunctions: 0 |
| 175 | + |
| 176 | +## Test that --section works with --raw-clang-ast. |
| 177 | +# RUN: llvm-objdump %t2.o --raw-clang-ast -j .llvm_faultmaps \ |
| 178 | +# RUN: | FileCheck %s --check-prefix=NO-AST --allow-empty |
| 179 | +# RUN: llvm-objdump %t2.o --raw-clang-ast -j __clangast \ |
| 180 | +# RUN: | FileCheck %s --check-prefix=CLANG-AST |
| 181 | + |
| 182 | +# NO-AST-NOT: {{.}} |
| 183 | +# CLANG-AST: foobar |
| 184 | + |
| 185 | +--- !ELF |
| 186 | +FileHeader: |
| 187 | + Class: ELFCLASS64 |
| 188 | + Data: ELFDATA2LSB |
| 189 | + Type: ET_REL |
| 190 | + Machine: EM_X86_64 |
| 191 | +Sections: |
| 192 | + - Name: .llvm_faultmaps |
| 193 | + Type: SHT_PROGBITS |
| 194 | + Content: '0100000000000000' |
| 195 | + - Name: __clangast |
| 196 | + Type: SHT_PROGBITS |
| 197 | + Content: '666f6f626172' # "foobar" |
| 198 | + |
| 199 | +## Test that the -j alias can be used flexibly. Create a baseline and ensure |
| 200 | +## all other combinations are identical. |
| 201 | +# RUN: llvm-objdump %t.h.elf -h -s --section .symtab > %t.full |
| 202 | +# RUN: llvm-objdump %t.h.elf -h -s -j .symtab > %t.1 |
| 203 | +# RUN: llvm-objdump %t.h.elf -h -s -j=.symtab > %t.2 |
| 204 | +# RUN: llvm-objdump %t.h.elf -h -s -j.symtab > %t.3 |
| 205 | +# RUN: llvm-objdump %t.h.elf -hsj .symtab > %t.4 |
| 206 | +# RUN: llvm-objdump %t.h.elf -hsj=.symtab > %t.5 |
| 207 | +# RUN: llvm-objdump %t.h.elf -hsj.symtab > %t.6 |
| 208 | + |
| 209 | +# RUN: cmp %t.full %t.1 |
| 210 | +# RUN: cmp %t.full %t.2 |
| 211 | +# RUN: cmp %t.full %t.3 |
| 212 | +# RUN: cmp %t.full %t.4 |
| 213 | +# RUN: cmp %t.full %t.5 |
| 214 | +# RUN: cmp %t.full %t.6 |
| 215 | + |
| 216 | +## Test that an unknown section name causes all section output to be suppressed. |
| 217 | +## TODO: Add a warning for this case. |
| 218 | +## See https://bugs.llvm.org/show_bug.cgi?id=41898. |
| 219 | +# RUN: llvm-objdump %t.h.elf -h --section foobar \ |
| 220 | +# RUN: | FileCheck %s --check-prefix=NO-SECTION |
| 221 | + |
| 222 | +# NO-SECTION: Sections: |
| 223 | +# NO-SECTION-NEXT: Idx Name Size VMA Type |
| 224 | +# NO-SECTION-NOT: {{.}} |
0 commit comments