xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/invalid-p_filesz-p_offset.test (revision a7a447be0fa934505f0c423fb97b91a68c1cc715)
133044a7aSGeorge Rimar## In this case, we have a program header with a file size that
233044a7aSGeorge Rimar## overflows the binary size. Check llvm-objcopy doesn't crash
333044a7aSGeorge Rimar## and report this error properly.
433044a7aSGeorge Rimar
533044a7aSGeorge Rimar# RUN: yaml2obj --docnum=1 %s -o %t1.o
633044a7aSGeorge Rimar# RUN: not llvm-objcopy %t1.o 2>&1 | FileCheck %s --check-prefix=ERR1
7c3bc6979SFangrui Song# ERR1: error: program header with offset 0x78 and file size 0x100000 goes past the end of the file
833044a7aSGeorge Rimar
933044a7aSGeorge Rimar--- !ELF
1033044a7aSGeorge RimarFileHeader:
1133044a7aSGeorge Rimar  Class:   ELFCLASS64
1233044a7aSGeorge Rimar  Data:    ELFDATA2LSB
1333044a7aSGeorge Rimar  Type:    ET_EXEC
1433044a7aSGeorge Rimar  Machine: EM_X86_64
1533044a7aSGeorge RimarSections:
1633044a7aSGeorge Rimar  - Name: .foo
1733044a7aSGeorge Rimar    Type: SHT_PROGBITS
1833044a7aSGeorge RimarProgramHeaders:
1933044a7aSGeorge Rimar  - Type:     PT_LOAD
2033044a7aSGeorge Rimar    FileSize: 0x100000
21*a7a447beSGeorgii Rymar    FirstSec: .foo
22*a7a447beSGeorgii Rymar    LastSec:  .foo
2333044a7aSGeorge Rimar
2433044a7aSGeorge Rimar## A similar case, but now the p_offset property of the program header is too large.
2533044a7aSGeorge Rimar
2633044a7aSGeorge Rimar# RUN: yaml2obj --docnum=2 %s -o %t2.o
2733044a7aSGeorge Rimar# RUN: not llvm-objcopy %t2.o 2>&1 | FileCheck %s --check-prefix=ERR2
2833044a7aSGeorge Rimar# ERR2: error: program header with offset 0x100000 and file size 0x1 goes past the end of the file
2933044a7aSGeorge Rimar
3033044a7aSGeorge Rimar--- !ELF
3133044a7aSGeorge RimarFileHeader:
3233044a7aSGeorge Rimar  Class:   ELFCLASS64
3333044a7aSGeorge Rimar  Data:    ELFDATA2LSB
3433044a7aSGeorge Rimar  Type:    ET_EXEC
3533044a7aSGeorge Rimar  Machine: EM_X86_64
3633044a7aSGeorge RimarProgramHeaders:
3733044a7aSGeorge Rimar  - Type:     PT_LOAD
3833044a7aSGeorge Rimar    Offset:   0x100000
3933044a7aSGeorge Rimar    FileSize: 1
40