1## Test that yaml2obj emits .debug_pubnames section.
2
3## a) Generate the '.debug_pubnames' section from the 'DWARF' entry.
4
5## Generate and verify a 32-bit little endian .debug_pubnames section.
6
7# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.le.o
8# RUN: llvm-readobj --sections --section-data %t1.le.o | \
9# RUN:   FileCheck -DSIZE=30 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-LE
10
11#            SHDR: Index: 1
12#       SHDR-NEXT: Name: .debug_pubnames (1)
13#       SHDR-NEXT: Type: SHT_PROGBITS (0x1)
14#       SHDR-NEXT: Flags [ (0x0)
15#       SHDR-NEXT: ]
16#       SHDR-NEXT: Address: 0x0
17#       SHDR-NEXT: Offset: 0x40
18#       SHDR-NEXT: Size: [[SIZE]]
19#       SHDR-NEXT: Link: 0
20#       SHDR-NEXT: Info: 0
21#       SHDR-NEXT: AddressAlignment: [[ADDRALIGN]]
22#       SHDR-NEXT: EntrySize: 0
23# DWARF32-LE-NEXT: SectionData (
24# DWARF32-LE-NEXT:   0000: 34120000 02003412 00002143 00007856 |4.....4...!C..xV|
25##                         ^-------                            unit_length (4-byte)
26##                                  ^---                       version (2-byte)
27##                                      ^--------              debug_info_offset (4-byte)
28##                                               ^--------     debug_info_length (4-byte)
29##                                                        ^--- offset (4-byte)
30##
31# DWARF32-LE-NEXT:   0010: 34126162 63002143 65876465 6600     |4.abc.!Ce.def.|
32##                         ----
33##                             ^--------                       name "abc\0"
34##                                      ^--------              offset (4-byte)
35##                                               ^--------     name "def\0"
36# DWARF32-LE-NEXT: )
37
38--- !ELF
39FileHeader:
40  Class: ELFCLASS64
41  Data:  [[ENDIAN]]
42  Type:  ET_EXEC
43DWARF:
44  debug_pubnames:
45    Length:     0x1234
46    Version:    2
47    UnitOffset: 0x1234
48    UnitSize:   0x4321
49    Entries:
50      - DieOffset: 0x12345678
51        Name:      abc
52      - DieOffset: 0x87654321
53        Name:      def
54
55## Generate and verify a 32-bit big endian .debug_pubnames section.
56
57# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.be.o
58# RUN: llvm-readobj --sections --section-data %t1.be.o | \
59# RUN:   FileCheck -DSIZE=30 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-BE
60
61# DWARF32-BE-NEXT: SectionData (
62# DWARF32-BE-NEXT:   0000: 00001234 00020000 12340000 43211234 |...4.....4..C!.4|
63##                         ^-------                            unit_length (4-byte)
64##                                  ^---                       version (2-byte)
65##                                      ^--------              debug_info_offset (4-byte)
66##                                               ^--------     debug_info_length (4-byte)
67##                                                        ^--- offset (4-byte)
68##
69# DWARF32-BE-NEXT:   0010: 56786162 63008765 43216465 6600     |Vxabc..eC!def.|
70##                         ----
71##                             ^--------                       name "abc\0"
72##                                      ^--------              offset (4-byte)
73##                                               ^--------     name "def\0"
74# DWARF32-BE-NEXT: )
75
76## b) Generate the .debug_pubnames section from raw section content.
77
78# RUN: yaml2obj --docnum=2 %s -o %t2.o
79# RUN: llvm-readobj --sections --section-data %t2.o | \
80# RUN:   FileCheck %s -DADDRALIGN=0 -DSIZE=3 --check-prefixes=SHDR,ARBITRARY-CONTENT
81
82#      ARBITRARY-CONTENT: SectionData (
83# ARBITRARY-CONTENT-NEXT:   0000: 112233
84# ARBITRARY-CONTENT-NEXT: )
85
86--- !ELF
87FileHeader:
88  Class: ELFCLASS64
89  Data:  ELFDATA2LSB
90  Type:  ET_EXEC
91Sections:
92  - Name:    .debug_pubnames
93    Type:    SHT_PROGBITS
94    Content: "112233"
95
96## c) Generate the .debug_pubnames section when the "Size" is specified.
97
98# RUN: yaml2obj --docnum=3 %s -o %t3.o
99# RUN: llvm-readobj --sections --section-data %t3.o | \
100# RUN:   FileCheck -DSIZE=16 -DADDRALIGN=0 %s --check-prefixes=SHDR,SIZE
101
102#      SIZE: SectionData (
103# SIZE-NEXT:   0000: 00000000 00000000 00000000 00000000  |................|
104# SIZE-NEXT: )
105
106--- !ELF
107FileHeader:
108  Class: ELFCLASS64
109  Data:  ELFDATA2LSB
110  Type:  ET_EXEC
111Sections:
112  - Name: .debug_pubnames
113    Type: SHT_PROGBITS
114    Size: 0x10
115
116## d) Test that yaml2obj emits an error message when both the "Size" and the
117## "debug_pubnames" entry are specified at the same time.
118
119# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR
120
121# ERROR: yaml2obj: error: cannot specify section '.debug_pubnames' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
122
123--- !ELF
124FileHeader:
125  Class: ELFCLASS64
126  Data:  ELFDATA2LSB
127  Type:  ET_EXEC
128Sections:
129  - Name: .debug_pubnames
130    Type: SHT_PROGBITS
131    Size: 0x10
132DWARF:
133  debug_pubnames:
134    Length:     0x1234
135    Version:    2
136    UnitOffset: 0x1234
137    UnitSize:   0x4321
138    Entries:    []
139
140## e) Test that yaml2obj emits an error message when both the "Content" and the
141## "debug_pubnames" entry are specified at the same time.
142
143# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR
144
145--- !ELF
146FileHeader:
147  Class: ELFCLASS64
148  Data:  ELFDATA2LSB
149  Type:  ET_EXEC
150Sections:
151  - Name:    .debug_pubnames
152    Type:    SHT_PROGBITS
153    Content: "00"
154DWARF:
155  debug_pubnames:
156    Length:     0x1234
157    Version:    2
158    UnitOffset: 0x1234
159    UnitSize:   0x4321
160    Entries:    []
161
162## f) Test that all the properties can be overridden by the section header when
163## the "debug_pubnames" entry doesn't exist.
164
165# RUN: yaml2obj --docnum=6 %s -o %t6.o
166# RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN
167
168#      OVERRIDDEN: [Nr] Name            Type   Address          Off    Size   ES Flg Lk Inf Al
169#      OVERRIDDEN: [ 1] .debug_pubnames STRTAB 0000000000002020 000050 00000e 01   A  2   1  2
170# OVERRIDDEN-NEXT: [ 2] .sec            STRTAB 0000000000000000 00005e 000000 00      0   0  0
171
172--- !ELF
173FileHeader:
174  Class: ELFCLASS64
175  Data:  ELFDATA2LSB
176  Type:  ET_EXEC
177Sections:
178  - Name:         .debug_pubnames
179    Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
180    Flags:        [SHF_ALLOC] ## 0 by default.
181    Link:         .sec        ## 0 by default.
182    EntSize:      1           ## 0 by default.
183    Info:         1           ## 0 by default.
184    AddressAlign: 2           ## 0 by default.
185    Address:      0x2020      ## 0x00 by default.
186    Offset:       0x50        ## 0x40 for the first section.
187    Size:         0x0e        ## Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
188  - Name:         .sec        ## Linked by .debug_pubnames.
189    Type:         SHT_STRTAB
190
191## g) Test that all the properties can be overridden by the section header when
192## the "debug_pubnames" entry exists.
193
194# RUN: yaml2obj --docnum=7 %s -o %t7.o
195# RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN
196
197--- !ELF
198FileHeader:
199  Class: ELFCLASS64
200  Data:  ELFDATA2LSB
201  Type:  ET_EXEC
202Sections:
203  - Name:         .debug_pubnames
204    Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
205    Flags:        [SHF_ALLOC] ## 0 by default.
206    Link:         .sec        ## 0 by default.
207    EntSize:      1           ## 0 by default.
208    Info:         1           ## 0 by default.
209    AddressAlign: 2           ## 1 by default.
210    Address:      0x2020      ## 0x00 by default.
211    Offset:       0x50        ## 0x40 for the first section.
212  - Name:         .sec        ## Linked by .debug_pubnames.
213    Type:         SHT_STRTAB
214DWARF:
215  debug_pubnames:
216    Length:     0x1234
217    Version:    2
218    UnitOffset: 0x1234
219    UnitSize:   0x4321
220    Entries:    []
221