1 /* Read the dynamic section at DYN and fill in INFO with indices DT_*.
2 Copyright (C) 2012-2017 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 is included multiple times and therefore lacks a header
20 file inclusion guard. */
23 #include <libc-diag.h>
30 inline void __attribute__ ((unused
, always_inline
))
31 elf_get_dynamic_info (struct link_map
*l
, ElfW(Dyn
) *temp
)
33 ElfW(Dyn
) *dyn
= l
->l_ld
;
35 #if __ELF_NATIVE_CLASS == 32
36 typedef Elf32_Word d_tag_utype
;
37 #elif __ELF_NATIVE_CLASS == 64
38 typedef Elf64_Xword d_tag_utype
;
41 #ifndef RTLD_BOOTSTRAP
48 while (dyn
->d_tag
!= DT_NULL
)
50 if ((d_tag_utype
) dyn
->d_tag
< DT_NUM
)
51 info
[dyn
->d_tag
] = dyn
;
52 else if (dyn
->d_tag
>= DT_LOPROC
&&
53 dyn
->d_tag
< DT_LOPROC
+ DT_THISPROCNUM
)
55 /* This does not violate the array bounds of l->l_info, but
56 gcc 4.6 on sparc somehow does not see this. */
57 DIAG_PUSH_NEEDS_COMMENT
;
58 DIAG_IGNORE_NEEDS_COMMENT (4.6,
60 info
[dyn
->d_tag
- DT_LOPROC
+ DT_NUM
] = dyn
;
61 DIAG_POP_NEEDS_COMMENT
;
63 else if ((d_tag_utype
) DT_VERSIONTAGIDX (dyn
->d_tag
) < DT_VERSIONTAGNUM
)
64 info
[VERSYMIDX (dyn
->d_tag
)] = dyn
;
65 else if ((d_tag_utype
) DT_EXTRATAGIDX (dyn
->d_tag
) < DT_EXTRANUM
)
66 info
[DT_EXTRATAGIDX (dyn
->d_tag
) + DT_NUM
+ DT_THISPROCNUM
67 + DT_VERSIONTAGNUM
] = dyn
;
68 else if ((d_tag_utype
) DT_VALTAGIDX (dyn
->d_tag
) < DT_VALNUM
)
69 info
[DT_VALTAGIDX (dyn
->d_tag
) + DT_NUM
+ DT_THISPROCNUM
70 + DT_VERSIONTAGNUM
+ DT_EXTRANUM
] = dyn
;
71 else if ((d_tag_utype
) DT_ADDRTAGIDX (dyn
->d_tag
) < DT_ADDRNUM
)
72 info
[DT_ADDRTAGIDX (dyn
->d_tag
) + DT_NUM
+ DT_THISPROCNUM
73 + DT_VERSIONTAGNUM
+ DT_EXTRANUM
+ DT_VALNUM
] = dyn
;
77 #define DL_RO_DYN_TEMP_CNT 8
79 #ifndef DL_RO_DYN_SECTION
80 /* Don't adjust .dynamic unnecessarily. */
83 ElfW(Addr
) l_addr
= l
->l_addr
;
86 # define ADJUST_DYN_INFO(tag) \
88 if (info[tag] != NULL) \
92 temp[cnt].d_tag = info[tag]->d_tag; \
93 temp[cnt].d_un.d_ptr = info[tag]->d_un.d_ptr + l_addr; \
94 info[tag] = temp + cnt++; \
97 info[tag]->d_un.d_ptr += l_addr; \
101 ADJUST_DYN_INFO (DT_HASH
);
102 ADJUST_DYN_INFO (DT_PLTGOT
);
103 ADJUST_DYN_INFO (DT_STRTAB
);
104 ADJUST_DYN_INFO (DT_SYMTAB
);
105 # if ! ELF_MACHINE_NO_RELA
106 ADJUST_DYN_INFO (DT_RELA
);
108 # if ! ELF_MACHINE_NO_REL
109 ADJUST_DYN_INFO (DT_REL
);
111 ADJUST_DYN_INFO (DT_JMPREL
);
112 ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM
));
113 ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH
) + DT_NUM
+ DT_THISPROCNUM
114 + DT_VERSIONTAGNUM
+ DT_EXTRANUM
+ DT_VALNUM
);
115 # undef ADJUST_DYN_INFO
116 assert (cnt
<= DL_RO_DYN_TEMP_CNT
);
119 if (info
[DT_PLTREL
] != NULL
)
121 #if ELF_MACHINE_NO_RELA
122 assert (info
[DT_PLTREL
]->d_un
.d_val
== DT_REL
);
123 #elif ELF_MACHINE_NO_REL
124 assert (info
[DT_PLTREL
]->d_un
.d_val
== DT_RELA
);
126 assert (info
[DT_PLTREL
]->d_un
.d_val
== DT_REL
127 || info
[DT_PLTREL
]->d_un
.d_val
== DT_RELA
);
130 #if ! ELF_MACHINE_NO_RELA
131 if (info
[DT_RELA
] != NULL
)
132 assert (info
[DT_RELAENT
]->d_un
.d_val
== sizeof (ElfW(Rela
)));
134 # if ! ELF_MACHINE_NO_REL
135 if (info
[DT_REL
] != NULL
)
136 assert (info
[DT_RELENT
]->d_un
.d_val
== sizeof (ElfW(Rel
)));
138 #ifdef RTLD_BOOTSTRAP
139 /* Only the bind now flags are allowed. */
140 assert (info
[VERSYMIDX (DT_FLAGS_1
)] == NULL
141 || (info
[VERSYMIDX (DT_FLAGS_1
)]->d_un
.d_val
& ~DF_1_NOW
) == 0);
142 assert (info
[DT_FLAGS
] == NULL
143 || (info
[DT_FLAGS
]->d_un
.d_val
& ~DF_BIND_NOW
) == 0);
144 /* Flags must not be set for ld.so. */
145 assert (info
[DT_RUNPATH
] == NULL
);
146 assert (info
[DT_RPATH
] == NULL
);
148 if (info
[DT_FLAGS
] != NULL
)
150 /* Flags are used. Translate to the old form where available.
151 Since these l_info entries are only tested for NULL pointers it
152 is ok if they point to the DT_FLAGS entry. */
153 l
->l_flags
= info
[DT_FLAGS
]->d_un
.d_val
;
155 if (l
->l_flags
& DF_SYMBOLIC
)
156 info
[DT_SYMBOLIC
] = info
[DT_FLAGS
];
157 if (l
->l_flags
& DF_TEXTREL
)
158 info
[DT_TEXTREL
] = info
[DT_FLAGS
];
159 if (l
->l_flags
& DF_BIND_NOW
)
160 info
[DT_BIND_NOW
] = info
[DT_FLAGS
];
162 if (info
[VERSYMIDX (DT_FLAGS_1
)] != NULL
)
164 l
->l_flags_1
= info
[VERSYMIDX (DT_FLAGS_1
)]->d_un
.d_val
;
166 /* Only DT_1_SUPPORTED_MASK bits are supported, and we would like
167 to assert this, but we can't. Users have been setting
168 unsupported DF_1_* flags for a long time and glibc has ignored
169 them. Therefore to avoid breaking existing applications the
170 best we can do is add a warning during debugging with the
171 intent of notifying the user of the problem. */
172 if (__builtin_expect (GLRO(dl_debug_mask
) & DL_DEBUG_FILES
, 0)
173 && l
->l_flags_1
& ~DT_1_SUPPORTED_MASK
)
174 _dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x in DT_FLAGS_1.\n",
175 l
->l_flags_1
& ~DT_1_SUPPORTED_MASK
);
177 if (l
->l_flags_1
& DF_1_NOW
)
178 info
[DT_BIND_NOW
] = info
[VERSYMIDX (DT_FLAGS_1
)];
180 if (info
[DT_RUNPATH
] != NULL
)
181 /* If both RUNPATH and RPATH are given, the latter is ignored. */
182 info
[DT_RPATH
] = NULL
;