libsoup3: update to 3.6.0; fix GTK2/3 app startup
[oi-userland.git] / components / developer / clang-18 / patches / 033-solaris-LLVM-JIT.patch
blob8c8f4fe11b412a5374b9951241c5e6e4a6a7d461
1 gnome-shell cores dump on sparc when mesa is build with llvm without this.
2 (to be submitted to upstream).
4 ------------ lwp# 1 / thread# 1 ---------------
5 00000000e7a01a84 fail (e7a017d8, 21, e7a017b0, 1d, f71a7cee, 0) + 108 (ssp.c:169)
6 00000000e7a01ad8 __stack_chk_fail (ff000000, ff000000, ff000000, 0, f3e29970, f3e33d44) + 28
7 00000000ea6c6328 llvm::RuntimeDyldELF::resolveRelocation(const llvm::SectionEntry&,unsigned long,unsignedlong,unsigned,long,unsigned long,unsigned) (3cd2e10, 3cd2ee8, 20, f30a6000, 6, 0) + 1c0
8 00000000ea6c639c llvm::RuntimeDyldELF::resolveRelocation(const llvm::RelocationEntry&,unsigned long) (3cd2e10, 3ee67d8, f30a6000, 0, 0, e7b04430) + 64
9 00000000ea6ab3e0 llvm::RuntimeDyldImpl::resolveRelocationList(const llvm::SmallVector<llvm::RelocationEntry, (unsigned)64>&,unsigned long) (3cd2e10, 3ee67c0, f30a6000, e7b04430, 0, 38) + e0
10 00000000ea6af60c llvm::RuntimeDyldImpl::resolveRelocations() (3cd2e10, 6, 1, e7b04430, 3cd42d0, 3ee67b0) + 2dc
11 00000000ea6af888 llvm::RuntimeDyld::resolveRelocations() (3e13038, 3d801a0, 3fa49a0, 3fa49b0, e7b04430, e7b04430) + 30
13 --- llvm-13.0.0.src/include/llvm/BinaryFormat/ELFRelocs/Sparc.def
14 +++ llvm-13.0.0.src/include/llvm/BinaryFormat/ELFRelocs/Sparc.def
15 @@ -87,3 +87,8 @@
16 ELF_RELOC(R_SPARC_GOTDATA_OP_HIX22, 82)
17 ELF_RELOC(R_SPARC_GOTDATA_OP_LOX10, 83)
18 ELF_RELOC(R_SPARC_GOTDATA_OP, 84)
19 +ELF_RELOC(R_SPARC_H34, 85)
20 +ELF_RELOC(R_SPARC_SIZE32, 86)
21 +ELF_RELOC(R_SPARC_SIZE64, 87)
22 +ELF_RELOC(R_SPARC_WDISP10, 88)
23 +ELF_RELOC(R_SPARC_NUM, 89)
24 --- llvm-13.0.0.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h.~1~ 2021-09-24 19:18:10.000000000 +0000
25 +++ llvm-13.0.0.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h 2022-01-02 14:26:31.003875610 +0000
26 @@ -109,6 +109,11 @@
27 assert(StubOffset <= AllocationSize && "Not enough space allocated!");
30 + void setStubOffset(unsigned Value) {
31 + StubOffset = Value;
32 + assert(StubOffset <= AllocationSize && "Not enough space allocated!");
33 + }
35 uintptr_t getObjAddress() const { return ObjAddress; }
38 --- llvm-13.0.0.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h.~1~ 2021-09-24 19:18:10.000000000 +0000
39 +++ llvm-13.0.0.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h 2022-01-02 14:26:31.004157633 +0000
40 @@ -54,6 +54,14 @@
41 void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
42 uint64_t Value, uint32_t Type, int64_t Addend);
44 + void resolveSPARC3264Relocation(const SectionEntry &Section,
45 + uint64_t Offset, uint64_t Value,
46 + uint32_t Type, int32_t Addend);
48 + void resolveSPARC64Relocation(const SectionEntry &Section,
49 + uint64_t Offset, uint64_t Value,
50 + uint32_t Type, int64_t Addend);
52 void resolveSystemZRelocation(const SectionEntry &Section, uint64_t Offset,
53 uint64_t Value, uint32_t Type, int64_t Addend);
55 @@ -71,6 +79,10 @@
56 return 32;
57 else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le)
58 return 44;
59 + else if (Arch == Triple::sparc)
60 + return 16;
61 + else if (Arch == Triple::sparcv9)
62 + return 32;
63 else if (Arch == Triple::x86_64)
64 return 6; // 2-byte jmp instruction + 32-bit relative address
65 else if (Arch == Triple::systemz)
66 --- llvm-13.0.0.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp.~1~ 2021-09-24 19:18:10.000000000 +0000
67 +++ llvm-13.0.0.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp 2022-01-02 14:26:31.005058486 +0000
68 @@ -887,6 +887,448 @@
72 +/// SPARC ELF Relocations - common to 32-bit and 64-bit.
73 +/// https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-24/index.html
74 +void RuntimeDyldELF::resolveSPARC3264Relocation(const SectionEntry &Section,
75 + uint64_t Offset,
76 + uint64_t Value,
77 + uint32_t Type,
78 + int32_t Addend) {
79 + uint64_t *TargetAddress =
80 + reinterpret_cast<uint64_t*>(reinterpret_cast<void*>(Section.getAddress()));
81 + uint64_t *TargetPtr =
82 + reinterpret_cast<uint64_t*>(Section.getAddressWithOffset(Offset));
83 + uint32_t Reloc = 0U;
84 + uint8_t *TargetPtr8 = nullptr;
85 + uint16_t *TargetPtr16 = nullptr;
86 + uint32_t *TargetPtr32 = nullptr;
87 + uint32_t LoadAddress = Section.getLoadAddressWithOffset(Offset) & 0xFFFFFFFF;
88 + uint32_t TargetValue = 0U;
89 + int32_t RS = 0;
90 + int32_t RM = 0;
92 + switch (Type) {
93 + default:
94 + llvm_unreachable("Unimplemented SPARC32 Relocation Type!");
95 + break;
96 + case ELF::R_SPARC_NONE:
97 + break;
98 + case ELF::R_SPARC_SIZE32:
99 + *TargetPtr = Section.getSize() + Addend;
100 + break;
101 + case ELF::R_SPARC_RELATIVE:
102 + *TargetPtr = LoadAddress + Addend;
103 + break;
104 + case ELF::R_SPARC_COPY:
105 + Value += Addend;
106 + (void) std::memcpy(TargetPtr,
107 + reinterpret_cast<void*>(static_cast<uintptr_t>(Value)),
108 + Section.getSize());
109 + break;
110 + case ELF::R_SPARC_8:
111 + TargetPtr8 = reinterpret_cast<uint8_t*>(TargetPtr);
112 + Value += Addend;
113 + *TargetPtr8 = Value;
114 + break;
115 + case ELF::R_SPARC_16:
116 + TargetPtr16 = reinterpret_cast<uint16_t*>(TargetPtr);
117 + Value += Addend;
118 + *TargetPtr16 = Value;
119 + break;
120 + case ELF::R_SPARC_32:
121 + case ELF::R_SPARC_GLOB_DAT:
122 + Value += Addend;
123 + *TargetPtr = Value;
124 + break;
125 + case ELF::R_SPARC_JMP_SLOT:
126 + break;
127 + case ELF::R_SPARC_TLS_DTPOFF32:
128 + Value += Addend;
129 + *TargetPtr = Value;
130 + break;
131 + case ELF::R_SPARC_TLS_TPOFF32:
132 + Value += Addend;
133 + *TargetPtr = Value - Offset;
134 + break;
135 + case ELF::R_SPARC_TLS_LE_HIX22:
136 + Value -= Offset;
137 + Value += Addend;
138 + *TargetPtr = (*TargetPtr & 0xFFC00000) | ((~Value) & 0x003FFFFFLL);
139 + break;
140 + case ELF::R_SPARC_TLS_LE_LOX10:
141 + Value -= Offset;
142 + Value += Addend;
143 + *TargetPtr = (*TargetPtr & 0xFFFFE000) | (Value & 0x000003FFLL);
144 + break;
145 + case ELF::R_SPARC_DISP8:
146 + Value += Addend;
147 + TargetPtr8 = reinterpret_cast<uint8_t*>(TargetAddress);
148 + *TargetPtr8 = (Value - reinterpret_cast<uintptr_t>(TargetPtr8));
149 + break;
150 + case ELF::R_SPARC_DISP16:
151 + Value += Addend;
152 + TargetPtr16 = reinterpret_cast<uint16_t*>(TargetAddress);
153 + *TargetPtr16 = (Value - reinterpret_cast<uintptr_t>(TargetPtr16));
154 + break;
155 + case ELF::R_SPARC_DISP32:
156 + Value += Addend;
157 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetAddress);
158 + *TargetPtr32 = (Value - reinterpret_cast<uintptr_t>(TargetPtr32));
159 + break;
160 + case ELF::R_SPARC_WDISP30:
161 + case ELF::R_SPARC_WDISP22:
162 + case ELF::R_SPARC_WDISP19:
163 + case ELF::R_SPARC_WDISP16:
164 + case ELF::R_SPARC_WDISP10:
165 + switch (Type) {
166 + default:
167 + llvm_unreachable("Impossible default case!");
168 + break;
169 + case ELF::R_SPARC_WDISP30:
170 + RS = 2;
171 + RM = 0x3FFFFFFF;
172 + break;
173 + case ELF::R_SPARC_WDISP22:
174 + RS = 2;
175 + RM = 0x003FFFFF;
176 + break;
177 + case ELF::R_SPARC_WDISP19:
178 + RS = 2;
179 + RM = 0x0007FFFF;
180 + break;
181 + case ELF::R_SPARC_WDISP16:
182 + RS = 2;
183 + break;
184 + case ELF::R_SPARC_WDISP10:
185 + RS = 2;
186 + break;
189 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
190 + Reloc = (((Value + Addend) - LoadAddress) >> RS);
191 + TargetValue = *TargetPtr32;
193 + switch (Type) {
194 + default:
195 + llvm_unreachable("Impossible default case!");
196 + break;
197 + case ELF::R_SPARC_WDISP16:
198 + TargetValue &= ~((0x3 << 20) | 0x3FFF);
199 + Reloc = (((Reloc & 0xC000) << (7 - 1)) | (Reloc & 0x3FFFF));
200 + *TargetPtr32 = TargetValue | Reloc;
201 + break;
202 + case ELF::R_SPARC_WDISP10:
203 + TargetValue &= ~((0x3 << 19) | (0xFF << 5));
204 + Reloc = (((Reloc & 0x300) << (13 - 2)) | ((Reloc & 0xFF) | (7 - 2)));
205 + *TargetPtr32 = TargetValue | Reloc;
206 + break;
207 + case ELF::R_SPARC_WDISP30:
208 + case ELF::R_SPARC_WDISP22:
209 + case ELF::R_SPARC_WDISP19:
210 + TargetValue &= ~RM;
211 + Reloc &= RM;
212 + *TargetPtr32 = TargetValue | Reloc;
213 + break;
215 + break;
216 + case ELF::R_SPARC_HI22:
217 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
218 + RS = 10;
219 + RM = 0x003FFFFF;
220 + Reloc = (Value + Addend) >> RS;
221 + TargetValue = *TargetPtr32;
222 + TargetValue &= ~RM;
223 + Reloc &= RM;
224 + *TargetPtr32 = TargetValue | Reloc;
225 + break;
226 + case ELF::R_SPARC_10:
227 + Value += Addend;
228 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
229 + *TargetPtr32 = Value;
230 + break;
231 + case ELF::R_SPARC_11:
232 + Value += Addend;
233 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
234 + *TargetPtr32 = Value;
235 + break;
236 + case ELF::R_SPARC_13:
237 + Value += Addend;
238 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
239 + *TargetPtr32 = Value;
240 + break;
241 + case ELF::R_SPARC_22:
242 + Value += Addend;
243 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
244 + *TargetPtr32 = Value;
245 + break;
246 + case ELF::R_SPARC_LO10:
247 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
248 + RS = 0;
249 + RM = 0x000003FF;
250 + Reloc = (Value + Addend) >> RS;
251 + TargetValue = *TargetPtr32;
252 + TargetValue &= ~RM;
253 + Reloc &= RM;
254 + *TargetPtr32 = TargetValue | Reloc;
255 + break;
256 + case ELF::R_SPARC_LM22:
257 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
258 + RS = 10;
259 + RM = 0x003FFFFF;
260 + Reloc = (Value + Addend) >> RS;
261 + TargetValue = *TargetPtr32;
262 + TargetValue &= ~RM;
263 + Reloc &= RM;
264 + *TargetPtr32 = TargetValue | Reloc;
265 + break;
266 + case ELF::R_SPARC_HIX22:
267 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
268 + RS = 10;
269 + RM = 0x3FFFFF;
270 + Reloc = Value + Addend;
271 + TargetValue = *TargetPtr32;
272 + TargetValue &= ~RM;
273 + Reloc ^= ~0;
274 + Reloc >>= RS;
275 + Reloc &= RM;
276 + *TargetPtr32 = TargetValue | Reloc;
277 + break;
278 + case ELF::R_SPARC_LOX10:
279 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
280 + Reloc = Value + Addend;
281 + TargetValue = *TargetPtr32;
282 + TargetValue &= ~0x1FFF;
283 + Reloc &= 0x3FF;
284 + Reloc |= 0x1C00;
285 + *TargetPtr32 = TargetValue | Reloc;
286 + break;
287 + case ELF::R_SPARC_HH22:
288 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
289 + RS = 42;
290 + RM = 0x003FFFFF;
291 + Reloc = (Value + Addend) >> RS;
292 + TargetValue = *TargetPtr32;
293 + TargetValue &= ~RM;
294 + Reloc &= RM;
295 + *TargetPtr32 = TargetValue | Reloc;
296 + break;
297 + case ELF::R_SPARC_HM10:
298 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
299 + RS = 32;
300 + RM = 0x000003FF;
301 + Reloc = (Value + Addend) >> RS;
302 + TargetValue = *TargetPtr32;
303 + TargetValue &= ~RM;
304 + Reloc &= RM;
305 + *TargetPtr32 = TargetValue | Reloc;
306 + break;
307 + case ELF::R_SPARC_H44:
308 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
309 + RS = 22;
310 + RM = 0x003FFFFF;
311 + Reloc = (Value + Addend) >> RS;
312 + TargetValue = *TargetPtr32;
313 + TargetValue &= ~RM;
314 + Reloc &= RM;
315 + *TargetPtr32 = TargetValue | Reloc;
316 + break;
317 + case ELF::R_SPARC_M44:
318 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
319 + RS = 12;
320 + RM = 0x000003FF;
321 + Reloc = (Value + Addend) >> RS;
322 + TargetValue = *TargetPtr32;
323 + TargetValue &= ~RM;
324 + Reloc &= RM;
325 + *TargetPtr32 = TargetValue | Reloc;
326 + break;
327 + case ELF::R_SPARC_L44:
328 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
329 + RS = 0;
330 + RM = 0x00000FFF;
331 + Reloc = (Value + Addend) >> RS;
332 + TargetValue = *TargetPtr32;
333 + TargetValue &= ~RM;
334 + Reloc &= RM;
335 + *TargetPtr32 = TargetValue | Reloc;
336 + break;
337 + case ELF::R_SPARC_GOT10:
338 + assert((Offset != static_cast<uint64_t>(-1)) &&
339 + "R_SPARC_GOT10: Invalid offset!");
340 + if ((Offset & 1) != 0)
341 + Offset &= ~1;
342 + else
343 + Offset |= 1;
345 + RS = 0;
346 + RM = 0x000003FF;
347 + Reloc = (Value + Addend) >> RS;
348 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
349 + TargetValue = *TargetPtr32;
350 + TargetValue &= ~RM;
351 + Reloc &= RM;
352 + *TargetPtr32 = TargetValue | Reloc;
353 + break;
354 + case ELF::R_SPARC_GOT13:
355 + assert((Offset != static_cast<uint64_t>(-1)) &&
356 + "R_SPARC_GOT13: Invalid offset!");
357 + if ((Offset & 1) != 0)
358 + Offset &= ~1;
359 + else
360 + Offset |= 1;
362 + RS = 0;
363 + RM = 0x00001FFF;
364 + Reloc = (Value + Addend) >> RS;
366 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
367 + TargetValue = *TargetPtr32;
368 + TargetValue &= ~RM;
369 + Reloc &= RM;
370 + *TargetPtr32 = TargetValue | Reloc;
371 + break;
372 + case ELF::R_SPARC_GOT22:
373 + assert((Offset != static_cast<uint64_t>(-1)) &&
374 + "R_SPARC_GOT22: Invalid offset!");
375 + if ((Offset & 1) != 0)
376 + Offset &= ~1;
377 + else
378 + Offset |= 1;
380 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
381 + RS = 10;
382 + RM = 0x003FFFFF;
383 + Reloc = (Value + Addend) >> RS;
384 + TargetValue = *TargetPtr32;
385 + TargetValue &= ~RM;
386 + Reloc &= RM;
387 + *TargetPtr32 = TargetValue | Reloc;
388 + break;
389 + case ELF::R_SPARC_PC10:
390 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
391 + RS = 0;
392 + RM =0x000003FF;
393 + Reloc = ((Value + Addend) - LoadAddress) >> RS;
394 + TargetValue = *TargetPtr32;
395 + TargetValue &= ~RM;
396 + Reloc &= RM;
397 + *TargetPtr32 = TargetValue | Reloc;
398 + break;
399 + case ELF::R_SPARC_PC22:
400 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
401 + RS = 10;
402 + RM = 0x003FFFFF;
403 + Reloc = ((Value + Addend) - LoadAddress) >> RS;
404 + TargetValue = *TargetPtr32;
405 + TargetValue &= ~RM;
406 + Reloc &= RM;
407 + *TargetPtr32 = TargetValue | Reloc;
408 + break;
409 + case ELF::R_SPARC_UA16:
410 + TargetPtr8 = reinterpret_cast<uint8_t*>(TargetPtr);
411 + TargetPtr8[0] = Value >> 8U;
412 + TargetPtr8[1] = Value;
413 + break;
414 + case ELF::R_SPARC_UA32:
415 + TargetPtr8 = reinterpret_cast<uint8_t*>(TargetPtr);
416 + TargetPtr8[0] = Value >> 24U;
417 + TargetPtr8[1] = Value >> 16U;
418 + TargetPtr8[2] = Value >> 8U;
419 + TargetPtr8[3] = Value;
420 + break;
421 + case ELF::R_SPARC_WPLT30:
422 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
423 + RS = 2;
424 + RM = 0x3FFFFFFF;
425 + Reloc = ((Value + Addend) - LoadAddress) >> RS;
426 + TargetValue = *TargetPtr32;
427 + TargetValue &= ~RM;
428 + Reloc &= RM;
429 + *TargetPtr32 = TargetValue | Reloc;
430 + TargetValue = *TargetPtr32;
431 + break;
435 +/// SPARCV9 ELF Relocatinos - valid in 64-bit only.
436 +/// https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-24-1/index.html
437 +void RuntimeDyldELF::resolveSPARC64Relocation(const SectionEntry &Section,
438 + uint64_t Offset, uint64_t Value,
439 + uint32_t Type, int64_t Addend) {
440 + uint64_t *TargetAddress =
441 + reinterpret_cast<uint64_t*>(reinterpret_cast<void*>(Section.getAddress()));
442 + uint64_t *TargetPtr =
443 + reinterpret_cast<uint64_t*>(Section.getAddressWithOffset(Offset));
444 + uint32_t Reloc;
445 + uintptr_t TargetPtrVal = reinterpret_cast<uintptr_t>(TargetPtr);
446 + uint8_t *TargetPtr8 = nullptr;
447 + uint16_t *TargetPtr16 = nullptr;
448 + uint32_t *TargetPtr32 = nullptr;
449 + uint64_t LoadAddress = Section.getLoadAddressWithOffset(Offset);
450 + uint64_t TargetValue = 0ULL;
451 + int32_t RS;
452 + int32_t RM;
454 + switch (Type) {
455 + case ELF::R_SPARC_HI22:
456 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
457 + RS = 10;
458 + RM = 0x003FFFFF;
459 + Reloc = (Value + Addend) >> RS;
460 + TargetValue = *TargetPtr32;
461 + TargetValue &= ~RM;
462 + Reloc &= RM;
463 + *TargetPtr32 = TargetValue | Reloc;
464 + break;
465 + case ELF::R_SPARC_64:
466 + case ELF::R_SPARC_GLOB_DAT:
467 + Value += Addend;
468 + *TargetPtr = Value;
469 + break;
470 + case ELF::R_SPARC_RELATIVE:
471 + *TargetPtr = LoadAddress + Addend;
472 + break;
473 + case ELF::R_SPARC_OLO10:
474 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
475 + *TargetPtr32 = (*TargetPtr32 & ~0x1FFF) | (((Value + Addend) & 0x3FF) +
476 + ((Offset >> 8) & 0x1FFF));
477 + break;
478 + case ELF::R_SPARC_DISP64:
479 + Value += Addend;
480 + *TargetPtr = (Value - reinterpret_cast<uintptr_t>(TargetPtr));
481 + break;
482 + case ELF::R_SPARC_REGISTER:
483 + Value += Addend;
484 + *TargetPtr = Value;
485 + break;
486 + case ELF::R_SPARC_PLT64:
487 + llvm::errs() << __PRETTY_FUNCTION__
488 + << ": Warning: Unimplemented R_SPARC_PLT64 Relocation type.\n" ;
489 + break;
490 + case ELF::R_SPARC_UA64:
491 + Value += Addend;
492 + if (0 == (TargetPtrVal & 3)) {
493 + TargetPtr32 = reinterpret_cast<uint32_t*>(TargetPtr);
494 + TargetPtr32[0] = Value >> 32;
495 + TargetPtr32[1] = Value;
496 + } else {
497 + TargetPtr8 = reinterpret_cast<uint8_t*>(TargetPtr);
498 + TargetPtr8[0] = Value >> 56;
499 + TargetPtr8[0] = Value >> 48;
500 + TargetPtr8[0] = Value >> 40;
501 + TargetPtr8[0] = Value >> 32;
502 + TargetPtr8[0] = Value >> 24;
503 + TargetPtr8[0] = Value >> 16;
504 + TargetPtr8[0] = Value >> 8;
505 + TargetPtr8[0] = Value;
507 + break;
508 + default:
509 + resolveSPARC3264Relocation(Section, Offset, Value, Type, Addend);
510 + break;
514 void RuntimeDyldELF::resolveSystemZRelocation(const SectionEntry &Section,
515 uint64_t Offset, uint64_t Value,
516 uint32_t Type, int64_t Addend) {
517 @@ -1037,6 +1479,12 @@
518 case Triple::bpfeb:
519 resolveBPFRelocation(Section, Offset, Value, Type, Addend);
520 break;
521 + case Triple::sparc:
522 + resolveSPARC3264Relocation(Section, Offset, Value, Type, Addend);
523 + break;
524 + case Triple::sparcv9:
525 + resolveSPARC64Relocation(Section, Offset, Value, Type, Addend);
526 + break;
527 default:
528 llvm_unreachable("Unsupported CPU type!");
530 @@ -1672,6 +2120,160 @@
531 else
532 addRelocationForSection(RE, Value.SectionID);
534 + } else if (Arch == Triple::sparc) {
535 + LLVM_DEBUG(dbgs() << "This is a SPARC32 relocation.\n");
536 + SectionEntry &Section = Sections[SectionID];
537 + uint8_t *Target = Section.getAddressWithOffset(Offset);
538 + uint32_t *TargetAddress = reinterpret_cast<uint32_t*>(Target);
539 + uint8_t *SectionAddress = Section.getAddress();
540 + uintptr_t StubOffset = Section.getStubOffset();
541 + uintptr_t StubAddress = static_cast<uintptr_t>(-1);
543 + if (RelType == ELF::R_SPARC_WDISP30) {
544 + // Look up for existing stub.
545 + StubMap::const_iterator i = Stubs.find(Value);
547 + if (i != Stubs.end()) {
548 + LLVM_DEBUG(dbgs() << " Stub function found\n");
549 + StubAddress =
550 + reinterpret_cast<uintptr_t>(Section.getAddressWithOffset(i->second));
552 + resolveRelocation(Section, Offset, StubAddress, RelType, 0);
553 + Section.advanceStubOffset(getMaxStubSize());
554 + } else {
555 + // Create a new stub function.
556 + LLVM_DEBUG(dbgs() << " Create a new stub function\n");
558 + uintptr_t BaseAddress =
559 + reinterpret_cast<uintptr_t>(Section.getAddress());
560 + uintptr_t StubAlignment = getStubAlignment();
561 + StubAddress = BaseAddress + StubOffset;
562 + StubAddress = llvm::alignTo(StubAddress, 4U);
563 + StubOffset = StubAddress - BaseAddress;
565 + Stubs[Value] = StubOffset;
566 + uint8_t *StubTargetAddr =
567 + createStubFunction(reinterpret_cast<uint8_t*>(StubAddress));
569 + // Creating Hi and Lo relocations for the filled stub instructions.
570 + RelocationEntry REhi(SectionID,
571 + StubTargetAddr - SectionAddress,
572 + ELF::R_SPARC_HI22, Value.Addend);
573 + RelocationEntry RElo(SectionID,
574 + StubTargetAddr - SectionAddress + 4,
575 + ELF::R_SPARC_LO10, Value.Addend);
577 + if (Value.SymbolName) {
578 + addRelocationForSymbol(REhi, Value.SymbolName);
579 + addRelocationForSymbol(RElo, Value.SymbolName);
580 + } else {
581 + addRelocationForSection(REhi, Value.SectionID);
582 + addRelocationForSection(RElo, Value.SectionID);
585 + resolveRelocation(Section, Offset, StubAddress, RelType, 0);
586 + Section.advanceStubOffset(getMaxStubSize());
588 + } else {
589 + uintptr_t BaseAddress =
590 + reinterpret_cast<uintptr_t>(Section.getAddress());
591 + uintptr_t StubAlignment = getStubAlignment();
592 + StubAddress = BaseAddress + StubOffset;
593 + StubAddress = llvm::alignTo(StubAddress, 4U);
594 + StubOffset = StubAddress - BaseAddress;
596 + RelocationEntry RE(SectionID, Offset, RelType, Addend);
597 + if (Value.SymbolName)
598 + addRelocationForSymbol(RE, Value.SymbolName);
599 + else
600 + addRelocationForSection(RE, Value.SectionID);
602 + resolveRelocation(Section, Offset, StubOffset, RelType, 0);
603 + Section.advanceStubOffset(getMaxStubSize());
605 + } else if (Arch == Triple::sparcv9) {
606 + LLVM_DEBUG(dbgs() << "This is a SPARC64 relocation.\n");
608 + SectionEntry &Section = Sections[SectionID];
609 + uint8_t *Target = Section.getAddressWithOffset(Offset);
610 + uint32_t *TargetAddress = reinterpret_cast<uint32_t*>(Target);
611 + uint8_t *SectionAddress = Section.getAddress();
612 + uintptr_t StubOffset = Section.getStubOffset();
613 + uintptr_t StubAddress = static_cast<uintptr_t>(-1);
615 + if (RelType == ELF::R_SPARC_WDISP30) {
616 + // Look up for existing stub.
617 + StubMap::const_iterator i = Stubs.find(Value);
618 + if (i != Stubs.end()) {
619 + LLVM_DEBUG(dbgs() << " Stub function found\n");
621 + StubAddress =
622 + reinterpret_cast<uintptr_t>(Section.getAddressWithOffset(i->second));
624 + resolveRelocation(Section, Offset, StubAddress, RelType, 0);
625 + Section.advanceStubOffset(getMaxStubSize());
626 + } else {
627 + // Create a new stub function.
628 + LLVM_DEBUG(dbgs() << " Create a new stub function\n");
630 + uintptr_t BaseAddress =
631 + reinterpret_cast<uintptr_t>(Section.getAddress());
632 + uintptr_t StubAlignment = getStubAlignment();
634 + StubAddress = BaseAddress + StubOffset;
635 + StubAddress = llvm::alignTo(StubAddress, 8U);
636 + StubOffset = StubAddress - BaseAddress;
637 + Stubs[Value] = StubOffset;
639 + uint8_t *StubTargetAddr =
640 + createStubFunction(reinterpret_cast<uint8_t*>(StubAddress));
642 + // Creating Hi and Lo relocations for the filled stub instructions.
643 + RelocationEntry REhh(SectionID,
644 + StubTargetAddr - SectionAddress,
645 + ELF::R_SPARC_HH22, Value.Addend);
646 + RelocationEntry REhm(SectionID,
647 + StubTargetAddr - SectionAddress + 8,
648 + ELF::R_SPARC_HM10, Value.Addend);
649 + RelocationEntry RElm(SectionID,
650 + StubTargetAddr - SectionAddress + 16,
651 + ELF::R_SPARC_LM22, Value.Addend);
652 + RelocationEntry RElo(SectionID,
653 + StubTargetAddr - SectionAddress + 24,
654 + ELF::R_SPARC_LO10, Value.Addend);
656 + if (Value.SymbolName) {
657 + addRelocationForSymbol(REhh, Value.SymbolName);
658 + addRelocationForSymbol(REhm, Value.SymbolName);
659 + addRelocationForSymbol(RElm, Value.SymbolName);
660 + addRelocationForSymbol(RElo, Value.SymbolName);
661 + } else {
662 + addRelocationForSection(REhh, Value.SectionID);
663 + addRelocationForSection(REhm, Value.SectionID);
664 + addRelocationForSection(RElm, Value.SectionID);
665 + addRelocationForSection(RElo, Value.SectionID);
668 + resolveRelocation(Section, Offset, StubAddress, RelType, 0);
669 + Section.advanceStubOffset(getMaxStubSize());
671 + } else {
672 + uintptr_t BaseAddress =
673 + reinterpret_cast<uintptr_t>(Section.getAddress());
674 + uintptr_t StubAlignment = getStubAlignment();
675 + StubAddress = BaseAddress + StubOffset;
676 + StubAddress = llvm::alignTo(StubAddress, 8U);
677 + StubOffset = StubAddress - BaseAddress;
679 + RelocationEntry RE(SectionID, Offset, RelType, Addend);
680 + if (Value.SymbolName)
681 + addRelocationForSymbol(RE, Value.SymbolName);
682 + else
683 + addRelocationForSection(RE, Value.SectionID);
685 + resolveRelocation(Section, Offset, StubAddress, RelType, 0);
686 + Section.advanceStubOffset(getMaxStubSize());
688 } else if (Arch == Triple::systemz &&
689 (RelType == ELF::R_390_PLT32DBL || RelType == ELF::R_390_GOTENT)) {
690 // Create function stubs for both PLT and GOT references, regardless of
691 --- llvm-13.0.0.src/include/llvm/Object/ELFObjectFile.h.~1~ 2021-09-24 19:18:10.000000000 +0000
692 +++ llvm-13.0.0.src/include/llvm/Object/ELFObjectFile.h 2022-01-02 14:26:31.005542785 +0000
693 @@ -1190,8 +1190,9 @@
694 case ELF::EM_CSKY:
695 return "elf32-csky";
696 case ELF::EM_SPARC:
697 - case ELF::EM_SPARC32PLUS:
698 return "elf32-sparc";
699 + case ELF::EM_SPARC32PLUS:
700 + return "elf32-sparc32plus";
701 case ELF::EM_AMDGPU:
702 return "elf32-amdgpu";
703 default:
704 @@ -1212,7 +1213,7 @@
705 case ELF::EM_S390:
706 return "elf64-s390";
707 case ELF::EM_SPARCV9:
708 - return "elf64-sparc";
709 + return "elf64-sparcv9";
710 case ELF::EM_MIPS:
711 return "elf64-mips";
712 case ELF::EM_AMDGPU:
713 @@ -1278,8 +1279,8 @@
714 return Triple::systemz;
716 case ELF::EM_SPARC:
717 - case ELF::EM_SPARC32PLUS:
718 return IsLittleEndian ? Triple::sparcel : Triple::sparc;
719 + case ELF::EM_SPARC32PLUS:
720 case ELF::EM_SPARCV9:
721 return Triple::sparcv9;