xref: /llvm-project/llvm/test/tools/llvm-objdump/warn-on-out-of-range-start-stop-address.test (revision a7a447be0fa934505f0c423fb97b91a68c1cc715)
1## This test checks warning messages if --start-address/--stop-address
2## do not intersect with address ranges of sections that have the SHF_ALLOC
3## flag.
4
5# RUN: yaml2obj --docnum=1 %s -o %t
6# RUN: yaml2obj --docnum=2 %s -o %t.2
7# RUN: yaml2obj --docnum=3 %s -o %t.o
8# RUN: yaml2obj --docnum=4 %s -o %t.3
9
10## Warn if no section covers any part of the specified range.
11
12## - Section ends at start of range:
13##           | range |
14## | section |
15# RUN: llvm-objdump --file-headers --start-address=0x1004 --stop-address=0x1006 %t 2>&1 \
16# RUN:   | FileCheck %s --check-prefix=WARN
17
18## - Range is between two sections:
19##             | range |
20## | section |           | section |
21# RUN: llvm-objdump --file-headers --start-address=0x1005 --stop-address=0x1006 %t 2>&1 \
22# RUN:   | FileCheck %s --check-prefix=WARN
23
24## - Range appears after any section:
25##                  | range |
26## | section |
27# RUN: llvm-objdump --file-headers --start-address=0x1405 --stop-address=0x1406 %t 2>&1 \
28# RUN:   | FileCheck %s --check-prefix=WARN
29
30## - Range starts at 0. (--start-address defaults to 0).
31# RUN: llvm-objdump --file-headers --stop-address=0x1000 %t 2>&1 \
32# RUN:   | FileCheck %s --check-prefix=WARN-STOP-ONLY
33
34## - Range ends at UINT64_MAX. (--stop-address defaults to UINT64_MAX)
35# RUN: llvm-objdump --file-headers --start-address=0x1500 %t 2>&1 \
36# RUN:   | FileCheck %s --check-prefix=WARN-START-ONLY
37
38## No warning if a section covers at least part of the specified range.
39
40## - Ranges are identical:
41## | range   |
42## | section |
43# RUN: llvm-objdump --file-headers --start-address=0x1000 --stop-address=0x1004 %t 2>&1 \
44# RUN:   | FileCheck %s --implicit-check-not=warning:
45
46## - Range is entirely within section:
47##  | range |
48## | section |
49# RUN: llvm-objdump --file-headers --start-address=0x1001 --stop-address=0x1003 %t 2>&1 \
50# RUN:   | FileCheck %s --implicit-check-not=warning:
51
52## - Section is entirely within range:
53## |   range   |
54##  | section |
55# RUN: llvm-objdump --file-headers --start-address=0xfff --stop-address=0x1005 %t 2>&1 \
56# RUN:   | FileCheck %s --implicit-check-not=warning:
57
58## - Section and range share same start, section larger:
59## | range |
60## | section |
61# RUN: llvm-objdump --file-headers --start-address=0x1000 --stop-address=0x1003 %t 2>&1 \
62# RUN:   | FileCheck %s --implicit-check-not=warning:
63
64## - Section and range share same start, range larger:
65## | range        |
66## | section |
67# RUN: llvm-objdump --file-headers --start-address=0x1000 --stop-address=0x1005 %t 2>&1 \
68# RUN:   | FileCheck %s --implicit-check-not=warning:
69
70## - Section and range share same end, section larger:
71##   | range |
72## | section |
73# RUN: llvm-objdump --file-headers --start-address=0x1001 --stop-address=0x1004 %t 2>&1 \
74# RUN:   | FileCheck %s --implicit-check-not=warning:
75
76## - Section and range share same end, range larger:
77## | range    |
78##  | section |
79# RUN: llvm-objdump --file-headers --start-address=0xfff --stop-address=0x1004 %t 2>&1 \
80# RUN:   | FileCheck %s --implicit-check-not=warning:
81
82## - Section and range partially overlap, range first:
83## | range |
84##   | section |
85# RUN: llvm-objdump --file-headers --start-address=0xfff --stop-address=0x1003 %t 2>&1 \
86# RUN:   | FileCheck %s --implicit-check-not=warning:
87
88## - Section and range partially overlap, section first:
89##       | range |
90## | section |
91# RUN: llvm-objdump --file-headers --start-address=0x1001 --stop-address=0x1005 %t 2>&1 \
92# RUN:   | FileCheck %s --implicit-check-not=warning:
93
94## - Range starts before first section and ends after second:
95## |            range               |
96##   | section |    | section |
97# RUN: llvm-objdump --file-headers --start-address=0xfff --stop-address=0x1405 %t 2>&1 \
98# RUN:   | FileCheck %s --implicit-check-not=warning:
99
100## Warn only for the input file that does not have the specified range.
101# RUN: llvm-objdump --file-headers --start-address=0x2001 --stop-address=0x2005 %t %t.2 2>&1 \
102# RUN:   | FileCheck %s --check-prefix=MULTI-INPUT
103
104## Warn if the specified range is in a segment but not in any section.
105# RUN: llvm-objdump --file-headers --start-address=0x1008 --stop-address=0x1009 %t 2>&1 \
106# RUN:   | FileCheck %s --check-prefix=WARN
107
108## Warning for --start-address/--stop-address works regardless of the other options used including --section.
109# RUN: llvm-objdump --syms --section=.text2 --start-address=0x1004 --stop-address=0x1005 %t 2>&1 \
110# RUN:   | FileCheck %s --check-prefix=WARN
111
112## Sections without the SHF_ALLOC flag are ignored in address range calculation.
113# RUN: llvm-objdump --file-headers --start-address=0x1 --stop-address=0x3 %t.3 2>&1 \
114# RUN:   | FileCheck %s --check-prefix=WARN
115
116## No warning for relocatable objects.
117# RUN: llvm-objdump --file-headers --start-address=0x1004 --stop-address=0x1005 %t.o 2>&1 \
118# RUN:   | FileCheck %s --implicit-check-not=warning:
119
120## No warning if neither --start-address nor --stop-address are specified.
121# RUN: llvm-objdump --file-headers %t 2>&1 | FileCheck %s --implicit-check-not=warning:
122
123# WARN: warning: {{.*}}: no section overlaps the range {{.*}} specified by --start-address/--stop-address
124# WARN-STOP-ONLY: warning: {{.*}}: no section has address less than 0x1000 specified by --stop-address
125# WARN-START-ONLY: warning: {{.*}}: no section has address greater than or equal to 0x1500 specified by --start-address
126
127# MULTI-INPUT: file format
128# MULTI-INPUT: warning: {{.*}}: no section overlaps the range [0x2001,0x2005) specified by --start-address/--stop-address
129# MULTI-INPUT: file format
130# MULTI-INPUT-NOT: warning:
131
132--- !ELF
133FileHeader:
134  Class:   ELFCLASS64
135  Data:    ELFDATA2LSB
136  Type:    ET_EXEC
137  Machine: EM_X86_64
138Sections:
139  - Name:    .text
140    Type:    SHT_PROGBITS
141    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
142    Address: 0x1000
143    Size:    4
144  - Name:    .text2
145    Type:    SHT_PROGBITS
146    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
147    Address: 0x1400
148    Size:    4
149ProgramHeaders:
150  - Type:     PT_LOAD
151    Flags:    [ PF_X, PF_R ]
152    VAddr:    0x1000
153    FileSize: 0x500
154    FirstSec: .text
155    LastSec:  .text2
156
157--- !ELF
158FileHeader:
159  Class:   ELFCLASS64
160  Data:    ELFDATA2LSB
161  Type:    ET_DYN
162  Machine: EM_X86_64
163Sections:
164  - Name:    .text
165    Type:    SHT_PROGBITS
166    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
167    Address: 0x2000
168    Size:    4
169ProgramHeaders:
170  - Type:     PT_LOAD
171    Flags:    [ PF_X, PF_R ]
172    VAddr:    0x1000
173    FileSize: 0x4
174    FirstSec: .text
175    LastSec:  .text
176
177--- !ELF
178FileHeader:
179  Class:   ELFCLASS64
180  Data:    ELFDATA2LSB
181  Type:    ET_REL
182  Machine: EM_X86_64
183Sections:
184  - Name:    .text
185    Type:    SHT_PROGBITS
186    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
187    Address: 0x1000
188    Size:    4
189
190--- !ELF
191FileHeader:
192  Class:   ELFCLASS64
193  Data:    ELFDATA2LSB
194  Type:    ET_DYN
195  Machine: EM_X86_64
196Sections:
197  - Name:    .non.alloc
198    Type:    SHT_PROGBITS
199    Size:    2
200