brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.1 KiB · 2d9bb1c Raw
146 lines · plain
1## If the offset and/or size fields of the PT_DYNAMIC field become corrupted,2## we should report a sensible message.3 4## Case A: Test case where the size of the PT_DYNAMIC header is too large to fit in the file,5##         but the start is within the file.6 7## Case A.1: the section header table is present in the object. Check that we report a warning about the8##           broken PT_DYNAMIC header, check we dump the dynamic table.9# RUN: yaml2obj %s -DFILESIZE=0x131 -o %t110# RUN: llvm-readobj %t1 --dynamic-table 2>&1 | FileCheck -DFILE=%t1 %s --check-prefixes=WARN1,WARN1-LLVM11# RUN: llvm-readelf %t1 --dynamic-table 2>&1 | FileCheck -DFILE=%t1 %s --check-prefixes=WARN1,WARN1-GNU12 13# WARN1: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0x131) exceeds the size of the file (0x1130)14 15# WARN1-LLVM:      DynamicSection [ (1 entries)16# WARN1-LLVM-NEXT:   Tag                Type Name/Value17# WARN1-LLVM-NEXT:   0x0000000000000000 NULL 0x018# WARN1-LLVM-NEXT: ]19 20# WARN1-GNU:       Dynamic section at offset 0x1000 contains 1 entries:21# WARN1-GNU-NEXT:   Tag                Type   Name/Value22# WARN1-GNU-NEXT:   0x0000000000000000 (NULL) 0x023 24## Case A.2: in this case we drop section headers. The dynamic table is not dumped.25# RUN: yaml2obj %s -DFILESIZE=0x12 -DNOHEADERS=true -o %t1.noheaders26# RUN: llvm-readobj %t1.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t1.noheaders %s \27# RUN:   --check-prefix=WARN1-NOHEADERS --implicit-check-not="DynamicSection ["28# RUN: llvm-readelf %t1.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t1.noheaders %s \29# RUN:   --check-prefix=WARN1-NOHEADERS --implicit-check-not="Dynamic section"30 31# WARN1-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0x12) exceeds the size of the file (0x1011)32 33## Case B: Test case where the offset of the PT_DYNAMIC header is too large to be in the file.34 35## Case B.1: the section header table is present in the object. Check that we report a warning about the36##           broken PT_DYNAMIC header. Check we also report a warning about broken fields of the SHT_DYNAMIC section.37# RUN: yaml2obj %s -DOFFSET=0x1131 -o %t238# RUN: llvm-readobj %t2 --dynamic-table 2>&1 | FileCheck -DFILE=%t2 %s \39# RUN:   --check-prefix=WARN2 --implicit-check-not=warning:40# RUN: llvm-readelf %t2 --dynamic-table 2>&1 | FileCheck -DFILE=%t2 %s \41# RUN:   --check-prefix=WARN2 --implicit-check-not=warning:42 43# WARN2: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1131) + file size (0x10) exceeds the size of the file (0x1130)44# WARN2: warning: '[[FILE]]': unable to read the dynamic table from SHT_DYNAMIC section with index 1: offset (0x1131) + size (0x10) is greater than the file size (0x1130)45# WARN2: warning: '[[FILE]]': no valid dynamic table was found46 47## Case B.2: in this case we drop section headers. The dynamic table is not dumped.48# RUN: yaml2obj %s -DOFFSET=0x1112 -DNOHEADERS=true -o %t2.noheaders49# RUN: llvm-readobj %t2.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t2.noheaders %s \50# RUN:   --check-prefix=WARN2-NOHEADERS --implicit-check-not="DynamicSection ["51# RUN: llvm-readelf %t2.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t2.noheaders %s \52# RUN:   --check-prefix=WARN2-NOHEADERS --implicit-check-not="Dynamic section"53 54# WARN2-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1112) + file size (0x10) exceeds the size of the file (0x1011)55 56## Case C: test we report a warning when the offset + the file size of the PT_DYNAMIC is so large a57##         value that it overflows the platform address size type. Check we also report a warning about58##         broken fields of the SHT_DYNAMIC section.59 60# RUN: yaml2obj %s -DOFFSET=0xffffffffffffffff -o %t361# RUN: llvm-readobj %t3 --dynamic-table 2>&1 | FileCheck -DFILE=%t3 %s \62# RUN:   --check-prefix=WARN3 --implicit-check-not=warning:63# RUN: llvm-readelf %t3 --dynamic-table 2>&1 | FileCheck -DFILE=%t3 %s \64# RUN:   --check-prefix=WARN3 --implicit-check-not=warning:65 66# WARN3: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffffffffffff) + file size (0x10) exceeds the size of the file (0x1130)67# WARN3: warning: '[[FILE]]': unable to read the dynamic table from SHT_DYNAMIC section with index 1: offset (0xffffffffffffffff) + size (0x10) is greater than the file size (0x1130)68# WARN3: warning: '[[FILE]]': no valid dynamic table was found69 70# RUN: yaml2obj %s -DNOHEADERS=true -DOFFSET=0xffffffffffffffff -o %t3.noheaders71# RUN: llvm-readobj %t3.noheaders --dynamic-table 2>&1 | \72# RUN:   FileCheck -DFILE=%t3.noheaders %s --check-prefix=WARN3-NOHEADERS73# RUN: llvm-readelf %t3.noheaders --dynamic-table 2>&1 | \74# RUN:   FileCheck -DFILE=%t3.noheaders %s --check-prefix=WARN3-NOHEADERS75 76# WARN3-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffffffffffff) + file size (0x10) exceeds the size of the file (0x1011)77 78# RUN: yaml2obj %s -DFILESIZE=0xffffffffffffffff -o %t479# RUN: llvm-readobj %t4 --dynamic-table 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=WARN480# RUN: llvm-readelf %t4 --dynamic-table 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=WARN481 82# WARN4: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffffffffffff) exceeds the size of the file (0x1130)83 84# RUN: yaml2obj %s -DNOHEADERS=true -DFILESIZE=0xffffffffffffffff -o %t4.noheaders85# RUN: llvm-readobj %t4.noheaders --dynamic-table 2>&1 | \86# RUN:   FileCheck -DFILE=%t4.noheaders %s --check-prefix=WARN4-NOHEADERS87# RUN: llvm-readelf %t4.noheaders --dynamic-table 2>&1 | \88# RUN:   FileCheck -DFILE=%t4.noheaders %s --check-prefix=WARN4-NOHEADERS89 90# WARN4-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffffffffffff) exceeds the size of the file (0x1011)91 92## Case D: the same as "Case C", but for a 32-bit object.93 94# RUN: yaml2obj %s -DBITS=32 -DFILESIZE=8 -DOFFSET=0xffffffff -o %t595# RUN: llvm-readobj %t5 --dynamic-table 2>&1 | FileCheck -DFILE=%t5 %s \96# RUN:   --check-prefix=WARN5 --implicit-check-not=warning:97# RUN: llvm-readelf %t5 --dynamic-table 2>&1 | FileCheck -DFILE=%t5 %s \98# RUN:   --check-prefix=WARN5 --implicit-check-not=warning:99 100# WARN5: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffff) + file size (0x8) exceeds the size of the file (0x10c8)101# WARN5: warning: '[[FILE]]': unable to read the dynamic table from SHT_DYNAMIC section with index 1: offset (0xffffffff) + size (0x8) is greater than the file size (0x10c8)102# WARN5: warning: '[[FILE]]': no valid dynamic table was found103 104# RUN: yaml2obj %s -DNOHEADERS=true -DBITS=32 -DFILESIZE=8 -DOFFSET=0xffffffff -o %t5.noheaders105# RUN: llvm-readobj %t5.noheaders --dynamic-table 2>&1 | \106# RUN:   FileCheck -DFILE=%t5.noheaders %s --check-prefix=WARN5-NOHEADERS107# RUN: llvm-readelf %t5.noheaders --dynamic-table 2>&1 | \108# RUN:   FileCheck -DFILE=%t5.noheaders %s --check-prefix=WARN5-NOHEADERS109 110# WARN5-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffff) + file size (0x8) exceeds the size of the file (0x1009)111 112# RUN: yaml2obj %s -DBITS=32 -DFILESIZE=0xffffffff -o %t6113# RUN: llvm-readobj %t6 --dynamic-table 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=WARN6114# RUN: llvm-readelf %t6 --dynamic-table 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=WARN6115 116# WARN6: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffff) exceeds the size of the file (0x10c8)117 118# RUN: yaml2obj %s -DNOHEADERS=true -DBITS=32 -DFILESIZE=0xffffffff -o %t6.noheaders119# RUN: llvm-readobj %t6.noheaders --dynamic-table 2>&1 | \120# RUN:   FileCheck -DFILE=%t6.noheaders %s --check-prefix=WARN6-NOHEADERS121# RUN: llvm-readelf %t6.noheaders --dynamic-table 2>&1 | \122# RUN:   FileCheck -DFILE=%t6.noheaders %s --check-prefix=WARN6-NOHEADERS123 124# WARN6-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffff) exceeds the size of the file (0x1009)125 126--- !ELF127FileHeader:128  Class: ELFCLASS[[BITS=64]]129  Data:  ELFDATA2LSB130  Type:  ET_EXEC131Sections:132  - Name:     .dynamic133    Type:     SHT_DYNAMIC134    Address:  0x1000135    Offset:   0x1000136    ShOffset: [[OFFSET=0x1000]]137    Entries:138      - Tag:   DT_NULL139        Value: 0140  - Type: SectionHeaderTable141    NoHeaders: [[NOHEADERS=false]]142ProgramHeaders:143  - Type:     PT_DYNAMIC144    FileSize: [[FILESIZE=0x10]]145    Offset:   [[OFFSET=0x1000]]146