Rename LDFLAGS-XXX to LDLIBS-XXX for -lstdc++
[glibc.git] / elf / do-rel.h
blob10d8f31c4e0ab153c0ce217efd07c5dcd23c3ea7
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, see
17 <http://www.gnu.org/licenses/>. */
19 /* This file may be included twice, to define both
20 `elf_dynamic_do_rel' and `elf_dynamic_do_rela'. */
22 #ifdef DO_RELA
23 # define elf_dynamic_do_Rel elf_dynamic_do_Rela
24 # define Rel Rela
25 # define elf_machine_rel elf_machine_rela
26 # define elf_machine_rel_relative elf_machine_rela_relative
27 #endif
29 #ifndef DO_ELF_MACHINE_REL_RELATIVE
30 # define DO_ELF_MACHINE_REL_RELATIVE(map, l_addr, relative) \
31 elf_machine_rel_relative (l_addr, relative, \
32 (void *) (l_addr + relative->r_offset))
33 #endif
35 #ifndef VERSYMIDX
36 # define VERSYMIDX(sym) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (sym))
37 #endif
38 #ifndef VALIDX
39 # define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
40 + DT_EXTRANUM + DT_VALTAGIDX (tag))
41 #endif
43 /* Perform the relocations in MAP on the running program image as specified
44 by RELTAG, SZTAG. If LAZY is nonzero, this is the first pass on PLT
45 relocations; they should be set up to call _dl_runtime_resolve, rather
46 than fully resolved now. */
48 auto inline void __attribute__ ((always_inline))
49 elf_dynamic_do_Rel (struct link_map *map,
50 ElfW(Addr) reladdr, ElfW(Addr) relsize,
51 __typeof (((ElfW(Dyn) *) 0)->d_un.d_val) nrelative,
52 int lazy, int skip_ifunc)
54 const ElfW(Rel) *r = (const void *) reladdr;
55 const ElfW(Rel) *end = (const void *) (reladdr + relsize);
56 ElfW(Addr) l_addr = map->l_addr;
57 # if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
58 const ElfW(Rel) *r2 = NULL;
59 const ElfW(Rel) *end2 = NULL;
60 # endif
62 #if (!defined DO_RELA || !defined ELF_MACHINE_PLT_REL) && !defined RTLD_BOOTSTRAP
63 /* We never bind lazily during ld.so bootstrap. Unfortunately gcc is
64 not clever enough to see through all the function calls to realize
65 that. */
66 if (lazy)
68 /* Doing lazy PLT relocations; they need very little info. */
69 for (; r < end; ++r)
70 # ifdef ELF_MACHINE_IRELATIVE
71 if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
73 if (r2 == NULL)
74 r2 = r;
75 end2 = r;
77 else
78 # endif
79 elf_machine_lazy_rel (map, l_addr, r, skip_ifunc);
81 # ifdef ELF_MACHINE_IRELATIVE
82 if (r2 != NULL)
83 for (; r2 <= end2; ++r2)
84 if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
85 elf_machine_lazy_rel (map, l_addr, r2, skip_ifunc);
86 # endif
88 else
89 #endif
91 const ElfW(Sym) *const symtab =
92 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
93 const ElfW(Rel) *relative = r;
94 r += nrelative;
96 #ifndef RTLD_BOOTSTRAP
97 /* This is defined in rtld.c, but nowhere in the static libc.a; make
98 the reference weak so static programs can still link. This
99 declaration cannot be done when compiling rtld.c (i.e. #ifdef
100 RTLD_BOOTSTRAP) because rtld.c contains the common defn for
101 _dl_rtld_map, which is incompatible with a weak decl in the same
102 file. */
103 # ifndef SHARED
104 weak_extern (GL(dl_rtld_map));
105 # endif
106 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
107 # if !defined DO_RELA || defined ELF_MACHINE_REL_RELATIVE
108 /* Rela platforms get the offset from r_addend and this must
109 be copied in the relocation address. Therefore we can skip
110 the relative relocations only if this is for rel
111 relocations or rela relocations if they are computed as
112 memory_loc += l_addr... */
113 if (l_addr != 0)
114 # else
115 /* ...or we know the object has been prelinked. */
116 if (l_addr != 0 || ! map->l_info[VALIDX(DT_GNU_PRELINKED)])
117 # endif
118 #endif
119 for (; relative < r; ++relative)
120 DO_ELF_MACHINE_REL_RELATIVE (map, l_addr, relative);
122 #ifdef RTLD_BOOTSTRAP
123 /* The dynamic linker always uses versioning. */
124 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
125 #else
126 if (map->l_info[VERSYMIDX (DT_VERSYM)])
127 #endif
129 const ElfW(Half) *const version =
130 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
132 for (; r < end; ++r)
134 #if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
135 if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
137 if (r2 == NULL)
138 r2 = r;
139 end2 = r;
140 continue;
142 #endif
144 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
145 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
146 &map->l_versions[ndx],
147 (void *) (l_addr + r->r_offset), skip_ifunc);
150 #if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
151 if (r2 != NULL)
152 for (; r2 <= end2; ++r2)
153 if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
155 ElfW(Half) ndx
156 = version[ELFW(R_SYM) (r2->r_info)] & 0x7fff;
157 elf_machine_rel (map, r2,
158 &symtab[ELFW(R_SYM) (r2->r_info)],
159 &map->l_versions[ndx],
160 (void *) (l_addr + r2->r_offset),
161 skip_ifunc);
163 #endif
165 #ifndef RTLD_BOOTSTRAP
166 else
168 for (; r < end; ++r)
169 # ifdef ELF_MACHINE_IRELATIVE
170 if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
172 if (r2 == NULL)
173 r2 = r;
174 end2 = r;
176 else
177 # endif
178 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
179 (void *) (l_addr + r->r_offset), skip_ifunc);
181 # ifdef ELF_MACHINE_IRELATIVE
182 if (r2 != NULL)
183 for (; r2 <= end2; ++r2)
184 if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
185 elf_machine_rel (map, r2, &symtab[ELFW(R_SYM) (r2->r_info)],
186 NULL, (void *) (l_addr + r2->r_offset),
187 skip_ifunc);
188 # endif
190 #endif
194 #undef elf_dynamic_do_Rel
195 #undef Rel
196 #undef elf_machine_rel
197 #undef elf_machine_rel_relative
198 #undef DO_ELF_MACHINE_REL_RELATIVE
199 #undef DO_RELA