151 lines · plain
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 in4## 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.o6# $ bin/llvm-objcopy --dump-section=.note.foo=tmp.txt tmp.o /dev/null7# $ xxd -p tmp.txt | tr -d '\n'; echo8# using the assembly shown with each test case.9 10# RUN: yaml2obj --docnum=1 %s -o %t1.o11# RUN: llvm-readelf -n %t1.o 2>&1 | FileCheck -DFILE=%t1.o %s --check-prefix=ERR-HEADER-SHORT12# RUN: llvm-readobj -n %t1.o 2>&1 | FileCheck -DFILE=%t1.o %s --check-prefix=ERR-HEADER-SHORT13 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 0x1015 16# .section ".note.foo", "a"17# .align 418# .long 5 /* namesz */19# .long end - begin /* descsz */20# .long 0x46494c45 /* type = NT_FILE */21# .asciz "CORE"22# .align 423# begin:24# .quad 0 /* no file mappings */25# end:26 27--- !ELF28FileHeader:29 Class: ELFCLASS6430 Data: ELFDATA2LSB31 Type: ET_CORE32Sections:33 - Name: .note.foo34 Type: SHT_NOTE35 Content: 0500000008000000454C4946434F524500000000000000000000000036ProgramHeaders:37 - Type: PT_NOTE38 FirstSec: .note.foo39 LastSec: .note.foo40 41# RUN: yaml2obj --docnum=2 %s -o %t2.o42# RUN: llvm-readelf -n %t2.o 2>&1 | FileCheck -DFILE=%t2.o %s --check-prefix=ERR-NULL-TERM43# RUN: llvm-readobj -n %t2.o 2>&1 | FileCheck -DFILE=%t2.o %s --check-prefix=ERR-NULL-TERM44 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 terminated46 47# .section ".note.foo", "a"48# .align 449# .long 5 /* namesz */50# .long end - begin /* descsz */51# .long 0x46494c45 /* type = NT_FILE */52# .asciz "CORE"53# .align 454# 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--- !ELF64FileHeader:65 Class: ELFCLASS6466 Data: ELFDATA2LSB67 Type: ET_CORE68Sections:69 - Name: .note.foo70 Type: SHT_NOTE71 Content: 050000002C000000454C4946434F524500000000010000000000000000100000000000000010000000000000002000000000000000300000000000007878787872ProgramHeaders:73 - Type: PT_NOTE74 FirstSec: .note.foo75 LastSec: .note.foo76 77# RUN: yaml2obj --docnum=3 %s -o %t3.o78# RUN: llvm-readelf -n %t3.o 2>&1 | FileCheck -DFILE=%t3.o %s --check-prefix=ERR-FILE-COUNT79# RUN: llvm-readobj -n %t3.o 2>&1 | FileCheck -DFILE=%t3.o %s --check-prefix=ERR-FILE-COUNT80 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 short82 83# .section ".note.foo", "a"84# .align 485# .long 5 /* namesz */86# .long end - begin /* descsz */87# .long 0x46494c45 /* type = NT_FILE */88# .asciz "CORE"89# .align 490# 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--- !ELF100FileHeader:101 Class: ELFCLASS64102 Data: ELFDATA2LSB103 Type: ET_CORE104Sections:105 - Name: .note.foo106 Type: SHT_NOTE107 Content: 050000002C000000454C4946434F5245000000000200000000000000001000000000000000100000000000000020000000000000003000000000000078797A00108ProgramHeaders:109 - Type: PT_NOTE110 FirstSec: .note.foo111 LastSec: .note.foo112 113# RUN: yaml2obj --docnum=4 %s -o %t4.o114# RUN: llvm-readelf -n %t4.o 2>&1 | FileCheck -DFILE=%t4.o %s --check-prefix=ERR-FILE-END-EARLY115# RUN: llvm-readobj -n %t4.o 2>&1 | FileCheck -DFILE=%t4.o %s --check-prefix=ERR-FILE-END-EARLY116 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 truncated118 119# .section ".note.foo", "a"120# .align 4121# .long 5 /* namesz */122# .long end - begin /* descsz */123# .long 0x46494c45 /* type = NT_FILE */124# .asciz "CORE"125# .align 4126# 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--- !ELF139FileHeader:140 Class: ELFCLASS64141 Data: ELFDATA2LSB142 Type: ET_CORE143Sections:144 - Name: .note.foo145 Type: SHT_NOTE146 Content: 0500000044000000454C4946434F5245000000000200000000000000001000000000000000100000000000000020000000000000003000000000000000400000000000000050000000000000006000000000000078797A00147ProgramHeaders:148 - Type: PT_NOTE149 FirstSec: .note.foo150 LastSec: .note.foo151