1## Check how we dump invalid SHT_RISCV_ATTRIBUTES sections.
2
3## This test case is used to ensure llvm-readobj checks the version of
4## attribute sections correctly. The only supported format is 'A' (41),
5## here we use 'B' (42).
6
7# RUN: yaml2obj %s -D BITS=32 -DCONTENT=42 -o %t1.32.o
8# RUN: llvm-readobj -A %t1.32.o 2>&1 | \
9# RUN:   FileCheck -DFILE=%t1 %s --implicit-check-not=warning: --check-prefix=ERR-FORMAT
10# RUN: yaml2obj %s -D BITS=64 -DCONTENT=42 -o %t1.64.o
11# RUN: llvm-readobj -A %t1.64.o 2>&1 | \
12# RUN:   FileCheck -DFILE=%t1 %s --implicit-check-not=warning: --check-prefix=ERR-FORMAT
13
14# ERR-FORMAT:      BuildAttributes {
15# ERR-FORMAT-NEXT:   FormatVersion: 0x42
16# ERR-FORMAT-NEXT: warning: '[[FILE]].{{32|64}}.o': unable to dump attributes from the SHT_RISCV_ATTRIBUTES section with index 1: unrecognized format-version: 0x42
17# ERR-FORMAT-NEXT: }
18
19--- !ELF
20FileHeader:
21  Class:   ELFCLASS[[BITS=64]]
22  Data:    ELFDATA2LSB
23  Type:    ET_REL
24  Machine: EM_RISCV
25Sections:
26  - Name:     .riscv.attributes
27    Type:     SHT_RISCV_ATTRIBUTES
28    Content:  [[CONTENT]]
29    ShOffset: [[SHOFFSET=<none>]]
30
31## Check we report a warning when we are unable to parse the attribute section data.
32## FIXME: this test case documents that we don't close the "Section X" clause of
33##        the output properly when a warning is reported by the attributes parser.
34
35# RUN: yaml2obj %s -D BITS=32 -DCONTENT=4100000000 -o %t2.32.o
36# RUN: llvm-readobj -A %t2.32.o 2>&1 | \
37# RUN:   FileCheck -DFILE=%t2 %s --implicit-check-not=warning: --check-prefix=ERR-LENGTH
38# RUN: yaml2obj %s -D BITS=64 -DCONTENT=4100000000 -o %t2.64.o
39# RUN: llvm-readobj -A %t2.64.o 2>&1 | \
40# RUN:   FileCheck -DFILE=%t2 %s --implicit-check-not=warning: --check-prefix=ERR-LENGTH
41
42# ERR-LENGTH:      BuildAttributes {
43# ERR-LENGTH-NEXT:   FormatVersion: 0x41
44# ERR-LENGTH-NEXT:   Section 1 {
45# ERR-LENGTH-NEXT: warning: '[[FILE]].{{32|64}}.o': unable to dump attributes from the SHT_RISCV_ATTRIBUTES section with index 1: invalid section length 0 at offset 0x1
46# ERR-LENGTH-NEXT:   }
47# ERR-LENGTH-NOT: {{.}}
48
49## Check that we don't report a warning when the SHT_RISCV_ATTRIBUTES section contains the
50## valid format version byte and no other data.
51
52# RUN: yaml2obj %s -DCONTENT=41 -o %t3.o
53# RUN: llvm-readobj -A %t3.o 2>&1 | \
54# RUN:   FileCheck %s --implicit-check-not=warning: --check-prefix=NO-CONTENT
55
56# NO-CONTENT:      BuildAttributes {
57# NO-CONTENT-NEXT:   FormatVersion: 0x41
58# NO-CONTENT-NEXT: }
59
60## Check we report a warning when we are unable to read the content of the SHT_RISCV_ATTRIBUTES section.
61
62# RUN: yaml2obj %s -DCONTENT="''" -DSHOFFSET=0xffffffff -o %t4.o
63# RUN: llvm-readobj -A %t4.o 2>&1 | \
64# RUN:   FileCheck %s -DFILE=%t4.o --implicit-check-not=warning: --check-prefix=BROKEN-CONTENT
65
66# BROKEN-CONTENT:      BuildAttributes {
67# BROKEN-CONTENT-NEXT: warning: '[[FILE]]': unable to read the content of the SHT_RISCV_ATTRIBUTES section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x168)
68# BROKEN-CONTENT-NEXT: }
69
70# RUN: yaml2obj %s -DCONTENT="''" -o %t5.o
71# RUN: llvm-readobj -A %t5.o 2>&1 | \
72# RUN:   FileCheck %s -DFILE=%t5.o --implicit-check-not=warning: --check-prefix=EMPTY-CONTENT
73
74# EMPTY-CONTENT:      BuildAttributes {
75# EMPTY-CONTENT-NEXT: warning: '[[FILE]]': the SHT_RISCV_ATTRIBUTES section with index 1 is empty
76# EMPTY-CONTENT-NEXT: }
77