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