1 /* Machine-dependent ELF dynamic relocation.
2 Parts copied from glibc/sysdeps/xtensa/dl-machine.h
3 Copyright (C) 2001, 2007 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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 /* Define this if the system uses RELOCA. */
21 #define ELF_USES_RELOCA
25 /* Translate a processor specific dynamic tag to the index
27 #define DT_XTENSA(x) (DT_XTENSA_##x - DT_LOPROC + DT_NUM + OS_NUM)
29 typedef struct xtensa_got_location_struct {
32 } xtensa_got_location;
34 /* Initialization sequence for the GOT. */
35 #define INIT_GOT(GOT_BASE, MODULE) \
37 xtensa_got_location *got_loc; \
38 Elf32_Addr l_addr = MODULE->loadaddr; \
41 got_loc = (xtensa_got_location *) \
42 (MODULE->dynamic_info[DT_XTENSA (GOT_LOC_OFF)] + l_addr); \
44 for (x = 0; x < MODULE->dynamic_info[DT_XTENSA (GOT_LOC_SZ)]; x++) \
46 Elf32_Addr got_start, got_end; \
47 got_start = got_loc[x].offset & ~(PAGE_SIZE - 1); \
48 got_end = ((got_loc[x].offset + got_loc[x].length + PAGE_SIZE - 1) \
49 & ~(PAGE_SIZE - 1)); \
50 _dl_mprotect ((void *)(got_start + l_addr) , got_end - got_start, \
51 PROT_READ | PROT_WRITE | PROT_EXEC); \
54 /* Fill in first GOT entry according to the ABI. */ \
55 GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
58 /* Parse dynamic info */
60 #define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
62 if (dpnt->d_tag == DT_XTENSA_GOT_LOC_OFF) \
63 dynamic[DT_XTENSA (GOT_LOC_OFF)] = dpnt->d_un.d_ptr; \
64 else if (dpnt->d_tag == DT_XTENSA_GOT_LOC_SZ) \
65 dynamic[DT_XTENSA (GOT_LOC_SZ)] = dpnt->d_un.d_val; \
68 /* Here we define the magic numbers that this dynamic loader should accept. */
69 #define MAGIC1 EM_XTENSA
72 /* Used for error messages. */
73 #define ELF_TARGET "Xtensa"
75 /* Need bootstrap relocations */
76 #define ARCH_NEEDS_BOOTSTRAP_RELOCS
79 extern unsigned long _dl_linux_resolver (struct elf_resolve *, int);
81 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
82 TLS variable, so undefined references should not be allowed to define
84 #define elf_machine_type_class(type) \
85 (((type) == R_XTENSA_JMP_SLOT || (type) == R_XTENSA_TLS_TPOFF \
86 || (type) == R_XTENSA_TLSDESC_FN || (type) == R_XTENSA_TLSDESC_ARG) \
87 * ELF_RTYPE_CLASS_PLT)
89 /* Return the link-time address of _DYNAMIC. */
90 static __always_inline Elf32_Addr
91 elf_machine_dynamic (void)
93 /* This function is only used while bootstrapping the runtime linker.
94 The "_DYNAMIC" symbol is always local so its GOT entry will initially
95 contain the link-time address. */
96 return (Elf32_Addr) &_DYNAMIC;
99 /* Return the run-time load address of the shared object. */
100 static __always_inline Elf32_Addr
101 elf_machine_load_address (void)
103 Elf32_Addr addr, tmp;
105 /* At this point, the runtime linker is being bootstrapped and the GOT
106 entry used for ".Lhere" will contain the link address. The CALL0 will
107 produce the dynamic address of ".Lhere" + 3. Thus, the end result is
108 equal to "dynamic_address(.Lhere) - link_address(.Lhere)". */
116 : "=a" (addr), "=a" (tmp));
121 static __always_inline void
122 elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
123 Elf32_Word relative_count)
125 Elf32_Rela *rpnt = (Elf32_Rela *) rel_addr;
126 while (relative_count--)
128 Elf32_Addr *const reloc_addr = (Elf32_Addr *) (load_off + rpnt->r_offset);
129 *reloc_addr += load_off + rpnt->r_addend;