Skip to content

Commit 7ef1763

Browse files
author
Georgii Rymar
committed
[llvm-readobj] - Stop using unwrapOrError() for all program_headers() calls.
program_headers() returns the list of program headers. This change allows to continue attempt of dumping when something is wrong with program headers. Differential revision: https://reviews.llvm.org/D83554
1 parent 6e198aa commit 7ef1763

File tree

8 files changed

+303
-36
lines changed

8 files changed

+303
-36
lines changed

llvm/test/Object/invalid.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ Sections:
228228
Link: .symtab
229229
Symbols: []
230230

231-
## Check that llvm-readobj reports an error if the e_phentsize field is broken.
231+
## Check that llvm-readobj reports a warning when the e_phentsize field is broken.
232232

233-
# RUN: not llvm-readobj --program-headers %p/Inputs/invalid-e_shnum.elf 2>&1 | \
233+
# RUN: llvm-readobj --program-headers %p/Inputs/invalid-e_shnum.elf 2>&1 | \
234234
# RUN: FileCheck -DFILE=%p/Inputs/invalid-e_shnum.elf --check-prefix=INVALID-PH-ENTSIZE %s
235235

236-
# INVALID-PH-ENTSIZE: error: '[[FILE]]': invalid e_phentsize: 12336
236+
# INVALID-PH-ENTSIZE: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 12336
237237

238238
## Check that llvm-readobj reports a warning when we have no SHT_SYMTAB_SHNDX section,
239239
## but have a symbol referencing it.
@@ -409,10 +409,10 @@ DynamicSymbols:
409409
## ELF header contains e_phentsize field with a value != sizeof(Elf_Phdr).
410410
## Check llvm-readobj reports it.
411411

412-
# RUN: not llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \
412+
# RUN: llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \
413413
# RUN: | FileCheck -DFILE=%p/Inputs/corrupt-invalid-phentsize.elf.x86-64 --check-prefix=PHENTSIZE %s
414414

415-
# PHENTSIZE: error: '[[FILE]]': invalid e_phentsize: 57
415+
# PHENTSIZE: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 57
416416

417417
## The dynamic table contains DT_STRTAB with a value that is not in any loadable segment.
418418
## Check llvm-readobj reports it.

llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test

Lines changed: 156 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@
140140

141141
--- !ELF
142142
FileHeader:
143-
Class: ELFCLASS64
144-
Data: ELFDATA2LSB
145-
Type: ET_EXEC
146-
Machine: EM_X86_64
143+
Class: ELFCLASS64
144+
Data: ELFDATA2LSB
145+
Type: ET_EXEC
146+
Machine: EM_X86_64
147+
EPhEntSize: [[PHENTSIZE=56]]
147148
Sections:
148149
- Name: .dynstr
149150
Type: SHT_STRTAB
@@ -637,3 +638,154 @@ Sections:
637638
Value: 0x1
638639
- Tag: DT_NULL
639640
Value: 0x0
641+
642+
## Check how we dump dynamic tags when we are unable to read program headers.
643+
# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 %s -o %t-phentsize-err
644+
# RUN: llvm-readobj --dynamic-table %t-phentsize-err 2>&1 | \
645+
# RUN: FileCheck %s --implicit-check-not=warning: -DFILE=%t-phentsize-err \
646+
# RUN: --check-prefixes=PHENTSIZE-WARN,PHENTSIZE-LLVM
647+
# RUN: llvm-readelf --dynamic-table %t-phentsize-err 2>&1 | \
648+
# RUN: FileCheck %s --implicit-check-not=warning: -DFILE=%t-phentsize-err \
649+
# RUN: --check-prefixes=PHENTSIZE-WARN,PHENTSIZE-GNU
650+
651+
# PHENTSIZE-WARN: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1
652+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_HASH: invalid e_phentsize: 1
653+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_STRTAB: invalid e_phentsize: 1
654+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_SYMTAB: invalid e_phentsize: 1
655+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_RELA: invalid e_phentsize: 1
656+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': DT_SYMENT value of 0x987 is not the size of a symbol (0x18)
657+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_REL: invalid e_phentsize: 1
658+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_JMPREL: invalid e_phentsize: 1
659+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_RELR: invalid e_phentsize: 1
660+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_ANDROID_RELR: invalid e_phentsize: 1
661+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_GNU_HASH: invalid e_phentsize: 1
662+
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': string table was not found
663+
664+
# PHENTSIZE-LLVM: DynamicSection [ (61 entries)
665+
# PHENTSIZE-LLVM-NEXT: Tag Type Name/Value
666+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
667+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes)
668+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000003 PLTGOT 0x1000
669+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000004 HASH 0x1000
670+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
671+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000006 SYMTAB 0x1000
672+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000007 RELA 0x1000
673+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000008 RELASZ 16 (bytes)
674+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000009 RELAENT 1929 (bytes)
675+
# PHENTSIZE-LLVM-NEXT: 0x000000000000000A STRSZ 16 (bytes)
676+
# PHENTSIZE-LLVM-NEXT: 0x000000000000000B SYMENT 2439 (bytes)
677+
# PHENTSIZE-LLVM-NEXT: 0x000000000000000C INIT 0x1000
678+
# PHENTSIZE-LLVM-NEXT: 0x000000000000000D FINI 0x1000
679+
# PHENTSIZE-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
680+
# PHENTSIZE-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
681+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890ABCDEF
682+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000011 REL 0x1000
683+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000012 RELSZ 16 (bytes)
684+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000013 RELENT 291 (bytes)
685+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000014 PLTREL RELA
686+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000015 DEBUG 0xFEDCBA0987654321
687+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000016 TEXTREL 0x1122334455667788
688+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000017 JMPREL 0x1000
689+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000018 BIND_NOW 0x8877665544332211
690+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000019 INIT_ARRAY 0x1000
691+
# PHENTSIZE-LLVM-NEXT: 0x000000000000001A FINI_ARRAY 0x1000
692+
# PHENTSIZE-LLVM-NEXT: 0x000000000000001B INIT_ARRAYSZ 16 (bytes)
693+
# PHENTSIZE-LLVM-NEXT: 0x000000000000001C FINI_ARRAYSZ 16 (bytes)
694+
# PHENTSIZE-LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [<?>]
695+
# PHENTSIZE-LLVM-NEXT: 0x000000000000001E FLAGS ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS
696+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000020 PREINIT_ARRAY 0x1000
697+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000021 PREINIT_ARRAYSZ 16 (bytes)
698+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000022 SYMTAB_SHNDX 0x1000
699+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000023 RELRSZ 0x10
700+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000024 RELR 0x1000
701+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000025 RELRENT 0x4321
702+
# PHENTSIZE-LLVM-NEXT: 0x000000006000000F ANDROID_REL 0x1000
703+
# PHENTSIZE-LLVM-NEXT: 0x0000000060000010 ANDROID_RELSZ 16 (bytes)
704+
# PHENTSIZE-LLVM-NEXT: 0x0000000060000011 ANDROID_RELA 0x1000
705+
# PHENTSIZE-LLVM-NEXT: 0x0000000060000012 ANDROID_RELASZ 16 (bytes)
706+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFE000 ANDROID_RELR 0x1000
707+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFE001 ANDROID_RELRSZ 0x10
708+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFE003 ANDROID_RELRENT 0x1234
709+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFEF5 GNU_HASH 0x1000
710+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFEF6 TLSDESC_PLT 0x1000
711+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFEF7 TLSDESC_GOT 0x1000
712+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFF9 RELACOUNT 0
713+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFA RELCOUNT 0
714+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON PIE {{$}}
715+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFF0 VERSYM 0x1000
716+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFC VERDEF 0x1000
717+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFD VERDEFNUM 0
718+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFE VERNEED 0x1000
719+
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFF VERNEEDNUM 0
720+
# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
721+
# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
722+
# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
723+
# PHENTSIZE-LLVM-NEXT: 0x0000000012345678 <unknown:>0x12345678 0x8765432187654321
724+
# PHENTSIZE-LLVM-NEXT: 0x000000006ABCDEF0 <unknown:>0x6abcdef0 0x9988776655443322
725+
# PHENTSIZE-LLVM-NEXT: 0x0000000076543210 <unknown:>0x76543210 0x5555666677778888
726+
# PHENTSIZE-LLVM-NEXT: 0x0000000000000000 NULL 0x0
727+
# PHENTSIZE-LLVM-NEXT: ]
728+
729+
# PHENTSIZE-GNU: Dynamic section at offset 0xc0 contains 61 entries:
730+
# PHENTSIZE-GNU-NEXT: Tag Type Name/Value
731+
# PHENTSIZE-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
732+
# PHENTSIZE-GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes)
733+
# PHENTSIZE-GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000
734+
# PHENTSIZE-GNU-NEXT: 0x0000000000000004 (HASH) 0x1000
735+
# PHENTSIZE-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
736+
# PHENTSIZE-GNU-NEXT: 0x0000000000000006 (SYMTAB) 0x1000
737+
# PHENTSIZE-GNU-NEXT: 0x0000000000000007 (RELA) 0x1000
738+
# PHENTSIZE-GNU-NEXT: 0x0000000000000008 (RELASZ) 16 (bytes)
739+
# PHENTSIZE-GNU-NEXT: 0x0000000000000009 (RELAENT) 1929 (bytes)
740+
# PHENTSIZE-GNU-NEXT: 0x000000000000000a (STRSZ) 16 (bytes)
741+
# PHENTSIZE-GNU-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes)
742+
# PHENTSIZE-GNU-NEXT: 0x000000000000000c (INIT) 0x1000
743+
# PHENTSIZE-GNU-NEXT: 0x000000000000000d (FINI) 0x1000
744+
# PHENTSIZE-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
745+
# PHENTSIZE-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
746+
# PHENTSIZE-GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef
747+
# PHENTSIZE-GNU-NEXT: 0x0000000000000011 (REL) 0x1000
748+
# PHENTSIZE-GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes)
749+
# PHENTSIZE-GNU-NEXT: 0x0000000000000013 (RELENT) 291 (bytes)
750+
# PHENTSIZE-GNU-NEXT: 0x0000000000000014 (PLTREL) RELA
751+
# PHENTSIZE-GNU-NEXT: 0x0000000000000015 (DEBUG) 0xfedcba0987654321
752+
# PHENTSIZE-GNU-NEXT: 0x0000000000000016 (TEXTREL) 0x1122334455667788
753+
# PHENTSIZE-GNU-NEXT: 0x0000000000000017 (JMPREL) 0x1000
754+
# PHENTSIZE-GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x8877665544332211
755+
# PHENTSIZE-GNU-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x1000
756+
# PHENTSIZE-GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000
757+
# PHENTSIZE-GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
758+
# PHENTSIZE-GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
759+
# PHENTSIZE-GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [<?>]
760+
# PHENTSIZE-GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS
761+
# PHENTSIZE-GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000
762+
# PHENTSIZE-GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes)
763+
# PHENTSIZE-GNU-NEXT: 0x0000000000000022 (SYMTAB_SHNDX) 0x1000
764+
# PHENTSIZE-GNU-NEXT: 0x0000000000000023 (RELRSZ) 0x10
765+
# PHENTSIZE-GNU-NEXT: 0x0000000000000024 (RELR) 0x1000
766+
# PHENTSIZE-GNU-NEXT: 0x0000000000000025 (RELRENT) 0x4321
767+
# PHENTSIZE-GNU-NEXT: 0x000000006000000f (ANDROID_REL) 0x1000
768+
# PHENTSIZE-GNU-NEXT: 0x0000000060000010 (ANDROID_RELSZ) 16 (bytes)
769+
# PHENTSIZE-GNU-NEXT: 0x0000000060000011 (ANDROID_RELA) 0x1000
770+
# PHENTSIZE-GNU-NEXT: 0x0000000060000012 (ANDROID_RELASZ) 16 (bytes)
771+
# PHENTSIZE-GNU-NEXT: 0x000000006fffe000 (ANDROID_RELR) 0x1000
772+
# PHENTSIZE-GNU-NEXT: 0x000000006fffe001 (ANDROID_RELRSZ) 0x10
773+
# PHENTSIZE-GNU-NEXT: 0x000000006fffe003 (ANDROID_RELRENT) 0x1234
774+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x1000
775+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffef6 (TLSDESC_PLT) 0x1000
776+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffef7 (TLSDESC_GOT) 0x1000
777+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffff9 (RELACOUNT) 0
778+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffa (RELCOUNT) 0
779+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffb (FLAGS_1) NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON PIE
780+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffff0 (VERSYM) 0x1000
781+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffc (VERDEF) 0x1000
782+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffd (VERDEFNUM) 0
783+
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x1000
784+
# PHENTSIZE-GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 0
785+
# PHENTSIZE-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
786+
# PHENTSIZE-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
787+
# PHENTSIZE-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
788+
# PHENTSIZE-GNU-NEXT: 0x0000000012345678 (<unknown:>0x12345678) 0x8765432187654321
789+
# PHENTSIZE-GNU-NEXT: 0x000000006abcdef0 (<unknown:>0x6abcdef0) 0x9988776655443322
790+
# PHENTSIZE-GNU-NEXT: 0x0000000076543210 (<unknown:>0x76543210) 0x5555666677778888
791+
# PHENTSIZE-GNU-NEXT: 0x0000000000000000 (NULL) 0x0

llvm/test/tools/llvm-readobj/ELF/gnu-notes.test

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@
8383

8484
--- !ELF
8585
FileHeader:
86-
Class: ELFCLASS64
87-
Data: ELFDATA2LSB
88-
Type: ET_EXEC
89-
Machine: EM_X86_64
86+
Class: ELFCLASS64
87+
Data: ELFDATA2LSB
88+
Type: ET_EXEC
89+
Machine: EM_X86_64
90+
EPhEntSize: [[PHENTSIZE=56]]
91+
SHNum: [[SHNUM=6]]
9092
Sections:
9193
- Name: .note.ABI-tag
9294
Type: SHT_NOTE
@@ -193,3 +195,16 @@ ProgramHeaders:
193195
FileSize: 0xffff0000
194196
Sections:
195197
- Section: .note
198+
199+
## Check we report a warning when we are unable to locate the PT_NOTE
200+
## segment because of broken program headers.
201+
# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 -DSHNUM=0 %s -o %t6.so
202+
# RUN: llvm-readelf --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-GNU
203+
# RUN: llvm-readobj --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-LLVM
204+
205+
# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1
206+
# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
207+
208+
# PHENTSIZE-WARN-LLVM: Notes [
209+
# PHENTSIZE-WARN-LLVM-NEXT: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
210+
# PHENTSIZE-WARN-LLVM-NEXT: ]

llvm/test/tools/llvm-readobj/ELF/gnu-phdrs.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,30 @@ ProgramHeaders:
354354
## Case 5: an arbitrary large offset that goes past the end of the file.
355355
- Type: PT_INTERP
356356
Offset: 0xAABBCCDDEEFF1122
357+
358+
## Check we report a warning when we are unable to read program headers.
359+
# RUN: yaml2obj --docnum=3 %s -o %t.phdr.err
360+
# RUN: llvm-readelf --program-headers %t.phdr.err 2>&1 | \
361+
# RUN: FileCheck %s -DFILE=%t.phdr.err --check-prefix=WARN-PHENTSIZE
362+
363+
# WARN-PHENTSIZE: Program Headers:
364+
# WARN-PHENTSIZE-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
365+
# WARN-PHENTSIZE-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
366+
# WARN-PHENTSIZE: Section to Segment mapping:
367+
# WARN-PHENTSIZE-NEXT: Segment Sections...
368+
# WARN-PHENTSIZE-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: invalid e_phentsize: 1
369+
370+
--- !ELF
371+
FileHeader:
372+
Class: ELFCLASS64
373+
Data: ELFDATA2LSB
374+
Type: ET_EXEC
375+
Machine: EM_X86_64
376+
EPhEntSize: 1
377+
Sections:
378+
- Name: .foo
379+
Type: SHT_PROGBITS
380+
ProgramHeaders:
381+
- Type: PT_PHDR
382+
Sections:
383+
- Section: .foo

llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping.test

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
--- !ELF
1616
FileHeader:
17-
Class: ELFCLASS64
18-
Data: ELFDATA2LSB
19-
Type: ET_EXEC
20-
Machine: EM_X86_64
21-
Entry: 0x12345678
17+
Class: ELFCLASS64
18+
Data: ELFDATA2LSB
19+
Type: ET_EXEC
20+
Machine: EM_X86_64
21+
EPhEntSize: [[PHENTSIZE=56]]
2222
Sections:
2323
- Name: .foo.begin
2424
Type: SHT_PROGBITS
@@ -74,3 +74,12 @@ ProgramHeaders:
7474
# NO-SECHDRS-NEXT: 00 {{$}}
7575
# NO-SECHDRS-NEXT: 01 {{$}}
7676
# NO-SECHDRS-NOT: {{.}}
77+
78+
## Check we report a warning when we are unable to read program headers.
79+
# RUN: yaml2obj %s -DPHENTSIZE=1 -o %t64-err1.elf
80+
# RUN: llvm-readelf --section-mapping %t64-err1.elf 2>&1 | \
81+
# RUN: FileCheck %s -DFILE=%t64-err1.elf --check-prefix=PHENTSIZE
82+
83+
# PHENTSIZE: Section to Segment mapping:
84+
# PHENTSIZE-NEXT: Segment Sections...
85+
# PHENTSIZE-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: invalid e_phentsize: 1

llvm/test/tools/llvm-readobj/ELF/program-headers.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,27 @@ ProgramHeaders:
168168
- Type: 0x65a3dbe6 ## PT_OPENBSD_RANDOMIZE
169169
- Type: 0x65a3dbe7 ## PT_OPENBSD_WXNEEDED
170170
- Type: 0x65a41be6 ## PT_OPENBSD_BOOTDATA
171+
172+
## Check we report a warning when we are unable to read program headers.
173+
# RUN: yaml2obj --docnum=2 %s -o %t.err
174+
# RUN: llvm-readobj --program-headers %t.err 2>&1 | \
175+
# RUN: FileCheck %s -DFILE=%t.err --check-prefix=WARN-PHENTSIZE
176+
177+
# WARN-PHENTSIZE: ProgramHeaders [
178+
# WARN-PHENTSIZE-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
179+
# WARN-PHENTSIZE-NEXT: ]
180+
181+
--- !ELF
182+
FileHeader:
183+
Class: ELFCLASS64
184+
Data: ELFDATA2LSB
185+
Type: ET_EXEC
186+
Machine: EM_X86_64
187+
EPhEntSize: 1
188+
Sections:
189+
- Name: .foo
190+
Type: SHT_PROGBITS
191+
ProgramHeaders:
192+
- Type: PT_PHDR
193+
Sections:
194+
- Section: .foo

llvm/test/tools/yaml2obj/ELF/header-sh-fields.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ ProgramHeaders:
9494

9595
## Override the e_phentsize field.
9696
# RUN: yaml2obj --docnum=2 %s -DPHENTSIZE=1 -o %t8
97-
# RUN: not llvm-readelf --file-headers %t8 2>&1 | FileCheck %s --check-prefix=PHENTSIZE
97+
# RUN: llvm-readelf --file-headers %t8 | FileCheck %s --check-prefix=PHENTSIZE
9898

99-
# PHENTSIZE: invalid e_phentsize: 1{{$}}
99+
# PHENTSIZE: Size of program headers: 1 (bytes)

0 commit comments

Comments
 (0)