Changeset 609 for branches/GNU/src/binutils/bfd/elflink.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elflink.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* ELF linking support for BFD. 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 … … 26 26 #include "elf-bfd.h" 27 27 28 b oolean28 bfd_boolean 29 29 _bfd_elf_create_got_section (abfd, info) 30 30 bfd *abfd; … … 32 32 { 33 33 flagword flags; 34 registerasection *s;34 asection *s; 35 35 struct elf_link_hash_entry *h; 36 struct bfd_link_hash_entry *bh; 36 37 struct elf_backend_data *bed = get_elf_backend_data (abfd); 37 38 int ptralign; 38 39 39 40 /* This function may be called more than once. */ 40 if (bfd_get_section_by_name (abfd, ".got") != NULL) 41 return true; 41 s = bfd_get_section_by_name (abfd, ".got"); 42 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0) 43 return TRUE; 42 44 43 45 switch (bed->s->arch_size) … … 53 55 default: 54 56 bfd_set_error (bfd_error_bad_value); 55 return false;57 return FALSE; 56 58 } 57 59 … … 63 65 || !bfd_set_section_flags (abfd, s, flags) 64 66 || !bfd_set_section_alignment (abfd, s, ptralign)) 65 return false;67 return FALSE; 66 68 67 69 if (bed->want_got_plt) … … 71 73 || !bfd_set_section_flags (abfd, s, flags) 72 74 || !bfd_set_section_alignment (abfd, s, ptralign)) 73 return false; 74 } 75 76 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got 77 (or .got.plt) section. We don't do this in the linker script 78 because we don't want to define the symbol if we are not creating 79 a global offset table. */ 80 h = NULL; 81 if (!(_bfd_generic_link_add_one_symbol 82 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, 83 bed->got_symbol_offset, (const char *) NULL, false, 84 bed->collect, (struct bfd_link_hash_entry **) &h))) 85 return false; 86 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 87 h->type = STT_OBJECT; 88 89 if (info->shared 90 && ! _bfd_elf_link_record_dynamic_symbol (info, h)) 91 return false; 92 93 elf_hash_table (info)->hgot = h; 75 return FALSE; 76 } 77 78 if (bed->want_got_sym) 79 { 80 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got 81 (or .got.plt) section. We don't do this in the linker script 82 because we don't want to define the symbol if we are not creating 83 a global offset table. */ 84 bh = NULL; 85 if (!(_bfd_generic_link_add_one_symbol 86 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, 87 bed->got_symbol_offset, (const char *) NULL, FALSE, 88 bed->collect, &bh))) 89 return FALSE; 90 h = (struct elf_link_hash_entry *) bh; 91 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 92 h->type = STT_OBJECT; 93 94 if (info->shared 95 && ! _bfd_elf_link_record_dynamic_symbol (info, h)) 96 return FALSE; 97 98 elf_hash_table (info)->hgot = h; 99 } 94 100 95 101 /* The first bit of the global offset table is the header. */ 96 102 s->_raw_size += bed->got_header_size + bed->got_symbol_offset; 97 103 98 return true;104 return TRUE; 99 105 } 100 106 … … 102 108 /* Create dynamic sections when linking against a dynamic object. */ 103 109 104 b oolean110 bfd_boolean 105 111 _bfd_elf_create_dynamic_sections (abfd, info) 106 112 bfd *abfd; … … 108 114 { 109 115 flagword flags, pltflags; 110 registerasection *s;116 asection *s; 111 117 struct elf_backend_data *bed = get_elf_backend_data (abfd); 112 118 int ptralign; … … 124 130 default: 125 131 bfd_set_error (bfd_error_bad_value); 126 return false;132 return FALSE; 127 133 } 128 134 … … 136 142 pltflags |= SEC_CODE; 137 143 if (bed->plt_not_loaded) 138 pltflags &= ~ (SEC_ LOAD | SEC_HAS_CONTENTS);144 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); 139 145 if (bed->plt_readonly) 140 146 pltflags |= SEC_READONLY; … … 144 150 || ! bfd_set_section_flags (abfd, s, pltflags) 145 151 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) 146 return false;152 return FALSE; 147 153 148 154 if (bed->want_plt_sym) … … 150 156 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the 151 157 .plt section. */ 152 struct elf_link_hash_entry *h = NULL; 158 struct elf_link_hash_entry *h; 159 struct bfd_link_hash_entry *bh = NULL; 160 153 161 if (! (_bfd_generic_link_add_one_symbol 154 162 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 155 (bfd_vma) 0, (const char *) NULL, false,156 get_elf_backend_data (abfd)->collect, 157 (struct bfd_link_hash_entry **) &h)))158 return false;163 (bfd_vma) 0, (const char *) NULL, FALSE, 164 get_elf_backend_data (abfd)->collect, &bh))) 165 return FALSE; 166 h = (struct elf_link_hash_entry *) bh; 159 167 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 160 168 h->type = STT_OBJECT; … … 162 170 if (info->shared 163 171 && ! _bfd_elf_link_record_dynamic_symbol (info, h)) 164 return false;172 return FALSE; 165 173 } 166 174 … … 170 178 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 171 179 || ! bfd_set_section_alignment (abfd, s, ptralign)) 172 return false;180 return FALSE; 173 181 174 182 if (! _bfd_elf_create_got_section (abfd, info)) 175 return false;183 return FALSE; 176 184 177 185 if (bed->want_dynbss) … … 186 194 if (s == NULL 187 195 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) 188 return false;196 return FALSE; 189 197 190 198 /* The .rel[a].bss section holds copy relocs. This section is not … … 207 215 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 208 216 || ! bfd_set_section_alignment (abfd, s, ptralign)) 209 return false;210 } 211 } 212 213 return true;217 return FALSE; 218 } 219 } 220 221 return TRUE; 214 222 } 215 223 … … 223 231 one. */ 224 232 225 b oolean233 bfd_boolean 226 234 _bfd_elf_link_record_dynamic_symbol (info, h) 227 235 struct bfd_link_info *info; … … 230 238 if (h->dynindx == -1) 231 239 { 232 struct bfd_strtab_hash *dynstr;240 struct elf_strtab_hash *dynstr; 233 241 char *p, *alc; 234 242 const char *name; 235 b oolean copy;243 bfd_boolean copy; 236 244 bfd_size_type indx; 237 245 … … 248 256 { 249 257 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 250 return true;258 return TRUE; 251 259 } 252 260 … … 262 270 { 263 271 /* Create a strtab to hold the dynamic symbol names. */ 264 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_str ingtab_init ();272 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init (); 265 273 if (dynstr == NULL) 266 return false;274 return FALSE; 267 275 } 268 276 269 277 /* We don't put any version information in the dynamic string 270 278 table. */ 271 279 name = h->root.root.string; 272 280 p = strchr (name, ELF_VER_CHR); … … 274 282 { 275 283 alc = NULL; 276 copy = false;284 copy = FALSE; 277 285 } 278 286 else 279 287 { 280 alc = bfd_malloc (p - name + 1); 288 size_t len = p - name + 1; 289 290 alc = bfd_malloc ((bfd_size_type) len); 281 291 if (alc == NULL) 282 return false;283 strncpy (alc, name, p - name);284 alc[ p - name] = '\0';292 return FALSE; 293 memcpy (alc, name, len - 1); 294 alc[len - 1] = '\0'; 285 295 name = alc; 286 copy = true;287 } 288 289 indx = _bfd_ stringtab_add (dynstr, name, true, copy);296 copy = TRUE; 297 } 298 299 indx = _bfd_elf_strtab_add (dynstr, name, copy); 290 300 291 301 if (alc != NULL) … … 293 303 294 304 if (indx == (bfd_size_type) -1) 295 return false;305 return FALSE; 296 306 h->dynstr_index = indx; 297 307 } 298 308 299 return true; 309 return TRUE; 310 } 311 312 /* Record a new local dynamic symbol. Returns 0 on failure, 1 on 313 success, and 2 on a failure caused by attempting to record a symbol 314 in a discarded section, eg. a discarded link-once section symbol. */ 315 316 int 317 elf_link_record_local_dynamic_symbol (info, input_bfd, input_indx) 318 struct bfd_link_info *info; 319 bfd *input_bfd; 320 long input_indx; 321 { 322 bfd_size_type amt; 323 struct elf_link_local_dynamic_entry *entry; 324 struct elf_link_hash_table *eht; 325 struct elf_strtab_hash *dynstr; 326 unsigned long dynstr_index; 327 char *name; 328 Elf_External_Sym_Shndx eshndx; 329 char esym[sizeof (Elf64_External_Sym)]; 330 331 if (! is_elf_hash_table (info)) 332 return 0; 333 334 /* See if the entry exists already. */ 335 for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next) 336 if (entry->input_bfd == input_bfd && entry->input_indx == input_indx) 337 return 1; 338 339 amt = sizeof (*entry); 340 entry = (struct elf_link_local_dynamic_entry *) bfd_alloc (input_bfd, amt); 341 if (entry == NULL) 342 return 0; 343 344 /* Go find the symbol, so that we can find it's name. */ 345 if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr, 346 (size_t) 1, (size_t) input_indx, 347 &entry->isym, esym, &eshndx)) 348 { 349 bfd_release (input_bfd, entry); 350 return 0; 351 } 352 353 if (entry->isym.st_shndx != SHN_UNDEF 354 && (entry->isym.st_shndx < SHN_LORESERVE 355 || entry->isym.st_shndx > SHN_HIRESERVE)) 356 { 357 asection *s; 358 359 s = bfd_section_from_elf_index (input_bfd, entry->isym.st_shndx); 360 if (s == NULL || bfd_is_abs_section (s->output_section)) 361 { 362 /* We can still bfd_release here as nothing has done another 363 bfd_alloc. We can't do this later in this function. */ 364 bfd_release (input_bfd, entry); 365 return 2; 366 } 367 } 368 369 name = (bfd_elf_string_from_elf_section 370 (input_bfd, elf_tdata (input_bfd)->symtab_hdr.sh_link, 371 entry->isym.st_name)); 372 373 dynstr = elf_hash_table (info)->dynstr; 374 if (dynstr == NULL) 375 { 376 /* Create a strtab to hold the dynamic symbol names. */ 377 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init (); 378 if (dynstr == NULL) 379 return 0; 380 } 381 382 dynstr_index = _bfd_elf_strtab_add (dynstr, name, FALSE); 383 if (dynstr_index == (unsigned long) -1) 384 return 0; 385 entry->isym.st_name = dynstr_index; 386 387 eht = elf_hash_table (info); 388 389 entry->next = eht->dynlocal; 390 eht->dynlocal = entry; 391 entry->input_bfd = input_bfd; 392 entry->input_indx = input_indx; 393 eht->dynsymcount++; 394 395 /* Whatever binding the symbol had before, it's now local. */ 396 entry->isym.st_info 397 = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info)); 398 399 /* The dynindx will be set at the end of size_dynamic_sections. */ 400 401 return 1; 300 402 } 301 403 … … 320 422 via elf_link_hash_traverse. */ 321 423 322 static b oolean elf_link_renumber_hash_table_dynsyms424 static bfd_boolean elf_link_renumber_hash_table_dynsyms 323 425 PARAMS ((struct elf_link_hash_entry *, PTR)); 324 426 325 static b oolean427 static bfd_boolean 326 428 elf_link_renumber_hash_table_dynsyms (h, data) 327 429 struct elf_link_hash_entry *h; … … 330 432 size_t *count = (size_t *) data; 331 433 434 if (h->root.type == bfd_link_hash_warning) 435 h = (struct elf_link_hash_entry *) h->root.u.i.link; 436 332 437 if (h->dynindx != -1) 333 438 h->dynindx = ++(*count); 334 439 335 return true;440 return TRUE; 336 441 } 337 442 … … 352 457 asection *p; 353 458 for (p = output_bfd->sections; p ; p = p->next) 354 elf_section_data (p)->dynindx = ++dynsymcount; 459 if ((p->flags & SEC_EXCLUDE) == 0) 460 elf_section_data (p)->dynindx = ++dynsymcount; 355 461 } 356 462 … … 398 504 { 399 505 asection *s; 400 401 lsect = (elf_linker_section_t *) 402 bfd_alloc (dynobj, sizeof (elf_linker_section_t));506 bfd_size_type amt = sizeof (elf_linker_section_t); 507 508 lsect = (elf_linker_section_t *) bfd_alloc (dynobj, amt); 403 509 404 510 *lsect = *defaults; 405 511 elf_linker_section (dynobj, which) = lsect; 406 512 lsect->which = which; 407 lsect->hole_written_p = false;513 lsect->hole_written_p = FALSE; 408 514 409 515 /* See if the sections already exist */ … … 424 530 s->_raw_size = align_power (s->_raw_size, lsect->alignment); 425 531 426 /* Is there a hole we have to provide? If so check whether the segment is427 too big already */532 /* Is there a hole we have to provide? If so check whether the 533 segment is too big already */ 428 534 if (lsect->hole_size) 429 535 { … … 432 538 if (lsect->hole_offset > lsect->max_hole_offset) 433 539 { 434 (*_bfd_error_handler) (_("%s: Section %s is already to large to put hole of %ld bytes in"), 435 bfd_get_filename (abfd), 436 lsect->name, 437 (long)lsect->hole_size); 540 (*_bfd_error_handler) 541 (_("%s: Section %s is too large to add hole of %ld bytes"), 542 bfd_get_filename (abfd), 543 lsect->name, 544 (long) lsect->hole_size); 438 545 439 546 bfd_set_error (bfd_error_bad_value); … … 449 556 if (lsect->sym_name) 450 557 { 451 struct elf_link_hash_entry *h = NULL; 558 struct elf_link_hash_entry *h; 559 struct bfd_link_hash_entry *bh; 560 452 561 #ifdef DEBUG 453 562 fprintf (stderr, "Adding %s to section %s\n", … … 455 564 lsect->name); 456 565 #endif 457 h = (struct elf_link_hash_entry *) 458 bfd_link_hash_lookup (info->hash, lsect->sym_name, false, false, false); 459 460 if ((h == NULL || h->root.type == bfd_link_hash_undefined) 461 && !(_bfd_generic_link_add_one_symbol (info, 462 abfd, 463 lsect->sym_name, 464 BSF_GLOBAL, 465 s, 466 ((lsect->hole_size) 467 ? s->_raw_size - lsect->hole_size + lsect->sym_offset 468 : lsect->sym_offset), 469 (const char *) NULL, 470 false, 471 get_elf_backend_data (abfd)->collect, 472 (struct bfd_link_hash_entry **) &h))) 473 return (elf_linker_section_t *)0; 566 bh = bfd_link_hash_lookup (info->hash, lsect->sym_name, 567 FALSE, FALSE, FALSE); 568 569 if ((bh == NULL || bh->type == bfd_link_hash_undefined) 570 && !(_bfd_generic_link_add_one_symbol 571 (info, abfd, lsect->sym_name, BSF_GLOBAL, s, 572 (lsect->hole_size 573 ? s->_raw_size - lsect->hole_size + lsect->sym_offset 574 : lsect->sym_offset), 575 (const char *) NULL, FALSE, 576 get_elf_backend_data (abfd)->collect, &bh))) 577 return (elf_linker_section_t *) 0; 578 h = (struct elf_link_hash_entry *) bh; 474 579 475 580 if ((defaults->which != LINKER_SECTION_SDATA) … … 482 587 if (info->shared 483 588 && ! _bfd_elf_link_record_dynamic_symbol (info, h)) 484 return (elf_linker_section_t *) 0;589 return (elf_linker_section_t *) 0; 485 590 } 486 591 } … … 508 613 _bfd_elf_find_pointer_linker_section (linker_pointers, addend, which) 509 614 elf_linker_section_pointers_t *linker_pointers; 510 bfd_ signed_vma addend;615 bfd_vma addend; 511 616 elf_linker_section_enum_t which; 512 617 { … … 523 628 /* Make the .rela section corresponding to the generated linker section. */ 524 629 525 b oolean630 bfd_boolean 526 631 _bfd_elf_make_linker_section_rela (dynobj, lsect, alignment) 527 632 bfd *dynobj; … … 530 635 { 531 636 if (lsect->rel_section) 532 return true;637 return TRUE; 533 638 534 639 lsect->rel_section = bfd_get_section_by_name (dynobj, lsect->rel_name); … … 546 651 | SEC_READONLY)) 547 652 || ! bfd_set_section_alignment (dynobj, lsect->rel_section, alignment)) 548 return false;549 } 550 551 return true;552 } 653 return FALSE; 654 } 655 656 return TRUE; 657 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.