]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/dynamic-link.h
Update.
[thirdparty/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");
a2e1b046 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
78#if ! ELF_MACHINE_NO_REL
79#include "do-rel.h"
f51d1dfd 80#define ELF_DYNAMIC_DO_REL(map, lazy) \
421f82e5 81 if ((map)->l_info[DT_REL]) \
f51d1dfd 82 elf_dynamic_do_rel ((map), DT_REL, DT_RELSZ, 0); \
a2e1b046
RM
83 if ((map)->l_info[DT_PLTREL] && \
84 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_REL) \
f51d1dfd 85 elf_dynamic_do_rel ((map), DT_JMPREL, DT_PLTRELSZ, (lazy));
421f82e5 86#else
f51d1dfd 87#define ELF_DYNAMIC_DO_REL(map, lazy) /* Nothing to do. */
421f82e5
RM
88#endif
89
90#if ! ELF_MACHINE_NO_RELA
91#define DO_RELA
92#include "do-rel.h"
f51d1dfd 93#define ELF_DYNAMIC_DO_RELA(map, lazy) \
421f82e5 94 if ((map)->l_info[DT_RELA]) \
f51d1dfd 95 elf_dynamic_do_rela ((map), DT_RELA, DT_RELASZ, 0); \
a2e1b046
RM
96 if ((map)->l_info[DT_PLTREL] && \
97 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_RELA) \
f51d1dfd 98 elf_dynamic_do_rela ((map), DT_JMPREL, DT_PLTRELSZ, (lazy));
421f82e5 99#else
f51d1dfd 100#define ELF_DYNAMIC_DO_RELA(map, lazy) /* Nothing to do. */
421f82e5
RM
101#endif
102
103/* This can't just be an inline function because GCC is too dumb
104 to inline functions containing inlines themselves. */
0501d603
UD
105#define ELF_DYNAMIC_RELOCATE(map, lazy) \
106 do { \
107 int edr_lazy = elf_machine_runtime_setup((map), (lazy)); \
108 ELF_DYNAMIC_DO_REL ((map), edr_lazy); \
109 ELF_DYNAMIC_DO_RELA ((map), edr_lazy); \
110 } while (0)
f51d1dfd
RM
111
112#endif