1## Check that we are able to dump MIPS PLT GOT entries using -A properly.
2
3# RUN: yaml2obj --docnum=1 %s -o %t.plt.o
4# RUN: llvm-readobj -A %t.plt.o | FileCheck %s --check-prefix=LLVM
5# RUN: llvm-readelf -A %t.plt.o | \
6# RUN:   FileCheck %s --strict-whitespace --match-full-lines --check-prefix=GNU
7
8# LLVM:      PLT GOT {
9# LLVM-NEXT:   Reserved entries [
10# LLVM-NEXT:     Entry {
11# LLVM-NEXT:       Address: 0x2000
12# LLVM-NEXT:       Initial: 0x0
13# LLVM-NEXT:       Purpose: PLT lazy resolver
14# LLVM-NEXT:     }
15# LLVM-NEXT:     Entry {
16# LLVM-NEXT:       Address: 0x2008
17# LLVM-NEXT:       Initial: 0x0
18# LLVM-NEXT:       Purpose: Module pointer
19# LLVM-NEXT:     }
20# LLVM-NEXT:   ]
21# LLVM-NEXT:   Entries [
22# LLVM-NEXT:     Entry {
23# LLVM-NEXT:       Address: 0x2010
24# LLVM-NEXT:       Initial: 0x0
25# LLVM-NEXT:       Value: 0x0
26# LLVM-NEXT:       Type: None (0x0)
27# LLVM-NEXT:       Section: Undefined (0x0)
28# LLVM-NEXT:       Name: foo (5)
29# LLVM-NEXT:     }
30# LLVM-NEXT:     Entry {
31# LLVM-NEXT:       Address: 0x2018
32# LLVM-NEXT:       Initial: 0x0
33# LLVM-NEXT:       Value: 0x0
34# LLVM-NEXT:       Type: None (0x0)
35# LLVM-NEXT:       Section: Undefined (0x0)
36# LLVM-NEXT:       Name: bar (1)
37# LLVM-NEXT:     }
38# LLVM-NEXT:   ]
39# LLVM-NEXT: }
40
41#       GNU:PLT GOT:
42# GNU-EMPTY:
43#  GNU-NEXT: Reserved entries:
44#  GNU-NEXT:   Address  Initial Purpose
45#  GNU-NEXT:  0000000000002000 0000000000000000 PLT lazy resolver
46#  GNU-NEXT:  0000000000002008 0000000000000000 Module pointer
47# GNU-EMPTY:
48#  GNU-NEXT: Entries:
49#  GNU-NEXT:   Address  Initial Sym.Val. Type    Ndx Name
50#  GNU-NEXT:  0000000000002010 0000000000000000 0000000000000000 NOTYPE  UND foo
51#  GNU-NEXT:  0000000000002018 0000000000000000 0000000000000000 NOTYPE  UND bar
52#   GNU-NOT:{{.}}
53
54--- !ELF
55FileHeader:
56  Class:   ELFCLASS64
57  Data:    ELFDATA2LSB
58  Type:    ET_REL
59  Machine: EM_MIPS
60Sections:
61  - Name:    .rel.plt
62    Type:    SHT_REL
63    Flags:   [ SHF_ALLOC ]
64    Address: 0x1000
65    Link:    .dynsym
66    Relocations:
67      - Offset: 0x1
68        Symbol: 1
69        Type:   R_MIPS_JUMP_SLOT
70      - Offset: 0x2
71        Symbol: 2
72        Type:   R_MIPS_JUMP_SLOT
73  - Name:    .got.plt
74    Type:    SHT_PROGBITS
75    Flags:   [ SHF_WRITE, SHF_ALLOC ]
76    Address: 0x2000
77    Size:    32 ## (dynamic symbols number + 2) * 8
78  - Name: .dynamic
79    Type: SHT_DYNAMIC
80    Entries:
81      - Tag:   DT_JMPREL
82        Value: 0x1000
83      - Tag:   DT_MIPS_PLTGOT
84        Value: 0x2000
85DynamicSymbols:
86  - Name:   "foo"
87  - Name:   "bar"
88
89## Check we report errors when dynamic tags, needed for dumping PLT, are missing.
90
91# RUN: yaml2obj --docnum=2 -DTAG=DT_MIPS_PLTGOT %s -o %t.err1.o
92# RUN: llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o --check-prefixes=NO-OUTPUT,ERR1
93
94# RUN: yaml2obj --docnum=2 -DTAG=DT_JMPREL %s -o %t.err2.o
95# RUN: llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o --check-prefixes=NO-OUTPUT,ERR2
96
97--- !ELF
98FileHeader:
99  Class:   ELFCLASS64
100  Data:    ELFDATA2LSB
101  Type:    ET_EXEC
102  Machine: EM_MIPS
103Sections:
104  - Name: .dynamic
105    Type: SHT_DYNAMIC
106    Entries:
107      - Tag:   [[TAG]]
108        Value: 0
109      - Tag:   DT_NULL
110        Value: 0
111
112## Check we report errors when we are unable to find PLTGOT/JMPREL sections.
113# RUN: yaml2obj --docnum=3 %s -DVAL1=0xffff -o %t.err3.o
114# RUN: llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefixes=NO-OUTPUT,ERR3
115
116# RUN: yaml2obj --docnum=3 %s -DVAL2=0xffff -o %t.err4.o
117# RUN: llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefixes=NO-OUTPUT,ERR4
118
119--- !ELF
120FileHeader:
121  Class:   ELFCLASS64
122  Data:    ELFDATA2LSB
123  Type:    ET_EXEC
124  Machine: EM_MIPS
125Sections:
126  - Name: .dynamic
127    Type: SHT_DYNAMIC
128    Entries:
129      - Tag:   DT_MIPS_PLTGOT
130        Value: [[VAL1=0]]
131      - Tag:   DT_JMPREL
132        Value: [[VAL2=0]]
133      - Tag:   DT_NULL
134        Value: 0
135  - Name:    .foo
136    Type:    SHT_PROGBITS
137    Address: 0x100
138    ShSize:  0xffffffff
139    Link:    [[LINK=0x1]]
140DynamicSymbols: []
141
142## Check we report errors when we are unable to dump PLTGOT properly.
143
144# RUN: yaml2obj --docnum=3 -DVAL1=0x100 %s -o %t.err5.o
145# RUN: llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefixes=NO-OUTPUT,ERR5
146
147# RUN: yaml2obj --docnum=3 -DVAL2=0x100 -DLINK=0xaaaaaaaa %s -o %t.err6.o
148# RUN: llvm-readobj -A %t.err6.o 2>&1 | FileCheck %s -DFILE=%t.err6.o -check-prefixes=NO-OUTPUT,ERR6
149
150# RUN: yaml2obj --docnum=3 -DVAL2=0x100 %s -o %t.err7.o
151# RUN: llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o -check-prefixes=NO-OUTPUT,ERR7
152
153# NO-OUTPUT:      LoadName: <Not found>
154# NO-OUTPUT-NEXT: There is no .MIPS.abiflags section in the file.
155# NO-OUTPUT-NEXT: There is no .MIPS.options section in the file.
156# NO-OUTPUT-NEXT: There is no .reginfo section in the file.
157
158# ERR1-NEXT: warning: '[[FILE]]': cannot find JMPREL dynamic tag
159# ERR2-NEXT: warning: '[[FILE]]': cannot find MIPS_PLTGOT dynamic tag
160# ERR3-NEXT: warning: '[[FILE]]': there is no non-empty PLTGOT section at 0xffff
161# ERR4-NEXT: warning: '[[FILE]]': there is no non-empty RELPLT section at 0xffff
162# ERR5-NEXT: warning: '[[FILE]]': unable to read PLTGOT section content: section [index 2] has a sh_offset (0x70) + sh_size (0xffffffff) that is greater than the file size (0x280)
163# ERR6-NEXT: warning: '[[FILE]]': unable to get a symbol table linked to the SHT_PROGBITS section with index 2: invalid section index: 2863311530
164# ERR7-NEXT: warning: '[[FILE]]': unable to get a string table for the SHT_DYNAMIC section with index 1: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
165
166# NO-OUTPUT-EMPTY:
167# NO-OUTPUT-NOT: {{.}}
168
169## Check how we print PLT entries when they are unnamed section symbols.
170# RUN: yaml2obj --docnum=4 %s -o %t3
171# RUN: llvm-readobj -A %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=SEC-SYMS-LLVM
172# RUN: llvm-readelf -A %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=SEC-SYMS-GNU
173
174# SEC-SYMS-LLVM:      PLT GOT {
175# SEC-SYMS-LLVM:        Entries [
176# SEC-SYMS-LLVM:          Entry {
177# SEC-SYMS-LLVM:            Section: Absolute (0xFFF1)
178# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
179# SEC-SYMS-LLVM-NEXT:       Name: <?> (0)
180# SEC-SYMS-LLVM-NEXT:     }
181# SEC-SYMS-LLVM-NEXT:     Entry {
182# SEC-SYMS-LLVM:            Section: .got.plt (0x2)
183# SEC-SYMS-LLVM-NEXT:       Name: .got.plt (0)
184# SEC-SYMS-LLVM-NEXT:     }
185# SEC-SYMS-LLVM-NEXT:     Entry {
186# SEC-SYMS-LLVM:            Section: Common (0xFFF2)
187# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
188# SEC-SYMS-LLVM-NEXT:       Name: <?> (0)
189# SEC-SYMS-LLVM-NEXT:     }
190# SEC-SYMS-LLVM-NEXT:     Entry {
191# SEC-SYMS-LLVM:            Type: Section (0x3)
192# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (4), but unable to locate the extended symbol index table
193# SEC-SYMS-LLVM-NEXT:       Section: Reserved (0xFFFF)
194# SEC-SYMS-LLVM-NEXT:       Name: <?> (0)
195# SEC-SYMS-LLVM-NEXT:     }
196# SEC-SYMS-LLVM-NEXT:   ]
197# SEC-SYMS-LLVM-NEXT: }
198
199# SEC-SYMS-GNU:      PLT GOT:
200# SEC-SYMS-GNU:       Entries:
201# SEC-SYMS-GNU-NEXT:   Address          {{.*}} Ndx Name
202# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
203# SEC-SYMS-GNU-NEXT:   0000000000002010 {{.*}} ABS <?>
204# SEC-SYMS-GNU-NEXT:   0000000000002018 {{.*}}   2 .got.plt
205# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
206# SEC-SYMS-GNU-NEXT:   0000000000002020 {{.*}} COM <?>
207# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (4), but unable to locate the extended symbol index table
208# SEC-SYMS-GNU-NEXT:   0000000000002028 {{.*}} RSV[0xffff] <?>
209
210--- !ELF
211FileHeader:
212  Class:   ELFCLASS64
213  Data:    ELFDATA2LSB
214  Type:    ET_REL
215  Machine: EM_MIPS
216Sections:
217  - Name:    .rel.plt
218    Type:    SHT_REL
219    Flags:   [ SHF_ALLOC ]
220    Address: 0x1000
221    Link:    .dynsym
222    Relocations:
223      - Offset: 0x1
224        Symbol: 1
225        Type:   R_MIPS_JUMP_SLOT
226      - Offset: 0x2
227        Symbol: 2
228        Type:   R_MIPS_JUMP_SLOT
229      - Offset: 0x2
230        Symbol: 3
231        Type:   R_MIPS_JUMP_SLOT
232      - Offset: 0x3
233        Symbol: 4
234        Type:   R_MIPS_JUMP_SLOT
235  - Name:    .got.plt
236    Type:    SHT_PROGBITS
237    Flags:   [ SHF_WRITE, SHF_ALLOC ]
238    Address: 0x2000
239    Size:    48 ## (dynamic symbols number + 2) * 8
240  - Name: .dynamic
241    Type: SHT_DYNAMIC
242    Entries:
243      - Tag:   DT_JMPREL
244        Value: 0x1000
245      - Tag:   DT_MIPS_PLTGOT
246        Value: 0x2000
247DynamicSymbols:
248  - Type:    STT_SECTION
249    Index:   SHN_ABS
250  - Type:    STT_SECTION
251    Section: .got.plt
252  - Type:    STT_SECTION
253    Index:   SHN_COMMON
254  - Type:    STT_SECTION
255    Index:   SHN_XINDEX
256