1## Test that malformed NT_FILE sections in core files are gracefully ignored. 2 3## llvm-mc doesn't support generating ET_CORE files; the 'Content' field in 4## each of the following test cases were generated with the following steps: 5# $ llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu tmp.s -o tmp.o 6# $ bin/llvm-objcopy --dump-section=.note.foo=tmp.txt tmp.o /dev/null 7# $ xxd -p tmp.txt | tr -d '\n'; echo 8# using the assembly shown with each test case. 9 10# RUN: yaml2obj --docnum=1 %s -o %t1.o 11# RUN: llvm-readelf -n %t1.o 2>&1 | FileCheck -DFILE=%t1.o %s --check-prefix=ERR-HEADER-SHORT 12# RUN: llvm-readobj -n %t1.o 2>&1 | FileCheck -DFILE=%t1.o %s --check-prefix=ERR-HEADER-SHORT 13 14# ERR-HEADER-SHORT: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: the note of size 0x8 is too short, expected at least 0x10 15 16# .section ".note.foo", "a" 17# .align 4 18# .long 5 /* namesz */ 19# .long end - begin /* descsz */ 20# .long 0x46494c45 /* type = NT_FILE */ 21# .asciz "CORE" 22# .align 4 23# begin: 24# .quad 0 /* no file mappings */ 25# end: 26 27--- !ELF 28FileHeader: 29 Class: ELFCLASS64 30 Data: ELFDATA2LSB 31 Type: ET_CORE 32Sections: 33 - Name: .note.foo 34 Type: SHT_NOTE 35 Content: 0500000008000000454C4946434F5245000000000000000000000000 36ProgramHeaders: 37 - Type: PT_NOTE 38 FirstSec: .note.foo 39 LastSec: .note.foo 40 41# RUN: yaml2obj --docnum=2 %s -o %t2.o 42# RUN: llvm-readelf -n %t2.o 2>&1 | FileCheck -DFILE=%t2.o %s --check-prefix=ERR-NULL-TERM 43# RUN: llvm-readobj -n %t2.o 2>&1 | FileCheck -DFILE=%t2.o %s --check-prefix=ERR-NULL-TERM 44 45# ERR-NULL-TERM: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: the note is not NUL terminated 46 47# .section ".note.foo", "a" 48# .align 4 49# .long 5 /* namesz */ 50# .long end - begin /* descsz */ 51# .long 0x46494c45 /* type = NT_FILE */ 52# .asciz "CORE" 53# .align 4 54# begin: 55# .quad 1 /* 1 file mapping */ 56# .quad 4096 /* page size */ 57# .quad 0x1000 /* start #1 */ 58# .quad 0x2000 /* end #1 */ 59# .quad 0x3000 /* offset #1 */ 60# .ascii "xxxx" 61# end: 62 63--- !ELF 64FileHeader: 65 Class: ELFCLASS64 66 Data: ELFDATA2LSB 67 Type: ET_CORE 68Sections: 69 - Name: .note.foo 70 Type: SHT_NOTE 71 Content: 050000002C000000454C4946434F5245000000000100000000000000001000000000000000100000000000000020000000000000003000000000000078787878 72ProgramHeaders: 73 - Type: PT_NOTE 74 FirstSec: .note.foo 75 LastSec: .note.foo 76 77# RUN: yaml2obj --docnum=3 %s -o %t3.o 78# RUN: llvm-readelf -n %t3.o 2>&1 | FileCheck -DFILE=%t3.o %s --check-prefix=ERR-FILE-COUNT 79# RUN: llvm-readobj -n %t3.o 2>&1 | FileCheck -DFILE=%t3.o %s --check-prefix=ERR-FILE-COUNT 80 81# ERR-FILE-COUNT: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: unable to read file mappings (found 2): the note of size 0x2c is too short 82 83# .section ".note.foo", "a" 84# .align 4 85# .long 5 /* namesz */ 86# .long end - begin /* descsz */ 87# .long 0x46494c45 /* type = NT_FILE */ 88# .asciz "CORE" 89# .align 4 90# begin: 91# .quad 2 /* 2 file mappings */ 92# .quad 4096 /* page size */ 93# .quad 0x1000 /* start #1 */ 94# .quad 0x2000 /* end #1 */ 95# .quad 0x3000 /* offset #1 */ 96# .asciz "xyz" 97# end: 98 99--- !ELF 100FileHeader: 101 Class: ELFCLASS64 102 Data: ELFDATA2LSB 103 Type: ET_CORE 104Sections: 105 - Name: .note.foo 106 Type: SHT_NOTE 107 Content: 050000002C000000454C4946434F5245000000000200000000000000001000000000000000100000000000000020000000000000003000000000000078797A00 108ProgramHeaders: 109 - Type: PT_NOTE 110 FirstSec: .note.foo 111 LastSec: .note.foo 112 113# RUN: yaml2obj --docnum=4 %s -o %t4.o 114# RUN: llvm-readelf -n %t4.o 2>&1 | FileCheck -DFILE=%t4.o %s --check-prefix=ERR-FILE-END-EARLY 115# RUN: llvm-readobj -n %t4.o 2>&1 | FileCheck -DFILE=%t4.o %s --check-prefix=ERR-FILE-END-EARLY 116 117# ERR-FILE-END-EARLY: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: unable to read the file name for the mapping with index 2: the note of size 0x44 is truncated 118 119# .section ".note.foo", "a" 120# .align 4 121# .long 5 /* namesz */ 122# .long end - begin /* descsz */ 123# .long 0x46494c45 /* type = NT_FILE */ 124# .asciz "CORE" 125# .align 4 126# begin: 127# .quad 2 /* 2 file mappings */ 128# .quad 4096 /* page size */ 129# .quad 0x1000 /* start #1 */ 130# .quad 0x2000 /* end #1 */ 131# .quad 0x3000 /* offset #1 */ 132# .quad 0x4000 /* start #2 */ 133# .quad 0x5000 /* end #2 */ 134# .quad 0x6000 /* offset #2 */ 135# .asciz "xyz" 136# end: 137 138--- !ELF 139FileHeader: 140 Class: ELFCLASS64 141 Data: ELFDATA2LSB 142 Type: ET_CORE 143Sections: 144 - Name: .note.foo 145 Type: SHT_NOTE 146 Content: 0500000044000000454C4946434F5245000000000200000000000000001000000000000000100000000000000020000000000000003000000000000000400000000000000050000000000000006000000000000078797A00 147ProgramHeaders: 148 - Type: PT_NOTE 149 FirstSec: .note.foo 150 LastSec: .note.foo 151