File: | src/gnu/usr.bin/binutils-2.17/bfd/elflink.c |
Warning: | line 5470, column 15 Assigned value is garbage or undefined |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* ELF linking support for BFD. | |||
2 | Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, | |||
3 | 2005, 2006 Free Software Foundation, Inc. | |||
4 | ||||
5 | This file is part of BFD, the Binary File Descriptor library. | |||
6 | ||||
7 | This program is free software; you can redistribute it and/or modify | |||
8 | it under the terms of the GNU General Public License as published by | |||
9 | the Free Software Foundation; either version 2 of the License, or | |||
10 | (at your option) any later version. | |||
11 | ||||
12 | This program is distributed in the hope that it will be useful, | |||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
15 | GNU General Public License for more details. | |||
16 | ||||
17 | You should have received a copy of the GNU General Public License | |||
18 | along with this program; if not, write to the Free Software | |||
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ | |||
20 | ||||
21 | #include "bfd.h" | |||
22 | #include "sysdep.h" | |||
23 | #include "bfdlink.h" | |||
24 | #include "libbfd.h" | |||
25 | #define ARCH_SIZE0 0 | |||
26 | #include "elf-bfd.h" | |||
27 | #include "safe-ctype.h" | |||
28 | #include "libiberty.h" | |||
29 | #include "objalloc.h" | |||
30 | ||||
31 | /* Define a symbol in a dynamic linkage section. */ | |||
32 | ||||
33 | struct elf_link_hash_entry * | |||
34 | _bfd_elf_define_linkage_sym (bfd *abfd, | |||
35 | struct bfd_link_info *info, | |||
36 | asection *sec, | |||
37 | const char *name) | |||
38 | { | |||
39 | struct elf_link_hash_entry *h; | |||
40 | struct bfd_link_hash_entry *bh; | |||
41 | const struct elf_backend_data *bed; | |||
42 | ||||
43 | h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( name), (0), (0), (0))); | |||
44 | if (h != NULL((void*)0)) | |||
45 | { | |||
46 | /* Zap symbol defined in an as-needed lib that wasn't linked. | |||
47 | This is a symptom of a larger problem: Absolute symbols | |||
48 | defined in shared libraries can't be overridden, because we | |||
49 | lose the link to the bfd which is via the symbol section. */ | |||
50 | h->root.type = bfd_link_hash_new; | |||
51 | } | |||
52 | ||||
53 | bh = &h->root; | |||
54 | if (!_bfd_generic_link_add_one_symbol (info, abfd, name, BSF_GLOBAL0x02, | |||
55 | sec, 0, NULL((void*)0), FALSE0, | |||
56 | get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->collect, | |||
57 | &bh)) | |||
58 | return NULL((void*)0); | |||
59 | h = (struct elf_link_hash_entry *) bh; | |||
60 | h->def_regular = 1; | |||
61 | h->type = STT_OBJECT1; | |||
62 | h->other = (h->other & ~ELF_ST_VISIBILITY (-1)((-1) & 0x3)) | STV_HIDDEN2; | |||
63 | ||||
64 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
65 | (*bed->elf_backend_hide_symbol) (info, h, TRUE1); | |||
66 | return h; | |||
67 | } | |||
68 | ||||
69 | bfd_boolean | |||
70 | _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) | |||
71 | { | |||
72 | flagword flags; | |||
73 | asection *s; | |||
74 | struct elf_link_hash_entry *h; | |||
75 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
76 | int ptralign; | |||
77 | ||||
78 | /* This function may be called more than once. */ | |||
79 | s = bfd_get_section_by_name (abfd, ".got"); | |||
80 | if (s != NULL((void*)0) && (s->flags & SEC_LINKER_CREATED0x200000) != 0) | |||
81 | return TRUE1; | |||
82 | ||||
83 | switch (bed->s->arch_size) | |||
84 | { | |||
85 | case 32: | |||
86 | ptralign = 2; | |||
87 | break; | |||
88 | ||||
89 | case 64: | |||
90 | ptralign = 3; | |||
91 | break; | |||
92 | ||||
93 | default: | |||
94 | bfd_set_error (bfd_error_bad_value); | |||
95 | return FALSE0; | |||
96 | } | |||
97 | ||||
98 | flags = bed->dynamic_sec_flags; | |||
99 | ||||
100 | s = bfd_make_section_with_flags (abfd, ".got", flags); | |||
101 | if (s == NULL((void*)0) | |||
102 | || !bfd_set_section_alignment (abfd, s, ptralign)(((s)->alignment_power = (ptralign)),1)) | |||
103 | return FALSE0; | |||
104 | ||||
105 | if (bed->want_got_plt) | |||
106 | { | |||
107 | s = bfd_make_section_with_flags (abfd, ".got.plt", flags); | |||
108 | if (s == NULL((void*)0) | |||
109 | || !bfd_set_section_alignment (abfd, s, ptralign)(((s)->alignment_power = (ptralign)),1)) | |||
110 | return FALSE0; | |||
111 | } | |||
112 | ||||
113 | if (bed->want_got_sym) | |||
114 | { | |||
115 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | |||
116 | (or .got.plt) section. We don't do this in the linker script | |||
117 | because we don't want to define the symbol if we are not creating | |||
118 | a global offset table. */ | |||
119 | h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); | |||
120 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->hgot = h; | |||
121 | if (h == NULL((void*)0)) | |||
122 | return FALSE0; | |||
123 | } | |||
124 | ||||
125 | /* The first bit of the global offset table is the header. */ | |||
126 | s->size += bed->got_header_size; | |||
127 | ||||
128 | return TRUE1; | |||
129 | } | |||
130 | ||||
131 | /* Create a strtab to hold the dynamic symbol names. */ | |||
132 | static bfd_boolean | |||
133 | _bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info) | |||
134 | { | |||
135 | struct elf_link_hash_table *hash_table; | |||
136 | ||||
137 | hash_table = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
138 | if (hash_table->dynobj == NULL((void*)0)) | |||
139 | hash_table->dynobj = abfd; | |||
140 | ||||
141 | if (hash_table->dynstr == NULL((void*)0)) | |||
142 | { | |||
143 | hash_table->dynstr = _bfd_elf_strtab_init (); | |||
144 | if (hash_table->dynstr == NULL((void*)0)) | |||
145 | return FALSE0; | |||
146 | } | |||
147 | return TRUE1; | |||
148 | } | |||
149 | ||||
150 | /* Create some sections which will be filled in with dynamic linking | |||
151 | information. ABFD is an input file which requires dynamic sections | |||
152 | to be created. The dynamic sections take up virtual memory space | |||
153 | when the final executable is run, so we need to create them before | |||
154 | addresses are assigned to the output sections. We work out the | |||
155 | actual contents and size of these sections later. */ | |||
156 | ||||
157 | bfd_boolean | |||
158 | _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |||
159 | { | |||
160 | flagword flags; | |||
161 | register asection *s; | |||
162 | const struct elf_backend_data *bed; | |||
163 | ||||
164 | if (! is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
165 | return FALSE0; | |||
166 | ||||
167 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynamic_sections_created) | |||
168 | return TRUE1; | |||
169 | ||||
170 | if (!_bfd_elf_link_create_dynstrtab (abfd, info)) | |||
171 | return FALSE0; | |||
172 | ||||
173 | abfd = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynobj; | |||
174 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
175 | ||||
176 | flags = bed->dynamic_sec_flags; | |||
177 | ||||
178 | /* A dynamically linked executable has a .interp section, but a | |||
179 | shared library does not. */ | |||
180 | if (info->executable && !info->static_link) | |||
181 | { | |||
182 | s = bfd_make_section_with_flags (abfd, ".interp", | |||
183 | flags | SEC_READONLY0x008); | |||
184 | if (s == NULL((void*)0)) | |||
185 | return FALSE0; | |||
186 | } | |||
187 | ||||
188 | if (! info->traditional_format) | |||
189 | { | |||
190 | s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr", | |||
191 | flags | SEC_READONLY0x008); | |||
192 | if (s == NULL((void*)0) | |||
193 | || ! bfd_set_section_alignment (abfd, s, 2)(((s)->alignment_power = (2)),1)) | |||
194 | return FALSE0; | |||
195 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->eh_info.hdr_sec = s; | |||
196 | } | |||
197 | ||||
198 | /* Create sections to hold version informations. These are removed | |||
199 | if they are not needed. */ | |||
200 | s = bfd_make_section_with_flags (abfd, ".gnu.version_d", | |||
201 | flags | SEC_READONLY0x008); | |||
202 | if (s == NULL((void*)0) | |||
203 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
204 | return FALSE0; | |||
205 | ||||
206 | s = bfd_make_section_with_flags (abfd, ".gnu.version", | |||
207 | flags | SEC_READONLY0x008); | |||
208 | if (s == NULL((void*)0) | |||
209 | || ! bfd_set_section_alignment (abfd, s, 1)(((s)->alignment_power = (1)),1)) | |||
210 | return FALSE0; | |||
211 | ||||
212 | s = bfd_make_section_with_flags (abfd, ".gnu.version_r", | |||
213 | flags | SEC_READONLY0x008); | |||
214 | if (s == NULL((void*)0) | |||
215 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
216 | return FALSE0; | |||
217 | ||||
218 | s = bfd_make_section_with_flags (abfd, ".dynsym", | |||
219 | flags | SEC_READONLY0x008); | |||
220 | if (s == NULL((void*)0) | |||
221 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
222 | return FALSE0; | |||
223 | ||||
224 | s = bfd_make_section_with_flags (abfd, ".dynstr", | |||
225 | flags | SEC_READONLY0x008); | |||
226 | if (s == NULL((void*)0)) | |||
227 | return FALSE0; | |||
228 | ||||
229 | s = bfd_make_section_with_flags (abfd, ".dynamic", flags); | |||
230 | if (s == NULL((void*)0) | |||
231 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
232 | return FALSE0; | |||
233 | ||||
234 | /* The special symbol _DYNAMIC is always set to the start of the | |||
235 | .dynamic section. We could set _DYNAMIC in a linker script, but we | |||
236 | only want to define it if we are, in fact, creating a .dynamic | |||
237 | section. We don't want to define it if there is no .dynamic | |||
238 | section, since on some ELF platforms the start up code examines it | |||
239 | to decide how to initialize the process. */ | |||
240 | if (!_bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC")) | |||
241 | return FALSE0; | |||
242 | ||||
243 | if (info->emit_hash) | |||
244 | { | |||
245 | s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY0x008); | |||
246 | if (s == NULL((void*)0) | |||
247 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
248 | return FALSE0; | |||
249 | elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry; | |||
250 | } | |||
251 | ||||
252 | if (info->emit_gnu_hash) | |||
253 | { | |||
254 | s = bfd_make_section_with_flags (abfd, ".gnu.hash", | |||
255 | flags | SEC_READONLY0x008); | |||
256 | if (s == NULL((void*)0) | |||
257 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
258 | return FALSE0; | |||
259 | /* For 64-bit ELF, .gnu.hash is a non-uniform entity size section: | |||
260 | 4 32-bit words followed by variable count of 64-bit words, then | |||
261 | variable count of 32-bit words. */ | |||
262 | if (bed->s->arch_size == 64) | |||
263 | elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize = 0; | |||
264 | else | |||
265 | elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize = 4; | |||
266 | } | |||
267 | ||||
268 | /* Let the backend create the rest of the sections. This lets the | |||
269 | backend set the right flags. The backend will normally create | |||
270 | the .got and .plt sections. */ | |||
271 | if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info)) | |||
272 | return FALSE0; | |||
273 | ||||
274 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynamic_sections_created = TRUE1; | |||
275 | ||||
276 | return TRUE1; | |||
277 | } | |||
278 | ||||
279 | /* Create dynamic sections when linking against a dynamic object. */ | |||
280 | ||||
281 | bfd_boolean | |||
282 | _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |||
283 | { | |||
284 | flagword flags, pltflags; | |||
285 | struct elf_link_hash_entry *h; | |||
286 | asection *s; | |||
287 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
288 | ||||
289 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and | |||
290 | .rel[a].bss sections. */ | |||
291 | flags = bed->dynamic_sec_flags; | |||
292 | ||||
293 | pltflags = flags; | |||
294 | if (bed->plt_not_loaded) | |||
295 | /* We do not clear SEC_ALLOC here because we still want the OS to | |||
296 | allocate space for the section; it's just that there's nothing | |||
297 | to read in from the object file. */ | |||
298 | pltflags &= ~ (SEC_CODE0x010 | SEC_LOAD0x002 | SEC_HAS_CONTENTS0x100); | |||
299 | else | |||
300 | pltflags |= SEC_ALLOC0x001 | SEC_CODE0x010 | SEC_LOAD0x002; | |||
301 | if (bed->plt_readonly) | |||
302 | pltflags |= SEC_READONLY0x008; | |||
303 | ||||
304 | s = bfd_make_section_with_flags (abfd, ".plt", pltflags); | |||
305 | if (s == NULL((void*)0) | |||
306 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)(((s)->alignment_power = (bed->plt_alignment)),1)) | |||
307 | return FALSE0; | |||
308 | ||||
309 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the | |||
310 | .plt section. */ | |||
311 | if (bed->want_plt_sym) | |||
312 | { | |||
313 | h = _bfd_elf_define_linkage_sym (abfd, info, s, | |||
314 | "_PROCEDURE_LINKAGE_TABLE_"); | |||
315 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->hplt = h; | |||
316 | if (h == NULL((void*)0)) | |||
317 | return FALSE0; | |||
318 | } | |||
319 | ||||
320 | s = bfd_make_section_with_flags (abfd, | |||
321 | (bed->default_use_rela_p | |||
322 | ? ".rela.plt" : ".rel.plt"), | |||
323 | flags | SEC_READONLY0x008); | |||
324 | if (s == NULL((void*)0) | |||
325 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
326 | return FALSE0; | |||
327 | ||||
328 | if (! _bfd_elf_create_got_section (abfd, info)) | |||
329 | return FALSE0; | |||
330 | ||||
331 | if (bed->want_dynbss) | |||
332 | { | |||
333 | /* The .dynbss section is a place to put symbols which are defined | |||
334 | by dynamic objects, are referenced by regular objects, and are | |||
335 | not functions. We must allocate space for them in the process | |||
336 | image and use a R_*_COPY reloc to tell the dynamic linker to | |||
337 | initialize them at run time. The linker script puts the .dynbss | |||
338 | section into the .bss section of the final image. */ | |||
339 | s = bfd_make_section_with_flags (abfd, ".dynbss", | |||
340 | (SEC_ALLOC0x001 | |||
341 | | SEC_LINKER_CREATED0x200000)); | |||
342 | if (s == NULL((void*)0)) | |||
343 | return FALSE0; | |||
344 | ||||
345 | /* The .rel[a].bss section holds copy relocs. This section is not | |||
346 | normally needed. We need to create it here, though, so that the | |||
347 | linker will map it to an output section. We can't just create it | |||
348 | only if we need it, because we will not know whether we need it | |||
349 | until we have seen all the input files, and the first time the | |||
350 | main linker code calls BFD after examining all the input files | |||
351 | (size_dynamic_sections) the input sections have already been | |||
352 | mapped to the output sections. If the section turns out not to | |||
353 | be needed, we can discard it later. We will never need this | |||
354 | section when generating a shared object, since they do not use | |||
355 | copy relocs. */ | |||
356 | if (! info->shared) | |||
357 | { | |||
358 | s = bfd_make_section_with_flags (abfd, | |||
359 | (bed->default_use_rela_p | |||
360 | ? ".rela.bss" : ".rel.bss"), | |||
361 | flags | SEC_READONLY0x008); | |||
362 | if (s == NULL((void*)0) | |||
363 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)(((s)->alignment_power = (bed->s->log_file_align)),1 )) | |||
364 | return FALSE0; | |||
365 | } | |||
366 | } | |||
367 | ||||
368 | return TRUE1; | |||
369 | } | |||
370 | ||||
371 | /* Record a new dynamic symbol. We record the dynamic symbols as we | |||
372 | read the input files, since we need to have a list of all of them | |||
373 | before we can determine the final sizes of the output sections. | |||
374 | Note that we may actually call this function even though we are not | |||
375 | going to output any dynamic symbols; in some cases we know that a | |||
376 | symbol should be in the dynamic symbol table, but only if there is | |||
377 | one. */ | |||
378 | ||||
379 | bfd_boolean | |||
380 | bfd_elf_link_record_dynamic_symbol (struct bfd_link_info *info, | |||
381 | struct elf_link_hash_entry *h) | |||
382 | { | |||
383 | if (h->dynindx == -1) | |||
384 | { | |||
385 | struct elf_strtab_hash *dynstr; | |||
386 | char *p; | |||
387 | const char *name; | |||
388 | bfd_size_type indx; | |||
389 | ||||
390 | /* XXX: The ABI draft says the linker must turn hidden and | |||
391 | internal symbols into STB_LOCAL symbols when producing the | |||
392 | DSO. However, if ld.so honors st_other in the dynamic table, | |||
393 | this would not be necessary. */ | |||
394 | switch (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3)) | |||
395 | { | |||
396 | case STV_INTERNAL1: | |||
397 | case STV_HIDDEN2: | |||
398 | if (h->root.type != bfd_link_hash_undefined | |||
399 | && h->root.type != bfd_link_hash_undefweak) | |||
400 | { | |||
401 | h->forced_local = 1; | |||
402 | if (!elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->is_relocatable_executable) | |||
403 | return TRUE1; | |||
404 | } | |||
405 | ||||
406 | default: | |||
407 | break; | |||
408 | } | |||
409 | ||||
410 | h->dynindx = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynsymcount; | |||
411 | ++elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynsymcount; | |||
412 | ||||
413 | dynstr = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr; | |||
414 | if (dynstr == NULL((void*)0)) | |||
415 | { | |||
416 | /* Create a strtab to hold the dynamic symbol names. */ | |||
417 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr = dynstr = _bfd_elf_strtab_init (); | |||
418 | if (dynstr == NULL((void*)0)) | |||
419 | return FALSE0; | |||
420 | } | |||
421 | ||||
422 | /* We don't put any version information in the dynamic string | |||
423 | table. */ | |||
424 | name = h->root.root.string; | |||
425 | p = strchr (name, ELF_VER_CHR'@'); | |||
426 | if (p != NULL((void*)0)) | |||
427 | /* We know that the p points into writable memory. In fact, | |||
428 | there are only a few symbols that have read-only names, being | |||
429 | those like _GLOBAL_OFFSET_TABLE_ that are created specially | |||
430 | by the backends. Most symbols will have names pointing into | |||
431 | an ELF string table read from a file, or to objalloc memory. */ | |||
432 | *p = 0; | |||
433 | ||||
434 | indx = _bfd_elf_strtab_add (dynstr, name, p != NULL((void*)0)); | |||
435 | ||||
436 | if (p != NULL((void*)0)) | |||
437 | *p = ELF_VER_CHR'@'; | |||
438 | ||||
439 | if (indx == (bfd_size_type) -1) | |||
440 | return FALSE0; | |||
441 | h->dynstr_index = indx; | |||
442 | } | |||
443 | ||||
444 | return TRUE1; | |||
445 | } | |||
446 | ||||
447 | /* Record an assignment to a symbol made by a linker script. We need | |||
448 | this in case some dynamic object refers to this symbol. */ | |||
449 | ||||
450 | bfd_boolean | |||
451 | bfd_elf_record_link_assignment (bfd *output_bfd, | |||
452 | struct bfd_link_info *info, | |||
453 | const char *name, | |||
454 | bfd_boolean provide, | |||
455 | bfd_boolean hidden) | |||
456 | { | |||
457 | struct elf_link_hash_entry *h; | |||
458 | struct elf_link_hash_table *htab; | |||
459 | ||||
460 | if (!is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
461 | return TRUE1; | |||
462 | ||||
463 | htab = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
464 | h = elf_link_hash_lookup (htab, name, !provide, TRUE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(htab )->root, (name), (!provide), (1), (0))); | |||
465 | if (h == NULL((void*)0)) | |||
466 | return provide; | |||
467 | ||||
468 | /* Since we're defining the symbol, don't let it seem to have not | |||
469 | been defined. record_dynamic_symbol and size_dynamic_sections | |||
470 | may depend on this. */ | |||
471 | if (h->root.type == bfd_link_hash_undefweak | |||
472 | || h->root.type == bfd_link_hash_undefined) | |||
473 | { | |||
474 | h->root.type = bfd_link_hash_new; | |||
475 | if (h->root.u.undef.next != NULL((void*)0) || htab->root.undefs_tail == &h->root) | |||
476 | bfd_link_repair_undef_list (&htab->root); | |||
477 | } | |||
478 | ||||
479 | if (h->root.type == bfd_link_hash_new) | |||
480 | h->non_elf = 0; | |||
481 | ||||
482 | /* If this symbol is being provided by the linker script, and it is | |||
483 | currently defined by a dynamic object, but not by a regular | |||
484 | object, then mark it as undefined so that the generic linker will | |||
485 | force the correct value. */ | |||
486 | if (provide | |||
487 | && h->def_dynamic | |||
488 | && !h->def_regular) | |||
489 | h->root.type = bfd_link_hash_undefined; | |||
490 | ||||
491 | /* If this symbol is not being provided by the linker script, and it is | |||
492 | currently defined by a dynamic object, but not by a regular object, | |||
493 | then clear out any version information because the symbol will not be | |||
494 | associated with the dynamic object any more. */ | |||
495 | if (!provide | |||
496 | && h->def_dynamic | |||
497 | && !h->def_regular) | |||
498 | h->verinfo.verdef = NULL((void*)0); | |||
499 | ||||
500 | h->def_regular = 1; | |||
501 | ||||
502 | if (provide && hidden) | |||
503 | { | |||
504 | const struct elf_backend_data *bed = get_elf_backend_data (output_bfd)((const struct elf_backend_data *) (output_bfd)->xvec-> backend_data); | |||
505 | ||||
506 | h->other = (h->other & ~ELF_ST_VISIBILITY (-1)((-1) & 0x3)) | STV_HIDDEN2; | |||
507 | (*bed->elf_backend_hide_symbol) (info, h, TRUE1); | |||
508 | } | |||
509 | ||||
510 | /* STV_HIDDEN and STV_INTERNAL symbols must be STB_LOCAL in shared objects | |||
511 | and executables. */ | |||
512 | if (!info->relocatable | |||
513 | && h->dynindx != -1 | |||
514 | && (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_HIDDEN2 | |||
515 | || ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_INTERNAL1)) | |||
516 | h->forced_local = 1; | |||
517 | ||||
518 | if ((h->def_dynamic | |||
519 | || h->ref_dynamic | |||
520 | || info->shared | |||
521 | || (info->executable && elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->is_relocatable_executable)) | |||
522 | && h->dynindx == -1) | |||
523 | { | |||
524 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
525 | return FALSE0; | |||
526 | ||||
527 | /* If this is a weak defined symbol, and we know a corresponding | |||
528 | real symbol from the same dynamic object, make sure the real | |||
529 | symbol is also made into a dynamic symbol. */ | |||
530 | if (h->u.weakdef != NULL((void*)0) | |||
531 | && h->u.weakdef->dynindx == -1) | |||
532 | { | |||
533 | if (! bfd_elf_link_record_dynamic_symbol (info, h->u.weakdef)) | |||
534 | return FALSE0; | |||
535 | } | |||
536 | } | |||
537 | ||||
538 | return TRUE1; | |||
539 | } | |||
540 | ||||
541 | /* Record a new local dynamic symbol. Returns 0 on failure, 1 on | |||
542 | success, and 2 on a failure caused by attempting to record a symbol | |||
543 | in a discarded section, eg. a discarded link-once section symbol. */ | |||
544 | ||||
545 | int | |||
546 | bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info, | |||
547 | bfd *input_bfd, | |||
548 | long input_indx) | |||
549 | { | |||
550 | bfd_size_type amt; | |||
551 | struct elf_link_local_dynamic_entry *entry; | |||
552 | struct elf_link_hash_table *eht; | |||
553 | struct elf_strtab_hash *dynstr; | |||
554 | unsigned long dynstr_index; | |||
555 | char *name; | |||
556 | Elf_External_Sym_Shndx eshndx; | |||
557 | char esym[sizeof (Elf64_External_Sym)]; | |||
558 | ||||
559 | if (! is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
560 | return 0; | |||
561 | ||||
562 | /* See if the entry exists already. */ | |||
563 | for (entry = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynlocal; entry ; entry = entry->next) | |||
564 | if (entry->input_bfd == input_bfd && entry->input_indx == input_indx) | |||
565 | return 1; | |||
566 | ||||
567 | amt = sizeof (*entry); | |||
568 | entry = bfd_alloc (input_bfd, amt); | |||
569 | if (entry == NULL((void*)0)) | |||
570 | return 0; | |||
571 | ||||
572 | /* Go find the symbol, so that we can find it's name. */ | |||
573 | if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)((input_bfd) -> tdata.elf_obj_data)->symtab_hdr, | |||
574 | 1, input_indx, &entry->isym, esym, &eshndx)) | |||
575 | { | |||
576 | bfd_release (input_bfd, entry); | |||
577 | return 0; | |||
578 | } | |||
579 | ||||
580 | if (entry->isym.st_shndx != SHN_UNDEF0 | |||
581 | && (entry->isym.st_shndx < SHN_LORESERVE0xFF00 | |||
582 | || entry->isym.st_shndx > SHN_HIRESERVE0xFFFF)) | |||
583 | { | |||
584 | asection *s; | |||
585 | ||||
586 | s = bfd_section_from_elf_index (input_bfd, entry->isym.st_shndx); | |||
587 | if (s == NULL((void*)0) || bfd_is_abs_section (s->output_section)((s->output_section) == ((asection *) &bfd_abs_section ))) | |||
588 | { | |||
589 | /* We can still bfd_release here as nothing has done another | |||
590 | bfd_alloc. We can't do this later in this function. */ | |||
591 | bfd_release (input_bfd, entry); | |||
592 | return 2; | |||
593 | } | |||
594 | } | |||
595 | ||||
596 | name = (bfd_elf_string_from_elf_section | |||
597 | (input_bfd, elf_tdata (input_bfd)((input_bfd) -> tdata.elf_obj_data)->symtab_hdr.sh_link, | |||
598 | entry->isym.st_name)); | |||
599 | ||||
600 | dynstr = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr; | |||
601 | if (dynstr == NULL((void*)0)) | |||
602 | { | |||
603 | /* Create a strtab to hold the dynamic symbol names. */ | |||
604 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr = dynstr = _bfd_elf_strtab_init (); | |||
605 | if (dynstr == NULL((void*)0)) | |||
606 | return 0; | |||
607 | } | |||
608 | ||||
609 | dynstr_index = _bfd_elf_strtab_add (dynstr, name, FALSE0); | |||
610 | if (dynstr_index == (unsigned long) -1) | |||
611 | return 0; | |||
612 | entry->isym.st_name = dynstr_index; | |||
613 | ||||
614 | eht = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
615 | ||||
616 | entry->next = eht->dynlocal; | |||
617 | eht->dynlocal = entry; | |||
618 | entry->input_bfd = input_bfd; | |||
619 | entry->input_indx = input_indx; | |||
620 | eht->dynsymcount++; | |||
621 | ||||
622 | /* Whatever binding the symbol had before, it's now local. */ | |||
623 | entry->isym.st_info | |||
624 | = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info))(((0) << 4) + ((((entry->isym.st_info) & 0xF)) & 0xF)); | |||
625 | ||||
626 | /* The dynindx will be set at the end of size_dynamic_sections. */ | |||
627 | ||||
628 | return 1; | |||
629 | } | |||
630 | ||||
631 | /* Return the dynindex of a local dynamic symbol. */ | |||
632 | ||||
633 | long | |||
634 | _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info *info, | |||
635 | bfd *input_bfd, | |||
636 | long input_indx) | |||
637 | { | |||
638 | struct elf_link_local_dynamic_entry *e; | |||
639 | ||||
640 | for (e = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynlocal; e ; e = e->next) | |||
641 | if (e->input_bfd == input_bfd && e->input_indx == input_indx) | |||
642 | return e->dynindx; | |||
643 | return -1; | |||
644 | } | |||
645 | ||||
646 | /* This function is used to renumber the dynamic symbols, if some of | |||
647 | them are removed because they are marked as local. This is called | |||
648 | via elf_link_hash_traverse. */ | |||
649 | ||||
650 | static bfd_boolean | |||
651 | elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry *h, | |||
652 | void *data) | |||
653 | { | |||
654 | size_t *count = data; | |||
655 | ||||
656 | if (h->root.type == bfd_link_hash_warning) | |||
657 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
658 | ||||
659 | if (h->forced_local) | |||
660 | return TRUE1; | |||
661 | ||||
662 | if (h->dynindx != -1) | |||
663 | h->dynindx = ++(*count); | |||
664 | ||||
665 | return TRUE1; | |||
666 | } | |||
667 | ||||
668 | ||||
669 | /* Like elf_link_renumber_hash_table_dynsyms, but just number symbols with | |||
670 | STB_LOCAL binding. */ | |||
671 | ||||
672 | static bfd_boolean | |||
673 | elf_link_renumber_local_hash_table_dynsyms (struct elf_link_hash_entry *h, | |||
674 | void *data) | |||
675 | { | |||
676 | size_t *count = data; | |||
677 | ||||
678 | if (h->root.type == bfd_link_hash_warning) | |||
679 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
680 | ||||
681 | if (!h->forced_local) | |||
682 | return TRUE1; | |||
683 | ||||
684 | if (h->dynindx != -1) | |||
685 | h->dynindx = ++(*count); | |||
686 | ||||
687 | return TRUE1; | |||
688 | } | |||
689 | ||||
690 | /* Return true if the dynamic symbol for a given section should be | |||
691 | omitted when creating a shared library. */ | |||
692 | bfd_boolean | |||
693 | _bfd_elf_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
694 | struct bfd_link_info *info, | |||
695 | asection *p) | |||
696 | { | |||
697 | switch (elf_section_data (p)((struct bfd_elf_section_data*)(p)->used_by_bfd)->this_hdr.sh_type) | |||
698 | { | |||
699 | case SHT_PROGBITS1: | |||
700 | case SHT_NOBITS8: | |||
701 | /* If sh_type is yet undecided, assume it could be | |||
702 | SHT_PROGBITS/SHT_NOBITS. */ | |||
703 | case SHT_NULL0: | |||
704 | if (strcmp (p->name, ".got") == 0 | |||
705 | || strcmp (p->name, ".got.plt") == 0 | |||
706 | || strcmp (p->name, ".plt") == 0) | |||
707 | { | |||
708 | asection *ip; | |||
709 | bfd *dynobj = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynobj; | |||
710 | ||||
711 | if (dynobj != NULL((void*)0) | |||
712 | && (ip = bfd_get_section_by_name (dynobj, p->name)) != NULL((void*)0) | |||
713 | && (ip->flags & SEC_LINKER_CREATED0x200000) | |||
714 | && ip->output_section == p) | |||
715 | return TRUE1; | |||
716 | } | |||
717 | return FALSE0; | |||
718 | ||||
719 | /* There shouldn't be section relative relocations | |||
720 | against any other section. */ | |||
721 | default: | |||
722 | return TRUE1; | |||
723 | } | |||
724 | } | |||
725 | ||||
726 | /* Assign dynsym indices. In a shared library we generate a section | |||
727 | symbol for each output section, which come first. Next come symbols | |||
728 | which have been forced to local binding. Then all of the back-end | |||
729 | allocated local dynamic syms, followed by the rest of the global | |||
730 | symbols. */ | |||
731 | ||||
732 | static unsigned long | |||
733 | _bfd_elf_link_renumber_dynsyms (bfd *output_bfd, | |||
734 | struct bfd_link_info *info, | |||
735 | unsigned long *section_sym_count) | |||
736 | { | |||
737 | unsigned long dynsymcount = 0; | |||
738 | ||||
739 | if (info->shared || elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->is_relocatable_executable) | |||
740 | { | |||
741 | const struct elf_backend_data *bed = get_elf_backend_data (output_bfd)((const struct elf_backend_data *) (output_bfd)->xvec-> backend_data); | |||
742 | asection *p; | |||
743 | for (p = output_bfd->sections; p ; p = p->next) | |||
744 | if ((p->flags & SEC_EXCLUDE0x8000) == 0 | |||
745 | && (p->flags & SEC_ALLOC0x001) != 0 | |||
746 | && !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p)) | |||
747 | elf_section_data (p)((struct bfd_elf_section_data*)(p)->used_by_bfd)->dynindx = ++dynsymcount; | |||
748 | } | |||
749 | *section_sym_count = dynsymcount; | |||
750 | ||||
751 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_link_renumber_local_hash_table_dynsyms), (& dynsymcount))) | |||
752 | elf_link_renumber_local_hash_table_dynsyms,(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_link_renumber_local_hash_table_dynsyms), (& dynsymcount))) | |||
753 | &dynsymcount)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_link_renumber_local_hash_table_dynsyms), (& dynsymcount))); | |||
754 | ||||
755 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynlocal) | |||
756 | { | |||
757 | struct elf_link_local_dynamic_entry *p; | |||
758 | for (p = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynlocal; p ; p = p->next) | |||
759 | p->dynindx = ++dynsymcount; | |||
760 | } | |||
761 | ||||
762 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_link_renumber_hash_table_dynsyms), (&dynsymcount ))) | |||
763 | elf_link_renumber_hash_table_dynsyms,(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_link_renumber_hash_table_dynsyms), (&dynsymcount ))) | |||
764 | &dynsymcount)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_link_renumber_hash_table_dynsyms), (&dynsymcount ))); | |||
765 | ||||
766 | /* There is an unused NULL entry at the head of the table which | |||
767 | we must account for in our count. Unless there weren't any | |||
768 | symbols, which means we'll have no table at all. */ | |||
769 | if (dynsymcount != 0) | |||
770 | ++dynsymcount; | |||
771 | ||||
772 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynsymcount = dynsymcount; | |||
773 | return dynsymcount; | |||
774 | } | |||
775 | ||||
776 | /* This function is called when we want to define a new symbol. It | |||
777 | handles the various cases which arise when we find a definition in | |||
778 | a dynamic object, or when there is already a definition in a | |||
779 | dynamic object. The new symbol is described by NAME, SYM, PSEC, | |||
780 | and PVALUE. We set SYM_HASH to the hash table entry. We set | |||
781 | OVERRIDE if the old symbol is overriding a new definition. We set | |||
782 | TYPE_CHANGE_OK if it is OK for the type to change. We set | |||
783 | SIZE_CHANGE_OK if it is OK for the size to change. By OK to | |||
784 | change, we mean that we shouldn't warn if the type or size does | |||
785 | change. We set POLD_ALIGNMENT if an old common symbol in a dynamic | |||
786 | object is overridden by a regular object. */ | |||
787 | ||||
788 | bfd_boolean | |||
789 | _bfd_elf_merge_symbol (bfd *abfd, | |||
790 | struct bfd_link_info *info, | |||
791 | const char *name, | |||
792 | Elf_Internal_Sym *sym, | |||
793 | asection **psec, | |||
794 | bfd_vma *pvalue, | |||
795 | unsigned int *pold_alignment, | |||
796 | struct elf_link_hash_entry **sym_hash, | |||
797 | bfd_boolean *skip, | |||
798 | bfd_boolean *override, | |||
799 | bfd_boolean *type_change_ok, | |||
800 | bfd_boolean *size_change_ok) | |||
801 | { | |||
802 | asection *sec, *oldsec; | |||
803 | struct elf_link_hash_entry *h; | |||
804 | struct elf_link_hash_entry *flip; | |||
805 | int bind; | |||
806 | bfd *oldbfd; | |||
807 | bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon; | |||
808 | bfd_boolean newweak, oldweak; | |||
809 | const struct elf_backend_data *bed; | |||
810 | ||||
811 | *skip = FALSE0; | |||
812 | *override = FALSE0; | |||
813 | ||||
814 | sec = *psec; | |||
815 | bind = ELF_ST_BIND (sym->st_info)(((unsigned int)(sym->st_info)) >> 4); | |||
816 | ||||
817 | if (! bfd_is_und_section (sec)((sec) == ((asection *) &bfd_und_section))) | |||
818 | h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( name), (1), (0), (0))); | |||
819 | else | |||
820 | h = ((struct elf_link_hash_entry *) | |||
821 | bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE1, FALSE0, FALSE0)); | |||
822 | if (h == NULL((void*)0)) | |||
823 | return FALSE0; | |||
824 | *sym_hash = h; | |||
825 | ||||
826 | /* This code is for coping with dynamic objects, and is only useful | |||
827 | if we are doing an ELF link. */ | |||
828 | if (info->hash->creator != abfd->xvec) | |||
829 | return TRUE1; | |||
830 | ||||
831 | /* For merging, we only care about real symbols. */ | |||
832 | ||||
833 | while (h->root.type == bfd_link_hash_indirect | |||
834 | || h->root.type == bfd_link_hash_warning) | |||
835 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
836 | ||||
837 | /* If we just created the symbol, mark it as being an ELF symbol. | |||
838 | Other than that, there is nothing to do--there is no merge issue | |||
839 | with a newly defined symbol--so we just return. */ | |||
840 | ||||
841 | if (h->root.type == bfd_link_hash_new) | |||
842 | { | |||
843 | h->non_elf = 0; | |||
844 | return TRUE1; | |||
845 | } | |||
846 | ||||
847 | /* OLDBFD and OLDSEC are a BFD and an ASECTION associated with the | |||
848 | existing symbol. */ | |||
849 | ||||
850 | switch (h->root.type) | |||
851 | { | |||
852 | default: | |||
853 | oldbfd = NULL((void*)0); | |||
854 | oldsec = NULL((void*)0); | |||
855 | break; | |||
856 | ||||
857 | case bfd_link_hash_undefined: | |||
858 | case bfd_link_hash_undefweak: | |||
859 | oldbfd = h->root.u.undef.abfd; | |||
860 | oldsec = NULL((void*)0); | |||
861 | break; | |||
862 | ||||
863 | case bfd_link_hash_defined: | |||
864 | case bfd_link_hash_defweak: | |||
865 | oldbfd = h->root.u.def.section->owner; | |||
866 | oldsec = h->root.u.def.section; | |||
867 | break; | |||
868 | ||||
869 | case bfd_link_hash_common: | |||
870 | oldbfd = h->root.u.c.p->section->owner; | |||
871 | oldsec = h->root.u.c.p->section; | |||
872 | break; | |||
873 | } | |||
874 | ||||
875 | /* In cases involving weak versioned symbols, we may wind up trying | |||
876 | to merge a symbol with itself. Catch that here, to avoid the | |||
877 | confusion that results if we try to override a symbol with | |||
878 | itself. The additional tests catch cases like | |||
879 | _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a | |||
880 | dynamic object, which we do want to handle here. */ | |||
881 | if (abfd == oldbfd | |||
882 | && ((abfd->flags & DYNAMIC0x40) == 0 | |||
883 | || !h->def_regular)) | |||
884 | return TRUE1; | |||
885 | ||||
886 | /* NEWDYN and OLDDYN indicate whether the new or old symbol, | |||
887 | respectively, is from a dynamic object. */ | |||
888 | ||||
889 | newdyn = (abfd->flags & DYNAMIC0x40) != 0; | |||
890 | ||||
891 | olddyn = FALSE0; | |||
892 | if (oldbfd != NULL((void*)0)) | |||
893 | olddyn = (oldbfd->flags & DYNAMIC0x40) != 0; | |||
894 | else if (oldsec != NULL((void*)0)) | |||
895 | { | |||
896 | /* This handles the special SHN_MIPS_{TEXT,DATA} section | |||
897 | indices used by MIPS ELF. */ | |||
898 | olddyn = (oldsec->symbol->flags & BSF_DYNAMIC0x8000) != 0; | |||
899 | } | |||
900 | ||||
901 | /* NEWDEF and OLDDEF indicate whether the new or old symbol, | |||
902 | respectively, appear to be a definition rather than reference. */ | |||
903 | ||||
904 | newdef = !bfd_is_und_section (sec)((sec) == ((asection *) &bfd_und_section)) && !bfd_is_com_section (sec)(((sec)->flags & 0x1000) != 0); | |||
905 | ||||
906 | olddef = (h->root.type != bfd_link_hash_undefined | |||
907 | && h->root.type != bfd_link_hash_undefweak | |||
908 | && h->root.type != bfd_link_hash_common); | |||
909 | ||||
910 | /* When we try to create a default indirect symbol from the dynamic | |||
911 | definition with the default version, we skip it if its type and | |||
912 | the type of existing regular definition mismatch. We only do it | |||
913 | if the existing regular definition won't be dynamic. */ | |||
914 | if (pold_alignment == NULL((void*)0) | |||
915 | && !info->shared | |||
916 | && !info->export_dynamic | |||
917 | && !h->ref_dynamic | |||
918 | && newdyn | |||
919 | && newdef | |||
920 | && !olddyn | |||
921 | && (olddef || h->root.type == bfd_link_hash_common) | |||
922 | && ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != h->type | |||
923 | && ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != STT_NOTYPE0 | |||
924 | && h->type != STT_NOTYPE0) | |||
925 | { | |||
926 | *skip = TRUE1; | |||
927 | return TRUE1; | |||
928 | } | |||
929 | ||||
930 | /* Check TLS symbol. We don't check undefined symbol introduced by | |||
931 | "ld -u". */ | |||
932 | if ((ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) == STT_TLS6 || h->type == STT_TLS6) | |||
933 | && ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != h->type | |||
934 | && oldbfd != NULL((void*)0)) | |||
935 | { | |||
936 | bfd *ntbfd, *tbfd; | |||
937 | bfd_boolean ntdef, tdef; | |||
938 | asection *ntsec, *tsec; | |||
939 | ||||
940 | if (h->type == STT_TLS6) | |||
941 | { | |||
942 | ntbfd = abfd; | |||
943 | ntsec = sec; | |||
944 | ntdef = newdef; | |||
945 | tbfd = oldbfd; | |||
946 | tsec = oldsec; | |||
947 | tdef = olddef; | |||
948 | } | |||
949 | else | |||
950 | { | |||
951 | ntbfd = oldbfd; | |||
952 | ntsec = oldsec; | |||
953 | ntdef = olddef; | |||
954 | tbfd = abfd; | |||
955 | tsec = sec; | |||
956 | tdef = newdef; | |||
957 | } | |||
958 | ||||
959 | if (tdef && ntdef) | |||
960 | (*_bfd_error_handler) | |||
961 | (_("%s: TLS definition in %B section %A mismatches non-TLS definition in %B section %A")("%s: TLS definition in %B section %A mismatches non-TLS definition in %B section %A" ), | |||
962 | tbfd, tsec, ntbfd, ntsec, h->root.root.string); | |||
963 | else if (!tdef && !ntdef) | |||
964 | (*_bfd_error_handler) | |||
965 | (_("%s: TLS reference in %B mismatches non-TLS reference in %B")("%s: TLS reference in %B mismatches non-TLS reference in %B" ), | |||
966 | tbfd, ntbfd, h->root.root.string); | |||
967 | else if (tdef) | |||
968 | (*_bfd_error_handler) | |||
969 | (_("%s: TLS definition in %B section %A mismatches non-TLS reference in %B")("%s: TLS definition in %B section %A mismatches non-TLS reference in %B" ), | |||
970 | tbfd, tsec, ntbfd, h->root.root.string); | |||
971 | else | |||
972 | (*_bfd_error_handler) | |||
973 | (_("%s: TLS reference in %B mismatches non-TLS definition in %B section %A")("%s: TLS reference in %B mismatches non-TLS definition in %B section %A" ), | |||
974 | tbfd, ntbfd, ntsec, h->root.root.string); | |||
975 | ||||
976 | bfd_set_error (bfd_error_bad_value); | |||
977 | return FALSE0; | |||
978 | } | |||
979 | ||||
980 | /* We need to remember if a symbol has a definition in a dynamic | |||
981 | object or is weak in all dynamic objects. Internal and hidden | |||
982 | visibility will make it unavailable to dynamic objects. */ | |||
983 | if (newdyn && !h->dynamic_def) | |||
984 | { | |||
985 | if (!bfd_is_und_section (sec)((sec) == ((asection *) &bfd_und_section))) | |||
986 | h->dynamic_def = 1; | |||
987 | else | |||
988 | { | |||
989 | /* Check if this symbol is weak in all dynamic objects. If it | |||
990 | is the first time we see it in a dynamic object, we mark | |||
991 | if it is weak. Otherwise, we clear it. */ | |||
992 | if (!h->ref_dynamic) | |||
993 | { | |||
994 | if (bind == STB_WEAK2) | |||
995 | h->dynamic_weak = 1; | |||
996 | } | |||
997 | else if (bind != STB_WEAK2) | |||
998 | h->dynamic_weak = 0; | |||
999 | } | |||
1000 | } | |||
1001 | ||||
1002 | /* If the old symbol has non-default visibility, we ignore the new | |||
1003 | definition from a dynamic object. */ | |||
1004 | if (newdyn | |||
1005 | && ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_DEFAULT0 | |||
1006 | && !bfd_is_und_section (sec)((sec) == ((asection *) &bfd_und_section))) | |||
1007 | { | |||
1008 | *skip = TRUE1; | |||
1009 | /* Make sure this symbol is dynamic. */ | |||
1010 | h->ref_dynamic = 1; | |||
1011 | /* A protected symbol has external availability. Make sure it is | |||
1012 | recorded as dynamic. | |||
1013 | ||||
1014 | FIXME: Should we check type and size for protected symbol? */ | |||
1015 | if (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_PROTECTED3) | |||
1016 | return bfd_elf_link_record_dynamic_symbol (info, h); | |||
1017 | else | |||
1018 | return TRUE1; | |||
1019 | } | |||
1020 | else if (!newdyn | |||
1021 | && ELF_ST_VISIBILITY (sym->st_other)((sym->st_other) & 0x3) != STV_DEFAULT0 | |||
1022 | && h->def_dynamic) | |||
1023 | { | |||
1024 | /* If the new symbol with non-default visibility comes from a | |||
1025 | relocatable file and the old definition comes from a dynamic | |||
1026 | object, we remove the old definition. */ | |||
1027 | if ((*sym_hash)->root.type == bfd_link_hash_indirect) | |||
1028 | h = *sym_hash; | |||
1029 | ||||
1030 | if ((h->root.u.undef.next || info->hash->undefs_tail == &h->root) | |||
1031 | && bfd_is_und_section (sec)((sec) == ((asection *) &bfd_und_section))) | |||
1032 | { | |||
1033 | /* If the new symbol is undefined and the old symbol was | |||
1034 | also undefined before, we need to make sure | |||
1035 | _bfd_generic_link_add_one_symbol doesn't mess | |||
1036 | up the linker hash table undefs list. Since the old | |||
1037 | definition came from a dynamic object, it is still on the | |||
1038 | undefs list. */ | |||
1039 | h->root.type = bfd_link_hash_undefined; | |||
1040 | h->root.u.undef.abfd = abfd; | |||
1041 | } | |||
1042 | else | |||
1043 | { | |||
1044 | h->root.type = bfd_link_hash_new; | |||
1045 | h->root.u.undef.abfd = NULL((void*)0); | |||
1046 | } | |||
1047 | ||||
1048 | if (h->def_dynamic) | |||
1049 | { | |||
1050 | h->def_dynamic = 0; | |||
1051 | h->ref_dynamic = 1; | |||
1052 | h->dynamic_def = 1; | |||
1053 | } | |||
1054 | /* FIXME: Should we check type and size for protected symbol? */ | |||
1055 | h->size = 0; | |||
1056 | h->type = 0; | |||
1057 | return TRUE1; | |||
1058 | } | |||
1059 | ||||
1060 | /* Differentiate strong and weak symbols. */ | |||
1061 | newweak = bind == STB_WEAK2; | |||
1062 | oldweak = (h->root.type == bfd_link_hash_defweak | |||
1063 | || h->root.type == bfd_link_hash_undefweak); | |||
1064 | ||||
1065 | /* If a new weak symbol definition comes from a regular file and the | |||
1066 | old symbol comes from a dynamic library, we treat the new one as | |||
1067 | strong. Similarly, an old weak symbol definition from a regular | |||
1068 | file is treated as strong when the new symbol comes from a dynamic | |||
1069 | library. Further, an old weak symbol from a dynamic library is | |||
1070 | treated as strong if the new symbol is from a dynamic library. | |||
1071 | This reflects the way glibc's ld.so works. | |||
1072 | ||||
1073 | Do this before setting *type_change_ok or *size_change_ok so that | |||
1074 | we warn properly when dynamic library symbols are overridden. */ | |||
1075 | ||||
1076 | if (newdef && !newdyn && olddyn) | |||
1077 | newweak = FALSE0; | |||
1078 | if (olddef && newdyn) | |||
1079 | oldweak = FALSE0; | |||
1080 | ||||
1081 | /* It's OK to change the type if either the existing symbol or the | |||
1082 | new symbol is weak. A type change is also OK if the old symbol | |||
1083 | is undefined and the new symbol is defined. */ | |||
1084 | ||||
1085 | if (oldweak | |||
1086 | || newweak | |||
1087 | || (newdef | |||
1088 | && h->root.type == bfd_link_hash_undefined)) | |||
1089 | *type_change_ok = TRUE1; | |||
1090 | ||||
1091 | /* It's OK to change the size if either the existing symbol or the | |||
1092 | new symbol is weak, or if the old symbol is undefined. */ | |||
1093 | ||||
1094 | if (*type_change_ok | |||
1095 | || h->root.type == bfd_link_hash_undefined) | |||
1096 | *size_change_ok = TRUE1; | |||
1097 | ||||
1098 | /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old | |||
1099 | symbol, respectively, appears to be a common symbol in a dynamic | |||
1100 | object. If a symbol appears in an uninitialized section, and is | |||
1101 | not weak, and is not a function, then it may be a common symbol | |||
1102 | which was resolved when the dynamic object was created. We want | |||
1103 | to treat such symbols specially, because they raise special | |||
1104 | considerations when setting the symbol size: if the symbol | |||
1105 | appears as a common symbol in a regular object, and the size in | |||
1106 | the regular object is larger, we must make sure that we use the | |||
1107 | larger size. This problematic case can always be avoided in C, | |||
1108 | but it must be handled correctly when using Fortran shared | |||
1109 | libraries. | |||
1110 | ||||
1111 | Note that if NEWDYNCOMMON is set, NEWDEF will be set, and | |||
1112 | likewise for OLDDYNCOMMON and OLDDEF. | |||
1113 | ||||
1114 | Note that this test is just a heuristic, and that it is quite | |||
1115 | possible to have an uninitialized symbol in a shared object which | |||
1116 | is really a definition, rather than a common symbol. This could | |||
1117 | lead to some minor confusion when the symbol really is a common | |||
1118 | symbol in some regular object. However, I think it will be | |||
1119 | harmless. */ | |||
1120 | ||||
1121 | if (newdyn | |||
1122 | && newdef | |||
1123 | && !newweak | |||
1124 | && (sec->flags & SEC_ALLOC0x001) != 0 | |||
1125 | && (sec->flags & SEC_LOAD0x002) == 0 | |||
1126 | && sym->st_size > 0 | |||
1127 | && ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) != STT_FUNC2) | |||
1128 | newdyncommon = TRUE1; | |||
1129 | else | |||
1130 | newdyncommon = FALSE0; | |||
1131 | ||||
1132 | if (olddyn | |||
1133 | && olddef | |||
1134 | && h->root.type == bfd_link_hash_defined | |||
1135 | && h->def_dynamic | |||
1136 | && (h->root.u.def.section->flags & SEC_ALLOC0x001) != 0 | |||
1137 | && (h->root.u.def.section->flags & SEC_LOAD0x002) == 0 | |||
1138 | && h->size > 0 | |||
1139 | && h->type != STT_FUNC2) | |||
1140 | olddyncommon = TRUE1; | |||
1141 | else | |||
1142 | olddyncommon = FALSE0; | |||
1143 | ||||
1144 | /* We now know everything about the old and new symbols. We ask the | |||
1145 | backend to check if we can merge them. */ | |||
1146 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
1147 | if (bed->merge_symbol | |||
1148 | && !bed->merge_symbol (info, sym_hash, h, sym, psec, pvalue, | |||
1149 | pold_alignment, skip, override, | |||
1150 | type_change_ok, size_change_ok, | |||
1151 | &newdyn, &newdef, &newdyncommon, &newweak, | |||
1152 | abfd, &sec, | |||
1153 | &olddyn, &olddef, &olddyncommon, &oldweak, | |||
1154 | oldbfd, &oldsec)) | |||
1155 | return FALSE0; | |||
1156 | ||||
1157 | /* If both the old and the new symbols look like common symbols in a | |||
1158 | dynamic object, set the size of the symbol to the larger of the | |||
1159 | two. */ | |||
1160 | ||||
1161 | if (olddyncommon | |||
1162 | && newdyncommon | |||
1163 | && sym->st_size != h->size) | |||
1164 | { | |||
1165 | /* Since we think we have two common symbols, issue a multiple | |||
1166 | common warning if desired. Note that we only warn if the | |||
1167 | size is different. If the size is the same, we simply let | |||
1168 | the old symbol override the new one as normally happens with | |||
1169 | symbols defined in dynamic objects. */ | |||
1170 | ||||
1171 | if (! ((*info->callbacks->multiple_common) | |||
1172 | (info, h->root.root.string, oldbfd, bfd_link_hash_common, | |||
1173 | h->size, abfd, bfd_link_hash_common, sym->st_size))) | |||
1174 | return FALSE0; | |||
1175 | ||||
1176 | if (sym->st_size > h->size) | |||
1177 | h->size = sym->st_size; | |||
1178 | ||||
1179 | *size_change_ok = TRUE1; | |||
1180 | } | |||
1181 | ||||
1182 | /* If we are looking at a dynamic object, and we have found a | |||
1183 | definition, we need to see if the symbol was already defined by | |||
1184 | some other object. If so, we want to use the existing | |||
1185 | definition, and we do not want to report a multiple symbol | |||
1186 | definition error; we do this by clobbering *PSEC to be | |||
1187 | bfd_und_section_ptr. | |||
1188 | ||||
1189 | We treat a common symbol as a definition if the symbol in the | |||
1190 | shared library is a function, since common symbols always | |||
1191 | represent variables; this can cause confusion in principle, but | |||
1192 | any such confusion would seem to indicate an erroneous program or | |||
1193 | shared library. We also permit a common symbol in a regular | |||
1194 | object to override a weak symbol in a shared object. */ | |||
1195 | ||||
1196 | if (newdyn | |||
1197 | && newdef | |||
1198 | && (olddef | |||
1199 | || (h->root.type == bfd_link_hash_common | |||
1200 | && (newweak | |||
1201 | || ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) == STT_FUNC2 | |||
1202 | || (!olddyn && info->executable))))) | |||
1203 | { | |||
1204 | *override = TRUE1; | |||
1205 | newdef = FALSE0; | |||
1206 | newdyncommon = FALSE0; | |||
1207 | ||||
1208 | *psec = sec = bfd_und_section_ptr((asection *) &bfd_und_section); | |||
1209 | *size_change_ok = TRUE1; | |||
1210 | ||||
1211 | /* If we get here when the old symbol is a common symbol, then | |||
1212 | we are explicitly letting it override a weak symbol or | |||
1213 | function in a dynamic object, and we don't want to warn about | |||
1214 | a type change. If the old symbol is a defined symbol, a type | |||
1215 | change warning may still be appropriate. */ | |||
1216 | ||||
1217 | if (h->root.type == bfd_link_hash_common) | |||
1218 | *type_change_ok = TRUE1; | |||
1219 | } | |||
1220 | ||||
1221 | /* Handle the special case of an old common symbol merging with a | |||
1222 | new symbol which looks like a common symbol in a shared object. | |||
1223 | We change *PSEC and *PVALUE to make the new symbol look like a | |||
1224 | common symbol, and let _bfd_generic_link_add_one_symbol do the | |||
1225 | right thing. */ | |||
1226 | ||||
1227 | if (newdyncommon | |||
1228 | && h->root.type == bfd_link_hash_common) | |||
1229 | { | |||
1230 | *override = TRUE1; | |||
1231 | newdef = FALSE0; | |||
1232 | newdyncommon = FALSE0; | |||
1233 | *pvalue = sym->st_size; | |||
1234 | *psec = sec = bed->common_section (oldsec); | |||
1235 | *size_change_ok = TRUE1; | |||
1236 | } | |||
1237 | ||||
1238 | /* Skip weak definitions of symbols that are already defined. */ | |||
1239 | if (newdef && olddef && newweak) | |||
1240 | *skip = TRUE1; | |||
1241 | ||||
1242 | /* If the old symbol is from a dynamic object, and the new symbol is | |||
1243 | a definition which is not from a dynamic object, then the new | |||
1244 | symbol overrides the old symbol. Symbols from regular files | |||
1245 | always take precedence over symbols from dynamic objects, even if | |||
1246 | they are defined after the dynamic object in the link. | |||
1247 | ||||
1248 | As above, we again permit a common symbol in a regular object to | |||
1249 | override a definition in a shared object if the shared object | |||
1250 | symbol is a function or is weak. */ | |||
1251 | ||||
1252 | flip = NULL((void*)0); | |||
1253 | if (!newdyn | |||
1254 | && (newdef | |||
1255 | || (bfd_is_com_section (sec)(((sec)->flags & 0x1000) != 0) | |||
1256 | && (oldweak | |||
1257 | || h->type == STT_FUNC2))) | |||
1258 | && olddyn | |||
1259 | && olddef | |||
1260 | && h->def_dynamic) | |||
1261 | { | |||
1262 | /* Change the hash table entry to undefined, and let | |||
1263 | _bfd_generic_link_add_one_symbol do the right thing with the | |||
1264 | new definition. */ | |||
1265 | ||||
1266 | h->root.type = bfd_link_hash_undefined; | |||
1267 | h->root.u.undef.abfd = h->root.u.def.section->owner; | |||
1268 | *size_change_ok = TRUE1; | |||
1269 | ||||
1270 | olddef = FALSE0; | |||
1271 | olddyncommon = FALSE0; | |||
1272 | ||||
1273 | /* We again permit a type change when a common symbol may be | |||
1274 | overriding a function. */ | |||
1275 | ||||
1276 | if (bfd_is_com_section (sec)(((sec)->flags & 0x1000) != 0)) | |||
1277 | *type_change_ok = TRUE1; | |||
1278 | ||||
1279 | if ((*sym_hash)->root.type == bfd_link_hash_indirect) | |||
1280 | flip = *sym_hash; | |||
1281 | else | |||
1282 | /* This union may have been set to be non-NULL when this symbol | |||
1283 | was seen in a dynamic object. We must force the union to be | |||
1284 | NULL, so that it is correct for a regular symbol. */ | |||
1285 | h->verinfo.vertree = NULL((void*)0); | |||
1286 | } | |||
1287 | ||||
1288 | /* Handle the special case of a new common symbol merging with an | |||
1289 | old symbol that looks like it might be a common symbol defined in | |||
1290 | a shared object. Note that we have already handled the case in | |||
1291 | which a new common symbol should simply override the definition | |||
1292 | in the shared library. */ | |||
1293 | ||||
1294 | if (! newdyn | |||
1295 | && bfd_is_com_section (sec)(((sec)->flags & 0x1000) != 0) | |||
1296 | && olddyncommon) | |||
1297 | { | |||
1298 | /* It would be best if we could set the hash table entry to a | |||
1299 | common symbol, but we don't know what to use for the section | |||
1300 | or the alignment. */ | |||
1301 | if (! ((*info->callbacks->multiple_common) | |||
1302 | (info, h->root.root.string, oldbfd, bfd_link_hash_common, | |||
1303 | h->size, abfd, bfd_link_hash_common, sym->st_size))) | |||
1304 | return FALSE0; | |||
1305 | ||||
1306 | /* If the presumed common symbol in the dynamic object is | |||
1307 | larger, pretend that the new symbol has its size. */ | |||
1308 | ||||
1309 | if (h->size > *pvalue) | |||
1310 | *pvalue = h->size; | |||
1311 | ||||
1312 | /* We need to remember the alignment required by the symbol | |||
1313 | in the dynamic object. */ | |||
1314 | BFD_ASSERT (pold_alignment)do { if (!(pold_alignment)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,1314); } while (0); | |||
1315 | *pold_alignment = h->root.u.def.section->alignment_power; | |||
1316 | ||||
1317 | olddef = FALSE0; | |||
1318 | olddyncommon = FALSE0; | |||
1319 | ||||
1320 | h->root.type = bfd_link_hash_undefined; | |||
1321 | h->root.u.undef.abfd = h->root.u.def.section->owner; | |||
1322 | ||||
1323 | *size_change_ok = TRUE1; | |||
1324 | *type_change_ok = TRUE1; | |||
1325 | ||||
1326 | if ((*sym_hash)->root.type == bfd_link_hash_indirect) | |||
1327 | flip = *sym_hash; | |||
1328 | else | |||
1329 | h->verinfo.vertree = NULL((void*)0); | |||
1330 | } | |||
1331 | ||||
1332 | if (flip != NULL((void*)0)) | |||
1333 | { | |||
1334 | /* Handle the case where we had a versioned symbol in a dynamic | |||
1335 | library and now find a definition in a normal object. In this | |||
1336 | case, we make the versioned symbol point to the normal one. */ | |||
1337 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
1338 | flip->root.type = h->root.type; | |||
1339 | h->root.type = bfd_link_hash_indirect; | |||
1340 | h->root.u.i.link = (struct bfd_link_hash_entry *) flip; | |||
1341 | (*bed->elf_backend_copy_indirect_symbol) (info, flip, h); | |||
1342 | flip->root.u.undef.abfd = h->root.u.undef.abfd; | |||
1343 | if (h->def_dynamic) | |||
1344 | { | |||
1345 | h->def_dynamic = 0; | |||
1346 | flip->ref_dynamic = 1; | |||
1347 | } | |||
1348 | } | |||
1349 | ||||
1350 | return TRUE1; | |||
1351 | } | |||
1352 | ||||
1353 | /* This function is called to create an indirect symbol from the | |||
1354 | default for the symbol with the default version if needed. The | |||
1355 | symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE. We | |||
1356 | set DYNSYM if the new indirect symbol is dynamic. */ | |||
1357 | ||||
1358 | bfd_boolean | |||
1359 | _bfd_elf_add_default_symbol (bfd *abfd, | |||
1360 | struct bfd_link_info *info, | |||
1361 | struct elf_link_hash_entry *h, | |||
1362 | const char *name, | |||
1363 | Elf_Internal_Sym *sym, | |||
1364 | asection **psec, | |||
1365 | bfd_vma *value, | |||
1366 | bfd_boolean *dynsym, | |||
1367 | bfd_boolean override) | |||
1368 | { | |||
1369 | bfd_boolean type_change_ok; | |||
1370 | bfd_boolean size_change_ok; | |||
1371 | bfd_boolean skip; | |||
1372 | char *shortname; | |||
1373 | struct elf_link_hash_entry *hi; | |||
1374 | struct bfd_link_hash_entry *bh; | |||
1375 | const struct elf_backend_data *bed; | |||
1376 | bfd_boolean collect; | |||
1377 | bfd_boolean dynamic; | |||
1378 | char *p; | |||
1379 | size_t len, shortlen; | |||
1380 | asection *sec; | |||
1381 | ||||
1382 | /* If this symbol has a version, and it is the default version, we | |||
1383 | create an indirect symbol from the default name to the fully | |||
1384 | decorated name. This will cause external references which do not | |||
1385 | specify a version to be bound to this version of the symbol. */ | |||
1386 | p = strchr (name, ELF_VER_CHR'@'); | |||
1387 | if (p == NULL((void*)0) || p[1] != ELF_VER_CHR'@') | |||
1388 | return TRUE1; | |||
1389 | ||||
1390 | if (override) | |||
1391 | { | |||
1392 | /* We are overridden by an old definition. We need to check if we | |||
1393 | need to create the indirect symbol from the default name. */ | |||
1394 | hi = elf_link_hash_lookup (elf_hash_table (info), name, TRUE,((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( name), (1), (0), (0))) | |||
1395 | FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( name), (1), (0), (0))); | |||
1396 | BFD_ASSERT (hi != NULL)do { if (!(hi != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,1396); } while (0); | |||
1397 | if (hi == h) | |||
1398 | return TRUE1; | |||
1399 | while (hi->root.type == bfd_link_hash_indirect | |||
1400 | || hi->root.type == bfd_link_hash_warning) | |||
1401 | { | |||
1402 | hi = (struct elf_link_hash_entry *) hi->root.u.i.link; | |||
1403 | if (hi == h) | |||
1404 | return TRUE1; | |||
1405 | } | |||
1406 | } | |||
1407 | ||||
1408 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
1409 | collect = bed->collect; | |||
1410 | dynamic = (abfd->flags & DYNAMIC0x40) != 0; | |||
1411 | ||||
1412 | shortlen = p - name; | |||
1413 | shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1); | |||
1414 | if (shortname == NULL((void*)0)) | |||
1415 | return FALSE0; | |||
1416 | memcpy (shortname, name, shortlen); | |||
1417 | shortname[shortlen] = '\0'; | |||
1418 | ||||
1419 | /* We are going to create a new symbol. Merge it with any existing | |||
1420 | symbol with this name. For the purposes of the merge, act as | |||
1421 | though we were defining the symbol we just defined, although we | |||
1422 | actually going to define an indirect symbol. */ | |||
1423 | type_change_ok = FALSE0; | |||
1424 | size_change_ok = FALSE0; | |||
1425 | sec = *psec; | |||
1426 | if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value, | |||
1427 | NULL((void*)0), &hi, &skip, &override, | |||
1428 | &type_change_ok, &size_change_ok)) | |||
1429 | return FALSE0; | |||
1430 | ||||
1431 | if (skip) | |||
1432 | goto nondefault; | |||
1433 | ||||
1434 | if (! override) | |||
1435 | { | |||
1436 | bh = &hi->root; | |||
1437 | if (! (_bfd_generic_link_add_one_symbol | |||
1438 | (info, abfd, shortname, BSF_INDIRECT0x2000, bfd_ind_section_ptr((asection *) &bfd_ind_section), | |||
1439 | 0, name, FALSE0, collect, &bh))) | |||
1440 | return FALSE0; | |||
1441 | hi = (struct elf_link_hash_entry *) bh; | |||
1442 | } | |||
1443 | else | |||
1444 | { | |||
1445 | /* In this case the symbol named SHORTNAME is overriding the | |||
1446 | indirect symbol we want to add. We were planning on making | |||
1447 | SHORTNAME an indirect symbol referring to NAME. SHORTNAME | |||
1448 | is the name without a version. NAME is the fully versioned | |||
1449 | name, and it is the default version. | |||
1450 | ||||
1451 | Overriding means that we already saw a definition for the | |||
1452 | symbol SHORTNAME in a regular object, and it is overriding | |||
1453 | the symbol defined in the dynamic object. | |||
1454 | ||||
1455 | When this happens, we actually want to change NAME, the | |||
1456 | symbol we just added, to refer to SHORTNAME. This will cause | |||
1457 | references to NAME in the shared object to become references | |||
1458 | to SHORTNAME in the regular object. This is what we expect | |||
1459 | when we override a function in a shared object: that the | |||
1460 | references in the shared object will be mapped to the | |||
1461 | definition in the regular object. */ | |||
1462 | ||||
1463 | while (hi->root.type == bfd_link_hash_indirect | |||
1464 | || hi->root.type == bfd_link_hash_warning) | |||
1465 | hi = (struct elf_link_hash_entry *) hi->root.u.i.link; | |||
1466 | ||||
1467 | h->root.type = bfd_link_hash_indirect; | |||
1468 | h->root.u.i.link = (struct bfd_link_hash_entry *) hi; | |||
1469 | if (h->def_dynamic) | |||
1470 | { | |||
1471 | h->def_dynamic = 0; | |||
1472 | hi->ref_dynamic = 1; | |||
1473 | if (hi->ref_regular | |||
1474 | || hi->def_regular) | |||
1475 | { | |||
1476 | if (! bfd_elf_link_record_dynamic_symbol (info, hi)) | |||
1477 | return FALSE0; | |||
1478 | } | |||
1479 | } | |||
1480 | ||||
1481 | /* Now set HI to H, so that the following code will set the | |||
1482 | other fields correctly. */ | |||
1483 | hi = h; | |||
1484 | } | |||
1485 | ||||
1486 | /* If there is a duplicate definition somewhere, then HI may not | |||
1487 | point to an indirect symbol. We will have reported an error to | |||
1488 | the user in that case. */ | |||
1489 | ||||
1490 | if (hi->root.type == bfd_link_hash_indirect) | |||
1491 | { | |||
1492 | struct elf_link_hash_entry *ht; | |||
1493 | ||||
1494 | ht = (struct elf_link_hash_entry *) hi->root.u.i.link; | |||
1495 | (*bed->elf_backend_copy_indirect_symbol) (info, ht, hi); | |||
1496 | ||||
1497 | /* See if the new flags lead us to realize that the symbol must | |||
1498 | be dynamic. */ | |||
1499 | if (! *dynsym) | |||
1500 | { | |||
1501 | if (! dynamic) | |||
1502 | { | |||
1503 | if (info->shared | |||
1504 | || hi->ref_dynamic) | |||
1505 | *dynsym = TRUE1; | |||
1506 | } | |||
1507 | else | |||
1508 | { | |||
1509 | if (hi->ref_regular) | |||
1510 | *dynsym = TRUE1; | |||
1511 | } | |||
1512 | } | |||
1513 | } | |||
1514 | ||||
1515 | /* We also need to define an indirection from the nondefault version | |||
1516 | of the symbol. */ | |||
1517 | ||||
1518 | nondefault: | |||
1519 | len = strlen (name); | |||
1520 | shortname = bfd_hash_allocate (&info->hash->table, len); | |||
1521 | if (shortname == NULL((void*)0)) | |||
1522 | return FALSE0; | |||
1523 | memcpy (shortname, name, shortlen); | |||
1524 | memcpy (shortname + shortlen, p + 1, len - shortlen); | |||
1525 | ||||
1526 | /* Once again, merge with any existing symbol. */ | |||
1527 | type_change_ok = FALSE0; | |||
1528 | size_change_ok = FALSE0; | |||
1529 | sec = *psec; | |||
1530 | if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value, | |||
1531 | NULL((void*)0), &hi, &skip, &override, | |||
1532 | &type_change_ok, &size_change_ok)) | |||
1533 | return FALSE0; | |||
1534 | ||||
1535 | if (skip) | |||
1536 | return TRUE1; | |||
1537 | ||||
1538 | if (override) | |||
1539 | { | |||
1540 | /* Here SHORTNAME is a versioned name, so we don't expect to see | |||
1541 | the type of override we do in the case above unless it is | |||
1542 | overridden by a versioned definition. */ | |||
1543 | if (hi->root.type != bfd_link_hash_defined | |||
1544 | && hi->root.type != bfd_link_hash_defweak) | |||
1545 | (*_bfd_error_handler) | |||
1546 | (_("%B: unexpected redefinition of indirect versioned symbol `%s'")("%B: unexpected redefinition of indirect versioned symbol `%s'" ), | |||
1547 | abfd, shortname); | |||
1548 | } | |||
1549 | else | |||
1550 | { | |||
1551 | bh = &hi->root; | |||
1552 | if (! (_bfd_generic_link_add_one_symbol | |||
1553 | (info, abfd, shortname, BSF_INDIRECT0x2000, | |||
1554 | bfd_ind_section_ptr((asection *) &bfd_ind_section), 0, name, FALSE0, collect, &bh))) | |||
1555 | return FALSE0; | |||
1556 | hi = (struct elf_link_hash_entry *) bh; | |||
1557 | ||||
1558 | /* If there is a duplicate definition somewhere, then HI may not | |||
1559 | point to an indirect symbol. We will have reported an error | |||
1560 | to the user in that case. */ | |||
1561 | ||||
1562 | if (hi->root.type == bfd_link_hash_indirect) | |||
1563 | { | |||
1564 | (*bed->elf_backend_copy_indirect_symbol) (info, h, hi); | |||
1565 | ||||
1566 | /* See if the new flags lead us to realize that the symbol | |||
1567 | must be dynamic. */ | |||
1568 | if (! *dynsym) | |||
1569 | { | |||
1570 | if (! dynamic) | |||
1571 | { | |||
1572 | if (info->shared | |||
1573 | || hi->ref_dynamic) | |||
1574 | *dynsym = TRUE1; | |||
1575 | } | |||
1576 | else | |||
1577 | { | |||
1578 | if (hi->ref_regular) | |||
1579 | *dynsym = TRUE1; | |||
1580 | } | |||
1581 | } | |||
1582 | } | |||
1583 | } | |||
1584 | ||||
1585 | return TRUE1; | |||
1586 | } | |||
1587 | ||||
1588 | /* This routine is used to export all defined symbols into the dynamic | |||
1589 | symbol table. It is called via elf_link_hash_traverse. */ | |||
1590 | ||||
1591 | bfd_boolean | |||
1592 | _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data) | |||
1593 | { | |||
1594 | struct elf_info_failed *eif = data; | |||
1595 | ||||
1596 | /* Ignore indirect symbols. These are added by the versioning code. */ | |||
1597 | if (h->root.type == bfd_link_hash_indirect) | |||
1598 | return TRUE1; | |||
1599 | ||||
1600 | if (h->root.type == bfd_link_hash_warning) | |||
1601 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
1602 | ||||
1603 | if (h->dynindx == -1 | |||
1604 | && (h->def_regular | |||
1605 | || h->ref_regular)) | |||
1606 | { | |||
1607 | struct bfd_elf_version_tree *t; | |||
1608 | struct bfd_elf_version_expr *d; | |||
1609 | ||||
1610 | for (t = eif->verdefs; t != NULL((void*)0); t = t->next) | |||
1611 | { | |||
1612 | if (t->globals.list != NULL((void*)0)) | |||
1613 | { | |||
1614 | d = (*t->match) (&t->globals, NULL((void*)0), h->root.root.string); | |||
1615 | if (d != NULL((void*)0)) | |||
1616 | goto doit; | |||
1617 | } | |||
1618 | ||||
1619 | if (t->locals.list != NULL((void*)0)) | |||
1620 | { | |||
1621 | d = (*t->match) (&t->locals, NULL((void*)0), h->root.root.string); | |||
1622 | if (d != NULL((void*)0)) | |||
1623 | return TRUE1; | |||
1624 | } | |||
1625 | } | |||
1626 | ||||
1627 | if (!eif->verdefs) | |||
1628 | { | |||
1629 | doit: | |||
1630 | if (! bfd_elf_link_record_dynamic_symbol (eif->info, h)) | |||
1631 | { | |||
1632 | eif->failed = TRUE1; | |||
1633 | return FALSE0; | |||
1634 | } | |||
1635 | } | |||
1636 | } | |||
1637 | ||||
1638 | return TRUE1; | |||
1639 | } | |||
1640 | ||||
1641 | /* Look through the symbols which are defined in other shared | |||
1642 | libraries and referenced here. Update the list of version | |||
1643 | dependencies. This will be put into the .gnu.version_r section. | |||
1644 | This function is called via elf_link_hash_traverse. */ | |||
1645 | ||||
1646 | bfd_boolean | |||
1647 | _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry *h, | |||
1648 | void *data) | |||
1649 | { | |||
1650 | struct elf_find_verdep_info *rinfo = data; | |||
1651 | Elf_Internal_Verneed *t; | |||
1652 | Elf_Internal_Vernaux *a; | |||
1653 | bfd_size_type amt; | |||
1654 | ||||
1655 | if (h->root.type == bfd_link_hash_warning) | |||
1656 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
1657 | ||||
1658 | /* We only care about symbols defined in shared objects with version | |||
1659 | information. */ | |||
1660 | if (!h->def_dynamic | |||
1661 | || h->def_regular | |||
1662 | || h->dynindx == -1 | |||
1663 | || h->verinfo.verdef == NULL((void*)0)) | |||
1664 | return TRUE1; | |||
1665 | ||||
1666 | /* See if we already know about this version. */ | |||
1667 | for (t = elf_tdata (rinfo->output_bfd)((rinfo->output_bfd) -> tdata.elf_obj_data)->verref; t != NULL((void*)0); t = t->vn_nextref) | |||
1668 | { | |||
1669 | if (t->vn_bfd != h->verinfo.verdef->vd_bfd) | |||
1670 | continue; | |||
1671 | ||||
1672 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
1673 | if (a->vna_nodename == h->verinfo.verdef->vd_nodename) | |||
1674 | return TRUE1; | |||
1675 | ||||
1676 | break; | |||
1677 | } | |||
1678 | ||||
1679 | /* This is a new version. Add it to tree we are building. */ | |||
1680 | ||||
1681 | if (t == NULL((void*)0)) | |||
1682 | { | |||
1683 | amt = sizeof *t; | |||
1684 | t = bfd_zalloc (rinfo->output_bfd, amt); | |||
1685 | if (t == NULL((void*)0)) | |||
1686 | { | |||
1687 | rinfo->failed = TRUE1; | |||
1688 | return FALSE0; | |||
1689 | } | |||
1690 | ||||
1691 | t->vn_bfd = h->verinfo.verdef->vd_bfd; | |||
1692 | t->vn_nextref = elf_tdata (rinfo->output_bfd)((rinfo->output_bfd) -> tdata.elf_obj_data)->verref; | |||
1693 | elf_tdata (rinfo->output_bfd)((rinfo->output_bfd) -> tdata.elf_obj_data)->verref = t; | |||
1694 | } | |||
1695 | ||||
1696 | amt = sizeof *a; | |||
1697 | a = bfd_zalloc (rinfo->output_bfd, amt); | |||
1698 | ||||
1699 | /* Note that we are copying a string pointer here, and testing it | |||
1700 | above. If bfd_elf_string_from_elf_section is ever changed to | |||
1701 | discard the string data when low in memory, this will have to be | |||
1702 | fixed. */ | |||
1703 | a->vna_nodename = h->verinfo.verdef->vd_nodename; | |||
1704 | ||||
1705 | a->vna_flags = h->verinfo.verdef->vd_flags; | |||
1706 | a->vna_nextptr = t->vn_auxptr; | |||
1707 | ||||
1708 | h->verinfo.verdef->vd_exp_refno = rinfo->vers; | |||
1709 | ++rinfo->vers; | |||
1710 | ||||
1711 | a->vna_other = h->verinfo.verdef->vd_exp_refno + 1; | |||
1712 | ||||
1713 | t->vn_auxptr = a; | |||
1714 | ||||
1715 | return TRUE1; | |||
1716 | } | |||
1717 | ||||
1718 | /* Figure out appropriate versions for all the symbols. We may not | |||
1719 | have the version number script until we have read all of the input | |||
1720 | files, so until that point we don't know which symbols should be | |||
1721 | local. This function is called via elf_link_hash_traverse. */ | |||
1722 | ||||
1723 | bfd_boolean | |||
1724 | _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data) | |||
1725 | { | |||
1726 | struct elf_assign_sym_version_info *sinfo; | |||
1727 | struct bfd_link_info *info; | |||
1728 | const struct elf_backend_data *bed; | |||
1729 | struct elf_info_failed eif; | |||
1730 | char *p; | |||
1731 | bfd_size_type amt; | |||
1732 | ||||
1733 | sinfo = data; | |||
1734 | info = sinfo->info; | |||
1735 | ||||
1736 | if (h->root.type == bfd_link_hash_warning) | |||
1737 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
1738 | ||||
1739 | /* Fix the symbol flags. */ | |||
1740 | eif.failed = FALSE0; | |||
1741 | eif.info = info; | |||
1742 | if (! _bfd_elf_fix_symbol_flags (h, &eif)) | |||
1743 | { | |||
1744 | if (eif.failed) | |||
1745 | sinfo->failed = TRUE1; | |||
1746 | return FALSE0; | |||
1747 | } | |||
1748 | ||||
1749 | /* We only need version numbers for symbols defined in regular | |||
1750 | objects. */ | |||
1751 | if (!h->def_regular) | |||
1752 | return TRUE1; | |||
1753 | ||||
1754 | bed = get_elf_backend_data (sinfo->output_bfd)((const struct elf_backend_data *) (sinfo->output_bfd)-> xvec->backend_data); | |||
1755 | p = strchr (h->root.root.string, ELF_VER_CHR'@'); | |||
1756 | if (p != NULL((void*)0) && h->verinfo.vertree == NULL((void*)0)) | |||
1757 | { | |||
1758 | struct bfd_elf_version_tree *t; | |||
1759 | bfd_boolean hidden; | |||
1760 | ||||
1761 | hidden = TRUE1; | |||
1762 | ||||
1763 | /* There are two consecutive ELF_VER_CHR characters if this is | |||
1764 | not a hidden symbol. */ | |||
1765 | ++p; | |||
1766 | if (*p == ELF_VER_CHR'@') | |||
1767 | { | |||
1768 | hidden = FALSE0; | |||
1769 | ++p; | |||
1770 | } | |||
1771 | ||||
1772 | /* If there is no version string, we can just return out. */ | |||
1773 | if (*p == '\0') | |||
1774 | { | |||
1775 | if (hidden) | |||
1776 | h->hidden = 1; | |||
1777 | return TRUE1; | |||
1778 | } | |||
1779 | ||||
1780 | /* Look for the version. If we find it, it is no longer weak. */ | |||
1781 | for (t = sinfo->verdefs; t != NULL((void*)0); t = t->next) | |||
1782 | { | |||
1783 | if (strcmp (t->name, p) == 0) | |||
1784 | { | |||
1785 | size_t len; | |||
1786 | char *alc; | |||
1787 | struct bfd_elf_version_expr *d; | |||
1788 | ||||
1789 | len = p - h->root.root.string; | |||
1790 | alc = bfd_malloc (len); | |||
1791 | if (alc == NULL((void*)0)) | |||
1792 | return FALSE0; | |||
1793 | memcpy (alc, h->root.root.string, len - 1); | |||
1794 | alc[len - 1] = '\0'; | |||
1795 | if (alc[len - 2] == ELF_VER_CHR'@') | |||
1796 | alc[len - 2] = '\0'; | |||
1797 | ||||
1798 | h->verinfo.vertree = t; | |||
1799 | t->used = TRUE1; | |||
1800 | d = NULL((void*)0); | |||
1801 | ||||
1802 | if (t->globals.list != NULL((void*)0)) | |||
1803 | d = (*t->match) (&t->globals, NULL((void*)0), alc); | |||
1804 | ||||
1805 | /* See if there is anything to force this symbol to | |||
1806 | local scope. */ | |||
1807 | if (d == NULL((void*)0) && t->locals.list != NULL((void*)0)) | |||
1808 | { | |||
1809 | d = (*t->match) (&t->locals, NULL((void*)0), alc); | |||
1810 | if (d != NULL((void*)0) | |||
1811 | && h->dynindx != -1 | |||
1812 | && ! info->export_dynamic) | |||
1813 | (*bed->elf_backend_hide_symbol) (info, h, TRUE1); | |||
1814 | } | |||
1815 | ||||
1816 | free (alc); | |||
1817 | break; | |||
1818 | } | |||
1819 | } | |||
1820 | ||||
1821 | /* If we are building an application, we need to create a | |||
1822 | version node for this version. */ | |||
1823 | if (t == NULL((void*)0) && info->executable) | |||
1824 | { | |||
1825 | struct bfd_elf_version_tree **pp; | |||
1826 | int version_index; | |||
1827 | ||||
1828 | /* If we aren't going to export this symbol, we don't need | |||
1829 | to worry about it. */ | |||
1830 | if (h->dynindx == -1) | |||
1831 | return TRUE1; | |||
1832 | ||||
1833 | amt = sizeof *t; | |||
1834 | t = bfd_zalloc (sinfo->output_bfd, amt); | |||
1835 | if (t == NULL((void*)0)) | |||
1836 | { | |||
1837 | sinfo->failed = TRUE1; | |||
1838 | return FALSE0; | |||
1839 | } | |||
1840 | ||||
1841 | t->name = p; | |||
1842 | t->name_indx = (unsigned int) -1; | |||
1843 | t->used = TRUE1; | |||
1844 | ||||
1845 | version_index = 1; | |||
1846 | /* Don't count anonymous version tag. */ | |||
1847 | if (sinfo->verdefs != NULL((void*)0) && sinfo->verdefs->vernum == 0) | |||
1848 | version_index = 0; | |||
1849 | for (pp = &sinfo->verdefs; *pp != NULL((void*)0); pp = &(*pp)->next) | |||
1850 | ++version_index; | |||
1851 | t->vernum = version_index; | |||
1852 | ||||
1853 | *pp = t; | |||
1854 | ||||
1855 | h->verinfo.vertree = t; | |||
1856 | } | |||
1857 | else if (t == NULL((void*)0)) | |||
1858 | { | |||
1859 | /* We could not find the version for a symbol when | |||
1860 | generating a shared archive. Return an error. */ | |||
1861 | (*_bfd_error_handler) | |||
1862 | (_("%B: undefined versioned symbol name %s")("%B: undefined versioned symbol name %s"), | |||
1863 | sinfo->output_bfd, h->root.root.string); | |||
1864 | bfd_set_error (bfd_error_bad_value); | |||
1865 | sinfo->failed = TRUE1; | |||
1866 | return FALSE0; | |||
1867 | } | |||
1868 | ||||
1869 | if (hidden) | |||
1870 | h->hidden = 1; | |||
1871 | } | |||
1872 | ||||
1873 | /* If we don't have a version for this symbol, see if we can find | |||
1874 | something. */ | |||
1875 | if (h->verinfo.vertree == NULL((void*)0) && sinfo->verdefs != NULL((void*)0)) | |||
1876 | { | |||
1877 | struct bfd_elf_version_tree *t; | |||
1878 | struct bfd_elf_version_tree *local_ver; | |||
1879 | struct bfd_elf_version_expr *d; | |||
1880 | ||||
1881 | /* See if can find what version this symbol is in. If the | |||
1882 | symbol is supposed to be local, then don't actually register | |||
1883 | it. */ | |||
1884 | local_ver = NULL((void*)0); | |||
1885 | for (t = sinfo->verdefs; t != NULL((void*)0); t = t->next) | |||
1886 | { | |||
1887 | if (t->globals.list != NULL((void*)0)) | |||
1888 | { | |||
1889 | bfd_boolean matched; | |||
1890 | ||||
1891 | matched = FALSE0; | |||
1892 | d = NULL((void*)0); | |||
1893 | while ((d = (*t->match) (&t->globals, d, | |||
1894 | h->root.root.string)) != NULL((void*)0)) | |||
1895 | if (d->symver) | |||
1896 | matched = TRUE1; | |||
1897 | else | |||
1898 | { | |||
1899 | /* There is a version without definition. Make | |||
1900 | the symbol the default definition for this | |||
1901 | version. */ | |||
1902 | h->verinfo.vertree = t; | |||
1903 | local_ver = NULL((void*)0); | |||
1904 | d->script = 1; | |||
1905 | break; | |||
1906 | } | |||
1907 | if (d != NULL((void*)0)) | |||
1908 | break; | |||
1909 | else if (matched) | |||
1910 | /* There is no undefined version for this symbol. Hide the | |||
1911 | default one. */ | |||
1912 | (*bed->elf_backend_hide_symbol) (info, h, TRUE1); | |||
1913 | } | |||
1914 | ||||
1915 | if (t->locals.list != NULL((void*)0)) | |||
1916 | { | |||
1917 | d = NULL((void*)0); | |||
1918 | while ((d = (*t->match) (&t->locals, d, | |||
1919 | h->root.root.string)) != NULL((void*)0)) | |||
1920 | { | |||
1921 | local_ver = t; | |||
1922 | /* If the match is "*", keep looking for a more | |||
1923 | explicit, perhaps even global, match. | |||
1924 | XXX: Shouldn't this be !d->wildcard instead? */ | |||
1925 | if (d->pattern[0] != '*' || d->pattern[1] != '\0') | |||
1926 | break; | |||
1927 | } | |||
1928 | ||||
1929 | if (d != NULL((void*)0)) | |||
1930 | break; | |||
1931 | } | |||
1932 | } | |||
1933 | ||||
1934 | if (local_ver != NULL((void*)0)) | |||
1935 | { | |||
1936 | h->verinfo.vertree = local_ver; | |||
1937 | if (h->dynindx != -1 | |||
1938 | && ! info->export_dynamic) | |||
1939 | { | |||
1940 | (*bed->elf_backend_hide_symbol) (info, h, TRUE1); | |||
1941 | } | |||
1942 | } | |||
1943 | } | |||
1944 | ||||
1945 | return TRUE1; | |||
1946 | } | |||
1947 | ||||
1948 | /* Read and swap the relocs from the section indicated by SHDR. This | |||
1949 | may be either a REL or a RELA section. The relocations are | |||
1950 | translated into RELA relocations and stored in INTERNAL_RELOCS, | |||
1951 | which should have already been allocated to contain enough space. | |||
1952 | The EXTERNAL_RELOCS are a buffer where the external form of the | |||
1953 | relocations should be stored. | |||
1954 | ||||
1955 | Returns FALSE if something goes wrong. */ | |||
1956 | ||||
1957 | static bfd_boolean | |||
1958 | elf_link_read_relocs_from_section (bfd *abfd, | |||
1959 | asection *sec, | |||
1960 | Elf_Internal_Shdr *shdr, | |||
1961 | void *external_relocs, | |||
1962 | Elf_Internal_Rela *internal_relocs) | |||
1963 | { | |||
1964 | const struct elf_backend_data *bed; | |||
1965 | void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *); | |||
1966 | const bfd_byte *erela; | |||
1967 | const bfd_byte *erelaend; | |||
1968 | Elf_Internal_Rela *irela; | |||
1969 | Elf_Internal_Shdr *symtab_hdr; | |||
1970 | size_t nsyms; | |||
1971 | ||||
1972 | /* Position ourselves at the start of the section. */ | |||
1973 | if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET0) != 0) | |||
1974 | return FALSE0; | |||
1975 | ||||
1976 | /* Read the relocations. */ | |||
1977 | if (bfd_bread (external_relocs, shdr->sh_size, abfd) != shdr->sh_size) | |||
1978 | return FALSE0; | |||
1979 | ||||
1980 | symtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
1981 | nsyms = symtab_hdr->sh_size / symtab_hdr->sh_entsize; | |||
1982 | ||||
1983 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
1984 | ||||
1985 | /* Convert the external relocations to the internal format. */ | |||
1986 | if (shdr->sh_entsize == bed->s->sizeof_rel) | |||
1987 | swap_in = bed->s->swap_reloc_in; | |||
1988 | else if (shdr->sh_entsize == bed->s->sizeof_rela) | |||
1989 | swap_in = bed->s->swap_reloca_in; | |||
1990 | else | |||
1991 | { | |||
1992 | bfd_set_error (bfd_error_wrong_format); | |||
1993 | return FALSE0; | |||
1994 | } | |||
1995 | ||||
1996 | erela = external_relocs; | |||
1997 | erelaend = erela + shdr->sh_size; | |||
1998 | irela = internal_relocs; | |||
1999 | while (erela < erelaend) | |||
2000 | { | |||
2001 | bfd_vma r_symndx; | |||
2002 | ||||
2003 | (*swap_in) (abfd, erela, irela); | |||
2004 | r_symndx = ELF32_R_SYM (irela->r_info)((irela->r_info) >> 8); | |||
2005 | if (bed->s->arch_size == 64) | |||
2006 | r_symndx >>= 24; | |||
2007 | if ((size_t) r_symndx >= nsyms) | |||
2008 | { | |||
2009 | (*_bfd_error_handler) | |||
2010 | (_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"("%B: bad reloc symbol index (0x%lx >= 0x%lx)" " for offset 0x%lx in section `%A'" ) | |||
2011 | " for offset 0x%lx in section `%A'")("%B: bad reloc symbol index (0x%lx >= 0x%lx)" " for offset 0x%lx in section `%A'" ), | |||
2012 | abfd, sec, | |||
2013 | (unsigned long) r_symndx, (unsigned long) nsyms, irela->r_offset); | |||
2014 | bfd_set_error (bfd_error_bad_value); | |||
2015 | return FALSE0; | |||
2016 | } | |||
2017 | irela += bed->s->int_rels_per_ext_rel; | |||
2018 | erela += shdr->sh_entsize; | |||
2019 | } | |||
2020 | ||||
2021 | return TRUE1; | |||
2022 | } | |||
2023 | ||||
2024 | /* Read and swap the relocs for a section O. They may have been | |||
2025 | cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are | |||
2026 | not NULL, they are used as buffers to read into. They are known to | |||
2027 | be large enough. If the INTERNAL_RELOCS relocs argument is NULL, | |||
2028 | the return value is allocated using either malloc or bfd_alloc, | |||
2029 | according to the KEEP_MEMORY argument. If O has two relocation | |||
2030 | sections (both REL and RELA relocations), then the REL_HDR | |||
2031 | relocations will appear first in INTERNAL_RELOCS, followed by the | |||
2032 | REL_HDR2 relocations. */ | |||
2033 | ||||
2034 | Elf_Internal_Rela * | |||
2035 | _bfd_elf_link_read_relocs (bfd *abfd, | |||
2036 | asection *o, | |||
2037 | void *external_relocs, | |||
2038 | Elf_Internal_Rela *internal_relocs, | |||
2039 | bfd_boolean keep_memory) | |||
2040 | { | |||
2041 | Elf_Internal_Shdr *rel_hdr; | |||
2042 | void *alloc1 = NULL((void*)0); | |||
2043 | Elf_Internal_Rela *alloc2 = NULL((void*)0); | |||
2044 | const struct elf_backend_data *bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2045 | ||||
2046 | if (elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->relocs != NULL((void*)0)) | |||
2047 | return elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->relocs; | |||
2048 | ||||
2049 | if (o->reloc_count == 0) | |||
2050 | return NULL((void*)0); | |||
2051 | ||||
2052 | rel_hdr = &elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hdr; | |||
2053 | ||||
2054 | if (internal_relocs == NULL((void*)0)) | |||
2055 | { | |||
2056 | bfd_size_type size; | |||
2057 | ||||
2058 | size = o->reloc_count; | |||
2059 | size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela); | |||
2060 | if (keep_memory) | |||
2061 | internal_relocs = bfd_alloc (abfd, size); | |||
2062 | else | |||
2063 | internal_relocs = alloc2 = bfd_malloc (size); | |||
2064 | if (internal_relocs == NULL((void*)0)) | |||
2065 | goto error_return; | |||
2066 | } | |||
2067 | ||||
2068 | if (external_relocs == NULL((void*)0)) | |||
2069 | { | |||
2070 | bfd_size_type size = rel_hdr->sh_size; | |||
2071 | ||||
2072 | if (elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hdr2) | |||
2073 | size += elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hdr2->sh_size; | |||
2074 | alloc1 = bfd_malloc (size); | |||
2075 | if (alloc1 == NULL((void*)0)) | |||
2076 | goto error_return; | |||
2077 | external_relocs = alloc1; | |||
2078 | } | |||
2079 | ||||
2080 | if (!elf_link_read_relocs_from_section (abfd, o, rel_hdr, | |||
2081 | external_relocs, | |||
2082 | internal_relocs)) | |||
2083 | goto error_return; | |||
2084 | if (elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hdr2 | |||
2085 | && (!elf_link_read_relocs_from_section | |||
2086 | (abfd, o, | |||
2087 | elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hdr2, | |||
2088 | ((bfd_byte *) external_relocs) + rel_hdr->sh_size, | |||
2089 | internal_relocs + (NUM_SHDR_ENTRIES (rel_hdr)((rel_hdr)->sh_size / (rel_hdr)->sh_entsize) | |||
2090 | * bed->s->int_rels_per_ext_rel)))) | |||
2091 | goto error_return; | |||
2092 | ||||
2093 | /* Cache the results for next time, if we can. */ | |||
2094 | if (keep_memory) | |||
2095 | elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->relocs = internal_relocs; | |||
2096 | ||||
2097 | if (alloc1 != NULL((void*)0)) | |||
2098 | free (alloc1); | |||
2099 | ||||
2100 | /* Don't free alloc2, since if it was allocated we are passing it | |||
2101 | back (under the name of internal_relocs). */ | |||
2102 | ||||
2103 | return internal_relocs; | |||
2104 | ||||
2105 | error_return: | |||
2106 | if (alloc1 != NULL((void*)0)) | |||
2107 | free (alloc1); | |||
2108 | if (alloc2 != NULL((void*)0)) | |||
2109 | free (alloc2); | |||
2110 | return NULL((void*)0); | |||
2111 | } | |||
2112 | ||||
2113 | /* Compute the size of, and allocate space for, REL_HDR which is the | |||
2114 | section header for a section containing relocations for O. */ | |||
2115 | ||||
2116 | bfd_boolean | |||
2117 | _bfd_elf_link_size_reloc_section (bfd *abfd, | |||
2118 | Elf_Internal_Shdr *rel_hdr, | |||
2119 | asection *o) | |||
2120 | { | |||
2121 | bfd_size_type reloc_count; | |||
2122 | bfd_size_type num_rel_hashes; | |||
2123 | ||||
2124 | /* Figure out how many relocations there will be. */ | |||
2125 | if (rel_hdr == &elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hdr) | |||
2126 | reloc_count = elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_count; | |||
2127 | else | |||
2128 | reloc_count = elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_count2; | |||
2129 | ||||
2130 | num_rel_hashes = o->reloc_count; | |||
2131 | if (num_rel_hashes < reloc_count) | |||
2132 | num_rel_hashes = reloc_count; | |||
2133 | ||||
2134 | /* That allows us to calculate the size of the section. */ | |||
2135 | rel_hdr->sh_size = rel_hdr->sh_entsize * reloc_count; | |||
2136 | ||||
2137 | /* The contents field must last into write_object_contents, so we | |||
2138 | allocate it with bfd_alloc rather than malloc. Also since we | |||
2139 | cannot be sure that the contents will actually be filled in, | |||
2140 | we zero the allocated space. */ | |||
2141 | rel_hdr->contents = bfd_zalloc (abfd, rel_hdr->sh_size); | |||
2142 | if (rel_hdr->contents == NULL((void*)0) && rel_hdr->sh_size != 0) | |||
2143 | return FALSE0; | |||
2144 | ||||
2145 | /* We only allocate one set of hash entries, so we only do it the | |||
2146 | first time we are called. */ | |||
2147 | if (elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hashes == NULL((void*)0) | |||
2148 | && num_rel_hashes) | |||
2149 | { | |||
2150 | struct elf_link_hash_entry **p; | |||
2151 | ||||
2152 | p = bfd_zmalloc (num_rel_hashes * sizeof (struct elf_link_hash_entry *)); | |||
2153 | if (p == NULL((void*)0)) | |||
2154 | return FALSE0; | |||
2155 | ||||
2156 | elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->rel_hashes = p; | |||
2157 | } | |||
2158 | ||||
2159 | return TRUE1; | |||
2160 | } | |||
2161 | ||||
2162 | /* Copy the relocations indicated by the INTERNAL_RELOCS (which | |||
2163 | originated from the section given by INPUT_REL_HDR) to the | |||
2164 | OUTPUT_BFD. */ | |||
2165 | ||||
2166 | bfd_boolean | |||
2167 | _bfd_elf_link_output_relocs (bfd *output_bfd, | |||
2168 | asection *input_section, | |||
2169 | Elf_Internal_Shdr *input_rel_hdr, | |||
2170 | Elf_Internal_Rela *internal_relocs, | |||
2171 | struct elf_link_hash_entry **rel_hash | |||
2172 | ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
2173 | { | |||
2174 | Elf_Internal_Rela *irela; | |||
2175 | Elf_Internal_Rela *irelaend; | |||
2176 | bfd_byte *erel; | |||
2177 | Elf_Internal_Shdr *output_rel_hdr; | |||
2178 | asection *output_section; | |||
2179 | unsigned int *rel_countp = NULL((void*)0); | |||
2180 | const struct elf_backend_data *bed; | |||
2181 | void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *); | |||
2182 | ||||
2183 | output_section = input_section->output_section; | |||
2184 | output_rel_hdr = NULL((void*)0); | |||
2185 | ||||
2186 | if (elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_hdr.sh_entsize | |||
2187 | == input_rel_hdr->sh_entsize) | |||
2188 | { | |||
2189 | output_rel_hdr = &elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_hdr; | |||
2190 | rel_countp = &elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_count; | |||
2191 | } | |||
2192 | else if (elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_hdr2 | |||
2193 | && (elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_hdr2->sh_entsize | |||
2194 | == input_rel_hdr->sh_entsize)) | |||
2195 | { | |||
2196 | output_rel_hdr = elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_hdr2; | |||
2197 | rel_countp = &elf_section_data (output_section)((struct bfd_elf_section_data*)(output_section)->used_by_bfd )->rel_count2; | |||
2198 | } | |||
2199 | else | |||
2200 | { | |||
2201 | (*_bfd_error_handler) | |||
2202 | (_("%B: relocation size mismatch in %B section %A")("%B: relocation size mismatch in %B section %A"), | |||
2203 | output_bfd, input_section->owner, input_section); | |||
2204 | bfd_set_error (bfd_error_wrong_object_format); | |||
2205 | return FALSE0; | |||
2206 | } | |||
2207 | ||||
2208 | bed = get_elf_backend_data (output_bfd)((const struct elf_backend_data *) (output_bfd)->xvec-> backend_data); | |||
2209 | if (input_rel_hdr->sh_entsize == bed->s->sizeof_rel) | |||
2210 | swap_out = bed->s->swap_reloc_out; | |||
2211 | else if (input_rel_hdr->sh_entsize == bed->s->sizeof_rela) | |||
2212 | swap_out = bed->s->swap_reloca_out; | |||
2213 | else | |||
2214 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" , 2214, __PRETTY_FUNCTION__); | |||
2215 | ||||
2216 | erel = output_rel_hdr->contents; | |||
2217 | erel += *rel_countp * input_rel_hdr->sh_entsize; | |||
2218 | irela = internal_relocs; | |||
2219 | irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)((input_rel_hdr)->sh_size / (input_rel_hdr)->sh_entsize ) | |||
2220 | * bed->s->int_rels_per_ext_rel); | |||
2221 | while (irela < irelaend) | |||
2222 | { | |||
2223 | (*swap_out) (output_bfd, irela, erel); | |||
2224 | irela += bed->s->int_rels_per_ext_rel; | |||
2225 | erel += input_rel_hdr->sh_entsize; | |||
2226 | } | |||
2227 | ||||
2228 | /* Bump the counter, so that we know where to add the next set of | |||
2229 | relocations. */ | |||
2230 | *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr)((input_rel_hdr)->sh_size / (input_rel_hdr)->sh_entsize ); | |||
2231 | ||||
2232 | return TRUE1; | |||
2233 | } | |||
2234 | ||||
2235 | /* Make weak undefined symbols in PIE dynamic. */ | |||
2236 | ||||
2237 | bfd_boolean | |||
2238 | _bfd_elf_link_hash_fixup_symbol (struct bfd_link_info *info, | |||
2239 | struct elf_link_hash_entry *h) | |||
2240 | { | |||
2241 | if (info->pie | |||
2242 | && h->dynindx == -1 | |||
2243 | && h->root.type == bfd_link_hash_undefweak) | |||
2244 | return bfd_elf_link_record_dynamic_symbol (info, h); | |||
2245 | ||||
2246 | return TRUE1; | |||
2247 | } | |||
2248 | ||||
2249 | /* Fix up the flags for a symbol. This handles various cases which | |||
2250 | can only be fixed after all the input files are seen. This is | |||
2251 | currently called by both adjust_dynamic_symbol and | |||
2252 | assign_sym_version, which is unnecessary but perhaps more robust in | |||
2253 | the face of future changes. */ | |||
2254 | ||||
2255 | bfd_boolean | |||
2256 | _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h, | |||
2257 | struct elf_info_failed *eif) | |||
2258 | { | |||
2259 | const struct elf_backend_data *bed = NULL((void*)0); | |||
2260 | ||||
2261 | /* If this symbol was mentioned in a non-ELF file, try to set | |||
2262 | DEF_REGULAR and REF_REGULAR correctly. This is the only way to | |||
2263 | permit a non-ELF file to correctly refer to a symbol defined in | |||
2264 | an ELF dynamic object. */ | |||
2265 | if (h->non_elf) | |||
2266 | { | |||
2267 | while (h->root.type == bfd_link_hash_indirect) | |||
2268 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
2269 | ||||
2270 | if (h->root.type != bfd_link_hash_defined | |||
2271 | && h->root.type != bfd_link_hash_defweak) | |||
2272 | { | |||
2273 | h->ref_regular = 1; | |||
2274 | h->ref_regular_nonweak = 1; | |||
2275 | } | |||
2276 | else | |||
2277 | { | |||
2278 | if (h->root.u.def.section->owner != NULL((void*)0) | |||
2279 | && (bfd_get_flavour (h->root.u.def.section->owner)((h->root.u.def.section->owner)->xvec->flavour) | |||
2280 | == bfd_target_elf_flavour)) | |||
2281 | { | |||
2282 | h->ref_regular = 1; | |||
2283 | h->ref_regular_nonweak = 1; | |||
2284 | } | |||
2285 | else | |||
2286 | h->def_regular = 1; | |||
2287 | } | |||
2288 | ||||
2289 | if (h->dynindx == -1 | |||
2290 | && (h->def_dynamic | |||
2291 | || h->ref_dynamic)) | |||
2292 | { | |||
2293 | if (! bfd_elf_link_record_dynamic_symbol (eif->info, h)) | |||
2294 | { | |||
2295 | eif->failed = TRUE1; | |||
2296 | return FALSE0; | |||
2297 | } | |||
2298 | } | |||
2299 | } | |||
2300 | else | |||
2301 | { | |||
2302 | /* Unfortunately, NON_ELF is only correct if the symbol | |||
2303 | was first seen in a non-ELF file. Fortunately, if the symbol | |||
2304 | was first seen in an ELF file, we're probably OK unless the | |||
2305 | symbol was defined in a non-ELF file. Catch that case here. | |||
2306 | FIXME: We're still in trouble if the symbol was first seen in | |||
2307 | a dynamic object, and then later in a non-ELF regular object. */ | |||
2308 | if ((h->root.type == bfd_link_hash_defined | |||
2309 | || h->root.type == bfd_link_hash_defweak) | |||
2310 | && !h->def_regular | |||
2311 | && (h->root.u.def.section->owner != NULL((void*)0) | |||
2312 | ? (bfd_get_flavour (h->root.u.def.section->owner)((h->root.u.def.section->owner)->xvec->flavour) | |||
2313 | != bfd_target_elf_flavour) | |||
2314 | : (bfd_is_abs_section (h->root.u.def.section)((h->root.u.def.section) == ((asection *) &bfd_abs_section )) | |||
2315 | && !h->def_dynamic))) | |||
2316 | h->def_regular = 1; | |||
2317 | } | |||
2318 | ||||
2319 | /* Backend specific symbol fixup. */ | |||
2320 | if (elf_hash_table (eif->info)((struct elf_link_hash_table *) ((eif->info)->hash))->dynobj) | |||
2321 | { | |||
2322 | bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj)((const struct elf_backend_data *) (((struct elf_link_hash_table *) ((eif->info)->hash))->dynobj)->xvec->backend_data ); | |||
2323 | if (bed->elf_backend_fixup_symbol | |||
2324 | && !(*bed->elf_backend_fixup_symbol) (eif->info, h)) | |||
2325 | return FALSE0; | |||
2326 | } | |||
2327 | ||||
2328 | /* If this is a final link, and the symbol was defined as a common | |||
2329 | symbol in a regular object file, and there was no definition in | |||
2330 | any dynamic object, then the linker will have allocated space for | |||
2331 | the symbol in a common section but the DEF_REGULAR | |||
2332 | flag will not have been set. */ | |||
2333 | if (h->root.type == bfd_link_hash_defined | |||
2334 | && !h->def_regular | |||
2335 | && h->ref_regular | |||
2336 | && !h->def_dynamic | |||
2337 | && (h->root.u.def.section->owner->flags & DYNAMIC0x40) == 0) | |||
2338 | h->def_regular = 1; | |||
2339 | ||||
2340 | /* If -Bsymbolic was used (which means to bind references to global | |||
2341 | symbols to the definition within the shared object), and this | |||
2342 | symbol was defined in a regular object, then it actually doesn't | |||
2343 | need a PLT entry. Likewise, if the symbol has non-default | |||
2344 | visibility. If the symbol has hidden or internal visibility, we | |||
2345 | will force it local. */ | |||
2346 | if (h->needs_plt | |||
2347 | && eif->info->shared | |||
2348 | && is_elf_hash_table (eif->info->hash)(((struct bfd_link_hash_table *) (eif->info->hash))-> type == bfd_link_elf_hash_table) | |||
2349 | && (eif->info->symbolic || eif->info->static_link | |||
2350 | || ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_DEFAULT0) | |||
2351 | && h->def_regular) | |||
2352 | { | |||
2353 | bfd_boolean force_local; | |||
2354 | ||||
2355 | force_local = (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_INTERNAL1 | |||
2356 | || ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_HIDDEN2); | |||
2357 | (*bed->elf_backend_hide_symbol) (eif->info, h, force_local); | |||
2358 | } | |||
2359 | ||||
2360 | /* If a weak undefined symbol has non-default visibility, we also | |||
2361 | hide it from the dynamic linker. */ | |||
2362 | if (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_DEFAULT0 | |||
2363 | && h->root.type == bfd_link_hash_undefweak) | |||
2364 | { | |||
2365 | const struct elf_backend_data *bed; | |||
2366 | bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj)((const struct elf_backend_data *) (((struct elf_link_hash_table *) ((eif->info)->hash))->dynobj)->xvec->backend_data ); | |||
2367 | (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE1); | |||
2368 | } | |||
2369 | ||||
2370 | /* If this is a weak defined symbol in a dynamic object, and we know | |||
2371 | the real definition in the dynamic object, copy interesting flags | |||
2372 | over to the real definition. */ | |||
2373 | if (h->u.weakdef != NULL((void*)0)) | |||
2374 | { | |||
2375 | struct elf_link_hash_entry *weakdef; | |||
2376 | ||||
2377 | weakdef = h->u.weakdef; | |||
2378 | if (h->root.type == bfd_link_hash_indirect) | |||
2379 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
2380 | ||||
2381 | BFD_ASSERT (h->root.type == bfd_link_hash_defineddo { if (!(h->root.type == bfd_link_hash_defined || h-> root.type == bfd_link_hash_defweak)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2382); } while (0) | |||
2382 | || h->root.type == bfd_link_hash_defweak)do { if (!(h->root.type == bfd_link_hash_defined || h-> root.type == bfd_link_hash_defweak)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2382); } while (0); | |||
2383 | BFD_ASSERT (weakdef->root.type == bfd_link_hash_defineddo { if (!(weakdef->root.type == bfd_link_hash_defined || weakdef ->root.type == bfd_link_hash_defweak)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2384); } while (0) | |||
2384 | || weakdef->root.type == bfd_link_hash_defweak)do { if (!(weakdef->root.type == bfd_link_hash_defined || weakdef ->root.type == bfd_link_hash_defweak)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2384); } while (0); | |||
2385 | BFD_ASSERT (weakdef->def_dynamic)do { if (!(weakdef->def_dynamic)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2385); } while (0); | |||
2386 | ||||
2387 | /* If the real definition is defined by a regular object file, | |||
2388 | don't do anything special. See the longer description in | |||
2389 | _bfd_elf_adjust_dynamic_symbol, below. */ | |||
2390 | if (weakdef->def_regular) | |||
2391 | h->u.weakdef = NULL((void*)0); | |||
2392 | else | |||
2393 | (*bed->elf_backend_copy_indirect_symbol) (eif->info, weakdef, | |||
2394 | h); | |||
2395 | } | |||
2396 | ||||
2397 | return TRUE1; | |||
2398 | } | |||
2399 | ||||
2400 | /* Make the backend pick a good value for a dynamic symbol. This is | |||
2401 | called via elf_link_hash_traverse, and also calls itself | |||
2402 | recursively. */ | |||
2403 | ||||
2404 | bfd_boolean | |||
2405 | _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data) | |||
2406 | { | |||
2407 | struct elf_info_failed *eif = data; | |||
2408 | bfd *dynobj; | |||
2409 | const struct elf_backend_data *bed; | |||
2410 | ||||
2411 | if (! is_elf_hash_table (eif->info->hash)(((struct bfd_link_hash_table *) (eif->info->hash))-> type == bfd_link_elf_hash_table)) | |||
2412 | return FALSE0; | |||
2413 | ||||
2414 | if (h->root.type == bfd_link_hash_warning) | |||
2415 | { | |||
2416 | h->got = elf_hash_table (eif->info)((struct elf_link_hash_table *) ((eif->info)->hash))->init_got_offset; | |||
2417 | h->plt = elf_hash_table (eif->info)((struct elf_link_hash_table *) ((eif->info)->hash))->init_plt_offset; | |||
2418 | ||||
2419 | /* When warning symbols are created, they **replace** the "real" | |||
2420 | entry in the hash table, thus we never get to see the real | |||
2421 | symbol in a hash traversal. So look at it now. */ | |||
2422 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
2423 | } | |||
2424 | ||||
2425 | /* Ignore indirect symbols. These are added by the versioning code. */ | |||
2426 | if (h->root.type == bfd_link_hash_indirect) | |||
2427 | return TRUE1; | |||
2428 | ||||
2429 | /* Fix the symbol flags. */ | |||
2430 | if (! _bfd_elf_fix_symbol_flags (h, eif)) | |||
2431 | return FALSE0; | |||
2432 | ||||
2433 | /* If this symbol does not require a PLT entry, and it is not | |||
2434 | defined by a dynamic object, or is not referenced by a regular | |||
2435 | object, ignore it. We do have to handle a weak defined symbol, | |||
2436 | even if no regular object refers to it, if we decided to add it | |||
2437 | to the dynamic symbol table. FIXME: Do we normally need to worry | |||
2438 | about symbols which are defined by one dynamic object and | |||
2439 | referenced by another one? */ | |||
2440 | if (!h->needs_plt | |||
2441 | && (h->def_regular | |||
2442 | || !h->def_dynamic | |||
2443 | || (!h->ref_regular | |||
2444 | && (h->u.weakdef == NULL((void*)0) || h->u.weakdef->dynindx == -1)))) | |||
2445 | { | |||
2446 | h->plt = elf_hash_table (eif->info)((struct elf_link_hash_table *) ((eif->info)->hash))->init_plt_offset; | |||
2447 | return TRUE1; | |||
2448 | } | |||
2449 | ||||
2450 | /* If we've already adjusted this symbol, don't do it again. This | |||
2451 | can happen via a recursive call. */ | |||
2452 | if (h->dynamic_adjusted) | |||
2453 | return TRUE1; | |||
2454 | ||||
2455 | /* Don't look at this symbol again. Note that we must set this | |||
2456 | after checking the above conditions, because we may look at a | |||
2457 | symbol once, decide not to do anything, and then get called | |||
2458 | recursively later after REF_REGULAR is set below. */ | |||
2459 | h->dynamic_adjusted = 1; | |||
2460 | ||||
2461 | /* If this is a weak definition, and we know a real definition, and | |||
2462 | the real symbol is not itself defined by a regular object file, | |||
2463 | then get a good value for the real definition. We handle the | |||
2464 | real symbol first, for the convenience of the backend routine. | |||
2465 | ||||
2466 | Note that there is a confusing case here. If the real definition | |||
2467 | is defined by a regular object file, we don't get the real symbol | |||
2468 | from the dynamic object, but we do get the weak symbol. If the | |||
2469 | processor backend uses a COPY reloc, then if some routine in the | |||
2470 | dynamic object changes the real symbol, we will not see that | |||
2471 | change in the corresponding weak symbol. This is the way other | |||
2472 | ELF linkers work as well, and seems to be a result of the shared | |||
2473 | library model. | |||
2474 | ||||
2475 | I will clarify this issue. Most SVR4 shared libraries define the | |||
2476 | variable _timezone and define timezone as a weak synonym. The | |||
2477 | tzset call changes _timezone. If you write | |||
2478 | extern int timezone; | |||
2479 | int _timezone = 5; | |||
2480 | int main () { tzset (); printf ("%d %d\n", timezone, _timezone); } | |||
2481 | you might expect that, since timezone is a synonym for _timezone, | |||
2482 | the same number will print both times. However, if the processor | |||
2483 | backend uses a COPY reloc, then actually timezone will be copied | |||
2484 | into your process image, and, since you define _timezone | |||
2485 | yourself, _timezone will not. Thus timezone and _timezone will | |||
2486 | wind up at different memory locations. The tzset call will set | |||
2487 | _timezone, leaving timezone unchanged. */ | |||
2488 | ||||
2489 | if (h->u.weakdef != NULL((void*)0)) | |||
2490 | { | |||
2491 | /* If we get to this point, we know there is an implicit | |||
2492 | reference by a regular object file via the weak symbol H. | |||
2493 | FIXME: Is this really true? What if the traversal finds | |||
2494 | H->U.WEAKDEF before it finds H? */ | |||
2495 | h->u.weakdef->ref_regular = 1; | |||
2496 | ||||
2497 | if (! _bfd_elf_adjust_dynamic_symbol (h->u.weakdef, eif)) | |||
2498 | return FALSE0; | |||
2499 | } | |||
2500 | ||||
2501 | /* If a symbol has no type and no size and does not require a PLT | |||
2502 | entry, then we are probably about to do the wrong thing here: we | |||
2503 | are probably going to create a COPY reloc for an empty object. | |||
2504 | This case can arise when a shared object is built with assembly | |||
2505 | code, and the assembly code fails to set the symbol type. */ | |||
2506 | if (h->size == 0 | |||
2507 | && h->type == STT_NOTYPE0 | |||
2508 | && !h->needs_plt) | |||
2509 | (*_bfd_error_handler) | |||
2510 | (_("warning: type and size of dynamic symbol `%s' are not defined")("warning: type and size of dynamic symbol `%s' are not defined" ), | |||
2511 | h->root.root.string); | |||
2512 | ||||
2513 | dynobj = elf_hash_table (eif->info)((struct elf_link_hash_table *) ((eif->info)->hash))->dynobj; | |||
2514 | bed = get_elf_backend_data (dynobj)((const struct elf_backend_data *) (dynobj)->xvec->backend_data ); | |||
2515 | if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h)) | |||
2516 | { | |||
2517 | eif->failed = TRUE1; | |||
2518 | return FALSE0; | |||
2519 | } | |||
2520 | ||||
2521 | return TRUE1; | |||
2522 | } | |||
2523 | ||||
2524 | /* Adjust all external symbols pointing into SEC_MERGE sections | |||
2525 | to reflect the object merging within the sections. */ | |||
2526 | ||||
2527 | bfd_boolean | |||
2528 | _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry *h, void *data) | |||
2529 | { | |||
2530 | asection *sec; | |||
2531 | ||||
2532 | if (h->root.type == bfd_link_hash_warning) | |||
2533 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
2534 | ||||
2535 | if ((h->root.type == bfd_link_hash_defined | |||
2536 | || h->root.type == bfd_link_hash_defweak) | |||
2537 | && ((sec = h->root.u.def.section)->flags & SEC_MERGE0x1000000) | |||
2538 | && sec->sec_info_type == ELF_INFO_TYPE_MERGE2) | |||
2539 | { | |||
2540 | bfd *output_bfd = data; | |||
2541 | ||||
2542 | h->root.u.def.value = | |||
2543 | _bfd_merged_section_offset (output_bfd, | |||
2544 | &h->root.u.def.section, | |||
2545 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->sec_info, | |||
2546 | h->root.u.def.value); | |||
2547 | } | |||
2548 | ||||
2549 | return TRUE1; | |||
2550 | } | |||
2551 | ||||
2552 | /* Returns false if the symbol referred to by H should be considered | |||
2553 | to resolve local to the current module, and true if it should be | |||
2554 | considered to bind dynamically. */ | |||
2555 | ||||
2556 | bfd_boolean | |||
2557 | _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry *h, | |||
2558 | struct bfd_link_info *info, | |||
2559 | bfd_boolean ignore_protected) | |||
2560 | { | |||
2561 | bfd_boolean binding_stays_local_p; | |||
2562 | ||||
2563 | if (h == NULL((void*)0)) | |||
2564 | return FALSE0; | |||
2565 | ||||
2566 | while (h->root.type == bfd_link_hash_indirect | |||
2567 | || h->root.type == bfd_link_hash_warning) | |||
2568 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
2569 | ||||
2570 | /* If it was forced local, then clearly it's not dynamic. */ | |||
2571 | if (h->dynindx == -1) | |||
2572 | return FALSE0; | |||
2573 | if (h->forced_local) | |||
2574 | return FALSE0; | |||
2575 | ||||
2576 | /* Identify the cases where name binding rules say that a | |||
2577 | visible symbol resolves locally. */ | |||
2578 | binding_stays_local_p = info->executable || info->symbolic; | |||
2579 | ||||
2580 | switch (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3)) | |||
2581 | { | |||
2582 | case STV_INTERNAL1: | |||
2583 | case STV_HIDDEN2: | |||
2584 | return FALSE0; | |||
2585 | ||||
2586 | case STV_PROTECTED3: | |||
2587 | /* Proper resolution for function pointer equality may require | |||
2588 | that these symbols perhaps be resolved dynamically, even though | |||
2589 | we should be resolving them to the current module. */ | |||
2590 | if (!ignore_protected || h->type != STT_FUNC2) | |||
2591 | binding_stays_local_p = TRUE1; | |||
2592 | break; | |||
2593 | ||||
2594 | default: | |||
2595 | break; | |||
2596 | } | |||
2597 | ||||
2598 | /* If it isn't defined locally, then clearly it's dynamic. */ | |||
2599 | if (!h->def_regular) | |||
2600 | return TRUE1; | |||
2601 | ||||
2602 | /* Otherwise, the symbol is dynamic if binding rules don't tell | |||
2603 | us that it remains local. */ | |||
2604 | return !binding_stays_local_p; | |||
2605 | } | |||
2606 | ||||
2607 | /* Return true if the symbol referred to by H should be considered | |||
2608 | to resolve local to the current module, and false otherwise. Differs | |||
2609 | from (the inverse of) _bfd_elf_dynamic_symbol_p in the treatment of | |||
2610 | undefined symbols and weak symbols. */ | |||
2611 | ||||
2612 | bfd_boolean | |||
2613 | _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h, | |||
2614 | struct bfd_link_info *info, | |||
2615 | bfd_boolean local_protected) | |||
2616 | { | |||
2617 | /* If it's a local sym, of course we resolve locally. */ | |||
2618 | if (h == NULL((void*)0)) | |||
2619 | return TRUE1; | |||
2620 | ||||
2621 | /* Common symbols that become definitions don't get the DEF_REGULAR | |||
2622 | flag set, so test it first, and don't bail out. */ | |||
2623 | if (ELF_COMMON_DEF_P (h)(!(h)->def_regular && !(h)->def_dynamic && (h)->root.type == bfd_link_hash_defined)) | |||
2624 | /* Do nothing. */; | |||
2625 | /* If we don't have a definition in a regular file, then we can't | |||
2626 | resolve locally. The sym is either undefined or dynamic. */ | |||
2627 | else if (!h->def_regular) | |||
2628 | return FALSE0; | |||
2629 | ||||
2630 | /* Forced local symbols resolve locally. */ | |||
2631 | if (h->forced_local) | |||
2632 | return TRUE1; | |||
2633 | ||||
2634 | /* As do non-dynamic symbols. */ | |||
2635 | if (h->dynindx == -1) | |||
2636 | return TRUE1; | |||
2637 | ||||
2638 | /* At this point, we know the symbol is defined and dynamic. In an | |||
2639 | executable it must resolve locally, likewise when building symbolic | |||
2640 | shared libraries. */ | |||
2641 | if (info->executable || info->symbolic) | |||
2642 | return TRUE1; | |||
2643 | ||||
2644 | /* Now deal with defined dynamic symbols in shared libraries. Ones | |||
2645 | with default visibility might not resolve locally. */ | |||
2646 | if (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_DEFAULT0) | |||
2647 | return FALSE0; | |||
2648 | ||||
2649 | /* However, STV_HIDDEN or STV_INTERNAL ones must be local. */ | |||
2650 | if (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_PROTECTED3) | |||
2651 | return TRUE1; | |||
2652 | ||||
2653 | /* STV_PROTECTED non-function symbols are local. */ | |||
2654 | if (h->type != STT_FUNC2) | |||
2655 | return TRUE1; | |||
2656 | ||||
2657 | /* Function pointer equality tests may require that STV_PROTECTED | |||
2658 | symbols be treated as dynamic symbols, even when we know that the | |||
2659 | dynamic linker will resolve them locally. */ | |||
2660 | return local_protected; | |||
2661 | } | |||
2662 | ||||
2663 | /* Caches some TLS segment info, and ensures that the TLS segment vma is | |||
2664 | aligned. Returns the first TLS output section. */ | |||
2665 | ||||
2666 | struct bfd_section * | |||
2667 | _bfd_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) | |||
2668 | { | |||
2669 | struct bfd_section *sec, *tls; | |||
2670 | unsigned int align = 0; | |||
2671 | ||||
2672 | for (sec = obfd->sections; sec != NULL((void*)0); sec = sec->next) | |||
2673 | if ((sec->flags & SEC_THREAD_LOCAL0x400) != 0) | |||
2674 | break; | |||
2675 | tls = sec; | |||
2676 | ||||
2677 | for (; sec != NULL((void*)0) && (sec->flags & SEC_THREAD_LOCAL0x400) != 0; sec = sec->next) | |||
2678 | if (sec->alignment_power > align) | |||
2679 | align = sec->alignment_power; | |||
2680 | ||||
2681 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->tls_sec = tls; | |||
2682 | ||||
2683 | /* Ensure the alignment of the first section is the largest alignment, | |||
2684 | so that the tls segment starts aligned. */ | |||
2685 | if (tls != NULL((void*)0)) | |||
2686 | tls->alignment_power = align; | |||
2687 | ||||
2688 | return tls; | |||
2689 | } | |||
2690 | ||||
2691 | /* Return TRUE iff this is a non-common, definition of a non-function symbol. */ | |||
2692 | static bfd_boolean | |||
2693 | is_global_data_symbol_definition (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
2694 | Elf_Internal_Sym *sym) | |||
2695 | { | |||
2696 | const struct elf_backend_data *bed; | |||
2697 | ||||
2698 | /* Local symbols do not count, but target specific ones might. */ | |||
2699 | if (ELF_ST_BIND (sym->st_info)(((unsigned int)(sym->st_info)) >> 4) != STB_GLOBAL1 | |||
2700 | && ELF_ST_BIND (sym->st_info)(((unsigned int)(sym->st_info)) >> 4) < STB_LOOS10) | |||
2701 | return FALSE0; | |||
2702 | ||||
2703 | /* Function symbols do not count. */ | |||
2704 | if (ELF_ST_TYPE (sym->st_info)((sym->st_info) & 0xF) == STT_FUNC2) | |||
2705 | return FALSE0; | |||
2706 | ||||
2707 | /* If the section is undefined, then so is the symbol. */ | |||
2708 | if (sym->st_shndx == SHN_UNDEF0) | |||
2709 | return FALSE0; | |||
2710 | ||||
2711 | /* If the symbol is defined in the common section, then | |||
2712 | it is a common definition and so does not count. */ | |||
2713 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
2714 | if (bed->common_definition (sym)) | |||
2715 | return FALSE0; | |||
2716 | ||||
2717 | /* If the symbol is in a target specific section then we | |||
2718 | must rely upon the backend to tell us what it is. */ | |||
2719 | if (sym->st_shndx >= SHN_LORESERVE0xFF00 && sym->st_shndx < SHN_ABS0xFFF1) | |||
2720 | /* FIXME - this function is not coded yet: | |||
2721 | ||||
2722 | return _bfd_is_global_symbol_definition (abfd, sym); | |||
2723 | ||||
2724 | Instead for now assume that the definition is not global, | |||
2725 | Even if this is wrong, at least the linker will behave | |||
2726 | in the same way that it used to do. */ | |||
2727 | return FALSE0; | |||
2728 | ||||
2729 | return TRUE1; | |||
2730 | } | |||
2731 | ||||
2732 | /* Search the symbol table of the archive element of the archive ABFD | |||
2733 | whose archive map contains a mention of SYMDEF, and determine if | |||
2734 | the symbol is defined in this element. */ | |||
2735 | static bfd_boolean | |||
2736 | elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef) | |||
2737 | { | |||
2738 | Elf_Internal_Shdr * hdr; | |||
2739 | bfd_size_type symcount; | |||
2740 | bfd_size_type extsymcount; | |||
2741 | bfd_size_type extsymoff; | |||
2742 | Elf_Internal_Sym *isymbuf; | |||
2743 | Elf_Internal_Sym *isym; | |||
2744 | Elf_Internal_Sym *isymend; | |||
2745 | bfd_boolean result; | |||
2746 | ||||
2747 | abfd = _bfd_get_elt_at_filepos (abfd, symdef->file_offset); | |||
2748 | if (abfd == NULL((void*)0)) | |||
2749 | return FALSE0; | |||
2750 | ||||
2751 | if (! bfd_check_format (abfd, bfd_object)) | |||
2752 | return FALSE0; | |||
2753 | ||||
2754 | /* If we have already included the element containing this symbol in the | |||
2755 | link then we do not need to include it again. Just claim that any symbol | |||
2756 | it contains is not a definition, so that our caller will not decide to | |||
2757 | (re)include this element. */ | |||
2758 | if (abfd->archive_pass) | |||
2759 | return FALSE0; | |||
2760 | ||||
2761 | /* Select the appropriate symbol table. */ | |||
2762 | if ((abfd->flags & DYNAMIC0x40) == 0 || elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == 0) | |||
2763 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
2764 | else | |||
2765 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynsymtab_hdr; | |||
2766 | ||||
2767 | symcount = hdr->sh_size / get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data )->s->sizeof_sym; | |||
2768 | ||||
2769 | /* The sh_info field of the symtab header tells us where the | |||
2770 | external symbols start. We don't care about the local symbols. */ | |||
2771 | if (elf_bad_symtab (abfd)(((abfd) -> tdata.elf_obj_data) -> bad_symtab)) | |||
2772 | { | |||
2773 | extsymcount = symcount; | |||
2774 | extsymoff = 0; | |||
2775 | } | |||
2776 | else | |||
2777 | { | |||
2778 | extsymcount = symcount - hdr->sh_info; | |||
2779 | extsymoff = hdr->sh_info; | |||
2780 | } | |||
2781 | ||||
2782 | if (extsymcount == 0) | |||
2783 | return FALSE0; | |||
2784 | ||||
2785 | /* Read in the symbol table. */ | |||
2786 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff, | |||
2787 | NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
2788 | if (isymbuf == NULL((void*)0)) | |||
2789 | return FALSE0; | |||
2790 | ||||
2791 | /* Scan the symbol table looking for SYMDEF. */ | |||
2792 | result = FALSE0; | |||
2793 | for (isym = isymbuf, isymend = isymbuf + extsymcount; isym < isymend; isym++) | |||
2794 | { | |||
2795 | const char *name; | |||
2796 | ||||
2797 | name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, | |||
2798 | isym->st_name); | |||
2799 | if (name == NULL((void*)0)) | |||
2800 | break; | |||
2801 | ||||
2802 | if (strcmp (name, symdef->name) == 0) | |||
2803 | { | |||
2804 | result = is_global_data_symbol_definition (abfd, isym); | |||
2805 | break; | |||
2806 | } | |||
2807 | } | |||
2808 | ||||
2809 | free (isymbuf); | |||
2810 | ||||
2811 | return result; | |||
2812 | } | |||
2813 | ||||
2814 | /* Add an entry to the .dynamic table. */ | |||
2815 | ||||
2816 | bfd_boolean | |||
2817 | _bfd_elf_add_dynamic_entry (struct bfd_link_info *info, | |||
2818 | bfd_vma tag, | |||
2819 | bfd_vma val) | |||
2820 | { | |||
2821 | struct elf_link_hash_table *hash_table; | |||
2822 | const struct elf_backend_data *bed; | |||
2823 | asection *s; | |||
2824 | bfd_size_type newsize; | |||
2825 | bfd_byte *newcontents; | |||
2826 | Elf_Internal_Dyn dyn; | |||
2827 | ||||
2828 | hash_table = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
2829 | if (! is_elf_hash_table (hash_table)(((struct bfd_link_hash_table *) (hash_table))->type == bfd_link_elf_hash_table )) | |||
2830 | return FALSE0; | |||
2831 | ||||
2832 | bed = get_elf_backend_data (hash_table->dynobj)((const struct elf_backend_data *) (hash_table->dynobj)-> xvec->backend_data); | |||
2833 | s = bfd_get_section_by_name (hash_table->dynobj, ".dynamic"); | |||
2834 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2834); } while (0); | |||
2835 | ||||
2836 | newsize = s->size + bed->s->sizeof_dyn; | |||
2837 | newcontents = bfd_realloc (s->contents, newsize); | |||
2838 | if (newcontents == NULL((void*)0)) | |||
2839 | return FALSE0; | |||
2840 | ||||
2841 | dyn.d_tag = tag; | |||
2842 | dyn.d_un.d_val = val; | |||
2843 | bed->s->swap_dyn_out (hash_table->dynobj, &dyn, newcontents + s->size); | |||
2844 | ||||
2845 | s->size = newsize; | |||
2846 | s->contents = newcontents; | |||
2847 | ||||
2848 | return TRUE1; | |||
2849 | } | |||
2850 | ||||
2851 | /* Add a DT_NEEDED entry for this dynamic object if DO_IT is true, | |||
2852 | otherwise just check whether one already exists. Returns -1 on error, | |||
2853 | 1 if a DT_NEEDED tag already exists, and 0 on success. */ | |||
2854 | ||||
2855 | static int | |||
2856 | elf_add_dt_needed_tag (bfd *abfd, | |||
2857 | struct bfd_link_info *info, | |||
2858 | const char *soname, | |||
2859 | bfd_boolean do_it) | |||
2860 | { | |||
2861 | struct elf_link_hash_table *hash_table; | |||
2862 | bfd_size_type oldsize; | |||
2863 | bfd_size_type strindex; | |||
2864 | ||||
2865 | if (!_bfd_elf_link_create_dynstrtab (abfd, info)) | |||
2866 | return -1; | |||
2867 | ||||
2868 | hash_table = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
2869 | oldsize = _bfd_elf_strtab_size (hash_table->dynstr); | |||
2870 | strindex = _bfd_elf_strtab_add (hash_table->dynstr, soname, FALSE0); | |||
2871 | if (strindex == (bfd_size_type) -1) | |||
2872 | return -1; | |||
2873 | ||||
2874 | if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr)) | |||
2875 | { | |||
2876 | asection *sdyn; | |||
2877 | const struct elf_backend_data *bed; | |||
2878 | bfd_byte *extdyn; | |||
2879 | ||||
2880 | bed = get_elf_backend_data (hash_table->dynobj)((const struct elf_backend_data *) (hash_table->dynobj)-> xvec->backend_data); | |||
2881 | sdyn = bfd_get_section_by_name (hash_table->dynobj, ".dynamic"); | |||
2882 | if (sdyn != NULL((void*)0)) | |||
2883 | for (extdyn = sdyn->contents; | |||
2884 | extdyn < sdyn->contents + sdyn->size; | |||
2885 | extdyn += bed->s->sizeof_dyn) | |||
2886 | { | |||
2887 | Elf_Internal_Dyn dyn; | |||
2888 | ||||
2889 | bed->s->swap_dyn_in (hash_table->dynobj, extdyn, &dyn); | |||
2890 | if (dyn.d_tag == DT_NEEDED1 | |||
2891 | && dyn.d_un.d_val == strindex) | |||
2892 | { | |||
2893 | _bfd_elf_strtab_delref (hash_table->dynstr, strindex); | |||
2894 | return 1; | |||
2895 | } | |||
2896 | } | |||
2897 | } | |||
2898 | ||||
2899 | if (do_it) | |||
2900 | { | |||
2901 | if (!_bfd_elf_link_create_dynamic_sections (hash_table->dynobj, info)) | |||
2902 | return -1; | |||
2903 | ||||
2904 | if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED1, strindex)) | |||
2905 | return -1; | |||
2906 | } | |||
2907 | else | |||
2908 | /* We were just checking for existence of the tag. */ | |||
2909 | _bfd_elf_strtab_delref (hash_table->dynstr, strindex); | |||
2910 | ||||
2911 | return 0; | |||
2912 | } | |||
2913 | ||||
2914 | /* Sort symbol by value and section. */ | |||
2915 | static int | |||
2916 | elf_sort_symbol (const void *arg1, const void *arg2) | |||
2917 | { | |||
2918 | const struct elf_link_hash_entry *h1; | |||
2919 | const struct elf_link_hash_entry *h2; | |||
2920 | bfd_signed_vma vdiff; | |||
2921 | ||||
2922 | h1 = *(const struct elf_link_hash_entry **) arg1; | |||
2923 | h2 = *(const struct elf_link_hash_entry **) arg2; | |||
2924 | vdiff = h1->root.u.def.value - h2->root.u.def.value; | |||
2925 | if (vdiff != 0) | |||
2926 | return vdiff > 0 ? 1 : -1; | |||
2927 | else | |||
2928 | { | |||
2929 | long sdiff = h1->root.u.def.section->id - h2->root.u.def.section->id; | |||
2930 | if (sdiff != 0) | |||
2931 | return sdiff > 0 ? 1 : -1; | |||
2932 | } | |||
2933 | return 0; | |||
2934 | } | |||
2935 | ||||
2936 | /* This function is used to adjust offsets into .dynstr for | |||
2937 | dynamic symbols. This is called via elf_link_hash_traverse. */ | |||
2938 | ||||
2939 | static bfd_boolean | |||
2940 | elf_adjust_dynstr_offsets (struct elf_link_hash_entry *h, void *data) | |||
2941 | { | |||
2942 | struct elf_strtab_hash *dynstr = data; | |||
2943 | ||||
2944 | if (h->root.type == bfd_link_hash_warning) | |||
2945 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
2946 | ||||
2947 | if (h->dynindx != -1) | |||
2948 | h->dynstr_index = _bfd_elf_strtab_offset (dynstr, h->dynstr_index); | |||
2949 | return TRUE1; | |||
2950 | } | |||
2951 | ||||
2952 | /* Assign string offsets in .dynstr, update all structures referencing | |||
2953 | them. */ | |||
2954 | ||||
2955 | static bfd_boolean | |||
2956 | elf_finalize_dynstr (bfd *output_bfd, struct bfd_link_info *info) | |||
2957 | { | |||
2958 | struct elf_link_hash_table *hash_table = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
2959 | struct elf_link_local_dynamic_entry *entry; | |||
2960 | struct elf_strtab_hash *dynstr = hash_table->dynstr; | |||
2961 | bfd *dynobj = hash_table->dynobj; | |||
2962 | asection *sdyn; | |||
2963 | bfd_size_type size; | |||
2964 | const struct elf_backend_data *bed; | |||
2965 | bfd_byte *extdyn; | |||
2966 | ||||
2967 | _bfd_elf_strtab_finalize (dynstr); | |||
2968 | size = _bfd_elf_strtab_size (dynstr); | |||
2969 | ||||
2970 | bed = get_elf_backend_data (dynobj)((const struct elf_backend_data *) (dynobj)->xvec->backend_data ); | |||
2971 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |||
2972 | BFD_ASSERT (sdyn != NULL)do { if (!(sdyn != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,2972); } while (0); | |||
2973 | ||||
2974 | /* Update all .dynamic entries referencing .dynstr strings. */ | |||
2975 | for (extdyn = sdyn->contents; | |||
2976 | extdyn < sdyn->contents + sdyn->size; | |||
2977 | extdyn += bed->s->sizeof_dyn) | |||
2978 | { | |||
2979 | Elf_Internal_Dyn dyn; | |||
2980 | ||||
2981 | bed->s->swap_dyn_in (dynobj, extdyn, &dyn); | |||
2982 | switch (dyn.d_tag) | |||
2983 | { | |||
2984 | case DT_STRSZ10: | |||
2985 | dyn.d_un.d_val = size; | |||
2986 | break; | |||
2987 | case DT_NEEDED1: | |||
2988 | case DT_SONAME14: | |||
2989 | case DT_RPATH15: | |||
2990 | case DT_RUNPATH29: | |||
2991 | case DT_FILTER0x7fffffff: | |||
2992 | case DT_AUXILIARY0x7ffffffd: | |||
2993 | dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val); | |||
2994 | break; | |||
2995 | default: | |||
2996 | continue; | |||
2997 | } | |||
2998 | bed->s->swap_dyn_out (dynobj, &dyn, extdyn); | |||
2999 | } | |||
3000 | ||||
3001 | /* Now update local dynamic symbols. */ | |||
3002 | for (entry = hash_table->dynlocal; entry ; entry = entry->next) | |||
3003 | entry->isym.st_name = _bfd_elf_strtab_offset (dynstr, | |||
3004 | entry->isym.st_name); | |||
3005 | ||||
3006 | /* And the rest of dynamic symbols. */ | |||
3007 | elf_link_hash_traverse (hash_table, elf_adjust_dynstr_offsets, dynstr)(bfd_link_hash_traverse (&(hash_table)->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_adjust_dynstr_offsets ), (dynstr))); | |||
3008 | ||||
3009 | /* Adjust version definitions. */ | |||
3010 | if (elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->cverdefs) | |||
3011 | { | |||
3012 | asection *s; | |||
3013 | bfd_byte *p; | |||
3014 | bfd_size_type i; | |||
3015 | Elf_Internal_Verdef def; | |||
3016 | Elf_Internal_Verdaux defaux; | |||
3017 | ||||
3018 | s = bfd_get_section_by_name (dynobj, ".gnu.version_d"); | |||
3019 | p = s->contents; | |||
3020 | do | |||
3021 | { | |||
3022 | _bfd_elf_swap_verdef_in (output_bfd, (Elf_External_Verdef *) p, | |||
3023 | &def); | |||
3024 | p += sizeof (Elf_External_Verdef); | |||
3025 | if (def.vd_aux != sizeof (Elf_External_Verdef)) | |||
3026 | continue; | |||
3027 | for (i = 0; i < def.vd_cnt; ++i) | |||
3028 | { | |||
3029 | _bfd_elf_swap_verdaux_in (output_bfd, | |||
3030 | (Elf_External_Verdaux *) p, &defaux); | |||
3031 | defaux.vda_name = _bfd_elf_strtab_offset (dynstr, | |||
3032 | defaux.vda_name); | |||
3033 | _bfd_elf_swap_verdaux_out (output_bfd, | |||
3034 | &defaux, (Elf_External_Verdaux *) p); | |||
3035 | p += sizeof (Elf_External_Verdaux); | |||
3036 | } | |||
3037 | } | |||
3038 | while (def.vd_next); | |||
3039 | } | |||
3040 | ||||
3041 | /* Adjust version references. */ | |||
3042 | if (elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->verref) | |||
3043 | { | |||
3044 | asection *s; | |||
3045 | bfd_byte *p; | |||
3046 | bfd_size_type i; | |||
3047 | Elf_Internal_Verneed need; | |||
3048 | Elf_Internal_Vernaux needaux; | |||
3049 | ||||
3050 | s = bfd_get_section_by_name (dynobj, ".gnu.version_r"); | |||
3051 | p = s->contents; | |||
3052 | do | |||
3053 | { | |||
3054 | _bfd_elf_swap_verneed_in (output_bfd, (Elf_External_Verneed *) p, | |||
3055 | &need); | |||
3056 | need.vn_file = _bfd_elf_strtab_offset (dynstr, need.vn_file); | |||
3057 | _bfd_elf_swap_verneed_out (output_bfd, &need, | |||
3058 | (Elf_External_Verneed *) p); | |||
3059 | p += sizeof (Elf_External_Verneed); | |||
3060 | for (i = 0; i < need.vn_cnt; ++i) | |||
3061 | { | |||
3062 | _bfd_elf_swap_vernaux_in (output_bfd, | |||
3063 | (Elf_External_Vernaux *) p, &needaux); | |||
3064 | needaux.vna_name = _bfd_elf_strtab_offset (dynstr, | |||
3065 | needaux.vna_name); | |||
3066 | _bfd_elf_swap_vernaux_out (output_bfd, | |||
3067 | &needaux, | |||
3068 | (Elf_External_Vernaux *) p); | |||
3069 | p += sizeof (Elf_External_Vernaux); | |||
3070 | } | |||
3071 | } | |||
3072 | while (need.vn_next); | |||
3073 | } | |||
3074 | ||||
3075 | return TRUE1; | |||
3076 | } | |||
3077 | ||||
3078 | /* Add symbols from an ELF object file to the linker hash table. */ | |||
3079 | ||||
3080 | static bfd_boolean | |||
3081 | elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) | |||
3082 | { | |||
3083 | Elf_Internal_Shdr *hdr; | |||
3084 | bfd_size_type symcount; | |||
3085 | bfd_size_type extsymcount; | |||
3086 | bfd_size_type extsymoff; | |||
3087 | struct elf_link_hash_entry **sym_hash; | |||
3088 | bfd_boolean dynamic; | |||
3089 | Elf_External_Versym *extversym = NULL((void*)0); | |||
3090 | Elf_External_Versym *ever; | |||
3091 | struct elf_link_hash_entry *weaks; | |||
3092 | struct elf_link_hash_entry **nondeflt_vers = NULL((void*)0); | |||
3093 | bfd_size_type nondeflt_vers_cnt = 0; | |||
3094 | Elf_Internal_Sym *isymbuf = NULL((void*)0); | |||
3095 | Elf_Internal_Sym *isym; | |||
3096 | Elf_Internal_Sym *isymend; | |||
3097 | const struct elf_backend_data *bed; | |||
3098 | bfd_boolean add_needed; | |||
3099 | struct elf_link_hash_table *htab; | |||
3100 | bfd_size_type amt; | |||
3101 | void *alloc_mark = NULL((void*)0); | |||
3102 | void *old_tab = NULL((void*)0); | |||
3103 | void *old_hash; | |||
3104 | void *old_ent; | |||
3105 | struct bfd_link_hash_entry *old_undefs = NULL((void*)0); | |||
3106 | struct bfd_link_hash_entry *old_undefs_tail = NULL((void*)0); | |||
3107 | long old_dynsymcount = 0; | |||
3108 | size_t tabsize = 0; | |||
3109 | size_t hashsize = 0; | |||
3110 | ||||
3111 | htab = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
3112 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
3113 | ||||
3114 | if ((abfd->flags & DYNAMIC0x40) == 0) | |||
3115 | dynamic = FALSE0; | |||
3116 | else | |||
3117 | { | |||
3118 | dynamic = TRUE1; | |||
3119 | ||||
3120 | /* You can't use -r against a dynamic object. Also, there's no | |||
3121 | hope of using a dynamic object which does not exactly match | |||
3122 | the format of the output file. */ | |||
3123 | if (info->relocatable | |||
3124 | || !is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table ) | |||
3125 | || htab->root.creator != abfd->xvec) | |||
3126 | { | |||
3127 | if (info->relocatable) | |||
3128 | bfd_set_error (bfd_error_invalid_operation); | |||
3129 | else | |||
3130 | bfd_set_error (bfd_error_wrong_format); | |||
3131 | goto error_return; | |||
3132 | } | |||
3133 | } | |||
3134 | ||||
3135 | /* As a GNU extension, any input sections which are named | |||
3136 | .gnu.warning.SYMBOL are treated as warning symbols for the given | |||
3137 | symbol. This differs from .gnu.warning sections, which generate | |||
3138 | warnings when they are included in an output file. */ | |||
3139 | if (info->executable) | |||
3140 | { | |||
3141 | asection *s; | |||
3142 | ||||
3143 | for (s = abfd->sections; s != NULL((void*)0); s = s->next) | |||
3144 | { | |||
3145 | const char *name; | |||
3146 | ||||
3147 | name = bfd_get_section_name (abfd, s)((s)->name + 0); | |||
3148 | if (strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0) | |||
3149 | { | |||
3150 | char *msg; | |||
3151 | bfd_size_type sz; | |||
3152 | ||||
3153 | name += sizeof ".gnu.warning." - 1; | |||
3154 | ||||
3155 | /* If this is a shared object, then look up the symbol | |||
3156 | in the hash table. If it is there, and it is already | |||
3157 | been defined, then we will not be using the entry | |||
3158 | from this shared object, so we don't need to warn. | |||
3159 | FIXME: If we see the definition in a regular object | |||
3160 | later on, we will warn, but we shouldn't. The only | |||
3161 | fix is to keep track of what warnings we are supposed | |||
3162 | to emit, and then handle them all at the end of the | |||
3163 | link. */ | |||
3164 | if (dynamic) | |||
3165 | { | |||
3166 | struct elf_link_hash_entry *h; | |||
3167 | ||||
3168 | h = elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(htab )->root, (name), (0), (0), (1))); | |||
3169 | ||||
3170 | /* FIXME: What about bfd_link_hash_common? */ | |||
3171 | if (h != NULL((void*)0) | |||
3172 | && (h->root.type == bfd_link_hash_defined | |||
3173 | || h->root.type == bfd_link_hash_defweak)) | |||
3174 | { | |||
3175 | /* We don't want to issue this warning. Clobber | |||
3176 | the section size so that the warning does not | |||
3177 | get copied into the output file. */ | |||
3178 | s->size = 0; | |||
3179 | continue; | |||
3180 | } | |||
3181 | } | |||
3182 | ||||
3183 | sz = s->size; | |||
3184 | msg = bfd_alloc (abfd, sz + 1); | |||
3185 | if (msg == NULL((void*)0)) | |||
3186 | goto error_return; | |||
3187 | ||||
3188 | if (! bfd_get_section_contents (abfd, s, msg, 0, sz)) | |||
3189 | goto error_return; | |||
3190 | ||||
3191 | msg[sz] = '\0'; | |||
3192 | ||||
3193 | if (! (_bfd_generic_link_add_one_symbol | |||
3194 | (info, abfd, name, BSF_WARNING0x1000, s, 0, msg, | |||
3195 | FALSE0, bed->collect, NULL((void*)0)))) | |||
3196 | goto error_return; | |||
3197 | ||||
3198 | if (! info->relocatable) | |||
3199 | { | |||
3200 | /* Clobber the section size so that the warning does | |||
3201 | not get copied into the output file. */ | |||
3202 | s->size = 0; | |||
3203 | ||||
3204 | /* Also set SEC_EXCLUDE, so that symbols defined in | |||
3205 | the warning section don't get copied to the output. */ | |||
3206 | s->flags |= SEC_EXCLUDE0x8000; | |||
3207 | } | |||
3208 | } | |||
3209 | } | |||
3210 | } | |||
3211 | ||||
3212 | add_needed = TRUE1; | |||
3213 | if (! dynamic) | |||
3214 | { | |||
3215 | /* If we are creating a shared library, create all the dynamic | |||
3216 | sections immediately. We need to attach them to something, | |||
3217 | so we attach them to this BFD, provided it is the right | |||
3218 | format. FIXME: If there are no input BFD's of the same | |||
3219 | format as the output, we can't make a shared library. */ | |||
3220 | if (info->shared | |||
3221 | && is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table ) | |||
3222 | && htab->root.creator == abfd->xvec | |||
3223 | && !htab->dynamic_sections_created) | |||
3224 | { | |||
3225 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) | |||
3226 | goto error_return; | |||
3227 | } | |||
3228 | } | |||
3229 | else if (!is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table )) | |||
3230 | goto error_return; | |||
3231 | else | |||
3232 | { | |||
3233 | asection *s; | |||
3234 | const char *soname = NULL((void*)0); | |||
3235 | struct bfd_link_needed_list *rpath = NULL((void*)0), *runpath = NULL((void*)0); | |||
3236 | int ret; | |||
3237 | ||||
3238 | /* ld --just-symbols and dynamic objects don't mix very well. | |||
3239 | ld shouldn't allow it. */ | |||
3240 | if ((s = abfd->sections) != NULL((void*)0) | |||
3241 | && s->sec_info_type == ELF_INFO_TYPE_JUST_SYMS4) | |||
3242 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" , 3242, __PRETTY_FUNCTION__); | |||
3243 | ||||
3244 | /* If this dynamic lib was specified on the command line with | |||
3245 | --as-needed in effect, then we don't want to add a DT_NEEDED | |||
3246 | tag unless the lib is actually used. Similary for libs brought | |||
3247 | in by another lib's DT_NEEDED. When --no-add-needed is used | |||
3248 | on a dynamic lib, we don't want to add a DT_NEEDED entry for | |||
3249 | any dynamic library in DT_NEEDED tags in the dynamic lib at | |||
3250 | all. */ | |||
3251 | add_needed = (elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class) | |||
3252 | & (DYN_AS_NEEDED | DYN_DT_NEEDED | |||
3253 | | DYN_NO_NEEDED)) == 0; | |||
3254 | ||||
3255 | s = bfd_get_section_by_name (abfd, ".dynamic"); | |||
3256 | if (s != NULL((void*)0)) | |||
3257 | { | |||
3258 | bfd_byte *dynbuf; | |||
3259 | bfd_byte *extdyn; | |||
3260 | int elfsec; | |||
3261 | unsigned long shlink; | |||
3262 | ||||
3263 | if (!bfd_malloc_and_get_section (abfd, s, &dynbuf)) | |||
3264 | goto error_free_dyn; | |||
3265 | ||||
3266 | elfsec = _bfd_elf_section_from_bfd_section (abfd, s); | |||
3267 | if (elfsec == -1) | |||
3268 | goto error_free_dyn; | |||
3269 | shlink = elf_elfsections (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_sect_ptr)[elfsec]->sh_link; | |||
3270 | ||||
3271 | for (extdyn = dynbuf; | |||
3272 | extdyn < dynbuf + s->size; | |||
3273 | extdyn += bed->s->sizeof_dyn) | |||
3274 | { | |||
3275 | Elf_Internal_Dyn dyn; | |||
3276 | ||||
3277 | bed->s->swap_dyn_in (abfd, extdyn, &dyn); | |||
3278 | if (dyn.d_tag == DT_SONAME14) | |||
3279 | { | |||
3280 | unsigned int tagv = dyn.d_un.d_val; | |||
3281 | soname = bfd_elf_string_from_elf_section (abfd, shlink, tagv); | |||
3282 | if (soname == NULL((void*)0)) | |||
3283 | goto error_free_dyn; | |||
3284 | } | |||
3285 | if (dyn.d_tag == DT_NEEDED1) | |||
3286 | { | |||
3287 | struct bfd_link_needed_list *n, **pn; | |||
3288 | char *fnm, *anm; | |||
3289 | unsigned int tagv = dyn.d_un.d_val; | |||
3290 | ||||
3291 | amt = sizeof (struct bfd_link_needed_list); | |||
3292 | n = bfd_alloc (abfd, amt); | |||
3293 | fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); | |||
3294 | if (n == NULL((void*)0) || fnm == NULL((void*)0)) | |||
3295 | goto error_free_dyn; | |||
3296 | amt = strlen (fnm) + 1; | |||
3297 | anm = bfd_alloc (abfd, amt); | |||
3298 | if (anm == NULL((void*)0)) | |||
3299 | goto error_free_dyn; | |||
3300 | memcpy (anm, fnm, amt); | |||
3301 | n->name = anm; | |||
3302 | n->by = abfd; | |||
3303 | n->next = NULL((void*)0); | |||
3304 | for (pn = &htab->needed; *pn != NULL((void*)0); pn = &(*pn)->next) | |||
3305 | ; | |||
3306 | *pn = n; | |||
3307 | } | |||
3308 | if (dyn.d_tag == DT_RUNPATH29) | |||
3309 | { | |||
3310 | struct bfd_link_needed_list *n, **pn; | |||
3311 | char *fnm, *anm; | |||
3312 | unsigned int tagv = dyn.d_un.d_val; | |||
3313 | ||||
3314 | amt = sizeof (struct bfd_link_needed_list); | |||
3315 | n = bfd_alloc (abfd, amt); | |||
3316 | fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); | |||
3317 | if (n == NULL((void*)0) || fnm == NULL((void*)0)) | |||
3318 | goto error_free_dyn; | |||
3319 | amt = strlen (fnm) + 1; | |||
3320 | anm = bfd_alloc (abfd, amt); | |||
3321 | if (anm == NULL((void*)0)) | |||
3322 | goto error_free_dyn; | |||
3323 | memcpy (anm, fnm, amt); | |||
3324 | n->name = anm; | |||
3325 | n->by = abfd; | |||
3326 | n->next = NULL((void*)0); | |||
3327 | for (pn = & runpath; | |||
3328 | *pn != NULL((void*)0); | |||
3329 | pn = &(*pn)->next) | |||
3330 | ; | |||
3331 | *pn = n; | |||
3332 | } | |||
3333 | /* Ignore DT_RPATH if we have seen DT_RUNPATH. */ | |||
3334 | if (!runpath && dyn.d_tag == DT_RPATH15) | |||
3335 | { | |||
3336 | struct bfd_link_needed_list *n, **pn; | |||
3337 | char *fnm, *anm; | |||
3338 | unsigned int tagv = dyn.d_un.d_val; | |||
3339 | ||||
3340 | amt = sizeof (struct bfd_link_needed_list); | |||
3341 | n = bfd_alloc (abfd, amt); | |||
3342 | fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); | |||
3343 | if (n == NULL((void*)0) || fnm == NULL((void*)0)) | |||
3344 | goto error_free_dyn; | |||
3345 | amt = strlen (fnm) + 1; | |||
3346 | anm = bfd_alloc (abfd, amt); | |||
3347 | if (anm == NULL((void*)0)) | |||
3348 | { | |||
3349 | error_free_dyn: | |||
3350 | free (dynbuf); | |||
3351 | goto error_return; | |||
3352 | } | |||
3353 | memcpy (anm, fnm, amt); | |||
3354 | n->name = anm; | |||
3355 | n->by = abfd; | |||
3356 | n->next = NULL((void*)0); | |||
3357 | for (pn = & rpath; | |||
3358 | *pn != NULL((void*)0); | |||
3359 | pn = &(*pn)->next) | |||
3360 | ; | |||
3361 | *pn = n; | |||
3362 | } | |||
3363 | } | |||
3364 | ||||
3365 | free (dynbuf); | |||
3366 | } | |||
3367 | ||||
3368 | /* DT_RUNPATH overrides DT_RPATH. Do _NOT_ bfd_release, as that | |||
3369 | frees all more recently bfd_alloc'd blocks as well. */ | |||
3370 | if (runpath) | |||
3371 | rpath = runpath; | |||
3372 | ||||
3373 | if (rpath) | |||
3374 | { | |||
3375 | struct bfd_link_needed_list **pn; | |||
3376 | for (pn = &htab->runpath; *pn != NULL((void*)0); pn = &(*pn)->next) | |||
3377 | ; | |||
3378 | *pn = rpath; | |||
3379 | } | |||
3380 | ||||
3381 | /* We do not want to include any of the sections in a dynamic | |||
3382 | object in the output file. We hack by simply clobbering the | |||
3383 | list of sections in the BFD. This could be handled more | |||
3384 | cleanly by, say, a new section flag; the existing | |||
3385 | SEC_NEVER_LOAD flag is not the one we want, because that one | |||
3386 | still implies that the section takes up space in the output | |||
3387 | file. */ | |||
3388 | bfd_section_list_clear (abfd); | |||
3389 | ||||
3390 | /* Find the name to use in a DT_NEEDED entry that refers to this | |||
3391 | object. If the object has a DT_SONAME entry, we use it. | |||
3392 | Otherwise, if the generic linker stuck something in | |||
3393 | elf_dt_name, we use that. Otherwise, we just use the file | |||
3394 | name. */ | |||
3395 | if (soname == NULL((void*)0) || *soname == '\0') | |||
3396 | { | |||
3397 | soname = elf_dt_name (abfd)(((abfd) -> tdata.elf_obj_data) -> dt_name); | |||
3398 | if (soname == NULL((void*)0) || *soname == '\0') | |||
3399 | soname = bfd_get_filename (abfd)((char *) (abfd)->filename); | |||
3400 | } | |||
3401 | ||||
3402 | /* Save the SONAME because sometimes the linker emulation code | |||
3403 | will need to know it. */ | |||
3404 | elf_dt_name (abfd)(((abfd) -> tdata.elf_obj_data) -> dt_name) = soname; | |||
3405 | ||||
3406 | ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed); | |||
3407 | if (ret < 0) | |||
3408 | goto error_return; | |||
3409 | ||||
3410 | /* If we have already included this dynamic object in the | |||
3411 | link, just ignore it. There is no reason to include a | |||
3412 | particular dynamic object more than once. */ | |||
3413 | if (ret > 0) | |||
3414 | return TRUE1; | |||
3415 | } | |||
3416 | ||||
3417 | /* If this is a dynamic object, we always link against the .dynsym | |||
3418 | symbol table, not the .symtab symbol table. The dynamic linker | |||
3419 | will only see the .dynsym symbol table, so there is no reason to | |||
3420 | look at .symtab for a dynamic object. */ | |||
3421 | ||||
3422 | if (! dynamic || elf_dynsymtab (abfd)(((abfd) -> tdata.elf_obj_data) -> dynsymtab_section) == 0) | |||
3423 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
3424 | else | |||
3425 | hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynsymtab_hdr; | |||
3426 | ||||
3427 | symcount = hdr->sh_size / bed->s->sizeof_sym; | |||
3428 | ||||
3429 | /* The sh_info field of the symtab header tells us where the | |||
3430 | external symbols start. We don't care about the local symbols at | |||
3431 | this point. */ | |||
3432 | if (elf_bad_symtab (abfd)(((abfd) -> tdata.elf_obj_data) -> bad_symtab)) | |||
3433 | { | |||
3434 | extsymcount = symcount; | |||
3435 | extsymoff = 0; | |||
3436 | } | |||
3437 | else | |||
3438 | { | |||
3439 | extsymcount = symcount - hdr->sh_info; | |||
3440 | extsymoff = hdr->sh_info; | |||
3441 | } | |||
3442 | ||||
3443 | sym_hash = NULL((void*)0); | |||
3444 | if (extsymcount != 0) | |||
3445 | { | |||
3446 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff, | |||
3447 | NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
3448 | if (isymbuf == NULL((void*)0)) | |||
3449 | goto error_return; | |||
3450 | ||||
3451 | /* We store a pointer to the hash table entry for each external | |||
3452 | symbol. */ | |||
3453 | amt = extsymcount * sizeof (struct elf_link_hash_entry *); | |||
3454 | sym_hash = bfd_alloc (abfd, amt); | |||
3455 | if (sym_hash == NULL((void*)0)) | |||
3456 | goto error_free_sym; | |||
3457 | elf_sym_hashes (abfd)(((abfd) -> tdata.elf_obj_data) -> sym_hashes) = sym_hash; | |||
3458 | } | |||
3459 | ||||
3460 | if (dynamic) | |||
3461 | { | |||
3462 | /* Read in any version definitions. */ | |||
3463 | if (!_bfd_elf_slurp_version_tables (abfd, | |||
3464 | info->default_imported_symver)) | |||
3465 | goto error_free_sym; | |||
3466 | ||||
3467 | /* Read in the symbol versions, but don't bother to convert them | |||
3468 | to internal format. */ | |||
3469 | if (elf_dynversym (abfd)(((abfd) -> tdata.elf_obj_data) -> dynversym_section) != 0) | |||
3470 | { | |||
3471 | Elf_Internal_Shdr *versymhdr; | |||
3472 | ||||
3473 | versymhdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->dynversym_hdr; | |||
3474 | extversym = bfd_malloc (versymhdr->sh_size); | |||
3475 | if (extversym == NULL((void*)0)) | |||
3476 | goto error_free_sym; | |||
3477 | amt = versymhdr->sh_size; | |||
3478 | if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET0) != 0 | |||
3479 | || bfd_bread (extversym, amt, abfd) != amt) | |||
3480 | goto error_free_vers; | |||
3481 | } | |||
3482 | } | |||
3483 | ||||
3484 | /* If we are loading an as-needed shared lib, save the symbol table | |||
3485 | state before we start adding symbols. If the lib turns out | |||
3486 | to be unneeded, restore the state. */ | |||
3487 | if ((elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class) & DYN_AS_NEEDED) != 0) | |||
3488 | { | |||
3489 | unsigned int i; | |||
3490 | size_t entsize; | |||
3491 | ||||
3492 | for (entsize = 0, i = 0; i < htab->root.table.size; i++) | |||
3493 | { | |||
3494 | struct bfd_hash_entry *p; | |||
3495 | struct elf_link_hash_entry *h; | |||
3496 | ||||
3497 | for (p = htab->root.table.table[i]; p != NULL((void*)0); p = p->next) | |||
3498 | { | |||
3499 | h = (struct elf_link_hash_entry *) p; | |||
3500 | entsize += htab->root.table.entsize; | |||
3501 | if (h->root.type == bfd_link_hash_warning) | |||
3502 | entsize += htab->root.table.entsize; | |||
3503 | } | |||
3504 | } | |||
3505 | ||||
3506 | tabsize = htab->root.table.size * sizeof (struct bfd_hash_entry *); | |||
3507 | hashsize = extsymcount * sizeof (struct elf_link_hash_entry *); | |||
3508 | old_tab = bfd_malloc (tabsize + entsize + hashsize); | |||
3509 | if (old_tab == NULL((void*)0)) | |||
3510 | goto error_free_vers; | |||
3511 | ||||
3512 | /* Remember the current objalloc pointer, so that all mem for | |||
3513 | symbols added can later be reclaimed. */ | |||
3514 | alloc_mark = bfd_hash_allocate (&htab->root.table, 1); | |||
3515 | if (alloc_mark == NULL((void*)0)) | |||
3516 | goto error_free_vers; | |||
3517 | ||||
3518 | /* Clone the symbol table and sym hashes. Remember some | |||
3519 | pointers into the symbol table, and dynamic symbol count. */ | |||
3520 | old_hash = (char *) old_tab + tabsize; | |||
3521 | old_ent = (char *) old_hash + hashsize; | |||
3522 | memcpy (old_tab, htab->root.table.table, tabsize); | |||
3523 | memcpy (old_hash, sym_hash, hashsize); | |||
3524 | old_undefs = htab->root.undefs; | |||
3525 | old_undefs_tail = htab->root.undefs_tail; | |||
3526 | old_dynsymcount = htab->dynsymcount; | |||
3527 | ||||
3528 | for (i = 0; i < htab->root.table.size; i++) | |||
3529 | { | |||
3530 | struct bfd_hash_entry *p; | |||
3531 | struct elf_link_hash_entry *h; | |||
3532 | ||||
3533 | for (p = htab->root.table.table[i]; p != NULL((void*)0); p = p->next) | |||
3534 | { | |||
3535 | memcpy (old_ent, p, htab->root.table.entsize); | |||
3536 | old_ent = (char *) old_ent + htab->root.table.entsize; | |||
3537 | h = (struct elf_link_hash_entry *) p; | |||
3538 | if (h->root.type == bfd_link_hash_warning) | |||
3539 | { | |||
3540 | memcpy (old_ent, h->root.u.i.link, htab->root.table.entsize); | |||
3541 | old_ent = (char *) old_ent + htab->root.table.entsize; | |||
3542 | } | |||
3543 | } | |||
3544 | } | |||
3545 | } | |||
3546 | ||||
3547 | weaks = NULL((void*)0); | |||
3548 | ever = extversym != NULL((void*)0) ? extversym + extsymoff : NULL((void*)0); | |||
3549 | for (isym = isymbuf, isymend = isymbuf + extsymcount; | |||
3550 | isym < isymend; | |||
3551 | isym++, sym_hash++, ever = (ever != NULL((void*)0) ? ever + 1 : NULL((void*)0))) | |||
3552 | { | |||
3553 | int bind; | |||
3554 | bfd_vma value; | |||
3555 | asection *sec, *new_sec; | |||
3556 | flagword flags; | |||
3557 | const char *name; | |||
3558 | struct elf_link_hash_entry *h; | |||
3559 | bfd_boolean definition; | |||
3560 | bfd_boolean size_change_ok; | |||
3561 | bfd_boolean type_change_ok; | |||
3562 | bfd_boolean new_weakdef; | |||
3563 | bfd_boolean override; | |||
3564 | bfd_boolean common; | |||
3565 | unsigned int old_alignment; | |||
3566 | bfd *old_bfd; | |||
3567 | ||||
3568 | override = FALSE0; | |||
3569 | ||||
3570 | flags = BSF_NO_FLAGS0x00; | |||
3571 | sec = NULL((void*)0); | |||
3572 | value = isym->st_value; | |||
3573 | *sym_hash = NULL((void*)0); | |||
3574 | common = bed->common_definition (isym); | |||
3575 | ||||
3576 | bind = ELF_ST_BIND (isym->st_info)(((unsigned int)(isym->st_info)) >> 4); | |||
3577 | if (bind == STB_LOCAL0) | |||
3578 | { | |||
3579 | /* This should be impossible, since ELF requires that all | |||
3580 | global symbols follow all local symbols, and that sh_info | |||
3581 | point to the first global symbol. Unfortunately, Irix 5 | |||
3582 | screws this up. */ | |||
3583 | continue; | |||
3584 | } | |||
3585 | else if (bind == STB_GLOBAL1) | |||
3586 | { | |||
3587 | if (isym->st_shndx != SHN_UNDEF0 && !common) | |||
3588 | flags = BSF_GLOBAL0x02; | |||
3589 | } | |||
3590 | else if (bind == STB_WEAK2) | |||
3591 | flags = BSF_WEAK0x80; | |||
3592 | else | |||
3593 | { | |||
3594 | /* Leave it up to the processor backend. */ | |||
3595 | } | |||
3596 | ||||
3597 | if (isym->st_shndx == SHN_UNDEF0) | |||
3598 | sec = bfd_und_section_ptr((asection *) &bfd_und_section); | |||
3599 | else if (isym->st_shndx < SHN_LORESERVE0xFF00 | |||
3600 | || isym->st_shndx > SHN_HIRESERVE0xFFFF) | |||
3601 | { | |||
3602 | sec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |||
3603 | if (sec == NULL((void*)0)) | |||
3604 | sec = bfd_abs_section_ptr((asection *) &bfd_abs_section); | |||
3605 | else if (sec->kept_section) | |||
3606 | { | |||
3607 | /* Symbols from discarded section are undefined. We keep | |||
3608 | its visibility. */ | |||
3609 | sec = bfd_und_section_ptr((asection *) &bfd_und_section); | |||
3610 | isym->st_shndx = SHN_UNDEF0; | |||
3611 | } | |||
3612 | else if ((abfd->flags & (EXEC_P0x02 | DYNAMIC0x40)) != 0) | |||
3613 | value -= sec->vma; | |||
3614 | } | |||
3615 | else if (isym->st_shndx == SHN_ABS0xFFF1) | |||
3616 | sec = bfd_abs_section_ptr((asection *) &bfd_abs_section); | |||
3617 | else if (isym->st_shndx == SHN_COMMON0xFFF2) | |||
3618 | { | |||
3619 | sec = bfd_com_section_ptr((asection *) &bfd_com_section); | |||
3620 | /* What ELF calls the size we call the value. What ELF | |||
3621 | calls the value we call the alignment. */ | |||
3622 | value = isym->st_size; | |||
3623 | } | |||
3624 | else | |||
3625 | { | |||
3626 | /* Leave it up to the processor backend. */ | |||
3627 | } | |||
3628 | ||||
3629 | name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, | |||
3630 | isym->st_name); | |||
3631 | if (name == NULL((void*)0)) | |||
3632 | goto error_free_vers; | |||
3633 | ||||
3634 | if (isym->st_shndx == SHN_COMMON0xFFF2 | |||
3635 | && ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF) == STT_TLS6) | |||
3636 | { | |||
3637 | asection *tcomm = bfd_get_section_by_name (abfd, ".tcommon"); | |||
3638 | ||||
3639 | if (tcomm == NULL((void*)0)) | |||
3640 | { | |||
3641 | tcomm = bfd_make_section_with_flags (abfd, ".tcommon", | |||
3642 | (SEC_ALLOC0x001 | |||
3643 | | SEC_IS_COMMON0x1000 | |||
3644 | | SEC_LINKER_CREATED0x200000 | |||
3645 | | SEC_THREAD_LOCAL0x400)); | |||
3646 | if (tcomm == NULL((void*)0)) | |||
3647 | goto error_free_vers; | |||
3648 | } | |||
3649 | sec = tcomm; | |||
3650 | } | |||
3651 | else if (bed->elf_add_symbol_hook) | |||
3652 | { | |||
3653 | if (! (*bed->elf_add_symbol_hook) (abfd, info, isym, &name, &flags, | |||
3654 | &sec, &value)) | |||
3655 | goto error_free_vers; | |||
3656 | ||||
3657 | /* The hook function sets the name to NULL if this symbol | |||
3658 | should be skipped for some reason. */ | |||
3659 | if (name == NULL((void*)0)) | |||
3660 | continue; | |||
3661 | } | |||
3662 | ||||
3663 | /* Sanity check that all possibilities were handled. */ | |||
3664 | if (sec == NULL((void*)0)) | |||
3665 | { | |||
3666 | bfd_set_error (bfd_error_bad_value); | |||
3667 | goto error_free_vers; | |||
3668 | } | |||
3669 | ||||
3670 | if (bfd_is_und_section (sec)((sec) == ((asection *) &bfd_und_section)) | |||
3671 | || bfd_is_com_section (sec)(((sec)->flags & 0x1000) != 0)) | |||
3672 | definition = FALSE0; | |||
3673 | else | |||
3674 | definition = TRUE1; | |||
3675 | ||||
3676 | size_change_ok = FALSE0; | |||
3677 | type_change_ok = bed->type_change_ok; | |||
3678 | old_alignment = 0; | |||
3679 | old_bfd = NULL((void*)0); | |||
3680 | new_sec = sec; | |||
3681 | ||||
3682 | if (is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table )) | |||
3683 | { | |||
3684 | Elf_Internal_Versym iver; | |||
3685 | unsigned int vernum = 0; | |||
3686 | bfd_boolean skip; | |||
3687 | ||||
3688 | if (ever == NULL((void*)0)) | |||
3689 | { | |||
3690 | if (info->default_imported_symver) | |||
3691 | /* Use the default symbol version created earlier. */ | |||
3692 | iver.vs_vers = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs; | |||
3693 | else | |||
3694 | iver.vs_vers = 0; | |||
3695 | } | |||
3696 | else | |||
3697 | _bfd_elf_swap_versym_in (abfd, ever, &iver); | |||
3698 | ||||
3699 | vernum = iver.vs_vers & VERSYM_VERSION0x7fff; | |||
3700 | ||||
3701 | /* If this is a hidden symbol, or if it is not version | |||
3702 | 1, we append the version name to the symbol name. | |||
3703 | However, we do not modify a non-hidden absolute symbol | |||
3704 | if it is not a function, because it might be the version | |||
3705 | symbol itself. FIXME: What if it isn't? */ | |||
3706 | if ((iver.vs_vers & VERSYM_HIDDEN0x8000) != 0 | |||
3707 | || (vernum > 1 && (! bfd_is_abs_section (sec)((sec) == ((asection *) &bfd_abs_section)) | |||
3708 | || ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF) == STT_FUNC2))) | |||
3709 | { | |||
3710 | const char *verstr; | |||
3711 | size_t namelen, verlen, newlen; | |||
3712 | char *newname, *p; | |||
3713 | ||||
3714 | if (isym->st_shndx != SHN_UNDEF0) | |||
3715 | { | |||
3716 | if (vernum > elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs) | |||
3717 | verstr = NULL((void*)0); | |||
3718 | else if (vernum > 1) | |||
3719 | verstr = | |||
3720 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef[vernum - 1].vd_nodename; | |||
3721 | else | |||
3722 | verstr = ""; | |||
3723 | ||||
3724 | if (verstr == NULL((void*)0)) | |||
3725 | { | |||
3726 | (*_bfd_error_handler) | |||
3727 | (_("%B: %s: invalid version %u (max %d)")("%B: %s: invalid version %u (max %d)"), | |||
3728 | abfd, name, vernum, | |||
3729 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->cverdefs); | |||
3730 | bfd_set_error (bfd_error_bad_value); | |||
3731 | goto error_free_vers; | |||
3732 | } | |||
3733 | } | |||
3734 | else | |||
3735 | { | |||
3736 | /* We cannot simply test for the number of | |||
3737 | entries in the VERNEED section since the | |||
3738 | numbers for the needed versions do not start | |||
3739 | at 0. */ | |||
3740 | Elf_Internal_Verneed *t; | |||
3741 | ||||
3742 | verstr = NULL((void*)0); | |||
3743 | for (t = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verref; | |||
3744 | t != NULL((void*)0); | |||
3745 | t = t->vn_nextref) | |||
3746 | { | |||
3747 | Elf_Internal_Vernaux *a; | |||
3748 | ||||
3749 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
3750 | { | |||
3751 | if (a->vna_other == vernum) | |||
3752 | { | |||
3753 | verstr = a->vna_nodename; | |||
3754 | break; | |||
3755 | } | |||
3756 | } | |||
3757 | if (a != NULL((void*)0)) | |||
3758 | break; | |||
3759 | } | |||
3760 | if (verstr == NULL((void*)0)) | |||
3761 | { | |||
3762 | (*_bfd_error_handler) | |||
3763 | (_("%B: %s: invalid needed version %d")("%B: %s: invalid needed version %d"), | |||
3764 | abfd, name, vernum); | |||
3765 | bfd_set_error (bfd_error_bad_value); | |||
3766 | goto error_free_vers; | |||
3767 | } | |||
3768 | } | |||
3769 | ||||
3770 | namelen = strlen (name); | |||
3771 | verlen = strlen (verstr); | |||
3772 | newlen = namelen + verlen + 2; | |||
3773 | if ((iver.vs_vers & VERSYM_HIDDEN0x8000) == 0 | |||
3774 | && isym->st_shndx != SHN_UNDEF0) | |||
3775 | ++newlen; | |||
3776 | ||||
3777 | newname = bfd_hash_allocate (&htab->root.table, newlen); | |||
3778 | if (newname == NULL((void*)0)) | |||
3779 | goto error_free_vers; | |||
3780 | memcpy (newname, name, namelen); | |||
3781 | p = newname + namelen; | |||
3782 | *p++ = ELF_VER_CHR'@'; | |||
3783 | /* If this is a defined non-hidden version symbol, | |||
3784 | we add another @ to the name. This indicates the | |||
3785 | default version of the symbol. */ | |||
3786 | if ((iver.vs_vers & VERSYM_HIDDEN0x8000) == 0 | |||
3787 | && isym->st_shndx != SHN_UNDEF0) | |||
3788 | *p++ = ELF_VER_CHR'@'; | |||
3789 | memcpy (p, verstr, verlen + 1); | |||
3790 | ||||
3791 | name = newname; | |||
3792 | } | |||
3793 | ||||
3794 | if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec, | |||
3795 | &value, &old_alignment, | |||
3796 | sym_hash, &skip, &override, | |||
3797 | &type_change_ok, &size_change_ok)) | |||
3798 | goto error_free_vers; | |||
3799 | ||||
3800 | if (skip) | |||
3801 | continue; | |||
3802 | ||||
3803 | if (override) | |||
3804 | definition = FALSE0; | |||
3805 | ||||
3806 | h = *sym_hash; | |||
3807 | while (h->root.type == bfd_link_hash_indirect | |||
3808 | || h->root.type == bfd_link_hash_warning) | |||
3809 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
3810 | ||||
3811 | /* Remember the old alignment if this is a common symbol, so | |||
3812 | that we don't reduce the alignment later on. We can't | |||
3813 | check later, because _bfd_generic_link_add_one_symbol | |||
3814 | will set a default for the alignment which we want to | |||
3815 | override. We also remember the old bfd where the existing | |||
3816 | definition comes from. */ | |||
3817 | switch (h->root.type) | |||
3818 | { | |||
3819 | default: | |||
3820 | break; | |||
3821 | ||||
3822 | case bfd_link_hash_defined: | |||
3823 | case bfd_link_hash_defweak: | |||
3824 | old_bfd = h->root.u.def.section->owner; | |||
3825 | break; | |||
3826 | ||||
3827 | case bfd_link_hash_common: | |||
3828 | old_bfd = h->root.u.c.p->section->owner; | |||
3829 | old_alignment = h->root.u.c.p->alignment_power; | |||
3830 | break; | |||
3831 | } | |||
3832 | ||||
3833 | if (elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef != NULL((void*)0) | |||
3834 | && ! override | |||
3835 | && vernum > 1 | |||
3836 | && definition) | |||
3837 | h->verinfo.verdef = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->verdef[vernum - 1]; | |||
3838 | } | |||
3839 | ||||
3840 | if (! (_bfd_generic_link_add_one_symbol | |||
3841 | (info, abfd, name, flags, sec, value, NULL((void*)0), FALSE0, bed->collect, | |||
3842 | (struct bfd_link_hash_entry **) sym_hash))) | |||
3843 | goto error_free_vers; | |||
3844 | ||||
3845 | h = *sym_hash; | |||
3846 | while (h->root.type == bfd_link_hash_indirect | |||
3847 | || h->root.type == bfd_link_hash_warning) | |||
3848 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
3849 | *sym_hash = h; | |||
3850 | ||||
3851 | new_weakdef = FALSE0; | |||
3852 | if (dynamic | |||
3853 | && definition | |||
3854 | && (flags & BSF_WEAK0x80) != 0 | |||
3855 | && ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF) != STT_FUNC2 | |||
3856 | && is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table ) | |||
3857 | && h->u.weakdef == NULL((void*)0)) | |||
3858 | { | |||
3859 | /* Keep a list of all weak defined non function symbols from | |||
3860 | a dynamic object, using the weakdef field. Later in this | |||
3861 | function we will set the weakdef field to the correct | |||
3862 | value. We only put non-function symbols from dynamic | |||
3863 | objects on this list, because that happens to be the only | |||
3864 | time we need to know the normal symbol corresponding to a | |||
3865 | weak symbol, and the information is time consuming to | |||
3866 | figure out. If the weakdef field is not already NULL, | |||
3867 | then this symbol was already defined by some previous | |||
3868 | dynamic object, and we will be using that previous | |||
3869 | definition anyhow. */ | |||
3870 | ||||
3871 | h->u.weakdef = weaks; | |||
3872 | weaks = h; | |||
3873 | new_weakdef = TRUE1; | |||
3874 | } | |||
3875 | ||||
3876 | /* Set the alignment of a common symbol. */ | |||
3877 | if ((common || bfd_is_com_section (sec)(((sec)->flags & 0x1000) != 0)) | |||
3878 | && h->root.type == bfd_link_hash_common) | |||
3879 | { | |||
3880 | unsigned int align; | |||
3881 | ||||
3882 | if (common) | |||
3883 | align = bfd_log2 (isym->st_value); | |||
3884 | else | |||
3885 | { | |||
3886 | /* The new symbol is a common symbol in a shared object. | |||
3887 | We need to get the alignment from the section. */ | |||
3888 | align = new_sec->alignment_power; | |||
3889 | } | |||
3890 | if (align > old_alignment | |||
3891 | /* Permit an alignment power of zero if an alignment of one | |||
3892 | is specified and no other alignments have been specified. */ | |||
3893 | || (isym->st_value == 1 && old_alignment == 0)) | |||
3894 | h->root.u.c.p->alignment_power = align; | |||
3895 | else | |||
3896 | h->root.u.c.p->alignment_power = old_alignment; | |||
3897 | } | |||
3898 | ||||
3899 | if (is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table )) | |||
3900 | { | |||
3901 | bfd_boolean dynsym; | |||
3902 | ||||
3903 | /* Check the alignment when a common symbol is involved. This | |||
3904 | can change when a common symbol is overridden by a normal | |||
3905 | definition or a common symbol is ignored due to the old | |||
3906 | normal definition. We need to make sure the maximum | |||
3907 | alignment is maintained. */ | |||
3908 | if ((old_alignment || common) | |||
3909 | && h->root.type != bfd_link_hash_common) | |||
3910 | { | |||
3911 | unsigned int common_align; | |||
3912 | unsigned int normal_align; | |||
3913 | unsigned int symbol_align; | |||
3914 | bfd *normal_bfd; | |||
3915 | bfd *common_bfd; | |||
3916 | ||||
3917 | symbol_align = ffs (h->root.u.def.value) - 1; | |||
3918 | if (h->root.u.def.section->owner != NULL((void*)0) | |||
3919 | && (h->root.u.def.section->owner->flags & DYNAMIC0x40) == 0) | |||
3920 | { | |||
3921 | normal_align = h->root.u.def.section->alignment_power; | |||
3922 | if (normal_align > symbol_align) | |||
3923 | normal_align = symbol_align; | |||
3924 | } | |||
3925 | else | |||
3926 | normal_align = symbol_align; | |||
3927 | ||||
3928 | if (old_alignment) | |||
3929 | { | |||
3930 | common_align = old_alignment; | |||
3931 | common_bfd = old_bfd; | |||
3932 | normal_bfd = abfd; | |||
3933 | } | |||
3934 | else | |||
3935 | { | |||
3936 | common_align = bfd_log2 (isym->st_value); | |||
3937 | common_bfd = abfd; | |||
3938 | normal_bfd = old_bfd; | |||
3939 | } | |||
3940 | ||||
3941 | if (normal_align < common_align) | |||
3942 | (*_bfd_error_handler) | |||
3943 | (_("Warning: alignment %u of symbol `%s' in %B"("Warning: alignment %u of symbol `%s' in %B" " is smaller than %u in %B" ) | |||
3944 | " is smaller than %u in %B")("Warning: alignment %u of symbol `%s' in %B" " is smaller than %u in %B" ), | |||
3945 | normal_bfd, common_bfd, | |||
3946 | 1 << normal_align, name, 1 << common_align); | |||
3947 | } | |||
3948 | ||||
3949 | /* Remember the symbol size and type. */ | |||
3950 | if (isym->st_size != 0 | |||
3951 | && (definition || h->size == 0)) | |||
3952 | { | |||
3953 | if (h->size != 0 && h->size != isym->st_size && ! size_change_ok) | |||
3954 | (*_bfd_error_handler) | |||
3955 | (_("Warning: size of symbol `%s' changed"("Warning: size of symbol `%s' changed" " from %lu in %B to %lu in %B" ) | |||
3956 | " from %lu in %B to %lu in %B")("Warning: size of symbol `%s' changed" " from %lu in %B to %lu in %B" ), | |||
3957 | old_bfd, abfd, | |||
3958 | name, (unsigned long) h->size, | |||
3959 | (unsigned long) isym->st_size); | |||
3960 | ||||
3961 | h->size = isym->st_size; | |||
3962 | } | |||
3963 | ||||
3964 | /* If this is a common symbol, then we always want H->SIZE | |||
3965 | to be the size of the common symbol. The code just above | |||
3966 | won't fix the size if a common symbol becomes larger. We | |||
3967 | don't warn about a size change here, because that is | |||
3968 | covered by --warn-common. */ | |||
3969 | if (h->root.type == bfd_link_hash_common) | |||
3970 | h->size = h->root.u.c.size; | |||
3971 | ||||
3972 | if (ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF) != STT_NOTYPE0 | |||
3973 | && (definition || h->type == STT_NOTYPE0)) | |||
3974 | { | |||
3975 | if (h->type != STT_NOTYPE0 | |||
3976 | && h->type != ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF) | |||
3977 | && ! type_change_ok) | |||
3978 | (*_bfd_error_handler) | |||
3979 | (_("Warning: type of symbol `%s' changed"("Warning: type of symbol `%s' changed" " from %d to %d in %B" ) | |||
3980 | " from %d to %d in %B")("Warning: type of symbol `%s' changed" " from %d to %d in %B" ), | |||
3981 | abfd, name, h->type, ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF)); | |||
3982 | ||||
3983 | h->type = ELF_ST_TYPE (isym->st_info)((isym->st_info) & 0xF); | |||
3984 | } | |||
3985 | ||||
3986 | /* If st_other has a processor-specific meaning, specific | |||
3987 | code might be needed here. We never merge the visibility | |||
3988 | attribute with the one from a dynamic object. */ | |||
3989 | if (bed->elf_backend_merge_symbol_attribute) | |||
3990 | (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition, | |||
3991 | dynamic); | |||
3992 | ||||
3993 | /* If this symbol has default visibility and the user has requested | |||
3994 | we not re-export it, then mark it as hidden. */ | |||
3995 | if (definition && !dynamic | |||
3996 | && (abfd->no_export | |||
3997 | || (abfd->my_archive && abfd->my_archive->no_export)) | |||
3998 | && ELF_ST_VISIBILITY (isym->st_other)((isym->st_other) & 0x3) != STV_INTERNAL1) | |||
3999 | isym->st_other = (STV_HIDDEN2 | |||
4000 | | (isym->st_other & ~ELF_ST_VISIBILITY (-1)((-1) & 0x3))); | |||
4001 | ||||
4002 | if (isym->st_other != 0 && !dynamic) | |||
4003 | { | |||
4004 | unsigned char hvis, symvis, other, nvis; | |||
4005 | ||||
4006 | /* Take the balance of OTHER from the definition. */ | |||
4007 | other = (definition ? isym->st_other : h->other); | |||
4008 | other &= ~ ELF_ST_VISIBILITY (-1)((-1) & 0x3); | |||
4009 | ||||
4010 | /* Combine visibilities, using the most constraining one. */ | |||
4011 | hvis = ELF_ST_VISIBILITY (h->other)((h->other) & 0x3); | |||
4012 | symvis = ELF_ST_VISIBILITY (isym->st_other)((isym->st_other) & 0x3); | |||
4013 | if (! hvis) | |||
4014 | nvis = symvis; | |||
4015 | else if (! symvis) | |||
4016 | nvis = hvis; | |||
4017 | else | |||
4018 | nvis = hvis < symvis ? hvis : symvis; | |||
4019 | ||||
4020 | h->other = other | nvis; | |||
4021 | } | |||
4022 | ||||
4023 | /* Set a flag in the hash table entry indicating the type of | |||
4024 | reference or definition we just found. Keep a count of | |||
4025 | the number of dynamic symbols we find. A dynamic symbol | |||
4026 | is one which is referenced or defined by both a regular | |||
4027 | object and a shared object. */ | |||
4028 | dynsym = FALSE0; | |||
4029 | if (! dynamic) | |||
4030 | { | |||
4031 | if (! definition) | |||
4032 | { | |||
4033 | h->ref_regular = 1; | |||
4034 | if (bind != STB_WEAK2) | |||
4035 | h->ref_regular_nonweak = 1; | |||
4036 | } | |||
4037 | else | |||
4038 | h->def_regular = 1; | |||
4039 | if (! info->executable | |||
4040 | || h->def_dynamic | |||
4041 | || h->ref_dynamic) | |||
4042 | dynsym = TRUE1; | |||
4043 | } | |||
4044 | else | |||
4045 | { | |||
4046 | if (! definition) | |||
4047 | h->ref_dynamic = 1; | |||
4048 | else | |||
4049 | h->def_dynamic = 1; | |||
4050 | if (h->def_regular | |||
4051 | || h->ref_regular | |||
4052 | || (h->u.weakdef != NULL((void*)0) | |||
4053 | && ! new_weakdef | |||
4054 | && h->u.weakdef->dynindx != -1)) | |||
4055 | dynsym = TRUE1; | |||
4056 | } | |||
4057 | ||||
4058 | /* Check to see if we need to add an indirect symbol for | |||
4059 | the default name. */ | |||
4060 | if (definition || h->root.type == bfd_link_hash_common) | |||
4061 | if (!_bfd_elf_add_default_symbol (abfd, info, h, name, isym, | |||
4062 | &sec, &value, &dynsym, | |||
4063 | override)) | |||
4064 | goto error_free_vers; | |||
4065 | ||||
4066 | if (definition && !dynamic) | |||
4067 | { | |||
4068 | char *p = strchr (name, ELF_VER_CHR'@'); | |||
4069 | if (p != NULL((void*)0) && p[1] != ELF_VER_CHR'@') | |||
4070 | { | |||
4071 | /* Queue non-default versions so that .symver x, x@FOO | |||
4072 | aliases can be checked. */ | |||
4073 | if (!nondeflt_vers) | |||
4074 | { | |||
4075 | amt = ((isymend - isym + 1) | |||
4076 | * sizeof (struct elf_link_hash_entry *)); | |||
4077 | nondeflt_vers = bfd_malloc (amt); | |||
4078 | } | |||
4079 | nondeflt_vers[nondeflt_vers_cnt++] = h; | |||
4080 | } | |||
4081 | } | |||
4082 | ||||
4083 | if (dynsym && h->dynindx == -1) | |||
4084 | { | |||
4085 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
4086 | goto error_free_vers; | |||
4087 | if (h->u.weakdef != NULL((void*)0) | |||
4088 | && ! new_weakdef | |||
4089 | && h->u.weakdef->dynindx == -1) | |||
4090 | { | |||
4091 | if (!bfd_elf_link_record_dynamic_symbol (info, h->u.weakdef)) | |||
4092 | goto error_free_vers; | |||
4093 | } | |||
4094 | } | |||
4095 | else if (dynsym && h->dynindx != -1) | |||
4096 | /* If the symbol already has a dynamic index, but | |||
4097 | visibility says it should not be visible, turn it into | |||
4098 | a local symbol. */ | |||
4099 | switch (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3)) | |||
4100 | { | |||
4101 | case STV_INTERNAL1: | |||
4102 | case STV_HIDDEN2: | |||
4103 | (*bed->elf_backend_hide_symbol) (info, h, TRUE1); | |||
4104 | dynsym = FALSE0; | |||
4105 | break; | |||
4106 | } | |||
4107 | ||||
4108 | if (!add_needed | |||
4109 | && definition | |||
4110 | && dynsym | |||
4111 | && h->ref_regular) | |||
4112 | { | |||
4113 | int ret; | |||
4114 | const char *soname = elf_dt_name (abfd)(((abfd) -> tdata.elf_obj_data) -> dt_name); | |||
4115 | ||||
4116 | /* A symbol from a library loaded via DT_NEEDED of some | |||
4117 | other library is referenced by a regular object. | |||
4118 | Add a DT_NEEDED entry for it. Issue an error if | |||
4119 | --no-add-needed is used. */ | |||
4120 | if ((elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class) & DYN_NO_NEEDED) != 0) | |||
4121 | { | |||
4122 | (*_bfd_error_handler) | |||
4123 | (_("%s: invalid DSO for symbol `%s' definition")("%s: invalid DSO for symbol `%s' definition"), | |||
4124 | abfd, name); | |||
4125 | bfd_set_error (bfd_error_bad_value); | |||
4126 | goto error_free_vers; | |||
4127 | } | |||
4128 | ||||
4129 | elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class) &= ~DYN_AS_NEEDED; | |||
4130 | ||||
4131 | add_needed = TRUE1; | |||
4132 | ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed); | |||
4133 | if (ret < 0) | |||
4134 | goto error_free_vers; | |||
4135 | ||||
4136 | BFD_ASSERT (ret == 0)do { if (!(ret == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,4136); } while (0); | |||
4137 | } | |||
4138 | } | |||
4139 | } | |||
4140 | ||||
4141 | if (extversym != NULL((void*)0)) | |||
4142 | { | |||
4143 | free (extversym); | |||
4144 | extversym = NULL((void*)0); | |||
4145 | } | |||
4146 | ||||
4147 | if (isymbuf != NULL((void*)0)) | |||
4148 | { | |||
4149 | free (isymbuf); | |||
4150 | isymbuf = NULL((void*)0); | |||
4151 | } | |||
4152 | ||||
4153 | if ((elf_dyn_lib_class (abfd)(((abfd) -> tdata.elf_obj_data) -> dyn_lib_class) & DYN_AS_NEEDED) != 0) | |||
4154 | { | |||
4155 | unsigned int i; | |||
4156 | ||||
4157 | /* Restore the symbol table. */ | |||
4158 | old_hash = (char *) old_tab + tabsize; | |||
4159 | old_ent = (char *) old_hash + hashsize; | |||
4160 | sym_hash = elf_sym_hashes (abfd)(((abfd) -> tdata.elf_obj_data) -> sym_hashes); | |||
4161 | memcpy (htab->root.table.table, old_tab, tabsize); | |||
4162 | memcpy (sym_hash, old_hash, hashsize); | |||
4163 | htab->root.undefs = old_undefs; | |||
4164 | htab->root.undefs_tail = old_undefs_tail; | |||
4165 | for (i = 0; i < htab->root.table.size; i++) | |||
4166 | { | |||
4167 | struct bfd_hash_entry *p; | |||
4168 | struct elf_link_hash_entry *h; | |||
4169 | ||||
4170 | for (p = htab->root.table.table[i]; p != NULL((void*)0); p = p->next) | |||
4171 | { | |||
4172 | h = (struct elf_link_hash_entry *) p; | |||
4173 | if (h->root.type == bfd_link_hash_warning) | |||
4174 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
4175 | if (h->dynindx >= old_dynsymcount) | |||
4176 | _bfd_elf_strtab_delref (htab->dynstr, h->dynstr_index); | |||
4177 | ||||
4178 | memcpy (p, old_ent, htab->root.table.entsize); | |||
4179 | old_ent = (char *) old_ent + htab->root.table.entsize; | |||
4180 | h = (struct elf_link_hash_entry *) p; | |||
4181 | if (h->root.type == bfd_link_hash_warning) | |||
4182 | { | |||
4183 | memcpy (h->root.u.i.link, old_ent, htab->root.table.entsize); | |||
4184 | old_ent = (char *) old_ent + htab->root.table.entsize; | |||
4185 | } | |||
4186 | } | |||
4187 | } | |||
4188 | ||||
4189 | free (old_tab); | |||
4190 | objalloc_free_block ((struct objalloc *) htab->root.table.memory, | |||
4191 | alloc_mark); | |||
4192 | if (nondeflt_vers != NULL((void*)0)) | |||
4193 | free (nondeflt_vers); | |||
4194 | return TRUE1; | |||
4195 | } | |||
4196 | ||||
4197 | if (old_tab != NULL((void*)0)) | |||
4198 | { | |||
4199 | free (old_tab); | |||
4200 | old_tab = NULL((void*)0); | |||
4201 | } | |||
4202 | ||||
4203 | /* Now that all the symbols from this input file are created, handle | |||
4204 | .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */ | |||
4205 | if (nondeflt_vers != NULL((void*)0)) | |||
4206 | { | |||
4207 | bfd_size_type cnt, symidx; | |||
4208 | ||||
4209 | for (cnt = 0; cnt < nondeflt_vers_cnt; ++cnt) | |||
4210 | { | |||
4211 | struct elf_link_hash_entry *h = nondeflt_vers[cnt], *hi; | |||
4212 | char *shortname, *p; | |||
4213 | ||||
4214 | p = strchr (h->root.root.string, ELF_VER_CHR'@'); | |||
4215 | if (p == NULL((void*)0) | |||
4216 | || (h->root.type != bfd_link_hash_defined | |||
4217 | && h->root.type != bfd_link_hash_defweak)) | |||
4218 | continue; | |||
4219 | ||||
4220 | amt = p - h->root.root.string; | |||
4221 | shortname = bfd_malloc (amt + 1); | |||
4222 | memcpy (shortname, h->root.root.string, amt); | |||
4223 | shortname[amt] = '\0'; | |||
4224 | ||||
4225 | hi = (struct elf_link_hash_entry *) | |||
4226 | bfd_link_hash_lookup (&htab->root, shortname, | |||
4227 | FALSE0, FALSE0, FALSE0); | |||
4228 | if (hi != NULL((void*)0) | |||
4229 | && hi->root.type == h->root.type | |||
4230 | && hi->root.u.def.value == h->root.u.def.value | |||
4231 | && hi->root.u.def.section == h->root.u.def.section) | |||
4232 | { | |||
4233 | (*bed->elf_backend_hide_symbol) (info, hi, TRUE1); | |||
4234 | hi->root.type = bfd_link_hash_indirect; | |||
4235 | hi->root.u.i.link = (struct bfd_link_hash_entry *) h; | |||
4236 | (*bed->elf_backend_copy_indirect_symbol) (info, h, hi); | |||
4237 | sym_hash = elf_sym_hashes (abfd)(((abfd) -> tdata.elf_obj_data) -> sym_hashes); | |||
4238 | if (sym_hash) | |||
4239 | for (symidx = 0; symidx < extsymcount; ++symidx) | |||
4240 | if (sym_hash[symidx] == hi) | |||
4241 | { | |||
4242 | sym_hash[symidx] = h; | |||
4243 | break; | |||
4244 | } | |||
4245 | } | |||
4246 | free (shortname); | |||
4247 | } | |||
4248 | free (nondeflt_vers); | |||
4249 | nondeflt_vers = NULL((void*)0); | |||
4250 | } | |||
4251 | ||||
4252 | /* Now set the weakdefs field correctly for all the weak defined | |||
4253 | symbols we found. The only way to do this is to search all the | |||
4254 | symbols. Since we only need the information for non functions in | |||
4255 | dynamic objects, that's the only time we actually put anything on | |||
4256 | the list WEAKS. We need this information so that if a regular | |||
4257 | object refers to a symbol defined weakly in a dynamic object, the | |||
4258 | real symbol in the dynamic object is also put in the dynamic | |||
4259 | symbols; we also must arrange for both symbols to point to the | |||
4260 | same memory location. We could handle the general case of symbol | |||
4261 | aliasing, but a general symbol alias can only be generated in | |||
4262 | assembler code, handling it correctly would be very time | |||
4263 | consuming, and other ELF linkers don't handle general aliasing | |||
4264 | either. */ | |||
4265 | if (weaks != NULL((void*)0)) | |||
4266 | { | |||
4267 | struct elf_link_hash_entry **hpp; | |||
4268 | struct elf_link_hash_entry **hppend; | |||
4269 | struct elf_link_hash_entry **sorted_sym_hash; | |||
4270 | struct elf_link_hash_entry *h; | |||
4271 | size_t sym_count; | |||
4272 | ||||
4273 | /* Since we have to search the whole symbol list for each weak | |||
4274 | defined symbol, search time for N weak defined symbols will be | |||
4275 | O(N^2). Binary search will cut it down to O(NlogN). */ | |||
4276 | amt = extsymcount * sizeof (struct elf_link_hash_entry *); | |||
4277 | sorted_sym_hash = bfd_malloc (amt); | |||
4278 | if (sorted_sym_hash == NULL((void*)0)) | |||
4279 | goto error_return; | |||
4280 | sym_hash = sorted_sym_hash; | |||
4281 | hpp = elf_sym_hashes (abfd)(((abfd) -> tdata.elf_obj_data) -> sym_hashes); | |||
4282 | hppend = hpp + extsymcount; | |||
4283 | sym_count = 0; | |||
4284 | for (; hpp < hppend; hpp++) | |||
4285 | { | |||
4286 | h = *hpp; | |||
4287 | if (h != NULL((void*)0) | |||
4288 | && h->root.type == bfd_link_hash_defined | |||
4289 | && h->type != STT_FUNC2) | |||
4290 | { | |||
4291 | *sym_hash = h; | |||
4292 | sym_hash++; | |||
4293 | sym_count++; | |||
4294 | } | |||
4295 | } | |||
4296 | ||||
4297 | qsort (sorted_sym_hash, sym_count, | |||
4298 | sizeof (struct elf_link_hash_entry *), | |||
4299 | elf_sort_symbol); | |||
4300 | ||||
4301 | while (weaks != NULL((void*)0)) | |||
4302 | { | |||
4303 | struct elf_link_hash_entry *hlook; | |||
4304 | asection *slook; | |||
4305 | bfd_vma vlook; | |||
4306 | long ilook; | |||
4307 | size_t i, j, idx; | |||
4308 | ||||
4309 | hlook = weaks; | |||
4310 | weaks = hlook->u.weakdef; | |||
4311 | hlook->u.weakdef = NULL((void*)0); | |||
4312 | ||||
4313 | BFD_ASSERT (hlook->root.type == bfd_link_hash_defineddo { if (!(hlook->root.type == bfd_link_hash_defined || hlook ->root.type == bfd_link_hash_defweak || hlook->root.type == bfd_link_hash_common || hlook->root.type == bfd_link_hash_indirect )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,4316); } while (0) | |||
4314 | || hlook->root.type == bfd_link_hash_defweakdo { if (!(hlook->root.type == bfd_link_hash_defined || hlook ->root.type == bfd_link_hash_defweak || hlook->root.type == bfd_link_hash_common || hlook->root.type == bfd_link_hash_indirect )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,4316); } while (0) | |||
4315 | || hlook->root.type == bfd_link_hash_commondo { if (!(hlook->root.type == bfd_link_hash_defined || hlook ->root.type == bfd_link_hash_defweak || hlook->root.type == bfd_link_hash_common || hlook->root.type == bfd_link_hash_indirect )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,4316); } while (0) | |||
4316 | || hlook->root.type == bfd_link_hash_indirect)do { if (!(hlook->root.type == bfd_link_hash_defined || hlook ->root.type == bfd_link_hash_defweak || hlook->root.type == bfd_link_hash_common || hlook->root.type == bfd_link_hash_indirect )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,4316); } while (0); | |||
4317 | slook = hlook->root.u.def.section; | |||
4318 | vlook = hlook->root.u.def.value; | |||
4319 | ||||
4320 | ilook = -1; | |||
4321 | i = 0; | |||
4322 | j = sym_count; | |||
4323 | while (i < j) | |||
4324 | { | |||
4325 | bfd_signed_vma vdiff; | |||
4326 | idx = (i + j) / 2; | |||
4327 | h = sorted_sym_hash [idx]; | |||
4328 | vdiff = vlook - h->root.u.def.value; | |||
4329 | if (vdiff < 0) | |||
4330 | j = idx; | |||
4331 | else if (vdiff > 0) | |||
4332 | i = idx + 1; | |||
4333 | else | |||
4334 | { | |||
4335 | long sdiff = slook->id - h->root.u.def.section->id; | |||
4336 | if (sdiff < 0) | |||
4337 | j = idx; | |||
4338 | else if (sdiff > 0) | |||
4339 | i = idx + 1; | |||
4340 | else | |||
4341 | { | |||
4342 | ilook = idx; | |||
4343 | break; | |||
4344 | } | |||
4345 | } | |||
4346 | } | |||
4347 | ||||
4348 | /* We didn't find a value/section match. */ | |||
4349 | if (ilook == -1) | |||
4350 | continue; | |||
4351 | ||||
4352 | for (i = ilook; i < sym_count; i++) | |||
4353 | { | |||
4354 | h = sorted_sym_hash [i]; | |||
4355 | ||||
4356 | /* Stop if value or section doesn't match. */ | |||
4357 | if (h->root.u.def.value != vlook | |||
4358 | || h->root.u.def.section != slook) | |||
4359 | break; | |||
4360 | else if (h != hlook) | |||
4361 | { | |||
4362 | hlook->u.weakdef = h; | |||
4363 | ||||
4364 | /* If the weak definition is in the list of dynamic | |||
4365 | symbols, make sure the real definition is put | |||
4366 | there as well. */ | |||
4367 | if (hlook->dynindx != -1 && h->dynindx == -1) | |||
4368 | { | |||
4369 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
4370 | goto error_return; | |||
4371 | } | |||
4372 | ||||
4373 | /* If the real definition is in the list of dynamic | |||
4374 | symbols, make sure the weak definition is put | |||
4375 | there as well. If we don't do this, then the | |||
4376 | dynamic loader might not merge the entries for the | |||
4377 | real definition and the weak definition. */ | |||
4378 | if (h->dynindx != -1 && hlook->dynindx == -1) | |||
4379 | { | |||
4380 | if (! bfd_elf_link_record_dynamic_symbol (info, hlook)) | |||
4381 | goto error_return; | |||
4382 | } | |||
4383 | break; | |||
4384 | } | |||
4385 | } | |||
4386 | } | |||
4387 | ||||
4388 | free (sorted_sym_hash); | |||
4389 | } | |||
4390 | ||||
4391 | if (bed->check_directives) | |||
4392 | (*bed->check_directives) (abfd, info); | |||
4393 | ||||
4394 | /* If this object is the same format as the output object, and it is | |||
4395 | not a shared library, then let the backend look through the | |||
4396 | relocs. | |||
4397 | ||||
4398 | This is required to build global offset table entries and to | |||
4399 | arrange for dynamic relocs. It is not required for the | |||
4400 | particular common case of linking non PIC code, even when linking | |||
4401 | against shared libraries, but unfortunately there is no way of | |||
4402 | knowing whether an object file has been compiled PIC or not. | |||
4403 | Looking through the relocs is not particularly time consuming. | |||
4404 | The problem is that we must either (1) keep the relocs in memory, | |||
4405 | which causes the linker to require additional runtime memory or | |||
4406 | (2) read the relocs twice from the input file, which wastes time. | |||
4407 | This would be a good case for using mmap. | |||
4408 | ||||
4409 | I have no idea how to handle linking PIC code into a file of a | |||
4410 | different format. It probably can't be done. */ | |||
4411 | if (! dynamic | |||
4412 | && is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table ) | |||
4413 | && htab->root.creator == abfd->xvec | |||
4414 | && bed->check_relocs != NULL((void*)0)) | |||
4415 | { | |||
4416 | asection *o; | |||
4417 | ||||
4418 | for (o = abfd->sections; o != NULL((void*)0); o = o->next) | |||
4419 | { | |||
4420 | Elf_Internal_Rela *internal_relocs; | |||
4421 | bfd_boolean ok; | |||
4422 | ||||
4423 | if ((o->flags & SEC_RELOC0x004) == 0 | |||
4424 | || o->reloc_count == 0 | |||
4425 | || ((info->strip == strip_all || info->strip == strip_debugger) | |||
4426 | && (o->flags & SEC_DEBUGGING0x2000) != 0) | |||
4427 | || bfd_is_abs_section (o->output_section)((o->output_section) == ((asection *) &bfd_abs_section ))) | |||
4428 | continue; | |||
4429 | ||||
4430 | internal_relocs = _bfd_elf_link_read_relocs (abfd, o, NULL((void*)0), NULL((void*)0), | |||
4431 | info->keep_memory); | |||
4432 | if (internal_relocs == NULL((void*)0)) | |||
4433 | goto error_return; | |||
4434 | ||||
4435 | ok = (*bed->check_relocs) (abfd, info, o, internal_relocs); | |||
4436 | ||||
4437 | if (elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->relocs != internal_relocs) | |||
4438 | free (internal_relocs); | |||
4439 | ||||
4440 | if (! ok) | |||
4441 | goto error_return; | |||
4442 | } | |||
4443 | } | |||
4444 | ||||
4445 | /* If this is a non-traditional link, try to optimize the handling | |||
4446 | of the .stab/.stabstr sections. */ | |||
4447 | if (! dynamic | |||
4448 | && ! info->traditional_format | |||
4449 | && is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table ) | |||
4450 | && (info->strip != strip_all && info->strip != strip_debugger)) | |||
4451 | { | |||
4452 | asection *stabstr; | |||
4453 | ||||
4454 | stabstr = bfd_get_section_by_name (abfd, ".stabstr"); | |||
4455 | if (stabstr != NULL((void*)0)) | |||
4456 | { | |||
4457 | bfd_size_type string_offset = 0; | |||
4458 | asection *stab; | |||
4459 | ||||
4460 | for (stab = abfd->sections; stab; stab = stab->next) | |||
4461 | if (strncmp (".stab", stab->name, 5) == 0 | |||
4462 | && (!stab->name[5] || | |||
4463 | (stab->name[5] == '.' && ISDIGIT (stab->name[6])(_sch_istable[(stab->name[6]) & 0xff] & (unsigned short )(_sch_isdigit)))) | |||
4464 | && (stab->flags & SEC_MERGE0x1000000) == 0 | |||
4465 | && !bfd_is_abs_section (stab->output_section)((stab->output_section) == ((asection *) &bfd_abs_section ))) | |||
4466 | { | |||
4467 | struct bfd_elf_section_data *secdata; | |||
4468 | ||||
4469 | secdata = elf_section_data (stab)((struct bfd_elf_section_data*)(stab)->used_by_bfd); | |||
4470 | if (! _bfd_link_section_stabs (abfd, &htab->stab_info, stab, | |||
4471 | stabstr, &secdata->sec_info, | |||
4472 | &string_offset)) | |||
4473 | goto error_return; | |||
4474 | if (secdata->sec_info) | |||
4475 | stab->sec_info_type = ELF_INFO_TYPE_STABS1; | |||
4476 | } | |||
4477 | } | |||
4478 | } | |||
4479 | ||||
4480 | if (is_elf_hash_table (htab)(((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table ) && add_needed) | |||
4481 | { | |||
4482 | /* Add this bfd to the loaded list. */ | |||
4483 | struct elf_link_loaded_list *n; | |||
4484 | ||||
4485 | n = bfd_alloc (abfd, sizeof (struct elf_link_loaded_list)); | |||
4486 | if (n == NULL((void*)0)) | |||
4487 | goto error_return; | |||
4488 | n->abfd = abfd; | |||
4489 | n->next = htab->loaded; | |||
4490 | htab->loaded = n; | |||
4491 | } | |||
4492 | ||||
4493 | return TRUE1; | |||
4494 | ||||
4495 | error_free_vers: | |||
4496 | if (old_tab != NULL((void*)0)) | |||
4497 | free (old_tab); | |||
4498 | if (nondeflt_vers != NULL((void*)0)) | |||
4499 | free (nondeflt_vers); | |||
4500 | if (extversym != NULL((void*)0)) | |||
4501 | free (extversym); | |||
4502 | error_free_sym: | |||
4503 | if (isymbuf != NULL((void*)0)) | |||
4504 | free (isymbuf); | |||
4505 | error_return: | |||
4506 | return FALSE0; | |||
4507 | } | |||
4508 | ||||
4509 | /* Return the linker hash table entry of a symbol that might be | |||
4510 | satisfied by an archive symbol. Return -1 on error. */ | |||
4511 | ||||
4512 | struct elf_link_hash_entry * | |||
4513 | _bfd_elf_archive_symbol_lookup (bfd *abfd, | |||
4514 | struct bfd_link_info *info, | |||
4515 | const char *name) | |||
4516 | { | |||
4517 | struct elf_link_hash_entry *h; | |||
4518 | char *p, *copy; | |||
4519 | size_t len, first; | |||
4520 | ||||
4521 | h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( name), (0), (0), (0))); | |||
4522 | if (h != NULL((void*)0)) | |||
4523 | return h; | |||
4524 | ||||
4525 | /* If this is a default version (the name contains @@), look up the | |||
4526 | symbol again with only one `@' as well as without the version. | |||
4527 | The effect is that references to the symbol with and without the | |||
4528 | version will be matched by the default symbol in the archive. */ | |||
4529 | ||||
4530 | p = strchr (name, ELF_VER_CHR'@'); | |||
4531 | if (p == NULL((void*)0) || p[1] != ELF_VER_CHR'@') | |||
4532 | return h; | |||
4533 | ||||
4534 | /* First check with only one `@'. */ | |||
4535 | len = strlen (name); | |||
4536 | copy = bfd_alloc (abfd, len); | |||
4537 | if (copy == NULL((void*)0)) | |||
4538 | return (struct elf_link_hash_entry *) -1; | |||
4539 | ||||
4540 | first = p - name + 1; | |||
4541 | memcpy (copy, name, first); | |||
4542 | memcpy (copy + first, name + first + 1, len - first); | |||
4543 | ||||
4544 | h = elf_link_hash_lookup (elf_hash_table (info), copy, FALSE, FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( copy), (0), (0), (0))); | |||
4545 | if (h == NULL((void*)0)) | |||
4546 | { | |||
4547 | /* We also need to check references to the symbol without the | |||
4548 | version. */ | |||
4549 | copy[first - 1] = '\0'; | |||
4550 | h = elf_link_hash_lookup (elf_hash_table (info), copy,((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( copy), (0), (0), (0))) | |||
4551 | FALSE, FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( copy), (0), (0), (0))); | |||
4552 | } | |||
4553 | ||||
4554 | bfd_release (abfd, copy); | |||
4555 | return h; | |||
4556 | } | |||
4557 | ||||
4558 | /* Add symbols from an ELF archive file to the linker hash table. We | |||
4559 | don't use _bfd_generic_link_add_archive_symbols because of a | |||
4560 | problem which arises on UnixWare. The UnixWare libc.so is an | |||
4561 | archive which includes an entry libc.so.1 which defines a bunch of | |||
4562 | symbols. The libc.so archive also includes a number of other | |||
4563 | object files, which also define symbols, some of which are the same | |||
4564 | as those defined in libc.so.1. Correct linking requires that we | |||
4565 | consider each object file in turn, and include it if it defines any | |||
4566 | symbols we need. _bfd_generic_link_add_archive_symbols does not do | |||
4567 | this; it looks through the list of undefined symbols, and includes | |||
4568 | any object file which defines them. When this algorithm is used on | |||
4569 | UnixWare, it winds up pulling in libc.so.1 early and defining a | |||
4570 | bunch of symbols. This means that some of the other objects in the | |||
4571 | archive are not included in the link, which is incorrect since they | |||
4572 | precede libc.so.1 in the archive. | |||
4573 | ||||
4574 | Fortunately, ELF archive handling is simpler than that done by | |||
4575 | _bfd_generic_link_add_archive_symbols, which has to allow for a.out | |||
4576 | oddities. In ELF, if we find a symbol in the archive map, and the | |||
4577 | symbol is currently undefined, we know that we must pull in that | |||
4578 | object file. | |||
4579 | ||||
4580 | Unfortunately, we do have to make multiple passes over the symbol | |||
4581 | table until nothing further is resolved. */ | |||
4582 | ||||
4583 | static bfd_boolean | |||
4584 | elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info) | |||
4585 | { | |||
4586 | symindex c; | |||
4587 | bfd_boolean *defined = NULL((void*)0); | |||
4588 | bfd_boolean *included = NULL((void*)0); | |||
4589 | carsym *symdefs; | |||
4590 | bfd_boolean loop; | |||
4591 | bfd_size_type amt; | |||
4592 | const struct elf_backend_data *bed; | |||
4593 | struct elf_link_hash_entry * (*archive_symbol_lookup) | |||
4594 | (bfd *, struct bfd_link_info *, const char *); | |||
4595 | ||||
4596 | if (! bfd_has_map (abfd)((abfd)->has_armap)) | |||
4597 | { | |||
4598 | /* An empty archive is a special case. */ | |||
4599 | if (bfd_openr_next_archived_file (abfd, NULL((void*)0)) == NULL((void*)0)) | |||
4600 | return TRUE1; | |||
4601 | bfd_set_error (bfd_error_no_armap); | |||
4602 | return FALSE0; | |||
4603 | } | |||
4604 | ||||
4605 | /* Keep track of all symbols we know to be already defined, and all | |||
4606 | files we know to be already included. This is to speed up the | |||
4607 | second and subsequent passes. */ | |||
4608 | c = bfd_ardata (abfd)((abfd)->tdata.aout_ar_data)->symdef_count; | |||
4609 | if (c == 0) | |||
4610 | return TRUE1; | |||
4611 | amt = c; | |||
4612 | amt *= sizeof (bfd_boolean); | |||
4613 | defined = bfd_zmalloc (amt); | |||
4614 | included = bfd_zmalloc (amt); | |||
4615 | if (defined == NULL((void*)0) || included == NULL((void*)0)) | |||
4616 | goto error_return; | |||
4617 | ||||
4618 | symdefs = bfd_ardata (abfd)((abfd)->tdata.aout_ar_data)->symdefs; | |||
4619 | bed = get_elf_backend_data (abfd)((const struct elf_backend_data *) (abfd)->xvec->backend_data ); | |||
4620 | archive_symbol_lookup = bed->elf_backend_archive_symbol_lookup; | |||
4621 | ||||
4622 | do | |||
4623 | { | |||
4624 | file_ptr last; | |||
4625 | symindex i; | |||
4626 | carsym *symdef; | |||
4627 | carsym *symdefend; | |||
4628 | ||||
4629 | loop = FALSE0; | |||
4630 | last = -1; | |||
4631 | ||||
4632 | symdef = symdefs; | |||
4633 | symdefend = symdef + c; | |||
4634 | for (i = 0; symdef < symdefend; symdef++, i++) | |||
4635 | { | |||
4636 | struct elf_link_hash_entry *h; | |||
4637 | bfd *element; | |||
4638 | struct bfd_link_hash_entry *undefs_tail; | |||
4639 | symindex mark; | |||
4640 | ||||
4641 | if (defined[i] || included[i]) | |||
4642 | continue; | |||
4643 | if (symdef->file_offset == last) | |||
4644 | { | |||
4645 | included[i] = TRUE1; | |||
4646 | continue; | |||
4647 | } | |||
4648 | ||||
4649 | h = archive_symbol_lookup (abfd, info, symdef->name); | |||
4650 | if (h == (struct elf_link_hash_entry *) -1) | |||
4651 | goto error_return; | |||
4652 | ||||
4653 | if (h == NULL((void*)0)) | |||
4654 | continue; | |||
4655 | ||||
4656 | if (h->root.type == bfd_link_hash_common) | |||
4657 | { | |||
4658 | /* We currently have a common symbol. The archive map contains | |||
4659 | a reference to this symbol, so we may want to include it. We | |||
4660 | only want to include it however, if this archive element | |||
4661 | contains a definition of the symbol, not just another common | |||
4662 | declaration of it. | |||
4663 | ||||
4664 | Unfortunately some archivers (including GNU ar) will put | |||
4665 | declarations of common symbols into their archive maps, as | |||
4666 | well as real definitions, so we cannot just go by the archive | |||
4667 | map alone. Instead we must read in the element's symbol | |||
4668 | table and check that to see what kind of symbol definition | |||
4669 | this is. */ | |||
4670 | if (! elf_link_is_defined_archive_symbol (abfd, symdef)) | |||
4671 | continue; | |||
4672 | } | |||
4673 | else if (h->root.type != bfd_link_hash_undefined) | |||
4674 | { | |||
4675 | if (h->root.type != bfd_link_hash_undefweak) | |||
4676 | defined[i] = TRUE1; | |||
4677 | continue; | |||
4678 | } | |||
4679 | ||||
4680 | /* We need to include this archive member. */ | |||
4681 | element = _bfd_get_elt_at_filepos (abfd, symdef->file_offset); | |||
4682 | if (element == NULL((void*)0)) | |||
4683 | goto error_return; | |||
4684 | ||||
4685 | if (! bfd_check_format (element, bfd_object)) | |||
4686 | goto error_return; | |||
4687 | ||||
4688 | /* Doublecheck that we have not included this object | |||
4689 | already--it should be impossible, but there may be | |||
4690 | something wrong with the archive. */ | |||
4691 | if (element->archive_pass != 0) | |||
4692 | { | |||
4693 | bfd_set_error (bfd_error_bad_value); | |||
4694 | goto error_return; | |||
4695 | } | |||
4696 | element->archive_pass = 1; | |||
4697 | ||||
4698 | undefs_tail = info->hash->undefs_tail; | |||
4699 | ||||
4700 | if (! (*info->callbacks->add_archive_element) (info, element, | |||
4701 | symdef->name)) | |||
4702 | goto error_return; | |||
4703 | if (! bfd_link_add_symbols (element, info)((*((element)->xvec->_bfd_link_add_symbols)) (element, info ))) | |||
4704 | goto error_return; | |||
4705 | ||||
4706 | /* If there are any new undefined symbols, we need to make | |||
4707 | another pass through the archive in order to see whether | |||
4708 | they can be defined. FIXME: This isn't perfect, because | |||
4709 | common symbols wind up on undefs_tail and because an | |||
4710 | undefined symbol which is defined later on in this pass | |||
4711 | does not require another pass. This isn't a bug, but it | |||
4712 | does make the code less efficient than it could be. */ | |||
4713 | if (undefs_tail != info->hash->undefs_tail) | |||
4714 | loop = TRUE1; | |||
4715 | ||||
4716 | /* Look backward to mark all symbols from this object file | |||
4717 | which we have already seen in this pass. */ | |||
4718 | mark = i; | |||
4719 | do | |||
4720 | { | |||
4721 | included[mark] = TRUE1; | |||
4722 | if (mark == 0) | |||
4723 | break; | |||
4724 | --mark; | |||
4725 | } | |||
4726 | while (symdefs[mark].file_offset == symdef->file_offset); | |||
4727 | ||||
4728 | /* We mark subsequent symbols from this object file as we go | |||
4729 | on through the loop. */ | |||
4730 | last = symdef->file_offset; | |||
4731 | } | |||
4732 | } | |||
4733 | while (loop); | |||
4734 | ||||
4735 | free (defined); | |||
4736 | free (included); | |||
4737 | ||||
4738 | return TRUE1; | |||
4739 | ||||
4740 | error_return: | |||
4741 | if (defined != NULL((void*)0)) | |||
4742 | free (defined); | |||
4743 | if (included != NULL((void*)0)) | |||
4744 | free (included); | |||
4745 | return FALSE0; | |||
4746 | } | |||
4747 | ||||
4748 | /* Given an ELF BFD, add symbols to the global hash table as | |||
4749 | appropriate. */ | |||
4750 | ||||
4751 | bfd_boolean | |||
4752 | bfd_elf_link_add_symbols (bfd *abfd, struct bfd_link_info *info) | |||
4753 | { | |||
4754 | switch (bfd_get_format (abfd)((abfd)->format)) | |||
4755 | { | |||
4756 | case bfd_object: | |||
4757 | return elf_link_add_object_symbols (abfd, info); | |||
4758 | case bfd_archive: | |||
4759 | return elf_link_add_archive_symbols (abfd, info); | |||
4760 | default: | |||
4761 | bfd_set_error (bfd_error_wrong_format); | |||
4762 | return FALSE0; | |||
4763 | } | |||
4764 | } | |||
4765 | ||||
4766 | /* This function will be called though elf_link_hash_traverse to store | |||
4767 | all hash value of the exported symbols in an array. */ | |||
4768 | ||||
4769 | static bfd_boolean | |||
4770 | elf_collect_hash_codes (struct elf_link_hash_entry *h, void *data) | |||
4771 | { | |||
4772 | unsigned long **valuep = data; | |||
4773 | const char *name; | |||
4774 | char *p; | |||
4775 | unsigned long ha; | |||
4776 | char *alc = NULL((void*)0); | |||
4777 | ||||
4778 | if (h->root.type == bfd_link_hash_warning) | |||
4779 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
4780 | ||||
4781 | /* Ignore indirect symbols. These are added by the versioning code. */ | |||
4782 | if (h->dynindx == -1) | |||
4783 | return TRUE1; | |||
4784 | ||||
4785 | name = h->root.root.string; | |||
4786 | p = strchr (name, ELF_VER_CHR'@'); | |||
4787 | if (p != NULL((void*)0)) | |||
4788 | { | |||
4789 | alc = bfd_malloc (p - name + 1); | |||
4790 | memcpy (alc, name, p - name); | |||
4791 | alc[p - name] = '\0'; | |||
4792 | name = alc; | |||
4793 | } | |||
4794 | ||||
4795 | /* Compute the hash value. */ | |||
4796 | ha = bfd_elf_hash (name); | |||
4797 | ||||
4798 | /* Store the found hash value in the array given as the argument. */ | |||
4799 | *(*valuep)++ = ha; | |||
4800 | ||||
4801 | /* And store it in the struct so that we can put it in the hash table | |||
4802 | later. */ | |||
4803 | h->u.elf_hash_value = ha; | |||
4804 | ||||
4805 | if (alc != NULL((void*)0)) | |||
4806 | free (alc); | |||
4807 | ||||
4808 | return TRUE1; | |||
4809 | } | |||
4810 | ||||
4811 | struct collect_gnu_hash_codes | |||
4812 | { | |||
4813 | bfd *output_bfd; | |||
4814 | const struct elf_backend_data *bed; | |||
4815 | unsigned long int nsyms; | |||
4816 | unsigned long int maskbits; | |||
4817 | unsigned long int *hashcodes; | |||
4818 | unsigned long int *hashval; | |||
4819 | unsigned long int *indx; | |||
4820 | unsigned long int *counts; | |||
4821 | bfd_vma *bitmask; | |||
4822 | bfd_byte *contents; | |||
4823 | long int min_dynindx; | |||
4824 | unsigned long int bucketcount; | |||
4825 | unsigned long int symindx; | |||
4826 | long int local_indx; | |||
4827 | long int shift1, shift2; | |||
4828 | unsigned long int mask; | |||
4829 | }; | |||
4830 | ||||
4831 | /* This function will be called though elf_link_hash_traverse to store | |||
4832 | all hash value of the exported symbols in an array. */ | |||
4833 | ||||
4834 | static bfd_boolean | |||
4835 | elf_collect_gnu_hash_codes (struct elf_link_hash_entry *h, void *data) | |||
4836 | { | |||
4837 | struct collect_gnu_hash_codes *s = data; | |||
4838 | const char *name; | |||
4839 | char *p; | |||
4840 | unsigned long ha; | |||
4841 | char *alc = NULL((void*)0); | |||
4842 | ||||
4843 | if (h->root.type == bfd_link_hash_warning) | |||
4844 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
4845 | ||||
4846 | /* Ignore indirect symbols. These are added by the versioning code. */ | |||
4847 | if (h->dynindx == -1) | |||
4848 | return TRUE1; | |||
4849 | ||||
4850 | /* Ignore also local symbols and undefined symbols. */ | |||
4851 | if (! (*s->bed->elf_hash_symbol) (h)) | |||
4852 | return TRUE1; | |||
4853 | ||||
4854 | name = h->root.root.string; | |||
4855 | p = strchr (name, ELF_VER_CHR'@'); | |||
4856 | if (p != NULL((void*)0)) | |||
4857 | { | |||
4858 | alc = bfd_malloc (p - name + 1); | |||
4859 | memcpy (alc, name, p - name); | |||
4860 | alc[p - name] = '\0'; | |||
4861 | name = alc; | |||
4862 | } | |||
4863 | ||||
4864 | /* Compute the hash value. */ | |||
4865 | ha = bfd_elf_gnu_hash (name); | |||
4866 | ||||
4867 | /* Store the found hash value in the array for compute_bucket_count, | |||
4868 | and also for .dynsym reordering purposes. */ | |||
4869 | s->hashcodes[s->nsyms] = ha; | |||
4870 | s->hashval[h->dynindx] = ha; | |||
4871 | ++s->nsyms; | |||
4872 | if (s->min_dynindx < 0 || s->min_dynindx > h->dynindx) | |||
4873 | s->min_dynindx = h->dynindx; | |||
4874 | ||||
4875 | if (alc != NULL((void*)0)) | |||
4876 | free (alc); | |||
4877 | ||||
4878 | return TRUE1; | |||
4879 | } | |||
4880 | ||||
4881 | /* This function will be called though elf_link_hash_traverse to do | |||
4882 | final dynaminc symbol renumbering. */ | |||
4883 | ||||
4884 | static bfd_boolean | |||
4885 | elf_renumber_gnu_hash_syms (struct elf_link_hash_entry *h, void *data) | |||
4886 | { | |||
4887 | struct collect_gnu_hash_codes *s = data; | |||
4888 | unsigned long int bucket; | |||
4889 | unsigned long int val; | |||
4890 | ||||
4891 | if (h->root.type == bfd_link_hash_warning) | |||
4892 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
4893 | ||||
4894 | /* Ignore indirect symbols. */ | |||
4895 | if (h->dynindx == -1) | |||
4896 | return TRUE1; | |||
4897 | ||||
4898 | /* Ignore also local symbols and undefined symbols. */ | |||
4899 | if (! (*s->bed->elf_hash_symbol) (h)) | |||
4900 | { | |||
4901 | if (h->dynindx >= s->min_dynindx) | |||
4902 | h->dynindx = s->local_indx++; | |||
4903 | return TRUE1; | |||
4904 | } | |||
4905 | ||||
4906 | bucket = s->hashval[h->dynindx] % s->bucketcount; | |||
4907 | val = (s->hashval[h->dynindx] >> s->shift1) | |||
4908 | & ((s->maskbits >> s->shift1) - 1); | |||
4909 | s->bitmask[val] |= ((bfd_vma) 1) << (s->hashval[h->dynindx] & s->mask); | |||
4910 | s->bitmask[val] | |||
4911 | |= ((bfd_vma) 1) << ((s->hashval[h->dynindx] >> s->shift2) & s->mask); | |||
4912 | val = s->hashval[h->dynindx] & ~(unsigned long int) 1; | |||
4913 | if (s->counts[bucket] == 1) | |||
4914 | /* Last element terminates the chain. */ | |||
4915 | val |= 1; | |||
4916 | bfd_put_32 (s->output_bfd, val,((*((s->output_bfd)->xvec->bfd_putx32)) ((val),(s-> contents + (s->indx[bucket] - s->symindx) * 4))) | |||
4917 | s->contents + (s->indx[bucket] - s->symindx) * 4)((*((s->output_bfd)->xvec->bfd_putx32)) ((val),(s-> contents + (s->indx[bucket] - s->symindx) * 4))); | |||
4918 | --s->counts[bucket]; | |||
4919 | h->dynindx = s->indx[bucket]++; | |||
4920 | return TRUE1; | |||
4921 | } | |||
4922 | ||||
4923 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ | |||
4924 | ||||
4925 | bfd_boolean | |||
4926 | _bfd_elf_hash_symbol (struct elf_link_hash_entry *h) | |||
4927 | { | |||
4928 | return !(h->forced_local | |||
4929 | || h->root.type == bfd_link_hash_undefined | |||
4930 | || h->root.type == bfd_link_hash_undefweak | |||
4931 | || ((h->root.type == bfd_link_hash_defined | |||
4932 | || h->root.type == bfd_link_hash_defweak) | |||
4933 | && h->root.u.def.section->output_section == NULL((void*)0))); | |||
4934 | } | |||
4935 | ||||
4936 | /* Array used to determine the number of hash table buckets to use | |||
4937 | based on the number of symbols there are. If there are fewer than | |||
4938 | 3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets, | |||
4939 | fewer than 37 we use 17 buckets, and so forth. We never use more | |||
4940 | than 32771 buckets. */ | |||
4941 | ||||
4942 | static const size_t elf_buckets[] = | |||
4943 | { | |||
4944 | 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209, | |||
4945 | 16411, 32771, 0 | |||
4946 | }; | |||
4947 | ||||
4948 | /* Compute bucket count for hashing table. We do not use a static set | |||
4949 | of possible tables sizes anymore. Instead we determine for all | |||
4950 | possible reasonable sizes of the table the outcome (i.e., the | |||
4951 | number of collisions etc) and choose the best solution. The | |||
4952 | weighting functions are not too simple to allow the table to grow | |||
4953 | without bounds. Instead one of the weighting factors is the size. | |||
4954 | Therefore the result is always a good payoff between few collisions | |||
4955 | (= short chain lengths) and table size. */ | |||
4956 | static size_t | |||
4957 | compute_bucket_count (struct bfd_link_info *info, unsigned long int *hashcodes, | |||
4958 | unsigned long int nsyms, int gnu_hash) | |||
4959 | { | |||
4960 | size_t dynsymcount = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynsymcount; | |||
4961 | size_t best_size = 0; | |||
4962 | unsigned long int i; | |||
4963 | bfd_size_type amt; | |||
4964 | ||||
4965 | /* We have a problem here. The following code to optimize the table | |||
4966 | size requires an integer type with more the 32 bits. If | |||
4967 | BFD_HOST_U_64_BIT is set we know about such a type. */ | |||
4968 | #ifdef BFD_HOST_U_64_BITunsigned long | |||
4969 | if (info->optimize) | |||
4970 | { | |||
4971 | size_t minsize; | |||
4972 | size_t maxsize; | |||
4973 | BFD_HOST_U_64_BITunsigned long best_chlen = ~((BFD_HOST_U_64_BITunsigned long) 0); | |||
4974 | bfd *dynobj = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynobj; | |||
4975 | const struct elf_backend_data *bed = get_elf_backend_data (dynobj)((const struct elf_backend_data *) (dynobj)->xvec->backend_data ); | |||
4976 | unsigned long int *counts; | |||
4977 | ||||
4978 | /* Possible optimization parameters: if we have NSYMS symbols we say | |||
4979 | that the hashing table must at least have NSYMS/4 and at most | |||
4980 | 2*NSYMS buckets. */ | |||
4981 | minsize = nsyms / 4; | |||
4982 | if (minsize == 0) | |||
4983 | minsize = 1; | |||
4984 | best_size = maxsize = nsyms * 2; | |||
4985 | if (gnu_hash) | |||
4986 | { | |||
4987 | if (minsize < 2) | |||
4988 | minsize = 2; | |||
4989 | if ((best_size & 31) == 0) | |||
4990 | ++best_size; | |||
4991 | } | |||
4992 | ||||
4993 | /* Create array where we count the collisions in. We must use bfd_malloc | |||
4994 | since the size could be large. */ | |||
4995 | amt = maxsize; | |||
4996 | amt *= sizeof (unsigned long int); | |||
4997 | counts = bfd_malloc (amt); | |||
4998 | if (counts == NULL((void*)0)) | |||
4999 | return 0; | |||
5000 | ||||
5001 | /* Compute the "optimal" size for the hash table. The criteria is a | |||
5002 | minimal chain length. The minor criteria is (of course) the size | |||
5003 | of the table. */ | |||
5004 | for (i = minsize; i < maxsize; ++i) | |||
5005 | { | |||
5006 | /* Walk through the array of hashcodes and count the collisions. */ | |||
5007 | BFD_HOST_U_64_BITunsigned long max; | |||
5008 | unsigned long int j; | |||
5009 | unsigned long int fact; | |||
5010 | ||||
5011 | if (gnu_hash && (i & 31) == 0) | |||
5012 | continue; | |||
5013 | ||||
5014 | memset (counts, '\0', i * sizeof (unsigned long int)); | |||
5015 | ||||
5016 | /* Determine how often each hash bucket is used. */ | |||
5017 | for (j = 0; j < nsyms; ++j) | |||
5018 | ++counts[hashcodes[j] % i]; | |||
5019 | ||||
5020 | /* For the weight function we need some information about the | |||
5021 | pagesize on the target. This is information need not be 100% | |||
5022 | accurate. Since this information is not available (so far) we | |||
5023 | define it here to a reasonable default value. If it is crucial | |||
5024 | to have a better value some day simply define this value. */ | |||
5025 | # ifndef BFD_TARGET_PAGESIZE(4096) | |||
5026 | # define BFD_TARGET_PAGESIZE(4096) (4096) | |||
5027 | # endif | |||
5028 | ||||
5029 | /* We in any case need 2 + DYNSYMCOUNT entries for the size values | |||
5030 | and the chains. */ | |||
5031 | max = (2 + dynsymcount) * bed->s->sizeof_hash_entry; | |||
5032 | ||||
5033 | # if 1 | |||
5034 | /* Variant 1: optimize for short chains. We add the squares | |||
5035 | of all the chain lengths (which favors many small chain | |||
5036 | over a few long chains). */ | |||
5037 | for (j = 0; j < i; ++j) | |||
5038 | max += counts[j] * counts[j]; | |||
5039 | ||||
5040 | /* This adds penalties for the overall size of the table. */ | |||
5041 | fact = i / (BFD_TARGET_PAGESIZE(4096) / bed->s->sizeof_hash_entry) + 1; | |||
5042 | max *= fact * fact; | |||
5043 | # else | |||
5044 | /* Variant 2: Optimize a lot more for small table. Here we | |||
5045 | also add squares of the size but we also add penalties for | |||
5046 | empty slots (the +1 term). */ | |||
5047 | for (j = 0; j < i; ++j) | |||
5048 | max += (1 + counts[j]) * (1 + counts[j]); | |||
5049 | ||||
5050 | /* The overall size of the table is considered, but not as | |||
5051 | strong as in variant 1, where it is squared. */ | |||
5052 | fact = i / (BFD_TARGET_PAGESIZE(4096) / bed->s->sizeof_hash_entry) + 1; | |||
5053 | max *= fact; | |||
5054 | # endif | |||
5055 | ||||
5056 | /* Compare with current best results. */ | |||
5057 | if (max < best_chlen) | |||
5058 | { | |||
5059 | best_chlen = max; | |||
5060 | best_size = i; | |||
5061 | } | |||
5062 | } | |||
5063 | ||||
5064 | free (counts); | |||
5065 | } | |||
5066 | else | |||
5067 | #endif /* defined (BFD_HOST_U_64_BIT) */ | |||
5068 | { | |||
5069 | /* This is the fallback solution if no 64bit type is available or if we | |||
5070 | are not supposed to spend much time on optimizations. We select the | |||
5071 | bucket count using a fixed set of numbers. */ | |||
5072 | for (i = 0; elf_buckets[i] != 0; i++) | |||
5073 | { | |||
5074 | best_size = elf_buckets[i]; | |||
5075 | if (nsyms < elf_buckets[i + 1]) | |||
5076 | break; | |||
5077 | } | |||
5078 | if (gnu_hash && best_size < 2) | |||
5079 | best_size = 2; | |||
5080 | } | |||
5081 | ||||
5082 | return best_size; | |||
5083 | } | |||
5084 | ||||
5085 | /* Set up the sizes and contents of the ELF dynamic sections. This is | |||
5086 | called by the ELF linker emulation before_allocation routine. We | |||
5087 | must set the sizes of the sections before the linker sets the | |||
5088 | addresses of the various sections. */ | |||
5089 | ||||
5090 | bfd_boolean | |||
5091 | bfd_elf_size_dynamic_sections (bfd *output_bfd, | |||
5092 | const char *soname, | |||
5093 | const char *rpath, | |||
5094 | const char *filter_shlib, | |||
5095 | const char * const *auxiliary_filters, | |||
5096 | struct bfd_link_info *info, | |||
5097 | asection **sinterpptr, | |||
5098 | struct bfd_elf_version_tree *verdefs) | |||
5099 | { | |||
5100 | bfd_size_type soname_indx; | |||
5101 | bfd *dynobj; | |||
5102 | const struct elf_backend_data *bed; | |||
5103 | struct elf_assign_sym_version_info asvinfo; | |||
5104 | ||||
5105 | *sinterpptr = NULL((void*)0); | |||
5106 | ||||
5107 | soname_indx = (bfd_size_type) -1; | |||
5108 | ||||
5109 | if (!is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
| ||||
5110 | return TRUE1; | |||
5111 | ||||
5112 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->relro = info->relro; | |||
5113 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->wxneeded = info->wxneeded; | |||
5114 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->executable = info->executable; | |||
5115 | if (info->execstack) | |||
5116 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->stack_flags = PF_R(1 << 2) | PF_W(1 << 1) | PF_X(1 << 0); | |||
5117 | else if (info->noexecstack) | |||
5118 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->stack_flags = PF_R(1 << 2) | PF_W(1 << 1); | |||
5119 | else | |||
5120 | { | |||
5121 | bfd *inputobj; | |||
5122 | asection *notesec = NULL((void*)0); | |||
5123 | int exec = 0; | |||
5124 | ||||
5125 | for (inputobj = info->input_bfds; | |||
5126 | inputobj; | |||
5127 | inputobj = inputobj->link_next) | |||
5128 | { | |||
5129 | asection *s; | |||
5130 | ||||
5131 | if (inputobj->flags & (DYNAMIC0x40 | BFD_LINKER_CREATED0x2000)) | |||
5132 | continue; | |||
5133 | s = bfd_get_section_by_name (inputobj, ".note.GNU-stack"); | |||
5134 | if (s) | |||
5135 | { | |||
5136 | if (s->flags & SEC_CODE0x010) | |||
5137 | exec = PF_X(1 << 0); | |||
5138 | notesec = s; | |||
5139 | } | |||
5140 | else | |||
5141 | exec = PF_X(1 << 0); | |||
5142 | } | |||
5143 | if (notesec) | |||
5144 | { | |||
5145 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->stack_flags = PF_R(1 << 2) | PF_W(1 << 1) | exec; | |||
5146 | if (exec && info->relocatable | |||
5147 | && notesec->output_section != bfd_abs_section_ptr((asection *) &bfd_abs_section)) | |||
5148 | notesec->output_section->flags |= SEC_CODE0x010; | |||
5149 | } | |||
5150 | } | |||
5151 | ||||
5152 | /* Any syms created from now on start with -1 in | |||
5153 | got.refcount/offset and plt.refcount/offset. */ | |||
5154 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->init_got_refcount | |||
5155 | = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->init_got_offset; | |||
5156 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->init_plt_refcount | |||
5157 | = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->init_plt_offset; | |||
5158 | ||||
5159 | /* The backend may have to create some sections regardless of whether | |||
5160 | we're dynamic or not. */ | |||
5161 | bed = get_elf_backend_data (output_bfd)((const struct elf_backend_data *) (output_bfd)->xvec-> backend_data); | |||
5162 | if (bed->elf_backend_always_size_sections | |||
5163 | && ! (*bed->elf_backend_always_size_sections) (output_bfd, info)) | |||
5164 | return FALSE0; | |||
5165 | ||||
5166 | dynobj = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynobj; | |||
5167 | ||||
5168 | /* If there were no dynamic objects in the link, there is nothing to | |||
5169 | do here. */ | |||
5170 | if (dynobj == NULL((void*)0)) | |||
5171 | return TRUE1; | |||
5172 | ||||
5173 | if (! _bfd_elf_maybe_strip_eh_frame_hdr (info)) | |||
5174 | return FALSE0; | |||
5175 | ||||
5176 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynamic_sections_created) | |||
5177 | { | |||
5178 | struct elf_info_failed eif; | |||
5179 | struct elf_link_hash_entry *h; | |||
5180 | asection *dynstr; | |||
5181 | struct bfd_elf_version_tree *t; | |||
5182 | struct bfd_elf_version_expr *d; | |||
5183 | asection *s; | |||
5184 | bfd_boolean all_defined; | |||
5185 | ||||
5186 | *sinterpptr = bfd_get_section_by_name (dynobj, ".interp"); | |||
5187 | ||||
5188 | if (soname != NULL((void*)0)) | |||
5189 | { | |||
5190 | soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5191 | soname, TRUE1); | |||
5192 | if (soname_indx == (bfd_size_type) -1 | |||
5193 | || !_bfd_elf_add_dynamic_entry (info, DT_SONAME14, soname_indx)) | |||
5194 | return FALSE0; | |||
5195 | } | |||
5196 | ||||
5197 | if (info->symbolic) | |||
5198 | { | |||
5199 | if (!_bfd_elf_add_dynamic_entry (info, DT_SYMBOLIC16, 0)) | |||
5200 | return FALSE0; | |||
5201 | info->flags |= DF_SYMBOLIC(1 << 1); | |||
5202 | } | |||
5203 | ||||
5204 | if (rpath != NULL((void*)0)) | |||
5205 | { | |||
5206 | bfd_size_type indx; | |||
5207 | ||||
5208 | indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, rpath, | |||
5209 | TRUE1); | |||
5210 | if (indx == (bfd_size_type) -1 | |||
5211 | || !_bfd_elf_add_dynamic_entry (info, DT_RPATH15, indx)) | |||
5212 | return FALSE0; | |||
5213 | ||||
5214 | if (info->new_dtags) | |||
5215 | { | |||
5216 | _bfd_elf_strtab_addref (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, indx); | |||
5217 | if (!_bfd_elf_add_dynamic_entry (info, DT_RUNPATH29, indx)) | |||
5218 | return FALSE0; | |||
5219 | } | |||
5220 | } | |||
5221 | ||||
5222 | if (filter_shlib != NULL((void*)0)) | |||
5223 | { | |||
5224 | bfd_size_type indx; | |||
5225 | ||||
5226 | indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5227 | filter_shlib, TRUE1); | |||
5228 | if (indx == (bfd_size_type) -1 | |||
5229 | || !_bfd_elf_add_dynamic_entry (info, DT_FILTER0x7fffffff, indx)) | |||
5230 | return FALSE0; | |||
5231 | } | |||
5232 | ||||
5233 | if (auxiliary_filters != NULL((void*)0)) | |||
5234 | { | |||
5235 | const char * const *p; | |||
5236 | ||||
5237 | for (p = auxiliary_filters; *p != NULL((void*)0); p++) | |||
5238 | { | |||
5239 | bfd_size_type indx; | |||
5240 | ||||
5241 | indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5242 | *p, TRUE1); | |||
5243 | if (indx == (bfd_size_type) -1 | |||
5244 | || !_bfd_elf_add_dynamic_entry (info, DT_AUXILIARY0x7ffffffd, indx)) | |||
5245 | return FALSE0; | |||
5246 | } | |||
5247 | } | |||
5248 | ||||
5249 | eif.info = info; | |||
5250 | eif.verdefs = verdefs; | |||
5251 | eif.failed = FALSE0; | |||
5252 | ||||
5253 | /* If we are supposed to export all symbols into the dynamic symbol | |||
5254 | table (this is not the normal case), then do so. */ | |||
5255 | if (info->export_dynamic) | |||
5256 | { | |||
5257 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_export_symbol), (&eif))) | |||
5258 | _bfd_elf_export_symbol,(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_export_symbol), (&eif))) | |||
5259 | &eif)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_export_symbol), (&eif))); | |||
5260 | if (eif.failed) | |||
5261 | return FALSE0; | |||
5262 | } | |||
5263 | ||||
5264 | /* Make all global versions with definition. */ | |||
5265 | for (t = verdefs; t != NULL((void*)0); t = t->next) | |||
5266 | for (d = t->globals.list; d != NULL((void*)0); d = d->next) | |||
5267 | if (!d->symver && d->symbol) | |||
5268 | { | |||
5269 | const char *verstr, *name; | |||
5270 | size_t namelen, verlen, newlen; | |||
5271 | char *newname, *p; | |||
5272 | struct elf_link_hash_entry *newh; | |||
5273 | ||||
5274 | name = d->symbol; | |||
5275 | namelen = strlen (name); | |||
5276 | verstr = t->name; | |||
5277 | verlen = strlen (verstr); | |||
5278 | newlen = namelen + verlen + 3; | |||
5279 | ||||
5280 | newname = bfd_malloc (newlen); | |||
5281 | if (newname == NULL((void*)0)) | |||
5282 | return FALSE0; | |||
5283 | memcpy (newname, name, namelen); | |||
5284 | ||||
5285 | /* Check the hidden versioned definition. */ | |||
5286 | p = newname + namelen; | |||
5287 | *p++ = ELF_VER_CHR'@'; | |||
5288 | memcpy (p, verstr, verlen + 1); | |||
5289 | newh = elf_link_hash_lookup (elf_hash_table (info),((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( newname), (0), (0), (0))) | |||
5290 | newname, FALSE, FALSE,((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( newname), (0), (0), (0))) | |||
5291 | FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( newname), (0), (0), (0))); | |||
5292 | if (newh == NULL((void*)0) | |||
5293 | || (newh->root.type != bfd_link_hash_defined | |||
5294 | && newh->root.type != bfd_link_hash_defweak)) | |||
5295 | { | |||
5296 | /* Check the default versioned definition. */ | |||
5297 | *p++ = ELF_VER_CHR'@'; | |||
5298 | memcpy (p, verstr, verlen + 1); | |||
5299 | newh = elf_link_hash_lookup (elf_hash_table (info),((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( newname), (0), (0), (0))) | |||
5300 | newname, FALSE, FALSE,((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( newname), (0), (0), (0))) | |||
5301 | FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( newname), (0), (0), (0))); | |||
5302 | } | |||
5303 | free (newname); | |||
5304 | ||||
5305 | /* Mark this version if there is a definition and it is | |||
5306 | not defined in a shared object. */ | |||
5307 | if (newh != NULL((void*)0) | |||
5308 | && !newh->def_dynamic | |||
5309 | && (newh->root.type == bfd_link_hash_defined | |||
5310 | || newh->root.type == bfd_link_hash_defweak)) | |||
5311 | d->symver = 1; | |||
5312 | } | |||
5313 | ||||
5314 | /* Attach all the symbols to their version information. */ | |||
5315 | asvinfo.output_bfd = output_bfd; | |||
5316 | asvinfo.info = info; | |||
5317 | asvinfo.verdefs = verdefs; | |||
5318 | asvinfo.failed = FALSE0; | |||
5319 | ||||
5320 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_link_assign_sym_version), (&asvinfo ))) | |||
5321 | _bfd_elf_link_assign_sym_version,(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_link_assign_sym_version), (&asvinfo ))) | |||
5322 | &asvinfo)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_link_assign_sym_version), (&asvinfo ))); | |||
5323 | if (asvinfo.failed) | |||
5324 | return FALSE0; | |||
5325 | ||||
5326 | if (!info->allow_undefined_version) | |||
5327 | { | |||
5328 | /* Check if all global versions have a definition. */ | |||
5329 | all_defined = TRUE1; | |||
5330 | for (t = verdefs; t != NULL((void*)0); t = t->next) | |||
5331 | for (d = t->globals.list; d != NULL((void*)0); d = d->next) | |||
5332 | if (!d->symver && !d->script) | |||
5333 | { | |||
5334 | (*_bfd_error_handler) | |||
5335 | (_("%s: undefined version: %s")("%s: undefined version: %s"), | |||
5336 | d->pattern, t->name); | |||
5337 | all_defined = FALSE0; | |||
5338 | } | |||
5339 | ||||
5340 | if (!all_defined) | |||
5341 | { | |||
5342 | bfd_set_error (bfd_error_bad_value); | |||
5343 | return FALSE0; | |||
5344 | } | |||
5345 | } | |||
5346 | ||||
5347 | /* Find all symbols which were defined in a dynamic object and make | |||
5348 | the backend pick a reasonable value for them. */ | |||
5349 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_adjust_dynamic_symbol), (&eif))) | |||
5350 | _bfd_elf_adjust_dynamic_symbol,(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_adjust_dynamic_symbol), (&eif))) | |||
5351 | &eif)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_adjust_dynamic_symbol), (&eif))); | |||
5352 | if (eif.failed) | |||
5353 | return FALSE0; | |||
5354 | ||||
5355 | /* Add some entries to the .dynamic section. We fill in some of the | |||
5356 | values later, in bfd_elf_final_link, but we must add the entries | |||
5357 | now so that we know the final size of the .dynamic section. */ | |||
5358 | ||||
5359 | /* If there are initialization and/or finalization functions to | |||
5360 | call then add the corresponding DT_INIT/DT_FINI entries. */ | |||
5361 | h = (info->init_function | |||
5362 | ? elf_link_hash_lookup (elf_hash_table (info),((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( info->init_function), (0), (0), (0))) | |||
5363 | info->init_function, FALSE,((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( info->init_function), (0), (0), (0))) | |||
5364 | FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( info->init_function), (0), (0), (0))) | |||
5365 | : NULL((void*)0)); | |||
5366 | if (h != NULL((void*)0) | |||
5367 | && (h->ref_regular | |||
5368 | || h->def_regular)) | |||
5369 | { | |||
5370 | if (!_bfd_elf_add_dynamic_entry (info, DT_INIT12, 0)) | |||
5371 | return FALSE0; | |||
5372 | } | |||
5373 | h = (info->fini_function | |||
5374 | ? elf_link_hash_lookup (elf_hash_table (info),((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( info->fini_function), (0), (0), (0))) | |||
5375 | info->fini_function, FALSE,((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( info->fini_function), (0), (0), (0))) | |||
5376 | FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( info->fini_function), (0), (0), (0))) | |||
5377 | : NULL((void*)0)); | |||
5378 | if (h != NULL((void*)0) | |||
5379 | && (h->ref_regular | |||
5380 | || h->def_regular)) | |||
5381 | { | |||
5382 | if (!_bfd_elf_add_dynamic_entry (info, DT_FINI13, 0)) | |||
5383 | return FALSE0; | |||
5384 | } | |||
5385 | ||||
5386 | s = bfd_get_section_by_name (output_bfd, ".preinit_array"); | |||
5387 | if (s != NULL((void*)0) && s->linker_has_input) | |||
5388 | { | |||
5389 | /* DT_PREINIT_ARRAY is not allowed in shared library. */ | |||
5390 | if (! info->executable) | |||
5391 | { | |||
5392 | bfd *sub; | |||
5393 | asection *o; | |||
5394 | ||||
5395 | for (sub = info->input_bfds; sub != NULL((void*)0); | |||
5396 | sub = sub->link_next) | |||
5397 | for (o = sub->sections; o != NULL((void*)0); o = o->next) | |||
5398 | if (elf_section_data (o)((struct bfd_elf_section_data*)(o)->used_by_bfd)->this_hdr.sh_type | |||
5399 | == SHT_PREINIT_ARRAY16) | |||
5400 | { | |||
5401 | (*_bfd_error_handler) | |||
5402 | (_("%B: .preinit_array section is not allowed in DSO")("%B: .preinit_array section is not allowed in DSO"), | |||
5403 | sub); | |||
5404 | break; | |||
5405 | } | |||
5406 | ||||
5407 | bfd_set_error (bfd_error_nonrepresentable_section); | |||
5408 | return FALSE0; | |||
5409 | } | |||
5410 | ||||
5411 | if (!_bfd_elf_add_dynamic_entry (info, DT_PREINIT_ARRAY32, 0) | |||
5412 | || !_bfd_elf_add_dynamic_entry (info, DT_PREINIT_ARRAYSZ33, 0)) | |||
5413 | return FALSE0; | |||
5414 | } | |||
5415 | s = bfd_get_section_by_name (output_bfd, ".init_array"); | |||
5416 | if (s != NULL((void*)0) && s->linker_has_input) | |||
5417 | { | |||
5418 | if (!_bfd_elf_add_dynamic_entry (info, DT_INIT_ARRAY25, 0) | |||
5419 | || !_bfd_elf_add_dynamic_entry (info, DT_INIT_ARRAYSZ27, 0)) | |||
5420 | return FALSE0; | |||
5421 | } | |||
5422 | s = bfd_get_section_by_name (output_bfd, ".fini_array"); | |||
5423 | if (s != NULL((void*)0) && s->linker_has_input) | |||
5424 | { | |||
5425 | if (!_bfd_elf_add_dynamic_entry (info, DT_FINI_ARRAY26, 0) | |||
5426 | || !_bfd_elf_add_dynamic_entry (info, DT_FINI_ARRAYSZ28, 0)) | |||
5427 | return FALSE0; | |||
5428 | } | |||
5429 | ||||
5430 | dynstr = bfd_get_section_by_name (dynobj, ".dynstr"); | |||
5431 | /* If .dynstr is excluded from the link, we don't want any of | |||
5432 | these tags. Strictly, we should be checking each section | |||
5433 | individually; This quick check covers for the case where | |||
5434 | someone does a /DISCARD/ : { *(*) }. */ | |||
5435 | if (dynstr != NULL((void*)0) && dynstr->output_section != bfd_abs_section_ptr((asection *) &bfd_abs_section)) | |||
5436 | { | |||
5437 | bfd_size_type strsize; | |||
5438 | ||||
5439 | strsize = _bfd_elf_strtab_size (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr); | |||
5440 | if ((info->emit_hash | |||
5441 | && !_bfd_elf_add_dynamic_entry (info, DT_HASH4, 0)) | |||
5442 | || (info->emit_gnu_hash | |||
5443 | && !_bfd_elf_add_dynamic_entry (info, DT_GNU_HASH0x6ffffef5, 0)) | |||
5444 | || !_bfd_elf_add_dynamic_entry (info, DT_STRTAB5, 0) | |||
5445 | || !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB6, 0) | |||
5446 | || !_bfd_elf_add_dynamic_entry (info, DT_STRSZ10, strsize) | |||
5447 | || !_bfd_elf_add_dynamic_entry (info, DT_SYMENT11, | |||
5448 | bed->s->sizeof_sym)) | |||
5449 | return FALSE0; | |||
5450 | } | |||
5451 | } | |||
5452 | ||||
5453 | /* The backend must work out the sizes of all the other dynamic | |||
5454 | sections. */ | |||
5455 | if (bed->elf_backend_size_dynamic_sections | |||
5456 | && ! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info)) | |||
5457 | return FALSE0; | |||
5458 | ||||
5459 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynamic_sections_created) | |||
5460 | { | |||
5461 | unsigned long section_sym_count; | |||
5462 | asection *s; | |||
5463 | ||||
5464 | /* Set up the version definition section. */ | |||
5465 | s = bfd_get_section_by_name (dynobj, ".gnu.version_d"); | |||
5466 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5466); } while (0); | |||
5467 | ||||
5468 | /* We may have created additional version definitions if we are | |||
5469 | just linking a regular application. */ | |||
5470 | verdefs = asvinfo.verdefs; | |||
| ||||
5471 | ||||
5472 | /* Skip anonymous version tag. */ | |||
5473 | if (verdefs != NULL((void*)0) && verdefs->vernum == 0) | |||
5474 | verdefs = verdefs->next; | |||
5475 | ||||
5476 | if (verdefs == NULL((void*)0) && !info->create_default_symver) | |||
5477 | s->flags |= SEC_EXCLUDE0x8000; | |||
5478 | else | |||
5479 | { | |||
5480 | unsigned int cdefs; | |||
5481 | bfd_size_type size; | |||
5482 | struct bfd_elf_version_tree *t; | |||
5483 | bfd_byte *p; | |||
5484 | Elf_Internal_Verdef def; | |||
5485 | Elf_Internal_Verdaux defaux; | |||
5486 | struct bfd_link_hash_entry *bh; | |||
5487 | struct elf_link_hash_entry *h; | |||
5488 | const char *name; | |||
5489 | ||||
5490 | cdefs = 0; | |||
5491 | size = 0; | |||
5492 | ||||
5493 | /* Make space for the base version. */ | |||
5494 | size += sizeof (Elf_External_Verdef); | |||
5495 | size += sizeof (Elf_External_Verdaux); | |||
5496 | ++cdefs; | |||
5497 | ||||
5498 | /* Make space for the default version. */ | |||
5499 | if (info->create_default_symver) | |||
5500 | { | |||
5501 | size += sizeof (Elf_External_Verdef); | |||
5502 | ++cdefs; | |||
5503 | } | |||
5504 | ||||
5505 | for (t = verdefs; t != NULL((void*)0); t = t->next) | |||
5506 | { | |||
5507 | struct bfd_elf_version_deps *n; | |||
5508 | ||||
5509 | size += sizeof (Elf_External_Verdef); | |||
5510 | size += sizeof (Elf_External_Verdaux); | |||
5511 | ++cdefs; | |||
5512 | ||||
5513 | for (n = t->deps; n != NULL((void*)0); n = n->next) | |||
5514 | size += sizeof (Elf_External_Verdaux); | |||
5515 | } | |||
5516 | ||||
5517 | s->size = size; | |||
5518 | s->contents = bfd_alloc (output_bfd, s->size); | |||
5519 | if (s->contents == NULL((void*)0) && s->size != 0) | |||
5520 | return FALSE0; | |||
5521 | ||||
5522 | /* Fill in the version definition section. */ | |||
5523 | ||||
5524 | p = s->contents; | |||
5525 | ||||
5526 | def.vd_version = VER_DEF_CURRENT1; | |||
5527 | def.vd_flags = VER_FLG_BASE0x1; | |||
5528 | def.vd_ndx = 1; | |||
5529 | def.vd_cnt = 1; | |||
5530 | if (info->create_default_symver) | |||
5531 | { | |||
5532 | def.vd_aux = 2 * sizeof (Elf_External_Verdef); | |||
5533 | def.vd_next = sizeof (Elf_External_Verdef); | |||
5534 | } | |||
5535 | else | |||
5536 | { | |||
5537 | def.vd_aux = sizeof (Elf_External_Verdef); | |||
5538 | def.vd_next = (sizeof (Elf_External_Verdef) | |||
5539 | + sizeof (Elf_External_Verdaux)); | |||
5540 | } | |||
5541 | ||||
5542 | if (soname_indx != (bfd_size_type) -1) | |||
5543 | { | |||
5544 | _bfd_elf_strtab_addref (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5545 | soname_indx); | |||
5546 | def.vd_hash = bfd_elf_hash (soname); | |||
5547 | defaux.vda_name = soname_indx; | |||
5548 | name = soname; | |||
5549 | } | |||
5550 | else | |||
5551 | { | |||
5552 | bfd_size_type indx; | |||
5553 | ||||
5554 | name = lbasename (output_bfd->filename); | |||
5555 | def.vd_hash = bfd_elf_hash (name); | |||
5556 | indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5557 | name, FALSE0); | |||
5558 | if (indx == (bfd_size_type) -1) | |||
5559 | return FALSE0; | |||
5560 | defaux.vda_name = indx; | |||
5561 | } | |||
5562 | defaux.vda_next = 0; | |||
5563 | ||||
5564 | _bfd_elf_swap_verdef_out (output_bfd, &def, | |||
5565 | (Elf_External_Verdef *) p); | |||
5566 | p += sizeof (Elf_External_Verdef); | |||
5567 | if (info->create_default_symver) | |||
5568 | { | |||
5569 | /* Add a symbol representing this version. */ | |||
5570 | bh = NULL((void*)0); | |||
5571 | if (! (_bfd_generic_link_add_one_symbol | |||
5572 | (info, dynobj, name, BSF_GLOBAL0x02, bfd_abs_section_ptr((asection *) &bfd_abs_section), | |||
5573 | 0, NULL((void*)0), FALSE0, | |||
5574 | get_elf_backend_data (dynobj)((const struct elf_backend_data *) (dynobj)->xvec->backend_data )->collect, &bh))) | |||
5575 | return FALSE0; | |||
5576 | h = (struct elf_link_hash_entry *) bh; | |||
5577 | h->non_elf = 0; | |||
5578 | h->def_regular = 1; | |||
5579 | h->type = STT_OBJECT1; | |||
5580 | h->verinfo.vertree = NULL((void*)0); | |||
5581 | ||||
5582 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
5583 | return FALSE0; | |||
5584 | ||||
5585 | /* Create a duplicate of the base version with the same | |||
5586 | aux block, but different flags. */ | |||
5587 | def.vd_flags = 0; | |||
5588 | def.vd_ndx = 2; | |||
5589 | def.vd_aux = sizeof (Elf_External_Verdef); | |||
5590 | if (verdefs) | |||
5591 | def.vd_next = (sizeof (Elf_External_Verdef) | |||
5592 | + sizeof (Elf_External_Verdaux)); | |||
5593 | else | |||
5594 | def.vd_next = 0; | |||
5595 | _bfd_elf_swap_verdef_out (output_bfd, &def, | |||
5596 | (Elf_External_Verdef *) p); | |||
5597 | p += sizeof (Elf_External_Verdef); | |||
5598 | } | |||
5599 | _bfd_elf_swap_verdaux_out (output_bfd, &defaux, | |||
5600 | (Elf_External_Verdaux *) p); | |||
5601 | p += sizeof (Elf_External_Verdaux); | |||
5602 | ||||
5603 | for (t = verdefs; t != NULL((void*)0); t = t->next) | |||
5604 | { | |||
5605 | unsigned int cdeps; | |||
5606 | struct bfd_elf_version_deps *n; | |||
5607 | ||||
5608 | cdeps = 0; | |||
5609 | for (n = t->deps; n != NULL((void*)0); n = n->next) | |||
5610 | ++cdeps; | |||
5611 | ||||
5612 | /* Add a symbol representing this version. */ | |||
5613 | bh = NULL((void*)0); | |||
5614 | if (! (_bfd_generic_link_add_one_symbol | |||
5615 | (info, dynobj, t->name, BSF_GLOBAL0x02, bfd_abs_section_ptr((asection *) &bfd_abs_section), | |||
5616 | 0, NULL((void*)0), FALSE0, | |||
5617 | get_elf_backend_data (dynobj)((const struct elf_backend_data *) (dynobj)->xvec->backend_data )->collect, &bh))) | |||
5618 | return FALSE0; | |||
5619 | h = (struct elf_link_hash_entry *) bh; | |||
5620 | h->non_elf = 0; | |||
5621 | h->def_regular = 1; | |||
5622 | h->type = STT_OBJECT1; | |||
5623 | h->verinfo.vertree = t; | |||
5624 | ||||
5625 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
5626 | return FALSE0; | |||
5627 | ||||
5628 | def.vd_version = VER_DEF_CURRENT1; | |||
5629 | def.vd_flags = 0; | |||
5630 | if (t->globals.list == NULL((void*)0) | |||
5631 | && t->locals.list == NULL((void*)0) | |||
5632 | && ! t->used) | |||
5633 | def.vd_flags |= VER_FLG_WEAK0x2; | |||
5634 | def.vd_ndx = t->vernum + (info->create_default_symver ? 2 : 1); | |||
5635 | def.vd_cnt = cdeps + 1; | |||
5636 | def.vd_hash = bfd_elf_hash (t->name); | |||
5637 | def.vd_aux = sizeof (Elf_External_Verdef); | |||
5638 | def.vd_next = 0; | |||
5639 | if (t->next != NULL((void*)0)) | |||
5640 | def.vd_next = (sizeof (Elf_External_Verdef) | |||
5641 | + (cdeps + 1) * sizeof (Elf_External_Verdaux)); | |||
5642 | ||||
5643 | _bfd_elf_swap_verdef_out (output_bfd, &def, | |||
5644 | (Elf_External_Verdef *) p); | |||
5645 | p += sizeof (Elf_External_Verdef); | |||
5646 | ||||
5647 | defaux.vda_name = h->dynstr_index; | |||
5648 | _bfd_elf_strtab_addref (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5649 | h->dynstr_index); | |||
5650 | defaux.vda_next = 0; | |||
5651 | if (t->deps != NULL((void*)0)) | |||
5652 | defaux.vda_next = sizeof (Elf_External_Verdaux); | |||
5653 | t->name_indx = defaux.vda_name; | |||
5654 | ||||
5655 | _bfd_elf_swap_verdaux_out (output_bfd, &defaux, | |||
5656 | (Elf_External_Verdaux *) p); | |||
5657 | p += sizeof (Elf_External_Verdaux); | |||
5658 | ||||
5659 | for (n = t->deps; n != NULL((void*)0); n = n->next) | |||
5660 | { | |||
5661 | if (n->version_needed == NULL((void*)0)) | |||
5662 | { | |||
5663 | /* This can happen if there was an error in the | |||
5664 | version script. */ | |||
5665 | defaux.vda_name = 0; | |||
5666 | } | |||
5667 | else | |||
5668 | { | |||
5669 | defaux.vda_name = n->version_needed->name_indx; | |||
5670 | _bfd_elf_strtab_addref (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5671 | defaux.vda_name); | |||
5672 | } | |||
5673 | if (n->next == NULL((void*)0)) | |||
5674 | defaux.vda_next = 0; | |||
5675 | else | |||
5676 | defaux.vda_next = sizeof (Elf_External_Verdaux); | |||
5677 | ||||
5678 | _bfd_elf_swap_verdaux_out (output_bfd, &defaux, | |||
5679 | (Elf_External_Verdaux *) p); | |||
5680 | p += sizeof (Elf_External_Verdaux); | |||
5681 | } | |||
5682 | } | |||
5683 | ||||
5684 | if (!_bfd_elf_add_dynamic_entry (info, DT_VERDEF0x6ffffffc, 0) | |||
5685 | || !_bfd_elf_add_dynamic_entry (info, DT_VERDEFNUM0x6ffffffd, cdefs)) | |||
5686 | return FALSE0; | |||
5687 | ||||
5688 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->cverdefs = cdefs; | |||
5689 | } | |||
5690 | ||||
5691 | if ((info->new_dtags && info->flags) || (info->flags & DF_STATIC_TLS(1 << 4))) | |||
5692 | { | |||
5693 | if (!_bfd_elf_add_dynamic_entry (info, DT_FLAGS30, info->flags)) | |||
5694 | return FALSE0; | |||
5695 | } | |||
5696 | else if (info->flags & DF_BIND_NOW(1 << 3)) | |||
5697 | { | |||
5698 | if (!_bfd_elf_add_dynamic_entry (info, DT_BIND_NOW24, 0)) | |||
5699 | return FALSE0; | |||
5700 | } | |||
5701 | ||||
5702 | if (info->flags_1) | |||
5703 | { | |||
5704 | if (info->executable) | |||
5705 | info->flags_1 &= ~ (DF_1_INITFIRST0x00000020 | |||
5706 | | DF_1_NODELETE0x00000008 | |||
5707 | | DF_1_NOOPEN0x00000040); | |||
5708 | if (!_bfd_elf_add_dynamic_entry (info, DT_FLAGS_10x6ffffffb, info->flags_1)) | |||
5709 | return FALSE0; | |||
5710 | } | |||
5711 | ||||
5712 | /* Work out the size of the version reference section. */ | |||
5713 | ||||
5714 | s = bfd_get_section_by_name (dynobj, ".gnu.version_r"); | |||
5715 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5715); } while (0); | |||
5716 | { | |||
5717 | struct elf_find_verdep_info sinfo; | |||
5718 | ||||
5719 | sinfo.output_bfd = output_bfd; | |||
5720 | sinfo.info = info; | |||
5721 | sinfo.vers = elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->cverdefs; | |||
5722 | if (sinfo.vers == 0) | |||
5723 | sinfo.vers = 1; | |||
5724 | sinfo.failed = FALSE0; | |||
5725 | ||||
5726 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_link_find_version_dependencies), (& sinfo))) | |||
5727 | _bfd_elf_link_find_version_dependencies,(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_link_find_version_dependencies), (& sinfo))) | |||
5728 | &sinfo)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (_bfd_elf_link_find_version_dependencies), (& sinfo))); | |||
5729 | ||||
5730 | if (elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->verref == NULL((void*)0)) | |||
5731 | s->flags |= SEC_EXCLUDE0x8000; | |||
5732 | else | |||
5733 | { | |||
5734 | Elf_Internal_Verneed *t; | |||
5735 | unsigned int size; | |||
5736 | unsigned int crefs; | |||
5737 | bfd_byte *p; | |||
5738 | ||||
5739 | /* Build the version definition section. */ | |||
5740 | size = 0; | |||
5741 | crefs = 0; | |||
5742 | for (t = elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->verref; | |||
5743 | t != NULL((void*)0); | |||
5744 | t = t->vn_nextref) | |||
5745 | { | |||
5746 | Elf_Internal_Vernaux *a; | |||
5747 | ||||
5748 | size += sizeof (Elf_External_Verneed); | |||
5749 | ++crefs; | |||
5750 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
5751 | size += sizeof (Elf_External_Vernaux); | |||
5752 | } | |||
5753 | ||||
5754 | s->size = size; | |||
5755 | s->contents = bfd_alloc (output_bfd, s->size); | |||
5756 | if (s->contents == NULL((void*)0)) | |||
5757 | return FALSE0; | |||
5758 | ||||
5759 | p = s->contents; | |||
5760 | for (t = elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->verref; | |||
5761 | t != NULL((void*)0); | |||
5762 | t = t->vn_nextref) | |||
5763 | { | |||
5764 | unsigned int caux; | |||
5765 | Elf_Internal_Vernaux *a; | |||
5766 | bfd_size_type indx; | |||
5767 | ||||
5768 | caux = 0; | |||
5769 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
5770 | ++caux; | |||
5771 | ||||
5772 | t->vn_version = VER_NEED_CURRENT1; | |||
5773 | t->vn_cnt = caux; | |||
5774 | indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5775 | elf_dt_name (t->vn_bfd)(((t->vn_bfd) -> tdata.elf_obj_data) -> dt_name) != NULL((void*)0) | |||
5776 | ? elf_dt_name (t->vn_bfd)(((t->vn_bfd) -> tdata.elf_obj_data) -> dt_name) | |||
5777 | : lbasename (t->vn_bfd->filename), | |||
5778 | FALSE0); | |||
5779 | if (indx == (bfd_size_type) -1) | |||
5780 | return FALSE0; | |||
5781 | t->vn_file = indx; | |||
5782 | t->vn_aux = sizeof (Elf_External_Verneed); | |||
5783 | if (t->vn_nextref == NULL((void*)0)) | |||
5784 | t->vn_next = 0; | |||
5785 | else | |||
5786 | t->vn_next = (sizeof (Elf_External_Verneed) | |||
5787 | + caux * sizeof (Elf_External_Vernaux)); | |||
5788 | ||||
5789 | _bfd_elf_swap_verneed_out (output_bfd, t, | |||
5790 | (Elf_External_Verneed *) p); | |||
5791 | p += sizeof (Elf_External_Verneed); | |||
5792 | ||||
5793 | for (a = t->vn_auxptr; a != NULL((void*)0); a = a->vna_nextptr) | |||
5794 | { | |||
5795 | a->vna_hash = bfd_elf_hash (a->vna_nodename); | |||
5796 | indx = _bfd_elf_strtab_add (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynstr, | |||
5797 | a->vna_nodename, FALSE0); | |||
5798 | if (indx == (bfd_size_type) -1) | |||
5799 | return FALSE0; | |||
5800 | a->vna_name = indx; | |||
5801 | if (a->vna_nextptr == NULL((void*)0)) | |||
5802 | a->vna_next = 0; | |||
5803 | else | |||
5804 | a->vna_next = sizeof (Elf_External_Vernaux); | |||
5805 | ||||
5806 | _bfd_elf_swap_vernaux_out (output_bfd, a, | |||
5807 | (Elf_External_Vernaux *) p); | |||
5808 | p += sizeof (Elf_External_Vernaux); | |||
5809 | } | |||
5810 | } | |||
5811 | ||||
5812 | if (!_bfd_elf_add_dynamic_entry (info, DT_VERNEED0x6ffffffe, 0) | |||
5813 | || !_bfd_elf_add_dynamic_entry (info, DT_VERNEEDNUM0x6fffffff, crefs)) | |||
5814 | return FALSE0; | |||
5815 | ||||
5816 | elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->cverrefs = crefs; | |||
5817 | } | |||
5818 | } | |||
5819 | ||||
5820 | if ((elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->cverrefs == 0 | |||
5821 | && elf_tdata (output_bfd)((output_bfd) -> tdata.elf_obj_data)->cverdefs == 0) | |||
5822 | || _bfd_elf_link_renumber_dynsyms (output_bfd, info, | |||
5823 | §ion_sym_count) == 0) | |||
5824 | { | |||
5825 | s = bfd_get_section_by_name (dynobj, ".gnu.version"); | |||
5826 | s->flags |= SEC_EXCLUDE0x8000; | |||
5827 | } | |||
5828 | } | |||
5829 | return TRUE1; | |||
5830 | } | |||
5831 | ||||
5832 | bfd_boolean | |||
5833 | bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info) | |||
5834 | { | |||
5835 | if (!is_elf_hash_table (info->hash)(((struct bfd_link_hash_table *) (info->hash))->type == bfd_link_elf_hash_table)) | |||
5836 | return TRUE1; | |||
5837 | ||||
5838 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynamic_sections_created) | |||
5839 | { | |||
5840 | bfd *dynobj; | |||
5841 | const struct elf_backend_data *bed; | |||
5842 | asection *s; | |||
5843 | bfd_size_type dynsymcount; | |||
5844 | unsigned long section_sym_count; | |||
5845 | unsigned int dtagcount; | |||
5846 | ||||
5847 | dynobj = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->dynobj; | |||
5848 | ||||
5849 | /* Assign dynsym indicies. In a shared library we generate a | |||
5850 | section symbol for each output section, which come first. | |||
5851 | Next come all of the back-end allocated local dynamic syms, | |||
5852 | followed by the rest of the global symbols. */ | |||
5853 | ||||
5854 | dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info, | |||
5855 | §ion_sym_count); | |||
5856 | ||||
5857 | /* Work out the size of the symbol version section. */ | |||
5858 | s = bfd_get_section_by_name (dynobj, ".gnu.version"); | |||
5859 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5859); } while (0); | |||
5860 | if (dynsymcount != 0 | |||
5861 | && (s->flags & SEC_EXCLUDE0x8000) == 0) | |||
5862 | { | |||
5863 | s->size = dynsymcount * sizeof (Elf_External_Versym); | |||
5864 | s->contents = bfd_zalloc (output_bfd, s->size); | |||
5865 | if (s->contents == NULL((void*)0)) | |||
5866 | return FALSE0; | |||
5867 | ||||
5868 | if (!_bfd_elf_add_dynamic_entry (info, DT_VERSYM0x6ffffff0, 0)) | |||
5869 | return FALSE0; | |||
5870 | } | |||
5871 | ||||
5872 | /* Set the size of the .dynsym and .hash sections. We counted | |||
5873 | the number of dynamic symbols in elf_link_add_object_symbols. | |||
5874 | We will build the contents of .dynsym and .hash when we build | |||
5875 | the final symbol table, because until then we do not know the | |||
5876 | correct value to give the symbols. We built the .dynstr | |||
5877 | section as we went along in elf_link_add_object_symbols. */ | |||
5878 | s = bfd_get_section_by_name (dynobj, ".dynsym"); | |||
5879 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5879); } while (0); | |||
5880 | bed = get_elf_backend_data (output_bfd)((const struct elf_backend_data *) (output_bfd)->xvec-> backend_data); | |||
5881 | s->size = dynsymcount * bed->s->sizeof_sym; | |||
5882 | ||||
5883 | if (dynsymcount != 0) | |||
5884 | { | |||
5885 | s->contents = bfd_alloc (output_bfd, s->size); | |||
5886 | if (s->contents == NULL((void*)0)) | |||
5887 | return FALSE0; | |||
5888 | ||||
5889 | /* The first entry in .dynsym is a dummy symbol. | |||
5890 | Clear all the section syms, in case we don't output them all. */ | |||
5891 | ++section_sym_count; | |||
5892 | memset (s->contents, 0, section_sym_count * bed->s->sizeof_sym); | |||
5893 | } | |||
5894 | ||||
5895 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->bucketcount = 0; | |||
5896 | ||||
5897 | /* Compute the size of the hashing table. As a side effect this | |||
5898 | computes the hash values for all the names we export. */ | |||
5899 | if (info->emit_hash) | |||
5900 | { | |||
5901 | unsigned long int *hashcodes; | |||
5902 | unsigned long int *hashcodesp; | |||
5903 | bfd_size_type amt; | |||
5904 | unsigned long int nsyms; | |||
5905 | size_t bucketcount; | |||
5906 | size_t hash_entry_size; | |||
5907 | ||||
5908 | /* Compute the hash values for all exported symbols. At the same | |||
5909 | time store the values in an array so that we could use them for | |||
5910 | optimizations. */ | |||
5911 | amt = dynsymcount * sizeof (unsigned long int); | |||
5912 | hashcodes = bfd_malloc (amt); | |||
5913 | if (hashcodes == NULL((void*)0)) | |||
5914 | return FALSE0; | |||
5915 | hashcodesp = hashcodes; | |||
5916 | ||||
5917 | /* Put all hash values in HASHCODES. */ | |||
5918 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_collect_hash_codes), (&hashcodesp))) | |||
5919 | elf_collect_hash_codes, &hashcodesp)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_collect_hash_codes), (&hashcodesp))); | |||
5920 | ||||
5921 | nsyms = hashcodesp - hashcodes; | |||
5922 | bucketcount | |||
5923 | = compute_bucket_count (info, hashcodes, nsyms, 0); | |||
5924 | free (hashcodes); | |||
5925 | ||||
5926 | if (bucketcount == 0) | |||
5927 | return FALSE0; | |||
5928 | ||||
5929 | elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->bucketcount = bucketcount; | |||
5930 | ||||
5931 | s = bfd_get_section_by_name (dynobj, ".hash"); | |||
5932 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5932); } while (0); | |||
5933 | hash_entry_size = elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->this_hdr.sh_entsize; | |||
5934 | s->size = ((2 + bucketcount + dynsymcount) * hash_entry_size); | |||
5935 | s->contents = bfd_zalloc (output_bfd, s->size); | |||
5936 | if (s->contents == NULL((void*)0)) | |||
5937 | return FALSE0; | |||
5938 | ||||
5939 | bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents)((8 * hash_entry_size) == 8 ? ((void) (*((unsigned char *) (s ->contents)) = (bucketcount) & 0xff)) : (8 * hash_entry_size ) == 16 ? ((*((output_bfd)->xvec->bfd_putx16)) ((bucketcount ),(s->contents))) : (8 * hash_entry_size) == 32 ? ((*((output_bfd )->xvec->bfd_putx32)) ((bucketcount),(s->contents))) : (8 * hash_entry_size) == 64 ? ((*((output_bfd)->xvec-> bfd_putx64)) ((bucketcount), (s->contents))) : (_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c", 5939, __PRETTY_FUNCTION__ ), (void) 0)); | |||
5940 | bfd_put (8 * hash_entry_size, output_bfd, dynsymcount,((8 * hash_entry_size) == 8 ? ((void) (*((unsigned char *) (s ->contents + hash_entry_size)) = (dynsymcount) & 0xff) ) : (8 * hash_entry_size) == 16 ? ((*((output_bfd)->xvec-> bfd_putx16)) ((dynsymcount),(s->contents + hash_entry_size ))) : (8 * hash_entry_size) == 32 ? ((*((output_bfd)->xvec ->bfd_putx32)) ((dynsymcount),(s->contents + hash_entry_size ))) : (8 * hash_entry_size) == 64 ? ((*((output_bfd)->xvec ->bfd_putx64)) ((dynsymcount), (s->contents + hash_entry_size ))) : (_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" , 5941, __PRETTY_FUNCTION__), (void) 0)) | |||
5941 | s->contents + hash_entry_size)((8 * hash_entry_size) == 8 ? ((void) (*((unsigned char *) (s ->contents + hash_entry_size)) = (dynsymcount) & 0xff) ) : (8 * hash_entry_size) == 16 ? ((*((output_bfd)->xvec-> bfd_putx16)) ((dynsymcount),(s->contents + hash_entry_size ))) : (8 * hash_entry_size) == 32 ? ((*((output_bfd)->xvec ->bfd_putx32)) ((dynsymcount),(s->contents + hash_entry_size ))) : (8 * hash_entry_size) == 64 ? ((*((output_bfd)->xvec ->bfd_putx64)) ((dynsymcount), (s->contents + hash_entry_size ))) : (_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" , 5941, __PRETTY_FUNCTION__), (void) 0)); | |||
5942 | } | |||
5943 | ||||
5944 | if (info->emit_gnu_hash) | |||
5945 | { | |||
5946 | size_t i, cnt; | |||
5947 | unsigned char *contents; | |||
5948 | struct collect_gnu_hash_codes cinfo; | |||
5949 | bfd_size_type amt; | |||
5950 | size_t bucketcount; | |||
5951 | ||||
5952 | memset (&cinfo, 0, sizeof (cinfo)); | |||
5953 | ||||
5954 | /* Compute the hash values for all exported symbols. At the same | |||
5955 | time store the values in an array so that we could use them for | |||
5956 | optimizations. */ | |||
5957 | amt = dynsymcount * 2 * sizeof (unsigned long int); | |||
5958 | cinfo.hashcodes = bfd_malloc (amt); | |||
5959 | if (cinfo.hashcodes == NULL((void*)0)) | |||
5960 | return FALSE0; | |||
5961 | ||||
5962 | cinfo.hashval = cinfo.hashcodes + dynsymcount; | |||
5963 | cinfo.min_dynindx = -1; | |||
5964 | cinfo.output_bfd = output_bfd; | |||
5965 | cinfo.bed = bed; | |||
5966 | ||||
5967 | /* Put all hash values in HASHCODES. */ | |||
5968 | elf_link_hash_traverse (elf_hash_table (info),(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_collect_gnu_hash_codes), (&cinfo))) | |||
5969 | elf_collect_gnu_hash_codes, &cinfo)(bfd_link_hash_traverse (&(((struct elf_link_hash_table * ) ((info)->hash)))->root, (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (elf_collect_gnu_hash_codes), (&cinfo))); | |||
5970 | ||||
5971 | bucketcount | |||
5972 | = compute_bucket_count (info, cinfo.hashcodes, cinfo.nsyms, 1); | |||
5973 | ||||
5974 | if (bucketcount == 0) | |||
5975 | { | |||
5976 | free (cinfo.hashcodes); | |||
5977 | return FALSE0; | |||
5978 | } | |||
5979 | ||||
5980 | s = bfd_get_section_by_name (dynobj, ".gnu.hash"); | |||
5981 | BFD_ASSERT (s != NULL)do { if (!(s != ((void*)0))) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5981); } while (0); | |||
5982 | ||||
5983 | if (cinfo.nsyms == 0) | |||
5984 | { | |||
5985 | /* Empty .gnu.hash section is special. */ | |||
5986 | BFD_ASSERT (cinfo.min_dynindx == -1)do { if (!(cinfo.min_dynindx == -1)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c" ,5986); } while (0); | |||
5987 | free (cinfo.hashcodes); | |||
5988 | s->size = 5 * 4 + bed->s->arch_size / 8; | |||
5989 | contents = bfd_zalloc (output_bfd, s->size); | |||
5990 | if (contents == NULL((void*)0)) | |||
5991 | return FALSE0; | |||
5992 | s->contents = contents; | |||
5993 | /* 1 empty bucket. */ | |||
5994 | bfd_put_32 (output_bfd, 1, contents)((*((output_bfd)->xvec->bfd_putx32)) ((1),(contents))); | |||
5995 | /* SYMIDX above the special symbol 0. */ | |||
5996 | bfd_put_32 (output_bfd, 1, contents + 4)((*((output_bfd)->xvec->bfd_putx32)) ((1),(contents + 4 ))); | |||
5997 | /* Just one word for bitmask |