Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / sysdeps / tile / dl-machine.h
blob9e36ee9820b6b67263762aa7b8ac345a4c2a916b
1 /* Copyright (C) 2011-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
4 Based on work contributed by by Carl Pederson & Martin Schwidefsky.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef dl_machine_h
21 #define dl_machine_h
23 #define ELF_MACHINE_NAME "tilegx"
25 #include <sys/param.h>
26 #include <string.h>
27 #include <link.h>
28 #include <bits/wordsize.h>
29 #include <arch/icache.h>
30 #include <arch/opcode.h>
32 /* Return nonzero iff ELF header is compatible with the running host. */
33 static inline int
34 elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
36 if (ehdr->e_machine != EM_TILEGX)
37 return 0;
38 #if __WORDSIZE == 32
39 return (ehdr->e_ident[EI_CLASS] == ELFCLASS32);
40 #else
41 return (ehdr->e_ident[EI_CLASS] == ELFCLASS64);
42 #endif
46 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
47 first element of the GOT. This must be inlined in a function which
48 uses global data. */
50 static inline ElfW(Addr)
51 elf_machine_dynamic (void)
53 ElfW(Addr) *got;
55 ElfW(Addr) tmp;
56 asm( " { lnk %0; moveli %1, hw2_last(_GLOBAL_OFFSET_TABLE_ - 1f) }\n"
57 "1: shl16insli %1, %1, hw1(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
58 " shl16insli %1, %1, hw0(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
59 " add %0, %0, %1"
60 : "=r" (got), "=r" (tmp));
62 return *got;
66 /* Return the run-time load address of the shared object. */
67 static inline ElfW(Addr)
68 elf_machine_load_address (void)
70 ElfW(Addr) *got;
71 ElfW(Addr) dynamic;
72 ElfW(Addr) tmp;
74 asm( " lnk %2\n"
75 "1: {\n"
76 " moveli %0, hw2_last(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
77 " moveli %1, hw2_last(_DYNAMIC - 1b)\n"
78 " }\n"
79 " {\n"
80 " shl16insli %0, %0, hw1(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
81 " shl16insli %1, %1, hw1(_DYNAMIC - 1b)\n"
82 " }\n"
83 " {\n"
84 " shl16insli %0, %0, hw0(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
85 " shl16insli %1, %1, hw0(_DYNAMIC - 1b)\n"
86 " }\n"
87 " {\n"
88 " add %0, %0, %2\n"
89 " add %1, %1, %2\n"
90 " }"
91 : "=r" (got), "=r" (dynamic), "=r" (tmp));
93 return dynamic - *got;
96 /* Flush some range of the instruction cache. If invoked prior to
97 actually setting dl_pagesize, we conservatively use 4KB, which
98 is the smallest page size we could plausibly be running with. */
99 static inline void
100 _dl_flush_icache (const void *addr, unsigned long size)
102 invalidate_icache (addr, size, GLRO(dl_pagesize) ? : 4096);
105 /* Set up the loaded object described by L so its unrelocated PLT
106 entries will jump to the on-demand fixup code in dl-runtime.c. */
108 static inline int __attribute__ ((unused))
109 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
111 ElfW(Addr) *gotplt;
112 extern void _dl_runtime_resolve (ElfW(Word));
113 extern void _dl_runtime_profile (ElfW(Word));
115 if (l->l_info[DT_JMPREL] && lazy)
117 gotplt = (ElfW(Addr) *) D_PTR (l, l_info[DT_PLTGOT]);
119 /* The GOT entries for functions in the PLT have not yet been filled
120 in. Their initial contents will arrange when called to put in
121 registers an offset into the .rel.plt section, and gotplt[0], then
122 jump to gotplt[1]. */
124 /* Identify this shared object. */
125 gotplt[0] = (ElfW(Addr)) l;
127 /* The gotplt[1] entry contains the address of a function which gets
128 called to get the address of a so far unresolved function and jump
129 to it. The profiling extension of the dynamic linker allows to
130 intercept the calls to collect information. In this case we don't
131 store the address in the GOTPLT so that all future calls also end
132 in this function. */
133 if (__builtin_expect (profile, 0))
135 gotplt[1] = (ElfW(Addr)) &_dl_runtime_profile;
137 if (GLRO(dl_profile) != NULL
138 && _dl_name_match_p (GLRO(dl_profile), l))
139 /* This is the object we are looking for. Say that we really
140 want profiling and the timers are started. */
141 GL(dl_profile_map) = l;
143 else
144 /* This function will get called to fix up the GOTPLT entry
145 indicated by the offset on the stack, and then jump to the
146 resolved address. */
147 gotplt[1] = (ElfW(Addr)) &_dl_runtime_resolve;
150 return lazy;
153 #if __WORDSIZE == 32
154 /* Mask identifying addresses reserved for the user program,
155 where the dynamic linker should not map anything. */
156 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
157 #endif
159 /* Initial entry point code for the dynamic linker.
160 The C function `_dl_start' is the real entry point;
161 its return value is the user program's entry point. */
163 #define RTLD_START asm (".globl _dl_start");
165 #ifndef RTLD_START_SPECIAL_INIT
166 #define RTLD_START_SPECIAL_INIT /* nothing */
167 #endif
169 /* Wrap a generic Tilera relocation type. */
170 #define R_TILE(x) R_TILEGX_##x
171 #define __R_TILE_TLS(x,c) R_TILEGX_TLS_##x##c
172 #define _R_TILE_TLS(x,c) __R_TILE_TLS(x,c)
173 #define R_TILE_TLS(x) _R_TILE_TLS(x,__ELF_NATIVE_CLASS)
175 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
176 TLS variable, so undefined references should not be allowed to
177 define the value.
178 ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
179 of the main executable's symbols, as for a COPY reloc. */
180 #define elf_machine_type_class(type) \
181 ((((type) == R_TILE(JMP_SLOT) || (type) == R_TILE_TLS(DTPMOD) \
182 || (type) == R_TILE_TLS(DTPOFF) || (type) == R_TILE_TLS(TPOFF)) \
183 * ELF_RTYPE_CLASS_PLT) \
184 | (((type) == R_TILE(COPY)) * ELF_RTYPE_CLASS_COPY))
186 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
187 #define ELF_MACHINE_JMP_SLOT R_TILE(JMP_SLOT)
189 /* TILE never uses Elf32_Rel relocations. */
190 #define ELF_MACHINE_NO_REL 1
191 #define ELF_MACHINE_NO_RELA 0
193 /* We define an initialization functions. This is called very early in
194 _dl_sysdep_start. */
195 #define DL_PLATFORM_INIT dl_platform_init ()
197 static inline void __attribute__ ((unused))
198 dl_platform_init (void)
200 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
201 /* Avoid an empty string which would disturb us. */
202 GLRO(dl_platform) = NULL;
205 static inline ElfW(Addr)
206 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
207 const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
208 const ElfW(Rela) *reloc,
209 ElfW(Addr) *reloc_addr, ElfW(Addr) value)
211 return *reloc_addr = value;
214 /* Return the final value of a plt relocation. */
215 static inline ElfW(Addr)
216 elf_machine_plt_value (struct link_map *map, const ElfW(Rela) *reloc,
217 ElfW(Addr) value)
219 return value;
222 /* Support notifying the simulator about new objects. */
223 void _dl_after_load (struct link_map *l);
224 #define DL_AFTER_LOAD _dl_after_load
226 /* Names of the architecture-specific auditing callback functions. */
227 #define ARCH_LA_PLTENTER tile_gnu_pltenter
228 #define ARCH_LA_PLTEXIT tile_gnu_pltexit
230 #endif /* !dl_machine_h */
233 #ifdef RESOLVE_MAP
235 struct reloc_howto
237 /* Right shift operand by this number of bits. */
238 unsigned char right_shift;
240 /* If nonzero, this is updating a code bundle. */
241 unsigned char is_bundle_update;
243 /* If nonzero, subtract the containing address from the address. */
244 unsigned char is_pcrel;
246 /* Size in bytes, or 0 if this table entry should be ignored. */
247 unsigned char byte_size;
250 /* Relocation information. Cannot contain create_* function pointers
251 because then the table would not be position-independent. */
252 static const struct reloc_howto howto[] =
254 #if __WORDSIZE == 32
255 /* The GX -m32 loader only handles 32-bit types, so it will be confused
256 by shifts larger than that. We convert them to just sign-extend;
257 they usually indicate a program bug or missed optimization, but we
258 have to handle them correctly anyway. */
259 # define S32 31
260 # define S48 31
261 #else
262 # define S32 32
263 # define S48 48
264 #endif
266 /* R_TILEGX_NONE */ { 0, 0, 0, 0 },
267 /* R_TILEGX_64 */ { 0, 0, 0, 8 },
268 /* R_TILEGX_32 */ { 0, 0, 0, 4 },
269 /* R_TILEGX_16 */ { 0, 0, 0, 2 },
270 /* R_TILEGX_8 */ { 0, 0, 0, 1 },
271 /* R_TILEGX_64_PCREL */ { 0, 0, 1, 8 },
272 /* R_TILEGX_32_PCREL */ { 0, 0, 1, 4 },
273 /* R_TILEGX_16_PCREL */ { 0, 0, 1, 2 },
274 /* R_TILEGX_8_PCREL */ { 0, 0, 1, 1 },
275 /* R_TILEGX_HW0 */ { 0, 0, 0, 0 },
276 /* R_TILEGX_HW1 */ { 16, 0, 0, 0 },
277 /* R_TILEGX_HW2 */ { S32, 0, 0, 0 },
278 /* R_TILEGX_HW3 */ { S48, 0, 0, 0 },
279 /* R_TILEGX_HW0_LAST */ { 0, 0, 0, 0 },
280 /* R_TILEGX_HW1_LAST */ { 16, 0, 0, 0 },
281 /* R_TILEGX_HW2_LAST */ { S32, 0, 0, 0 },
282 /* R_TILEGX_COPY */ { 0, 0, 0, 0 },
283 /* R_TILEGX_GLOB_DAT */ { 0, 0, 0, 8 },
284 /* R_TILEGX_JMP_SLOT */ { 0, 0, 0, 0 },
285 /* R_TILEGX_RELATIVE */ { 0, 0, 0, 0 },
286 /* R_TILEGX_BROFF_X1 */ { 3, 1, 1, 8 },
287 /* R_TILEGX_JUMPOFF_X1 */ { 3, 1, 1, 8 },
288 /* R_TILEGX_JUMPOFF_X1_PLT */ { 3, 1, 1, 8 },
289 /* R_TILEGX_IMM8_X0 */ { 0, 1, 0, 8 },
290 /* R_TILEGX_IMM8_Y0 */ { 0, 1, 0, 8 },
291 /* R_TILEGX_IMM8_X1 */ { 0, 1, 0, 8 },
292 /* R_TILEGX_IMM8_Y1 */ { 0, 1, 0, 8 },
293 /* R_TILEGX_DEST_IMM8_X1 */ { 0, 1, 0, 8 },
294 /* R_TILEGX_MT_IMM14_X1 */ { 0, 1, 0, 8 },
295 /* R_TILEGX_MF_IMM14_X1 */ { 0, 1, 0, 8 },
296 /* R_TILEGX_MMSTART_X0 */ { 0, 1, 0, 8 },
297 /* R_TILEGX_MMEND_X0 */ { 0, 1, 0, 8 },
298 /* R_TILEGX_SHAMT_X0 */ { 0, 1, 0, 8 },
299 /* R_TILEGX_SHAMT_X1 */ { 0, 1, 0, 8 },
300 /* R_TILEGX_SHAMT_Y0 */ { 0, 1, 0, 8 },
301 /* R_TILEGX_SHAMT_Y1 */ { 0, 1, 0, 8 },
302 /* R_TILEGX_IMM16_X0_HW0 */ { 0, 1, 0, 8 },
303 /* R_TILEGX_IMM16_X1_HW0 */ { 0, 1, 0, 8 },
304 /* R_TILEGX_IMM16_X0_HW1 */ { 16, 1, 0, 8 },
305 /* R_TILEGX_IMM16_X1_HW1 */ { 16, 1, 0, 8 },
306 /* R_TILEGX_IMM16_X0_HW2 */ { S32, 1, 0, 8 },
307 /* R_TILEGX_IMM16_X1_HW2 */ { S32, 1, 0, 8 },
308 /* R_TILEGX_IMM16_X0_HW3 */ { S48, 1, 0, 8 },
309 /* R_TILEGX_IMM16_X1_HW3 */ { S48, 1, 0, 8 },
310 /* R_TILEGX_IMM16_X0_HW0_LAST */ { 0, 1, 0, 8 },
311 /* R_TILEGX_IMM16_X1_HW0_LAST */ { 0, 1, 0, 8 },
312 /* R_TILEGX_IMM16_X0_HW1_LAST */ { 16, 1, 0, 8 },
313 /* R_TILEGX_IMM16_X1_HW1_LAST */ { 16, 1, 0, 8 },
314 /* R_TILEGX_IMM16_X0_HW2_LAST */ { S32, 1, 0, 8 },
315 /* R_TILEGX_IMM16_X1_HW2_LAST */ { S32, 1, 0, 8 },
316 /* R_TILEGX_IMM16_X0_HW0_PCREL */ { 0, 1, 1, 8 },
317 /* R_TILEGX_IMM16_X1_HW0_PCREL */ { 0, 1, 1, 8 },
318 /* R_TILEGX_IMM16_X0_HW1_PCREL */ { 16, 1, 1, 8 },
319 /* R_TILEGX_IMM16_X1_HW1_PCREL */ { 16, 1, 1, 8 },
320 /* R_TILEGX_IMM16_X0_HW2_PCREL */ { S32, 1, 1, 8 },
321 /* R_TILEGX_IMM16_X1_HW2_PCREL */ { S32, 1, 1, 8 },
322 /* R_TILEGX_IMM16_X0_HW3_PCREL */ { S48, 1, 1, 8 },
323 /* R_TILEGX_IMM16_X1_HW3_PCREL */ { S48, 1, 1, 8 },
324 /* R_TILEGX_IMM16_X0_HW0_LAST_PCREL */ { 0, 1, 1, 8 },
325 /* R_TILEGX_IMM16_X1_HW0_LAST_PCREL */ { 0, 1, 1, 8 },
326 /* R_TILEGX_IMM16_X0_HW1_LAST_PCREL */ { 16, 1, 1, 8 },
327 /* R_TILEGX_IMM16_X1_HW1_LAST_PCREL */ { 16, 1, 1, 8 },
328 /* R_TILEGX_IMM16_X0_HW2_LAST_PCREL */ { S32, 1, 1, 8 },
329 /* R_TILEGX_IMM16_X1_HW2_LAST_PCREL */ { S32, 1, 1, 8 },
330 /* R_TILEGX_IMM16_X0_HW0_GOT */ { 0, 1, 0, 0 },
331 /* R_TILEGX_IMM16_X1_HW0_GOT */ { 0, 1, 0, 0 },
332 /* R_TILEGX_IMM16_X0_HW1_GOT */ { 16, 1, 0, 0 },
333 /* R_TILEGX_IMM16_X1_HW1_GOT */ { 16, 1, 0, 0 },
334 /* R_TILEGX_IMM16_X0_HW2_GOT */ { S32, 1, 0, 0 },
335 /* R_TILEGX_IMM16_X1_HW2_GOT */ { S32, 1, 0, 0 },
336 /* R_TILEGX_IMM16_X0_HW3_GOT */ { S48, 1, 0, 0 },
337 /* R_TILEGX_IMM16_X1_HW3_GOT */ { S48, 1, 0, 0 },
338 /* R_TILEGX_IMM16_X0_HW0_LAST_GOT */ { 0, 1, 0, 0 },
339 /* R_TILEGX_IMM16_X1_HW0_LAST_GOT */ { 0, 1, 0, 0 },
340 /* R_TILEGX_IMM16_X0_HW1_LAST_GOT */ { 16, 1, 0, 0 },
341 /* R_TILEGX_IMM16_X1_HW1_LAST_GOT */ { 16, 1, 0, 0 },
342 /* R_TILEGX_IMM16_X0_HW2_LAST_GOT */ { S32, 1, 0, 0 },
343 /* R_TILEGX_IMM16_X1_HW2_LAST_GOT */ { S32, 1, 0, 0 },
344 /* R_TILEGX_IMM16_X0_HW0_TLS_GD */ { 0, 1, 0, 8 },
345 /* R_TILEGX_IMM16_X1_HW0_TLS_GD */ { 0, 1, 0, 8 },
346 /* R_TILEGX_IMM16_X0_HW1_TLS_GD */ { 16, 1, 0, 8 },
347 /* R_TILEGX_IMM16_X1_HW1_TLS_GD */ { 16, 1, 0, 8 },
348 /* R_TILEGX_IMM16_X0_HW2_TLS_GD */ { S32, 1, 0, 8 },
349 /* R_TILEGX_IMM16_X1_HW2_TLS_GD */ { S32, 1, 0, 8 },
350 /* R_TILEGX_IMM16_X0_HW3_TLS_GD */ { S48, 1, 0, 8 },
351 /* R_TILEGX_IMM16_X1_HW3_TLS_GD */ { S48, 1, 0, 8 },
352 /* R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD */{ 0, 1, 0, 8 },
353 /* R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD */{ 0, 1, 0, 8 },
354 /* R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD */{ 16, 1, 0, 8 },
355 /* R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD */{ 16, 1, 0, 8 },
356 /* R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD */{ S32, 1, 0, 8 },
357 /* R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD */{ S32, 1, 0, 8 },
358 /* R_TILEGX_IMM16_X0_HW0_TLS_IE */ { 0, 1, 0, 8 },
359 /* R_TILEGX_IMM16_X1_HW0_TLS_IE */ { 0, 1, 0, 8 },
360 /* R_TILEGX_IMM16_X0_HW1_TLS_IE */ { 16, 1, 0, 8 },
361 /* R_TILEGX_IMM16_X1_HW1_TLS_IE */ { 16, 1, 0, 8 },
362 /* R_TILEGX_IMM16_X0_HW2_TLS_IE */ { S32, 1, 0, 8 },
363 /* R_TILEGX_IMM16_X1_HW2_TLS_IE */ { S32, 1, 0, 8 },
364 /* R_TILEGX_IMM16_X0_HW3_TLS_IE */ { S48, 1, 0, 8 },
365 /* R_TILEGX_IMM16_X1_HW3_TLS_IE */ { S48, 1, 0, 8 },
366 /* R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE */{ 0, 1, 0, 8 },
367 /* R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE */{ 0, 1, 0, 8 },
368 /* R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE */{ 16, 1, 0, 8 },
369 /* R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE */{ 16, 1, 0, 8 },
370 /* R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE */{ S32, 1, 0, 8 },
371 /* R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE */{ S32, 1, 0, 8 },
372 /* R_TILEGX_TLS_DTPMOD64 */ { 0, 0, 0, 0 },
373 /* R_TILEGX_TLS_DTPOFF64 */ { 0, 0, 0, 0 },
374 /* R_TILEGX_TLS_TPOFF64 */ { 0, 0, 0, 0 },
375 /* R_TILEGX_TLS_DTPMOD32 */ { 0, 0, 0, 0 },
376 /* R_TILEGX_TLS_DTPOFF32 */ { 0, 0, 0, 0 },
377 /* R_TILEGX_TLS_TPOFF32 */ { 0, 0, 0, 0 }
380 #if __ELF_NATIVE_CLASS == 32
381 #define ELFW_R_TYPE ELF32_R_TYPE
382 #define ELFW_ST_TYPE ELF32_ST_TYPE
383 #else
384 #define ELFW_R_TYPE ELF64_R_TYPE
385 #define ELFW_ST_TYPE ELF64_ST_TYPE
386 #endif
388 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
389 MAP is the object containing the reloc. */
391 auto inline void __attribute__ ((always_inline))
392 elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
393 const ElfW(Sym) *sym, const struct r_found_version *version,
394 void *const reloc_addr_arg, int skip_ifunc)
396 ElfW(Addr) *const reloc_addr = reloc_addr_arg;
397 const unsigned int r_type = ELFW_R_TYPE (reloc->r_info);
399 #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
400 if (__builtin_expect (r_type == R_TILE(RELATIVE), 0))
402 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
403 /* This is defined in rtld.c, but nowhere in the static libc.a;
404 make the reference weak so static programs can still link.
405 This declaration cannot be done when compiling rtld.c
406 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
407 common defn for _dl_rtld_map, which is incompatible with a
408 weak decl in the same file. */
409 # ifndef SHARED
410 weak_extern (GL(dl_rtld_map));
411 # endif
412 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
413 # endif
414 *reloc_addr = map->l_addr + reloc->r_addend;
415 return;
417 #endif
419 if (__builtin_expect (r_type == R_TILE(NONE), 0))
420 return;
422 #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
423 const ElfW(Sym) *const refsym = sym;
424 #endif
425 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
426 ElfW(Addr) value;
428 if (sym == NULL)
429 value = 0;
430 else if (ELFW_ST_TYPE (sym->st_info) == STT_SECTION)
431 value = map->l_addr; /* like a RELATIVE reloc */
432 else
433 value = sym_map->l_addr + sym->st_value;
435 if (sym != NULL
436 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
437 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
438 && __builtin_expect (!skip_ifunc, 1))
439 value = ((Elf64_Addr (*) (void)) value) ();
441 switch (r_type)
443 case R_TILE(JMP_SLOT):
444 elf_machine_fixup_plt (map, 0, 0, 0, reloc, reloc_addr,
445 value + reloc->r_addend);
446 return;
448 #ifndef RESOLVE_CONFLICT_FIND_MAP
449 case R_TILE_TLS(DTPMOD):
450 # ifdef RTLD_BOOTSTRAP
451 /* During startup the dynamic linker is always the module
452 with index 1.
453 XXX If this relocation is necessary move before RESOLVE
454 call. */
455 *reloc_addr = 1;
456 # else
457 /* Get the information from the link map returned by the
458 resolv function. */
459 if (sym_map != NULL)
460 *reloc_addr = sym_map->l_tls_modid;
461 # endif
462 return;
463 case R_TILE_TLS(DTPOFF):
464 # ifndef RTLD_BOOTSTRAP
465 /* During relocation all TLS symbols are defined and used.
466 Therefore the offset is already correct. */
467 if (sym != NULL)
468 *reloc_addr = sym->st_value + reloc->r_addend;
469 # endif
470 return;
471 case R_TILE_TLS(TPOFF):
472 # ifdef RTLD_BOOTSTRAP
473 *reloc_addr = sym->st_value + reloc->r_addend + map->l_tls_offset;
474 # else
475 if (sym != NULL)
477 CHECK_STATIC_TLS (map, sym_map);
478 *reloc_addr = (sym->st_value + reloc->r_addend
479 + sym_map->l_tls_offset);
481 #endif
482 return;
483 #endif /* use TLS */
485 #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
486 /* Not needed in dl-conflict.c. */
487 case R_TILE(COPY):
488 if (sym == NULL)
489 /* This can happen in trace mode if an object could not be found. */
490 return;
491 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
492 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
493 && __builtin_expect (GLRO(dl_verbose), 0)))
495 const char *strtab;
497 strtab = (const char *) D_PTR (map,l_info[DT_STRTAB]);
498 _dl_error_printf ("%s: Symbol `%s' has different size in shared"
499 " object, consider re-linking\n",
500 RTLD_PROGNAME, strtab + refsym->st_name);
502 memcpy (reloc_addr_arg, (void *) value,
503 MIN (sym->st_size, refsym->st_size));
504 return;
505 #endif
508 /* All remaining relocations must be in the lookup table. */
509 const struct reloc_howto *h = &howto[r_type];
510 if ((unsigned int) r_type >= sizeof howto / sizeof howto[0] ||
511 h->byte_size == 0)
513 #if !defined RTLD_BOOTSTRAP || defined _NDEBUG
514 /* We add these checks in the version to relocate ld.so only
515 if we are still debugging. */
516 _dl_reloc_bad_type (map, r_type, 0);
517 #endif
518 return;
521 value += reloc->r_addend;
523 /* The lookup table entry knows how to perform this reloc. */
524 if (h->is_pcrel)
525 value -= (ElfW(Addr)) reloc_addr;
527 value = ((long) value) >> h->right_shift;
529 switch (h->byte_size)
531 case 1:
532 *(char *) reloc_addr = value;
533 return;
534 case 2:
535 *(short *) reloc_addr = value;
536 return;
537 case 4:
538 *(int *) reloc_addr = value;
539 return;
540 case 8:
541 if (!h->is_bundle_update)
543 *(ElfW(Addr) *) reloc_addr = value;
544 return;
548 /* We are updating a bundle, so use the function pointer that
549 swizzles the operand bits into the right location. */
551 tile_bundle_bits *p = (tile_bundle_bits *) reloc_addr;
552 tile_bundle_bits bits = *p;
554 #define MUNGE_SIGNED(func, length) do { \
555 bits = ((bits & ~create_##func (-1)) | create_##func (value)); \
556 ElfW(Addr) result = get_##func (bits); \
557 int signbits = __WORDSIZE - length; \
558 result = (long) (result << signbits) >> signbits; \
559 if (result != value) \
560 _dl_signal_error (0, map->l_name, NULL, \
561 "relocation value too large for " #func); \
562 } while (0)
564 #define MUNGE(func) MUNGE_SIGNED(func, __WORDSIZE)
566 #define MUNGE_NOCHECK(func) \
567 bits = ((bits & ~create_##func (-1)) | create_##func (value))
569 switch (r_type)
571 case R_TILEGX_BROFF_X1:
572 MUNGE_SIGNED (BrOff_X1, 17);
573 break;
574 case R_TILEGX_JUMPOFF_X1:
575 case R_TILEGX_JUMPOFF_X1_PLT:
576 MUNGE_SIGNED (JumpOff_X1, 27);
577 break;
578 case R_TILEGX_IMM8_X0:
579 MUNGE_SIGNED (Imm8_X0, 8);
580 break;
581 case R_TILEGX_IMM8_Y0:
582 MUNGE_SIGNED (Imm8_Y0, 8);
583 break;
584 case R_TILEGX_IMM8_X1:
585 MUNGE_SIGNED (Imm8_X1, 8);
586 break;
587 case R_TILEGX_IMM8_Y1:
588 MUNGE_SIGNED (Imm8_Y1, 8);
589 break;
590 case R_TILEGX_MT_IMM14_X1:
591 MUNGE (MT_Imm14_X1);
592 break;
593 case R_TILEGX_MF_IMM14_X1:
594 MUNGE (MF_Imm14_X1);
595 break;
596 case R_TILEGX_IMM16_X0_HW0:
597 case R_TILEGX_IMM16_X0_HW1:
598 case R_TILEGX_IMM16_X0_HW2:
599 case R_TILEGX_IMM16_X0_HW3:
600 case R_TILEGX_IMM16_X0_HW0_PCREL:
601 case R_TILEGX_IMM16_X0_HW1_PCREL:
602 case R_TILEGX_IMM16_X0_HW2_PCREL:
603 case R_TILEGX_IMM16_X0_HW3_PCREL:
604 case R_TILEGX_IMM16_X0_HW0_TLS_GD:
605 case R_TILEGX_IMM16_X0_HW0_TLS_IE:
606 MUNGE_NOCHECK (Imm16_X0);
607 break;
608 case R_TILEGX_IMM16_X0_HW0_LAST:
609 case R_TILEGX_IMM16_X0_HW1_LAST:
610 case R_TILEGX_IMM16_X0_HW2_LAST:
611 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
612 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
613 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
614 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
615 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
616 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
617 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
618 MUNGE_SIGNED (Imm16_X0, 16);
619 break;
620 case R_TILEGX_IMM16_X1_HW0:
621 case R_TILEGX_IMM16_X1_HW1:
622 case R_TILEGX_IMM16_X1_HW2:
623 case R_TILEGX_IMM16_X1_HW3:
624 case R_TILEGX_IMM16_X1_HW0_PCREL:
625 case R_TILEGX_IMM16_X1_HW1_PCREL:
626 case R_TILEGX_IMM16_X1_HW2_PCREL:
627 case R_TILEGX_IMM16_X1_HW3_PCREL:
628 case R_TILEGX_IMM16_X1_HW0_TLS_GD:
629 case R_TILEGX_IMM16_X1_HW0_TLS_IE:
630 MUNGE_NOCHECK (Imm16_X1);
631 break;
632 case R_TILEGX_IMM16_X1_HW0_LAST:
633 case R_TILEGX_IMM16_X1_HW1_LAST:
634 case R_TILEGX_IMM16_X1_HW2_LAST:
635 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
636 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
637 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
638 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
639 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
640 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
641 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
642 MUNGE_SIGNED (Imm16_X1, 16);
643 break;
644 case R_TILEGX_MMSTART_X0:
645 MUNGE (BFStart_X0);
646 break;
647 case R_TILEGX_MMEND_X0:
648 MUNGE (BFEnd_X0);
649 break;
650 case R_TILEGX_SHAMT_X0:
651 MUNGE (ShAmt_X0);
652 break;
653 case R_TILEGX_SHAMT_X1:
654 MUNGE (ShAmt_X1);
655 break;
656 case R_TILEGX_SHAMT_Y0:
657 MUNGE (ShAmt_Y0);
658 break;
659 case R_TILEGX_SHAMT_Y1:
660 MUNGE (ShAmt_Y1);
661 break;
663 #undef MUNGE
664 *p = bits;
665 _dl_flush_icache (p, sizeof (*p));
668 auto inline void __attribute__ ((always_inline))
669 elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
670 void *const reloc_addr_arg)
672 ElfW(Addr) *const reloc_addr = reloc_addr_arg;
673 *reloc_addr = l_addr + reloc->r_addend;
676 auto inline void __attribute__ ((always_inline))
677 elf_machine_lazy_rel (struct link_map *map,
678 ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
679 int skip_ifunc)
681 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
683 /* Check for unexpected PLT reloc type. */
684 if (__builtin_expect (r_type == R_TILE(JMP_SLOT), 1))
686 *(ElfW(Addr) *) (l_addr + reloc->r_offset) += l_addr;
688 else
689 _dl_reloc_bad_type (map, r_type, 1);
692 #endif /* RESOLVE_MAP */