]> sourceware.org Git - glibc.git/blame - elf/dynamic-link.h
Update.
[glibc.git] / elf / dynamic-link.h
CommitLineData
d66e34cd 1/* Inline functions for dynamic linking.
df4ef2ab 2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
afd4eb37
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
d66e34cd
RM
19
20#include <elf.h>
d66e34cd 21#include <dl-machine.h>
d66e34cd
RM
22#include <assert.h>
23
421f82e5 24
cf29ffbe
UD
25/* Global read-only variable defined in rtld.c which is nonzero if we
26 shall give more warning messages. */
27extern int _dl_verbose __attribute__ ((unused));
28
29
d66e34cd
RM
30/* Read the dynamic section at DYN and fill in INFO with indices DT_*. */
31
e75154a6 32static inline void __attribute__ ((unused))
df4ef2ab 33elf_get_dynamic_info (ElfW(Dyn) *dyn,
1228ed5c
UD
34 ElfW(Dyn) *info[DT_NUM + DT_PROCNUM + DT_VERSIONTAGNUM
35 + DT_EXTRANUM])
d66e34cd
RM
36{
37 unsigned int i;
38
1228ed5c 39 for (i = 0; i < DT_NUM + DT_PROCNUM + DT_VERSIONTAGNUM + DT_EXTRANUM; ++i)
d66e34cd
RM
40 info[i] = NULL;
41
b122c703
RM
42 if (! dyn)
43 return;
44
d66e34cd
RM
45 while (dyn->d_tag != DT_NULL)
46 {
a2e1b046
RM
47 if (dyn->d_tag < DT_NUM)
48 info[dyn->d_tag] = dyn;
49 else if (dyn->d_tag >= DT_LOPROC &&
50 dyn->d_tag < DT_LOPROC + DT_PROCNUM)
51 info[dyn->d_tag - DT_LOPROC + DT_NUM] = dyn;
1228ed5c
UD
52 else if ((Elf32_Word) DT_VERSIONTAGIDX (dyn->d_tag) < DT_VERSIONTAGNUM)
53 info[DT_VERSIONTAGIDX (dyn->d_tag) + DT_NUM + DT_PROCNUM] = dyn;
df4ef2ab 54 else if ((Elf32_Word) DT_EXTRATAGIDX (dyn->d_tag) < DT_EXTRANUM)
1228ed5c
UD
55 info[DT_EXTRATAGIDX (dyn->d_tag) + DT_NUM + DT_PROCNUM
56 + DT_VERSIONTAGNUM] = dyn;
a2e1b046 57 else
38334018 58 assert (! "bad dynamic tag");
bd355af0 59 ++dyn;
d66e34cd
RM
60 }
61
62 if (info[DT_RELA])
266180eb 63 assert (info[DT_RELAENT]->d_un.d_val == sizeof (ElfW(Rela)));
d66e34cd 64 if (info[DT_REL])
266180eb 65 assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
d66e34cd
RM
66 if (info[DT_PLTREL])
67 assert (info[DT_PLTREL]->d_un.d_val == DT_REL ||
68 info[DT_PLTREL]->d_un.d_val == DT_RELA);
69}
70
f51d1dfd
RM
71#ifdef RESOLVE
72
421f82e5
RM
73/* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.
74 These functions are almost identical, so we use cpp magic to avoid
75 duplicating their code. It cannot be done in a more general function
76 because we must be able to completely inline. */
77
ca34d7a7
UD
78/* On some machines, notably Sparc, DT_REL* includes DT_JMPREL in its
79 range. Note that according to the ELF spec, this is completely legal!
80 But conditionally define things so that on machines we know this will
81 not happen we do something more optimal. */
82
83#ifdef ELF_MACHINE_PLTREL_OVERLAP
84#define _ELF_DYNAMIC_DO_RELOC(RELOC, reloc, map, lazy) \
85 do { \
86 ElfW(Addr) r_addr, r_size, p_addr, p_size; \
87 if ((map)->l_info[DT_##RELOC]) \
88 { \
89 r_addr = (map)->l_info[DT_##RELOC]->d_un.d_ptr; \
90 r_size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val; \
91 if ((map)->l_info[DT_PLTREL] && \
92 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC) \
93 { \
94 p_addr = (map)->l_info[DT_JMPREL]->d_un.d_ptr; \
95 p_size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \
96 if (r_addr <= p_addr && r_addr+r_size > p_addr) \
97 { \
98 ElfW(Addr) r2_addr, r2_size; \
bd355af0
UD
99 r2_addr = p_addr + p_size; \
100 if (r2_addr < r_addr + r_size) \
ca34d7a7 101 { \
bd355af0 102 r2_size = r_addr + r_size - r2_addr; \
ca34d7a7
UD
103 elf_dynamic_do_##reloc ((map), r2_addr, r2_size, 0); \
104 } \
105 r_size = p_addr - r_addr; \
106 } \
107 } \
108 \
109 elf_dynamic_do_##reloc ((map), r_addr, r_size, 0); \
110 if (p_addr) \
111 elf_dynamic_do_##reloc ((map), p_addr, p_size, (lazy)); \
112 } \
113 else if ((map)->l_info[DT_PLTREL] && \
114 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC) \
115 { \
116 p_addr = (map)->l_info[DT_JMPREL]->d_un.d_ptr; \
117 p_size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \
118 \
119 elf_dynamic_do_##reloc ((map), p_addr, p_size, (lazy)); \
120 } \
121 } while (0)
122#else
123#define _ELF_DYNAMIC_DO_RELOC(RELOC, reloc, map, lazy) \
124 do { \
125 if ((map)->l_info[DT_##RELOC]) \
126 { \
127 ElfW(Addr) r_addr, r_size; \
128 r_addr = (map)->l_info[DT_##RELOC]->d_un.d_ptr; \
129 r_size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val; \
130 elf_dynamic_do_##reloc ((map), r_addr, r_size, 0); \
131 } \
132 if ((map)->l_info[DT_PLTREL] && \
133 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC) \
134 { \
135 ElfW(Addr) p_addr, p_size; \
136 p_addr = (map)->l_info[DT_JMPREL]->d_un.d_ptr; \
137 p_size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \
138 elf_dynamic_do_##reloc ((map), p_addr, p_size, (lazy)); \
139 } \
140 } while (0)
141#endif
142
421f82e5
RM
143#if ! ELF_MACHINE_NO_REL
144#include "do-rel.h"
ca34d7a7
UD
145#define ELF_DYNAMIC_DO_REL(map, lazy) \
146 _ELF_DYNAMIC_DO_RELOC (REL, rel, map, lazy)
421f82e5 147#else
f51d1dfd 148#define ELF_DYNAMIC_DO_REL(map, lazy) /* Nothing to do. */
421f82e5
RM
149#endif
150
151#if ! ELF_MACHINE_NO_RELA
152#define DO_RELA
153#include "do-rel.h"
ca34d7a7
UD
154#define ELF_DYNAMIC_DO_RELA(map, lazy) \
155 _ELF_DYNAMIC_DO_RELOC (RELA, rela, map, lazy)
421f82e5 156#else
f51d1dfd 157#define ELF_DYNAMIC_DO_RELA(map, lazy) /* Nothing to do. */
421f82e5
RM
158#endif
159
160/* This can't just be an inline function because GCC is too dumb
161 to inline functions containing inlines themselves. */
3996f34b
UD
162#define ELF_DYNAMIC_RELOCATE(map, lazy, consider_profile) \
163 do { \
164 int profile = (consider_profile && _dl_profile != NULL \
165 && _dl_name_match_p (_dl_profile, (map))); \
166 int edr_lazy = elf_machine_runtime_setup ((map), (lazy) || profile, \
167 profile); \
168 ELF_DYNAMIC_DO_REL ((map), edr_lazy); \
169 ELF_DYNAMIC_DO_RELA ((map), edr_lazy); \
0501d603 170 } while (0)
f51d1dfd
RM
171
172#endif
This page took 0.895372 seconds and 5 git commands to generate.