File: | src/gnu/usr.bin/binutils-2.17/bfd/elf.c |
Warning: | line 4892, column 12 Access to field 'size' results in a dereference of a null pointer (loaded from field 'bfd_section') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* ELF executable support for BFD. | |||
2 | ||||
3 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, | |||
4 | 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. | |||
5 | ||||
6 | This file is part of BFD, the Binary File Descriptor library. | |||
7 | ||||
8 | This program is free software; you can redistribute it and/or modify | |||
9 | it under the terms of the GNU General Public License as published by | |||
10 | the Free Software Foundation; either version 2 of the License, or | |||
11 | (at your option) any later version. | |||
12 | ||||
13 | This program is distributed in the hope that it will be useful, | |||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
16 | GNU General Public License for more details. | |||
17 | ||||
18 | You should have received a copy of the GNU General Public License | |||
19 | along with this program; if not, write to the Free Software | |||
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ | |||
21 | ||||
22 | /* | |||
23 | SECTION | |||
24 | ELF backends | |||
25 | ||||
26 | BFD support for ELF formats is being worked on. | |||
27 | Currently, the best supported back ends are for sparc and i386 | |||
28 | (running svr4 or Solaris 2). | |||
29 | ||||
30 | Documentation of the internals of the support code still needs | |||
31 | to be written. The code is changing quickly enough that we | |||
32 | haven't bothered yet. */ | |||
33 | ||||
34 | /* For sparc64-cross-sparc32. */ | |||
35 | #define _SYSCALL32 | |||
36 | #include "bfd.h" | |||
37 | #include "sysdep.h" | |||
38 | #include "bfdlink.h" | |||
39 | #include "libbfd.h" | |||
40 | #define ARCH_SIZE0 0 | |||
41 | #include "elf-bfd.h" | |||
42 | #include "libiberty.h" | |||
43 | ||||
44 | static int elf_sort_sections (const void *, const void *); | |||
45 | static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *); | |||
46 | static bfd_boolean prep_headers (bfd *); | |||
47 | static bfd_boolean swap_out_syms (bfd *, struct bfd_strtab_hash **, int) ; | |||
48 | static bfd_boolean elfcore_read_notes (bfd *, file_ptr, bfd_size_type) ; | |||
49 | ||||
50 | /* Swap version information in and out. The version information is | |||
51 | currently size independent. If that ever changes, this code will | |||
52 | need to move into elfcode.h. */ | |||
53 | ||||
54 | /* Swap in a Verdef structure. */ | |||
55 | ||||
56 | void | |||
57 | _bfd_elf_swap_verdef_in (bfd *abfd, | |||
58 | const Elf_External_Verdef *src, | |||
59 | Elf_Internal_Verdef *dst) | |||
60 | { | |||
61 | dst->vd_version = H_GET_16 (abfd, src->vd_version)((*((abfd)->xvec->bfd_h_getx16)) (src->vd_version)); | |||
62 | dst->vd_flags = H_GET_16 (abfd, src->vd_flags)((*((abfd)->xvec->bfd_h_getx16)) (src->vd_flags)); | |||
63 | dst->vd_ndx = H_GET_16 (abfd, src->vd_ndx)((*((abfd)->xvec->bfd_h_getx16)) (src->vd_ndx)); | |||
64 | dst->vd_cnt = H_GET_16 (abfd, src->vd_cnt)((*((abfd)->xvec->bfd_h_getx16)) (src->vd_cnt)); | |||
65 | dst->vd_hash = H_GET_32 (abfd, src->vd_hash)((*((abfd)->xvec->bfd_h_getx32)) (src->vd_hash)); | |||
66 | dst->vd_aux = H_GET_32 (abfd, src->vd_aux)((*((abfd)->xvec->bfd_h_getx32)) (src->vd_aux)); | |||
67 | dst->vd_next = H_GET_32 (abfd, src->vd_next)((*((abfd)->xvec->bfd_h_getx32)) (src->vd_next)); | |||
68 | } | |||
69 | ||||
70 | /* Swap out a Verdef structure. */ | |||
71 | ||||
72 | void | |||
73 | _bfd_elf_swap_verdef_out (bfd *abfd, | |||
74 | const Elf_Internal_Verdef *src, | |||
75 | Elf_External_Verdef *dst) | |||
76 | { | |||
77 | H_PUT_16 (abfd, src->vd_version, dst->vd_version)((*((abfd)->xvec->bfd_h_putx16)) (src->vd_version, dst ->vd_version)); | |||
78 | H_PUT_16 (abfd, src->vd_flags, dst->vd_flags)((*((abfd)->xvec->bfd_h_putx16)) (src->vd_flags, dst ->vd_flags)); | |||
79 | H_PUT_16 (abfd, src->vd_ndx, dst->vd_ndx)((*((abfd)->xvec->bfd_h_putx16)) (src->vd_ndx, dst-> vd_ndx)); | |||
80 | H_PUT_16 (abfd, src->vd_cnt, dst->vd_cnt)((*((abfd)->xvec->bfd_h_putx16)) (src->vd_cnt, dst-> vd_cnt)); | |||
81 | H_PUT_32 (abfd, src->vd_hash, dst->vd_hash)((*((abfd)->xvec->bfd_h_putx32)) (src->vd_hash, dst-> vd_hash)); | |||
82 | H_PUT_32 (abfd, src->vd_aux, dst->vd_aux)((*((abfd)->xvec->bfd_h_putx32)) (src->vd_aux, dst-> vd_aux)); | |||
83 | H_PUT_32 (abfd, src->vd_next, dst->vd_next)((*((abfd)->xvec->bfd_h_putx32)) (src->vd_next, dst-> vd_next)); | |||
84 | } | |||
85 | ||||
86 | /* Swap in a Verdaux structure. */ | |||
87 | ||||
88 | void | |||
89 | _bfd_elf_swap_verdaux_in (bfd *abfd, | |||
90 | const Elf_External_Verdaux *src, | |||
91 | Elf_Internal_Verdaux *dst) | |||
92 | { | |||
93 | dst->vda_name = H_GET_32 (abfd, src->vda_name)((*((abfd)->xvec->bfd_h_getx32)) (src->vda_name)); | |||
94 | dst->vda_next = H_GET_32 (abfd, src->vda_next)((*((abfd)->xvec->bfd_h_getx32)) (src->vda_next)); | |||
95 | } | |||
96 | ||||
97 | /* Swap out a Verdaux structure. */ | |||
98 | ||||
99 | void | |||
100 | _bfd_elf_swap_verdaux_out (bfd *abfd, | |||
101 | const Elf_Internal_Verdaux *src, | |||
102 | Elf_External_Verdaux *dst) | |||
103 | { | |||
104 | H_PUT_32 (abfd, src->vda_name, dst->vda_name)((*((abfd)->xvec->bfd_h_putx32)) (src->vda_name, dst ->vda_name)); | |||
105 | H_PUT_32 (abfd, src->vda_next, dst->vda_next)((*((abfd)->xvec->bfd_h_putx32)) (src->vda_next, dst ->vda_next)); | |||
106 | } | |||
107 | ||||
108 | /* Swap in a Verneed structure. */ | |||
109 | ||||
110 | void | |||
111 | _bfd_elf_swap_verneed_in (bfd *abfd, | |||
112 | const Elf_External_Verneed *src, | |||
113 | Elf_Internal_Verneed *dst) | |||
114 | { | |||
115 | dst->vn_version = H_GET_16 (abfd, src->vn_version)((*((abfd)->xvec->bfd_h_getx16)) (src->vn_version)); | |||
116 | dst->vn_cnt = H_GET_16 (abfd, src->vn_cnt)((*((abfd)->xvec->bfd_h_getx16)) (src->vn_cnt)); | |||
117 | dst->vn_file = H_GET_32 (abfd, src->vn_file)((*((abfd)->xvec->bfd_h_getx32)) (src->vn_file)); | |||
118 | dst->vn_aux = H_GET_32 (abfd, src->vn_aux)((*((abfd)->xvec->bfd_h_getx32)) (src->vn_aux)); | |||
119 | dst->vn_next = H_GET_32 (abfd, src->vn_next)((*((abfd)->xvec->bfd_h_getx32)) (src->vn_next)); | |||
120 | } | |||
121 | ||||
122 | /* Swap out a Verneed structure. */ | |||
123 | ||||
124 | void | |||
125 | _bfd_elf_swap_verneed_out (bfd *abfd, | |||
126 | const Elf_Internal_Verneed *src, | |||
127 | Elf_External_Verneed *dst) | |||
128 | { | |||
129 | H_PUT_16 (abfd, src->vn_version, dst->vn_version)((*((abfd)->xvec->bfd_h_putx16)) (src->vn_version, dst ->vn_version)); | |||
130 | H_PUT_16 (abfd, src->vn_cnt, dst->vn_cnt)((*((abfd)->xvec->bfd_h_putx16)) (src->vn_cnt, dst-> vn_cnt)); | |||
131 | H_PUT_32 (abfd, src->vn_file, dst->vn_file)((*((abfd)->xvec->bfd_h_putx32)) (src->vn_file, dst-> vn_file)); | |||
132 | H_PUT_32 (abfd, src->vn_aux, dst->vn_aux)((*((abfd)->xvec->bfd_h_putx32)) (src->vn_aux, dst-> vn_aux)); | |||
133 | H_PUT_32 (abfd, src->vn_next, dst->vn_next)((*((abfd)->xvec->bfd_h_putx32)) (src->vn_next, dst-> vn_next)); | |||
134 | } | |||
135 | ||||
136 | /* Swap in a Vernaux structure. */ | |||
137 | ||||
138 | void | |||
139 | _bfd_elf_swap_vernaux_in (bfd *abfd, | |||
140 | const Elf_External_Vernaux *src, | |||
141 | Elf_Internal_Vernaux *dst) | |||
142 | { | |||
143 | dst->vna_hash = H_GET_32 (abfd, src->vna_hash)((*((abfd)->xvec->bfd_h_getx32)) (src->vna_hash)); | |||
144 | dst->vna_flags = H_GET_16 (abfd, src->vna_flags)((*((abfd)->xvec->bfd_h_getx16)) (src->vna_flags)); | |||
145 | dst->vna_other = H_GET_16 (abfd, src->vna_other)((*((abfd)->xvec->bfd_h_getx16)) (src->vna_other)); | |||
146 | dst->vna_name = H_GET_32 (abfd, src->vna_name)((*((abfd)->xvec->bfd_h_getx32)) (src->vna_name)); | |||
147 | dst->vna_next = H_GET_32 (abfd, src->vna_next)((*((abfd)->xvec->bfd_h_getx32)) (src->vna_next)); | |||
148 | } | |||
149 | ||||
150 | /* Swap out a Vernaux structure. */ | |||
151 | ||||
152 | void | |||
153 | _bfd_elf_swap_vernaux_out (bfd *abfd, | |||
154 | const Elf_Internal_Vernaux *src, | |||
155 | Elf_External_Vernaux *dst) | |||
156 | { | |||
157 | H_PUT_32 (abfd, src->vna_hash, dst->vna_hash)((*((abfd)->xvec->bfd_h_putx32)) (src->vna_hash, dst ->vna_hash)); | |||
158 | H_PUT_16 (abfd, src->vna_flags, dst->vna_flags)((*((abfd)->xvec->bfd_h_putx16)) (src->vna_flags, dst ->vna_flags)); | |||
159 | H_PUT_16 (abfd, src->vna_other, dst->vna_other)((*((abfd)->xvec->bfd_h_putx16)) (src->vna_other, dst ->vna_other)); | |||
160 | H_PUT_32 (abfd, src->vna_name, dst->vna_name)((*((abfd)->xvec->bfd_h_putx32)) (src->vna_name, dst ->vna_name)); | |||
161 | H_PUT_32 (abfd, src->vna_next, dst->vna_next)((*((abfd)->xvec->bfd_h_putx32)) (src->vna_next, dst ->vna_next)); | |||
162 | } | |||
163 | ||||
164 | /* Swap in a Versym structure. */ | |||
165 | ||||
166 | void | |||
167 | _bfd_elf_swap_versym_in (bfd *abfd, | |||
168 | const Elf_External_Versym *src, | |||
169 | Elf_Internal_Versym *dst) | |||
170 | { | |||
171 | dst->vs_vers = H_GET_16 (abfd, src->vs_vers)((*((abfd)->xvec->bfd_h_getx16)) (src->vs_vers)); | |||
172 | } | |||
173 | ||||
174 | /* Swap out a Versym structure. */ | |||
175 | ||||
176 | void | |||
177 | _bfd_elf_swap_versym_out (bfd *abfd, | |||
178 | const Elf_Internal_Versym *src, | |||
179 | Elf_External_Versym *dst) | |||
180 | { | |||
181 | H_PUT_16 (abfd, src->vs_vers, dst->vs_vers)((*((abfd)->xvec->bfd_h_putx16)) (src->vs_vers, dst-> vs_vers)); | |||
182 | } | |||
183 | ||||
184 | /* Standard ELF hash function. Do not change this function; you will | |||
185 | cause invalid hash tables to be generated. */ | |||
186 | ||||
187 | unsigned long | |||
188 | bfd_elf_hash (const char *namearg) | |||
189 | { | |||
190 | const unsigned char *name = (const unsigned char *) namearg; | |||
191 | unsigned long h = 0; | |||
192 | unsigned long g; | |||
193 | int ch; | |||
194 | ||||
195 | while ((ch = *name++) != '\0') | |||
196 | { | |||
197 | h = (h << 4) + ch; | |||
198 | if ((g = (h & 0xf0000000)) != 0) | |||
199 | { | |||
200 | h ^= g >> 24; | |||
201 | /* The ELF ABI says `h &= ~g', but this is equivalent in | |||
202 | this case and on some machines one insn instead of two. */ | |||
203 | h ^= g; | |||
204 | } | |||
205 | } | |||
206 | return h & 0xffffffff; | |||
207 | } | |||
208 | ||||
209 | /* DT_GNU_HASH hash function. Do not change this function; you will | |||
210 | cause invalid hash tables to be generated. */ | |||
211 | ||||
212 | unsigned long | |||
213 | bfd_elf_gnu_hash (const char *namearg) | |||
214 | { | |||
215 | const unsigned char *name = (const unsigned char *) namearg; | |||
216 | unsigned long h = 5381; | |||
217 | unsigned char ch; | |||
218 | ||||
219 | while ((ch = *name++) != '\0') | |||
220 | h = (h << 5) + h + ch; | |||
221 | return h & 0xffffffff; | |||
222 | } | |||
223 | ||||
224 | bfd_boolean | |||
225 | bfd_elf_mkobject (bfd *abfd) | |||
226 | { | |||
227 | /* This just does initialization. */ | |||
228 | /* coff_mkobject zalloc's space for tdata.coff_obj_data ... */ | |||
229 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data) = bfd_zalloc (abfd, sizeof (struct elf_obj_tdata)); | |||
230 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data) == 0) | |||
231 | return FALSE0; | |||
232 | /* Since everything is done at close time, do we need any | |||
233 | initialization? */ | |||
234 | ||||
235 | return TRUE1; | |||
236 | } | |||
237 | ||||
238 | bfd_boolean | |||
239 | bfd_elf_mkcorefile (bfd *abfd) | |||
240 | { | |||
241 | /* I think this can be done just like an object file. */ | |||
242 | return bfd_elf_mkobject (abfd); | |||
243 | } | |||
244 | ||||
245 | char * | |||
246 | bfd_elf_get_str_section (bfd *abfd, unsigned int shindex) | |||
247 | { | |||
248 | Elf_Internal_Shdr **i_shdrp; | |||
249 | bfd_byte *shstrtab = NULL((void*)0); | |||
250 | file_ptr offset; | |||
251 | bfd_size_type shstrtabsize; | |||
252 | ||||
253 | i_shdrp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr); | |||
254 | if (i_shdrp == 0 || i_shdrp[shindex] == 0) | |||
255 | return NULL((void*)0); | |||
256 | ||||
257 | shstrtab = i_shdrp[shindex]->contents; | |||
258 | if (shstrtab == NULL((void*)0)) | |||
259 | { | |||
260 | /* No cached one, attempt to read, and cache what we read. */ | |||
261 | offset = i_shdrp[shindex]->sh_offset; | |||
262 | shstrtabsize = i_shdrp[shindex]->sh_size; | |||
263 | ||||
264 | /* Allocate and clear an extra byte at the end, to prevent crashes | |||
265 | in case the string table is not terminated. */ | |||
266 | if (shstrtabsize + 1 == 0 | |||
267 | || (shstrtab = bfd_alloc (abfd, shstrtabsize + 1)) == NULL((void*)0) | |||
268 | || bfd_seek (abfd, offset, SEEK_SET0) != 0) | |||
269 | shstrtab = NULL((void*)0); | |||
270 | else if (bfd_bread (shstrtab, shstrtabsize, abfd) != shstrtabsize) | |||
271 | { | |||
272 | if (bfd_get_error () != bfd_error_system_call) | |||
273 | bfd_set_error (bfd_error_file_truncated); | |||
274 | shstrtab = NULL((void*)0); | |||
275 | } | |||
276 | else | |||
277 | shstrtab[shstrtabsize] = '\0'; | |||
278 | i_shdrp[shindex]->contents = shstrtab; | |||
279 | } | |||
280 | return (char *) shstrtab; | |||
281 | } | |||
282 | ||||
283 | char * | |||
284 | bfd_elf_string_from_elf_section (bfd *abfd, | |||
285 | unsigned int shindex, | |||
286 | unsigned int strindex) | |||
287 | { | |||
288 | Elf_Internal_Shdr *hdr; | |||
289 | ||||
290 | if (strindex == 0) | |||
291 | return ""; | |||
292 | ||||
293 | hdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex]; | |||
294 | ||||
295 | if (hdr->contents == NULL((void*)0) | |||
296 | && bfd_elf_get_str_section (abfd, shindex) == NULL((void*)0)) | |||
297 | return NULL((void*)0); | |||
298 | ||||
299 | if (strindex >= hdr->sh_size) | |||
300 | { | |||
301 | unsigned int shstrndx = elf_elfheader(abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shstrndx; | |||
302 | (*_bfd_error_handler) | |||
303 | (_("%B: invalid string offset %u >= %lu for section `%s'")("%B: invalid string offset %u >= %lu for section `%s'"), | |||
304 | abfd, strindex, (unsigned long) hdr->sh_size, | |||
305 | (shindex == shstrndx && strindex == hdr->sh_name | |||
306 | ? ".shstrtab" | |||
307 | : bfd_elf_string_from_elf_section (abfd, shstrndx, hdr->sh_name))); | |||
308 | return ""; | |||
309 | } | |||
310 | ||||
311 | return ((char *) hdr->contents) + strindex; | |||
312 | } | |||
313 | ||||
314 | /* Read and convert symbols to internal format. | |||
315 | SYMCOUNT specifies the number of symbols to read, starting from | |||
316 | symbol SYMOFFSET. If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF | |||
317 | are non-NULL, they are used to store the internal symbols, external | |||
318 | symbols, and symbol section index extensions, respectively. */ | |||
319 | ||||
320 | Elf_Internal_Sym * | |||
321 | bfd_elf_get_elf_syms (bfd *ibfd, | |||
322 | Elf_Internal_Shdr *symtab_hdr, | |||
323 | size_t symcount, | |||
324 | size_t symoffset, | |||
325 | Elf_Internal_Sym *intsym_buf, | |||
326 | void *extsym_buf, | |||
327 | Elf_External_Sym_Shndx *extshndx_buf) | |||
328 | { | |||
329 | Elf_Internal_Shdr *shndx_hdr; | |||
330 | void *alloc_ext; | |||
331 | const bfd_byte *esym; | |||
332 | Elf_External_Sym_Shndx *alloc_extshndx; | |||
333 | Elf_External_Sym_Shndx *shndx; | |||
334 | Elf_Internal_Sym *isym; | |||
335 | Elf_Internal_Sym *isymend; | |||
336 | const struct elf_backend_data *bed; | |||
337 | size_t extsym_size; | |||
338 | bfd_size_type amt; | |||
339 | file_ptr pos; | |||
340 | ||||
341 | if (symcount == 0) | |||
342 | return intsym_buf; | |||
343 | ||||
344 | /* Normal syms might have section extension entries. */ | |||
345 | shndx_hdr = NULL((void*)0); | |||
346 | if (symtab_hdr == &elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->symtab_hdr) | |||
347 | shndx_hdr = &elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->symtab_shndx_hdr; | |||
348 | ||||
349 | /* Read the symbols. */ | |||
350 | alloc_ext = NULL((void*)0); | |||
351 | alloc_extshndx = NULL((void*)0); | |||
352 | bed = get_elf_backend_data (ibfd)((const struct elf_backend_data *) (ibfd)->xvec->backend_data ); | |||
353 | extsym_size = bed->s->sizeof_sym; | |||
354 | amt = symcount * extsym_size; | |||
355 | pos = symtab_hdr->sh_offset + symoffset * extsym_size; | |||
356 | if (extsym_buf == NULL((void*)0)) | |||
357 | { | |||
358 | alloc_ext = bfd_malloc2 (symcount, extsym_size); | |||
359 | extsym_buf = alloc_ext; | |||
360 | } | |||
361 | if (extsym_buf == NULL((void*)0) | |||
362 | || bfd_seek (ibfd, pos, SEEK_SET0) != 0 | |||
363 | || bfd_bread (extsym_buf, amt, ibfd) != amt) | |||
364 | { | |||
365 | intsym_buf = NULL((void*)0); | |||
366 | goto out; | |||
367 | } | |||
368 | ||||
369 | if (shndx_hdr == NULL((void*)0) || shndx_hdr->sh_size == 0) | |||
370 | extshndx_buf = NULL((void*)0); | |||
371 | else | |||
372 | { | |||
373 | amt = symcount * sizeof (Elf_External_Sym_Shndx); | |||
374 | pos = shndx_hdr->sh_offset + symoffset * sizeof (Elf_External_Sym_Shndx); | |||
375 | if (extshndx_buf == NULL((void*)0)) | |||
376 | { | |||
377 | alloc_extshndx = bfd_malloc2 (symcount, | |||
378 | sizeof (Elf_External_Sym_Shndx)); | |||
379 | extshndx_buf = alloc_extshndx; | |||
380 | } | |||
381 | if (extshndx_buf == NULL((void*)0) | |||
382 | || bfd_seek (ibfd, pos, SEEK_SET0) != 0 | |||
383 | || bfd_bread (extshndx_buf, amt, ibfd) != amt) | |||
384 | { | |||
385 | intsym_buf = NULL((void*)0); | |||
386 | goto out; | |||
387 | } | |||
388 | } | |||
389 | ||||
390 | if (intsym_buf == NULL((void*)0)) | |||
391 | { | |||
392 | intsym_buf = bfd_malloc2 (symcount, sizeof (Elf_Internal_Sym)); | |||
393 | if (intsym_buf == NULL((void*)0)) | |||
394 | goto out; | |||
395 | } | |||
396 | ||||
397 | /* Convert the symbols to internal form. */ | |||
398 | isymend = intsym_buf + symcount; | |||
399 | for (esym = extsym_buf, isym = intsym_buf, shndx = extshndx_buf; | |||
400 | isym < isymend; | |||
401 | esym += extsym_size, isym++, shndx = shndx != NULL((void*)0) ? shndx + 1 : NULL((void*)0)) | |||
402 | (*bed->s->swap_symbol_in) (ibfd, esym, shndx, isym); | |||
403 | ||||
404 | out: | |||
405 | if (alloc_ext != NULL((void*)0)) | |||
406 | free (alloc_ext); | |||
407 | if (alloc_extshndx != NULL((void*)0)) | |||
408 | free (alloc_extshndx); | |||
409 | ||||
410 | return intsym_buf; | |||
411 | } | |||
412 | ||||
413 | /* Look up a symbol name. */ | |||
414 | const char * | |||
415 | bfd_elf_sym_name (bfd *abfd, | |||
416 | Elf_Internal_Shdr *symtab_hdr, | |||
417 | Elf_Internal_Sym *isym, | |||
418 | asection *sym_sec) | |||
419 | { | |||
420 | const char *name; | |||
421 | unsigned int iname = isym->st_name; | |||
422 | unsigned int shindex = symtab_hdr->sh_link; | |||
423 | ||||
424 | if (iname == 0 && ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF) == STT_SECTION3 | |||
425 | /* Check for a bogus st_shndx to avoid crashing. */ | |||
426 | && isym->st_shndx < elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections) | |||
427 | && !(isym->st_shndx >= SHN_LORESERVE0xFF00 && isym->st_shndx <= SHN_HIRESERVE0xFFFF)) | |||
428 | { | |||
429 | iname = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[isym->st_shndx]->sh_name; | |||
430 | shindex = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shstrndx; | |||
431 | } | |||
432 | ||||
433 | name = bfd_elf_string_from_elf_section (abfd, shindex, iname); | |||
434 | if (name == NULL((void*)0)) | |||
435 | name = "(null)"; | |||
436 | else if (sym_sec && *name == '\0') | |||
437 | name = bfd_section_name (abfd, sym_sec)((sym_sec)->name); | |||
438 | ||||
439 | return name; | |||
440 | } | |||
441 | ||||
442 | /* Elf_Internal_Shdr->contents is an array of these for SHT_GROUP | |||
443 | sections. The first element is the flags, the rest are section | |||
444 | pointers. */ | |||
445 | ||||
446 | typedef union elf_internal_group { | |||
447 | Elf_Internal_Shdr *shdr; | |||
448 | unsigned int flags; | |||
449 | } Elf_Internal_Group; | |||
450 | ||||
451 | /* Return the name of the group signature symbol. Why isn't the | |||
452 | signature just a string? */ | |||
453 | ||||
454 | static const char * | |||
455 | group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr) | |||
456 | { | |||
457 | Elf_Internal_Shdr *hdr; | |||
458 | unsigned char esym[sizeof (Elf64_External_Sym)]; | |||
459 | Elf_External_Sym_Shndx eshndx; | |||
460 | Elf_Internal_Sym isym; | |||
461 | ||||
462 | /* First we need to ensure the symbol table is available. Make sure | |||
463 | that it is a symbol table section. */ | |||
464 | hdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr) [ghdr->sh_link]; | |||
465 | if (hdr->sh_type != SHT_SYMTAB2 | |||
466 | || ! bfd_section_from_shdr (abfd, ghdr->sh_link)) | |||
467 | return NULL((void*)0); | |||
468 | ||||
469 | /* Go read the symbol. */ | |||
470 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
471 | if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info, | |||
472 | &isym, esym, &eshndx) == NULL((void*)0)) | |||
473 | return NULL((void*)0); | |||
474 | ||||
475 | return bfd_elf_sym_name (abfd, hdr, &isym, NULL((void*)0)); | |||
476 | } | |||
477 | ||||
478 | /* Set next_in_group list pointer, and group name for NEWSECT. */ | |||
479 | ||||
480 | static bfd_boolean | |||
481 | setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect) | |||
482 | { | |||
483 | unsigned int num_group = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->num_group; | |||
484 | ||||
485 | /* If num_group is zero, read in all SHT_GROUP sections. The count | |||
486 | is set to -1 if there are no SHT_GROUP sections. */ | |||
487 | if (num_group == 0) | |||
488 | { | |||
489 | unsigned int i, shnum; | |||
490 | ||||
491 | /* First count the number of groups. If we have a SHT_GROUP | |||
492 | section with just a flag word (ie. sh_size is 4), ignore it. */ | |||
493 | shnum = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
494 | num_group = 0; | |||
495 | for (i = 0; i < shnum; i++) | |||
496 | { | |||
497 | Elf_Internal_Shdr *shdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[i]; | |||
498 | if (shdr->sh_type == SHT_GROUP17 && shdr->sh_size >= 8) | |||
499 | num_group += 1; | |||
500 | } | |||
501 | ||||
502 | if (num_group == 0) | |||
503 | { | |||
504 | num_group = (unsigned) -1; | |||
505 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->num_group = num_group; | |||
506 | } | |||
507 | else | |||
508 | { | |||
509 | /* We keep a list of elf section headers for group sections, | |||
510 | so we can find them quickly. */ | |||
511 | bfd_size_type amt; | |||
512 | ||||
513 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->num_group = num_group; | |||
514 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->group_sect_ptr | |||
515 | = bfd_alloc2 (abfd, num_group, sizeof (Elf_Internal_Shdr *)); | |||
516 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->group_sect_ptr == NULL((void*)0)) | |||
517 | return FALSE0; | |||
518 | ||||
519 | num_group = 0; | |||
520 | for (i = 0; i < shnum; i++) | |||
521 | { | |||
522 | Elf_Internal_Shdr *shdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[i]; | |||
523 | if (shdr->sh_type == SHT_GROUP17 && shdr->sh_size >= 8) | |||
524 | { | |||
525 | unsigned char *src; | |||
526 | Elf_Internal_Group *dest; | |||
527 | ||||
528 | /* Add to list of sections. */ | |||
529 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->group_sect_ptr[num_group] = shdr; | |||
530 | num_group += 1; | |||
531 | ||||
532 | /* Read the raw contents. */ | |||
533 | BFD_ASSERT (sizeof (*dest) >= 4)do { if (!(sizeof (*dest) >= 4)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,533); } while (0); | |||
534 | amt = shdr->sh_size * sizeof (*dest) / 4; | |||
535 | shdr->contents = bfd_alloc2 (abfd, shdr->sh_size, | |||
536 | sizeof (*dest) / 4); | |||
537 | if (shdr->contents == NULL((void*)0) | |||
538 | || bfd_seek (abfd, shdr->sh_offset, SEEK_SET0) != 0 | |||
539 | || (bfd_bread (shdr->contents, shdr->sh_size, abfd) | |||
540 | != shdr->sh_size)) | |||
541 | return FALSE0; | |||
542 | ||||
543 | /* Translate raw contents, a flag word followed by an | |||
544 | array of elf section indices all in target byte order, | |||
545 | to the flag word followed by an array of elf section | |||
546 | pointers. */ | |||
547 | src = shdr->contents + shdr->sh_size; | |||
548 | dest = (Elf_Internal_Group *) (shdr->contents + amt); | |||
549 | while (1) | |||
550 | { | |||
551 | unsigned int idx; | |||
552 | ||||
553 | src -= 4; | |||
554 | --dest; | |||
555 | idx = H_GET_32 (abfd, src)((*((abfd)->xvec->bfd_h_getx32)) (src)); | |||
556 | if (src == shdr->contents) | |||
557 | { | |||
558 | dest->flags = idx; | |||
559 | if (shdr->bfd_section != NULL((void*)0) && (idx & GRP_COMDAT0x1)) | |||
560 | shdr->bfd_section->flags | |||
561 | |= SEC_LINK_ONCE0x20000 | SEC_LINK_DUPLICATES_DISCARD0x0; | |||
562 | break; | |||
563 | } | |||
564 | if (idx >= shnum) | |||
565 | { | |||
566 | ((*_bfd_error_handler) | |||
567 | (_("%B: invalid SHT_GROUP entry")("%B: invalid SHT_GROUP entry"), abfd)); | |||
568 | idx = 0; | |||
569 | } | |||
570 | dest->shdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[idx]; | |||
571 | } | |||
572 | } | |||
573 | } | |||
574 | } | |||
575 | } | |||
576 | ||||
577 | if (num_group != (unsigned) -1) | |||
578 | { | |||
579 | unsigned int i; | |||
580 | ||||
581 | for (i = 0; i < num_group; i++) | |||
582 | { | |||
583 | Elf_Internal_Shdr *shdr = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->group_sect_ptr[i]; | |||
584 | Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents; | |||
585 | unsigned int n_elt = shdr->sh_size / 4; | |||
586 | ||||
587 | /* Look through this group's sections to see if current | |||
588 | section is a member. */ | |||
589 | while (--n_elt != 0) | |||
590 | if ((++idx)->shdr == hdr) | |||
591 | { | |||
592 | asection *s = NULL((void*)0); | |||
593 | ||||
594 | /* We are a member of this group. Go looking through | |||
595 | other members to see if any others are linked via | |||
596 | next_in_group. */ | |||
597 | idx = (Elf_Internal_Group *) shdr->contents; | |||
598 | n_elt = shdr->sh_size / 4; | |||
599 | while (--n_elt != 0) | |||
600 | if ((s = (++idx)->shdr->bfd_section) != NULL((void*)0) | |||
601 | && elf_next_in_group (s)(((struct bfd_elf_section_data*)(s)->used_by_bfd)->next_in_group ) != NULL((void*)0)) | |||
602 | break; | |||
603 | if (n_elt != 0) | |||
604 | { | |||
605 | /* Snarf the group name from other member, and | |||
606 | insert current section in circular list. */ | |||
607 | elf_group_name (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> group.name) = elf_group_name (s)(((struct bfd_elf_section_data*)(s)->used_by_bfd)->group .name); | |||
608 | elf_next_in_group (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> next_in_group) = elf_next_in_group (s)(((struct bfd_elf_section_data*)(s)->used_by_bfd)->next_in_group ); | |||
609 | elf_next_in_group (s)(((struct bfd_elf_section_data*)(s)->used_by_bfd)->next_in_group ) = newsect; | |||
610 | } | |||
611 | else | |||
612 | { | |||
613 | const char *gname; | |||
614 | ||||
615 | gname = group_signature (abfd, shdr); | |||
616 | if (gname == NULL((void*)0)) | |||
617 | return FALSE0; | |||
618 | elf_group_name (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> group.name) = gname; | |||
619 | ||||
620 | /* Start a circular list with one element. */ | |||
621 | elf_next_in_group (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> next_in_group) = newsect; | |||
622 | } | |||
623 | ||||
624 | /* If the group section has been created, point to the | |||
625 | new member. */ | |||
626 | if (shdr->bfd_section != NULL((void*)0)) | |||
627 | elf_next_in_group (shdr->bfd_section)(((struct bfd_elf_section_data*)(shdr->bfd_section)->used_by_bfd )->next_in_group) = newsect; | |||
628 | ||||
629 | i = num_group - 1; | |||
630 | break; | |||
631 | } | |||
632 | } | |||
633 | } | |||
634 | ||||
635 | if (elf_group_name (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> group.name) == NULL((void*)0)) | |||
636 | { | |||
637 | (*_bfd_error_handler) (_("%B: no group info for section %A")("%B: no group info for section %A"), | |||
638 | abfd, newsect); | |||
639 | } | |||
640 | return TRUE1; | |||
641 | } | |||
642 | ||||
643 | bfd_boolean | |||
644 | _bfd_elf_setup_sections (bfd *abfd) | |||
645 | { | |||
646 | unsigned int i; | |||
647 | unsigned int num_group = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->num_group; | |||
648 | bfd_boolean result = TRUE1; | |||
649 | asection *s; | |||
650 | ||||
651 | /* Process SHF_LINK_ORDER. */ | |||
652 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
653 | { | |||
654 | Elf_Internal_Shdr *this_hdr = &elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr; | |||
655 | if ((this_hdr->sh_flags & SHF_LINK_ORDER(1 << 7)) != 0) | |||
656 | { | |||
657 | unsigned int elfsec = this_hdr->sh_link; | |||
658 | /* FIXME: The old Intel compiler and old strip/objcopy may | |||
659 | not set the sh_link or sh_info fields. Hence we could | |||
660 | get the situation where elfsec is 0. */ | |||
661 | if (elfsec == 0) | |||
662 | { | |||
663 | const struct elf_backend_data *bed | |||
664 | = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
665 | if (bed->link_order_error_handler) | |||
666 | bed->link_order_error_handler | |||
667 | (_("%B: warning: sh_link not set for section `%A'")("%B: warning: sh_link not set for section `%A'"), | |||
668 | abfd, s); | |||
669 | } | |||
670 | else | |||
671 | { | |||
672 | asection *link; | |||
673 | ||||
674 | this_hdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elfsec]; | |||
675 | ||||
676 | /* PR 1991, 2008: | |||
677 | Some strip/objcopy may leave an incorrect value in | |||
678 | sh_link. We don't want to proceed. */ | |||
679 | link = this_hdr->bfd_section; | |||
680 | if (link == NULL((void*)0)) | |||
681 | { | |||
682 | (*_bfd_error_handler) | |||
683 | (_("%B: sh_link [%d] in section `%A' is incorrect")("%B: sh_link [%d] in section `%A' is incorrect"), | |||
684 | s->owner, s, elfsec); | |||
685 | result = FALSE0; | |||
686 | } | |||
687 | ||||
688 | elf_linked_to_section (s)(((struct bfd_elf_section_data*)(s)->used_by_bfd)->linked_to ) = link; | |||
689 | } | |||
690 | } | |||
691 | } | |||
692 | ||||
693 | /* Process section groups. */ | |||
694 | if (num_group == (unsigned) -1) | |||
695 | return result; | |||
696 | ||||
697 | for (i = 0; i < num_group; i++) | |||
698 | { | |||
699 | Elf_Internal_Shdr *shdr = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->group_sect_ptr[i]; | |||
700 | Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents; | |||
701 | unsigned int n_elt = shdr->sh_size / 4; | |||
702 | ||||
703 | while (--n_elt != 0) | |||
704 | if ((++idx)->shdr->bfd_section) | |||
705 | elf_sec_group (idx->shdr->bfd_section)(((struct bfd_elf_section_data*)(idx->shdr->bfd_section )->used_by_bfd)->sec_group) = shdr->bfd_section; | |||
706 | else if (idx->shdr->sh_type == SHT_RELA4 | |||
707 | || idx->shdr->sh_type == SHT_REL9) | |||
708 | /* We won't include relocation sections in section groups in | |||
709 | output object files. We adjust the group section size here | |||
710 | so that relocatable link will work correctly when | |||
711 | relocation sections are in section group in input object | |||
712 | files. */ | |||
713 | shdr->bfd_section->size -= 4; | |||
714 | else | |||
715 | { | |||
716 | /* There are some unknown sections in the group. */ | |||
717 | (*_bfd_error_handler) | |||
718 | (_("%B: unknown [%d] section `%s' in group [%s]")("%B: unknown [%d] section `%s' in group [%s]"), | |||
719 | abfd, | |||
720 | (unsigned int) idx->shdr->sh_type, | |||
721 | bfd_elf_string_from_elf_section (abfd, | |||
722 | (elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header) | |||
723 | ->e_shstrndx), | |||
724 | idx->shdr->sh_name), | |||
725 | shdr->bfd_section->name); | |||
726 | result = FALSE0; | |||
727 | } | |||
728 | } | |||
729 | return result; | |||
730 | } | |||
731 | ||||
732 | bfd_boolean | |||
733 | bfd_elf_is_group_section (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), const asection *sec) | |||
734 | { | |||
735 | return elf_next_in_group (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->next_in_group ) != NULL((void*)0); | |||
736 | } | |||
737 | ||||
738 | /* Make a BFD section from an ELF section. We store a pointer to the | |||
739 | BFD section in the bfd_section field of the header. */ | |||
740 | ||||
741 | bfd_boolean | |||
742 | _bfd_elf_make_section_from_shdr (bfd *abfd, | |||
743 | Elf_Internal_Shdr *hdr, | |||
744 | const char *name, | |||
745 | int shindex) | |||
746 | { | |||
747 | asection *newsect; | |||
748 | flagword flags; | |||
749 | const struct elf_backend_data *bed; | |||
750 | ||||
751 | if (hdr->bfd_section != NULL((void*)0)) | |||
752 | { | |||
753 | BFD_ASSERT (strcmp (name,do { if (!(strcmp (name, ((hdr->bfd_section)->name + 0) ) == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,754); } while (0) | |||
754 | bfd_get_section_name (abfd, hdr->bfd_section)) == 0)do { if (!(strcmp (name, ((hdr->bfd_section)->name + 0) ) == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,754); } while (0); | |||
755 | return TRUE1; | |||
756 | } | |||
757 | ||||
758 | newsect = bfd_make_section_anyway (abfd, name); | |||
759 | if (newsect == NULL((void*)0)) | |||
760 | return FALSE0; | |||
761 | ||||
762 | hdr->bfd_section = newsect; | |||
763 | elf_section_data (newsect)((struct bfd_elf_section_data*)(newsect)->used_by_bfd)->this_hdr = *hdr; | |||
764 | elf_section_data (newsect)((struct bfd_elf_section_data*)(newsect)->used_by_bfd)->this_idx = shindex; | |||
765 | ||||
766 | /* Always use the real type/flags. */ | |||
767 | elf_section_type (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> this_hdr.sh_type) = hdr->sh_type; | |||
768 | elf_section_flags (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> this_hdr.sh_flags) = hdr->sh_flags; | |||
769 | ||||
770 | newsect->filepos = hdr->sh_offset; | |||
771 | ||||
772 | if (! bfd_set_section_vma (abfd, newsect, hdr->sh_addr)(((newsect)->vma = (newsect)->lma = (hdr->sh_addr)), ((newsect)->user_set_vma = 1), 1) | |||
773 | || ! bfd_set_section_size (abfd, newsect, hdr->sh_size) | |||
774 | || ! bfd_set_section_alignment (abfd, newsect,(((newsect)->alignment_power = (bfd_log2 ((bfd_vma) hdr-> sh_addralign))),1) | |||
775 | bfd_log2 ((bfd_vma) hdr->sh_addralign))(((newsect)->alignment_power = (bfd_log2 ((bfd_vma) hdr-> sh_addralign))),1)) | |||
776 | return FALSE0; | |||
777 | ||||
778 | flags = SEC_NO_FLAGS0x000; | |||
779 | if (hdr->sh_type != SHT_NOBITS8) | |||
780 | flags |= SEC_HAS_CONTENTS0x100; | |||
781 | if (hdr->sh_type == SHT_GROUP17) | |||
782 | flags |= SEC_GROUP0x4000000 | SEC_EXCLUDE0x8000; | |||
783 | if ((hdr->sh_flags & SHF_ALLOC(1 << 1)) != 0) | |||
784 | { | |||
785 | flags |= SEC_ALLOC0x001; | |||
786 | if (hdr->sh_type != SHT_NOBITS8) | |||
787 | flags |= SEC_LOAD0x002; | |||
788 | } | |||
789 | if ((hdr->sh_flags & SHF_WRITE(1 << 0)) == 0) | |||
790 | flags |= SEC_READONLY0x008; | |||
791 | if ((hdr->sh_flags & SHF_EXECINSTR(1 << 2)) != 0) | |||
792 | flags |= SEC_CODE0x010; | |||
793 | else if ((flags & SEC_LOAD0x002) != 0) | |||
794 | flags |= SEC_DATA0x020; | |||
795 | if ((hdr->sh_flags & SHF_MERGE(1 << 4)) != 0) | |||
796 | { | |||
797 | flags |= SEC_MERGE0x1000000; | |||
798 | newsect->entsize = hdr->sh_entsize; | |||
799 | if ((hdr->sh_flags & SHF_STRINGS(1 << 5)) != 0) | |||
800 | flags |= SEC_STRINGS0x2000000; | |||
801 | } | |||
802 | if (hdr->sh_flags & SHF_GROUP(1 << 9)) | |||
803 | if (!setup_group (abfd, hdr, newsect)) | |||
804 | return FALSE0; | |||
805 | if ((hdr->sh_flags & SHF_TLS(1 << 10)) != 0) | |||
806 | flags |= SEC_THREAD_LOCAL0x400; | |||
807 | ||||
808 | if ((flags & SEC_ALLOC0x001) == 0) | |||
809 | { | |||
810 | /* The debugging sections appear to be recognized only by name, | |||
811 | not any sort of flag. Their SEC_ALLOC bits are cleared. */ | |||
812 | static const struct | |||
813 | { | |||
814 | const char *name; | |||
815 | int len; | |||
816 | } debug_sections [] = | |||
817 | { | |||
818 | { "debug", 5 }, /* 'd' */ | |||
819 | { NULL((void*)0), 0 }, /* 'e' */ | |||
820 | { NULL((void*)0), 0 }, /* 'f' */ | |||
821 | { "gnu.linkonce.wi.", 17 }, /* 'g' */ | |||
822 | { NULL((void*)0), 0 }, /* 'h' */ | |||
823 | { NULL((void*)0), 0 }, /* 'i' */ | |||
824 | { NULL((void*)0), 0 }, /* 'j' */ | |||
825 | { NULL((void*)0), 0 }, /* 'k' */ | |||
826 | { "line", 4 }, /* 'l' */ | |||
827 | { NULL((void*)0), 0 }, /* 'm' */ | |||
828 | { NULL((void*)0), 0 }, /* 'n' */ | |||
829 | { NULL((void*)0), 0 }, /* 'o' */ | |||
830 | { NULL((void*)0), 0 }, /* 'p' */ | |||
831 | { NULL((void*)0), 0 }, /* 'q' */ | |||
832 | { NULL((void*)0), 0 }, /* 'r' */ | |||
833 | { "stab", 4 } /* 's' */ | |||
834 | }; | |||
835 | ||||
836 | if (name [0] == '.') | |||
837 | { | |||
838 | int i = name [1] - 'd'; | |||
839 | if (i >= 0 | |||
840 | && i < (int) ARRAY_SIZE (debug_sections)(sizeof (debug_sections) / sizeof ((debug_sections)[0])) | |||
841 | && debug_sections [i].name != NULL((void*)0) | |||
842 | && strncmp (&name [1], debug_sections [i].name, | |||
843 | debug_sections [i].len) == 0) | |||
844 | flags |= SEC_DEBUGGING0x2000; | |||
845 | } | |||
846 | } | |||
847 | ||||
848 | /* As a GNU extension, if the name begins with .gnu.linkonce, we | |||
849 | only link a single copy of the section. This is used to support | |||
850 | g++. g++ will emit each template expansion in its own section. | |||
851 | The symbols will be defined as weak, so that multiple definitions | |||
852 | are permitted. The GNU linker extension is to actually discard | |||
853 | all but one of the sections. */ | |||
854 | if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0 | |||
855 | && elf_next_in_group (newsect)(((struct bfd_elf_section_data*)(newsect)->used_by_bfd)-> next_in_group) == NULL((void*)0)) | |||
856 | flags |= SEC_LINK_ONCE0x20000 | SEC_LINK_DUPLICATES_DISCARD0x0; | |||
857 | ||||
858 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
859 | if (bed->elf_backend_section_flags) | |||
860 | if (! bed->elf_backend_section_flags (&flags, hdr)) | |||
861 | return FALSE0; | |||
862 | ||||
863 | if (! bfd_set_section_flags (abfd, newsect, flags)) | |||
864 | return FALSE0; | |||
865 | ||||
866 | if ((flags & SEC_ALLOC0x001) != 0) | |||
867 | { | |||
868 | Elf_Internal_Phdr *phdr; | |||
869 | unsigned int i; | |||
870 | ||||
871 | /* Look through the phdrs to see if we need to adjust the lma. | |||
872 | If all the p_paddr fields are zero, we ignore them, since | |||
873 | some ELF linkers produce such output. */ | |||
874 | phdr = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->phdr; | |||
875 | for (i = 0; i < elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; i++, phdr++) | |||
876 | { | |||
877 | if (phdr->p_paddr != 0) | |||
878 | break; | |||
879 | } | |||
880 | if (i < elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum) | |||
881 | { | |||
882 | phdr = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->phdr; | |||
883 | for (i = 0; i < elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; i++, phdr++) | |||
884 | { | |||
885 | /* This section is part of this segment if its file | |||
886 | offset plus size lies within the segment's memory | |||
887 | span and, if the section is loaded, the extent of the | |||
888 | loaded data lies within the extent of the segment. | |||
889 | ||||
890 | Note - we used to check the p_paddr field as well, and | |||
891 | refuse to set the LMA if it was 0. This is wrong | |||
892 | though, as a perfectly valid initialised segment can | |||
893 | have a p_paddr of zero. Some architectures, eg ARM, | |||
894 | place special significance on the address 0 and | |||
895 | executables need to be able to have a segment which | |||
896 | covers this address. */ | |||
897 | if (phdr->p_type == PT_LOAD1 | |||
898 | && (bfd_vma) hdr->sh_offset >= phdr->p_offset | |||
899 | && (hdr->sh_offset + hdr->sh_size | |||
900 | <= phdr->p_offset + phdr->p_memsz) | |||
901 | && ((flags & SEC_LOAD0x002) == 0 | |||
902 | || (hdr->sh_offset + hdr->sh_size | |||
903 | <= phdr->p_offset + phdr->p_filesz))) | |||
904 | { | |||
905 | if ((flags & SEC_LOAD0x002) == 0) | |||
906 | newsect->lma = (phdr->p_paddr | |||
907 | + hdr->sh_addr - phdr->p_vaddr); | |||
908 | else | |||
909 | /* We used to use the same adjustment for SEC_LOAD | |||
910 | sections, but that doesn't work if the segment | |||
911 | is packed with code from multiple VMAs. | |||
912 | Instead we calculate the section LMA based on | |||
913 | the segment LMA. It is assumed that the | |||
914 | segment will contain sections with contiguous | |||
915 | LMAs, even if the VMAs are not. */ | |||
916 | newsect->lma = (phdr->p_paddr | |||
917 | + hdr->sh_offset - phdr->p_offset); | |||
918 | ||||
919 | /* With contiguous segments, we can't tell from file | |||
920 | offsets whether a section with zero size should | |||
921 | be placed at the end of one segment or the | |||
922 | beginning of the next. Decide based on vaddr. */ | |||
923 | if (hdr->sh_addr >= phdr->p_vaddr | |||
924 | && (hdr->sh_addr + hdr->sh_size | |||
925 | <= phdr->p_vaddr + phdr->p_memsz)) | |||
926 | break; | |||
927 | } | |||
928 | } | |||
929 | } | |||
930 | } | |||
931 | ||||
932 | return TRUE1; | |||
933 | } | |||
934 | ||||
935 | /* | |||
936 | INTERNAL_FUNCTION | |||
937 | bfd_elf_find_section | |||
938 | ||||
939 | SYNOPSIS | |||
940 | struct elf_internal_shdr *bfd_elf_find_section (bfd *abfd, char *name); | |||
941 | ||||
942 | DESCRIPTION | |||
943 | Helper functions for GDB to locate the string tables. | |||
944 | Since BFD hides string tables from callers, GDB needs to use an | |||
945 | internal hook to find them. Sun's .stabstr, in particular, | |||
946 | isn't even pointed to by the .stab section, so ordinary | |||
947 | mechanisms wouldn't work to find it, even if we had some. | |||
948 | */ | |||
949 | ||||
950 | struct elf_internal_shdr * | |||
951 | bfd_elf_find_section (bfd *abfd, char *name) | |||
952 | { | |||
953 | Elf_Internal_Shdr **i_shdrp; | |||
954 | char *shstrtab; | |||
955 | unsigned int max; | |||
956 | unsigned int i; | |||
957 | ||||
958 | i_shdrp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr); | |||
959 | if (i_shdrp != NULL((void*)0)) | |||
960 | { | |||
961 | shstrtab = bfd_elf_get_str_section (abfd, | |||
962 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shstrndx); | |||
963 | if (shstrtab != NULL((void*)0)) | |||
964 | { | |||
965 | max = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
966 | for (i = 1; i < max; i++) | |||
967 | if (!strcmp (&shstrtab[i_shdrp[i]->sh_name], name)) | |||
968 | return i_shdrp[i]; | |||
969 | } | |||
970 | } | |||
971 | return 0; | |||
972 | } | |||
973 | ||||
974 | const char *const bfd_elf_section_type_names[] = { | |||
975 | "SHT_NULL", "SHT_PROGBITS", "SHT_SYMTAB", "SHT_STRTAB", | |||
976 | "SHT_RELA", "SHT_HASH", "SHT_DYNAMIC", "SHT_NOTE", | |||
977 | "SHT_NOBITS", "SHT_REL", "SHT_SHLIB", "SHT_DYNSYM", | |||
978 | }; | |||
979 | ||||
980 | /* ELF relocs are against symbols. If we are producing relocatable | |||
981 | output, and the reloc is against an external symbol, and nothing | |||
982 | has given us any additional addend, the resulting reloc will also | |||
983 | be against the same symbol. In such a case, we don't want to | |||
984 | change anything about the way the reloc is handled, since it will | |||
985 | all be done at final link time. Rather than put special case code | |||
986 | into bfd_perform_relocation, all the reloc types use this howto | |||
987 | function. It just short circuits the reloc if producing | |||
988 | relocatable output against an external symbol. */ | |||
989 | ||||
990 | bfd_reloc_status_type | |||
991 | bfd_elf_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
992 | arelent *reloc_entry, | |||
993 | asymbol *symbol, | |||
994 | void *data ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
995 | asection *input_section, | |||
996 | bfd *output_bfd, | |||
997 | char **error_message ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
998 | { | |||
999 | if (output_bfd != NULL((void*)0) | |||
1000 | && (symbol->flags & BSF_SECTION_SYM0x100) == 0 | |||
1001 | && (! reloc_entry->howto->partial_inplace | |||
1002 | || reloc_entry->addend == 0)) | |||
1003 | { | |||
1004 | reloc_entry->address += input_section->output_offset; | |||
1005 | return bfd_reloc_ok; | |||
1006 | } | |||
1007 | ||||
1008 | return bfd_reloc_continue; | |||
1009 | } | |||
1010 | ||||
1011 | /* Make sure sec_info_type is cleared if sec_info is cleared too. */ | |||
1012 | ||||
1013 | static void | |||
1014 | merge_sections_remove_hook (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
1015 | asection *sec) | |||
1016 | { | |||
1017 | BFD_ASSERT (sec->sec_info_type == ELF_INFO_TYPE_MERGE)do { if (!(sec->sec_info_type == 2)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1017); } while (0); | |||
1018 | sec->sec_info_type = ELF_INFO_TYPE_NONE0; | |||
1019 | } | |||
1020 | ||||
1021 | /* Finish SHF_MERGE section merging. */ | |||
1022 | ||||
1023 | bfd_boolean | |||
1024 | _bfd_elf_merge_sections (bfd *abfd, struct bfd_link_info *info) | |||
1025 | { | |||
1026 | bfd *ibfd; | |||
1027 | asection *sec; | |||
1028 | ||||
1029 | if (!is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
1030 | return FALSE0; | |||
1031 | ||||
1032 | for (ibfd = info->input_bfds; ibfd != NULL((void*)0); ibfd = ibfd->link_next) | |||
1033 | if ((ibfd->flags & DYNAMIC0x40) == 0) | |||
1034 | for (sec = ibfd->sections; sec != NULL((void*)0); sec = sec->next) | |||
1035 | if ((sec->flags & SEC_MERGE0x1000000) != 0 | |||
1036 | && !bfd_is_abs_section (sec->output_section)((sec->output_section) == ((asection *) &bfd_abs_section ))) | |||
1037 | { | |||
1038 | struct bfd_elf_section_data *secdata; | |||
1039 | ||||
1040 | secdata = elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd); | |||
1041 | if (! _bfd_add_merge_section (abfd, | |||
1042 | &elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->merge_info, | |||
1043 | sec, &secdata->sec_info)) | |||
1044 | return FALSE0; | |||
1045 | else if (secdata->sec_info) | |||
1046 | sec->sec_info_type = ELF_INFO_TYPE_MERGE2; | |||
1047 | } | |||
1048 | ||||
1049 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->merge_info != NULL((void*)0)) | |||
1050 | _bfd_merge_sections (abfd, info, elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->merge_info, | |||
1051 | merge_sections_remove_hook); | |||
1052 | return TRUE1; | |||
1053 | } | |||
1054 | ||||
1055 | void | |||
1056 | _bfd_elf_link_just_syms (asection *sec, struct bfd_link_info *info) | |||
1057 | { | |||
1058 | sec->output_section = bfd_abs_section_ptr((asection *) &bfd_abs_section); | |||
1059 | sec->output_offset = sec->vma; | |||
1060 | if (!is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
1061 | return; | |||
1062 | ||||
1063 | sec->sec_info_type = ELF_INFO_TYPE_JUST_SYMS4; | |||
1064 | } | |||
1065 | ||||
1066 | /* Copy the program header and other data from one object module to | |||
1067 | another. */ | |||
1068 | ||||
1069 | bfd_boolean | |||
1070 | _bfd_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd) | |||
1071 | { | |||
1072 | if (bfd_get_flavour (ibfd)((ibfd)->xvec->flavour) != bfd_target_elf_flavour | |||
1073 | || bfd_get_flavour (obfd)((obfd)->xvec->flavour) != bfd_target_elf_flavour) | |||
1074 | return TRUE1; | |||
1075 | ||||
1076 | BFD_ASSERT (!elf_flags_init (obfd)do { if (!(!(((obfd) -> tdata.elf_obj_data) -> flags_init ) || ((((obfd) -> tdata.elf_obj_data) -> elf_header)-> e_flags == (((ibfd) -> tdata.elf_obj_data) -> elf_header )->e_flags))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1078); } while (0) | |||
1077 | || (elf_elfheader (obfd)->e_flagsdo { if (!(!(((obfd) -> tdata.elf_obj_data) -> flags_init ) || ((((obfd) -> tdata.elf_obj_data) -> elf_header)-> e_flags == (((ibfd) -> tdata.elf_obj_data) -> elf_header )->e_flags))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1078); } while (0) | |||
1078 | == elf_elfheader (ibfd)->e_flags))do { if (!(!(((obfd) -> tdata.elf_obj_data) -> flags_init ) || ((((obfd) -> tdata.elf_obj_data) -> elf_header)-> e_flags == (((ibfd) -> tdata.elf_obj_data) -> elf_header )->e_flags))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1078); } while (0); | |||
1079 | ||||
1080 | elf_gp (obfd)(((obfd) -> tdata.elf_obj_data) -> gp) = elf_gp (ibfd)(((ibfd) -> tdata.elf_obj_data) -> gp); | |||
1081 | elf_elfheader (obfd)(((obfd) -> tdata.elf_obj_data) -> elf_header)->e_flags = elf_elfheader (ibfd)(((ibfd) -> tdata.elf_obj_data) -> elf_header)->e_flags; | |||
1082 | elf_flags_init (obfd)(((obfd) -> tdata.elf_obj_data) -> flags_init) = TRUE1; | |||
1083 | return TRUE1; | |||
1084 | } | |||
1085 | ||||
1086 | static const char * | |||
1087 | get_segment_type (unsigned int p_type) | |||
1088 | { | |||
1089 | const char *pt; | |||
1090 | switch (p_type) | |||
1091 | { | |||
1092 | case PT_NULL0: pt = "NULL"; break; | |||
1093 | case PT_LOAD1: pt = "LOAD"; break; | |||
1094 | case PT_DYNAMIC2: pt = "DYNAMIC"; break; | |||
1095 | case PT_INTERP3: pt = "INTERP"; break; | |||
1096 | case PT_NOTE4: pt = "NOTE"; break; | |||
1097 | case PT_SHLIB5: pt = "SHLIB"; break; | |||
1098 | case PT_PHDR6: pt = "PHDR"; break; | |||
1099 | case PT_TLS7: pt = "TLS"; break; | |||
1100 | case PT_GNU_EH_FRAME(0x60000000 + 0x474e550): pt = "EH_FRAME"; break; | |||
1101 | case PT_GNU_STACK(0x60000000 + 0x474e551): pt = "STACK"; break; | |||
1102 | case PT_GNU_RELRO(0x60000000 + 0x474e552): pt = "RELRO"; break; | |||
1103 | case PT_OPENBSD_RANDOMIZE0x65a3dbe6: pt = "OPENBSD_RANDOMIZE"; break; | |||
1104 | case PT_OPENBSD_WXNEEDED0x65a3dbe7: pt = "OPENBSD_WXNEEDED"; break; | |||
1105 | case PT_OPENBSD_BOOTDATA0x65a41be6: pt = "OPENBSD_BOOTDATA"; break; | |||
1106 | default: pt = NULL((void*)0); break; | |||
1107 | } | |||
1108 | return pt; | |||
1109 | } | |||
1110 | ||||
1111 | /* Print out the program headers. */ | |||
1112 | ||||
1113 | bfd_boolean | |||
1114 | _bfd_elf_print_private_bfd_data (bfd *abfd, void *farg) | |||
1115 | { | |||
1116 | FILE *f = farg; | |||
1117 | Elf_Internal_Phdr *p; | |||
1118 | asection *s; | |||
1119 | bfd_byte *dynbuf = NULL((void*)0); | |||
1120 | ||||
1121 | p = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->phdr; | |||
1122 | if (p != NULL((void*)0)) | |||
1123 | { | |||
1124 | unsigned int i, c; | |||
1125 | ||||
1126 | fprintf (f, _("\nProgram Header:\n")("\nProgram Header:\n")); | |||
1127 | c = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; | |||
1128 | for (i = 0; i < c; i++, p++) | |||
1129 | { | |||
1130 | const char *pt = get_segment_type (p->p_type); | |||
1131 | char buf[20]; | |||
1132 | ||||
1133 | if (pt == NULL((void*)0)) | |||
1134 | { | |||
1135 | sprintf (buf, "0x%lx", p->p_type); | |||
1136 | pt = buf; | |||
1137 | } | |||
1138 | fprintf (f, "%8s off 0x", pt); | |||
1139 | bfd_fprintf_vma (abfd, f, p->p_offset); | |||
1140 | fprintf (f, " vaddr 0x"); | |||
1141 | bfd_fprintf_vma (abfd, f, p->p_vaddr); | |||
1142 | fprintf (f, " paddr 0x"); | |||
1143 | bfd_fprintf_vma (abfd, f, p->p_paddr); | |||
1144 | fprintf (f, " align 2**%u\n", bfd_log2 (p->p_align)); | |||
1145 | fprintf (f, " filesz 0x"); | |||
1146 | bfd_fprintf_vma (abfd, f, p->p_filesz); | |||
1147 | fprintf (f, " memsz 0x"); | |||
1148 | bfd_fprintf_vma (abfd, f, p->p_memsz); | |||
1149 | fprintf (f, " flags %c%c%c", | |||
1150 | (p->p_flags & PF_R(1 << 2)) != 0 ? 'r' : '-', | |||
1151 | (p->p_flags & PF_W(1 << 1)) != 0 ? 'w' : '-', | |||
1152 | (p->p_flags & PF_X(1 << 0)) != 0 ? 'x' : '-'); | |||
1153 | if ((p->p_flags &~ (unsigned) (PF_R(1 << 2) | PF_W(1 << 1) | PF_X(1 << 0))) != 0) | |||
1154 | fprintf (f, " %lx", p->p_flags &~ (unsigned) (PF_R(1 << 2) | PF_W(1 << 1) | PF_X(1 << 0))); | |||
1155 | fprintf (f, "\n"); | |||
1156 | } | |||
1157 | } | |||
1158 | ||||
1159 | s = bfd_get_section_by_name (abfd, ".dynamic"); | |||
1160 | if (s != NULL((void*)0)) | |||
1161 | { | |||
1162 | int elfsec; | |||
1163 | unsigned long shlink; | |||
1164 | bfd_byte *extdyn, *extdynend; | |||
1165 | size_t extdynsize; | |||
1166 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |||
1167 | ||||
1168 | fprintf (f, _("\nDynamic Section:\n")("\nDynamic Section:\n")); | |||
1169 | ||||
1170 | if (!bfd_malloc_and_get_section (abfd, s, &dynbuf)) | |||
1171 | goto error_return; | |||
1172 | ||||
1173 | elfsec = _bfd_elf_section_from_bfd_section (abfd, s); | |||
1174 | if (elfsec == -1) | |||
1175 | goto error_return; | |||
1176 | shlink = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elfsec]->sh_link; | |||
1177 | ||||
1178 | extdynsize = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_dyn; | |||
1179 | swap_dyn_in = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->swap_dyn_in; | |||
1180 | ||||
1181 | extdyn = dynbuf; | |||
1182 | extdynend = extdyn + s->size; | |||
1183 | for (; extdyn < extdynend; extdyn += extdynsize) | |||
1184 | { | |||
1185 | Elf_Internal_Dyn dyn; | |||
1186 | const char *name; | |||
1187 | char ab[20]; | |||
1188 | bfd_boolean stringp; | |||
1189 | ||||
1190 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |||
1191 | ||||
1192 | if (dyn.d_tag == DT_NULL0) | |||
1193 | break; | |||
1194 | ||||
1195 | stringp = FALSE0; | |||
1196 | switch (dyn.d_tag) | |||
1197 | { | |||
1198 | default: | |||
1199 | sprintf (ab, "0x%lx", (unsigned long) dyn.d_tag); | |||
1200 | name = ab; | |||
1201 | break; | |||
1202 | ||||
1203 | case DT_NEEDED1: name = "NEEDED"; stringp = TRUE1; break; | |||
1204 | case DT_PLTRELSZ2: name = "PLTRELSZ"; break; | |||
1205 | case DT_PLTGOT3: name = "PLTGOT"; break; | |||
1206 | case DT_HASH4: name = "HASH"; break; | |||
1207 | case DT_STRTAB5: name = "STRTAB"; break; | |||
1208 | case DT_SYMTAB6: name = "SYMTAB"; break; | |||
1209 | case DT_RELA7: name = "RELA"; break; | |||
1210 | case DT_RELASZ8: name = "RELASZ"; break; | |||
1211 | case DT_RELAENT9: name = "RELAENT"; break; | |||
1212 | case DT_STRSZ10: name = "STRSZ"; break; | |||
1213 | case DT_SYMENT11: name = "SYMENT"; break; | |||
1214 | case DT_INIT12: name = "INIT"; break; | |||
1215 | case DT_FINI13: name = "FINI"; break; | |||
1216 | case DT_SONAME14: name = "SONAME"; stringp = TRUE1; break; | |||
1217 | case DT_RPATH15: name = "RPATH"; stringp = TRUE1; break; | |||
1218 | case DT_SYMBOLIC16: name = "SYMBOLIC"; break; | |||
1219 | case DT_REL17: name = "REL"; break; | |||
1220 | case DT_RELSZ18: name = "RELSZ"; break; | |||
1221 | case DT_RELENT19: name = "RELENT"; break; | |||
1222 | case DT_PLTREL20: name = "PLTREL"; break; | |||
1223 | case DT_DEBUG21: name = "DEBUG"; break; | |||
1224 | case DT_TEXTREL22: name = "TEXTREL"; break; | |||
1225 | case DT_JMPREL23: name = "JMPREL"; break; | |||
1226 | case DT_BIND_NOW24: name = "BIND_NOW"; break; | |||
1227 | case DT_INIT_ARRAY25: name = "INIT_ARRAY"; break; | |||
1228 | case DT_FINI_ARRAY26: name = "FINI_ARRAY"; break; | |||
1229 | case DT_INIT_ARRAYSZ27: name = "INIT_ARRAYSZ"; break; | |||
1230 | case DT_FINI_ARRAYSZ28: name = "FINI_ARRAYSZ"; break; | |||
1231 | case DT_RUNPATH29: name = "RUNPATH"; stringp = TRUE1; break; | |||
1232 | case DT_FLAGS30: name = "FLAGS"; break; | |||
1233 | case DT_PREINIT_ARRAY32: name = "PREINIT_ARRAY"; break; | |||
1234 | case DT_PREINIT_ARRAYSZ33: name = "PREINIT_ARRAYSZ"; break; | |||
1235 | case DT_CHECKSUM0x6ffffdf8: name = "CHECKSUM"; break; | |||
1236 | case DT_PLTPADSZ0x6ffffdf9: name = "PLTPADSZ"; break; | |||
1237 | case DT_MOVEENT0x6ffffdfa: name = "MOVEENT"; break; | |||
1238 | case DT_MOVESZ0x6ffffdfb: name = "MOVESZ"; break; | |||
1239 | case DT_FEATURE0x6ffffdfc: name = "FEATURE"; break; | |||
1240 | case DT_POSFLAG_10x6ffffdfd: name = "POSFLAG_1"; break; | |||
1241 | case DT_SYMINSZ0x6ffffdfe: name = "SYMINSZ"; break; | |||
1242 | case DT_SYMINENT0x6ffffdff: name = "SYMINENT"; break; | |||
1243 | case DT_CONFIG0x6ffffefa: name = "CONFIG"; stringp = TRUE1; break; | |||
1244 | case DT_DEPAUDIT0x6ffffefb: name = "DEPAUDIT"; stringp = TRUE1; break; | |||
1245 | case DT_AUDIT0x6ffffefc: name = "AUDIT"; stringp = TRUE1; break; | |||
1246 | case DT_PLTPAD0x6ffffefd: name = "PLTPAD"; break; | |||
1247 | case DT_MOVETAB0x6ffffefe: name = "MOVETAB"; break; | |||
1248 | case DT_SYMINFO0x6ffffeff: name = "SYMINFO"; break; | |||
1249 | case DT_RELACOUNT0x6ffffff9: name = "RELACOUNT"; break; | |||
1250 | case DT_RELCOUNT0x6ffffffa: name = "RELCOUNT"; break; | |||
1251 | case DT_FLAGS_10x6ffffffb: name = "FLAGS_1"; break; | |||
1252 | case DT_VERSYM0x6ffffff0: name = "VERSYM"; break; | |||
1253 | case DT_VERDEF0x6ffffffc: name = "VERDEF"; break; | |||
1254 | case DT_VERDEFNUM0x6ffffffd: name = "VERDEFNUM"; break; | |||
1255 | case DT_VERNEED0x6ffffffe: name = "VERNEED"; break; | |||
1256 | case DT_VERNEEDNUM0x6fffffff: name = "VERNEEDNUM"; break; | |||
1257 | case DT_AUXILIARY0x7ffffffd: name = "AUXILIARY"; stringp = TRUE1; break; | |||
1258 | case DT_USED0x7ffffffe: name = "USED"; break; | |||
1259 | case DT_FILTER0x7fffffff: name = "FILTER"; stringp = TRUE1; break; | |||
1260 | case DT_GNU_HASH0x6ffffef5: name = "GNU_HASH"; break; | |||
1261 | case DT_RELR36: name = "RELR"; break; | |||
1262 | case DT_RELRSZ35: name = "RELRSZ"; break; | |||
1263 | case DT_RELRENT37: name = "RELRENT"; break; | |||
1264 | } | |||
1265 | ||||
1266 | fprintf (f, " %-11s ", name); | |||
1267 | if (! stringp) | |||
1268 | fprintf (f, "0x%lx", (unsigned long) dyn.d_un.d_val); | |||
1269 | else | |||
1270 | { | |||
1271 | const char *string; | |||
1272 | unsigned int tagv = dyn.d_un.d_val; | |||
1273 | ||||
1274 | string = bfd_elf_string_from_elf_section (abfd, shlink, tagv); | |||
1275 | if (string == NULL((void*)0)) | |||
1276 | goto error_return; | |||
1277 | fprintf (f, "%s", string); | |||
1278 | } | |||
1279 | fprintf (f, "\n"); | |||
1280 | } | |||
1281 | ||||
1282 | free (dynbuf); | |||
1283 | dynbuf = NULL((void*)0); | |||
1284 | } | |||
1285 | ||||
1286 | if ((elf_dynverdef (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverdef_section) != 0 && elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef == NULL((void*)0)) | |||
1287 | || (elf_dynverref (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverref_section) != 0 && elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref == NULL((void*)0))) | |||
1288 | { | |||
1289 | if (! _bfd_elf_slurp_version_tables (abfd, FALSE0)) | |||
1290 | return FALSE0; | |||
1291 | } | |||
1292 | ||||
1293 | if (elf_dynverdef (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverdef_section) != 0) | |||
1294 | { | |||
1295 | Elf_Internal_Verdef *t; | |||
1296 | ||||
1297 | fprintf (f, _("\nVersion definitions:\n")("\nVersion definitions:\n")); | |||
1298 | for (t = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef; t != NULL((void*)0); t = t->vd_nextdef) | |||
1299 | { | |||
1300 | fprintf (f, "%d 0x%2.2x 0x%8.8lx %s\n", t->vd_ndx, | |||
1301 | t->vd_flags, t->vd_hash, | |||
1302 | t->vd_nodename ? t->vd_nodename : "<corrupt>"); | |||
1303 | if (t->vd_auxptr != NULL((void*)0) && t->vd_auxptr->vda_nextptr != NULL((void*)0)) | |||
1304 | { | |||
1305 | Elf_Internal_Verdaux *a; | |||
1306 | ||||
1307 | fprintf (f, "\t"); | |||
1308 | for (a = t->vd_auxptr->vda_nextptr; | |||
1309 | a != NULL((void*)0); | |||
1310 | a = a->vda_nextptr) | |||
1311 | fprintf (f, "%s ", | |||
1312 | a->vda_nodename ? a->vda_nodename : "<corrupt>"); | |||
1313 | fprintf (f, "\n"); | |||
1314 | } | |||
1315 | } | |||
1316 | } | |||
1317 | ||||
1318 | if (elf_dynverref (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverref_section) != 0) | |||
1319 | { | |||
1320 | Elf_Internal_Verneed *t; | |||
1321 | ||||
1322 | fprintf (f, _("\nVersion References:\n")("\nVersion References:\n")); | |||
1323 | for (t = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref; t != NULL((void*)0); t = t->vn_nextref) | |||
1324 | { | |||
1325 | Elf_Internal_Vernaux *a; | |||
1326 | ||||
1327 | fprintf (f, _(" required from %s:\n")(" required from %s:\n"), | |||
1328 | t->vn_filename ? t->vn_filename : "<corrupt>"); | |||
1329 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
1330 | fprintf (f, " 0x%8.8lx 0x%2.2x %2.2d %s\n", a->vna_hash, | |||
1331 | a->vna_flags, a->vna_other, | |||
1332 | a->vna_nodename ? a->vna_nodename : "<corrupt>"); | |||
1333 | } | |||
1334 | } | |||
1335 | ||||
1336 | return TRUE1; | |||
1337 | ||||
1338 | error_return: | |||
1339 | if (dynbuf != NULL((void*)0)) | |||
1340 | free (dynbuf); | |||
1341 | return FALSE0; | |||
1342 | } | |||
1343 | ||||
1344 | /* Display ELF-specific fields of a symbol. */ | |||
1345 | ||||
1346 | void | |||
1347 | bfd_elf_print_symbol (bfd *abfd, | |||
1348 | void *filep, | |||
1349 | asymbol *symbol, | |||
1350 | bfd_print_symbol_type how) | |||
1351 | { | |||
1352 | FILE *file = filep; | |||
1353 | switch (how) | |||
1354 | { | |||
1355 | case bfd_print_symbol_name: | |||
1356 | fprintf (file, "%s", symbol->name); | |||
1357 | break; | |||
1358 | case bfd_print_symbol_more: | |||
1359 | fprintf (file, "elf "); | |||
1360 | bfd_fprintf_vma (abfd, file, symbol->value); | |||
1361 | fprintf (file, " %lx", (long) symbol->flags); | |||
1362 | break; | |||
1363 | case bfd_print_symbol_all: | |||
1364 | { | |||
1365 | const char *section_name; | |||
1366 | const char *name = NULL((void*)0); | |||
1367 | const struct elf_backend_data *bed; | |||
1368 | unsigned char st_other; | |||
1369 | bfd_vma val; | |||
1370 | ||||
1371 | section_name = symbol->section ? symbol->section->name : "(*none*)"; | |||
1372 | ||||
1373 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
1374 | if (bed->elf_backend_print_symbol_all) | |||
1375 | name = (*bed->elf_backend_print_symbol_all) (abfd, filep, symbol); | |||
1376 | ||||
1377 | if (name == NULL((void*)0)) | |||
1378 | { | |||
1379 | name = symbol->name; | |||
1380 | bfd_print_symbol_vandf (abfd, file, symbol); | |||
1381 | } | |||
1382 | ||||
1383 | fprintf (file, " %s\t", section_name); | |||
1384 | /* Print the "other" value for a symbol. For common symbols, | |||
1385 | we've already printed the size; now print the alignment. | |||
1386 | For other symbols, we have no specified alignment, and | |||
1387 | we've printed the address; now print the size. */ | |||
1388 | if (bfd_is_com_section (symbol->section)(((symbol->section)->flags & 0x1000) != 0)) | |||
1389 | val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_value; | |||
1390 | else | |||
1391 | val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_size; | |||
1392 | bfd_fprintf_vma (abfd, file, val); | |||
1393 | ||||
1394 | /* If we have version information, print it. */ | |||
1395 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynversym_section != 0 | |||
1396 | && (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynverdef_section != 0 | |||
1397 | || elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynverref_section != 0)) | |||
1398 | { | |||
1399 | unsigned int vernum; | |||
1400 | const char *version_string; | |||
1401 | ||||
1402 | vernum = ((elf_symbol_type *) symbol)->version & VERSYM_VERSION0x7fff; | |||
1403 | ||||
1404 | if (vernum == 0) | |||
1405 | version_string = ""; | |||
1406 | else if (vernum == 1) | |||
1407 | version_string = "Base"; | |||
1408 | else if (vernum <= elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs) | |||
1409 | version_string = | |||
1410 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef[vernum - 1].vd_nodename; | |||
1411 | else | |||
1412 | { | |||
1413 | Elf_Internal_Verneed *t; | |||
1414 | ||||
1415 | version_string = ""; | |||
1416 | for (t = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref; | |||
1417 | t != NULL((void*)0); | |||
1418 | t = t->vn_nextref) | |||
1419 | { | |||
1420 | Elf_Internal_Vernaux *a; | |||
1421 | ||||
1422 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
1423 | { | |||
1424 | if (a->vna_other == vernum) | |||
1425 | { | |||
1426 | version_string = a->vna_nodename; | |||
1427 | break; | |||
1428 | } | |||
1429 | } | |||
1430 | } | |||
1431 | } | |||
1432 | ||||
1433 | if ((((elf_symbol_type *) symbol)->version & VERSYM_HIDDEN0x8000) == 0) | |||
1434 | fprintf (file, " %-11s", version_string); | |||
1435 | else | |||
1436 | { | |||
1437 | int i; | |||
1438 | ||||
1439 | fprintf (file, " (%s)", version_string); | |||
1440 | for (i = 10 - strlen (version_string); i > 0; --i) | |||
1441 | putc (' ', file)(!__isthreaded ? __sputc(' ', file) : (putc)(' ', file)); | |||
1442 | } | |||
1443 | } | |||
1444 | ||||
1445 | /* If the st_other field is not zero, print it. */ | |||
1446 | st_other = ((elf_symbol_type *) symbol)->internal_elf_sym.st_other; | |||
1447 | ||||
1448 | switch (st_other) | |||
1449 | { | |||
1450 | case 0: break; | |||
1451 | case STV_INTERNAL1: fprintf (file, " .internal"); break; | |||
1452 | case STV_HIDDEN2: fprintf (file, " .hidden"); break; | |||
1453 | case STV_PROTECTED3: fprintf (file, " .protected"); break; | |||
1454 | default: | |||
1455 | /* Some other non-defined flags are also present, so print | |||
1456 | everything hex. */ | |||
1457 | fprintf (file, " 0x%02x", (unsigned int) st_other); | |||
1458 | } | |||
1459 | ||||
1460 | fprintf (file, " %s", name); | |||
1461 | } | |||
1462 | break; | |||
1463 | } | |||
1464 | } | |||
1465 | ||||
1466 | /* Create an entry in an ELF linker hash table. */ | |||
1467 | ||||
1468 | struct bfd_hash_entry * | |||
1469 | _bfd_elf_link_hash_newfunc (struct bfd_hash_entry *entry, | |||
1470 | struct bfd_hash_table *table, | |||
1471 | const char *string) | |||
1472 | { | |||
1473 | /* Allocate the structure if it has not already been allocated by a | |||
1474 | subclass. */ | |||
1475 | if (entry == NULL((void*)0)) | |||
1476 | { | |||
1477 | entry = bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry)); | |||
1478 | if (entry == NULL((void*)0)) | |||
1479 | return entry; | |||
1480 | } | |||
1481 | ||||
1482 | /* Call the allocation method of the superclass. */ | |||
1483 | entry = _bfd_link_hash_newfunc (entry, table, string); | |||
1484 | if (entry != NULL((void*)0)) | |||
1485 | { | |||
1486 | struct elf_link_hash_entry *ret = (struct elf_link_hash_entry *) entry; | |||
1487 | struct elf_link_hash_table *htab = (struct elf_link_hash_table *) table; | |||
1488 | ||||
1489 | /* Set local fields. */ | |||
1490 | ret->indx = -1; | |||
1491 | ret->dynindx = -1; | |||
1492 | ret->got = htab->init_got_refcount; | |||
1493 | ret->plt = htab->init_plt_refcount; | |||
1494 | memset (&ret->size, 0, (sizeof (struct elf_link_hash_entry) | |||
1495 | - offsetof (struct elf_link_hash_entry, size)__builtin_offsetof(struct elf_link_hash_entry, size))); | |||
1496 | /* Assume that we have been called by a non-ELF symbol reader. | |||
1497 | This flag is then reset by the code which reads an ELF input | |||
1498 | file. This ensures that a symbol created by a non-ELF symbol | |||
1499 | reader will have the flag set correctly. */ | |||
1500 | ret->non_elf = 1; | |||
1501 | } | |||
1502 | ||||
1503 | return entry; | |||
1504 | } | |||
1505 | ||||
1506 | /* Copy data from an indirect symbol to its direct symbol, hiding the | |||
1507 | old indirect symbol. Also used for copying flags to a weakdef. */ | |||
1508 | ||||
1509 | void | |||
1510 | _bfd_elf_link_hash_copy_indirect (struct bfd_link_info *info, | |||
1511 | struct elf_link_hash_entry *dir, | |||
1512 | struct elf_link_hash_entry *ind) | |||
1513 | { | |||
1514 | struct elf_link_hash_table *htab; | |||
1515 | ||||
1516 | /* Copy down any references that we may have already seen to the | |||
1517 | symbol which just became indirect. */ | |||
1518 | ||||
1519 | dir->ref_dynamic |= ind->ref_dynamic; | |||
1520 | dir->ref_regular |= ind->ref_regular; | |||
1521 | dir->ref_regular_nonweak |= ind->ref_regular_nonweak; | |||
1522 | dir->non_got_ref |= ind->non_got_ref; | |||
1523 | dir->needs_plt |= ind->needs_plt; | |||
1524 | dir->pointer_equality_needed |= ind->pointer_equality_needed; | |||
1525 | ||||
1526 | if (ind->root.type != bfd_link_hash_indirect) | |||
1527 | return; | |||
1528 | ||||
1529 | /* Copy over the global and procedure linkage table refcount entries. | |||
1530 | These may have been already set up by a check_relocs routine. */ | |||
1531 | htab = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
1532 | if (ind->got.refcount > htab->init_got_refcount.refcount) | |||
1533 | { | |||
1534 | if (dir->got.refcount < 0) | |||
1535 | dir->got.refcount = 0; | |||
1536 | dir->got.refcount += ind->got.refcount; | |||
1537 | ind->got.refcount = htab->init_got_refcount.refcount; | |||
1538 | } | |||
1539 | ||||
1540 | if (ind->plt.refcount > htab->init_plt_refcount.refcount) | |||
1541 | { | |||
1542 | if (dir->plt.refcount < 0) | |||
1543 | dir->plt.refcount = 0; | |||
1544 | dir->plt.refcount += ind->plt.refcount; | |||
1545 | ind->plt.refcount = htab->init_plt_refcount.refcount; | |||
1546 | } | |||
1547 | ||||
1548 | if (ind->dynindx != -1) | |||
1549 | { | |||
1550 | if (dir->dynindx != -1) | |||
1551 | _bfd_elf_strtab_delref (htab->dynstr, dir->dynstr_index); | |||
1552 | dir->dynindx = ind->dynindx; | |||
1553 | dir->dynstr_index = ind->dynstr_index; | |||
1554 | ind->dynindx = -1; | |||
1555 | ind->dynstr_index = 0; | |||
1556 | } | |||
1557 | } | |||
1558 | ||||
1559 | void | |||
1560 | _bfd_elf_link_hash_hide_symbol (struct bfd_link_info *info, | |||
1561 | struct elf_link_hash_entry *h, | |||
1562 | bfd_boolean force_local) | |||
1563 | { | |||
1564 | h->plt = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->init_plt_offset; | |||
1565 | h->needs_plt = 0; | |||
1566 | if (force_local) | |||
1567 | { | |||
1568 | h->forced_local = 1; | |||
1569 | if (h->dynindx != -1) | |||
1570 | { | |||
1571 | h->dynindx = -1; | |||
1572 | _bfd_elf_strtab_delref (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
1573 | h->dynstr_index); | |||
1574 | } | |||
1575 | } | |||
1576 | } | |||
1577 | ||||
1578 | /* Initialize an ELF linker hash table. */ | |||
1579 | ||||
1580 | bfd_boolean | |||
1581 | _bfd_elf_link_hash_table_init | |||
1582 | (struct elf_link_hash_table *table, | |||
1583 | bfd *abfd, | |||
1584 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, | |||
1585 | struct bfd_hash_table *, | |||
1586 | const char *), | |||
1587 | unsigned int entsize) | |||
1588 | { | |||
1589 | bfd_boolean ret; | |||
1590 | int can_refcount = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->can_refcount; | |||
1591 | ||||
1592 | table->dynamic_sections_created = FALSE0; | |||
1593 | table->dynobj = NULL((void*)0); | |||
1594 | table->init_got_refcount.refcount = can_refcount - 1; | |||
1595 | table->init_plt_refcount.refcount = can_refcount - 1; | |||
1596 | table->init_got_offset.offset = -(bfd_vma) 1; | |||
1597 | table->init_plt_offset.offset = -(bfd_vma) 1; | |||
1598 | /* The first dynamic symbol is a dummy. */ | |||
1599 | table->dynsymcount = 1; | |||
1600 | table->dynstr = NULL((void*)0); | |||
1601 | table->bucketcount = 0; | |||
1602 | table->needed = NULL((void*)0); | |||
1603 | table->hgot = NULL((void*)0); | |||
1604 | table->merge_info = NULL((void*)0); | |||
1605 | memset (&table->stab_info, 0, sizeof (table->stab_info)); | |||
1606 | memset (&table->eh_info, 0, sizeof (table->eh_info)); | |||
1607 | table->dynlocal = NULL((void*)0); | |||
1608 | table->runpath = NULL((void*)0); | |||
1609 | table->tls_sec = NULL((void*)0); | |||
1610 | table->tls_size = 0; | |||
1611 | table->loaded = NULL((void*)0); | |||
1612 | table->is_relocatable_executable = FALSE0; | |||
1613 | ||||
1614 | ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc, entsize); | |||
1615 | table->root.type = bfd_link_elf_hash_table; | |||
1616 | ||||
1617 | return ret; | |||
1618 | } | |||
1619 | ||||
1620 | /* Create an ELF linker hash table. */ | |||
1621 | ||||
1622 | struct bfd_link_hash_table * | |||
1623 | _bfd_elf_link_hash_table_create (bfd *abfd) | |||
1624 | { | |||
1625 | struct elf_link_hash_table *ret; | |||
1626 | bfd_size_type amt = sizeof (struct elf_link_hash_table); | |||
1627 | ||||
1628 | ret = bfd_malloc (amt); | |||
1629 | if (ret == NULL((void*)0)) | |||
1630 | return NULL((void*)0); | |||
1631 | ||||
1632 | if (! _bfd_elf_link_hash_table_init (ret, abfd, _bfd_elf_link_hash_newfunc, | |||
1633 | sizeof (struct elf_link_hash_entry))) | |||
1634 | { | |||
1635 | free (ret); | |||
1636 | return NULL((void*)0); | |||
1637 | } | |||
1638 | ||||
1639 | return &ret->root; | |||
1640 | } | |||
1641 | ||||
1642 | /* This is a hook for the ELF emulation code in the generic linker to | |||
1643 | tell the backend linker what file name to use for the DT_NEEDED | |||
1644 | entry for a dynamic object. */ | |||
1645 | ||||
1646 | void | |||
1647 | bfd_elf_set_dt_needed_name (bfd *abfd, const char *name) | |||
1648 | { | |||
1649 | if (bfd_get_flavour (abfd)((abfd)->xvec->flavour) == bfd_target_elf_flavour | |||
1650 | && bfd_get_format (abfd)((abfd)->format) == bfd_object) | |||
1651 | elf_dt_name (abfd)(((abfd) -> tdata.elf_obj_data) -> dt_name) = name; | |||
1652 | } | |||
1653 | ||||
1654 | int | |||
1655 | bfd_elf_get_dyn_lib_class (bfd *abfd) | |||
1656 | { | |||
1657 | int lib_class; | |||
1658 | if (bfd_get_flavour (abfd)((abfd)->xvec->flavour) == bfd_target_elf_flavour | |||
1659 | && bfd_get_format (abfd)((abfd)->format) == bfd_object) | |||
1660 | lib_class = elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class); | |||
1661 | else | |||
1662 | lib_class = 0; | |||
1663 | return lib_class; | |||
1664 | } | |||
1665 | ||||
1666 | void | |||
1667 | bfd_elf_set_dyn_lib_class (bfd *abfd, int lib_class) | |||
1668 | { | |||
1669 | if (bfd_get_flavour (abfd)((abfd)->xvec->flavour) == bfd_target_elf_flavour | |||
1670 | && bfd_get_format (abfd)((abfd)->format) == bfd_object) | |||
1671 | elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class) = lib_class; | |||
1672 | } | |||
1673 | ||||
1674 | /* Get the list of DT_NEEDED entries for a link. This is a hook for | |||
1675 | the linker ELF emulation code. */ | |||
1676 | ||||
1677 | struct bfd_link_needed_list * | |||
1678 | bfd_elf_get_needed_list (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
1679 | struct bfd_link_info *info) | |||
1680 | { | |||
1681 | if (! is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
1682 | return NULL((void*)0); | |||
1683 | return elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->needed; | |||
1684 | } | |||
1685 | ||||
1686 | /* Get the list of DT_RPATH/DT_RUNPATH entries for a link. This is a | |||
1687 | hook for the linker ELF emulation code. */ | |||
1688 | ||||
1689 | struct bfd_link_needed_list * | |||
1690 | bfd_elf_get_runpath_list (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
1691 | struct bfd_link_info *info) | |||
1692 | { | |||
1693 | if (! is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
1694 | return NULL((void*)0); | |||
1695 | return elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->runpath; | |||
1696 | } | |||
1697 | ||||
1698 | /* Get the name actually used for a dynamic object for a link. This | |||
1699 | is the SONAME entry if there is one. Otherwise, it is the string | |||
1700 | passed to bfd_elf_set_dt_needed_name, or it is the filename. */ | |||
1701 | ||||
1702 | const char * | |||
1703 | bfd_elf_get_dt_soname (bfd *abfd) | |||
1704 | { | |||
1705 | if (bfd_get_flavour (abfd)((abfd)->xvec->flavour) == bfd_target_elf_flavour | |||
1706 | && bfd_get_format (abfd)((abfd)->format) == bfd_object) | |||
1707 | return elf_dt_name (abfd)(((abfd) -> tdata.elf_obj_data) -> dt_name); | |||
1708 | return NULL((void*)0); | |||
1709 | } | |||
1710 | ||||
1711 | /* Get the list of DT_NEEDED entries from a BFD. This is a hook for | |||
1712 | the ELF linker emulation code. */ | |||
1713 | ||||
1714 | bfd_boolean | |||
1715 | bfd_elf_get_bfd_needed_list (bfd *abfd, | |||
1716 | struct bfd_link_needed_list **pneeded) | |||
1717 | { | |||
1718 | asection *s; | |||
1719 | bfd_byte *dynbuf = NULL((void*)0); | |||
1720 | int elfsec; | |||
1721 | unsigned long shlink; | |||
1722 | bfd_byte *extdyn, *extdynend; | |||
1723 | size_t extdynsize; | |||
1724 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |||
1725 | ||||
1726 | *pneeded = NULL((void*)0); | |||
1727 | ||||
1728 | if (bfd_get_flavour (abfd)((abfd)->xvec->flavour) != bfd_target_elf_flavour | |||
1729 | || bfd_get_format (abfd)((abfd)->format) != bfd_object) | |||
1730 | return TRUE1; | |||
1731 | ||||
1732 | s = bfd_get_section_by_name (abfd, ".dynamic"); | |||
1733 | if (s == NULL((void*)0) || s->size == 0) | |||
1734 | return TRUE1; | |||
1735 | ||||
1736 | if (!bfd_malloc_and_get_section (abfd, s, &dynbuf)) | |||
1737 | goto error_return; | |||
1738 | ||||
1739 | elfsec = _bfd_elf_section_from_bfd_section (abfd, s); | |||
1740 | if (elfsec == -1) | |||
1741 | goto error_return; | |||
1742 | ||||
1743 | shlink = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elfsec]->sh_link; | |||
1744 | ||||
1745 | extdynsize = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_dyn; | |||
1746 | swap_dyn_in = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->swap_dyn_in; | |||
1747 | ||||
1748 | extdyn = dynbuf; | |||
1749 | extdynend = extdyn + s->size; | |||
1750 | for (; extdyn < extdynend; extdyn += extdynsize) | |||
1751 | { | |||
1752 | Elf_Internal_Dyn dyn; | |||
1753 | ||||
1754 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |||
1755 | ||||
1756 | if (dyn.d_tag == DT_NULL0) | |||
1757 | break; | |||
1758 | ||||
1759 | if (dyn.d_tag == DT_NEEDED1) | |||
1760 | { | |||
1761 | const char *string; | |||
1762 | struct bfd_link_needed_list *l; | |||
1763 | unsigned int tagv = dyn.d_un.d_val; | |||
1764 | bfd_size_type amt; | |||
1765 | ||||
1766 | string = bfd_elf_string_from_elf_section (abfd, shlink, tagv); | |||
1767 | if (string == NULL((void*)0)) | |||
1768 | goto error_return; | |||
1769 | ||||
1770 | amt = sizeof *l; | |||
1771 | l = bfd_alloc (abfd, amt); | |||
1772 | if (l == NULL((void*)0)) | |||
1773 | goto error_return; | |||
1774 | ||||
1775 | l->by = abfd; | |||
1776 | l->name = string; | |||
1777 | l->next = *pneeded; | |||
1778 | *pneeded = l; | |||
1779 | } | |||
1780 | } | |||
1781 | ||||
1782 | free (dynbuf); | |||
1783 | ||||
1784 | return TRUE1; | |||
1785 | ||||
1786 | error_return: | |||
1787 | if (dynbuf != NULL((void*)0)) | |||
1788 | free (dynbuf); | |||
1789 | return FALSE0; | |||
1790 | } | |||
1791 | ||||
1792 | /* Allocate an ELF string table--force the first byte to be zero. */ | |||
1793 | ||||
1794 | struct bfd_strtab_hash * | |||
1795 | _bfd_elf_stringtab_init (void) | |||
1796 | { | |||
1797 | struct bfd_strtab_hash *ret; | |||
1798 | ||||
1799 | ret = _bfd_stringtab_init (); | |||
1800 | if (ret != NULL((void*)0)) | |||
1801 | { | |||
1802 | bfd_size_type loc; | |||
1803 | ||||
1804 | loc = _bfd_stringtab_add (ret, "", TRUE1, FALSE0); | |||
1805 | BFD_ASSERT (loc == 0 || loc == (bfd_size_type) -1)do { if (!(loc == 0 || loc == (bfd_size_type) -1)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c",1805); } while (0); | |||
1806 | if (loc == (bfd_size_type) -1) | |||
1807 | { | |||
1808 | _bfd_stringtab_free (ret); | |||
1809 | ret = NULL((void*)0); | |||
1810 | } | |||
1811 | } | |||
1812 | return ret; | |||
1813 | } | |||
1814 | ||||
1815 | /* ELF .o/exec file reading */ | |||
1816 | ||||
1817 | /* Create a new bfd section from an ELF section header. */ | |||
1818 | ||||
1819 | bfd_boolean | |||
1820 | bfd_section_from_shdr (bfd *abfd, unsigned int shindex) | |||
1821 | { | |||
1822 | Elf_Internal_Shdr *hdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex]; | |||
1823 | Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header); | |||
1824 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
1825 | const char *name; | |||
1826 | ||||
1827 | name = bfd_elf_string_from_elf_section (abfd, | |||
1828 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shstrndx, | |||
1829 | hdr->sh_name); | |||
1830 | if (name == NULL((void*)0)) | |||
1831 | return FALSE0; | |||
1832 | ||||
1833 | switch (hdr->sh_type) | |||
1834 | { | |||
1835 | case SHT_NULL0: | |||
1836 | /* Inactive section. Throw it away. */ | |||
1837 | return TRUE1; | |||
1838 | ||||
1839 | case SHT_PROGBITS1: /* Normal section with contents. */ | |||
1840 | case SHT_NOBITS8: /* .bss section. */ | |||
1841 | case SHT_HASH5: /* .hash section. */ | |||
1842 | case SHT_NOTE7: /* .note section. */ | |||
1843 | case SHT_INIT_ARRAY14: /* .init_array section. */ | |||
1844 | case SHT_FINI_ARRAY15: /* .fini_array section. */ | |||
1845 | case SHT_PREINIT_ARRAY16: /* .preinit_array section. */ | |||
1846 | case SHT_GNU_LIBLIST0x6ffffff7: /* .gnu.liblist section. */ | |||
1847 | case SHT_GNU_HASH0x6ffffff6: /* .gnu.hash section. */ | |||
1848 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
1849 | ||||
1850 | case SHT_DYNAMIC6: /* Dynamic linking information. */ | |||
1851 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) | |||
1852 | return FALSE0; | |||
1853 | if (hdr->sh_link > elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections) | |||
1854 | || elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_link] == NULL((void*)0)) | |||
1855 | return FALSE0; | |||
1856 | if (elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_link]->sh_type != SHT_STRTAB3) | |||
1857 | { | |||
1858 | Elf_Internal_Shdr *dynsymhdr; | |||
1859 | ||||
1860 | /* The shared libraries distributed with hpux11 have a bogus | |||
1861 | sh_link field for the ".dynamic" section. Find the | |||
1862 | string table for the ".dynsym" section instead. */ | |||
1863 | if (elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) != 0) | |||
1864 | { | |||
1865 | dynsymhdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section)]; | |||
1866 | hdr->sh_link = dynsymhdr->sh_link; | |||
1867 | } | |||
1868 | else | |||
1869 | { | |||
1870 | unsigned int i, num_sec; | |||
1871 | ||||
1872 | num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
1873 | for (i = 1; i < num_sec; i++) | |||
1874 | { | |||
1875 | dynsymhdr = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[i]; | |||
1876 | if (dynsymhdr->sh_type == SHT_DYNSYM11) | |||
1877 | { | |||
1878 | hdr->sh_link = dynsymhdr->sh_link; | |||
1879 | break; | |||
1880 | } | |||
1881 | } | |||
1882 | } | |||
1883 | } | |||
1884 | break; | |||
1885 | ||||
1886 | case SHT_SYMTAB2: /* A symbol table */ | |||
1887 | if (elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section) == shindex) | |||
1888 | return TRUE1; | |||
1889 | ||||
1890 | if (hdr->sh_entsize != bed->s->sizeof_sym) | |||
1891 | return FALSE0; | |||
1892 | BFD_ASSERT (elf_onesymtab (abfd) == 0)do { if (!((((abfd) -> tdata.elf_obj_data) -> symtab_section ) == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1892); } while (0); | |||
1893 | elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section) = shindex; | |||
1894 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr = *hdr; | |||
1895 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
1896 | abfd->flags |= HAS_SYMS0x10; | |||
1897 | ||||
1898 | /* Sometimes a shared object will map in the symbol table. If | |||
1899 | SHF_ALLOC is set, and this is a shared object, then we also | |||
1900 | treat this section as a BFD section. We can not base the | |||
1901 | decision purely on SHF_ALLOC, because that flag is sometimes | |||
1902 | set in a relocatable object file, which would confuse the | |||
1903 | linker. */ | |||
1904 | if ((hdr->sh_flags & SHF_ALLOC(1 << 1)) != 0 | |||
1905 | && (abfd->flags & DYNAMIC0x40) != 0 | |||
1906 | && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name, | |||
1907 | shindex)) | |||
1908 | return FALSE0; | |||
1909 | ||||
1910 | /* Go looking for SHT_SYMTAB_SHNDX too, since if there is one we | |||
1911 | can't read symbols without that section loaded as well. It | |||
1912 | is most likely specified by the next section header. */ | |||
1913 | if (elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elf_symtab_shndx (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_shndx_section )]->sh_link != shindex) | |||
1914 | { | |||
1915 | unsigned int i, num_sec; | |||
1916 | ||||
1917 | num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
1918 | for (i = shindex + 1; i < num_sec; i++) | |||
1919 | { | |||
1920 | Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[i]; | |||
1921 | if (hdr2->sh_type == SHT_SYMTAB_SHNDX18 | |||
1922 | && hdr2->sh_link == shindex) | |||
1923 | break; | |||
1924 | } | |||
1925 | if (i == num_sec) | |||
1926 | for (i = 1; i < shindex; i++) | |||
1927 | { | |||
1928 | Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[i]; | |||
1929 | if (hdr2->sh_type == SHT_SYMTAB_SHNDX18 | |||
1930 | && hdr2->sh_link == shindex) | |||
1931 | break; | |||
1932 | } | |||
1933 | if (i != shindex) | |||
1934 | return bfd_section_from_shdr (abfd, i); | |||
1935 | } | |||
1936 | return TRUE1; | |||
1937 | ||||
1938 | case SHT_DYNSYM11: /* A dynamic symbol table */ | |||
1939 | if (elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == shindex) | |||
1940 | return TRUE1; | |||
1941 | ||||
1942 | if (hdr->sh_entsize != bed->s->sizeof_sym) | |||
1943 | return FALSE0; | |||
1944 | BFD_ASSERT (elf_dynsymtab (abfd) == 0)do { if (!((((abfd) -> tdata.elf_obj_data) -> dynsymtab_section ) == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1944); } while (0); | |||
1945 | elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) = shindex; | |||
1946 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynsymtab_hdr = *hdr; | |||
1947 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynsymtab_hdr; | |||
1948 | abfd->flags |= HAS_SYMS0x10; | |||
1949 | ||||
1950 | /* Besides being a symbol table, we also treat this as a regular | |||
1951 | section, so that objcopy can handle it. */ | |||
1952 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
1953 | ||||
1954 | case SHT_SYMTAB_SHNDX18: /* Symbol section indices when >64k sections */ | |||
1955 | if (elf_symtab_shndx (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_shndx_section ) == shindex) | |||
1956 | return TRUE1; | |||
1957 | ||||
1958 | BFD_ASSERT (elf_symtab_shndx (abfd) == 0)do { if (!((((abfd) -> tdata.elf_obj_data) -> symtab_shndx_section ) == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,1958); } while (0); | |||
1959 | elf_symtab_shndx (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_shndx_section ) = shindex; | |||
1960 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_shndx_hdr = *hdr; | |||
1961 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_shndx_hdr; | |||
1962 | return TRUE1; | |||
1963 | ||||
1964 | case SHT_STRTAB3: /* A string table */ | |||
1965 | if (hdr->bfd_section != NULL((void*)0)) | |||
1966 | return TRUE1; | |||
1967 | if (ehdr->e_shstrndx == shindex) | |||
1968 | { | |||
1969 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_hdr = *hdr; | |||
1970 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_hdr; | |||
1971 | return TRUE1; | |||
1972 | } | |||
1973 | if (elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section)]->sh_link == shindex) | |||
1974 | { | |||
1975 | symtab_strtab: | |||
1976 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->strtab_hdr = *hdr; | |||
1977 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->strtab_hdr; | |||
1978 | return TRUE1; | |||
1979 | } | |||
1980 | if (elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section)]->sh_link == shindex) | |||
1981 | { | |||
1982 | dynsymtab_strtab: | |||
1983 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynstrtab_hdr = *hdr; | |||
1984 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynstrtab_hdr; | |||
1985 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = hdr; | |||
1986 | /* We also treat this as a regular section, so that objcopy | |||
1987 | can handle it. */ | |||
1988 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, | |||
1989 | shindex); | |||
1990 | } | |||
1991 | ||||
1992 | /* If the string table isn't one of the above, then treat it as a | |||
1993 | regular section. We need to scan all the headers to be sure, | |||
1994 | just in case this strtab section appeared before the above. */ | |||
1995 | if (elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section) == 0 || elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == 0) | |||
1996 | { | |||
1997 | unsigned int i, num_sec; | |||
1998 | ||||
1999 | num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
2000 | for (i = 1; i < num_sec; i++) | |||
2001 | { | |||
2002 | Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[i]; | |||
2003 | if (hdr2->sh_link == shindex) | |||
2004 | { | |||
2005 | /* Prevent endless recursion on broken objects. */ | |||
2006 | if (i == shindex) | |||
2007 | return FALSE0; | |||
2008 | if (! bfd_section_from_shdr (abfd, i)) | |||
2009 | return FALSE0; | |||
2010 | if (elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section) == i) | |||
2011 | goto symtab_strtab; | |||
2012 | if (elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == i) | |||
2013 | goto dynsymtab_strtab; | |||
2014 | } | |||
2015 | } | |||
2016 | } | |||
2017 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
2018 | ||||
2019 | case SHT_REL9: | |||
2020 | case SHT_RELA4: | |||
2021 | /* *These* do a lot of work -- but build no sections! */ | |||
2022 | { | |||
2023 | asection *target_sect; | |||
2024 | Elf_Internal_Shdr *hdr2; | |||
2025 | unsigned int num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
2026 | ||||
2027 | if (hdr->sh_entsize | |||
2028 | != (bfd_size_type) (hdr->sh_type == SHT_REL9 | |||
2029 | ? bed->s->sizeof_rel : bed->s->sizeof_rela)) | |||
2030 | return FALSE0; | |||
2031 | ||||
2032 | /* Check for a bogus link to avoid crashing. */ | |||
2033 | if ((hdr->sh_link >= SHN_LORESERVE0xFF00 && hdr->sh_link <= SHN_HIRESERVE0xFFFF) | |||
2034 | || hdr->sh_link >= num_sec) | |||
2035 | { | |||
2036 | ((*_bfd_error_handler) | |||
2037 | (_("%B: invalid link %lu for reloc section %s (index %u)")("%B: invalid link %lu for reloc section %s (index %u)"), | |||
2038 | abfd, hdr->sh_link, name, shindex)); | |||
2039 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, | |||
2040 | shindex); | |||
2041 | } | |||
2042 | ||||
2043 | /* For some incomprehensible reason Oracle distributes | |||
2044 | libraries for Solaris in which some of the objects have | |||
2045 | bogus sh_link fields. It would be nice if we could just | |||
2046 | reject them, but, unfortunately, some people need to use | |||
2047 | them. We scan through the section headers; if we find only | |||
2048 | one suitable symbol table, we clobber the sh_link to point | |||
2049 | to it. I hope this doesn't break anything. */ | |||
2050 | if (elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_link]->sh_type != SHT_SYMTAB2 | |||
2051 | && elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_link]->sh_type != SHT_DYNSYM11) | |||
2052 | { | |||
2053 | unsigned int scan; | |||
2054 | int found; | |||
2055 | ||||
2056 | found = 0; | |||
2057 | for (scan = 1; scan < num_sec; scan++) | |||
2058 | { | |||
2059 | if (elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[scan]->sh_type == SHT_SYMTAB2 | |||
2060 | || elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[scan]->sh_type == SHT_DYNSYM11) | |||
2061 | { | |||
2062 | if (found != 0) | |||
2063 | { | |||
2064 | found = 0; | |||
2065 | break; | |||
2066 | } | |||
2067 | found = scan; | |||
2068 | } | |||
2069 | } | |||
2070 | if (found != 0) | |||
2071 | hdr->sh_link = found; | |||
2072 | } | |||
2073 | ||||
2074 | /* Get the symbol table. */ | |||
2075 | if ((elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_link]->sh_type == SHT_SYMTAB2 | |||
2076 | || elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_link]->sh_type == SHT_DYNSYM11) | |||
2077 | && ! bfd_section_from_shdr (abfd, hdr->sh_link)) | |||
2078 | return FALSE0; | |||
2079 | ||||
2080 | /* If this reloc section does not use the main symbol table we | |||
2081 | don't treat it as a reloc section. BFD can't adequately | |||
2082 | represent such a section, so at least for now, we don't | |||
2083 | try. We just present it as a normal section. We also | |||
2084 | can't use it as a reloc section if it points to the null | |||
2085 | section, an invalid section, or another reloc section. */ | |||
2086 | if (hdr->sh_link != elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section) | |||
2087 | || hdr->sh_info == SHN_UNDEF0 | |||
2088 | || (hdr->sh_info >= SHN_LORESERVE0xFF00 && hdr->sh_info <= SHN_HIRESERVE0xFFFF) | |||
2089 | || hdr->sh_info >= num_sec | |||
2090 | || elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_info]->sh_type == SHT_REL9 | |||
2091 | || elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[hdr->sh_info]->sh_type == SHT_RELA4) | |||
2092 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, | |||
2093 | shindex); | |||
2094 | ||||
2095 | if (! bfd_section_from_shdr (abfd, hdr->sh_info)) | |||
2096 | return FALSE0; | |||
2097 | target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info); | |||
2098 | if (target_sect == NULL((void*)0)) | |||
2099 | return FALSE0; | |||
2100 | ||||
2101 | if ((target_sect->flags & SEC_RELOC0x004) == 0 | |||
2102 | || target_sect->reloc_count == 0) | |||
2103 | hdr2 = &elf_section_data (target_sect)((struct bfd_elf_section_data*)(target_sect)->used_by_bfd)->rel_hdr; | |||
2104 | else | |||
2105 | { | |||
2106 | bfd_size_type amt; | |||
2107 | BFD_ASSERT (elf_section_data (target_sect)->rel_hdr2 == NULL)do { if (!(((struct bfd_elf_section_data*)(target_sect)->used_by_bfd )->rel_hdr2 == ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,2107); } while (0); | |||
2108 | amt = sizeof (*hdr2); | |||
2109 | hdr2 = bfd_alloc (abfd, amt); | |||
2110 | elf_section_data (target_sect)((struct bfd_elf_section_data*)(target_sect)->used_by_bfd)->rel_hdr2 = hdr2; | |||
2111 | } | |||
2112 | *hdr2 = *hdr; | |||
2113 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[shindex] = hdr2; | |||
2114 | target_sect->reloc_count += NUM_SHDR_ENTRIES (hdr)((hdr)->sh_size / (hdr)->sh_entsize); | |||
2115 | target_sect->flags |= SEC_RELOC0x004; | |||
2116 | target_sect->relocation = NULL((void*)0); | |||
2117 | target_sect->rel_filepos = hdr->sh_offset; | |||
2118 | /* In the section to which the relocations apply, mark whether | |||
2119 | its relocations are of the REL or RELA variety. */ | |||
2120 | if (hdr->sh_size != 0) | |||
2121 | target_sect->use_rela_p = hdr->sh_type == SHT_RELA4; | |||
2122 | abfd->flags |= HAS_RELOC0x01; | |||
2123 | return TRUE1; | |||
2124 | } | |||
2125 | break; | |||
2126 | ||||
2127 | case SHT_RELR19: | |||
2128 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
2129 | ||||
2130 | case SHT_GNU_verdef0x6ffffffd: | |||
2131 | elf_dynverdef (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverdef_section) = shindex; | |||
2132 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynverdef_hdr = *hdr; | |||
2133 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
2134 | break; | |||
2135 | ||||
2136 | case SHT_GNU_versym0x6fffffff: | |||
2137 | if (hdr->sh_entsize != sizeof (Elf_External_Versym)) | |||
2138 | return FALSE0; | |||
2139 | elf_dynversym (abfd)(((abfd) -> tdata.elf_obj_data) -> dynversym_section) = shindex; | |||
2140 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynversym_hdr = *hdr; | |||
2141 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
2142 | break; | |||
2143 | ||||
2144 | case SHT_GNU_verneed0x6ffffffe: | |||
2145 | elf_dynverref (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverref_section) = shindex; | |||
2146 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynverref_hdr = *hdr; | |||
2147 | return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); | |||
2148 | break; | |||
2149 | ||||
2150 | case SHT_SHLIB10: | |||
2151 | return TRUE1; | |||
2152 | ||||
2153 | case SHT_GROUP17: | |||
2154 | /* We need a BFD section for objcopy and relocatable linking, | |||
2155 | and it's handy to have the signature available as the section | |||
2156 | name. */ | |||
2157 | if (hdr->sh_entsize != GRP_ENTRY_SIZE4) | |||
2158 | return FALSE0; | |||
2159 | name = group_signature (abfd, hdr); | |||
2160 | if (name == NULL((void*)0)) | |||
2161 | return FALSE0; | |||
2162 | if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) | |||
2163 | return FALSE0; | |||
2164 | if (hdr->contents != NULL((void*)0)) | |||
2165 | { | |||
2166 | Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents; | |||
2167 | unsigned int n_elt = hdr->sh_size / 4; | |||
2168 | asection *s; | |||
2169 | ||||
2170 | if (idx->flags & GRP_COMDAT0x1) | |||
2171 | hdr->bfd_section->flags | |||
2172 | |= SEC_LINK_ONCE0x20000 | SEC_LINK_DUPLICATES_DISCARD0x0; | |||
2173 | ||||
2174 | /* We try to keep the same section order as it comes in. */ | |||
2175 | idx += n_elt; | |||
2176 | while (--n_elt != 0) | |||
2177 | if ((s = (--idx)->shdr->bfd_section) != NULL((void*)0) | |||
2178 | && elf_next_in_group (s)(((struct bfd_elf_section_data*)(s)->used_by_bfd)->next_in_group ) != NULL((void*)0)) | |||
2179 | { | |||
2180 | elf_next_in_group (hdr->bfd_section)(((struct bfd_elf_section_data*)(hdr->bfd_section)->used_by_bfd )->next_in_group) = s; | |||
2181 | break; | |||
2182 | } | |||
2183 | } | |||
2184 | break; | |||
2185 | ||||
2186 | case SHT_LLVM_LINKER_OPTIONS0x6fff4c01: | |||
2187 | case SHT_LLVM_ADDRSIG0x6fff4c03: | |||
2188 | return TRUE1; | |||
2189 | ||||
2190 | default: | |||
2191 | /* Check for any processor-specific section types. */ | |||
2192 | return bed->elf_backend_section_from_shdr (abfd, hdr, name, | |||
2193 | shindex); | |||
2194 | } | |||
2195 | ||||
2196 | return TRUE1; | |||
2197 | } | |||
2198 | ||||
2199 | /* Return the section for the local symbol specified by ABFD, R_SYMNDX. | |||
2200 | Return SEC for sections that have no elf section, and NULL on error. */ | |||
2201 | ||||
2202 | asection * | |||
2203 | bfd_section_from_r_symndx (bfd *abfd, | |||
2204 | struct sym_sec_cache *cache, | |||
2205 | asection *sec, | |||
2206 | unsigned long r_symndx) | |||
2207 | { | |||
2208 | Elf_Internal_Shdr *symtab_hdr; | |||
2209 | unsigned char esym[sizeof (Elf64_External_Sym)]; | |||
2210 | Elf_External_Sym_Shndx eshndx; | |||
2211 | Elf_Internal_Sym isym; | |||
2212 | unsigned int ent = r_symndx % LOCAL_SYM_CACHE_SIZE32; | |||
2213 | ||||
2214 | if (cache->abfd == abfd && cache->indx[ent] == r_symndx) | |||
2215 | return cache->sec[ent]; | |||
2216 | ||||
2217 | symtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
2218 | if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx, | |||
2219 | &isym, esym, &eshndx) == NULL((void*)0)) | |||
2220 | return NULL((void*)0); | |||
2221 | ||||
2222 | if (cache->abfd != abfd) | |||
2223 | { | |||
2224 | memset (cache->indx, -1, sizeof (cache->indx)); | |||
2225 | cache->abfd = abfd; | |||
2226 | } | |||
2227 | cache->indx[ent] = r_symndx; | |||
2228 | cache->sec[ent] = sec; | |||
2229 | if ((isym.st_shndx != SHN_UNDEF0 && isym.st_shndx < SHN_LORESERVE0xFF00) | |||
2230 | || isym.st_shndx > SHN_HIRESERVE0xFFFF) | |||
2231 | { | |||
2232 | asection *s; | |||
2233 | s = bfd_section_from_elf_index (abfd, isym.st_shndx); | |||
2234 | if (s != NULL((void*)0)) | |||
2235 | cache->sec[ent] = s; | |||
2236 | } | |||
2237 | return cache->sec[ent]; | |||
2238 | } | |||
2239 | ||||
2240 | /* Given an ELF section number, retrieve the corresponding BFD | |||
2241 | section. */ | |||
2242 | ||||
2243 | asection * | |||
2244 | bfd_section_from_elf_index (bfd *abfd, unsigned int index) | |||
2245 | { | |||
2246 | if (index >= elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections)) | |||
2247 | return NULL((void*)0); | |||
2248 | return elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[index]->bfd_section; | |||
2249 | } | |||
2250 | ||||
2251 | static const struct bfd_elf_special_section special_sections_b[] = | |||
2252 | { | |||
2253 | { ".bss", 4, -2, SHT_NOBITS8, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2254 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2255 | }; | |||
2256 | ||||
2257 | static const struct bfd_elf_special_section special_sections_c[] = | |||
2258 | { | |||
2259 | { ".comment", 8, 0, SHT_PROGBITS1, 0 }, | |||
2260 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2261 | }; | |||
2262 | ||||
2263 | static const struct bfd_elf_special_section special_sections_d[] = | |||
2264 | { | |||
2265 | { ".data", 5, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2266 | { ".data1", 6, 0, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2267 | { ".debug", 6, 0, SHT_PROGBITS1, 0 }, | |||
2268 | { ".debug_line", 11, 0, SHT_PROGBITS1, 0 }, | |||
2269 | { ".debug_info", 11, 0, SHT_PROGBITS1, 0 }, | |||
2270 | { ".debug_abbrev", 13, 0, SHT_PROGBITS1, 0 }, | |||
2271 | { ".debug_aranges", 14, 0, SHT_PROGBITS1, 0 }, | |||
2272 | { ".dynamic", 8, 0, SHT_DYNAMIC6, SHF_ALLOC(1 << 1) }, | |||
2273 | { ".dynstr", 7, 0, SHT_STRTAB3, SHF_ALLOC(1 << 1) }, | |||
2274 | { ".dynsym", 7, 0, SHT_DYNSYM11, SHF_ALLOC(1 << 1) }, | |||
2275 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2276 | }; | |||
2277 | ||||
2278 | static const struct bfd_elf_special_section special_sections_f[] = | |||
2279 | { | |||
2280 | { ".fini", 5, 0, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_EXECINSTR(1 << 2) }, | |||
2281 | { ".fini_array", 11, 0, SHT_FINI_ARRAY15, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2282 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2283 | }; | |||
2284 | ||||
2285 | static const struct bfd_elf_special_section special_sections_g[] = | |||
2286 | { | |||
2287 | { ".gnu.linkonce.b",15, -2, SHT_NOBITS8, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2288 | { ".got", 4, 0, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2289 | { ".gnu.version", 12, 0, SHT_GNU_versym0x6fffffff, 0 }, | |||
2290 | { ".gnu.version_d", 14, 0, SHT_GNU_verdef0x6ffffffd, 0 }, | |||
2291 | { ".gnu.version_r", 14, 0, SHT_GNU_verneed0x6ffffffe, 0 }, | |||
2292 | { ".gnu.liblist", 12, 0, SHT_GNU_LIBLIST0x6ffffff7, SHF_ALLOC(1 << 1) }, | |||
2293 | { ".gnu.conflict", 13, 0, SHT_RELA4, SHF_ALLOC(1 << 1) }, | |||
2294 | { ".gnu.hash", 9, 0, SHT_GNU_HASH0x6ffffff6, SHF_ALLOC(1 << 1) }, | |||
2295 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2296 | }; | |||
2297 | ||||
2298 | static const struct bfd_elf_special_section special_sections_h[] = | |||
2299 | { | |||
2300 | { ".hash", 5, 0, SHT_HASH5, SHF_ALLOC(1 << 1) }, | |||
2301 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2302 | }; | |||
2303 | ||||
2304 | static const struct bfd_elf_special_section special_sections_i[] = | |||
2305 | { | |||
2306 | { ".init", 5, 0, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_EXECINSTR(1 << 2) }, | |||
2307 | { ".init_array", 11, 0, SHT_INIT_ARRAY14, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2308 | { ".interp", 7, 0, SHT_PROGBITS1, 0 }, | |||
2309 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2310 | }; | |||
2311 | ||||
2312 | static const struct bfd_elf_special_section special_sections_l[] = | |||
2313 | { | |||
2314 | { ".line", 5, 0, SHT_PROGBITS1, 0 }, | |||
2315 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2316 | }; | |||
2317 | ||||
2318 | static const struct bfd_elf_special_section special_sections_n[] = | |||
2319 | { | |||
2320 | { ".note.GNU-stack",15, 0, SHT_PROGBITS1, 0 }, | |||
2321 | { ".note", 5, -1, SHT_NOTE7, 0 }, | |||
2322 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2323 | }; | |||
2324 | ||||
2325 | static const struct bfd_elf_special_section special_sections_p[] = | |||
2326 | { | |||
2327 | { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY16, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) }, | |||
2328 | { ".plt", 4, 0, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_EXECINSTR(1 << 2) }, | |||
2329 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2330 | }; | |||
2331 | ||||
2332 | static const struct bfd_elf_special_section special_sections_r[] = | |||
2333 | { | |||
2334 | { ".rodata", 7, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) }, | |||
2335 | { ".rodata1", 8, 0, SHT_PROGBITS1, SHF_ALLOC(1 << 1) }, | |||
2336 | { ".rela", 5, -1, SHT_RELA4, 0 }, | |||
2337 | { ".rel", 4, -1, SHT_REL9, 0 }, | |||
2338 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2339 | }; | |||
2340 | ||||
2341 | static const struct bfd_elf_special_section special_sections_s[] = | |||
2342 | { | |||
2343 | { ".shstrtab", 9, 0, SHT_STRTAB3, 0 }, | |||
2344 | { ".strtab", 7, 0, SHT_STRTAB3, 0 }, | |||
2345 | { ".symtab", 7, 0, SHT_SYMTAB2, 0 }, | |||
2346 | { ".stabstr", 5, 3, SHT_STRTAB3, 0 }, | |||
2347 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2348 | }; | |||
2349 | ||||
2350 | static const struct bfd_elf_special_section special_sections_t[] = | |||
2351 | { | |||
2352 | { ".text", 5, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_EXECINSTR(1 << 2) }, | |||
2353 | { ".tbss", 5, -2, SHT_NOBITS8, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) + SHF_TLS(1 << 10) }, | |||
2354 | { ".tdata", 6, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) + SHF_TLS(1 << 10) }, | |||
2355 | { NULL((void*)0), 0, 0, 0, 0 } | |||
2356 | }; | |||
2357 | ||||
2358 | static const struct bfd_elf_special_section *special_sections[] = | |||
2359 | { | |||
2360 | special_sections_b, /* 'b' */ | |||
2361 | special_sections_c, /* 'b' */ | |||
2362 | special_sections_d, /* 'd' */ | |||
2363 | NULL((void*)0), /* 'e' */ | |||
2364 | special_sections_f, /* 'f' */ | |||
2365 | special_sections_g, /* 'g' */ | |||
2366 | special_sections_h, /* 'h' */ | |||
2367 | special_sections_i, /* 'i' */ | |||
2368 | NULL((void*)0), /* 'j' */ | |||
2369 | NULL((void*)0), /* 'k' */ | |||
2370 | special_sections_l, /* 'l' */ | |||
2371 | NULL((void*)0), /* 'm' */ | |||
2372 | special_sections_n, /* 'n' */ | |||
2373 | NULL((void*)0), /* 'o' */ | |||
2374 | special_sections_p, /* 'p' */ | |||
2375 | NULL((void*)0), /* 'q' */ | |||
2376 | special_sections_r, /* 'r' */ | |||
2377 | special_sections_s, /* 's' */ | |||
2378 | special_sections_t, /* 't' */ | |||
2379 | }; | |||
2380 | ||||
2381 | const struct bfd_elf_special_section * | |||
2382 | _bfd_elf_get_special_section (const char *name, | |||
2383 | const struct bfd_elf_special_section *spec, | |||
2384 | unsigned int rela) | |||
2385 | { | |||
2386 | int i; | |||
2387 | int len; | |||
2388 | ||||
2389 | len = strlen (name); | |||
2390 | ||||
2391 | for (i = 0; spec[i].prefix != NULL((void*)0); i++) | |||
2392 | { | |||
2393 | int suffix_len; | |||
2394 | int prefix_len = spec[i].prefix_length; | |||
2395 | ||||
2396 | if (len < prefix_len) | |||
2397 | continue; | |||
2398 | if (memcmp (name, spec[i].prefix, prefix_len) != 0) | |||
2399 | continue; | |||
2400 | ||||
2401 | suffix_len = spec[i].suffix_length; | |||
2402 | if (suffix_len <= 0) | |||
2403 | { | |||
2404 | if (name[prefix_len] != 0) | |||
2405 | { | |||
2406 | if (suffix_len == 0) | |||
2407 | continue; | |||
2408 | if (name[prefix_len] != '.' | |||
2409 | && (suffix_len == -2 | |||
2410 | || (rela && spec[i].type == SHT_REL9))) | |||
2411 | continue; | |||
2412 | } | |||
2413 | } | |||
2414 | else | |||
2415 | { | |||
2416 | if (len < prefix_len + suffix_len) | |||
2417 | continue; | |||
2418 | if (memcmp (name + len - suffix_len, | |||
2419 | spec[i].prefix + prefix_len, | |||
2420 | suffix_len) != 0) | |||
2421 | continue; | |||
2422 | } | |||
2423 | return &spec[i]; | |||
2424 | } | |||
2425 | ||||
2426 | return NULL((void*)0); | |||
2427 | } | |||
2428 | ||||
2429 | const struct bfd_elf_special_section * | |||
2430 | _bfd_elf_get_sec_type_attr (bfd *abfd, asection *sec) | |||
2431 | { | |||
2432 | int i; | |||
2433 | const struct bfd_elf_special_section *spec; | |||
2434 | const struct elf_backend_data *bed; | |||
2435 | ||||
2436 | /* See if this is one of the special sections. */ | |||
2437 | if (sec->name == NULL((void*)0)) | |||
2438 | return NULL((void*)0); | |||
2439 | ||||
2440 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2441 | spec = bed->special_sections; | |||
2442 | if (spec) | |||
2443 | { | |||
2444 | spec = _bfd_elf_get_special_section (sec->name, | |||
2445 | bed->special_sections, | |||
2446 | sec->use_rela_p); | |||
2447 | if (spec != NULL((void*)0)) | |||
2448 | return spec; | |||
2449 | } | |||
2450 | ||||
2451 | if (sec->name[0] != '.') | |||
2452 | return NULL((void*)0); | |||
2453 | ||||
2454 | i = sec->name[1] - 'b'; | |||
2455 | if (i < 0 || i > 't' - 'b') | |||
2456 | return NULL((void*)0); | |||
2457 | ||||
2458 | spec = special_sections[i]; | |||
2459 | ||||
2460 | if (spec == NULL((void*)0)) | |||
2461 | return NULL((void*)0); | |||
2462 | ||||
2463 | return _bfd_elf_get_special_section (sec->name, spec, sec->use_rela_p); | |||
2464 | } | |||
2465 | ||||
2466 | bfd_boolean | |||
2467 | _bfd_elf_new_section_hook (bfd *abfd, asection *sec) | |||
2468 | { | |||
2469 | struct bfd_elf_section_data *sdata; | |||
2470 | const struct elf_backend_data *bed; | |||
2471 | const struct bfd_elf_special_section *ssect; | |||
2472 | ||||
2473 | sdata = (struct bfd_elf_section_data *) sec->used_by_bfd; | |||
2474 | if (sdata == NULL((void*)0)) | |||
2475 | { | |||
2476 | sdata = bfd_zalloc (abfd, sizeof (*sdata)); | |||
2477 | if (sdata == NULL((void*)0)) | |||
2478 | return FALSE0; | |||
2479 | sec->used_by_bfd = sdata; | |||
2480 | } | |||
2481 | ||||
2482 | /* Indicate whether or not this section should use RELA relocations. */ | |||
2483 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2484 | sec->use_rela_p = bed->default_use_rela_p; | |||
2485 | ||||
2486 | /* When we read a file, we don't need section type and flags unless | |||
2487 | it is a linker created section. They will be overridden in | |||
2488 | _bfd_elf_make_section_from_shdr anyway. */ | |||
2489 | if (abfd->direction != read_direction | |||
2490 | || (sec->flags & SEC_LINKER_CREATED0x200000) != 0) | |||
2491 | { | |||
2492 | ssect = (*bed->get_sec_type_attr) (abfd, sec); | |||
2493 | if (ssect != NULL((void*)0)) | |||
2494 | { | |||
2495 | elf_section_type (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->this_hdr .sh_type) = ssect->type; | |||
2496 | elf_section_flags (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->this_hdr .sh_flags) = ssect->attr; | |||
2497 | } | |||
2498 | } | |||
2499 | ||||
2500 | return TRUE1; | |||
2501 | } | |||
2502 | ||||
2503 | /* Create a new bfd section from an ELF program header. | |||
2504 | ||||
2505 | Since program segments have no names, we generate a synthetic name | |||
2506 | of the form segment<NUM>, where NUM is generally the index in the | |||
2507 | program header table. For segments that are split (see below) we | |||
2508 | generate the names segment<NUM>a and segment<NUM>b. | |||
2509 | ||||
2510 | Note that some program segments may have a file size that is different than | |||
2511 | (less than) the memory size. All this means is that at execution the | |||
2512 | system must allocate the amount of memory specified by the memory size, | |||
2513 | but only initialize it with the first "file size" bytes read from the | |||
2514 | file. This would occur for example, with program segments consisting | |||
2515 | of combined data+bss. | |||
2516 | ||||
2517 | To handle the above situation, this routine generates TWO bfd sections | |||
2518 | for the single program segment. The first has the length specified by | |||
2519 | the file size of the segment, and the second has the length specified | |||
2520 | by the difference between the two sizes. In effect, the segment is split | |||
2521 | into it's initialized and uninitialized parts. | |||
2522 | ||||
2523 | */ | |||
2524 | ||||
2525 | bfd_boolean | |||
2526 | _bfd_elf_make_section_from_phdr (bfd *abfd, | |||
2527 | Elf_Internal_Phdr *hdr, | |||
2528 | int index, | |||
2529 | const char *typename) | |||
2530 | { | |||
2531 | asection *newsect; | |||
2532 | char *name; | |||
2533 | char namebuf[64]; | |||
2534 | size_t len; | |||
2535 | int split; | |||
2536 | ||||
2537 | split = ((hdr->p_memsz > 0) | |||
2538 | && (hdr->p_filesz > 0) | |||
2539 | && (hdr->p_memsz > hdr->p_filesz)); | |||
2540 | sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : ""); | |||
2541 | len = strlen (namebuf) + 1; | |||
2542 | name = bfd_alloc (abfd, len); | |||
2543 | if (!name) | |||
2544 | return FALSE0; | |||
2545 | memcpy (name, namebuf, len); | |||
2546 | newsect = bfd_make_section (abfd, name); | |||
2547 | if (newsect == NULL((void*)0)) | |||
2548 | return FALSE0; | |||
2549 | newsect->vma = hdr->p_vaddr; | |||
2550 | newsect->lma = hdr->p_paddr; | |||
2551 | newsect->size = hdr->p_filesz; | |||
2552 | newsect->filepos = hdr->p_offset; | |||
2553 | newsect->flags |= SEC_HAS_CONTENTS0x100; | |||
2554 | newsect->alignment_power = bfd_log2 (hdr->p_align); | |||
2555 | if (hdr->p_type == PT_LOAD1) | |||
2556 | { | |||
2557 | newsect->flags |= SEC_ALLOC0x001; | |||
2558 | newsect->flags |= SEC_LOAD0x002; | |||
2559 | if (hdr->p_flags & PF_X(1 << 0)) | |||
2560 | { | |||
2561 | /* FIXME: all we known is that it has execute PERMISSION, | |||
2562 | may be data. */ | |||
2563 | newsect->flags |= SEC_CODE0x010; | |||
2564 | } | |||
2565 | } | |||
2566 | if (!(hdr->p_flags & PF_W(1 << 1))) | |||
2567 | { | |||
2568 | newsect->flags |= SEC_READONLY0x008; | |||
2569 | } | |||
2570 | ||||
2571 | if (split) | |||
2572 | { | |||
2573 | sprintf (namebuf, "%s%db", typename, index); | |||
2574 | len = strlen (namebuf) + 1; | |||
2575 | name = bfd_alloc (abfd, len); | |||
2576 | if (!name) | |||
2577 | return FALSE0; | |||
2578 | memcpy (name, namebuf, len); | |||
2579 | newsect = bfd_make_section (abfd, name); | |||
2580 | if (newsect == NULL((void*)0)) | |||
2581 | return FALSE0; | |||
2582 | newsect->vma = hdr->p_vaddr + hdr->p_filesz; | |||
2583 | newsect->lma = hdr->p_paddr + hdr->p_filesz; | |||
2584 | newsect->size = hdr->p_memsz - hdr->p_filesz; | |||
2585 | if (hdr->p_type == PT_LOAD1) | |||
2586 | { | |||
2587 | newsect->flags |= SEC_ALLOC0x001; | |||
2588 | if (hdr->p_flags & PF_X(1 << 0)) | |||
2589 | newsect->flags |= SEC_CODE0x010; | |||
2590 | } | |||
2591 | if (!(hdr->p_flags & PF_W(1 << 1))) | |||
2592 | newsect->flags |= SEC_READONLY0x008; | |||
2593 | } | |||
2594 | ||||
2595 | return TRUE1; | |||
2596 | } | |||
2597 | ||||
2598 | bfd_boolean | |||
2599 | bfd_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int index) | |||
2600 | { | |||
2601 | const struct elf_backend_data *bed; | |||
2602 | ||||
2603 | switch (hdr->p_type) | |||
2604 | { | |||
2605 | case PT_NULL0: | |||
2606 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "null"); | |||
2607 | ||||
2608 | case PT_LOAD1: | |||
2609 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "load"); | |||
2610 | ||||
2611 | case PT_DYNAMIC2: | |||
2612 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "dynamic"); | |||
2613 | ||||
2614 | case PT_INTERP3: | |||
2615 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "interp"); | |||
2616 | ||||
2617 | case PT_NOTE4: | |||
2618 | if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note")) | |||
2619 | return FALSE0; | |||
2620 | if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz)) | |||
2621 | return FALSE0; | |||
2622 | return TRUE1; | |||
2623 | ||||
2624 | case PT_SHLIB5: | |||
2625 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "shlib"); | |||
2626 | ||||
2627 | case PT_PHDR6: | |||
2628 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "phdr"); | |||
2629 | ||||
2630 | case PT_GNU_EH_FRAME(0x60000000 + 0x474e550): | |||
2631 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, | |||
2632 | "eh_frame_hdr"); | |||
2633 | ||||
2634 | case PT_GNU_STACK(0x60000000 + 0x474e551): | |||
2635 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "stack"); | |||
2636 | ||||
2637 | case PT_GNU_RELRO(0x60000000 + 0x474e552): | |||
2638 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro"); | |||
2639 | ||||
2640 | case PT_OPENBSD_RANDOMIZE0x65a3dbe6: | |||
2641 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, | |||
2642 | "openbsd_randomize"); | |||
2643 | ||||
2644 | case PT_OPENBSD_WXNEEDED0x65a3dbe7: | |||
2645 | return _bfd_elf_make_section_from_phdr (abfd, hdr, index, | |||
2646 | "openbsd_wxneeded"); | |||
2647 | ||||
2648 | default: | |||
2649 | /* Check for any processor-specific program segment types. */ | |||
2650 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2651 | return bed->elf_backend_section_from_phdr (abfd, hdr, index, "proc"); | |||
2652 | } | |||
2653 | } | |||
2654 | ||||
2655 | /* Initialize REL_HDR, the section-header for new section, containing | |||
2656 | relocations against ASECT. If USE_RELA_P is TRUE, we use RELA | |||
2657 | relocations; otherwise, we use REL relocations. */ | |||
2658 | ||||
2659 | bfd_boolean | |||
2660 | _bfd_elf_init_reloc_shdr (bfd *abfd, | |||
2661 | Elf_Internal_Shdr *rel_hdr, | |||
2662 | asection *asect, | |||
2663 | bfd_boolean use_rela_p) | |||
2664 | { | |||
2665 | char *name; | |||
2666 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2667 | bfd_size_type amt = sizeof ".rela" + strlen (asect->name); | |||
2668 | ||||
2669 | name = bfd_alloc (abfd, amt); | |||
2670 | if (name == NULL((void*)0)) | |||
2671 | return FALSE0; | |||
2672 | sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", asect->name); | |||
2673 | rel_hdr->sh_name = | |||
2674 | (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), name, | |||
2675 | FALSE0); | |||
2676 | if (rel_hdr->sh_name == (unsigned int) -1) | |||
2677 | return FALSE0; | |||
2678 | rel_hdr->sh_type = use_rela_p ? SHT_RELA4 : SHT_REL9; | |||
2679 | rel_hdr->sh_entsize = (use_rela_p | |||
2680 | ? bed->s->sizeof_rela | |||
2681 | : bed->s->sizeof_rel); | |||
2682 | rel_hdr->sh_addralign = 1 << bed->s->log_file_align; | |||
2683 | rel_hdr->sh_flags = 0; | |||
2684 | rel_hdr->sh_addr = 0; | |||
2685 | rel_hdr->sh_size = 0; | |||
2686 | rel_hdr->sh_offset = 0; | |||
2687 | ||||
2688 | return TRUE1; | |||
2689 | } | |||
2690 | ||||
2691 | /* Set up an ELF internal section header for a section. */ | |||
2692 | ||||
2693 | static void | |||
2694 | elf_fake_sections (bfd *abfd, asection *asect, void *failedptrarg) | |||
2695 | { | |||
2696 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2697 | bfd_boolean *failedptr = failedptrarg; | |||
2698 | Elf_Internal_Shdr *this_hdr; | |||
2699 | ||||
2700 | if (*failedptr) | |||
2701 | { | |||
2702 | /* We already failed; just get out of the bfd_map_over_sections | |||
2703 | loop. */ | |||
2704 | return; | |||
2705 | } | |||
2706 | ||||
2707 | this_hdr = &elf_section_data (asect)((struct bfd_elf_section_data*)(asect)->used_by_bfd)->this_hdr; | |||
2708 | ||||
2709 | this_hdr->sh_name = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), | |||
2710 | asect->name, FALSE0); | |||
2711 | if (this_hdr->sh_name == (unsigned int) -1) | |||
2712 | { | |||
2713 | *failedptr = TRUE1; | |||
2714 | return; | |||
2715 | } | |||
2716 | ||||
2717 | /* Don't clear sh_flags. Assembler may set additional bits. */ | |||
2718 | ||||
2719 | if ((asect->flags & SEC_ALLOC0x001) != 0 | |||
2720 | || asect->user_set_vma) | |||
2721 | this_hdr->sh_addr = asect->vma; | |||
2722 | else | |||
2723 | this_hdr->sh_addr = 0; | |||
2724 | ||||
2725 | this_hdr->sh_offset = 0; | |||
2726 | this_hdr->sh_size = asect->size; | |||
2727 | this_hdr->sh_link = 0; | |||
2728 | this_hdr->sh_addralign = 1 << asect->alignment_power; | |||
2729 | /* The sh_entsize and sh_info fields may have been set already by | |||
2730 | copy_private_section_data. */ | |||
2731 | ||||
2732 | this_hdr->bfd_section = asect; | |||
2733 | this_hdr->contents = NULL((void*)0); | |||
2734 | ||||
2735 | /* If the section type is unspecified, we set it based on | |||
2736 | asect->flags. */ | |||
2737 | if (this_hdr->sh_type == SHT_NULL0) | |||
2738 | { | |||
2739 | if ((asect->flags & SEC_GROUP0x4000000) != 0) | |||
2740 | this_hdr->sh_type = SHT_GROUP17; | |||
2741 | else if ((asect->flags & SEC_ALLOC0x001) != 0 | |||
2742 | && (((asect->flags & (SEC_LOAD0x002 | SEC_HAS_CONTENTS0x100)) == 0) | |||
2743 | || (asect->flags & SEC_NEVER_LOAD0x200) != 0)) | |||
2744 | this_hdr->sh_type = SHT_NOBITS8; | |||
2745 | else | |||
2746 | this_hdr->sh_type = SHT_PROGBITS1; | |||
2747 | } | |||
2748 | ||||
2749 | switch (this_hdr->sh_type) | |||
2750 | { | |||
2751 | default: | |||
2752 | break; | |||
2753 | ||||
2754 | case SHT_STRTAB3: | |||
2755 | case SHT_INIT_ARRAY14: | |||
2756 | case SHT_FINI_ARRAY15: | |||
2757 | case SHT_PREINIT_ARRAY16: | |||
2758 | case SHT_NOTE7: | |||
2759 | case SHT_NOBITS8: | |||
2760 | case SHT_PROGBITS1: | |||
2761 | break; | |||
2762 | ||||
2763 | case SHT_HASH5: | |||
2764 | this_hdr->sh_entsize = bed->s->sizeof_hash_entry; | |||
2765 | break; | |||
2766 | ||||
2767 | case SHT_DYNSYM11: | |||
2768 | this_hdr->sh_entsize = bed->s->sizeof_sym; | |||
2769 | break; | |||
2770 | ||||
2771 | case SHT_DYNAMIC6: | |||
2772 | this_hdr->sh_entsize = bed->s->sizeof_dyn; | |||
2773 | break; | |||
2774 | ||||
2775 | case SHT_RELA4: | |||
2776 | if (get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->may_use_rela_p) | |||
2777 | this_hdr->sh_entsize = bed->s->sizeof_rela; | |||
2778 | break; | |||
2779 | ||||
2780 | case SHT_REL9: | |||
2781 | if (get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->may_use_rel_p) | |||
2782 | this_hdr->sh_entsize = bed->s->sizeof_rel; | |||
2783 | break; | |||
2784 | ||||
2785 | case SHT_GNU_versym0x6fffffff: | |||
2786 | this_hdr->sh_entsize = sizeof (Elf_External_Versym); | |||
2787 | break; | |||
2788 | ||||
2789 | case SHT_GNU_verdef0x6ffffffd: | |||
2790 | this_hdr->sh_entsize = 0; | |||
2791 | /* objcopy or strip will copy over sh_info, but may not set | |||
2792 | cverdefs. The linker will set cverdefs, but sh_info will be | |||
2793 | zero. */ | |||
2794 | if (this_hdr->sh_info == 0) | |||
2795 | this_hdr->sh_info = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs; | |||
2796 | else | |||
2797 | BFD_ASSERT (elf_tdata (abfd)->cverdefs == 0do { if (!(((abfd) -> tdata.elf_obj_data)->cverdefs == 0 || this_hdr->sh_info == ((abfd) -> tdata.elf_obj_data) ->cverdefs)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,2798); } while (0) | |||
2798 | || this_hdr->sh_info == elf_tdata (abfd)->cverdefs)do { if (!(((abfd) -> tdata.elf_obj_data)->cverdefs == 0 || this_hdr->sh_info == ((abfd) -> tdata.elf_obj_data) ->cverdefs)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,2798); } while (0); | |||
2799 | break; | |||
2800 | ||||
2801 | case SHT_GNU_verneed0x6ffffffe: | |||
2802 | this_hdr->sh_entsize = 0; | |||
2803 | /* objcopy or strip will copy over sh_info, but may not set | |||
2804 | cverrefs. The linker will set cverrefs, but sh_info will be | |||
2805 | zero. */ | |||
2806 | if (this_hdr->sh_info == 0) | |||
2807 | this_hdr->sh_info = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverrefs; | |||
2808 | else | |||
2809 | BFD_ASSERT (elf_tdata (abfd)->cverrefs == 0do { if (!(((abfd) -> tdata.elf_obj_data)->cverrefs == 0 || this_hdr->sh_info == ((abfd) -> tdata.elf_obj_data) ->cverrefs)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,2810); } while (0) | |||
2810 | || this_hdr->sh_info == elf_tdata (abfd)->cverrefs)do { if (!(((abfd) -> tdata.elf_obj_data)->cverrefs == 0 || this_hdr->sh_info == ((abfd) -> tdata.elf_obj_data) ->cverrefs)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,2810); } while (0); | |||
2811 | break; | |||
2812 | ||||
2813 | case SHT_GROUP17: | |||
2814 | this_hdr->sh_entsize = 4; | |||
2815 | break; | |||
2816 | ||||
2817 | case SHT_GNU_HASH0x6ffffff6: | |||
2818 | this_hdr->sh_entsize = bed->s->arch_size == 64 ? 0 : 4; | |||
2819 | break; | |||
2820 | } | |||
2821 | ||||
2822 | if ((asect->flags & SEC_ALLOC0x001) != 0) | |||
2823 | this_hdr->sh_flags |= SHF_ALLOC(1 << 1); | |||
2824 | if ((asect->flags & SEC_READONLY0x008) == 0) | |||
2825 | this_hdr->sh_flags |= SHF_WRITE(1 << 0); | |||
2826 | if ((asect->flags & SEC_CODE0x010) != 0) | |||
2827 | this_hdr->sh_flags |= SHF_EXECINSTR(1 << 2); | |||
2828 | if ((asect->flags & SEC_MERGE0x1000000) != 0) | |||
2829 | { | |||
2830 | this_hdr->sh_flags |= SHF_MERGE(1 << 4); | |||
2831 | this_hdr->sh_entsize = asect->entsize; | |||
2832 | if ((asect->flags & SEC_STRINGS0x2000000) != 0) | |||
2833 | this_hdr->sh_flags |= SHF_STRINGS(1 << 5); | |||
2834 | } | |||
2835 | if ((asect->flags & SEC_GROUP0x4000000) == 0 && elf_group_name (asect)(((struct bfd_elf_section_data*)(asect)->used_by_bfd)-> group.name) != NULL((void*)0)) | |||
2836 | this_hdr->sh_flags |= SHF_GROUP(1 << 9); | |||
2837 | if ((asect->flags & SEC_THREAD_LOCAL0x400) != 0) | |||
2838 | { | |||
2839 | this_hdr->sh_flags |= SHF_TLS(1 << 10); | |||
2840 | if (asect->size == 0 | |||
2841 | && (asect->flags & SEC_HAS_CONTENTS0x100) == 0) | |||
2842 | { | |||
2843 | struct bfd_link_order *o = asect->map_tail.link_order; | |||
2844 | ||||
2845 | this_hdr->sh_size = 0; | |||
2846 | if (o != NULL((void*)0)) | |||
2847 | { | |||
2848 | this_hdr->sh_size = o->offset + o->size; | |||
2849 | if (this_hdr->sh_size != 0) | |||
2850 | this_hdr->sh_type = SHT_NOBITS8; | |||
2851 | } | |||
2852 | } | |||
2853 | } | |||
2854 | ||||
2855 | /* Check for processor-specific section types. */ | |||
2856 | if (bed->elf_backend_fake_sections | |||
2857 | && !(*bed->elf_backend_fake_sections) (abfd, this_hdr, asect)) | |||
2858 | *failedptr = TRUE1; | |||
2859 | ||||
2860 | /* If the section has relocs, set up a section header for the | |||
2861 | SHT_REL[A] section. If two relocation sections are required for | |||
2862 | this section, it is up to the processor-specific back-end to | |||
2863 | create the other. */ | |||
2864 | if ((asect->flags & SEC_RELOC0x004) != 0 | |||
2865 | && !_bfd_elf_init_reloc_shdr (abfd, | |||
2866 | &elf_section_data (asect)((struct bfd_elf_section_data*)(asect)->used_by_bfd)->rel_hdr, | |||
2867 | asect, | |||
2868 | asect->use_rela_p)) | |||
2869 | *failedptr = TRUE1; | |||
2870 | } | |||
2871 | ||||
2872 | /* Fill in the contents of a SHT_GROUP section. */ | |||
2873 | ||||
2874 | void | |||
2875 | bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg) | |||
2876 | { | |||
2877 | bfd_boolean *failedptr = failedptrarg; | |||
2878 | unsigned long symindx; | |||
2879 | asection *elt, *first; | |||
2880 | unsigned char *loc; | |||
2881 | bfd_boolean gas; | |||
2882 | ||||
2883 | /* Ignore linker created group section. See elfNN_ia64_object_p in | |||
2884 | elfxx-ia64.c. */ | |||
2885 | if (((sec->flags & (SEC_GROUP0x4000000 | SEC_LINKER_CREATED0x200000)) != SEC_GROUP0x4000000) | |||
2886 | || *failedptr) | |||
2887 | return; | |||
2888 | ||||
2889 | symindx = 0; | |||
2890 | if (elf_group_id (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->group .id) != NULL((void*)0)) | |||
2891 | symindx = elf_group_id (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->group .id)->udata.i; | |||
2892 | ||||
2893 | if (symindx == 0) | |||
2894 | { | |||
2895 | /* If called from the assembler, swap_out_syms will have set up | |||
2896 | elf_section_syms; If called for "ld -r", use target_index. */ | |||
2897 | if (elf_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> section_syms) != NULL((void*)0)) | |||
2898 | symindx = elf_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> section_syms)[sec->index]->udata.i; | |||
2899 | else | |||
2900 | symindx = sec->target_index; | |||
2901 | } | |||
2902 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->this_hdr.sh_info = symindx; | |||
2903 | ||||
2904 | /* The contents won't be allocated for "ld -r" or objcopy. */ | |||
2905 | gas = TRUE1; | |||
2906 | if (sec->contents == NULL((void*)0)) | |||
2907 | { | |||
2908 | gas = FALSE0; | |||
2909 | sec->contents = bfd_alloc (abfd, sec->size); | |||
2910 | ||||
2911 | /* Arrange for the section to be written out. */ | |||
2912 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->this_hdr.contents = sec->contents; | |||
2913 | if (sec->contents == NULL((void*)0)) | |||
2914 | { | |||
2915 | *failedptr = TRUE1; | |||
2916 | return; | |||
2917 | } | |||
2918 | } | |||
2919 | ||||
2920 | loc = sec->contents + sec->size; | |||
2921 | ||||
2922 | /* Get the pointer to the first section in the group that gas | |||
2923 | squirreled away here. objcopy arranges for this to be set to the | |||
2924 | start of the input section group. */ | |||
2925 | first = elt = elf_next_in_group (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->next_in_group ); | |||
2926 | ||||
2927 | /* First element is a flag word. Rest of section is elf section | |||
2928 | indices for all the sections of the group. Write them backwards | |||
2929 | just to keep the group in the same order as given in .section | |||
2930 | directives, not that it matters. */ | |||
2931 | while (elt != NULL((void*)0)) | |||
2932 | { | |||
2933 | asection *s; | |||
2934 | unsigned int idx; | |||
2935 | ||||
2936 | loc -= 4; | |||
2937 | s = elt; | |||
2938 | if (!gas) | |||
2939 | s = s->output_section; | |||
2940 | idx = 0; | |||
2941 | if (s != NULL((void*)0)) | |||
2942 | idx = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
2943 | H_PUT_32 (abfd, idx, loc)((*((abfd)->xvec->bfd_h_putx32)) (idx, loc)); | |||
2944 | elt = elf_next_in_group (elt)(((struct bfd_elf_section_data*)(elt)->used_by_bfd)->next_in_group ); | |||
2945 | if (elt == first) | |||
2946 | break; | |||
2947 | } | |||
2948 | ||||
2949 | if ((loc -= 4) != sec->contents) | |||
2950 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c", 2950 , __PRETTY_FUNCTION__); | |||
2951 | ||||
2952 | H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc)((*((abfd)->xvec->bfd_h_putx32)) (sec->flags & 0x20000 ? 0x1 : 0, loc)); | |||
2953 | } | |||
2954 | ||||
2955 | /* Assign all ELF section numbers. The dummy first section is handled here | |||
2956 | too. The link/info pointers for the standard section types are filled | |||
2957 | in here too, while we're at it. */ | |||
2958 | ||||
2959 | static bfd_boolean | |||
2960 | assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) | |||
2961 | { | |||
2962 | struct elf_obj_tdata *t = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data); | |||
2963 | asection *sec; | |||
2964 | unsigned int section_number, secn; | |||
2965 | Elf_Internal_Shdr **i_shdrp; | |||
2966 | struct bfd_elf_section_data *d; | |||
2967 | ||||
2968 | section_number = 1; | |||
2969 | ||||
2970 | _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr)); | |||
2971 | ||||
2972 | /* SHT_GROUP sections are in relocatable files only. */ | |||
2973 | if (link_info == NULL((void*)0) || link_info->relocatable) | |||
2974 | { | |||
2975 | /* Put SHT_GROUP sections first. */ | |||
2976 | for (sec = abfd->sections; sec != NULL((void*)0); sec = sec->next) | |||
2977 | { | |||
2978 | d = elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd); | |||
2979 | ||||
2980 | if (d->this_hdr.sh_type == SHT_GROUP17) | |||
2981 | { | |||
2982 | if (sec->flags & SEC_LINKER_CREATED0x200000) | |||
2983 | { | |||
2984 | /* Remove the linker created SHT_GROUP sections. */ | |||
2985 | bfd_section_list_remove (abfd, sec)do { asection *_s = sec; asection *_next = _s->next; asection *_prev = _s->prev; if (_prev) _prev->next = _next; else (abfd)->sections = _next; if (_next) _next->prev = _prev ; else (abfd)->section_last = _prev; } while (0); | |||
2986 | abfd->section_count--; | |||
2987 | } | |||
2988 | else | |||
2989 | { | |||
2990 | if (section_number == SHN_LORESERVE0xFF00) | |||
2991 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
2992 | d->this_idx = section_number++; | |||
2993 | } | |||
2994 | } | |||
2995 | } | |||
2996 | } | |||
2997 | ||||
2998 | for (sec = abfd->sections; sec; sec = sec->next) | |||
2999 | { | |||
3000 | d = elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd); | |||
3001 | ||||
3002 | if (d->this_hdr.sh_type != SHT_GROUP17) | |||
3003 | { | |||
3004 | if (section_number == SHN_LORESERVE0xFF00) | |||
3005 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3006 | d->this_idx = section_number++; | |||
3007 | } | |||
3008 | _bfd_elf_strtab_addref (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), d->this_hdr.sh_name); | |||
3009 | if ((sec->flags & SEC_RELOC0x004) == 0) | |||
3010 | d->rel_idx = 0; | |||
3011 | else | |||
3012 | { | |||
3013 | if (section_number == SHN_LORESERVE0xFF00) | |||
3014 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3015 | d->rel_idx = section_number++; | |||
3016 | _bfd_elf_strtab_addref (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), d->rel_hdr.sh_name); | |||
3017 | } | |||
3018 | ||||
3019 | if (d->rel_hdr2) | |||
3020 | { | |||
3021 | if (section_number == SHN_LORESERVE0xFF00) | |||
3022 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3023 | d->rel_idx2 = section_number++; | |||
3024 | _bfd_elf_strtab_addref (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), d->rel_hdr2->sh_name); | |||
3025 | } | |||
3026 | else | |||
3027 | d->rel_idx2 = 0; | |||
3028 | } | |||
3029 | ||||
3030 | if (section_number == SHN_LORESERVE0xFF00) | |||
3031 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3032 | t->shstrtab_section = section_number++; | |||
3033 | _bfd_elf_strtab_addref (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), t->shstrtab_hdr.sh_name); | |||
3034 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shstrndx = t->shstrtab_section; | |||
3035 | ||||
3036 | if (bfd_get_symcount (abfd)((abfd)->symcount) > 0) | |||
3037 | { | |||
3038 | if (section_number == SHN_LORESERVE0xFF00) | |||
3039 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3040 | t->symtab_section = section_number++; | |||
3041 | _bfd_elf_strtab_addref (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), t->symtab_hdr.sh_name); | |||
3042 | if (section_number > SHN_LORESERVE0xFF00 - 2) | |||
3043 | { | |||
3044 | if (section_number == SHN_LORESERVE0xFF00) | |||
3045 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3046 | t->symtab_shndx_section = section_number++; | |||
3047 | t->symtab_shndx_hdr.sh_name | |||
3048 | = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), | |||
3049 | ".symtab_shndx", FALSE0); | |||
3050 | if (t->symtab_shndx_hdr.sh_name == (unsigned int) -1) | |||
3051 | return FALSE0; | |||
3052 | } | |||
3053 | if (section_number == SHN_LORESERVE0xFF00) | |||
3054 | section_number += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3055 | t->strtab_section = section_number++; | |||
3056 | _bfd_elf_strtab_addref (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), t->strtab_hdr.sh_name); | |||
3057 | } | |||
3058 | ||||
3059 | _bfd_elf_strtab_finalize (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr)); | |||
3060 | t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr)); | |||
3061 | ||||
3062 | elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections) = section_number; | |||
3063 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shnum = section_number; | |||
3064 | if (section_number > SHN_LORESERVE0xFF00) | |||
3065 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shnum -= SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
3066 | ||||
3067 | /* Set up the list of section header pointers, in agreement with the | |||
3068 | indices. */ | |||
3069 | i_shdrp = bfd_zalloc2 (abfd, section_number, sizeof (Elf_Internal_Shdr *)); | |||
3070 | if (i_shdrp == NULL((void*)0)) | |||
3071 | return FALSE0; | |||
3072 | ||||
3073 | i_shdrp[0] = bfd_zalloc (abfd, sizeof (Elf_Internal_Shdr)); | |||
3074 | if (i_shdrp[0] == NULL((void*)0)) | |||
3075 | { | |||
3076 | bfd_release (abfd, i_shdrp); | |||
3077 | return FALSE0; | |||
3078 | } | |||
3079 | ||||
3080 | elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr) = i_shdrp; | |||
3081 | ||||
3082 | i_shdrp[t->shstrtab_section] = &t->shstrtab_hdr; | |||
3083 | if (bfd_get_symcount (abfd)((abfd)->symcount) > 0) | |||
3084 | { | |||
3085 | i_shdrp[t->symtab_section] = &t->symtab_hdr; | |||
3086 | if (elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections) > SHN_LORESERVE0xFF00) | |||
3087 | { | |||
3088 | i_shdrp[t->symtab_shndx_section] = &t->symtab_shndx_hdr; | |||
3089 | t->symtab_shndx_hdr.sh_link = t->symtab_section; | |||
3090 | } | |||
3091 | i_shdrp[t->strtab_section] = &t->strtab_hdr; | |||
3092 | t->symtab_hdr.sh_link = t->strtab_section; | |||
3093 | } | |||
3094 | ||||
3095 | for (sec = abfd->sections; sec; sec = sec->next) | |||
3096 | { | |||
3097 | struct bfd_elf_section_data *d = elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd); | |||
3098 | asection *s; | |||
3099 | const char *name; | |||
3100 | ||||
3101 | i_shdrp[d->this_idx] = &d->this_hdr; | |||
3102 | if (d->rel_idx != 0) | |||
3103 | i_shdrp[d->rel_idx] = &d->rel_hdr; | |||
3104 | if (d->rel_idx2 != 0) | |||
3105 | i_shdrp[d->rel_idx2] = d->rel_hdr2; | |||
3106 | ||||
3107 | /* Fill in the sh_link and sh_info fields while we're at it. */ | |||
3108 | ||||
3109 | /* sh_link of a reloc section is the section index of the symbol | |||
3110 | table. sh_info is the section index of the section to which | |||
3111 | the relocation entries apply. */ | |||
3112 | if (d->rel_idx != 0) | |||
3113 | { | |||
3114 | d->rel_hdr.sh_link = t->symtab_section; | |||
3115 | d->rel_hdr.sh_info = d->this_idx; | |||
3116 | } | |||
3117 | if (d->rel_idx2 != 0) | |||
3118 | { | |||
3119 | d->rel_hdr2->sh_link = t->symtab_section; | |||
3120 | d->rel_hdr2->sh_info = d->this_idx; | |||
3121 | } | |||
3122 | ||||
3123 | /* We need to set up sh_link for SHF_LINK_ORDER. */ | |||
3124 | if ((d->this_hdr.sh_flags & SHF_LINK_ORDER(1 << 7)) != 0) | |||
3125 | { | |||
3126 | s = elf_linked_to_section (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->linked_to ); | |||
3127 | if (s) | |||
3128 | { | |||
3129 | /* elf_linked_to_section points to the input section. */ | |||
3130 | if (link_info != NULL((void*)0)) | |||
3131 | { | |||
3132 | /* Check discarded linkonce section. */ | |||
3133 | if (elf_discarded_section (s)(!((s) == ((asection *) &bfd_abs_section)) && ((( s)->output_section) == ((asection *) &bfd_abs_section) ) && (s)->sec_info_type != 2 && (s)->sec_info_type != 4)) | |||
3134 | { | |||
3135 | asection *kept; | |||
3136 | (*_bfd_error_handler) | |||
3137 | (_("%B: sh_link of section `%A' points to discarded section `%A' of `%B'")("%B: sh_link of section `%A' points to discarded section `%A' of `%B'" ), | |||
3138 | abfd, d->this_hdr.bfd_section, | |||
3139 | s, s->owner); | |||
3140 | /* Point to the kept section if it has the same | |||
3141 | size as the discarded one. */ | |||
3142 | kept = _bfd_elf_check_kept_section (s, link_info); | |||
3143 | if (kept == NULL((void*)0)) | |||
3144 | { | |||
3145 | bfd_set_error (bfd_error_bad_value); | |||
3146 | return FALSE0; | |||
3147 | } | |||
3148 | s = kept; | |||
3149 | } | |||
3150 | ||||
3151 | s = s->output_section; | |||
3152 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,3152); } while (0); | |||
3153 | } | |||
3154 | else | |||
3155 | { | |||
3156 | /* Handle objcopy. */ | |||
3157 | if (s->output_section == NULL((void*)0)) | |||
3158 | { | |||
3159 | (*_bfd_error_handler) | |||
3160 | (_("%B: sh_link of section `%A' points to removed section `%A' of `%B'")("%B: sh_link of section `%A' points to removed section `%A' of `%B'" ), | |||
3161 | abfd, d->this_hdr.bfd_section, s, s->owner); | |||
3162 | bfd_set_error (bfd_error_bad_value); | |||
3163 | return FALSE0; | |||
3164 | } | |||
3165 | s = s->output_section; | |||
3166 | } | |||
3167 | d->this_hdr.sh_link = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
3168 | } | |||
3169 | else | |||
3170 | { | |||
3171 | /* PR 290: | |||
3172 | The Intel C compiler generates SHT_IA_64_UNWIND with | |||
3173 | SHF_LINK_ORDER. But it doesn't set the sh_link or | |||
3174 | sh_info fields. Hence we could get the situation | |||
3175 | where s is NULL. */ | |||
3176 | const struct elf_backend_data *bed | |||
3177 | = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
3178 | if (bed->link_order_error_handler) | |||
3179 | bed->link_order_error_handler | |||
3180 | (_("%B: warning: sh_link not set for section `%A'")("%B: warning: sh_link not set for section `%A'"), | |||
3181 | abfd, sec); | |||
3182 | } | |||
3183 | } | |||
3184 | ||||
3185 | switch (d->this_hdr.sh_type) | |||
3186 | { | |||
3187 | case SHT_REL9: | |||
3188 | case SHT_RELA4: | |||
3189 | /* A reloc section which we are treating as a normal BFD | |||
3190 | section. sh_link is the section index of the symbol | |||
3191 | table. sh_info is the section index of the section to | |||
3192 | which the relocation entries apply. We assume that an | |||
3193 | allocated reloc section uses the dynamic symbol table. | |||
3194 | FIXME: How can we be sure? */ | |||
3195 | s = bfd_get_section_by_name (abfd, ".dynsym"); | |||
3196 | if (s != NULL((void*)0)) | |||
3197 | d->this_hdr.sh_link = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
3198 | ||||
3199 | /* We look up the section the relocs apply to by name. */ | |||
3200 | name = sec->name; | |||
3201 | if (d->this_hdr.sh_type == SHT_REL9) | |||
3202 | name += 4; | |||
3203 | else | |||
3204 | name += 5; | |||
3205 | s = bfd_get_section_by_name (abfd, name); | |||
3206 | if (s != NULL((void*)0)) | |||
3207 | d->this_hdr.sh_info = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
3208 | break; | |||
3209 | ||||
3210 | case SHT_STRTAB3: | |||
3211 | /* We assume that a section named .stab*str is a stabs | |||
3212 | string section. We look for a section with the same name | |||
3213 | but without the trailing ``str'', and set its sh_link | |||
3214 | field to point to this section. */ | |||
3215 | if (strncmp (sec->name, ".stab", sizeof ".stab" - 1) == 0 | |||
3216 | && strcmp (sec->name + strlen (sec->name) - 3, "str") == 0) | |||
3217 | { | |||
3218 | size_t len; | |||
3219 | char *alc; | |||
3220 | ||||
3221 | len = strlen (sec->name); | |||
3222 | alc = bfd_malloc (len - 2); | |||
3223 | if (alc == NULL((void*)0)) | |||
3224 | return FALSE0; | |||
3225 | memcpy (alc, sec->name, len - 3); | |||
3226 | alc[len - 3] = '\0'; | |||
3227 | s = bfd_get_section_by_name (abfd, alc); | |||
3228 | free (alc); | |||
3229 | if (s != NULL((void*)0)) | |||
3230 | { | |||
3231 | elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_link = d->this_idx; | |||
3232 | ||||
3233 | /* This is a .stab section. */ | |||
3234 | if (elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize == 0) | |||
3235 | elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize | |||
3236 | = 4 + 2 * bfd_get_arch_size (abfd) / 8; | |||
3237 | } | |||
3238 | } | |||
3239 | break; | |||
3240 | ||||
3241 | case SHT_DYNAMIC6: | |||
3242 | case SHT_DYNSYM11: | |||
3243 | case SHT_GNU_verneed0x6ffffffe: | |||
3244 | case SHT_GNU_verdef0x6ffffffd: | |||
3245 | /* sh_link is the section header index of the string table | |||
3246 | used for the dynamic entries, or the symbol table, or the | |||
3247 | version strings. */ | |||
3248 | s = bfd_get_section_by_name (abfd, ".dynstr"); | |||
3249 | if (s != NULL((void*)0)) | |||
3250 | d->this_hdr.sh_link = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
3251 | break; | |||
3252 | ||||
3253 | case SHT_GNU_LIBLIST0x6ffffff7: | |||
3254 | /* sh_link is the section header index of the prelink library | |||
3255 | list | |||
3256 | used for the dynamic entries, or the symbol table, or the | |||
3257 | version strings. */ | |||
3258 | s = bfd_get_section_by_name (abfd, (sec->flags & SEC_ALLOC0x001) | |||
3259 | ? ".dynstr" : ".gnu.libstr"); | |||
3260 | if (s != NULL((void*)0)) | |||
3261 | d->this_hdr.sh_link = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
3262 | break; | |||
3263 | ||||
3264 | case SHT_HASH5: | |||
3265 | case SHT_GNU_HASH0x6ffffff6: | |||
3266 | case SHT_GNU_versym0x6fffffff: | |||
3267 | /* sh_link is the section header index of the symbol table | |||
3268 | this hash table or version table is for. */ | |||
3269 | s = bfd_get_section_by_name (abfd, ".dynsym"); | |||
3270 | if (s != NULL((void*)0)) | |||
3271 | d->this_hdr.sh_link = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_idx; | |||
3272 | break; | |||
3273 | ||||
3274 | case SHT_GROUP17: | |||
3275 | d->this_hdr.sh_link = t->symtab_section; | |||
3276 | } | |||
3277 | } | |||
3278 | ||||
3279 | for (secn = 1; secn < section_number; ++secn) | |||
3280 | if (i_shdrp[secn] == NULL((void*)0)) | |||
3281 | i_shdrp[secn] = i_shdrp[0]; | |||
3282 | else | |||
3283 | i_shdrp[secn]->sh_name = _bfd_elf_strtab_offset (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr), | |||
3284 | i_shdrp[secn]->sh_name); | |||
3285 | return TRUE1; | |||
3286 | } | |||
3287 | ||||
3288 | /* Map symbol from it's internal number to the external number, moving | |||
3289 | all local symbols to be at the head of the list. */ | |||
3290 | ||||
3291 | static int | |||
3292 | sym_is_global (bfd *abfd, asymbol *sym) | |||
3293 | { | |||
3294 | /* If the backend has a special mapping, use it. */ | |||
3295 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
3296 | if (bed->elf_backend_sym_is_global) | |||
3297 | return (*bed->elf_backend_sym_is_global) (abfd, sym); | |||
3298 | ||||
3299 | return ((sym->flags & (BSF_GLOBAL0x02 | BSF_WEAK0x80)) != 0 | |||
3300 | || bfd_is_und_section (bfd_get_section (sym))((((sym)->section)) == ((asection *) &bfd_und_section) ) | |||
3301 | || bfd_is_com_section (bfd_get_section (sym))(((((sym)->section))->flags & 0x1000) != 0)); | |||
3302 | } | |||
3303 | ||||
3304 | static bfd_boolean | |||
3305 | elf_map_symbols (bfd *abfd) | |||
3306 | { | |||
3307 | unsigned int symcount = bfd_get_symcount (abfd)((abfd)->symcount); | |||
3308 | asymbol **syms = bfd_get_outsymbols (abfd)((abfd)->outsymbols); | |||
3309 | asymbol **sect_syms; | |||
3310 | unsigned int num_locals = 0; | |||
3311 | unsigned int num_globals = 0; | |||
3312 | unsigned int num_locals2 = 0; | |||
3313 | unsigned int num_globals2 = 0; | |||
3314 | int max_index = 0; | |||
3315 | unsigned int idx; | |||
3316 | asection *asect; | |||
3317 | asymbol **new_syms; | |||
3318 | ||||
3319 | #ifdef DEBUG | |||
3320 | fprintf (stderr(&__sF[2]), "elf_map_symbols\n"); | |||
3321 | fflush (stderr(&__sF[2])); | |||
3322 | #endif | |||
3323 | ||||
3324 | for (asect = abfd->sections; asect; asect = asect->next) | |||
3325 | { | |||
3326 | if (max_index < asect->index) | |||
3327 | max_index = asect->index; | |||
3328 | } | |||
3329 | ||||
3330 | max_index++; | |||
3331 | sect_syms = bfd_zalloc2 (abfd, max_index, sizeof (asymbol *)); | |||
3332 | if (sect_syms == NULL((void*)0)) | |||
3333 | return FALSE0; | |||
3334 | elf_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> section_syms) = sect_syms; | |||
3335 | elf_num_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> num_section_syms) = max_index; | |||
3336 | ||||
3337 | /* Init sect_syms entries for any section symbols we have already | |||
3338 | decided to output. */ | |||
3339 | for (idx = 0; idx < symcount; idx++) | |||
3340 | { | |||
3341 | asymbol *sym = syms[idx]; | |||
3342 | ||||
3343 | if ((sym->flags & BSF_SECTION_SYM0x100) != 0 | |||
3344 | && sym->value == 0) | |||
3345 | { | |||
3346 | asection *sec; | |||
3347 | ||||
3348 | sec = sym->section; | |||
3349 | ||||
3350 | if (sec->owner != NULL((void*)0)) | |||
3351 | { | |||
3352 | if (sec->owner != abfd) | |||
3353 | { | |||
3354 | if (sec->output_offset != 0) | |||
3355 | continue; | |||
3356 | ||||
3357 | sec = sec->output_section; | |||
3358 | ||||
3359 | /* Empty sections in the input files may have had a | |||
3360 | section symbol created for them. (See the comment | |||
3361 | near the end of _bfd_generic_link_output_symbols in | |||
3362 | linker.c). If the linker script discards such | |||
3363 | sections then we will reach this point. Since we know | |||
3364 | that we cannot avoid this case, we detect it and skip | |||
3365 | the abort and the assignment to the sect_syms array. | |||
3366 | To reproduce this particular case try running the | |||
3367 | linker testsuite test ld-scripts/weak.exp for an ELF | |||
3368 | port that uses the generic linker. */ | |||
3369 | if (sec->owner == NULL((void*)0)) | |||
3370 | continue; | |||
3371 | ||||
3372 | BFD_ASSERT (sec->owner == abfd)do { if (!(sec->owner == abfd)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,3372); } while (0); | |||
3373 | } | |||
3374 | sect_syms[sec->index] = syms[idx]; | |||
3375 | } | |||
3376 | } | |||
3377 | } | |||
3378 | ||||
3379 | /* Classify all of the symbols. */ | |||
3380 | for (idx = 0; idx < symcount; idx++) | |||
3381 | { | |||
3382 | if (!sym_is_global (abfd, syms[idx])) | |||
3383 | num_locals++; | |||
3384 | else | |||
3385 | num_globals++; | |||
3386 | } | |||
3387 | ||||
3388 | /* We will be adding a section symbol for each BFD section. Most normal | |||
3389 | sections will already have a section symbol in outsymbols, but | |||
3390 | eg. SHT_GROUP sections will not, and we need the section symbol mapped | |||
3391 | at least in that case. */ | |||
3392 | for (asect = abfd->sections; asect; asect = asect->next) | |||
3393 | { | |||
3394 | if (sect_syms[asect->index] == NULL((void*)0)) | |||
3395 | { | |||
3396 | if (!sym_is_global (abfd, asect->symbol)) | |||
3397 | num_locals++; | |||
3398 | else | |||
3399 | num_globals++; | |||
3400 | } | |||
3401 | } | |||
3402 | ||||
3403 | /* Now sort the symbols so the local symbols are first. */ | |||
3404 | new_syms = bfd_alloc2 (abfd, num_locals + num_globals, sizeof (asymbol *)); | |||
3405 | ||||
3406 | if (new_syms == NULL((void*)0)) | |||
3407 | return FALSE0; | |||
3408 | ||||
3409 | for (idx = 0; idx < symcount; idx++) | |||
3410 | { | |||
3411 | asymbol *sym = syms[idx]; | |||
3412 | unsigned int i; | |||
3413 | ||||
3414 | if (!sym_is_global (abfd, sym)) | |||
3415 | i = num_locals2++; | |||
3416 | else | |||
3417 | i = num_locals + num_globals2++; | |||
3418 | new_syms[i] = sym; | |||
3419 | sym->udata.i = i + 1; | |||
3420 | } | |||
3421 | for (asect = abfd->sections; asect; asect = asect->next) | |||
3422 | { | |||
3423 | if (sect_syms[asect->index] == NULL((void*)0)) | |||
3424 | { | |||
3425 | asymbol *sym = asect->symbol; | |||
3426 | unsigned int i; | |||
3427 | ||||
3428 | sect_syms[asect->index] = sym; | |||
3429 | if (!sym_is_global (abfd, sym)) | |||
3430 | i = num_locals2++; | |||
3431 | else | |||
3432 | i = num_locals + num_globals2++; | |||
3433 | new_syms[i] = sym; | |||
3434 | sym->udata.i = i + 1; | |||
3435 | } | |||
3436 | } | |||
3437 | ||||
3438 | bfd_set_symtab (abfd, new_syms, num_locals + num_globals); | |||
3439 | ||||
3440 | elf_num_locals (abfd)(((abfd) -> tdata.elf_obj_data) -> num_locals) = num_locals; | |||
3441 | elf_num_globals (abfd)(((abfd) -> tdata.elf_obj_data) -> num_globals) = num_globals; | |||
3442 | return TRUE1; | |||
3443 | } | |||
3444 | ||||
3445 | /* Align to the maximum file alignment that could be required for any | |||
3446 | ELF data structure. */ | |||
3447 | ||||
3448 | static inline file_ptr | |||
3449 | align_file_position (file_ptr off, int align) | |||
3450 | { | |||
3451 | return (off + align - 1) & ~(align - 1); | |||
3452 | } | |||
3453 | ||||
3454 | /* Assign a file position to a section, optionally aligning to the | |||
3455 | required section alignment. */ | |||
3456 | ||||
3457 | file_ptr | |||
3458 | _bfd_elf_assign_file_position_for_section (Elf_Internal_Shdr *i_shdrp, | |||
3459 | file_ptr offset, | |||
3460 | bfd_boolean align) | |||
3461 | { | |||
3462 | if (align) | |||
3463 | { | |||
3464 | unsigned int al; | |||
3465 | ||||
3466 | al = i_shdrp->sh_addralign; | |||
3467 | if (al > 1) | |||
3468 | offset = BFD_ALIGN (offset, al)((((bfd_vma) (offset) + (al) - 1) >= (bfd_vma) (offset)) ? (((bfd_vma) (offset) + ((al) - 1)) & ~ (bfd_vma) ((al)-1 )) : ~ (bfd_vma) 0); | |||
3469 | } | |||
3470 | i_shdrp->sh_offset = offset; | |||
3471 | if (i_shdrp->bfd_section != NULL((void*)0)) | |||
3472 | i_shdrp->bfd_section->filepos = offset; | |||
3473 | if (i_shdrp->sh_type != SHT_NOBITS8) | |||
3474 | offset += i_shdrp->sh_size; | |||
3475 | return offset; | |||
3476 | } | |||
3477 | ||||
3478 | /* Compute the file positions we are going to put the sections at, and | |||
3479 | otherwise prepare to begin writing out the ELF file. If LINK_INFO | |||
3480 | is not NULL, this is being called by the ELF backend linker. */ | |||
3481 | ||||
3482 | bfd_boolean | |||
3483 | _bfd_elf_compute_section_file_positions (bfd *abfd, | |||
3484 | struct bfd_link_info *link_info) | |||
3485 | { | |||
3486 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
3487 | bfd_boolean failed; | |||
3488 | struct bfd_strtab_hash *strtab = NULL((void*)0); | |||
3489 | Elf_Internal_Shdr *shstrtab_hdr; | |||
3490 | ||||
3491 | if (abfd->output_has_begun
| |||
3492 | return TRUE1; | |||
3493 | ||||
3494 | /* Do any elf backend specific processing first. */ | |||
3495 | if (bed->elf_backend_begin_write_processing) | |||
3496 | (*bed->elf_backend_begin_write_processing) (abfd, link_info); | |||
3497 | ||||
3498 | if (! prep_headers (abfd)) | |||
3499 | return FALSE0; | |||
3500 | ||||
3501 | /* Post process the headers if necessary. */ | |||
3502 | if (bed->elf_backend_post_process_headers) | |||
3503 | (*bed->elf_backend_post_process_headers) (abfd, link_info); | |||
3504 | ||||
3505 | failed = FALSE0; | |||
3506 | bfd_map_over_sections (abfd, elf_fake_sections, &failed); | |||
3507 | if (failed) | |||
3508 | return FALSE0; | |||
3509 | ||||
3510 | if (!assign_section_numbers (abfd, link_info)) | |||
3511 | return FALSE0; | |||
3512 | ||||
3513 | /* The backend linker builds symbol table information itself. */ | |||
3514 | if (link_info
| |||
3515 | { | |||
3516 | /* Non-zero if doing a relocatable link. */ | |||
3517 | int relocatable_p = ! (abfd->flags & (EXEC_P0x02 | DYNAMIC0x40)); | |||
3518 | ||||
3519 | if (! swap_out_syms (abfd, &strtab, relocatable_p)) | |||
3520 | return FALSE0; | |||
3521 | } | |||
3522 | ||||
3523 | if (link_info
| |||
3524 | { | |||
3525 | bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed); | |||
3526 | if (failed) | |||
3527 | return FALSE0; | |||
3528 | } | |||
3529 | ||||
3530 | shstrtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_hdr; | |||
3531 | /* sh_name was set in prep_headers. */ | |||
3532 | shstrtab_hdr->sh_type = SHT_STRTAB3; | |||
3533 | shstrtab_hdr->sh_flags = 0; | |||
3534 | shstrtab_hdr->sh_addr = 0; | |||
3535 | shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr)); | |||
3536 | shstrtab_hdr->sh_entsize = 0; | |||
3537 | shstrtab_hdr->sh_link = 0; | |||
3538 | shstrtab_hdr->sh_info = 0; | |||
3539 | /* sh_offset is set in assign_file_positions_except_relocs. */ | |||
3540 | shstrtab_hdr->sh_addralign = 1; | |||
3541 | ||||
3542 | if (!assign_file_positions_except_relocs (abfd, link_info)) | |||
3543 | return FALSE0; | |||
3544 | ||||
3545 | if (link_info == NULL((void*)0) && bfd_get_symcount (abfd)((abfd)->symcount) > 0) | |||
3546 | { | |||
3547 | file_ptr off; | |||
3548 | Elf_Internal_Shdr *hdr; | |||
3549 | ||||
3550 | off = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos; | |||
3551 | ||||
3552 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
3553 | off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE1); | |||
3554 | ||||
3555 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_shndx_hdr; | |||
3556 | if (hdr->sh_size != 0) | |||
3557 | off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE1); | |||
3558 | ||||
3559 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->strtab_hdr; | |||
3560 | off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE1); | |||
3561 | ||||
3562 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos = off; | |||
3563 | ||||
3564 | /* Now that we know where the .strtab section goes, write it | |||
3565 | out. */ | |||
3566 | if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET0) != 0 | |||
3567 | || ! _bfd_stringtab_emit (abfd, strtab)) | |||
3568 | return FALSE0; | |||
3569 | _bfd_stringtab_free (strtab); | |||
3570 | } | |||
3571 | ||||
3572 | abfd->output_has_begun = TRUE1; | |||
3573 | ||||
3574 | return TRUE1; | |||
3575 | } | |||
3576 | ||||
3577 | /* Create a mapping from a set of sections to a program segment. */ | |||
3578 | ||||
3579 | static struct elf_segment_map * | |||
3580 | make_mapping (bfd *abfd, | |||
3581 | asection **sections, | |||
3582 | unsigned int from, | |||
3583 | unsigned int to, | |||
3584 | bfd_boolean phdr) | |||
3585 | { | |||
3586 | struct elf_segment_map *m; | |||
3587 | unsigned int i; | |||
3588 | asection **hdrpp; | |||
3589 | bfd_size_type amt; | |||
3590 | ||||
3591 | amt = sizeof (struct elf_segment_map); | |||
3592 | amt += (to - from - 1) * sizeof (asection *); | |||
3593 | m = bfd_zalloc (abfd, amt); | |||
3594 | if (m == NULL((void*)0)) | |||
3595 | return NULL((void*)0); | |||
3596 | m->next = NULL((void*)0); | |||
3597 | m->p_type = PT_LOAD1; | |||
3598 | for (i = from, hdrpp = sections + from; i < to; i++, hdrpp++) | |||
3599 | m->sections[i - from] = *hdrpp; | |||
3600 | m->count = to - from; | |||
3601 | ||||
3602 | if (from == 0 && phdr) | |||
3603 | { | |||
3604 | /* Include the headers in the first PT_LOAD segment. */ | |||
3605 | m->includes_filehdr = 1; | |||
3606 | m->includes_phdrs = 1; | |||
3607 | } | |||
3608 | ||||
3609 | return m; | |||
3610 | } | |||
3611 | ||||
3612 | /* Create the PT_DYNAMIC segment, which includes DYNSEC. Returns NULL | |||
3613 | on failure. */ | |||
3614 | ||||
3615 | struct elf_segment_map * | |||
3616 | _bfd_elf_make_dynamic_segment (bfd *abfd, asection *dynsec) | |||
3617 | { | |||
3618 | struct elf_segment_map *m; | |||
3619 | ||||
3620 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); | |||
3621 | if (m == NULL((void*)0)) | |||
3622 | return NULL((void*)0); | |||
3623 | m->next = NULL((void*)0); | |||
3624 | m->p_type = PT_DYNAMIC2; | |||
3625 | m->count = 1; | |||
3626 | m->sections[0] = dynsec; | |||
3627 | ||||
3628 | return m; | |||
3629 | } | |||
3630 | ||||
3631 | /* Set up a mapping from BFD sections to program segments. */ | |||
3632 | ||||
3633 | static bfd_boolean | |||
3634 | map_sections_to_segments (bfd *abfd) | |||
3635 | { | |||
3636 | asection **sections = NULL((void*)0); | |||
3637 | asection *s; | |||
3638 | unsigned int i; | |||
3639 | unsigned int count; | |||
3640 | struct elf_segment_map *mfirst; | |||
3641 | struct elf_segment_map **pm; | |||
3642 | struct elf_segment_map *m; | |||
3643 | asection *last_hdr; | |||
3644 | bfd_vma last_size; | |||
3645 | unsigned int phdr_index; | |||
3646 | bfd_vma maxpagesize; | |||
3647 | asection **hdrpp; | |||
3648 | bfd_boolean phdr_in_segment = TRUE1; | |||
3649 | bfd_boolean writable; | |||
3650 | int tls_count = 0; | |||
3651 | asection *first_tls = NULL((void*)0); | |||
3652 | asection *dynsec, *eh_frame_hdr, *randomdata; | |||
3653 | bfd_size_type amt; | |||
3654 | ||||
3655 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map != NULL((void*)0)) | |||
3656 | return TRUE1; | |||
3657 | ||||
3658 | if (bfd_count_sections (abfd)((abfd)->section_count) == 0) | |||
3659 | return TRUE1; | |||
3660 | ||||
3661 | /* Select the allocated sections, and sort them. */ | |||
3662 | ||||
3663 | sections = bfd_malloc2 (bfd_count_sections (abfd)((abfd)->section_count), sizeof (asection *)); | |||
3664 | if (sections == NULL((void*)0)) | |||
3665 | goto error_return; | |||
3666 | ||||
3667 | i = 0; | |||
3668 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
3669 | { | |||
3670 | if ((s->flags & SEC_ALLOC0x001) != 0) | |||
3671 | { | |||
3672 | sections[i] = s; | |||
3673 | ++i; | |||
3674 | } | |||
3675 | } | |||
3676 | BFD_ASSERT (i <= bfd_count_sections (abfd))do { if (!(i <= ((abfd)->section_count))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,3676); } while (0); | |||
3677 | count = i; | |||
3678 | ||||
3679 | qsort (sections, (size_t) count, sizeof (asection *), elf_sort_sections); | |||
3680 | ||||
3681 | /* Build the mapping. */ | |||
3682 | ||||
3683 | mfirst = NULL((void*)0); | |||
3684 | pm = &mfirst; | |||
3685 | ||||
3686 | /* If we have a .interp section, or are creating an executable and | |||
3687 | have a .dynamic section, then create a PT_PHDR segment for the | |||
3688 | program headers. */ | |||
3689 | s = bfd_get_section_by_name (abfd, ".interp"); | |||
3690 | if ((s != NULL((void*)0) && (s->flags & SEC_LOAD0x002) != 0) || | |||
3691 | (bfd_get_section_by_name (abfd, ".dynamic") && | |||
3692 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->executable)) | |||
3693 | { | |||
3694 | amt = sizeof (struct elf_segment_map); | |||
3695 | m = bfd_zalloc (abfd, amt); | |||
3696 | if (m == NULL((void*)0)) | |||
3697 | goto error_return; | |||
3698 | m->next = NULL((void*)0); | |||
3699 | m->p_type = PT_PHDR6; | |||
3700 | /* FIXME: UnixWare and Solaris set PF_X, Irix 5 does not. */ | |||
3701 | m->p_flags = PF_R(1 << 2) | PF_X(1 << 0); | |||
3702 | m->p_flags_valid = 1; | |||
3703 | m->includes_phdrs = 1; | |||
3704 | ||||
3705 | *pm = m; | |||
3706 | pm = &m->next; | |||
3707 | } | |||
3708 | ||||
3709 | /* If we have a .interp section, then create a PT_INTERP segment for | |||
3710 | the .interp section. */ | |||
3711 | if (s != NULL((void*)0) && (s->flags & SEC_LOAD0x002) != 0) | |||
3712 | { | |||
3713 | amt = sizeof (struct elf_segment_map); | |||
3714 | m = bfd_zalloc (abfd, amt); | |||
3715 | if (m == NULL((void*)0)) | |||
3716 | goto error_return; | |||
3717 | m->next = NULL((void*)0); | |||
3718 | m->p_type = PT_INTERP3; | |||
3719 | m->count = 1; | |||
3720 | m->sections[0] = s; | |||
3721 | ||||
3722 | *pm = m; | |||
3723 | pm = &m->next; | |||
3724 | } | |||
3725 | ||||
3726 | /* Look through the sections. We put sections in the same program | |||
3727 | segment when the start of the second section can be placed within | |||
3728 | a few bytes of the end of the first section. */ | |||
3729 | last_hdr = NULL((void*)0); | |||
3730 | last_size = 0; | |||
3731 | phdr_index = 0; | |||
3732 | maxpagesize = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->maxpagesize; | |||
3733 | writable = FALSE0; | |||
3734 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); | |||
3735 | if (dynsec != NULL((void*)0) | |||
3736 | && (dynsec->flags & SEC_LOAD0x002) == 0) | |||
3737 | dynsec = NULL((void*)0); | |||
3738 | ||||
3739 | /* Deal with -Ttext or something similar such that the first section | |||
3740 | is not adjacent to the program headers. This is an | |||
3741 | approximation, since at this point we don't know exactly how many | |||
3742 | program headers we will need. */ | |||
3743 | if (count > 0) | |||
3744 | { | |||
3745 | bfd_size_type phdr_size; | |||
3746 | ||||
3747 | phdr_size = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size; | |||
3748 | if (phdr_size == 0) | |||
3749 | phdr_size = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_phdr; | |||
3750 | if ((abfd->flags & D_PAGED0x100) == 0 | |||
3751 | || sections[0]->lma < phdr_size | |||
3752 | || sections[0]->lma % maxpagesize < phdr_size % maxpagesize) | |||
3753 | phdr_in_segment = FALSE0; | |||
3754 | } | |||
3755 | ||||
3756 | for (i = 0, hdrpp = sections; i < count; i++, hdrpp++) | |||
3757 | { | |||
3758 | asection *hdr; | |||
3759 | bfd_boolean new_segment; | |||
3760 | ||||
3761 | hdr = *hdrpp; | |||
3762 | ||||
3763 | /* See if this section and the last one will fit in the same | |||
3764 | segment. */ | |||
3765 | ||||
3766 | if (last_hdr == NULL((void*)0)) | |||
3767 | { | |||
3768 | /* If we don't have a segment yet, then we don't need a new | |||
3769 | one (we build the last one after this loop). */ | |||
3770 | new_segment = FALSE0; | |||
3771 | } | |||
3772 | else if (last_hdr->lma - last_hdr->vma != hdr->lma - hdr->vma) | |||
3773 | { | |||
3774 | /* If this section has a different relation between the | |||
3775 | virtual address and the load address, then we need a new | |||
3776 | segment. */ | |||
3777 | new_segment = TRUE1; | |||
3778 | } | |||
3779 | else if (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)((((bfd_vma) (last_hdr->lma + last_size) + (maxpagesize) - 1) >= (bfd_vma) (last_hdr->lma + last_size)) ? (((bfd_vma ) (last_hdr->lma + last_size) + ((maxpagesize) - 1)) & ~ (bfd_vma) ((maxpagesize)-1)) : ~ (bfd_vma) 0) | |||
3780 | < BFD_ALIGN (hdr->lma, maxpagesize)((((bfd_vma) (hdr->lma) + (maxpagesize) - 1) >= (bfd_vma ) (hdr->lma)) ? (((bfd_vma) (hdr->lma) + ((maxpagesize) - 1)) & ~ (bfd_vma) ((maxpagesize)-1)) : ~ (bfd_vma) 0)) | |||
3781 | { | |||
3782 | /* If putting this section in this segment would force us to | |||
3783 | skip a page in the segment, then we need a new segment. */ | |||
3784 | new_segment = TRUE1; | |||
3785 | } | |||
3786 | else if ((last_hdr->flags & (SEC_LOAD0x002 | SEC_THREAD_LOCAL0x400)) == 0 | |||
3787 | && (hdr->flags & (SEC_LOAD0x002 | SEC_THREAD_LOCAL0x400)) != 0) | |||
3788 | { | |||
3789 | /* We don't want to put a loadable section after a | |||
3790 | nonloadable section in the same segment. | |||
3791 | Consider .tbss sections as loadable for this purpose. */ | |||
3792 | new_segment = TRUE1; | |||
3793 | } | |||
3794 | else if ((abfd->flags & D_PAGED0x100) == 0) | |||
3795 | { | |||
3796 | /* If the file is not demand paged, which means that we | |||
3797 | don't require the sections to be correctly aligned in the | |||
3798 | file, then there is no other reason for a new segment. */ | |||
3799 | new_segment = FALSE0; | |||
3800 | } | |||
3801 | else if (! writable | |||
3802 | && (hdr->flags & SEC_READONLY0x008) == 0 | |||
3803 | && (((last_hdr->lma + last_size - 1) | |||
3804 | & ~(maxpagesize - 1)) | |||
3805 | != (hdr->lma & ~(maxpagesize - 1)))) | |||
3806 | { | |||
3807 | /* We don't want to put a writable section in a read only | |||
3808 | segment, unless they are on the same page in memory | |||
3809 | anyhow. We already know that the last section does not | |||
3810 | bring us past the current section on the page, so the | |||
3811 | only case in which the new section is not on the same | |||
3812 | page as the previous section is when the previous section | |||
3813 | ends precisely on a page boundary. */ | |||
3814 | new_segment = TRUE1; | |||
3815 | } | |||
3816 | else | |||
3817 | { | |||
3818 | /* Otherwise, we can use the same segment. */ | |||
3819 | new_segment = FALSE0; | |||
3820 | } | |||
3821 | ||||
3822 | if (! new_segment) | |||
3823 | { | |||
3824 | if ((hdr->flags & SEC_READONLY0x008) == 0) | |||
3825 | writable = TRUE1; | |||
3826 | last_hdr = hdr; | |||
3827 | /* .tbss sections effectively have zero size. */ | |||
3828 | if ((hdr->flags & (SEC_THREAD_LOCAL0x400 | SEC_LOAD0x002)) != SEC_THREAD_LOCAL0x400) | |||
3829 | last_size = hdr->size; | |||
3830 | else | |||
3831 | last_size = 0; | |||
3832 | continue; | |||
3833 | } | |||
3834 | ||||
3835 | /* We need a new program segment. We must create a new program | |||
3836 | header holding all the sections from phdr_index until hdr. */ | |||
3837 | ||||
3838 | m = make_mapping (abfd, sections, phdr_index, i, phdr_in_segment); | |||
3839 | if (m == NULL((void*)0)) | |||
3840 | goto error_return; | |||
3841 | ||||
3842 | *pm = m; | |||
3843 | pm = &m->next; | |||
3844 | ||||
3845 | if ((hdr->flags & SEC_READONLY0x008) == 0) | |||
3846 | writable = TRUE1; | |||
3847 | else | |||
3848 | writable = FALSE0; | |||
3849 | ||||
3850 | last_hdr = hdr; | |||
3851 | /* .tbss sections effectively have zero size. */ | |||
3852 | if ((hdr->flags & (SEC_THREAD_LOCAL0x400 | SEC_LOAD0x002)) != SEC_THREAD_LOCAL0x400) | |||
3853 | last_size = hdr->size; | |||
3854 | else | |||
3855 | last_size = 0; | |||
3856 | phdr_index = i; | |||
3857 | phdr_in_segment = FALSE0; | |||
3858 | } | |||
3859 | ||||
3860 | /* Create a final PT_LOAD program segment. */ | |||
3861 | if (last_hdr != NULL((void*)0)) | |||
3862 | { | |||
3863 | m = make_mapping (abfd, sections, phdr_index, i, phdr_in_segment); | |||
3864 | if (m == NULL((void*)0)) | |||
3865 | goto error_return; | |||
3866 | ||||
3867 | *pm = m; | |||
3868 | pm = &m->next; | |||
3869 | } | |||
3870 | ||||
3871 | /* If there is a .dynamic section, throw in a PT_DYNAMIC segment. */ | |||
3872 | if (dynsec != NULL((void*)0)) | |||
3873 | { | |||
3874 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); | |||
3875 | if (m == NULL((void*)0)) | |||
3876 | goto error_return; | |||
3877 | *pm = m; | |||
3878 | pm = &m->next; | |||
3879 | } | |||
3880 | ||||
3881 | /* For each loadable .note section, add a PT_NOTE segment. We don't | |||
3882 | use bfd_get_section_by_name, because if we link together | |||
3883 | nonloadable .note sections and loadable .note sections, we will | |||
3884 | generate two .note sections in the output file. FIXME: Using | |||
3885 | names for section types is bogus anyhow. */ | |||
3886 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
3887 | { | |||
3888 | if ((s->flags & SEC_LOAD0x002) != 0 | |||
3889 | && strncmp (s->name, ".note", 5) == 0) | |||
3890 | { | |||
3891 | amt = sizeof (struct elf_segment_map); | |||
3892 | m = bfd_zalloc (abfd, amt); | |||
3893 | if (m == NULL((void*)0)) | |||
3894 | goto error_return; | |||
3895 | m->next = NULL((void*)0); | |||
3896 | m->p_type = PT_NOTE4; | |||
3897 | m->count = 1; | |||
3898 | m->sections[0] = s; | |||
3899 | ||||
3900 | *pm = m; | |||
3901 | pm = &m->next; | |||
3902 | } | |||
3903 | if (s->flags & SEC_THREAD_LOCAL0x400) | |||
3904 | { | |||
3905 | if (! tls_count) | |||
3906 | first_tls = s; | |||
3907 | tls_count++; | |||
3908 | } | |||
3909 | } | |||
3910 | ||||
3911 | /* If there are any SHF_TLS output sections, add PT_TLS segment. */ | |||
3912 | if (tls_count > 0) | |||
3913 | { | |||
3914 | int i; | |||
3915 | ||||
3916 | amt = sizeof (struct elf_segment_map); | |||
3917 | amt += (tls_count - 1) * sizeof (asection *); | |||
3918 | m = bfd_zalloc (abfd, amt); | |||
3919 | if (m == NULL((void*)0)) | |||
3920 | goto error_return; | |||
3921 | m->next = NULL((void*)0); | |||
3922 | m->p_type = PT_TLS7; | |||
3923 | m->count = tls_count; | |||
3924 | /* Mandated PF_R. */ | |||
3925 | m->p_flags = PF_R(1 << 2); | |||
3926 | m->p_flags_valid = 1; | |||
3927 | for (i = 0; i < tls_count; ++i) | |||
3928 | { | |||
3929 | BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL)do { if (!(first_tls->flags & 0x400)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,3929); } while (0); | |||
3930 | m->sections[i] = first_tls; | |||
3931 | first_tls = first_tls->next; | |||
3932 | } | |||
3933 | ||||
3934 | *pm = m; | |||
3935 | pm = &m->next; | |||
3936 | } | |||
3937 | ||||
3938 | /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME | |||
3939 | segment. */ | |||
3940 | eh_frame_hdr = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->eh_frame_hdr; | |||
3941 | if (eh_frame_hdr != NULL((void*)0) | |||
3942 | && (eh_frame_hdr->output_section->flags & SEC_LOAD0x002) != 0) | |||
3943 | { | |||
3944 | amt = sizeof (struct elf_segment_map); | |||
3945 | m = bfd_zalloc (abfd, amt); | |||
3946 | if (m == NULL((void*)0)) | |||
3947 | goto error_return; | |||
3948 | m->next = NULL((void*)0); | |||
3949 | m->p_type = PT_GNU_EH_FRAME(0x60000000 + 0x474e550); | |||
3950 | m->count = 1; | |||
3951 | m->sections[0] = eh_frame_hdr->output_section; | |||
3952 | ||||
3953 | *pm = m; | |||
3954 | pm = &m->next; | |||
3955 | } | |||
3956 | ||||
3957 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->stack_flags) | |||
3958 | { | |||
3959 | amt = sizeof (struct elf_segment_map); | |||
3960 | m = bfd_zalloc (abfd, amt); | |||
3961 | if (m == NULL((void*)0)) | |||
3962 | goto error_return; | |||
3963 | m->next = NULL((void*)0); | |||
3964 | m->p_type = PT_GNU_STACK(0x60000000 + 0x474e551); | |||
3965 | m->p_flags = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->stack_flags; | |||
3966 | m->p_flags_valid = 1; | |||
3967 | ||||
3968 | *pm = m; | |||
3969 | pm = &m->next; | |||
3970 | } | |||
3971 | ||||
3972 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->wxneeded) | |||
3973 | { | |||
3974 | amt = sizeof (struct elf_segment_map); | |||
3975 | m = bfd_zalloc (abfd, amt); | |||
3976 | if (m == NULL((void*)0)) | |||
3977 | goto error_return; | |||
3978 | m->next = NULL((void*)0); | |||
3979 | m->p_type = PT_OPENBSD_WXNEEDED0x65a3dbe7; | |||
3980 | m->p_flags = 1; | |||
3981 | m->p_flags_valid = 1; | |||
3982 | ||||
3983 | *pm = m; | |||
3984 | pm = &m->next; | |||
3985 | } | |||
3986 | ||||
3987 | /* If there is a .openbsd.randomdata section, throw in a PT_OPENBSD_RANDOMIZE | |||
3988 | segment. */ | |||
3989 | randomdata = bfd_get_section_by_name (abfd, ".openbsd.randomdata"); | |||
3990 | if (randomdata != NULL((void*)0) && (randomdata->flags & SEC_LOAD0x002) != 0) | |||
3991 | { | |||
3992 | amt = sizeof (struct elf_segment_map); | |||
3993 | m = bfd_zalloc (abfd, amt); | |||
3994 | if (m == NULL((void*)0)) | |||
3995 | goto error_return; | |||
3996 | m->next = NULL((void*)0); | |||
3997 | m->p_type = PT_OPENBSD_RANDOMIZE0x65a3dbe6; | |||
3998 | m->count = 1; | |||
3999 | m->sections[0] = randomdata->output_section; | |||
4000 | ||||
4001 | *pm = m; | |||
4002 | pm = &m->next; | |||
4003 | } | |||
4004 | ||||
4005 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->relro) | |||
4006 | { | |||
4007 | amt = sizeof (struct elf_segment_map); | |||
4008 | m = bfd_zalloc (abfd, amt); | |||
4009 | if (m == NULL((void*)0)) | |||
4010 | goto error_return; | |||
4011 | m->next = NULL((void*)0); | |||
4012 | m->p_type = PT_GNU_RELRO(0x60000000 + 0x474e552); | |||
4013 | m->p_flags = PF_R(1 << 2); | |||
4014 | m->p_flags_valid = 1; | |||
4015 | ||||
4016 | *pm = m; | |||
4017 | pm = &m->next; | |||
4018 | } | |||
4019 | ||||
4020 | free (sections); | |||
4021 | sections = NULL((void*)0); | |||
4022 | ||||
4023 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map = mfirst; | |||
4024 | return TRUE1; | |||
4025 | ||||
4026 | error_return: | |||
4027 | if (sections != NULL((void*)0)) | |||
4028 | free (sections); | |||
4029 | return FALSE0; | |||
4030 | } | |||
4031 | ||||
4032 | /* Sort sections by address. */ | |||
4033 | ||||
4034 | static int | |||
4035 | elf_sort_sections (const void *arg1, const void *arg2) | |||
4036 | { | |||
4037 | const asection *sec1 = *(const asection **) arg1; | |||
4038 | const asection *sec2 = *(const asection **) arg2; | |||
4039 | bfd_size_type size1, size2; | |||
4040 | ||||
4041 | /* Sort by LMA first, since this is the address used to | |||
4042 | place the section into a segment. */ | |||
4043 | if (sec1->lma < sec2->lma) | |||
4044 | return -1; | |||
4045 | else if (sec1->lma > sec2->lma) | |||
4046 | return 1; | |||
4047 | ||||
4048 | /* Then sort by VMA. Normally the LMA and the VMA will be | |||
4049 | the same, and this will do nothing. */ | |||
4050 | if (sec1->vma < sec2->vma) | |||
4051 | return -1; | |||
4052 | else if (sec1->vma > sec2->vma) | |||
4053 | return 1; | |||
4054 | ||||
4055 | /* Put !SEC_LOAD sections after SEC_LOAD ones. */ | |||
4056 | ||||
4057 | #define TOEND(x) (((x)->flags & (SEC_LOAD0x002 | SEC_THREAD_LOCAL0x400)) == 0) | |||
4058 | ||||
4059 | if (TOEND (sec1)) | |||
4060 | { | |||
4061 | if (TOEND (sec2)) | |||
4062 | { | |||
4063 | /* If the indicies are the same, do not return 0 | |||
4064 | here, but continue to try the next comparison. */ | |||
4065 | if (sec1->target_index - sec2->target_index != 0) | |||
4066 | return sec1->target_index - sec2->target_index; | |||
4067 | } | |||
4068 | else | |||
4069 | return 1; | |||
4070 | } | |||
4071 | else if (TOEND (sec2)) | |||
4072 | return -1; | |||
4073 | ||||
4074 | #undef TOEND | |||
4075 | ||||
4076 | /* Sort by size, to put zero sized sections | |||
4077 | before others at the same address. */ | |||
4078 | ||||
4079 | size1 = (sec1->flags & SEC_LOAD0x002) ? sec1->size : 0; | |||
4080 | size2 = (sec2->flags & SEC_LOAD0x002) ? sec2->size : 0; | |||
4081 | ||||
4082 | if (size1 < size2) | |||
4083 | return -1; | |||
4084 | if (size1 > size2) | |||
4085 | return 1; | |||
4086 | ||||
4087 | return sec1->target_index - sec2->target_index; | |||
4088 | } | |||
4089 | ||||
4090 | /* Ian Lance Taylor writes: | |||
4091 | ||||
4092 | We shouldn't be using % with a negative signed number. That's just | |||
4093 | not good. We have to make sure either that the number is not | |||
4094 | negative, or that the number has an unsigned type. When the types | |||
4095 | are all the same size they wind up as unsigned. When file_ptr is a | |||
4096 | larger signed type, the arithmetic winds up as signed long long, | |||
4097 | which is wrong. | |||
4098 | ||||
4099 | What we're trying to say here is something like ``increase OFF by | |||
4100 | the least amount that will cause it to be equal to the VMA modulo | |||
4101 | the page size.'' */ | |||
4102 | /* In other words, something like: | |||
4103 | ||||
4104 | vma_offset = m->sections[0]->vma % bed->maxpagesize; | |||
4105 | off_offset = off % bed->maxpagesize; | |||
4106 | if (vma_offset < off_offset) | |||
4107 | adjustment = vma_offset + bed->maxpagesize - off_offset; | |||
4108 | else | |||
4109 | adjustment = vma_offset - off_offset; | |||
4110 | ||||
4111 | which can can be collapsed into the expression below. */ | |||
4112 | ||||
4113 | static file_ptr | |||
4114 | vma_page_aligned_bias (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize) | |||
4115 | { | |||
4116 | return ((vma - off) % maxpagesize); | |||
4117 | } | |||
4118 | ||||
4119 | static void | |||
4120 | print_segment_map (bfd *abfd) | |||
4121 | { | |||
4122 | struct elf_segment_map *m; | |||
4123 | unsigned int i, j; | |||
4124 | ||||
4125 | fprintf (stderr(&__sF[2]), _(" Section to Segment mapping:\n")(" Section to Segment mapping:\n")); | |||
4126 | fprintf (stderr(&__sF[2]), _(" Segment Sections...\n")(" Segment Sections...\n")); | |||
4127 | ||||
4128 | for (i= 0, m = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map; | |||
4129 | m != NULL((void*)0); | |||
4130 | i++, m = m->next) | |||
4131 | { | |||
4132 | const char *pt = get_segment_type (m->p_type); | |||
4133 | char buf[32]; | |||
4134 | ||||
4135 | if (pt == NULL((void*)0)) | |||
4136 | { | |||
4137 | if (m->p_type >= PT_LOPROC0x70000000 && m->p_type <= PT_HIPROC0x7FFFFFFF) | |||
4138 | sprintf (buf, "LOPROC+%7.7x", | |||
4139 | (unsigned int) (m->p_type - PT_LOPROC0x70000000)); | |||
4140 | else if (m->p_type >= PT_LOOS0x60000000 && m->p_type <= PT_HIOS0x6fffffff) | |||
4141 | sprintf (buf, "LOOS+%7.7x", | |||
4142 | (unsigned int) (m->p_type - PT_LOOS0x60000000)); | |||
4143 | else | |||
4144 | snprintf (buf, sizeof (buf), "%8.8x", | |||
4145 | (unsigned int) m->p_type); | |||
4146 | pt = buf; | |||
4147 | } | |||
4148 | fprintf (stderr(&__sF[2]), " %2.2d: %14.14s: ", i, pt); | |||
4149 | for (j = 0; j < m->count; j++) | |||
4150 | fprintf (stderr(&__sF[2]), "%s ", m->sections [j]->name); | |||
4151 | putc ('\n',stderr)(!__isthreaded ? __sputc('\n', (&__sF[2])) : (putc)('\n', (&__sF[2]))); | |||
4152 | } | |||
4153 | } | |||
4154 | ||||
4155 | /* Assign file positions to the sections based on the mapping from | |||
4156 | sections to segments. This function also sets up some fields in | |||
4157 | the file header, and writes out the program headers. */ | |||
4158 | ||||
4159 | static bfd_boolean | |||
4160 | assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info) | |||
4161 | { | |||
4162 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
4163 | unsigned int count; | |||
4164 | struct elf_segment_map *m; | |||
4165 | unsigned int alloc; | |||
4166 | Elf_Internal_Phdr *phdrs; | |||
4167 | file_ptr off, voff; | |||
4168 | bfd_vma filehdr_vaddr, filehdr_paddr; | |||
4169 | bfd_vma phdrs_vaddr, phdrs_paddr; | |||
4170 | Elf_Internal_Phdr *p; | |||
4171 | ||||
4172 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map == NULL((void*)0)) | |||
4173 | { | |||
4174 | if (! map_sections_to_segments (abfd)) | |||
4175 | return FALSE0; | |||
4176 | } | |||
4177 | else | |||
4178 | { | |||
4179 | /* The placement algorithm assumes that non allocated sections are | |||
4180 | not in PT_LOAD segments. We ensure this here by removing such | |||
4181 | sections from the segment map. We also remove excluded | |||
4182 | sections. */ | |||
4183 | for (m = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map; | |||
4184 | m != NULL((void*)0); | |||
4185 | m = m->next) | |||
4186 | { | |||
4187 | unsigned int new_count; | |||
4188 | unsigned int i; | |||
4189 | ||||
4190 | new_count = 0; | |||
4191 | for (i = 0; i < m->count; i ++) | |||
4192 | { | |||
4193 | if ((m->sections[i]->flags & SEC_EXCLUDE0x8000) == 0 | |||
4194 | && ((m->sections[i]->flags & SEC_ALLOC0x001) != 0 | |||
4195 | || m->p_type != PT_LOAD1)) | |||
4196 | { | |||
4197 | if (i != new_count) | |||
4198 | m->sections[new_count] = m->sections[i]; | |||
4199 | ||||
4200 | new_count ++; | |||
4201 | } | |||
4202 | } | |||
4203 | ||||
4204 | if (new_count != m->count) | |||
4205 | m->count = new_count; | |||
4206 | } | |||
4207 | } | |||
4208 | ||||
4209 | if (bed->elf_backend_modify_segment_map) | |||
4210 | { | |||
4211 | if (! (*bed->elf_backend_modify_segment_map) (abfd, link_info)) | |||
4212 | return FALSE0; | |||
4213 | } | |||
4214 | ||||
4215 | count = 0; | |||
4216 | for (m = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map; m != NULL((void*)0); m = m->next) | |||
4217 | ++count; | |||
4218 | ||||
4219 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phoff = bed->s->sizeof_ehdr; | |||
4220 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phentsize = bed->s->sizeof_phdr; | |||
4221 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum = count; | |||
4222 | ||||
4223 | if (count == 0) | |||
4224 | { | |||
4225 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos = bed->s->sizeof_ehdr; | |||
4226 | return TRUE1; | |||
4227 | } | |||
4228 | ||||
4229 | /* If we already counted the number of program segments, make sure | |||
4230 | that we allocated enough space. This happens when SIZEOF_HEADERS | |||
4231 | is used in a linker script. */ | |||
4232 | alloc = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size / bed->s->sizeof_phdr; | |||
4233 | if (alloc != 0 && count > alloc) | |||
4234 | { | |||
4235 | ((*_bfd_error_handler) | |||
4236 | (_("%B: Not enough room for program headers (allocated %u, need %u)")("%B: Not enough room for program headers (allocated %u, need %u)" ), | |||
4237 | abfd, alloc, count)); | |||
4238 | print_segment_map (abfd); | |||
4239 | bfd_set_error (bfd_error_bad_value); | |||
4240 | return FALSE0; | |||
4241 | } | |||
4242 | ||||
4243 | if (alloc == 0) | |||
4244 | alloc = count; | |||
4245 | ||||
4246 | phdrs = bfd_alloc2 (abfd, alloc, sizeof (Elf_Internal_Phdr)); | |||
4247 | if (phdrs == NULL((void*)0)) | |||
4248 | return FALSE0; | |||
4249 | ||||
4250 | off = bed->s->sizeof_ehdr; | |||
4251 | off += alloc * bed->s->sizeof_phdr; | |||
4252 | ||||
4253 | filehdr_vaddr = 0; | |||
4254 | filehdr_paddr = 0; | |||
4255 | phdrs_vaddr = 0; | |||
4256 | phdrs_paddr = 0; | |||
4257 | ||||
4258 | for (m = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map, p = phdrs; | |||
4259 | m != NULL((void*)0); | |||
4260 | m = m->next, p++) | |||
4261 | { | |||
4262 | unsigned int i; | |||
4263 | asection **secpp; | |||
4264 | ||||
4265 | /* If elf_segment_map is not from map_sections_to_segments, the | |||
4266 | sections may not be correctly ordered. NOTE: sorting should | |||
4267 | not be done to the PT_NOTE section of a corefile, which may | |||
4268 | contain several pseudo-sections artificially created by bfd. | |||
4269 | Sorting these pseudo-sections breaks things badly. */ | |||
4270 | if (m->count > 1 | |||
4271 | && !(elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_type == ET_CORE4 | |||
4272 | && m->p_type == PT_NOTE4)) | |||
4273 | qsort (m->sections, (size_t) m->count, sizeof (asection *), | |||
4274 | elf_sort_sections); | |||
4275 | ||||
4276 | /* An ELF segment (described by Elf_Internal_Phdr) may contain a | |||
4277 | number of sections with contents contributing to both p_filesz | |||
4278 | and p_memsz, followed by a number of sections with no contents | |||
4279 | that just contribute to p_memsz. In this loop, OFF tracks next | |||
4280 | available file offset for PT_LOAD and PT_NOTE segments. VOFF is | |||
4281 | an adjustment we use for segments that have no file contents | |||
4282 | but need zero filled memory allocation. */ | |||
4283 | voff = 0; | |||
4284 | p->p_type = m->p_type; | |||
4285 | p->p_flags = m->p_flags; | |||
4286 | ||||
4287 | if (p->p_type == PT_LOAD1 | |||
4288 | && m->count > 0) | |||
4289 | { | |||
4290 | bfd_size_type align; | |||
4291 | bfd_vma adjust; | |||
4292 | unsigned int align_power = 0; | |||
4293 | ||||
4294 | for (i = 0, secpp = m->sections; i < m->count; i++, secpp++) | |||
4295 | { | |||
4296 | unsigned int secalign; | |||
4297 | ||||
4298 | secalign = bfd_get_section_alignment (abfd, *secpp)((*secpp)->alignment_power + 0); | |||
4299 | if (secalign > align_power) | |||
4300 | align_power = secalign; | |||
4301 | } | |||
4302 | align = (bfd_size_type) 1 << align_power; | |||
4303 | ||||
4304 | if ((abfd->flags & D_PAGED0x100) != 0 && bed->maxpagesize > align) | |||
4305 | align = bed->maxpagesize; | |||
4306 | ||||
4307 | adjust = vma_page_aligned_bias (m->sections[0]->vma, off, align); | |||
4308 | off += adjust; | |||
4309 | if (adjust != 0 | |||
4310 | && !m->includes_filehdr | |||
4311 | && !m->includes_phdrs | |||
4312 | && (ufile_ptr) off >= align) | |||
4313 | { | |||
4314 | /* If the first section isn't loadable, the same holds for | |||
4315 | any other sections. Since the segment won't need file | |||
4316 | space, we can make p_offset overlap some prior segment. | |||
4317 | However, .tbss is special. If a segment starts with | |||
4318 | .tbss, we need to look at the next section to decide | |||
4319 | whether the segment has any loadable sections. */ | |||
4320 | i = 0; | |||
4321 | while ((m->sections[i]->flags & SEC_LOAD0x002) == 0) | |||
4322 | { | |||
4323 | if ((m->sections[i]->flags & SEC_THREAD_LOCAL0x400) == 0 | |||
4324 | || ++i >= m->count) | |||
4325 | { | |||
4326 | off -= adjust; | |||
4327 | voff = adjust - align; | |||
4328 | break; | |||
4329 | } | |||
4330 | } | |||
4331 | } | |||
4332 | } | |||
4333 | /* Make sure the .dynamic section is the first section in the | |||
4334 | PT_DYNAMIC segment. */ | |||
4335 | else if (p->p_type == PT_DYNAMIC2 | |||
4336 | && m->count > 1 | |||
4337 | && strcmp (m->sections[0]->name, ".dynamic") != 0) | |||
4338 | { | |||
4339 | _bfd_error_handler | |||
4340 | (_("%B: The first section in the PT_DYNAMIC segment is not the .dynamic section")("%B: The first section in the PT_DYNAMIC segment is not the .dynamic section" ), | |||
4341 | abfd); | |||
4342 | bfd_set_error (bfd_error_bad_value); | |||
4343 | return FALSE0; | |||
4344 | } | |||
4345 | ||||
4346 | if (m->count == 0) | |||
4347 | p->p_vaddr = 0; | |||
4348 | else | |||
4349 | p->p_vaddr = m->sections[0]->vma; | |||
4350 | ||||
4351 | if (m->p_paddr_valid) | |||
4352 | p->p_paddr = m->p_paddr; | |||
4353 | else if (m->count == 0) | |||
4354 | p->p_paddr = 0; | |||
4355 | else | |||
4356 | p->p_paddr = m->sections[0]->lma; | |||
4357 | ||||
4358 | if (p->p_type == PT_LOAD1 | |||
4359 | && (abfd->flags & D_PAGED0x100) != 0) | |||
4360 | p->p_align = bed->maxpagesize; | |||
4361 | else if (m->count == 0) | |||
4362 | p->p_align = 1 << bed->s->log_file_align; | |||
4363 | else | |||
4364 | p->p_align = 0; | |||
4365 | ||||
4366 | p->p_offset = 0; | |||
4367 | p->p_filesz = 0; | |||
4368 | p->p_memsz = 0; | |||
4369 | ||||
4370 | if (m->includes_filehdr) | |||
4371 | { | |||
4372 | if (! m->p_flags_valid) | |||
4373 | p->p_flags |= PF_R(1 << 2); | |||
4374 | p->p_offset = 0; | |||
4375 | p->p_filesz = bed->s->sizeof_ehdr; | |||
4376 | p->p_memsz = bed->s->sizeof_ehdr; | |||
4377 | if (m->count > 0) | |||
4378 | { | |||
4379 | BFD_ASSERT (p->p_type == PT_LOAD)do { if (!(p->p_type == 1)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,4379); } while (0); | |||
4380 | ||||
4381 | if (p->p_vaddr < (bfd_vma) off) | |||
4382 | { | |||
4383 | (*_bfd_error_handler) | |||
4384 | (_("%B: Not enough room for program headers, try linking with -N")("%B: Not enough room for program headers, try linking with -N" ), | |||
4385 | abfd); | |||
4386 | bfd_set_error (bfd_error_bad_value); | |||
4387 | return FALSE0; | |||
4388 | } | |||
4389 | ||||
4390 | p->p_vaddr -= off; | |||
4391 | if (! m->p_paddr_valid) | |||
4392 | p->p_paddr -= off; | |||
4393 | } | |||
4394 | if (p->p_type == PT_LOAD1) | |||
4395 | { | |||
4396 | filehdr_vaddr = p->p_vaddr; | |||
4397 | filehdr_paddr = p->p_paddr; | |||
4398 | } | |||
4399 | } | |||
4400 | ||||
4401 | if (m->includes_phdrs) | |||
4402 | { | |||
4403 | if (! m->p_flags_valid) | |||
4404 | p->p_flags |= PF_R(1 << 2); | |||
4405 | ||||
4406 | if (m->includes_filehdr) | |||
4407 | { | |||
4408 | if (p->p_type == PT_LOAD1) | |||
4409 | { | |||
4410 | phdrs_vaddr = p->p_vaddr + bed->s->sizeof_ehdr; | |||
4411 | phdrs_paddr = p->p_paddr + bed->s->sizeof_ehdr; | |||
4412 | } | |||
4413 | } | |||
4414 | else | |||
4415 | { | |||
4416 | p->p_offset = bed->s->sizeof_ehdr; | |||
4417 | ||||
4418 | if (m->count > 0) | |||
4419 | { | |||
4420 | BFD_ASSERT (p->p_type == PT_LOAD)do { if (!(p->p_type == 1)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,4420); } while (0); | |||
4421 | p->p_vaddr -= off - p->p_offset; | |||
4422 | if (! m->p_paddr_valid) | |||
4423 | p->p_paddr -= off - p->p_offset; | |||
4424 | } | |||
4425 | ||||
4426 | if (p->p_type == PT_LOAD1) | |||
4427 | { | |||
4428 | phdrs_vaddr = p->p_vaddr; | |||
4429 | phdrs_paddr = p->p_paddr; | |||
4430 | } | |||
4431 | else | |||
4432 | phdrs_vaddr = bed->maxpagesize + bed->s->sizeof_ehdr; | |||
4433 | } | |||
4434 | ||||
4435 | p->p_filesz += alloc * bed->s->sizeof_phdr; | |||
4436 | p->p_memsz += alloc * bed->s->sizeof_phdr; | |||
4437 | } | |||
4438 | ||||
4439 | if (p->p_type == PT_LOAD1 | |||
4440 | || (p->p_type == PT_NOTE4 && bfd_get_format (abfd)((abfd)->format) == bfd_core)) | |||
4441 | { | |||
4442 | if (! m->includes_filehdr && ! m->includes_phdrs) | |||
4443 | p->p_offset = off + voff; | |||
4444 | else | |||
4445 | { | |||
4446 | file_ptr adjust; | |||
4447 | ||||
4448 | adjust = off - (p->p_offset + p->p_filesz); | |||
4449 | p->p_filesz += adjust; | |||
4450 | p->p_memsz += adjust; | |||
4451 | } | |||
4452 | } | |||
4453 | ||||
4454 | for (i = 0, secpp = m->sections; i < m->count; i++, secpp++) | |||
4455 | { | |||
4456 | asection *sec; | |||
4457 | flagword flags; | |||
4458 | bfd_size_type align; | |||
4459 | ||||
4460 | sec = *secpp; | |||
4461 | flags = sec->flags; | |||
4462 | align = 1 << bfd_get_section_alignment (abfd, sec)((sec)->alignment_power + 0); | |||
4463 | ||||
4464 | if (p->p_type == PT_LOAD1 | |||
4465 | || p->p_type == PT_TLS7) | |||
4466 | { | |||
4467 | bfd_signed_vma adjust; | |||
4468 | ||||
4469 | if ((flags & SEC_LOAD0x002) != 0) | |||
4470 | { | |||
4471 | adjust = sec->lma - (p->p_paddr + p->p_filesz); | |||
4472 | if (adjust < 0) | |||
4473 | { | |||
4474 | (*_bfd_error_handler) | |||
4475 | (_("%B: section %A lma 0x%lx overlaps previous sections")("%B: section %A lma 0x%lx overlaps previous sections"), | |||
4476 | abfd, sec, (unsigned long) sec->lma); | |||
4477 | adjust = 0; | |||
4478 | } | |||
4479 | off += adjust; | |||
4480 | p->p_filesz += adjust; | |||
4481 | p->p_memsz += adjust; | |||
4482 | } | |||
4483 | /* .tbss is special. It doesn't contribute to p_memsz of | |||
4484 | normal segments. */ | |||
4485 | else if ((flags & SEC_THREAD_LOCAL0x400) == 0 | |||
4486 | || p->p_type == PT_TLS7) | |||
4487 | { | |||
4488 | /* The section VMA must equal the file position | |||
4489 | modulo the page size. */ | |||
4490 | bfd_size_type page = align; | |||
4491 | if ((abfd->flags & D_PAGED0x100) != 0 && bed->maxpagesize > page) | |||
4492 | page = bed->maxpagesize; | |||
4493 | adjust = vma_page_aligned_bias (sec->vma, | |||
4494 | p->p_vaddr + p->p_memsz, | |||
4495 | page); | |||
4496 | p->p_memsz += adjust; | |||
4497 | } | |||
4498 | } | |||
4499 | ||||
4500 | if (p->p_type == PT_NOTE4 && bfd_get_format (abfd)((abfd)->format) == bfd_core) | |||
4501 | { | |||
4502 | /* The section at i == 0 is the one that actually contains | |||
4503 | everything. */ | |||
4504 | if (i == 0) | |||
4505 | { | |||
4506 | sec->filepos = off; | |||
4507 | off += sec->size; | |||
4508 | p->p_filesz = sec->size; | |||
4509 | p->p_memsz = 0; | |||
4510 | p->p_align = 1; | |||
4511 | } | |||
4512 | else | |||
4513 | { | |||
4514 | /* The rest are fake sections that shouldn't be written. */ | |||
4515 | sec->filepos = 0; | |||
4516 | sec->size = 0; | |||
4517 | sec->flags = 0; | |||
4518 | continue; | |||
4519 | } | |||
4520 | } | |||
4521 | else | |||
4522 | { | |||
4523 | if (p->p_type == PT_LOAD1) | |||
4524 | { | |||
4525 | sec->filepos = off; | |||
4526 | /* FIXME: The SEC_HAS_CONTENTS test here dates back to | |||
4527 | 1997, and the exact reason for it isn't clear. One | |||
4528 | plausible explanation is that it is to work around | |||
4529 | a problem we have with linker scripts using data | |||
4530 | statements in NOLOAD sections. I don't think it | |||
4531 | makes a great deal of sense to have such a section | |||
4532 | assigned to a PT_LOAD segment, but apparently | |||
4533 | people do this. The data statement results in a | |||
4534 | bfd_data_link_order being built, and these need | |||
4535 | section contents to write into. Eventually, we get | |||
4536 | to _bfd_elf_write_object_contents which writes any | |||
4537 | section with contents to the output. Make room | |||
4538 | here for the write, so that following segments are | |||
4539 | not trashed. */ | |||
4540 | if ((flags & SEC_LOAD0x002) != 0 | |||
4541 | || (flags & SEC_HAS_CONTENTS0x100) != 0) | |||
4542 | off += sec->size; | |||
4543 | } | |||
4544 | ||||
4545 | if ((flags & SEC_LOAD0x002) != 0) | |||
4546 | { | |||
4547 | p->p_filesz += sec->size; | |||
4548 | p->p_memsz += sec->size; | |||
4549 | } | |||
4550 | /* PR ld/594: Sections in note segments which are not loaded | |||
4551 | contribute to the file size but not the in-memory size. */ | |||
4552 | else if (p->p_type == PT_NOTE4 | |||
4553 | && (flags & SEC_HAS_CONTENTS0x100) != 0) | |||
4554 | p->p_filesz += sec->size; | |||
4555 | ||||
4556 | /* .tbss is special. It doesn't contribute to p_memsz of | |||
4557 | normal segments. */ | |||
4558 | else if ((flags & SEC_THREAD_LOCAL0x400) == 0 | |||
4559 | || p->p_type == PT_TLS7) | |||
4560 | p->p_memsz += sec->size; | |||
4561 | ||||
4562 | if (p->p_type == PT_TLS7 | |||
4563 | && sec->size == 0 | |||
4564 | && (sec->flags & SEC_HAS_CONTENTS0x100) == 0) | |||
4565 | { | |||
4566 | struct bfd_link_order *o = sec->map_tail.link_order; | |||
4567 | if (o != NULL((void*)0)) | |||
4568 | p->p_memsz += o->offset + o->size; | |||
4569 | } | |||
4570 | ||||
4571 | if (align > p->p_align | |||
4572 | && (p->p_type != PT_LOAD1 || (abfd->flags & D_PAGED0x100) == 0)) | |||
4573 | p->p_align = align; | |||
4574 | } | |||
4575 | ||||
4576 | if (! m->p_flags_valid) | |||
4577 | { | |||
4578 | p->p_flags |= PF_R(1 << 2); | |||
4579 | if ((flags & SEC_CODE0x010) != 0) | |||
4580 | p->p_flags |= PF_X(1 << 0); | |||
4581 | if ((flags & SEC_READONLY0x008) == 0) | |||
4582 | p->p_flags |= PF_W(1 << 1); | |||
4583 | } | |||
4584 | } | |||
4585 | } | |||
4586 | ||||
4587 | /* Now that we have set the section file positions, we can set up | |||
4588 | the file positions for the non PT_LOAD segments. */ | |||
4589 | for (m = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map, p = phdrs; | |||
4590 | m != NULL((void*)0); | |||
4591 | m = m->next, p++) | |||
4592 | { | |||
4593 | if (p->p_type != PT_LOAD1 && m->count > 0) | |||
4594 | { | |||
4595 | BFD_ASSERT (! m->includes_filehdr && ! m->includes_phdrs)do { if (!(! m->includes_filehdr && ! m->includes_phdrs )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c", 4595); } while (0); | |||
4596 | /* If the section has not yet been assigned a file position, | |||
4597 | do so now. The ARM BPABI requires that .dynamic section | |||
4598 | not be marked SEC_ALLOC because it is not part of any | |||
4599 | PT_LOAD segment, so it will not be processed above. */ | |||
4600 | if (p->p_type == PT_DYNAMIC2 && m->sections[0]->filepos == 0) | |||
4601 | { | |||
4602 | unsigned int i; | |||
4603 | Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr); | |||
4604 | ||||
4605 | i = 1; | |||
4606 | while (i_shdrpp[i]->bfd_section != m->sections[0]) | |||
4607 | ++i; | |||
4608 | off = (_bfd_elf_assign_file_position_for_section | |||
4609 | (i_shdrpp[i], off, TRUE1)); | |||
4610 | p->p_filesz = m->sections[0]->size; | |||
4611 | } | |||
4612 | p->p_offset = m->sections[0]->filepos; | |||
4613 | } | |||
4614 | if (m->count == 0) | |||
4615 | { | |||
4616 | if (m->includes_filehdr) | |||
4617 | { | |||
4618 | p->p_vaddr = filehdr_vaddr; | |||
4619 | if (! m->p_paddr_valid) | |||
4620 | p->p_paddr = filehdr_paddr; | |||
4621 | } | |||
4622 | else if (m->includes_phdrs) | |||
4623 | { | |||
4624 | p->p_vaddr = phdrs_vaddr; | |||
4625 | if (! m->p_paddr_valid) | |||
4626 | p->p_paddr = phdrs_paddr; | |||
4627 | } | |||
4628 | else if (p->p_type == PT_GNU_RELRO(0x60000000 + 0x474e552)) | |||
4629 | { | |||
4630 | Elf_Internal_Phdr *lp; | |||
4631 | ||||
4632 | for (lp = phdrs; lp < phdrs + count; ++lp) | |||
4633 | { | |||
4634 | if (lp->p_type == PT_LOAD1 | |||
4635 | && lp->p_vaddr <= link_info->relro_end | |||
4636 | && lp->p_vaddr >= link_info->relro_start | |||
4637 | && lp->p_vaddr + lp->p_filesz | |||
4638 | >= link_info->relro_end) | |||
4639 | break; | |||
4640 | } | |||
4641 | ||||
4642 | if (lp < phdrs + count | |||
4643 | && link_info->relro_end > lp->p_vaddr) | |||
4644 | { | |||
4645 | p->p_vaddr = lp->p_vaddr; | |||
4646 | p->p_paddr = lp->p_paddr; | |||
4647 | p->p_offset = lp->p_offset; | |||
4648 | p->p_filesz = link_info->relro_end - lp->p_vaddr; | |||
4649 | p->p_memsz = p->p_filesz; | |||
4650 | p->p_align = 1; | |||
4651 | p->p_flags = (lp->p_flags & ~PF_W(1 << 1)); | |||
4652 | } | |||
4653 | else | |||
4654 | { | |||
4655 | memset (p, 0, sizeof *p); | |||
4656 | p->p_type = PT_NULL0; | |||
4657 | } | |||
4658 | } | |||
4659 | } | |||
4660 | } | |||
4661 | ||||
4662 | /* Clear out any program headers we allocated but did not use. */ | |||
4663 | for (; count < alloc; count++, p++) | |||
4664 | { | |||
4665 | memset (p, 0, sizeof *p); | |||
4666 | p->p_type = PT_NULL0; | |||
4667 | } | |||
4668 | ||||
4669 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->phdr = phdrs; | |||
4670 | ||||
4671 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos = off; | |||
4672 | ||||
4673 | /* Write out the program headers. */ | |||
4674 | if (bfd_seek (abfd, (bfd_signed_vma) bed->s->sizeof_ehdr, SEEK_SET0) != 0 | |||
4675 | || bed->s->write_out_phdrs (abfd, phdrs, alloc) != 0) | |||
4676 | return FALSE0; | |||
4677 | ||||
4678 | return TRUE1; | |||
4679 | } | |||
4680 | ||||
4681 | /* Get the size of the program header. | |||
4682 | ||||
4683 | If this is called by the linker before any of the section VMA's are set, it | |||
4684 | can't calculate the correct value for a strange memory layout. This only | |||
4685 | happens when SIZEOF_HEADERS is used in a linker script. In this case, | |||
4686 | SORTED_HDRS is NULL and we assume the normal scenario of one text and one | |||
4687 | data segment (exclusive of .interp and .dynamic). | |||
4688 | ||||
4689 | ??? User written scripts must either not use SIZEOF_HEADERS, or assume there | |||
4690 | will be two segments. */ | |||
4691 | ||||
4692 | static bfd_size_type | |||
4693 | get_program_header_size (bfd *abfd) | |||
4694 | { | |||
4695 | size_t segs; | |||
4696 | asection *s; | |||
4697 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
4698 | ||||
4699 | /* We can't return a different result each time we're called. */ | |||
4700 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size != 0) | |||
4701 | return elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size; | |||
4702 | ||||
4703 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map != NULL((void*)0)) | |||
4704 | { | |||
4705 | struct elf_segment_map *m; | |||
4706 | ||||
4707 | segs = 0; | |||
4708 | for (m = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->segment_map; m != NULL((void*)0); m = m->next) | |||
4709 | ++segs; | |||
4710 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size = segs * bed->s->sizeof_phdr; | |||
4711 | return elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size; | |||
4712 | } | |||
4713 | ||||
4714 | /* We used to assume that two PT_LOAD segments would be enough, | |||
4715 | code and data, with the change to pad the PLT and GOT, this is no | |||
4716 | longer true. Now there can be several PT_LOAD sections. 7 seems | |||
4717 | to be enough with BSS_PLT and .rodata-X, where we have text, data, | |||
4718 | GOT, dynamic, PLT, bss */ | |||
4719 | segs = 7; | |||
4720 | ||||
4721 | s = bfd_get_section_by_name (abfd, ".interp"); | |||
4722 | s = bfd_get_section_by_name (abfd, ".interp"); | |||
4723 | if ((s != NULL((void*)0) && (s->flags & SEC_LOAD0x002) != 0) || | |||
4724 | (bfd_get_section_by_name (abfd, ".dynamic") && | |||
4725 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->executable)) | |||
4726 | { | |||
4727 | /* We need a PT_PHDR segment. */ | |||
4728 | ++segs; | |||
4729 | } | |||
4730 | ||||
4731 | if (s != NULL((void*)0) && (s->flags & SEC_LOAD0x002) != 0) | |||
4732 | { | |||
4733 | /* If we have a loadable interpreter section, we need a | |||
4734 | PT_INTERP segment. */ | |||
4735 | ++segs; | |||
4736 | } | |||
4737 | ||||
4738 | if (bfd_get_section_by_name (abfd, ".dynamic") != NULL((void*)0)) | |||
4739 | { | |||
4740 | /* We need a PT_DYNAMIC segment. */ | |||
4741 | ++segs; | |||
4742 | } | |||
4743 | ||||
4744 | if (bfd_get_section_by_name (abfd, ".openbsd.randomdata") != NULL((void*)0)) | |||
4745 | { | |||
4746 | /* We need a PT_OPENBSD_RANDOMIZE segment. */ | |||
4747 | ++segs; | |||
4748 | } | |||
4749 | ||||
4750 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->eh_frame_hdr) | |||
4751 | { | |||
4752 | /* We need a PT_GNU_EH_FRAME segment. */ | |||
4753 | ++segs; | |||
4754 | } | |||
4755 | ||||
4756 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->stack_flags) | |||
4757 | { | |||
4758 | /* We need a PT_GNU_STACK segment. */ | |||
4759 | ++segs; | |||
4760 | } | |||
4761 | ||||
4762 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->relro) | |||
4763 | { | |||
4764 | /* We need a PT_GNU_RELRO segment. */ | |||
4765 | ++segs; | |||
4766 | } | |||
4767 | ||||
4768 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->wxneeded) | |||
4769 | { | |||
4770 | /* We need a PT_OPENBSD_WXNEEDED segment. */ | |||
4771 | ++segs; | |||
4772 | } | |||
4773 | ||||
4774 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
4775 | { | |||
4776 | if ((s->flags & SEC_LOAD0x002) != 0 | |||
4777 | && strncmp (s->name, ".note", 5) == 0) | |||
4778 | { | |||
4779 | /* We need a PT_NOTE segment. */ | |||
4780 | ++segs; | |||
4781 | } | |||
4782 | } | |||
4783 | ||||
4784 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
4785 | { | |||
4786 | if (s->flags & SEC_THREAD_LOCAL0x400) | |||
4787 | { | |||
4788 | /* We need a PT_TLS segment. */ | |||
4789 | ++segs; | |||
4790 | break; | |||
4791 | } | |||
4792 | } | |||
4793 | ||||
4794 | /* Let the backend count up any program headers it might need. */ | |||
4795 | if (bed->elf_backend_additional_program_headers) | |||
4796 | { | |||
4797 | int a; | |||
4798 | ||||
4799 | a = (*bed->elf_backend_additional_program_headers) (abfd); | |||
4800 | if (a == -1) | |||
4801 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c", 4801 , __PRETTY_FUNCTION__); | |||
4802 | segs += a; | |||
4803 | } | |||
4804 | ||||
4805 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size = segs * bed->s->sizeof_phdr; | |||
4806 | return elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->program_header_size; | |||
4807 | } | |||
4808 | ||||
4809 | /* Work out the file positions of all the sections. This is called by | |||
4810 | _bfd_elf_compute_section_file_positions. All the section sizes and | |||
4811 | VMAs must be known before this is called. | |||
4812 | ||||
4813 | Reloc sections come in two flavours: Those processed specially as | |||
4814 | "side-channel" data attached to a section to which they apply, and | |||
4815 | those that bfd doesn't process as relocations. The latter sort are | |||
4816 | stored in a normal bfd section by bfd_section_from_shdr. We don't | |||
4817 | consider the former sort here, unless they form part of the loadable | |||
4818 | image. Reloc sections not assigned here will be handled later by | |||
4819 | assign_file_positions_for_relocs. | |||
4820 | ||||
4821 | We also don't set the positions of the .symtab and .strtab here. */ | |||
4822 | ||||
4823 | static bfd_boolean | |||
4824 | assign_file_positions_except_relocs (bfd *abfd, | |||
4825 | struct bfd_link_info *link_info) | |||
4826 | { | |||
4827 | struct elf_obj_tdata * const tdata = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data); | |||
4828 | Elf_Internal_Ehdr * const i_ehdrp = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header); | |||
4829 | Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr); | |||
4830 | unsigned int num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
4831 | file_ptr off; | |||
4832 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
4833 | ||||
4834 | if ((abfd->flags & (EXEC_P0x02 | DYNAMIC0x40)) == 0 | |||
4835 | && bfd_get_format (abfd)((abfd)->format) != bfd_core) | |||
4836 | { | |||
4837 | Elf_Internal_Shdr **hdrpp; | |||
4838 | unsigned int i; | |||
4839 | ||||
4840 | /* Start after the ELF header. */ | |||
4841 | off = i_ehdrp->e_ehsize; | |||
4842 | ||||
4843 | /* We are not creating an executable, which means that we are | |||
4844 | not creating a program header, and that the actual order of | |||
4845 | the sections in the file is unimportant. */ | |||
4846 | for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++) | |||
4847 | { | |||
4848 | Elf_Internal_Shdr *hdr; | |||
4849 | ||||
4850 | hdr = *hdrpp; | |||
4851 | if (((hdr->sh_type == SHT_REL9 || hdr->sh_type == SHT_RELA4) | |||
4852 | && hdr->bfd_section == NULL((void*)0)) | |||
4853 | || i == tdata->symtab_section | |||
4854 | || i == tdata->symtab_shndx_section | |||
4855 | || i == tdata->strtab_section) | |||
4856 | { | |||
4857 | hdr->sh_offset = -1; | |||
4858 | } | |||
4859 | else | |||
4860 | off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE1); | |||
4861 | ||||
4862 | if (i == SHN_LORESERVE0xFF00 - 1) | |||
4863 | { | |||
4864 | i += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
4865 | hdrpp += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
4866 | } | |||
4867 | } | |||
4868 | } | |||
4869 | else | |||
4870 | { | |||
4871 | unsigned int i; | |||
4872 | Elf_Internal_Shdr **hdrpp; | |||
4873 | ||||
4874 | /* Assign file positions for the loaded sections based on the | |||
4875 | assignment of sections to segments. */ | |||
4876 | if (! assign_file_positions_for_segments (abfd, link_info)) | |||
4877 | return FALSE0; | |||
4878 | ||||
4879 | /* Assign file positions for the other sections. */ | |||
4880 | ||||
4881 | off = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos; | |||
4882 | for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++) | |||
4883 | { | |||
4884 | Elf_Internal_Shdr *hdr; | |||
4885 | ||||
4886 | hdr = *hdrpp; | |||
4887 | if (hdr->bfd_section != NULL((void*)0) | |||
4888 | && hdr->bfd_section->filepos != 0) | |||
4889 | hdr->sh_offset = hdr->bfd_section->filepos; | |||
4890 | else if ((hdr->sh_flags & SHF_ALLOC(1 << 1)) != 0) | |||
4891 | { | |||
4892 | if (hdr->bfd_section->size != 0) | |||
| ||||
4893 | { | |||
4894 | ((*_bfd_error_handler) | |||
4895 | (_("%B: warning: allocated section `%s' not in segment")("%B: warning: allocated section `%s' not in segment"), | |||
4896 | abfd, | |||
4897 | (hdr->bfd_section == NULL((void*)0) | |||
4898 | ? "*unknown*" | |||
4899 | : hdr->bfd_section->name))); | |||
4900 | } | |||
4901 | if ((abfd->flags & D_PAGED0x100) != 0) | |||
4902 | off += vma_page_aligned_bias (hdr->sh_addr, off, | |||
4903 | bed->maxpagesize); | |||
4904 | else | |||
4905 | off += vma_page_aligned_bias (hdr->sh_addr, off, | |||
4906 | hdr->sh_addralign); | |||
4907 | off = _bfd_elf_assign_file_position_for_section (hdr, off, | |||
4908 | FALSE0); | |||
4909 | } | |||
4910 | else if (((hdr->sh_type == SHT_REL9 || hdr->sh_type == SHT_RELA4) | |||
4911 | && hdr->bfd_section == NULL((void*)0)) | |||
4912 | || hdr == i_shdrpp[tdata->symtab_section] | |||
4913 | || hdr == i_shdrpp[tdata->symtab_shndx_section] | |||
4914 | || hdr == i_shdrpp[tdata->strtab_section]) | |||
4915 | hdr->sh_offset = -1; | |||
4916 | else | |||
4917 | off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE1); | |||
4918 | ||||
4919 | if (i == SHN_LORESERVE0xFF00 - 1) | |||
4920 | { | |||
4921 | i += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
4922 | hdrpp += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
4923 | } | |||
4924 | } | |||
4925 | } | |||
4926 | ||||
4927 | /* Place the section headers. */ | |||
4928 | off = align_file_position (off, 1 << bed->s->log_file_align); | |||
4929 | i_ehdrp->e_shoff = off; | |||
4930 | off += i_ehdrp->e_shnum * i_ehdrp->e_shentsize; | |||
4931 | ||||
4932 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos = off; | |||
4933 | ||||
4934 | return TRUE1; | |||
4935 | } | |||
4936 | ||||
4937 | static bfd_boolean | |||
4938 | prep_headers (bfd *abfd) | |||
4939 | { | |||
4940 | Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ | |||
4941 | Elf_Internal_Phdr *i_phdrp = 0; /* Program header table, internal form */ | |||
4942 | Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */ | |||
4943 | struct elf_strtab_hash *shstrtab; | |||
4944 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
4945 | ||||
4946 | i_ehdrp = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header); | |||
4947 | i_shdrp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr); | |||
4948 | ||||
4949 | shstrtab = _bfd_elf_strtab_init (); | |||
4950 | if (shstrtab == NULL((void*)0)) | |||
4951 | return FALSE0; | |||
4952 | ||||
4953 | elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr) = shstrtab; | |||
4954 | ||||
4955 | i_ehdrp->e_ident[EI_MAG00] = ELFMAG00x7F; | |||
4956 | i_ehdrp->e_ident[EI_MAG11] = ELFMAG1'E'; | |||
4957 | i_ehdrp->e_ident[EI_MAG22] = ELFMAG2'L'; | |||
4958 | i_ehdrp->e_ident[EI_MAG33] = ELFMAG3'F'; | |||
4959 | ||||
4960 | i_ehdrp->e_ident[EI_CLASS4] = bed->s->elfclass; | |||
4961 | i_ehdrp->e_ident[EI_DATA5] = | |||
4962 | bfd_big_endian (abfd)((abfd)->xvec->byteorder == BFD_ENDIAN_BIG) ? ELFDATA2MSB2 : ELFDATA2LSB1; | |||
4963 | i_ehdrp->e_ident[EI_VERSION6] = bed->s->ev_current; | |||
4964 | ||||
4965 | if ((abfd->flags & DYNAMIC0x40) != 0) | |||
4966 | i_ehdrp->e_type = ET_DYN3; | |||
4967 | else if ((abfd->flags & EXEC_P0x02) != 0) | |||
4968 | i_ehdrp->e_type = ET_EXEC2; | |||
4969 | else if (bfd_get_format (abfd)((abfd)->format) == bfd_core) | |||
4970 | i_ehdrp->e_type = ET_CORE4; | |||
4971 | else | |||
4972 | i_ehdrp->e_type = ET_REL1; | |||
4973 | ||||
4974 | switch (bfd_get_arch (abfd)) | |||
4975 | { | |||
4976 | case bfd_arch_unknown: | |||
4977 | i_ehdrp->e_machine = EM_NONE0; | |||
4978 | break; | |||
4979 | ||||
4980 | /* There used to be a long list of cases here, each one setting | |||
4981 | e_machine to the same EM_* macro #defined as ELF_MACHINE_CODE | |||
4982 | in the corresponding bfd definition. To avoid duplication, | |||
4983 | the switch was removed. Machines that need special handling | |||
4984 | can generally do it in elf_backend_final_write_processing(), | |||
4985 | unless they need the information earlier than the final write. | |||
4986 | Such need can generally be supplied by replacing the tests for | |||
4987 | e_machine with the conditions used to determine it. */ | |||
4988 | default: | |||
4989 | i_ehdrp->e_machine = bed->elf_machine_code; | |||
4990 | } | |||
4991 | ||||
4992 | i_ehdrp->e_version = bed->s->ev_current; | |||
4993 | i_ehdrp->e_ehsize = bed->s->sizeof_ehdr; | |||
4994 | ||||
4995 | /* No program header, for now. */ | |||
4996 | i_ehdrp->e_phoff = 0; | |||
4997 | i_ehdrp->e_phentsize = 0; | |||
4998 | i_ehdrp->e_phnum = 0; | |||
4999 | ||||
5000 | /* Each bfd section is section header entry. */ | |||
5001 | i_ehdrp->e_entry = bfd_get_start_address (abfd)((abfd)->start_address); | |||
5002 | i_ehdrp->e_shentsize = bed->s->sizeof_shdr; | |||
5003 | ||||
5004 | /* If we're building an executable, we'll need a program header table. */ | |||
5005 | if (abfd->flags & EXEC_P0x02) | |||
5006 | /* It all happens later. */ | |||
5007 | ; | |||
5008 | else | |||
5009 | { | |||
5010 | i_ehdrp->e_phentsize = 0; | |||
5011 | i_phdrp = 0; | |||
5012 | i_ehdrp->e_phoff = 0; | |||
5013 | } | |||
5014 | ||||
5015 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr.sh_name = | |||
5016 | (unsigned int) _bfd_elf_strtab_add (shstrtab, ".symtab", FALSE0); | |||
5017 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->strtab_hdr.sh_name = | |||
5018 | (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", FALSE0); | |||
5019 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_hdr.sh_name = | |||
5020 | (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", FALSE0); | |||
5021 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr.sh_name == (unsigned int) -1 | |||
5022 | || elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr.sh_name == (unsigned int) -1 | |||
5023 | || elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_hdr.sh_name == (unsigned int) -1) | |||
5024 | return FALSE0; | |||
5025 | ||||
5026 | return TRUE1; | |||
5027 | } | |||
5028 | ||||
5029 | /* Assign file positions for all the reloc sections which are not part | |||
5030 | of the loadable file image. */ | |||
5031 | ||||
5032 | void | |||
5033 | _bfd_elf_assign_file_positions_for_relocs (bfd *abfd) | |||
5034 | { | |||
5035 | file_ptr off; | |||
5036 | unsigned int i, num_sec; | |||
5037 | Elf_Internal_Shdr **shdrpp; | |||
5038 | ||||
5039 | off = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos; | |||
5040 | ||||
5041 | num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
5042 | for (i = 1, shdrpp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr) + 1; i < num_sec; i++, shdrpp++) | |||
5043 | { | |||
5044 | Elf_Internal_Shdr *shdrp; | |||
5045 | ||||
5046 | shdrp = *shdrpp; | |||
5047 | if ((shdrp->sh_type == SHT_REL9 || shdrp->sh_type == SHT_RELA4) | |||
5048 | && shdrp->sh_offset == -1) | |||
5049 | off = _bfd_elf_assign_file_position_for_section (shdrp, off, TRUE1); | |||
5050 | } | |||
5051 | ||||
5052 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->next_file_pos = off; | |||
5053 | } | |||
5054 | ||||
5055 | bfd_boolean | |||
5056 | _bfd_elf_write_object_contents (bfd *abfd) | |||
5057 | { | |||
5058 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
5059 | Elf_Internal_Ehdr *i_ehdrp; | |||
5060 | Elf_Internal_Shdr **i_shdrp; | |||
5061 | bfd_boolean failed; | |||
5062 | unsigned int count, num_sec; | |||
5063 | ||||
5064 | if (! abfd->output_has_begun | |||
5065 | && ! _bfd_elf_compute_section_file_positions (abfd, NULL((void*)0))) | |||
5066 | return FALSE0; | |||
5067 | ||||
5068 | i_shdrp = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr); | |||
5069 | i_ehdrp = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header); | |||
5070 | ||||
5071 | failed = FALSE0; | |||
5072 | bfd_map_over_sections (abfd, bed->s->write_relocs, &failed); | |||
5073 | if (failed) | |||
5074 | return FALSE0; | |||
5075 | ||||
5076 | _bfd_elf_assign_file_positions_for_relocs (abfd); | |||
5077 | ||||
5078 | /* After writing the headers, we need to write the sections too... */ | |||
5079 | num_sec = elf_numsections (abfd)(((abfd) -> tdata.elf_obj_data) -> num_elf_sections); | |||
5080 | for (count = 1; count < num_sec; count++) | |||
5081 | { | |||
5082 | if (bed->elf_backend_section_processing) | |||
5083 | (*bed->elf_backend_section_processing) (abfd, i_shdrp[count]); | |||
5084 | if (i_shdrp[count]->contents) | |||
5085 | { | |||
5086 | bfd_size_type amt = i_shdrp[count]->sh_size; | |||
5087 | ||||
5088 | if (bfd_seek (abfd, i_shdrp[count]->sh_offset, SEEK_SET0) != 0 | |||
5089 | || bfd_bwrite (i_shdrp[count]->contents, amt, abfd) != amt) | |||
5090 | return FALSE0; | |||
5091 | } | |||
5092 | if (count == SHN_LORESERVE0xFF00 - 1) | |||
5093 | count += SHN_HIRESERVE0xFFFF + 1 - SHN_LORESERVE0xFF00; | |||
5094 | } | |||
5095 | ||||
5096 | /* Write out the section header names. */ | |||
5097 | if (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr) != NULL((void*)0) | |||
5098 | && (bfd_seek (abfd, elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_hdr.sh_offset, SEEK_SET0) != 0 | |||
5099 | || ! _bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr)))) | |||
5100 | return FALSE0; | |||
5101 | ||||
5102 | if (bed->elf_backend_final_write_processing) | |||
5103 | (*bed->elf_backend_final_write_processing) (abfd, | |||
5104 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->linker); | |||
5105 | ||||
5106 | return bed->s->write_shdrs_and_ehdr (abfd); | |||
5107 | } | |||
5108 | ||||
5109 | bfd_boolean | |||
5110 | _bfd_elf_write_corefile_contents (bfd *abfd) | |||
5111 | { | |||
5112 | /* Hopefully this can be done just like an object file. */ | |||
5113 | return _bfd_elf_write_object_contents (abfd); | |||
5114 | } | |||
5115 | ||||
5116 | /* Given a section, search the header to find them. */ | |||
5117 | ||||
5118 | int | |||
5119 | _bfd_elf_section_from_bfd_section (bfd *abfd, struct bfd_section *asect) | |||
5120 | { | |||
5121 | const struct elf_backend_data *bed; | |||
5122 | int index; | |||
5123 | ||||
5124 | if (elf_section_data (asect)((struct bfd_elf_section_data*)(asect)->used_by_bfd) != NULL((void*)0) | |||
5125 | && elf_section_data (asect)((struct bfd_elf_section_data*)(asect)->used_by_bfd)->this_idx != 0) | |||
5126 | return elf_section_data (asect)((struct bfd_elf_section_data*)(asect)->used_by_bfd)->this_idx; | |||
5127 | ||||
5128 | if (bfd_is_abs_section (asect)((asect) == ((asection *) &bfd_abs_section))) | |||
5129 | index = SHN_ABS0xFFF1; | |||
5130 | else if (bfd_is_com_section (asect)(((asect)->flags & 0x1000) != 0)) | |||
5131 | index = SHN_COMMON0xFFF2; | |||
5132 | else if (bfd_is_und_section (asect)((asect) == ((asection *) &bfd_und_section))) | |||
5133 | index = SHN_UNDEF0; | |||
5134 | else | |||
5135 | index = -1; | |||
5136 | ||||
5137 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
5138 | if (bed->elf_backend_section_from_bfd_section) | |||
5139 | { | |||
5140 | int retval = index; | |||
5141 | ||||
5142 | if ((*bed->elf_backend_section_from_bfd_section) (abfd, asect, &retval)) | |||
5143 | return retval; | |||
5144 | } | |||
5145 | ||||
5146 | if (index == -1) | |||
5147 | bfd_set_error (bfd_error_nonrepresentable_section); | |||
5148 | ||||
5149 | return index; | |||
5150 | } | |||
5151 | ||||
5152 | /* Given a BFD symbol, return the index in the ELF symbol table, or -1 | |||
5153 | on error. */ | |||
5154 | ||||
5155 | int | |||
5156 | _bfd_elf_symbol_from_bfd_symbol (bfd *abfd, asymbol **asym_ptr_ptr) | |||
5157 | { | |||
5158 | asymbol *asym_ptr = *asym_ptr_ptr; | |||
5159 | int idx; | |||
5160 | flagword flags = asym_ptr->flags; | |||
5161 | ||||
5162 | /* When gas creates relocations against local labels, it creates its | |||
5163 | own symbol for the section, but does put the symbol into the | |||
5164 | symbol chain, so udata is 0. When the linker is generating | |||
5165 | relocatable output, this section symbol may be for one of the | |||
5166 | input sections rather than the output section. */ | |||
5167 | if (asym_ptr->udata.i == 0 | |||
5168 | && (flags & BSF_SECTION_SYM0x100) | |||
5169 | && asym_ptr->section) | |||
5170 | { | |||
5171 | int indx; | |||
5172 | ||||
5173 | if (asym_ptr->section->output_section != NULL((void*)0)) | |||
5174 | indx = asym_ptr->section->output_section->index; | |||
5175 | else | |||
5176 | indx = asym_ptr->section->index; | |||
5177 | if (indx < elf_num_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> num_section_syms) | |||
5178 | && elf_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> section_syms)[indx] != NULL((void*)0)) | |||
5179 | asym_ptr->udata.i = elf_section_syms (abfd)(((abfd) -> tdata.elf_obj_data) -> section_syms)[indx]->udata.i; | |||
5180 | } | |||
5181 | ||||
5182 | idx = asym_ptr->udata.i; | |||
5183 | ||||
5184 | if (idx == 0) | |||
5185 | { | |||
5186 | /* This case can occur when using --strip-symbol on a symbol | |||
5187 | which is used in a relocation entry. */ | |||
5188 | (*_bfd_error_handler) | |||
5189 | (_("%B: symbol `%s' required but not present")("%B: symbol `%s' required but not present"), | |||
5190 | abfd, bfd_asymbol_name (asym_ptr)((asym_ptr)->name)); | |||
5191 | bfd_set_error (bfd_error_no_symbols); | |||
5192 | return -1; | |||
5193 | } | |||
5194 | ||||
5195 | #if DEBUG & 4 | |||
5196 | { | |||
5197 | fprintf (stderr(&__sF[2]), | |||
5198 | "elf_symbol_from_bfd_symbol 0x%.8lx, name = %s, sym num = %d, flags = 0x%.8lx%s\n", | |||
5199 | (long) asym_ptr, asym_ptr->name, idx, flags, | |||
5200 | elf_symbol_flags (flags)); | |||
5201 | fflush (stderr(&__sF[2])); | |||
5202 | } | |||
5203 | #endif | |||
5204 | ||||
5205 | return idx; | |||
5206 | } | |||
5207 | ||||
5208 | /* Rewrite program header information. */ | |||
5209 | ||||
5210 | static bfd_boolean | |||
5211 | rewrite_elf_program_header (bfd *ibfd, bfd *obfd) | |||
5212 | { | |||
5213 | Elf_Internal_Ehdr *iehdr; | |||
5214 | struct elf_segment_map *map; | |||
5215 | struct elf_segment_map *map_first; | |||
5216 | struct elf_segment_map **pointer_to_map; | |||
5217 | Elf_Internal_Phdr *segment; | |||
5218 | asection *section; | |||
5219 | unsigned int i; | |||
5220 | unsigned int num_segments; | |||
5221 | bfd_boolean phdr_included = FALSE0; | |||
5222 | bfd_vma maxpagesize; | |||
5223 | struct elf_segment_map *phdr_adjust_seg = NULL((void*)0); | |||
5224 | unsigned int phdr_adjust_num = 0; | |||
5225 | const struct elf_backend_data *bed; | |||
5226 | ||||
5227 | bed = get_elf_backend_data (ibfd)((const struct elf_backend_data *) (ibfd)->xvec->backend_data ); | |||
5228 | iehdr = elf_elfheader (ibfd)(((ibfd) -> tdata.elf_obj_data) -> elf_header); | |||
5229 | ||||
5230 | map_first = NULL((void*)0); | |||
5231 | pointer_to_map = &map_first; | |||
5232 | ||||
5233 | num_segments = elf_elfheader (ibfd)(((ibfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; | |||
5234 | maxpagesize = get_elf_backend_data (obfd)((const struct elf_backend_data *) (obfd)->xvec->backend_data )->maxpagesize; | |||
5235 | ||||
5236 | /* Returns the end address of the segment + 1. */ | |||
5237 | #define SEGMENT_END(segment, start) \ | |||
5238 | (start + (segment->p_memsz > segment->p_filesz \ | |||
5239 | ? segment->p_memsz : segment->p_filesz)) | |||
5240 | ||||
5241 | #define SECTION_SIZE(section, segment) \ | |||
5242 | (((section->flags & (SEC_HAS_CONTENTS0x100 | SEC_THREAD_LOCAL0x400)) \ | |||
5243 | != SEC_THREAD_LOCAL0x400 || segment->p_type == PT_TLS7) \ | |||
5244 | ? section->size : 0) | |||
5245 | ||||
5246 | /* Returns TRUE if the given section is contained within | |||
5247 | the given segment. VMA addresses are compared. */ | |||
5248 | #define IS_CONTAINED_BY_VMA(section, segment) \ | |||
5249 | (section->vma >= segment->p_vaddr \ | |||
5250 | && (section->vma + SECTION_SIZE (section, segment) \ | |||
5251 | <= (SEGMENT_END (segment, segment->p_vaddr)))) | |||
5252 | ||||
5253 | /* Returns TRUE if the given section is contained within | |||
5254 | the given segment. LMA addresses are compared. */ | |||
5255 | #define IS_CONTAINED_BY_LMA(section, segment, base) \ | |||
5256 | (section->lma >= base \ | |||
5257 | && (section->lma + SECTION_SIZE (section, segment) \ | |||
5258 | <= SEGMENT_END (segment, base))) | |||
5259 | ||||
5260 | /* Special case: corefile "NOTE" section containing regs, prpsinfo etc. */ | |||
5261 | #define IS_COREFILE_NOTE(p, s) \ | |||
5262 | (p->p_type == PT_NOTE4 \ | |||
5263 | && bfd_get_format (ibfd)((ibfd)->format) == bfd_core \ | |||
5264 | && s->vma == 0 && s->lma == 0 \ | |||
5265 | && (bfd_vma) s->filepos >= p->p_offset \ | |||
5266 | && ((bfd_vma) s->filepos + s->size \ | |||
5267 | <= p->p_offset + p->p_filesz)) | |||
5268 | ||||
5269 | /* The complicated case when p_vaddr is 0 is to handle the Solaris | |||
5270 | linker, which generates a PT_INTERP section with p_vaddr and | |||
5271 | p_memsz set to 0. */ | |||
5272 | #define IS_SOLARIS_PT_INTERP(p, s) \ | |||
5273 | (p->p_vaddr == 0 \ | |||
5274 | && p->p_paddr == 0 \ | |||
5275 | && p->p_memsz == 0 \ | |||
5276 | && p->p_filesz > 0 \ | |||
5277 | && (s->flags & SEC_HAS_CONTENTS0x100) != 0 \ | |||
5278 | && s->size > 0 \ | |||
5279 | && (bfd_vma) s->filepos >= p->p_offset \ | |||
5280 | && ((bfd_vma) s->filepos + s->size \ | |||
5281 | <= p->p_offset + p->p_filesz)) | |||
5282 | ||||
5283 | /* Decide if the given section should be included in the given segment. | |||
5284 | A section will be included if: | |||
5285 | 1. It is within the address space of the segment -- we use the LMA | |||
5286 | if that is set for the segment and the VMA otherwise, | |||
5287 | 2. It is an allocated segment, | |||
5288 | 3. There is an output section associated with it, | |||
5289 | 4. The section has not already been allocated to a previous segment. | |||
5290 | 5. PT_GNU_STACK segments do not include any sections. | |||
5291 | 6. PT_TLS segment includes only SHF_TLS sections. | |||
5292 | 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments. | |||
5293 | 8. PT_DYNAMIC should not contain empty sections at the beginning | |||
5294 | (with the possible exception of .dynamic). */ | |||
5295 | #define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed) \ | |||
5296 | ((((segment->p_paddr \ | |||
5297 | ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \ | |||
5298 | : IS_CONTAINED_BY_VMA (section, segment)) \ | |||
5299 | && (section->flags & SEC_ALLOC0x001) != 0) \ | |||
5300 | || IS_COREFILE_NOTE (segment, section)) \ | |||
5301 | && section->output_section != NULL((void*)0) \ | |||
5302 | && segment->p_type != PT_GNU_STACK(0x60000000 + 0x474e551) \ | |||
5303 | && (segment->p_type != PT_TLS7 \ | |||
5304 | || (section->flags & SEC_THREAD_LOCAL0x400)) \ | |||
5305 | && (segment->p_type == PT_LOAD1 \ | |||
5306 | || segment->p_type == PT_TLS7 \ | |||
5307 | || (section->flags & SEC_THREAD_LOCAL0x400) == 0) \ | |||
5308 | && (segment->p_type != PT_DYNAMIC2 \ | |||
5309 | || SECTION_SIZE (section, segment) > 0 \ | |||
5310 | || (segment->p_paddr \ | |||
5311 | ? segment->p_paddr != section->lma \ | |||
5312 | : segment->p_vaddr != section->vma) \ | |||
5313 | || (strcmp (bfd_get_section_name (ibfd, section)((section)->name + 0), ".dynamic") \ | |||
5314 | == 0)) \ | |||
5315 | && ! section->segment_mark) | |||
5316 | ||||
5317 | /* Returns TRUE iff seg1 starts after the end of seg2. */ | |||
5318 | #define SEGMENT_AFTER_SEGMENT(seg1, seg2, field) \ | |||
5319 | (seg1->field >= SEGMENT_END (seg2, seg2->field)) | |||
5320 | ||||
5321 | /* Returns TRUE iff seg1 and seg2 overlap. Segments overlap iff both | |||
5322 | their VMA address ranges and their LMA address ranges overlap. | |||
5323 | It is possible to have overlapping VMA ranges without overlapping LMA | |||
5324 | ranges. RedBoot images for example can have both .data and .bss mapped | |||
5325 | to the same VMA range, but with the .data section mapped to a different | |||
5326 | LMA. */ | |||
5327 | #define SEGMENT_OVERLAPS(seg1, seg2) \ | |||
5328 | ( !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_vaddr) \ | |||
5329 | || SEGMENT_AFTER_SEGMENT (seg2, seg1, p_vaddr)) \ | |||
5330 | && !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_paddr) \ | |||
5331 | || SEGMENT_AFTER_SEGMENT (seg2, seg1, p_paddr))) | |||
5332 | ||||
5333 | /* Initialise the segment mark field. */ | |||
5334 | for (section = ibfd->sections; section != NULL((void*)0); section = section->next) | |||
5335 | section->segment_mark = FALSE0; | |||
5336 | ||||
5337 | /* Scan through the segments specified in the program header | |||
5338 | of the input BFD. For this first scan we look for overlaps | |||
5339 | in the loadable segments. These can be created by weird | |||
5340 | parameters to objcopy. Also, fix some solaris weirdness. */ | |||
5341 | for (i = 0, segment = elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr; | |||
5342 | i < num_segments; | |||
5343 | i++, segment++) | |||
5344 | { | |||
5345 | unsigned int j; | |||
5346 | Elf_Internal_Phdr *segment2; | |||
5347 | ||||
5348 | if (segment->p_type == PT_INTERP3) | |||
5349 | for (section = ibfd->sections; section; section = section->next) | |||
5350 | if (IS_SOLARIS_PT_INTERP (segment, section)) | |||
5351 | { | |||
5352 | /* Mininal change so that the normal section to segment | |||
5353 | assignment code will work. */ | |||
5354 | segment->p_vaddr = section->vma; | |||
5355 | break; | |||
5356 | } | |||
5357 | ||||
5358 | if (segment->p_type != PT_LOAD1) | |||
5359 | continue; | |||
5360 | ||||
5361 | /* Determine if this segment overlaps any previous segments. */ | |||
5362 | for (j = 0, segment2 = elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr; j < i; j++, segment2 ++) | |||
5363 | { | |||
5364 | bfd_signed_vma extra_length; | |||
5365 | ||||
5366 | if (segment2->p_type != PT_LOAD1 | |||
5367 | || ! SEGMENT_OVERLAPS (segment, segment2)) | |||
5368 | continue; | |||
5369 | ||||
5370 | /* Merge the two segments together. */ | |||
5371 | if (segment2->p_vaddr < segment->p_vaddr) | |||
5372 | { | |||
5373 | /* Extend SEGMENT2 to include SEGMENT and then delete | |||
5374 | SEGMENT. */ | |||
5375 | extra_length = | |||
5376 | SEGMENT_END (segment, segment->p_vaddr) | |||
5377 | - SEGMENT_END (segment2, segment2->p_vaddr); | |||
5378 | ||||
5379 | if (extra_length > 0) | |||
5380 | { | |||
5381 | segment2->p_memsz += extra_length; | |||
5382 | segment2->p_filesz += extra_length; | |||
5383 | } | |||
5384 | ||||
5385 | segment->p_type = PT_NULL0; | |||
5386 | ||||
5387 | /* Since we have deleted P we must restart the outer loop. */ | |||
5388 | i = 0; | |||
5389 | segment = elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr; | |||
5390 | break; | |||
5391 | } | |||
5392 | else | |||
5393 | { | |||
5394 | /* Extend SEGMENT to include SEGMENT2 and then delete | |||
5395 | SEGMENT2. */ | |||
5396 | extra_length = | |||
5397 | SEGMENT_END (segment2, segment2->p_vaddr) | |||
5398 | - SEGMENT_END (segment, segment->p_vaddr); | |||
5399 | ||||
5400 | if (extra_length > 0) | |||
5401 | { | |||
5402 | segment->p_memsz += extra_length; | |||
5403 | segment->p_filesz += extra_length; | |||
5404 | } | |||
5405 | ||||
5406 | segment2->p_type = PT_NULL0; | |||
5407 | } | |||
5408 | } | |||
5409 | } | |||
5410 | ||||
5411 | /* The second scan attempts to assign sections to segments. */ | |||
5412 | for (i = 0, segment = elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr; | |||
5413 | i < num_segments; | |||
5414 | i ++, segment ++) | |||
5415 | { | |||
5416 | unsigned int section_count; | |||
5417 | asection ** sections; | |||
5418 | asection * output_section; | |||
5419 | unsigned int isec; | |||
5420 | bfd_vma matching_lma; | |||
5421 | bfd_vma suggested_lma; | |||
5422 | unsigned int j; | |||
5423 | bfd_size_type amt; | |||
5424 | ||||
5425 | if (segment->p_type == PT_NULL0) | |||
5426 | continue; | |||
5427 | ||||
5428 | /* Compute how many sections might be placed into this segment. */ | |||
5429 | for (section = ibfd->sections, section_count = 0; | |||
5430 | section != NULL((void*)0); | |||
5431 | section = section->next) | |||
5432 | if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed)) | |||
5433 | ++section_count; | |||
5434 | ||||
5435 | /* Allocate a segment map big enough to contain | |||
5436 | all of the sections we have selected. */ | |||
5437 | amt = sizeof (struct elf_segment_map); | |||
5438 | amt += ((bfd_size_type) section_count - 1) * sizeof (asection *); | |||
5439 | map = bfd_alloc (obfd, amt); | |||
5440 | if (map == NULL((void*)0)) | |||
5441 | return FALSE0; | |||
5442 | ||||
5443 | /* Initialise the fields of the segment map. Default to | |||
5444 | using the physical address of the segment in the input BFD. */ | |||
5445 | map->next = NULL((void*)0); | |||
5446 | map->p_type = segment->p_type; | |||
5447 | map->p_flags = segment->p_flags; | |||
5448 | map->p_flags_valid = 1; | |||
5449 | map->p_paddr = segment->p_paddr; | |||
5450 | map->p_paddr_valid = 1; | |||
5451 | ||||
5452 | /* Determine if this segment contains the ELF file header | |||
5453 | and if it contains the program headers themselves. */ | |||
5454 | map->includes_filehdr = (segment->p_offset == 0 | |||
5455 | && segment->p_filesz >= iehdr->e_ehsize); | |||
5456 | ||||
5457 | map->includes_phdrs = 0; | |||
5458 | ||||
5459 | if (! phdr_included || segment->p_type != PT_LOAD1) | |||
5460 | { | |||
5461 | map->includes_phdrs = | |||
5462 | (segment->p_offset <= (bfd_vma) iehdr->e_phoff | |||
5463 | && (segment->p_offset + segment->p_filesz | |||
5464 | >= ((bfd_vma) iehdr->e_phoff | |||
5465 | + iehdr->e_phnum * iehdr->e_phentsize))); | |||
5466 | ||||
5467 | if (segment->p_type == PT_LOAD1 && map->includes_phdrs) | |||
5468 | phdr_included = TRUE1; | |||
5469 | } | |||
5470 | ||||
5471 | if (section_count == 0) | |||
5472 | { | |||
5473 | /* Special segments, such as the PT_PHDR segment, may contain | |||
5474 | no sections, but ordinary, loadable segments should contain | |||
5475 | something. They are allowed by the ELF spec however, so only | |||
5476 | a warning is produced. */ | |||
5477 | if (segment->p_type == PT_LOAD1) | |||
5478 | (*_bfd_error_handler) | |||
5479 | (_("%B: warning: Empty loadable segment detected, is this intentional ?\n")("%B: warning: Empty loadable segment detected, is this intentional ?\n" ), | |||
5480 | ibfd); | |||
5481 | ||||
5482 | map->count = 0; | |||
5483 | *pointer_to_map = map; | |||
5484 | pointer_to_map = &map->next; | |||
5485 | ||||
5486 | continue; | |||
5487 | } | |||
5488 | ||||
5489 | /* Now scan the sections in the input BFD again and attempt | |||
5490 | to add their corresponding output sections to the segment map. | |||
5491 | The problem here is how to handle an output section which has | |||
5492 | been moved (ie had its LMA changed). There are four possibilities: | |||
5493 | ||||
5494 | 1. None of the sections have been moved. | |||
5495 | In this case we can continue to use the segment LMA from the | |||
5496 | input BFD. | |||
5497 | ||||
5498 | 2. All of the sections have been moved by the same amount. | |||
5499 | In this case we can change the segment's LMA to match the LMA | |||
5500 | of the first section. | |||
5501 | ||||
5502 | 3. Some of the sections have been moved, others have not. | |||
5503 | In this case those sections which have not been moved can be | |||
5504 | placed in the current segment which will have to have its size, | |||
5505 | and possibly its LMA changed, and a new segment or segments will | |||
5506 | have to be created to contain the other sections. | |||
5507 | ||||
5508 | 4. The sections have been moved, but not by the same amount. | |||
5509 | In this case we can change the segment's LMA to match the LMA | |||
5510 | of the first section and we will have to create a new segment | |||
5511 | or segments to contain the other sections. | |||
5512 | ||||
5513 | In order to save time, we allocate an array to hold the section | |||
5514 | pointers that we are interested in. As these sections get assigned | |||
5515 | to a segment, they are removed from this array. */ | |||
5516 | ||||
5517 | /* Gcc 2.96 miscompiles this code on mips. Don't do casting here | |||
5518 | to work around this long long bug. */ | |||
5519 | sections = bfd_malloc2 (section_count, sizeof (asection *)); | |||
5520 | if (sections == NULL((void*)0)) | |||
5521 | return FALSE0; | |||
5522 | ||||
5523 | /* Step One: Scan for segment vs section LMA conflicts. | |||
5524 | Also add the sections to the section array allocated above. | |||
5525 | Also add the sections to the current segment. In the common | |||
5526 | case, where the sections have not been moved, this means that | |||
5527 | we have completely filled the segment, and there is nothing | |||
5528 | more to do. */ | |||
5529 | isec = 0; | |||
5530 | matching_lma = 0; | |||
5531 | suggested_lma = 0; | |||
5532 | ||||
5533 | for (j = 0, section = ibfd->sections; | |||
5534 | section != NULL((void*)0); | |||
5535 | section = section->next) | |||
5536 | { | |||
5537 | if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed)) | |||
5538 | { | |||
5539 | output_section = section->output_section; | |||
5540 | ||||
5541 | sections[j ++] = section; | |||
5542 | ||||
5543 | /* The Solaris native linker always sets p_paddr to 0. | |||
5544 | We try to catch that case here, and set it to the | |||
5545 | correct value. Note - some backends require that | |||
5546 | p_paddr be left as zero. */ | |||
5547 | if (segment->p_paddr == 0 | |||
5548 | && segment->p_vaddr != 0 | |||
5549 | && (! bed->want_p_paddr_set_to_zero) | |||
5550 | && isec == 0 | |||
5551 | && output_section->lma != 0 | |||
5552 | && (output_section->vma == (segment->p_vaddr | |||
5553 | + (map->includes_filehdr | |||
5554 | ? iehdr->e_ehsize | |||
5555 | : 0) | |||
5556 | + (map->includes_phdrs | |||
5557 | ? (iehdr->e_phnum | |||
5558 | * iehdr->e_phentsize) | |||
5559 | : 0)))) | |||
5560 | map->p_paddr = segment->p_vaddr; | |||
5561 | ||||
5562 | /* Match up the physical address of the segment with the | |||
5563 | LMA address of the output section. */ | |||
5564 | if (IS_CONTAINED_BY_LMA (output_section, segment, map->p_paddr) | |||
5565 | || IS_COREFILE_NOTE (segment, section) | |||
5566 | || (bed->want_p_paddr_set_to_zero && | |||
5567 | IS_CONTAINED_BY_VMA (output_section, segment)) | |||
5568 | ) | |||
5569 | { | |||
5570 | if (matching_lma == 0) | |||
5571 | matching_lma = output_section->lma; | |||
5572 | ||||
5573 | /* We assume that if the section fits within the segment | |||
5574 | then it does not overlap any other section within that | |||
5575 | segment. */ | |||
5576 | map->sections[isec ++] = output_section; | |||
5577 | } | |||
5578 | else if (suggested_lma == 0) | |||
5579 | suggested_lma = output_section->lma; | |||
5580 | } | |||
5581 | } | |||
5582 | ||||
5583 | BFD_ASSERT (j == section_count)do { if (!(j == section_count)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,5583); } while (0); | |||
5584 | ||||
5585 | /* Step Two: Adjust the physical address of the current segment, | |||
5586 | if necessary. */ | |||
5587 | if (isec == section_count) | |||
5588 | { | |||
5589 | /* All of the sections fitted within the segment as currently | |||
5590 | specified. This is the default case. Add the segment to | |||
5591 | the list of built segments and carry on to process the next | |||
5592 | program header in the input BFD. */ | |||
5593 | map->count = section_count; | |||
5594 | *pointer_to_map = map; | |||
5595 | pointer_to_map = &map->next; | |||
5596 | ||||
5597 | free (sections); | |||
5598 | continue; | |||
5599 | } | |||
5600 | else | |||
5601 | { | |||
5602 | if (matching_lma != 0) | |||
5603 | { | |||
5604 | /* At least one section fits inside the current segment. | |||
5605 | Keep it, but modify its physical address to match the | |||
5606 | LMA of the first section that fitted. */ | |||
5607 | map->p_paddr = matching_lma; | |||
5608 | } | |||
5609 | else | |||
5610 | { | |||
5611 | /* None of the sections fitted inside the current segment. | |||
5612 | Change the current segment's physical address to match | |||
5613 | the LMA of the first section. */ | |||
5614 | map->p_paddr = suggested_lma; | |||
5615 | } | |||
5616 | ||||
5617 | /* Offset the segment physical address from the lma | |||
5618 | to allow for space taken up by elf headers. */ | |||
5619 | if (map->includes_filehdr) | |||
5620 | map->p_paddr -= iehdr->e_ehsize; | |||
5621 | ||||
5622 | if (map->includes_phdrs) | |||
5623 | { | |||
5624 | map->p_paddr -= iehdr->e_phnum * iehdr->e_phentsize; | |||
5625 | ||||
5626 | /* iehdr->e_phnum is just an estimate of the number | |||
5627 | of program headers that we will need. Make a note | |||
5628 | here of the number we used and the segment we chose | |||
5629 | to hold these headers, so that we can adjust the | |||
5630 | offset when we know the correct value. */ | |||
5631 | phdr_adjust_num = iehdr->e_phnum; | |||
5632 | phdr_adjust_seg = map; | |||
5633 | } | |||
5634 | } | |||
5635 | ||||
5636 | /* Step Three: Loop over the sections again, this time assigning | |||
5637 | those that fit to the current segment and removing them from the | |||
5638 | sections array; but making sure not to leave large gaps. Once all | |||
5639 | possible sections have been assigned to the current segment it is | |||
5640 | added to the list of built segments and if sections still remain | |||
5641 | to be assigned, a new segment is constructed before repeating | |||
5642 | the loop. */ | |||
5643 | isec = 0; | |||
5644 | do | |||
5645 | { | |||
5646 | map->count = 0; | |||
5647 | suggested_lma = 0; | |||
5648 | ||||
5649 | /* Fill the current segment with sections that fit. */ | |||
5650 | for (j = 0; j < section_count; j++) | |||
5651 | { | |||
5652 | section = sections[j]; | |||
5653 | ||||
5654 | if (section == NULL((void*)0)) | |||
5655 | continue; | |||
5656 | ||||
5657 | output_section = section->output_section; | |||
5658 | ||||
5659 | BFD_ASSERT (output_section != NULL)do { if (!(output_section != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,5659); } while (0); | |||
5660 | ||||
5661 | if (IS_CONTAINED_BY_LMA (output_section, segment, map->p_paddr) | |||
5662 | || IS_COREFILE_NOTE (segment, section)) | |||
5663 | { | |||
5664 | if (map->count == 0) | |||
5665 | { | |||
5666 | /* If the first section in a segment does not start at | |||
5667 | the beginning of the segment, then something is | |||
5668 | wrong. */ | |||
5669 | if (output_section->lma != | |||
5670 | (map->p_paddr | |||
5671 | + (map->includes_filehdr ? iehdr->e_ehsize : 0) | |||
5672 | + (map->includes_phdrs | |||
5673 | ? iehdr->e_phnum * iehdr->e_phentsize | |||
5674 | : 0))) | |||
5675 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c", 5675 , __PRETTY_FUNCTION__); | |||
5676 | } | |||
5677 | else | |||
5678 | { | |||
5679 | asection * prev_sec; | |||
5680 | ||||
5681 | prev_sec = map->sections[map->count - 1]; | |||
5682 | ||||
5683 | /* If the gap between the end of the previous section | |||
5684 | and the start of this section is more than | |||
5685 | maxpagesize then we need to start a new segment. */ | |||
5686 | if ((BFD_ALIGN (prev_sec->lma + prev_sec->size,((((bfd_vma) (prev_sec->lma + prev_sec->size) + (maxpagesize ) - 1) >= (bfd_vma) (prev_sec->lma + prev_sec->size) ) ? (((bfd_vma) (prev_sec->lma + prev_sec->size) + ((maxpagesize ) - 1)) & ~ (bfd_vma) ((maxpagesize)-1)) : ~ (bfd_vma) 0) | |||
5687 | maxpagesize)((((bfd_vma) (prev_sec->lma + prev_sec->size) + (maxpagesize ) - 1) >= (bfd_vma) (prev_sec->lma + prev_sec->size) ) ? (((bfd_vma) (prev_sec->lma + prev_sec->size) + ((maxpagesize ) - 1)) & ~ (bfd_vma) ((maxpagesize)-1)) : ~ (bfd_vma) 0) | |||
5688 | < BFD_ALIGN (output_section->lma, maxpagesize)((((bfd_vma) (output_section->lma) + (maxpagesize) - 1) >= (bfd_vma) (output_section->lma)) ? (((bfd_vma) (output_section ->lma) + ((maxpagesize) - 1)) & ~ (bfd_vma) ((maxpagesize )-1)) : ~ (bfd_vma) 0)) | |||
5689 | || ((prev_sec->lma + prev_sec->size) | |||
5690 | > output_section->lma)) | |||
5691 | { | |||
5692 | if (suggested_lma == 0) | |||
5693 | suggested_lma = output_section->lma; | |||
5694 | ||||
5695 | continue; | |||
5696 | } | |||
5697 | } | |||
5698 | ||||
5699 | map->sections[map->count++] = output_section; | |||
5700 | ++isec; | |||
5701 | sections[j] = NULL((void*)0); | |||
5702 | section->segment_mark = TRUE1; | |||
5703 | } | |||
5704 | else if (suggested_lma == 0) | |||
5705 | suggested_lma = output_section->lma; | |||
5706 | } | |||
5707 | ||||
5708 | BFD_ASSERT (map->count > 0)do { if (!(map->count > 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,5708); } while (0); | |||
5709 | ||||
5710 | /* Add the current segment to the list of built segments. */ | |||
5711 | *pointer_to_map = map; | |||
5712 | pointer_to_map = &map->next; | |||
5713 | ||||
5714 | if (isec < section_count) | |||
5715 | { | |||
5716 | /* We still have not allocated all of the sections to | |||
5717 | segments. Create a new segment here, initialise it | |||
5718 | and carry on looping. */ | |||
5719 | amt = sizeof (struct elf_segment_map); | |||
5720 | amt += ((bfd_size_type) section_count - 1) * sizeof (asection *); | |||
5721 | map = bfd_alloc (obfd, amt); | |||
5722 | if (map == NULL((void*)0)) | |||
5723 | { | |||
5724 | free (sections); | |||
5725 | return FALSE0; | |||
5726 | } | |||
5727 | ||||
5728 | /* Initialise the fields of the segment map. Set the physical | |||
5729 | physical address to the LMA of the first section that has | |||
5730 | not yet been assigned. */ | |||
5731 | map->next = NULL((void*)0); | |||
5732 | map->p_type = segment->p_type; | |||
5733 | map->p_flags = segment->p_flags; | |||
5734 | map->p_flags_valid = 1; | |||
5735 | map->p_paddr = suggested_lma; | |||
5736 | map->p_paddr_valid = 1; | |||
5737 | map->includes_filehdr = 0; | |||
5738 | map->includes_phdrs = 0; | |||
5739 | } | |||
5740 | } | |||
5741 | while (isec < section_count); | |||
5742 | ||||
5743 | free (sections); | |||
5744 | } | |||
5745 | ||||
5746 | /* The Solaris linker creates program headers in which all the | |||
5747 | p_paddr fields are zero. When we try to objcopy or strip such a | |||
5748 | file, we get confused. Check for this case, and if we find it | |||
5749 | reset the p_paddr_valid fields. */ | |||
5750 | for (map = map_first; map != NULL((void*)0); map = map->next) | |||
5751 | if (map->p_paddr != 0) | |||
5752 | break; | |||
5753 | if (map == NULL((void*)0)) | |||
5754 | for (map = map_first; map != NULL((void*)0); map = map->next) | |||
5755 | map->p_paddr_valid = 0; | |||
5756 | ||||
5757 | elf_tdata (obfd)((obfd) -> tdata.elf_obj_data)->segment_map = map_first; | |||
5758 | ||||
5759 | /* If we had to estimate the number of program headers that were | |||
5760 | going to be needed, then check our estimate now and adjust | |||
5761 | the offset if necessary. */ | |||
5762 | if (phdr_adjust_seg != NULL((void*)0)) | |||
5763 | { | |||
5764 | unsigned int count; | |||
5765 | ||||
5766 | for (count = 0, map = map_first; map != NULL((void*)0); map = map->next) | |||
5767 | count++; | |||
5768 | ||||
5769 | if (count > phdr_adjust_num) | |||
5770 | phdr_adjust_seg->p_paddr | |||
5771 | -= (count - phdr_adjust_num) * iehdr->e_phentsize; | |||
5772 | } | |||
5773 | ||||
5774 | #undef SEGMENT_END | |||
5775 | #undef SECTION_SIZE | |||
5776 | #undef IS_CONTAINED_BY_VMA | |||
5777 | #undef IS_CONTAINED_BY_LMA | |||
5778 | #undef IS_COREFILE_NOTE | |||
5779 | #undef IS_SOLARIS_PT_INTERP | |||
5780 | #undef INCLUDE_SECTION_IN_SEGMENT | |||
5781 | #undef SEGMENT_AFTER_SEGMENT | |||
5782 | #undef SEGMENT_OVERLAPS | |||
5783 | return TRUE1; | |||
5784 | } | |||
5785 | ||||
5786 | /* Copy ELF program header information. */ | |||
5787 | ||||
5788 | static bfd_boolean | |||
5789 | copy_elf_program_header (bfd *ibfd, bfd *obfd) | |||
5790 | { | |||
5791 | Elf_Internal_Ehdr *iehdr; | |||
5792 | struct elf_segment_map *map; | |||
5793 | struct elf_segment_map *map_first; | |||
5794 | struct elf_segment_map **pointer_to_map; | |||
5795 | Elf_Internal_Phdr *segment; | |||
5796 | unsigned int i; | |||
5797 | unsigned int num_segments; | |||
5798 | bfd_boolean phdr_included = FALSE0; | |||
5799 | ||||
5800 | iehdr = elf_elfheader (ibfd)(((ibfd) -> tdata.elf_obj_data) -> elf_header); | |||
5801 | ||||
5802 | map_first = NULL((void*)0); | |||
5803 | pointer_to_map = &map_first; | |||
5804 | ||||
5805 | num_segments = elf_elfheader (ibfd)(((ibfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; | |||
5806 | for (i = 0, segment = elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr; | |||
5807 | i < num_segments; | |||
5808 | i++, segment++) | |||
5809 | { | |||
5810 | asection *section; | |||
5811 | unsigned int section_count; | |||
5812 | bfd_size_type amt; | |||
5813 | Elf_Internal_Shdr *this_hdr; | |||
5814 | ||||
5815 | /* FIXME: Do we need to copy PT_NULL segment? */ | |||
5816 | if (segment->p_type == PT_NULL0) | |||
5817 | continue; | |||
5818 | ||||
5819 | /* Compute how many sections are in this segment. */ | |||
5820 | for (section = ibfd->sections, section_count = 0; | |||
5821 | section != NULL((void*)0); | |||
5822 | section = section->next) | |||
5823 | { | |||
5824 | this_hdr = &(elf_section_data(section)((struct bfd_elf_section_data*)(section)->used_by_bfd)->this_hdr); | |||
5825 | if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment)(this_hdr->sh_size > 0 && (segment->p_type != 7 || (this_hdr->sh_flags & (1 << 10)) != 0) && (this_hdr->sh_flags & (1 << 1) ? (this_hdr-> sh_addr >= segment->p_vaddr && this_hdr->sh_addr + this_hdr->sh_size <= segment->p_vaddr + segment-> p_memsz) : ((bfd_vma) this_hdr->sh_offset >= segment-> p_offset && (this_hdr->sh_offset + this_hdr->sh_size <= segment->p_offset + segment->p_filesz))))) | |||
5826 | section_count++; | |||
5827 | } | |||
5828 | ||||
5829 | /* Allocate a segment map big enough to contain | |||
5830 | all of the sections we have selected. */ | |||
5831 | amt = sizeof (struct elf_segment_map); | |||
5832 | if (section_count != 0) | |||
5833 | amt += ((bfd_size_type) section_count - 1) * sizeof (asection *); | |||
5834 | map = bfd_alloc (obfd, amt); | |||
5835 | if (map == NULL((void*)0)) | |||
5836 | return FALSE0; | |||
5837 | ||||
5838 | /* Initialize the fields of the output segment map with the | |||
5839 | input segment. */ | |||
5840 | map->next = NULL((void*)0); | |||
5841 | map->p_type = segment->p_type; | |||
5842 | map->p_flags = segment->p_flags; | |||
5843 | map->p_flags_valid = 1; | |||
5844 | map->p_paddr = segment->p_paddr; | |||
5845 | map->p_paddr_valid = 1; | |||
5846 | ||||
5847 | /* Determine if this segment contains the ELF file header | |||
5848 | and if it contains the program headers themselves. */ | |||
5849 | map->includes_filehdr = (segment->p_offset == 0 | |||
5850 | && segment->p_filesz >= iehdr->e_ehsize); | |||
5851 | ||||
5852 | map->includes_phdrs = 0; | |||
5853 | if (! phdr_included || segment->p_type != PT_LOAD1) | |||
5854 | { | |||
5855 | map->includes_phdrs = | |||
5856 | (segment->p_offset <= (bfd_vma) iehdr->e_phoff | |||
5857 | && (segment->p_offset + segment->p_filesz | |||
5858 | >= ((bfd_vma) iehdr->e_phoff | |||
5859 | + iehdr->e_phnum * iehdr->e_phentsize))); | |||
5860 | ||||
5861 | if (segment->p_type == PT_LOAD1 && map->includes_phdrs) | |||
5862 | phdr_included = TRUE1; | |||
5863 | } | |||
5864 | ||||
5865 | if (section_count != 0) | |||
5866 | { | |||
5867 | unsigned int isec = 0; | |||
5868 | ||||
5869 | for (section = ibfd->sections; | |||
5870 | section != NULL((void*)0); | |||
5871 | section = section->next) | |||
5872 | { | |||
5873 | this_hdr = &(elf_section_data(section)((struct bfd_elf_section_data*)(section)->used_by_bfd)->this_hdr); | |||
5874 | if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment)(this_hdr->sh_size > 0 && (segment->p_type != 7 || (this_hdr->sh_flags & (1 << 10)) != 0) && (this_hdr->sh_flags & (1 << 1) ? (this_hdr-> sh_addr >= segment->p_vaddr && this_hdr->sh_addr + this_hdr->sh_size <= segment->p_vaddr + segment-> p_memsz) : ((bfd_vma) this_hdr->sh_offset >= segment-> p_offset && (this_hdr->sh_offset + this_hdr->sh_size <= segment->p_offset + segment->p_filesz))))) | |||
5875 | map->sections[isec++] = section->output_section; | |||
5876 | } | |||
5877 | } | |||
5878 | ||||
5879 | map->count = section_count; | |||
5880 | *pointer_to_map = map; | |||
5881 | pointer_to_map = &map->next; | |||
5882 | } | |||
5883 | ||||
5884 | elf_tdata (obfd)((obfd) -> tdata.elf_obj_data)->segment_map = map_first; | |||
5885 | return TRUE1; | |||
5886 | } | |||
5887 | ||||
5888 | /* Copy private BFD data. This copies or rewrites ELF program header | |||
5889 | information. */ | |||
5890 | ||||
5891 | static bfd_boolean | |||
5892 | copy_private_bfd_data (bfd *ibfd, bfd *obfd) | |||
5893 | { | |||
5894 | if (bfd_get_flavour (ibfd)((ibfd)->xvec->flavour) != bfd_target_elf_flavour | |||
5895 | || bfd_get_flavour (obfd)((obfd)->xvec->flavour) != bfd_target_elf_flavour) | |||
5896 | return TRUE1; | |||
5897 | ||||
5898 | if (elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr == NULL((void*)0)) | |||
5899 | return TRUE1; | |||
5900 | ||||
5901 | if (ibfd->xvec == obfd->xvec) | |||
5902 | { | |||
5903 | /* Check if any sections in the input BFD covered by ELF program | |||
5904 | header are changed. */ | |||
5905 | Elf_Internal_Phdr *segment; | |||
5906 | asection *section, *osec; | |||
5907 | unsigned int i, num_segments; | |||
5908 | Elf_Internal_Shdr *this_hdr; | |||
5909 | ||||
5910 | /* Initialize the segment mark field. */ | |||
5911 | for (section = obfd->sections; section != NULL((void*)0); | |||
5912 | section = section->next) | |||
5913 | section->segment_mark = FALSE0; | |||
5914 | ||||
5915 | num_segments = elf_elfheader (ibfd)(((ibfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; | |||
5916 | for (i = 0, segment = elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr; | |||
5917 | i < num_segments; | |||
5918 | i++, segment++) | |||
5919 | { | |||
5920 | for (section = ibfd->sections; | |||
5921 | section != NULL((void*)0); section = section->next) | |||
5922 | { | |||
5923 | /* We mark the output section so that we know it comes | |||
5924 | from the input BFD. */ | |||
5925 | osec = section->output_section; | |||
5926 | if (osec) | |||
5927 | osec->segment_mark = TRUE1; | |||
5928 | ||||
5929 | /* Check if this section is covered by the segment. */ | |||
5930 | this_hdr = &(elf_section_data(section)((struct bfd_elf_section_data*)(section)->used_by_bfd)->this_hdr); | |||
5931 | if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment)(this_hdr->sh_size > 0 && (segment->p_type != 7 || (this_hdr->sh_flags & (1 << 10)) != 0) && (this_hdr->sh_flags & (1 << 1) ? (this_hdr-> sh_addr >= segment->p_vaddr && this_hdr->sh_addr + this_hdr->sh_size <= segment->p_vaddr + segment-> p_memsz) : ((bfd_vma) this_hdr->sh_offset >= segment-> p_offset && (this_hdr->sh_offset + this_hdr->sh_size <= segment->p_offset + segment->p_filesz))))) | |||
5932 | { | |||
5933 | /* FIXME: Check if its output section is changed or | |||
5934 | removed. What else do we need to check? */ | |||
5935 | if (osec == NULL((void*)0) | |||
5936 | || section->flags != osec->flags | |||
5937 | || section->lma != osec->lma | |||
5938 | || section->vma != osec->vma | |||
5939 | || section->size != osec->size | |||
5940 | || section->rawsize != osec->rawsize | |||
5941 | || section->alignment_power != osec->alignment_power) | |||
5942 | goto rewrite; | |||
5943 | } | |||
5944 | } | |||
5945 | } | |||
5946 | ||||
5947 | /* Check to see if any output section doesn't come from the | |||
5948 | input BFD. */ | |||
5949 | for (section = obfd->sections; section != NULL((void*)0); | |||
5950 | section = section->next) | |||
5951 | { | |||
5952 | if (section->segment_mark == FALSE0) | |||
5953 | goto rewrite; | |||
5954 | else | |||
5955 | section->segment_mark = FALSE0; | |||
5956 | } | |||
5957 | ||||
5958 | return copy_elf_program_header (ibfd, obfd); | |||
5959 | } | |||
5960 | ||||
5961 | rewrite: | |||
5962 | return rewrite_elf_program_header (ibfd, obfd); | |||
5963 | } | |||
5964 | ||||
5965 | /* Initialize private output section information from input section. */ | |||
5966 | ||||
5967 | bfd_boolean | |||
5968 | _bfd_elf_init_private_section_data (bfd *ibfd, | |||
5969 | asection *isec, | |||
5970 | bfd *obfd, | |||
5971 | asection *osec, | |||
5972 | struct bfd_link_info *link_info) | |||
5973 | ||||
5974 | { | |||
5975 | Elf_Internal_Shdr *ihdr, *ohdr; | |||
5976 | bfd_boolean need_group = link_info == NULL((void*)0) || link_info->relocatable; | |||
5977 | ||||
5978 | if (ibfd->xvec->flavour != bfd_target_elf_flavour | |||
5979 | || obfd->xvec->flavour != bfd_target_elf_flavour) | |||
5980 | return TRUE1; | |||
5981 | ||||
5982 | /* FIXME: What if the output ELF section type has been set to | |||
5983 | something different? */ | |||
5984 | if (elf_section_type (osec)(((struct bfd_elf_section_data*)(osec)->used_by_bfd)->this_hdr .sh_type) == SHT_NULL0) | |||
5985 | elf_section_type (osec)(((struct bfd_elf_section_data*)(osec)->used_by_bfd)->this_hdr .sh_type) = elf_section_type (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->this_hdr .sh_type); | |||
5986 | ||||
5987 | /* Set things up for objcopy and relocatable link. The output | |||
5988 | SHT_GROUP section will have its elf_next_in_group pointing back | |||
5989 | to the input group members. Ignore linker created group section. | |||
5990 | See elfNN_ia64_object_p in elfxx-ia64.c. */ | |||
5991 | ||||
5992 | if (need_group) | |||
5993 | { | |||
5994 | if (elf_sec_group (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->sec_group ) == NULL((void*)0) | |||
5995 | || (elf_sec_group (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->sec_group )->flags & SEC_LINKER_CREATED0x200000) == 0) | |||
5996 | { | |||
5997 | if (elf_section_flags (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->this_hdr .sh_flags) & SHF_GROUP(1 << 9)) | |||
5998 | elf_section_flags (osec)(((struct bfd_elf_section_data*)(osec)->used_by_bfd)->this_hdr .sh_flags) |= SHF_GROUP(1 << 9); | |||
5999 | elf_next_in_group (osec)(((struct bfd_elf_section_data*)(osec)->used_by_bfd)->next_in_group ) = elf_next_in_group (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->next_in_group ); | |||
6000 | elf_group_name (osec)(((struct bfd_elf_section_data*)(osec)->used_by_bfd)->group .name) = elf_group_name (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->group .name); | |||
6001 | } | |||
6002 | } | |||
6003 | ||||
6004 | ihdr = &elf_section_data (isec)((struct bfd_elf_section_data*)(isec)->used_by_bfd)->this_hdr; | |||
6005 | ||||
6006 | /* We need to handle elf_linked_to_section for SHF_LINK_ORDER. We | |||
6007 | don't use the output section of the linked-to section since it | |||
6008 | may be NULL at this point. */ | |||
6009 | if ((ihdr->sh_flags & SHF_LINK_ORDER(1 << 7)) != 0) | |||
6010 | { | |||
6011 | ohdr = &elf_section_data (osec)((struct bfd_elf_section_data*)(osec)->used_by_bfd)->this_hdr; | |||
6012 | ohdr->sh_flags |= SHF_LINK_ORDER(1 << 7); | |||
6013 | elf_linked_to_section (osec)(((struct bfd_elf_section_data*)(osec)->used_by_bfd)->linked_to ) = elf_linked_to_section (isec)(((struct bfd_elf_section_data*)(isec)->used_by_bfd)->linked_to ); | |||
6014 | } | |||
6015 | ||||
6016 | osec->use_rela_p = isec->use_rela_p; | |||
6017 | ||||
6018 | return TRUE1; | |||
6019 | } | |||
6020 | ||||
6021 | /* Copy private section information. This copies over the entsize | |||
6022 | field, and sometimes the info field. */ | |||
6023 | ||||
6024 | bfd_boolean | |||
6025 | _bfd_elf_copy_private_section_data (bfd *ibfd, | |||
6026 | asection *isec, | |||
6027 | bfd *obfd, | |||
6028 | asection *osec) | |||
6029 | { | |||
6030 | Elf_Internal_Shdr *ihdr, *ohdr; | |||
6031 | ||||
6032 | if (ibfd->xvec->flavour != bfd_target_elf_flavour | |||
6033 | || obfd->xvec->flavour != bfd_target_elf_flavour) | |||
6034 | return TRUE1; | |||
6035 | ||||
6036 | ihdr = &elf_section_data (isec)((struct bfd_elf_section_data*)(isec)->used_by_bfd)->this_hdr; | |||
6037 | ohdr = &elf_section_data (osec)((struct bfd_elf_section_data*)(osec)->used_by_bfd)->this_hdr; | |||
6038 | ||||
6039 | ohdr->sh_entsize = ihdr->sh_entsize; | |||
6040 | ||||
6041 | if (ihdr->sh_type == SHT_SYMTAB2 | |||
6042 | || ihdr->sh_type == SHT_DYNSYM11 | |||
6043 | || ihdr->sh_type == SHT_GNU_verneed0x6ffffffe | |||
6044 | || ihdr->sh_type == SHT_GNU_verdef0x6ffffffd) | |||
6045 | ohdr->sh_info = ihdr->sh_info; | |||
6046 | ||||
6047 | return _bfd_elf_init_private_section_data (ibfd, isec, obfd, osec, | |||
6048 | NULL((void*)0)); | |||
6049 | } | |||
6050 | ||||
6051 | /* Copy private header information. */ | |||
6052 | ||||
6053 | bfd_boolean | |||
6054 | _bfd_elf_copy_private_header_data (bfd *ibfd, bfd *obfd) | |||
6055 | { | |||
6056 | if (bfd_get_flavour (ibfd)((ibfd)->xvec->flavour) != bfd_target_elf_flavour | |||
6057 | || bfd_get_flavour (obfd)((obfd)->xvec->flavour) != bfd_target_elf_flavour) | |||
6058 | return TRUE1; | |||
6059 | ||||
6060 | /* Copy over private BFD data if it has not already been copied. | |||
6061 | This must be done here, rather than in the copy_private_bfd_data | |||
6062 | entry point, because the latter is called after the section | |||
6063 | contents have been set, which means that the program headers have | |||
6064 | already been worked out. */ | |||
6065 | if (elf_tdata (obfd)((obfd) -> tdata.elf_obj_data)->segment_map == NULL((void*)0) && elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->phdr != NULL((void*)0)) | |||
6066 | { | |||
6067 | if (! copy_private_bfd_data (ibfd, obfd)) | |||
6068 | return FALSE0; | |||
6069 | } | |||
6070 | ||||
6071 | return TRUE1; | |||
6072 | } | |||
6073 | ||||
6074 | /* Copy private symbol information. If this symbol is in a section | |||
6075 | which we did not map into a BFD section, try to map the section | |||
6076 | index correctly. We use special macro definitions for the mapped | |||
6077 | section indices; these definitions are interpreted by the | |||
6078 | swap_out_syms function. */ | |||
6079 | ||||
6080 | #define MAP_ONESYMTAB(0xFF3F + 1) (SHN_HIOS0xFF3F + 1) | |||
6081 | #define MAP_DYNSYMTAB(0xFF3F + 2) (SHN_HIOS0xFF3F + 2) | |||
6082 | #define MAP_STRTAB(0xFF3F + 3) (SHN_HIOS0xFF3F + 3) | |||
6083 | #define MAP_SHSTRTAB(0xFF3F + 4) (SHN_HIOS0xFF3F + 4) | |||
6084 | #define MAP_SYM_SHNDX(0xFF3F + 5) (SHN_HIOS0xFF3F + 5) | |||
6085 | ||||
6086 | bfd_boolean | |||
6087 | _bfd_elf_copy_private_symbol_data (bfd *ibfd, | |||
6088 | asymbol *isymarg, | |||
6089 | bfd *obfd, | |||
6090 | asymbol *osymarg) | |||
6091 | { | |||
6092 | elf_symbol_type *isym, *osym; | |||
6093 | ||||
6094 | if (bfd_get_flavour (ibfd)((ibfd)->xvec->flavour) != bfd_target_elf_flavour | |||
6095 | || bfd_get_flavour (obfd)((obfd)->xvec->flavour) != bfd_target_elf_flavour) | |||
6096 | return TRUE1; | |||
6097 | ||||
6098 | isym = elf_symbol_from (ibfd, isymarg)(((isymarg)->the_bfd->xvec->flavour == bfd_target_elf_flavour && (isymarg)->the_bfd->tdata.elf_obj_data != 0 ) ? (elf_symbol_type *) (isymarg) : 0); | |||
6099 | osym = elf_symbol_from (obfd, osymarg)(((osymarg)->the_bfd->xvec->flavour == bfd_target_elf_flavour && (osymarg)->the_bfd->tdata.elf_obj_data != 0 ) ? (elf_symbol_type *) (osymarg) : 0); | |||
6100 | ||||
6101 | if (isym != NULL((void*)0) | |||
6102 | && osym != NULL((void*)0) | |||
6103 | && bfd_is_abs_section (isym->symbol.section)((isym->symbol.section) == ((asection *) &bfd_abs_section ))) | |||
6104 | { | |||
6105 | unsigned int shndx; | |||
6106 | ||||
6107 | shndx = isym->internal_elf_sym.st_shndx; | |||
6108 | if (shndx == elf_onesymtab (ibfd)(((ibfd) -> tdata.elf_obj_data) -> symtab_section)) | |||
6109 | shndx = MAP_ONESYMTAB(0xFF3F + 1); | |||
6110 | else if (shndx == elf_dynsymtab (ibfd)(((ibfd) -> tdata.elf_obj_data) -> dynsymtab_section)) | |||
6111 | shndx = MAP_DYNSYMTAB(0xFF3F + 2); | |||
6112 | else if (shndx == elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->strtab_section) | |||
6113 | shndx = MAP_STRTAB(0xFF3F + 3); | |||
6114 | else if (shndx == elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->shstrtab_section) | |||
6115 | shndx = MAP_SHSTRTAB(0xFF3F + 4); | |||
6116 | else if (shndx == elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->symtab_shndx_section) | |||
6117 | shndx = MAP_SYM_SHNDX(0xFF3F + 5); | |||
6118 | osym->internal_elf_sym.st_shndx = shndx; | |||
6119 | } | |||
6120 | ||||
6121 | return TRUE1; | |||
6122 | } | |||
6123 | ||||
6124 | /* Swap out the symbols. */ | |||
6125 | ||||
6126 | static bfd_boolean | |||
6127 | swap_out_syms (bfd *abfd, | |||
6128 | struct bfd_strtab_hash **sttp, | |||
6129 | int relocatable_p) | |||
6130 | { | |||
6131 | const struct elf_backend_data *bed; | |||
6132 | int symcount; | |||
6133 | asymbol **syms; | |||
6134 | struct bfd_strtab_hash *stt; | |||
6135 | Elf_Internal_Shdr *symtab_hdr; | |||
6136 | Elf_Internal_Shdr *symtab_shndx_hdr; | |||
6137 | Elf_Internal_Shdr *symstrtab_hdr; | |||
6138 | bfd_byte *outbound_syms; | |||
6139 | bfd_byte *outbound_shndx; | |||
6140 | int idx; | |||
6141 | bfd_size_type amt; | |||
6142 | bfd_boolean name_local_sections; | |||
6143 | ||||
6144 | if (!elf_map_symbols (abfd)) | |||
6145 | return FALSE0; | |||
6146 | ||||
6147 | /* Dump out the symtabs. */ | |||
6148 | stt = _bfd_elf_stringtab_init (); | |||
6149 | if (stt == NULL((void*)0)) | |||
6150 | return FALSE0; | |||
6151 | ||||
6152 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
6153 | symcount = bfd_get_symcount (abfd)((abfd)->symcount); | |||
6154 | symtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
6155 | symtab_hdr->sh_type = SHT_SYMTAB2; | |||
6156 | symtab_hdr->sh_entsize = bed->s->sizeof_sym; | |||
6157 | symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1); | |||
6158 | symtab_hdr->sh_info = elf_num_locals (abfd)(((abfd) -> tdata.elf_obj_data) -> num_locals) + 1; | |||
6159 | symtab_hdr->sh_addralign = 1 << bed->s->log_file_align; | |||
6160 | ||||
6161 | symstrtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->strtab_hdr; | |||
6162 | symstrtab_hdr->sh_type = SHT_STRTAB3; | |||
6163 | ||||
6164 | outbound_syms = bfd_alloc2 (abfd, 1 + symcount, bed->s->sizeof_sym); | |||
6165 | if (outbound_syms == NULL((void*)0)) | |||
6166 | { | |||
6167 | _bfd_stringtab_free (stt); | |||
6168 | return FALSE0; | |||
6169 | } | |||
6170 | symtab_hdr->contents = outbound_syms; | |||
6171 | ||||
6172 | outbound_shndx = NULL((void*)0); | |||
6173 | symtab_shndx_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_shndx_hdr; | |||
6174 | if (symtab_shndx_hdr->sh_name != 0) | |||
6175 | { | |||
6176 | amt = (bfd_size_type) (1 + symcount) * sizeof (Elf_External_Sym_Shndx); | |||
6177 | outbound_shndx = bfd_zalloc2 (abfd, 1 + symcount, | |||
6178 | sizeof (Elf_External_Sym_Shndx)); | |||
6179 | if (outbound_shndx == NULL((void*)0)) | |||
6180 | { | |||
6181 | _bfd_stringtab_free (stt); | |||
6182 | return FALSE0; | |||
6183 | } | |||
6184 | ||||
6185 | symtab_shndx_hdr->contents = outbound_shndx; | |||
6186 | symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX18; | |||
6187 | symtab_shndx_hdr->sh_size = amt; | |||
6188 | symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx); | |||
6189 | symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx); | |||
6190 | } | |||
6191 | ||||
6192 | /* Now generate the data (for "contents"). */ | |||
6193 | { | |||
6194 | /* Fill in zeroth symbol and swap it out. */ | |||
6195 | Elf_Internal_Sym sym; | |||
6196 | sym.st_name = 0; | |||
6197 | sym.st_value = 0; | |||
6198 | sym.st_size = 0; | |||
6199 | sym.st_info = 0; | |||
6200 | sym.st_other = 0; | |||
6201 | sym.st_shndx = SHN_UNDEF0; | |||
6202 | bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx); | |||
6203 | outbound_syms += bed->s->sizeof_sym; | |||
6204 | if (outbound_shndx != NULL((void*)0)) | |||
6205 | outbound_shndx += sizeof (Elf_External_Sym_Shndx); | |||
6206 | } | |||
6207 | ||||
6208 | name_local_sections | |||
6209 | = (bed->elf_backend_name_local_section_symbols | |||
6210 | && bed->elf_backend_name_local_section_symbols (abfd)); | |||
6211 | ||||
6212 | syms = bfd_get_outsymbols (abfd)((abfd)->outsymbols); | |||
6213 | for (idx = 0; idx < symcount; idx++) | |||
6214 | { | |||
6215 | Elf_Internal_Sym sym; | |||
6216 | bfd_vma value = syms[idx]->value; | |||
6217 | elf_symbol_type *type_ptr; | |||
6218 | flagword flags = syms[idx]->flags; | |||
6219 | int type; | |||
6220 | ||||
6221 | if (!name_local_sections | |||
6222 | && (flags & (BSF_SECTION_SYM0x100 | BSF_GLOBAL0x02)) == BSF_SECTION_SYM0x100) | |||
6223 | { | |||
6224 | /* Local section symbols have no name. */ | |||
6225 | sym.st_name = 0; | |||
6226 | } | |||
6227 | else | |||
6228 | { | |||
6229 | sym.st_name = (unsigned long) _bfd_stringtab_add (stt, | |||
6230 | syms[idx]->name, | |||
6231 | TRUE1, FALSE0); | |||
6232 | if (sym.st_name == (unsigned long) -1) | |||
6233 | { | |||
6234 | _bfd_stringtab_free (stt); | |||
6235 | return FALSE0; | |||
6236 | } | |||
6237 | } | |||
6238 | ||||
6239 | type_ptr = elf_symbol_from (abfd, syms[idx])(((syms[idx])->the_bfd->xvec->flavour == bfd_target_elf_flavour && (syms[idx])->the_bfd->tdata.elf_obj_data != 0) ? (elf_symbol_type *) (syms[idx]) : 0); | |||
6240 | ||||
6241 | if ((flags & BSF_SECTION_SYM0x100) == 0 | |||
6242 | && bfd_is_com_section (syms[idx]->section)(((syms[idx]->section)->flags & 0x1000) != 0)) | |||
6243 | { | |||
6244 | /* ELF common symbols put the alignment into the `value' field, | |||
6245 | and the size into the `size' field. This is backwards from | |||
6246 | how BFD handles it, so reverse it here. */ | |||
6247 | sym.st_size = value; | |||
6248 | if (type_ptr == NULL((void*)0) | |||
6249 | || type_ptr->internal_elf_sym.st_value == 0) | |||
6250 | sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value)); | |||
6251 | else | |||
6252 | sym.st_value = type_ptr->internal_elf_sym.st_value; | |||
6253 | sym.st_shndx = _bfd_elf_section_from_bfd_section | |||
6254 | (abfd, syms[idx]->section); | |||
6255 | } | |||
6256 | else | |||
6257 | { | |||
6258 | asection *sec = syms[idx]->section; | |||
6259 | int shndx; | |||
6260 | ||||
6261 | if (sec->output_section) | |||
6262 | { | |||
6263 | value += sec->output_offset; | |||
6264 | sec = sec->output_section; | |||
6265 | } | |||
6266 | ||||
6267 | /* Don't add in the section vma for relocatable output. */ | |||
6268 | if (! relocatable_p) | |||
6269 | value += sec->vma; | |||
6270 | sym.st_value = value; | |||
6271 | sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0; | |||
6272 | ||||
6273 | if (bfd_is_abs_section (sec)((sec) == ((asection *) &bfd_abs_section)) | |||
6274 | && type_ptr != NULL((void*)0) | |||
6275 | && type_ptr->internal_elf_sym.st_shndx != 0) | |||
6276 | { | |||
6277 | /* This symbol is in a real ELF section which we did | |||
6278 | not create as a BFD section. Undo the mapping done | |||
6279 | by copy_private_symbol_data. */ | |||
6280 | shndx = type_ptr->internal_elf_sym.st_shndx; | |||
6281 | switch (shndx) | |||
6282 | { | |||
6283 | case MAP_ONESYMTAB(0xFF3F + 1): | |||
6284 | shndx = elf_onesymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> symtab_section); | |||
6285 | break; | |||
6286 | case MAP_DYNSYMTAB(0xFF3F + 2): | |||
6287 | shndx = elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section); | |||
6288 | break; | |||
6289 | case MAP_STRTAB(0xFF3F + 3): | |||
6290 | shndx = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->strtab_section; | |||
6291 | break; | |||
6292 | case MAP_SHSTRTAB(0xFF3F + 4): | |||
6293 | shndx = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->shstrtab_section; | |||
6294 | break; | |||
6295 | case MAP_SYM_SHNDX(0xFF3F + 5): | |||
6296 | shndx = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_shndx_section; | |||
6297 | break; | |||
6298 | default: | |||
6299 | break; | |||
6300 | } | |||
6301 | } | |||
6302 | else | |||
6303 | { | |||
6304 | shndx = _bfd_elf_section_from_bfd_section (abfd, sec); | |||
6305 | ||||
6306 | if (shndx == -1) | |||
6307 | { | |||
6308 | asection *sec2; | |||
6309 | ||||
6310 | /* Writing this would be a hell of a lot easier if | |||
6311 | we had some decent documentation on bfd, and | |||
6312 | knew what to expect of the library, and what to | |||
6313 | demand of applications. For example, it | |||
6314 | appears that `objcopy' might not set the | |||
6315 | section of a symbol to be a section that is | |||
6316 | actually in the output file. */ | |||
6317 | sec2 = bfd_get_section_by_name (abfd, sec->name); | |||
6318 | if (sec2 == NULL((void*)0)) | |||
6319 | { | |||
6320 | _bfd_error_handler (_("\("Unable to find equivalent output section for symbol '%s' from section '%s'" ) | |||
6321 | Unable to find equivalent output section for symbol '%s' from section '%s'")("Unable to find equivalent output section for symbol '%s' from section '%s'" ), | |||
6322 | syms[idx]->name ? syms[idx]->name : "<Local sym>", | |||
6323 | sec->name); | |||
6324 | bfd_set_error (bfd_error_invalid_operation); | |||
6325 | _bfd_stringtab_free (stt); | |||
6326 | return FALSE0; | |||
6327 | } | |||
6328 | ||||
6329 | shndx = _bfd_elf_section_from_bfd_section (abfd, sec2); | |||
6330 | BFD_ASSERT (shndx != -1)do { if (!(shndx != -1)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,6330); } while (0); | |||
6331 | } | |||
6332 | } | |||
6333 | ||||
6334 | sym.st_shndx = shndx; | |||
6335 | } | |||
6336 | ||||
6337 | if ((flags & BSF_THREAD_LOCAL0x40000) != 0) | |||
6338 | type = STT_TLS6; | |||
6339 | else if ((flags & BSF_FUNCTION0x10) != 0) | |||
6340 | type = STT_FUNC2; | |||
6341 | else if ((flags & BSF_OBJECT0x10000) != 0) | |||
6342 | type = STT_OBJECT1; | |||
6343 | else | |||
6344 | type = STT_NOTYPE0; | |||
6345 | ||||
6346 | if (syms[idx]->section->flags & SEC_THREAD_LOCAL0x400) | |||
6347 | type = STT_TLS6; | |||
6348 | ||||
6349 | /* Processor-specific types. */ | |||
6350 | if (type_ptr != NULL((void*)0) | |||
6351 | && bed->elf_backend_get_symbol_type) | |||
6352 | type = ((*bed->elf_backend_get_symbol_type) | |||
6353 | (&type_ptr->internal_elf_sym, type)); | |||
6354 | ||||
6355 | if (flags & BSF_SECTION_SYM0x100) | |||
6356 | { | |||
6357 | if (flags & BSF_GLOBAL0x02) | |||
6358 | sym.st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION)(((1) << 4) + ((3) & 0xF)); | |||
6359 | else | |||
6360 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION)(((0) << 4) + ((3) & 0xF)); | |||
6361 | } | |||
6362 | else if (bfd_is_com_section (syms[idx]->section)(((syms[idx]->section)->flags & 0x1000) != 0)) | |||
6363 | sym.st_info = ELF_ST_INFO (STB_GLOBAL, type)(((1) << 4) + ((type) & 0xF)); | |||
6364 | else if (bfd_is_und_section (syms[idx]->section)((syms[idx]->section) == ((asection *) &bfd_und_section ))) | |||
6365 | sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK)(((((flags & 0x80) ? 2 : 1)) << 4) + ((type) & 0xF )) | |||
6366 | ? STB_WEAK(((((flags & 0x80) ? 2 : 1)) << 4) + ((type) & 0xF )) | |||
6367 | : STB_GLOBAL),(((((flags & 0x80) ? 2 : 1)) << 4) + ((type) & 0xF )) | |||
6368 | type)(((((flags & 0x80) ? 2 : 1)) << 4) + ((type) & 0xF )); | |||
6369 | else if (flags & BSF_FILE0x4000) | |||
6370 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE)(((0) << 4) + ((4) & 0xF)); | |||
6371 | else | |||
6372 | { | |||
6373 | int bind = STB_LOCAL0; | |||
6374 | ||||
6375 | if (flags & BSF_LOCAL0x01) | |||
6376 | bind = STB_LOCAL0; | |||
6377 | else if (flags & BSF_WEAK0x80) | |||
6378 | bind = STB_WEAK2; | |||
6379 | else if (flags & BSF_GLOBAL0x02) | |||
6380 | bind = STB_GLOBAL1; | |||
6381 | ||||
6382 | sym.st_info = ELF_ST_INFO (bind, type)(((bind) << 4) + ((type) & 0xF)); | |||
6383 | } | |||
6384 | ||||
6385 | if (type_ptr != NULL((void*)0)) | |||
6386 | sym.st_other = type_ptr->internal_elf_sym.st_other; | |||
6387 | else | |||
6388 | sym.st_other = 0; | |||
6389 | ||||
6390 | bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx); | |||
6391 | outbound_syms += bed->s->sizeof_sym; | |||
6392 | if (outbound_shndx != NULL((void*)0)) | |||
6393 | outbound_shndx += sizeof (Elf_External_Sym_Shndx); | |||
6394 | } | |||
6395 | ||||
6396 | *sttp = stt; | |||
6397 | symstrtab_hdr->sh_size = _bfd_stringtab_size (stt); | |||
6398 | symstrtab_hdr->sh_type = SHT_STRTAB3; | |||
6399 | ||||
6400 | symstrtab_hdr->sh_flags = 0; | |||
6401 | symstrtab_hdr->sh_addr = 0; | |||
6402 | symstrtab_hdr->sh_entsize = 0; | |||
6403 | symstrtab_hdr->sh_link = 0; | |||
6404 | symstrtab_hdr->sh_info = 0; | |||
6405 | symstrtab_hdr->sh_addralign = 1; | |||
6406 | ||||
6407 | return TRUE1; | |||
6408 | } | |||
6409 | ||||
6410 | /* Return the number of bytes required to hold the symtab vector. | |||
6411 | ||||
6412 | Note that we base it on the count plus 1, since we will null terminate | |||
6413 | the vector allocated based on this size. However, the ELF symbol table | |||
6414 | always has a dummy entry as symbol #0, so it ends up even. */ | |||
6415 | ||||
6416 | long | |||
6417 | _bfd_elf_get_symtab_upper_bound (bfd *abfd) | |||
6418 | { | |||
6419 | long symcount; | |||
6420 | long symtab_size; | |||
6421 | Elf_Internal_Shdr *hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
6422 | ||||
6423 | symcount = hdr->sh_size / get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_sym; | |||
6424 | symtab_size = (symcount + 1) * (sizeof (asymbol *)); | |||
6425 | if (symcount > 0) | |||
6426 | symtab_size -= sizeof (asymbol *); | |||
6427 | ||||
6428 | return symtab_size; | |||
6429 | } | |||
6430 | ||||
6431 | long | |||
6432 | _bfd_elf_get_dynamic_symtab_upper_bound (bfd *abfd) | |||
6433 | { | |||
6434 | long symcount; | |||
6435 | long symtab_size; | |||
6436 | Elf_Internal_Shdr *hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynsymtab_hdr; | |||
6437 | ||||
6438 | if (elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == 0) | |||
6439 | { | |||
6440 | bfd_set_error (bfd_error_invalid_operation); | |||
6441 | return -1; | |||
6442 | } | |||
6443 | ||||
6444 | symcount = hdr->sh_size / get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_sym; | |||
6445 | symtab_size = (symcount + 1) * (sizeof (asymbol *)); | |||
6446 | if (symcount > 0) | |||
6447 | symtab_size -= sizeof (asymbol *); | |||
6448 | ||||
6449 | return symtab_size; | |||
6450 | } | |||
6451 | ||||
6452 | long | |||
6453 | _bfd_elf_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
6454 | sec_ptr asect) | |||
6455 | { | |||
6456 | return (asect->reloc_count + 1) * sizeof (arelent *); | |||
6457 | } | |||
6458 | ||||
6459 | /* Canonicalize the relocs. */ | |||
6460 | ||||
6461 | long | |||
6462 | _bfd_elf_canonicalize_reloc (bfd *abfd, | |||
6463 | sec_ptr section, | |||
6464 | arelent **relptr, | |||
6465 | asymbol **symbols) | |||
6466 | { | |||
6467 | arelent *tblptr; | |||
6468 | unsigned int i; | |||
6469 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
6470 | ||||
6471 | if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE0)) | |||
6472 | return -1; | |||
6473 | ||||
6474 | tblptr = section->relocation; | |||
6475 | for (i = 0; i < section->reloc_count; i++) | |||
6476 | *relptr++ = tblptr++; | |||
6477 | ||||
6478 | *relptr = NULL((void*)0); | |||
6479 | ||||
6480 | return section->reloc_count; | |||
6481 | } | |||
6482 | ||||
6483 | long | |||
6484 | _bfd_elf_canonicalize_symtab (bfd *abfd, asymbol **allocation) | |||
6485 | { | |||
6486 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
6487 | long symcount = bed->s->slurp_symbol_table (abfd, allocation, FALSE0); | |||
6488 | ||||
6489 | if (symcount >= 0) | |||
6490 | bfd_get_symcount (abfd)((abfd)->symcount) = symcount; | |||
6491 | return symcount; | |||
6492 | } | |||
6493 | ||||
6494 | long | |||
6495 | _bfd_elf_canonicalize_dynamic_symtab (bfd *abfd, | |||
6496 | asymbol **allocation) | |||
6497 | { | |||
6498 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
6499 | long symcount = bed->s->slurp_symbol_table (abfd, allocation, TRUE1); | |||
6500 | ||||
6501 | if (symcount >= 0) | |||
6502 | bfd_get_dynamic_symcount (abfd)((abfd)->dynsymcount) = symcount; | |||
6503 | return symcount; | |||
6504 | } | |||
6505 | ||||
6506 | /* Return the size required for the dynamic reloc entries. Any loadable | |||
6507 | section that was actually installed in the BFD, and has type SHT_REL | |||
6508 | or SHT_RELA, and uses the dynamic symbol table, is considered to be a | |||
6509 | dynamic reloc section. */ | |||
6510 | ||||
6511 | long | |||
6512 | _bfd_elf_get_dynamic_reloc_upper_bound (bfd *abfd) | |||
6513 | { | |||
6514 | long ret; | |||
6515 | asection *s; | |||
6516 | ||||
6517 | if (elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == 0) | |||
6518 | { | |||
6519 | bfd_set_error (bfd_error_invalid_operation); | |||
6520 | return -1; | |||
6521 | } | |||
6522 | ||||
6523 | ret = sizeof (arelent *); | |||
6524 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
6525 | if ((s->flags & SEC_LOAD0x002) != 0 | |||
6526 | && elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_link == elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) | |||
6527 | && (elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_type == SHT_REL9 | |||
6528 | || elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_type == SHT_RELA4)) | |||
6529 | ret += ((s->size / elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize) | |||
6530 | * sizeof (arelent *)); | |||
6531 | ||||
6532 | return ret; | |||
6533 | } | |||
6534 | ||||
6535 | /* Canonicalize the dynamic relocation entries. Note that we return the | |||
6536 | dynamic relocations as a single block, although they are actually | |||
6537 | associated with particular sections; the interface, which was | |||
6538 | designed for SunOS style shared libraries, expects that there is only | |||
6539 | one set of dynamic relocs. Any loadable section that was actually | |||
6540 | installed in the BFD, and has type SHT_REL or SHT_RELA, and uses the | |||
6541 | dynamic symbol table, is considered to be a dynamic reloc section. */ | |||
6542 | ||||
6543 | long | |||
6544 | _bfd_elf_canonicalize_dynamic_reloc (bfd *abfd, | |||
6545 | arelent **storage, | |||
6546 | asymbol **syms) | |||
6547 | { | |||
6548 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); | |||
6549 | asection *s; | |||
6550 | long ret; | |||
6551 | ||||
6552 | if (elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == 0) | |||
6553 | { | |||
6554 | bfd_set_error (bfd_error_invalid_operation); | |||
6555 | return -1; | |||
6556 | } | |||
6557 | ||||
6558 | slurp_relocs = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->slurp_reloc_table; | |||
6559 | ret = 0; | |||
6560 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
6561 | { | |||
6562 | if ((s->flags & SEC_LOAD0x002) != 0 | |||
6563 | && elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_link == elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) | |||
6564 | && (elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_type == SHT_REL9 | |||
6565 | || elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_type == SHT_RELA4)) | |||
6566 | { | |||
6567 | arelent *p; | |||
6568 | long count, i; | |||
6569 | ||||
6570 | if (! (*slurp_relocs) (abfd, s, syms, TRUE1)) | |||
6571 | return -1; | |||
6572 | count = s->size / elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize; | |||
6573 | p = s->relocation; | |||
6574 | for (i = 0; i < count; i++) | |||
6575 | *storage++ = p++; | |||
6576 | ret += count; | |||
6577 | } | |||
6578 | } | |||
6579 | ||||
6580 | *storage = NULL((void*)0); | |||
6581 | ||||
6582 | return ret; | |||
6583 | } | |||
6584 | ||||
6585 | /* Read in the version information. */ | |||
6586 | ||||
6587 | bfd_boolean | |||
6588 | _bfd_elf_slurp_version_tables (bfd *abfd, bfd_boolean default_imported_symver) | |||
6589 | { | |||
6590 | bfd_byte *contents = NULL((void*)0); | |||
6591 | unsigned int freeidx = 0; | |||
6592 | ||||
6593 | if (elf_dynverref (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverref_section) != 0) | |||
6594 | { | |||
6595 | Elf_Internal_Shdr *hdr; | |||
6596 | Elf_External_Verneed *everneed; | |||
6597 | Elf_Internal_Verneed *iverneed; | |||
6598 | unsigned int i; | |||
6599 | bfd_byte *contents_end; | |||
6600 | ||||
6601 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynverref_hdr; | |||
6602 | ||||
6603 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref = bfd_zalloc2 (abfd, hdr->sh_info, | |||
6604 | sizeof (Elf_Internal_Verneed)); | |||
6605 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref == NULL((void*)0)) | |||
6606 | goto error_return; | |||
6607 | ||||
6608 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverrefs = hdr->sh_info; | |||
6609 | ||||
6610 | contents = bfd_malloc (hdr->sh_size); | |||
6611 | if (contents == NULL((void*)0)) | |||
6612 | { | |||
6613 | error_return_verref: | |||
6614 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref = NULL((void*)0); | |||
6615 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverrefs = 0; | |||
6616 | goto error_return; | |||
6617 | } | |||
6618 | if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET0) != 0 | |||
6619 | || bfd_bread (contents, hdr->sh_size, abfd) != hdr->sh_size) | |||
6620 | goto error_return_verref; | |||
6621 | ||||
6622 | if (hdr->sh_info && hdr->sh_size < sizeof (Elf_External_Verneed)) | |||
6623 | goto error_return_verref; | |||
6624 | ||||
6625 | BFD_ASSERT (sizeof (Elf_External_Verneed)do { if (!(sizeof (Elf_External_Verneed) == sizeof (Elf_External_Vernaux ))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,6626); } while (0) | |||
6626 | == sizeof (Elf_External_Vernaux))do { if (!(sizeof (Elf_External_Verneed) == sizeof (Elf_External_Vernaux ))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,6626); } while (0); | |||
6627 | contents_end = contents + hdr->sh_size - sizeof (Elf_External_Verneed); | |||
6628 | everneed = (Elf_External_Verneed *) contents; | |||
6629 | iverneed = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref; | |||
6630 | for (i = 0; i < hdr->sh_info; i++, iverneed++) | |||
6631 | { | |||
6632 | Elf_External_Vernaux *evernaux; | |||
6633 | Elf_Internal_Vernaux *ivernaux; | |||
6634 | unsigned int j; | |||
6635 | ||||
6636 | _bfd_elf_swap_verneed_in (abfd, everneed, iverneed); | |||
6637 | ||||
6638 | iverneed->vn_bfd = abfd; | |||
6639 | ||||
6640 | iverneed->vn_filename = | |||
6641 | bfd_elf_string_from_elf_section (abfd, hdr->sh_link, | |||
6642 | iverneed->vn_file); | |||
6643 | if (iverneed->vn_filename == NULL((void*)0)) | |||
6644 | goto error_return_verref; | |||
6645 | ||||
6646 | if (iverneed->vn_cnt == 0) | |||
6647 | iverneed->vn_auxptr = NULL((void*)0); | |||
6648 | else | |||
6649 | { | |||
6650 | iverneed->vn_auxptr = bfd_alloc2 (abfd, iverneed->vn_cnt, | |||
6651 | sizeof (Elf_Internal_Vernaux)); | |||
6652 | if (iverneed->vn_auxptr == NULL((void*)0)) | |||
6653 | goto error_return_verref; | |||
6654 | } | |||
6655 | ||||
6656 | if (iverneed->vn_aux | |||
6657 | > (size_t) (contents_end - (bfd_byte *) everneed)) | |||
6658 | goto error_return_verref; | |||
6659 | ||||
6660 | evernaux = ((Elf_External_Vernaux *) | |||
6661 | ((bfd_byte *) everneed + iverneed->vn_aux)); | |||
6662 | ivernaux = iverneed->vn_auxptr; | |||
6663 | for (j = 0; j < iverneed->vn_cnt; j++, ivernaux++) | |||
6664 | { | |||
6665 | _bfd_elf_swap_vernaux_in (abfd, evernaux, ivernaux); | |||
6666 | ||||
6667 | ivernaux->vna_nodename = | |||
6668 | bfd_elf_string_from_elf_section (abfd, hdr->sh_link, | |||
6669 | ivernaux->vna_name); | |||
6670 | if (ivernaux->vna_nodename == NULL((void*)0)) | |||
6671 | goto error_return_verref; | |||
6672 | ||||
6673 | if (j + 1 < iverneed->vn_cnt) | |||
6674 | ivernaux->vna_nextptr = ivernaux + 1; | |||
6675 | else | |||
6676 | ivernaux->vna_nextptr = NULL((void*)0); | |||
6677 | ||||
6678 | if (ivernaux->vna_next | |||
6679 | > (size_t) (contents_end - (bfd_byte *) evernaux)) | |||
6680 | goto error_return_verref; | |||
6681 | ||||
6682 | evernaux = ((Elf_External_Vernaux *) | |||
6683 | ((bfd_byte *) evernaux + ivernaux->vna_next)); | |||
6684 | ||||
6685 | if (ivernaux->vna_other > freeidx) | |||
6686 | freeidx = ivernaux->vna_other; | |||
6687 | } | |||
6688 | ||||
6689 | if (i + 1 < hdr->sh_info) | |||
6690 | iverneed->vn_nextref = iverneed + 1; | |||
6691 | else | |||
6692 | iverneed->vn_nextref = NULL((void*)0); | |||
6693 | ||||
6694 | if (iverneed->vn_next | |||
6695 | > (size_t) (contents_end - (bfd_byte *) everneed)) | |||
6696 | goto error_return_verref; | |||
6697 | ||||
6698 | everneed = ((Elf_External_Verneed *) | |||
6699 | ((bfd_byte *) everneed + iverneed->vn_next)); | |||
6700 | } | |||
6701 | ||||
6702 | free (contents); | |||
6703 | contents = NULL((void*)0); | |||
6704 | } | |||
6705 | ||||
6706 | if (elf_dynverdef (abfd)(((abfd) -> tdata.elf_obj_data) -> dynverdef_section) != 0) | |||
6707 | { | |||
6708 | Elf_Internal_Shdr *hdr; | |||
6709 | Elf_External_Verdef *everdef; | |||
6710 | Elf_Internal_Verdef *iverdef; | |||
6711 | Elf_Internal_Verdef *iverdefarr; | |||
6712 | Elf_Internal_Verdef iverdefmem; | |||
6713 | unsigned int i; | |||
6714 | unsigned int maxidx; | |||
6715 | bfd_byte *contents_end_def, *contents_end_aux; | |||
6716 | ||||
6717 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynverdef_hdr; | |||
6718 | ||||
6719 | contents = bfd_malloc (hdr->sh_size); | |||
6720 | if (contents == NULL((void*)0)) | |||
6721 | goto error_return; | |||
6722 | if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET0) != 0 | |||
6723 | || bfd_bread (contents, hdr->sh_size, abfd) != hdr->sh_size) | |||
6724 | goto error_return; | |||
6725 | ||||
6726 | if (hdr->sh_info && hdr->sh_size < sizeof (Elf_External_Verdef)) | |||
6727 | goto error_return; | |||
6728 | ||||
6729 | BFD_ASSERT (sizeof (Elf_External_Verdef)do { if (!(sizeof (Elf_External_Verdef) >= sizeof (Elf_External_Verdaux ))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,6730); } while (0) | |||
6730 | >= sizeof (Elf_External_Verdaux))do { if (!(sizeof (Elf_External_Verdef) >= sizeof (Elf_External_Verdaux ))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c" ,6730); } while (0); | |||
6731 | contents_end_def = contents + hdr->sh_size | |||
6732 | - sizeof (Elf_External_Verdef); | |||
6733 | contents_end_aux = contents + hdr->sh_size | |||
6734 | - sizeof (Elf_External_Verdaux); | |||
6735 | ||||
6736 | /* We know the number of entries in the section but not the maximum | |||
6737 | index. Therefore we have to run through all entries and find | |||
6738 | the maximum. */ | |||
6739 | everdef = (Elf_External_Verdef *) contents; | |||
6740 | maxidx = 0; | |||
6741 | for (i = 0; i < hdr->sh_info; ++i) | |||
6742 | { | |||
6743 | _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem); | |||
6744 | ||||
6745 | if ((iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION0x7fff)) > maxidx) | |||
6746 | maxidx = iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION0x7fff); | |||
6747 | ||||
6748 | if (iverdefmem.vd_next | |||
6749 | > (size_t) (contents_end_def - (bfd_byte *) everdef)) | |||
6750 | goto error_return; | |||
6751 | ||||
6752 | everdef = ((Elf_External_Verdef *) | |||
6753 | ((bfd_byte *) everdef + iverdefmem.vd_next)); | |||
6754 | } | |||
6755 | ||||
6756 | if (default_imported_symver) | |||
6757 | { | |||
6758 | if (freeidx > maxidx) | |||
6759 | maxidx = ++freeidx; | |||
6760 | else | |||
6761 | freeidx = ++maxidx; | |||
6762 | } | |||
6763 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef = bfd_zalloc2 (abfd, maxidx, | |||
6764 | sizeof (Elf_Internal_Verdef)); | |||
6765 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef == NULL((void*)0)) | |||
6766 | goto error_return; | |||
6767 | ||||
6768 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs = maxidx; | |||
6769 | ||||
6770 | everdef = (Elf_External_Verdef *) contents; | |||
6771 | iverdefarr = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef; | |||
6772 | for (i = 0; i < hdr->sh_info; i++) | |||
6773 | { | |||
6774 | Elf_External_Verdaux *everdaux; | |||
6775 | Elf_Internal_Verdaux *iverdaux; | |||
6776 | unsigned int j; | |||
6777 | ||||
6778 | _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem); | |||
6779 | ||||
6780 | if ((iverdefmem.vd_ndx & VERSYM_VERSION0x7fff) == 0) | |||
6781 | { | |||
6782 | error_return_verdef: | |||
6783 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef = NULL((void*)0); | |||
6784 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs = 0; | |||
6785 | goto error_return; | |||
6786 | } | |||
6787 | ||||
6788 | iverdef = &iverdefarr[(iverdefmem.vd_ndx & VERSYM_VERSION0x7fff) - 1]; | |||
6789 | memcpy (iverdef, &iverdefmem, sizeof (Elf_Internal_Verdef)); | |||
6790 | ||||
6791 | iverdef->vd_bfd = abfd; | |||
6792 | ||||
6793 | if (iverdef->vd_cnt == 0) | |||
6794 | iverdef->vd_auxptr = NULL((void*)0); | |||
6795 | else | |||
6796 | { | |||
6797 | iverdef->vd_auxptr = bfd_alloc2 (abfd, iverdef->vd_cnt, | |||
6798 | sizeof (Elf_Internal_Verdaux)); | |||
6799 | if (iverdef->vd_auxptr == NULL((void*)0)) | |||
6800 | goto error_return_verdef; | |||
6801 | } | |||
6802 | ||||
6803 | if (iverdef->vd_aux | |||
6804 | > (size_t) (contents_end_aux - (bfd_byte *) everdef)) | |||
6805 | goto error_return_verdef; | |||
6806 | ||||
6807 | everdaux = ((Elf_External_Verdaux *) | |||
6808 | ((bfd_byte *) everdef + iverdef->vd_aux)); | |||
6809 | iverdaux = iverdef->vd_auxptr; | |||
6810 | for (j = 0; j < iverdef->vd_cnt; j++, iverdaux++) | |||
6811 | { | |||
6812 | _bfd_elf_swap_verdaux_in (abfd, everdaux, iverdaux); | |||
6813 | ||||
6814 | iverdaux->vda_nodename = | |||
6815 | bfd_elf_string_from_elf_section (abfd, hdr->sh_link, | |||
6816 | iverdaux->vda_name); | |||
6817 | if (iverdaux->vda_nodename == NULL((void*)0)) | |||
6818 | goto error_return_verdef; | |||
6819 | ||||
6820 | if (j + 1 < iverdef->vd_cnt) | |||
6821 | iverdaux->vda_nextptr = iverdaux + 1; | |||
6822 | else | |||
6823 | iverdaux->vda_nextptr = NULL((void*)0); | |||
6824 | ||||
6825 | if (iverdaux->vda_next | |||
6826 | > (size_t) (contents_end_aux - (bfd_byte *) everdaux)) | |||
6827 | goto error_return_verdef; | |||
6828 | ||||
6829 | everdaux = ((Elf_External_Verdaux *) | |||
6830 | ((bfd_byte *) everdaux + iverdaux->vda_next)); | |||
6831 | } | |||
6832 | ||||
6833 | if (iverdef->vd_cnt) | |||
6834 | iverdef->vd_nodename = iverdef->vd_auxptr->vda_nodename; | |||
6835 | ||||
6836 | if ((size_t) (iverdef - iverdefarr) + 1 < maxidx) | |||
6837 | iverdef->vd_nextdef = iverdef + 1; | |||
6838 | else | |||
6839 | iverdef->vd_nextdef = NULL((void*)0); | |||
6840 | ||||
6841 | everdef = ((Elf_External_Verdef *) | |||
6842 | ((bfd_byte *) everdef + iverdef->vd_next)); | |||
6843 | } | |||
6844 | ||||
6845 | free (contents); | |||
6846 | contents = NULL((void*)0); | |||
6847 | } | |||
6848 | else if (default_imported_symver) | |||
6849 | { | |||
6850 | if (freeidx < 3) | |||
6851 | freeidx = 3; | |||
6852 | else | |||
6853 | freeidx++; | |||
6854 | ||||
6855 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef = bfd_zalloc2 (abfd, freeidx, | |||
6856 | sizeof (Elf_Internal_Verdef)); | |||
6857 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef == NULL((void*)0)) | |||
6858 | goto error_return; | |||
6859 | ||||
6860 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs = freeidx; | |||
6861 | } | |||
6862 | ||||
6863 | /* Create a default version based on the soname. */ | |||
6864 | if (default_imported_symver) | |||
6865 | { | |||
6866 | Elf_Internal_Verdef *iverdef; | |||
6867 | Elf_Internal_Verdaux *iverdaux; | |||
6868 | ||||
6869 | iverdef = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef[freeidx - 1];; | |||
6870 | ||||
6871 | iverdef->vd_version = VER_DEF_CURRENT1; | |||
6872 | iverdef->vd_flags = 0; | |||
6873 | iverdef->vd_ndx = freeidx; | |||
6874 | iverdef->vd_cnt = 1; | |||
6875 | ||||
6876 | iverdef->vd_bfd = abfd; | |||
6877 | ||||
6878 | iverdef->vd_nodename = bfd_elf_get_dt_soname (abfd); | |||
6879 | if (iverdef->vd_nodename == NULL((void*)0)) | |||
6880 | goto error_return_verdef; | |||
6881 | iverdef->vd_nextdef = NULL((void*)0); | |||
6882 | iverdef->vd_auxptr = bfd_alloc (abfd, sizeof (Elf_Internal_Verdaux)); | |||
6883 | if (iverdef->vd_auxptr == NULL((void*)0)) | |||
6884 | goto error_return_verdef; | |||
6885 | ||||
6886 | iverdaux = iverdef->vd_auxptr; | |||
6887 | iverdaux->vda_nodename = iverdef->vd_nodename; | |||
6888 | iverdaux->vda_nextptr = NULL((void*)0); | |||
6889 | } | |||
6890 | ||||
6891 | return TRUE1; | |||
6892 | ||||
6893 | error_return: | |||
6894 | if (contents != NULL((void*)0)) | |||
6895 | free (contents); | |||
6896 | return FALSE0; | |||
6897 | } | |||
6898 | ||||
6899 | asymbol * | |||
6900 | _bfd_elf_make_empty_symbol (bfd *abfd) | |||
6901 | { | |||
6902 | elf_symbol_type *newsym; | |||
6903 | bfd_size_type amt = sizeof (elf_symbol_type); | |||
6904 | ||||
6905 | newsym = bfd_zalloc (abfd, amt); | |||
6906 | if (!newsym) | |||
6907 | return NULL((void*)0); | |||
6908 | else | |||
6909 | { | |||
6910 | newsym->symbol.the_bfd = abfd; | |||
6911 | return &newsym->symbol; | |||
6912 | } | |||
6913 | } | |||
6914 | ||||
6915 | void | |||
6916 | _bfd_elf_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
6917 | asymbol *symbol, | |||
6918 | symbol_info *ret) | |||
6919 | { | |||
6920 | bfd_symbol_info (symbol, ret); | |||
6921 | } | |||
6922 | ||||
6923 | /* Return whether a symbol name implies a local symbol. Most targets | |||
6924 | use this function for the is_local_label_name entry point, but some | |||
6925 | override it. */ | |||
6926 | ||||
6927 | bfd_boolean | |||
6928 | _bfd_elf_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
6929 | const char *name) | |||
6930 | { | |||
6931 | /* Normal local symbols start with ``.L''. */ | |||
6932 | if (name[0] == '.' && name[1] == 'L') | |||
6933 | return TRUE1; | |||
6934 | ||||
6935 | /* At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate | |||
6936 | DWARF debugging symbols starting with ``..''. */ | |||
6937 | if (name[0] == '.' && name[1] == '.') | |||
6938 | return TRUE1; | |||
6939 | ||||
6940 | /* gcc will sometimes generate symbols beginning with ``_.L_'' when | |||
6941 | emitting DWARF debugging output. I suspect this is actually a | |||
6942 | small bug in gcc (it calls ASM_OUTPUT_LABEL when it should call | |||
6943 | ASM_GENERATE_INTERNAL_LABEL, and this causes the leading | |||
6944 | underscore to be emitted on some ELF targets). For ease of use, | |||
6945 | we treat such symbols as local. */ | |||
6946 | if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_') | |||
6947 | return TRUE1; | |||
6948 | ||||
6949 | return FALSE0; | |||
6950 | } | |||
6951 | ||||
6952 | alent * | |||
6953 | _bfd_elf_get_lineno (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
6954 | asymbol *symbol ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
6955 | { | |||
6956 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c", 6956 , __PRETTY_FUNCTION__); | |||
6957 | return NULL((void*)0); | |||
6958 | } | |||
6959 | ||||
6960 | bfd_boolean | |||
6961 | _bfd_elf_set_arch_mach (bfd *abfd, | |||
6962 | enum bfd_architecture arch, | |||
6963 | unsigned long machine) | |||
6964 | { | |||
6965 | /* If this isn't the right architecture for this backend, and this | |||
6966 | isn't the generic backend, fail. */ | |||
6967 | if (arch != get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->arch | |||
6968 | && arch != bfd_arch_unknown | |||
6969 | && get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->arch != bfd_arch_unknown) | |||
6970 | return FALSE0; | |||
6971 | ||||
6972 | return bfd_default_set_arch_mach (abfd, arch, machine); | |||
6973 | } | |||
6974 | ||||
6975 | /* Find the function to a particular section and offset, | |||
6976 | for error reporting. */ | |||
6977 | ||||
6978 | static bfd_boolean | |||
6979 | elf_find_function (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
6980 | asection *section, | |||
6981 | asymbol **symbols, | |||
6982 | bfd_vma offset, | |||
6983 | const char **filename_ptr, | |||
6984 | const char **functionname_ptr) | |||
6985 | { | |||
6986 | const char *filename; | |||
6987 | asymbol *func, *file; | |||
6988 | bfd_vma low_func; | |||
6989 | asymbol **p; | |||
6990 | /* ??? Given multiple file symbols, it is impossible to reliably | |||
6991 | choose the right file name for global symbols. File symbols are | |||
6992 | local symbols, and thus all file symbols must sort before any | |||
6993 | global symbols. The ELF spec may be interpreted to say that a | |||
6994 | file symbol must sort before other local symbols, but currently | |||
6995 | ld -r doesn't do this. So, for ld -r output, it is possible to | |||
6996 | make a better choice of file name for local symbols by ignoring | |||
6997 | file symbols appearing after a given local symbol. */ | |||
6998 | enum { nothing_seen, symbol_seen, file_after_symbol_seen } state; | |||
6999 | ||||
7000 | filename = NULL((void*)0); | |||
7001 | func = NULL((void*)0); | |||
7002 | file = NULL((void*)0); | |||
7003 | low_func = 0; | |||
7004 | state = nothing_seen; | |||
7005 | ||||
7006 | for (p = symbols; *p != NULL((void*)0); p++) | |||
7007 | { | |||
7008 | elf_symbol_type *q; | |||
7009 | ||||
7010 | q = (elf_symbol_type *) *p; | |||
7011 | ||||
7012 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)((q->internal_elf_sym.st_info) & 0xF)) | |||
7013 | { | |||
7014 | default: | |||
7015 | break; | |||
7016 | case STT_FILE4: | |||
7017 | file = &q->symbol; | |||
7018 | if (state == symbol_seen) | |||
7019 | state = file_after_symbol_seen; | |||
7020 | continue; | |||
7021 | case STT_NOTYPE0: | |||
7022 | case STT_FUNC2: | |||
7023 | if (bfd_get_section (&q->symbol)((&q->symbol)->section) == section | |||
7024 | && q->symbol.value >= low_func | |||
7025 | && q->symbol.value <= offset) | |||
7026 | { | |||
7027 | func = (asymbol *) q; | |||
7028 | low_func = q->symbol.value; | |||
7029 | filename = NULL((void*)0); | |||
7030 | if (file != NULL((void*)0) | |||
7031 | && (ELF_ST_BIND (q->internal_elf_sym.st_info)(((unsigned int)(q->internal_elf_sym.st_info)) >> 4) == STB_LOCAL0 | |||
7032 | || state != file_after_symbol_seen)) | |||
7033 | filename = bfd_asymbol_name (file)((file)->name); | |||
7034 | } | |||
7035 | break; | |||
7036 | } | |||
7037 | if (state == nothing_seen) | |||
7038 | state = symbol_seen; | |||
7039 | } | |||
7040 | ||||
7041 | if (func == NULL((void*)0)) | |||
7042 | return FALSE0; | |||
7043 | ||||
7044 | if (filename_ptr) | |||
7045 | *filename_ptr = filename; | |||
7046 | if (functionname_ptr) | |||
7047 | *functionname_ptr = bfd_asymbol_name (func)((func)->name); | |||
7048 | ||||
7049 | return TRUE1; | |||
7050 | } | |||
7051 | ||||
7052 | /* Find the nearest line to a particular section and offset, | |||
7053 | for error reporting. */ | |||
7054 | ||||
7055 | bfd_boolean | |||
7056 | _bfd_elf_find_nearest_line (bfd *abfd, | |||
7057 | asection *section, | |||
7058 | asymbol **symbols, | |||
7059 | bfd_vma offset, | |||
7060 | const char **filename_ptr, | |||
7061 | const char **functionname_ptr, | |||
7062 | unsigned int *line_ptr) | |||
7063 | { | |||
7064 | bfd_boolean found; | |||
7065 | ||||
7066 | if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset, | |||
7067 | filename_ptr, functionname_ptr, | |||
7068 | line_ptr)) | |||
7069 | { | |||
7070 | if (!*functionname_ptr) | |||
7071 | elf_find_function (abfd, section, symbols, offset, | |||
7072 | *filename_ptr ? NULL((void*)0) : filename_ptr, | |||
7073 | functionname_ptr); | |||
7074 | ||||
7075 | return TRUE1; | |||
7076 | } | |||
7077 | ||||
7078 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |||
7079 | filename_ptr, functionname_ptr, | |||
7080 | line_ptr, 0, | |||
7081 | &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dwarf2_find_line_info)) | |||
7082 | { | |||
7083 | if (!*functionname_ptr) | |||
7084 | elf_find_function (abfd, section, symbols, offset, | |||
7085 | *filename_ptr ? NULL((void*)0) : filename_ptr, | |||
7086 | functionname_ptr); | |||
7087 | ||||
7088 | return TRUE1; | |||
7089 | } | |||
7090 | ||||
7091 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |||
7092 | &found, filename_ptr, | |||
7093 | functionname_ptr, line_ptr, | |||
7094 | &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->line_info)) | |||
7095 | return FALSE0; | |||
7096 | if (found && (*functionname_ptr || *line_ptr)) | |||
7097 | return TRUE1; | |||
7098 | ||||
7099 | if (symbols == NULL((void*)0)) | |||
7100 | return FALSE0; | |||
7101 | ||||
7102 | if (! elf_find_function (abfd, section, symbols, offset, | |||
7103 | filename_ptr, functionname_ptr)) | |||
7104 | return FALSE0; | |||
7105 | ||||
7106 | *line_ptr = 0; | |||
7107 | return TRUE1; | |||
7108 | } | |||
7109 | ||||
7110 | /* Find the line for a symbol. */ | |||
7111 | ||||
7112 | bfd_boolean | |||
7113 | _bfd_elf_find_line (bfd *abfd, asymbol **symbols, asymbol *symbol, | |||
7114 | const char **filename_ptr, unsigned int *line_ptr) | |||
7115 | { | |||
7116 | return _bfd_dwarf2_find_line (abfd, symbols, symbol, | |||
7117 | filename_ptr, line_ptr, 0, | |||
7118 | &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dwarf2_find_line_info); | |||
7119 | } | |||
7120 | ||||
7121 | /* After a call to bfd_find_nearest_line, successive calls to | |||
7122 | bfd_find_inliner_info can be used to get source information about | |||
7123 | each level of function inlining that terminated at the address | |||
7124 | passed to bfd_find_nearest_line. Currently this is only supported | |||
7125 | for DWARF2 with appropriate DWARF3 extensions. */ | |||
7126 | ||||
7127 | bfd_boolean | |||
7128 | _bfd_elf_find_inliner_info (bfd *abfd, | |||
7129 | const char **filename_ptr, | |||
7130 | const char **functionname_ptr, | |||
7131 | unsigned int *line_ptr) | |||
7132 | { | |||
7133 | bfd_boolean found; | |||
7134 | found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr, | |||
7135 | functionname_ptr, line_ptr, | |||
7136 | & elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dwarf2_find_line_info); | |||
7137 | return found; | |||
7138 | } | |||
7139 | ||||
7140 | int | |||
7141 | _bfd_elf_sizeof_headers (bfd *abfd, bfd_boolean reloc) | |||
7142 | { | |||
7143 | int ret; | |||
7144 | ||||
7145 | ret = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_ehdr; | |||
7146 | if (! reloc) | |||
7147 | ret += get_program_header_size (abfd); | |||
7148 | return ret; | |||
7149 | } | |||
7150 | ||||
7151 | bfd_boolean | |||
7152 | _bfd_elf_set_section_contents (bfd *abfd, | |||
7153 | sec_ptr section, | |||
7154 | const void *location, | |||
7155 | file_ptr offset, | |||
7156 | bfd_size_type count) | |||
7157 | { | |||
7158 | Elf_Internal_Shdr *hdr; | |||
7159 | bfd_signed_vma pos; | |||
7160 | ||||
7161 | if (! abfd->output_has_begun | |||
| ||||
7162 | && ! _bfd_elf_compute_section_file_positions (abfd, NULL((void*)0))) | |||
7163 | return FALSE0; | |||
7164 | ||||
7165 | hdr = &elf_section_data (section)((struct bfd_elf_section_data*)(section)->used_by_bfd)->this_hdr; | |||
7166 | pos = hdr->sh_offset + offset; | |||
7167 | if (bfd_seek (abfd, pos, SEEK_SET0) != 0 | |||
7168 | || bfd_bwrite (location, count, abfd) != count) | |||
7169 | return FALSE0; | |||
7170 | ||||
7171 | return TRUE1; | |||
7172 | } | |||
7173 | ||||
7174 | void | |||
7175 | _bfd_elf_no_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
7176 | arelent *cache_ptr ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
7177 | Elf_Internal_Rela *dst ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
7178 | { | |||
7179 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf.c", 7179 , __PRETTY_FUNCTION__); | |||
7180 | } | |||
7181 | ||||
7182 | /* Try to convert a non-ELF reloc into an ELF one. */ | |||
7183 | ||||
7184 | bfd_boolean | |||
7185 | _bfd_elf_validate_reloc (bfd *abfd, arelent *areloc) | |||
7186 | { | |||
7187 | /* Check whether we really have an ELF howto. */ | |||
7188 | ||||
7189 | if ((*areloc->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec) | |||
7190 | { | |||
7191 | bfd_reloc_code_real_type code; | |||
7192 | reloc_howto_type *howto; | |||
7193 | ||||
7194 | /* Alien reloc: Try to determine its type to replace it with an | |||
7195 | equivalent ELF reloc. */ | |||
7196 | ||||
7197 | if (areloc->howto->pc_relative) | |||
7198 | { | |||
7199 | switch (areloc->howto->bitsize) | |||
7200 | { | |||
7201 | case 8: | |||
7202 | code = BFD_RELOC_8_PCREL; | |||
7203 | break; | |||
7204 | case 12: | |||
7205 | code = BFD_RELOC_12_PCREL; | |||
7206 | break; | |||
7207 | case 16: | |||
7208 | code = BFD_RELOC_16_PCREL; | |||
7209 | break; | |||
7210 | case 24: | |||
7211 | code = BFD_RELOC_24_PCREL; | |||
7212 | break; | |||
7213 | case 32: | |||
7214 | code = BFD_RELOC_32_PCREL; | |||
7215 | break; | |||
7216 | case 64: | |||
7217 | code = BFD_RELOC_64_PCREL; | |||
7218 | break; | |||
7219 | default: | |||
7220 | goto fail; | |||
7221 | } | |||
7222 | ||||
7223 | howto = bfd_reloc_type_lookup (abfd, code); | |||
7224 | ||||
7225 | if (areloc->howto->pcrel_offset != howto->pcrel_offset) | |||
7226 | { | |||
7227 | if (howto->pcrel_offset) | |||
7228 | areloc->addend += areloc->address; | |||
7229 | else | |||
7230 | areloc->addend -= areloc->address; /* addend is unsigned!! */ | |||
7231 | } | |||
7232 | } | |||
7233 | else | |||
7234 | { | |||
7235 | switch (areloc->howto->bitsize) | |||
7236 | { | |||
7237 | case 8: | |||
7238 | code = BFD_RELOC_8; | |||
7239 | break; | |||
7240 | case 14: | |||
7241 | code = BFD_RELOC_14; | |||
7242 | break; | |||
7243 | case 16: | |||
7244 | code = BFD_RELOC_16; | |||
7245 | break; | |||
7246 | case 26: | |||
7247 | code = BFD_RELOC_26; | |||
7248 | break; | |||
7249 | case 32: | |||
7250 | code = BFD_RELOC_32; | |||
7251 | break; | |||
7252 | case 64: | |||
7253 | code = BFD_RELOC_64; | |||
7254 | break; | |||
7255 | default: | |||
7256 | goto fail; | |||
7257 | } | |||
7258 | ||||
7259 | howto = bfd_reloc_type_lookup (abfd, code); | |||
7260 | } | |||
7261 | ||||
7262 | if (howto) | |||
7263 | areloc->howto = howto; | |||
7264 | else | |||
7265 | goto fail; | |||
7266 | } | |||
7267 | ||||
7268 | return TRUE1; | |||
7269 | ||||
7270 | fail: | |||
7271 | (*_bfd_error_handler) | |||
7272 | (_("%B: unsupported relocation type %s")("%B: unsupported relocation type %s"), | |||
7273 | abfd, areloc->howto->name); | |||
7274 | bfd_set_error (bfd_error_bad_value); | |||
7275 | return FALSE0; | |||
7276 | } | |||
7277 | ||||
7278 | bfd_boolean | |||
7279 | _bfd_elf_close_and_cleanup (bfd *abfd) | |||
7280 | { | |||
7281 | if (bfd_get_format (abfd)((abfd)->format) == bfd_object) | |||
7282 | { | |||
7283 | if (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr) != NULL((void*)0)) | |||
7284 | _bfd_elf_strtab_free (elf_shstrtab (abfd)(((abfd) -> tdata.elf_obj_data) -> strtab_ptr)); | |||
7285 | _bfd_dwarf2_cleanup_debug_info (abfd); | |||
7286 | } | |||
7287 | ||||
7288 | return _bfd_generic_close_and_cleanupbfd_true (abfd); | |||
7289 | } | |||
7290 | ||||
7291 | /* For Rel targets, we encode meaningful data for BFD_RELOC_VTABLE_ENTRY | |||
7292 | in the relocation's offset. Thus we cannot allow any sort of sanity | |||
7293 | range-checking to interfere. There is nothing else to do in processing | |||
7294 | this reloc. */ | |||
7295 | ||||
7296 | bfd_reloc_status_type | |||
7297 | _bfd_elf_rel_vtable_reloc_fn | |||
7298 | (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), arelent *re ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
7299 | struct bfd_symbol *symbol ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
7300 | void *data ATTRIBUTE_UNUSED__attribute__ ((__unused__)), asection *is ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
7301 | bfd *obfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), char **errmsg ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
7302 | { | |||
7303 | return bfd_reloc_ok; | |||
7304 | } | |||
7305 | ||||
7306 | /* Elf core file support. Much of this only works on native | |||
7307 | toolchains, since we rely on knowing the | |||
7308 | machine-dependent procfs structure in order to pick | |||
7309 | out details about the corefile. */ | |||
7310 | ||||
7311 | #ifdef HAVE_SYS_PROCFS_H | |||
7312 | # include <sys/procfs.h> | |||
7313 | #endif | |||
7314 | ||||
7315 | /* FIXME: this is kinda wrong, but it's what gdb wants. */ | |||
7316 | ||||
7317 | static int | |||
7318 | elfcore_make_pid (bfd *abfd) | |||
7319 | { | |||
7320 | return ((elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid << 16) | |||
7321 | + (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid)); | |||
7322 | } | |||
7323 | ||||
7324 | /* If there isn't a section called NAME, make one, using | |||
7325 | data from SECT. Note, this function will generate a | |||
7326 | reference to NAME, so you shouldn't deallocate or | |||
7327 | overwrite it. */ | |||
7328 | ||||
7329 | static bfd_boolean | |||
7330 | elfcore_maybe_make_sect (bfd *abfd, char *name, asection *sect) | |||
7331 | { | |||
7332 | asection *sect2; | |||
7333 | ||||
7334 | if (bfd_get_section_by_name (abfd, name) != NULL((void*)0)) | |||
7335 | return TRUE1; | |||
7336 | ||||
7337 | sect2 = bfd_make_section (abfd, name); | |||
7338 | if (sect2 == NULL((void*)0)) | |||
7339 | return FALSE0; | |||
7340 | ||||
7341 | sect2->size = sect->size; | |||
7342 | sect2->filepos = sect->filepos; | |||
7343 | sect2->flags = sect->flags; | |||
7344 | sect2->alignment_power = sect->alignment_power; | |||
7345 | return TRUE1; | |||
7346 | } | |||
7347 | ||||
7348 | /* Create a pseudosection containing SIZE bytes at FILEPOS. This | |||
7349 | actually creates up to two pseudosections: | |||
7350 | - For the single-threaded case, a section named NAME, unless | |||
7351 | such a section already exists. | |||
7352 | - For the multi-threaded case, a section named "NAME/PID", where | |||
7353 | PID is elfcore_make_pid (abfd). | |||
7354 | Both pseudosections have identical contents. */ | |||
7355 | bfd_boolean | |||
7356 | _bfd_elfcore_make_pseudosection (bfd *abfd, | |||
7357 | char *name, | |||
7358 | size_t size, | |||
7359 | ufile_ptr filepos) | |||
7360 | { | |||
7361 | char buf[100]; | |||
7362 | char *threaded_name; | |||
7363 | size_t len; | |||
7364 | asection *sect; | |||
7365 | ||||
7366 | /* Build the section name. */ | |||
7367 | ||||
7368 | sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd)); | |||
7369 | len = strlen (buf) + 1; | |||
7370 | threaded_name = bfd_alloc (abfd, len); | |||
7371 | if (threaded_name == NULL((void*)0)) | |||
7372 | return FALSE0; | |||
7373 | memcpy (threaded_name, buf, len); | |||
7374 | ||||
7375 | sect = bfd_make_section_anyway (abfd, threaded_name); | |||
7376 | if (sect == NULL((void*)0)) | |||
7377 | return FALSE0; | |||
7378 | sect->size = size; | |||
7379 | sect->filepos = filepos; | |||
7380 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
7381 | sect->alignment_power = 2; | |||
7382 | ||||
7383 | return elfcore_maybe_make_sect (abfd, name, sect); | |||
7384 | } | |||
7385 | ||||
7386 | /* prstatus_t exists on: | |||
7387 | solaris 2.5+ | |||
7388 | linux 2.[01] + glibc | |||
7389 | unixware 4.2 | |||
7390 | */ | |||
7391 | ||||
7392 | #if defined (HAVE_PRSTATUS_T) | |||
7393 | ||||
7394 | static bfd_boolean | |||
7395 | elfcore_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |||
7396 | { | |||
7397 | size_t size; | |||
7398 | int offset; | |||
7399 | ||||
7400 | if (note->descsz == sizeof (prstatus_t)) | |||
7401 | { | |||
7402 | prstatus_t prstat; | |||
7403 | ||||
7404 | size = sizeof (prstat.pr_reg); | |||
7405 | offset = offsetof (prstatus_t, pr_reg)__builtin_offsetof(prstatus_t, pr_reg); | |||
7406 | memcpy (&prstat, note->descdata, sizeof (prstat)); | |||
7407 | ||||
7408 | /* Do not overwrite the core signal if it | |||
7409 | has already been set by another thread. */ | |||
7410 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal == 0) | |||
7411 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal = prstat.pr_cursig; | |||
7412 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid = prstat.pr_pid; | |||
7413 | ||||
7414 | /* pr_who exists on: | |||
7415 | solaris 2.5+ | |||
7416 | unixware 4.2 | |||
7417 | pr_who doesn't exist on: | |||
7418 | linux 2.[01] | |||
7419 | */ | |||
7420 | #if defined (HAVE_PRSTATUS_T_PR_WHO) | |||
7421 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = prstat.pr_who; | |||
7422 | #endif | |||
7423 | } | |||
7424 | #if defined (HAVE_PRSTATUS32_T) | |||
7425 | else if (note->descsz == sizeof (prstatus32_t)) | |||
7426 | { | |||
7427 | /* 64-bit host, 32-bit corefile */ | |||
7428 | prstatus32_t prstat; | |||
7429 | ||||
7430 | size = sizeof (prstat.pr_reg); | |||
7431 | offset = offsetof (prstatus32_t, pr_reg)__builtin_offsetof(prstatus32_t, pr_reg); | |||
7432 | memcpy (&prstat, note->descdata, sizeof (prstat)); | |||
7433 | ||||
7434 | /* Do not overwrite the core signal if it | |||
7435 | has already been set by another thread. */ | |||
7436 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal == 0) | |||
7437 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal = prstat.pr_cursig; | |||
7438 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid = prstat.pr_pid; | |||
7439 | ||||
7440 | /* pr_who exists on: | |||
7441 | solaris 2.5+ | |||
7442 | unixware 4.2 | |||
7443 | pr_who doesn't exist on: | |||
7444 | linux 2.[01] | |||
7445 | */ | |||
7446 | #if defined (HAVE_PRSTATUS32_T_PR_WHO) | |||
7447 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = prstat.pr_who; | |||
7448 | #endif | |||
7449 | } | |||
7450 | #endif /* HAVE_PRSTATUS32_T */ | |||
7451 | else | |||
7452 | { | |||
7453 | /* Fail - we don't know how to handle any other | |||
7454 | note size (ie. data object type). */ | |||
7455 | return TRUE1; | |||
7456 | } | |||
7457 | ||||
7458 | /* Make a ".reg/999" section and a ".reg" section. */ | |||
7459 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |||
7460 | size, note->descpos + offset); | |||
7461 | } | |||
7462 | #endif /* defined (HAVE_PRSTATUS_T) */ | |||
7463 | ||||
7464 | /* Create a pseudosection containing the exact contents of NOTE. */ | |||
7465 | static bfd_boolean | |||
7466 | elfcore_make_note_pseudosection (bfd *abfd, | |||
7467 | char *name, | |||
7468 | Elf_Internal_Note *note) | |||
7469 | { | |||
7470 | return _bfd_elfcore_make_pseudosection (abfd, name, | |||
7471 | note->descsz, note->descpos); | |||
7472 | } | |||
7473 | ||||
7474 | /* There isn't a consistent prfpregset_t across platforms, | |||
7475 | but it doesn't matter, because we don't have to pick this | |||
7476 | data structure apart. */ | |||
7477 | ||||
7478 | static bfd_boolean | |||
7479 | elfcore_grok_prfpreg (bfd *abfd, Elf_Internal_Note *note) | |||
7480 | { | |||
7481 | return elfcore_make_note_pseudosection (abfd, ".reg2", note); | |||
7482 | } | |||
7483 | ||||
7484 | /* Linux dumps the Intel SSE regs in a note named "LINUX" with a note | |||
7485 | type of 5 (NT_PRXFPREG). Just include the whole note's contents | |||
7486 | literally. */ | |||
7487 | ||||
7488 | static bfd_boolean | |||
7489 | elfcore_grok_prxfpreg (bfd *abfd, Elf_Internal_Note *note) | |||
7490 | { | |||
7491 | return elfcore_make_note_pseudosection (abfd, ".reg-xfp", note); | |||
7492 | } | |||
7493 | ||||
7494 | #if defined (HAVE_PRPSINFO_T) | |||
7495 | typedef prpsinfo_t elfcore_psinfo_t; | |||
7496 | #if defined (HAVE_PRPSINFO32_T) /* Sparc64 cross Sparc32 */ | |||
7497 | typedef prpsinfo32_t elfcore_psinfo32_t; | |||
7498 | #endif | |||
7499 | #endif | |||
7500 | ||||
7501 | #if defined (HAVE_PSINFO_T) | |||
7502 | typedef psinfo_t elfcore_psinfo_t; | |||
7503 | #if defined (HAVE_PSINFO32_T) /* Sparc64 cross Sparc32 */ | |||
7504 | typedef psinfo32_t elfcore_psinfo32_t; | |||
7505 | #endif | |||
7506 | #endif | |||
7507 | ||||
7508 | /* return a malloc'ed copy of a string at START which is at | |||
7509 | most MAX bytes long, possibly without a terminating '\0'. | |||
7510 | the copy will always have a terminating '\0'. */ | |||
7511 | ||||
7512 | char * | |||
7513 | _bfd_elfcore_strndup (bfd *abfd, char *start, size_t max) | |||
7514 | { | |||
7515 | char *dups; | |||
7516 | char *end = memchr (start, '\0', max); | |||
7517 | size_t len; | |||
7518 | ||||
7519 | if (end == NULL((void*)0)) | |||
7520 | len = max; | |||
7521 | else | |||
7522 | len = end - start; | |||
7523 | ||||
7524 | dups = bfd_alloc (abfd, len + 1); | |||
7525 | if (dups == NULL((void*)0)) | |||
7526 | return NULL((void*)0); | |||
7527 | ||||
7528 | memcpy (dups, start, len); | |||
7529 | dups[len] = '\0'; | |||
7530 | ||||
7531 | return dups; | |||
7532 | } | |||
7533 | ||||
7534 | #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) | |||
7535 | static bfd_boolean | |||
7536 | elfcore_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |||
7537 | { | |||
7538 | if (note->descsz == sizeof (elfcore_psinfo_t)) | |||
7539 | { | |||
7540 | elfcore_psinfo_t psinfo; | |||
7541 | ||||
7542 | memcpy (&psinfo, note->descdata, sizeof (psinfo)); | |||
7543 | ||||
7544 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_program | |||
7545 | = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, | |||
7546 | sizeof (psinfo.pr_fname)); | |||
7547 | ||||
7548 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command | |||
7549 | = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, | |||
7550 | sizeof (psinfo.pr_psargs)); | |||
7551 | } | |||
7552 | #if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T) | |||
7553 | else if (note->descsz == sizeof (elfcore_psinfo32_t)) | |||
7554 | { | |||
7555 | /* 64-bit host, 32-bit corefile */ | |||
7556 | elfcore_psinfo32_t psinfo; | |||
7557 | ||||
7558 | memcpy (&psinfo, note->descdata, sizeof (psinfo)); | |||
7559 | ||||
7560 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_program | |||
7561 | = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, | |||
7562 | sizeof (psinfo.pr_fname)); | |||
7563 | ||||
7564 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command | |||
7565 | = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, | |||
7566 | sizeof (psinfo.pr_psargs)); | |||
7567 | } | |||
7568 | #endif | |||
7569 | ||||
7570 | else | |||
7571 | { | |||
7572 | /* Fail - we don't know how to handle any other | |||
7573 | note size (ie. data object type). */ | |||
7574 | return TRUE1; | |||
7575 | } | |||
7576 | ||||
7577 | /* Note that for some reason, a spurious space is tacked | |||
7578 | onto the end of the args in some (at least one anyway) | |||
7579 | implementations, so strip it off if it exists. */ | |||
7580 | ||||
7581 | { | |||
7582 | char *command = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command; | |||
7583 | int n = strlen (command); | |||
7584 | ||||
7585 | if (0 < n && command[n - 1] == ' ') | |||
7586 | command[n - 1] = '\0'; | |||
7587 | } | |||
7588 | ||||
7589 | return TRUE1; | |||
7590 | } | |||
7591 | #endif /* defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) */ | |||
7592 | ||||
7593 | #if defined (HAVE_PSTATUS_T) | |||
7594 | static bfd_boolean | |||
7595 | elfcore_grok_pstatus (bfd *abfd, Elf_Internal_Note *note) | |||
7596 | { | |||
7597 | if (note->descsz == sizeof (pstatus_t) | |||
7598 | #if defined (HAVE_PXSTATUS_T) | |||
7599 | || note->descsz == sizeof (pxstatus_t) | |||
7600 | #endif | |||
7601 | ) | |||
7602 | { | |||
7603 | pstatus_t pstat; | |||
7604 | ||||
7605 | memcpy (&pstat, note->descdata, sizeof (pstat)); | |||
7606 | ||||
7607 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid = pstat.pr_pid; | |||
7608 | } | |||
7609 | #if defined (HAVE_PSTATUS32_T) | |||
7610 | else if (note->descsz == sizeof (pstatus32_t)) | |||
7611 | { | |||
7612 | /* 64-bit host, 32-bit corefile */ | |||
7613 | pstatus32_t pstat; | |||
7614 | ||||
7615 | memcpy (&pstat, note->descdata, sizeof (pstat)); | |||
7616 | ||||
7617 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid = pstat.pr_pid; | |||
7618 | } | |||
7619 | #endif | |||
7620 | /* Could grab some more details from the "representative" | |||
7621 | lwpstatus_t in pstat.pr_lwp, but we'll catch it all in an | |||
7622 | NT_LWPSTATUS note, presumably. */ | |||
7623 | ||||
7624 | return TRUE1; | |||
7625 | } | |||
7626 | #endif /* defined (HAVE_PSTATUS_T) */ | |||
7627 | ||||
7628 | #if defined (HAVE_LWPSTATUS_T) | |||
7629 | static bfd_boolean | |||
7630 | elfcore_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note) | |||
7631 | { | |||
7632 | lwpstatus_t lwpstat; | |||
7633 | char buf[100]; | |||
7634 | char *name; | |||
7635 | size_t len; | |||
7636 | asection *sect; | |||
7637 | ||||
7638 | if (note->descsz != sizeof (lwpstat) | |||
7639 | #if defined (HAVE_LWPXSTATUS_T) | |||
7640 | && note->descsz != sizeof (lwpxstatus_t) | |||
7641 | #endif | |||
7642 | ) | |||
7643 | return TRUE1; | |||
7644 | ||||
7645 | memcpy (&lwpstat, note->descdata, sizeof (lwpstat)); | |||
7646 | ||||
7647 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = lwpstat.pr_lwpid; | |||
7648 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal = lwpstat.pr_cursig; | |||
7649 | ||||
7650 | /* Make a ".reg/999" section. */ | |||
7651 | ||||
7652 | sprintf (buf, ".reg/%d", elfcore_make_pid (abfd)); | |||
7653 | len = strlen (buf) + 1; | |||
7654 | name = bfd_alloc (abfd, len); | |||
7655 | if (name == NULL((void*)0)) | |||
7656 | return FALSE0; | |||
7657 | memcpy (name, buf, len); | |||
7658 | ||||
7659 | sect = bfd_make_section_anyway (abfd, name); | |||
7660 | if (sect == NULL((void*)0)) | |||
7661 | return FALSE0; | |||
7662 | ||||
7663 | #if defined (HAVE_LWPSTATUS_T_PR_CONTEXT) | |||
7664 | sect->size = sizeof (lwpstat.pr_context.uc_mcontext.gregs); | |||
7665 | sect->filepos = note->descpos | |||
7666 | + offsetof (lwpstatus_t, pr_context.uc_mcontext.gregs)__builtin_offsetof(lwpstatus_t, pr_context.uc_mcontext.gregs); | |||
7667 | #endif | |||
7668 | ||||
7669 | #if defined (HAVE_LWPSTATUS_T_PR_REG) | |||
7670 | sect->size = sizeof (lwpstat.pr_reg); | |||
7671 | sect->filepos = note->descpos + offsetof (lwpstatus_t, pr_reg)__builtin_offsetof(lwpstatus_t, pr_reg); | |||
7672 | #endif | |||
7673 | ||||
7674 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
7675 | sect->alignment_power = 2; | |||
7676 | ||||
7677 | if (!elfcore_maybe_make_sect (abfd, ".reg", sect)) | |||
7678 | return FALSE0; | |||
7679 | ||||
7680 | /* Make a ".reg2/999" section */ | |||
7681 | ||||
7682 | sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd)); | |||
7683 | len = strlen (buf) + 1; | |||
7684 | name = bfd_alloc (abfd, len); | |||
7685 | if (name == NULL((void*)0)) | |||
7686 | return FALSE0; | |||
7687 | memcpy (name, buf, len); | |||
7688 | ||||
7689 | sect = bfd_make_section_anyway (abfd, name); | |||
7690 | if (sect == NULL((void*)0)) | |||
7691 | return FALSE0; | |||
7692 | ||||
7693 | #if defined (HAVE_LWPSTATUS_T_PR_CONTEXT) | |||
7694 | sect->size = sizeof (lwpstat.pr_context.uc_mcontext.fpregs); | |||
7695 | sect->filepos = note->descpos | |||
7696 | + offsetof (lwpstatus_t, pr_context.uc_mcontext.fpregs)__builtin_offsetof(lwpstatus_t, pr_context.uc_mcontext.fpregs ); | |||
7697 | #endif | |||
7698 | ||||
7699 | #if defined (HAVE_LWPSTATUS_T_PR_FPREG) | |||
7700 | sect->size = sizeof (lwpstat.pr_fpreg); | |||
7701 | sect->filepos = note->descpos + offsetof (lwpstatus_t, pr_fpreg)__builtin_offsetof(lwpstatus_t, pr_fpreg); | |||
7702 | #endif | |||
7703 | ||||
7704 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
7705 | sect->alignment_power = 2; | |||
7706 | ||||
7707 | return elfcore_maybe_make_sect (abfd, ".reg2", sect); | |||
7708 | } | |||
7709 | #endif /* defined (HAVE_LWPSTATUS_T) */ | |||
7710 | ||||
7711 | #if defined (HAVE_WIN32_PSTATUS_T) | |||
7712 | static bfd_boolean | |||
7713 | elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note) | |||
7714 | { | |||
7715 | char buf[30]; | |||
7716 | char *name; | |||
7717 | size_t len; | |||
7718 | asection *sect; | |||
7719 | win32_pstatus_t pstatus; | |||
7720 | ||||
7721 | if (note->descsz < sizeof (pstatus)) | |||
7722 | return TRUE1; | |||
7723 | ||||
7724 | memcpy (&pstatus, note->descdata, sizeof (pstatus)); | |||
7725 | ||||
7726 | switch (pstatus.data_type) | |||
7727 | { | |||
7728 | case NOTE_INFO_PROCESS: | |||
7729 | /* FIXME: need to add ->core_command. */ | |||
7730 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal = pstatus.data.process_info.signal; | |||
7731 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid = pstatus.data.process_info.pid; | |||
7732 | break; | |||
7733 | ||||
7734 | case NOTE_INFO_THREAD: | |||
7735 | /* Make a ".reg/999" section. */ | |||
7736 | sprintf (buf, ".reg/%ld", (long) pstatus.data.thread_info.tid); | |||
7737 | ||||
7738 | len = strlen (buf) + 1; | |||
7739 | name = bfd_alloc (abfd, len); | |||
7740 | if (name == NULL((void*)0)) | |||
7741 | return FALSE0; | |||
7742 | ||||
7743 | memcpy (name, buf, len); | |||
7744 | ||||
7745 | sect = bfd_make_section_anyway (abfd, name); | |||
7746 | if (sect == NULL((void*)0)) | |||
7747 | return FALSE0; | |||
7748 | ||||
7749 | sect->size = sizeof (pstatus.data.thread_info.thread_context); | |||
7750 | sect->filepos = (note->descpos | |||
7751 | + offsetof (struct win32_pstatus,__builtin_offsetof(struct win32_pstatus, data.thread_info.thread_context ) | |||
7752 | data.thread_info.thread_context)__builtin_offsetof(struct win32_pstatus, data.thread_info.thread_context )); | |||
7753 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
7754 | sect->alignment_power = 2; | |||
7755 | ||||
7756 | if (pstatus.data.thread_info.is_active_thread) | |||
7757 | if (! elfcore_maybe_make_sect (abfd, ".reg", sect)) | |||
7758 | return FALSE0; | |||
7759 | break; | |||
7760 | ||||
7761 | case NOTE_INFO_MODULE: | |||
7762 | /* Make a ".module/xxxxxxxx" section. */ | |||
7763 | sprintf (buf, ".module/%08lx", | |||
7764 | (long) pstatus.data.module_info.base_address); | |||
7765 | ||||
7766 | len = strlen (buf) + 1; | |||
7767 | name = bfd_alloc (abfd, len); | |||
7768 | if (name == NULL((void*)0)) | |||
7769 | return FALSE0; | |||
7770 | ||||
7771 | memcpy (name, buf, len); | |||
7772 | ||||
7773 | sect = bfd_make_section_anyway (abfd, name); | |||
7774 | ||||
7775 | if (sect == NULL((void*)0)) | |||
7776 | return FALSE0; | |||
7777 | ||||
7778 | sect->size = note->descsz; | |||
7779 | sect->filepos = note->descpos; | |||
7780 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
7781 | sect->alignment_power = 2; | |||
7782 | break; | |||
7783 | ||||
7784 | default: | |||
7785 | return TRUE1; | |||
7786 | } | |||
7787 | ||||
7788 | return TRUE1; | |||
7789 | } | |||
7790 | #endif /* HAVE_WIN32_PSTATUS_T */ | |||
7791 | ||||
7792 | static bfd_boolean | |||
7793 | elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) | |||
7794 | { | |||
7795 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
7796 | ||||
7797 | switch (note->type) | |||
7798 | { | |||
7799 | default: | |||
7800 | return TRUE1; | |||
7801 | ||||
7802 | case NT_PRSTATUS1: | |||
7803 | if (bed->elf_backend_grok_prstatus) | |||
7804 | if ((*bed->elf_backend_grok_prstatus) (abfd, note)) | |||
7805 | return TRUE1; | |||
7806 | #if defined (HAVE_PRSTATUS_T) | |||
7807 | return elfcore_grok_prstatus (abfd, note); | |||
7808 | #else | |||
7809 | return TRUE1; | |||
7810 | #endif | |||
7811 | ||||
7812 | #if defined (HAVE_PSTATUS_T) | |||
7813 | case NT_PSTATUS10: | |||
7814 | return elfcore_grok_pstatus (abfd, note); | |||
7815 | #endif | |||
7816 | ||||
7817 | #if defined (HAVE_LWPSTATUS_T) | |||
7818 | case NT_LWPSTATUS16: | |||
7819 | return elfcore_grok_lwpstatus (abfd, note); | |||
7820 | #endif | |||
7821 | ||||
7822 | case NT_FPREGSET2: /* FIXME: rename to NT_PRFPREG */ | |||
7823 | return elfcore_grok_prfpreg (abfd, note); | |||
7824 | ||||
7825 | #if defined (HAVE_WIN32_PSTATUS_T) | |||
7826 | case NT_WIN32PSTATUS18: | |||
7827 | return elfcore_grok_win32pstatus (abfd, note); | |||
7828 | #endif | |||
7829 | ||||
7830 | case NT_PRXFPREG0x46e62b7f: /* Linux SSE extension */ | |||
7831 | if (note->namesz == 6 | |||
7832 | && strcmp (note->namedata, "LINUX") == 0) | |||
7833 | return elfcore_grok_prxfpreg (abfd, note); | |||
7834 | else | |||
7835 | return TRUE1; | |||
7836 | ||||
7837 | case NT_PRPSINFO3: | |||
7838 | case NT_PSINFO13: | |||
7839 | if (bed->elf_backend_grok_psinfo) | |||
7840 | if ((*bed->elf_backend_grok_psinfo) (abfd, note)) | |||
7841 | return TRUE1; | |||
7842 | #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) | |||
7843 | return elfcore_grok_psinfo (abfd, note); | |||
7844 | #else | |||
7845 | return TRUE1; | |||
7846 | #endif | |||
7847 | ||||
7848 | case NT_AUXV6: | |||
7849 | { | |||
7850 | asection *sect = bfd_make_section_anyway (abfd, ".auxv"); | |||
7851 | ||||
7852 | if (sect == NULL((void*)0)) | |||
7853 | return FALSE0; | |||
7854 | sect->size = note->descsz; | |||
7855 | sect->filepos = note->descpos; | |||
7856 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
7857 | sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32; | |||
7858 | ||||
7859 | return TRUE1; | |||
7860 | } | |||
7861 | } | |||
7862 | } | |||
7863 | ||||
7864 | static bfd_boolean | |||
7865 | elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp) | |||
7866 | { | |||
7867 | char *cp; | |||
7868 | ||||
7869 | cp = strchr (note->namedata, '@'); | |||
7870 | if (cp != NULL((void*)0)) | |||
7871 | { | |||
7872 | *lwpidp = atoi(cp + 1); | |||
7873 | return TRUE1; | |||
7874 | } | |||
7875 | return FALSE0; | |||
7876 | } | |||
7877 | ||||
7878 | static bfd_boolean | |||
7879 | elfcore_grok_netbsd_procinfo (bfd *abfd, Elf_Internal_Note *note) | |||
7880 | { | |||
7881 | ||||
7882 | /* Signal number at offset 0x08. */ | |||
7883 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal | |||
7884 | = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x08)((*((abfd)->xvec->bfd_h_getx32)) ((bfd_byte *) note-> descdata + 0x08)); | |||
7885 | ||||
7886 | /* Process ID at offset 0x50. */ | |||
7887 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid | |||
7888 | = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x50)((*((abfd)->xvec->bfd_h_getx32)) ((bfd_byte *) note-> descdata + 0x50)); | |||
7889 | ||||
7890 | /* Command name at 0x7c (max 32 bytes, including nul). */ | |||
7891 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command | |||
7892 | = _bfd_elfcore_strndup (abfd, note->descdata + 0x7c, 31); | |||
7893 | ||||
7894 | return elfcore_make_note_pseudosection (abfd, ".note.netbsdcore.procinfo", | |||
7895 | note); | |||
7896 | } | |||
7897 | ||||
7898 | static bfd_boolean | |||
7899 | elfcore_grok_netbsd_note (bfd *abfd, Elf_Internal_Note *note) | |||
7900 | { | |||
7901 | int lwp; | |||
7902 | ||||
7903 | if (elfcore_netbsd_get_lwpid (note, &lwp)) | |||
7904 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = lwp; | |||
7905 | ||||
7906 | if (note->type == NT_NETBSDCORE_PROCINFO1) | |||
7907 | { | |||
7908 | /* NetBSD-specific core "procinfo". Note that we expect to | |||
7909 | find this note before any of the others, which is fine, | |||
7910 | since the kernel writes this note out first when it | |||
7911 | creates a core file. */ | |||
7912 | ||||
7913 | return elfcore_grok_netbsd_procinfo (abfd, note); | |||
7914 | } | |||
7915 | ||||
7916 | /* As of Jan 2002 there are no other machine-independent notes | |||
7917 | defined for NetBSD core files. If the note type is less | |||
7918 | than the start of the machine-dependent note types, we don't | |||
7919 | understand it. */ | |||
7920 | ||||
7921 | if (note->type < NT_NETBSDCORE_FIRSTMACH32) | |||
7922 | return TRUE1; | |||
7923 | ||||
7924 | ||||
7925 | switch (bfd_get_arch (abfd)) | |||
7926 | { | |||
7927 | /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 and | |||
7928 | PT_GETFPREGS == mach+2. */ | |||
7929 | ||||
7930 | case bfd_arch_alpha: | |||
7931 | case bfd_arch_sparc: | |||
7932 | switch (note->type) | |||
7933 | { | |||
7934 | case NT_NETBSDCORE_FIRSTMACH32+0: | |||
7935 | return elfcore_make_note_pseudosection (abfd, ".reg", note); | |||
7936 | ||||
7937 | case NT_NETBSDCORE_FIRSTMACH32+2: | |||
7938 | return elfcore_make_note_pseudosection (abfd, ".reg2", note); | |||
7939 | ||||
7940 | default: | |||
7941 | return TRUE1; | |||
7942 | } | |||
7943 | ||||
7944 | /* On all other arch's, PT_GETREGS == mach+1 and | |||
7945 | PT_GETFPREGS == mach+3. */ | |||
7946 | ||||
7947 | default: | |||
7948 | switch (note->type) | |||
7949 | { | |||
7950 | case NT_NETBSDCORE_FIRSTMACH32+1: | |||
7951 | return elfcore_make_note_pseudosection (abfd, ".reg", note); | |||
7952 | ||||
7953 | case NT_NETBSDCORE_FIRSTMACH32+3: | |||
7954 | return elfcore_make_note_pseudosection (abfd, ".reg2", note); | |||
7955 | ||||
7956 | default: | |||
7957 | return TRUE1; | |||
7958 | } | |||
7959 | } | |||
7960 | /* NOTREACHED */ | |||
7961 | } | |||
7962 | ||||
7963 | static bfd_boolean | |||
7964 | elfcore_grok_openbsd_procinfo (bfd *abfd, Elf_Internal_Note *note) | |||
7965 | { | |||
7966 | /* Signal number at offset 0x08. */ | |||
7967 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal | |||
7968 | = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x08)((*((abfd)->xvec->bfd_h_getx32)) ((bfd_byte *) note-> descdata + 0x08)); | |||
7969 | ||||
7970 | /* Process ID at offset 0x20. */ | |||
7971 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid | |||
7972 | = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x20)((*((abfd)->xvec->bfd_h_getx32)) ((bfd_byte *) note-> descdata + 0x20)); | |||
7973 | ||||
7974 | /* Command name at 0x48 (max 32 bytes, including nul). */ | |||
7975 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command | |||
7976 | = _bfd_elfcore_strndup (abfd, note->descdata + 0x48, 31); | |||
7977 | ||||
7978 | return TRUE1; | |||
7979 | } | |||
7980 | ||||
7981 | static bfd_boolean | |||
7982 | elfcore_grok_openbsd_note (bfd *abfd, Elf_Internal_Note *note) | |||
7983 | { | |||
7984 | int lwp; | |||
7985 | ||||
7986 | if (elfcore_netbsd_get_lwpid (note, &lwp)) | |||
7987 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = lwp; | |||
7988 | ||||
7989 | if (note->type == NT_OPENBSD_PROCINFO10) | |||
7990 | return elfcore_grok_openbsd_procinfo (abfd, note); | |||
7991 | ||||
7992 | if (note->type == NT_OPENBSD_REGS20) | |||
7993 | return elfcore_make_note_pseudosection (abfd, ".reg", note); | |||
7994 | ||||
7995 | if (note->type == NT_OPENBSD_FPREGS21) | |||
7996 | return elfcore_make_note_pseudosection (abfd, ".reg2", note); | |||
7997 | ||||
7998 | if (note->type == NT_OPENBSD_XFPREGS22) | |||
7999 | return elfcore_make_note_pseudosection (abfd, ".reg-xfp", note); | |||
8000 | ||||
8001 | if (note->type == NT_OPENBSD_AUXV11) | |||
8002 | { | |||
8003 | asection *sect = bfd_make_section_anyway (abfd, ".auxv"); | |||
8004 | ||||
8005 | if (sect == NULL((void*)0)) | |||
8006 | return FALSE0; | |||
8007 | sect->size = note->descsz; | |||
8008 | sect->filepos = note->descpos; | |||
8009 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
8010 | sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32; | |||
8011 | ||||
8012 | return TRUE1; | |||
8013 | } | |||
8014 | ||||
8015 | if (note->type == NT_OPENBSD_WCOOKIE23) | |||
8016 | { | |||
8017 | asection *sect = bfd_make_section_anyway (abfd, ".wcookie"); | |||
8018 | ||||
8019 | if (sect == NULL((void*)0)) | |||
8020 | return FALSE0; | |||
8021 | sect->size = note->descsz; | |||
8022 | sect->filepos = note->descpos; | |||
8023 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
8024 | sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32; | |||
8025 | ||||
8026 | return TRUE1; | |||
8027 | } | |||
8028 | ||||
8029 | return TRUE1; | |||
8030 | } | |||
8031 | ||||
8032 | static bfd_boolean | |||
8033 | elfcore_grok_nto_status (bfd *abfd, Elf_Internal_Note *note, pid_t *tid) | |||
8034 | { | |||
8035 | void *ddata = note->descdata; | |||
8036 | char buf[100]; | |||
8037 | char *name; | |||
8038 | asection *sect; | |||
8039 | short sig; | |||
8040 | unsigned flags; | |||
8041 | ||||
8042 | /* nto_procfs_status 'pid' field is at offset 0. */ | |||
8043 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid = bfd_get_32 (abfd, (bfd_byte *) ddata)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) ddata)); | |||
8044 | ||||
8045 | /* nto_procfs_status 'tid' field is at offset 4. Pass it back. */ | |||
8046 | *tid = bfd_get_32 (abfd, (bfd_byte *) ddata + 4)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) ddata + 4) ); | |||
8047 | ||||
8048 | /* nto_procfs_status 'flags' field is at offset 8. */ | |||
8049 | flags = bfd_get_32 (abfd, (bfd_byte *) ddata + 8)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) ddata + 8) ); | |||
8050 | ||||
8051 | /* nto_procfs_status 'what' field is at offset 14. */ | |||
8052 | if ((sig = bfd_get_16 (abfd, (bfd_byte *) ddata + 14)((*((abfd)->xvec->bfd_getx16)) ((bfd_byte *) ddata + 14 ))) > 0) | |||
8053 | { | |||
8054 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal = sig; | |||
8055 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = *tid; | |||
8056 | } | |||
8057 | ||||
8058 | /* _DEBUG_FLAG_CURTID (current thread) is 0x80. Some cores | |||
8059 | do not come from signals so we make sure we set the current | |||
8060 | thread just in case. */ | |||
8061 | if (flags & 0x00000080) | |||
8062 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid = *tid; | |||
8063 | ||||
8064 | /* Make a ".qnx_core_status/%d" section. */ | |||
8065 | sprintf (buf, ".qnx_core_status/%ld", (long) *tid); | |||
8066 | ||||
8067 | name = bfd_alloc (abfd, strlen (buf) + 1); | |||
8068 | if (name == NULL((void*)0)) | |||
8069 | return FALSE0; | |||
8070 | strcpy (name, buf); | |||
8071 | ||||
8072 | sect = bfd_make_section_anyway (abfd, name); | |||
8073 | if (sect == NULL((void*)0)) | |||
8074 | return FALSE0; | |||
8075 | ||||
8076 | sect->size = note->descsz; | |||
8077 | sect->filepos = note->descpos; | |||
8078 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
8079 | sect->alignment_power = 2; | |||
8080 | ||||
8081 | return (elfcore_maybe_make_sect (abfd, ".qnx_core_status", sect)); | |||
8082 | } | |||
8083 | ||||
8084 | static bfd_boolean | |||
8085 | elfcore_grok_nto_regs (bfd *abfd, | |||
8086 | Elf_Internal_Note *note, | |||
8087 | pid_t tid, | |||
8088 | char *base) | |||
8089 | { | |||
8090 | char buf[100]; | |||
8091 | char *name; | |||
8092 | asection *sect; | |||
8093 | ||||
8094 | /* Make a "(base)/%d" section. */ | |||
8095 | sprintf (buf, "%s/%ld", base, (long) tid); | |||
8096 | ||||
8097 | name = bfd_alloc (abfd, strlen (buf) + 1); | |||
8098 | if (name == NULL((void*)0)) | |||
8099 | return FALSE0; | |||
8100 | strcpy (name, buf); | |||
8101 | ||||
8102 | sect = bfd_make_section_anyway (abfd, name); | |||
8103 | if (sect == NULL((void*)0)) | |||
8104 | return FALSE0; | |||
8105 | ||||
8106 | sect->size = note->descsz; | |||
8107 | sect->filepos = note->descpos; | |||
8108 | sect->flags = SEC_HAS_CONTENTS0x100; | |||
8109 | sect->alignment_power = 2; | |||
8110 | ||||
8111 | /* This is the current thread. */ | |||
8112 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_lwpid == tid) | |||
8113 | return elfcore_maybe_make_sect (abfd, base, sect); | |||
8114 | ||||
8115 | return TRUE1; | |||
8116 | } | |||
8117 | ||||
8118 | #define BFD_QNT_CORE_INFO7 7 | |||
8119 | #define BFD_QNT_CORE_STATUS8 8 | |||
8120 | #define BFD_QNT_CORE_GREG9 9 | |||
8121 | #define BFD_QNT_CORE_FPREG10 10 | |||
8122 | ||||
8123 | static bfd_boolean | |||
8124 | elfcore_grok_nto_note (bfd *abfd, Elf_Internal_Note *note) | |||
8125 | { | |||
8126 | /* Every GREG section has a STATUS section before it. Store the | |||
8127 | tid from the previous call to pass down to the next gregs | |||
8128 | function. */ | |||
8129 | static pid_t tid = 1; | |||
8130 | ||||
8131 | switch (note->type) | |||
8132 | { | |||
8133 | case BFD_QNT_CORE_INFO7: | |||
8134 | return elfcore_make_note_pseudosection (abfd, ".qnx_core_info", note); | |||
8135 | case BFD_QNT_CORE_STATUS8: | |||
8136 | return elfcore_grok_nto_status (abfd, note, &tid); | |||
8137 | case BFD_QNT_CORE_GREG9: | |||
8138 | return elfcore_grok_nto_regs (abfd, note, tid, ".reg"); | |||
8139 | case BFD_QNT_CORE_FPREG10: | |||
8140 | return elfcore_grok_nto_regs (abfd, note, tid, ".reg2"); | |||
8141 | default: | |||
8142 | return TRUE1; | |||
8143 | } | |||
8144 | } | |||
8145 | ||||
8146 | /* Function: elfcore_write_note | |||
8147 | ||||
8148 | Inputs: | |||
8149 | buffer to hold note | |||
8150 | name of note | |||
8151 | type of note | |||
8152 | data for note | |||
8153 | size of data for note | |||
8154 | ||||
8155 | Return: | |||
8156 | End of buffer containing note. */ | |||
8157 | ||||
8158 | char * | |||
8159 | elfcore_write_note (bfd *abfd, | |||
8160 | char *buf, | |||
8161 | int *bufsiz, | |||
8162 | const char *name, | |||
8163 | int type, | |||
8164 | const void *input, | |||
8165 | int size) | |||
8166 | { | |||
8167 | Elf_External_Note *xnp; | |||
8168 | size_t namesz; | |||
8169 | size_t pad; | |||
8170 | size_t newspace; | |||
8171 | char *p, *dest; | |||
8172 | ||||
8173 | namesz = 0; | |||
8174 | pad = 0; | |||
8175 | if (name != NULL((void*)0)) | |||
8176 | { | |||
8177 | const struct elf_backend_data *bed; | |||
8178 | ||||
8179 | namesz = strlen (name) + 1; | |||
8180 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
8181 | pad = -namesz & ((1 << bed->s->log_file_align) - 1); | |||
8182 | } | |||
8183 | ||||
8184 | newspace = 12 + namesz + pad + size; | |||
8185 | ||||
8186 | p = realloc (buf, *bufsiz + newspace); | |||
8187 | dest = p + *bufsiz; | |||
8188 | *bufsiz += newspace; | |||
8189 | xnp = (Elf_External_Note *) dest; | |||
8190 | H_PUT_32 (abfd, namesz, xnp->namesz)((*((abfd)->xvec->bfd_h_putx32)) (namesz, xnp->namesz )); | |||
8191 | H_PUT_32 (abfd, size, xnp->descsz)((*((abfd)->xvec->bfd_h_putx32)) (size, xnp->descsz) ); | |||
8192 | H_PUT_32 (abfd, type, xnp->type)((*((abfd)->xvec->bfd_h_putx32)) (type, xnp->type)); | |||
8193 | dest = xnp->name; | |||
8194 | if (name != NULL((void*)0)) | |||
8195 | { | |||
8196 | memcpy (dest, name, namesz); | |||
8197 | dest += namesz; | |||
8198 | while (pad != 0) | |||
8199 | { | |||
8200 | *dest++ = '\0'; | |||
8201 | --pad; | |||
8202 | } | |||
8203 | } | |||
8204 | memcpy (dest, input, size); | |||
8205 | return p; | |||
8206 | } | |||
8207 | ||||
8208 | #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) | |||
8209 | char * | |||
8210 | elfcore_write_prpsinfo (bfd *abfd, | |||
8211 | char *buf, | |||
8212 | int *bufsiz, | |||
8213 | const char *fname, | |||
8214 | const char *psargs) | |||
8215 | { | |||
8216 | int note_type; | |||
8217 | char *note_name = "CORE"; | |||
8218 | ||||
8219 | #if defined (HAVE_PSINFO_T) | |||
8220 | psinfo_t data; | |||
8221 | note_type = NT_PSINFO13; | |||
8222 | #else | |||
8223 | prpsinfo_t data; | |||
8224 | note_type = NT_PRPSINFO3; | |||
8225 | #endif | |||
8226 | ||||
8227 | memset (&data, 0, sizeof (data)); | |||
8228 | strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); | |||
8229 | strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); | |||
8230 | return elfcore_write_note (abfd, buf, bufsiz, | |||
8231 | note_name, note_type, &data, sizeof (data)); | |||
8232 | } | |||
8233 | #endif /* PSINFO_T or PRPSINFO_T */ | |||
8234 | ||||
8235 | #if defined (HAVE_PRSTATUS_T) | |||
8236 | char * | |||
8237 | elfcore_write_prstatus (bfd *abfd, | |||
8238 | char *buf, | |||
8239 | int *bufsiz, | |||
8240 | long pid, | |||
8241 | int cursig, | |||
8242 | const void *gregs) | |||
8243 | { | |||
8244 | prstatus_t prstat; | |||
8245 | char *note_name = "CORE"; | |||
8246 | ||||
8247 | memset (&prstat, 0, sizeof (prstat)); | |||
8248 | prstat.pr_pid = pid; | |||
8249 | prstat.pr_cursig = cursig; | |||
8250 | memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); | |||
8251 | return elfcore_write_note (abfd, buf, bufsiz, | |||
8252 | note_name, NT_PRSTATUS1, &prstat, sizeof (prstat)); | |||
8253 | } | |||
8254 | #endif /* HAVE_PRSTATUS_T */ | |||
8255 | ||||
8256 | #if defined (HAVE_LWPSTATUS_T) | |||
8257 | char * | |||
8258 | elfcore_write_lwpstatus (bfd *abfd, | |||
8259 | char *buf, | |||
8260 | int *bufsiz, | |||
8261 | long pid, | |||
8262 | int cursig, | |||
8263 | const void *gregs) | |||
8264 | { | |||
8265 | lwpstatus_t lwpstat; | |||
8266 | char *note_name = "CORE"; | |||
8267 | ||||
8268 | memset (&lwpstat, 0, sizeof (lwpstat)); | |||
8269 | lwpstat.pr_lwpid = pid >> 16; | |||
8270 | lwpstat.pr_cursig = cursig; | |||
8271 | #if defined (HAVE_LWPSTATUS_T_PR_REG) | |||
8272 | memcpy (lwpstat.pr_reg, gregs, sizeof (lwpstat.pr_reg)); | |||
8273 | #elif defined (HAVE_LWPSTATUS_T_PR_CONTEXT) | |||
8274 | #if !defined(gregs) | |||
8275 | memcpy (lwpstat.pr_context.uc_mcontext.gregs, | |||
8276 | gregs, sizeof (lwpstat.pr_context.uc_mcontext.gregs)); | |||
8277 | #else | |||
8278 | memcpy (lwpstat.pr_context.uc_mcontext.__gregs, | |||
8279 | gregs, sizeof (lwpstat.pr_context.uc_mcontext.__gregs)); | |||
8280 | #endif | |||
8281 | #endif | |||
8282 | return elfcore_write_note (abfd, buf, bufsiz, note_name, | |||
8283 | NT_LWPSTATUS16, &lwpstat, sizeof (lwpstat)); | |||
8284 | } | |||
8285 | #endif /* HAVE_LWPSTATUS_T */ | |||
8286 | ||||
8287 | #if defined (HAVE_PSTATUS_T) | |||
8288 | char * | |||
8289 | elfcore_write_pstatus (bfd *abfd, | |||
8290 | char *buf, | |||
8291 | int *bufsiz, | |||
8292 | long pid, | |||
8293 | int cursig ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
8294 | const void *gregs ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
8295 | { | |||
8296 | pstatus_t pstat; | |||
8297 | char *note_name = "CORE"; | |||
8298 | ||||
8299 | memset (&pstat, 0, sizeof (pstat)); | |||
8300 | pstat.pr_pid = pid & 0xffff; | |||
8301 | buf = elfcore_write_note (abfd, buf, bufsiz, note_name, | |||
8302 | NT_PSTATUS10, &pstat, sizeof (pstat)); | |||
8303 | return buf; | |||
8304 | } | |||
8305 | #endif /* HAVE_PSTATUS_T */ | |||
8306 | ||||
8307 | char * | |||
8308 | elfcore_write_prfpreg (bfd *abfd, | |||
8309 | char *buf, | |||
8310 | int *bufsiz, | |||
8311 | const void *fpregs, | |||
8312 | int size) | |||
8313 | { | |||
8314 | char *note_name = "CORE"; | |||
8315 | return elfcore_write_note (abfd, buf, bufsiz, | |||
8316 | note_name, NT_FPREGSET2, fpregs, size); | |||
8317 | } | |||
8318 | ||||
8319 | char * | |||
8320 | elfcore_write_prxfpreg (bfd *abfd, | |||
8321 | char *buf, | |||
8322 | int *bufsiz, | |||
8323 | const void *xfpregs, | |||
8324 | int size) | |||
8325 | { | |||
8326 | char *note_name = "LINUX"; | |||
8327 | return elfcore_write_note (abfd, buf, bufsiz, | |||
8328 | note_name, NT_PRXFPREG0x46e62b7f, xfpregs, size); | |||
8329 | } | |||
8330 | ||||
8331 | static bfd_boolean | |||
8332 | elfcore_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size) | |||
8333 | { | |||
8334 | char *buf; | |||
8335 | char *p; | |||
8336 | ||||
8337 | if (size <= 0) | |||
8338 | return TRUE1; | |||
8339 | ||||
8340 | if (bfd_seek (abfd, offset, SEEK_SET0) != 0) | |||
8341 | return FALSE0; | |||
8342 | ||||
8343 | buf = bfd_malloc (size); | |||
8344 | if (buf == NULL((void*)0)) | |||
8345 | return FALSE0; | |||
8346 | ||||
8347 | if (bfd_bread (buf, size, abfd) != size) | |||
8348 | { | |||
8349 | error: | |||
8350 | free (buf); | |||
8351 | return FALSE0; | |||
8352 | } | |||
8353 | ||||
8354 | p = buf; | |||
8355 | while (p < buf + size) | |||
8356 | { | |||
8357 | /* FIXME: bad alignment assumption. */ | |||
8358 | Elf_External_Note *xnp = (Elf_External_Note *) p; | |||
8359 | Elf_Internal_Note in; | |||
8360 | ||||
8361 | in.type = H_GET_32 (abfd, xnp->type)((*((abfd)->xvec->bfd_h_getx32)) (xnp->type)); | |||
8362 | ||||
8363 | in.namesz = H_GET_32 (abfd, xnp->namesz)((*((abfd)->xvec->bfd_h_getx32)) (xnp->namesz)); | |||
8364 | in.namedata = xnp->name; | |||
8365 | ||||
8366 | in.descsz = H_GET_32 (abfd, xnp->descsz)((*((abfd)->xvec->bfd_h_getx32)) (xnp->descsz)); | |||
8367 | in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4)((((bfd_vma) (in.namesz) + (4) - 1) >= (bfd_vma) (in.namesz )) ? (((bfd_vma) (in.namesz) + ((4) - 1)) & ~ (bfd_vma) ( (4)-1)) : ~ (bfd_vma) 0); | |||
8368 | in.descpos = offset + (in.descdata - buf); | |||
8369 | ||||
8370 | if (strncmp (in.namedata, "NetBSD-CORE", 11) == 0) | |||
8371 | { | |||
8372 | if (! elfcore_grok_netbsd_note (abfd, &in)) | |||
8373 | goto error; | |||
8374 | } | |||
8375 | else if (strncmp (in.namedata, "OpenBSD", 7) == 0) | |||
8376 | { | |||
8377 | if (! elfcore_grok_openbsd_note (abfd, &in)) | |||
8378 | goto error; | |||
8379 | } | |||
8380 | else if (strncmp (in.namedata, "QNX", 3) == 0) | |||
8381 | { | |||
8382 | if (! elfcore_grok_nto_note (abfd, &in)) | |||
8383 | goto error; | |||
8384 | } | |||
8385 | else | |||
8386 | { | |||
8387 | if (! elfcore_grok_note (abfd, &in)) | |||
8388 | goto error; | |||
8389 | } | |||
8390 | ||||
8391 | p = in.descdata + BFD_ALIGN (in.descsz, 4)((((bfd_vma) (in.descsz) + (4) - 1) >= (bfd_vma) (in.descsz )) ? (((bfd_vma) (in.descsz) + ((4) - 1)) & ~ (bfd_vma) ( (4)-1)) : ~ (bfd_vma) 0); | |||
8392 | } | |||
8393 | ||||
8394 | free (buf); | |||
8395 | return TRUE1; | |||
8396 | } | |||
8397 | ||||
8398 | /* Providing external access to the ELF program header table. */ | |||
8399 | ||||
8400 | /* Return an upper bound on the number of bytes required to store a | |||
8401 | copy of ABFD's program header table entries. Return -1 if an error | |||
8402 | occurs; bfd_get_error will return an appropriate code. */ | |||
8403 | ||||
8404 | long | |||
8405 | bfd_get_elf_phdr_upper_bound (bfd *abfd) | |||
8406 | { | |||
8407 | if (abfd->xvec->flavour != bfd_target_elf_flavour) | |||
8408 | { | |||
8409 | bfd_set_error (bfd_error_wrong_format); | |||
8410 | return -1; | |||
8411 | } | |||
8412 | ||||
8413 | return elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum * sizeof (Elf_Internal_Phdr); | |||
8414 | } | |||
8415 | ||||
8416 | /* Copy ABFD's program header table entries to *PHDRS. The entries | |||
8417 | will be stored as an array of Elf_Internal_Phdr structures, as | |||
8418 | defined in include/elf/internal.h. To find out how large the | |||
8419 | buffer needs to be, call bfd_get_elf_phdr_upper_bound. | |||
8420 | ||||
8421 | Return the number of program header table entries read, or -1 if an | |||
8422 | error occurs; bfd_get_error will return an appropriate code. */ | |||
8423 | ||||
8424 | int | |||
8425 | bfd_get_elf_phdrs (bfd *abfd, void *phdrs) | |||
8426 | { | |||
8427 | int num_phdrs; | |||
8428 | ||||
8429 | if (abfd->xvec->flavour != bfd_target_elf_flavour) | |||
8430 | { | |||
8431 | bfd_set_error (bfd_error_wrong_format); | |||
8432 | return -1; | |||
8433 | } | |||
8434 | ||||
8435 | num_phdrs = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_phnum; | |||
8436 | memcpy (phdrs, elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->phdr, | |||
8437 | num_phdrs * sizeof (Elf_Internal_Phdr)); | |||
8438 | ||||
8439 | return num_phdrs; | |||
8440 | } | |||
8441 | ||||
8442 | void | |||
8443 | _bfd_elf_sprintf_vma (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), char *buf, bfd_vma value) | |||
8444 | { | |||
8445 | #ifdef BFD64 | |||
8446 | Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ | |||
8447 | ||||
8448 | i_ehdrp = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header); | |||
8449 | if (i_ehdrp == NULL((void*)0)) | |||
8450 | sprintf_vma (buf, value)sprintf (buf, "%016lx", value); | |||
8451 | else | |||
8452 | { | |||
8453 | if (i_ehdrp->e_ident[EI_CLASS4] == ELFCLASS642) | |||
8454 | { | |||
8455 | #if BFD_HOST_64BIT_LONG1 | |||
8456 | sprintf (buf, "%016lx", value); | |||
8457 | #else | |||
8458 | sprintf (buf, "%08lx%08lx", _bfd_int64_high (value), | |||
8459 | _bfd_int64_low (value)); | |||
8460 | #endif | |||
8461 | } | |||
8462 | else | |||
8463 | sprintf (buf, "%08lx", (unsigned long) (value & 0xffffffff)); | |||
8464 | } | |||
8465 | #else | |||
8466 | sprintf_vma (buf, value)sprintf (buf, "%016lx", value); | |||
8467 | #endif | |||
8468 | } | |||
8469 | ||||
8470 | void | |||
8471 | _bfd_elf_fprintf_vma (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), void *stream, bfd_vma value) | |||
8472 | { | |||
8473 | #ifdef BFD64 | |||
8474 | Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ | |||
8475 | ||||
8476 | i_ehdrp = elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header); | |||
8477 | if (i_ehdrp == NULL((void*)0)) | |||
8478 | fprintf_vma ((FILE *) stream, value)fprintf ((FILE *) stream, "%016lx", value); | |||
8479 | else | |||
8480 | { | |||
8481 | if (i_ehdrp->e_ident[EI_CLASS4] == ELFCLASS642) | |||
8482 | { | |||
8483 | #if BFD_HOST_64BIT_LONG1 | |||
8484 | fprintf ((FILE *) stream, "%016lx", value); | |||
8485 | #else | |||
8486 | fprintf ((FILE *) stream, "%08lx%08lx", | |||
8487 | _bfd_int64_high (value), _bfd_int64_low (value)); | |||
8488 | #endif | |||
8489 | } | |||
8490 | else | |||
8491 | fprintf ((FILE *) stream, "%08lx", | |||
8492 | (unsigned long) (value & 0xffffffff)); | |||
8493 | } | |||
8494 | #else | |||
8495 | fprintf_vma ((FILE *) stream, value)fprintf ((FILE *) stream, "%016lx", value); | |||
8496 | #endif | |||
8497 | } | |||
8498 | ||||
8499 | enum elf_reloc_type_class | |||
8500 | _bfd_elf_reloc_type_class (const Elf_Internal_Rela *rela ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
8501 | { | |||
8502 | return reloc_class_normal; | |||
8503 | } | |||
8504 | ||||
8505 | /* For RELA architectures, return the relocation value for a | |||
8506 | relocation against a local symbol. */ | |||
8507 | ||||
8508 | bfd_vma | |||
8509 | _bfd_elf_rela_local_sym (bfd *abfd, | |||
8510 | Elf_Internal_Sym *sym, | |||
8511 | asection **psec, | |||
8512 | Elf_Internal_Rela *rel) | |||
8513 | { | |||
8514 | asection *sec = *psec; | |||
8515 | bfd_vma relocation; | |||
8516 | ||||
8517 | relocation = (sec->output_section->vma | |||
8518 | + sec->output_offset | |||
8519 | + sym->st_value); | |||
8520 | if ((sec->flags & SEC_MERGE0x1000000) | |||
8521 | && ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) == STT_SECTION3 | |||
8522 | && sec->sec_info_type == ELF_INFO_TYPE_MERGE2) | |||
8523 | { | |||
8524 | rel->r_addend = | |||
8525 | _bfd_merged_section_offset (abfd, psec, | |||
8526 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->sec_info, | |||
8527 | sym->st_value + rel->r_addend); | |||
8528 | if (sec != *psec) | |||
8529 | { | |||
8530 | /* If we have changed the section, and our original section is | |||
8531 | marked with SEC_EXCLUDE, it means that the original | |||
8532 | SEC_MERGE section has been completely subsumed in some | |||
8533 | other SEC_MERGE section. In this case, we need to leave | |||
8534 | some info around for --emit-relocs. */ | |||
8535 | if ((sec->flags & SEC_EXCLUDE0x8000) != 0) | |||
8536 | sec->kept_section = *psec; | |||
8537 | sec = *psec; | |||
8538 | } | |||
8539 | rel->r_addend -= relocation; | |||
8540 | rel->r_addend += sec->output_section->vma + sec->output_offset; | |||
8541 | } | |||
8542 | return relocation; | |||
8543 | } | |||
8544 | ||||
8545 | bfd_vma | |||
8546 | _bfd_elf_rel_local_sym (bfd *abfd, | |||
8547 | Elf_Internal_Sym *sym, | |||
8548 | asection **psec, | |||
8549 | bfd_vma addend) | |||
8550 | { | |||
8551 | asection *sec = *psec; | |||
8552 | ||||
8553 | if (sec->sec_info_type != ELF_INFO_TYPE_MERGE2) | |||
8554 | return sym->st_value + addend; | |||
8555 | ||||
8556 | return _bfd_merged_section_offset (abfd, psec, | |||
8557 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->sec_info, | |||
8558 | sym->st_value + addend); | |||
8559 | } | |||
8560 | ||||
8561 | bfd_vma | |||
8562 | _bfd_elf_section_offset (bfd *abfd, | |||
8563 | struct bfd_link_info *info, | |||
8564 | asection *sec, | |||
8565 | bfd_vma offset) | |||
8566 | { | |||
8567 | switch (sec->sec_info_type) | |||
8568 | { | |||
8569 | case ELF_INFO_TYPE_STABS1: | |||
8570 | return _bfd_stab_section_offset (sec, elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->sec_info, | |||
8571 | offset); | |||
8572 | case ELF_INFO_TYPE_EH_FRAME3: | |||
8573 | return _bfd_elf_eh_frame_section_offset (abfd, info, sec, offset); | |||
8574 | default: | |||
8575 | return offset; | |||
8576 | } | |||
8577 | } | |||
8578 | ||||
8579 | /* Create a new BFD as if by bfd_openr. Rather than opening a file, | |||
8580 | reconstruct an ELF file by reading the segments out of remote memory | |||
8581 | based on the ELF file header at EHDR_VMA and the ELF program headers it | |||
8582 | points to. If not null, *LOADBASEP is filled in with the difference | |||
8583 | between the VMAs from which the segments were read, and the VMAs the | |||
8584 | file headers (and hence BFD's idea of each section's VMA) put them at. | |||
8585 | ||||
8586 | The function TARGET_READ_MEMORY is called to copy LEN bytes from the | |||
8587 | remote memory at target address VMA into the local buffer at MYADDR; it | |||
8588 | should return zero on success or an `errno' code on failure. TEMPL must | |||
8589 | be a BFD for an ELF target with the word size and byte order found in | |||
8590 | the remote memory. */ | |||
8591 | ||||
8592 | bfd * | |||
8593 | bfd_elf_bfd_from_remote_memory | |||
8594 | (bfd *templ, | |||
8595 | bfd_vma ehdr_vma, | |||
8596 | bfd_vma *loadbasep, | |||
8597 | int (*target_read_memory) (bfd_vma, bfd_byte *, int)) | |||
8598 | { | |||
8599 | return (*get_elf_backend_data (templ)((const struct elf_backend_data *) (templ)->xvec->backend_data )->elf_backend_bfd_from_remote_memory) | |||
8600 | (templ, ehdr_vma, loadbasep, target_read_memory); | |||
8601 | } | |||
8602 | ||||
8603 | long | |||
8604 | _bfd_elf_get_synthetic_symtab (bfd *abfd, | |||
8605 | long symcount ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
8606 | asymbol **syms ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
8607 | long dynsymcount, | |||
8608 | asymbol **dynsyms, | |||
8609 | asymbol **ret) | |||
8610 | { | |||
8611 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
8612 | asection *relplt; | |||
8613 | asymbol *s; | |||
8614 | const char *relplt_name; | |||
8615 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); | |||
8616 | arelent *p; | |||
8617 | long count, i, n; | |||
8618 | size_t size; | |||
8619 | Elf_Internal_Shdr *hdr; | |||
8620 | char *names; | |||
8621 | asection *plt; | |||
8622 | ||||
8623 | *ret = NULL((void*)0); | |||
8624 | ||||
8625 | if ((abfd->flags & (DYNAMIC0x40 | EXEC_P0x02)) == 0) | |||
8626 | return 0; | |||
8627 | ||||
8628 | if (dynsymcount <= 0) | |||
8629 | return 0; | |||
8630 | ||||
8631 | if (!bed->plt_sym_val) | |||
8632 | return 0; | |||
8633 | ||||
8634 | relplt_name = bed->relplt_name; | |||
8635 | if (relplt_name == NULL((void*)0)) | |||
8636 | relplt_name = bed->default_use_rela_p ? ".rela.plt" : ".rel.plt"; | |||
8637 | relplt = bfd_get_section_by_name (abfd, relplt_name); | |||
8638 | if (relplt == NULL((void*)0)) | |||
8639 | return 0; | |||
8640 | ||||
8641 | hdr = &elf_section_data (relplt)((struct bfd_elf_section_data*)(relplt)->used_by_bfd)->this_hdr; | |||
8642 | if (hdr->sh_link != elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) | |||
8643 | || (hdr->sh_type != SHT_REL9 && hdr->sh_type != SHT_RELA4)) | |||
8644 | return 0; | |||
8645 | ||||
8646 | plt = bfd_get_section_by_name (abfd, ".plt"); | |||
8647 | if (plt == NULL((void*)0)) | |||
8648 | return 0; | |||
8649 | ||||
8650 | slurp_relocs = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->slurp_reloc_table; | |||
8651 | if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE1)) | |||
8652 | return -1; | |||
8653 | ||||
8654 | count = relplt->size / hdr->sh_entsize; | |||
8655 | size = count * sizeof (asymbol); | |||
8656 | p = relplt->relocation; | |||
8657 | for (i = 0; i < count; i++, p++) | |||
8658 | size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); | |||
8659 | ||||
8660 | s = *ret = bfd_malloc (size); | |||
8661 | if (s == NULL((void*)0)) | |||
8662 | return -1; | |||
8663 | ||||
8664 | names = (char *) (s + count); | |||
8665 | p = relplt->relocation; | |||
8666 | n = 0; | |||
8667 | for (i = 0; i < count; i++, s++, p++) | |||
8668 | { | |||
8669 | size_t len; | |||
8670 | bfd_vma addr; | |||
8671 | ||||
8672 | addr = bed->plt_sym_val (i, plt, p); | |||
8673 | if (addr == (bfd_vma) -1) | |||
8674 | continue; | |||
8675 | ||||
8676 | *s = **p->sym_ptr_ptr; | |||
8677 | /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since | |||
8678 | we are defining a symbol, ensure one of them is set. */ | |||
8679 | if ((s->flags & BSF_LOCAL0x01) == 0) | |||
8680 | s->flags |= BSF_GLOBAL0x02; | |||
8681 | s->section = plt; | |||
8682 | s->value = addr - plt->vma; | |||
8683 | s->name = names; | |||
8684 | len = strlen ((*p->sym_ptr_ptr)->name); | |||
8685 | memcpy (names, (*p->sym_ptr_ptr)->name, len); | |||
8686 | names += len; | |||
8687 | memcpy (names, "@plt", sizeof ("@plt")); | |||
8688 | names += sizeof ("@plt"); | |||
8689 | ++n; | |||
8690 | } | |||
8691 | ||||
8692 | return n; | |||
8693 | } | |||
8694 | ||||
8695 | /* Sort symbol by binding and section. We want to put definitions | |||
8696 | sorted by section at the beginning. */ | |||
8697 | ||||
8698 | static int | |||
8699 | elf_sort_elf_symbol (const void *arg1, const void *arg2) | |||
8700 | { | |||
8701 | const Elf_Internal_Sym *s1; | |||
8702 | const Elf_Internal_Sym *s2; | |||
8703 | int shndx; | |||
8704 | ||||
8705 | /* Make sure that undefined symbols are at the end. */ | |||
8706 | s1 = (const Elf_Internal_Sym *) arg1; | |||
8707 | if (s1->st_shndx == SHN_UNDEF0) | |||
8708 | return 1; | |||
8709 | s2 = (const Elf_Internal_Sym *) arg2; | |||
8710 | if (s2->st_shndx == SHN_UNDEF0) | |||
8711 | return -1; | |||
8712 | ||||
8713 | /* Sorted by section index. */ | |||
8714 | shndx = s1->st_shndx - s2->st_shndx; | |||
8715 | if (shndx != 0) | |||
8716 | return shndx; | |||
8717 | ||||
8718 | /* Sorted by binding. */ | |||
8719 | return ELF_ST_BIND (s1->st_info)(((unsigned int)(s1->st_info)) >> 4) - ELF_ST_BIND (s2->st_info)(((unsigned int)(s2->st_info)) >> 4); | |||
8720 | } | |||
8721 | ||||
8722 | struct elf_symbol | |||
8723 | { | |||
8724 | Elf_Internal_Sym *sym; | |||
8725 | const char *name; | |||
8726 | }; | |||
8727 | ||||
8728 | static int | |||
8729 | elf_sym_name_compare (const void *arg1, const void *arg2) | |||
8730 | { | |||
8731 | const struct elf_symbol *s1 = (const struct elf_symbol *) arg1; | |||
8732 | const struct elf_symbol *s2 = (const struct elf_symbol *) arg2; | |||
8733 | return strcmp (s1->name, s2->name); | |||
8734 | } | |||
8735 | ||||
8736 | /* Check if 2 sections define the same set of local and global | |||
8737 | symbols. */ | |||
8738 | ||||
8739 | bfd_boolean | |||
8740 | bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, | |||
8741 | struct bfd_link_info *info) | |||
8742 | { | |||
8743 | bfd *bfd1, *bfd2; | |||
8744 | const struct elf_backend_data *bed1, *bed2; | |||
8745 | Elf_Internal_Shdr *hdr1, *hdr2; | |||
8746 | bfd_size_type symcount1, symcount2; | |||
8747 | Elf_Internal_Sym *isymbuf1, *isymbuf2; | |||
8748 | Elf_Internal_Sym *isymstart1 = NULL((void*)0), *isymstart2 = NULL((void*)0), *isym; | |||
8749 | Elf_Internal_Sym *isymend; | |||
8750 | struct elf_symbol *symp, *symtable1 = NULL((void*)0), *symtable2 = NULL((void*)0); | |||
8751 | bfd_size_type count1, count2, i; | |||
8752 | int shndx1, shndx2; | |||
8753 | bfd_boolean result; | |||
8754 | ||||
8755 | bfd1 = sec1->owner; | |||
8756 | bfd2 = sec2->owner; | |||
8757 | ||||
8758 | /* If both are .gnu.linkonce sections, they have to have the same | |||
8759 | section name. */ | |||
8760 | if (strncmp (sec1->name, ".gnu.linkonce", | |||
8761 | sizeof ".gnu.linkonce" - 1) == 0 | |||
8762 | && strncmp (sec2->name, ".gnu.linkonce", | |||
8763 | sizeof ".gnu.linkonce" - 1) == 0) | |||
8764 | return strcmp (sec1->name + sizeof ".gnu.linkonce", | |||
8765 | sec2->name + sizeof ".gnu.linkonce") == 0; | |||
8766 | ||||
8767 | /* Both sections have to be in ELF. */ | |||
8768 | if (bfd_get_flavour (bfd1)((bfd1)->xvec->flavour) != bfd_target_elf_flavour | |||
8769 | || bfd_get_flavour (bfd2)((bfd2)->xvec->flavour) != bfd_target_elf_flavour) | |||
8770 | return FALSE0; | |||
8771 | ||||
8772 | if (elf_section_type (sec1)(((struct bfd_elf_section_data*)(sec1)->used_by_bfd)->this_hdr .sh_type) != elf_section_type (sec2)(((struct bfd_elf_section_data*)(sec2)->used_by_bfd)->this_hdr .sh_type)) | |||
8773 | return FALSE0; | |||
8774 | ||||
8775 | if ((elf_section_flags (sec1)(((struct bfd_elf_section_data*)(sec1)->used_by_bfd)->this_hdr .sh_flags) & SHF_GROUP(1 << 9)) != 0 | |||
8776 | && (elf_section_flags (sec2)(((struct bfd_elf_section_data*)(sec2)->used_by_bfd)->this_hdr .sh_flags) & SHF_GROUP(1 << 9)) != 0) | |||
8777 | { | |||
8778 | /* If both are members of section groups, they have to have the | |||
8779 | same group name. */ | |||
8780 | if (strcmp (elf_group_name (sec1)(((struct bfd_elf_section_data*)(sec1)->used_by_bfd)->group .name), elf_group_name (sec2)(((struct bfd_elf_section_data*)(sec2)->used_by_bfd)->group .name)) != 0) | |||
8781 | return FALSE0; | |||
8782 | } | |||
8783 | ||||
8784 | shndx1 = _bfd_elf_section_from_bfd_section (bfd1, sec1); | |||
8785 | shndx2 = _bfd_elf_section_from_bfd_section (bfd2, sec2); | |||
8786 | if (shndx1 == -1 || shndx2 == -1) | |||
8787 | return FALSE0; | |||
8788 | ||||
8789 | bed1 = get_elf_backend_data (bfd1)((const struct elf_backend_data *) (bfd1)->xvec->backend_data ); | |||
8790 | bed2 = get_elf_backend_data (bfd2)((const struct elf_backend_data *) (bfd2)->xvec->backend_data ); | |||
8791 | hdr1 = &elf_tdata (bfd1)((bfd1) -> tdata.elf_obj_data)->symtab_hdr; | |||
8792 | symcount1 = hdr1->sh_size / bed1->s->sizeof_sym; | |||
8793 | hdr2 = &elf_tdata (bfd2)((bfd2) -> tdata.elf_obj_data)->symtab_hdr; | |||
8794 | symcount2 = hdr2->sh_size / bed2->s->sizeof_sym; | |||
8795 | ||||
8796 | if (symcount1 == 0 || symcount2 == 0) | |||
8797 | return FALSE0; | |||
8798 | ||||
8799 | result = FALSE0; | |||
8800 | isymbuf1 = elf_tdata (bfd1)((bfd1) -> tdata.elf_obj_data)->symbuf; | |||
8801 | isymbuf2 = elf_tdata (bfd2)((bfd2) -> tdata.elf_obj_data)->symbuf; | |||
8802 | ||||
8803 | if (isymbuf1 == NULL((void*)0)) | |||
8804 | { | |||
8805 | isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0, | |||
8806 | NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
8807 | if (isymbuf1 == NULL((void*)0)) | |||
8808 | goto done; | |||
8809 | /* Sort symbols by binding and section. Global definitions are at | |||
8810 | the beginning. */ | |||
8811 | qsort (isymbuf1, symcount1, sizeof (Elf_Internal_Sym), | |||
8812 | elf_sort_elf_symbol); | |||
8813 | if (!info->reduce_memory_overheads) | |||
8814 | elf_tdata (bfd1)((bfd1) -> tdata.elf_obj_data)->symbuf = isymbuf1; | |||
8815 | } | |||
8816 | ||||
8817 | if (isymbuf2 == NULL((void*)0)) | |||
8818 | { | |||
8819 | isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0, | |||
8820 | NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
8821 | if (isymbuf2 == NULL((void*)0)) | |||
8822 | goto done; | |||
8823 | /* Sort symbols by binding and section. Global definitions are at | |||
8824 | the beginning. */ | |||
8825 | qsort (isymbuf2, symcount2, sizeof (Elf_Internal_Sym), | |||
8826 | elf_sort_elf_symbol); | |||
8827 | if (!info->reduce_memory_overheads) | |||
8828 | elf_tdata (bfd2)((bfd2) -> tdata.elf_obj_data)->symbuf = isymbuf2; | |||
8829 | } | |||
8830 | ||||
8831 | /* Count definitions in the section. */ | |||
8832 | count1 = 0; | |||
8833 | for (isym = isymbuf1, isymend = isym + symcount1; | |||
8834 | isym < isymend; isym++) | |||
8835 | { | |||
8836 | if (isym->st_shndx == (unsigned int) shndx1) | |||
8837 | { | |||
8838 | if (count1 == 0) | |||
8839 | isymstart1 = isym; | |||
8840 | count1++; | |||
8841 | } | |||
8842 | ||||
8843 | if (count1 && isym->st_shndx != (unsigned int) shndx1) | |||
8844 | break; | |||
8845 | } | |||
8846 | ||||
8847 | count2 = 0; | |||
8848 | for (isym = isymbuf2, isymend = isym + symcount2; | |||
8849 | isym < isymend; isym++) | |||
8850 | { | |||
8851 | if (isym->st_shndx == (unsigned int) shndx2) | |||
8852 | { | |||
8853 | if (count2 == 0) | |||
8854 | isymstart2 = isym; | |||
8855 | count2++; | |||
8856 | } | |||
8857 | ||||
8858 | if (count2 && isym->st_shndx != (unsigned int) shndx2) | |||
8859 | break; | |||
8860 | } | |||
8861 | ||||
8862 | if (count1 == 0 || count2 == 0 || count1 != count2) | |||
8863 | goto done; | |||
8864 | ||||
8865 | symtable1 = bfd_malloc (count1 * sizeof (struct elf_symbol)); | |||
8866 | symtable2 = bfd_malloc (count1 * sizeof (struct elf_symbol)); | |||
8867 | ||||
8868 | if (symtable1 == NULL((void*)0) || symtable2 == NULL((void*)0)) | |||
8869 | goto done; | |||
8870 | ||||
8871 | symp = symtable1; | |||
8872 | for (isym = isymstart1, isymend = isym + count1; | |||
8873 | isym < isymend; isym++) | |||
8874 | { | |||
8875 | symp->sym = isym; | |||
8876 | symp->name = bfd_elf_string_from_elf_section (bfd1, | |||
8877 | hdr1->sh_link, | |||
8878 | isym->st_name); | |||
8879 | symp++; | |||
8880 | } | |||
8881 | ||||
8882 | symp = symtable2; | |||
8883 | for (isym = isymstart2, isymend = isym + count1; | |||
8884 | isym < isymend; isym++) | |||
8885 | { | |||
8886 | symp->sym = isym; | |||
8887 | symp->name = bfd_elf_string_from_elf_section (bfd2, | |||
8888 | hdr2->sh_link, | |||
8889 | isym->st_name); | |||
8890 | symp++; | |||
8891 | } | |||
8892 | ||||
8893 | /* Sort symbol by name. */ | |||
8894 | qsort (symtable1, count1, sizeof (struct elf_symbol), | |||
8895 | elf_sym_name_compare); | |||
8896 | qsort (symtable2, count1, sizeof (struct elf_symbol), | |||
8897 | elf_sym_name_compare); | |||
8898 | ||||
8899 | for (i = 0; i < count1; i++) | |||
8900 | /* Two symbols must have the same binding, type and name. */ | |||
8901 | if (symtable1 [i].sym->st_info != symtable2 [i].sym->st_info | |||
8902 | || symtable1 [i].sym->st_other != symtable2 [i].sym->st_other | |||
8903 | || strcmp (symtable1 [i].name, symtable2 [i].name) != 0) | |||
8904 | goto done; | |||
8905 | ||||
8906 | result = TRUE1; | |||
8907 | ||||
8908 | done: | |||
8909 | if (symtable1) | |||
8910 | free (symtable1); | |||
8911 | if (symtable2) | |||
8912 | free (symtable2); | |||
8913 | if (info->reduce_memory_overheads) | |||
8914 | { | |||
8915 | if (isymbuf1) | |||
8916 | free (isymbuf1); | |||
8917 | if (isymbuf2) | |||
8918 | free (isymbuf2); | |||
8919 | } | |||
8920 | ||||
8921 | return result; | |||
8922 | } | |||
8923 | ||||
8924 | /* It is only used by x86-64 so far. */ | |||
8925 | asection _bfd_elf_large_com_section | |||
8926 | = BFD_FAKE_SECTION (_bfd_elf_large_com_section,{ "LARGE_COMMON", 0, 0, ((void*)0), ((void*)0), 0x1000, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (struct bfd_section *) &_bfd_elf_large_com_section, 0, ((void*)0), ((void*)0 ), 0, 0, 0, 0, ((void*)0), ((void*)0), ((void*)0), 0, 0, ((void *)0), 0, 0, ((void*)0), ((void*)0), ((void*)0), (struct bfd_symbol *) ((void*)0), (struct bfd_symbol **) ((void*)0), { ((void*) 0) }, { ((void*)0) } } | |||
8927 | SEC_IS_COMMON, NULL, NULL, "LARGE_COMMON",{ "LARGE_COMMON", 0, 0, ((void*)0), ((void*)0), 0x1000, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (struct bfd_section *) &_bfd_elf_large_com_section, 0, ((void*)0), ((void*)0 ), 0, 0, 0, 0, ((void*)0), ((void*)0), ((void*)0), 0, 0, ((void *)0), 0, 0, ((void*)0), ((void*)0), ((void*)0), (struct bfd_symbol *) ((void*)0), (struct bfd_symbol **) ((void*)0), { ((void*) 0) }, { ((void*)0) } } | |||
8928 | 0){ "LARGE_COMMON", 0, 0, ((void*)0), ((void*)0), 0x1000, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (struct bfd_section *) &_bfd_elf_large_com_section, 0, ((void*)0), ((void*)0 ), 0, 0, 0, 0, ((void*)0), ((void*)0), ((void*)0), 0, 0, ((void *)0), 0, 0, ((void*)0), ((void*)0), ((void*)0), (struct bfd_symbol *) ((void*)0), (struct bfd_symbol **) ((void*)0), { ((void*) 0) }, { ((void*)0) } }; | |||
8929 | ||||
8930 | /* Return TRUE if 2 section types are compatible. */ | |||
8931 | ||||
8932 | bfd_boolean | |||
8933 | _bfd_elf_match_sections_by_type (bfd *abfd, const asection *asec, | |||
8934 | bfd *bbfd, const asection *bsec) | |||
8935 | { | |||
8936 | if (asec == NULL((void*)0) | |||
8937 | || bsec == NULL((void*)0) | |||
8938 | || abfd->xvec->flavour != bfd_target_elf_flavour | |||
8939 | || bbfd->xvec->flavour != bfd_target_elf_flavour) | |||
8940 | return TRUE1; | |||
8941 | ||||
8942 | return elf_section_type (asec)(((struct bfd_elf_section_data*)(asec)->used_by_bfd)->this_hdr .sh_type) == elf_section_type (bsec)(((struct bfd_elf_section_data*)(bsec)->used_by_bfd)->this_hdr .sh_type); | |||
8943 | } |