update from main archive 970124
[glibc.git] / elf / dynamic-link.h
blobc613f824d8ebac7aab95e34d51d74f2fff88241a
1 /* Inline functions for dynamic linking.
2 Copyright (C) 1995, 1996, 1997 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 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.
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.
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. */
20 #include <elf.h>
21 #include <dl-machine.h>
22 #include <assert.h>
25 /* Read the dynamic section at DYN and fill in INFO with indices DT_*. */
27 static inline void __attribute__ ((unused))
28 elf_get_dynamic_info (ElfW(Dyn) *dyn,
29 ElfW(Dyn) *info[DT_NUM + DT_PROCNUM + DT_EXTRANUM])
31 unsigned int i;
33 for (i = 0; i < DT_NUM + DT_PROCNUM + DT_EXTRANUM; ++i)
34 info[i] = NULL;
36 if (! dyn)
37 return;
39 while (dyn->d_tag != DT_NULL)
41 if (dyn->d_tag < DT_NUM)
42 info[dyn->d_tag] = dyn;
43 else if (dyn->d_tag >= DT_LOPROC &&
44 dyn->d_tag < DT_LOPROC + DT_PROCNUM)
45 info[dyn->d_tag - DT_LOPROC + DT_NUM] = dyn;
46 else if ((Elf32_Word) DT_EXTRATAGIDX (dyn->d_tag) < DT_EXTRANUM)
47 info[DT_EXTRATAGIDX (dyn->d_tag) + DT_NUM + DT_PROCNUM] = dyn;
48 else
49 assert (! "bad dynamic tag");
50 dyn++;
53 if (info[DT_RELA])
54 assert (info[DT_RELAENT]->d_un.d_val == sizeof (ElfW(Rela)));
55 if (info[DT_REL])
56 assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
57 if (info[DT_PLTREL])
58 assert (info[DT_PLTREL]->d_un.d_val == DT_REL ||
59 info[DT_PLTREL]->d_un.d_val == DT_RELA);
62 #ifdef RESOLVE
64 /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.
65 These functions are almost identical, so we use cpp magic to avoid
66 duplicating their code. It cannot be done in a more general function
67 because we must be able to completely inline. */
69 #if ! ELF_MACHINE_NO_REL
70 #include "do-rel.h"
71 #define ELF_DYNAMIC_DO_REL(map, lazy) \
72 if ((map)->l_info[DT_REL]) \
73 elf_dynamic_do_rel ((map), DT_REL, DT_RELSZ, 0); \
74 if ((map)->l_info[DT_PLTREL] && \
75 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_REL) \
76 elf_dynamic_do_rel ((map), DT_JMPREL, DT_PLTRELSZ, (lazy));
77 #else
78 #define ELF_DYNAMIC_DO_REL(map, lazy) /* Nothing to do. */
79 #endif
81 #if ! ELF_MACHINE_NO_RELA
82 #define DO_RELA
83 #include "do-rel.h"
84 #define ELF_DYNAMIC_DO_RELA(map, lazy) \
85 if ((map)->l_info[DT_RELA]) \
86 elf_dynamic_do_rela ((map), DT_RELA, DT_RELASZ, 0); \
87 if ((map)->l_info[DT_PLTREL] && \
88 (map)->l_info[DT_PLTREL]->d_un.d_val == DT_RELA) \
89 elf_dynamic_do_rela ((map), DT_JMPREL, DT_PLTRELSZ, (lazy));
90 #else
91 #define ELF_DYNAMIC_DO_RELA(map, lazy) /* Nothing to do. */
92 #endif
94 /* This can't just be an inline function because GCC is too dumb
95 to inline functions containing inlines themselves. */
96 #define ELF_DYNAMIC_RELOCATE(map, lazy) \
97 do { ELF_DYNAMIC_DO_REL ((map), (lazy)); \
98 ELF_DYNAMIC_DO_RELA ((map), (lazy)); } while (0)
100 #endif