gnu-phdrs.test 17.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
## Check how llvm-readelf dumps program headers and prints sections to segments mapping.

## Check that -l, --program-headers and --segments are the same option.
# RUN: yaml2obj --docnum=1 -DBITS=32 -DMACHINE=EM_386 %s -o %t32.elf
# RUN: llvm-readelf -l %t32.elf 2>&1 > %t.readelf-l.txt
# RUN: llvm-readelf --program-headers %t32.elf 2>&1 > %t.readelf-pheaders.txt
# RUN: cmp %t.readelf-l.txt %t.readelf-pheaders.txt
# RUN: llvm-readelf --segments %t32.elf 2>&1 > %t.readelf-segments.txt
# RUN: cmp %t.readelf-l.txt %t.readelf-segments.txt

## Check we are able to print program headers of different types.
# RUN: llvm-readelf -l %t32.elf | \
# RUN:   FileCheck %s --check-prefixes=ELF32,MAPPING --strict-whitespace --match-full-lines

# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t64.elf
# RUN: llvm-readelf -l %t64.elf | \
# RUN:   FileCheck %s --check-prefixes=ELF64,MAPPING --strict-whitespace --match-full-lines

#       ELF32:There are 23 program headers, starting at offset 52
# ELF32-EMPTY:
# ELF32-NEXT:Program Headers:
# ELF32-NEXT:  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
# ELF32-NEXT:  PHDR           0x000314 0x00001000 0x00001000 0x00003 0x00003  W  0x1
# ELF32-NEXT:  PHDR           0x000317 0x00002000 0x00002000 0x00007 0x00007   E 0x1
# ELF32-NEXT:  NULL           0x000317 0x00002000 0x00002000 0x00007 0x00007   E 0x1
# ELF32-NEXT:  DYNAMIC        0x000314 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1
# ELF32-NEXT:  INTERP         0x00031e 0x00003000 0x00003000 0x00004 0x00004 RW  0x1
# ELF32-NEXT:      [Requesting program interpreter: ABC]
# ELF32-NEXT:  NOTE           0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  SHLIB          0x000314 0x00001000 0x00001000 0x00001 0x00001     0x1
# ELF32-NEXT:  TLS            0x000322 0x00004000 0x00004000 0x00001 0x00001     0x1
# ELF32-NEXT:  <unknown>: 0x60000000 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  GNU_EH_FRAME   0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  SUNW_UNWIND    0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  GNU_STACK      0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  GNU_RELRO      0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  GNU_PROPERTY   0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x65a3dbe6 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x65a3dbe7 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x65a41be6 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x6fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x70000000 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x70000001 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x70000002 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x70000003 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-NEXT:  <unknown>: 0x7fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003     0x1
# ELF32-EMPTY:

#       ELF64:There are 23 program headers, starting at offset 64
# ELF64-EMPTY:
# ELF64-NEXT:Program Headers:
# ELF64-NEXT:  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
# ELF64-NEXT:  PHDR           0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003  W  0x1
# ELF64-NEXT:  PHDR           0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007   E 0x1
# ELF64-NEXT:  NULL           0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007   E 0x1
# ELF64-NEXT:  DYNAMIC        0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1
# ELF64-NEXT:  INTERP         0x000552 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW  0x1
# ELF64-NEXT:      [Requesting program interpreter: ABC]
# ELF64-NEXT:  NOTE           0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  SHLIB          0x000548 0x0000000000001000 0x0000000000001000 0x000001 0x000001     0x1
# ELF64-NEXT:  TLS            0x000556 0x0000000000004000 0x0000000000004000 0x000001 0x000001     0x1
# ELF64-NEXT:  <unknown>: 0x60000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  GNU_EH_FRAME   0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  SUNW_UNWIND    0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  GNU_STACK      0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  GNU_RELRO      0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  GNU_PROPERTY   0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x65a3dbe6 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x65a3dbe7 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x65a41be6 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x6fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x70000001 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x70000003 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-NEXT:  <unknown>: 0x7fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003     0x1
# ELF64-EMPTY:

#      MAPPING: Section to Segment mapping:
# MAPPING-NEXT:  Segment Sections...
# MAPPING-NEXT:   00     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   01     .bar.begin .bar.end {{$}}
# MAPPING-NEXT:   02     .bar.begin .bar.end {{$}}
# MAPPING-NEXT:   03     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   04     .interp {{$}}
# MAPPING-NEXT:   05     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   06     .foo.begin {{$}}
# MAPPING-NEXT:   07     .tls {{$}}
# MAPPING-NEXT:   08     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   09     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   10     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   11     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   12     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   13     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   14     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   15     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   16     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   17     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   18     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   19     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   20     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   21     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   22     .foo.begin .foo.end {{$}}
# MAPPING-NEXT:   None   .unused .strtab .shstrtab {{$}}

--- !ELF
FileHeader:
  Class:   ELFCLASS[[BITS]]
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: [[MACHINE]]
  Entry:   0x12345678
Sections:
  - Name:    .foo.begin
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC ]
    Address: 0x1000
    Size:    0x1
  - Name:    .foo.end
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC ]
    Size:    0x2
  - Name:    .bar.begin
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC ]
    Address: 0x2000
    Size:    0x3
  - Name:    .bar.end
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC ]
    Size:    0x4
  - Name:    .interp
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC ]
    Address: 0x3000
    Content: "41424300" ## "ABC"
  - Name:    .tls
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC, SHF_TLS ]
    Address: 0x4000
    Size:    0x1
  - Name:    .unused
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC, SHF_TLS ]
    Address: 0x5000
    Size:    0x1
ProgramHeaders:
## Case 1: an arbitrary segment with sections.
  - Type:  PT_PHDR
    Flags: [ PF_W ]
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 2: another segment with different sections.
  - Type:  PT_PHDR
    Flags: [ PF_X ]
    VAddr: 0x2000
    Sections:
      - Section: .bar.begin
      - Section: .bar.end
## Case 3: the PT_NULL segment.
  - Type:  PT_NULL
    Flags: [ PF_X ]
    VAddr: 0x2000
    Sections:
      - Section: .bar.begin
      - Section: .bar.end
## Case 4: the PT_DYNAMIC segment.
  - Type:  PT_DYNAMIC
    Flags: [ PF_R, PF_W, PF_X ]
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 5: the PT_INTERP segment.
  - Type:  PT_INTERP
    Flags: [ PF_R, PF_W ]
    VAddr: 0x3000
    Sections:
      - Section: .interp
## Case 6: the PT_NOTE segment.
  - Type: PT_NOTE
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 7: the PT_SHLIB segment.
  - Type: PT_SHLIB
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
## Case 8: the PT_TLS segment.
  - Type: PT_TLS
    VAddr: 0x4000
    Sections:
      - Section: .tls
## Case 9: the PT_LOOS segment.
  - Type:  0x60000000 ## PT_LOOS
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 10: the PT_GNU_EH_FRAME segment.
  - Type: PT_GNU_EH_FRAME
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 11: the PT_SUNW_UNWIND segment.
  - Type: 0x6464e550 ## PT_SUNW_UNWIND
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 12: the PT_GNU_STACK segment.
  - Type: PT_GNU_STACK
    Sections:
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 13: the PT_GNU_RELRO segment.
  - Type: PT_GNU_RELRO
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 14: the PT_GNU_PROPERTY segment.
  - Type: PT_GNU_PROPERTY
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 15: the PT_OPENBSD_RANDOMIZE segment.
  - Type: 0x65a3dbe6 ## PT_OPENBSD_RANDOMIZE
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 16: the PT_OPENBSD_WXNEEDED segment.
  - Type: 0x65a3dbe7 ## PT_OPENBSD_WXNEEDED
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 17: the PT_OPENBSD_BOOTDATA segment.
  - Type: 0x65a41be6 ## PT_OPENBSD_BOOTDATA
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 18: the PT_HIOS segment.
  - Type: 0x6fffffff ## PT_HIOS
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 19: the PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO segment.
  - Type: 0x70000000 ## PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 20: the PT_ARM_EXIDX/PT_MIPS_RTPROC segment.
  - Type: 0x70000001 ## PT_ARM_EXIDX, PT_MIPS_RTPROC
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 20: the PT_MIPS_OPTIONS segment.
  - Type: 0x70000002 ## PT_MIPS_OPTIONS
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 21: the PT_MIPS_ABIFLAGS segment.
  - Type: 0x70000003 ## PT_MIPS_ABIFLAGS
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end
## Case 22: the PT_HIPROC segment.
  - Type: 0x7fffffff ## PT_HIPROC
    VAddr: 0x1000
    Sections:
      - Section: .foo.begin
      - Section: .foo.end

## Check how we dump ARM specific program headers.
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf
# RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM

# ARM:      <unknown>: 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
# ARM-NEXT:            EXIDX      0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
# ARM-NEXT: <unknown>: 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1

## Check how we dump MIPS specific program headers.
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf
# RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS

# MIPS:      REGINFO  0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
# MIPS-NEXT: RTPROC   0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
# MIPS-NEXT: OPTIONS  0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
# MIPS-NEXT: ABIFLAGS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1

## Check we report a warning when a program interpreter name is non-null-terminated or when
## PT_INTERP has an offset that goes past the end of the file.
# RUN: yaml2obj --docnum=2 %s -o %t.err

## Show the size of the output produced. It is used in the YAML below.
# RUN: wc -c < %t.err | FileCheck %s --check-prefix=SIZE
# SIZE: 560

## Write the additional 'C', '\0, 'C' bytes to the end.
# RUN: echo -n -e "C\x00C" >> %t.err

# RUN: llvm-readelf --program-headers %t.err 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t.err --check-prefix=ERROR-INTERP

# ERROR-INTERP:      Type           Offset
# ERROR-INTERP-NEXT: INTERP         0x000[[#%x,OFFSET:0x230]]
# ERROR-INTERP-NEXT:     [Requesting program interpreter: C]
# ERROR-INTERP-NEXT: INTERP         0x000[[#OFFSET + 1]]
# ERROR-INTERP-NEXT:     [Requesting program interpreter: ]
# ERROR-INTERP-NEXT: INTERP         0x000[[#OFFSET + 2]]
# ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+2]]: it is not null-terminated
# ERROR-INTERP-NEXT: INTERP         0x000[[#OFFSET + 3]]
# ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+3]]: it goes past the end of the file (0x[[#OFFSET + 3]])
# ERROR-INTERP-NEXT: INTERP         0xaabbccddeeff1122
# ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0xaabbccddeeff1122: it goes past the end of the file (0x[[#OFFSET + 3]])

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
ProgramHeaders:
## Case 1: the offset points to the first additional byte.
  - Type:   PT_INTERP
    Offset: 560
## Case 1: the offset points to the second additional byte,
##         which is a null byte.
  - Type:   PT_INTERP
    Offset: 561
## Case 3: the offset points to the third additional
##         byte, which is the last byte in the file.
  - Type:   PT_INTERP
    Offset: 562
## Case 4: the offset goes 1 byte past the end of the file.
  - Type:   PT_INTERP
    Offset: 563
## Case 5: an arbitrary large offset that goes past the end of the file.
  - Type:   PT_INTERP
    Offset: 0xAABBCCDDEEFF1122

## Check we report a warning when we are unable to read program headers.
## Case A: the e_phentsize field is invalid.
# RUN: yaml2obj --docnum=3 -DPHENTSIZE=1 %s -o %t.phdr.err
# RUN: llvm-readelf --program-headers %t.phdr.err 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t.phdr.err --check-prefix=WARN-PHENTSIZE

# WARN-PHENTSIZE:      Program Headers:
# WARN-PHENTSIZE-NEXT:   Type Offset VirtAddr PhysAddr FileSiz  MemSiz Flg Align
# WARN-PHENTSIZE-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
# WARN-PHENTSIZE:      Section to Segment mapping:
# WARN-PHENTSIZE-NEXT:   Segment Sections...
# WARN-PHENTSIZE-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: invalid e_phentsize: 1

--- !ELF
FileHeader:
  Class:      ELFCLASS64
  Data:       ELFDATA2LSB
  Type:       ET_EXEC
  Machine:    EM_X86_64
  EPhEntSize: [[PHENTSIZE=56]]
  EPhOff:     [[PHOFF=64]]
Sections:
  - Name: .foo
    Type: SHT_PROGBITS
ProgramHeaders:
  - Type: PT_PHDR
    Sections:
      - Section: .foo

## Case B: the value of the e_phoff field is invalid.

## Check that we do not report a warning when the program header table ends right before the end of the file.
## 0x160 + size of headers (56) == file size.
# RUN: yaml2obj --docnum=3 -DPHOFF=0x160 %s -o %t.phdr.no.err2
# RUN: llvm-readelf %t.phdr.no.err2 --program-headers 2>&1 | FileCheck %s --implicit-check-not=warning:

## Check we report a warning when e_phoff goes 1 byte past the end of the file.
# RUN: yaml2obj --docnum=3 -DPHOFF=0x161 %s -o %t.phdr.err2
# RUN: llvm-readelf --program-headers %t.phdr.err2 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t.phdr.err2 --check-prefix=WARN-PHOFF -DOFF=0x161

# WARN-PHOFF:      Program Headers:
# WARN-PHOFF-NEXT:   Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
# WARN-PHOFF-NEXT: warning: '[[FILE]]': unable to dump program headers: program headers are longer than binary of size 408: e_phoff = [[OFF]], e_phnum = 1, e_phentsize = 56
# WARN-PHOFF:      Section to Segment mapping:
# WARN-PHOFF-NEXT:   Segment Sections...
# WARN-PHOFF-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: program headers are longer than binary of size 408: e_phoff = [[OFF]], e_phnum = 1, e_phentsize = 56

## Check we report a warning when the value of e_phoff is so large that
## e_phoff + e_phnum * e_phentsize > UINT64_MAX.
# RUN: yaml2obj --docnum=3 -DPHOFF=0xffffffffffffffff %s -o %t.phdr.err3
# RUN: llvm-readelf --program-headers %t.phdr.err3 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t.phdr.err3 --check-prefix=WARN-PHOFF -DOFF=0xffffffffffffffff