1 /* Read the dynamic section at DYN and fill in INFO with indices DT_*.
2 Copyright (C) 2012 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/>. */
26 inline void __attribute__ ((unused
, always_inline
))
27 elf_get_dynamic_info (struct link_map
*l
, ElfW(Dyn
) *temp
)
29 ElfW(Dyn
) *dyn
= l
->l_ld
;
31 #if __ELF_NATIVE_CLASS == 32
32 typedef Elf32_Word d_tag_utype
;
33 #elif __ELF_NATIVE_CLASS == 64
34 typedef Elf64_Xword d_tag_utype
;
37 #ifndef RTLD_BOOTSTRAP
44 while (dyn
->d_tag
!= DT_NULL
)
46 if ((d_tag_utype
) dyn
->d_tag
< DT_NUM
)
47 info
[dyn
->d_tag
] = dyn
;
48 else if (dyn
->d_tag
>= DT_LOPROC
&&
49 dyn
->d_tag
< DT_LOPROC
+ DT_THISPROCNUM
)
50 info
[dyn
->d_tag
- DT_LOPROC
+ DT_NUM
] = dyn
;
51 else if ((d_tag_utype
) DT_VERSIONTAGIDX (dyn
->d_tag
) < DT_VERSIONTAGNUM
)
52 info
[VERSYMIDX (dyn
->d_tag
)] = dyn
;
53 else if ((d_tag_utype
) DT_EXTRATAGIDX (dyn
->d_tag
) < DT_EXTRANUM
)
54 info
[DT_EXTRATAGIDX (dyn
->d_tag
) + DT_NUM
+ DT_THISPROCNUM
55 + DT_VERSIONTAGNUM
] = dyn
;
56 else if ((d_tag_utype
) DT_VALTAGIDX (dyn
->d_tag
) < DT_VALNUM
)
57 info
[DT_VALTAGIDX (dyn
->d_tag
) + DT_NUM
+ DT_THISPROCNUM
58 + DT_VERSIONTAGNUM
+ DT_EXTRANUM
] = dyn
;
59 else if ((d_tag_utype
) DT_ADDRTAGIDX (dyn
->d_tag
) < DT_ADDRNUM
)
60 info
[DT_ADDRTAGIDX (dyn
->d_tag
) + DT_NUM
+ DT_THISPROCNUM
61 + DT_VERSIONTAGNUM
+ DT_EXTRANUM
+ DT_VALNUM
] = dyn
;
65 #define DL_RO_DYN_TEMP_CNT 8
67 #ifndef DL_RO_DYN_SECTION
68 /* Don't adjust .dynamic unnecessarily. */
71 ElfW(Addr
) l_addr
= l
->l_addr
;
74 # define ADJUST_DYN_INFO(tag) \
76 if (info[tag] != NULL) \
80 temp[cnt].d_tag = info[tag]->d_tag; \
81 temp[cnt].d_un.d_ptr = info[tag]->d_un.d_ptr + l_addr; \
82 info[tag] = temp + cnt++; \
85 info[tag]->d_un.d_ptr += l_addr; \
89 ADJUST_DYN_INFO (DT_HASH
);
90 ADJUST_DYN_INFO (DT_PLTGOT
);
91 ADJUST_DYN_INFO (DT_STRTAB
);
92 ADJUST_DYN_INFO (DT_SYMTAB
);
93 # if ! ELF_MACHINE_NO_RELA
94 ADJUST_DYN_INFO (DT_RELA
);
96 # if ! ELF_MACHINE_NO_REL
97 ADJUST_DYN_INFO (DT_REL
);
99 ADJUST_DYN_INFO (DT_JMPREL
);
100 ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM
));
101 ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH
) + DT_NUM
+ DT_THISPROCNUM
102 + DT_VERSIONTAGNUM
+ DT_EXTRANUM
+ DT_VALNUM
);
103 # undef ADJUST_DYN_INFO
104 assert (cnt
<= DL_RO_DYN_TEMP_CNT
);
107 if (info
[DT_PLTREL
] != NULL
)
109 #if ELF_MACHINE_NO_RELA
110 assert (info
[DT_PLTREL
]->d_un
.d_val
== DT_REL
);
111 #elif ELF_MACHINE_NO_REL
112 assert (info
[DT_PLTREL
]->d_un
.d_val
== DT_RELA
);
114 assert (info
[DT_PLTREL
]->d_un
.d_val
== DT_REL
115 || info
[DT_PLTREL
]->d_un
.d_val
== DT_RELA
);
118 #if ! ELF_MACHINE_NO_RELA
119 if (info
[DT_RELA
] != NULL
)
120 assert (info
[DT_RELAENT
]->d_un
.d_val
== sizeof (ElfW(Rela
)));
122 # if ! ELF_MACHINE_NO_REL
123 if (info
[DT_REL
] != NULL
)
124 assert (info
[DT_RELENT
]->d_un
.d_val
== sizeof (ElfW(Rel
)));
126 #ifdef RTLD_BOOTSTRAP
127 /* Only the bind now flags are allowed. */
128 assert (info
[VERSYMIDX (DT_FLAGS_1
)] == NULL
129 || (info
[VERSYMIDX (DT_FLAGS_1
)]->d_un
.d_val
& ~DF_1_NOW
) == 0);
130 assert (info
[DT_FLAGS
] == NULL
131 || (info
[DT_FLAGS
]->d_un
.d_val
& ~DF_BIND_NOW
) == 0);
132 /* Flags must not be set for ld.so. */
133 assert (info
[DT_RUNPATH
] == NULL
);
134 assert (info
[DT_RPATH
] == NULL
);
136 if (info
[DT_FLAGS
] != NULL
)
138 /* Flags are used. Translate to the old form where available.
139 Since these l_info entries are only tested for NULL pointers it
140 is ok if they point to the DT_FLAGS entry. */
141 l
->l_flags
= info
[DT_FLAGS
]->d_un
.d_val
;
143 if (l
->l_flags
& DF_SYMBOLIC
)
144 info
[DT_SYMBOLIC
] = info
[DT_FLAGS
];
145 if (l
->l_flags
& DF_TEXTREL
)
146 info
[DT_TEXTREL
] = info
[DT_FLAGS
];
147 if (l
->l_flags
& DF_BIND_NOW
)
148 info
[DT_BIND_NOW
] = info
[DT_FLAGS
];
150 if (info
[VERSYMIDX (DT_FLAGS_1
)] != NULL
)
152 l
->l_flags_1
= info
[VERSYMIDX (DT_FLAGS_1
)]->d_un
.d_val
;
154 /* Only DT_1_SUPPORTED_MASK bits are allowed. */
155 assert ((l
->l_flags_1
& ~DT_1_SUPPORTED_MASK
) == 0);
157 if (l
->l_flags_1
& DF_1_NOW
)
158 info
[DT_BIND_NOW
] = info
[VERSYMIDX (DT_FLAGS_1
)];
160 if (info
[DT_RUNPATH
] != NULL
)
161 /* If both RUNPATH and RPATH are given, the latter is ignored. */
162 info
[DT_RPATH
] = NULL
;