1 /* Copyright (C) 2011-2017 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/>. */
24 #define ELF_MACHINE_NAME "tilegx"
26 #define ELF_MACHINE_NAME "tilepro"
29 #include <sys/param.h>
32 #include <bits/wordsize.h>
33 #include <arch/icache.h>
34 #include <arch/opcode.h>
36 /* Return nonzero iff ELF header is compatible with the running host. */
38 elf_machine_matches_host (const ElfW(Ehdr
) *ehdr
)
40 #if defined __tilegx__
41 if (ehdr
->e_machine
!= EM_TILEGX
)
44 return (ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
);
46 return (ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
);
48 #elif defined __tilepro__
49 return ehdr
->e_machine
== EM_TILEPRO
;
51 # error "Unknown tile architecture."
56 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
57 first element of the GOT. This must be inlined in a function which
60 static inline ElfW(Addr
)
61 elf_machine_dynamic (void)
67 asm( " { lnk %0; moveli %1, hw2_last(_GLOBAL_OFFSET_TABLE_ - 1f) }\n"
68 "1: shl16insli %1, %1, hw1(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
69 " shl16insli %1, %1, hw0(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
71 : "=r" (got
), "=r" (tmp
));
74 "1: addli %0, %0, lo16(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
75 " auli %0, %0, ha16(_GLOBAL_OFFSET_TABLE_ - 1b)"
83 /* Return the run-time load address of the shared object. */
84 static inline ElfW(Addr
)
85 elf_machine_load_address (void)
94 " moveli %0, hw2_last(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
95 " moveli %1, hw2_last(_DYNAMIC - 1b)\n"
98 " shl16insli %0, %0, hw1(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
99 " shl16insli %1, %1, hw1(_DYNAMIC - 1b)\n"
102 " shl16insli %0, %0, hw0(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
103 " shl16insli %1, %1, hw0(_DYNAMIC - 1b)\n"
109 : "=r" (got
), "=r" (dynamic
), "=r" (tmp
));
113 " addli %0, %0, lo16(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
114 " addli %1, %0, lo16(_DYNAMIC - 1b)\n"
117 " auli %0, %0, ha16(_GLOBAL_OFFSET_TABLE_ - 1b)\n"
118 " auli %1, %1, ha16(_DYNAMIC - 1b)\n"
120 : "=r" (got
), "=r" (dynamic
));
123 return dynamic
- *got
;
126 /* Flush some range of the instruction cache. If invoked prior to
127 actually setting dl_pagesize, we conservatively use 4KB, which
128 is the smallest page size we could plausibly be running with. */
130 _dl_flush_icache (const void *addr
, unsigned long size
)
132 invalidate_icache (addr
, size
, GLRO(dl_pagesize
) ? : 4096);
135 /* Set up the loaded object described by L so its unrelocated PLT
136 entries will jump to the on-demand fixup code in dl-runtime.c. */
138 static inline int __attribute__ ((unused
))
139 elf_machine_runtime_setup (struct link_map
*l
, int lazy
, int profile
)
142 extern void _dl_runtime_resolve (ElfW(Word
));
143 extern void _dl_runtime_profile (ElfW(Word
));
145 if (l
->l_info
[DT_JMPREL
] && lazy
)
147 gotplt
= (ElfW(Addr
) *) D_PTR (l
, l_info
[DT_PLTGOT
]);
149 /* The GOT entries for functions in the PLT have not yet been filled
150 in. Their initial contents will arrange when called to put in
151 registers an offset into the .rel.plt section, and gotplt[0], then
152 jump to gotplt[1]. */
154 /* Identify this shared object. */
155 gotplt
[0] = (ElfW(Addr
)) l
;
157 /* The gotplt[1] entry contains the address of a function which gets
158 called to get the address of a so far unresolved function and jump
159 to it. The profiling extension of the dynamic linker allows to
160 intercept the calls to collect information. In this case we don't
161 store the address in the GOTPLT so that all future calls also end
163 if (__builtin_expect (profile
, 0))
165 gotplt
[1] = (ElfW(Addr
)) &_dl_runtime_profile
;
167 if (GLRO(dl_profile
) != NULL
168 && _dl_name_match_p (GLRO(dl_profile
), l
))
169 /* This is the object we are looking for. Say that we really
170 want profiling and the timers are started. */
171 GL(dl_profile_map
) = l
;
174 /* This function will get called to fix up the GOTPLT entry
175 indicated by the offset on the stack, and then jump to the
177 gotplt
[1] = (ElfW(Addr
)) &_dl_runtime_resolve
;
184 /* Mask identifying addresses reserved for the user program,
185 where the dynamic linker should not map anything. */
186 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
189 /* Initial entry point code for the dynamic linker.
190 The C function `_dl_start' is the real entry point;
191 its return value is the user program's entry point. */
193 #define RTLD_START asm (".globl _dl_start");
195 #ifndef RTLD_START_SPECIAL_INIT
196 #define RTLD_START_SPECIAL_INIT /* nothing */
199 /* Wrap a generic Tilera relocation type. */
201 #define R_TILE(x) R_TILEGX_##x
202 #define __R_TILE_TLS(x,c) R_TILEGX_TLS_##x##c
203 #define _R_TILE_TLS(x,c) __R_TILE_TLS(x,c)
204 #define R_TILE_TLS(x) _R_TILE_TLS(x,__ELF_NATIVE_CLASS)
206 #define R_TILE(x) R_TILEPRO_##x
207 #define R_TILE_TLS(x) R_TILEPRO_TLS_##x##32
210 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
211 TLS variable, so undefined references should not be allowed to
213 ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
214 of the main executable's symbols, as for a COPY reloc. */
215 #define elf_machine_type_class(type) \
216 ((((type) == R_TILE(JMP_SLOT) || (type) == R_TILE_TLS(DTPMOD) \
217 || (type) == R_TILE_TLS(DTPOFF) || (type) == R_TILE_TLS(TPOFF)) \
218 * ELF_RTYPE_CLASS_PLT) \
219 | (((type) == R_TILE(COPY)) * ELF_RTYPE_CLASS_COPY))
221 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
222 #define ELF_MACHINE_JMP_SLOT R_TILE(JMP_SLOT)
224 /* TILE never uses Elf32_Rel relocations. */
225 #define ELF_MACHINE_NO_REL 1
226 #define ELF_MACHINE_NO_RELA 0
228 /* We define an initialization functions. This is called very early in
230 #define DL_PLATFORM_INIT dl_platform_init ()
232 static inline void __attribute__ ((unused
))
233 dl_platform_init (void)
235 if (GLRO(dl_platform
) != NULL
&& *GLRO(dl_platform
) == '\0')
236 /* Avoid an empty string which would disturb us. */
237 GLRO(dl_platform
) = NULL
;
240 static inline ElfW(Addr
)
241 elf_machine_fixup_plt (struct link_map
*map
, lookup_t t
,
242 const ElfW(Rela
) *reloc
,
243 ElfW(Addr
) *reloc_addr
, ElfW(Addr
) value
)
245 return *reloc_addr
= value
;
248 /* Return the final value of a plt relocation. */
249 static inline ElfW(Addr
)
250 elf_machine_plt_value (struct link_map
*map
, const ElfW(Rela
) *reloc
,
256 /* Support notifying the simulator about new objects. */
257 void internal_function
_dl_after_load (struct link_map
*l
);
258 #define DL_AFTER_LOAD _dl_after_load
260 /* Names of the architecture-specific auditing callback functions. */
261 #define ARCH_LA_PLTENTER tile_gnu_pltenter
262 #define ARCH_LA_PLTEXIT tile_gnu_pltexit
264 #endif /* !dl_machine_h */
271 /* Right shift operand by this number of bits. */
272 unsigned char right_shift
;
275 /* If nonzero, this is updating a code bundle. */
276 unsigned char is_bundle_update
;
278 /* If nonzero, add 0x8000 to the value. */
279 unsigned char add_0x8000
;
282 /* If nonzero, subtract the containing address from the address. */
283 unsigned char is_pcrel
;
285 /* Size in bytes, or 0 if this table entry should be ignored. */
286 unsigned char byte_size
;
289 /* Relocation information. Cannot contain create_* function pointers
290 because then the table would not be position-independent. */
291 static const struct reloc_howto howto
[] =
295 # if __WORDSIZE == 32
296 /* The GX -m32 loader only handles 32-bit types, so it will be confused
297 by shifts larger than that. We convert them to just sign-extend;
298 they usually indicate a program bug or missed optimization, but we
299 have to handle them correctly anyway. */
307 /* R_TILEGX_NONE */ { 0, 0, 0, 0 },
308 /* R_TILEGX_64 */ { 0, 0, 0, 8 },
309 /* R_TILEGX_32 */ { 0, 0, 0, 4 },
310 /* R_TILEGX_16 */ { 0, 0, 0, 2 },
311 /* R_TILEGX_8 */ { 0, 0, 0, 1 },
312 /* R_TILEGX_64_PCREL */ { 0, 0, 1, 8 },
313 /* R_TILEGX_32_PCREL */ { 0, 0, 1, 4 },
314 /* R_TILEGX_16_PCREL */ { 0, 0, 1, 2 },
315 /* R_TILEGX_8_PCREL */ { 0, 0, 1, 1 },
316 /* R_TILEGX_HW0 */ { 0, 0, 0, 0 },
317 /* R_TILEGX_HW1 */ { 16, 0, 0, 0 },
318 /* R_TILEGX_HW2 */ { S32
, 0, 0, 0 },
319 /* R_TILEGX_HW3 */ { S48
, 0, 0, 0 },
320 /* R_TILEGX_HW0_LAST */ { 0, 0, 0, 0 },
321 /* R_TILEGX_HW1_LAST */ { 16, 0, 0, 0 },
322 /* R_TILEGX_HW2_LAST */ { S32
, 0, 0, 0 },
323 /* R_TILEGX_COPY */ { 0, 0, 0, 0 },
324 /* R_TILEGX_GLOB_DAT */ { 0, 0, 0, 8 },
325 /* R_TILEGX_JMP_SLOT */ { 0, 0, 0, 0 },
326 /* R_TILEGX_RELATIVE */ { 0, 0, 0, 0 },
327 /* R_TILEGX_BROFF_X1 */ { 3, 1, 1, 8 },
328 /* R_TILEGX_JUMPOFF_X1 */ { 3, 1, 1, 8 },
329 /* R_TILEGX_JUMPOFF_X1_PLT */ { 3, 1, 1, 8 },
330 /* R_TILEGX_IMM8_X0 */ { 0, 1, 0, 8 },
331 /* R_TILEGX_IMM8_Y0 */ { 0, 1, 0, 8 },
332 /* R_TILEGX_IMM8_X1 */ { 0, 1, 0, 8 },
333 /* R_TILEGX_IMM8_Y1 */ { 0, 1, 0, 8 },
334 /* R_TILEGX_DEST_IMM8_X1 */ { 0, 1, 0, 8 },
335 /* R_TILEGX_MT_IMM14_X1 */ { 0, 1, 0, 8 },
336 /* R_TILEGX_MF_IMM14_X1 */ { 0, 1, 0, 8 },
337 /* R_TILEGX_MMSTART_X0 */ { 0, 1, 0, 8 },
338 /* R_TILEGX_MMEND_X0 */ { 0, 1, 0, 8 },
339 /* R_TILEGX_SHAMT_X0 */ { 0, 1, 0, 8 },
340 /* R_TILEGX_SHAMT_X1 */ { 0, 1, 0, 8 },
341 /* R_TILEGX_SHAMT_Y0 */ { 0, 1, 0, 8 },
342 /* R_TILEGX_SHAMT_Y1 */ { 0, 1, 0, 8 },
343 /* R_TILEGX_IMM16_X0_HW0 */ { 0, 1, 0, 8 },
344 /* R_TILEGX_IMM16_X1_HW0 */ { 0, 1, 0, 8 },
345 /* R_TILEGX_IMM16_X0_HW1 */ { 16, 1, 0, 8 },
346 /* R_TILEGX_IMM16_X1_HW1 */ { 16, 1, 0, 8 },
347 /* R_TILEGX_IMM16_X0_HW2 */ { S32
, 1, 0, 8 },
348 /* R_TILEGX_IMM16_X1_HW2 */ { S32
, 1, 0, 8 },
349 /* R_TILEGX_IMM16_X0_HW3 */ { S48
, 1, 0, 8 },
350 /* R_TILEGX_IMM16_X1_HW3 */ { S48
, 1, 0, 8 },
351 /* R_TILEGX_IMM16_X0_HW0_LAST */ { 0, 1, 0, 8 },
352 /* R_TILEGX_IMM16_X1_HW0_LAST */ { 0, 1, 0, 8 },
353 /* R_TILEGX_IMM16_X0_HW1_LAST */ { 16, 1, 0, 8 },
354 /* R_TILEGX_IMM16_X1_HW1_LAST */ { 16, 1, 0, 8 },
355 /* R_TILEGX_IMM16_X0_HW2_LAST */ { S32
, 1, 0, 8 },
356 /* R_TILEGX_IMM16_X1_HW2_LAST */ { S32
, 1, 0, 8 },
357 /* R_TILEGX_IMM16_X0_HW0_PCREL */ { 0, 1, 1, 8 },
358 /* R_TILEGX_IMM16_X1_HW0_PCREL */ { 0, 1, 1, 8 },
359 /* R_TILEGX_IMM16_X0_HW1_PCREL */ { 16, 1, 1, 8 },
360 /* R_TILEGX_IMM16_X1_HW1_PCREL */ { 16, 1, 1, 8 },
361 /* R_TILEGX_IMM16_X0_HW2_PCREL */ { S32
, 1, 1, 8 },
362 /* R_TILEGX_IMM16_X1_HW2_PCREL */ { S32
, 1, 1, 8 },
363 /* R_TILEGX_IMM16_X0_HW3_PCREL */ { S48
, 1, 1, 8 },
364 /* R_TILEGX_IMM16_X1_HW3_PCREL */ { S48
, 1, 1, 8 },
365 /* R_TILEGX_IMM16_X0_HW0_LAST_PCREL */ { 0, 1, 1, 8 },
366 /* R_TILEGX_IMM16_X1_HW0_LAST_PCREL */ { 0, 1, 1, 8 },
367 /* R_TILEGX_IMM16_X0_HW1_LAST_PCREL */ { 16, 1, 1, 8 },
368 /* R_TILEGX_IMM16_X1_HW1_LAST_PCREL */ { 16, 1, 1, 8 },
369 /* R_TILEGX_IMM16_X0_HW2_LAST_PCREL */ { S32
, 1, 1, 8 },
370 /* R_TILEGX_IMM16_X1_HW2_LAST_PCREL */ { S32
, 1, 1, 8 },
371 /* R_TILEGX_IMM16_X0_HW0_GOT */ { 0, 1, 0, 0 },
372 /* R_TILEGX_IMM16_X1_HW0_GOT */ { 0, 1, 0, 0 },
373 /* R_TILEGX_IMM16_X0_HW1_GOT */ { 16, 1, 0, 0 },
374 /* R_TILEGX_IMM16_X1_HW1_GOT */ { 16, 1, 0, 0 },
375 /* R_TILEGX_IMM16_X0_HW2_GOT */ { S32
, 1, 0, 0 },
376 /* R_TILEGX_IMM16_X1_HW2_GOT */ { S32
, 1, 0, 0 },
377 /* R_TILEGX_IMM16_X0_HW3_GOT */ { S48
, 1, 0, 0 },
378 /* R_TILEGX_IMM16_X1_HW3_GOT */ { S48
, 1, 0, 0 },
379 /* R_TILEGX_IMM16_X0_HW0_LAST_GOT */ { 0, 1, 0, 0 },
380 /* R_TILEGX_IMM16_X1_HW0_LAST_GOT */ { 0, 1, 0, 0 },
381 /* R_TILEGX_IMM16_X0_HW1_LAST_GOT */ { 16, 1, 0, 0 },
382 /* R_TILEGX_IMM16_X1_HW1_LAST_GOT */ { 16, 1, 0, 0 },
383 /* R_TILEGX_IMM16_X0_HW2_LAST_GOT */ { S32
, 1, 0, 0 },
384 /* R_TILEGX_IMM16_X1_HW2_LAST_GOT */ { S32
, 1, 0, 0 },
385 /* R_TILEGX_IMM16_X0_HW0_TLS_GD */ { 0, 1, 0, 8 },
386 /* R_TILEGX_IMM16_X1_HW0_TLS_GD */ { 0, 1, 0, 8 },
387 /* R_TILEGX_IMM16_X0_HW1_TLS_GD */ { 16, 1, 0, 8 },
388 /* R_TILEGX_IMM16_X1_HW1_TLS_GD */ { 16, 1, 0, 8 },
389 /* R_TILEGX_IMM16_X0_HW2_TLS_GD */ { S32
, 1, 0, 8 },
390 /* R_TILEGX_IMM16_X1_HW2_TLS_GD */ { S32
, 1, 0, 8 },
391 /* R_TILEGX_IMM16_X0_HW3_TLS_GD */ { S48
, 1, 0, 8 },
392 /* R_TILEGX_IMM16_X1_HW3_TLS_GD */ { S48
, 1, 0, 8 },
393 /* R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD */{ 0, 1, 0, 8 },
394 /* R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD */{ 0, 1, 0, 8 },
395 /* R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD */{ 16, 1, 0, 8 },
396 /* R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD */{ 16, 1, 0, 8 },
397 /* R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD */{ S32
, 1, 0, 8 },
398 /* R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD */{ S32
, 1, 0, 8 },
399 /* R_TILEGX_IMM16_X0_HW0_TLS_IE */ { 0, 1, 0, 8 },
400 /* R_TILEGX_IMM16_X1_HW0_TLS_IE */ { 0, 1, 0, 8 },
401 /* R_TILEGX_IMM16_X0_HW1_TLS_IE */ { 16, 1, 0, 8 },
402 /* R_TILEGX_IMM16_X1_HW1_TLS_IE */ { 16, 1, 0, 8 },
403 /* R_TILEGX_IMM16_X0_HW2_TLS_IE */ { S32
, 1, 0, 8 },
404 /* R_TILEGX_IMM16_X1_HW2_TLS_IE */ { S32
, 1, 0, 8 },
405 /* R_TILEGX_IMM16_X0_HW3_TLS_IE */ { S48
, 1, 0, 8 },
406 /* R_TILEGX_IMM16_X1_HW3_TLS_IE */ { S48
, 1, 0, 8 },
407 /* R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE */{ 0, 1, 0, 8 },
408 /* R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE */{ 0, 1, 0, 8 },
409 /* R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE */{ 16, 1, 0, 8 },
410 /* R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE */{ 16, 1, 0, 8 },
411 /* R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE */{ S32
, 1, 0, 8 },
412 /* R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE */{ S32
, 1, 0, 8 },
413 /* R_TILEGX_TLS_DTPMOD64 */ { 0, 0, 0, 0 },
414 /* R_TILEGX_TLS_DTPOFF64 */ { 0, 0, 0, 0 },
415 /* R_TILEGX_TLS_TPOFF64 */ { 0, 0, 0, 0 },
416 /* R_TILEGX_TLS_DTPMOD32 */ { 0, 0, 0, 0 },
417 /* R_TILEGX_TLS_DTPOFF32 */ { 0, 0, 0, 0 },
418 /* R_TILEGX_TLS_TPOFF32 */ { 0, 0, 0, 0 }
420 /* R_TILEPRO_NONE */ { 0, 0, 0, 0 },
421 /* R_TILEPRO_32 */ { 0, 0, 0, 4 },
422 /* R_TILEPRO_16 */ { 0, 0, 0, 2 },
423 /* R_TILEPRO_8 */ { 0, 0, 0, 1 },
424 /* R_TILEPRO_32_PCREL */ { 0, 0, 1, 4 },
425 /* R_TILEPRO_16_PCREL */ { 0, 0, 1, 2 },
426 /* R_TILEPRO_8_PCREL */ { 0, 0, 1, 1 },
427 /* R_TILEPRO_LO16 */ { 0, 0, 0, 2 },
428 /* R_TILEPRO_HI16 */ { 16, 0, 0, 2 },
429 /* R_TILEPRO_HA16 */ { 16, 1, 0, 2 },
430 /* R_TILEPRO_COPY */ { 0, 0, 0, 0 },
431 /* R_TILEPRO_GLOB_DAT */ { 0, 0, 0, 4 },
432 /* R_TILEPRO_JMP_SLOT */ { 0, 0, 0, 0 },
433 /* R_TILEPRO_RELATIVE */ { 0, 0, 0, 0 },
434 /* R_TILEPRO_BROFF_X1 */ { 3, 0, 1, 8 },
435 /* R_TILEPRO_JOFFLONG_X1 */ { 3, 0, 1, 8 },
436 /* R_TILEPRO_JOFFLONG_X1_PLT */ { 3, 0, 1, 8 },
437 /* R_TILEPRO_IMM8_X0 */ { 0, 0, 0, 8 },
438 /* R_TILEPRO_IMM8_Y0 */ { 0, 0, 0, 8 },
439 /* R_TILEPRO_IMM8_X1 */ { 0, 0, 0, 8 },
440 /* R_TILEPRO_IMM8_Y1 */ { 0, 0, 0, 8 },
441 /* R_TILEPRO_MT_IMM15_X1 */ { 0, 0, 0, 8 },
442 /* R_TILEPRO_MF_IMM15_X1 */ { 0, 0, 0, 8 },
443 /* R_TILEPRO_IMM16_X0 */ { 0, 0, 0, 8 },
444 /* R_TILEPRO_IMM16_X1 */ { 0, 0, 0, 8 },
445 /* R_TILEPRO_IMM16_X0_LO */ { 0, 0, 0, 8 },
446 /* R_TILEPRO_IMM16_X1_LO */ { 0, 0, 0, 8 },
447 /* R_TILEPRO_IMM16_X0_HI */ { 16, 0, 0, 8 },
448 /* R_TILEPRO_IMM16_X1_HI */ { 16, 0, 0, 8 },
449 /* R_TILEPRO_IMM16_X0_HA */ { 16, 1, 0, 8 },
450 /* R_TILEPRO_IMM16_X1_HA */ { 16, 1, 0, 8 },
451 /* R_TILEPRO_IMM16_X0_PCREL */ { 0, 0, 1, 8 },
452 /* R_TILEPRO_IMM16_X1_PCREL */ { 0, 0, 1, 8 },
453 /* R_TILEPRO_IMM16_X0_LO_PCREL */ { 0, 0, 1, 8 },
454 /* R_TILEPRO_IMM16_X1_LO_PCREL */ { 0, 0, 1, 8 },
455 /* R_TILEPRO_IMM16_X0_HI_PCREL */ { 16, 0, 1, 8 },
456 /* R_TILEPRO_IMM16_X1_HI_PCREL */ { 16, 0, 1, 8 },
457 /* R_TILEPRO_IMM16_X0_HA_PCREL */ { 16, 1, 1, 8 },
458 /* R_TILEPRO_IMM16_X1_HA_PCREL */ { 16, 1, 1, 8 },
459 /* R_TILEPRO_IMM16_X0_GOT */ { 0, 0, 0, 0 },
460 /* R_TILEPRO_IMM16_X1_GOT */ { 0, 0, 0, 0 },
461 /* R_TILEPRO_IMM16_X0_GOT_LO */ { 0, 0, 0, 0 },
462 /* R_TILEPRO_IMM16_X1_GOT_LO */ { 0, 0, 0, 0 },
463 /* R_TILEPRO_IMM16_X0_GOT_HI */ { 0, 0, 0, 0 },
464 /* R_TILEPRO_IMM16_X1_GOT_HI */ { 0, 0, 0, 0 },
465 /* R_TILEPRO_IMM16_X0_GOT_HA */ { 0, 0, 0, 0 },
466 /* R_TILEPRO_IMM16_X1_GOT_HA */ { 0, 0, 0, 0 },
467 /* R_TILEPRO_MMSTART_X0 */ { 0, 0, 0, 8 },
468 /* R_TILEPRO_MMEND_X0 */ { 0, 0, 0, 8 },
469 /* R_TILEPRO_MMSTART_X1 */ { 0, 0, 0, 8 },
470 /* R_TILEPRO_MMEND_X1 */ { 0, 0, 0, 8 },
471 /* R_TILEPRO_SHAMT_X0 */ { 0, 0, 0, 8 },
472 /* R_TILEPRO_SHAMT_X1 */ { 0, 0, 0, 8 },
473 /* R_TILEPRO_SHAMT_Y0 */ { 0, 0, 0, 8 },
474 /* R_TILEPRO_SHAMT_Y1 */ { 0, 0, 0, 8 },
475 /* R_TILEPRO_SN_BROFF */ { 0, 0, 0, 0 },
476 /* R_TILEPRO_SN_IMM8 */ { 0, 0, 0, 0 },
477 /* R_TILEPRO_SN_UIMM8 */ { 0, 0, 0, 0 },
478 /* R_TILEPRO_SN_BYTE0 */ { 0, 0, 0, 0 },
479 /* R_TILEPRO_SN_BYTE1 */ { 0, 0, 0, 0 },
480 /* R_TILEPRO_SN_BYTE2 */ { 0, 0, 0, 0 },
481 /* R_TILEPRO_SN_BYTE3 */ { 0, 0, 0, 0 },
482 /* R_TILEPRO_SN_SPCREL0 */ { 0, 0, 0, 0 },
483 /* R_TILEPRO_SN_SPCREL1 */ { 0, 0, 0, 0 },
484 /* R_TILEPRO_SN_SPCREL2 */ { 0, 0, 0, 0 },
485 /* R_TILEPRO_SN_SPCREL3 */ { 0, 0, 0, 0 },
486 /* R_TILEPRO_IMM16_X0_TLS_GD */ { 0, 0, 0, 8 },
487 /* R_TILEPRO_IMM16_X1_TLS_GD */ { 0, 0, 0, 8 },
488 /* R_TILEPRO_IMM16_X0_TLS_GD_LO */ { 0, 0, 0, 8 },
489 /* R_TILEPRO_IMM16_X1_TLS_GD_LO */ { 0, 0, 0, 8 },
490 /* R_TILEPRO_IMM16_X0_TLS_GD_HI */ { 16, 0, 0, 8 },
491 /* R_TILEPRO_IMM16_X1_TLS_GD_HI */ { 16, 0, 0, 8 },
492 /* R_TILEPRO_IMM16_X0_TLS_GD_HA */ { 16, 1, 0, 8 },
493 /* R_TILEPRO_IMM16_X1_TLS_GD_HA */ { 16, 1, 0, 8 },
494 /* R_TILEPRO_IMM16_X0_TLS_IE */ { 0, 0, 0, 8 },
495 /* R_TILEPRO_IMM16_X1_TLS_IE */ { 0, 0, 0, 8 },
496 /* R_TILEPRO_IMM16_X0_TLS_IE_LO */ { 0, 0, 0, 8 },
497 /* R_TILEPRO_IMM16_X1_TLS_IE_LO */ { 0, 0, 0, 8 },
498 /* R_TILEPRO_IMM16_X0_TLS_IE_HI */ { 16, 0, 0, 8 },
499 /* R_TILEPRO_IMM16_X1_TLS_IE_HI */ { 16, 0, 0, 8 },
500 /* R_TILEPRO_IMM16_X0_TLS_IE_HA */ { 16, 1, 0, 8 },
501 /* R_TILEPRO_IMM16_X1_TLS_IE_HA */ { 16, 1, 0, 8 },
502 /* R_TILEPRO_TLS_DTPMOD32 */ { 0, 0, 0, 0 },
503 /* R_TILEPRO_TLS_DTPOFF32 */ { 0, 0, 0, 0 },
504 /* R_TILEPRO_TLS_TPOFF32 */ { 0, 0, 0, 0 },
508 #if __ELF_NATIVE_CLASS == 32
509 #define ELFW_R_TYPE ELF32_R_TYPE
510 #define ELFW_ST_TYPE ELF32_ST_TYPE
512 #define ELFW_R_TYPE ELF64_R_TYPE
513 #define ELFW_ST_TYPE ELF64_ST_TYPE
516 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
517 MAP is the object containing the reloc. */
519 auto inline void __attribute__ ((always_inline
))
520 elf_machine_rela (struct link_map
*map
, const ElfW(Rela
) *reloc
,
521 const ElfW(Sym
) *sym
, const struct r_found_version
*version
,
522 void *const reloc_addr_arg
, int skip_ifunc
)
524 ElfW(Addr
) *const reloc_addr
= reloc_addr_arg
;
525 const unsigned int r_type
= ELFW_R_TYPE (reloc
->r_info
);
527 #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
528 if (__builtin_expect (r_type
== R_TILE(RELATIVE
), 0))
530 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
531 /* This is defined in rtld.c, but nowhere in the static libc.a;
532 make the reference weak so static programs can still link.
533 This declaration cannot be done when compiling rtld.c
534 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
535 common defn for _dl_rtld_map, which is incompatible with a
536 weak decl in the same file. */
538 weak_extern (GL(dl_rtld_map
));
540 if (map
!= &GL(dl_rtld_map
)) /* Already done in rtld itself. */
542 *reloc_addr
= map
->l_addr
+ reloc
->r_addend
;
547 if (__builtin_expect (r_type
== R_TILE(NONE
), 0))
550 #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
551 const ElfW(Sym
) *const refsym
= sym
;
553 struct link_map
*sym_map
= RESOLVE_MAP (&sym
, version
, r_type
);
558 else if (ELFW_ST_TYPE (sym
->st_info
) == STT_SECTION
)
559 value
= map
->l_addr
; /* like a RELATIVE reloc */
561 value
= sym_map
->l_addr
+ sym
->st_value
;
564 && __builtin_expect (ELFW(ST_TYPE
) (sym
->st_info
) == STT_GNU_IFUNC
, 0)
565 && __builtin_expect (sym
->st_shndx
!= SHN_UNDEF
, 1)
566 && __builtin_expect (!skip_ifunc
, 1))
567 value
= ((Elf64_Addr (*) (void)) value
) ();
571 case R_TILE(JMP_SLOT
):
572 elf_machine_fixup_plt (map
, 0, reloc
, reloc_addr
,
573 value
+ reloc
->r_addend
);
576 #ifndef RESOLVE_CONFLICT_FIND_MAP
577 case R_TILE_TLS(DTPMOD
):
578 # ifdef RTLD_BOOTSTRAP
579 /* During startup the dynamic linker is always the module
581 XXX If this relocation is necessary move before RESOLVE
585 /* Get the information from the link map returned by the
588 *reloc_addr
= sym_map
->l_tls_modid
;
591 case R_TILE_TLS(DTPOFF
):
592 # ifndef RTLD_BOOTSTRAP
593 /* During relocation all TLS symbols are defined and used.
594 Therefore the offset is already correct. */
596 *reloc_addr
= sym
->st_value
+ reloc
->r_addend
;
599 case R_TILE_TLS(TPOFF
):
600 # ifdef RTLD_BOOTSTRAP
601 *reloc_addr
= sym
->st_value
+ reloc
->r_addend
+ map
->l_tls_offset
;
605 CHECK_STATIC_TLS (map
, sym_map
);
606 *reloc_addr
= (sym
->st_value
+ reloc
->r_addend
607 + sym_map
->l_tls_offset
);
613 #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
614 /* Not needed in dl-conflict.c. */
617 /* This can happen in trace mode if an object could not be found. */
619 if (__builtin_expect (sym
->st_size
> refsym
->st_size
, 0)
620 || (__builtin_expect (sym
->st_size
< refsym
->st_size
, 0)
621 && __builtin_expect (GLRO(dl_verbose
), 0)))
625 strtab
= (const char *) D_PTR (map
,l_info
[DT_STRTAB
]);
626 _dl_error_printf ("%s: Symbol `%s' has different size in shared"
627 " object, consider re-linking\n",
628 RTLD_PROGNAME
, strtab
+ refsym
->st_name
);
630 memcpy (reloc_addr_arg
, (void *) value
,
631 MIN (sym
->st_size
, refsym
->st_size
));
636 /* All remaining relocations must be in the lookup table. */
637 const struct reloc_howto
*h
= &howto
[r_type
];
638 if ((unsigned int) r_type
>= sizeof howto
/ sizeof howto
[0] ||
641 #if !defined RTLD_BOOTSTRAP || defined _NDEBUG
642 /* We add these checks in the version to relocate ld.so only
643 if we are still debugging. */
644 _dl_reloc_bad_type (map
, r_type
, 0);
649 value
+= reloc
->r_addend
;
651 /* The lookup table entry knows how to perform this reloc. */
653 value
-= (ElfW(Addr
)) reloc_addr
;
660 value
= ((long) value
) >> h
->right_shift
;
662 switch (h
->byte_size
)
665 *(char *) reloc_addr
= value
;
668 *(short *) reloc_addr
= value
;
671 *(int *) reloc_addr
= value
;
675 if (!h
->is_bundle_update
)
677 *(ElfW(Addr
) *) reloc_addr
= value
;
683 /* We are updating a bundle, so use the function pointer that
684 swizzles the operand bits into the right location. */
686 tile_bundle_bits
*p
= (tile_bundle_bits
*) reloc_addr
;
687 tile_bundle_bits bits
= *p
;
689 #define MUNGE_SIGNED(func, length) do { \
690 bits = ((bits & ~create_##func (-1)) | create_##func (value)); \
691 ElfW(Addr) result = get_##func (bits); \
692 int signbits = __WORDSIZE - length; \
693 result = (long) (result << signbits) >> signbits; \
694 if (result != value) \
695 _dl_signal_error (0, map->l_name, NULL, \
696 "relocation value too large for " #func); \
699 #define MUNGE(func) MUNGE_SIGNED(func, __WORDSIZE)
701 #define MUNGE_NOCHECK(func) \
702 bits = ((bits & ~create_##func (-1)) | create_##func (value))
707 case R_TILEGX_BROFF_X1
:
708 MUNGE_SIGNED (BrOff_X1
, 17);
710 case R_TILEGX_JUMPOFF_X1
:
711 case R_TILEGX_JUMPOFF_X1_PLT
:
712 MUNGE_SIGNED (JumpOff_X1
, 27);
714 case R_TILEGX_IMM8_X0
:
715 MUNGE_SIGNED (Imm8_X0
, 8);
717 case R_TILEGX_IMM8_Y0
:
718 MUNGE_SIGNED (Imm8_Y0
, 8);
720 case R_TILEGX_IMM8_X1
:
721 MUNGE_SIGNED (Imm8_X1
, 8);
723 case R_TILEGX_IMM8_Y1
:
724 MUNGE_SIGNED (Imm8_Y1
, 8);
726 case R_TILEGX_MT_IMM14_X1
:
729 case R_TILEGX_MF_IMM14_X1
:
732 case R_TILEGX_IMM16_X0_HW0
:
733 case R_TILEGX_IMM16_X0_HW1
:
734 case R_TILEGX_IMM16_X0_HW2
:
735 case R_TILEGX_IMM16_X0_HW3
:
736 case R_TILEGX_IMM16_X0_HW0_PCREL
:
737 case R_TILEGX_IMM16_X0_HW1_PCREL
:
738 case R_TILEGX_IMM16_X0_HW2_PCREL
:
739 case R_TILEGX_IMM16_X0_HW3_PCREL
:
740 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
741 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
742 MUNGE_NOCHECK (Imm16_X0
);
744 case R_TILEGX_IMM16_X0_HW0_LAST
:
745 case R_TILEGX_IMM16_X0_HW1_LAST
:
746 case R_TILEGX_IMM16_X0_HW2_LAST
:
747 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
748 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
749 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
750 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
751 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
752 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
753 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
754 MUNGE_SIGNED (Imm16_X0
, 16);
756 case R_TILEGX_IMM16_X1_HW0
:
757 case R_TILEGX_IMM16_X1_HW1
:
758 case R_TILEGX_IMM16_X1_HW2
:
759 case R_TILEGX_IMM16_X1_HW3
:
760 case R_TILEGX_IMM16_X1_HW0_PCREL
:
761 case R_TILEGX_IMM16_X1_HW1_PCREL
:
762 case R_TILEGX_IMM16_X1_HW2_PCREL
:
763 case R_TILEGX_IMM16_X1_HW3_PCREL
:
764 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
765 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
766 MUNGE_NOCHECK (Imm16_X1
);
768 case R_TILEGX_IMM16_X1_HW0_LAST
:
769 case R_TILEGX_IMM16_X1_HW1_LAST
:
770 case R_TILEGX_IMM16_X1_HW2_LAST
:
771 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
772 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
773 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
774 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
775 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
776 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
777 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
778 MUNGE_SIGNED (Imm16_X1
, 16);
780 case R_TILEGX_MMSTART_X0
:
783 case R_TILEGX_MMEND_X0
:
786 case R_TILEGX_SHAMT_X0
:
789 case R_TILEGX_SHAMT_X1
:
792 case R_TILEGX_SHAMT_Y0
:
795 case R_TILEGX_SHAMT_Y1
:
799 case R_TILEPRO_BROFF_X1
:
800 MUNGE_SIGNED (BrOff_X1
, 17);
802 case R_TILEPRO_JOFFLONG_X1
:
803 case R_TILEPRO_JOFFLONG_X1_PLT
:
804 MUNGE_NOCHECK (JOffLong_X1
); /* holds full 32-bit value */
806 case R_TILEPRO_IMM8_X0
:
807 MUNGE_SIGNED (Imm8_X0
, 8);
809 case R_TILEPRO_IMM8_Y0
:
810 MUNGE_SIGNED (Imm8_Y0
, 8);
812 case R_TILEPRO_IMM8_X1
:
813 MUNGE_SIGNED (Imm8_X1
, 8);
815 case R_TILEPRO_IMM8_Y1
:
816 MUNGE_SIGNED (Imm8_Y1
, 8);
818 case R_TILEPRO_MT_IMM15_X1
:
821 case R_TILEPRO_MF_IMM15_X1
:
824 case R_TILEPRO_IMM16_X0_LO
:
825 case R_TILEPRO_IMM16_X0_HI
:
826 case R_TILEPRO_IMM16_X0_HA
:
827 case R_TILEPRO_IMM16_X0_LO_PCREL
:
828 case R_TILEPRO_IMM16_X0_HI_PCREL
:
829 case R_TILEPRO_IMM16_X0_HA_PCREL
:
830 case R_TILEPRO_IMM16_X0_TLS_GD_LO
:
831 case R_TILEPRO_IMM16_X0_TLS_GD_HI
:
832 case R_TILEPRO_IMM16_X0_TLS_GD_HA
:
833 case R_TILEPRO_IMM16_X0_TLS_IE_LO
:
834 case R_TILEPRO_IMM16_X0_TLS_IE_HI
:
835 case R_TILEPRO_IMM16_X0_TLS_IE_HA
:
836 MUNGE_NOCHECK (Imm16_X0
);
838 case R_TILEPRO_IMM16_X0
:
839 case R_TILEPRO_IMM16_X0_PCREL
:
840 case R_TILEPRO_IMM16_X0_TLS_GD
:
841 case R_TILEPRO_IMM16_X0_TLS_IE
:
842 MUNGE_SIGNED (Imm16_X0
, 16);
844 case R_TILEPRO_IMM16_X1_LO
:
845 case R_TILEPRO_IMM16_X1_HI
:
846 case R_TILEPRO_IMM16_X1_HA
:
847 case R_TILEPRO_IMM16_X1_LO_PCREL
:
848 case R_TILEPRO_IMM16_X1_HI_PCREL
:
849 case R_TILEPRO_IMM16_X1_HA_PCREL
:
850 case R_TILEPRO_IMM16_X1_TLS_GD_LO
:
851 case R_TILEPRO_IMM16_X1_TLS_GD_HI
:
852 case R_TILEPRO_IMM16_X1_TLS_GD_HA
:
853 case R_TILEPRO_IMM16_X1_TLS_IE_LO
:
854 case R_TILEPRO_IMM16_X1_TLS_IE_HI
:
855 case R_TILEPRO_IMM16_X1_TLS_IE_HA
:
856 MUNGE_NOCHECK (Imm16_X1
);
858 case R_TILEPRO_IMM16_X1
:
859 case R_TILEPRO_IMM16_X1_PCREL
:
860 case R_TILEPRO_IMM16_X1_TLS_GD
:
861 case R_TILEPRO_IMM16_X1_TLS_IE
:
862 MUNGE_SIGNED (Imm16_X1
, 16);
864 case R_TILEPRO_MMSTART_X0
:
867 case R_TILEPRO_MMEND_X0
:
870 case R_TILEPRO_MMSTART_X1
:
873 case R_TILEPRO_MMEND_X1
:
876 case R_TILEPRO_SHAMT_X0
:
879 case R_TILEPRO_SHAMT_X1
:
882 case R_TILEPRO_SHAMT_Y0
:
885 case R_TILEPRO_SHAMT_Y1
:
892 _dl_flush_icache (p
, sizeof (*p
));
895 auto inline void __attribute__ ((always_inline
))
896 elf_machine_rela_relative (ElfW(Addr
) l_addr
, const ElfW(Rela
) *reloc
,
897 void *const reloc_addr_arg
)
899 ElfW(Addr
) *const reloc_addr
= reloc_addr_arg
;
900 *reloc_addr
= l_addr
+ reloc
->r_addend
;
903 auto inline void __attribute__ ((always_inline
))
904 elf_machine_lazy_rel (struct link_map
*map
,
905 ElfW(Addr
) l_addr
, const ElfW(Rela
) *reloc
,
908 const unsigned int r_type
= ELF32_R_TYPE (reloc
->r_info
);
910 /* Check for unexpected PLT reloc type. */
911 if (__builtin_expect (r_type
== R_TILE(JMP_SLOT
), 1))
913 *(ElfW(Addr
) *) (l_addr
+ reloc
->r_offset
) += l_addr
;
916 _dl_reloc_bad_type (map
, r_type
, 1);
919 #endif /* RESOLVE_MAP */