Changeset 609 for branches/GNU/src/binutils/bfd/elflink.h
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elflink.h
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* ELF linker support. 2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001 2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 3 3 Free Software Foundation, Inc. 4 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 modify8 it under the terms of the GNU General Public License as published by9 the Free Software Foundation; either version 2 of the License, or10 (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 of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU General Public License for more details.16 17 You should have received a copy of the GNU General Public License18 along with this program; if not, write to the Free Software19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */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 20 21 21 /* ELF linker code. */ … … 26 26 struct elf_info_failed 27 27 { 28 b oolean failed;28 bfd_boolean failed; 29 29 struct bfd_link_info *info; 30 struct bfd_elf_version_tree *verdefs; 30 31 }; 31 32 32 static boolean elf_link_add_object_symbols 33 static bfd_boolean is_global_data_symbol_definition 34 PARAMS ((bfd *, Elf_Internal_Sym *)); 35 static bfd_boolean elf_link_is_defined_archive_symbol 36 PARAMS ((bfd *, carsym *)); 37 static bfd_boolean elf_link_add_object_symbols 33 38 PARAMS ((bfd *, struct bfd_link_info *)); 34 static b oolean elf_link_add_archive_symbols39 static bfd_boolean elf_link_add_archive_symbols 35 40 PARAMS ((bfd *, struct bfd_link_info *)); 36 static boolean elf_merge_symbol 37 PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *, 38 asection **, bfd_vma *, struct elf_link_hash_entry **, 39 boolean *, boolean *, boolean *, boolean)); 40 static boolean elf_export_symbol 41 static bfd_boolean elf_merge_symbol 42 PARAMS ((bfd *, struct bfd_link_info *, const char *, 43 Elf_Internal_Sym *, asection **, bfd_vma *, 44 struct elf_link_hash_entry **, bfd_boolean *, bfd_boolean *, 45 bfd_boolean *, bfd_boolean *, bfd_boolean)); 46 static bfd_boolean elf_add_default_symbol 47 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, 48 const char *, Elf_Internal_Sym *, asection **, bfd_vma *, 49 bfd_boolean *, bfd_boolean, bfd_boolean)); 50 static bfd_boolean elf_export_symbol 41 51 PARAMS ((struct elf_link_hash_entry *, PTR)); 42 static boolean elf_fix_symbol_flags 52 static bfd_boolean elf_finalize_dynstr 53 PARAMS ((bfd *, struct bfd_link_info *)); 54 static bfd_boolean elf_fix_symbol_flags 43 55 PARAMS ((struct elf_link_hash_entry *, struct elf_info_failed *)); 44 static b oolean elf_adjust_dynamic_symbol56 static bfd_boolean elf_adjust_dynamic_symbol 45 57 PARAMS ((struct elf_link_hash_entry *, PTR)); 46 static b oolean elf_link_find_version_dependencies58 static bfd_boolean elf_link_find_version_dependencies 47 59 PARAMS ((struct elf_link_hash_entry *, PTR)); 48 static b oolean elf_link_find_version_dependencies60 static bfd_boolean elf_link_assign_sym_version 49 61 PARAMS ((struct elf_link_hash_entry *, PTR)); 50 static b oolean elf_link_assign_sym_version62 static bfd_boolean elf_collect_hash_codes 51 63 PARAMS ((struct elf_link_hash_entry *, PTR)); 52 static boolean elf_collect_hash_codes 53 PARAMS ((struct elf_link_hash_entry *, PTR)); 54 static boolean elf_link_read_relocs_from_section 64 static bfd_boolean elf_link_read_relocs_from_section 55 65 PARAMS ((bfd *, Elf_Internal_Shdr *, PTR, Elf_Internal_Rela *)); 56 static void elf_link_output_relocs 66 static size_t compute_bucket_count 67 PARAMS ((struct bfd_link_info *)); 68 static bfd_boolean elf_link_output_relocs 57 69 PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *)); 58 static b oolean elf_link_size_reloc_section70 static bfd_boolean elf_link_size_reloc_section 59 71 PARAMS ((bfd *, Elf_Internal_Shdr *, asection *)); 60 72 static void elf_link_adjust_relocs 61 73 PARAMS ((bfd *, Elf_Internal_Shdr *, unsigned int, 62 74 struct elf_link_hash_entry **)); 75 static int elf_link_sort_cmp1 76 PARAMS ((const void *, const void *)); 77 static int elf_link_sort_cmp2 78 PARAMS ((const void *, const void *)); 79 static size_t elf_link_sort_relocs 80 PARAMS ((bfd *, struct bfd_link_info *, asection **)); 81 static bfd_boolean elf_section_ignore_discarded_relocs 82 PARAMS ((asection *)); 63 83 64 84 /* Given an ELF BFD, add symbols to the global hash table as 65 85 appropriate. */ 66 86 67 b oolean87 bfd_boolean 68 88 elf_bfd_link_add_symbols (abfd, info) 69 89 bfd *abfd; … … 78 98 default: 79 99 bfd_set_error (bfd_error_wrong_format); 80 return false;100 return FALSE; 81 101 } 82 102 } 83 103 84 104 85 /* Return trueiff this is a non-common, definition of a non-function symbol. */86 static b oolean105 /* Return TRUE iff this is a non-common, definition of a non-function symbol. */ 106 static bfd_boolean 87 107 is_global_data_symbol_definition (abfd, sym) 88 108 bfd * abfd ATTRIBUTE_UNUSED; … … 92 112 if (ELF_ST_BIND (sym->st_info) != STB_GLOBAL 93 113 && ELF_ST_BIND (sym->st_info) < STB_LOOS) 94 return false;114 return FALSE; 95 115 96 116 /* Function symbols do not count. */ 97 117 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC) 98 return false;118 return FALSE; 99 119 100 120 /* If the section is undefined, then so is the symbol. */ 101 121 if (sym->st_shndx == SHN_UNDEF) 102 return false;122 return FALSE; 103 123 104 124 /* If the symbol is defined in the common section, then 105 125 it is a common definition and so does not count. */ 106 126 if (sym->st_shndx == SHN_COMMON) 107 return false;127 return FALSE; 108 128 109 129 /* If the symbol is in a target specific section then we … … 117 137 Even if this is wrong, at least the linker will behave 118 138 in the same way that it used to do. */ 119 return false;120 121 return true;139 return FALSE; 140 141 return TRUE; 122 142 } 123 143 … … 125 145 whose archive map contains a mention of SYMDEF, and determine if 126 146 the symbol is defined in this element. */ 127 static b oolean147 static bfd_boolean 128 148 elf_link_is_defined_archive_symbol (abfd, symdef) 129 149 bfd * abfd; … … 131 151 { 132 152 Elf_Internal_Shdr * hdr; 133 Elf_External_Sym * esym;134 Elf_External_Sym * esymend;135 Elf_External_Sym * buf = NULL;136 size_t symcount;137 size_t extsymcount;138 size_t extsymoff;139 b oolean result = false;153 bfd_size_type symcount; 154 bfd_size_type extsymcount; 155 bfd_size_type extsymoff; 156 Elf_Internal_Sym *isymbuf; 157 Elf_Internal_Sym *isym; 158 Elf_Internal_Sym *isymend; 159 bfd_boolean result; 140 160 141 161 abfd = _bfd_get_elt_at_filepos (abfd, symdef->file_offset); 142 162 if (abfd == (bfd *) NULL) 143 return false;163 return FALSE; 144 164 145 165 if (! bfd_check_format (abfd, bfd_object)) 146 return false;166 return FALSE; 147 167 148 168 /* If we have already included the element containing this symbol in the … … 151 171 (re)include this element. */ 152 172 if (abfd->archive_pass) 153 return false;173 return FALSE; 154 174 155 175 /* Select the appropriate symbol table. */ … … 174 194 } 175 195 176 buf = ((Elf_External_Sym *) 177 bfd_malloc (extsymcount * sizeof (Elf_External_Sym))); 178 if (buf == NULL && extsymcount != 0) 179 return false; 180 181 /* Read in the symbol table. 182 FIXME: This ought to be cached somewhere. */ 183 if (bfd_seek (abfd, 184 hdr->sh_offset + extsymoff * sizeof (Elf_External_Sym), 185 SEEK_SET) != 0 186 || (bfd_read ((PTR) buf, sizeof (Elf_External_Sym), extsymcount, abfd) 187 != extsymcount * sizeof (Elf_External_Sym))) 188 { 189 free (buf); 190 return false; 191 } 196 if (extsymcount == 0) 197 return FALSE; 198 199 /* Read in the symbol table. */ 200 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff, 201 NULL, NULL, NULL); 202 if (isymbuf == NULL) 203 return FALSE; 192 204 193 205 /* Scan the symbol table looking for SYMDEF. */ 194 esymend = buf + extsymcount; 195 for (esym = buf; 196 esym < esymend; 197 esym++) 198 { 199 Elf_Internal_Sym sym; 200 const char * name; 201 202 elf_swap_symbol_in (abfd, esym, & sym); 203 204 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, sym.st_name); 206 result = FALSE; 207 for (isym = isymbuf, isymend = isymbuf + extsymcount; isym < isymend; isym++) 208 { 209 const char *name; 210 211 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, 212 isym->st_name); 205 213 if (name == (const char *) NULL) 206 214 break; … … 208 216 if (strcmp (name, symdef->name) == 0) 209 217 { 210 result = is_global_data_symbol_definition (abfd, &sym);218 result = is_global_data_symbol_definition (abfd, isym); 211 219 break; 212 220 } 213 221 } 214 222 215 free ( buf);223 free (isymbuf); 216 224 217 225 return result; … … 244 252 table until nothing further is resolved. */ 245 253 246 static b oolean254 static bfd_boolean 247 255 elf_link_add_archive_symbols (abfd, info) 248 256 bfd *abfd; … … 250 258 { 251 259 symindex c; 252 b oolean *defined = NULL;253 b oolean *included = NULL;260 bfd_boolean *defined = NULL; 261 bfd_boolean *included = NULL; 254 262 carsym *symdefs; 255 boolean loop; 263 bfd_boolean loop; 264 bfd_size_type amt; 256 265 257 266 if (! bfd_has_map (abfd)) … … 259 268 /* An empty archive is a special case. */ 260 269 if (bfd_openr_next_archived_file (abfd, (bfd *) NULL) == NULL) 261 return true;270 return TRUE; 262 271 bfd_set_error (bfd_error_no_armap); 263 return false;272 return FALSE; 264 273 } 265 274 … … 269 278 c = bfd_ardata (abfd)->symdef_count; 270 279 if (c == 0) 271 return true; 272 defined = (boolean *) bfd_malloc (c * sizeof (boolean)); 273 included = (boolean *) bfd_malloc (c * sizeof (boolean)); 274 if (defined == (boolean *) NULL || included == (boolean *) NULL) 280 return TRUE; 281 amt = c; 282 amt *= sizeof (bfd_boolean); 283 defined = (bfd_boolean *) bfd_zmalloc (amt); 284 included = (bfd_boolean *) bfd_zmalloc (amt); 285 if (defined == (bfd_boolean *) NULL || included == (bfd_boolean *) NULL) 275 286 goto error_return; 276 memset (defined, 0, c * sizeof (boolean));277 memset (included, 0, c * sizeof (boolean));278 287 279 288 symdefs = bfd_ardata (abfd)->symdefs; … … 286 295 carsym *symdefend; 287 296 288 loop = false;297 loop = FALSE; 289 298 last = -1; 290 299 … … 302 311 if (symdef->file_offset == last) 303 312 { 304 included[i] = true;313 included[i] = TRUE; 305 314 continue; 306 315 } 307 316 308 317 h = elf_link_hash_lookup (elf_hash_table (info), symdef->name, 309 false, false, false);318 FALSE, FALSE, FALSE); 310 319 311 320 if (h == NULL) 312 321 { 313 322 char *p, *copy; 323 size_t len, first; 314 324 315 325 /* If this is a default version (the name contains @@), 316 look up the symbol again with out the version. The317 effect is that references to the symbol without the318 version will be matched by the default symbol in the319 archive. */326 look up the symbol again with only one `@' as well 327 as without the version. The effect is that references 328 to the symbol with and without the version will be 329 matched by the default symbol in the archive. */ 320 330 321 331 p = strchr (symdef->name, ELF_VER_CHR); … … 323 333 continue; 324 334 325 copy = bfd_alloc (abfd, p - symdef->name + 1); 335 /* First check with only one `@'. */ 336 len = strlen (symdef->name); 337 copy = bfd_alloc (abfd, (bfd_size_type) len); 326 338 if (copy == NULL) 327 339 goto error_return; 328 memcpy (copy, symdef->name, p - symdef->name); 329 copy[p - symdef->name] = '\0'; 340 first = p - symdef->name + 1; 341 memcpy (copy, symdef->name, first); 342 memcpy (copy + first, symdef->name + first + 1, len - first); 330 343 331 344 h = elf_link_hash_lookup (elf_hash_table (info), copy, 332 false, false, false); 345 FALSE, FALSE, FALSE); 346 347 if (h == NULL) 348 { 349 /* We also need to check references to the symbol 350 without the version. */ 351 352 copy[first - 1] = '\0'; 353 h = elf_link_hash_lookup (elf_hash_table (info), 354 copy, FALSE, FALSE, FALSE); 355 } 333 356 334 357 bfd_release (abfd, copy); … … 358 381 { 359 382 if (h->root.type != bfd_link_hash_undefweak) 360 defined[i] = true;383 defined[i] = TRUE; 361 384 continue; 362 385 } … … 396 419 does make the code less efficient than it could be. */ 397 420 if (undefs_tail != info->hash->undefs_tail) 398 loop = true;421 loop = TRUE; 399 422 400 423 /* Look backward to mark all symbols from this object file … … 403 426 do 404 427 { 405 included[mark] = true;428 included[mark] = TRUE; 406 429 if (mark == 0) 407 430 break; … … 420 443 free (included); 421 444 422 return true;445 return TRUE; 423 446 424 447 error_return: 425 if (defined != (b oolean *) NULL)448 if (defined != (bfd_boolean *) NULL) 426 449 free (defined); 427 if (included != (b oolean *) NULL)450 if (included != (bfd_boolean *) NULL) 428 451 free (included); 429 return false;452 return FALSE; 430 453 } 431 454 … … 442 465 a shared object. */ 443 466 444 static b oolean445 elf_merge_symbol (abfd, info, name, sym, psec, pvalue, sym_hash, 467 static bfd_boolean 468 elf_merge_symbol (abfd, info, name, sym, psec, pvalue, sym_hash, skip, 446 469 override, type_change_ok, size_change_ok, dt_needed) 447 470 bfd *abfd; … … 452 475 bfd_vma *pvalue; 453 476 struct elf_link_hash_entry **sym_hash; 454 boolean *override; 455 boolean *type_change_ok; 456 boolean *size_change_ok; 457 boolean dt_needed; 477 bfd_boolean *skip; 478 bfd_boolean *override; 479 bfd_boolean *type_change_ok; 480 bfd_boolean *size_change_ok; 481 bfd_boolean dt_needed; 458 482 { 459 483 asection *sec; 460 484 struct elf_link_hash_entry *h; 485 struct elf_link_hash_entry *flip; 461 486 int bind; 462 487 bfd *oldbfd; 463 boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon; 464 465 *override = false; 488 bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon; 489 bfd_boolean newweakdef, oldweakdef, newweakundef, oldweakundef; 490 491 *skip = FALSE; 492 *override = FALSE; 466 493 467 494 sec = *psec; … … 469 496 470 497 if (! bfd_is_und_section (sec)) 471 h = elf_link_hash_lookup (elf_hash_table (info), name, true, false, false);498 h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, FALSE, FALSE); 472 499 else 473 500 h = ((struct elf_link_hash_entry *) 474 bfd_wrapped_link_hash_lookup (abfd, info, name, true, false, false));501 bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, FALSE, FALSE)); 475 502 if (h == NULL) 476 return false;503 return FALSE; 477 504 *sym_hash = h; 478 505 … … 480 507 if we are doing an ELF link. */ 481 508 if (info->hash->creator != abfd->xvec) 482 return true;509 return TRUE; 483 510 484 511 /* For merging, we only care about real symbols. */ … … 495 522 { 496 523 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF; 497 return true;524 return TRUE; 498 525 } 499 526 … … 530 557 && ((abfd->flags & DYNAMIC) == 0 531 558 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) 532 return true;559 return TRUE; 533 560 534 561 /* NEWDYN and OLDDYN indicate whether the new or old symbol, … … 536 563 537 564 if ((abfd->flags & DYNAMIC) != 0) 538 newdyn = true;565 newdyn = TRUE; 539 566 else 540 newdyn = false;567 newdyn = FALSE; 541 568 542 569 if (oldbfd != NULL) … … 547 574 548 575 /* This code handles the special SHN_MIPS_{TEXT,DATA} section 549 576 indices used by MIPS ELF. */ 550 577 switch (h->root.type) 551 578 { … … 565 592 566 593 if (hsec == NULL) 567 olddyn = false;594 olddyn = FALSE; 568 595 else 569 596 olddyn = (hsec->symbol->flags & BSF_DYNAMIC) != 0; … … 574 601 575 602 if (bfd_is_und_section (sec) || bfd_is_com_section (sec)) 576 newdef = false;603 newdef = FALSE; 577 604 else 578 newdef = true;605 newdef = TRUE; 579 606 580 607 if (h->root.type == bfd_link_hash_undefined 581 608 || h->root.type == bfd_link_hash_undefweak 582 609 || h->root.type == bfd_link_hash_common) 583 olddef = false;610 olddef = FALSE; 584 611 else 585 olddef = true; 612 olddef = TRUE; 613 614 /* We need to rememeber if a symbol has a definition in a dynamic 615 object or is weak in all dynamic objects. Internal and hidden 616 visibility will make it unavailable to dynamic objects. */ 617 if (newdyn && (h->elf_link_hash_flags & ELF_LINK_DYNAMIC_DEF) == 0) 618 { 619 if (!bfd_is_und_section (sec)) 620 h->elf_link_hash_flags |= ELF_LINK_DYNAMIC_DEF; 621 else 622 { 623 /* Check if this symbol is weak in all dynamic objects. If it 624 is the first time we see it in a dynamic object, we mark 625 if it is weak. Otherwise, we clear it. */ 626 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0) 627 { 628 if (bind == STB_WEAK) 629 h->elf_link_hash_flags |= ELF_LINK_DYNAMIC_WEAK; 630 } 631 else if (bind != STB_WEAK) 632 h->elf_link_hash_flags &= ~ELF_LINK_DYNAMIC_WEAK; 633 } 634 } 635 636 /* If the old symbol has non-default visibility, we ignore the new 637 definition from a dynamic object. */ 638 if (newdyn 639 && ELF_ST_VISIBILITY (h->other) 640 && !bfd_is_und_section (sec)) 641 { 642 *skip = TRUE; 643 /* Make sure this symbol is dynamic. */ 644 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC; 645 /* A protected symbol has external availability. Make sure it is 646 recorded as dynamic. 647 648 FIXME: Should we check type and size for protected symbol? */ 649 if (ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) 650 return _bfd_elf_link_record_dynamic_symbol (info, h); 651 else 652 return TRUE; 653 } 654 else if (!newdyn 655 && ELF_ST_VISIBILITY (sym->st_other) 656 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0) 657 { 658 /* If the new symbol with non-default visibility comes from a 659 relocatable file and the old definition comes from a dynamic 660 object, we remove the old definition. */ 661 if ((*sym_hash)->root.type == bfd_link_hash_indirect) 662 h = *sym_hash; 663 h->root.type = bfd_link_hash_new; 664 h->root.u.undef.abfd = NULL; 665 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) 666 { 667 h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC; 668 h->elf_link_hash_flags |= (ELF_LINK_HASH_REF_DYNAMIC 669 | ELF_LINK_DYNAMIC_DEF); 670 } 671 /* FIXME: Should we check type and size for protected symbol? */ 672 h->size = 0; 673 h->type = 0; 674 return TRUE; 675 } 676 677 /* We need to treat weak definiton right, depending on if there is a 678 definition from a dynamic object. */ 679 if (bind == STB_WEAK) 680 { 681 if (olddef) 682 { 683 newweakdef = TRUE; 684 newweakundef = FALSE; 685 } 686 else 687 { 688 newweakdef = FALSE; 689 newweakundef = TRUE; 690 } 691 } 692 else 693 newweakdef = newweakundef = FALSE; 694 695 /* If the new weak definition comes from a relocatable file and the 696 old symbol comes from a dynamic object, we treat the new one as 697 strong. */ 698 if (newweakdef && !newdyn && olddyn) 699 newweakdef = FALSE; 700 701 if (h->root.type == bfd_link_hash_defweak) 702 { 703 oldweakdef = TRUE; 704 oldweakundef = FALSE; 705 } 706 else if (h->root.type == bfd_link_hash_undefweak) 707 { 708 oldweakdef = FALSE; 709 oldweakundef = TRUE; 710 } 711 else 712 oldweakdef = oldweakundef = FALSE; 713 714 /* If the old weak definition comes from a relocatable file and the 715 new symbol comes from a dynamic object, we treat the old one as 716 strong. */ 717 if (oldweakdef && !olddyn && newdyn) 718 oldweakdef = FALSE; 586 719 587 720 /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old … … 613 746 && (sec->flags & SEC_LOAD) == 0 614 747 && sym->st_size > 0 615 && bind != STB_WEAK 748 && !newweakdef 749 && !newweakundef 616 750 && ELF_ST_TYPE (sym->st_info) != STT_FUNC) 617 newdyncommon = true;751 newdyncommon = TRUE; 618 752 else 619 newdyncommon = false;753 newdyncommon = FALSE; 620 754 621 755 if (olddyn … … 627 761 && h->size > 0 628 762 && h->type != STT_FUNC) 629 olddyncommon = true;763 olddyncommon = TRUE; 630 764 else 631 olddyncommon = false;765 olddyncommon = FALSE; 632 766 633 767 /* It's OK to change the type if either the existing symbol or the … … 636 770 required at the run time. */ 637 771 638 if ((! dt_needed && h->root.type == bfd_link_hash_defweak) 639 || h->root.type == bfd_link_hash_undefweak 640 || bind == STB_WEAK) 641 *type_change_ok = true; 772 if ((! dt_needed && oldweakdef) 773 || oldweakundef 774 || newweakdef 775 || newweakundef) 776 *type_change_ok = TRUE; 642 777 643 778 /* It's OK to change the size if either the existing symbol or the … … 646 781 if (*type_change_ok 647 782 || h->root.type == bfd_link_hash_undefined) 648 *size_change_ok = true;783 *size_change_ok = TRUE; 649 784 650 785 /* If both the old and the new symbols look like common symbols in a … … 657 792 { 658 793 /* Since we think we have two common symbols, issue a multiple 659 660 661 662 794 common warning if desired. Note that we only warn if the 795 size is different. If the size is the same, we simply let 796 the old symbol override the new one as normally happens with 797 symbols defined in dynamic objects. */ 663 798 664 799 if (! ((*info->callbacks->multiple_common) 665 800 (info, h->root.root.string, oldbfd, bfd_link_hash_common, 666 801 h->size, abfd, bfd_link_hash_common, sym->st_size))) 667 return false;802 return FALSE; 668 803 669 804 if (sym->st_size > h->size) 670 805 h->size = sym->st_size; 671 806 672 *size_change_ok = true;807 *size_change_ok = TRUE; 673 808 } 674 809 … … 696 831 && (olddef 697 832 || (h->root.type == bfd_link_hash_common 698 && (bind == STB_WEAK 833 && (newweakdef 834 || newweakundef 699 835 || ELF_ST_TYPE (sym->st_info) == STT_FUNC))) 700 && ( h->root.type != bfd_link_hash_defweak836 && (!oldweakdef 701 837 || dt_needed 702 || bind == STB_WEAK)) 703 { 704 *override = true; 705 newdef = false; 706 newdyncommon = false; 838 || newweakdef 839 || newweakundef)) 840 { 841 *override = TRUE; 842 newdef = FALSE; 843 newdyncommon = FALSE; 707 844 708 845 *psec = sec = bfd_und_section_ptr; 709 *size_change_ok = true;846 *size_change_ok = TRUE; 710 847 711 848 /* If we get here when the old symbol is a common symbol, then 712 713 714 715 849 we are explicitly letting it override a weak symbol or 850 function in a dynamic object, and we don't want to warn about 851 a type change. If the old symbol is a defined symbol, a type 852 change warning may still be appropriate. */ 716 853 717 854 if (h->root.type == bfd_link_hash_common) 718 *type_change_ok = true;855 *type_change_ok = TRUE; 719 856 } 720 857 … … 728 865 && h->root.type == bfd_link_hash_common) 729 866 { 730 *override = true;731 newdef = false;732 newdyncommon = false;867 *override = TRUE; 868 newdef = FALSE; 869 newdyncommon = FALSE; 733 870 *pvalue = sym->st_size; 734 871 *psec = sec = bfd_com_section_ptr; 735 *size_change_ok = true;872 *size_change_ok = TRUE; 736 873 } 737 874 … … 749 886 override a weak definition in a regular object. */ 750 887 888 flip = NULL; 751 889 if (! newdyn 752 890 && (newdef 753 891 || (bfd_is_com_section (sec) 754 && (h->root.type == bfd_link_hash_defweak 755 || h->type == STT_FUNC))) 892 && (oldweakdef || h->type == STT_FUNC))) 756 893 && olddyn 757 894 && olddef 758 895 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 759 && (bind != STB_WEAK 760 || h->root.type == bfd_link_hash_defweak)) 896 && ((!newweakdef && !newweakundef) || oldweakdef)) 761 897 { 762 898 /* Change the hash table entry to undefined, and let … … 766 902 h->root.type = bfd_link_hash_undefined; 767 903 h->root.u.undef.abfd = h->root.u.def.section->owner; 768 *size_change_ok = true;769 770 olddef = false;771 olddyncommon = false;904 *size_change_ok = TRUE; 905 906 olddef = FALSE; 907 olddyncommon = FALSE; 772 908 773 909 /* We again permit a type change when a common symbol may be 774 910 overriding a function. */ 775 911 776 912 if (bfd_is_com_section (sec)) 777 *type_change_ok = true; 778 779 /* This union may have been set to be non-NULL when this symbol 780 was seen in a dynamic object. We must force the union to be 781 NULL, so that it is correct for a regular symbol. */ 782 783 h->verinfo.vertree = NULL; 784 785 /* In this special case, if H is the target of an indirection, 786 we want the caller to frob with H rather than with the 787 indirect symbol. That will permit the caller to redefine the 788 target of the indirection, rather than the indirect symbol 789 itself. FIXME: This will break the -y option if we store a 790 symbol with a different name. */ 791 *sym_hash = h; 913 *type_change_ok = TRUE; 914 915 if ((*sym_hash)->root.type == bfd_link_hash_indirect) 916 flip = *sym_hash; 917 else 918 /* This union may have been set to be non-NULL when this symbol 919 was seen in a dynamic object. We must force the union to be 920 NULL, so that it is correct for a regular symbol. */ 921 h->verinfo.vertree = NULL; 792 922 } 793 923 … … 808 938 (info, h->root.root.string, oldbfd, bfd_link_hash_common, 809 939 h->size, abfd, bfd_link_hash_common, sym->st_size))) 810 return false;940 return FALSE; 811 941 812 942 /* If the predumed common symbol in the dynamic object is 813 943 larger, pretend that the new symbol has its size. */ 814 944 815 945 if (h->size > *pvalue) … … 820 950 the regular object. */ 821 951 822 olddef = false;823 olddyncommon = false;952 olddef = FALSE; 953 olddyncommon = FALSE; 824 954 825 955 h->root.type = bfd_link_hash_undefined; 826 956 h->root.u.undef.abfd = h->root.u.def.section->owner; 827 957 828 *size_change_ok = true; 829 *type_change_ok = true; 830 831 h->verinfo.vertree = NULL; 958 *size_change_ok = TRUE; 959 *type_change_ok = TRUE; 960 961 if ((*sym_hash)->root.type == bfd_link_hash_indirect) 962 flip = *sym_hash; 963 else 964 h->verinfo.vertree = NULL; 965 } 966 967 if (flip != NULL) 968 { 969 /* Handle the case where we had a versioned symbol in a dynamic 970 library and now find a definition in a normal object. In this 971 case, we make the versioned symbol point to the normal one. */ 972 struct elf_backend_data *bed = get_elf_backend_data (abfd); 973 flip->root.type = h->root.type; 974 h->root.type = bfd_link_hash_indirect; 975 h->root.u.i.link = (struct bfd_link_hash_entry *) flip; 976 (*bed->elf_backend_copy_indirect_symbol) (bed, flip, h); 977 flip->root.u.undef.abfd = h->root.u.undef.abfd; 978 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) 979 { 980 h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC; 981 flip->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC; 982 } 832 983 } 833 984 … … 839 990 if (olddef 840 991 && ! dt_needed 841 && h->root.type == bfd_link_hash_defweak992 && oldweakdef 842 993 && newdef 843 994 && newdyn 844 && bind != STB_WEAK) 995 && !newweakdef 996 && !newweakundef) 845 997 { 846 998 /* To make this work we have to frob the flags so that the rest 847 848 999 of the code does not think we are using the regular 1000 definition. */ 849 1001 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) 850 1002 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR; … … 855 1007 856 1008 /* If H is the target of an indirection, we want the caller to 857 858 859 1009 use H rather than the indirect symbol. Otherwise if we are 1010 defining a new indirect symbol we will wind up attaching it 1011 to the entry we are overriding. */ 860 1012 *sym_hash = h; 861 1013 } … … 863 1015 /* Handle the special case of a non-weak definition in a shared 864 1016 object followed by a weak definition in a regular object. In 865 this case we prefer t odefinition in the shared object. To make1017 this case we prefer the definition in the shared object. To make 866 1018 this work we have to tell the caller to not treat the new symbol 867 1019 as a definition. */ 868 1020 if (olddef 869 1021 && olddyn 870 && h->root.type != bfd_link_hash_defweak1022 && !oldweakdef 871 1023 && newdef 872 1024 && ! newdyn 873 && bind == STB_WEAK)874 *override = true;875 876 return true;1025 && (newweakdef || newweakundef)) 1026 *override = TRUE; 1027 1028 return TRUE; 877 1029 } 878 1030 1031 /* This function is called to create an indirect symbol from the 1032 default for the symbol with the default version if needed. The 1033 symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE. We 1034 set DYNSYM if the new indirect symbol is dynamic. DT_NEEDED 1035 indicates if it comes from a DT_NEEDED entry of a shared object. */ 1036 1037 static bfd_boolean 1038 elf_add_default_symbol (abfd, info, h, name, sym, psec, value, 1039 dynsym, override, dt_needed) 1040 bfd *abfd; 1041 struct bfd_link_info *info; 1042 struct elf_link_hash_entry *h; 1043 const char *name; 1044 Elf_Internal_Sym *sym; 1045 asection **psec; 1046 bfd_vma *value; 1047 bfd_boolean *dynsym; 1048 bfd_boolean override; 1049 bfd_boolean dt_needed; 1050 { 1051 bfd_boolean type_change_ok; 1052 bfd_boolean size_change_ok; 1053 bfd_boolean skip; 1054 char *shortname; 1055 struct elf_link_hash_entry *hi; 1056 struct bfd_link_hash_entry *bh; 1057 struct elf_backend_data *bed; 1058 bfd_boolean collect; 1059 bfd_boolean dynamic; 1060 char *p; 1061 size_t len, shortlen; 1062 asection *sec; 1063 1064 /* If this symbol has a version, and it is the default version, we 1065 create an indirect symbol from the default name to the fully 1066 decorated name. This will cause external references which do not 1067 specify a version to be bound to this version of the symbol. */ 1068 p = strchr (name, ELF_VER_CHR); 1069 if (p == NULL || p[1] != ELF_VER_CHR) 1070 return TRUE; 1071 1072 if (override) 1073 { 1074 /* We are overridden by an old defition. We need to check if we 1075 need to create the indirect symbol from the default name. */ 1076 hi = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, 1077 FALSE, FALSE); 1078 BFD_ASSERT (hi != NULL); 1079 if (hi == h) 1080 return TRUE; 1081 while (hi->root.type == bfd_link_hash_indirect 1082 || hi->root.type == bfd_link_hash_warning) 1083 { 1084 hi = (struct elf_link_hash_entry *) hi->root.u.i.link; 1085 if (hi == h) 1086 return TRUE; 1087 } 1088 } 1089 1090 bed = get_elf_backend_data (abfd); 1091 collect = bed->collect; 1092 dynamic = (abfd->flags & DYNAMIC) != 0; 1093 1094 shortlen = p - name; 1095 shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1); 1096 if (shortname == NULL) 1097 return FALSE; 1098 memcpy (shortname, name, shortlen); 1099 shortname[shortlen] = '\0'; 1100 1101 /* We are going to create a new symbol. Merge it with any existing 1102 symbol with this name. For the purposes of the merge, act as 1103 though we were defining the symbol we just defined, although we 1104 actually going to define an indirect symbol. */ 1105 type_change_ok = FALSE; 1106 size_change_ok = FALSE; 1107 sec = *psec; 1108 if (! elf_merge_symbol (abfd, info, shortname, sym, &sec, value, 1109 &hi, &skip, &override, &type_change_ok, 1110 &size_change_ok, dt_needed)) 1111 return FALSE; 1112 1113 if (skip) 1114 goto nondefault; 1115 1116 if (! override) 1117 { 1118 bh = &hi->root; 1119 if (! (_bfd_generic_link_add_one_symbol 1120 (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr, 1121 (bfd_vma) 0, name, FALSE, collect, &bh))) 1122 return FALSE; 1123 hi = (struct elf_link_hash_entry *) bh; 1124 } 1125 else 1126 { 1127 /* In this case the symbol named SHORTNAME is overriding the 1128 indirect symbol we want to add. We were planning on making 1129 SHORTNAME an indirect symbol referring to NAME. SHORTNAME 1130 is the name without a version. NAME is the fully versioned 1131 name, and it is the default version. 1132 1133 Overriding means that we already saw a definition for the 1134 symbol SHORTNAME in a regular object, and it is overriding 1135 the symbol defined in the dynamic object. 1136 1137 When this happens, we actually want to change NAME, the 1138 symbol we just added, to refer to SHORTNAME. This will cause 1139 references to NAME in the shared object to become references 1140 to SHORTNAME in the regular object. This is what we expect 1141 when we override a function in a shared object: that the 1142 references in the shared object will be mapped to the 1143 definition in the regular object. */ 1144 1145 while (hi->root.type == bfd_link_hash_indirect 1146 || hi->root.type == bfd_link_hash_warning) 1147 hi = (struct elf_link_hash_entry *) hi->root.u.i.link; 1148 1149 h->root.type = bfd_link_hash_indirect; 1150 h->root.u.i.link = (struct bfd_link_hash_entry *) hi; 1151 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) 1152 { 1153 h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC; 1154 hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC; 1155 if (hi->elf_link_hash_flags 1156 & (ELF_LINK_HASH_REF_REGULAR 1157 | ELF_LINK_HASH_DEF_REGULAR)) 1158 { 1159 if (! _bfd_elf_link_record_dynamic_symbol (info, hi)) 1160 return FALSE; 1161 } 1162 } 1163 1164 /* Now set HI to H, so that the following code will set the 1165 other fields correctly. */ 1166 hi = h; 1167 } 1168 1169 /* If there is a duplicate definition somewhere, then HI may not 1170 point to an indirect symbol. We will have reported an error to 1171 the user in that case. */ 1172 1173 if (hi->root.type == bfd_link_hash_indirect) 1174 { 1175 struct elf_link_hash_entry *ht; 1176 1177 /* If the symbol became indirect, then we assume that we have 1178 not seen a definition before. */ 1179 BFD_ASSERT ((hi->elf_link_hash_flags 1180 & (ELF_LINK_HASH_DEF_DYNAMIC 1181 | ELF_LINK_HASH_DEF_REGULAR)) == 0); 1182 1183 ht = (struct elf_link_hash_entry *) hi->root.u.i.link; 1184 (*bed->elf_backend_copy_indirect_symbol) (bed, ht, hi); 1185 1186 /* See if the new flags lead us to realize that the symbol must 1187 be dynamic. */ 1188 if (! *dynsym) 1189 { 1190 if (! dynamic) 1191 { 1192 if (info->shared 1193 || ((hi->elf_link_hash_flags 1194 & ELF_LINK_HASH_REF_DYNAMIC) != 0)) 1195 *dynsym = TRUE; 1196 } 1197 else 1198 { 1199 if ((hi->elf_link_hash_flags 1200 & ELF_LINK_HASH_REF_REGULAR) != 0) 1201 *dynsym = TRUE; 1202 } 1203 } 1204 } 1205 1206 /* We also need to define an indirection from the nondefault version 1207 of the symbol. */ 1208 1209 nondefault: 1210 len = strlen (name); 1211 shortname = bfd_hash_allocate (&info->hash->table, len); 1212 if (shortname == NULL) 1213 return FALSE; 1214 memcpy (shortname, name, shortlen); 1215 memcpy (shortname + shortlen, p + 1, len - shortlen); 1216 1217 /* Once again, merge with any existing symbol. */ 1218 type_change_ok = FALSE; 1219 size_change_ok = FALSE; 1220 sec = *psec; 1221 if (! elf_merge_symbol (abfd, info, shortname, sym, &sec, value, 1222 &hi, &skip, &override, &type_change_ok, 1223 &size_change_ok, dt_needed)) 1224 return FALSE; 1225 1226 if (skip) 1227 return TRUE; 1228 1229 if (override) 1230 { 1231 /* Here SHORTNAME is a versioned name, so we don't expect to see 1232 the type of override we do in the case above unless it is 1233 overridden by a versioned definiton. */ 1234 if (hi->root.type != bfd_link_hash_defined 1235 && hi->root.type != bfd_link_hash_defweak) 1236 (*_bfd_error_handler) 1237 (_("%s: warning: unexpected redefinition of indirect versioned symbol `%s'"), 1238 bfd_archive_filename (abfd), shortname); 1239 } 1240 else 1241 { 1242 bh = &hi->root; 1243 if (! (_bfd_generic_link_add_one_symbol 1244 (info, abfd, shortname, BSF_INDIRECT, 1245 bfd_ind_section_ptr, (bfd_vma) 0, name, FALSE, collect, &bh))) 1246 return FALSE; 1247 hi = (struct elf_link_hash_entry *) bh; 1248 1249 /* If there is a duplicate definition somewhere, then HI may not 1250 point to an indirect symbol. We will have reported an error 1251 to the user in that case. */ 1252 1253 if (hi->root.type == bfd_link_hash_indirect) 1254 { 1255 /* If the symbol became indirect, then we assume that we have 1256 not seen a definition before. */ 1257 BFD_ASSERT ((hi->elf_link_hash_flags 1258 & (ELF_LINK_HASH_DEF_DYNAMIC 1259 | ELF_LINK_HASH_DEF_REGULAR)) == 0); 1260 1261 (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi); 1262 1263 /* See if the new flags lead us to realize that the symbol 1264 must be dynamic. */ 1265 if (! *dynsym) 1266 { 1267 if (! dynamic) 1268 { 1269 if (info->shared 1270 || ((hi->elf_link_hash_flags 1271 & ELF_LINK_HASH_REF_DYNAMIC) != 0)) 1272 *dynsym = TRUE; 1273 } 1274 else 1275 { 1276 if ((hi->elf_link_hash_flags 1277 & ELF_LINK_HASH_REF_REGULAR) != 0) 1278 *dynsym = TRUE; 1279 } 1280 } 1281 } 1282 } 1283 1284 return TRUE; 1285 } 1286 879 1287 /* Add symbols from an ELF object file to the linker hash table. */ 880 1288 881 static b oolean1289 static bfd_boolean 882 1290 elf_link_add_object_symbols (abfd, info) 883 1291 bfd *abfd; 884 1292 struct bfd_link_info *info; 885 1293 { 886 b oolean (*add_symbol_hook) PARAMS ((bfd *, struct bfd_link_info *,887 888 const char **, flagword *,889 asection **, bfd_vma *)); 890 boolean (*check_relocs) PARAMS ((bfd *, struct bfd_link_info*,891 asection *,const Elf_Internal_Rela *));892 b oolean collect;1294 bfd_boolean (*add_symbol_hook) 1295 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, 1296 const char **, flagword *, asection **, bfd_vma *)); 1297 bfd_boolean (*check_relocs) 1298 PARAMS ((bfd *, struct bfd_link_info *, asection *, 1299 const Elf_Internal_Rela *)); 1300 bfd_boolean collect; 893 1301 Elf_Internal_Shdr *hdr; 894 size_t symcount; 895 size_t extsymcount; 896 size_t extsymoff; 897 Elf_External_Sym *buf = NULL; 1302 bfd_size_type symcount; 1303 bfd_size_type extsymcount; 1304 bfd_size_type extsymoff; 898 1305 struct elf_link_hash_entry **sym_hash; 899 b oolean dynamic;1306 bfd_boolean dynamic; 900 1307 Elf_External_Versym *extversym = NULL; 901 1308 Elf_External_Versym *ever; 902 Elf_External_Dyn *dynbuf = NULL;903 1309 struct elf_link_hash_entry *weaks; 904 Elf_External_Sym *esym; 905 Elf_External_Sym *esymend; 1310 struct elf_link_hash_entry **nondeflt_vers = NULL; 1311 bfd_size_type nondeflt_vers_cnt = 0; 1312 Elf_Internal_Sym *isymbuf = NULL; 1313 Elf_Internal_Sym *isym; 1314 Elf_Internal_Sym *isymend; 906 1315 struct elf_backend_data *bed; 907 boolean dt_needed; 1316 bfd_boolean dt_needed; 1317 struct elf_link_hash_table * hash_table; 1318 bfd_size_type amt; 1319 1320 hash_table = elf_hash_table (info); 908 1321 909 1322 bed = get_elf_backend_data (abfd); … … 912 1325 913 1326 if ((abfd->flags & DYNAMIC) == 0) 914 dynamic = false;1327 dynamic = FALSE; 915 1328 else 916 1329 { 917 dynamic = true;1330 dynamic = TRUE; 918 1331 919 1332 /* You can't use -r against a dynamic object. Also, there's no … … 960 1373 struct elf_link_hash_entry *h; 961 1374 962 h = elf_link_hash_lookup ( elf_hash_table (info), name,963 false, false, true);1375 h = elf_link_hash_lookup (hash_table, name, 1376 FALSE, FALSE, TRUE); 964 1377 965 1378 /* FIXME: What about bfd_link_hash_common? */ … … 969 1382 { 970 1383 /* We don't want to issue this warning. Clobber 971 972 1384 the section size so that the warning does not 1385 get copied into the output file. */ 973 1386 s->_raw_size = 0; 974 1387 continue; … … 988 1401 if (! (_bfd_generic_link_add_one_symbol 989 1402 (info, abfd, name, BSF_WARNING, s, (bfd_vma) 0, msg, 990 false, collect, (struct bfd_link_hash_entry **) NULL)))1403 FALSE, collect, (struct bfd_link_hash_entry **) NULL))) 991 1404 goto error_return; 992 1405 … … 994 1407 { 995 1408 /* Clobber the section size so that the warning does 996 1409 not get copied into the output file. */ 997 1410 s->_raw_size = 0; 998 1411 } … … 1001 1414 } 1002 1415 1003 /* If this is a dynamic object, we always link against the .dynsym 1004 symbol table, not the .symtab symbol table. The dynamic linker 1005 will only see the .dynsym symbol table, so there is no reason to 1006 look at .symtab for a dynamic object. */ 1007 1008 if (! dynamic || elf_dynsymtab (abfd) == 0) 1009 hdr = &elf_tdata (abfd)->symtab_hdr; 1010 else 1011 hdr = &elf_tdata (abfd)->dynsymtab_hdr; 1012 1013 if (dynamic) 1014 { 1015 /* Read in any version definitions. */ 1016 1017 if (! _bfd_elf_slurp_version_tables (abfd)) 1018 goto error_return; 1019 1020 /* Read in the symbol versions, but don't bother to convert them 1021 to internal format. */ 1022 if (elf_dynversym (abfd) != 0) 1023 { 1024 Elf_Internal_Shdr *versymhdr; 1025 1026 versymhdr = &elf_tdata (abfd)->dynversym_hdr; 1027 extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size); 1028 if (extversym == NULL) 1029 goto error_return; 1030 if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET) != 0 1031 || (bfd_read ((PTR) extversym, 1, versymhdr->sh_size, abfd) 1032 != versymhdr->sh_size)) 1033 goto error_return; 1034 } 1035 } 1036 1037 symcount = hdr->sh_size / sizeof (Elf_External_Sym); 1038 1039 /* The sh_info field of the symtab header tells us where the 1040 external symbols start. We don't care about the local symbols at 1041 this point. */ 1042 if (elf_bad_symtab (abfd)) 1043 { 1044 extsymcount = symcount; 1045 extsymoff = 0; 1046 } 1047 else 1048 { 1049 extsymcount = symcount - hdr->sh_info; 1050 extsymoff = hdr->sh_info; 1051 } 1052 1053 buf = ((Elf_External_Sym *) 1054 bfd_malloc (extsymcount * sizeof (Elf_External_Sym))); 1055 if (buf == NULL && extsymcount != 0) 1056 goto error_return; 1057 1058 /* We store a pointer to the hash table entry for each external 1059 symbol. */ 1060 sym_hash = ((struct elf_link_hash_entry **) 1061 bfd_alloc (abfd, 1062 extsymcount * sizeof (struct elf_link_hash_entry *))); 1063 if (sym_hash == NULL) 1064 goto error_return; 1065 elf_sym_hashes (abfd) = sym_hash; 1066 1067 dt_needed = false; 1068 1416 dt_needed = FALSE; 1069 1417 if (! dynamic) 1070 1418 { 1071 1419 /* If we are creating a shared library, create all the dynamic 1072 1073 1074 1075 1420 sections immediately. We need to attach them to something, 1421 so we attach them to this BFD, provided it is the right 1422 format. FIXME: If there are no input BFD's of the same 1423 format as the output, we can't make a shared library. */ 1076 1424 if (info->shared 1077 && ! elf_hash_table (info)->dynamic_sections_created 1425 && is_elf_hash_table (info) 1426 && ! hash_table->dynamic_sections_created 1078 1427 && abfd->xvec == info->hash->creator) 1079 1428 { … … 1082 1431 } 1083 1432 } 1433 else if (! is_elf_hash_table (info)) 1434 goto error_return; 1084 1435 else 1085 1436 { 1086 1437 asection *s; 1087 b oolean add_needed;1438 bfd_boolean add_needed; 1088 1439 const char *name; 1089 1440 bfd_size_type oldsize; 1090 1441 bfd_size_type strindex; 1442 struct bfd_link_needed_list *rpath = NULL, *runpath = NULL; 1443 1444 /* ld --just-symbols and dynamic objects don't mix very well. 1445 Test for --just-symbols by looking at info set up by 1446 _bfd_elf_link_just_syms. */ 1447 if ((s = abfd->sections) != NULL 1448 && s->sec_info_type == ELF_INFO_TYPE_JUST_SYMS) 1449 goto error_return; 1091 1450 1092 1451 /* Find the name to use in a DT_NEEDED entry that refers to this … … 1097 1456 elf_dt_name, we don't make a DT_NEEDED entry at all, even if 1098 1457 there is a DT_SONAME entry. */ 1099 add_needed = true;1458 add_needed = TRUE; 1100 1459 name = bfd_get_filename (abfd); 1101 1460 if (elf_dt_name (abfd) != NULL) … … 1105 1464 { 1106 1465 if (elf_dt_soname (abfd) != NULL) 1107 dt_needed = true;1108 1109 add_needed = false;1466 dt_needed = TRUE; 1467 1468 add_needed = FALSE; 1110 1469 } 1111 1470 } … … 1113 1472 if (s != NULL) 1114 1473 { 1474 Elf_External_Dyn *dynbuf = NULL; 1115 1475 Elf_External_Dyn *extdyn; 1116 1476 Elf_External_Dyn *extdynend; 1117 1477 int elfsec; 1118 unsigned long link; 1119 int rpath; 1120 int runpath; 1121 1122 dynbuf = (Elf_External_Dyn *) bfd_malloc ((size_t) s->_raw_size); 1478 unsigned long shlink; 1479 1480 dynbuf = (Elf_External_Dyn *) bfd_malloc (s->_raw_size); 1123 1481 if (dynbuf == NULL) 1124 1482 goto error_return; … … 1126 1484 if (! bfd_get_section_contents (abfd, s, (PTR) dynbuf, 1127 1485 (file_ptr) 0, s->_raw_size)) 1128 goto error_ return;1486 goto error_free_dyn; 1129 1487 1130 1488 elfsec = _bfd_elf_section_from_bfd_section (abfd, s); 1131 1489 if (elfsec == -1) 1132 goto error_return; 1133 link = elf_elfsections (abfd)[elfsec]->sh_link; 1134 1135 { 1136 /* The shared libraries distributed with hpux11 have a bogus 1137 sh_link field for the ".dynamic" section. This code detects 1138 when LINK refers to a section that is not a string table and 1139 tries to find the string table for the ".dynsym" section 1140 instead. */ 1141 Elf_Internal_Shdr *hdr = elf_elfsections (abfd)[link]; 1142 if (hdr->sh_type != SHT_STRTAB) 1143 { 1144 asection *s = bfd_get_section_by_name (abfd, ".dynsym"); 1145 int elfsec = _bfd_elf_section_from_bfd_section (abfd, s); 1146 if (elfsec == -1) 1147 goto error_return; 1148 link = elf_elfsections (abfd)[elfsec]->sh_link; 1149 } 1150 } 1490 goto error_free_dyn; 1491 shlink = elf_elfsections (abfd)[elfsec]->sh_link; 1151 1492 1152 1493 extdyn = dynbuf; 1153 1494 extdynend = extdyn + s->_raw_size / sizeof (Elf_External_Dyn); 1154 rpath = 0;1155 runpath = 0;1156 1495 for (; extdyn < extdynend; extdyn++) 1157 1496 { … … 1161 1500 if (dyn.d_tag == DT_SONAME) 1162 1501 { 1163 name = bfd_elf_string_from_elf_section (abfd, link,1164 dyn.d_un.d_val);1502 unsigned int tagv = dyn.d_un.d_val; 1503 name = bfd_elf_string_from_elf_section (abfd, shlink, tagv); 1165 1504 if (name == NULL) 1166 goto error_ return;1505 goto error_free_dyn; 1167 1506 } 1168 1507 if (dyn.d_tag == DT_NEEDED) … … 1170 1509 struct bfd_link_needed_list *n, **pn; 1171 1510 char *fnm, *anm; 1172 1173 n = ((struct bfd_link_needed_list *) 1174 bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));1175 fnm = bfd_elf_string_from_elf_section (abfd, link,1176 dyn.d_un.d_val);1511 unsigned int tagv = dyn.d_un.d_val; 1512 1513 amt = sizeof (struct bfd_link_needed_list); 1514 n = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt); 1515 fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); 1177 1516 if (n == NULL || fnm == NULL) 1178 goto error_return; 1179 anm = bfd_alloc (abfd, strlen (fnm) + 1); 1517 goto error_free_dyn; 1518 amt = strlen (fnm) + 1; 1519 anm = bfd_alloc (abfd, amt); 1180 1520 if (anm == NULL) 1181 goto error_ return;1182 strcpy (anm, fnm);1521 goto error_free_dyn; 1522 memcpy (anm, fnm, (size_t) amt); 1183 1523 n->name = anm; 1184 1524 n->by = abfd; 1185 1525 n->next = NULL; 1186 for (pn = & elf_hash_table (info)->needed;1526 for (pn = & hash_table->needed; 1187 1527 *pn != NULL; 1188 1528 pn = &(*pn)->next) … … 1194 1534 struct bfd_link_needed_list *n, **pn; 1195 1535 char *fnm, *anm; 1196 1197 /* When we see DT_RPATH before DT_RUNPATH, we have 1198 to clear runpath. Do _NOT_ bfd_release, as that 1199 frees all more recently bfd_alloc'd blocks as 1200 well. */ 1201 if (rpath && elf_hash_table (info)->runpath) 1202 elf_hash_table (info)->runpath = NULL; 1203 1204 n = ((struct bfd_link_needed_list *) 1205 bfd_alloc (abfd, sizeof (struct bfd_link_needed_list))); 1206 fnm = bfd_elf_string_from_elf_section (abfd, link, 1207 dyn.d_un.d_val); 1536 unsigned int tagv = dyn.d_un.d_val; 1537 1538 amt = sizeof (struct bfd_link_needed_list); 1539 n = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt); 1540 fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); 1208 1541 if (n == NULL || fnm == NULL) 1209 goto error_return; 1210 anm = bfd_alloc (abfd, strlen (fnm) + 1); 1542 goto error_free_dyn; 1543 amt = strlen (fnm) + 1; 1544 anm = bfd_alloc (abfd, amt); 1211 1545 if (anm == NULL) 1212 goto error_ return;1213 strcpy (anm, fnm);1546 goto error_free_dyn; 1547 memcpy (anm, fnm, (size_t) amt); 1214 1548 n->name = anm; 1215 1549 n->by = abfd; 1216 1550 n->next = NULL; 1217 for (pn = & elf_hash_table (info)->runpath;1551 for (pn = & runpath; 1218 1552 *pn != NULL; 1219 1553 pn = &(*pn)->next) 1220 1554 ; 1221 1555 *pn = n; 1222 runpath = 1;1223 rpath = 0;1224 1556 } 1225 1557 /* Ignore DT_RPATH if we have seen DT_RUNPATH. */ 1226 1558 if (!runpath && dyn.d_tag == DT_RPATH) 1227 1559 { 1228 1560 struct bfd_link_needed_list *n, **pn; 1229 1561 char *fnm, *anm; 1230 1231 n = ((struct bfd_link_needed_list *) 1232 bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));1233 fnm = bfd_elf_string_from_elf_section (abfd, link,1234 dyn.d_un.d_val);1562 unsigned int tagv = dyn.d_un.d_val; 1563 1564 amt = sizeof (struct bfd_link_needed_list); 1565 n = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt); 1566 fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); 1235 1567 if (n == NULL || fnm == NULL) 1236 goto error_return; 1237 anm = bfd_alloc (abfd, strlen (fnm) + 1); 1568 goto error_free_dyn; 1569 amt = strlen (fnm) + 1; 1570 anm = bfd_alloc (abfd, amt); 1238 1571 if (anm == NULL) 1239 goto error_return; 1240 strcpy (anm, fnm); 1572 { 1573 error_free_dyn: 1574 free (dynbuf); 1575 goto error_return; 1576 } 1577 memcpy (anm, fnm, (size_t) amt); 1241 1578 n->name = anm; 1242 1579 n->by = abfd; 1243 1580 n->next = NULL; 1244 for (pn = & elf_hash_table (info)->runpath;1581 for (pn = & rpath; 1245 1582 *pn != NULL; 1246 1583 pn = &(*pn)->next) 1247 1584 ; 1248 1585 *pn = n; 1249 rpath = 1;1250 1586 } 1251 1587 } 1252 1588 1253 1589 free (dynbuf); 1254 dynbuf = NULL; 1590 } 1591 1592 /* DT_RUNPATH overrides DT_RPATH. Do _NOT_ bfd_release, as that 1593 frees all more recently bfd_alloc'd blocks as well. */ 1594 if (runpath) 1595 rpath = runpath; 1596 1597 if (rpath) 1598 { 1599 struct bfd_link_needed_list **pn; 1600 for (pn = & hash_table->runpath; 1601 *pn != NULL; 1602 pn = &(*pn)->next) 1603 ; 1604 *pn = rpath; 1255 1605 } 1256 1606 … … 1262 1612 still implies that the section takes up space in the output 1263 1613 file. */ 1264 abfd->sections = NULL; 1265 abfd->section_count = 0; 1614 bfd_section_list_clear (abfd); 1266 1615 1267 1616 /* If this is the first dynamic object found in the link, create 1268 1617 the special sections required for dynamic linking. */ 1269 if (! elf_hash_table (info)->dynamic_sections_created) 1270 { 1271 if (! elf_link_create_dynamic_sections (abfd, info)) 1272 goto error_return; 1273 } 1618 if (! hash_table->dynamic_sections_created) 1619 if (! elf_link_create_dynamic_sections (abfd, info)) 1620 goto error_return; 1274 1621 1275 1622 if (add_needed) 1276 1623 { 1277 1624 /* Add a DT_NEEDED entry for this dynamic object. */ 1278 oldsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr); 1279 strindex = _bfd_stringtab_add (elf_hash_table (info)->dynstr, name, 1280 true, false); 1625 oldsize = _bfd_elf_strtab_size (hash_table->dynstr); 1626 strindex = _bfd_elf_strtab_add (hash_table->dynstr, name, FALSE); 1281 1627 if (strindex == (bfd_size_type) -1) 1282 1628 goto error_return; 1283 1629 1284 if (oldsize == _bfd_ stringtab_size (elf_hash_table (info)->dynstr))1630 if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr)) 1285 1631 { 1286 1632 asection *sdyn; … … 1292 1638 link, just ignore it. There is no reason to include 1293 1639 a particular dynamic object more than once. */ 1294 sdyn = bfd_get_section_by_name (elf_hash_table (info)->dynobj, 1295 ".dynamic"); 1640 sdyn = bfd_get_section_by_name (hash_table->dynobj, ".dynamic"); 1296 1641 BFD_ASSERT (sdyn != NULL); 1297 1642 … … 1303 1648 Elf_Internal_Dyn dyn; 1304 1649 1305 elf_swap_dyn_in (elf_hash_table (info)->dynobj, dyncon, 1306 &dyn); 1650 elf_swap_dyn_in (hash_table->dynobj, dyncon, & dyn); 1307 1651 if (dyn.d_tag == DT_NEEDED 1308 1652 && dyn.d_un.d_val == strindex) 1309 1653 { 1310 if (buf != NULL) 1311 free (buf); 1312 if (extversym != NULL) 1313 free (extversym); 1314 return true; 1654 _bfd_elf_strtab_delref (hash_table->dynstr, strindex); 1655 return TRUE; 1315 1656 } 1316 1657 } 1317 1658 } 1318 1659 1319 if (! elf_add_dynamic_entry (info, DT_NEEDED, strindex))1660 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_NEEDED, strindex)) 1320 1661 goto error_return; 1321 1662 } 1322 1663 1323 1664 /* Save the SONAME, if there is one, because sometimes the 1324 1665 linker emulation code will need to know it. */ 1325 1666 if (*name == '\0') 1326 name = b fd_get_filename (abfd);1667 name = basename (bfd_get_filename (abfd)); 1327 1668 elf_dt_name (abfd) = name; 1328 1669 } 1329 1670 1330 if (bfd_seek (abfd, 1331 hdr->sh_offset + extsymoff * sizeof (Elf_External_Sym), 1332 SEEK_SET) != 0 1333 || (bfd_read ((PTR) buf, sizeof (Elf_External_Sym), extsymcount, abfd) 1334 != extsymcount * sizeof (Elf_External_Sym))) 1335 goto error_return; 1671 /* If this is a dynamic object, we always link against the .dynsym 1672 symbol table, not the .symtab symbol table. The dynamic linker 1673 will only see the .dynsym symbol table, so there is no reason to 1674 look at .symtab for a dynamic object. */ 1675 1676 if (! dynamic || elf_dynsymtab (abfd) == 0) 1677 hdr = &elf_tdata (abfd)->symtab_hdr; 1678 else 1679 hdr = &elf_tdata (abfd)->dynsymtab_hdr; 1680 1681 symcount = hdr->sh_size / sizeof (Elf_External_Sym); 1682 1683 /* The sh_info field of the symtab header tells us where the 1684 external symbols start. We don't care about the local symbols at 1685 this point. */ 1686 if (elf_bad_symtab (abfd)) 1687 { 1688 extsymcount = symcount; 1689 extsymoff = 0; 1690 } 1691 else 1692 { 1693 extsymcount = symcount - hdr->sh_info; 1694 extsymoff = hdr->sh_info; 1695 } 1696 1697 sym_hash = NULL; 1698 if (extsymcount != 0) 1699 { 1700 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff, 1701 NULL, NULL, NULL); 1702 if (isymbuf == NULL) 1703 goto error_return; 1704 1705 /* We store a pointer to the hash table entry for each external 1706 symbol. */ 1707 amt = extsymcount * sizeof (struct elf_link_hash_entry *); 1708 sym_hash = (struct elf_link_hash_entry **) bfd_alloc (abfd, amt); 1709 if (sym_hash == NULL) 1710 goto error_free_sym; 1711 elf_sym_hashes (abfd) = sym_hash; 1712 } 1713 1714 if (dynamic) 1715 { 1716 /* Read in any version definitions. */ 1717 if (! _bfd_elf_slurp_version_tables (abfd)) 1718 goto error_free_sym; 1719 1720 /* Read in the symbol versions, but don't bother to convert them 1721 to internal format. */ 1722 if (elf_dynversym (abfd) != 0) 1723 { 1724 Elf_Internal_Shdr *versymhdr; 1725 1726 versymhdr = &elf_tdata (abfd)->dynversym_hdr; 1727 extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size); 1728 if (extversym == NULL) 1729 goto error_free_sym; 1730 amt = versymhdr->sh_size; 1731 if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET) != 0 1732 || bfd_bread ((PTR) extversym, amt, abfd) != amt) 1733 goto error_free_vers; 1734 } 1735 } 1336 1736 1337 1737 weaks = NULL; 1338 1738 1339 1739 ever = extversym != NULL ? extversym + extsymoff : NULL; 1340 esymend = buf + extsymcount; 1341 for (esym = buf; 1342 esym < esymend; 1343 esym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL)) 1344 { 1345 Elf_Internal_Sym sym; 1740 for (isym = isymbuf, isymend = isymbuf + extsymcount; 1741 isym < isymend; 1742 isym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL)) 1743 { 1346 1744 int bind; 1347 1745 bfd_vma value; … … 1350 1748 const char *name; 1351 1749 struct elf_link_hash_entry *h; 1352 boolean definition; 1353 boolean size_change_ok, type_change_ok; 1354 boolean new_weakdef; 1750 bfd_boolean definition; 1751 bfd_boolean size_change_ok; 1752 bfd_boolean type_change_ok; 1753 bfd_boolean new_weakdef; 1754 bfd_boolean override; 1355 1755 unsigned int old_alignment; 1356 1357 elf_swap_symbol_in (abfd, esym, &sym); 1756 bfd *old_bfd; 1757 1758 override = FALSE; 1358 1759 1359 1760 flags = BSF_NO_FLAGS; 1360 1761 sec = NULL; 1361 value = sym.st_value;1762 value = isym->st_value; 1362 1763 *sym_hash = NULL; 1363 1764 1364 bind = ELF_ST_BIND ( sym.st_info);1765 bind = ELF_ST_BIND (isym->st_info); 1365 1766 if (bind == STB_LOCAL) 1366 1767 { … … 1373 1774 else if (bind == STB_GLOBAL) 1374 1775 { 1375 if ( sym.st_shndx != SHN_UNDEF1376 && sym.st_shndx != SHN_COMMON)1776 if (isym->st_shndx != SHN_UNDEF 1777 && isym->st_shndx != SHN_COMMON) 1377 1778 flags = BSF_GLOBAL; 1378 1779 } … … 1384 1785 } 1385 1786 1386 if ( sym.st_shndx == SHN_UNDEF)1787 if (isym->st_shndx == SHN_UNDEF) 1387 1788 sec = bfd_und_section_ptr; 1388 else if ( sym.st_shndx > 0 && sym.st_shndx < SHN_LORESERVE)1389 { 1390 sec = section_from_elf_index (abfd, sym.st_shndx);1789 else if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE) 1790 { 1791 sec = section_from_elf_index (abfd, isym->st_shndx); 1391 1792 if (sec == NULL) 1392 1793 sec = bfd_abs_section_ptr; … … 1394 1795 value -= sec->vma; 1395 1796 } 1396 else if ( sym.st_shndx == SHN_ABS)1797 else if (isym->st_shndx == SHN_ABS) 1397 1798 sec = bfd_abs_section_ptr; 1398 else if ( sym.st_shndx == SHN_COMMON)1799 else if (isym->st_shndx == SHN_COMMON) 1399 1800 { 1400 1801 sec = bfd_com_section_ptr; 1401 1802 /* What ELF calls the size we call the value. What ELF 1402 1803 calls the value we call the alignment. */ 1403 value = sym.st_size;1804 value = isym->st_size; 1404 1805 } 1405 1806 else … … 1408 1809 } 1409 1810 1410 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, sym.st_name); 1811 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, 1812 isym->st_name); 1411 1813 if (name == (const char *) NULL) 1412 goto error_return; 1413 1414 if (add_symbol_hook) 1415 { 1416 if (! (*add_symbol_hook) (abfd, info, &sym, &name, &flags, &sec, 1814 goto error_free_vers; 1815 1816 if (isym->st_shndx == SHN_COMMON 1817 && ELF_ST_TYPE (isym->st_info) == STT_TLS) 1818 { 1819 asection *tcomm = bfd_get_section_by_name (abfd, ".tcommon"); 1820 1821 if (tcomm == NULL) 1822 { 1823 tcomm = bfd_make_section (abfd, ".tcommon"); 1824 if (tcomm == NULL 1825 || !bfd_set_section_flags (abfd, tcomm, (SEC_ALLOC 1826 | SEC_IS_COMMON 1827 | SEC_LINKER_CREATED 1828 | SEC_THREAD_LOCAL))) 1829 goto error_free_vers; 1830 } 1831 sec = tcomm; 1832 } 1833 else if (add_symbol_hook) 1834 { 1835 if (! (*add_symbol_hook) (abfd, info, isym, &name, &flags, &sec, 1417 1836 &value)) 1418 goto error_ return;1837 goto error_free_vers; 1419 1838 1420 1839 /* The hook function sets the name to NULL if this symbol … … 1428 1847 { 1429 1848 bfd_set_error (bfd_error_bad_value); 1430 goto error_ return;1849 goto error_free_vers; 1431 1850 } 1432 1851 1433 1852 if (bfd_is_und_section (sec) 1434 1853 || bfd_is_com_section (sec)) 1435 definition = false;1854 definition = FALSE; 1436 1855 else 1437 definition = true;1438 1439 size_change_ok = false;1856 definition = TRUE; 1857 1858 size_change_ok = FALSE; 1440 1859 type_change_ok = get_elf_backend_data (abfd)->type_change_ok; 1441 1860 old_alignment = 0; 1861 old_bfd = NULL; 1862 1442 1863 if (info->hash->creator->flavour == bfd_target_elf_flavour) 1443 1864 { 1444 1865 Elf_Internal_Versym iver; 1445 1866 unsigned int vernum = 0; 1446 b oolean override;1867 bfd_boolean skip; 1447 1868 1448 1869 if (ever != NULL) … … 1452 1873 1453 1874 /* If this is a hidden symbol, or if it is not version 1454 1455 1456 1457 1875 1, we append the version name to the symbol name. 1876 However, we do not modify a non-hidden absolute 1877 symbol, because it might be the version symbol 1878 itself. FIXME: What if it isn't? */ 1458 1879 if ((iver.vs_vers & VERSYM_HIDDEN) != 0 1459 1880 || (vernum > 1 && ! bfd_is_abs_section (sec))) 1460 1881 { 1461 1882 const char *verstr; 1462 int namelen, newlen;1883 size_t namelen, verlen, newlen; 1463 1884 char *newname, *p; 1464 1885 1465 if ( sym.st_shndx != SHN_UNDEF)1886 if (isym->st_shndx != SHN_UNDEF) 1466 1887 { 1467 1888 if (vernum > elf_tdata (abfd)->dynverdef_hdr.sh_info) … … 1469 1890 (*_bfd_error_handler) 1470 1891 (_("%s: %s: invalid version %u (max %d)"), 1471 bfd_ get_filename (abfd), name, vernum,1892 bfd_archive_filename (abfd), name, vernum, 1472 1893 elf_tdata (abfd)->dynverdef_hdr.sh_info); 1473 1894 bfd_set_error (bfd_error_bad_value); 1474 goto error_ return;1895 goto error_free_vers; 1475 1896 } 1476 1897 else if (vernum > 1) … … 1510 1931 (*_bfd_error_handler) 1511 1932 (_("%s: %s: invalid needed version %d"), 1512 bfd_ get_filename (abfd), name, vernum);1933 bfd_archive_filename (abfd), name, vernum); 1513 1934 bfd_set_error (bfd_error_bad_value); 1514 goto error_ return;1935 goto error_free_vers; 1515 1936 } 1516 1937 } 1517 1938 1518 1939 namelen = strlen (name); 1519 newlen = namelen + strlen (verstr) + 2; 1520 if ((iver.vs_vers & VERSYM_HIDDEN) == 0) 1940 verlen = strlen (verstr); 1941 newlen = namelen + verlen + 2; 1942 if ((iver.vs_vers & VERSYM_HIDDEN) == 0 1943 && isym->st_shndx != SHN_UNDEF) 1521 1944 ++newlen; 1522 1945 1523 newname = (char *) bfd_alloc (abfd, newlen);1946 newname = (char *) bfd_alloc (abfd, (bfd_size_type) newlen); 1524 1947 if (newname == NULL) 1525 goto error_ return;1526 strcpy (newname, name);1948 goto error_free_vers; 1949 memcpy (newname, name, namelen); 1527 1950 p = newname + namelen; 1528 1951 *p++ = ELF_VER_CHR; … … 1531 1954 default version of the symbol. */ 1532 1955 if ((iver.vs_vers & VERSYM_HIDDEN) == 0 1533 && sym.st_shndx != SHN_UNDEF)1956 && isym->st_shndx != SHN_UNDEF) 1534 1957 *p++ = ELF_VER_CHR; 1535 strcpy (p, verstr);1958 memcpy (p, verstr, verlen + 1); 1536 1959 1537 1960 name = newname; … … 1539 1962 } 1540 1963 1541 if (! elf_merge_symbol (abfd, info, name, &sym, &sec, &value, 1542 sym_hash, &override, &type_change_ok, 1543 &size_change_ok, dt_needed)) 1544 goto error_return; 1964 if (! elf_merge_symbol (abfd, info, name, isym, &sec, &value, 1965 sym_hash, &skip, &override, 1966 &type_change_ok, &size_change_ok, 1967 dt_needed)) 1968 goto error_free_vers; 1969 1970 if (skip) 1971 continue; 1545 1972 1546 1973 if (override) 1547 definition = false;1974 definition = FALSE; 1548 1975 1549 1976 h = *sym_hash; … … 1553 1980 1554 1981 /* Remember the old alignment if this is a common symbol, so 1555 that we don't reduce the alignment later on. We can't 1556 check later, because _bfd_generic_link_add_one_symbol 1557 will set a default for the alignment which we want to 1558 override. */ 1559 if (h->root.type == bfd_link_hash_common) 1560 old_alignment = h->root.u.c.p->alignment_power; 1982 that we don't reduce the alignment later on. We can't 1983 check later, because _bfd_generic_link_add_one_symbol 1984 will set a default for the alignment which we want to 1985 override. We also remember the old bfd where the existing 1986 definition comes from. */ 1987 switch (h->root.type) 1988 { 1989 default: 1990 break; 1991 1992 case bfd_link_hash_defined: 1993 case bfd_link_hash_defweak: 1994 old_bfd = h->root.u.def.section->owner; 1995 break; 1996 1997 case bfd_link_hash_common: 1998 old_bfd = h->root.u.c.p->section->owner; 1999 old_alignment = h->root.u.c.p->alignment_power; 2000 break; 2001 } 1561 2002 1562 2003 if (elf_tdata (abfd)->verdef != NULL … … 1569 2010 if (! (_bfd_generic_link_add_one_symbol 1570 2011 (info, abfd, name, flags, sec, value, (const char *) NULL, 1571 false, collect, (struct bfd_link_hash_entry **) sym_hash)))1572 goto error_ return;2012 FALSE, collect, (struct bfd_link_hash_entry **) sym_hash))) 2013 goto error_free_vers; 1573 2014 1574 2015 h = *sym_hash; … … 1578 2019 *sym_hash = h; 1579 2020 1580 new_weakdef = false;2021 new_weakdef = FALSE; 1581 2022 if (dynamic 1582 2023 && definition 1583 2024 && (flags & BSF_WEAK) != 0 1584 && ELF_ST_TYPE ( sym.st_info) != STT_FUNC2025 && ELF_ST_TYPE (isym->st_info) != STT_FUNC 1585 2026 && info->hash->creator->flavour == bfd_target_elf_flavour 1586 2027 && h->weakdef == NULL) … … 1600 2041 h->weakdef = weaks; 1601 2042 weaks = h; 1602 new_weakdef = true;2043 new_weakdef = TRUE; 1603 2044 } 1604 2045 1605 2046 /* Set the alignment of a common symbol. */ 1606 if ( sym.st_shndx == SHN_COMMON2047 if (isym->st_shndx == SHN_COMMON 1607 2048 && h->root.type == bfd_link_hash_common) 1608 2049 { 1609 2050 unsigned int align; 1610 2051 1611 align = bfd_log2 ( sym.st_value);2052 align = bfd_log2 (isym->st_value); 1612 2053 if (align > old_alignment 1613 2054 /* Permit an alignment power of zero if an alignment of one 1614 2055 is specified and no other alignments have been specified. */ 1615 || ( sym.st_value == 1 && old_alignment == 0))2056 || (isym->st_value == 1 && old_alignment == 0)) 1616 2057 h->root.u.c.p->alignment_power = align; 2058 else 2059 h->root.u.c.p->alignment_power = old_alignment; 1617 2060 } 1618 2061 … … 1620 2063 { 1621 2064 int old_flags; 1622 b oolean dynsym;2065 bfd_boolean dynsym; 1623 2066 int new_flag; 1624 2067 2068 /* Check the alignment when a common symbol is involved. This 2069 can change when a common symbol is overriden by a normal 2070 definition or a common symbol is ignored due to the old 2071 normal definition. We need to make sure the maximum 2072 alignment is maintained. */ 2073 if ((old_alignment || isym->st_shndx == SHN_COMMON) 2074 && h->root.type != bfd_link_hash_common) 2075 { 2076 unsigned int common_align; 2077 unsigned int normal_align; 2078 unsigned int symbol_align; 2079 bfd *normal_bfd; 2080 bfd *common_bfd; 2081 2082 symbol_align = ffs (h->root.u.def.value) - 1; 2083 if ((h->root.u.def.section->owner->flags & DYNAMIC) == 0) 2084 { 2085 normal_align = h->root.u.def.section->alignment_power; 2086 if (normal_align > symbol_align) 2087 normal_align = symbol_align; 2088 } 2089 else 2090 normal_align = symbol_align; 2091 2092 if (old_alignment) 2093 { 2094 common_align = old_alignment; 2095 common_bfd = old_bfd; 2096 normal_bfd = abfd; 2097 } 2098 else 2099 { 2100 common_align = bfd_log2 (isym->st_value); 2101 common_bfd = abfd; 2102 normal_bfd = old_bfd; 2103 } 2104 2105 if (normal_align < common_align) 2106 (*_bfd_error_handler) 2107 (_("Warning: alignment %u of symbol `%s' in %s is smaller than %u in %s"), 2108 1 << normal_align, 2109 name, 2110 bfd_archive_filename (normal_bfd), 2111 1 << common_align, 2112 bfd_archive_filename (common_bfd)); 2113 } 2114 1625 2115 /* Remember the symbol size and type. */ 1626 if ( sym.st_size != 02116 if (isym->st_size != 0 1627 2117 && (definition || h->size == 0)) 1628 2118 { 1629 if (h->size != 0 && h->size != sym.st_size && ! size_change_ok)2119 if (h->size != 0 && h->size != isym->st_size && ! size_change_ok) 1630 2120 (*_bfd_error_handler) 1631 (_("Warning: size of symbol `%s' changed from %lu to %lu in %s"), 1632 name, (unsigned long) h->size, (unsigned long) sym.st_size, 1633 bfd_get_filename (abfd)); 1634 1635 h->size = sym.st_size; 2121 (_("Warning: size of symbol `%s' changed from %lu in %s to %lu in %s"), 2122 name, (unsigned long) h->size, 2123 bfd_archive_filename (old_bfd), 2124 (unsigned long) isym->st_size, 2125 bfd_archive_filename (abfd)); 2126 2127 h->size = isym->st_size; 1636 2128 } 1637 2129 1638 2130 /* If this is a common symbol, then we always want H->SIZE 1639 1640 1641 1642 2131 to be the size of the common symbol. The code just above 2132 won't fix the size if a common symbol becomes larger. We 2133 don't warn about a size change here, because that is 2134 covered by --warn-common. */ 1643 2135 if (h->root.type == bfd_link_hash_common) 1644 2136 h->size = h->root.u.c.size; 1645 2137 1646 if (ELF_ST_TYPE ( sym.st_info) != STT_NOTYPE2138 if (ELF_ST_TYPE (isym->st_info) != STT_NOTYPE 1647 2139 && (definition || h->type == STT_NOTYPE)) 1648 2140 { 1649 2141 if (h->type != STT_NOTYPE 1650 && h->type != ELF_ST_TYPE ( sym.st_info)2142 && h->type != ELF_ST_TYPE (isym->st_info) 1651 2143 && ! type_change_ok) 1652 2144 (*_bfd_error_handler) 1653 2145 (_("Warning: type of symbol `%s' changed from %d to %d in %s"), 1654 name, h->type, ELF_ST_TYPE ( sym.st_info),1655 bfd_ get_filename (abfd));1656 1657 h->type = ELF_ST_TYPE ( sym.st_info);2146 name, h->type, ELF_ST_TYPE (isym->st_info), 2147 bfd_archive_filename (abfd)); 2148 2149 h->type = ELF_ST_TYPE (isym->st_info); 1658 2150 } 1659 2151 1660 /* If st_other has a processor-specific meaning, specific code 1661 might be needed here. */ 1662 if (sym.st_other != 0) 2152 /* If st_other has a processor-specific meaning, specific 2153 code might be needed here. We never merge the visibility 2154 attribute with the one from a dynamic object. */ 2155 if (isym->st_other != 0 && !dynamic) 1663 2156 { 2157 unsigned char hvis, symvis, other, nvis; 2158 2159 /* Take the balance of OTHER from the definition. */ 2160 other = (definition ? isym->st_other : h->other); 2161 other &= ~ ELF_ST_VISIBILITY (-1); 2162 1664 2163 /* Combine visibilities, using the most constraining one. */ 1665 unsigned char hvis = ELF_ST_VISIBILITY (h->other); 1666 unsigned char symvis = ELF_ST_VISIBILITY (sym.st_other); 1667 1668 if (symvis && (hvis > symvis || hvis == 0)) 1669 h->other = sym.st_other; 1670 1671 /* If neither has visibility, use the st_other of the 1672 definition. This is an arbitrary choice, since the 1673 other bits have no general meaning. */ 1674 if (!symvis && !hvis 1675 && (definition || h->other == 0)) 1676 h->other = sym.st_other; 2164 hvis = ELF_ST_VISIBILITY (h->other); 2165 symvis = ELF_ST_VISIBILITY (isym->st_other); 2166 if (! hvis) 2167 nvis = symvis; 2168 else if (! symvis) 2169 nvis = hvis; 2170 else 2171 nvis = hvis < symvis ? hvis : symvis; 2172 2173 h->other = other | nvis; 1677 2174 } 1678 2175 … … 1683 2180 object and a shared object. */ 1684 2181 old_flags = h->elf_link_hash_flags; 1685 dynsym = false;2182 dynsym = FALSE; 1686 2183 if (! dynamic) 1687 2184 { … … 1697 2194 || (old_flags & (ELF_LINK_HASH_DEF_DYNAMIC 1698 2195 | ELF_LINK_HASH_REF_DYNAMIC)) != 0) 1699 dynsym = true;2196 dynsym = TRUE; 1700 2197 } 1701 2198 else … … 1710 2207 && ! new_weakdef 1711 2208 && h->weakdef->dynindx != -1)) 1712 dynsym = true;2209 dynsym = TRUE; 1713 2210 } 1714 2211 1715 2212 h->elf_link_hash_flags |= new_flag; 1716 2213 1717 /* If this symbol has a version, and it is the default 1718 version, we create an indirect symbol from the default 1719 name to the fully decorated name. This will cause 1720 external references which do not specify a version to be 1721 bound to this version of the symbol. */ 2214 /* Check to see if we need to add an indirect symbol for 2215 the default name. */ 1722 2216 if (definition || h->root.type == bfd_link_hash_common) 2217 if (! elf_add_default_symbol (abfd, info, h, name, isym, 2218 &sec, &value, &dynsym, 2219 override, dt_needed)) 2220 goto error_free_vers; 2221 2222 if (definition && !dynamic) 1723 2223 { 1724 char *p; 1725 1726 p = strchr (name, ELF_VER_CHR); 1727 if (p != NULL && p[1] == ELF_VER_CHR) 2224 char *p = strchr (name, ELF_VER_CHR); 2225 if (p != NULL && p[1] != ELF_VER_CHR) 1728 2226 { 1729 char *shortname; 1730 struct elf_link_hash_entry *hi; 1731 boolean override; 1732 1733 shortname = bfd_hash_allocate (&info->hash->table, 1734 p - name + 1); 1735 if (shortname == NULL) 1736 goto error_return; 1737 strncpy (shortname, name, p - name); 1738 shortname[p - name] = '\0'; 1739 1740 /* We are going to create a new symbol. Merge it 1741 with any existing symbol with this name. For the 1742 purposes of the merge, act as though we were 1743 defining the symbol we just defined, although we 1744 actually going to define an indirect symbol. */ 1745 type_change_ok = false; 1746 size_change_ok = false; 1747 if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec, 1748 &value, &hi, &override, 1749 &type_change_ok, 1750 &size_change_ok, dt_needed)) 1751 goto error_return; 1752 1753 if (! override) 2227 /* Queue non-default versions so that .symver x, x@FOO 2228 aliases can be checked. */ 2229 if (! nondeflt_vers) 1754 2230 { 1755 if (! (_bfd_generic_link_add_one_symbol 1756 (info, abfd, shortname, BSF_INDIRECT, 1757 bfd_ind_section_ptr, (bfd_vma) 0, name, false, 1758 collect, (struct bfd_link_hash_entry **) &hi))) 1759 goto error_return; 2231 amt = (isymend - isym + 1) 2232 * sizeof (struct elf_link_hash_entry *); 2233 nondeflt_vers = bfd_malloc (amt); 1760 2234 } 1761 else 1762 { 1763 /* In this case the symbol named SHORTNAME is 1764 overriding the indirect symbol we want to 1765 add. We were planning on making SHORTNAME an 1766 indirect symbol referring to NAME. SHORTNAME 1767 is the name without a version. NAME is the 1768 fully versioned name, and it is the default 1769 version. 1770 1771 Overriding means that we already saw a 1772 definition for the symbol SHORTNAME in a 1773 regular object, and it is overriding the 1774 symbol defined in the dynamic object. 1775 1776 When this happens, we actually want to change 1777 NAME, the symbol we just added, to refer to 1778 SHORTNAME. This will cause references to 1779 NAME in the shared object to become 1780 references to SHORTNAME in the regular 1781 object. This is what we expect when we 1782 override a function in a shared object: that 1783 the references in the shared object will be 1784 mapped to the definition in the regular 1785 object. */ 1786 1787 while (hi->root.type == bfd_link_hash_indirect 1788 || hi->root.type == bfd_link_hash_warning) 1789 hi = (struct elf_link_hash_entry *) hi->root.u.i.link; 1790 1791 h->root.type = bfd_link_hash_indirect; 1792 h->root.u.i.link = (struct bfd_link_hash_entry *) hi; 1793 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) 1794 { 1795 h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC; 1796 hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC; 1797 if (hi->elf_link_hash_flags 1798 & (ELF_LINK_HASH_REF_REGULAR 1799 | ELF_LINK_HASH_DEF_REGULAR)) 1800 { 1801 if (! _bfd_elf_link_record_dynamic_symbol (info, 1802 hi)) 1803 goto error_return; 1804 } 1805 } 1806 1807 /* Now set HI to H, so that the following code 1808 will set the other fields correctly. */ 1809 hi = h; 1810 } 1811 1812 /* If there is a duplicate definition somewhere, 1813 then HI may not point to an indirect symbol. We 1814 will have reported an error to the user in that 1815 case. */ 1816 1817 if (hi->root.type == bfd_link_hash_indirect) 1818 { 1819 struct elf_link_hash_entry *ht; 1820 1821 /* If the symbol became indirect, then we assume 1822 that we have not seen a definition before. */ 1823 BFD_ASSERT ((hi->elf_link_hash_flags 1824 & (ELF_LINK_HASH_DEF_DYNAMIC 1825 | ELF_LINK_HASH_DEF_REGULAR)) 1826 == 0); 1827 1828 ht = (struct elf_link_hash_entry *) hi->root.u.i.link; 1829 (*bed->elf_backend_copy_indirect_symbol) (ht, hi); 1830 1831 /* See if the new flags lead us to realize that 1832 the symbol must be dynamic. */ 1833 if (! dynsym) 1834 { 1835 if (! dynamic) 1836 { 1837 if (info->shared 1838 || ((hi->elf_link_hash_flags 1839 & ELF_LINK_HASH_REF_DYNAMIC) 1840 != 0)) 1841 dynsym = true; 1842 } 1843 else 1844 { 1845 if ((hi->elf_link_hash_flags 1846 & ELF_LINK_HASH_REF_REGULAR) != 0) 1847 dynsym = true; 1848 } 1849 } 1850 } 1851 1852 /* We also need to define an indirection from the 1853 nondefault version of the symbol. */ 1854 1855 shortname = bfd_hash_allocate (&info->hash->table, 1856 strlen (name)); 1857 if (shortname == NULL) 1858 goto error_return; 1859 strncpy (shortname, name, p - name); 1860 strcpy (shortname + (p - name), p + 1); 1861 1862 /* Once again, merge with any existing symbol. */ 1863 type_change_ok = false; 1864 size_change_ok = false; 1865 if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec, 1866 &value, &hi, &override, 1867 &type_change_ok, 1868 &size_change_ok, dt_needed)) 1869 goto error_return; 1870 1871 if (override) 1872 { 1873 /* Here SHORTNAME is a versioned name, so we 1874 don't expect to see the type of override we 1875 do in the case above. */ 1876 (*_bfd_error_handler) 1877 (_("%s: warning: unexpected redefinition of `%s'"), 1878 bfd_get_filename (abfd), shortname); 1879 } 1880 else 1881 { 1882 if (! (_bfd_generic_link_add_one_symbol 1883 (info, abfd, shortname, BSF_INDIRECT, 1884 bfd_ind_section_ptr, (bfd_vma) 0, name, false, 1885 collect, (struct bfd_link_hash_entry **) &hi))) 1886 goto error_return; 1887 1888 /* If there is a duplicate definition somewhere, 1889 then HI may not point to an indirect symbol. 1890 We will have reported an error to the user in 1891 that case. */ 1892 1893 if (hi->root.type == bfd_link_hash_indirect) 1894 { 1895 /* If the symbol became indirect, then we 1896 assume that we have not seen a definition 1897 before. */ 1898 BFD_ASSERT ((hi->elf_link_hash_flags 1899 & (ELF_LINK_HASH_DEF_DYNAMIC 1900 | ELF_LINK_HASH_DEF_REGULAR)) 1901 == 0); 1902 1903 (*bed->elf_backend_copy_indirect_symbol) (h, hi); 1904 1905 /* See if the new flags lead us to realize 1906 that the symbol must be dynamic. */ 1907 if (! dynsym) 1908 { 1909 if (! dynamic) 1910 { 1911 if (info->shared 1912 || ((hi->elf_link_hash_flags 1913 & ELF_LINK_HASH_REF_DYNAMIC) 1914 != 0)) 1915 dynsym = true; 1916 } 1917 else 1918 { 1919 if ((hi->elf_link_hash_flags 1920 & ELF_LINK_HASH_REF_REGULAR) != 0) 1921 dynsym = true; 1922 } 1923 } 1924 } 1925 } 2235 nondeflt_vers [nondeflt_vers_cnt++] = h; 1926 2236 } 1927 2237 } … … 1930 2240 { 1931 2241 if (! _bfd_elf_link_record_dynamic_symbol (info, h)) 1932 goto error_ return;2242 goto error_free_vers; 1933 2243 if (h->weakdef != NULL 1934 2244 && ! new_weakdef 1935 2245 && h->weakdef->dynindx == -1) 1936 2246 { 1937 if (! _bfd_elf_link_record_dynamic_symbol (info, 1938 h->weakdef)) 1939 goto error_return; 2247 if (! _bfd_elf_link_record_dynamic_symbol (info, h->weakdef)) 2248 goto error_free_vers; 1940 2249 } 1941 2250 } … … 1948 2257 case STV_INTERNAL: 1949 2258 case STV_HIDDEN: 1950 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 1951 (*bed->elf_backend_hide_symbol) (info, h); 2259 (*bed->elf_backend_hide_symbol) (info, h, TRUE); 1952 2260 break; 1953 2261 } … … 1960 2268 bfd_size_type strindex; 1961 2269 2270 if (! is_elf_hash_table (info)) 2271 goto error_free_vers; 2272 1962 2273 /* The symbol from a DT_NEEDED object is referenced from 1963 2274 the regular object to create a dynamic executable. We 1964 2275 have to make sure there is a DT_NEEDED entry for it. */ 1965 2276 1966 dt_needed = false; 1967 oldsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr); 1968 strindex = _bfd_stringtab_add (elf_hash_table (info)->dynstr, 1969 elf_dt_soname (abfd), 1970 true, false); 2277 dt_needed = FALSE; 2278 oldsize = _bfd_elf_strtab_size (hash_table->dynstr); 2279 strindex = _bfd_elf_strtab_add (hash_table->dynstr, 2280 elf_dt_soname (abfd), FALSE); 1971 2281 if (strindex == (bfd_size_type) -1) 1972 goto error_return; 1973 1974 if (oldsize 1975 == _bfd_stringtab_size (elf_hash_table (info)->dynstr)) 2282 goto error_free_vers; 2283 2284 if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr)) 1976 2285 { 1977 2286 asection *sdyn; 1978 2287 Elf_External_Dyn *dyncon, *dynconend; 1979 2288 1980 sdyn = bfd_get_section_by_name ( elf_hash_table (info)->dynobj,2289 sdyn = bfd_get_section_by_name (hash_table->dynobj, 1981 2290 ".dynamic"); 1982 2291 BFD_ASSERT (sdyn != NULL); … … 1989 2298 Elf_Internal_Dyn dyn; 1990 2299 1991 elf_swap_dyn_in ( elf_hash_table (info)->dynobj,2300 elf_swap_dyn_in (hash_table->dynobj, 1992 2301 dyncon, &dyn); 1993 2302 BFD_ASSERT (dyn.d_tag != DT_NEEDED || … … 1996 2305 } 1997 2306 1998 if (! elf_add_dynamic_entry (info, DT_NEEDED, strindex))1999 goto error_ return;2307 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_NEEDED, strindex)) 2308 goto error_free_vers; 2000 2309 } 2001 2310 } 2002 2311 } 2312 2313 /* Now that all the symbols from this input file are created, handle 2314 .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */ 2315 if (nondeflt_vers != NULL) 2316 { 2317 bfd_size_type cnt, symidx; 2318 2319 for (cnt = 0; cnt < nondeflt_vers_cnt; ++cnt) 2320 { 2321 struct elf_link_hash_entry *h = nondeflt_vers[cnt], *hi; 2322 char *shortname, *p; 2323 2324 p = strchr (h->root.root.string, ELF_VER_CHR); 2325 if (p == NULL 2326 || (h->root.type != bfd_link_hash_defined 2327 && h->root.type != bfd_link_hash_defweak)) 2328 continue; 2329 2330 amt = p - h->root.root.string; 2331 shortname = bfd_malloc (amt + 1); 2332 memcpy (shortname, h->root.root.string, amt); 2333 shortname[amt] = '\0'; 2334 2335 hi = (struct elf_link_hash_entry *) 2336 bfd_link_hash_lookup (info->hash, shortname, 2337 FALSE, FALSE, FALSE); 2338 if (hi != NULL 2339 && hi->root.type == h->root.type 2340 && hi->root.u.def.value == h->root.u.def.value 2341 && hi->root.u.def.section == h->root.u.def.section) 2342 { 2343 (*bed->elf_backend_hide_symbol) (info, hi, TRUE); 2344 hi->root.type = bfd_link_hash_indirect; 2345 hi->root.u.i.link = (struct bfd_link_hash_entry *) h; 2346 (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi); 2347 sym_hash = elf_sym_hashes (abfd); 2348 if (sym_hash) 2349 for (symidx = 0; symidx < extsymcount; ++symidx) 2350 if (sym_hash[symidx] == hi) 2351 { 2352 sym_hash[symidx] = h; 2353 break; 2354 } 2355 } 2356 free (shortname); 2357 } 2358 free (nondeflt_vers); 2359 nondeflt_vers = NULL; 2360 } 2361 2362 if (extversym != NULL) 2363 { 2364 free (extversym); 2365 extversym = NULL; 2366 } 2367 2368 if (isymbuf != NULL) 2369 free (isymbuf); 2370 isymbuf = NULL; 2003 2371 2004 2372 /* Now set the weakdefs field correctly for all the weak defined … … 2059 2427 2060 2428 /* If the real definition is in the list of dynamic 2061 2062 2063 2064 2429 symbols, make sure the weak definition is put there 2430 as well. If we don't do this, then the dynamic 2431 loader might not merge the entries for the real 2432 definition and the weak definition. */ 2065 2433 if (h->dynindx != -1 2066 2434 && hlook->dynindx == -1) … … 2069 2437 goto error_return; 2070 2438 } 2071 2072 2439 break; 2073 2440 } 2074 2441 } 2075 }2076 2077 if (buf != NULL)2078 {2079 free (buf);2080 buf = NULL;2081 }2082 2083 if (extversym != NULL)2084 {2085 free (extversym);2086 extversym = NULL;2087 2442 } 2088 2443 … … 2114 2469 { 2115 2470 Elf_Internal_Rela *internal_relocs; 2116 b oolean ok;2471 bfd_boolean ok; 2117 2472 2118 2473 if ((o->flags & SEC_RELOC) == 0 … … 2132 2487 ok = (*check_relocs) (abfd, info, o, internal_relocs); 2133 2488 2134 if ( ! info->keep_memory)2489 if (elf_section_data (o)->relocs != internal_relocs) 2135 2490 free (internal_relocs); 2136 2491 … … 2140 2495 } 2141 2496 2142 /* If this is a non-traditional , non-relocateable link, try to2143 o ptimize the handling of the .stab/.stabstr sections. */2497 /* If this is a non-traditional link, try to optimize the handling 2498 of the .stab/.stabstr sections. */ 2144 2499 if (! dynamic 2145 && ! info->relocateable2146 2500 && ! info->traditional_format 2147 2501 && info->hash->creator->flavour == bfd_target_elf_flavour 2502 && is_elf_hash_table (info) 2148 2503 && (info->strip != strip_all && info->strip != strip_debugger)) 2149 2504 { … … 2151 2506 2152 2507 stab = bfd_get_section_by_name (abfd, ".stab"); 2153 if (stab != NULL) 2508 if (stab != NULL 2509 && (stab->flags & SEC_MERGE) == 0 2510 && !bfd_is_abs_section (stab->output_section)) 2154 2511 { 2155 2512 stabstr = bfd_get_section_by_name (abfd, ".stabstr"); … … 2161 2518 secdata = elf_section_data (stab); 2162 2519 if (! _bfd_link_section_stabs (abfd, 2163 & elf_hash_table (info)->stab_info,2520 & hash_table->stab_info, 2164 2521 stab, stabstr, 2165 &secdata->s tab_info))2522 &secdata->sec_info)) 2166 2523 goto error_return; 2524 if (secdata->sec_info) 2525 stab->sec_info_type = ELF_INFO_TYPE_STABS; 2167 2526 } 2168 2527 } 2169 2528 } 2170 2529 2171 return true; 2172 2173 error_return: 2174 if (buf != NULL) 2175 free (buf); 2176 if (dynbuf != NULL) 2177 free (dynbuf); 2530 if (! info->relocateable && ! dynamic 2531 && is_elf_hash_table (info)) 2532 { 2533 asection *s; 2534 2535 for (s = abfd->sections; s != NULL; s = s->next) 2536 if ((s->flags & SEC_MERGE) != 0 2537 && !bfd_is_abs_section (s->output_section)) 2538 { 2539 struct bfd_elf_section_data *secdata; 2540 2541 secdata = elf_section_data (s); 2542 if (! _bfd_merge_section (abfd, 2543 & hash_table->merge_info, 2544 s, &secdata->sec_info)) 2545 goto error_return; 2546 else if (secdata->sec_info) 2547 s->sec_info_type = ELF_INFO_TYPE_MERGE; 2548 } 2549 } 2550 2551 if (is_elf_hash_table (info)) 2552 { 2553 /* Add this bfd to the loaded list. */ 2554 struct elf_link_loaded_list *n; 2555 2556 n = ((struct elf_link_loaded_list *) 2557 bfd_alloc (abfd, sizeof (struct elf_link_loaded_list))); 2558 if (n == NULL) 2559 goto error_return; 2560 n->abfd = abfd; 2561 n->next = hash_table->loaded; 2562 hash_table->loaded = n; 2563 } 2564 2565 return TRUE; 2566 2567 error_free_vers: 2568 if (nondeflt_vers != NULL) 2569 free (nondeflt_vers); 2178 2570 if (extversym != NULL) 2179 2571 free (extversym); 2180 return false; 2572 error_free_sym: 2573 if (isymbuf != NULL) 2574 free (isymbuf); 2575 error_return: 2576 return FALSE; 2181 2577 } 2182 2578 … … 2188 2584 actual contents and size of these sections later. */ 2189 2585 2190 b oolean2586 bfd_boolean 2191 2587 elf_link_create_dynamic_sections (abfd, info) 2192 2588 bfd *abfd; … … 2196 2592 register asection *s; 2197 2593 struct elf_link_hash_entry *h; 2594 struct bfd_link_hash_entry *bh; 2198 2595 struct elf_backend_data *bed; 2199 2596 2597 if (! is_elf_hash_table (info)) 2598 return FALSE; 2599 2200 2600 if (elf_hash_table (info)->dynamic_sections_created) 2201 return true;2601 return TRUE; 2202 2602 2203 2603 /* Make sure that all dynamic sections use the same input BFD. */ … … 2219 2619 if (s == NULL 2220 2620 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)) 2221 return false; 2621 return FALSE; 2622 } 2623 2624 if (! info->traditional_format 2625 && info->hash->creator->flavour == bfd_target_elf_flavour) 2626 { 2627 s = bfd_make_section (abfd, ".eh_frame_hdr"); 2628 if (s == NULL 2629 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2630 || ! bfd_set_section_alignment (abfd, s, 2)) 2631 return FALSE; 2632 elf_hash_table (info)->eh_info.hdr_sec = s; 2222 2633 } 2223 2634 … … 2228 2639 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2229 2640 || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN)) 2230 return false;2641 return FALSE; 2231 2642 2232 2643 s = bfd_make_section (abfd, ".gnu.version"); … … 2234 2645 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2235 2646 || ! bfd_set_section_alignment (abfd, s, 1)) 2236 return false;2647 return FALSE; 2237 2648 2238 2649 s = bfd_make_section (abfd, ".gnu.version_r"); … … 2240 2651 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2241 2652 || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN)) 2242 return false;2653 return FALSE; 2243 2654 2244 2655 s = bfd_make_section (abfd, ".dynsym"); … … 2246 2657 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2247 2658 || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN)) 2248 return false;2659 return FALSE; 2249 2660 2250 2661 s = bfd_make_section (abfd, ".dynstr"); 2251 2662 if (s == NULL 2252 2663 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)) 2253 return false;2664 return FALSE; 2254 2665 2255 2666 /* Create a strtab to hold the dynamic symbol names. */ 2256 2667 if (elf_hash_table (info)->dynstr == NULL) 2257 2668 { 2258 elf_hash_table (info)->dynstr = elf_stringtab_init ();2669 elf_hash_table (info)->dynstr = _bfd_elf_strtab_init (); 2259 2670 if (elf_hash_table (info)->dynstr == NULL) 2260 return false;2671 return FALSE; 2261 2672 } 2262 2673 … … 2265 2676 || ! bfd_set_section_flags (abfd, s, flags) 2266 2677 || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN)) 2267 return false;2678 return FALSE; 2268 2679 2269 2680 /* The special symbol _DYNAMIC is always set to the start of the … … 2275 2686 is no .dynamic section, since on some ELF platforms the start up 2276 2687 code examines it to decide how to initialize the process. */ 2277 h = NULL;2688 bh = NULL; 2278 2689 if (! (_bfd_generic_link_add_one_symbol 2279 2690 (info, abfd, "_DYNAMIC", BSF_GLOBAL, s, (bfd_vma) 0, 2280 (const char *) NULL, false, get_elf_backend_data (abfd)->collect,2281 (struct bfd_link_hash_entry **) &h))) 2282 return false;2691 (const char *) 0, FALSE, get_elf_backend_data (abfd)->collect, &bh))) 2692 return FALSE; 2693 h = (struct elf_link_hash_entry *) bh; 2283 2694 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 2284 2695 h->type = STT_OBJECT; … … 2286 2697 if (info->shared 2287 2698 && ! _bfd_elf_link_record_dynamic_symbol (info, h)) 2288 return false;2699 return FALSE; 2289 2700 2290 2701 bed = get_elf_backend_data (abfd); … … 2294 2705 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2295 2706 || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN)) 2296 return false;2707 return FALSE; 2297 2708 elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry; 2298 2709 … … 2301 2712 the .got and .plt sections. */ 2302 2713 if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info)) 2303 return false;2304 2305 elf_hash_table (info)->dynamic_sections_created = true;2306 2307 return true;2714 return FALSE; 2715 2716 elf_hash_table (info)->dynamic_sections_created = TRUE; 2717 2718 return TRUE; 2308 2719 } 2309 2720 2310 2721 /* Add an entry to the .dynamic table. */ 2311 2722 2312 b oolean2723 bfd_boolean 2313 2724 elf_add_dynamic_entry (info, tag, val) 2314 2725 struct bfd_link_info *info; … … 2319 2730 bfd *dynobj; 2320 2731 asection *s; 2321 size_tnewsize;2732 bfd_size_type newsize; 2322 2733 bfd_byte *newcontents; 2734 2735 if (! is_elf_hash_table (info)) 2736 return FALSE; 2323 2737 2324 2738 dynobj = elf_hash_table (info)->dynobj; … … 2330 2744 newcontents = (bfd_byte *) bfd_realloc (s->contents, newsize); 2331 2745 if (newcontents == NULL) 2332 return false;2746 return FALSE; 2333 2747 2334 2748 dyn.d_tag = tag; … … 2340 2754 s->contents = newcontents; 2341 2755 2342 return true; 2343 } 2344 2345 /* Record a new local dynamic symbol. */ 2346 2347 boolean 2348 elf_link_record_local_dynamic_symbol (info, input_bfd, input_indx) 2349 struct bfd_link_info *info; 2350 bfd *input_bfd; 2351 long input_indx; 2352 { 2353 struct elf_link_local_dynamic_entry *entry; 2354 struct elf_link_hash_table *eht; 2355 struct bfd_strtab_hash *dynstr; 2356 Elf_External_Sym esym; 2357 unsigned long dynstr_index; 2358 char *name; 2359 2360 /* See if the entry exists already. */ 2361 for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next) 2362 if (entry->input_bfd == input_bfd && entry->input_indx == input_indx) 2363 return true; 2364 2365 entry = (struct elf_link_local_dynamic_entry *) 2366 bfd_alloc (input_bfd, sizeof (*entry)); 2367 if (entry == NULL) 2368 return false; 2369 2370 /* Go find the symbol, so that we can find it's name. */ 2371 if (bfd_seek (input_bfd, 2372 (elf_tdata (input_bfd)->symtab_hdr.sh_offset 2373 + input_indx * sizeof (Elf_External_Sym)), 2374 SEEK_SET) != 0 2375 || (bfd_read (&esym, sizeof (Elf_External_Sym), 1, input_bfd) 2376 != sizeof (Elf_External_Sym))) 2377 return false; 2378 elf_swap_symbol_in (input_bfd, &esym, &entry->isym); 2379 2380 name = (bfd_elf_string_from_elf_section 2381 (input_bfd, elf_tdata (input_bfd)->symtab_hdr.sh_link, 2382 entry->isym.st_name)); 2383 2384 dynstr = elf_hash_table (info)->dynstr; 2385 if (dynstr == NULL) 2386 { 2387 /* Create a strtab to hold the dynamic symbol names. */ 2388 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_stringtab_init (); 2389 if (dynstr == NULL) 2390 return false; 2391 } 2392 2393 dynstr_index = _bfd_stringtab_add (dynstr, name, true, false); 2394 if (dynstr_index == (unsigned long) -1) 2395 return false; 2396 entry->isym.st_name = dynstr_index; 2397 2398 eht = elf_hash_table (info); 2399 2400 entry->next = eht->dynlocal; 2401 eht->dynlocal = entry; 2402 entry->input_bfd = input_bfd; 2403 entry->input_indx = input_indx; 2404 eht->dynsymcount++; 2405 2406 /* Whatever binding the symbol had before, it's now local. */ 2407 entry->isym.st_info 2408 = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info)); 2409 2410 /* The dynindx will be set at the end of size_dynamic_sections. */ 2411 2412 return true; 2756 return TRUE; 2413 2757 } 2414 2758 … … 2421 2765 relocations should be stored. 2422 2766 2423 Returns falseif something goes wrong. */2424 2425 static b oolean2767 Returns FALSE if something goes wrong. */ 2768 2769 static bfd_boolean 2426 2770 elf_link_read_relocs_from_section (abfd, shdr, external_relocs, 2427 2771 internal_relocs) … … 2432 2776 { 2433 2777 struct elf_backend_data *bed; 2778 void (*swap_in) PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *)); 2779 const bfd_byte *erela; 2780 const bfd_byte *erelaend; 2781 Elf_Internal_Rela *irela; 2434 2782 2435 2783 /* If there aren't any relocations, that's OK. */ 2436 2784 if (!shdr) 2437 return true;2785 return TRUE; 2438 2786 2439 2787 /* Position ourselves at the start of the section. */ 2440 2788 if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0) 2441 return false;2789 return FALSE; 2442 2790 2443 2791 /* Read the relocations. */ 2444 if (bfd_read (external_relocs, 1, shdr->sh_size, abfd) 2445 != shdr->sh_size) 2446 return false; 2792 if (bfd_bread (external_relocs, shdr->sh_size, abfd) != shdr->sh_size) 2793 return FALSE; 2447 2794 2448 2795 bed = get_elf_backend_data (abfd); … … 2450 2797 /* Convert the external relocations to the internal format. */ 2451 2798 if (shdr->sh_entsize == sizeof (Elf_External_Rel)) 2452 { 2453 Elf_External_Rel *erel; 2454 Elf_External_Rel *erelend; 2455 Elf_Internal_Rela *irela; 2456 Elf_Internal_Rel *irel; 2457 2458 erel = (Elf_External_Rel *) external_relocs; 2459 erelend = erel + NUM_SHDR_ENTRIES (shdr); 2460 irela = internal_relocs; 2461 irel = bfd_alloc (abfd, (bed->s->int_rels_per_ext_rel 2462 * sizeof (Elf_Internal_Rel))); 2463 for (; erel < erelend; erel++, irela += bed->s->int_rels_per_ext_rel) 2464 { 2465 unsigned int i; 2466 2467 if (bed->s->swap_reloc_in) 2468 (*bed->s->swap_reloc_in) (abfd, (bfd_byte *) erel, irel); 2469 else 2470 elf_swap_reloc_in (abfd, erel, irel); 2471 2472 for (i = 0; i < bed->s->int_rels_per_ext_rel; ++i) 2473 { 2474 irela[i].r_offset = irel[i].r_offset; 2475 irela[i].r_info = irel[i].r_info; 2476 irela[i].r_addend = 0; 2477 } 2478 } 2479 } 2799 swap_in = bed->s->swap_reloc_in; 2800 else if (shdr->sh_entsize == sizeof (Elf_External_Rela)) 2801 swap_in = bed->s->swap_reloca_in; 2480 2802 else 2481 2803 { 2482 Elf_External_Rela *erela; 2483 Elf_External_Rela *erelaend; 2484 Elf_Internal_Rela *irela; 2485 2486 BFD_ASSERT (shdr->sh_entsize == sizeof (Elf_External_Rela)); 2487 2488 erela = (Elf_External_Rela *) external_relocs; 2489 erelaend = erela + NUM_SHDR_ENTRIES (shdr); 2490 irela = internal_relocs; 2491 for (; erela < erelaend; erela++, irela += bed->s->int_rels_per_ext_rel) 2492 { 2493 if (bed->s->swap_reloca_in) 2494 (*bed->s->swap_reloca_in) (abfd, (bfd_byte *) erela, irela); 2495 else 2496 elf_swap_reloca_in (abfd, erela, irela); 2497 } 2498 } 2499 2500 return true; 2804 bfd_set_error (bfd_error_wrong_format); 2805 return FALSE; 2806 } 2807 2808 erela = external_relocs; 2809 erelaend = erela + NUM_SHDR_ENTRIES (shdr) * shdr->sh_entsize; 2810 irela = internal_relocs; 2811 while (erela < erelaend) 2812 { 2813 (*swap_in) (abfd, erela, irela); 2814 irela += bed->s->int_rels_per_ext_rel; 2815 erela += shdr->sh_entsize; 2816 } 2817 2818 return TRUE; 2501 2819 } 2502 2820 … … 2518 2836 PTR external_relocs; 2519 2837 Elf_Internal_Rela *internal_relocs; 2520 b oolean keep_memory;2838 bfd_boolean keep_memory; 2521 2839 { 2522 2840 Elf_Internal_Shdr *rel_hdr; … … 2535 2853 if (internal_relocs == NULL) 2536 2854 { 2537 size_tsize;2538 2539 size = (o->reloc_count * bed->s->int_rels_per_ext_rel2540 * sizeof (Elf_Internal_Rela));2855 bfd_size_type size; 2856 2857 size = o->reloc_count; 2858 size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela); 2541 2859 if (keep_memory) 2542 2860 internal_relocs = (Elf_Internal_Rela *) bfd_alloc (abfd, size); … … 2549 2867 if (external_relocs == NULL) 2550 2868 { 2551 size_t size = (size_t)rel_hdr->sh_size;2869 bfd_size_type size = rel_hdr->sh_size; 2552 2870 2553 2871 if (elf_section_data (o)->rel_hdr2) 2554 size += (size_t)elf_section_data (o)->rel_hdr2->sh_size;2872 size += elf_section_data (o)->rel_hdr2->sh_size; 2555 2873 alloc1 = (PTR) bfd_malloc (size); 2556 2874 if (alloc1 == NULL) … … 2595 2913 this in case some dynamic object refers to this symbol. */ 2596 2914 2597 /*ARGSUSED*/ 2598 boolean 2915 bfd_boolean 2599 2916 NAME(bfd_elf,record_link_assignment) (output_bfd, info, name, provide) 2600 2917 bfd *output_bfd ATTRIBUTE_UNUSED; 2601 2918 struct bfd_link_info *info; 2602 2919 const char *name; 2603 b oolean provide;2920 bfd_boolean provide; 2604 2921 { 2605 2922 struct elf_link_hash_entry *h; 2606 2923 2607 2924 if (info->hash->creator->flavour != bfd_target_elf_flavour) 2608 return true;2609 2610 h = elf_link_hash_lookup (elf_hash_table (info), name, true, true, false);2925 return TRUE; 2926 2927 h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, TRUE, FALSE); 2611 2928 if (h == NULL) 2612 return false;2929 return FALSE; 2613 2930 2614 2931 if (h->root.type == bfd_link_hash_new) 2615 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;2932 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; 2616 2933 2617 2934 /* If this symbol is being provided by the linker script, and it is … … 2635 2952 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 2636 2953 2637 /* When possible, keep the original type of the symbol */2638 if (h->type == STT_NOTYPE)2639 h->type = STT_OBJECT;2640 2641 2954 if (((h->elf_link_hash_flags & (ELF_LINK_HASH_DEF_DYNAMIC 2642 2955 | ELF_LINK_HASH_REF_DYNAMIC)) != 0 … … 2645 2958 { 2646 2959 if (! _bfd_elf_link_record_dynamic_symbol (info, h)) 2647 return false;2960 return FALSE; 2648 2961 2649 2962 /* If this is a weak defined symbol, and we know a corresponding … … 2654 2967 { 2655 2968 if (! _bfd_elf_link_record_dynamic_symbol (info, h->weakdef)) 2656 return false;2657 } 2658 } 2659 2660 return true;2969 return FALSE; 2970 } 2971 } 2972 2973 return TRUE; 2661 2974 } 2662 2975 … … 2673 2986 /* Version tree. */ 2674 2987 struct bfd_elf_version_tree *verdefs; 2675 /* Whether we are exporting all dynamic symbols. */2676 boolean export_dynamic;2677 2988 /* Whether we had a failure. */ 2678 b oolean failed;2989 bfd_boolean failed; 2679 2990 }; 2680 2991 … … 2691 3002 unsigned int vers; 2692 3003 /* Whether we had a failure. */ 2693 b oolean failed;3004 bfd_boolean failed; 2694 3005 }; 2695 3006 … … 2723 3034 unsigned long int *hashcodesp; 2724 3035 unsigned long int i; 3036 bfd_size_type amt; 2725 3037 2726 3038 /* Compute the hash values for all exported symbols. At the same 2727 3039 time store the values in an array so that we could use them for 2728 3040 optimizations. */ 2729 hashcodes = (unsigned long int *) bfd_malloc (dynsymcount 2730 * sizeof (unsigned long int)); 3041 amt = dynsymcount; 3042 amt *= sizeof (unsigned long int); 3043 hashcodes = (unsigned long int *) bfd_malloc (amt); 2731 3044 if (hashcodes == NULL) 2732 3045 return 0; … … 2737 3050 elf_collect_hash_codes, &hashcodesp); 2738 3051 2739 /* We have a problem here. The following code to optimize the table2740 size requires an integer type with more the 32 bits. If2741 BFD_HOST_U_64_BIT is set we know about such a type. */3052 /* We have a problem here. The following code to optimize the table 3053 size requires an integer type with more the 32 bits. If 3054 BFD_HOST_U_64_BIT is set we know about such a type. */ 2742 3055 #ifdef BFD_HOST_U_64_BIT 2743 if (info->optimize == true)3056 if (info->optimize) 2744 3057 { 2745 3058 unsigned long int nsyms = hashcodesp - hashcodes; … … 2759 3072 /* Create array where we count the collisions in. We must use bfd_malloc 2760 3073 since the size could be large. */ 2761 counts = (unsigned long int *) bfd_malloc (maxsize 2762 * sizeof (unsigned long int)); 3074 amt = maxsize; 3075 amt *= sizeof (unsigned long int); 3076 counts = (unsigned long int *) bfd_malloc (amt); 2763 3077 if (counts == NULL) 2764 3078 { … … 2854 3168 addresses of the various sections. */ 2855 3169 2856 b oolean3170 bfd_boolean 2857 3171 NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath, 2858 export_dynamic,filter_shlib,3172 filter_shlib, 2859 3173 auxiliary_filters, info, sinterpptr, 2860 3174 verdefs) … … 2862 3176 const char *soname; 2863 3177 const char *rpath; 2864 boolean export_dynamic;2865 3178 const char *filter_shlib; 2866 3179 const char * const *auxiliary_filters; … … 2879 3192 2880 3193 if (info->hash->creator->flavour != bfd_target_elf_flavour) 2881 return true; 3194 return TRUE; 3195 3196 if (! is_elf_hash_table (info)) 3197 return TRUE; 3198 3199 /* Any syms created from now on start with -1 in 3200 got.refcount/offset and plt.refcount/offset. */ 3201 elf_hash_table (info)->init_refcount = elf_hash_table (info)->init_offset; 2882 3202 2883 3203 /* The backend may have to create some sections regardless of whether … … 2886 3206 if (bed->elf_backend_always_size_sections 2887 3207 && ! (*bed->elf_backend_always_size_sections) (output_bfd, info)) 2888 return false;3208 return FALSE; 2889 3209 2890 3210 dynobj = elf_hash_table (info)->dynobj; … … 2893 3213 do here. */ 2894 3214 if (dynobj == NULL) 2895 return true; 3215 return TRUE; 3216 3217 if (! _bfd_elf_maybe_strip_eh_frame_hdr (info)) 3218 return FALSE; 2896 3219 2897 3220 if (elf_hash_table (info)->dynamic_sections_created) … … 2900 3223 struct elf_link_hash_entry *h; 2901 3224 asection *dynstr; 3225 struct bfd_elf_version_tree *t; 3226 struct bfd_elf_version_expr *d; 3227 bfd_boolean all_defined; 2902 3228 2903 3229 *sinterpptr = bfd_get_section_by_name (dynobj, ".interp"); … … 2906 3232 if (soname != NULL) 2907 3233 { 2908 soname_indx = _bfd_ stringtab_add (elf_hash_table (info)->dynstr,2909 soname, true, true);3234 soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, 3235 soname, TRUE); 2910 3236 if (soname_indx == (bfd_size_type) -1 2911 || ! elf_add_dynamic_entry (info, DT_SONAME, soname_indx)) 2912 return false; 3237 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_SONAME, 3238 soname_indx)) 3239 return FALSE; 2913 3240 } 2914 3241 2915 3242 if (info->symbolic) 2916 3243 { 2917 if (! elf_add_dynamic_entry (info, DT_SYMBOLIC, 0)) 2918 return false; 3244 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_SYMBOLIC, 3245 (bfd_vma) 0)) 3246 return FALSE; 2919 3247 info->flags |= DF_SYMBOLIC; 2920 3248 } … … 2924 3252 bfd_size_type indx; 2925 3253 2926 indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr, rpath, 2927 true, true); 3254 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, rpath, 3255 TRUE); 3256 if (info->new_dtags) 3257 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, indx); 2928 3258 if (indx == (bfd_size_type) -1 2929 || ! elf_add_dynamic_entry (info, DT_RPATH, indx)3259 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_RPATH, indx) 2930 3260 || (info->new_dtags 2931 && ! elf_add_dynamic_entry (info, DT_RUNPATH, indx))) 2932 return false; 3261 && ! elf_add_dynamic_entry (info, (bfd_vma) DT_RUNPATH, 3262 indx))) 3263 return FALSE; 2933 3264 } 2934 3265 … … 2937 3268 bfd_size_type indx; 2938 3269 2939 indx = _bfd_ stringtab_add (elf_hash_table (info)->dynstr,2940 filter_shlib, true, true);3270 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, 3271 filter_shlib, TRUE); 2941 3272 if (indx == (bfd_size_type) -1 2942 || ! elf_add_dynamic_entry (info, DT_FILTER, indx))2943 return false;3273 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_FILTER, indx)) 3274 return FALSE; 2944 3275 } 2945 3276 … … 2952 3283 bfd_size_type indx; 2953 3284 2954 indx = _bfd_ stringtab_add (elf_hash_table (info)->dynstr,2955 *p, true, true);3285 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, 3286 *p, TRUE); 2956 3287 if (indx == (bfd_size_type) -1 2957 || ! elf_add_dynamic_entry (info, DT_AUXILIARY, indx)) 2958 return false; 3288 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_AUXILIARY, 3289 indx)) 3290 return FALSE; 2959 3291 } 2960 3292 } 2961 3293 2962 3294 eif.info = info; 2963 eif.failed = false; 3295 eif.verdefs = verdefs; 3296 eif.failed = FALSE; 2964 3297 2965 3298 /* If we are supposed to export all symbols into the dynamic symbol 2966 2967 if ( export_dynamic)3299 table (this is not the normal case), then do so. */ 3300 if (info->export_dynamic) 2968 3301 { 2969 3302 elf_link_hash_traverse (elf_hash_table (info), elf_export_symbol, 2970 3303 (PTR) &eif); 2971 3304 if (eif.failed) 2972 return false; 2973 } 3305 return FALSE; 3306 } 3307 3308 /* Make all global versions with definiton. */ 3309 for (t = verdefs; t != NULL; t = t->next) 3310 for (d = t->globals; d != NULL; d = d->next) 3311 if (!d->symver && strchr (d->pattern, '*') == NULL) 3312 { 3313 const char *verstr, *name; 3314 size_t namelen, verlen, newlen; 3315 char *newname, *p; 3316 struct elf_link_hash_entry *newh; 3317 3318 name = d->pattern; 3319 namelen = strlen (name); 3320 verstr = t->name; 3321 verlen = strlen (verstr); 3322 newlen = namelen + verlen + 3; 3323 3324 newname = (char *) bfd_malloc ((bfd_size_type) newlen); 3325 if (newname == NULL) 3326 return FALSE; 3327 memcpy (newname, name, namelen); 3328 3329 /* Check the hidden versioned definition. */ 3330 p = newname + namelen; 3331 *p++ = ELF_VER_CHR; 3332 memcpy (p, verstr, verlen + 1); 3333 newh = elf_link_hash_lookup (elf_hash_table (info), 3334 newname, FALSE, FALSE, 3335 FALSE); 3336 if (newh == NULL 3337 || (newh->root.type != bfd_link_hash_defined 3338 && newh->root.type != bfd_link_hash_defweak)) 3339 { 3340 /* Check the default versioned definition. */ 3341 *p++ = ELF_VER_CHR; 3342 memcpy (p, verstr, verlen + 1); 3343 newh = elf_link_hash_lookup (elf_hash_table (info), 3344 newname, FALSE, FALSE, 3345 FALSE); 3346 } 3347 free (newname); 3348 3349 /* Mark this version if there is a definition and it is 3350 not defined in a shared object. */ 3351 if (newh != NULL 3352 && ((newh->elf_link_hash_flags 3353 & ELF_LINK_HASH_DEF_DYNAMIC) == 0) 3354 && (newh->root.type == bfd_link_hash_defined 3355 || newh->root.type == bfd_link_hash_defweak)) 3356 d->symver = 1; 3357 } 2974 3358 2975 3359 /* Attach all the symbols to their version information. */ … … 2977 3361 asvinfo.info = info; 2978 3362 asvinfo.verdefs = verdefs; 2979 asvinfo.export_dynamic = export_dynamic; 2980 asvinfo.failed = false; 3363 asvinfo.failed = FALSE; 2981 3364 2982 3365 elf_link_hash_traverse (elf_hash_table (info), … … 2984 3367 (PTR) &asvinfo); 2985 3368 if (asvinfo.failed) 2986 return false; 3369 return FALSE; 3370 3371 if (!info->allow_undefined_version) 3372 { 3373 /* Check if all global versions have a definiton. */ 3374 all_defined = TRUE; 3375 for (t = verdefs; t != NULL; t = t->next) 3376 for (d = t->globals; d != NULL; d = d->next) 3377 if (!d->symver && !d->script 3378 && strchr (d->pattern, '*') == NULL) 3379 { 3380 (*_bfd_error_handler) 3381 (_("%s: undefined version: %s"), 3382 d->pattern, t->name); 3383 all_defined = FALSE; 3384 } 3385 3386 if (!all_defined) 3387 { 3388 bfd_set_error (bfd_error_bad_value); 3389 return FALSE; 3390 } 3391 } 2987 3392 2988 3393 /* Find all symbols which were defined in a dynamic object and make … … 2992 3397 (PTR) &eif); 2993 3398 if (eif.failed) 2994 return false;3399 return FALSE; 2995 3400 2996 3401 /* Add some entries to the .dynamic section. We fill in some of the … … 3002 3407 h = (info->init_function 3003 3408 ? elf_link_hash_lookup (elf_hash_table (info), 3004 info->init_function, false,3005 false, false)3409 info->init_function, FALSE, 3410 FALSE, FALSE) 3006 3411 : NULL); 3007 3412 if (h != NULL … … 3009 3414 | ELF_LINK_HASH_DEF_REGULAR)) != 0) 3010 3415 { 3011 if (! elf_add_dynamic_entry (info, DT_INIT,0))3012 return false;3416 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_INIT, (bfd_vma) 0)) 3417 return FALSE; 3013 3418 } 3014 3419 h = (info->fini_function 3015 3420 ? elf_link_hash_lookup (elf_hash_table (info), 3016 info->fini_function, false,3017 false, false)3421 info->fini_function, FALSE, 3422 FALSE, FALSE) 3018 3423 : NULL); 3019 3424 if (h != NULL … … 3021 3426 | ELF_LINK_HASH_DEF_REGULAR)) != 0) 3022 3427 { 3023 if (! elf_add_dynamic_entry (info, DT_FINI, 0)) 3024 return false; 3428 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_FINI, (bfd_vma) 0)) 3429 return FALSE; 3430 } 3431 3432 if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL) 3433 { 3434 /* DT_PREINIT_ARRAY is not allowed in shared library. */ 3435 if (info->shared) 3436 { 3437 bfd *sub; 3438 asection *o; 3439 3440 for (sub = info->input_bfds; sub != NULL; 3441 sub = sub->link_next) 3442 for (o = sub->sections; o != NULL; o = o->next) 3443 if (elf_section_data (o)->this_hdr.sh_type 3444 == SHT_PREINIT_ARRAY) 3445 { 3446 (*_bfd_error_handler) 3447 (_("%s: .preinit_array section is not allowed in DSO"), 3448 bfd_archive_filename (sub)); 3449 break; 3450 } 3451 3452 bfd_set_error (bfd_error_nonrepresentable_section); 3453 return FALSE; 3454 } 3455 3456 if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY, 3457 (bfd_vma) 0) 3458 || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ, 3459 (bfd_vma) 0)) 3460 return FALSE; 3461 } 3462 if (bfd_get_section_by_name (output_bfd, ".init_array") != NULL) 3463 { 3464 if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY, 3465 (bfd_vma) 0) 3466 || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ, 3467 (bfd_vma) 0)) 3468 return FALSE; 3469 } 3470 if (bfd_get_section_by_name (output_bfd, ".fini_array") != NULL) 3471 { 3472 if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY, 3473 (bfd_vma) 0) 3474 || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ, 3475 (bfd_vma) 0)) 3476 return FALSE; 3025 3477 } 3026 3478 … … 3034 3486 bfd_size_type strsize; 3035 3487 3036 strsize = _bfd_ stringtab_size (elf_hash_table (info)->dynstr);3037 if (! elf_add_dynamic_entry (info, DT_HASH,0)3038 || ! elf_add_dynamic_entry (info, DT_STRTAB,0)3039 || ! elf_add_dynamic_entry (info, DT_SYMTAB,0)3040 || ! elf_add_dynamic_entry (info, DT_STRSZ, strsize)3041 || ! elf_add_dynamic_entry (info, DT_SYMENT,3042 sizeof (Elf_External_Sym)))3043 return false;3488 strsize = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr); 3489 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_HASH, (bfd_vma) 0) 3490 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_STRTAB, (bfd_vma) 0) 3491 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_SYMTAB, (bfd_vma) 0) 3492 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_STRSZ, strsize) 3493 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_SYMENT, 3494 (bfd_vma) sizeof (Elf_External_Sym))) 3495 return FALSE; 3044 3496 } 3045 3497 } … … 3049 3501 if (bed->elf_backend_size_dynamic_sections 3050 3502 && ! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info)) 3051 return false;3503 return FALSE; 3052 3504 3053 3505 if (elf_hash_table (info)->dynamic_sections_created) 3054 3506 { 3055 size_tdynsymcount;3507 bfd_size_type dynsymcount; 3056 3508 asection *s; 3057 3509 size_t bucketcount = 0; 3058 3510 size_t hash_entry_size; 3511 unsigned int dtagcount; 3059 3512 3060 3513 /* Set up the version definition section. */ … … 3063 3516 3064 3517 /* We may have created additional version definitions if we are 3065 3518 just linking a regular application. */ 3066 3519 verdefs = asvinfo.verdefs; 3520 3521 /* Skip anonymous version tag. */ 3522 if (verdefs != NULL && verdefs->vernum == 0) 3523 verdefs = verdefs->next; 3067 3524 3068 3525 if (verdefs == NULL) … … 3100 3557 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size); 3101 3558 if (s->contents == NULL && s->_raw_size != 0) 3102 return false;3559 return FALSE; 3103 3560 3104 3561 /* Fill in the version definition section. */ … … 3116 3573 if (soname_indx != (bfd_size_type) -1) 3117 3574 { 3575 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, 3576 soname_indx); 3118 3577 def.vd_hash = bfd_elf_hash (soname); 3119 3578 defaux.vda_name = soname_indx; … … 3124 3583 bfd_size_type indx; 3125 3584 3126 name = output_bfd->filename;3585 name = basename (output_bfd->filename); 3127 3586 def.vd_hash = bfd_elf_hash (name); 3128 indx = _bfd_ stringtab_add (elf_hash_table (info)->dynstr,3129 name, true, false);3587 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, 3588 name, FALSE); 3130 3589 if (indx == (bfd_size_type) -1) 3131 return false;3590 return FALSE; 3132 3591 defaux.vda_name = indx; 3133 3592 } … … 3135 3594 3136 3595 _bfd_elf_swap_verdef_out (output_bfd, &def, 3137 (Elf_External_Verdef *) p);3596 (Elf_External_Verdef *) p); 3138 3597 p += sizeof (Elf_External_Verdef); 3139 3598 _bfd_elf_swap_verdaux_out (output_bfd, &defaux, … … 3146 3605 struct bfd_elf_version_deps *n; 3147 3606 struct elf_link_hash_entry *h; 3607 struct bfd_link_hash_entry *bh; 3148 3608 3149 3609 cdeps = 0; … … 3152 3612 3153 3613 /* Add a symbol representing this version. */ 3154 h = NULL;3614 bh = NULL; 3155 3615 if (! (_bfd_generic_link_add_one_symbol 3156 3616 (info, dynobj, t->name, BSF_GLOBAL, bfd_abs_section_ptr, 3157 (bfd_vma) 0, (const char *) NULL, false,3158 get_elf_backend_data (dynobj)->collect, 3159 (struct bfd_link_hash_entry **) &h)))3160 return false;3617 (bfd_vma) 0, (const char *) NULL, FALSE, 3618 get_elf_backend_data (dynobj)->collect, &bh))) 3619 return FALSE; 3620 h = (struct elf_link_hash_entry *) bh; 3161 3621 h->elf_link_hash_flags &= ~ ELF_LINK_NON_ELF; 3162 3622 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; … … 3165 3625 3166 3626 if (! _bfd_elf_link_record_dynamic_symbol (info, h)) 3167 return false;3627 return FALSE; 3168 3628 3169 3629 def.vd_version = VER_DEF_CURRENT; … … 3186 3646 3187 3647 defaux.vda_name = h->dynstr_index; 3648 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, 3649 h->dynstr_index); 3188 3650 if (t->deps == NULL) 3189 3651 defaux.vda_next = 0; … … 3205 3667 } 3206 3668 else 3207 defaux.vda_name = n->version_needed->name_indx; 3669 { 3670 defaux.vda_name = n->version_needed->name_indx; 3671 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, 3672 defaux.vda_name); 3673 } 3208 3674 if (n->next == NULL) 3209 3675 defaux.vda_next = 0; … … 3217 3683 } 3218 3684 3219 if (! elf_add_dynamic_entry (info, DT_VERDEF, 0) 3220 || ! elf_add_dynamic_entry (info, DT_VERDEFNUM, cdefs)) 3221 return false; 3685 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_VERDEF, (bfd_vma) 0) 3686 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_VERDEFNUM, 3687 (bfd_vma) cdefs)) 3688 return FALSE; 3222 3689 3223 3690 elf_tdata (output_bfd)->cverdefs = cdefs; 3224 3691 } 3225 3692 3226 if ( info->new_dtags && info->flags)3227 { 3228 if (! elf_add_dynamic_entry (info, DT_FLAGS, info->flags))3229 return false;3693 if ((info->new_dtags && info->flags) || (info->flags & DF_STATIC_TLS)) 3694 { 3695 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_FLAGS, info->flags)) 3696 return FALSE; 3230 3697 } 3231 3698 … … 3236 3703 | DF_1_NODELETE 3237 3704 | DF_1_NOOPEN); 3238 if (! elf_add_dynamic_entry (info, DT_FLAGS_1, info->flags_1)) 3239 return false; 3705 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_FLAGS_1, 3706 info->flags_1)) 3707 return FALSE; 3240 3708 } 3241 3709 … … 3252 3720 if (sinfo.vers == 0) 3253 3721 sinfo.vers = 1; 3254 sinfo.failed = false;3722 sinfo.failed = FALSE; 3255 3723 3256 3724 elf_link_hash_traverse (elf_hash_table (info), … … 3283 3751 3284 3752 s->_raw_size = size; 3285 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s ize);3753 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size); 3286 3754 if (s->contents == NULL) 3287 return false;3755 return FALSE; 3288 3756 3289 3757 p = s->contents; … … 3302 3770 t->vn_version = VER_NEED_CURRENT; 3303 3771 t->vn_cnt = caux; 3304 if (elf_dt_name (t->vn_bfd) != NULL) 3305 indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr, 3306 elf_dt_name (t->vn_bfd), 3307 true, false); 3308 else 3309 indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr, 3310 t->vn_bfd->filename, true, false); 3772 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, 3773 elf_dt_name (t->vn_bfd) != NULL 3774 ? elf_dt_name (t->vn_bfd) 3775 : basename (t->vn_bfd->filename), 3776 FALSE); 3311 3777 if (indx == (bfd_size_type) -1) 3312 return false;3778 return FALSE; 3313 3779 t->vn_file = indx; 3314 3780 t->vn_aux = sizeof (Elf_External_Verneed); … … 3326 3792 { 3327 3793 a->vna_hash = bfd_elf_hash (a->vna_nodename); 3328 indx = _bfd_ stringtab_add (elf_hash_table (info)->dynstr,3329 a->vna_nodename, true, false);3794 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, 3795 a->vna_nodename, FALSE); 3330 3796 if (indx == (bfd_size_type) -1) 3331 return false;3797 return FALSE; 3332 3798 a->vna_name = indx; 3333 3799 if (a->vna_nextptr == NULL) … … 3342 3808 } 3343 3809 3344 if (! elf_add_dynamic_entry (info, DT_VERNEED, 0) 3345 || ! elf_add_dynamic_entry (info, DT_VERNEEDNUM, crefs)) 3346 return false; 3810 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_VERNEED, 3811 (bfd_vma) 0) 3812 || ! elf_add_dynamic_entry (info, (bfd_vma) DT_VERNEEDNUM, 3813 (bfd_vma) crefs)) 3814 return FALSE; 3347 3815 3348 3816 elf_tdata (output_bfd)->cverrefs = crefs; … … 3373 3841 s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->_raw_size); 3374 3842 if (s->contents == NULL) 3375 return false;3376 3377 if (! elf_add_dynamic_entry (info, DT_VERSYM,0))3378 return false;3843 return FALSE; 3844 3845 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_VERSYM, (bfd_vma) 0)) 3846 return FALSE; 3379 3847 } 3380 3848 … … 3390 3858 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size); 3391 3859 if (s->contents == NULL && s->_raw_size != 0) 3392 return false;3860 return FALSE; 3393 3861 3394 3862 if (dynsymcount != 0) … … 3403 3871 isym.st_other = 0; 3404 3872 isym.st_shndx = 0; 3405 elf_swap_symbol_out (output_bfd, &isym, 3406 (PTR) (Elf_External_Sym *) s->contents); 3873 elf_swap_symbol_out (output_bfd, &isym, (PTR) s->contents, (PTR) 0); 3407 3874 } 3408 3875 … … 3415 3882 hash_entry_size = elf_section_data (s)->this_hdr.sh_entsize; 3416 3883 s->_raw_size = ((2 + bucketcount + dynsymcount) * hash_entry_size); 3417 s->contents = (bfd_byte *) bfd_ alloc (output_bfd, s->_raw_size);3884 s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->_raw_size); 3418 3885 if (s->contents == NULL) 3419 return false;3420 memset (s->contents, 0, (size_t) s->_raw_size); 3421 3422 bfd_put (8 * hash_entry_size, output_bfd, bucketcount,s->contents);3423 bfd_put (8 * hash_entry_size, output_bfd, dynsymcount,3886 return FALSE; 3887 3888 bfd_put (8 * hash_entry_size, output_bfd, (bfd_vma) bucketcount, 3889 s->contents); 3890 bfd_put (8 * hash_entry_size, output_bfd, (bfd_vma) dynsymcount, 3424 3891 s->contents + hash_entry_size); 3425 3892 … … 3428 3895 s = bfd_get_section_by_name (dynobj, ".dynstr"); 3429 3896 BFD_ASSERT (s != NULL); 3430 s->_raw_size = _bfd_stringtab_size (elf_hash_table (info)->dynstr); 3431 3432 if (! elf_add_dynamic_entry (info, DT_NULL, 0)) 3433 return false; 3434 } 3435 3436 return true; 3897 3898 elf_finalize_dynstr (output_bfd, info); 3899 3900 s->_raw_size = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr); 3901 3902 for (dtagcount = 0; dtagcount <= info->spare_dynamic_tags; ++dtagcount) 3903 if (! elf_add_dynamic_entry (info, (bfd_vma) DT_NULL, (bfd_vma) 0)) 3904 return FALSE; 3905 } 3906 3907 return TRUE; 3437 3908 } 3438 3909 3910 3911 /* This function is used to adjust offsets into .dynstr for 3912 dynamic symbols. This is called via elf_link_hash_traverse. */ 3913 3914 static bfd_boolean elf_adjust_dynstr_offsets 3915 PARAMS ((struct elf_link_hash_entry *, PTR)); 3916 3917 static bfd_boolean 3918 elf_adjust_dynstr_offsets (h, data) 3919 struct elf_link_hash_entry *h; 3920 PTR data; 3921 { 3922 struct elf_strtab_hash *dynstr = (struct elf_strtab_hash *) data; 3923 3924 if (h->root.type == bfd_link_hash_warning) 3925 h = (struct elf_link_hash_entry *) h->root.u.i.link; 3926 3927 if (h->dynindx != -1) 3928 h->dynstr_index = _bfd_elf_strtab_offset (dynstr, h->dynstr_index); 3929 return TRUE; 3930 } 3931 3932 /* Assign string offsets in .dynstr, update all structures referencing 3933 them. */ 3934 3935 static bfd_boolean 3936 elf_finalize_dynstr (output_bfd, info) 3937 bfd *output_bfd; 3938 struct bfd_link_info *info; 3939 { 3940 struct elf_link_local_dynamic_entry *entry; 3941 struct elf_strtab_hash *dynstr = elf_hash_table (info)->dynstr; 3942 bfd *dynobj = elf_hash_table (info)->dynobj; 3943 asection *sdyn; 3944 bfd_size_type size; 3945 Elf_External_Dyn *dyncon, *dynconend; 3946 3947 _bfd_elf_strtab_finalize (dynstr); 3948 size = _bfd_elf_strtab_size (dynstr); 3949 3950 /* Update all .dynamic entries referencing .dynstr strings. */ 3951 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); 3952 BFD_ASSERT (sdyn != NULL); 3953 3954 dyncon = (Elf_External_Dyn *) sdyn->contents; 3955 dynconend = (Elf_External_Dyn *) (sdyn->contents + 3956 sdyn->_raw_size); 3957 for (; dyncon < dynconend; dyncon++) 3958 { 3959 Elf_Internal_Dyn dyn; 3960 3961 elf_swap_dyn_in (dynobj, dyncon, & dyn); 3962 switch (dyn.d_tag) 3963 { 3964 case DT_STRSZ: 3965 dyn.d_un.d_val = size; 3966 elf_swap_dyn_out (dynobj, & dyn, dyncon); 3967 break; 3968 case DT_NEEDED: 3969 case DT_SONAME: 3970 case DT_RPATH: 3971 case DT_RUNPATH: 3972 case DT_FILTER: 3973 case DT_AUXILIARY: 3974 dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val); 3975 elf_swap_dyn_out (dynobj, & dyn, dyncon); 3976 break; 3977 default: 3978 break; 3979 } 3980 } 3981 3982 /* Now update local dynamic symbols. */ 3983 for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next) 3984 entry->isym.st_name = _bfd_elf_strtab_offset (dynstr, 3985 entry->isym.st_name); 3986 3987 /* And the rest of dynamic symbols. */ 3988 elf_link_hash_traverse (elf_hash_table (info), 3989 elf_adjust_dynstr_offsets, dynstr); 3990 3991 /* Adjust version definitions. */ 3992 if (elf_tdata (output_bfd)->cverdefs) 3993 { 3994 asection *s; 3995 bfd_byte *p; 3996 bfd_size_type i; 3997 Elf_Internal_Verdef def; 3998 Elf_Internal_Verdaux defaux; 3999 4000 s = bfd_get_section_by_name (dynobj, ".gnu.version_d"); 4001 p = (bfd_byte *) s->contents; 4002 do 4003 { 4004 _bfd_elf_swap_verdef_in (output_bfd, (Elf_External_Verdef *) p, 4005 &def); 4006 p += sizeof (Elf_External_Verdef); 4007 for (i = 0; i < def.vd_cnt; ++i) 4008 { 4009 _bfd_elf_swap_verdaux_in (output_bfd, 4010 (Elf_External_Verdaux *) p, &defaux); 4011 defaux.vda_name = _bfd_elf_strtab_offset (dynstr, 4012 defaux.vda_name); 4013 _bfd_elf_swap_verdaux_out (output_bfd, 4014 &defaux, (Elf_External_Verdaux *) p); 4015 p += sizeof (Elf_External_Verdaux); 4016 } 4017 } 4018 while (def.vd_next); 4019 } 4020 4021 /* Adjust version references. */ 4022 if (elf_tdata (output_bfd)->verref) 4023 { 4024 asection *s; 4025 bfd_byte *p; 4026 bfd_size_type i; 4027 Elf_Internal_Verneed need; 4028 Elf_Internal_Vernaux needaux; 4029 4030 s = bfd_get_section_by_name (dynobj, ".gnu.version_r"); 4031 p = (bfd_byte *) s->contents; 4032 do 4033 { 4034 _bfd_elf_swap_verneed_in (output_bfd, (Elf_External_Verneed *) p, 4035 &need); 4036 need.vn_file = _bfd_elf_strtab_offset (dynstr, need.vn_file); 4037 _bfd_elf_swap_verneed_out (output_bfd, &need, 4038 (Elf_External_Verneed *) p); 4039 p += sizeof (Elf_External_Verneed); 4040 for (i = 0; i < need.vn_cnt; ++i) 4041 { 4042 _bfd_elf_swap_vernaux_in (output_bfd, 4043 (Elf_External_Vernaux *) p, &needaux); 4044 needaux.vna_name = _bfd_elf_strtab_offset (dynstr, 4045 needaux.vna_name); 4046 _bfd_elf_swap_vernaux_out (output_bfd, 4047 &needaux, 4048 (Elf_External_Vernaux *) p); 4049 p += sizeof (Elf_External_Vernaux); 4050 } 4051 } 4052 while (need.vn_next); 4053 } 4054 4055 return TRUE; 4056 } 3439 4057 3440 4058 /* Fix up the flags for a symbol. This handles various cases which … … 3444 4062 the face of future changes. */ 3445 4063 3446 static b oolean4064 static bfd_boolean 3447 4065 elf_fix_symbol_flags (h, eif) 3448 4066 struct elf_link_hash_entry *h; … … 3479 4097 if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h)) 3480 4098 { 3481 eif->failed = true;3482 return false;4099 eif->failed = TRUE; 4100 return FALSE; 3483 4101 } 3484 4102 } … … 3487 4105 { 3488 4106 /* Unfortunately, ELF_LINK_NON_ELF is only correct if the symbol 3489 3490 3491 3492 3493 4107 was first seen in a non-ELF file. Fortunately, if the symbol 4108 was first seen in an ELF file, we're probably OK unless the 4109 symbol was defined in a non-ELF file. Catch that case here. 4110 FIXME: We're still in trouble if the symbol was first seen in 4111 a dynamic object, and then later in a non-ELF regular object. */ 3494 4112 if ((h->root.type == bfd_link_hash_defined 3495 4113 || h->root.type == bfd_link_hash_defweak) … … 3526 4144 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0 3527 4145 && eif->info->shared 4146 && is_elf_hash_table (eif->info) 3528 4147 && (eif->info->symbolic 3529 4148 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL … … 3532 4151 { 3533 4152 struct elf_backend_data *bed; 4153 bfd_boolean force_local; 4154 3534 4155 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj); 3535 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL 3536 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) 3537 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;3538 (*bed->elf_backend_hide_symbol) (eif->info, h );4156 4157 force_local = (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL 4158 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN); 4159 (*bed->elf_backend_hide_symbol) (eif->info, h, force_local); 3539 4160 } 3540 4161 … … 3546 4167 struct elf_link_hash_entry *weakdef; 3547 4168 4169 weakdef = h->weakdef; 4170 if (h->root.type == bfd_link_hash_indirect) 4171 h = (struct elf_link_hash_entry *) h->root.u.i.link; 4172 3548 4173 BFD_ASSERT (h->root.type == bfd_link_hash_defined 3549 4174 || h->root.type == bfd_link_hash_defweak); 3550 weakdef = h->weakdef;3551 4175 BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined 3552 4176 || weakdef->root.type == bfd_link_hash_defweak); … … 3559 4183 h->weakdef = NULL; 3560 4184 else 3561 weakdef->elf_link_hash_flags |= 3562 (h->elf_link_hash_flags 3563 & (ELF_LINK_HASH_REF_REGULAR 3564 | ELF_LINK_HASH_REF_REGULAR_NONWEAK 3565 | ELF_LINK_NON_GOT_REF)); 3566 } 3567 3568 return true; 4185 { 4186 struct elf_backend_data *bed; 4187 4188 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj); 4189 (*bed->elf_backend_copy_indirect_symbol) (bed, weakdef, h); 4190 } 4191 } 4192 4193 return TRUE; 3569 4194 } 3570 4195 … … 3573 4198 recursively. */ 3574 4199 3575 static b oolean4200 static bfd_boolean 3576 4201 elf_adjust_dynamic_symbol (h, data) 3577 4202 struct elf_link_hash_entry *h; … … 3582 4207 struct elf_backend_data *bed; 3583 4208 4209 if (! is_elf_hash_table (eif->info)) 4210 return FALSE; 4211 4212 if (h->root.type == bfd_link_hash_warning) 4213 { 4214 h->plt = elf_hash_table (eif->info)->init_offset; 4215 h->got = elf_hash_table (eif->info)->init_offset; 4216 4217 /* When warning symbols are created, they **replace** the "real" 4218 entry in the hash table, thus we never get to see the real 4219 symbol in a hash traversal. So look at it now. */ 4220 h = (struct elf_link_hash_entry *) h->root.u.i.link; 4221 } 4222 3584 4223 /* Ignore indirect symbols. These are added by the versioning code. */ 3585 4224 if (h->root.type == bfd_link_hash_indirect) 3586 return true;4225 return TRUE; 3587 4226 3588 4227 /* Fix the symbol flags. */ 3589 4228 if (! elf_fix_symbol_flags (h, eif)) 3590 return false;4229 return FALSE; 3591 4230 3592 4231 /* If this symbol does not require a PLT entry, and it is not … … 3603 4242 && (h->weakdef == NULL || h->weakdef->dynindx == -1)))) 3604 4243 { 3605 h->plt .offset = (bfd_vma) -1;3606 return true;4244 h->plt = elf_hash_table (eif->info)->init_offset; 4245 return TRUE; 3607 4246 } 3608 4247 … … 3610 4249 can happen via a recursive call. */ 3611 4250 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) 3612 return true;4251 return TRUE; 3613 4252 3614 4253 /* Don't look at this symbol again. Note that we must set this … … 3655 4294 3656 4295 if (! elf_adjust_dynamic_symbol (h->weakdef, (PTR) eif)) 3657 return false;4296 return FALSE; 3658 4297 } 3659 4298 … … 3668 4307 (*_bfd_error_handler) 3669 4308 (_("warning: type and size of dynamic symbol `%s' are not defined"), 3670 4309 h->root.root.string); 3671 4310 3672 4311 dynobj = elf_hash_table (eif->info)->dynobj; … … 3674 4313 if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h)) 3675 4314 { 3676 eif->failed = true;3677 return false;3678 } 3679 3680 return true;4315 eif->failed = TRUE; 4316 return FALSE; 4317 } 4318 4319 return TRUE; 3681 4320 } 3682 4321 … … 3685 4324 symbol table. It is called via elf_link_hash_traverse. */ 3686 4325 3687 static b oolean4326 static bfd_boolean 3688 4327 elf_export_symbol (h, data) 3689 4328 struct elf_link_hash_entry *h; … … 3694 4333 /* Ignore indirect symbols. These are added by the versioning code. */ 3695 4334 if (h->root.type == bfd_link_hash_indirect) 3696 return true; 4335 return TRUE; 4336 4337 if (h->root.type == bfd_link_hash_warning) 4338 h = (struct elf_link_hash_entry *) h->root.u.i.link; 3697 4339 3698 4340 if (h->dynindx == -1 … … 3700 4342 & (ELF_LINK_HASH_DEF_REGULAR | ELF_LINK_HASH_REF_REGULAR)) != 0) 3701 4343 { 3702 if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h)) 3703 { 3704 eif->failed = true; 3705 return false; 3706 } 3707 } 3708 3709 return true; 4344 struct bfd_elf_version_tree *t; 4345 struct bfd_elf_version_expr *d; 4346 4347 for (t = eif->verdefs; t != NULL; t = t->next) 4348 { 4349 if (t->globals != NULL) 4350 { 4351 for (d = t->globals; d != NULL; d = d->next) 4352 { 4353 if ((*d->match) (d, h->root.root.string)) 4354 goto doit; 4355 } 4356 } 4357 4358 if (t->locals != NULL) 4359 { 4360 for (d = t->locals ; d != NULL; d = d->next) 4361 { 4362 if ((*d->match) (d, h->root.root.string)) 4363 return TRUE; 4364 } 4365 } 4366 } 4367 4368 if (!eif->verdefs) 4369 { 4370 doit: 4371 if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h)) 4372 { 4373 eif->failed = TRUE; 4374 return FALSE; 4375 } 4376 } 4377 } 4378 4379 return TRUE; 3710 4380 } 3711 4381 … … 3716 4386 This function is called via elf_link_hash_traverse. */ 3717 4387 3718 static b oolean4388 static bfd_boolean 3719 4389 elf_link_find_version_dependencies (h, data) 3720 4390 struct elf_link_hash_entry *h; … … 3724 4394 Elf_Internal_Verneed *t; 3725 4395 Elf_Internal_Vernaux *a; 4396 bfd_size_type amt; 4397 4398 if (h->root.type == bfd_link_hash_warning) 4399 h = (struct elf_link_hash_entry *) h->root.u.i.link; 3726 4400 3727 4401 /* We only care about symbols defined in shared objects with version … … 3731 4405 || h->dynindx == -1 3732 4406 || h->verinfo.verdef == NULL) 3733 return true;4407 return TRUE; 3734 4408 3735 4409 /* See if we already know about this version. */ … … 3741 4415 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr) 3742 4416 if (a->vna_nodename == h->verinfo.verdef->vd_nodename) 3743 return true;4417 return TRUE; 3744 4418 3745 4419 break; … … 3750 4424 if (t == NULL) 3751 4425 { 3752 t = (Elf_Internal_Verneed *) bfd_zalloc (rinfo->output_bfd, sizeof *t); 4426 amt = sizeof *t; 4427 t = (Elf_Internal_Verneed *) bfd_zalloc (rinfo->output_bfd, amt); 3753 4428 if (t == NULL) 3754 4429 { 3755 rinfo->failed = true;3756 return false;4430 rinfo->failed = TRUE; 4431 return FALSE; 3757 4432 } 3758 4433 … … 3762 4437 } 3763 4438 3764 a = (Elf_Internal_Vernaux *) bfd_zalloc (rinfo->output_bfd, sizeof *a); 4439 amt = sizeof *a; 4440 a = (Elf_Internal_Vernaux *) bfd_zalloc (rinfo->output_bfd, amt); 3765 4441 3766 4442 /* Note that we are copying a string pointer here, and testing it … … 3780 4456 t->vn_auxptr = a; 3781 4457 3782 return true;4458 return TRUE; 3783 4459 } 3784 4460 … … 3788 4464 local. This function is called via elf_link_hash_traverse. */ 3789 4465 3790 static b oolean4466 static bfd_boolean 3791 4467 elf_link_assign_sym_version (h, data) 3792 4468 struct elf_link_hash_entry *h; 3793 4469 PTR data; 3794 4470 { 3795 struct elf_assign_sym_version_info *sinfo = 3796 (struct elf_assign_sym_version_info *) data; 3797 struct bfd_link_info *info = sinfo->info; 4471 struct elf_assign_sym_version_info *sinfo; 4472 struct bfd_link_info *info; 3798 4473 struct elf_backend_data *bed; 3799 4474 struct elf_info_failed eif; 3800 4475 char *p; 4476 bfd_size_type amt; 4477 4478 sinfo = (struct elf_assign_sym_version_info *) data; 4479 info = sinfo->info; 4480 4481 if (h->root.type == bfd_link_hash_warning) 4482 h = (struct elf_link_hash_entry *) h->root.u.i.link; 3801 4483 3802 4484 /* Fix the symbol flags. */ 3803 eif.failed = false;4485 eif.failed = FALSE; 3804 4486 eif.info = info; 3805 4487 if (! elf_fix_symbol_flags (h, &eif)) 3806 4488 { 3807 4489 if (eif.failed) 3808 sinfo->failed = true;3809 return false;4490 sinfo->failed = TRUE; 4491 return FALSE; 3810 4492 } 3811 4493 … … 3813 4495 objects. */ 3814 4496 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 3815 return true;4497 return TRUE; 3816 4498 3817 4499 bed = get_elf_backend_data (sinfo->output_bfd); … … 3820 4502 { 3821 4503 struct bfd_elf_version_tree *t; 3822 b oolean hidden;3823 3824 hidden = true;4504 bfd_boolean hidden; 4505 4506 hidden = TRUE; 3825 4507 3826 4508 /* There are two consecutive ELF_VER_CHR characters if this is 3827 4509 not a hidden symbol. */ 3828 4510 ++p; 3829 4511 if (*p == ELF_VER_CHR) 3830 4512 { 3831 hidden = false;4513 hidden = FALSE; 3832 4514 ++p; 3833 4515 } … … 3838 4520 if (hidden) 3839 4521 h->elf_link_hash_flags |= ELF_LINK_HIDDEN; 3840 return true;4522 return TRUE; 3841 4523 } 3842 4524 … … 3846 4528 if (strcmp (t->name, p) == 0) 3847 4529 { 3848 int len;4530 size_t len; 3849 4531 char *alc; 3850 4532 struct bfd_elf_version_expr *d; 3851 4533 3852 4534 len = p - h->root.root.string; 3853 alc = bfd_ alloc (sinfo->output_bfd,len);4535 alc = bfd_malloc ((bfd_size_type) len); 3854 4536 if (alc == NULL) 3855 return false;3856 strncpy (alc, h->root.root.string, len - 1);4537 return FALSE; 4538 memcpy (alc, h->root.root.string, len - 1); 3857 4539 alc[len - 1] = '\0'; 3858 4540 if (alc[len - 2] == ELF_VER_CHR) 3859 4541 alc[len - 2] = '\0'; 3860 4542 3861 4543 h->verinfo.vertree = t; 3862 t->used = true;4544 t->used = TRUE; 3863 4545 d = NULL; 3864 4546 … … 3871 4553 3872 4554 /* See if there is anything to force this symbol to 3873 4555 local scope. */ 3874 4556 if (d == NULL && t->locals != NULL) 3875 4557 { … … 3880 4562 if (h->dynindx != -1 3881 4563 && info->shared 3882 && ! sinfo->export_dynamic)4564 && ! info->export_dynamic) 3883 4565 { 3884 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 3885 (*bed->elf_backend_hide_symbol) (info, h); 3886 /* FIXME: The name of the symbol has 3887 already been recorded in the dynamic 3888 string table section. */ 4566 (*bed->elf_backend_hide_symbol) (info, h, TRUE); 3889 4567 } 3890 4568 … … 3894 4572 } 3895 4573 3896 bfd_release (sinfo->output_bfd,alc);4574 free (alc); 3897 4575 break; 3898 4576 } … … 3900 4578 3901 4579 /* If we are building an application, we need to create a 3902 4580 version node for this version. */ 3903 4581 if (t == NULL && ! info->shared) 3904 4582 { … … 3907 4585 3908 4586 /* If we aren't going to export this symbol, we don't need 3909 4587 to worry about it. */ 3910 4588 if (h->dynindx == -1) 3911 return true; 3912 4589 return TRUE; 4590 4591 amt = sizeof *t; 3913 4592 t = ((struct bfd_elf_version_tree *) 3914 bfd_alloc (sinfo->output_bfd, sizeof *t));4593 bfd_alloc (sinfo->output_bfd, amt)); 3915 4594 if (t == NULL) 3916 4595 { 3917 sinfo->failed = true;3918 return false;4596 sinfo->failed = TRUE; 4597 return FALSE; 3919 4598 } 3920 4599 … … 3925 4604 t->deps = NULL; 3926 4605 t->name_indx = (unsigned int) -1; 3927 t->used = true;4606 t->used = TRUE; 3928 4607 3929 4608 version_index = 1; 4609 /* Don't count anonymous version tag. */ 4610 if (sinfo->verdefs != NULL && sinfo->verdefs->vernum == 0) 4611 version_index = 0; 3930 4612 for (pp = &sinfo->verdefs; *pp != NULL; pp = &(*pp)->next) 3931 4613 ++version_index; … … 3939 4621 { 3940 4622 /* We could not find the version for a symbol when 3941 4623 generating a shared archive. Return an error. */ 3942 4624 (*_bfd_error_handler) 3943 4625 (_("%s: undefined versioned symbol name %s"), 3944 4626 bfd_get_filename (sinfo->output_bfd), h->root.root.string); 3945 4627 bfd_set_error (bfd_error_bad_value); 3946 sinfo->failed = true;3947 return false;4628 sinfo->failed = TRUE; 4629 return FALSE; 3948 4630 } 3949 4631 … … 3957 4639 { 3958 4640 struct bfd_elf_version_tree *t; 3959 struct bfd_elf_version_tree * deflt;4641 struct bfd_elf_version_tree *local_ver; 3960 4642 struct bfd_elf_version_expr *d; 3961 4643 3962 4644 /* See if can find what version this symbol is in. If the 3963 3964 3965 deflt= NULL;4645 symbol is supposed to be local, then don't actually register 4646 it. */ 4647 local_ver = NULL; 3966 4648 for (t = sinfo->verdefs; t != NULL; t = t->next) 3967 4649 { 3968 4650 if (t->globals != NULL) 3969 4651 { 4652 bfd_boolean matched; 4653 4654 matched = FALSE; 3970 4655 for (d = t->globals; d != NULL; d = d->next) 3971 4656 { 3972 4657 if ((*d->match) (d, h->root.root.string)) 3973 4658 { 3974 h->verinfo.vertree = t; 3975 break; 4659 if (d->symver) 4660 matched = TRUE; 4661 else 4662 { 4663 /* There is a version without definition. Make 4664 the symbol the default definition for this 4665 version. */ 4666 h->verinfo.vertree = t; 4667 local_ver = NULL; 4668 d->script = 1; 4669 break; 4670 } 3976 4671 } 3977 4672 } … … 3979 4674 if (d != NULL) 3980 4675 break; 4676 else if (matched) 4677 /* There is no undefined version for this symbol. Hide the 4678 default one. */ 4679 (*bed->elf_backend_hide_symbol) (info, h, TRUE); 3981 4680 } 3982 4681 … … 3985 4684 for (d = t->locals; d != NULL; d = d->next) 3986 4685 { 4686 /* If the match is "*", keep looking for a more 4687 explicit, perhaps even global, match. */ 3987 4688 if (d->pattern[0] == '*' && d->pattern[1] == '\0') 3988 deflt= t;4689 local_ver = t; 3989 4690 else if ((*d->match) (d, h->root.root.string)) 3990 4691 { 3991 h->verinfo.vertree = t; 3992 if (h->dynindx != -1 3993 && info->shared 3994 && ! sinfo->export_dynamic) 3995 { 3996 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 3997 (*bed->elf_backend_hide_symbol) (info, h); 3998 /* FIXME: The name of the symbol has already 3999 been recorded in the dynamic string table 4000 section. */ 4001 } 4692 local_ver = t; 4002 4693 break; 4003 4694 } … … 4009 4700 } 4010 4701 4011 if ( deflt != NULL && h->verinfo.vertree == NULL)4012 { 4013 h->verinfo.vertree = deflt;4702 if (local_ver != NULL) 4703 { 4704 h->verinfo.vertree = local_ver; 4014 4705 if (h->dynindx != -1 4015 4706 && info->shared 4016 && ! sinfo->export_dynamic)4707 && ! info->export_dynamic) 4017 4708 { 4018 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 4019 (*bed->elf_backend_hide_symbol) (info, h); 4020 /* FIXME: The name of the symbol has already been 4021 recorded in the dynamic string table section. */ 4709 (*bed->elf_backend_hide_symbol) (info, h, TRUE); 4022 4710 } 4023 4711 } 4024 4712 } 4025 4713 4026 return true;4714 return TRUE; 4027 4715 } 4028 4716 … … 4046 4734 /* symbol version section (.gnu.version). */ 4047 4735 asection *symver_sec; 4736 /* first SHF_TLS section (if any). */ 4737 asection *first_tls_sec; 4048 4738 /* Buffer large enough to hold contents of any section. */ 4049 4739 bfd_byte *contents; … … 4055 4745 BFD. */ 4056 4746 Elf_External_Sym *external_syms; 4747 /* And a buffer for symbol section indices. */ 4748 Elf_External_Sym_Shndx *locsym_shndx; 4057 4749 /* Buffer large enough to hold internal local symbols of any input 4058 4750 BFD. */ … … 4066 4758 /* Buffer to hold swapped out symbols. */ 4067 4759 Elf_External_Sym *symbuf; 4760 /* And one for symbol section indices. */ 4761 Elf_External_Sym_Shndx *symshndxbuf; 4068 4762 /* Number of swapped out symbols in buffer. */ 4069 4763 size_t symbuf_count; 4070 4764 /* Number of symbols which fit in symbuf. */ 4071 4765 size_t symbuf_size; 4766 /* And same for symshndxbuf. */ 4767 size_t shndxbuf_size; 4072 4768 }; 4073 4769 4074 static b oolean elf_link_output_sym4770 static bfd_boolean elf_link_output_sym 4075 4771 PARAMS ((struct elf_final_link_info *, const char *, 4076 4772 Elf_Internal_Sym *, asection *)); 4077 static b oolean elf_link_flush_output_syms4773 static bfd_boolean elf_link_flush_output_syms 4078 4774 PARAMS ((struct elf_final_link_info *)); 4079 static b oolean elf_link_output_extsym4775 static bfd_boolean elf_link_output_extsym 4080 4776 PARAMS ((struct elf_link_hash_entry *, PTR)); 4081 static boolean elf_link_input_bfd 4777 static bfd_boolean elf_link_sec_merge_syms 4778 PARAMS ((struct elf_link_hash_entry *, PTR)); 4779 static bfd_boolean elf_link_check_versioned_symbol 4780 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); 4781 static bfd_boolean elf_link_input_bfd 4082 4782 PARAMS ((struct elf_final_link_info *, bfd *)); 4083 static b oolean elf_reloc_link_order4783 static bfd_boolean elf_reloc_link_order 4084 4784 PARAMS ((bfd *, struct bfd_link_info *, asection *, 4085 4785 struct bfd_link_order *)); … … 4089 4789 struct elf_outext_info 4090 4790 { 4091 b oolean failed;4092 b oolean localsyms;4791 bfd_boolean failed; 4792 bfd_boolean localsyms; 4093 4793 struct elf_final_link_info *finfo; 4094 4794 }; … … 4097 4797 section header for a section containing relocations for O. */ 4098 4798 4099 static b oolean4799 static bfd_boolean 4100 4800 elf_link_size_reloc_section (abfd, rel_hdr, o) 4101 4801 bfd *abfd; … … 4103 4803 asection *o; 4104 4804 { 4105 unsigned reloc_count; 4805 bfd_size_type reloc_count; 4806 bfd_size_type num_rel_hashes; 4106 4807 4107 4808 /* Figure out how many relocations there will be. */ … … 4110 4811 else 4111 4812 reloc_count = elf_section_data (o)->rel_count2; 4813 4814 num_rel_hashes = o->reloc_count; 4815 if (num_rel_hashes < reloc_count) 4816 num_rel_hashes = reloc_count; 4112 4817 4113 4818 /* That allows us to calculate the size of the section. */ … … 4120 4825 rel_hdr->contents = (PTR) bfd_zalloc (abfd, rel_hdr->sh_size); 4121 4826 if (rel_hdr->contents == NULL && rel_hdr->sh_size != 0) 4122 return false;4827 return FALSE; 4123 4828 4124 4829 /* We only allocate one set of hash entries, so we only do it the 4125 4830 first time we are called. */ 4126 if (elf_section_data (o)->rel_hashes == NULL) 4831 if (elf_section_data (o)->rel_hashes == NULL 4832 && num_rel_hashes) 4127 4833 { 4128 4834 struct elf_link_hash_entry **p; 4129 4835 4130 4836 p = ((struct elf_link_hash_entry **) 4131 bfd_zmalloc ( o->reloc_count4837 bfd_zmalloc (num_rel_hashes 4132 4838 * sizeof (struct elf_link_hash_entry *))); 4133 if (p == NULL && o->reloc_count != 0)4134 return false;4839 if (p == NULL) 4840 return FALSE; 4135 4841 4136 4842 elf_section_data (o)->rel_hashes = p; 4137 4843 } 4138 4844 4139 return true;4845 return TRUE; 4140 4846 } 4141 4847 … … 4154 4860 unsigned int i; 4155 4861 struct elf_backend_data *bed = get_elf_backend_data (abfd); 4156 Elf_Internal_Rel *irel; 4157 Elf_Internal_Rela *irela; 4158 4159 irel = (Elf_Internal_Rel *) bfd_zmalloc (sizeof (Elf_Internal_Rel) 4160 * bed->s->int_rels_per_ext_rel); 4161 if (irel == NULL) 4162 { 4163 (*_bfd_error_handler) (_("Error: out of memory")); 4164 abort (); 4165 } 4166 4167 irela = (Elf_Internal_Rela *) bfd_zmalloc (sizeof (Elf_Internal_Rela) 4168 * bed->s->int_rels_per_ext_rel); 4169 if (irela == NULL) 4170 { 4171 (*_bfd_error_handler) (_("Error: out of memory")); 4172 abort (); 4173 } 4174 4175 for (i = 0; i < count; i++, rel_hash++) 4176 { 4862 bfd_byte *erela; 4863 void (*swap_in) PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *)); 4864 void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *)); 4865 4866 if (rel_hdr->sh_entsize == sizeof (Elf_External_Rel)) 4867 { 4868 swap_in = bed->s->swap_reloc_in; 4869 swap_out = bed->s->swap_reloc_out; 4870 } 4871 else if (rel_hdr->sh_entsize == sizeof (Elf_External_Rela)) 4872 { 4873 swap_in = bed->s->swap_reloca_in; 4874 swap_out = bed->s->swap_reloca_out; 4875 } 4876 else 4877 abort (); 4878 4879 if (bed->s->int_rels_per_ext_rel > MAX_INT_RELS_PER_EXT_REL) 4880 abort (); 4881 4882 erela = rel_hdr->contents; 4883 for (i = 0; i < count; i++, rel_hash++, erela += rel_hdr->sh_entsize) 4884 { 4885 Elf_Internal_Rela irela[MAX_INT_RELS_PER_EXT_REL]; 4886 unsigned int j; 4887 4177 4888 if (*rel_hash == NULL) 4178 4889 continue; … … 4180 4891 BFD_ASSERT ((*rel_hash)->indx >= 0); 4181 4892 4182 if (rel_hdr->sh_entsize == sizeof (Elf_External_Rel)) 4183 { 4184 Elf_External_Rel *erel; 4185 unsigned int j; 4186 4187 erel = (Elf_External_Rel *) rel_hdr->contents + i; 4188 if (bed->s->swap_reloc_in) 4189 (*bed->s->swap_reloc_in) (abfd, (bfd_byte *) erel, irel); 4190 else 4191 elf_swap_reloc_in (abfd, erel, irel); 4192 4193 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++) 4194 irel[j].r_info = ELF_R_INFO ((*rel_hash)->indx, 4195 ELF_R_TYPE (irel[j].r_info)); 4196 4197 if (bed->s->swap_reloc_out) 4198 (*bed->s->swap_reloc_out) (abfd, irel, (bfd_byte *) erel); 4199 else 4200 elf_swap_reloc_out (abfd, irel, erel); 4201 } 4202 else 4203 { 4204 Elf_External_Rela *erela; 4205 unsigned int j; 4206 4207 BFD_ASSERT (rel_hdr->sh_entsize 4208 == sizeof (Elf_External_Rela)); 4209 4210 erela = (Elf_External_Rela *) rel_hdr->contents + i; 4211 if (bed->s->swap_reloca_in) 4212 (*bed->s->swap_reloca_in) (abfd, (bfd_byte *) erela, irela); 4213 else 4214 elf_swap_reloca_in (abfd, erela, irela); 4215 4216 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++) 4217 irela[j].r_info = ELF_R_INFO ((*rel_hash)->indx, 4218 ELF_R_TYPE (irela[j].r_info)); 4219 4220 if (bed->s->swap_reloca_out) 4221 (*bed->s->swap_reloca_out) (abfd, irela, (bfd_byte *) erela); 4222 else 4223 elf_swap_reloca_out (abfd, irela, erela); 4224 } 4225 } 4226 4227 free (irel); 4228 free (irela); 4893 (*swap_in) (abfd, erela, irela); 4894 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++) 4895 irela[j].r_info = ELF_R_INFO ((*rel_hash)->indx, 4896 ELF_R_TYPE (irela[j].r_info)); 4897 (*swap_out) (abfd, irela, erela); 4898 } 4229 4899 } 4230 4900 4901 struct elf_link_sort_rela 4902 { 4903 bfd_vma offset; 4904 enum elf_reloc_type_class type; 4905 /* We use this as an array of size int_rels_per_ext_rel. */ 4906 Elf_Internal_Rela rela[1]; 4907 }; 4908 4909 static int 4910 elf_link_sort_cmp1 (A, B) 4911 const PTR A; 4912 const PTR B; 4913 { 4914 struct elf_link_sort_rela *a = (struct elf_link_sort_rela *) A; 4915 struct elf_link_sort_rela *b = (struct elf_link_sort_rela *) B; 4916 int relativea, relativeb; 4917 4918 relativea = a->type == reloc_class_relative; 4919 relativeb = b->type == reloc_class_relative; 4920 4921 if (relativea < relativeb) 4922 return 1; 4923 if (relativea > relativeb) 4924 return -1; 4925 if (ELF_R_SYM (a->rela->r_info) < ELF_R_SYM (b->rela->r_info)) 4926 return -1; 4927 if (ELF_R_SYM (a->rela->r_info) > ELF_R_SYM (b->rela->r_info)) 4928 return 1; 4929 if (a->rela->r_offset < b->rela->r_offset) 4930 return -1; 4931 if (a->rela->r_offset > b->rela->r_offset) 4932 return 1; 4933 return 0; 4934 } 4935 4936 static int 4937 elf_link_sort_cmp2 (A, B) 4938 const PTR A; 4939 const PTR B; 4940 { 4941 struct elf_link_sort_rela *a = (struct elf_link_sort_rela *) A; 4942 struct elf_link_sort_rela *b = (struct elf_link_sort_rela *) B; 4943 int copya, copyb; 4944 4945 if (a->offset < b->offset) 4946 return -1; 4947 if (a->offset > b->offset) 4948 return 1; 4949 copya = (a->type == reloc_class_copy) * 2 + (a->type == reloc_class_plt); 4950 copyb = (b->type == reloc_class_copy) * 2 + (b->type == reloc_class_plt); 4951 if (copya < copyb) 4952 return -1; 4953 if (copya > copyb) 4954 return 1; 4955 if (a->rela->r_offset < b->rela->r_offset) 4956 return -1; 4957 if (a->rela->r_offset > b->rela->r_offset) 4958 return 1; 4959 return 0; 4960 } 4961 4962 static size_t 4963 elf_link_sort_relocs (abfd, info, psec) 4964 bfd *abfd; 4965 struct bfd_link_info *info; 4966 asection **psec; 4967 { 4968 bfd *dynobj = elf_hash_table (info)->dynobj; 4969 asection *reldyn, *o; 4970 bfd_size_type count, size; 4971 size_t i, ret, sort_elt, ext_size; 4972 bfd_byte *sort, *s_non_relative, *p; 4973 struct elf_link_sort_rela *sq; 4974 struct elf_backend_data *bed = get_elf_backend_data (abfd); 4975 int i2e = bed->s->int_rels_per_ext_rel; 4976 void (*swap_in) PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *)); 4977 void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *)); 4978 4979 reldyn = bfd_get_section_by_name (abfd, ".rela.dyn"); 4980 if (reldyn == NULL || reldyn->_raw_size == 0) 4981 { 4982 reldyn = bfd_get_section_by_name (abfd, ".rel.dyn"); 4983 if (reldyn == NULL || reldyn->_raw_size == 0) 4984 return 0; 4985 ext_size = sizeof (Elf_External_Rel); 4986 swap_in = bed->s->swap_reloc_in; 4987 swap_out = bed->s->swap_reloc_out; 4988 } 4989 else 4990 { 4991 ext_size = sizeof (Elf_External_Rela); 4992 swap_in = bed->s->swap_reloca_in; 4993 swap_out = bed->s->swap_reloca_out; 4994 } 4995 count = reldyn->_raw_size / ext_size; 4996 4997 size = 0; 4998 for (o = dynobj->sections; o != NULL; o = o->next) 4999 if ((o->flags & (SEC_HAS_CONTENTS|SEC_LINKER_CREATED)) 5000 == (SEC_HAS_CONTENTS|SEC_LINKER_CREATED) 5001 && o->output_section == reldyn) 5002 size += o->_raw_size; 5003 5004 if (size != reldyn->_raw_size) 5005 return 0; 5006 5007 sort_elt = (sizeof (struct elf_link_sort_rela) 5008 + (i2e - 1) * sizeof (Elf_Internal_Rela)); 5009 sort = bfd_zmalloc (sort_elt * count); 5010 if (sort == NULL) 5011 { 5012 (*info->callbacks->warning) 5013 (info, _("Not enough memory to sort relocations"), 0, abfd, 0, 5014 (bfd_vma) 0); 5015 return 0; 5016 } 5017 5018 for (o = dynobj->sections; o != NULL; o = o->next) 5019 if ((o->flags & (SEC_HAS_CONTENTS|SEC_LINKER_CREATED)) 5020 == (SEC_HAS_CONTENTS|SEC_LINKER_CREATED) 5021 && o->output_section == reldyn) 5022 { 5023 bfd_byte *erel, *erelend; 5024 5025 erel = o->contents; 5026 erelend = o->contents + o->_raw_size; 5027 p = sort + o->output_offset / ext_size * sort_elt; 5028 while (erel < erelend) 5029 { 5030 struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p; 5031 (*swap_in) (abfd, erel, s->rela); 5032 s->type = (*bed->elf_backend_reloc_type_class) (s->rela); 5033 p += sort_elt; 5034 erel += ext_size; 5035 } 5036 } 5037 5038 qsort (sort, (size_t) count, sort_elt, elf_link_sort_cmp1); 5039 5040 for (i = 0, p = sort; i < count; i++, p += sort_elt) 5041 { 5042 struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p; 5043 if (s->type != reloc_class_relative) 5044 break; 5045 } 5046 ret = i; 5047 s_non_relative = p; 5048 5049 sq = (struct elf_link_sort_rela *) s_non_relative; 5050 for (; i < count; i++, p += sort_elt) 5051 { 5052 struct elf_link_sort_rela *sp = (struct elf_link_sort_rela *) p; 5053 if (ELF_R_SYM (sp->rela->r_info) != ELF_R_SYM (sq->rela->r_info)) 5054 sq = sp; 5055 sp->offset = sq->rela->r_offset; 5056 } 5057 5058 qsort (s_non_relative, (size_t) count - ret, sort_elt, elf_link_sort_cmp2); 5059 5060 for (o = dynobj->sections; o != NULL; o = o->next) 5061 if ((o->flags & (SEC_HAS_CONTENTS|SEC_LINKER_CREATED)) 5062 == (SEC_HAS_CONTENTS|SEC_LINKER_CREATED) 5063 && o->output_section == reldyn) 5064 { 5065 bfd_byte *erel, *erelend; 5066 5067 erel = o->contents; 5068 erelend = o->contents + o->_raw_size; 5069 p = sort + o->output_offset / ext_size * sort_elt; 5070 while (erel < erelend) 5071 { 5072 struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p; 5073 (*swap_out) (abfd, s->rela, erel); 5074 p += sort_elt; 5075 erel += ext_size; 5076 } 5077 } 5078 5079 free (sort); 5080 *psec = reldyn; 5081 return ret; 5082 } 5083 4231 5084 /* Do the final step of an ELF link. */ 4232 5085 4233 b oolean5086 bfd_boolean 4234 5087 elf_bfd_final_link (abfd, info) 4235 5088 bfd *abfd; 4236 5089 struct bfd_link_info *info; 4237 5090 { 4238 boolean dynamic; 5091 bfd_boolean dynamic; 5092 bfd_boolean emit_relocs; 4239 5093 bfd *dynobj; 4240 5094 struct elf_final_link_info finfo; … … 4242 5096 register struct bfd_link_order *p; 4243 5097 register bfd *sub; 4244 size_t max_contents_size; 4245 size_t max_external_reloc_size; 4246 size_t max_internal_reloc_count; 4247 size_t max_sym_count; 5098 bfd_size_type max_contents_size; 5099 bfd_size_type max_external_reloc_size; 5100 bfd_size_type max_internal_reloc_count; 5101 bfd_size_type max_sym_count; 5102 bfd_size_type max_sym_shndx_count; 4248 5103 file_ptr off; 4249 5104 Elf_Internal_Sym elfsym; 4250 5105 unsigned int i; 4251 5106 Elf_Internal_Shdr *symtab_hdr; 5107 Elf_Internal_Shdr *symtab_shndx_hdr; 4252 5108 Elf_Internal_Shdr *symstrtab_hdr; 4253 5109 struct elf_backend_data *bed = get_elf_backend_data (abfd); 4254 5110 struct elf_outext_info eoinfo; 5111 bfd_boolean merged; 5112 size_t relativecount = 0; 5113 asection *reldyn = 0; 5114 bfd_size_type amt; 5115 5116 if (! is_elf_hash_table (info)) 5117 return FALSE; 4255 5118 4256 5119 if (info->shared) … … 4259 5122 dynamic = elf_hash_table (info)->dynamic_sections_created; 4260 5123 dynobj = elf_hash_table (info)->dynobj; 5124 5125 emit_relocs = (info->relocateable 5126 || info->emitrelocations 5127 || bed->elf_backend_emit_relocs); 4261 5128 4262 5129 finfo.info = info; … … 4264 5131 finfo.symstrtab = elf_stringtab_init (); 4265 5132 if (finfo.symstrtab == NULL) 4266 return false;5133 return FALSE; 4267 5134 4268 5135 if (! dynamic) … … 4285 5152 finfo.internal_relocs = NULL; 4286 5153 finfo.external_syms = NULL; 5154 finfo.locsym_shndx = NULL; 4287 5155 finfo.internal_syms = NULL; 4288 5156 finfo.indices = NULL; 4289 5157 finfo.sections = NULL; 4290 5158 finfo.symbuf = NULL; 5159 finfo.symshndxbuf = NULL; 4291 5160 finfo.symbuf_count = 0; 5161 finfo.shndxbuf_size = 0; 5162 finfo.first_tls_sec = NULL; 5163 for (o = abfd->sections; o != (asection *) NULL; o = o->next) 5164 if ((o->flags & SEC_THREAD_LOCAL) != 0 5165 && (o->flags & SEC_LOAD) != 0) 5166 { 5167 finfo.first_tls_sec = o; 5168 break; 5169 } 4292 5170 4293 5171 /* Count up the number of relocations we will output for each output … … 4298 5176 max_internal_reloc_count = 0; 4299 5177 max_sym_count = 0; 5178 max_sym_shndx_count = 0; 5179 merged = FALSE; 4300 5180 for (o = abfd->sections; o != (asection *) NULL; o = o->next) 4301 5181 { 5182 struct bfd_elf_section_data *esdo = elf_section_data (o); 4302 5183 o->reloc_count = 0; 4303 5184 4304 5185 for (p = o->link_order_head; p != NULL; p = p->next) 4305 5186 { 5187 unsigned int reloc_count = 0; 5188 struct bfd_elf_section_data *esdi = NULL; 5189 unsigned int *rel_count1; 5190 4306 5191 if (p->type == bfd_section_reloc_link_order 4307 5192 || p->type == bfd_symbol_reloc_link_order) 4308 ++o->reloc_count;5193 reloc_count = 1; 4309 5194 else if (p->type == bfd_indirect_link_order) 4310 5195 { … … 4312 5197 4313 5198 sec = p->u.indirect.section; 5199 esdi = elf_section_data (sec); 4314 5200 4315 5201 /* Mark all sections which are to be included in the … … 4317 5203 to do this so that we can identify any sections which 4318 5204 the linker has decided to not include. */ 4319 sec->linker_mark = true; 5205 sec->linker_mark = TRUE; 5206 5207 if (sec->flags & SEC_MERGE) 5208 merged = TRUE; 4320 5209 4321 5210 if (info->relocateable || info->emitrelocations) 4322 o->reloc_count += sec->reloc_count; 5211 reloc_count = sec->reloc_count; 5212 else if (bed->elf_backend_count_relocs) 5213 { 5214 Elf_Internal_Rela * relocs; 5215 5216 relocs = (NAME(_bfd_elf,link_read_relocs) 5217 (abfd, sec, (PTR) NULL, 5218 (Elf_Internal_Rela *) NULL, info->keep_memory)); 5219 5220 reloc_count = (*bed->elf_backend_count_relocs) (sec, relocs); 5221 5222 if (elf_section_data (o)->relocs != relocs) 5223 free (relocs); 5224 } 4323 5225 4324 5226 if (sec->_raw_size > max_contents_size) … … 4342 5244 if (sym_count > max_sym_count) 4343 5245 max_sym_count = sym_count; 5246 5247 if (sym_count > max_sym_shndx_count 5248 && elf_symtab_shndx (sec->owner) != 0) 5249 max_sym_shndx_count = sym_count; 4344 5250 4345 5251 if ((sec->flags & SEC_RELOC) != 0) … … 4355 5261 } 4356 5262 } 5263 5264 if (reloc_count == 0) 5265 continue; 5266 5267 o->reloc_count += reloc_count; 5268 5269 /* MIPS may have a mix of REL and RELA relocs on sections. 5270 To support this curious ABI we keep reloc counts in 5271 elf_section_data too. We must be careful to add the 5272 relocations from the input section to the right output 5273 count. FIXME: Get rid of one count. We have 5274 o->reloc_count == esdo->rel_count + esdo->rel_count2. */ 5275 rel_count1 = &esdo->rel_count; 5276 if (esdi != NULL) 5277 { 5278 bfd_boolean same_size; 5279 bfd_size_type entsize1; 5280 5281 entsize1 = esdi->rel_hdr.sh_entsize; 5282 BFD_ASSERT (entsize1 == sizeof (Elf_External_Rel) 5283 || entsize1 == sizeof (Elf_External_Rela)); 5284 same_size = (!o->use_rela_p 5285 == (entsize1 == sizeof (Elf_External_Rel))); 5286 5287 if (!same_size) 5288 rel_count1 = &esdo->rel_count2; 5289 5290 if (esdi->rel_hdr2 != NULL) 5291 { 5292 bfd_size_type entsize2 = esdi->rel_hdr2->sh_entsize; 5293 unsigned int alt_count; 5294 unsigned int *rel_count2; 5295 5296 BFD_ASSERT (entsize2 != entsize1 5297 && (entsize2 == sizeof (Elf_External_Rel) 5298 || entsize2 == sizeof (Elf_External_Rela))); 5299 5300 rel_count2 = &esdo->rel_count2; 5301 if (!same_size) 5302 rel_count2 = &esdo->rel_count; 5303 5304 /* The following is probably too simplistic if the 5305 backend counts output relocs unusually. */ 5306 BFD_ASSERT (bed->elf_backend_count_relocs == NULL); 5307 alt_count = NUM_SHDR_ENTRIES (esdi->rel_hdr2); 5308 *rel_count2 += alt_count; 5309 reloc_count -= alt_count; 5310 } 5311 } 5312 *rel_count1 += reloc_count; 4357 5313 } 4358 5314 … … 4376 5332 } 4377 5333 5334 if (! info->relocateable && merged) 5335 elf_link_hash_traverse (elf_hash_table (info), 5336 elf_link_sec_merge_syms, (PTR) abfd); 5337 4378 5338 /* Figure out the file positions for everything but the symbol table 4379 5339 and the relocs. We set symcount to force assign_section_numbers … … 4383 5343 if (! _bfd_elf_compute_section_file_positions (abfd, info)) 4384 5344 goto error_return; 4385 4386 /* Figure out how many relocations we will have in each section.4387 Just using RELOC_COUNT isn't good enough since that doesn't4388 maintain a separate value for REL vs. RELA relocations. */4389 if (info->relocateable || info->emitrelocations)4390 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)4391 for (o = sub->sections; o != NULL; o = o->next)4392 {4393 asection *output_section;4394 4395 if (! o->linker_mark)4396 {4397 /* This section was omitted from the link. */4398 continue;4399 }4400 4401 output_section = o->output_section;4402 4403 if (output_section != NULL4404 && (o->flags & SEC_RELOC) != 0)4405 {4406 struct bfd_elf_section_data *esdi4407 = elf_section_data (o);4408 struct bfd_elf_section_data *esdo4409 = elf_section_data (output_section);4410 unsigned int *rel_count;4411 unsigned int *rel_count2;4412 4413 /* We must be careful to add the relocation froms the4414 input section to the right output count. */4415 if (esdi->rel_hdr.sh_entsize == esdo->rel_hdr.sh_entsize)4416 {4417 rel_count = &esdo->rel_count;4418 rel_count2 = &esdo->rel_count2;4419 }4420 else4421 {4422 rel_count = &esdo->rel_count2;4423 rel_count2 = &esdo->rel_count;4424 }4425 4426 *rel_count += NUM_SHDR_ENTRIES (& esdi->rel_hdr);4427 if (esdi->rel_hdr2)4428 *rel_count2 += NUM_SHDR_ENTRIES (esdi->rel_hdr2);4429 }4430 }4431 5345 4432 5346 /* That created the reloc sections. Set their sizes, and assign … … 4464 5378 /* sh_name is set in prep_headers. */ 4465 5379 symtab_hdr->sh_type = SHT_SYMTAB; 4466 symtab_hdr->sh_flags = 0; 4467 symtab_hdr->sh_addr = 0; 4468 symtab_hdr->sh_size = 0; 5380 /* sh_flags, sh_addr and sh_size all start off zero. */ 4469 5381 symtab_hdr->sh_entsize = sizeof (Elf_External_Sym); 4470 5382 /* sh_link is set in assign_section_numbers. */ … … 4474 5386 4475 5387 off = elf_tdata (abfd)->next_file_pos; 4476 off = _bfd_elf_assign_file_position_for_section (symtab_hdr, off, true);5388 off = _bfd_elf_assign_file_position_for_section (symtab_hdr, off, TRUE); 4477 5389 4478 5390 /* Note that at this point elf_tdata (abfd)->next_file_pos is … … 4486 5398 else 4487 5399 finfo.symbuf_size = max_sym_count; 4488 finfo.symbuf = ((Elf_External_Sym *) 4489 bfd_malloc (finfo.symbuf_size * sizeof (Elf_External_Sym))); 5400 amt = finfo.symbuf_size; 5401 amt *= sizeof (Elf_External_Sym); 5402 finfo.symbuf = (Elf_External_Sym *) bfd_malloc (amt); 4490 5403 if (finfo.symbuf == NULL) 4491 5404 goto error_return; 5405 if (elf_numsections (abfd) > SHN_LORESERVE) 5406 { 5407 /* Wild guess at number of output symbols. realloc'd as needed. */ 5408 amt = 2 * max_sym_count + elf_numsections (abfd) + 1000; 5409 finfo.shndxbuf_size = amt; 5410 amt *= sizeof (Elf_External_Sym_Shndx); 5411 finfo.symshndxbuf = (Elf_External_Sym_Shndx *) bfd_zmalloc (amt); 5412 if (finfo.symshndxbuf == NULL) 5413 goto error_return; 5414 } 4492 5415 4493 5416 /* Start writing out the symbol table. The first symbol is always a 4494 5417 dummy symbol. */ 4495 if (info->strip != strip_all || info->relocateable || info->emitrelocations) 5418 if (info->strip != strip_all 5419 || emit_relocs) 4496 5420 { 4497 5421 elfsym.st_value = 0; … … 4526 5450 index field of the section, so that we can find it again when 4527 5451 outputting relocs. */ 4528 if (info->strip != strip_all || info->relocateable || info->emitrelocations) 5452 if (info->strip != strip_all 5453 || emit_relocs) 4529 5454 { 4530 5455 elfsym.st_size = 0; 4531 5456 elfsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); 4532 5457 elfsym.st_other = 0; 4533 for (i = 1; i < elf_ elfheader (abfd)->e_shnum; i++)5458 for (i = 1; i < elf_numsections (abfd); i++) 4534 5459 { 4535 5460 o = section_from_elf_index (abfd, i); … … 4544 5469 &elfsym, o)) 4545 5470 goto error_return; 5471 if (i == SHN_LORESERVE - 1) 5472 i += SHN_HIRESERVE + 1 - SHN_LORESERVE; 4546 5473 } 4547 5474 } … … 4549 5476 /* Allocate some memory to hold information read in from the input 4550 5477 files. */ 4551 finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); 4552 finfo.external_relocs = (PTR) bfd_malloc (max_external_reloc_size); 4553 finfo.internal_relocs = ((Elf_Internal_Rela *) 4554 bfd_malloc (max_internal_reloc_count 4555 * sizeof (Elf_Internal_Rela) 4556 * bed->s->int_rels_per_ext_rel)); 4557 finfo.external_syms = ((Elf_External_Sym *) 4558 bfd_malloc (max_sym_count 4559 * sizeof (Elf_External_Sym))); 4560 finfo.internal_syms = ((Elf_Internal_Sym *) 4561 bfd_malloc (max_sym_count 4562 * sizeof (Elf_Internal_Sym))); 4563 finfo.indices = (long *) bfd_malloc (max_sym_count * sizeof (long)); 4564 finfo.sections = ((asection **) 4565 bfd_malloc (max_sym_count * sizeof (asection *))); 4566 if ((finfo.contents == NULL && max_contents_size != 0) 4567 || (finfo.external_relocs == NULL && max_external_reloc_size != 0) 4568 || (finfo.internal_relocs == NULL && max_internal_reloc_count != 0) 4569 || (finfo.external_syms == NULL && max_sym_count != 0) 4570 || (finfo.internal_syms == NULL && max_sym_count != 0) 4571 || (finfo.indices == NULL && max_sym_count != 0) 4572 || (finfo.sections == NULL && max_sym_count != 0)) 4573 goto error_return; 5478 if (max_contents_size != 0) 5479 { 5480 finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); 5481 if (finfo.contents == NULL) 5482 goto error_return; 5483 } 5484 5485 if (max_external_reloc_size != 0) 5486 { 5487 finfo.external_relocs = (PTR) bfd_malloc (max_external_reloc_size); 5488 if (finfo.external_relocs == NULL) 5489 goto error_return; 5490 } 5491 5492 if (max_internal_reloc_count != 0) 5493 { 5494 amt = max_internal_reloc_count * bed->s->int_rels_per_ext_rel; 5495 amt *= sizeof (Elf_Internal_Rela); 5496 finfo.internal_relocs = (Elf_Internal_Rela *) bfd_malloc (amt); 5497 if (finfo.internal_relocs == NULL) 5498 goto error_return; 5499 } 5500 5501 if (max_sym_count != 0) 5502 { 5503 amt = max_sym_count * sizeof (Elf_External_Sym); 5504 finfo.external_syms = (Elf_External_Sym *) bfd_malloc (amt); 5505 if (finfo.external_syms == NULL) 5506 goto error_return; 5507 5508 amt = max_sym_count * sizeof (Elf_Internal_Sym); 5509 finfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt); 5510 if (finfo.internal_syms == NULL) 5511 goto error_return; 5512 5513 amt = max_sym_count * sizeof (long); 5514 finfo.indices = (long *) bfd_malloc (amt); 5515 if (finfo.indices == NULL) 5516 goto error_return; 5517 5518 amt = max_sym_count * sizeof (asection *); 5519 finfo.sections = (asection **) bfd_malloc (amt); 5520 if (finfo.sections == NULL) 5521 goto error_return; 5522 } 5523 5524 if (max_sym_shndx_count != 0) 5525 { 5526 amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx); 5527 finfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt); 5528 if (finfo.locsym_shndx == NULL) 5529 goto error_return; 5530 } 5531 5532 if (finfo.first_tls_sec) 5533 { 5534 unsigned int align = 0; 5535 bfd_vma base = finfo.first_tls_sec->vma, end = 0; 5536 asection *sec; 5537 5538 for (sec = finfo.first_tls_sec; 5539 sec && (sec->flags & SEC_THREAD_LOCAL); 5540 sec = sec->next) 5541 { 5542 bfd_vma size = sec->_raw_size; 5543 5544 if (bfd_get_section_alignment (abfd, sec) > align) 5545 align = bfd_get_section_alignment (abfd, sec); 5546 if (sec->_raw_size == 0 && (sec->flags & SEC_HAS_CONTENTS) == 0) 5547 { 5548 struct bfd_link_order *o; 5549 5550 size = 0; 5551 for (o = sec->link_order_head; o != NULL; o = o->next) 5552 if (size < o->offset + o->size) 5553 size = o->offset + o->size; 5554 } 5555 end = sec->vma + size; 5556 } 5557 elf_hash_table (info)->tls_segment 5558 = bfd_zalloc (abfd, sizeof (struct elf_link_tls_segment)); 5559 if (elf_hash_table (info)->tls_segment == NULL) 5560 goto error_return; 5561 elf_hash_table (info)->tls_segment->start = base; 5562 elf_hash_table (info)->tls_segment->size = end - base; 5563 elf_hash_table (info)->tls_segment->align = align; 5564 } 4574 5565 4575 5566 /* Since ELF permits relocations to be against local symbols, we … … 4594 5585 4595 5586 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) 4596 sub->output_has_begun = false;5587 sub->output_has_begun = FALSE; 4597 5588 for (o = abfd->sections; o != NULL; o = o->next) 4598 5589 { … … 4600 5591 { 4601 5592 if (p->type == bfd_indirect_link_order 4602 && (bfd_get_flavour (p->u.indirect.section->owner) 4603 == bfd_target_elf_flavour)) 5593 && (bfd_get_flavour ((sub = p->u.indirect.section->owner)) 5594 == bfd_target_elf_flavour) 5595 && elf_elfheader (sub)->e_ident[EI_CLASS] == bed->s->elfclass) 4604 5596 { 4605 sub = p->u.indirect.section->owner;4606 5597 if (! sub->output_has_begun) 4607 5598 { 4608 5599 if (! elf_link_input_bfd (&finfo, sub)) 4609 5600 goto error_return; 4610 sub->output_has_begun = true;5601 sub->output_has_begun = TRUE; 4611 5602 } 4612 5603 } … … 4625 5616 } 4626 5617 5618 /* Output any global symbols that got converted to local in a 5619 version script or due to symbol visibility. We do this in a 5620 separate step since ELF requires all local symbols to appear 5621 prior to any global symbols. FIXME: We should only do this if 5622 some global symbols were, in fact, converted to become local. 5623 FIXME: Will this work correctly with the Irix 5 linker? */ 5624 eoinfo.failed = FALSE; 5625 eoinfo.finfo = &finfo; 5626 eoinfo.localsyms = TRUE; 5627 elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym, 5628 (PTR) &eoinfo); 5629 if (eoinfo.failed) 5630 return FALSE; 5631 4627 5632 /* That wrote out all the local symbols. Finish up the symbol table 4628 5633 with the global symbols. Even if we want to strip everything we … … 4630 5635 converted to local in a version script. */ 4631 5636 4632 if (info->shared)4633 {4634 /* Output any global symbols that got converted to local in a4635 version script. We do this in a separate step since ELF4636 requires all local symbols to appear prior to any global4637 symbols. FIXME: We should only do this if some global4638 symbols were, in fact, converted to become local. FIXME:4639 Will this work correctly with the Irix 5 linker? */4640 eoinfo.failed = false;4641 eoinfo.finfo = &finfo;4642 eoinfo.localsyms = true;4643 elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym,4644 (PTR) &eoinfo);4645 if (eoinfo.failed)4646 return false;4647 }4648 4649 5637 /* The sh_info field records the index of the first non local symbol. */ 4650 5638 symtab_hdr->sh_info = bfd_get_symcount (abfd); … … 4655 5643 Elf_Internal_Sym sym; 4656 5644 Elf_External_Sym *dynsym = 4657 (Elf_External_Sym *) finfo.dynsym_sec->contents;5645 (Elf_External_Sym *) finfo.dynsym_sec->contents; 4658 5646 long last_local = 0; 4659 5647 … … 4671 5659 { 4672 5660 int indx; 5661 Elf_External_Sym *dest; 5662 4673 5663 indx = elf_section_data (s)->this_idx; 4674 5664 BFD_ASSERT (indx > 0); 4675 5665 sym.st_shndx = indx; 4676 5666 sym.st_value = s->vma; 4677 4678 elf_swap_symbol_out (abfd, &sym, 4679 dynsym + elf_section_data (s)->dynindx); 5667 dest = dynsym + elf_section_data (s)->dynindx; 5668 elf_swap_symbol_out (abfd, &sym, (PTR) dest, (PTR) 0); 4680 5669 } 4681 5670 … … 4690 5679 { 4691 5680 asection *s; 5681 Elf_External_Sym *dest; 4692 5682 4693 5683 sym.st_size = e->isym.st_size; … … 4696 5686 /* Copy the internal symbol as is. 4697 5687 Note that we saved a word of storage and overwrote 4698 the original st_name with the dynstr_index. */ 4699 sym = e->isym; 4700 4701 if (e->isym.st_shndx > 0 && e->isym.st_shndx < SHN_LORESERVE) 5688 the original st_name with the dynstr_index. */ 5689 sym = e->isym; 5690 5691 if (e->isym.st_shndx != SHN_UNDEF 5692 && (e->isym.st_shndx < SHN_LORESERVE 5693 || e->isym.st_shndx > SHN_HIRESERVE)) 4702 5694 { 4703 5695 s = bfd_section_from_elf_index (e->input_bfd, … … 4714 5706 last_local = e->dynindx; 4715 5707 4716 elf_swap_symbol_out (abfd, &sym, dynsym + e->dynindx); 5708 dest = dynsym + e->dynindx; 5709 elf_swap_symbol_out (abfd, &sym, (PTR) dest, (PTR) 0); 4717 5710 } 4718 5711 } … … 4723 5716 4724 5717 /* We get the global symbols from the hash table. */ 4725 eoinfo.failed = false;4726 eoinfo.localsyms = false;5718 eoinfo.failed = FALSE; 5719 eoinfo.localsyms = FALSE; 4727 5720 eoinfo.finfo = &finfo; 4728 5721 elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym, 4729 5722 (PTR) &eoinfo); 4730 5723 if (eoinfo.failed) 4731 return false;5724 return FALSE; 4732 5725 4733 5726 /* If backend needs to output some symbols not present in the hash … … 4735 5728 if (bed->elf_backend_output_arch_syms) 4736 5729 { 4737 if (! (*bed->elf_backend_output_arch_syms)4738 (abfd, info, (PTR) &finfo,4739 (boolean (*) PARAMS ((PTR, const char *, 4740 Elf_Internal_Sym *, asection *)))4741 elf_link_output_sym))4742 return false;5730 typedef bfd_boolean (*out_sym_func) 5731 PARAMS ((PTR, const char *, Elf_Internal_Sym *, asection *)); 5732 5733 if (! ((*bed->elf_backend_output_arch_syms) 5734 (abfd, info, (PTR) &finfo, (out_sym_func) elf_link_output_sym))) 5735 return FALSE; 4743 5736 } 4744 5737 4745 5738 /* Flush all symbols to the file. */ 4746 5739 if (! elf_link_flush_output_syms (&finfo)) 4747 return false;5740 return FALSE; 4748 5741 4749 5742 /* Now we know the size of the symtab section. */ 4750 5743 off += symtab_hdr->sh_size; 5744 5745 symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr; 5746 if (symtab_shndx_hdr->sh_name != 0) 5747 { 5748 symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX; 5749 symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx); 5750 symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx); 5751 amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx); 5752 symtab_shndx_hdr->sh_size = amt; 5753 5754 off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr, 5755 off, TRUE); 5756 5757 if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0 5758 || (bfd_bwrite ((PTR) finfo.symshndxbuf, amt, abfd) != amt)) 5759 return FALSE; 5760 } 5761 4751 5762 4752 5763 /* Finish up and write out the symbol string table (.strtab) … … 4764 5775 symstrtab_hdr->sh_addralign = 1; 4765 5776 4766 off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, off, true);5777 off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, off, TRUE); 4767 5778 elf_tdata (abfd)->next_file_pos = off; 4768 5779 … … 4771 5782 if (bfd_seek (abfd, symstrtab_hdr->sh_offset, SEEK_SET) != 0 4772 5783 || ! _bfd_stringtab_emit (abfd, finfo.symstrtab)) 4773 return false;5784 return FALSE; 4774 5785 } 4775 5786 … … 4794 5805 } 4795 5806 5807 if (dynamic && info->combreloc && dynobj != NULL) 5808 relativecount = elf_link_sort_relocs (abfd, info, &reldyn); 5809 4796 5810 /* If we are linking against a dynamic object, or generating a 4797 5811 shared library, finish up the dynamic linking information. */ … … 4817 5831 { 4818 5832 default: 5833 break; 5834 case DT_NULL: 5835 if (relativecount > 0 && dyncon + 1 < dynconend) 5836 { 5837 switch (elf_section_data (reldyn)->this_hdr.sh_type) 5838 { 5839 case SHT_REL: dyn.d_tag = DT_RELCOUNT; break; 5840 case SHT_RELA: dyn.d_tag = DT_RELACOUNT; break; 5841 default: break; 5842 } 5843 if (dyn.d_tag != DT_NULL) 5844 { 5845 dyn.d_un.d_val = relativecount; 5846 elf_swap_dyn_out (dynobj, &dyn, dyncon); 5847 relativecount = 0; 5848 } 5849 } 4819 5850 break; 4820 5851 case DT_INIT: … … 4828 5859 4829 5860 h = elf_link_hash_lookup (elf_hash_table (info), name, 4830 false, false, true);5861 FALSE, FALSE, TRUE); 4831 5862 if (h != NULL 4832 5863 && (h->root.type == bfd_link_hash_defined … … 4849 5880 } 4850 5881 break; 5882 5883 case DT_PREINIT_ARRAYSZ: 5884 name = ".preinit_array"; 5885 goto get_size; 5886 case DT_INIT_ARRAYSZ: 5887 name = ".init_array"; 5888 goto get_size; 5889 case DT_FINI_ARRAYSZ: 5890 name = ".fini_array"; 5891 get_size: 5892 o = bfd_get_section_by_name (abfd, name); 5893 if (o == NULL) 5894 { 5895 (*_bfd_error_handler) 5896 (_("%s: could not find output section %s"), 5897 bfd_get_filename (abfd), name); 5898 goto error_return; 5899 } 5900 if (o->_raw_size == 0) 5901 (*_bfd_error_handler) 5902 (_("warning: %s section has zero size"), name); 5903 dyn.d_un.d_val = o->_raw_size; 5904 elf_swap_dyn_out (dynobj, &dyn, dyncon); 5905 break; 5906 5907 case DT_PREINIT_ARRAY: 5908 name = ".preinit_array"; 5909 goto get_vma; 5910 case DT_INIT_ARRAY: 5911 name = ".init_array"; 5912 goto get_vma; 5913 case DT_FINI_ARRAY: 5914 name = ".fini_array"; 5915 goto get_vma; 4851 5916 4852 5917 case DT_HASH: … … 4869 5934 get_vma: 4870 5935 o = bfd_get_section_by_name (abfd, name); 4871 BFD_ASSERT (o != NULL); 5936 if (o == NULL) 5937 { 5938 (*_bfd_error_handler) 5939 (_("%s: could not find output section %s"), 5940 bfd_get_filename (abfd), name); 5941 goto error_return; 5942 } 4872 5943 dyn.d_un.d_ptr = o->vma; 4873 5944 elf_swap_dyn_out (dynobj, &dyn, dyncon); … … 4883 5954 type = SHT_RELA; 4884 5955 dyn.d_un.d_val = 0; 4885 for (i = 1; i < elf_ elfheader (abfd)->e_shnum; i++)5956 for (i = 1; i < elf_numsections (abfd); i++) 4886 5957 { 4887 5958 Elf_Internal_Shdr *hdr; … … 4922 5993 { 4923 5994 /* At this point, we are only interested in sections 4924 5995 created by elf_link_create_dynamic_sections. */ 4925 5996 continue; 4926 5997 } … … 4930 6001 { 4931 6002 if (! bfd_set_section_contents (abfd, o->output_section, 4932 o->contents, o->output_offset, 6003 o->contents, 6004 (file_ptr) o->output_offset, 4933 6005 o->_raw_size)) 4934 6006 goto error_return; … … 4936 6008 else 4937 6009 { 4938 file_ptr off;4939 4940 6010 /* The contents of the .dynstr section are actually in a 4941 6011 stringtab. */ 4942 6012 off = elf_section_data (o->output_section)->this_hdr.sh_offset; 4943 6013 if (bfd_seek (abfd, off, SEEK_SET) != 0 4944 || ! _bfd_ stringtab_emit (abfd,4945 elf_hash_table (info)->dynstr))6014 || ! _bfd_elf_strtab_emit (abfd, 6015 elf_hash_table (info)->dynstr)) 4946 6016 goto error_return; 4947 6017 } … … 4949 6019 } 4950 6020 6021 if (info->relocateable) 6022 { 6023 bfd_boolean failed = FALSE; 6024 6025 bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed); 6026 if (failed) 6027 goto error_return; 6028 } 6029 4951 6030 /* If we have optimized stabs strings, output them. */ 4952 6031 if (elf_hash_table (info)->stab_info != NULL) 4953 6032 { 4954 6033 if (! _bfd_write_stab_strings (abfd, &elf_hash_table (info)->stab_info)) 6034 goto error_return; 6035 } 6036 6037 if (info->eh_frame_hdr) 6038 { 6039 if (! _bfd_elf_write_section_eh_frame_hdr (abfd, info)) 4955 6040 goto error_return; 4956 6041 } … … 4966 6051 if (finfo.external_syms != NULL) 4967 6052 free (finfo.external_syms); 6053 if (finfo.locsym_shndx != NULL) 6054 free (finfo.locsym_shndx); 4968 6055 if (finfo.internal_syms != NULL) 4969 6056 free (finfo.internal_syms); … … 4974 6061 if (finfo.symbuf != NULL) 4975 6062 free (finfo.symbuf); 6063 if (finfo.symshndxbuf != NULL) 6064 free (finfo.symshndxbuf); 4976 6065 for (o = abfd->sections; o != NULL; o = o->next) 4977 6066 { … … 4981 6070 } 4982 6071 4983 elf_tdata (abfd)->linker = true;4984 4985 return true;6072 elf_tdata (abfd)->linker = TRUE; 6073 6074 return TRUE; 4986 6075 4987 6076 error_return: … … 4996 6085 if (finfo.external_syms != NULL) 4997 6086 free (finfo.external_syms); 6087 if (finfo.locsym_shndx != NULL) 6088 free (finfo.locsym_shndx); 4998 6089 if (finfo.internal_syms != NULL) 4999 6090 free (finfo.internal_syms); … … 5004 6095 if (finfo.symbuf != NULL) 5005 6096 free (finfo.symbuf); 6097 if (finfo.symshndxbuf != NULL) 6098 free (finfo.symshndxbuf); 5006 6099 for (o = abfd->sections; o != NULL; o = o->next) 5007 6100 { … … 5011 6104 } 5012 6105 5013 return false;6106 return FALSE; 5014 6107 } 5015 6108 5016 6109 /* Add a symbol to the output symbol table. */ 5017 6110 5018 static b oolean6111 static bfd_boolean 5019 6112 elf_link_output_sym (finfo, name, elfsym, input_sec) 5020 6113 struct elf_final_link_info *finfo; … … 5023 6116 asection *input_sec; 5024 6117 { 5025 boolean (*output_symbol_hook) PARAMS ((bfd *,5026 struct bfd_link_info *info, 5027 const char *, 5028 Elf_Internal_Sym*,5029 6118 Elf_External_Sym *dest; 6119 Elf_External_Sym_Shndx *destshndx; 6120 bfd_boolean (*output_symbol_hook) 6121 PARAMS ((bfd *, struct bfd_link_info *info, const char *, 6122 Elf_Internal_Sym *, asection *)); 5030 6123 5031 6124 output_symbol_hook = get_elf_backend_data (finfo->output_bfd)-> … … 5035 6128 if (! ((*output_symbol_hook) 5036 6129 (finfo->output_bfd, finfo->info, name, elfsym, input_sec))) 5037 return false;6130 return FALSE; 5038 6131 } 5039 6132 … … 5045 6138 { 5046 6139 elfsym->st_name = (unsigned long) _bfd_stringtab_add (finfo->symstrtab, 5047 name, true, 5048 false); 6140 name, TRUE, FALSE); 5049 6141 if (elfsym->st_name == (unsigned long) -1) 5050 return false;6142 return FALSE; 5051 6143 } 5052 6144 … … 5054 6146 { 5055 6147 if (! elf_link_flush_output_syms (finfo)) 5056 return false; 5057 } 5058 5059 elf_swap_symbol_out (finfo->output_bfd, elfsym, 5060 (PTR) (finfo->symbuf + finfo->symbuf_count)); 5061 ++finfo->symbuf_count; 5062 5063 ++ bfd_get_symcount (finfo->output_bfd); 5064 5065 return true; 6148 return FALSE; 6149 } 6150 6151 dest = finfo->symbuf + finfo->symbuf_count; 6152 destshndx = finfo->symshndxbuf; 6153 if (destshndx != NULL) 6154 { 6155 if (bfd_get_symcount (finfo->output_bfd) >= finfo->shndxbuf_size) 6156 { 6157 bfd_size_type amt; 6158 6159 amt = finfo->shndxbuf_size * sizeof (Elf_External_Sym_Shndx); 6160 finfo->symshndxbuf = destshndx = bfd_realloc (destshndx, amt * 2); 6161 if (destshndx == NULL) 6162 return FALSE; 6163 memset ((char *) destshndx + amt, 0, amt); 6164 finfo->shndxbuf_size *= 2; 6165 } 6166 destshndx += bfd_get_symcount (finfo->output_bfd); 6167 } 6168 6169 elf_swap_symbol_out (finfo->output_bfd, elfsym, (PTR) dest, (PTR) destshndx); 6170 finfo->symbuf_count += 1; 6171 bfd_get_symcount (finfo->output_bfd) += 1; 6172 6173 return TRUE; 5066 6174 } 5067 6175 5068 6176 /* Flush the output symbols to the file. */ 5069 6177 5070 static b oolean6178 static bfd_boolean 5071 6179 elf_link_flush_output_syms (finfo) 5072 6180 struct elf_final_link_info *finfo; … … 5074 6182 if (finfo->symbuf_count > 0) 5075 6183 { 5076 Elf_Internal_Shdr *symtab; 5077 5078 symtab = &elf_tdata (finfo->output_bfd)->symtab_hdr; 5079 5080 if (bfd_seek (finfo->output_bfd, symtab->sh_offset + symtab->sh_size, 5081 SEEK_SET) != 0 5082 || (bfd_write ((PTR) finfo->symbuf, finfo->symbuf_count, 5083 sizeof (Elf_External_Sym), finfo->output_bfd) 5084 != finfo->symbuf_count * sizeof (Elf_External_Sym))) 5085 return false; 5086 5087 symtab->sh_size += finfo->symbuf_count * sizeof (Elf_External_Sym); 5088 6184 Elf_Internal_Shdr *hdr; 6185 file_ptr pos; 6186 bfd_size_type amt; 6187 6188 hdr = &elf_tdata (finfo->output_bfd)->symtab_hdr; 6189 pos = hdr->sh_offset + hdr->sh_size; 6190 amt = finfo->symbuf_count * sizeof (Elf_External_Sym); 6191 if (bfd_seek (finfo->output_bfd, pos, SEEK_SET) != 0 6192 || bfd_bwrite ((PTR) finfo->symbuf, amt, finfo->output_bfd) != amt) 6193 return FALSE; 6194 6195 hdr->sh_size += amt; 5089 6196 finfo->symbuf_count = 0; 5090 6197 } 5091 6198 5092 return true; 6199 return TRUE; 6200 } 6201 6202 /* Adjust all external symbols pointing into SEC_MERGE sections 6203 to reflect the object merging within the sections. */ 6204 6205 static bfd_boolean 6206 elf_link_sec_merge_syms (h, data) 6207 struct elf_link_hash_entry *h; 6208 PTR data; 6209 { 6210 asection *sec; 6211 6212 if (h->root.type == bfd_link_hash_warning) 6213 h = (struct elf_link_hash_entry *) h->root.u.i.link; 6214 6215 if ((h->root.type == bfd_link_hash_defined 6216 || h->root.type == bfd_link_hash_defweak) 6217 && ((sec = h->root.u.def.section)->flags & SEC_MERGE) 6218 && sec->sec_info_type == ELF_INFO_TYPE_MERGE) 6219 { 6220 bfd *output_bfd = (bfd *) data; 6221 6222 h->root.u.def.value = 6223 _bfd_merged_section_offset (output_bfd, 6224 &h->root.u.def.section, 6225 elf_section_data (sec)->sec_info, 6226 h->root.u.def.value, (bfd_vma) 0); 6227 } 6228 6229 return TRUE; 6230 } 6231 6232 /* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in 6233 allowing an unsatisfied unversioned symbol in the DSO to match a 6234 versioned symbol that would normally require an explicit version. 6235 We also handle the case that a DSO references a hidden symbol 6236 which may be satisfied by a versioned symbol in another DSO. */ 6237 6238 static bfd_boolean 6239 elf_link_check_versioned_symbol (info, h) 6240 struct bfd_link_info *info; 6241 struct elf_link_hash_entry *h; 6242 { 6243 bfd *abfd; 6244 struct elf_link_loaded_list *loaded; 6245 6246 if (info->hash->creator->flavour != bfd_target_elf_flavour) 6247 return FALSE; 6248 6249 switch (h->root.type) 6250 { 6251 default: 6252 abfd = NULL; 6253 break; 6254 6255 case bfd_link_hash_undefined: 6256 case bfd_link_hash_undefweak: 6257 abfd = h->root.u.undef.abfd; 6258 if ((abfd->flags & DYNAMIC) == 0 || elf_dt_soname (abfd) == NULL) 6259 return FALSE; 6260 break; 6261 6262 case bfd_link_hash_defined: 6263 case bfd_link_hash_defweak: 6264 abfd = h->root.u.def.section->owner; 6265 break; 6266 6267 case bfd_link_hash_common: 6268 abfd = h->root.u.c.p->section->owner; 6269 break; 6270 } 6271 BFD_ASSERT (abfd != NULL); 6272 6273 for (loaded = elf_hash_table (info)->loaded; 6274 loaded != NULL; 6275 loaded = loaded->next) 6276 { 6277 bfd *input; 6278 Elf_Internal_Shdr *hdr; 6279 bfd_size_type symcount; 6280 bfd_size_type extsymcount; 6281 bfd_size_type extsymoff; 6282 Elf_Internal_Shdr *versymhdr; 6283 Elf_Internal_Sym *isym; 6284 Elf_Internal_Sym *isymend; 6285 Elf_Internal_Sym *isymbuf; 6286 Elf_External_Versym *ever; 6287 Elf_External_Versym *extversym; 6288 6289 input = loaded->abfd; 6290 6291 /* We check each DSO for a possible hidden versioned definition. */ 6292 if (input == abfd 6293 || (input->flags & DYNAMIC) == 0 6294 || elf_dynversym (input) == 0) 6295 continue; 6296 6297 hdr = &elf_tdata (input)->dynsymtab_hdr; 6298 6299 symcount = hdr->sh_size / sizeof (Elf_External_Sym); 6300 if (elf_bad_symtab (input)) 6301 { 6302 extsymcount = symcount; 6303 extsymoff = 0; 6304 } 6305 else 6306 { 6307 extsymcount = symcount - hdr->sh_info; 6308 extsymoff = hdr->sh_info; 6309 } 6310 6311 if (extsymcount == 0) 6312 continue; 6313 6314 isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff, 6315 NULL, NULL, NULL); 6316 if (isymbuf == NULL) 6317 return FALSE; 6318 6319 /* Read in any version definitions. */ 6320 versymhdr = &elf_tdata (input)->dynversym_hdr; 6321 extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size); 6322 if (extversym == NULL) 6323 goto error_ret; 6324 6325 if (bfd_seek (input, versymhdr->sh_offset, SEEK_SET) != 0 6326 || (bfd_bread ((PTR) extversym, versymhdr->sh_size, input) 6327 != versymhdr->sh_size)) 6328 { 6329 free (extversym); 6330 error_ret: 6331 free (isymbuf); 6332 return FALSE; 6333 } 6334 6335 ever = extversym + extsymoff; 6336 isymend = isymbuf + extsymcount; 6337 for (isym = isymbuf; isym < isymend; isym++, ever++) 6338 { 6339 const char *name; 6340 Elf_Internal_Versym iver; 6341 6342 if (ELF_ST_BIND (isym->st_info) == STB_LOCAL 6343 || isym->st_shndx == SHN_UNDEF) 6344 continue; 6345 6346 name = bfd_elf_string_from_elf_section (input, 6347 hdr->sh_link, 6348 isym->st_name); 6349 if (strcmp (name, h->root.root.string) != 0) 6350 continue; 6351 6352 _bfd_elf_swap_versym_in (input, ever, &iver); 6353 6354 if ((iver.vs_vers & VERSYM_HIDDEN) == 0) 6355 { 6356 /* If we have a non-hidden versioned sym, then it should 6357 have provided a definition for the undefined sym. */ 6358 abort (); 6359 } 6360 6361 if ((iver.vs_vers & VERSYM_VERSION) == 2) 6362 { 6363 /* This is the oldest (default) sym. We can use it. */ 6364 free (extversym); 6365 free (isymbuf); 6366 return TRUE; 6367 } 6368 } 6369 6370 free (extversym); 6371 free (isymbuf); 6372 } 6373 6374 return FALSE; 5093 6375 } 5094 6376 … … 5100 6382 global symbols. */ 5101 6383 5102 static b oolean6384 static bfd_boolean 5103 6385 elf_link_output_extsym (h, data) 5104 6386 struct elf_link_hash_entry *h; … … 5107 6389 struct elf_outext_info *eoinfo = (struct elf_outext_info *) data; 5108 6390 struct elf_final_link_info *finfo = eoinfo->finfo; 5109 b oolean strip;6391 bfd_boolean strip; 5110 6392 Elf_Internal_Sym sym; 5111 6393 asection *input_sec; 5112 6394 6395 if (h->root.type == bfd_link_hash_warning) 6396 { 6397 h = (struct elf_link_hash_entry *) h->root.u.i.link; 6398 if (h->root.type == bfd_link_hash_new) 6399 return TRUE; 6400 } 6401 5113 6402 /* Decide whether to output this symbol in this pass. */ 5114 6403 if (eoinfo->localsyms) 5115 6404 { 5116 6405 if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 5117 return true;6406 return TRUE; 5118 6407 } 5119 6408 else 5120 6409 { 5121 6410 if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 5122 return true;6411 return TRUE; 5123 6412 } 5124 6413 … … 5131 6420 warnings for them. */ 5132 6421 if (! finfo->info->relocateable 5133 && ! finfo->info->allow_shlib_undefined 5134 && ! (finfo->info->shared 5135 && !finfo->info->no_undefined) 6422 && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined) 5136 6423 && h->root.type == bfd_link_hash_undefined 5137 6424 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 5138 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0) 6425 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0 6426 && ! elf_link_check_versioned_symbol (finfo->info, h)) 5139 6427 { 5140 6428 if (! ((*finfo->info->callbacks->undefined_symbol) 5141 6429 (finfo->info, h->root.root.string, h->root.u.undef.abfd, 5142 (asection *) NULL, 0, true))) 5143 { 5144 eoinfo->failed = true; 5145 return false; 5146 } 6430 (asection *) NULL, (bfd_vma) 0, TRUE))) 6431 { 6432 eoinfo->failed = TRUE; 6433 return FALSE; 6434 } 6435 } 6436 6437 /* We should also warn if a forced local symbol is referenced from 6438 shared libraries. */ 6439 if (! finfo->info->relocateable 6440 && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined) 6441 && (h->elf_link_hash_flags 6442 & (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC 6443 | ELF_LINK_DYNAMIC_DEF | ELF_LINK_DYNAMIC_WEAK)) 6444 == (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC) 6445 && ! elf_link_check_versioned_symbol (finfo->info, h)) 6446 { 6447 (*_bfd_error_handler) 6448 (_("%s: %s symbol `%s' in %s is referenced by DSO"), 6449 bfd_get_filename (finfo->output_bfd), 6450 ELF_ST_VISIBILITY (h->other) == STV_INTERNAL 6451 ? "internal" 6452 : ELF_ST_VISIBILITY (h->other) == STV_HIDDEN 6453 ? "hidden" : "local", 6454 h->root.root.string, 6455 bfd_archive_filename (h->root.u.def.section->owner)); 6456 eoinfo->failed = TRUE; 6457 return FALSE; 5147 6458 } 5148 6459 … … 5152 6463 output it. */ 5153 6464 if (h->indx == -2) 5154 strip = false;6465 strip = FALSE; 5155 6466 else if (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 5156 6467 || (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0) 5157 6468 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 5158 6469 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0) 5159 strip = true; 5160 else if (finfo->info->strip == strip_all 5161 || (finfo->info->strip == strip_some 5162 && bfd_hash_lookup (finfo->info->keep_hash, 5163 h->root.root.string, 5164 false, false) == NULL)) 5165 strip = true; 6470 strip = TRUE; 6471 else if (finfo->info->strip == strip_all) 6472 strip = TRUE; 6473 else if (finfo->info->strip == strip_some 6474 && bfd_hash_lookup (finfo->info->keep_hash, 6475 h->root.root.string, FALSE, FALSE) == NULL) 6476 strip = TRUE; 6477 else if (finfo->info->strip_discarded 6478 && (h->root.type == bfd_link_hash_defined 6479 || h->root.type == bfd_link_hash_defweak) 6480 && elf_discarded_section (h->root.u.def.section)) 6481 strip = TRUE; 5166 6482 else 5167 strip = false;6483 strip = FALSE; 5168 6484 5169 6485 /* If we're stripping it, and it's not a dynamic symbol, there's … … 5172 6488 && h->dynindx == -1 5173 6489 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 5174 return true;6490 return TRUE; 5175 6491 5176 6492 sym.st_value = 0; … … 5189 6505 default: 5190 6506 case bfd_link_hash_new: 6507 case bfd_link_hash_warning: 5191 6508 abort (); 5192 return false;6509 return FALSE; 5193 6510 5194 6511 case bfd_link_hash_undefined: 5195 input_sec = bfd_und_section_ptr;5196 sym.st_shndx = SHN_UNDEF;5197 break;5198 5199 6512 case bfd_link_hash_undefweak: 5200 6513 input_sec = bfd_und_section_ptr; … … 5211 6524 _bfd_elf_section_from_bfd_section (finfo->output_bfd, 5212 6525 input_sec->output_section); 5213 if (sym.st_shndx == (unsigned short) -1)6526 if (sym.st_shndx == SHN_BAD) 5214 6527 { 5215 6528 (*_bfd_error_handler) … … 5218 6531 input_sec->output_section->name, 5219 6532 input_sec->name); 5220 eoinfo->failed = true;5221 return false;6533 eoinfo->failed = TRUE; 6534 return FALSE; 5222 6535 } 5223 6536 … … 5227 6540 sym.st_value = h->root.u.def.value + input_sec->output_offset; 5228 6541 if (! finfo->info->relocateable) 5229 sym.st_value += input_sec->output_section->vma; 6542 { 6543 sym.st_value += input_sec->output_section->vma; 6544 if (h->type == STT_TLS) 6545 { 6546 /* STT_TLS symbols are relative to PT_TLS segment 6547 base. */ 6548 BFD_ASSERT (finfo->first_tls_sec != NULL); 6549 sym.st_value -= finfo->first_tls_sec->vma; 6550 } 6551 } 5230 6552 } 5231 6553 else … … 5247 6569 case bfd_link_hash_indirect: 5248 6570 /* These symbols are created by symbol versioning. They point 5249 to the decorated version of the name. For example, if the 5250 symbol foo@@GNU_1.2 is the default, which should be used when 5251 foo is used with no version, then we add an indirect symbol 5252 foo which points to foo@@GNU_1.2. We ignore these symbols, 5253 since the indirected symbol is already in the hash table. */ 5254 return true; 5255 5256 case bfd_link_hash_warning: 5257 /* We can't represent these symbols in ELF, although a warning 5258 symbol may have come from a .gnu.warning.SYMBOL section. We 5259 just put the target symbol in the hash table. If the target 5260 symbol does not really exist, don't do anything. */ 5261 if (h->root.u.i.link->type == bfd_link_hash_new) 5262 return true; 5263 return (elf_link_output_extsym 5264 ((struct elf_link_hash_entry *) h->root.u.i.link, data)); 6571 to the decorated version of the name. For example, if the 6572 symbol foo@@GNU_1.2 is the default, which should be used when 6573 foo is used with no version, then we add an indirect symbol 6574 foo which points to foo@@GNU_1.2. We ignore these symbols, 6575 since the indirected symbol is already in the hash table. */ 6576 return TRUE; 5265 6577 } 5266 6578 5267 6579 /* Give the processor backend a chance to tweak the symbol value, 5268 6580 and also to finish up anything that needs to be done for this 5269 symbol. */ 6581 symbol. FIXME: Not calling elf_backend_finish_dynamic_symbol for 6582 forced local syms when non-shared is due to a historical quirk. */ 5270 6583 if ((h->dynindx != -1 5271 6584 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 6585 && (finfo->info->shared 6586 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 5272 6587 && elf_hash_table (finfo->info)->dynamic_sections_created) 5273 6588 { … … 5278 6593 (finfo->output_bfd, finfo->info, h, &sym))) 5279 6594 { 5280 eoinfo->failed = true;5281 return false;6595 eoinfo->failed = TRUE; 6596 return FALSE; 5282 6597 } 5283 6598 } … … 5291 6606 if (sym.st_shndx == SHN_UNDEF 5292 6607 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) != 0 5293 && (ELF_ST_BIND (sym.st_info) == STB_GLOBAL5294 || ELF_ST_BIND (sym.st_info) == STB_WEAK))6608 && (ELF_ST_BIND (sym.st_info) == STB_GLOBAL 6609 || ELF_ST_BIND (sym.st_info) == STB_WEAK)) 5295 6610 { 5296 6611 int bindtype; … … 5303 6618 } 5304 6619 5305 /* If a symbol is not defined locally, we clear the visibility 5306 field. */ 5307 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 5308 sym.st_other ^= ELF_ST_VISIBILITY(sym.st_other); 6620 /* If a non-weak symbol with non-default visibility is not defined 6621 locally, it is a fatal error. */ 6622 if (! finfo->info->relocateable 6623 && ELF_ST_VISIBILITY (sym.st_other) 6624 && ELF_ST_BIND (sym.st_info) != STB_WEAK 6625 && h->root.type == bfd_link_hash_undefined 6626 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 6627 { 6628 (*_bfd_error_handler) 6629 (_("%s: %s symbol `%s' isn't defined"), 6630 bfd_get_filename (finfo->output_bfd), 6631 ELF_ST_VISIBILITY (sym.st_other) == STV_PROTECTED 6632 ? "protected" 6633 : ELF_ST_VISIBILITY (sym.st_other) == STV_INTERNAL 6634 ? "internal" : "hidden", 6635 h->root.root.string); 6636 eoinfo->failed = TRUE; 6637 return FALSE; 6638 } 5309 6639 5310 6640 /* If this symbol should be put in the .dynsym section, then put it 5311 there now. We have already know the symbol index. We also fill5312 inthe entry in the .hash section. */6641 there now. We already know the symbol index. We also fill in 6642 the entry in the .hash section. */ 5313 6643 if (h->dynindx != -1 5314 6644 && elf_hash_table (finfo->info)->dynamic_sections_created) … … 5319 6649 bfd_byte *bucketpos; 5320 6650 bfd_vma chain; 6651 Elf_External_Sym *esym; 5321 6652 5322 6653 sym.st_name = h->dynstr_index; 5323 5324 elf_swap_symbol_out (finfo->output_bfd, &sym, 5325 (PTR) (((Elf_External_Sym *) 5326 finfo->dynsym_sec->contents) 5327 + h->dynindx)); 6654 esym = (Elf_External_Sym *) finfo->dynsym_sec->contents + h->dynindx; 6655 elf_swap_symbol_out (finfo->output_bfd, &sym, (PTR) esym, (PTR) 0); 5328 6656 5329 6657 bucketcount = elf_hash_table (finfo->info)->bucketcount; … … 5334 6662 + (bucket + 2) * hash_entry_size); 5335 6663 chain = bfd_get (8 * hash_entry_size, finfo->output_bfd, bucketpos); 5336 bfd_put (8 * hash_entry_size, finfo->output_bfd, h->dynindx, bucketpos); 6664 bfd_put (8 * hash_entry_size, finfo->output_bfd, (bfd_vma) h->dynindx, 6665 bucketpos); 5337 6666 bfd_put (8 * hash_entry_size, finfo->output_bfd, chain, 5338 6667 ((bfd_byte *) finfo->hash_sec->contents … … 5342 6671 { 5343 6672 Elf_Internal_Versym iversym; 6673 Elf_External_Versym *eversym; 5344 6674 5345 6675 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) … … 5361 6691 iversym.vs_vers |= VERSYM_HIDDEN; 5362 6692 5363 _bfd_elf_swap_versym_out (finfo->output_bfd, &iversym, 5364 (((Elf_External_Versym *) 5365 finfo->symver_sec->contents) 5366 + h->dynindx)); 6693 eversym = (Elf_External_Versym *) finfo->symver_sec->contents; 6694 eversym += h->dynindx; 6695 _bfd_elf_swap_versym_out (finfo->output_bfd, &iversym, eversym); 5367 6696 } 5368 6697 } … … 5370 6699 /* If we're stripping it, then it was just a dynamic symbol, and 5371 6700 there's nothing else to do. */ 5372 if (strip )5373 return true;6701 if (strip || (input_sec->flags & SEC_EXCLUDE) != 0) 6702 return TRUE; 5374 6703 5375 6704 h->indx = bfd_get_symcount (finfo->output_bfd); … … 5377 6706 if (! elf_link_output_sym (finfo, h->root.root.string, &sym, input_sec)) 5378 6707 { 5379 eoinfo->failed = true;5380 return false;5381 } 5382 5383 return true;6708 eoinfo->failed = TRUE; 6709 return FALSE; 6710 } 6711 6712 return TRUE; 5384 6713 } 5385 6714 … … 5388 6717 OUTPUT_BFD. */ 5389 6718 5390 static void6719 static bfd_boolean 5391 6720 elf_link_output_relocs (output_bfd, input_section, input_rel_hdr, 5392 6721 internal_relocs) … … 5398 6727 Elf_Internal_Rela *irela; 5399 6728 Elf_Internal_Rela *irelaend; 6729 bfd_byte *erel; 5400 6730 Elf_Internal_Shdr *output_rel_hdr; 5401 6731 asection *output_section; 5402 6732 unsigned int *rel_countp = NULL; 5403 6733 struct elf_backend_data *bed; 6734 void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *)); 5404 6735 5405 6736 output_section = input_section->output_section; … … 5419 6750 rel_countp = &elf_section_data (output_section)->rel_count2; 5420 6751 } 5421 5422 BFD_ASSERT (output_rel_hdr != NULL); 6752 else 6753 { 6754 (*_bfd_error_handler) 6755 (_("%s: relocation size mismatch in %s section %s"), 6756 bfd_get_filename (output_bfd), 6757 bfd_archive_filename (input_section->owner), 6758 input_section->name); 6759 bfd_set_error (bfd_error_wrong_object_format); 6760 return FALSE; 6761 } 5423 6762 5424 6763 bed = get_elf_backend_data (output_bfd); 6764 if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rel)) 6765 swap_out = bed->s->swap_reloc_out; 6766 else if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rela)) 6767 swap_out = bed->s->swap_reloca_out; 6768 else 6769 abort (); 6770 6771 erel = output_rel_hdr->contents; 6772 erel += *rel_countp * input_rel_hdr->sh_entsize; 5425 6773 irela = internal_relocs; 5426 irelaend = irela + NUM_SHDR_ENTRIES (input_rel_hdr) 5427 * bed->s->int_rels_per_ext_rel; 5428 5429 if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rel)) 5430 { 5431 Elf_External_Rel *erel; 5432 Elf_Internal_Rel *irel; 5433 5434 irel = (Elf_Internal_Rel *) bfd_zmalloc (bed->s->int_rels_per_ext_rel 5435 * sizeof (Elf_Internal_Rel)); 5436 if (irel == NULL) 5437 { 5438 (*_bfd_error_handler) (_("Error: out of memory")); 5439 abort (); 5440 } 5441 5442 erel = ((Elf_External_Rel *) output_rel_hdr->contents + *rel_countp); 5443 for (; irela < irelaend; irela += bed->s->int_rels_per_ext_rel, erel++) 5444 { 5445 unsigned int i; 5446 5447 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++) 5448 { 5449 irel[i].r_offset = irela[i].r_offset; 5450 irel[i].r_info = irela[i].r_info; 5451 BFD_ASSERT (irela[i].r_addend == 0); 5452 } 5453 5454 if (bed->s->swap_reloc_out) 5455 (*bed->s->swap_reloc_out) (output_bfd, irel, (PTR) erel); 5456 else 5457 elf_swap_reloc_out (output_bfd, irel, erel); 5458 } 5459 5460 free (irel); 5461 } 5462 else 5463 { 5464 Elf_External_Rela *erela; 5465 5466 BFD_ASSERT (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rela)); 5467 5468 erela = ((Elf_External_Rela *) output_rel_hdr->contents + *rel_countp); 5469 for (; irela < irelaend; irela += bed->s->int_rels_per_ext_rel, erela++) 5470 if (bed->s->swap_reloca_out) 5471 (*bed->s->swap_reloca_out) (output_bfd, irela, (PTR) erela); 5472 else 5473 elf_swap_reloca_out (output_bfd, irela, erela); 6774 irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr) 6775 * bed->s->int_rels_per_ext_rel); 6776 while (irela < irelaend) 6777 { 6778 (*swap_out) (output_bfd, irela, erel); 6779 irela += bed->s->int_rels_per_ext_rel; 6780 erel += input_rel_hdr->sh_entsize; 5474 6781 } 5475 6782 … … 5477 6784 relocations. */ 5478 6785 *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr); 6786 6787 return TRUE; 5479 6788 } 5480 6789 … … 5484 6793 don't have to keep them in memory. */ 5485 6794 5486 static b oolean6795 static bfd_boolean 5487 6796 elf_link_input_bfd (finfo, input_bfd) 5488 6797 struct elf_final_link_info *finfo; 5489 6798 bfd *input_bfd; 5490 6799 { 5491 boolean (*relocate_section) PARAMS ((bfd *, struct bfd_link_info *, 5492 bfd *, asection *, bfd_byte *, 5493 Elf_Internal_Rela *, 5494 Elf_Internal_Sym *, asection **)); 6800 bfd_boolean (*relocate_section) 6801 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 6802 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 5495 6803 bfd *output_bfd; 5496 6804 Elf_Internal_Shdr *symtab_hdr; 5497 6805 size_t locsymcount; 5498 6806 size_t extsymoff; 5499 Elf_External_Sym *external_syms; 5500 Elf_External_Sym *esym; 5501 Elf_External_Sym *esymend; 6807 Elf_Internal_Sym *isymbuf; 5502 6808 Elf_Internal_Sym *isym; 6809 Elf_Internal_Sym *isymend; 5503 6810 long *pindex; 5504 6811 asection **ppsection; 5505 6812 asection *o; 5506 6813 struct elf_backend_data *bed; 6814 bfd_boolean emit_relocs; 6815 struct elf_link_hash_entry **sym_hashes; 5507 6816 5508 6817 output_bfd = finfo->output_bfd; … … 5514 6823 contents. */ 5515 6824 if ((input_bfd->flags & DYNAMIC) != 0) 5516 return true; 6825 return TRUE; 6826 6827 emit_relocs = (finfo->info->relocateable 6828 || finfo->info->emitrelocations 6829 || bed->elf_backend_emit_relocs); 5517 6830 5518 6831 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; … … 5529 6842 5530 6843 /* Read the local symbols. */ 5531 if (symtab_hdr->contents != NULL) 5532 external_syms = (Elf_External_Sym *) symtab_hdr->contents; 5533 else if (locsymcount == 0) 5534 external_syms = NULL; 5535 else 5536 { 5537 external_syms = finfo->external_syms; 5538 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 5539 || (bfd_read (external_syms, sizeof (Elf_External_Sym), 5540 locsymcount, input_bfd) 5541 != locsymcount * sizeof (Elf_External_Sym))) 5542 return false; 5543 } 5544 5545 /* Swap in the local symbols and write out the ones which we know 5546 are going into the output file. */ 5547 esym = external_syms; 5548 esymend = esym + locsymcount; 5549 isym = finfo->internal_syms; 5550 pindex = finfo->indices; 5551 ppsection = finfo->sections; 5552 for (; esym < esymend; esym++, isym++, pindex++, ppsection++) 6844 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 6845 if (isymbuf == NULL && locsymcount != 0) 6846 { 6847 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0, 6848 finfo->internal_syms, 6849 finfo->external_syms, 6850 finfo->locsym_shndx); 6851 if (isymbuf == NULL) 6852 return FALSE; 6853 } 6854 6855 /* Find local symbol sections and adjust values of symbols in 6856 SEC_MERGE sections. Write out those local symbols we know are 6857 going into the output file. */ 6858 isymend = isymbuf + locsymcount; 6859 for (isym = isymbuf, pindex = finfo->indices, ppsection = finfo->sections; 6860 isym < isymend; 6861 isym++, pindex++, ppsection++) 5553 6862 { 5554 6863 asection *isec; … … 5556 6865 Elf_Internal_Sym osym; 5557 6866 5558 elf_swap_symbol_in (input_bfd, esym, isym);5559 6867 *pindex = -1; 5560 6868 … … 5568 6876 } 5569 6877 5570 name = NULL;5571 6878 if (isym->st_shndx == SHN_UNDEF) 5572 { 5573 isec = bfd_und_section_ptr; 5574 name = isec->name; 5575 } 5576 else if (isym->st_shndx > 0 && isym->st_shndx < SHN_LORESERVE) 5577 isec = section_from_elf_index (input_bfd, isym->st_shndx); 6879 isec = bfd_und_section_ptr; 6880 else if (isym->st_shndx < SHN_LORESERVE 6881 || isym->st_shndx > SHN_HIRESERVE) 6882 { 6883 isec = section_from_elf_index (input_bfd, isym->st_shndx); 6884 if (isec 6885 && isec->sec_info_type == ELF_INFO_TYPE_MERGE 6886 && ELF_ST_TYPE (isym->st_info) != STT_SECTION) 6887 isym->st_value = 6888 _bfd_merged_section_offset (output_bfd, &isec, 6889 elf_section_data (isec)->sec_info, 6890 isym->st_value, (bfd_vma) 0); 6891 } 5578 6892 else if (isym->st_shndx == SHN_ABS) 5579 { 5580 isec = bfd_abs_section_ptr; 5581 name = isec->name; 5582 } 6893 isec = bfd_abs_section_ptr; 5583 6894 else if (isym->st_shndx == SHN_COMMON) 5584 { 5585 isec = bfd_com_section_ptr; 5586 name = isec->name; 5587 } 6895 isec = bfd_com_section_ptr; 5588 6896 else 5589 6897 { … … 5595 6903 5596 6904 /* Don't output the first, undefined, symbol. */ 5597 if ( esym == external_syms)6905 if (ppsection == finfo->sections) 5598 6906 continue; 5599 6907 5600 6908 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION) 5601 6909 { 5602 asection *ksec;5603 5604 /* Save away all section symbol values. */5605 if (isec != NULL)5606 {5607 if (name)5608 {5609 if (isec->symbol->value != isym->st_value)5610 (*_bfd_error_handler)5611 (_("%s: invalid section symbol index 0x%x (%s) ingored"),5612 bfd_get_filename (input_bfd), isym->st_shndx,5613 name);5614 continue;5615 }5616 isec->symbol->value = isym->st_value;5617 }5618 5619 /* If this is a discarded link-once section symbol, update5620 it's value to that of the kept section symbol. The5621 linker will keep the first of any matching link-once5622 sections, so we should have already seen it's section5623 symbol. I trust no-one will have the bright idea of5624 re-ordering the bfd list... */5625 if (isec != NULL5626 && (bfd_get_section_flags (input_bfd, isec) & SEC_LINK_ONCE) != 05627 && (ksec = isec->kept_section) != NULL)5628 {5629 isym->st_value = ksec->symbol->value;5630 5631 /* That put the value right, but the section info is all5632 wrong. I hope this works. */5633 isec->output_offset = ksec->output_offset;5634 isec->output_section = ksec->output_section;5635 }5636 5637 6910 /* We never output section symbols. Instead, we use the 5638 6911 section symbol of the corresponding section in the output … … 5655 6928 5656 6929 /* If this symbol is defined in a section which we are 5657 discarding, we don't need to keep it, but note that 5658 linker_mark is only reliable for sections that have contents. 5659 For the benefit of the MIPS ELF linker, we check SEC_EXCLUDE 5660 as well as linker_mark. */ 5661 if (isym->st_shndx > 0 5662 && isym->st_shndx < SHN_LORESERVE 6930 discarding, we don't need to keep it, but note that 6931 linker_mark is only reliable for sections that have contents. 6932 For the benefit of the MIPS ELF linker, we check SEC_EXCLUDE 6933 as well as linker_mark. */ 6934 if ((isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE) 5663 6935 && isec != NULL 5664 6936 && ((! isec->linker_mark && (isec->flags & SEC_HAS_CONTENTS) != 0) … … 5671 6943 isym->st_name); 5672 6944 if (name == NULL) 5673 return false;6945 return FALSE; 5674 6946 5675 6947 /* See if we are discarding symbols with this name. */ 5676 6948 if ((finfo->info->strip == strip_some 5677 && (bfd_hash_lookup (finfo->info->keep_hash, name, false, false)6949 && (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE) 5678 6950 == NULL)) 5679 || (finfo->info->discard == discard_l 6951 || (((finfo->info->discard == discard_sec_merge 6952 && (isec->flags & SEC_MERGE) && ! finfo->info->relocateable) 6953 || finfo->info->discard == discard_l) 5680 6954 && bfd_is_local_label_name (input_bfd, name))) 5681 6955 continue; … … 5688 6962 osym.st_shndx = _bfd_elf_section_from_bfd_section (output_bfd, 5689 6963 isec->output_section); 5690 if (osym.st_shndx == (unsigned short) -1)5691 return false;6964 if (osym.st_shndx == SHN_BAD) 6965 return FALSE; 5692 6966 5693 6967 *pindex = bfd_get_symcount (output_bfd); … … 5702 6976 osym.st_value += isec->output_offset; 5703 6977 if (! finfo->info->relocateable) 5704 osym.st_value += isec->output_section->vma; 6978 { 6979 osym.st_value += isec->output_section->vma; 6980 if (ELF_ST_TYPE (osym.st_info) == STT_TLS) 6981 { 6982 /* STT_TLS symbols are relative to PT_TLS segment base. */ 6983 BFD_ASSERT (finfo->first_tls_sec != NULL); 6984 osym.st_value -= finfo->first_tls_sec->vma; 6985 } 6986 } 5705 6987 5706 6988 if (! elf_link_output_sym (finfo, name, &osym, isec)) 5707 return false;6989 return FALSE; 5708 6990 } 5709 6991 5710 6992 /* Relocate the contents of each section. */ 6993 sym_hashes = elf_sym_hashes (input_bfd); 5711 6994 for (o = input_bfd->sections; o != NULL; o = o->next) 5712 6995 { … … 5731 7014 5732 7015 /* Get the contents of the section. They have been cached by a 5733 5734 5735 7016 relaxation routine. Note that o is a section in an input 7017 file, so the contents field will not have been set by any of 7018 the routines which work on output files. */ 5736 7019 if (elf_section_data (o)->this_hdr.contents != NULL) 5737 7020 contents = elf_section_data (o)->this_hdr.contents; … … 5741 7024 if (! bfd_get_section_contents (input_bfd, o, contents, 5742 7025 (file_ptr) 0, o->_raw_size)) 5743 return false;7026 return FALSE; 5744 7027 } 5745 7028 … … 5751 7034 internal_relocs = (NAME(_bfd_elf,link_read_relocs) 5752 7035 (input_bfd, o, finfo->external_relocs, 5753 finfo->internal_relocs, false));7036 finfo->internal_relocs, FALSE)); 5754 7037 if (internal_relocs == NULL 5755 7038 && o->reloc_count > 0) 5756 return false; 7039 return FALSE; 7040 7041 /* Run through the relocs looking for any against symbols 7042 from discarded sections and section symbols from 7043 removed link-once sections. Complain about relocs 7044 against discarded sections. Zero relocs against removed 7045 link-once sections. */ 7046 if (!finfo->info->relocateable 7047 && !elf_section_ignore_discarded_relocs (o)) 7048 { 7049 Elf_Internal_Rela *rel, *relend; 7050 7051 rel = internal_relocs; 7052 relend = rel + o->reloc_count * bed->s->int_rels_per_ext_rel; 7053 for ( ; rel < relend; rel++) 7054 { 7055 unsigned long r_symndx = ELF_R_SYM (rel->r_info); 7056 7057 if (r_symndx >= locsymcount 7058 || (elf_bad_symtab (input_bfd) 7059 && finfo->sections[r_symndx] == NULL)) 7060 { 7061 struct elf_link_hash_entry *h; 7062 7063 h = sym_hashes[r_symndx - extsymoff]; 7064 while (h->root.type == bfd_link_hash_indirect 7065 || h->root.type == bfd_link_hash_warning) 7066 h = (struct elf_link_hash_entry *) h->root.u.i.link; 7067 7068 /* Complain if the definition comes from a 7069 discarded section. */ 7070 if ((h->root.type == bfd_link_hash_defined 7071 || h->root.type == bfd_link_hash_defweak) 7072 && elf_discarded_section (h->root.u.def.section)) 7073 { 7074 if ((o->flags & SEC_DEBUGGING) != 0) 7075 { 7076 BFD_ASSERT (r_symndx != 0); 7077 memset (rel, 0, sizeof (*rel)); 7078 } 7079 else 7080 { 7081 if (! ((*finfo->info->callbacks->undefined_symbol) 7082 (finfo->info, h->root.root.string, 7083 input_bfd, o, rel->r_offset, 7084 TRUE))) 7085 return FALSE; 7086 } 7087 } 7088 } 7089 else 7090 { 7091 asection *sec = finfo->sections[r_symndx]; 7092 7093 if (sec != NULL && elf_discarded_section (sec)) 7094 { 7095 if ((o->flags & SEC_DEBUGGING) != 0 7096 || (sec->flags & SEC_LINK_ONCE) != 0) 7097 { 7098 BFD_ASSERT (r_symndx != 0); 7099 rel->r_info 7100 = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info)); 7101 rel->r_addend = 0; 7102 } 7103 else 7104 { 7105 bfd_boolean ok; 7106 const char *msg 7107 = _("local symbols in discarded section %s"); 7108 bfd_size_type amt 7109 = strlen (sec->name) + strlen (msg) - 1; 7110 char *buf = (char *) bfd_malloc (amt); 7111 7112 if (buf != NULL) 7113 sprintf (buf, msg, sec->name); 7114 else 7115 buf = (char *) sec->name; 7116 ok = (*finfo->info->callbacks 7117 ->undefined_symbol) (finfo->info, buf, 7118 input_bfd, o, 7119 rel->r_offset, 7120 TRUE); 7121 if (buf != sec->name) 7122 free (buf); 7123 if (!ok) 7124 return FALSE; 7125 } 7126 } 7127 } 7128 } 7129 } 5757 7130 5758 7131 /* Relocate the section by invoking a back end routine. … … 5779 7152 input_bfd, o, contents, 5780 7153 internal_relocs, 5781 finfo->internal_syms,7154 isymbuf, 5782 7155 finfo->sections)) 5783 return false;5784 5785 if ( finfo->info->relocateable || finfo->info->emitrelocations)7156 return FALSE; 7157 7158 if (emit_relocs) 5786 7159 { 5787 7160 Elf_Internal_Rela *irela; 5788 7161 Elf_Internal_Rela *irelaend; 7162 bfd_vma last_offset; 5789 7163 struct elf_link_hash_entry **rel_hash; 5790 Elf_Internal_Shdr *input_rel_hdr ;7164 Elf_Internal_Shdr *input_rel_hdr, *input_rel_hdr2; 5791 7165 unsigned int next_erel; 7166 bfd_boolean (*reloc_emitter) 7167 PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, 7168 Elf_Internal_Rela *)); 7169 bfd_boolean rela_normal; 7170 7171 input_rel_hdr = &elf_section_data (o)->rel_hdr; 7172 rela_normal = (bed->rela_normal 7173 && (input_rel_hdr->sh_entsize 7174 == sizeof (Elf_External_Rela))); 5792 7175 5793 7176 /* Adjust the reloc addresses and symbol indices. */ 5794 7177 5795 7178 irela = internal_relocs; 5796 irelaend = irela 5797 + o->reloc_count * bed->s->int_rels_per_ext_rel; 7179 irelaend = irela + o->reloc_count * bed->s->int_rels_per_ext_rel; 5798 7180 rel_hash = (elf_section_data (o->output_section)->rel_hashes 5799 7181 + elf_section_data (o->output_section)->rel_count 5800 7182 + elf_section_data (o->output_section)->rel_count2); 7183 last_offset = o->output_offset; 7184 if (!finfo->info->relocateable) 7185 last_offset += o->output_section->vma; 5801 7186 for (next_erel = 0; irela < irelaend; irela++, next_erel++) 5802 7187 { 5803 7188 unsigned long r_symndx; 5804 Elf_Internal_Sym *isym;5805 7189 asection *sec; 7190 Elf_Internal_Sym sym; 5806 7191 5807 7192 if (next_erel == bed->s->int_rels_per_ext_rel) … … 5811 7196 } 5812 7197 7198 irela->r_offset = _bfd_elf_section_offset (output_bfd, 7199 finfo->info, o, 7200 irela->r_offset); 7201 if (irela->r_offset >= (bfd_vma) -2) 7202 { 7203 /* This is a reloc for a deleted entry or somesuch. 7204 Turn it into an R_*_NONE reloc, at the same 7205 offset as the last reloc. elf_eh_frame.c and 7206 elf_bfd_discard_info rely on reloc offsets 7207 being ordered. */ 7208 irela->r_offset = last_offset; 7209 irela->r_info = 0; 7210 irela->r_addend = 0; 7211 continue; 7212 } 7213 5813 7214 irela->r_offset += o->output_offset; 5814 7215 5815 7216 /* Relocs in an executable have to be virtual addresses. */ 5816 if ( finfo->info->emitrelocations)7217 if (!finfo->info->relocateable) 5817 7218 irela->r_offset += o->output_section->vma; 5818 7219 7220 last_offset = irela->r_offset; 7221 5819 7222 r_symndx = ELF_R_SYM (irela->r_info); 5820 5821 if (r_symndx == 0) 7223 if (r_symndx == STN_UNDEF) 5822 7224 continue; 5823 7225 … … 5856 7258 5857 7259 *rel_hash = NULL; 5858 isym = finfo->internal_syms + r_symndx;7260 sym = isymbuf[r_symndx]; 5859 7261 sec = finfo->sections[r_symndx]; 5860 if (ELF_ST_TYPE ( isym->st_info) == STT_SECTION)7262 if (ELF_ST_TYPE (sym.st_info) == STT_SECTION) 5861 7263 { 5862 7264 /* I suppose the backend ought to fill in the … … 5865 7267 discarded a section, the output_section will 5866 7268 be the absolute section. */ 5867 if (sec != NULL 5868 && (bfd_is_abs_section (sec) 5869 || (sec->output_section != NULL 5870 && bfd_is_abs_section (sec->output_section)))) 7269 if (bfd_is_abs_section (sec) 7270 || (sec != NULL 7271 && bfd_is_abs_section (sec->output_section))) 5871 7272 r_symndx = 0; 5872 7273 else if (sec == NULL || sec->owner == NULL) 5873 7274 { 5874 7275 bfd_set_error (bfd_error_bad_value); 5875 return false;7276 return FALSE; 5876 7277 } 5877 7278 else … … 5880 7281 BFD_ASSERT (r_symndx != 0); 5881 7282 } 7283 7284 /* Adjust the addend according to where the 7285 section winds up in the output section. */ 7286 if (rela_normal) 7287 irela->r_addend += sec->output_offset; 5882 7288 } 5883 7289 else … … 5885 7291 if (finfo->indices[r_symndx] == -1) 5886 7292 { 5887 unsigned long link;7293 unsigned long shlink; 5888 7294 const char *name; 5889 7295 asection *osec; … … 5893 7299 /* You can't do ld -r -s. */ 5894 7300 bfd_set_error (bfd_error_invalid_operation); 5895 return false;7301 return FALSE; 5896 7302 } 5897 7303 … … 5899 7305 since it is needed by a reloc, we 5900 7306 must output it now. */ 5901 link = symtab_hdr->sh_link; 5902 name = bfd_elf_string_from_elf_section (input_bfd, 5903 link, 5904 isym->st_name); 7307 shlink = symtab_hdr->sh_link; 7308 name = (bfd_elf_string_from_elf_section 7309 (input_bfd, shlink, sym.st_name)); 5905 7310 if (name == NULL) 5906 return false;7311 return FALSE; 5907 7312 5908 7313 osec = sec->output_section; 5909 isym->st_shndx =7314 sym.st_shndx = 5910 7315 _bfd_elf_section_from_bfd_section (output_bfd, 5911 7316 osec); 5912 if ( isym->st_shndx == (unsigned short) -1)5913 return false;5914 5915 isym->st_value += sec->output_offset;7317 if (sym.st_shndx == SHN_BAD) 7318 return FALSE; 7319 7320 sym.st_value += sec->output_offset; 5916 7321 if (! finfo->info->relocateable) 5917 isym->st_value += osec->vma; 5918 5919 finfo->indices[r_symndx] = bfd_get_symcount (output_bfd); 5920 5921 if (! elf_link_output_sym (finfo, name, isym, sec)) 5922 return false; 7322 { 7323 sym.st_value += osec->vma; 7324 if (ELF_ST_TYPE (sym.st_info) == STT_TLS) 7325 { 7326 /* STT_TLS symbols are relative to PT_TLS 7327 segment base. */ 7328 BFD_ASSERT (finfo->first_tls_sec != NULL); 7329 sym.st_value -= finfo->first_tls_sec->vma; 7330 } 7331 } 7332 7333 finfo->indices[r_symndx] 7334 = bfd_get_symcount (output_bfd); 7335 7336 if (! elf_link_output_sym (finfo, name, &sym, sec)) 7337 return FALSE; 5923 7338 } 5924 7339 … … 5931 7346 5932 7347 /* Swap out the relocs. */ 5933 input_rel_hdr = &elf_section_data (o)->rel_hdr; 5934 elf_link_output_relocs (output_bfd, o, 5935 input_rel_hdr, 5936 internal_relocs); 5937 internal_relocs += NUM_SHDR_ENTRIES (input_rel_hdr) 5938 * bed->s->int_rels_per_ext_rel; 5939 input_rel_hdr = elf_section_data (o)->rel_hdr2; 5940 if (input_rel_hdr) 5941 elf_link_output_relocs (output_bfd, o, 5942 input_rel_hdr, 5943 internal_relocs); 7348 if (bed->elf_backend_emit_relocs 7349 && !(finfo->info->relocateable 7350 || finfo->info->emitrelocations)) 7351 reloc_emitter = bed->elf_backend_emit_relocs; 7352 else 7353 reloc_emitter = elf_link_output_relocs; 7354 7355 if (input_rel_hdr->sh_size != 0 7356 && ! (*reloc_emitter) (output_bfd, o, input_rel_hdr, 7357 internal_relocs)) 7358 return FALSE; 7359 7360 input_rel_hdr2 = elf_section_data (o)->rel_hdr2; 7361 if (input_rel_hdr2 && input_rel_hdr2->sh_size != 0) 7362 { 7363 internal_relocs += (NUM_SHDR_ENTRIES (input_rel_hdr) 7364 * bed->s->int_rels_per_ext_rel); 7365 if (! (*reloc_emitter) (output_bfd, o, input_rel_hdr2, 7366 internal_relocs)) 7367 return FALSE; 7368 } 5944 7369 } 5945 7370 } 5946 7371 5947 7372 /* Write out the modified section contents. */ 5948 if (elf_section_data (o)->stab_info == NULL) 5949 { 5950 if (! (o->flags & SEC_EXCLUDE) && 5951 ! bfd_set_section_contents (output_bfd, o->output_section, 5952 contents, o->output_offset, 5953 (o->_cooked_size != 0 5954 ? o->_cooked_size 5955 : o->_raw_size))) 5956 return false; 5957 } 5958 else 5959 { 7373 if (bed->elf_backend_write_section 7374 && (*bed->elf_backend_write_section) (output_bfd, o, contents)) 7375 { 7376 /* Section written out. */ 7377 } 7378 else switch (o->sec_info_type) 7379 { 7380 case ELF_INFO_TYPE_STABS: 5960 7381 if (! (_bfd_write_section_stabs 5961 (output_bfd, &elf_hash_table (finfo->info)->stab_info, 5962 o, &elf_section_data (o)->stab_info, contents))) 5963 return false; 5964 } 5965 } 5966 5967 return true; 7382 (output_bfd, 7383 &elf_hash_table (finfo->info)->stab_info, 7384 o, &elf_section_data (o)->sec_info, contents))) 7385 return FALSE; 7386 break; 7387 case ELF_INFO_TYPE_MERGE: 7388 if (! _bfd_write_merged_section (output_bfd, o, 7389 elf_section_data (o)->sec_info)) 7390 return FALSE; 7391 break; 7392 case ELF_INFO_TYPE_EH_FRAME: 7393 { 7394 if (! _bfd_elf_write_section_eh_frame (output_bfd, finfo->info, 7395 o, contents)) 7396 return FALSE; 7397 } 7398 break; 7399 default: 7400 { 7401 bfd_size_type sec_size; 7402 7403 sec_size = (o->_cooked_size != 0 ? o->_cooked_size : o->_raw_size); 7404 if (! (o->flags & SEC_EXCLUDE) 7405 && ! bfd_set_section_contents (output_bfd, o->output_section, 7406 contents, 7407 (file_ptr) o->output_offset, 7408 sec_size)) 7409 return FALSE; 7410 } 7411 break; 7412 } 7413 } 7414 7415 return TRUE; 5968 7416 } 5969 7417 … … 5973 7421 with -Ur. */ 5974 7422 5975 static b oolean7423 static bfd_boolean 5976 7424 elf_reloc_link_order (output_bfd, info, output_section, link_order) 5977 7425 bfd *output_bfd; … … 5987 7435 Elf_Internal_Shdr *rel_hdr; 5988 7436 struct elf_backend_data *bed = get_elf_backend_data (output_bfd); 7437 Elf_Internal_Rela irel[MAX_INT_RELS_PER_EXT_REL]; 7438 bfd_byte *erel; 7439 unsigned int i; 5989 7440 5990 7441 howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc); … … 5992 7443 { 5993 7444 bfd_set_error (bfd_error_bad_value); 5994 return false;7445 return FALSE; 5995 7446 } 5996 7447 … … 6012 7463 6013 7464 /* Treat a reloc against a defined symbol as though it were 6014 7465 actually against the section. */ 6015 7466 h = ((struct elf_link_hash_entry *) 6016 7467 bfd_wrapped_link_hash_lookup (output_bfd, info, 6017 7468 link_order->u.reloc.p->u.name, 6018 false, false, true));7469 FALSE, FALSE, TRUE)); 6019 7470 if (h != NULL 6020 7471 && (h->root.type == bfd_link_hash_defined … … 6027 7478 *rel_hash_ptr = NULL; 6028 7479 /* It seems that we ought to add the symbol value to the 6029 6030 7480 addend here, but in practice it has already been added 7481 because it was passed to constructor_callback. */ 6031 7482 addend += section->output_section->vma + section->output_offset; 6032 7483 } … … 6044 7495 (info, link_order->u.reloc.p->u.name, (bfd *) NULL, 6045 7496 (asection *) NULL, (bfd_vma) 0))) 6046 return false;7497 return FALSE; 6047 7498 indx = 0; 6048 7499 } … … 6056 7507 bfd_reloc_status_type rstat; 6057 7508 bfd_byte *buf; 6058 boolean ok; 7509 bfd_boolean ok; 7510 const char *sym_name; 6059 7511 6060 7512 size = bfd_get_reloc_size (howto); 6061 7513 buf = (bfd_byte *) bfd_zmalloc (size); 6062 7514 if (buf == (bfd_byte *) NULL) 6063 return false;6064 rstat = _bfd_relocate_contents (howto, output_bfd, addend, buf);7515 return FALSE; 7516 rstat = _bfd_relocate_contents (howto, output_bfd, (bfd_vma) addend, buf); 6065 7517 switch (rstat) 6066 7518 { 6067 7519 case bfd_reloc_ok: 6068 7520 break; 7521 6069 7522 default: 6070 7523 case bfd_reloc_outofrange: 6071 7524 abort (); 7525 6072 7526 case bfd_reloc_overflow: 7527 if (link_order->type == bfd_section_reloc_link_order) 7528 sym_name = bfd_section_name (output_bfd, 7529 link_order->u.reloc.p->u.section); 7530 else 7531 sym_name = link_order->u.reloc.p->u.name; 6073 7532 if (! ((*info->callbacks->reloc_overflow) 6074 (info, 6075 (link_order->type == bfd_section_reloc_link_order 6076 ? bfd_section_name (output_bfd, 6077 link_order->u.reloc.p->u.section) 6078 : link_order->u.reloc.p->u.name), 6079 howto->name, addend, (bfd *) NULL, (asection *) NULL, 6080 (bfd_vma) 0))) 7533 (info, sym_name, howto->name, addend, 7534 (bfd *) NULL, (asection *) NULL, (bfd_vma) 0))) 6081 7535 { 6082 7536 free (buf); 6083 return false;7537 return FALSE; 6084 7538 } 6085 7539 break; … … 6089 7543 free (buf); 6090 7544 if (! ok) 6091 return false;7545 return FALSE; 6092 7546 } 6093 7547 … … 6099 7553 offset += output_section->vma; 6100 7554 7555 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++) 7556 { 7557 irel[i].r_offset = offset; 7558 irel[i].r_info = 0; 7559 irel[i].r_addend = 0; 7560 } 7561 irel[0].r_info = ELF_R_INFO (indx, howto->type); 7562 6101 7563 rel_hdr = &elf_section_data (output_section)->rel_hdr; 6102 7564 erel = rel_hdr->contents; 6103 7565 if (rel_hdr->sh_type == SHT_REL) 6104 7566 { 6105 Elf_Internal_Rel *irel; 6106 Elf_External_Rel *erel; 6107 unsigned int i; 6108 6109 irel = (Elf_Internal_Rel *) bfd_zmalloc (bed->s->int_rels_per_ext_rel 6110 * sizeof (Elf_Internal_Rel)); 6111 if (irel == NULL) 6112 return false; 6113 6114 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++) 6115 irel[i].r_offset = offset; 6116 irel[0].r_info = ELF_R_INFO (indx, howto->type); 6117 6118 erel = ((Elf_External_Rel *) rel_hdr->contents 6119 + elf_section_data (output_section)->rel_count); 6120 6121 if (bed->s->swap_reloc_out) 6122 (*bed->s->swap_reloc_out) (output_bfd, irel, (bfd_byte *) erel); 6123 else 6124 elf_swap_reloc_out (output_bfd, irel, erel); 6125 6126 free (irel); 7567 erel += (elf_section_data (output_section)->rel_count 7568 * sizeof (Elf_External_Rel)); 7569 (*bed->s->swap_reloc_out) (output_bfd, irel, erel); 6127 7570 } 6128 7571 else 6129 7572 { 6130 Elf_Internal_Rela *irela; 6131 Elf_External_Rela *erela; 6132 unsigned int i; 6133 6134 irela = (Elf_Internal_Rela *) bfd_zmalloc (bed->s->int_rels_per_ext_rel 6135 * sizeof (Elf_Internal_Rela)); 6136 if (irela == NULL) 6137 return false; 6138 6139 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++) 6140 irela[i].r_offset = offset; 6141 irela[0].r_info = ELF_R_INFO (indx, howto->type); 6142 irela[0].r_addend = addend; 6143 6144 erela = ((Elf_External_Rela *) rel_hdr->contents 6145 + elf_section_data (output_section)->rel_count); 6146 6147 if (bed->s->swap_reloca_out) 6148 (*bed->s->swap_reloca_out) (output_bfd, irela, (bfd_byte *) erela); 6149 else 6150 elf_swap_reloca_out (output_bfd, irela, erela); 7573 irel[0].r_addend = addend; 7574 erel += (elf_section_data (output_section)->rel_count 7575 * sizeof (Elf_External_Rela)); 7576 (*bed->s->swap_reloca_out) (output_bfd, irel, erel); 6151 7577 } 6152 7578 6153 7579 ++elf_section_data (output_section)->rel_count; 6154 7580 6155 return true;7581 return TRUE; 6156 7582 } 6157 7583 … … 6159 7585 /* Allocate a pointer to live in a linker created section. */ 6160 7586 6161 b oolean7587 bfd_boolean 6162 7588 elf_create_pointer_linker_section (abfd, info, lsect, h, rel) 6163 7589 bfd *abfd; … … 6169 7595 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; 6170 7596 elf_linker_section_pointers_t *linker_section_ptr; 6171 unsigned long r_symndx = ELF_R_SYM (rel->r_info);; 7597 unsigned long r_symndx = ELF_R_SYM (rel->r_info); 7598 bfd_size_type amt; 6172 7599 6173 7600 BFD_ASSERT (lsect != NULL); 6174 7601 6175 /* Is this a global symbol? */7602 /* Is this a global symbol? */ 6176 7603 if (h != NULL) 6177 7604 { 6178 /* Has this symbol already been allocated , if so, our work is done*/7605 /* Has this symbol already been allocated? If so, our work is done. */ 6179 7606 if (_bfd_elf_find_pointer_linker_section (h->linker_section_pointer, 6180 7607 rel->r_addend, 6181 7608 lsect->which)) 6182 return true;7609 return TRUE; 6183 7610 6184 7611 ptr_linker_section_ptr = &h->linker_section_pointer; … … 6187 7614 { 6188 7615 if (! elf_link_record_dynamic_symbol (info, h)) 6189 return false;7616 return FALSE; 6190 7617 } 6191 7618 … … 6193 7620 lsect->rel_section->_raw_size += sizeof (Elf_External_Rela); 6194 7621 } 6195 6196 else /* Allocation of a pointer to a local symbol */6197 {7622 else 7623 { 7624 /* Allocation of a pointer to a local symbol. */ 6198 7625 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); 6199 7626 6200 /* Allocate a table to hold the local symbols if first time */7627 /* Allocate a table to hold the local symbols if first time. */ 6201 7628 if (!ptr) 6202 7629 { … … 6204 7631 register unsigned int i; 6205 7632 6206 ptr = (elf_linker_section_pointers_t **) 6207 bfd_alloc (abfd, num_symbols * sizeof (elf_linker_section_pointers_t *)); 7633 amt = num_symbols; 7634 amt *= sizeof (elf_linker_section_pointers_t *); 7635 ptr = (elf_linker_section_pointers_t **) bfd_alloc (abfd, amt); 6208 7636 6209 7637 if (!ptr) 6210 return false;7638 return FALSE; 6211 7639 6212 7640 elf_local_ptr_offsets (abfd) = ptr; 6213 7641 for (i = 0; i < num_symbols; i++) 6214 ptr[i] = (elf_linker_section_pointers_t *) 0;6215 } 6216 6217 /* Has this symbol already been allocated , if so, our work is done*/7642 ptr[i] = (elf_linker_section_pointers_t *) 0; 7643 } 7644 7645 /* Has this symbol already been allocated? If so, our work is done. */ 6218 7646 if (_bfd_elf_find_pointer_linker_section (ptr[r_symndx], 6219 7647 rel->r_addend, 6220 7648 lsect->which)) 6221 return true;7649 return TRUE; 6222 7650 6223 7651 ptr_linker_section_ptr = &ptr[r_symndx]; … … 6233 7661 } 6234 7662 6235 /* Allocate space for a pointer in the linker section, and allocate a new pointer record6236 from internal memory. */7663 /* Allocate space for a pointer in the linker section, and allocate 7664 a new pointer record from internal memory. */ 6237 7665 BFD_ASSERT (ptr_linker_section_ptr != NULL); 6238 linker_section_ptr = (elf_linker_section_pointers_t *)6239 bfd_alloc (abfd, sizeof (elf_linker_section_pointers_t));7666 amt = sizeof (elf_linker_section_pointers_t); 7667 linker_section_ptr = (elf_linker_section_pointers_t *) bfd_alloc (abfd, amt); 6240 7668 6241 7669 if (!linker_section_ptr) 6242 return false;7670 return FALSE; 6243 7671 6244 7672 linker_section_ptr->next = *ptr_linker_section_ptr; 6245 7673 linker_section_ptr->addend = rel->r_addend; 6246 7674 linker_section_ptr->which = lsect->which; 6247 linker_section_ptr->written_address_p = false;7675 linker_section_ptr->written_address_p = FALSE; 6248 7676 *ptr_linker_section_ptr = linker_section_ptr; 6249 7677 … … 6251 7679 if (lsect->hole_size && lsect->hole_offset < lsect->max_hole_offset) 6252 7680 { 6253 linker_section_ptr->offset = lsect->section->_raw_size - lsect->hole_size + (ARCH_SIZE / 8); 7681 linker_section_ptr->offset = (lsect->section->_raw_size 7682 - lsect->hole_size + (ARCH_SIZE / 8)); 6254 7683 lsect->hole_offset += ARCH_SIZE / 8; 6255 7684 lsect->sym_offset += ARCH_SIZE / 8; 6256 if (lsect->sym_hash) /* Bump up symbol value if needed */ 6257 { 7685 if (lsect->sym_hash) 7686 { 7687 /* Bump up symbol value if needed. */ 6258 7688 lsect->sym_hash->root.u.def.value += ARCH_SIZE / 8; 6259 7689 #ifdef DEBUG 6260 7690 fprintf (stderr, "Bump up %s by %ld, current value = %ld\n", 6261 7691 lsect->sym_hash->root.root.string, 6262 (long) ARCH_SIZE / 8,6263 (long) lsect->sym_hash->root.u.def.value);7692 (long) ARCH_SIZE / 8, 7693 (long) lsect->sym_hash->root.u.def.value); 6264 7694 #endif 6265 7695 } … … 6272 7702 6273 7703 #ifdef DEBUG 6274 fprintf (stderr, "Create pointer in linker section %s, offset = %ld, section size = %ld\n", 6275 lsect->name, (long)linker_section_ptr->offset, (long)lsect->section->_raw_size); 7704 fprintf (stderr, 7705 "Create pointer in linker section %s, offset = %ld, section size = %ld\n", 7706 lsect->name, (long) linker_section_ptr->offset, 7707 (long) lsect->section->_raw_size); 6276 7708 #endif 6277 7709 6278 return true;7710 return TRUE; 6279 7711 } 6280 7712 … … 6290 7722 6291 7723 bfd_vma 6292 elf_finish_pointer_linker_section (output_bfd, input_bfd, info, lsect, h, relocation, rel, relative_reloc) 7724 elf_finish_pointer_linker_section (output_bfd, input_bfd, info, lsect, h, 7725 relocation, rel, relative_reloc) 6293 7726 bfd *output_bfd; 6294 7727 bfd *input_bfd; … … 6304 7737 BFD_ASSERT (lsect != NULL); 6305 7738 6306 if (h != NULL) /* global symbol */ 6307 { 6308 linker_section_ptr = _bfd_elf_find_pointer_linker_section (h->linker_section_pointer, 6309 rel->r_addend, 6310 lsect->which); 7739 if (h != NULL) 7740 { 7741 /* Handle global symbol. */ 7742 linker_section_ptr = (_bfd_elf_find_pointer_linker_section 7743 (h->linker_section_pointer, 7744 rel->r_addend, 7745 lsect->which)); 6311 7746 6312 7747 BFD_ASSERT (linker_section_ptr != NULL); … … 6327 7762 if (!linker_section_ptr->written_address_p) 6328 7763 { 6329 linker_section_ptr->written_address_p = true; 6330 bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend, 6331 lsect->section->contents + linker_section_ptr->offset); 7764 linker_section_ptr->written_address_p = TRUE; 7765 bfd_put_ptr (output_bfd, 7766 relocation + linker_section_ptr->addend, 7767 (lsect->section->contents 7768 + linker_section_ptr->offset)); 6332 7769 } 6333 7770 } 6334 7771 } 6335 else /* local symbol */ 6336 { 7772 else 7773 { 7774 /* Handle local symbol. */ 6337 7775 unsigned long r_symndx = ELF_R_SYM (rel->r_info); 6338 7776 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); 6339 7777 BFD_ASSERT (elf_local_ptr_offsets (input_bfd)[r_symndx] != NULL); 6340 linker_section_ptr = _bfd_elf_find_pointer_linker_section (elf_local_ptr_offsets (input_bfd)[r_symndx], 6341 rel->r_addend, 6342 lsect->which); 7778 linker_section_ptr = (_bfd_elf_find_pointer_linker_section 7779 (elf_local_ptr_offsets (input_bfd)[r_symndx], 7780 rel->r_addend, 7781 lsect->which)); 6343 7782 6344 7783 BFD_ASSERT (linker_section_ptr != NULL); 6345 7784 6346 /* Write out pointer if it hasn't been rewritten out before */7785 /* Write out pointer if it hasn't been rewritten out before. */ 6347 7786 if (!linker_section_ptr->written_address_p) 6348 7787 { 6349 linker_section_ptr->written_address_p = true;7788 linker_section_ptr->written_address_p = TRUE; 6350 7789 bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend, 6351 7790 lsect->section->contents + linker_section_ptr->offset); … … 6354 7793 { 6355 7794 asection *srel = lsect->rel_section; 6356 Elf_Internal_Rela *outrel; 7795 Elf_Internal_Rela outrel[MAX_INT_RELS_PER_EXT_REL]; 7796 bfd_byte *erel; 6357 7797 struct elf_backend_data *bed = get_elf_backend_data (output_bfd); 6358 7798 unsigned int i; 6359 7799 6360 outrel = (Elf_Internal_Rela *) bfd_zmalloc (sizeof (Elf_Internal_Rela)6361 * bed->s->int_rels_per_ext_rel);6362 if ( outrel == NULL)7800 /* We need to generate a relative reloc for the dynamic 7801 linker. */ 7802 if (!srel) 6363 7803 { 6364 (*_bfd_error_handler) (_("Error: out of memory")); 6365 return 0; 7804 srel = bfd_get_section_by_name (elf_hash_table (info)->dynobj, 7805 lsect->rel_name); 7806 lsect->rel_section = srel; 6366 7807 } 6367 7808 6368 /* We need to generate a relative reloc for the dynamic linker. */6369 if (!srel)6370 lsect->rel_section = srel = bfd_get_section_by_name (elf_hash_table (info)->dynobj,6371 lsect->rel_name);6372 6373 7809 BFD_ASSERT (srel != NULL); 6374 7810 6375 7811 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++) 6376 outrel[i].r_offset = (lsect->section->output_section->vma 6377 + lsect->section->output_offset 6378 + linker_section_ptr->offset); 7812 { 7813 outrel[i].r_offset = (lsect->section->output_section->vma 7814 + lsect->section->output_offset 7815 + linker_section_ptr->offset); 7816 outrel[i].r_info = 0; 7817 outrel[i].r_addend = 0; 7818 } 6379 7819 outrel[0].r_info = ELF_R_INFO (0, relative_reloc); 6380 outrel[0].r_addend = 0; 6381 elf_swap_reloca_out (output_bfd, outrel, 6382 (((Elf_External_Rela *) 6383 lsect->section->contents) 6384 + elf_section_data (lsect->section)->rel_count)); 6385 ++elf_section_data (lsect->section)->rel_count; 6386 6387 free (outrel); 7820 erel = lsect->section->contents; 7821 erel += (elf_section_data (lsect->section)->rel_count++ 7822 * sizeof (Elf_External_Rela)); 7823 elf_swap_reloca_out (output_bfd, outrel, erel); 6388 7824 } 6389 7825 } … … 6396 7832 6397 7833 #ifdef DEBUG 6398 fprintf (stderr, "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", 6399 lsect->name, (long)relocation, (long)relocation); 7834 fprintf (stderr, 7835 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", 7836 lsect->name, (long) relocation, (long) relocation); 6400 7837 #endif 6401 7838 … … 6408 7845 /* Garbage collect unused sections. */ 6409 7846 6410 static boolean elf_gc_mark 6411 PARAMS ((struct bfd_link_info *info, asection *sec, 6412 asection * (*gc_mark_hook) 6413 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, 6414 struct elf_link_hash_entry *, Elf_Internal_Sym *)))); 6415 6416 static boolean elf_gc_sweep 6417 PARAMS ((struct bfd_link_info *info, 6418 boolean (*gc_sweep_hook) 6419 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o, 6420 const Elf_Internal_Rela *relocs)))); 6421 6422 static boolean elf_gc_sweep_symbol 6423 PARAMS ((struct elf_link_hash_entry *h, PTR idxptr)); 6424 6425 static boolean elf_gc_allocate_got_offsets 6426 PARAMS ((struct elf_link_hash_entry *h, PTR offarg)); 6427 6428 static boolean elf_gc_propagate_vtable_entries_used 6429 PARAMS ((struct elf_link_hash_entry *h, PTR dummy)); 6430 6431 static boolean elf_gc_smash_unused_vtentry_relocs 6432 PARAMS ((struct elf_link_hash_entry *h, PTR dummy)); 7847 static bfd_boolean elf_gc_mark 7848 PARAMS ((struct bfd_link_info *, asection *, 7849 asection * (*) (asection *, struct bfd_link_info *, 7850 Elf_Internal_Rela *, struct elf_link_hash_entry *, 7851 Elf_Internal_Sym *))); 7852 7853 static bfd_boolean elf_gc_sweep 7854 PARAMS ((struct bfd_link_info *, 7855 bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *, 7856 const Elf_Internal_Rela *))); 7857 7858 static bfd_boolean elf_gc_sweep_symbol 7859 PARAMS ((struct elf_link_hash_entry *, PTR)); 7860 7861 static bfd_boolean elf_gc_allocate_got_offsets 7862 PARAMS ((struct elf_link_hash_entry *, PTR)); 7863 7864 static bfd_boolean elf_gc_propagate_vtable_entries_used 7865 PARAMS ((struct elf_link_hash_entry *, PTR)); 7866 7867 static bfd_boolean elf_gc_smash_unused_vtentry_relocs 7868 PARAMS ((struct elf_link_hash_entry *, PTR)); 6433 7869 6434 7870 /* The mark phase of garbage collection. For a given section, mark 6435 it, and all the sections which define symbols to which it refers. */ 6436 6437 static boolean 7871 it and any sections in this section's group, and all the sections 7872 which define symbols to which it refers. */ 7873 7874 typedef asection * (*gc_mark_hook_fn) 7875 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 7876 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 7877 7878 static bfd_boolean 6438 7879 elf_gc_mark (info, sec, gc_mark_hook) 6439 7880 struct bfd_link_info *info; 6440 7881 asection *sec; 6441 asection * (*gc_mark_hook) 6442 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, 6443 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 7882 gc_mark_hook_fn gc_mark_hook; 6444 7883 { 6445 boolean ret = true; 7884 bfd_boolean ret; 7885 asection *group_sec; 6446 7886 6447 7887 sec->gc_mark = 1; 6448 7888 7889 /* Mark all the sections in the group. */ 7890 group_sec = elf_section_data (sec)->next_in_group; 7891 if (group_sec && !group_sec->gc_mark) 7892 if (!elf_gc_mark (info, group_sec, gc_mark_hook)) 7893 return FALSE; 7894 6449 7895 /* Look through the section relocs. */ 6450 7896 ret = TRUE; 6451 7897 if ((sec->flags & SEC_RELOC) != 0 && sec->reloc_count > 0) 6452 7898 { … … 6456 7902 size_t nlocsyms; 6457 7903 size_t extsymoff; 6458 Elf_External_Sym *locsyms, *freesyms = NULL;6459 7904 bfd *input_bfd = sec->owner; 6460 7905 struct elf_backend_data *bed = get_elf_backend_data (input_bfd); 6461 6462 /* GCFIXME: how to arrange so that relocs and symbols are not 6463 reread continually? */ 7906 Elf_Internal_Sym *isym = NULL; 6464 7907 6465 7908 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; … … 6470 7913 { 6471 7914 nlocsyms = symtab_hdr->sh_size / sizeof (Elf_External_Sym); 6472 7915 extsymoff = 0; 6473 7916 } 6474 7917 else 6475 7918 extsymoff = nlocsyms = symtab_hdr->sh_info; 6476 if (symtab_hdr->contents) 6477 locsyms = (Elf_External_Sym *) symtab_hdr->contents; 6478 else if (nlocsyms == 0) 6479 locsyms = NULL; 6480 else 6481 { 6482 locsyms = freesyms = 6483 bfd_malloc (nlocsyms * sizeof (Elf_External_Sym)); 6484 if (freesyms == NULL 6485 || bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 6486 || (bfd_read (locsyms, sizeof (Elf_External_Sym), 6487 nlocsyms, input_bfd) 6488 != nlocsyms * sizeof (Elf_External_Sym))) 6489 { 6490 ret = false; 6491 goto out1; 6492 } 7919 7920 isym = (Elf_Internal_Sym *) symtab_hdr->contents; 7921 if (isym == NULL && nlocsyms != 0) 7922 { 7923 isym = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, nlocsyms, 0, 7924 NULL, NULL, NULL); 7925 if (isym == NULL) 7926 return FALSE; 6493 7927 } 6494 7928 6495 7929 /* Read the relocations. */ 6496 7930 relstart = (NAME(_bfd_elf,link_read_relocs) 6497 ( sec->owner, sec, NULL, (Elf_Internal_Rela *) NULL,7931 (input_bfd, sec, NULL, (Elf_Internal_Rela *) NULL, 6498 7932 info->keep_memory)); 6499 7933 if (relstart == NULL) 6500 7934 { 6501 ret = false;7935 ret = FALSE; 6502 7936 goto out1; 6503 7937 } … … 6509 7943 asection *rsec; 6510 7944 struct elf_link_hash_entry *h; 6511 Elf_Internal_Sym s;6512 7945 6513 7946 r_symndx = ELF_R_SYM (rel->r_info); … … 6515 7948 continue; 6516 7949 6517 if (elf_bad_symtab (sec->owner)) 6518 { 6519 elf_swap_symbol_in (input_bfd, &locsyms[r_symndx], &s); 6520 if (ELF_ST_BIND (s.st_info) == STB_LOCAL) 6521 rsec = (*gc_mark_hook) (sec->owner, info, rel, NULL, &s); 6522 else 6523 { 6524 h = sym_hashes[r_symndx - extsymoff]; 6525 rsec = (*gc_mark_hook) (sec->owner, info, rel, h, NULL); 6526 } 6527 } 6528 else if (r_symndx >= nlocsyms) 7950 if (r_symndx >= nlocsyms 7951 || ELF_ST_BIND (isym[r_symndx].st_info) != STB_LOCAL) 6529 7952 { 6530 7953 h = sym_hashes[r_symndx - extsymoff]; 6531 rsec = (*gc_mark_hook) (sec ->owner, info, rel, h, NULL);7954 rsec = (*gc_mark_hook) (sec, info, rel, h, NULL); 6532 7955 } 6533 7956 else 6534 7957 { 6535 elf_swap_symbol_in (input_bfd, &locsyms[r_symndx], &s); 6536 rsec = (*gc_mark_hook) (sec->owner, info, rel, NULL, &s); 7958 rsec = (*gc_mark_hook) (sec, info, rel, NULL, &isym[r_symndx]); 6537 7959 } 6538 7960 6539 7961 if (rsec && !rsec->gc_mark) 6540 if (!elf_gc_mark (info, rsec, gc_mark_hook)) 6541 { 6542 ret = false; 6543 goto out2; 6544 } 7962 { 7963 if (bfd_get_flavour (rsec->owner) != bfd_target_elf_flavour) 7964 rsec->gc_mark = 1; 7965 else if (!elf_gc_mark (info, rsec, gc_mark_hook)) 7966 { 7967 ret = FALSE; 7968 goto out2; 7969 } 7970 } 6545 7971 } 6546 7972 6547 7973 out2: 6548 if ( !info->keep_memory)7974 if (elf_section_data (sec)->relocs != relstart) 6549 7975 free (relstart); 6550 7976 out1: 6551 if (freesyms) 6552 free (freesyms); 7977 if (isym != NULL && symtab_hdr->contents != (unsigned char *) isym) 7978 { 7979 if (! info->keep_memory) 7980 free (isym); 7981 else 7982 symtab_hdr->contents = (unsigned char *) isym; 7983 } 6553 7984 } 6554 7985 … … 6558 7989 /* The sweep phase of garbage collection. Remove all garbage sections. */ 6559 7990 6560 static boolean 7991 typedef bfd_boolean (*gc_sweep_hook_fn) 7992 PARAMS ((bfd *, struct bfd_link_info *, asection *, 7993 const Elf_Internal_Rela *)); 7994 7995 static bfd_boolean 6561 7996 elf_gc_sweep (info, gc_sweep_hook) 6562 7997 struct bfd_link_info *info; 6563 boolean (*gc_sweep_hook) 6564 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o, 6565 const Elf_Internal_Rela *relocs)); 7998 gc_sweep_hook_fn gc_sweep_hook; 6566 7999 { 6567 8000 bfd *sub; … … 6598 8031 { 6599 8032 Elf_Internal_Rela *internal_relocs; 6600 b oolean r;8033 bfd_boolean r; 6601 8034 6602 8035 internal_relocs = (NAME(_bfd_elf,link_read_relocs) 6603 8036 (o->owner, o, NULL, NULL, info->keep_memory)); 6604 8037 if (internal_relocs == NULL) 6605 return false;8038 return FALSE; 6606 8039 6607 8040 r = (*gc_sweep_hook) (o->owner, info, o, internal_relocs); 6608 8041 6609 if ( !info->keep_memory)8042 if (elf_section_data (o)->relocs != internal_relocs) 6610 8043 free (internal_relocs); 6611 8044 6612 8045 if (!r) 6613 return false;8046 return FALSE; 6614 8047 } 6615 8048 } … … 6629 8062 } 6630 8063 6631 return true;8064 return TRUE; 6632 8065 } 6633 8066 6634 8067 /* Sweep symbols in swept sections. Called via elf_link_hash_traverse. */ 6635 8068 6636 static b oolean8069 static bfd_boolean 6637 8070 elf_gc_sweep_symbol (h, idxptr) 6638 8071 struct elf_link_hash_entry *h; … … 6641 8074 int *idx = (int *) idxptr; 6642 8075 8076 if (h->root.type == bfd_link_hash_warning) 8077 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8078 6643 8079 if (h->dynindx != -1 6644 8080 && ((h->root.type != bfd_link_hash_defined … … 6647 8083 h->dynindx = (*idx)++; 6648 8084 6649 return true;8085 return TRUE; 6650 8086 } 6651 8087 … … 6653 8089 elf_link_hash_traverse. */ 6654 8090 6655 static b oolean8091 static bfd_boolean 6656 8092 elf_gc_propagate_vtable_entries_used (h, okp) 6657 8093 struct elf_link_hash_entry *h; 6658 8094 PTR okp; 6659 8095 { 8096 if (h->root.type == bfd_link_hash_warning) 8097 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8098 6660 8099 /* Those that are not vtables. */ 6661 8100 if (h->vtable_parent == NULL) 6662 return true;8101 return TRUE; 6663 8102 6664 8103 /* Those vtables that do not have parents, we cannot merge. */ 6665 8104 if (h->vtable_parent == (struct elf_link_hash_entry *) -1) 6666 return true;8105 return TRUE; 6667 8106 6668 8107 /* If we've already been done, exit. */ 6669 8108 if (h->vtable_entries_used && h->vtable_entries_used[-1]) 6670 return true;8109 return TRUE; 6671 8110 6672 8111 /* Make sure the parent's table is up to date. */ … … 6683 8122 { 6684 8123 size_t n; 6685 b oolean *cu, *pu;8124 bfd_boolean *cu, *pu; 6686 8125 6687 8126 /* Or the parent's entries into ours. */ 6688 8127 cu = h->vtable_entries_used; 6689 cu[-1] = true;8128 cu[-1] = TRUE; 6690 8129 pu = h->vtable_parent->vtable_entries_used; 6691 8130 if (pu != NULL) 6692 8131 { 6693 n = h->vtable_parent->vtable_entries_size / FILE_ALIGN; 6694 while (--n != 0) 8132 asection *sec = h->root.u.def.section; 8133 struct elf_backend_data *bed = get_elf_backend_data (sec->owner); 8134 int file_align = bed->s->file_align; 8135 8136 n = h->vtable_parent->vtable_entries_size / file_align; 8137 while (n--) 6695 8138 { 6696 if (*pu) *cu = true; 6697 pu++, cu++; 8139 if (*pu) 8140 *cu = TRUE; 8141 pu++; 8142 cu++; 6698 8143 } 6699 8144 } 6700 8145 } 6701 8146 6702 return true;8147 return TRUE; 6703 8148 } 6704 8149 6705 static b oolean8150 static bfd_boolean 6706 8151 elf_gc_smash_unused_vtentry_relocs (h, okp) 6707 8152 struct elf_link_hash_entry *h; … … 6712 8157 Elf_Internal_Rela *relstart, *relend, *rel; 6713 8158 struct elf_backend_data *bed; 8159 int file_align; 8160 8161 if (h->root.type == bfd_link_hash_warning) 8162 h = (struct elf_link_hash_entry *) h->root.u.i.link; 6714 8163 6715 8164 /* Take care of both those symbols that do not describe vtables as 6716 8165 well as those that are not loaded. */ 6717 8166 if (h->vtable_parent == NULL) 6718 return true;8167 return TRUE; 6719 8168 6720 8169 BFD_ASSERT (h->root.type == bfd_link_hash_defined … … 6726 8175 6727 8176 relstart = (NAME(_bfd_elf,link_read_relocs) 6728 (sec->owner, sec, NULL, (Elf_Internal_Rela *) NULL, true));8177 (sec->owner, sec, NULL, (Elf_Internal_Rela *) NULL, TRUE)); 6729 8178 if (!relstart) 6730 return *(b oolean *)okp = false;8179 return *(bfd_boolean *) okp = FALSE; 6731 8180 bed = get_elf_backend_data (sec->owner); 8181 file_align = bed->s->file_align; 8182 6732 8183 relend = relstart + sec->reloc_count * bed->s->int_rels_per_ext_rel; 6733 8184 … … 6739 8190 && (rel->r_offset - hstart) < h->vtable_entries_size) 6740 8191 { 6741 bfd_vma entry = (rel->r_offset - hstart) / FILE_ALIGN;8192 bfd_vma entry = (rel->r_offset - hstart) / file_align; 6742 8193 if (h->vtable_entries_used[entry]) 6743 8194 continue; … … 6747 8198 } 6748 8199 6749 return true;8200 return TRUE; 6750 8201 } 6751 8202 6752 8203 /* Do mark and sweep of unused sections. */ 6753 8204 6754 b oolean8205 bfd_boolean 6755 8206 elf_gc_sections (abfd, info) 6756 8207 bfd *abfd; 6757 8208 struct bfd_link_info *info; 6758 8209 { 6759 b oolean ok = true;8210 bfd_boolean ok = TRUE; 6760 8211 bfd *sub; 6761 8212 asection * (*gc_mark_hook) 6762 PARAMS (( bfd *abfd, struct bfd_link_info *, Elf_Internal_Rela *,6763 8213 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 8214 struct elf_link_hash_entry *h, Elf_Internal_Sym *)); 6764 8215 6765 8216 if (!get_elf_backend_data (abfd)->can_gc_sections 6766 8217 || info->relocateable || info->emitrelocations 6767 8218 || elf_hash_table (info)->dynamic_sections_created) 6768 return true;8219 return TRUE; 6769 8220 6770 8221 /* Apply transitive closure to the vtable entry usage info. */ … … 6773 8224 (PTR) &ok); 6774 8225 if (!ok) 6775 return false;8226 return FALSE; 6776 8227 6777 8228 /* Kill the vtable relocations that were not used. */ … … 6780 8231 (PTR) &ok); 6781 8232 if (!ok) 6782 return false;8233 return FALSE; 6783 8234 6784 8235 /* Grovel through relocs to find out who stays ... */ … … 6795 8246 { 6796 8247 if (o->flags & SEC_KEEP) 6797 6798 return false;8248 if (!elf_gc_mark (info, o, gc_mark_hook)) 8249 return FALSE; 6799 8250 } 6800 8251 } 6801 8252 6802 8253 /* ... and mark SEC_EXCLUDE for those that go. */ 6803 if (!elf_gc_sweep (info, get_elf_backend_data (abfd)->gc_sweep_hook))6804 return false;6805 6806 return true;8254 if (!elf_gc_sweep (info, get_elf_backend_data (abfd)->gc_sweep_hook)) 8255 return FALSE; 8256 8257 return TRUE; 6807 8258 } 6808 8259 … … 6810 8261 /* Called from check_relocs to record the existance of a VTINHERIT reloc. */ 6811 8262 6812 b oolean8263 bfd_boolean 6813 8264 elf_gc_record_vtinherit (abfd, sec, h, offset) 6814 8265 bfd *abfd; … … 6844 8295 6845 8296 (*_bfd_error_handler) ("%s: %s+%lu: No symbol found for INHERIT", 6846 bfd_ get_filename (abfd), sec->name,6847 (unsigned long) offset);8297 bfd_archive_filename (abfd), sec->name, 8298 (unsigned long) offset); 6848 8299 bfd_set_error (bfd_error_invalid_operation); 6849 return false;6850 6851 win:8300 return FALSE; 8301 8302 win: 6852 8303 if (!h) 6853 8304 { … … 6862 8313 child->vtable_parent = h; 6863 8314 6864 return true;8315 return TRUE; 6865 8316 } 6866 8317 6867 8318 /* Called from check_relocs to record the existance of a VTENTRY reloc. */ 6868 8319 6869 b oolean8320 bfd_boolean 6870 8321 elf_gc_record_vtentry (abfd, sec, h, addend) 6871 8322 bfd *abfd ATTRIBUTE_UNUSED; … … 6874 8325 bfd_vma addend; 6875 8326 { 8327 struct elf_backend_data *bed = get_elf_backend_data (abfd); 8328 int file_align = bed->s->file_align; 8329 6876 8330 if (addend >= h->vtable_entries_size) 6877 8331 { 6878 8332 size_t size, bytes; 6879 b oolean *ptr = h->vtable_entries_used;8333 bfd_boolean *ptr = h->vtable_entries_used; 6880 8334 6881 8335 /* While the symbol is undefined, we have to be prepared to handle … … 6896 8350 /* Allocate one extra entry for use as a "done" flag for the 6897 8351 consolidation pass. */ 6898 bytes = (size / FILE_ALIGN + 1) * sizeof (boolean);8352 bytes = (size / file_align + 1) * sizeof (bfd_boolean); 6899 8353 6900 8354 if (ptr) 6901 8355 { 6902 ptr = bfd_realloc (ptr - 1, bytes);8356 ptr = bfd_realloc (ptr - 1, (bfd_size_type) bytes); 6903 8357 6904 8358 if (ptr != NULL) … … 6906 8360 size_t oldbytes; 6907 8361 6908 oldbytes = (h->vtable_entries_size/FILE_ALIGN + 1) * sizeof (boolean); 6909 memset (((char *)ptr) + oldbytes, 0, bytes - oldbytes); 8362 oldbytes = ((h->vtable_entries_size / file_align + 1) 8363 * sizeof (bfd_boolean)); 8364 memset (((char *) ptr) + oldbytes, 0, bytes - oldbytes); 6910 8365 } 6911 8366 } 6912 8367 else 6913 ptr = bfd_zmalloc ( bytes);8368 ptr = bfd_zmalloc ((bfd_size_type) bytes); 6914 8369 6915 8370 if (ptr == NULL) 6916 return false;8371 return FALSE; 6917 8372 6918 8373 /* And arrange for that done flag to be at index -1. */ … … 6921 8376 } 6922 8377 6923 h->vtable_entries_used[addend / FILE_ALIGN] = true;6924 6925 return true;8378 h->vtable_entries_used[addend / file_align] = TRUE; 8379 8380 return TRUE; 6926 8381 } 6927 8382 … … 6929 8384 we're done. Should be called from final_link. */ 6930 8385 6931 b oolean8386 bfd_boolean 6932 8387 elf_gc_common_finalize_got_offsets (abfd, info) 6933 8388 bfd *abfd; … … 6982 8437 elf_gc_allocate_got_offsets, 6983 8438 (PTR) &gotoff); 6984 return true;8439 return TRUE; 6985 8440 } 6986 8441 … … 6988 8443 to real got offsets. */ 6989 8444 6990 static b oolean8445 static bfd_boolean 6991 8446 elf_gc_allocate_got_offsets (h, offarg) 6992 8447 struct elf_link_hash_entry *h; … … 6995 8450 bfd_vma *off = (bfd_vma *) offarg; 6996 8451 8452 if (h->root.type == bfd_link_hash_warning) 8453 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8454 6997 8455 if (h->got.refcount > 0) 6998 8456 { … … 7003 8461 h->got.offset = (bfd_vma) -1; 7004 8462 7005 return true;8463 return TRUE; 7006 8464 } 7007 8465 … … 7009 8467 got entry reference counting is enabled. */ 7010 8468 7011 b oolean8469 bfd_boolean 7012 8470 elf_gc_common_final_link (abfd, info) 7013 8471 bfd *abfd; … … 7015 8473 { 7016 8474 if (!elf_gc_common_finalize_got_offsets (abfd, info)) 7017 return false;8475 return FALSE; 7018 8476 7019 8477 /* Invoke the regular ELF backend linker to do all the work. */ … … 7024 8482 all hash value of the exported symbols in an array. */ 7025 8483 7026 static b oolean8484 static bfd_boolean 7027 8485 elf_collect_hash_codes (h, data) 7028 8486 struct elf_link_hash_entry *h; … … 7035 8493 char *alc = NULL; 7036 8494 8495 if (h->root.type == bfd_link_hash_warning) 8496 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8497 7037 8498 /* Ignore indirect symbols. These are added by the versioning code. */ 7038 8499 if (h->dynindx == -1) 7039 return true;8500 return TRUE; 7040 8501 7041 8502 name = h->root.root.string; … … 7043 8504 if (p != NULL) 7044 8505 { 7045 alc = bfd_malloc ( p - name + 1);7046 memcpy (alc, name, p - name);8506 alc = bfd_malloc ((bfd_size_type) (p - name + 1)); 8507 memcpy (alc, name, (size_t) (p - name)); 7047 8508 alc[p - name] = '\0'; 7048 8509 name = alc; … … 7062 8523 free (alc); 7063 8524 7064 return true;8525 return TRUE; 7065 8526 } 8527 8528 bfd_boolean 8529 elf_reloc_symbol_deleted_p (offset, cookie) 8530 bfd_vma offset; 8531 PTR cookie; 8532 { 8533 struct elf_reloc_cookie *rcookie = (struct elf_reloc_cookie *) cookie; 8534 8535 if (rcookie->bad_symtab) 8536 rcookie->rel = rcookie->rels; 8537 8538 for (; rcookie->rel < rcookie->relend; rcookie->rel++) 8539 { 8540 unsigned long r_symndx; 8541 8542 if (! rcookie->bad_symtab) 8543 if (rcookie->rel->r_offset > offset) 8544 return FALSE; 8545 if (rcookie->rel->r_offset != offset) 8546 continue; 8547 8548 r_symndx = ELF_R_SYM (rcookie->rel->r_info); 8549 if (r_symndx == SHN_UNDEF) 8550 return TRUE; 8551 8552 if (r_symndx >= rcookie->locsymcount 8553 || ELF_ST_BIND (rcookie->locsyms[r_symndx].st_info) != STB_LOCAL) 8554 { 8555 struct elf_link_hash_entry *h; 8556 8557 h = rcookie->sym_hashes[r_symndx - rcookie->extsymoff]; 8558 8559 while (h->root.type == bfd_link_hash_indirect 8560 || h->root.type == bfd_link_hash_warning) 8561 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8562 8563 if ((h->root.type == bfd_link_hash_defined 8564 || h->root.type == bfd_link_hash_defweak) 8565 && elf_discarded_section (h->root.u.def.section)) 8566 return TRUE; 8567 else 8568 return FALSE; 8569 } 8570 else 8571 { 8572 /* It's not a relocation against a global symbol, 8573 but it could be a relocation against a local 8574 symbol for a discarded section. */ 8575 asection *isec; 8576 Elf_Internal_Sym *isym; 8577 8578 /* Need to: get the symbol; get the section. */ 8579 isym = &rcookie->locsyms[r_symndx]; 8580 if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE) 8581 { 8582 isec = section_from_elf_index (rcookie->abfd, isym->st_shndx); 8583 if (isec != NULL && elf_discarded_section (isec)) 8584 return TRUE; 8585 } 8586 } 8587 return FALSE; 8588 } 8589 return FALSE; 8590 } 8591 8592 /* Discard unneeded references to discarded sections. 8593 Returns TRUE if any section's size was changed. */ 8594 /* This function assumes that the relocations are in sorted order, 8595 which is true for all known assemblers. */ 8596 8597 bfd_boolean 8598 elf_bfd_discard_info (output_bfd, info) 8599 bfd *output_bfd; 8600 struct bfd_link_info *info; 8601 { 8602 struct elf_reloc_cookie cookie; 8603 asection *stab, *eh; 8604 Elf_Internal_Shdr *symtab_hdr; 8605 struct elf_backend_data *bed; 8606 bfd *abfd; 8607 unsigned int count; 8608 bfd_boolean ret = FALSE; 8609 8610 if (info->traditional_format 8611 || info->hash->creator->flavour != bfd_target_elf_flavour 8612 || ! is_elf_hash_table (info)) 8613 return FALSE; 8614 8615 for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next) 8616 { 8617 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) 8618 continue; 8619 8620 bed = get_elf_backend_data (abfd); 8621 8622 if ((abfd->flags & DYNAMIC) != 0) 8623 continue; 8624 8625 eh = bfd_get_section_by_name (abfd, ".eh_frame"); 8626 if (info->relocateable 8627 || (eh != NULL 8628 && (eh->_raw_size == 0 8629 || bfd_is_abs_section (eh->output_section)))) 8630 eh = NULL; 8631 8632 stab = bfd_get_section_by_name (abfd, ".stab"); 8633 if (stab != NULL 8634 && (stab->_raw_size == 0 8635 || bfd_is_abs_section (stab->output_section) 8636 || stab->sec_info_type != ELF_INFO_TYPE_STABS)) 8637 stab = NULL; 8638 8639 if (stab == NULL 8640 && eh == NULL 8641 && bed->elf_backend_discard_info == NULL) 8642 continue; 8643 8644 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 8645 cookie.abfd = abfd; 8646 cookie.sym_hashes = elf_sym_hashes (abfd); 8647 cookie.bad_symtab = elf_bad_symtab (abfd); 8648 if (cookie.bad_symtab) 8649 { 8650 cookie.locsymcount = symtab_hdr->sh_size / sizeof (Elf_External_Sym); 8651 cookie.extsymoff = 0; 8652 } 8653 else 8654 { 8655 cookie.locsymcount = symtab_hdr->sh_info; 8656 cookie.extsymoff = symtab_hdr->sh_info; 8657 } 8658 8659 cookie.locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; 8660 if (cookie.locsyms == NULL && cookie.locsymcount != 0) 8661 { 8662 cookie.locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, 8663 cookie.locsymcount, 0, 8664 NULL, NULL, NULL); 8665 if (cookie.locsyms == NULL) 8666 return FALSE; 8667 } 8668 8669 if (stab != NULL) 8670 { 8671 cookie.rels = NULL; 8672 count = stab->reloc_count; 8673 if (count != 0) 8674 cookie.rels = (NAME(_bfd_elf,link_read_relocs) 8675 (abfd, stab, (PTR) NULL, (Elf_Internal_Rela *) NULL, 8676 info->keep_memory)); 8677 if (cookie.rels != NULL) 8678 { 8679 cookie.rel = cookie.rels; 8680 cookie.relend = cookie.rels; 8681 cookie.relend += count * bed->s->int_rels_per_ext_rel; 8682 if (_bfd_discard_section_stabs (abfd, stab, 8683 elf_section_data (stab)->sec_info, 8684 elf_reloc_symbol_deleted_p, 8685 &cookie)) 8686 ret = TRUE; 8687 if (elf_section_data (stab)->relocs != cookie.rels) 8688 free (cookie.rels); 8689 } 8690 } 8691 8692 if (eh != NULL) 8693 { 8694 cookie.rels = NULL; 8695 count = eh->reloc_count; 8696 if (count != 0) 8697 cookie.rels = (NAME(_bfd_elf,link_read_relocs) 8698 (abfd, eh, (PTR) NULL, (Elf_Internal_Rela *) NULL, 8699 info->keep_memory)); 8700 cookie.rel = cookie.rels; 8701 cookie.relend = cookie.rels; 8702 if (cookie.rels != NULL) 8703 cookie.relend += count * bed->s->int_rels_per_ext_rel; 8704 8705 if (_bfd_elf_discard_section_eh_frame (abfd, info, eh, 8706 elf_reloc_symbol_deleted_p, 8707 &cookie)) 8708 ret = TRUE; 8709 8710 if (cookie.rels != NULL 8711 && elf_section_data (eh)->relocs != cookie.rels) 8712 free (cookie.rels); 8713 } 8714 8715 if (bed->elf_backend_discard_info != NULL 8716 && (*bed->elf_backend_discard_info) (abfd, &cookie, info)) 8717 ret = TRUE; 8718 8719 if (cookie.locsyms != NULL 8720 && symtab_hdr->contents != (unsigned char *) cookie.locsyms) 8721 { 8722 if (! info->keep_memory) 8723 free (cookie.locsyms); 8724 else 8725 symtab_hdr->contents = (unsigned char *) cookie.locsyms; 8726 } 8727 } 8728 8729 if (info->eh_frame_hdr 8730 && !info->relocateable 8731 && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info)) 8732 ret = TRUE; 8733 8734 return ret; 8735 } 8736 8737 static bfd_boolean 8738 elf_section_ignore_discarded_relocs (sec) 8739 asection *sec; 8740 { 8741 struct elf_backend_data *bed; 8742 8743 switch (sec->sec_info_type) 8744 { 8745 case ELF_INFO_TYPE_STABS: 8746 case ELF_INFO_TYPE_EH_FRAME: 8747 return TRUE; 8748 default: 8749 break; 8750 } 8751 8752 bed = get_elf_backend_data (sec->owner); 8753 if (bed->elf_backend_ignore_discarded_relocs != NULL 8754 && (*bed->elf_backend_ignore_discarded_relocs) (sec)) 8755 return TRUE; 8756 8757 return FALSE; 8758 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.