Fix spelling errors in sysdeps/powerpc files.
[glibc.git] / sysdeps / powerpc / powerpc32 / dl-machine.c
blobbd42fdf7d5f3d48d420d55a3ea7569f4e77f24c0
1 /* Machine-dependent ELF dynamic relocation functions. PowerPC version.
2 Copyright (C) 1995-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <unistd.h>
20 #include <string.h>
21 #include <sys/param.h>
22 #include <link.h>
23 #include <ldsodefs.h>
24 #include <elf/dynamic-link.h>
25 #include <dl-machine.h>
26 #include <_itoa.h>
28 /* The value __cache_line_size is defined in dl-sysdep.c and is initialised
29 by _dl_sysdep_start via DL_PLATFORM_INIT. */
30 extern int __cache_line_size attribute_hidden;
32 /* Because ld.so is now versioned, these functions can be in their own file;
33 no relocations need to be done to call them.
34 Of course, if ld.so is not versioned... */
35 #if defined SHARED && !(DO_VERSIONING - 0)
36 #error This will not work with versioning turned off, sorry.
37 #endif
40 /* Stuff for the PLT. */
41 #define PLT_INITIAL_ENTRY_WORDS 18
42 #define PLT_LONGBRANCH_ENTRY_WORDS 0
43 #define PLT_TRAMPOLINE_ENTRY_WORDS 6
44 #define PLT_DOUBLE_SIZE (1<<13)
45 #define PLT_ENTRY_START_WORDS(entry_number) \
46 (PLT_INITIAL_ENTRY_WORDS + (entry_number)*2 \
47 + ((entry_number) > PLT_DOUBLE_SIZE \
48 ? ((entry_number) - PLT_DOUBLE_SIZE)*2 \
49 : 0))
50 #define PLT_DATA_START_WORDS(num_entries) PLT_ENTRY_START_WORDS(num_entries)
52 /* Macros to build PowerPC opcode words. */
53 #define OPCODE_ADDI(rd,ra,simm) \
54 (0x38000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff))
55 #define OPCODE_ADDIS(rd,ra,simm) \
56 (0x3c000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff))
57 #define OPCODE_ADD(rd,ra,rb) \
58 (0x7c000214 | (rd) << 21 | (ra) << 16 | (rb) << 11)
59 #define OPCODE_B(target) (0x48000000 | ((target) & 0x03fffffc))
60 #define OPCODE_BA(target) (0x48000002 | ((target) & 0x03fffffc))
61 #define OPCODE_BCTR() 0x4e800420
62 #define OPCODE_LWZ(rd,d,ra) \
63 (0x80000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff))
64 #define OPCODE_LWZU(rd,d,ra) \
65 (0x84000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff))
66 #define OPCODE_MTCTR(rd) (0x7C0903A6 | (rd) << 21)
67 #define OPCODE_RLWINM(ra,rs,sh,mb,me) \
68 (0x54000000 | (rs) << 21 | (ra) << 16 | (sh) << 11 | (mb) << 6 | (me) << 1)
70 #define OPCODE_LI(rd,simm) OPCODE_ADDI(rd,0,simm)
71 #define OPCODE_ADDIS_HI(rd,ra,value) \
72 OPCODE_ADDIS(rd,ra,((value) + 0x8000) >> 16)
73 #define OPCODE_LIS_HI(rd,value) OPCODE_ADDIS_HI(rd,0,value)
74 #define OPCODE_SLWI(ra,rs,sh) OPCODE_RLWINM(ra,rs,sh,0,31-sh)
77 #define PPC_DCBST(where) asm volatile ("dcbst 0,%0" : : "r"(where) : "memory")
78 #define PPC_SYNC asm volatile ("sync" : : : "memory")
79 #define PPC_ISYNC asm volatile ("sync; isync" : : : "memory")
80 #define PPC_ICBI(where) asm volatile ("icbi 0,%0" : : "r"(where) : "memory")
81 #define PPC_DIE asm volatile ("tweq 0,0")
83 /* Use this when you've modified some code, but it won't be in the
84 instruction fetch queue (or when it doesn't matter if it is). */
85 #define MODIFIED_CODE_NOQUEUE(where) \
86 do { PPC_DCBST(where); PPC_SYNC; PPC_ICBI(where); } while (0)
87 /* Use this when it might be in the instruction queue. */
88 #define MODIFIED_CODE(where) \
89 do { PPC_DCBST(where); PPC_SYNC; PPC_ICBI(where); PPC_ISYNC; } while (0)
92 /* The idea here is that to conform to the ABI, we are supposed to try
93 to load dynamic objects between 0x10000 (we actually use 0x40000 as
94 the lower bound, to increase the chance of a memory reference from
95 a null pointer giving a segfault) and the program's load address;
96 this may allow us to use a branch instruction in the PLT rather
97 than a computed jump. The address is only used as a preference for
98 mmap, so if we get it wrong the worst that happens is that it gets
99 mapped somewhere else. */
101 ElfW(Addr)
102 __elf_preferred_address (struct link_map *loader, size_t maplength,
103 ElfW(Addr) mapstartpref)
105 ElfW(Addr) low, high;
106 struct link_map *l;
107 Lmid_t nsid;
109 /* If the object has a preference, load it there! */
110 if (mapstartpref != 0)
111 return mapstartpref;
113 /* Otherwise, quickly look for a suitable gap between 0x3FFFF and
114 0x70000000. 0x3FFFF is so that references off NULL pointers will
115 cause a segfault, 0x70000000 is just paranoia (it should always
116 be superseded by the program's load address). */
117 low = 0x0003FFFF;
118 high = 0x70000000;
119 for (nsid = 0; nsid < DL_NNS; ++nsid)
120 for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next)
122 ElfW(Addr) mapstart, mapend;
123 mapstart = l->l_map_start & ~(GLRO(dl_pagesize) - 1);
124 mapend = l->l_map_end | (GLRO(dl_pagesize) - 1);
125 assert (mapend > mapstart);
127 /* Prefer gaps below the main executable, note that l ==
128 _dl_loaded does not work for static binaries loading
129 e.g. libnss_*.so. */
130 if ((mapend >= high || l->l_type == lt_executable)
131 && high >= mapstart)
132 high = mapstart;
133 else if (mapend >= low && low >= mapstart)
134 low = mapend;
135 else if (high >= mapend && mapstart >= low)
137 if (high - mapend >= mapstart - low)
138 low = mapend;
139 else
140 high = mapstart;
144 high -= 0x10000; /* Allow some room between objects. */
145 maplength = (maplength | (GLRO(dl_pagesize) - 1)) + 1;
146 if (high <= low || high - low < maplength )
147 return 0;
148 return high - maplength; /* Both high and maplength are page-aligned. */
151 /* Set up the loaded object described by L so its unrelocated PLT
152 entries will jump to the on-demand fixup code in dl-runtime.c.
153 Also install a small trampoline to be used by entries that have
154 been relocated to an address too far away for a single branch. */
156 /* There are many kinds of PLT entries:
158 (1) A direct jump to the actual routine, either a relative or
159 absolute branch. These are set up in __elf_machine_fixup_plt.
161 (2) Short lazy entries. These cover the first 8192 slots in
162 the PLT, and look like (where 'index' goes from 0 to 8191):
164 li %r11, index*4
165 b &plt[PLT_TRAMPOLINE_ENTRY_WORDS+1]
167 (3) Short indirect jumps. These replace (2) when a direct jump
168 wouldn't reach. They look the same except that the branch
169 is 'b &plt[PLT_LONGBRANCH_ENTRY_WORDS]'.
171 (4) Long lazy entries. These cover the slots when a short entry
172 won't fit ('index*4' overflows its field), and look like:
174 lis %r11, %hi(index*4 + &plt[PLT_DATA_START_WORDS])
175 lwzu %r12, %r11, %lo(index*4 + &plt[PLT_DATA_START_WORDS])
176 b &plt[PLT_TRAMPOLINE_ENTRY_WORDS]
177 bctr
179 (5) Long indirect jumps. These replace (4) when a direct jump
180 wouldn't reach. They look like:
182 lis %r11, %hi(index*4 + &plt[PLT_DATA_START_WORDS])
183 lwz %r12, %r11, %lo(index*4 + &plt[PLT_DATA_START_WORDS])
184 mtctr %r12
185 bctr
187 (6) Long direct jumps. These are used when thread-safety is not
188 required. They look like:
190 lis %r12, %hi(finaladdr)
191 addi %r12, %r12, %lo(finaladdr)
192 mtctr %r12
193 bctr
196 The lazy entries, (2) and (4), are set up here in
197 __elf_machine_runtime_setup. (1), (3), and (5) are set up in
198 __elf_machine_fixup_plt. (1), (3), and (6) can also be constructed
199 in __process_machine_rela.
201 The reason for the somewhat strange construction of the long
202 entries, (4) and (5), is that we need to ensure thread-safety. For
203 (1) and (3), this is obvious because only one instruction is
204 changed and the PPC architecture guarantees that aligned stores are
205 atomic. For (5), this is more tricky. When changing (4) to (5),
206 the `b' instruction is first changed to `mtctr'; this is safe
207 and is why the `lwzu' instruction is not just a simple `addi'.
208 Once this is done, and is visible to all processors, the `lwzu' can
209 safely be changed to a `lwz'. */
211 __elf_machine_runtime_setup (struct link_map *map, int lazy, int profile)
213 if (map->l_info[DT_JMPREL])
215 Elf32_Word i;
216 Elf32_Word *plt = (Elf32_Word *) D_PTR (map, l_info[DT_PLTGOT]);
217 Elf32_Word num_plt_entries = (map->l_info[DT_PLTRELSZ]->d_un.d_val
218 / sizeof (Elf32_Rela));
219 Elf32_Word rel_offset_words = PLT_DATA_START_WORDS (num_plt_entries);
220 Elf32_Word data_words = (Elf32_Word) (plt + rel_offset_words);
221 Elf32_Word size_modified;
223 extern void _dl_runtime_resolve (void);
224 extern void _dl_prof_resolve (void);
226 /* Convert the index in r11 into an actual address, and get the
227 word at that address. */
228 plt[PLT_LONGBRANCH_ENTRY_WORDS] = OPCODE_ADDIS_HI (11, 11, data_words);
229 plt[PLT_LONGBRANCH_ENTRY_WORDS + 1] = OPCODE_LWZ (11, data_words, 11);
231 /* Call the procedure at that address. */
232 plt[PLT_LONGBRANCH_ENTRY_WORDS + 2] = OPCODE_MTCTR (11);
233 plt[PLT_LONGBRANCH_ENTRY_WORDS + 3] = OPCODE_BCTR ();
235 if (lazy)
237 Elf32_Word *tramp = plt + PLT_TRAMPOLINE_ENTRY_WORDS;
238 Elf32_Word dlrr;
239 Elf32_Word offset;
241 #ifndef PROF
242 dlrr = (Elf32_Word) (profile
243 ? _dl_prof_resolve
244 : _dl_runtime_resolve);
245 if (profile && GLRO(dl_profile) != NULL
246 && _dl_name_match_p (GLRO(dl_profile), map))
247 /* This is the object we are looking for. Say that we really
248 want profiling and the timers are started. */
249 GL(dl_profile_map) = map;
250 #else
251 dlrr = (Elf32_Word) _dl_runtime_resolve;
252 #endif
254 /* For the long entries, subtract off data_words. */
255 tramp[0] = OPCODE_ADDIS_HI (11, 11, -data_words);
256 tramp[1] = OPCODE_ADDI (11, 11, -data_words);
258 /* Multiply index of entry by 3 (in r11). */
259 tramp[2] = OPCODE_SLWI (12, 11, 1);
260 tramp[3] = OPCODE_ADD (11, 12, 11);
261 if (dlrr <= 0x01fffffc || dlrr >= 0xfe000000)
263 /* Load address of link map in r12. */
264 tramp[4] = OPCODE_LI (12, (Elf32_Word) map);
265 tramp[5] = OPCODE_ADDIS_HI (12, 12, (Elf32_Word) map);
267 /* Call _dl_runtime_resolve. */
268 tramp[6] = OPCODE_BA (dlrr);
270 else
272 /* Get address of _dl_runtime_resolve in CTR. */
273 tramp[4] = OPCODE_LI (12, dlrr);
274 tramp[5] = OPCODE_ADDIS_HI (12, 12, dlrr);
275 tramp[6] = OPCODE_MTCTR (12);
277 /* Load address of link map in r12. */
278 tramp[7] = OPCODE_LI (12, (Elf32_Word) map);
279 tramp[8] = OPCODE_ADDIS_HI (12, 12, (Elf32_Word) map);
281 /* Call _dl_runtime_resolve. */
282 tramp[9] = OPCODE_BCTR ();
285 /* Set up the lazy PLT entries. */
286 offset = PLT_INITIAL_ENTRY_WORDS;
287 i = 0;
288 while (i < num_plt_entries && i < PLT_DOUBLE_SIZE)
290 plt[offset ] = OPCODE_LI (11, i * 4);
291 plt[offset+1] = OPCODE_B ((PLT_TRAMPOLINE_ENTRY_WORDS + 2
292 - (offset+1))
293 * 4);
294 i++;
295 offset += 2;
297 while (i < num_plt_entries)
299 plt[offset ] = OPCODE_LIS_HI (11, i * 4 + data_words);
300 plt[offset+1] = OPCODE_LWZU (12, i * 4 + data_words, 11);
301 plt[offset+2] = OPCODE_B ((PLT_TRAMPOLINE_ENTRY_WORDS
302 - (offset+2))
303 * 4);
304 plt[offset+3] = OPCODE_BCTR ();
305 i++;
306 offset += 4;
310 /* Now, we've modified code. We need to write the changes from
311 the data cache to a second-level unified cache, then make
312 sure that stale data in the instruction cache is removed.
313 (In a multiprocessor system, the effect is more complex.)
314 Most of the PLT shouldn't be in the instruction cache, but
315 there may be a little overlap at the start and the end.
317 Assumes that dcbst and icbi apply to lines of 16 bytes or
318 more. Current known line sizes are 16, 32, and 128 bytes.
319 The following gets the __cache_line_size, when available. */
321 /* Default minimum 4 words per cache line. */
322 int line_size_words = 4;
324 if (lazy && __cache_line_size != 0)
325 /* Convert bytes to words. */
326 line_size_words = __cache_line_size / 4;
328 size_modified = lazy ? rel_offset_words : 6;
329 for (i = 0; i < size_modified; i += line_size_words)
330 PPC_DCBST (plt + i);
331 PPC_DCBST (plt + size_modified - 1);
332 PPC_SYNC;
334 for (i = 0; i < size_modified; i += line_size_words)
335 PPC_ICBI (plt + i);
336 PPC_ICBI (plt + size_modified - 1);
337 PPC_ISYNC;
340 return lazy;
343 Elf32_Addr
344 __elf_machine_fixup_plt (struct link_map *map,
345 Elf32_Addr *reloc_addr, Elf32_Addr finaladdr)
347 Elf32_Sword delta = finaladdr - (Elf32_Word) reloc_addr;
348 if (delta << 6 >> 6 == delta)
349 *reloc_addr = OPCODE_B (delta);
350 else if (finaladdr <= 0x01fffffc || finaladdr >= 0xfe000000)
351 *reloc_addr = OPCODE_BA (finaladdr);
352 else
354 Elf32_Word *plt, *data_words;
355 Elf32_Word index, offset, num_plt_entries;
357 num_plt_entries = (map->l_info[DT_PLTRELSZ]->d_un.d_val
358 / sizeof(Elf32_Rela));
359 plt = (Elf32_Word *) D_PTR (map, l_info[DT_PLTGOT]);
360 offset = reloc_addr - plt;
361 index = (offset - PLT_INITIAL_ENTRY_WORDS)/2;
362 data_words = plt + PLT_DATA_START_WORDS (num_plt_entries);
364 reloc_addr += 1;
366 if (index < PLT_DOUBLE_SIZE)
368 data_words[index] = finaladdr;
369 PPC_SYNC;
370 *reloc_addr = OPCODE_B ((PLT_LONGBRANCH_ENTRY_WORDS - (offset+1))
371 * 4);
373 else
375 index -= (index - PLT_DOUBLE_SIZE)/2;
377 data_words[index] = finaladdr;
378 PPC_SYNC;
380 reloc_addr[1] = OPCODE_MTCTR (12);
381 MODIFIED_CODE_NOQUEUE (reloc_addr + 1);
382 PPC_SYNC;
384 reloc_addr[0] = OPCODE_LWZ (12,
385 (Elf32_Word) (data_words + index), 11);
388 MODIFIED_CODE (reloc_addr);
389 return finaladdr;
392 void
393 _dl_reloc_overflow (struct link_map *map,
394 const char *name,
395 Elf32_Addr *const reloc_addr,
396 const Elf32_Sym *refsym)
398 char buffer[128];
399 char *t;
400 t = stpcpy (buffer, name);
401 t = stpcpy (t, " relocation at 0x00000000");
402 _itoa_word ((unsigned) reloc_addr, t, 16, 0);
403 if (refsym)
405 const char *strtab;
407 strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
408 t = stpcpy (t, " for symbol `");
409 t = stpcpy (t, strtab + refsym->st_name);
410 t = stpcpy (t, "'");
412 t = stpcpy (t, " out of range");
413 _dl_signal_error (0, map->l_name, NULL, buffer);
416 void
417 __process_machine_rela (struct link_map *map,
418 const Elf32_Rela *reloc,
419 struct link_map *sym_map,
420 const Elf32_Sym *sym,
421 const Elf32_Sym *refsym,
422 Elf32_Addr *const reloc_addr,
423 Elf32_Addr const finaladdr,
424 int rinfo)
426 switch (rinfo)
428 case R_PPC_NONE:
429 return;
431 case R_PPC_ADDR32:
432 case R_PPC_GLOB_DAT:
433 case R_PPC_RELATIVE:
434 *reloc_addr = finaladdr;
435 return;
437 case R_PPC_IRELATIVE:
438 *reloc_addr = ((Elf32_Addr (*) (void)) finaladdr) ();
439 return;
441 case R_PPC_UADDR32:
442 ((char *) reloc_addr)[0] = finaladdr >> 24;
443 ((char *) reloc_addr)[1] = finaladdr >> 16;
444 ((char *) reloc_addr)[2] = finaladdr >> 8;
445 ((char *) reloc_addr)[3] = finaladdr;
446 break;
448 case R_PPC_ADDR24:
449 if (__builtin_expect (finaladdr > 0x01fffffc && finaladdr < 0xfe000000, 0))
450 _dl_reloc_overflow (map, "R_PPC_ADDR24", reloc_addr, refsym);
451 *reloc_addr = (*reloc_addr & 0xfc000003) | (finaladdr & 0x3fffffc);
452 break;
454 case R_PPC_ADDR16:
455 if (__builtin_expect (finaladdr > 0x7fff && finaladdr < 0xffff8000, 0))
456 _dl_reloc_overflow (map, "R_PPC_ADDR16", reloc_addr, refsym);
457 *(Elf32_Half*) reloc_addr = finaladdr;
458 break;
460 case R_PPC_UADDR16:
461 if (__builtin_expect (finaladdr > 0x7fff && finaladdr < 0xffff8000, 0))
462 _dl_reloc_overflow (map, "R_PPC_UADDR16", reloc_addr, refsym);
463 ((char *) reloc_addr)[0] = finaladdr >> 8;
464 ((char *) reloc_addr)[1] = finaladdr;
465 break;
467 case R_PPC_ADDR16_LO:
468 *(Elf32_Half*) reloc_addr = finaladdr;
469 break;
471 case R_PPC_ADDR16_HI:
472 *(Elf32_Half*) reloc_addr = finaladdr >> 16;
473 break;
475 case R_PPC_ADDR16_HA:
476 *(Elf32_Half*) reloc_addr = (finaladdr + 0x8000) >> 16;
477 break;
479 case R_PPC_ADDR14:
480 case R_PPC_ADDR14_BRTAKEN:
481 case R_PPC_ADDR14_BRNTAKEN:
482 if (__builtin_expect (finaladdr > 0x7fff && finaladdr < 0xffff8000, 0))
483 _dl_reloc_overflow (map, "R_PPC_ADDR14", reloc_addr, refsym);
484 *reloc_addr = (*reloc_addr & 0xffff0003) | (finaladdr & 0xfffc);
485 if (rinfo != R_PPC_ADDR14)
486 *reloc_addr = ((*reloc_addr & 0xffdfffff)
487 | ((rinfo == R_PPC_ADDR14_BRTAKEN)
488 ^ (finaladdr >> 31)) << 21);
489 break;
491 case R_PPC_REL24:
493 Elf32_Sword delta = finaladdr - (Elf32_Word) reloc_addr;
494 if (delta << 6 >> 6 != delta)
495 _dl_reloc_overflow (map, "R_PPC_REL24", reloc_addr, refsym);
496 *reloc_addr = (*reloc_addr & 0xfc000003) | (delta & 0x3fffffc);
498 break;
500 case R_PPC_COPY:
501 if (sym == NULL)
502 /* This can happen in trace mode when an object could not be
503 found. */
504 return;
505 if (sym->st_size > refsym->st_size
506 || (GLRO(dl_verbose) && sym->st_size < refsym->st_size))
508 const char *strtab;
510 strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
511 _dl_error_printf ("\
512 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
513 rtld_progname ?: "<program name unknown>",
514 strtab + refsym->st_name);
516 memcpy (reloc_addr, (char *) finaladdr, MIN (sym->st_size,
517 refsym->st_size));
518 return;
520 case R_PPC_REL32:
521 *reloc_addr = finaladdr - (Elf32_Word) reloc_addr;
522 return;
524 case R_PPC_JMP_SLOT:
525 /* It used to be that elf_machine_fixup_plt was used here,
526 but that doesn't work when ld.so relocates itself
527 for the second time. On the bright side, there's
528 no need to worry about thread-safety here. */
530 Elf32_Sword delta = finaladdr - (Elf32_Word) reloc_addr;
531 if (delta << 6 >> 6 == delta)
532 *reloc_addr = OPCODE_B (delta);
533 else if (finaladdr <= 0x01fffffc || finaladdr >= 0xfe000000)
534 *reloc_addr = OPCODE_BA (finaladdr);
535 else
537 Elf32_Word *plt, *data_words;
538 Elf32_Word index, offset, num_plt_entries;
540 plt = (Elf32_Word *) D_PTR (map, l_info[DT_PLTGOT]);
541 offset = reloc_addr - plt;
543 if (offset < PLT_DOUBLE_SIZE*2 + PLT_INITIAL_ENTRY_WORDS)
545 index = (offset - PLT_INITIAL_ENTRY_WORDS)/2;
546 num_plt_entries = (map->l_info[DT_PLTRELSZ]->d_un.d_val
547 / sizeof(Elf32_Rela));
548 data_words = plt + PLT_DATA_START_WORDS (num_plt_entries);
549 data_words[index] = finaladdr;
550 reloc_addr[0] = OPCODE_LI (11, index * 4);
551 reloc_addr[1] = OPCODE_B ((PLT_LONGBRANCH_ENTRY_WORDS
552 - (offset+1))
553 * 4);
554 MODIFIED_CODE_NOQUEUE (reloc_addr + 1);
556 else
558 reloc_addr[0] = OPCODE_LIS_HI (12, finaladdr);
559 reloc_addr[1] = OPCODE_ADDI (12, 12, finaladdr);
560 reloc_addr[2] = OPCODE_MTCTR (12);
561 reloc_addr[3] = OPCODE_BCTR ();
562 MODIFIED_CODE_NOQUEUE (reloc_addr + 3);
566 break;
568 #define DO_TLS_RELOC(suffix) \
569 case R_PPC_DTPREL##suffix: \
570 /* During relocation all TLS symbols are defined and used. \
571 Therefore the offset is already correct. */ \
572 if (sym_map != NULL) \
573 do_reloc##suffix ("R_PPC_DTPREL"#suffix, \
574 TLS_DTPREL_VALUE (sym, reloc)); \
575 break; \
576 case R_PPC_TPREL##suffix: \
577 if (sym_map != NULL) \
579 CHECK_STATIC_TLS (map, sym_map); \
580 do_reloc##suffix ("R_PPC_TPREL"#suffix, \
581 TLS_TPREL_VALUE (sym_map, sym, reloc)); \
583 break;
585 inline void do_reloc16 (const char *r_name, Elf32_Addr value)
587 if (__builtin_expect (value > 0x7fff && value < 0xffff8000, 0))
588 _dl_reloc_overflow (map, r_name, reloc_addr, refsym);
589 *(Elf32_Half *) reloc_addr = value;
591 inline void do_reloc16_LO (const char *r_name, Elf32_Addr value)
593 *(Elf32_Half *) reloc_addr = value;
595 inline void do_reloc16_HI (const char *r_name, Elf32_Addr value)
597 *(Elf32_Half *) reloc_addr = value >> 16;
599 inline void do_reloc16_HA (const char *r_name, Elf32_Addr value)
601 *(Elf32_Half *) reloc_addr = (value + 0x8000) >> 16;
603 DO_TLS_RELOC (16)
604 DO_TLS_RELOC (16_LO)
605 DO_TLS_RELOC (16_HI)
606 DO_TLS_RELOC (16_HA)
608 default:
609 _dl_reloc_bad_type (map, rinfo, 0);
610 return;
613 MODIFIED_CODE_NOQUEUE (reloc_addr);