iconv mapping of 0xA8 0xEC in CP1258 is non-canonical
[glibc.git] / elf / do-rel.h
blob3f8e7eb8c94a0d572f36641b5beec797307a1229
1 /* Do relocations for ELF dynamic linking.
2 Copyright (C) 1995-2003, 2004, 2011 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 /* This file may be included twice, to define both
21 `elf_dynamic_do_rel' and `elf_dynamic_do_rela'. */
23 #ifdef DO_RELA
24 # define elf_dynamic_do_Rel elf_dynamic_do_Rela
25 # define Rel Rela
26 # define elf_machine_rel elf_machine_rela
27 # define elf_machine_rel_relative elf_machine_rela_relative
28 #endif
30 #ifndef DO_ELF_MACHINE_REL_RELATIVE
31 # define DO_ELF_MACHINE_REL_RELATIVE(map, l_addr, relative) \
32 elf_machine_rel_relative (l_addr, relative, \
33 (void *) (l_addr + relative->r_offset))
34 #endif
36 #ifndef VERSYMIDX
37 # define VERSYMIDX(sym) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (sym))
38 #endif
39 #ifndef VALIDX
40 # define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
41 + DT_EXTRANUM + DT_VALTAGIDX (tag))
42 #endif
44 /* Perform the relocations in MAP on the running program image as specified
45 by RELTAG, SZTAG. If LAZY is nonzero, this is the first pass on PLT
46 relocations; they should be set up to call _dl_runtime_resolve, rather
47 than fully resolved now. */
49 auto inline void __attribute__ ((always_inline))
50 elf_dynamic_do_Rel (struct link_map *map,
51 ElfW(Addr) reladdr, ElfW(Addr) relsize,
52 __typeof (((ElfW(Dyn) *) 0)->d_un.d_val) nrelative,
53 int lazy, int skip_ifunc)
55 const ElfW(Rel) *r = (const void *) reladdr;
56 const ElfW(Rel) *end = (const void *) (reladdr + relsize);
57 ElfW(Addr) l_addr = map->l_addr;
58 # if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
59 const ElfW(Rel) *r2 = NULL;
60 const ElfW(Rel) *end2 = NULL;
61 # endif
63 #if (!defined DO_RELA || !defined ELF_MACHINE_PLT_REL) && !defined RTLD_BOOTSTRAP
64 /* We never bind lazily during ld.so bootstrap. Unfortunately gcc is
65 not clever enough to see through all the function calls to realize
66 that. */
67 if (lazy)
69 /* Doing lazy PLT relocations; they need very little info. */
70 for (; r < end; ++r)
71 # ifdef ELF_MACHINE_IRELATIVE
72 if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
74 if (r2 == NULL)
75 r2 = r;
76 end2 = r;
78 else
79 # endif
80 elf_machine_lazy_rel (map, l_addr, r, skip_ifunc);
82 # ifdef ELF_MACHINE_IRELATIVE
83 if (r2 != NULL)
84 for (; r2 <= end2; ++r2)
85 if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
86 elf_machine_lazy_rel (map, l_addr, r2, skip_ifunc);
87 # endif
89 else
90 #endif
92 const ElfW(Sym) *const symtab =
93 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
94 const ElfW(Rel) *relative = r;
95 r += nrelative;
97 #ifndef RTLD_BOOTSTRAP
98 /* This is defined in rtld.c, but nowhere in the static libc.a; make
99 the reference weak so static programs can still link. This
100 declaration cannot be done when compiling rtld.c (i.e. #ifdef
101 RTLD_BOOTSTRAP) because rtld.c contains the common defn for
102 _dl_rtld_map, which is incompatible with a weak decl in the same
103 file. */
104 # ifndef SHARED
105 weak_extern (GL(dl_rtld_map));
106 # endif
107 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
108 # if !defined DO_RELA || defined ELF_MACHINE_REL_RELATIVE
109 /* Rela platforms get the offset from r_addend and this must
110 be copied in the relocation address. Therefore we can skip
111 the relative relocations only if this is for rel
112 relocations or rela relocations if they are computed as
113 memory_loc += l_addr... */
114 if (l_addr != 0)
115 # else
116 /* ...or we know the object has been prelinked. */
117 if (l_addr != 0 || ! map->l_info[VALIDX(DT_GNU_PRELINKED)])
118 # endif
119 #endif
120 for (; relative < r; ++relative)
121 DO_ELF_MACHINE_REL_RELATIVE (map, l_addr, relative);
123 #ifdef RTLD_BOOTSTRAP
124 /* The dynamic linker always uses versioning. */
125 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
126 #else
127 if (map->l_info[VERSYMIDX (DT_VERSYM)])
128 #endif
130 const ElfW(Half) *const version =
131 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
133 for (; r < end; ++r)
135 #if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
136 if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
138 if (r2 == NULL)
139 r2 = r;
140 end2 = r;
141 continue;
143 #endif
145 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
146 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
147 &map->l_versions[ndx],
148 (void *) (l_addr + r->r_offset), skip_ifunc);
151 #if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
152 if (r2 != NULL)
153 for (; r2 <= end2; ++r2)
154 if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
156 ElfW(Half) ndx
157 = version[ELFW(R_SYM) (r2->r_info)] & 0x7fff;
158 elf_machine_rel (map, r2,
159 &symtab[ELFW(R_SYM) (r2->r_info)],
160 &map->l_versions[ndx],
161 (void *) (l_addr + r2->r_offset),
162 skip_ifunc);
164 #endif
166 #ifndef RTLD_BOOTSTRAP
167 else
169 for (; r < end; ++r)
170 # ifdef ELF_MACHINE_IRELATIVE
171 if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
173 if (r2 == NULL)
174 r2 = r;
175 end2 = r;
177 else
178 # endif
179 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
180 (void *) (l_addr + r->r_offset), skip_ifunc);
182 # ifdef ELF_MACHINE_IRELATIVE
183 if (r2 != NULL)
184 for (; r2 <= end2; ++r2)
185 if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
186 elf_machine_rel (map, r2, &symtab[ELFW(R_SYM) (r2->r_info)],
187 NULL, (void *) (l_addr + r2->r_offset),
188 skip_ifunc);
189 # endif
191 #endif
195 #undef elf_dynamic_do_Rel
196 #undef Rel
197 #undef elf_machine_rel
198 #undef elf_machine_rel_relative
199 #undef DO_ELF_MACHINE_REL_RELATIVE
200 #undef DO_RELA