00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "bfd.h"
00026 #include "sysdep.h"
00027 #include "bfdlink.h"
00028 #include "libbfd.h"
00029 #define ARCH_SIZE 0
00030 #include "elf-bfd.h"
00031 #include "safe-ctype.h"
00032 #include "libiberty.h"
00033
00034 #ifdef IPA_LINK
00035 #include "ipa_ld.h"
00036
00037 #define SHN_IPA_TEXT 0xff01
00038 #define SHN_IPA_DATA 0xff02
00039
00040 int ld_set_ndx (bfd *abfd) __attribute__((weak));
00041
00042 int
00043 ld_set_ndx (bfd *abfd)
00044 {
00045 (void) abfd;
00046 return 0;
00047 }
00048 #endif
00049
00050 bfd_boolean
00051 _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
00052 {
00053 flagword flags;
00054 asection *s;
00055 struct elf_link_hash_entry *h;
00056 struct bfd_link_hash_entry *bh;
00057 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
00058 int ptralign;
00059
00060
00061 s = bfd_get_section_by_name (abfd, ".got");
00062 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
00063 return TRUE;
00064
00065 switch (bed->s->arch_size)
00066 {
00067 case 32:
00068 ptralign = 2;
00069 break;
00070
00071 case 64:
00072 ptralign = 3;
00073 break;
00074
00075 default:
00076 bfd_set_error (bfd_error_bad_value);
00077 return FALSE;
00078 }
00079
00080 flags = bed->dynamic_sec_flags;
00081
00082 s = bfd_make_section (abfd, ".got");
00083 if (s == NULL
00084 || !bfd_set_section_flags (abfd, s, flags)
00085 || !bfd_set_section_alignment (abfd, s, ptralign))
00086 return FALSE;
00087
00088 if (bed->want_got_plt)
00089 {
00090 s = bfd_make_section (abfd, ".got.plt");
00091 if (s == NULL
00092 || !bfd_set_section_flags (abfd, s, flags)
00093 || !bfd_set_section_alignment (abfd, s, ptralign))
00094 return FALSE;
00095 }
00096
00097 if (bed->want_got_sym)
00098 {
00099
00100
00101
00102
00103 bh = NULL;
00104 if (!(_bfd_generic_link_add_one_symbol
00105 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
00106 bed->got_symbol_offset, NULL, FALSE, bed->collect, &bh)))
00107 return FALSE;
00108 h = (struct elf_link_hash_entry *) bh;
00109 h->def_regular = 1;
00110 h->type = STT_OBJECT;
00111 h->other = STV_HIDDEN;
00112
00113 if (! info->executable
00114 && ! bfd_elf_link_record_dynamic_symbol (info, h))
00115 return FALSE;
00116
00117 elf_hash_table (info)->hgot = h;
00118 }
00119
00120
00121 s->size += bed->got_header_size + bed->got_symbol_offset;
00122
00123 return TRUE;
00124 }
00125
00126
00127 static bfd_boolean
00128 _bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info)
00129 {
00130 struct elf_link_hash_table *hash_table;
00131
00132 hash_table = elf_hash_table (info);
00133 if (hash_table->dynobj == NULL)
00134 hash_table->dynobj = abfd;
00135
00136 if (hash_table->dynstr == NULL)
00137 {
00138 hash_table->dynstr = _bfd_elf_strtab_init ();
00139 if (hash_table->dynstr == NULL)
00140 return FALSE;
00141 }
00142 return TRUE;
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152 bfd_boolean
00153 _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
00154 {
00155 flagword flags;
00156 register asection *s;
00157 struct elf_link_hash_entry *h;
00158 struct bfd_link_hash_entry *bh;
00159 const struct elf_backend_data *bed;
00160
00161 if (! is_elf_hash_table (info->hash))
00162 return FALSE;
00163
00164 if (elf_hash_table (info)->dynamic_sections_created)
00165 return TRUE;
00166
00167 if (!_bfd_elf_link_create_dynstrtab (abfd, info))
00168 return FALSE;
00169
00170 abfd = elf_hash_table (info)->dynobj;
00171 bed = get_elf_backend_data (abfd);
00172
00173 flags = bed->dynamic_sec_flags;
00174
00175
00176
00177 if (info->executable)
00178 {
00179 s = bfd_make_section (abfd, ".interp");
00180 if (s == NULL
00181 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY))
00182 return FALSE;
00183 }
00184
00185 if (! info->traditional_format)
00186 {
00187 s = bfd_make_section (abfd, ".eh_frame_hdr");
00188 if (s == NULL
00189 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00190 || ! bfd_set_section_alignment (abfd, s, 2))
00191 return FALSE;
00192 elf_hash_table (info)->eh_info.hdr_sec = s;
00193 }
00194
00195
00196
00197 s = bfd_make_section (abfd, ".gnu.version_d");
00198 if (s == NULL
00199 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00200 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00201 return FALSE;
00202
00203 s = bfd_make_section (abfd, ".gnu.version");
00204 if (s == NULL
00205 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00206 || ! bfd_set_section_alignment (abfd, s, 1))
00207 return FALSE;
00208
00209 s = bfd_make_section (abfd, ".gnu.version_r");
00210 if (s == NULL
00211 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00212 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00213 return FALSE;
00214
00215 s = bfd_make_section (abfd, ".dynsym");
00216 if (s == NULL
00217 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00218 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00219 return FALSE;
00220
00221 s = bfd_make_section (abfd, ".dynstr");
00222 if (s == NULL
00223 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY))
00224 return FALSE;
00225
00226 s = bfd_make_section (abfd, ".dynamic");
00227 if (s == NULL
00228 || ! bfd_set_section_flags (abfd, s, flags)
00229 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00230 return FALSE;
00231
00232
00233
00234
00235
00236
00237
00238 h = elf_link_hash_lookup (elf_hash_table (info), "_DYNAMIC",
00239 FALSE, FALSE, FALSE);
00240 if (h != NULL)
00241 {
00242
00243
00244
00245
00246 h->root.type = bfd_link_hash_new;
00247 }
00248 bh = &h->root;
00249 if (! (_bfd_generic_link_add_one_symbol
00250 (info, abfd, "_DYNAMIC", BSF_GLOBAL, s, 0, NULL, FALSE,
00251 get_elf_backend_data (abfd)->collect, &bh)))
00252 return FALSE;
00253 h = (struct elf_link_hash_entry *) bh;
00254 h->def_regular = 1;
00255 h->type = STT_OBJECT;
00256
00257 if (! info->executable
00258 && ! bfd_elf_link_record_dynamic_symbol (info, h))
00259 return FALSE;
00260
00261 s = bfd_make_section (abfd, ".hash");
00262 if (s == NULL
00263 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00264 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00265 return FALSE;
00266 elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry;
00267
00268
00269
00270
00271 if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info))
00272 return FALSE;
00273
00274 elf_hash_table (info)->dynamic_sections_created = TRUE;
00275
00276 return TRUE;
00277 }
00278
00279
00280
00281 bfd_boolean
00282 _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
00283 {
00284 flagword flags, pltflags;
00285 asection *s;
00286 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
00287
00288
00289
00290 flags = bed->dynamic_sec_flags;
00291
00292 pltflags = flags;
00293 if (bed->plt_not_loaded)
00294
00295
00296
00297 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
00298 else
00299 pltflags |= SEC_ALLOC | SEC_CODE | SEC_LOAD;
00300 if (bed->plt_readonly)
00301 pltflags |= SEC_READONLY;
00302
00303 s = bfd_make_section (abfd, ".plt");
00304 if (s == NULL
00305 || ! bfd_set_section_flags (abfd, s, pltflags)
00306 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
00307 return FALSE;
00308
00309 if (bed->want_plt_sym)
00310 {
00311
00312
00313 struct elf_link_hash_entry *h;
00314 struct bfd_link_hash_entry *bh = NULL;
00315
00316 if (! (_bfd_generic_link_add_one_symbol
00317 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL,
00318 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
00319 return FALSE;
00320 h = (struct elf_link_hash_entry *) bh;
00321 h->def_regular = 1;
00322 h->type = STT_OBJECT;
00323
00324 if (! info->executable
00325 && ! bfd_elf_link_record_dynamic_symbol (info, h))
00326 return FALSE;
00327 }
00328
00329 s = bfd_make_section (abfd,
00330 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
00331 if (s == NULL
00332 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00333 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00334 return FALSE;
00335
00336 if (! _bfd_elf_create_got_section (abfd, info))
00337 return FALSE;
00338
00339 if (bed->want_dynbss)
00340 {
00341
00342
00343
00344
00345
00346
00347 s = bfd_make_section (abfd, ".dynbss");
00348 if (s == NULL
00349 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
00350 return FALSE;
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 if (! info->shared)
00364 {
00365 s = bfd_make_section (abfd,
00366 (bed->default_use_rela_p
00367 ? ".rela.bss" : ".rel.bss"));
00368 if (s == NULL
00369 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
00370 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
00371 return FALSE;
00372 }
00373 }
00374
00375 return TRUE;
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 bfd_boolean
00387 bfd_elf_link_record_dynamic_symbol (struct bfd_link_info *info,
00388 struct elf_link_hash_entry *h)
00389 {
00390 if (h->dynindx == -1)
00391 {
00392 struct elf_strtab_hash *dynstr;
00393 char *p;
00394 const char *name;
00395 bfd_size_type indx;
00396
00397
00398
00399
00400
00401 switch (ELF_ST_VISIBILITY (h->other))
00402 {
00403 case STV_INTERNAL:
00404 case STV_HIDDEN:
00405 if (h->root.type != bfd_link_hash_undefined
00406 && h->root.type != bfd_link_hash_undefweak)
00407 {
00408 h->forced_local = 1;
00409 if (!elf_hash_table (info)->is_relocatable_executable)
00410 return TRUE;
00411 }
00412
00413 default:
00414 break;
00415 }
00416
00417 h->dynindx = elf_hash_table (info)->dynsymcount;
00418 ++elf_hash_table (info)->dynsymcount;
00419
00420 dynstr = elf_hash_table (info)->dynstr;
00421 if (dynstr == NULL)
00422 {
00423
00424 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init ();
00425 if (dynstr == NULL)
00426 return FALSE;
00427 }
00428
00429
00430
00431 name = h->root.root.string;
00432 p = strchr (name, ELF_VER_CHR);
00433 if (p != NULL)
00434
00435
00436
00437
00438
00439 *p = 0;
00440
00441 indx = _bfd_elf_strtab_add (dynstr, name, p != NULL);
00442
00443 if (p != NULL)
00444 *p = ELF_VER_CHR;
00445
00446 if (indx == (bfd_size_type) -1)
00447 return FALSE;
00448 h->dynstr_index = indx;
00449 }
00450
00451 return TRUE;
00452 }
00453
00454
00455
00456
00457 bfd_boolean
00458 bfd_elf_record_link_assignment (bfd *output_bfd ATTRIBUTE_UNUSED,
00459 struct bfd_link_info *info,
00460 const char *name,
00461 bfd_boolean provide)
00462 {
00463 struct elf_link_hash_entry *h;
00464 struct elf_link_hash_table *htab;
00465
00466 if (!is_elf_hash_table (info->hash))
00467 return TRUE;
00468
00469 htab = elf_hash_table (info);
00470 h = elf_link_hash_lookup (htab, name, !provide, TRUE, FALSE);
00471 if (h == NULL)
00472 return provide;
00473
00474
00475
00476
00477 if (h->root.type == bfd_link_hash_undefweak
00478 || h->root.type == bfd_link_hash_undefined)
00479 {
00480 h->root.type = bfd_link_hash_new;
00481 if (h->root.u.undef.next != NULL || htab->root.undefs_tail == &h->root)
00482 bfd_link_repair_undef_list (&htab->root);
00483 }
00484
00485 if (h->root.type == bfd_link_hash_new)
00486 h->non_elf = 0;
00487
00488
00489
00490
00491
00492 if (provide
00493 && h->def_dynamic
00494 && !h->def_regular)
00495 h->root.type = bfd_link_hash_undefined;
00496
00497
00498
00499
00500
00501 if (!provide
00502 && h->def_dynamic
00503 && !h->def_regular)
00504 h->verinfo.verdef = NULL;
00505
00506 h->def_regular = 1;
00507
00508
00509
00510 if (!info->relocatable
00511 && h->dynindx != -1
00512 && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
00513 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
00514 h->forced_local = 1;
00515
00516 if ((h->def_dynamic
00517 || h->ref_dynamic
00518 || info->shared
00519 || (info->executable && elf_hash_table (info)->is_relocatable_executable))
00520 && h->dynindx == -1)
00521 {
00522 if (! bfd_elf_link_record_dynamic_symbol (info, h))
00523 return FALSE;
00524
00525
00526
00527
00528 if (h->u.weakdef != NULL
00529 && h->u.weakdef->dynindx == -1)
00530 {
00531 if (! bfd_elf_link_record_dynamic_symbol (info, h->u.weakdef))
00532 return FALSE;
00533 }
00534 }
00535
00536 return TRUE;
00537 }
00538
00539
00540
00541
00542
00543 int
00544 bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
00545 bfd *input_bfd,
00546 long input_indx)
00547 {
00548 bfd_size_type amt;
00549 struct elf_link_local_dynamic_entry *entry;
00550 struct elf_link_hash_table *eht;
00551 struct elf_strtab_hash *dynstr;
00552 unsigned long dynstr_index;
00553 char *name;
00554 Elf_External_Sym_Shndx eshndx;
00555 char esym[sizeof (Elf64_External_Sym)];
00556
00557 if (! is_elf_hash_table (info->hash))
00558 return 0;
00559
00560
00561 for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next)
00562 if (entry->input_bfd == input_bfd && entry->input_indx == input_indx)
00563 return 1;
00564
00565 amt = sizeof (*entry);
00566 entry = bfd_alloc (input_bfd, amt);
00567 if (entry == NULL)
00568 return 0;
00569
00570
00571 if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
00572 1, input_indx, &entry->isym, esym, &eshndx))
00573 {
00574 bfd_release (input_bfd, entry);
00575 return 0;
00576 }
00577
00578 if (entry->isym.st_shndx != SHN_UNDEF
00579 && (entry->isym.st_shndx < SHN_LORESERVE
00580 || entry->isym.st_shndx > SHN_HIRESERVE))
00581 {
00582 asection *s;
00583
00584 s = bfd_section_from_elf_index (input_bfd, entry->isym.st_shndx);
00585 if (s == NULL || bfd_is_abs_section (s->output_section))
00586 {
00587
00588
00589 bfd_release (input_bfd, entry);
00590 return 2;
00591 }
00592 }
00593
00594 name = (bfd_elf_string_from_elf_section
00595 (input_bfd, elf_tdata (input_bfd)->symtab_hdr.sh_link,
00596 entry->isym.st_name));
00597
00598 dynstr = elf_hash_table (info)->dynstr;
00599 if (dynstr == NULL)
00600 {
00601
00602 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init ();
00603 if (dynstr == NULL)
00604 return 0;
00605 }
00606
00607 dynstr_index = _bfd_elf_strtab_add (dynstr, name, FALSE);
00608 if (dynstr_index == (unsigned long) -1)
00609 return 0;
00610 entry->isym.st_name = dynstr_index;
00611
00612 eht = elf_hash_table (info);
00613
00614 entry->next = eht->dynlocal;
00615 eht->dynlocal = entry;
00616 entry->input_bfd = input_bfd;
00617 entry->input_indx = input_indx;
00618 eht->dynsymcount++;
00619
00620
00621 entry->isym.st_info
00622 = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info));
00623
00624
00625
00626 return 1;
00627 }
00628
00629
00630
00631 long
00632 _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info *info,
00633 bfd *input_bfd,
00634 long input_indx)
00635 {
00636 struct elf_link_local_dynamic_entry *e;
00637
00638 for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
00639 if (e->input_bfd == input_bfd && e->input_indx == input_indx)
00640 return e->dynindx;
00641 return -1;
00642 }
00643
00644
00645
00646
00647
00648 static bfd_boolean
00649 elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry *h,
00650 void *data)
00651 {
00652 size_t *count = data;
00653
00654 if (h->root.type == bfd_link_hash_warning)
00655 h = (struct elf_link_hash_entry *) h->root.u.i.link;
00656
00657 if (h->forced_local)
00658 return TRUE;
00659
00660 if (h->dynindx != -1)
00661 h->dynindx = ++(*count);
00662
00663 return TRUE;
00664 }
00665
00666
00667
00668
00669
00670 static bfd_boolean
00671 elf_link_renumber_local_hash_table_dynsyms (struct elf_link_hash_entry *h,
00672 void *data)
00673 {
00674 size_t *count = data;
00675
00676 if (h->root.type == bfd_link_hash_warning)
00677 h = (struct elf_link_hash_entry *) h->root.u.i.link;
00678
00679 if (!h->forced_local)
00680 return TRUE;
00681
00682 if (h->dynindx != -1)
00683 h->dynindx = ++(*count);
00684
00685 return TRUE;
00686 }
00687
00688
00689
00690 bfd_boolean
00691 _bfd_elf_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
00692 struct bfd_link_info *info,
00693 asection *p)
00694 {
00695 switch (elf_section_data (p)->this_hdr.sh_type)
00696 {
00697 case SHT_PROGBITS:
00698 case SHT_NOBITS:
00699
00700
00701 case SHT_NULL:
00702 if (strcmp (p->name, ".got") == 0
00703 || strcmp (p->name, ".got.plt") == 0
00704 || strcmp (p->name, ".plt") == 0)
00705 {
00706 asection *ip;
00707 bfd *dynobj = elf_hash_table (info)->dynobj;
00708
00709 if (dynobj != NULL
00710 && (ip = bfd_get_section_by_name (dynobj, p->name)) != NULL
00711 && (ip->flags & SEC_LINKER_CREATED)
00712 && ip->output_section == p)
00713 return TRUE;
00714 }
00715 return FALSE;
00716
00717
00718
00719 default:
00720 return TRUE;
00721 }
00722 }
00723
00724
00725
00726
00727
00728
00729
00730 unsigned long
00731 _bfd_elf_link_renumber_dynsyms (bfd *output_bfd, struct bfd_link_info *info)
00732 {
00733 unsigned long dynsymcount = 0;
00734
00735 if (info->shared || elf_hash_table (info)->is_relocatable_executable)
00736 {
00737 const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
00738 asection *p;
00739 for (p = output_bfd->sections; p ; p = p->next)
00740 if ((p->flags & SEC_EXCLUDE) == 0
00741 && (p->flags & SEC_ALLOC) != 0
00742 && !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p))
00743 elf_section_data (p)->dynindx = ++dynsymcount;
00744 }
00745
00746 elf_link_hash_traverse (elf_hash_table (info),
00747 elf_link_renumber_local_hash_table_dynsyms,
00748 &dynsymcount);
00749
00750 if (elf_hash_table (info)->dynlocal)
00751 {
00752 struct elf_link_local_dynamic_entry *p;
00753 for (p = elf_hash_table (info)->dynlocal; p ; p = p->next)
00754 p->dynindx = ++dynsymcount;
00755 }
00756
00757 elf_link_hash_traverse (elf_hash_table (info),
00758 elf_link_renumber_hash_table_dynsyms,
00759 &dynsymcount);
00760
00761
00762
00763
00764 if (dynsymcount != 0)
00765 ++dynsymcount;
00766
00767 return elf_hash_table (info)->dynsymcount = dynsymcount;
00768 }
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782 bfd_boolean
00783 _bfd_elf_merge_symbol (bfd *abfd,
00784 struct bfd_link_info *info,
00785 const char *name,
00786 Elf_Internal_Sym *sym,
00787 asection **psec,
00788 bfd_vma *pvalue,
00789 unsigned int *pold_alignment,
00790 struct elf_link_hash_entry **sym_hash,
00791 bfd_boolean *skip,
00792 bfd_boolean *override,
00793 bfd_boolean *type_change_ok,
00794 bfd_boolean *size_change_ok)
00795 {
00796 asection *sec, *oldsec;
00797 struct elf_link_hash_entry *h;
00798 struct elf_link_hash_entry *flip;
00799 int bind;
00800 bfd *oldbfd;
00801 bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
00802 bfd_boolean newweak, oldweak;
00803
00804 *skip = FALSE;
00805 *override = FALSE;
00806
00807 sec = *psec;
00808 bind = ELF_ST_BIND (sym->st_info);
00809
00810 if (! bfd_is_und_section (sec))
00811 h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, FALSE, FALSE);
00812 else
00813 h = ((struct elf_link_hash_entry *)
00814 bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, FALSE, FALSE));
00815 if (h == NULL)
00816 return FALSE;
00817 *sym_hash = h;
00818
00819
00820
00821 if (info->hash->creator != abfd->xvec)
00822 return TRUE;
00823
00824
00825
00826 while (h->root.type == bfd_link_hash_indirect
00827 || h->root.type == bfd_link_hash_warning)
00828 h = (struct elf_link_hash_entry *) h->root.u.i.link;
00829
00830
00831
00832
00833
00834 if (h->root.type == bfd_link_hash_new)
00835 {
00836 #ifdef IPA_LINK
00837 extern int ld_set_ndx(bfd *);
00838
00839 h->ipa_indx = ld_set_ndx (abfd);
00840 #endif
00841 h->non_elf = 0;
00842 return TRUE;
00843 }
00844
00845
00846
00847
00848 switch (h->root.type)
00849 {
00850 default:
00851 oldbfd = NULL;
00852 oldsec = NULL;
00853 break;
00854
00855 case bfd_link_hash_undefined:
00856 case bfd_link_hash_undefweak:
00857 oldbfd = h->root.u.undef.abfd;
00858 oldsec = NULL;
00859 break;
00860
00861 case bfd_link_hash_defined:
00862 case bfd_link_hash_defweak:
00863 oldbfd = h->root.u.def.section->owner;
00864 oldsec = h->root.u.def.section;
00865 break;
00866
00867 case bfd_link_hash_common:
00868 oldbfd = h->root.u.c.p->section->owner;
00869 oldsec = h->root.u.c.p->section;
00870 break;
00871 }
00872
00873
00874
00875
00876
00877
00878
00879 #ifdef KEY
00880
00881 if (! h->root.u.def.section_is_invalid)
00882 #endif
00883 if (abfd == oldbfd
00884 && ((abfd->flags & DYNAMIC) == 0
00885 || !h->def_regular))
00886 return TRUE;
00887
00888
00889
00890
00891 if ((abfd->flags & DYNAMIC) != 0)
00892 newdyn = TRUE;
00893 else
00894 newdyn = FALSE;
00895
00896 if (oldbfd != NULL)
00897 olddyn = (oldbfd->flags & DYNAMIC) != 0;
00898 else
00899 {
00900 asection *hsec;
00901
00902
00903
00904 switch (h->root.type)
00905 {
00906 default:
00907 hsec = NULL;
00908 break;
00909
00910 case bfd_link_hash_defined:
00911 case bfd_link_hash_defweak:
00912 #ifdef KEY
00913 hsec = NULL;
00914 if (! h->root.u.def.section_is_invalid)
00915 #endif
00916 hsec = h->root.u.def.section;
00917 break;
00918
00919 case bfd_link_hash_common:
00920 hsec = h->root.u.c.p->section;
00921 break;
00922 }
00923
00924 if (hsec == NULL)
00925 olddyn = FALSE;
00926 else
00927 olddyn = (hsec->symbol->flags & BSF_DYNAMIC) != 0;
00928 }
00929
00930
00931
00932
00933 if (bfd_is_und_section (sec) || bfd_is_com_section (sec))
00934 newdef = FALSE;
00935 else
00936 newdef = TRUE;
00937
00938 if (h->root.type == bfd_link_hash_undefined
00939 || h->root.type == bfd_link_hash_undefweak
00940 || h->root.type == bfd_link_hash_common)
00941 olddef = FALSE;
00942 else
00943 olddef = TRUE;
00944
00945
00946 if ((ELF_ST_TYPE (sym->st_info) == STT_TLS || h->type == STT_TLS)
00947 && ELF_ST_TYPE (sym->st_info) != h->type)
00948 {
00949 bfd *ntbfd, *tbfd;
00950 bfd_boolean ntdef, tdef;
00951 asection *ntsec, *tsec;
00952
00953 if (h->type == STT_TLS)
00954 {
00955 ntbfd = abfd;
00956 ntsec = sec;
00957 ntdef = newdef;
00958 tbfd = oldbfd;
00959 tsec = oldsec;
00960 tdef = olddef;
00961 }
00962 else
00963 {
00964 ntbfd = oldbfd;
00965 ntsec = oldsec;
00966 ntdef = olddef;
00967 tbfd = abfd;
00968 tsec = sec;
00969 tdef = newdef;
00970 }
00971
00972 if (tdef && ntdef)
00973 (*_bfd_error_handler)
00974 (_("%s: TLS definition in %B section %A mismatches non-TLS definition in %B section %A"),
00975 tbfd, tsec, ntbfd, ntsec, h->root.root.string);
00976 else if (!tdef && !ntdef)
00977 (*_bfd_error_handler)
00978 (_("%s: TLS reference in %B mismatches non-TLS reference in %B"),
00979 tbfd, ntbfd, h->root.root.string);
00980 else if (tdef)
00981 (*_bfd_error_handler)
00982 (_("%s: TLS definition in %B section %A mismatches non-TLS reference in %B"),
00983 tbfd, tsec, ntbfd, h->root.root.string);
00984 else
00985 (*_bfd_error_handler)
00986 (_("%s: TLS reference in %B mismatches non-TLS definition in %B section %A"),
00987 tbfd, ntbfd, ntsec, h->root.root.string);
00988
00989 bfd_set_error (bfd_error_bad_value);
00990 return FALSE;
00991 }
00992
00993
00994
00995
00996 if (newdyn && !h->dynamic_def)
00997 {
00998 if (!bfd_is_und_section (sec))
00999 h->dynamic_def = 1;
01000 else
01001 {
01002
01003
01004
01005 if (!h->ref_dynamic)
01006 {
01007 if (bind == STB_WEAK)
01008 h->dynamic_weak = 1;
01009 }
01010 else if (bind != STB_WEAK)
01011 h->dynamic_weak = 0;
01012 }
01013 }
01014
01015
01016
01017 if (newdyn
01018 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
01019 && !bfd_is_und_section (sec))
01020 {
01021 *skip = TRUE;
01022
01023 h->ref_dynamic = 1;
01024
01025
01026
01027
01028 if (ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
01029 return bfd_elf_link_record_dynamic_symbol (info, h);
01030 else
01031 return TRUE;
01032 }
01033 else if (!newdyn
01034 && ELF_ST_VISIBILITY (sym->st_other) != STV_DEFAULT
01035 && h->def_dynamic)
01036 {
01037
01038
01039
01040 if ((*sym_hash)->root.type == bfd_link_hash_indirect)
01041 h = *sym_hash;
01042
01043 if ((h->root.u.undef.next || info->hash->undefs_tail == &h->root)
01044 && bfd_is_und_section (sec))
01045 {
01046
01047
01048
01049
01050
01051
01052 h->root.type = bfd_link_hash_undefined;
01053 h->root.u.undef.abfd = abfd;
01054 }
01055 else
01056 {
01057 h->root.type = bfd_link_hash_new;
01058 h->root.u.undef.abfd = NULL;
01059 }
01060
01061 if (h->def_dynamic)
01062 {
01063 h->def_dynamic = 0;
01064 h->ref_dynamic = 1;
01065 h->dynamic_def = 1;
01066 }
01067
01068 h->size = 0;
01069 h->type = 0;
01070 return TRUE;
01071 }
01072
01073
01074 newweak = bind == STB_WEAK;
01075 oldweak = (h->root.type == bfd_link_hash_defweak
01076 || h->root.type == bfd_link_hash_undefweak);
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089 if (newdef && !newdyn && olddyn)
01090 newweak = FALSE;
01091 if (olddef && newdyn)
01092 oldweak = FALSE;
01093
01094
01095
01096
01097
01098 if (oldweak
01099 || newweak
01100 || (newdef
01101 && h->root.type == bfd_link_hash_undefined))
01102 *type_change_ok = TRUE;
01103
01104
01105
01106
01107 if (*type_change_ok
01108 || h->root.type == bfd_link_hash_undefined)
01109 *size_change_ok = TRUE;
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134 if (newdyn
01135 && newdef
01136 && !newweak
01137 && (sec->flags & SEC_ALLOC) != 0
01138 && (sec->flags & SEC_LOAD) == 0
01139 && sym->st_size > 0
01140 && ELF_ST_TYPE (sym->st_info) != STT_FUNC)
01141 newdyncommon = TRUE;
01142 else
01143 newdyncommon = FALSE;
01144
01145 if (olddyn
01146 && olddef
01147 && h->root.type == bfd_link_hash_defined
01148 && h->def_dynamic
01149 && (h->root.u.def.section->flags & SEC_ALLOC) != 0
01150 && (h->root.u.def.section->flags & SEC_LOAD) == 0
01151 && h->size > 0
01152 && h->type != STT_FUNC)
01153 olddyncommon = TRUE;
01154 else
01155 olddyncommon = FALSE;
01156
01157
01158
01159
01160
01161 if (olddyncommon
01162 && newdyncommon
01163 && sym->st_size != h->size)
01164 {
01165
01166
01167
01168
01169
01170
01171 if (! ((*info->callbacks->multiple_common)
01172 (info, h->root.root.string, oldbfd, bfd_link_hash_common,
01173 h->size, abfd, bfd_link_hash_common, sym->st_size)))
01174 return FALSE;
01175
01176 if (sym->st_size > h->size)
01177 h->size = sym->st_size;
01178
01179 *size_change_ok = TRUE;
01180 }
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196 if (newdyn
01197 && newdef
01198 && (olddef
01199 || (h->root.type == bfd_link_hash_common
01200 && (newweak
01201 || ELF_ST_TYPE (sym->st_info) == STT_FUNC))))
01202 {
01203 *override = TRUE;
01204 newdef = FALSE;
01205 newdyncommon = FALSE;
01206
01207 *psec = sec = bfd_und_section_ptr;
01208 *size_change_ok = TRUE;
01209
01210
01211
01212
01213
01214
01215
01216 if (h->root.type == bfd_link_hash_common)
01217 *type_change_ok = TRUE;
01218 }
01219
01220
01221
01222
01223
01224
01225
01226 if (newdyncommon
01227 && h->root.type == bfd_link_hash_common)
01228 {
01229 *override = TRUE;
01230 newdef = FALSE;
01231 newdyncommon = FALSE;
01232 *pvalue = sym->st_size;
01233 *psec = sec = bfd_com_section_ptr;
01234 *size_change_ok = TRUE;
01235 }
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247 flip = NULL;
01248 if (!newdyn
01249 && (newdef
01250 || (bfd_is_com_section (sec)
01251 && (oldweak
01252 || h->type == STT_FUNC)))
01253 && olddyn
01254 && olddef
01255 && h->def_dynamic)
01256 {
01257
01258
01259
01260
01261 h->root.type = bfd_link_hash_undefined;
01262 h->root.u.undef.abfd = h->root.u.def.section->owner;
01263 *size_change_ok = TRUE;
01264
01265 olddef = FALSE;
01266 olddyncommon = FALSE;
01267
01268
01269
01270
01271 if (bfd_is_com_section (sec))
01272 *type_change_ok = TRUE;
01273
01274 if ((*sym_hash)->root.type == bfd_link_hash_indirect)
01275 flip = *sym_hash;
01276 else
01277
01278
01279
01280 h->verinfo.vertree = NULL;
01281 }
01282
01283
01284
01285
01286
01287
01288
01289 if (! newdyn
01290 && bfd_is_com_section (sec)
01291 && olddyncommon)
01292 {
01293
01294
01295
01296 if (! ((*info->callbacks->multiple_common)
01297 (info, h->root.root.string, oldbfd, bfd_link_hash_common,
01298 h->size, abfd, bfd_link_hash_common, sym->st_size)))
01299 return FALSE;
01300
01301
01302
01303
01304 if (h->size > *pvalue)
01305 *pvalue = h->size;
01306
01307
01308
01309 BFD_ASSERT (pold_alignment);
01310 *pold_alignment = h->root.u.def.section->alignment_power;
01311
01312 olddef = FALSE;
01313 olddyncommon = FALSE;
01314
01315 h->root.type = bfd_link_hash_undefined;
01316 h->root.u.undef.abfd = h->root.u.def.section->owner;
01317
01318 *size_change_ok = TRUE;
01319 *type_change_ok = TRUE;
01320
01321 if ((*sym_hash)->root.type == bfd_link_hash_indirect)
01322 flip = *sym_hash;
01323 else
01324 h->verinfo.vertree = NULL;
01325 }
01326
01327 if (flip != NULL)
01328 {
01329
01330
01331
01332 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
01333 flip->root.type = h->root.type;
01334 h->root.type = bfd_link_hash_indirect;
01335 h->root.u.i.link = (struct bfd_link_hash_entry *) flip;
01336 (*bed->elf_backend_copy_indirect_symbol) (bed, flip, h);
01337 flip->root.u.undef.abfd = h->root.u.undef.abfd;
01338 if (h->def_dynamic)
01339 {
01340 h->def_dynamic = 0;
01341 flip->ref_dynamic = 1;
01342 }
01343 }
01344
01345 return TRUE;
01346 }
01347
01348
01349
01350
01351
01352
01353 bfd_boolean
01354 _bfd_elf_add_default_symbol (bfd *abfd,
01355 struct bfd_link_info *info,
01356 struct elf_link_hash_entry *h,
01357 const char *name,
01358 Elf_Internal_Sym *sym,
01359 asection **psec,
01360 bfd_vma *value,
01361 bfd_boolean *dynsym,
01362 bfd_boolean override)
01363 {
01364 bfd_boolean type_change_ok;
01365 bfd_boolean size_change_ok;
01366 bfd_boolean skip;
01367 char *shortname;
01368 struct elf_link_hash_entry *hi;
01369 struct bfd_link_hash_entry *bh;
01370 const struct elf_backend_data *bed;
01371 bfd_boolean collect;
01372 bfd_boolean dynamic;
01373 char *p;
01374 size_t len, shortlen;
01375 asection *sec;
01376
01377
01378
01379
01380
01381 p = strchr (name, ELF_VER_CHR);
01382 if (p == NULL || p[1] != ELF_VER_CHR)
01383 return TRUE;
01384
01385 if (override)
01386 {
01387
01388
01389 hi = elf_link_hash_lookup (elf_hash_table (info), name, TRUE,
01390 FALSE, FALSE);
01391 BFD_ASSERT (hi != NULL);
01392 if (hi == h)
01393 return TRUE;
01394 while (hi->root.type == bfd_link_hash_indirect
01395 || hi->root.type == bfd_link_hash_warning)
01396 {
01397 hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
01398 if (hi == h)
01399 return TRUE;
01400 }
01401 }
01402
01403 bed = get_elf_backend_data (abfd);
01404 collect = bed->collect;
01405 dynamic = (abfd->flags & DYNAMIC) != 0;
01406
01407 shortlen = p - name;
01408 shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1);
01409 if (shortname == NULL)
01410 return FALSE;
01411 memcpy (shortname, name, shortlen);
01412 shortname[shortlen] = '\0';
01413
01414
01415
01416
01417
01418 type_change_ok = FALSE;
01419 size_change_ok = FALSE;
01420 sec = *psec;
01421 if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
01422 NULL, &hi, &skip, &override,
01423 &type_change_ok, &size_change_ok))
01424 return FALSE;
01425
01426 if (skip)
01427 goto nondefault;
01428
01429 if (! override)
01430 {
01431 bh = &hi->root;
01432 if (! (_bfd_generic_link_add_one_symbol
01433 (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr,
01434 0, name, FALSE, collect, &bh)))
01435 return FALSE;
01436 hi = (struct elf_link_hash_entry *) bh;
01437 }
01438 else
01439 {
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458 while (hi->root.type == bfd_link_hash_indirect
01459 || hi->root.type == bfd_link_hash_warning)
01460 hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
01461
01462 h->root.type = bfd_link_hash_indirect;
01463 h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
01464 if (h->def_dynamic)
01465 {
01466 h->def_dynamic = 0;
01467 hi->ref_dynamic = 1;
01468 if (hi->ref_regular
01469 || hi->def_regular)
01470 {
01471 if (! bfd_elf_link_record_dynamic_symbol (info, hi))
01472 return FALSE;
01473 }
01474 }
01475
01476
01477
01478 hi = h;
01479 }
01480
01481
01482
01483
01484
01485 if (hi->root.type == bfd_link_hash_indirect)
01486 {
01487 struct elf_link_hash_entry *ht;
01488
01489 ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
01490 (*bed->elf_backend_copy_indirect_symbol) (bed, ht, hi);
01491
01492
01493
01494 if (! *dynsym)
01495 {
01496 if (! dynamic)
01497 {
01498 if (info->shared
01499 || hi->ref_dynamic)
01500 *dynsym = TRUE;
01501 }
01502 else
01503 {
01504 if (hi->ref_regular)
01505 *dynsym = TRUE;
01506 }
01507 }
01508 }
01509
01510
01511
01512
01513 nondefault:
01514 len = strlen (name);
01515 shortname = bfd_hash_allocate (&info->hash->table, len);
01516 if (shortname == NULL)
01517 return FALSE;
01518 memcpy (shortname, name, shortlen);
01519 memcpy (shortname + shortlen, p + 1, len - shortlen);
01520
01521
01522 type_change_ok = FALSE;
01523 size_change_ok = FALSE;
01524 sec = *psec;
01525 if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
01526 NULL, &hi, &skip, &override,
01527 &type_change_ok, &size_change_ok))
01528 return FALSE;
01529
01530 if (skip)
01531 return TRUE;
01532
01533 if (override)
01534 {
01535
01536
01537
01538 if (hi->root.type != bfd_link_hash_defined
01539 && hi->root.type != bfd_link_hash_defweak)
01540 (*_bfd_error_handler)
01541 (_("%B: unexpected redefinition of indirect versioned symbol `%s'"),
01542 abfd, shortname);
01543 }
01544 else
01545 {
01546 bh = &hi->root;
01547 if (! (_bfd_generic_link_add_one_symbol
01548 (info, abfd, shortname, BSF_INDIRECT,
01549 bfd_ind_section_ptr, 0, name, FALSE, collect, &bh)))
01550 return FALSE;
01551 hi = (struct elf_link_hash_entry *) bh;
01552
01553
01554
01555
01556
01557 if (hi->root.type == bfd_link_hash_indirect)
01558 {
01559 (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi);
01560
01561
01562
01563 if (! *dynsym)
01564 {
01565 if (! dynamic)
01566 {
01567 if (info->shared
01568 || hi->ref_dynamic)
01569 *dynsym = TRUE;
01570 }
01571 else
01572 {
01573 if (hi->ref_regular)
01574 *dynsym = TRUE;
01575 }
01576 }
01577 }
01578 }
01579
01580 return TRUE;
01581 }
01582
01583
01584
01585
01586 bfd_boolean
01587 _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
01588 {
01589 struct elf_info_failed *eif = data;
01590
01591
01592 if (h->root.type == bfd_link_hash_indirect)
01593 return TRUE;
01594
01595 if (h->root.type == bfd_link_hash_warning)
01596 h = (struct elf_link_hash_entry *) h->root.u.i.link;
01597
01598 if (h->dynindx == -1
01599 && (h->def_regular
01600 || h->ref_regular))
01601 {
01602 struct bfd_elf_version_tree *t;
01603 struct bfd_elf_version_expr *d;
01604
01605 for (t = eif->verdefs; t != NULL; t = t->next)
01606 {
01607 if (t->globals.list != NULL)
01608 {
01609 d = (*t->match) (&t->globals, NULL, h->root.root.string);
01610 if (d != NULL)
01611 goto doit;
01612 }
01613
01614 if (t->locals.list != NULL)
01615 {
01616 d = (*t->match) (&t->locals, NULL, h->root.root.string);
01617 if (d != NULL)
01618 return TRUE;
01619 }
01620 }
01621
01622 if (!eif->verdefs)
01623 {
01624 doit:
01625 if (! bfd_elf_link_record_dynamic_symbol (eif->info, h))
01626 {
01627 eif->failed = TRUE;
01628 return FALSE;
01629 }
01630 }
01631 }
01632
01633 return TRUE;
01634 }
01635
01636
01637
01638
01639
01640
01641 bfd_boolean
01642 _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry *h,
01643 void *data)
01644 {
01645 struct elf_find_verdep_info *rinfo = data;
01646 Elf_Internal_Verneed *t;
01647 Elf_Internal_Vernaux *a;
01648 bfd_size_type amt;
01649
01650 if (h->root.type == bfd_link_hash_warning)
01651 h = (struct elf_link_hash_entry *) h->root.u.i.link;
01652
01653
01654
01655 if (!h->def_dynamic
01656 || h->def_regular
01657 || h->dynindx == -1
01658 || h->verinfo.verdef == NULL)
01659 return TRUE;
01660
01661
01662 for (t = elf_tdata (rinfo->output_bfd)->verref; t != NULL; t = t->vn_nextref)
01663 {
01664 if (t->vn_bfd != h->verinfo.verdef->vd_bfd)
01665 continue;
01666
01667 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
01668 if (a->vna_nodename == h->verinfo.verdef->vd_nodename)
01669 return TRUE;
01670
01671 break;
01672 }
01673
01674
01675
01676 if (t == NULL)
01677 {
01678 amt = sizeof *t;
01679 t = bfd_zalloc (rinfo->output_bfd, amt);
01680 if (t == NULL)
01681 {
01682 rinfo->failed = TRUE;
01683 return FALSE;
01684 }
01685
01686 t->vn_bfd = h->verinfo.verdef->vd_bfd;
01687 t->vn_nextref = elf_tdata (rinfo->output_bfd)->verref;
01688 elf_tdata (rinfo->output_bfd)->verref = t;
01689 }
01690
01691 amt = sizeof *a;
01692 a = bfd_zalloc (rinfo->output_bfd, amt);
01693
01694
01695
01696
01697
01698 a->vna_nodename = h->verinfo.verdef->vd_nodename;
01699
01700 a->vna_flags = h->verinfo.verdef->vd_flags;
01701 a->vna_nextptr = t->vn_auxptr;
01702
01703 h->verinfo.verdef->vd_exp_refno = rinfo->vers;
01704 ++rinfo->vers;
01705
01706 a->vna_other = h->verinfo.verdef->vd_exp_refno + 1;
01707
01708 t->vn_auxptr = a;
01709
01710 return TRUE;
01711 }
01712
01713
01714
01715
01716
01717
01718 bfd_boolean
01719 _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data)
01720 {
01721 struct elf_assign_sym_version_info *sinfo;
01722 struct bfd_link_info *info;
01723 const struct elf_backend_data *bed;
01724 struct elf_info_failed eif;
01725 char *p;
01726 bfd_size_type amt;
01727
01728 sinfo = data;
01729 info = sinfo->info;
01730
01731 if (h->root.type == bfd_link_hash_warning)
01732 h = (struct elf_link_hash_entry *) h->root.u.i.link;
01733
01734
01735 eif.failed = FALSE;
01736 eif.info = info;
01737 if (! _bfd_elf_fix_symbol_flags (h, &eif))
01738 {
01739 if (eif.failed)
01740 sinfo->failed = TRUE;
01741 return FALSE;
01742 }
01743
01744
01745
01746 if (!h->def_regular)
01747 return TRUE;
01748
01749 bed = get_elf_backend_data (sinfo->output_bfd);
01750 p = strchr (h->root.root.string, ELF_VER_CHR);
01751 if (p != NULL && h->verinfo.vertree == NULL)
01752 {
01753 struct bfd_elf_version_tree *t;
01754 bfd_boolean hidden;
01755
01756 hidden = TRUE;
01757
01758
01759
01760 ++p;
01761 if (*p == ELF_VER_CHR)
01762 {
01763 hidden = FALSE;
01764 ++p;
01765 }
01766
01767
01768 if (*p == '\0')
01769 {
01770 if (hidden)
01771 h->hidden = 1;
01772 return TRUE;
01773 }
01774
01775
01776 for (t = sinfo->verdefs; t != NULL; t = t->next)
01777 {
01778 if (strcmp (t->name, p) == 0)
01779 {
01780 size_t len;
01781 char *alc;
01782 struct bfd_elf_version_expr *d;
01783
01784 len = p - h->root.root.string;
01785 alc = bfd_malloc (len);
01786 if (alc == NULL)
01787 return FALSE;
01788 memcpy (alc, h->root.root.string, len - 1);
01789 alc[len - 1] = '\0';
01790 if (alc[len - 2] == ELF_VER_CHR)
01791 alc[len - 2] = '\0';
01792
01793 h->verinfo.vertree = t;
01794 t->used = TRUE;
01795 d = NULL;
01796
01797 if (t->globals.list != NULL)
01798 d = (*t->match) (&t->globals, NULL, alc);
01799
01800
01801
01802 if (d == NULL && t->locals.list != NULL)
01803 {
01804 d = (*t->match) (&t->locals, NULL, alc);
01805 if (d != NULL
01806 && h->dynindx != -1
01807 && info->shared
01808 && ! info->export_dynamic)
01809 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
01810 }
01811
01812 free (alc);
01813 break;
01814 }
01815 }
01816
01817
01818
01819 if (t == NULL && info->executable)
01820 {
01821 struct bfd_elf_version_tree **pp;
01822 int version_index;
01823
01824
01825
01826 if (h->dynindx == -1)
01827 return TRUE;
01828
01829 amt = sizeof *t;
01830 t = bfd_zalloc (sinfo->output_bfd, amt);
01831 if (t == NULL)
01832 {
01833 sinfo->failed = TRUE;
01834 return FALSE;
01835 }
01836
01837 t->name = p;
01838 t->name_indx = (unsigned int) -1;
01839 t->used = TRUE;
01840
01841 version_index = 1;
01842
01843 if (sinfo->verdefs != NULL && sinfo->verdefs->vernum == 0)
01844 version_index = 0;
01845 for (pp = &sinfo->verdefs; *pp != NULL; pp = &(*pp)->next)
01846 ++version_index;
01847 t->vernum = version_index;
01848
01849 *pp = t;
01850
01851 h->verinfo.vertree = t;
01852 }
01853 else if (t == NULL)
01854 {
01855
01856
01857 (*_bfd_error_handler)
01858 (_("%B: undefined versioned symbol name %s"),
01859 sinfo->output_bfd, h->root.root.string);
01860 bfd_set_error (bfd_error_bad_value);
01861 sinfo->failed = TRUE;
01862 return FALSE;
01863 }
01864
01865 if (hidden)
01866 h->hidden = 1;
01867 }
01868
01869
01870
01871 if (h->verinfo.vertree == NULL && sinfo->verdefs != NULL)
01872 {
01873 struct bfd_elf_version_tree *t;
01874 struct bfd_elf_version_tree *local_ver;
01875 struct bfd_elf_version_expr *d;
01876
01877
01878
01879
01880 local_ver = NULL;
01881 for (t = sinfo->verdefs; t != NULL; t = t->next)
01882 {
01883 if (t->globals.list != NULL)
01884 {
01885 bfd_boolean matched;
01886
01887 matched = FALSE;
01888 d = NULL;
01889 while ((d = (*t->match) (&t->globals, d,
01890 h->root.root.string)) != NULL)
01891 if (d->symver)
01892 matched = TRUE;
01893 else
01894 {
01895
01896
01897
01898 h->verinfo.vertree = t;
01899 local_ver = NULL;
01900 d->script = 1;
01901 break;
01902 }
01903 if (d != NULL)
01904 break;
01905 else if (matched)
01906
01907
01908 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
01909 }
01910
01911 if (t->locals.list != NULL)
01912 {
01913 d = NULL;
01914 while ((d = (*t->match) (&t->locals, d,
01915 h->root.root.string)) != NULL)
01916 {
01917 local_ver = t;
01918
01919
01920
01921 if (d->pattern[0] != '*' || d->pattern[1] != '\0')
01922 break;
01923 }
01924
01925 if (d != NULL)
01926 break;
01927 }
01928 }
01929
01930 if (local_ver != NULL)
01931 {
01932 h->verinfo.vertree = local_ver;
01933 if (h->dynindx != -1
01934 && info->shared
01935 && ! info->export_dynamic)
01936 {
01937 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
01938 }
01939 }
01940 }
01941
01942 return TRUE;
01943 }
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954 static bfd_boolean
01955 elf_link_read_relocs_from_section (bfd *abfd,
01956 asection *sec,
01957 Elf_Internal_Shdr *shdr,
01958 void *external_relocs,
01959 Elf_Internal_Rela *internal_relocs)
01960 {
01961 const struct elf_backend_data *bed;
01962 void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
01963 const bfd_byte *erela;
01964 const bfd_byte *erelaend;
01965 Elf_Internal_Rela *irela;
01966 Elf_Internal_Shdr *symtab_hdr;
01967 size_t nsyms;
01968
01969
01970 if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0)
01971 return FALSE;
01972
01973
01974 if (bfd_bread (external_relocs, shdr->sh_size, abfd) != shdr->sh_size)
01975 return FALSE;
01976
01977 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
01978 nsyms = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
01979
01980 bed = get_elf_backend_data (abfd);
01981
01982
01983 if (shdr->sh_entsize == bed->s->sizeof_rel)
01984 swap_in = bed->s->swap_reloc_in;
01985 else if (shdr->sh_entsize == bed->s->sizeof_rela)
01986 swap_in = bed->s->swap_reloca_in;
01987 else
01988 {
01989 bfd_set_error (bfd_error_wrong_format);
01990 return FALSE;
01991 }
01992
01993 erela = external_relocs;
01994 erelaend = erela + shdr->sh_size;
01995 irela = internal_relocs;
01996 while (erela < erelaend)
01997 {
01998 bfd_vma r_symndx;
01999
02000 (*swap_in) (abfd, erela, irela);
02001 r_symndx = ELF32_R_SYM (irela->r_info);
02002 if (bed->s->arch_size == 64)
02003 r_symndx >>= 24;
02004 if ((size_t) r_symndx >= nsyms)
02005 {
02006 (*_bfd_error_handler)
02007 (_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"
02008 " for offset 0x%lx in section `%A'"),
02009 abfd, sec,
02010 (unsigned long) r_symndx, (unsigned long) nsyms, irela->r_offset);
02011 bfd_set_error (bfd_error_bad_value);
02012 return FALSE;
02013 }
02014 irela += bed->s->int_rels_per_ext_rel;
02015 erela += shdr->sh_entsize;
02016 }
02017
02018 return TRUE;
02019 }
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031 Elf_Internal_Rela *
02032 _bfd_elf_link_read_relocs (bfd *abfd,
02033 asection *o,
02034 void *external_relocs,
02035 Elf_Internal_Rela *internal_relocs,
02036 bfd_boolean keep_memory)
02037 {
02038 Elf_Internal_Shdr *rel_hdr;
02039 void *alloc1 = NULL;
02040 Elf_Internal_Rela *alloc2 = NULL;
02041 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
02042
02043 if (elf_section_data (o)->relocs != NULL)
02044 return elf_section_data (o)->relocs;
02045
02046 if (o->reloc_count == 0)
02047 return NULL;
02048
02049 rel_hdr = &elf_section_data (o)->rel_hdr;
02050
02051 if (internal_relocs == NULL)
02052 {
02053 bfd_size_type size;
02054
02055 size = o->reloc_count;
02056 size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela);
02057 if (keep_memory)
02058 internal_relocs = bfd_alloc (abfd, size);
02059 else
02060 internal_relocs = alloc2 = bfd_malloc (size);
02061 if (internal_relocs == NULL)
02062 goto error_return;
02063 }
02064
02065 if (external_relocs == NULL)
02066 {
02067 bfd_size_type size = rel_hdr->sh_size;
02068
02069 if (elf_section_data (o)->rel_hdr2)
02070 size += elf_section_data (o)->rel_hdr2->sh_size;
02071 alloc1 = bfd_malloc (size);
02072 if (alloc1 == NULL)
02073 goto error_return;
02074 external_relocs = alloc1;
02075 }
02076
02077 if (!elf_link_read_relocs_from_section (abfd, o, rel_hdr,
02078 external_relocs,
02079 internal_relocs))
02080 goto error_return;
02081 if (elf_section_data (o)->rel_hdr2
02082 && (!elf_link_read_relocs_from_section
02083 (abfd, o,
02084 elf_section_data (o)->rel_hdr2,
02085 ((bfd_byte *) external_relocs) + rel_hdr->sh_size,
02086 internal_relocs + (NUM_SHDR_ENTRIES (rel_hdr)
02087 * bed->s->int_rels_per_ext_rel))))
02088 goto error_return;
02089
02090
02091 if (keep_memory)
02092 elf_section_data (o)->relocs = internal_relocs;
02093
02094 if (alloc1 != NULL)
02095 free (alloc1);
02096
02097
02098
02099
02100 return internal_relocs;
02101
02102 error_return:
02103 if (alloc1 != NULL)
02104 free (alloc1);
02105 if (alloc2 != NULL)
02106 free (alloc2);
02107 return NULL;
02108 }
02109
02110
02111
02112
02113 bfd_boolean
02114 _bfd_elf_link_size_reloc_section (bfd *abfd,
02115 Elf_Internal_Shdr *rel_hdr,
02116 asection *o)
02117 {
02118 bfd_size_type reloc_count;
02119 bfd_size_type num_rel_hashes;
02120
02121
02122 if (rel_hdr == &elf_section_data (o)->rel_hdr)
02123 reloc_count = elf_section_data (o)->rel_count;
02124 else
02125 reloc_count = elf_section_data (o)->rel_count2;
02126
02127 num_rel_hashes = o->reloc_count;
02128 if (num_rel_hashes < reloc_count)
02129 num_rel_hashes = reloc_count;
02130
02131
02132 rel_hdr->sh_size = rel_hdr->sh_entsize * reloc_count;
02133
02134
02135
02136
02137
02138 rel_hdr->contents = bfd_zalloc (abfd, rel_hdr->sh_size);
02139 if (rel_hdr->contents == NULL && rel_hdr->sh_size != 0)
02140 return FALSE;
02141
02142
02143
02144 if (elf_section_data (o)->rel_hashes == NULL
02145 && num_rel_hashes)
02146 {
02147 struct elf_link_hash_entry **p;
02148
02149 p = bfd_zmalloc (num_rel_hashes * sizeof (struct elf_link_hash_entry *));
02150 if (p == NULL)
02151 return FALSE;
02152
02153 elf_section_data (o)->rel_hashes = p;
02154 }
02155
02156 return TRUE;
02157 }
02158
02159
02160
02161
02162
02163 bfd_boolean
02164 _bfd_elf_link_output_relocs (bfd *output_bfd,
02165 asection *input_section,
02166 Elf_Internal_Shdr *input_rel_hdr,
02167 Elf_Internal_Rela *internal_relocs)
02168 {
02169 Elf_Internal_Rela *irela;
02170 Elf_Internal_Rela *irelaend;
02171 bfd_byte *erel;
02172 Elf_Internal_Shdr *output_rel_hdr;
02173 asection *output_section;
02174 unsigned int *rel_countp = NULL;
02175 const struct elf_backend_data *bed;
02176 void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
02177
02178 output_section = input_section->output_section;
02179 output_rel_hdr = NULL;
02180
02181 if (elf_section_data (output_section)->rel_hdr.sh_entsize
02182 == input_rel_hdr->sh_entsize)
02183 {
02184 output_rel_hdr = &elf_section_data (output_section)->rel_hdr;
02185 rel_countp = &elf_section_data (output_section)->rel_count;
02186 }
02187 else if (elf_section_data (output_section)->rel_hdr2
02188 && (elf_section_data (output_section)->rel_hdr2->sh_entsize
02189 == input_rel_hdr->sh_entsize))
02190 {
02191 output_rel_hdr = elf_section_data (output_section)->rel_hdr2;
02192 rel_countp = &elf_section_data (output_section)->rel_count2;
02193 }
02194 else
02195 {
02196 (*_bfd_error_handler)
02197 (_("%B: relocation size mismatch in %B section %A"),
02198 output_bfd, input_section->owner, input_section);
02199 bfd_set_error (bfd_error_wrong_object_format);
02200 return FALSE;
02201 }
02202
02203 bed = get_elf_backend_data (output_bfd);
02204 if (input_rel_hdr->sh_entsize == bed->s->sizeof_rel)
02205 swap_out = bed->s->swap_reloc_out;
02206 else if (input_rel_hdr->sh_entsize == bed->s->sizeof_rela)
02207 swap_out = bed->s->swap_reloca_out;
02208 else
02209 abort ();
02210
02211 erel = output_rel_hdr->contents;
02212 erel += *rel_countp * input_rel_hdr->sh_entsize;
02213 irela = internal_relocs;
02214 irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
02215 * bed->s->int_rels_per_ext_rel);
02216 while (irela < irelaend)
02217 {
02218 (*swap_out) (output_bfd, irela, erel);
02219 irela += bed->s->int_rels_per_ext_rel;
02220 erel += input_rel_hdr->sh_entsize;
02221 }
02222
02223
02224
02225 *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr);
02226
02227 return TRUE;
02228 }
02229
02230
02231
02232
02233
02234
02235
02236 bfd_boolean
02237 _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h,
02238 struct elf_info_failed *eif)
02239 {
02240
02241
02242
02243
02244 if (h->non_elf)
02245 {
02246 while (h->root.type == bfd_link_hash_indirect)
02247 h = (struct elf_link_hash_entry *) h->root.u.i.link;
02248
02249 if (h->root.type != bfd_link_hash_defined
02250 && h->root.type != bfd_link_hash_defweak)
02251 {
02252 h->ref_regular = 1;
02253 h->ref_regular_nonweak = 1;
02254 }
02255 else
02256 {
02257 if (h->root.u.def.section->owner != NULL
02258 && (bfd_get_flavour (h->root.u.def.section->owner)
02259 == bfd_target_elf_flavour))
02260 {
02261 h->ref_regular = 1;
02262 h->ref_regular_nonweak = 1;
02263 }
02264 else
02265 h->def_regular = 1;
02266 }
02267
02268 if (h->dynindx == -1
02269 && (h->def_dynamic
02270 || h->ref_dynamic))
02271 {
02272 if (! bfd_elf_link_record_dynamic_symbol (eif->info, h))
02273 {
02274 eif->failed = TRUE;
02275 return FALSE;
02276 }
02277 }
02278 }
02279 else
02280 {
02281
02282
02283
02284
02285
02286
02287 if ((h->root.type == bfd_link_hash_defined
02288 || h->root.type == bfd_link_hash_defweak)
02289 && !h->def_regular
02290 && (h->root.u.def.section->owner != NULL
02291 ? (bfd_get_flavour (h->root.u.def.section->owner)
02292 != bfd_target_elf_flavour)
02293 : (bfd_is_abs_section (h->root.u.def.section)
02294 && !h->def_dynamic)))
02295 h->def_regular = 1;
02296 }
02297
02298
02299
02300
02301
02302
02303 if (h->root.type == bfd_link_hash_defined
02304 && !h->def_regular
02305 && h->ref_regular
02306 && !h->def_dynamic
02307 && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
02308 h->def_regular = 1;
02309
02310
02311
02312
02313
02314
02315
02316 if (h->needs_plt
02317 && eif->info->shared
02318 && is_elf_hash_table (eif->info->hash)
02319 && (eif->info->symbolic
02320 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
02321 && h->def_regular)
02322 {
02323 const struct elf_backend_data *bed;
02324 bfd_boolean force_local;
02325
02326 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
02327
02328 force_local = (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
02329 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN);
02330 (*bed->elf_backend_hide_symbol) (eif->info, h, force_local);
02331 }
02332
02333
02334
02335 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
02336 && h->root.type == bfd_link_hash_undefweak)
02337 {
02338 const struct elf_backend_data *bed;
02339 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
02340 (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
02341 }
02342
02343
02344
02345
02346 if (h->u.weakdef != NULL)
02347 {
02348 struct elf_link_hash_entry *weakdef;
02349
02350 weakdef = h->u.weakdef;
02351 if (h->root.type == bfd_link_hash_indirect)
02352 h = (struct elf_link_hash_entry *) h->root.u.i.link;
02353
02354 BFD_ASSERT (h->root.type == bfd_link_hash_defined
02355 || h->root.type == bfd_link_hash_defweak);
02356 BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined
02357 || weakdef->root.type == bfd_link_hash_defweak);
02358 BFD_ASSERT (weakdef->def_dynamic);
02359
02360
02361
02362
02363 if (weakdef->def_regular)
02364 h->u.weakdef = NULL;
02365 else
02366 {
02367 const struct elf_backend_data *bed;
02368
02369 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
02370 (*bed->elf_backend_copy_indirect_symbol) (bed, weakdef, h);
02371 }
02372 }
02373
02374 return TRUE;
02375 }
02376
02377
02378
02379
02380
02381 bfd_boolean
02382 _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data)
02383 {
02384 struct elf_info_failed *eif = data;
02385 bfd *dynobj;
02386 const struct elf_backend_data *bed;
02387
02388 if (! is_elf_hash_table (eif->info->hash))
02389 return FALSE;
02390
02391 if (h->root.type == bfd_link_hash_warning)
02392 {
02393 h->plt = elf_hash_table (eif->info)->init_offset;
02394 h->got = elf_hash_table (eif->info)->init_offset;
02395
02396
02397
02398
02399 h = (struct elf_link_hash_entry *) h->root.u.i.link;
02400 }
02401
02402
02403 if (h->root.type == bfd_link_hash_indirect)
02404 return TRUE;
02405
02406
02407 if (! _bfd_elf_fix_symbol_flags (h, eif))
02408 return FALSE;
02409
02410
02411
02412
02413
02414
02415
02416
02417 if (!h->needs_plt
02418 && (h->def_regular
02419 || !h->def_dynamic
02420 || (!h->ref_regular
02421 && (h->u.weakdef == NULL || h->u.weakdef->dynindx == -1))))
02422 {
02423 h->plt = elf_hash_table (eif->info)->init_offset;
02424 return TRUE;
02425 }
02426
02427
02428
02429 if (h->dynamic_adjusted)
02430 return TRUE;
02431
02432
02433
02434
02435
02436 h->dynamic_adjusted = 1;
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466 if (h->u.weakdef != NULL)
02467 {
02468
02469
02470
02471
02472 h->u.weakdef->ref_regular = 1;
02473
02474 if (! _bfd_elf_adjust_dynamic_symbol (h->u.weakdef, eif))
02475 return FALSE;
02476 }
02477
02478
02479
02480
02481
02482
02483 if (h->size == 0
02484 && h->type == STT_NOTYPE
02485 && !h->needs_plt)
02486 (*_bfd_error_handler)
02487 (_("warning: type and size of dynamic symbol `%s' are not defined"),
02488 h->root.root.string);
02489
02490 dynobj = elf_hash_table (eif->info)->dynobj;
02491 bed = get_elf_backend_data (dynobj);
02492 if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h))
02493 {
02494 eif->failed = TRUE;
02495 return FALSE;
02496 }
02497
02498 return TRUE;
02499 }
02500
02501
02502
02503
02504 bfd_boolean
02505 _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry *h, void *data)
02506 {
02507 asection *sec;
02508
02509 if (h->root.type == bfd_link_hash_warning)
02510 h = (struct elf_link_hash_entry *) h->root.u.i.link;
02511
02512 if ((h->root.type == bfd_link_hash_defined
02513 || h->root.type == bfd_link_hash_defweak)
02514 && ((sec = h->root.u.def.section)->flags & SEC_MERGE)
02515 && sec->sec_info_type == ELF_INFO_TYPE_MERGE)
02516 {
02517 bfd *output_bfd = data;
02518
02519 h->root.u.def.value =
02520 _bfd_merged_section_offset (output_bfd,
02521 &h->root.u.def.section,
02522 elf_section_data (sec)->sec_info,
02523 h->root.u.def.value);
02524 }
02525
02526 return TRUE;
02527 }
02528
02529
02530
02531
02532
02533 bfd_boolean
02534 _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry *h,
02535 struct bfd_link_info *info,
02536 bfd_boolean ignore_protected)
02537 {
02538 bfd_boolean binding_stays_local_p;
02539
02540 if (h == NULL)
02541 return FALSE;
02542
02543 while (h->root.type == bfd_link_hash_indirect
02544 || h->root.type == bfd_link_hash_warning)
02545 h = (struct elf_link_hash_entry *) h->root.u.i.link;
02546
02547
02548 if (h->dynindx == -1)
02549 return FALSE;
02550 if (h->forced_local)
02551 return FALSE;
02552
02553
02554
02555 binding_stays_local_p = info->executable || info->symbolic;
02556
02557 switch (ELF_ST_VISIBILITY (h->other))
02558 {
02559 case STV_INTERNAL:
02560 case STV_HIDDEN:
02561 return FALSE;
02562
02563 case STV_PROTECTED:
02564
02565
02566
02567 if (!ignore_protected || h->type != STT_FUNC)
02568 binding_stays_local_p = TRUE;
02569 break;
02570
02571 default:
02572 break;
02573 }
02574
02575
02576 if (!h->def_regular)
02577 return TRUE;
02578
02579
02580
02581 return !binding_stays_local_p;
02582 }
02583
02584
02585
02586
02587
02588
02589 bfd_boolean
02590 _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h,
02591 struct bfd_link_info *info,
02592 bfd_boolean local_protected)
02593 {
02594
02595 if (h == NULL)
02596 return TRUE;
02597
02598
02599
02600 if (ELF_COMMON_DEF_P (h))
02601 ;
02602
02603
02604 else if (!h->def_regular)
02605 return FALSE;
02606
02607
02608 if (h->forced_local)
02609 return TRUE;
02610
02611
02612 if (h->dynindx == -1)
02613 return TRUE;
02614
02615
02616
02617
02618 if (info->executable || info->symbolic)
02619 return TRUE;
02620
02621
02622
02623 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
02624 return FALSE;
02625
02626
02627 if (ELF_ST_VISIBILITY (h->other) != STV_PROTECTED)
02628 return TRUE;
02629
02630
02631 if (h->type != STT_FUNC)
02632 return TRUE;
02633
02634
02635
02636
02637 return local_protected;
02638 }
02639
02640
02641
02642
02643 struct bfd_section *
02644 _bfd_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
02645 {
02646 struct bfd_section *sec, *tls;
02647 unsigned int align = 0;
02648
02649 for (sec = obfd->sections; sec != NULL; sec = sec->next)
02650 if ((sec->flags & SEC_THREAD_LOCAL) != 0)
02651 break;
02652 tls = sec;
02653
02654 for (; sec != NULL && (sec->flags & SEC_THREAD_LOCAL) != 0; sec = sec->next)
02655 if (sec->alignment_power > align)
02656 align = sec->alignment_power;
02657
02658 elf_hash_table (info)->tls_sec = tls;
02659
02660
02661
02662 if (tls != NULL)
02663 tls->alignment_power = align;
02664
02665 return tls;
02666 }
02667
02668
02669 static bfd_boolean
02670 is_global_data_symbol_definition (bfd *abfd ATTRIBUTE_UNUSED,
02671 Elf_Internal_Sym *sym)
02672 {
02673
02674 if (ELF_ST_BIND (sym->st_info) != STB_GLOBAL
02675 && ELF_ST_BIND (sym->st_info) < STB_LOOS)
02676 return FALSE;
02677
02678
02679 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
02680 return FALSE;
02681
02682
02683 if (sym->st_shndx == SHN_UNDEF)
02684 return FALSE;
02685
02686
02687
02688 if (sym->st_shndx == SHN_COMMON)
02689 return FALSE;
02690
02691
02692
02693 if (sym->st_shndx >= SHN_LORESERVE && sym->st_shndx < SHN_ABS)
02694
02695
02696
02697
02698
02699
02700
02701 return FALSE;
02702
02703 return TRUE;
02704 }
02705
02706
02707
02708
02709 static bfd_boolean
02710 elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
02711 {
02712 Elf_Internal_Shdr * hdr;
02713 bfd_size_type symcount;
02714 bfd_size_type extsymcount;
02715 bfd_size_type extsymoff;
02716 Elf_Internal_Sym *isymbuf;
02717 Elf_Internal_Sym *isym;
02718 Elf_Internal_Sym *isymend;
02719 bfd_boolean result;
02720
02721 abfd = _bfd_get_elt_at_filepos (abfd, symdef->file_offset);
02722 if (abfd == NULL)
02723 return FALSE;
02724
02725 if (! bfd_check_format (abfd, bfd_object))
02726 return FALSE;
02727
02728
02729
02730
02731
02732 if (abfd->archive_pass)
02733 return FALSE;
02734
02735
02736 if ((abfd->flags & DYNAMIC) == 0 || elf_dynsymtab (abfd) == 0)
02737 hdr = &elf_tdata (abfd)->symtab_hdr;
02738 else
02739 hdr = &elf_tdata (abfd)->dynsymtab_hdr;
02740
02741 symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
02742
02743
02744
02745 if (elf_bad_symtab (abfd))
02746 {
02747 extsymcount = symcount;
02748 extsymoff = 0;
02749 }
02750 else
02751 {
02752 extsymcount = symcount - hdr->sh_info;
02753 extsymoff = hdr->sh_info;
02754 }
02755
02756 if (extsymcount == 0)
02757 return FALSE;
02758
02759
02760 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
02761 NULL, NULL, NULL);
02762 if (isymbuf == NULL)
02763 return FALSE;
02764
02765
02766 result = FALSE;
02767 for (isym = isymbuf, isymend = isymbuf + extsymcount; isym < isymend; isym++)
02768 {
02769 const char *name;
02770
02771 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
02772 isym->st_name);
02773 if (name == NULL)
02774 break;
02775
02776 if (strcmp (name, symdef->name) == 0)
02777 {
02778 result = is_global_data_symbol_definition (abfd, isym);
02779 break;
02780 }
02781 }
02782
02783 free (isymbuf);
02784
02785 return result;
02786 }
02787
02788
02789
02790 bfd_boolean
02791 _bfd_elf_add_dynamic_entry (struct bfd_link_info *info,
02792 bfd_vma tag,
02793 bfd_vma val)
02794 {
02795 struct elf_link_hash_table *hash_table;
02796 const struct elf_backend_data *bed;
02797 asection *s;
02798 bfd_size_type newsize;
02799 bfd_byte *newcontents;
02800 Elf_Internal_Dyn dyn;
02801
02802 hash_table = elf_hash_table (info);
02803 if (! is_elf_hash_table (hash_table))
02804 return FALSE;
02805
02806 if (info->warn_shared_textrel && info->shared && tag == DT_TEXTREL)
02807 _bfd_error_handler
02808 (_("warning: creating a DT_TEXTREL in a shared object."));
02809
02810 bed = get_elf_backend_data (hash_table->dynobj);
02811 s = bfd_get_section_by_name (hash_table->dynobj, ".dynamic");
02812 BFD_ASSERT (s != NULL);
02813
02814 newsize = s->size + bed->s->sizeof_dyn;
02815 newcontents = bfd_realloc (s->contents, newsize);
02816 if (newcontents == NULL)
02817 return FALSE;
02818
02819 dyn.d_tag = tag;
02820 dyn.d_un.d_val = val;
02821 bed->s->swap_dyn_out (hash_table->dynobj, &dyn, newcontents + s->size);
02822
02823 s->size = newsize;
02824 s->contents = newcontents;
02825
02826 return TRUE;
02827 }
02828
02829
02830
02831
02832
02833 static int
02834 elf_add_dt_needed_tag (bfd *abfd,
02835 struct bfd_link_info *info,
02836 const char *soname,
02837 bfd_boolean do_it)
02838 {
02839 struct elf_link_hash_table *hash_table;
02840 bfd_size_type oldsize;
02841 bfd_size_type strindex;
02842
02843 if (!_bfd_elf_link_create_dynstrtab (abfd, info))
02844 return -1;
02845
02846 hash_table = elf_hash_table (info);
02847 oldsize = _bfd_elf_strtab_size (hash_table->dynstr);
02848 strindex = _bfd_elf_strtab_add (hash_table->dynstr, soname, FALSE);
02849 if (strindex == (bfd_size_type) -1)
02850 return -1;
02851
02852 if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr))
02853 {
02854 asection *sdyn;
02855 const struct elf_backend_data *bed;
02856 bfd_byte *extdyn;
02857
02858 bed = get_elf_backend_data (hash_table->dynobj);
02859 sdyn = bfd_get_section_by_name (hash_table->dynobj, ".dynamic");
02860 if (sdyn != NULL)
02861 for (extdyn = sdyn->contents;
02862 extdyn < sdyn->contents + sdyn->size;
02863 extdyn += bed->s->sizeof_dyn)
02864 {
02865 Elf_Internal_Dyn dyn;
02866
02867 bed->s->swap_dyn_in (hash_table->dynobj, extdyn, &dyn);
02868 if (dyn.d_tag == DT_NEEDED
02869 && dyn.d_un.d_val == strindex)
02870 {
02871 _bfd_elf_strtab_delref (hash_table->dynstr, strindex);
02872 return 1;
02873 }
02874 }
02875 }
02876
02877 if (do_it)
02878 {
02879 if (!_bfd_elf_link_create_dynamic_sections (hash_table->dynobj, info))
02880 return -1;
02881
02882 if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex))
02883 return -1;
02884 }
02885 else
02886
02887 _bfd_elf_strtab_delref (hash_table->dynstr, strindex);
02888
02889 return 0;
02890 }
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901 struct elf_smash_syms_data
02902 {
02903 bfd *not_needed;
02904 struct elf_link_hash_table *htab;
02905 bfd_boolean twiddled;
02906 };
02907
02908 static bfd_boolean
02909 elf_smash_syms (struct elf_link_hash_entry *h, void *data)
02910 {
02911 struct elf_smash_syms_data *inf = (struct elf_smash_syms_data *) data;
02912 struct bfd_link_hash_entry *bh;
02913
02914 switch (h->root.type)
02915 {
02916 default:
02917 case bfd_link_hash_new:
02918 return TRUE;
02919
02920 case bfd_link_hash_undefined:
02921 if (h->root.u.undef.abfd != inf->not_needed)
02922 return TRUE;
02923 if (h->root.u.undef.weak != NULL
02924 && h->root.u.undef.weak != inf->not_needed)
02925 {
02926
02927
02928 h->root.type = bfd_link_hash_undefweak;
02929 h->root.u.undef.abfd = h->root.u.undef.weak;
02930 if (h->root.u.undef.next != NULL
02931 || inf->htab->root.undefs_tail == &h->root)
02932 inf->twiddled = TRUE;
02933 return TRUE;
02934 }
02935 break;
02936
02937 case bfd_link_hash_undefweak:
02938 if (h->root.u.undef.abfd != inf->not_needed)
02939 return TRUE;
02940 break;
02941
02942 case bfd_link_hash_defined:
02943 case bfd_link_hash_defweak:
02944 if (h->root.u.def.section->owner != inf->not_needed)
02945 return TRUE;
02946 break;
02947
02948 case bfd_link_hash_common:
02949 if (h->root.u.c.p->section->owner != inf->not_needed)
02950 return TRUE;
02951 break;
02952
02953 case bfd_link_hash_warning:
02954 case bfd_link_hash_indirect:
02955 elf_smash_syms ((struct elf_link_hash_entry *) h->root.u.i.link, data);
02956 if (h->root.u.i.link->type != bfd_link_hash_new)
02957 return TRUE;
02958 if (h->root.u.i.link->u.undef.abfd != inf->not_needed)
02959 return TRUE;
02960 break;
02961 }
02962
02963
02964
02965 if (h->ref_regular)
02966 abort ();
02967
02968
02969
02970 bh = h->root.u.undef.next;
02971 if (bh == &h->root)
02972 bh = NULL;
02973 if (bh != NULL || inf->htab->root.undefs_tail == &h->root)
02974 inf->twiddled = TRUE;
02975 (*inf->htab->root.table.newfunc) (&h->root.root,
02976 &inf->htab->root.table,
02977 h->root.root.string);
02978 h->root.u.undef.next = bh;
02979 h->root.u.undef.abfd = inf->not_needed;
02980 h->non_elf = 0;
02981 return TRUE;
02982 }
02983
02984
02985 static int
02986 elf_sort_symbol (const void *arg1, const void *arg2)
02987 {
02988 const struct elf_link_hash_entry *h1;
02989 const struct elf_link_hash_entry *h2;
02990 bfd_signed_vma vdiff;
02991
02992 h1 = *(const struct elf_link_hash_entry **) arg1;
02993 h2 = *(const struct elf_link_hash_entry **) arg2;
02994 vdiff = h1->root.u.def.value - h2->root.u.def.value;
02995 if (vdiff != 0)
02996 return vdiff > 0 ? 1 : -1;
02997 else
02998 {
02999 #ifdef KEY
03000 long sdiff = h1->root.u.def.section - h2->root.u.def.section;
03001 #else
03002 long sdiff = h1->root.u.def.section->id - h2->root.u.def.section->id;
03003 #endif
03004 if (sdiff != 0)
03005 return sdiff > 0 ? 1 : -1;
03006 }
03007 return 0;
03008 }
03009
03010
03011
03012
03013 static bfd_boolean
03014 elf_adjust_dynstr_offsets (struct elf_link_hash_entry *h, void *data)
03015 {
03016 struct elf_strtab_hash *dynstr = data;
03017
03018 if (h->root.type == bfd_link_hash_warning)
03019 h = (struct elf_link_hash_entry *) h->root.u.i.link;
03020
03021 if (h->dynindx != -1)
03022 h->dynstr_index = _bfd_elf_strtab_offset (dynstr, h->dynstr_index);
03023 return TRUE;
03024 }
03025
03026
03027
03028
03029 static bfd_boolean
03030 elf_finalize_dynstr (bfd *output_bfd, struct bfd_link_info *info)
03031 {
03032 struct elf_link_hash_table *hash_table = elf_hash_table (info);
03033 struct elf_link_local_dynamic_entry *entry;
03034 struct elf_strtab_hash *dynstr = hash_table->dynstr;
03035 bfd *dynobj = hash_table->dynobj;
03036 asection *sdyn;
03037 bfd_size_type size;
03038 const struct elf_backend_data *bed;
03039 bfd_byte *extdyn;
03040
03041 _bfd_elf_strtab_finalize (dynstr);
03042 size = _bfd_elf_strtab_size (dynstr);
03043
03044 bed = get_elf_backend_data (dynobj);
03045 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
03046 BFD_ASSERT (sdyn != NULL);
03047
03048
03049 for (extdyn = sdyn->contents;
03050 extdyn < sdyn->contents + sdyn->size;
03051 extdyn += bed->s->sizeof_dyn)
03052 {
03053 Elf_Internal_Dyn dyn;
03054
03055 bed->s->swap_dyn_in (dynobj, extdyn, &dyn);
03056 switch (dyn.d_tag)
03057 {
03058 case DT_STRSZ:
03059 dyn.d_un.d_val = size;
03060 break;
03061 case DT_NEEDED:
03062 case DT_SONAME:
03063 case DT_RPATH:
03064 case DT_RUNPATH:
03065 case DT_FILTER:
03066 case DT_AUXILIARY:
03067 dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val);
03068 break;
03069 default:
03070 continue;
03071 }
03072 bed->s->swap_dyn_out (dynobj, &dyn, extdyn);
03073 }
03074
03075
03076 for (entry = hash_table->dynlocal; entry ; entry = entry->next)
03077 entry->isym.st_name = _bfd_elf_strtab_offset (dynstr,
03078 entry->isym.st_name);
03079
03080
03081 elf_link_hash_traverse (hash_table, elf_adjust_dynstr_offsets, dynstr);
03082
03083
03084 if (elf_tdata (output_bfd)->cverdefs)
03085 {
03086 asection *s;
03087 bfd_byte *p;
03088 bfd_size_type i;
03089 Elf_Internal_Verdef def;
03090 Elf_Internal_Verdaux defaux;
03091
03092 s = bfd_get_section_by_name (dynobj, ".gnu.version_d");
03093 p = s->contents;
03094 do
03095 {
03096 _bfd_elf_swap_verdef_in (output_bfd, (Elf_External_Verdef *) p,
03097 &def);
03098 p += sizeof (Elf_External_Verdef);
03099 if (def.vd_aux != sizeof (Elf_External_Verdef))
03100 continue;
03101 for (i = 0; i < def.vd_cnt; ++i)
03102 {
03103 _bfd_elf_swap_verdaux_in (output_bfd,
03104 (Elf_External_Verdaux *) p, &defaux);
03105 defaux.vda_name = _bfd_elf_strtab_offset (dynstr,
03106 defaux.vda_name);
03107 _bfd_elf_swap_verdaux_out (output_bfd,
03108 &defaux, (Elf_External_Verdaux *) p);
03109 p += sizeof (Elf_External_Verdaux);
03110 }
03111 }
03112 while (def.vd_next);
03113 }
03114
03115
03116 if (elf_tdata (output_bfd)->verref)
03117 {
03118 asection *s;
03119 bfd_byte *p;
03120 bfd_size_type i;
03121 Elf_Internal_Verneed need;
03122 Elf_Internal_Vernaux needaux;
03123
03124 s = bfd_get_section_by_name (dynobj, ".gnu.version_r");
03125 p = s->contents;
03126 do
03127 {
03128 _bfd_elf_swap_verneed_in (output_bfd, (Elf_External_Verneed *) p,
03129 &need);
03130 need.vn_file = _bfd_elf_strtab_offset (dynstr, need.vn_file);
03131 _bfd_elf_swap_verneed_out (output_bfd, &need,
03132 (Elf_External_Verneed *) p);
03133 p += sizeof (Elf_External_Verneed);
03134 for (i = 0; i < need.vn_cnt; ++i)
03135 {
03136 _bfd_elf_swap_vernaux_in (output_bfd,
03137 (Elf_External_Vernaux *) p, &needaux);
03138 needaux.vna_name = _bfd_elf_strtab_offset (dynstr,
03139 needaux.vna_name);
03140 _bfd_elf_swap_vernaux_out (output_bfd,
03141 &needaux,
03142 (Elf_External_Vernaux *) p);
03143 p += sizeof (Elf_External_Vernaux);
03144 }
03145 }
03146 while (need.vn_next);
03147 }
03148
03149 return TRUE;
03150 }
03151
03152
03153
03154 static bfd_boolean
03155 elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
03156 {
03157 bfd_boolean (*add_symbol_hook)
03158 (bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
03159 const char **, flagword *, asection **, bfd_vma *);
03160 bfd_boolean (*check_relocs)
03161 (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
03162 bfd_boolean (*check_directives)
03163 (bfd *, struct bfd_link_info *);
03164 bfd_boolean collect;
03165 Elf_Internal_Shdr *hdr;
03166 bfd_size_type symcount;
03167 bfd_size_type extsymcount;
03168 bfd_size_type extsymoff;
03169 struct elf_link_hash_entry **sym_hash;
03170 bfd_boolean dynamic;
03171 Elf_External_Versym *extversym = NULL;
03172 Elf_External_Versym *ever;
03173 struct elf_link_hash_entry *weaks;
03174 struct elf_link_hash_entry **nondeflt_vers = NULL;
03175 bfd_size_type nondeflt_vers_cnt = 0;
03176 Elf_Internal_Sym *isymbuf = NULL;
03177 Elf_Internal_Sym *isym;
03178 Elf_Internal_Sym *isymend;
03179 const struct elf_backend_data *bed;
03180 bfd_boolean add_needed;
03181 struct elf_link_hash_table * hash_table;
03182 bfd_size_type amt;
03183
03184 hash_table = elf_hash_table (info);
03185
03186 bed = get_elf_backend_data (abfd);
03187 add_symbol_hook = bed->elf_add_symbol_hook;
03188 collect = bed->collect;
03189
03190 if ((abfd->flags & DYNAMIC) == 0)
03191 dynamic = FALSE;
03192 else
03193 {
03194 dynamic = TRUE;
03195
03196
03197
03198
03199 if (info->relocatable
03200 || !is_elf_hash_table (hash_table)
03201 || hash_table->root.creator != abfd->xvec)
03202 {
03203 if (info->relocatable)
03204 bfd_set_error (bfd_error_invalid_operation);
03205 else
03206 bfd_set_error (bfd_error_wrong_format);
03207 goto error_return;
03208 }
03209 }
03210
03211
03212
03213
03214
03215 if (info->executable)
03216 {
03217 asection *s;
03218
03219 for (s = abfd->sections; s != NULL; s = s->next)
03220 {
03221 const char *name;
03222
03223 name = bfd_get_section_name (abfd, s);
03224 if (strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0)
03225 {
03226 char *msg;
03227 bfd_size_type sz;
03228
03229 name += sizeof ".gnu.warning." - 1;
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239
03240 if (dynamic)
03241 {
03242 struct elf_link_hash_entry *h;
03243
03244 h = elf_link_hash_lookup (hash_table, name,
03245 FALSE, FALSE, TRUE);
03246
03247
03248 if (h != NULL
03249 && (h->root.type == bfd_link_hash_defined
03250 || h->root.type == bfd_link_hash_defweak))
03251 {
03252
03253
03254
03255 s->size = 0;
03256 continue;
03257 }
03258 }
03259
03260 sz = s->size;
03261 msg = bfd_alloc (abfd, sz + 1);
03262 if (msg == NULL)
03263 goto error_return;
03264
03265 if (! bfd_get_section_contents (abfd, s, msg, 0, sz))
03266 goto error_return;
03267
03268 msg[sz] = '\0';
03269
03270 if (! (_bfd_generic_link_add_one_symbol
03271 (info, abfd, name, BSF_WARNING, s, 0, msg,
03272 FALSE, collect, NULL)))
03273 goto error_return;
03274
03275 if (! info->relocatable)
03276 {
03277
03278
03279 s->size = 0;
03280
03281
03282
03283 s->flags |= SEC_EXCLUDE;
03284 }
03285 }
03286 }
03287 }
03288
03289 add_needed = TRUE;
03290 if (! dynamic)
03291 {
03292
03293
03294
03295
03296
03297 if (info->shared
03298 && is_elf_hash_table (hash_table)
03299 && hash_table->root.creator == abfd->xvec
03300 && ! hash_table->dynamic_sections_created)
03301 {
03302 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
03303 goto error_return;
03304 }
03305 }
03306 else if (!is_elf_hash_table (hash_table))
03307 goto error_return;
03308 else
03309 {
03310 asection *s;
03311 const char *soname = NULL;
03312 struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
03313 int ret;
03314
03315
03316
03317
03318 if ((s = abfd->sections) != NULL
03319 && s->sec_info_type == ELF_INFO_TYPE_JUST_SYMS)
03320 goto error_return;
03321
03322
03323
03324
03325
03326
03327
03328
03329 add_needed = (elf_dyn_lib_class (abfd)
03330 & (DYN_AS_NEEDED | DYN_DT_NEEDED
03331 | DYN_NO_NEEDED)) == 0;
03332
03333 s = bfd_get_section_by_name (abfd, ".dynamic");
03334 if (s != NULL)
03335 {
03336 bfd_byte *dynbuf;
03337 bfd_byte *extdyn;
03338 int elfsec;
03339 unsigned long shlink;
03340
03341 if (!bfd_malloc_and_get_section (abfd, s, &dynbuf))
03342 goto error_free_dyn;
03343
03344 elfsec = _bfd_elf_section_from_bfd_section (abfd, s);
03345 if (elfsec == -1)
03346 goto error_free_dyn;
03347 shlink = elf_elfsections (abfd)[elfsec]->sh_link;
03348
03349 for (extdyn = dynbuf;
03350 extdyn < dynbuf + s->size;
03351 extdyn += bed->s->sizeof_dyn)
03352 {
03353 Elf_Internal_Dyn dyn;
03354
03355 bed->s->swap_dyn_in (abfd, extdyn, &dyn);
03356 if (dyn.d_tag == DT_SONAME)
03357 {
03358 unsigned int tagv = dyn.d_un.d_val;
03359 soname = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
03360 if (soname == NULL)
03361 goto error_free_dyn;
03362 }
03363 if (dyn.d_tag == DT_NEEDED)
03364 {
03365 struct bfd_link_needed_list *n, **pn;
03366 char *fnm, *anm;
03367 unsigned int tagv = dyn.d_un.d_val;
03368
03369 amt = sizeof (struct bfd_link_needed_list);
03370 n = bfd_alloc (abfd, amt);
03371 fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
03372 if (n == NULL || fnm == NULL)
03373 goto error_free_dyn;
03374 amt = strlen (fnm) + 1;
03375 anm = bfd_alloc (abfd, amt);
03376 if (anm == NULL)
03377 goto error_free_dyn;
03378 memcpy (anm, fnm, amt);
03379 n->name = anm;
03380 n->by = abfd;
03381 n->next = NULL;
03382 for (pn = & hash_table->needed;
03383 *pn != NULL;
03384 pn = &(*pn)->next)
03385 ;
03386 *pn = n;
03387 }
03388 if (dyn.d_tag == DT_RUNPATH)
03389 {
03390 struct bfd_link_needed_list *n, **pn;
03391 char *fnm, *anm;
03392 unsigned int tagv = dyn.d_un.d_val;
03393
03394 amt = sizeof (struct bfd_link_needed_list);
03395 n = bfd_alloc (abfd, amt);
03396 fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
03397 if (n == NULL || fnm == NULL)
03398 goto error_free_dyn;
03399 amt = strlen (fnm) + 1;
03400 anm = bfd_alloc (abfd, amt);
03401 if (anm == NULL)
03402 goto error_free_dyn;
03403 memcpy (anm, fnm, amt);
03404 n->name = anm;
03405 n->by = abfd;
03406 n->next = NULL;
03407 for (pn = & runpath;
03408 *pn != NULL;
03409 pn = &(*pn)->next)
03410 ;
03411 *pn = n;
03412 }
03413
03414 if (!runpath && dyn.d_tag == DT_RPATH)
03415 {
03416 struct bfd_link_needed_list *n, **pn;
03417 char *fnm, *anm;
03418 unsigned int tagv = dyn.d_un.d_val;
03419
03420 amt = sizeof (struct bfd_link_needed_list);
03421 n = bfd_alloc (abfd, amt);
03422 fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
03423 if (n == NULL || fnm == NULL)
03424 goto error_free_dyn;
03425 amt = strlen (fnm) + 1;
03426 anm = bfd_alloc (abfd, amt);
03427 if (anm == NULL)
03428 {
03429 error_free_dyn:
03430 free (dynbuf);
03431 goto error_return;
03432 }
03433 memcpy (anm, fnm, amt);
03434 n->name = anm;
03435 n->by = abfd;
03436 n->next = NULL;
03437 for (pn = & rpath;
03438 *pn != NULL;
03439 pn = &(*pn)->next)
03440 ;
03441 *pn = n;
03442 }
03443 }
03444
03445 free (dynbuf);
03446 }
03447
03448
03449
03450 if (runpath)
03451 rpath = runpath;
03452
03453 if (rpath)
03454 {
03455 struct bfd_link_needed_list **pn;
03456 for (pn = & hash_table->runpath;
03457 *pn != NULL;
03458 pn = &(*pn)->next)
03459 ;
03460 *pn = rpath;
03461 }
03462
03463
03464
03465
03466
03467
03468
03469
03470 bfd_section_list_clear (abfd);
03471
03472
03473
03474
03475
03476
03477 if (soname == NULL || *soname == '\0')
03478 {
03479 soname = elf_dt_name (abfd);
03480 if (soname == NULL || *soname == '\0')
03481 soname = bfd_get_filename (abfd);
03482 }
03483
03484
03485
03486 elf_dt_name (abfd) = soname;
03487
03488 ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed);
03489 if (ret < 0)
03490 goto error_return;
03491
03492
03493
03494
03495 if (ret > 0)
03496 return TRUE;
03497 }
03498
03499
03500
03501
03502
03503
03504 if (! dynamic || elf_dynsymtab (abfd) == 0)
03505 hdr = &elf_tdata (abfd)->symtab_hdr;
03506 else
03507 hdr = &elf_tdata (abfd)->dynsymtab_hdr;
03508
03509 symcount = hdr->sh_size / bed->s->sizeof_sym;
03510
03511
03512
03513
03514 if (elf_bad_symtab (abfd))
03515 {
03516 extsymcount = symcount;
03517 extsymoff = 0;
03518 }
03519 else
03520 {
03521 extsymcount = symcount - hdr->sh_info;
03522 extsymoff = hdr->sh_info;
03523 }
03524
03525 sym_hash = NULL;
03526 if (extsymcount != 0)
03527 {
03528 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
03529 NULL, NULL, NULL);
03530 if (isymbuf == NULL)
03531 goto error_return;
03532
03533
03534
03535 amt = extsymcount * sizeof (struct elf_link_hash_entry *);
03536 sym_hash = bfd_alloc (abfd, amt);
03537 if (sym_hash == NULL)
03538 goto error_free_sym;
03539 elf_sym_hashes (abfd) = sym_hash;
03540 }
03541
03542 if (dynamic)
03543 {
03544
03545 if (!_bfd_elf_slurp_version_tables (abfd,
03546 info->default_imported_symver))
03547 goto error_free_sym;
03548
03549
03550
03551 if (elf_dynversym (abfd) != 0)
03552 {
03553 Elf_Internal_Shdr *versymhdr;
03554
03555 versymhdr = &elf_tdata (abfd)->dynversym_hdr;
03556 extversym = bfd_malloc (versymhdr->sh_size);
03557 if (extversym == NULL)
03558 goto error_free_sym;
03559 amt = versymhdr->sh_size;
03560 if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET) != 0
03561 || bfd_bread (extversym, amt, abfd) != amt)
03562 goto error_free_vers;
03563 }
03564 }
03565
03566 weaks = NULL;
03567
03568 ever = extversym != NULL ? extversym + extsymoff : NULL;
03569 for (isym = isymbuf, isymend = isymbuf + extsymcount;
03570 isym < isymend;
03571 isym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL))
03572 {
03573 int bind;
03574 bfd_vma value;
03575 asection *sec, *new_sec;
03576 flagword flags;
03577 const char *name;
03578 struct elf_link_hash_entry *h;
03579 bfd_boolean definition;
03580 bfd_boolean size_change_ok;
03581 bfd_boolean type_change_ok;
03582 bfd_boolean new_weakdef;
03583 bfd_boolean override;
03584 unsigned int old_alignment;
03585 bfd *old_bfd;
03586
03587 override = FALSE;
03588
03589 flags = BSF_NO_FLAGS;
03590 sec = NULL;
03591 value = isym->st_value;
03592 *sym_hash = NULL;
03593
03594 bind = ELF_ST_BIND (isym->st_info);
03595 if (bind == STB_LOCAL)
03596 {
03597
03598
03599
03600
03601 continue;
03602 }
03603 else if (bind == STB_GLOBAL)
03604 {
03605 if (isym->st_shndx != SHN_UNDEF
03606 && isym->st_shndx != SHN_COMMON)
03607 flags = BSF_GLOBAL;
03608 }
03609 else if (bind == STB_WEAK)
03610 flags = BSF_WEAK;
03611 else
03612 {
03613
03614 }
03615
03616 if (isym->st_shndx == SHN_UNDEF)
03617 sec = bfd_und_section_ptr;
03618 else if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE)
03619 {
03620 sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
03621 if (sec == NULL)
03622 sec = bfd_abs_section_ptr;
03623 else if (sec->kept_section)
03624 {
03625
03626
03627 sec = bfd_und_section_ptr;
03628 isym->st_shndx = SHN_UNDEF;
03629 isym->st_other = STV_DEFAULT
03630 | (isym->st_other & ~ ELF_ST_VISIBILITY(-1));
03631 }
03632 else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
03633 value -= sec->vma;
03634 }
03635 else if (isym->st_shndx == SHN_ABS)
03636 sec = bfd_abs_section_ptr;
03637 else if (isym->st_shndx == SHN_COMMON)
03638 {
03639 sec = bfd_com_section_ptr;
03640
03641
03642 value = isym->st_size;
03643 }
03644 #ifdef IPA_LINK
03645 else if (isym->st_shndx == SHN_IPA_TEXT)
03646 sec = bfd_whirl_text_section_ptr;
03647 else if (isym->st_shndx == SHN_IPA_DATA)
03648 sec = bfd_whirl_data_section_ptr;
03649 #endif
03650 else
03651 {
03652
03653 }
03654
03655 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
03656 isym->st_name);
03657 if (name == NULL)
03658 goto error_free_vers;
03659
03660 if (isym->st_shndx == SHN_COMMON
03661 && ELF_ST_TYPE (isym->st_info) == STT_TLS)
03662 {
03663 asection *tcomm = bfd_get_section_by_name (abfd, ".tcommon");
03664
03665 if (tcomm == NULL)
03666 {
03667 tcomm = bfd_make_section (abfd, ".tcommon");
03668 if (tcomm == NULL
03669 || !bfd_set_section_flags (abfd, tcomm, (SEC_ALLOC
03670 | SEC_IS_COMMON
03671 | SEC_LINKER_CREATED
03672 | SEC_THREAD_LOCAL)))
03673 goto error_free_vers;
03674 }
03675 sec = tcomm;
03676 }
03677 else if (add_symbol_hook)
03678 {
03679 if (! (*add_symbol_hook) (abfd, info, isym, &name, &flags, &sec,
03680 &value))
03681 goto error_free_vers;
03682
03683
03684
03685 if (name == NULL)
03686 continue;
03687 }
03688
03689
03690 if (sec == NULL)
03691 {
03692 bfd_set_error (bfd_error_bad_value);
03693 goto error_free_vers;
03694 }
03695
03696 if (bfd_is_und_section (sec)
03697 || bfd_is_com_section (sec))
03698 definition = FALSE;
03699 else
03700 definition = TRUE;
03701
03702 size_change_ok = FALSE;
03703 type_change_ok = get_elf_backend_data (abfd)->type_change_ok;
03704 old_alignment = 0;
03705 old_bfd = NULL;
03706 new_sec = sec;
03707
03708 if (is_elf_hash_table (hash_table))
03709 {
03710 Elf_Internal_Versym iver;
03711 unsigned int vernum = 0;
03712 bfd_boolean skip;
03713
03714 if (ever == NULL)
03715 {
03716 if (info->default_imported_symver)
03717
03718 iver.vs_vers = elf_tdata (abfd)->cverdefs;
03719 else
03720 iver.vs_vers = 0;
03721 }
03722 else
03723 _bfd_elf_swap_versym_in (abfd, ever, &iver);
03724
03725 vernum = iver.vs_vers & VERSYM_VERSION;
03726
03727
03728
03729
03730
03731
03732 if ((iver.vs_vers & VERSYM_HIDDEN) != 0
03733 || (vernum > 1 && ! bfd_is_abs_section (sec)))
03734 {
03735 const char *verstr;
03736 size_t namelen, verlen, newlen;
03737 char *newname, *p;
03738
03739 if (isym->st_shndx != SHN_UNDEF)
03740 {
03741 if (vernum > elf_tdata (abfd)->cverdefs)
03742 verstr = NULL;
03743 else if (vernum > 1)
03744 verstr =
03745 elf_tdata (abfd)->verdef[vernum - 1].vd_nodename;
03746 else
03747 verstr = "";
03748
03749 if (verstr == NULL)
03750 {
03751 (*_bfd_error_handler)
03752 (_("%B: %s: invalid version %u (max %d)"),
03753 abfd, name, vernum,
03754 elf_tdata (abfd)->cverdefs);
03755 bfd_set_error (bfd_error_bad_value);
03756 goto error_free_vers;
03757 }
03758 }
03759 else
03760 {
03761
03762
03763
03764
03765 Elf_Internal_Verneed *t;
03766
03767 verstr = NULL;
03768 for (t = elf_tdata (abfd)->verref;
03769 t != NULL;
03770 t = t->vn_nextref)
03771 {
03772 Elf_Internal_Vernaux *a;
03773
03774 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
03775 {
03776 if (a->vna_other == vernum)
03777 {
03778 verstr = a->vna_nodename;
03779 break;
03780 }
03781 }
03782 if (a != NULL)
03783 break;
03784 }
03785 if (verstr == NULL)
03786 {
03787 (*_bfd_error_handler)
03788 (_("%B: %s: invalid needed version %d"),
03789 abfd, name, vernum);
03790 bfd_set_error (bfd_error_bad_value);
03791 goto error_free_vers;
03792 }
03793 }
03794
03795 namelen = strlen (name);
03796 verlen = strlen (verstr);
03797 newlen = namelen + verlen + 2;
03798 if ((iver.vs_vers & VERSYM_HIDDEN) == 0
03799 && isym->st_shndx != SHN_UNDEF)
03800 ++newlen;
03801
03802 newname = bfd_alloc (abfd, newlen);
03803 if (newname == NULL)
03804 goto error_free_vers;
03805 memcpy (newname, name, namelen);
03806 p = newname + namelen;
03807 *p++ = ELF_VER_CHR;
03808
03809
03810
03811 if ((iver.vs_vers & VERSYM_HIDDEN) == 0
03812 && isym->st_shndx != SHN_UNDEF)
03813 *p++ = ELF_VER_CHR;
03814 memcpy (p, verstr, verlen + 1);
03815
03816 name = newname;
03817 }
03818
03819 if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec,
03820 &value, &old_alignment,
03821 sym_hash, &skip, &override,
03822 &type_change_ok, &size_change_ok))
03823 goto error_free_vers;
03824
03825 if (skip)
03826 continue;
03827
03828 if (override)
03829 definition = FALSE;
03830
03831 h = *sym_hash;
03832 while (h->root.type == bfd_link_hash_indirect
03833 || h->root.type == bfd_link_hash_warning)
03834 h = (struct elf_link_hash_entry *) h->root.u.i.link;
03835
03836
03837
03838
03839
03840
03841
03842 switch (h->root.type)
03843 {
03844 default:
03845 break;
03846
03847 case bfd_link_hash_defined:
03848 case bfd_link_hash_defweak:
03849 #ifdef KEY
03850
03851 if ( h->root.u.def.section_is_invalid )
03852 old_bfd = (bfd*)h->root.u.def.section;
03853 else
03854 #endif
03855 old_bfd = h->root.u.def.section->owner;
03856 break;
03857
03858 case bfd_link_hash_common:
03859 #ifdef KEY
03860
03861 if ( h->root.u.def.section_is_invalid )
03862 old_bfd = (bfd*)h->root.u.def.section;
03863 else
03864 #endif
03865 old_bfd = h->root.u.c.p->section->owner;
03866 old_alignment = h->root.u.c.p->alignment_power;
03867 break;
03868 }
03869
03870 if (elf_tdata (abfd)->verdef != NULL
03871 && ! override
03872 && vernum > 1
03873 && definition)
03874 h->verinfo.verdef = &elf_tdata (abfd)->verdef[vernum - 1];
03875 }
03876
03877 if (! (_bfd_generic_link_add_one_symbol
03878 (info, abfd, name, flags, sec, value, NULL, FALSE, collect,
03879 (struct bfd_link_hash_entry **) sym_hash)))
03880 goto error_free_vers;
03881
03882 h = *sym_hash;
03883 while (h->root.type == bfd_link_hash_indirect
03884 || h->root.type == bfd_link_hash_warning)
03885 h = (struct elf_link_hash_entry *) h->root.u.i.link;
03886 *sym_hash = h;
03887
03888 new_weakdef = FALSE;
03889 if (dynamic
03890 && definition
03891 && (flags & BSF_WEAK) != 0
03892 && ELF_ST_TYPE (isym->st_info) != STT_FUNC
03893 && is_elf_hash_table (hash_table)
03894 && h->u.weakdef == NULL)
03895 {
03896
03897
03898
03899
03900
03901
03902
03903
03904
03905
03906
03907
03908 h->u.weakdef = weaks;
03909 weaks = h;
03910 new_weakdef = TRUE;
03911 }
03912
03913
03914 if ((isym->st_shndx == SHN_COMMON
03915 || bfd_is_com_section (sec))
03916 && h->root.type == bfd_link_hash_common)
03917 {
03918 unsigned int align;
03919
03920 if (isym->st_shndx == SHN_COMMON)
03921 align = bfd_log2 (isym->st_value);
03922 else
03923 {
03924
03925
03926 align = new_sec->alignment_power;
03927 }
03928 if (align > old_alignment
03929
03930
03931 || (isym->st_value == 1 && old_alignment == 0))
03932 h->root.u.c.p->alignment_power = align;
03933 else
03934 h->root.u.c.p->alignment_power = old_alignment;
03935 }
03936
03937 if (is_elf_hash_table (hash_table))
03938 {
03939 bfd_boolean dynsym;
03940
03941
03942
03943
03944
03945
03946 if ((old_alignment || isym->st_shndx == SHN_COMMON)
03947 && h->root.type != bfd_link_hash_common)
03948 {
03949 unsigned int common_align;
03950 unsigned int normal_align;
03951 unsigned int symbol_align;
03952 bfd *normal_bfd;
03953 bfd *common_bfd;
03954
03955 symbol_align = ffs (h->root.u.def.value) - 1;
03956 if (h->root.u.def.section->owner != NULL
03957 && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
03958 {
03959 normal_align = h->root.u.def.section->alignment_power;
03960 if (normal_align > symbol_align)
03961 normal_align = symbol_align;
03962 }
03963 else
03964 normal_align = symbol_align;
03965
03966 if (old_alignment)
03967 {
03968 common_align = old_alignment;
03969 common_bfd = old_bfd;
03970 normal_bfd = abfd;
03971 }
03972 else
03973 {
03974 common_align = bfd_log2 (isym->st_value);
03975 common_bfd = abfd;
03976 normal_bfd = old_bfd;
03977 }
03978
03979 if (normal_align < common_align)
03980 (*_bfd_error_handler)
03981 (_("Warning: alignment %u of symbol `%s' in %B"
03982 " is smaller than %u in %B"),
03983 normal_bfd, common_bfd,
03984 1 << normal_align, name, 1 << common_align);
03985 }
03986
03987
03988 if (isym->st_size != 0
03989 && (definition || h->size == 0))
03990 {
03991 #ifndef KEY // bug 2051
03992 if (h->size != 0 && h->size != isym->st_size && ! size_change_ok)
03993 (*_bfd_error_handler)
03994 (_("Warning: size of symbol `%s' changed"
03995 " from %lu in %B to %lu in %B"),
03996 old_bfd, abfd,
03997 name, (unsigned long) h->size,
03998 (unsigned long) isym->st_size);
03999 #endif
04000 h->size = isym->st_size;
04001 }
04002
04003
04004
04005
04006
04007
04008 if (h->root.type == bfd_link_hash_common)
04009 h->size = h->root.u.c.size;
04010
04011 if (ELF_ST_TYPE (isym->st_info) != STT_NOTYPE
04012 && (definition || h->type == STT_NOTYPE))
04013 {
04014 if (h->type != STT_NOTYPE
04015 && h->type != ELF_ST_TYPE (isym->st_info)
04016 && ! type_change_ok)
04017 (*_bfd_error_handler)
04018 (_("Warning: type of symbol `%s' changed"
04019 " from %d to %d in %B"),
04020 abfd, name, h->type, ELF_ST_TYPE (isym->st_info));
04021
04022 h->type = ELF_ST_TYPE (isym->st_info);
04023 }
04024
04025
04026
04027
04028 if (bed->elf_backend_merge_symbol_attribute)
04029 (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition,
04030 dynamic);
04031
04032
04033
04034 if (definition && !dynamic
04035 && (abfd->no_export
04036 || (abfd->my_archive && abfd->my_archive->no_export))
04037 && ELF_ST_VISIBILITY (isym->st_other) != STV_INTERNAL)
04038 isym->st_other = STV_HIDDEN | (isym->st_other & ~ ELF_ST_VISIBILITY (-1));
04039
04040 if (isym->st_other != 0 && !dynamic)
04041 {
04042 unsigned char hvis, symvis, other, nvis;
04043
04044
04045 other = (definition ? isym->st_other : h->other);
04046 other &= ~ ELF_ST_VISIBILITY (-1);
04047
04048
04049 hvis = ELF_ST_VISIBILITY (h->other);
04050 symvis = ELF_ST_VISIBILITY (isym->st_other);
04051 if (! hvis)
04052 nvis = symvis;
04053 else if (! symvis)
04054 nvis = hvis;
04055 else
04056 nvis = hvis < symvis ? hvis : symvis;
04057
04058 h->other = other | nvis;
04059 }
04060
04061
04062
04063
04064
04065
04066 dynsym = FALSE;
04067 if (! dynamic)
04068 {
04069 if (! definition)
04070 {
04071 #ifdef IPA_LINK
04072 if (!ipa_is_whirl(abfd))
04073 #endif
04074 h->ref_regular = 1;
04075 if (bind != STB_WEAK)
04076 h->ref_regular_nonweak = 1;
04077 }
04078 else
04079 {
04080 #ifdef IPA_LINK
04081 if (!ipa_is_whirl(abfd))
04082 #endif
04083 h->def_regular = 1;
04084 }
04085 if (! info->executable
04086 || h->def_dynamic
04087 || h->ref_dynamic)
04088 dynsym = TRUE;
04089 }
04090 else
04091 {
04092 if (! definition)
04093 h->ref_dynamic = 1;
04094 else
04095 h->def_dynamic = 1;
04096 if (h->def_regular
04097 || h->ref_regular
04098 || (h->u.weakdef != NULL
04099 && ! new_weakdef
04100 && h->u.weakdef->dynindx != -1))
04101 dynsym = TRUE;
04102 }
04103
04104
04105
04106 if (definition || h->root.type == bfd_link_hash_common)
04107 if (!_bfd_elf_add_default_symbol (abfd, info, h, name, isym,
04108 &sec, &value, &dynsym,
04109 override))
04110 goto error_free_vers;
04111
04112 if (definition && !dynamic)
04113 {
04114 char *p = strchr (name, ELF_VER_CHR);
04115 if (p != NULL && p[1] != ELF_VER_CHR)
04116 {
04117
04118
04119 if (! nondeflt_vers)
04120 {
04121 amt = (isymend - isym + 1)
04122 * sizeof (struct elf_link_hash_entry *);
04123 nondeflt_vers = bfd_malloc (amt);
04124 }
04125 nondeflt_vers [nondeflt_vers_cnt++] = h;
04126 }
04127 }
04128
04129 if (dynsym && h->dynindx == -1)
04130 {
04131 if (! bfd_elf_link_record_dynamic_symbol (info, h))
04132 goto error_free_vers;
04133 if (h->u.weakdef != NULL
04134 && ! new_weakdef
04135 && h->u.weakdef->dynindx == -1)
04136 {
04137 if (! bfd_elf_link_record_dynamic_symbol (info, h->u.weakdef))
04138 goto error_free_vers;
04139 }
04140 }
04141 else if (dynsym && h->dynindx != -1)
04142
04143
04144
04145 switch (ELF_ST_VISIBILITY (h->other))
04146 {
04147 case STV_INTERNAL:
04148 case STV_HIDDEN:
04149 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
04150 dynsym = FALSE;
04151 break;
04152 }
04153
04154 if (!add_needed
04155 && definition
04156 && dynsym
04157 && h->ref_regular)
04158 {
04159 int ret;
04160 const char *soname = elf_dt_name (abfd);
04161
04162
04163
04164
04165
04166 if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
04167 {
04168 (*_bfd_error_handler)
04169 (_("%s: invalid DSO for symbol `%s' definition"),
04170 abfd, name);
04171 bfd_set_error (bfd_error_bad_value);
04172 goto error_free_vers;
04173 }
04174
04175 elf_dyn_lib_class (abfd) &= ~DYN_AS_NEEDED;
04176
04177 add_needed = TRUE;
04178 ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed);
04179 if (ret < 0)
04180 goto error_free_vers;
04181
04182 BFD_ASSERT (ret == 0);
04183 }
04184 }
04185 }
04186
04187
04188
04189 if (nondeflt_vers != NULL)
04190 {
04191 bfd_size_type cnt, symidx;
04192
04193 for (cnt = 0; cnt < nondeflt_vers_cnt; ++cnt)
04194 {
04195 struct elf_link_hash_entry *h = nondeflt_vers[cnt], *hi;
04196 char *shortname, *p;
04197
04198 p = strchr (h->root.root.string, ELF_VER_CHR);
04199 if (p == NULL
04200 || (h->root.type != bfd_link_hash_defined
04201 && h->root.type != bfd_link_hash_defweak))
04202 continue;
04203
04204 amt = p - h->root.root.string;
04205 shortname = bfd_malloc (amt + 1);
04206 memcpy (shortname, h->root.root.string, amt);
04207 shortname[amt] = '\0';
04208
04209 hi = (struct elf_link_hash_entry *)
04210 bfd_link_hash_lookup (&hash_table->root, shortname,
04211 FALSE, FALSE, FALSE);
04212 if (hi != NULL
04213 && hi->root.type == h->root.type
04214 && hi->root.u.def.value == h->root.u.def.value
04215 && hi->root.u.def.section == h->root.u.def.section)
04216 {
04217 (*bed->elf_backend_hide_symbol) (info, hi, TRUE);
04218 hi->root.type = bfd_link_hash_indirect;
04219 hi->root.u.i.link = (struct bfd_link_hash_entry *) h;
04220 (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi);
04221 sym_hash = elf_sym_hashes (abfd);
04222 if (sym_hash)
04223 for (symidx = 0; symidx < extsymcount; ++symidx)
04224 if (sym_hash[symidx] == hi)
04225 {
04226 sym_hash[symidx] = h;
04227 break;
04228 }
04229 }
04230 free (shortname);
04231 }
04232 free (nondeflt_vers);
04233 nondeflt_vers = NULL;
04234 }
04235
04236 if (extversym != NULL)
04237 {
04238 free (extversym);
04239 extversym = NULL;
04240 }
04241
04242 if (isymbuf != NULL)
04243 free (isymbuf);
04244 isymbuf = NULL;
04245
04246 if (!add_needed
04247 && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
04248 {
04249
04250
04251 struct elf_smash_syms_data inf;
04252 inf.not_needed = abfd;
04253 inf.htab = hash_table;
04254 inf.twiddled = FALSE;
04255 elf_link_hash_traverse (hash_table, elf_smash_syms, &inf);
04256 if (inf.twiddled)
04257 bfd_link_repair_undef_list (&hash_table->root);
04258 weaks = NULL;
04259 }
04260
04261
04262
04263
04264
04265
04266
04267
04268
04269
04270
04271
04272
04273
04274 if (weaks != NULL)
04275 {
04276 struct elf_link_hash_entry **hpp;
04277 struct elf_link_hash_entry **hppend;
04278 struct elf_link_hash_entry **sorted_sym_hash;
04279 struct elf_link_hash_entry *h;
04280 size_t sym_count;
04281
04282
04283
04284
04285 amt = extsymcount * sizeof (struct elf_link_hash_entry *);
04286 sorted_sym_hash = bfd_malloc (amt);
04287 if (sorted_sym_hash == NULL)
04288 goto error_return;
04289 sym_hash = sorted_sym_hash;
04290 hpp = elf_sym_hashes (abfd);
04291 hppend = hpp + extsymcount;
04292 sym_count = 0;
04293 for (; hpp < hppend; hpp++)
04294 {
04295 h = *hpp;
04296 if (h != NULL
04297 && h->root.type == bfd_link_hash_defined
04298 && h->type != STT_FUNC)
04299 {
04300 *sym_hash = h;
04301 sym_hash++;
04302 sym_count++;
04303 }
04304 }
04305
04306 qsort (sorted_sym_hash, sym_count,
04307 sizeof (struct elf_link_hash_entry *),
04308 elf_sort_symbol);
04309
04310 while (weaks != NULL)
04311 {
04312 struct elf_link_hash_entry *hlook;
04313 asection *slook;
04314 bfd_vma vlook;
04315 long ilook;
04316 size_t i, j, idx;
04317
04318 hlook = weaks;
04319 weaks = hlook->u.weakdef;
04320 hlook->u.weakdef = NULL;
04321 #ifndef KEY
04322 BFD_ASSERT (hlook->root.type == bfd_link_hash_defined
04323 || hlook->root.type == bfd_link_hash_defweak
04324 || hlook->root.type == bfd_link_hash_common
04325 || hlook->root.type == bfd_link_hash_indirect);
04326 #endif
04327 slook = hlook->root.u.def.section;
04328 vlook = hlook->root.u.def.value;
04329
04330 ilook = -1;
04331 i = 0;
04332 j = sym_count;
04333 while (i < j)
04334 {
04335 bfd_signed_vma vdiff;
04336 idx = (i + j) / 2;
04337 h = sorted_sym_hash [idx];
04338 vdiff = vlook - h->root.u.def.value;
04339 if (vdiff < 0)
04340 j = idx;
04341 else if (vdiff > 0)
04342 i = idx + 1;
04343 else
04344 {
04345 #ifdef KEY
04346 long sdiff = slook - h->root.u.def.section;
04347 #else
04348 long sdiff = slook->id - h->root.u.def.section->id;
04349 #endif
04350 if (sdiff < 0)
04351 j = idx;
04352 else if (sdiff > 0)
04353 i = idx + 1;
04354 else
04355 {
04356 ilook = idx;
04357 break;
04358 }
04359 }
04360 }
04361
04362
04363 if (ilook == -1)
04364 continue;
04365
04366 for (i = ilook; i < sym_count; i++)
04367 {
04368 h = sorted_sym_hash [i];
04369
04370
04371 if (h->root.u.def.value != vlook
04372 || h->root.u.def.section != slook)
04373 break;
04374 else if (h != hlook)
04375 {
04376 hlook->u.weakdef = h;
04377
04378
04379
04380
04381 if (hlook->dynindx != -1 && h->dynindx == -1)
04382 {
04383 if (! bfd_elf_link_record_dynamic_symbol (info, h))
04384 goto error_return;
04385 }
04386
04387
04388
04389
04390
04391
04392 if (h->dynindx != -1 && hlook->dynindx == -1)
04393 {
04394 if (! bfd_elf_link_record_dynamic_symbol (info, hlook))
04395 goto error_return;
04396 }
04397 break;
04398 }
04399 }
04400 }
04401
04402 free (sorted_sym_hash);
04403 }
04404
04405 check_directives = get_elf_backend_data (abfd)->check_directives;
04406 if (check_directives)
04407 check_directives (abfd, info);
04408
04409
04410
04411
04412
04413
04414
04415
04416
04417
04418
04419
04420
04421
04422
04423
04424
04425
04426 check_relocs = get_elf_backend_data (abfd)->check_relocs;
04427 if (! dynamic
04428 && is_elf_hash_table (hash_table)
04429 && hash_table->root.creator == abfd->xvec
04430 && check_relocs != NULL)
04431 {
04432 asection *o;
04433
04434 for (o = abfd->sections; o != NULL; o = o->next)
04435 {
04436 Elf_Internal_Rela *internal_relocs;
04437 bfd_boolean ok;
04438
04439 if ((o->flags & SEC_RELOC) == 0
04440 || o->reloc_count == 0
04441 || ((info->strip == strip_all || info->strip == strip_debugger)
04442 && (o->flags & SEC_DEBUGGING) != 0)
04443 || bfd_is_abs_section (o->output_section))
04444 continue;
04445
04446 internal_relocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL,
04447 info->keep_memory);
04448 if (internal_relocs == NULL)
04449 goto error_return;
04450
04451 ok = (*check_relocs) (abfd, info, o, internal_relocs);
04452
04453 if (elf_section_data (o)->relocs != internal_relocs)
04454 free (internal_relocs);
04455
04456 if (! ok)
04457 goto error_return;
04458 }
04459 }
04460
04461
04462
04463 if (! dynamic
04464 && ! info->traditional_format
04465 && is_elf_hash_table (hash_table)
04466 && (info->strip != strip_all && info->strip != strip_debugger))
04467 {
04468 asection *stabstr;
04469
04470 stabstr = bfd_get_section_by_name (abfd, ".stabstr");
04471 if (stabstr != NULL)
04472 {
04473 bfd_size_type string_offset = 0;
04474 asection *stab;
04475
04476 for (stab = abfd->sections; stab; stab = stab->next)
04477 if (strncmp (".stab", stab->name, 5) == 0
04478 && (!stab->name[5] ||
04479 (stab->name[5] == '.' && ISDIGIT (stab->name[6])))
04480 && (stab->flags & SEC_MERGE) == 0
04481 && !bfd_is_abs_section (stab->output_section))
04482 {
04483 struct bfd_elf_section_data *secdata;
04484
04485 secdata = elf_section_data (stab);
04486 if (! _bfd_link_section_stabs (abfd,
04487 &hash_table->stab_info,
04488 stab, stabstr,
04489 &secdata->sec_info,
04490 &string_offset))
04491 goto error_return;
04492 if (secdata->sec_info)
04493 stab->sec_info_type = ELF_INFO_TYPE_STABS;
04494 }
04495 }
04496 }
04497
04498 if (is_elf_hash_table (hash_table) && add_needed)
04499 {
04500
04501 struct elf_link_loaded_list *n;
04502
04503 n = bfd_alloc (abfd, sizeof (struct elf_link_loaded_list));
04504 if (n == NULL)
04505 goto error_return;
04506 n->abfd = abfd;
04507 n->next = hash_table->loaded;
04508 hash_table->loaded = n;
04509 }
04510
04511 return TRUE;
04512
04513 error_free_vers:
04514 if (nondeflt_vers != NULL)
04515 free (nondeflt_vers);
04516 if (extversym != NULL)
04517 free (extversym);
04518 error_free_sym:
04519 if (isymbuf != NULL)
04520 free (isymbuf);
04521 error_return:
04522 return FALSE;
04523 }
04524
04525
04526
04527
04528 struct elf_link_hash_entry *
04529 _bfd_elf_archive_symbol_lookup (bfd *abfd,
04530 struct bfd_link_info *info,
04531 const char *name)
04532 {
04533 struct elf_link_hash_entry *h;
04534 char *p, *copy;
04535 size_t len, first;
04536
04537 h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
04538 if (h != NULL)
04539 return h;
04540
04541
04542
04543
04544
04545
04546 p = strchr (name, ELF_VER_CHR);
04547 if (p == NULL || p[1] != ELF_VER_CHR)
04548 return h;
04549
04550
04551 len = strlen (name);
04552 copy = bfd_alloc (abfd, len);
04553 if (copy == NULL)
04554 return (struct elf_link_hash_entry *) 0 - 1;
04555
04556 first = p - name + 1;
04557 memcpy (copy, name, first);
04558 memcpy (copy + first, name + first + 1, len - first);
04559
04560 h = elf_link_hash_lookup (elf_hash_table (info), copy, FALSE, FALSE, FALSE);
04561 if (h == NULL)
04562 {
04563
04564
04565 copy[first - 1] = '\0';
04566 h = elf_link_hash_lookup (elf_hash_table (info), copy,
04567 FALSE, FALSE, FALSE);
04568 }
04569
04570 bfd_release (abfd, copy);
04571 return h;
04572 }
04573
04574
04575
04576
04577
04578
04579
04580
04581
04582
04583
04584
04585
04586
04587
04588
04589
04590
04591
04592
04593
04594
04595
04596
04597
04598
04599 static bfd_boolean
04600 elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
04601 {
04602 symindex c;
04603 bfd_boolean *defined = NULL;
04604 bfd_boolean *included = NULL;
04605 carsym *symdefs;
04606 bfd_boolean loop;
04607 bfd_size_type amt;
04608 const struct elf_backend_data *bed;
04609 struct elf_link_hash_entry * (*archive_symbol_lookup)
04610 (bfd *, struct bfd_link_info *, const char *);
04611
04612 if (! bfd_has_map (abfd))
04613 {
04614
04615 if (bfd_openr_next_archived_file (abfd, NULL) == NULL)
04616 return TRUE;
04617 bfd_set_error (bfd_error_no_armap);
04618 return FALSE;
04619 }
04620
04621
04622
04623
04624 c = bfd_ardata (abfd)->symdef_count;
04625 if (c == 0)
04626 return TRUE;
04627 amt = c;
04628 amt *= sizeof (bfd_boolean);
04629 defined = bfd_zmalloc (amt);
04630 included = bfd_zmalloc (amt);
04631 if (defined == NULL || included == NULL)
04632 goto error_return;
04633
04634 symdefs = bfd_ardata (abfd)->symdefs;
04635 bed = get_elf_backend_data (abfd);
04636 archive_symbol_lookup = bed->elf_backend_archive_symbol_lookup;
04637
04638 do
04639 {
04640 file_ptr last;
04641 symindex i;
04642 carsym *symdef;
04643 carsym *symdefend;
04644
04645 loop = FALSE;
04646 last = -1;
04647
04648 symdef = symdefs;
04649 symdefend = symdef + c;
04650 for (i = 0; symdef < symdefend; symdef++, i++)
04651 {
04652 struct elf_link_hash_entry *h;
04653 bfd *element;
04654 struct bfd_link_hash_entry *undefs_tail;
04655 symindex mark;
04656
04657 if (defined[i] || included[i])
04658 continue;
04659 if (symdef->file_offset == last)
04660 {
04661 included[i] = TRUE;
04662 continue;
04663 }
04664
04665 h = archive_symbol_lookup (abfd, info, symdef->name);
04666 if (h == (struct elf_link_hash_entry *) 0 - 1)
04667 goto error_return;
04668
04669 if (h == NULL)
04670 continue;
04671
04672 if (h->root.type == bfd_link_hash_common)
04673 {
04674
04675
04676
04677
04678
04679
04680
04681
04682
04683
04684
04685
04686 if (! elf_link_is_defined_archive_symbol (abfd, symdef))
04687 continue;
04688 }
04689 else if (h->root.type != bfd_link_hash_undefined)
04690 {
04691 if (h->root.type != bfd_link_hash_undefweak)
04692 defined[i] = TRUE;
04693 continue;
04694 }
04695
04696
04697 element = _bfd_get_elt_at_filepos (abfd, symdef->file_offset);
04698 if (element == NULL)
04699 goto error_return;
04700
04701 if (! bfd_check_format (element, bfd_object))
04702 goto error_return;
04703
04704
04705
04706
04707 if (element->archive_pass != 0)
04708 {
04709 #ifdef KEY // TODO: In binutils 2.14, the code continues rather than
04710
04711
04712
04713
04714 continue;
04715 #endif
04716 bfd_set_error (bfd_error_bad_value);
04717 goto error_return;
04718 }
04719 element->archive_pass = 1;
04720
04721 undefs_tail = info->hash->undefs_tail;
04722
04723 if (! (*info->callbacks->add_archive_element) (info, element,
04724 symdef->name))
04725 goto error_return;
04726 if (! bfd_link_add_symbols (element, info))
04727 goto error_return;
04728
04729 #ifdef IPA_LINK
04730
04731 if (ipa_is_whirl(element)) {
04732 ipa_process_whirl_in_archive(abfd, element);
04733 }
04734 #endif
04735
04736
04737
04738
04739
04740
04741
04742
04743 if (undefs_tail != info->hash->undefs_tail)
04744 loop = TRUE;
04745
04746
04747
04748 mark = i;
04749 do
04750 {
04751 included[mark] = TRUE;
04752 if (mark == 0)
04753 break;
04754 --mark;
04755 }
04756 while (symdefs[mark].file_offset == symdef->file_offset);
04757
04758
04759
04760 last = symdef->file_offset;
04761 }
04762 }
04763 while (loop);
04764
04765 free (defined);
04766 free (included);
04767
04768 return TRUE;
04769
04770 error_return:
04771 if (defined != NULL)
04772 free (defined);
04773 if (included != NULL)
04774 free (included);
04775 return FALSE;
04776 }
04777
04778
04779
04780
04781 bfd_boolean
04782 bfd_elf_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
04783 {
04784 switch (bfd_get_format (abfd))
04785 {
04786 case bfd_object:
04787 return elf_link_add_object_symbols (abfd, info);
04788 case bfd_archive:
04789 return elf_link_add_archive_symbols (abfd, info);
04790 default:
04791 bfd_set_error (bfd_error_wrong_format);
04792 return FALSE;
04793 }
04794 }
04795
04796
04797
04798
04799 static bfd_boolean
04800 elf_collect_hash_codes (struct elf_link_hash_entry *h, void *data)
04801 {
04802 unsigned long **valuep = data;
04803 const char *name;
04804 char *p;
04805 unsigned long ha;
04806 char *alc = NULL;
04807
04808 if (h->root.type == bfd_link_hash_warning)
04809 h = (struct elf_link_hash_entry *) h->root.u.i.link;
04810
04811
04812 if (h->dynindx == -1)
04813 return TRUE;
04814
04815 name = h->root.root.string;
04816 p = strchr (name, ELF_VER_CHR);
04817 if (p != NULL)
04818 {
04819 alc = bfd_malloc (p - name + 1);
04820 memcpy (alc, name, p - name);
04821 alc[p - name] = '\0';
04822 name = alc;
04823 }
04824
04825
04826 ha = bfd_elf_hash (name);
04827
04828
04829 *(*valuep)++ = ha;
04830
04831
04832
04833 h->u.elf_hash_value = ha;
04834
04835 if (alc != NULL)
04836 free (alc);
04837
04838 return TRUE;
04839 }
04840
04841
04842
04843
04844
04845
04846
04847 static const size_t elf_buckets[] =
04848 {
04849 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
04850 16411, 32771, 0
04851 };
04852
04853
04854
04855
04856
04857
04858
04859
04860
04861 static size_t
04862 compute_bucket_count (struct bfd_link_info *info)
04863 {
04864 size_t dynsymcount = elf_hash_table (info)->dynsymcount;
04865 size_t best_size = 0;
04866 unsigned long int *hashcodes;
04867 unsigned long int *hashcodesp;
04868 unsigned long int i;
04869 bfd_size_type amt;
04870
04871
04872
04873
04874 amt = dynsymcount;
04875 amt *= sizeof (unsigned long int);
04876 hashcodes = bfd_malloc (amt);
04877 if (hashcodes == NULL)
04878 return 0;
04879 hashcodesp = hashcodes;
04880
04881
04882 elf_link_hash_traverse (elf_hash_table (info),
04883 elf_collect_hash_codes, &hashcodesp);
04884
04885
04886
04887
04888 #ifdef BFD_HOST_U_64_BIT
04889 if (info->optimize)
04890 {
04891 unsigned long int nsyms = hashcodesp - hashcodes;
04892 size_t minsize;
04893 size_t maxsize;
04894 BFD_HOST_U_64_BIT best_chlen = ~((BFD_HOST_U_64_BIT) 0);
04895 unsigned long int *counts ;
04896 bfd *dynobj = elf_hash_table (info)->dynobj;
04897 const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
04898
04899
04900
04901
04902 minsize = nsyms / 4;
04903 if (minsize == 0)
04904 minsize = 1;
04905 best_size = maxsize = nsyms * 2;
04906
04907
04908
04909 amt = maxsize;
04910 amt *= sizeof (unsigned long int);
04911 counts = bfd_malloc (amt);
04912 if (counts == NULL)
04913 {
04914 free (hashcodes);
04915 return 0;
04916 }
04917
04918
04919
04920
04921 for (i = minsize; i < maxsize; ++i)
04922 {
04923
04924 BFD_HOST_U_64_BIT max;
04925 unsigned long int j;
04926 unsigned long int fact;
04927
04928 memset (counts, '\0', i * sizeof (unsigned long int));
04929
04930
04931 for (j = 0; j < nsyms; ++j)
04932 ++counts[hashcodes[j] % i];
04933
04934
04935
04936
04937
04938
04939 # ifndef BFD_TARGET_PAGESIZE
04940 # define BFD_TARGET_PAGESIZE (4096)
04941 # endif
04942
04943
04944
04945 max = (2 + nsyms) * (bed->s->arch_size / 8);
04946
04947 # if 1
04948
04949
04950
04951 for (j = 0; j < i; ++j)
04952 max += counts[j] * counts[j];
04953
04954
04955 fact = i / (BFD_TARGET_PAGESIZE / (bed->s->arch_size / 8)) + 1;
04956 max *= fact * fact;
04957 # else
04958
04959
04960
04961 for (j = 0; j < i; ++j)
04962 max += (1 + counts[j]) * (1 + counts[j]);
04963
04964
04965
04966 fact = i / (BFD_TARGET_PAGESIZE / (bed->s->arch_size / 8)) + 1;
04967 max *= fact;
04968 # endif
04969
04970
04971 if (max < best_chlen)
04972 {
04973 best_chlen = max;
04974 best_size = i;
04975 }
04976 }
04977
04978 free (counts);
04979 }
04980 else
04981 #endif
04982 {
04983
04984
04985
04986 for (i = 0; elf_buckets[i] != 0; i++)
04987 {
04988 best_size = elf_buckets[i];
04989 if (dynsymcount < elf_buckets[i + 1])
04990 break;
04991 }
04992 }
04993
04994
04995 free (hashcodes);
04996
04997 return best_size;
04998 }
04999
05000
05001
05002
05003
05004
05005 bfd_boolean
05006 bfd_elf_size_dynamic_sections (bfd *output_bfd,
05007 const char *soname,
05008 const char *rpath,
05009 const char *filter_shlib,
05010 const char * const *auxiliary_filters,
05011 struct bfd_link_info *info,
05012 asection **sinterpptr,
05013 struct bfd_elf_version_tree *verdefs)
05014 {
05015 bfd_size_type soname_indx;
05016 bfd *dynobj;
05017 const struct elf_backend_data *bed;
05018 struct elf_assign_sym_version_info asvinfo;
05019
05020 *sinterpptr = NULL;
05021
05022 soname_indx = (bfd_size_type) -1;
05023
05024 if (!is_elf_hash_table (info->hash))
05025 return TRUE;
05026
05027 elf_tdata (output_bfd)->relro = info->relro;
05028 if (info->execstack)
05029 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
05030 else if (info->noexecstack)
05031 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
05032 else
05033 {
05034 bfd *inputobj;
05035 asection *notesec = NULL;
05036 int exec = 0;
05037
05038 for (inputobj = info->input_bfds;
05039 inputobj;
05040 inputobj = inputobj->link_next)
05041 {
05042 asection *s;
05043
05044 if (inputobj->flags & (DYNAMIC | BFD_LINKER_CREATED))
05045 continue;
05046 s = bfd_get_section_by_name (inputobj, ".note.GNU-stack");
05047 if (s)
05048 {
05049 if (s->flags & SEC_CODE)
05050 exec = PF_X;
05051 notesec = s;
05052 }
05053 else
05054 exec = PF_X;
05055 }
05056 if (notesec)
05057 {
05058 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | exec;
05059 if (exec && info->relocatable
05060 && notesec->output_section != bfd_abs_section_ptr)
05061 notesec->output_section->flags |= SEC_CODE;
05062 }
05063 }
05064
05065
05066
05067 elf_hash_table (info)->init_refcount = elf_hash_table (info)->init_offset;
05068
05069
05070
05071 bed = get_elf_backend_data (output_bfd);
05072 if (bed->elf_backend_always_size_sections
05073 && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
05074 return FALSE;
05075
05076 dynobj = elf_hash_table (info)->dynobj;
05077
05078
05079
05080 if (dynobj == NULL)
05081 return TRUE;
05082
05083 if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
05084 return FALSE;
05085
05086 if (elf_hash_table (info)->dynamic_sections_created)
05087 {
05088 struct elf_info_failed eif;
05089 struct elf_link_hash_entry *h;
05090 asection *dynstr;
05091 struct bfd_elf_version_tree *t;
05092 struct bfd_elf_version_expr *d;
05093 bfd_boolean all_defined;
05094
05095 *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
05096 BFD_ASSERT (*sinterpptr != NULL || !info->executable);
05097
05098 if (soname != NULL)
05099 {
05100 soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
05101 soname, TRUE);
05102 if (soname_indx == (bfd_size_type) -1
05103 || !_bfd_elf_add_dynamic_entry (info, DT_SONAME, soname_indx))
05104 return FALSE;
05105 }
05106
05107 if (info->symbolic)
05108 {
05109 if (!_bfd_elf_add_dynamic_entry (info, DT_SYMBOLIC, 0))
05110 return FALSE;
05111 info->flags |= DF_SYMBOLIC;
05112 }
05113
05114 if (rpath != NULL)
05115 {
05116 bfd_size_type indx;
05117
05118 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, rpath,
05119 TRUE);
05120 if (indx == (bfd_size_type) -1
05121 || !_bfd_elf_add_dynamic_entry (info, DT_RPATH, indx))
05122 return FALSE;
05123
05124 if (info->new_dtags)
05125 {
05126 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, indx);
05127 if (!_bfd_elf_add_dynamic_entry (info, DT_RUNPATH, indx))
05128 return FALSE;
05129 }
05130 }
05131
05132 if (filter_shlib != NULL)
05133 {
05134 bfd_size_type indx;
05135
05136 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
05137 filter_shlib, TRUE);
05138 if (indx == (bfd_size_type) -1
05139 || !_bfd_elf_add_dynamic_entry (info, DT_FILTER, indx))
05140 return FALSE;
05141 }
05142
05143 if (auxiliary_filters != NULL)
05144 {
05145 const char * const *p;
05146
05147 for (p = auxiliary_filters; *p != NULL; p++)
05148 {
05149 bfd_size_type indx;
05150
05151 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
05152 *p, TRUE);
05153 if (indx == (bfd_size_type) -1
05154 || !_bfd_elf_add_dynamic_entry (info, DT_AUXILIARY, indx))
05155 return FALSE;
05156 }
05157 }
05158
05159 eif.info = info;
05160 eif.verdefs = verdefs;
05161 eif.failed = FALSE;
05162
05163
05164
05165 if (info->export_dynamic)
05166 {
05167 elf_link_hash_traverse (elf_hash_table (info),
05168 _bfd_elf_export_symbol,
05169 &eif);
05170 if (eif.failed)
05171 return FALSE;
05172 }
05173
05174
05175 for (t = verdefs; t != NULL; t = t->next)
05176 for (d = t->globals.list; d != NULL; d = d->next)
05177 if (!d->symver && d->symbol)
05178 {
05179 const char *verstr, *name;
05180 size_t namelen, verlen, newlen;
05181 char *newname, *p;
05182 struct elf_link_hash_entry *newh;
05183
05184 name = d->symbol;
05185 namelen = strlen (name);
05186 verstr = t->name;
05187 verlen = strlen (verstr);
05188 newlen = namelen + verlen + 3;
05189
05190 newname = bfd_malloc (newlen);
05191 if (newname == NULL)
05192 return FALSE;
05193 memcpy (newname, name, namelen);
05194
05195
05196 p = newname + namelen;
05197 *p++ = ELF_VER_CHR;
05198 memcpy (p, verstr, verlen + 1);
05199 newh = elf_link_hash_lookup (elf_hash_table (info),
05200 newname, FALSE, FALSE,
05201 FALSE);
05202 if (newh == NULL
05203 || (newh->root.type != bfd_link_hash_defined
05204 && newh->root.type != bfd_link_hash_defweak))
05205 {
05206
05207 *p++ = ELF_VER_CHR;
05208 memcpy (p, verstr, verlen + 1);
05209 newh = elf_link_hash_lookup (elf_hash_table (info),
05210 newname, FALSE, FALSE,
05211 FALSE);
05212 }
05213 free (newname);
05214
05215
05216
05217 if (newh != NULL
05218 && !newh->def_dynamic
05219 && (newh->root.type == bfd_link_hash_defined
05220 || newh->root.type == bfd_link_hash_defweak))
05221 d->symver = 1;
05222 }
05223
05224
05225 asvinfo.output_bfd = output_bfd;
05226 asvinfo.info = info;
05227 asvinfo.verdefs = verdefs;
05228 asvinfo.failed = FALSE;
05229
05230 elf_link_hash_traverse (elf_hash_table (info),
05231 _bfd_elf_link_assign_sym_version,
05232 &asvinfo);
05233 if (asvinfo.failed)
05234 return FALSE;
05235
05236 if (!info->allow_undefined_version)
05237 {
05238
05239 all_defined = TRUE;
05240 for (t = verdefs; t != NULL; t = t->next)
05241 for (d = t->globals.list; d != NULL; d = d->next)
05242 if (!d->symver && !d->script)
05243 {
05244 (*_bfd_error_handler)
05245 (_("%s: undefined version: %s"),
05246 d->pattern, t->name);
05247 all_defined = FALSE;
05248 }
05249
05250 if (!all_defined)
05251 {
05252 bfd_set_error (bfd_error_bad_value);
05253 return FALSE;
05254 }
05255 }
05256
05257
05258
05259 elf_link_hash_traverse (elf_hash_table (info),
05260 _bfd_elf_adjust_dynamic_symbol,
05261 &eif);
05262 if (eif.failed)
05263 return FALSE;
05264
05265
05266
05267
05268
05269
05270
05271 h = (info->init_function
05272 ? elf_link_hash_lookup (elf_hash_table (info),
05273 info->init_function, FALSE,
05274 FALSE, FALSE)
05275 : NULL);
05276 if (h != NULL
05277 && (h->ref_regular
05278 || h->def_regular))
05279 {
05280 if (!_bfd_elf_add_dynamic_entry (info, DT_INIT, 0))
05281 return FALSE;
05282 }
05283 h = (info->fini_function
05284 ? elf_link_hash_lookup (elf_hash_table (info),
05285 info->fini_function, FALSE,
05286 FALSE, FALSE)
05287 : NULL);
05288 if (h != NULL
05289 && (h->ref_regular
05290 || h->def_regular))
05291 {
05292 if (!_bfd_elf_add_dynamic_entry (info, DT_FINI, 0))
05293 return FALSE;
05294 }
05295
05296 if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
05297 {
05298
05299 if (! info->executable)
05300 {
05301 bfd *sub;
05302 asection *o;
05303
05304 for (sub = info->input_bfds; sub != NULL;
05305 sub = sub->link_next)
05306 for (o = sub->sections; o != NULL; o = o->next)
05307 if (elf_section_data (o)->this_hdr.sh_type
05308 == SHT_PREINIT_ARRAY)
05309 {
05310 (*_bfd_error_handler)
05311 (_("%B: .preinit_array section is not allowed in DSO"),
05312 sub);
05313 break;
05314 }
05315
05316 bfd_set_error (bfd_error_nonrepresentable_section);
05317 return FALSE;
05318 }
05319
05320 if (!_bfd_elf_add_dynamic_entry (info, DT_PREINIT_ARRAY, 0)
05321 || !_bfd_elf_add_dynamic_entry (info, DT_PREINIT_ARRAYSZ, 0))
05322 return FALSE;
05323 }
05324 if (bfd_get_section_by_name (output_bfd, ".init_array") != NULL)
05325 {
05326 if (!_bfd_elf_add_dynamic_entry (info, DT_INIT_ARRAY, 0)
05327 || !_bfd_elf_add_dynamic_entry (info, DT_INIT_ARRAYSZ, 0))
05328 return FALSE;
05329 }
05330 if (bfd_get_section_by_name (output_bfd, ".fini_array") != NULL)
05331 {
05332 if (!_bfd_elf_add_dynamic_entry (info, DT_FINI_ARRAY, 0)
05333 || !_bfd_elf_add_dynamic_entry (info, DT_FINI_ARRAYSZ, 0))
05334 return FALSE;
05335 }
05336
05337 dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
05338
05339
05340
05341
05342 if (dynstr != NULL && dynstr->output_section != bfd_abs_section_ptr)
05343 {
05344 bfd_size_type strsize;
05345
05346 strsize = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
05347 if (!_bfd_elf_add_dynamic_entry (info, DT_HASH, 0)
05348 || !_bfd_elf_add_dynamic_entry (info, DT_STRTAB, 0)
05349 || !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB, 0)
05350 || !_bfd_elf_add_dynamic_entry (info, DT_STRSZ, strsize)
05351 || !_bfd_elf_add_dynamic_entry (info, DT_SYMENT,
05352 bed->s->sizeof_sym))
05353 return FALSE;
05354 }
05355 }
05356
05357
05358
05359 if (bed->elf_backend_size_dynamic_sections
05360 && ! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info))
05361 return FALSE;
05362
05363 if (elf_hash_table (info)->dynamic_sections_created)
05364 {
05365 bfd_size_type dynsymcount;
05366 asection *s;
05367 size_t bucketcount = 0;
05368 size_t hash_entry_size;
05369 unsigned int dtagcount;
05370
05371
05372 s = bfd_get_section_by_name (dynobj, ".gnu.version_d");
05373 BFD_ASSERT (s != NULL);
05374
05375
05376
05377 verdefs = asvinfo.verdefs;
05378
05379
05380 if (verdefs != NULL && verdefs->vernum == 0)
05381 verdefs = verdefs->next;
05382
05383 if (verdefs == NULL && !info->create_default_symver)
05384 _bfd_strip_section_from_output (info, s);
05385 else
05386 {
05387 unsigned int cdefs;
05388 bfd_size_type size;
05389 struct bfd_elf_version_tree *t;
05390 bfd_byte *p;
05391 Elf_Internal_Verdef def;
05392 Elf_Internal_Verdaux defaux;
05393 struct bfd_link_hash_entry *bh;
05394 struct elf_link_hash_entry *h;
05395 const char *name;
05396
05397 cdefs = 0;
05398 size = 0;
05399
05400
05401 size += sizeof (Elf_External_Verdef);
05402 size += sizeof (Elf_External_Verdaux);
05403 ++cdefs;
05404
05405
05406 if (info->create_default_symver)
05407 {
05408 size += sizeof (Elf_External_Verdef);
05409 ++cdefs;
05410 }
05411
05412 for (t = verdefs; t != NULL; t = t->next)
05413 {
05414 struct bfd_elf_version_deps *n;
05415
05416 size += sizeof (Elf_External_Verdef);
05417 size += sizeof (Elf_External_Verdaux);
05418 ++cdefs;
05419
05420 for (n = t->deps; n != NULL; n = n->next)
05421 size += sizeof (Elf_External_Verdaux);
05422 }
05423
05424 s->size = size;
05425 s->contents = bfd_alloc (output_bfd, s->size);
05426 if (s->contents == NULL && s->size != 0)
05427 return FALSE;
05428
05429
05430
05431 p = s->contents;
05432
05433 def.vd_version = VER_DEF_CURRENT;
05434 def.vd_flags = VER_FLG_BASE;
05435 def.vd_ndx = 1;
05436 def.vd_cnt = 1;
05437 if (info->create_default_symver)
05438 {
05439 def.vd_aux = 2 * sizeof (Elf_External_Verdef);
05440 def.vd_next = sizeof (Elf_External_Verdef);
05441 }
05442 else
05443 {
05444 def.vd_aux = sizeof (Elf_External_Verdef);
05445 def.vd_next = (sizeof (Elf_External_Verdef)
05446 + sizeof (Elf_External_Verdaux));
05447 }
05448
05449 if (soname_indx != (bfd_size_type) -1)
05450 {
05451 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
05452 soname_indx);
05453 def.vd_hash = bfd_elf_hash (soname);
05454 defaux.vda_name = soname_indx;
05455 name = soname;
05456 }
05457 else
05458 {
05459 bfd_size_type indx;
05460
05461 name = basename (output_bfd->filename);
05462 def.vd_hash = bfd_elf_hash (name);
05463 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
05464 name, FALSE);
05465 if (indx == (bfd_size_type) -1)
05466 return FALSE;
05467 defaux.vda_name = indx;
05468 }
05469 defaux.vda_next = 0;
05470
05471 _bfd_elf_swap_verdef_out (output_bfd, &def,
05472 (Elf_External_Verdef *) p);
05473 p += sizeof (Elf_External_Verdef);
05474 if (info->create_default_symver)
05475 {
05476
05477 bh = NULL;
05478 if (! (_bfd_generic_link_add_one_symbol
05479 (info, dynobj, name, BSF_GLOBAL, bfd_abs_section_ptr,
05480 0, NULL, FALSE,
05481 get_elf_backend_data (dynobj)->collect, &bh)))
05482 return FALSE;
05483 h = (struct elf_link_hash_entry *) bh;
05484 h->non_elf = 0;
05485 h->def_regular = 1;
05486 h->type = STT_OBJECT;
05487 h->verinfo.vertree = NULL;
05488
05489 if (! bfd_elf_link_record_dynamic_symbol (info, h))
05490 return FALSE;
05491
05492
05493
05494 def.vd_flags = 0;
05495 def.vd_ndx = 2;
05496 def.vd_aux = sizeof (Elf_External_Verdef);
05497 if (verdefs)
05498 def.vd_next = (sizeof (Elf_External_Verdef)
05499 + sizeof (Elf_External_Verdaux));
05500 else
05501 def.vd_next = 0;
05502 _bfd_elf_swap_verdef_out (output_bfd, &def,
05503 (Elf_External_Verdef *) p);
05504 p += sizeof (Elf_External_Verdef);
05505 }
05506 _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
05507 (Elf_External_Verdaux *) p);
05508 p += sizeof (Elf_External_Verdaux);
05509
05510 for (t = verdefs; t != NULL; t = t->next)
05511 {
05512 unsigned int cdeps;
05513 struct bfd_elf_version_deps *n;
05514
05515 cdeps = 0;
05516 for (n = t->deps; n != NULL; n = n->next)
05517 ++cdeps;
05518
05519
05520 bh = NULL;
05521 if (! (_bfd_generic_link_add_one_symbol
05522 (info, dynobj, t->name, BSF_GLOBAL, bfd_abs_section_ptr,
05523 0, NULL, FALSE,
05524 get_elf_backend_data (dynobj)->collect, &bh)))
05525 return FALSE;
05526 h = (struct elf_link_hash_entry *) bh;
05527 h->non_elf = 0;
05528 h->def_regular = 1;
05529 h->type = STT_OBJECT;
05530 h->verinfo.vertree = t;
05531
05532 if (! bfd_elf_link_record_dynamic_symbol (info, h))
05533 return FALSE;
05534
05535 def.vd_version = VER_DEF_CURRENT;
05536 def.vd_flags = 0;
05537 if (t->globals.list == NULL
05538 && t->locals.list == NULL
05539 && ! t->used)
05540 def.vd_flags |= VER_FLG_WEAK;
05541 def.vd_ndx = t->vernum + (info->create_default_symver ? 2 : 1);
05542 def.vd_cnt = cdeps + 1;
05543 def.vd_hash = bfd_elf_hash (t->name);
05544 def.vd_aux = sizeof (Elf_External_Verdef);
05545 def.vd_next = 0;
05546 if (t->next != NULL)
05547 def.vd_next = (sizeof (Elf_External_Verdef)
05548 + (cdeps + 1) * sizeof (Elf_External_Verdaux));
05549
05550 _bfd_elf_swap_verdef_out (output_bfd, &def,
05551 (Elf_External_Verdef *) p);
05552 p += sizeof (Elf_External_Verdef);
05553
05554 defaux.vda_name = h->dynstr_index;
05555 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
05556 h->dynstr_index);
05557 defaux.vda_next = 0;
05558 if (t->deps != NULL)
05559 defaux.vda_next = sizeof (Elf_External_Verdaux);
05560 t->name_indx = defaux.vda_name;
05561
05562 _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
05563 (Elf_External_Verdaux *) p);
05564 p += sizeof (Elf_External_Verdaux);
05565
05566 for (n = t->deps; n != NULL; n = n->next)
05567 {
05568 if (n->version_needed == NULL)
05569 {
05570
05571
05572 defaux.vda_name = 0;
05573 }
05574 else
05575 {
05576 defaux.vda_name = n->version_needed->name_indx;
05577 _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
05578 defaux.vda_name);
05579 }
05580 if (n->next == NULL)
05581 defaux.vda_next = 0;
05582 else
05583 defaux.vda_next = sizeof (Elf_External_Verdaux);
05584
05585 _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
05586 (Elf_External_Verdaux *) p);
05587 p += sizeof (Elf_External_Verdaux);
05588 }
05589 }
05590
05591 if (!_bfd_elf_add_dynamic_entry (info, DT_VERDEF, 0)
05592 || !_bfd_elf_add_dynamic_entry (info, DT_VERDEFNUM, cdefs))
05593 return FALSE;
05594
05595 elf_tdata (output_bfd)->cverdefs = cdefs;
05596 }
05597
05598 if ((info->new_dtags && info->flags) || (info->flags & DF_STATIC_TLS))
05599 {
05600 if (!_bfd_elf_add_dynamic_entry (info, DT_FLAGS, info->flags))
05601 return FALSE;
05602 }
05603 else if (info->flags & DF_BIND_NOW)
05604 {
05605 if (!_bfd_elf_add_dynamic_entry (info, DT_BIND_NOW, 0))
05606 return FALSE;
05607 }
05608
05609 if (info->flags_1)
05610 {
05611 if (info->executable)
05612 info->flags_1 &= ~ (DF_1_INITFIRST
05613 | DF_1_NODELETE
05614 | DF_1_NOOPEN);
05615 if (!_bfd_elf_add_dynamic_entry (info, DT_FLAGS_1, info->flags_1))
05616 return FALSE;
05617 }
05618
05619
05620
05621 s = bfd_get_section_by_name (dynobj, ".gnu.version_r");
05622 BFD_ASSERT (s != NULL);
05623 {
05624 struct elf_find_verdep_info sinfo;
05625
05626 sinfo.output_bfd = output_bfd;
05627 sinfo.info = info;
05628 sinfo.vers = elf_tdata (output_bfd)->cverdefs;
05629 if (sinfo.vers == 0)
05630 sinfo.vers = 1;
05631 sinfo.failed = FALSE;
05632
05633 elf_link_hash_traverse (elf_hash_table (info),
05634 _bfd_elf_link_find_version_dependencies,
05635 &sinfo);
05636
05637 if (elf_tdata (output_bfd)->verref == NULL)
05638 _bfd_strip_section_from_output (info, s);
05639 else
05640 {
05641 Elf_Internal_Verneed *t;
05642 unsigned int size;
05643 unsigned int crefs;
05644 bfd_byte *p;
05645
05646
05647 size = 0;
05648 crefs = 0;
05649 for (t = elf_tdata (output_bfd)->verref;
05650 t != NULL;
05651 t = t->vn_nextref)
05652 {
05653 Elf_Internal_Vernaux *a;
05654
05655 size += sizeof (Elf_External_Verneed);
05656 ++crefs;
05657 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
05658 size += sizeof (Elf_External_Vernaux);
05659 }
05660
05661 s->size = size;
05662 s->contents = bfd_alloc (output_bfd, s->size);
05663 if (s->contents == NULL)
05664 return FALSE;
05665
05666 p = s->contents;
05667 for (t = elf_tdata (output_bfd)->verref;
05668 t != NULL;
05669 t = t->vn_nextref)
05670 {
05671 unsigned int caux;
05672 Elf_Internal_Vernaux *a;
05673 bfd_size_type indx;
05674
05675 caux = 0;
05676 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
05677 ++caux;
05678
05679 t->vn_version = VER_NEED_CURRENT;
05680 t->vn_cnt = caux;
05681 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
05682 elf_dt_name (t->vn_bfd) != NULL
05683 ? elf_dt_name (t->vn_bfd)
05684 : basename (t->vn_bfd->filename),
05685 FALSE);
05686 if (indx == (bfd_size_type) -1)
05687 return FALSE;
05688 t->vn_file = indx;
05689 t->vn_aux = sizeof (Elf_External_Verneed);
05690 if (t->vn_nextref == NULL)
05691 t->vn_next = 0;
05692 else
05693 t->vn_next = (sizeof (Elf_External_Verneed)
05694 + caux * sizeof (Elf_External_Vernaux));
05695
05696 _bfd_elf_swap_verneed_out (output_bfd, t,
05697 (Elf_External_Verneed *) p);
05698 p += sizeof (Elf_External_Verneed);
05699
05700 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
05701 {
05702 a->vna_hash = bfd_elf_hash (a->vna_nodename);
05703 indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
05704 a->vna_nodename, FALSE);
05705 if (indx == (bfd_size_type) -1)
05706 return FALSE;
05707 a->vna_name = indx;
05708 if (a->vna_nextptr == NULL)
05709 a->vna_next = 0;
05710 else
05711 a->vna_next = sizeof (Elf_External_Vernaux);
05712
05713 _bfd_elf_swap_vernaux_out (output_bfd, a,
05714 (Elf_External_Vernaux *) p);
05715 p += sizeof (Elf_External_Vernaux);
05716 }
05717 }
05718
05719 if (!_bfd_elf_add_dynamic_entry (info, DT_VERNEED, 0)
05720 || !_bfd_elf_add_dynamic_entry (info, DT_VERNEEDNUM, crefs))
05721 return FALSE;
05722
05723 elf_tdata (output_bfd)->cverrefs = crefs;
05724 }
05725 }
05726
05727
05728
05729
05730
05731
05732 dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info);
05733
05734
05735 s = bfd_get_section_by_name (dynobj, ".gnu.version");
05736 BFD_ASSERT (s != NULL);
05737 if (dynsymcount == 0
05738 || (verdefs == NULL && elf_tdata (output_bfd)->verref == NULL
05739 && !info->create_default_symver))
05740 {
05741 _bfd_strip_section_from_output (info, s);
05742
05743
05744 dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info);
05745 }
05746 else
05747 {
05748 s->size = dynsymcount * sizeof (Elf_External_Versym);
05749 s->contents = bfd_zalloc (output_bfd, s->size);
05750 if (s->contents == NULL)
05751 return FALSE;
05752
05753 if (!_bfd_elf_add_dynamic_entry (info, DT_VERSYM, 0))
05754 return FALSE;
05755 }
05756
05757
05758
05759
05760
05761
05762
05763 s = bfd_get_section_by_name (dynobj, ".dynsym");
05764 BFD_ASSERT (s != NULL);
05765 s->size = dynsymcount * bed->s->sizeof_sym;
05766 s->contents = bfd_alloc (output_bfd, s->size);
05767 if (s->contents == NULL && s->size != 0)
05768 return FALSE;
05769
05770 if (dynsymcount != 0)
05771 {
05772 Elf_Internal_Sym isym;
05773
05774
05775 isym.st_value = 0;
05776 isym.st_size = 0;
05777 isym.st_name = 0;
05778 isym.st_info = 0;
05779 isym.st_other = 0;
05780 isym.st_shndx = 0;
05781 bed->s->swap_symbol_out (output_bfd, &isym, s->contents, 0);
05782 }
05783
05784
05785
05786 bucketcount = compute_bucket_count (info);
05787
05788 s = bfd_get_section_by_name (dynobj, ".hash");
05789 BFD_ASSERT (s != NULL);
05790 hash_entry_size = elf_section_data (s)->this_hdr.sh_entsize;
05791 s->size = ((2 + bucketcount + dynsymcount) * hash_entry_size);
05792 s->contents = bfd_zalloc (output_bfd, s->size);
05793 if (s->contents == NULL)
05794 return FALSE;
05795
05796 bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents);
05797 bfd_put (8 * hash_entry_size, output_bfd, dynsymcount,
05798 s->contents + hash_entry_size);
05799
05800 elf_hash_table (info)->bucketcount = bucketcount;
05801
05802 s = bfd_get_section_by_name (dynobj, ".dynstr");
05803 BFD_ASSERT (s != NULL);
05804
05805 elf_finalize_dynstr (output_bfd, info);
05806
05807 s->size = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
05808
05809 for (dtagcount = 0; dtagcount <= info->spare_dynamic_tags; ++dtagcount)
05810 if (!_bfd_elf_add_dynamic_entry (info, DT_NULL, 0))
05811 return FALSE;
05812 }
05813
05814 return TRUE;
05815 }
05816
05817
05818
05819
05820
05821 struct elf_final_link_info
05822 {
05823
05824 struct bfd_link_info *info;
05825
05826 bfd *output_bfd;
05827
05828 struct bfd_strtab_hash *symstrtab;
05829
05830 asection *dynsym_sec;
05831
05832 asection *hash_sec;
05833
05834 asection *symver_sec;
05835
05836 bfd_byte *contents;
05837
05838 void *external_relocs;
05839
05840 Elf_Internal_Rela *internal_relocs;
05841
05842
05843 bfd_byte *external_syms;
05844
05845 Elf_External_Sym_Shndx *locsym_shndx;
05846
05847
05848 Elf_Internal_Sym *internal_syms;
05849
05850
05851 long *indices;
05852
05853
05854 asection **sections;
05855
05856 bfd_byte *symbuf;
05857
05858 Elf_External_Sym_Shndx *symshndxbuf;
05859
05860 size_t symbuf_count;
05861
05862 size_t symbuf_size;
05863
05864 size_t shndxbuf_size;
05865 };
05866
05867
05868
05869 struct elf_outext_info
05870 {
05871 bfd_boolean failed;
05872 bfd_boolean localsyms;
05873 struct elf_final_link_info *finfo;
05874 };
05875
05876
05877
05878
05879
05880
05881 static void
05882 elf_link_adjust_relocs (bfd *abfd,
05883 Elf_Internal_Shdr *rel_hdr,
05884 unsigned int count,
05885 struct elf_link_hash_entry **rel_hash)
05886 {
05887 unsigned int i;
05888 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
05889 bfd_byte *erela;
05890 void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
05891 void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
05892 bfd_vma r_type_mask;
05893 int r_sym_shift;
05894
05895 if (rel_hdr->sh_entsize == bed->s->sizeof_rel)
05896 {
05897 swap_in = bed->s->swap_reloc_in;
05898 swap_out = bed->s->swap_reloc_out;
05899 }
05900 else if (rel_hdr->sh_entsize == bed->s->sizeof_rela)
05901 {
05902 swap_in = bed->s->swap_reloca_in;
05903 swap_out = bed->s->swap_reloca_out;
05904 }
05905 else
05906 abort ();
05907
05908 if (bed->s->int_rels_per_ext_rel > MAX_INT_RELS_PER_EXT_REL)
05909 abort ();
05910
05911 if (bed->s->arch_size == 32)
05912 {
05913 r_type_mask = 0xff;
05914 r_sym_shift = 8;
05915 }
05916 else
05917 {
05918 r_type_mask = 0xffffffff;
05919 r_sym_shift = 32;
05920 }
05921
05922 erela = rel_hdr->contents;
05923 for (i = 0; i < count; i++, rel_hash++, erela += rel_hdr->sh_entsize)
05924 {
05925 Elf_Internal_Rela irela[MAX_INT_RELS_PER_EXT_REL];
05926 unsigned int j;
05927
05928 if (*rel_hash == NULL)
05929 continue;
05930
05931 BFD_ASSERT ((*rel_hash)->indx >= 0);
05932
05933 (*swap_in) (abfd, erela, irela);
05934 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
05935 irela[j].r_info = ((bfd_vma) (*rel_hash)->indx << r_sym_shift
05936 | (irela[j].r_info & r_type_mask));
05937 (*swap_out) (abfd, irela, erela);
05938 }
05939 }
05940
05941 struct elf_link_sort_rela
05942 {
05943 union {
05944 bfd_vma offset;
05945 bfd_vma sym_mask;
05946 } u;
05947 enum elf_reloc_type_class type;
05948
05949 Elf_Internal_Rela rela[1];
05950 };
05951
05952 static int
05953 elf_link_sort_cmp1 (const void *A, const void *B)
05954 {
05955 const struct elf_link_sort_rela *a = A;
05956 const struct elf_link_sort_rela *b = B;
05957 int relativea, relativeb;
05958
05959 relativea = a->type == reloc_class_relative;
05960 relativeb = b->type == reloc_class_relative;
05961
05962 if (relativea < relativeb)
05963 return 1;
05964 if (relativea > relativeb)
05965 return -1;
05966 if ((a->rela->r_info & a->u.sym_mask) < (b->rela->r_info & b->u.sym_mask))
05967 return -1;
05968 if ((a->rela->r_info & a->u.sym_mask) > (b->rela->r_info & b->u.sym_mask))
05969 return 1;
05970 if (a->rela->r_offset < b->rela->r_offset)
05971 return -1;
05972 if (a->rela->r_offset > b->rela->r_offset)
05973 return 1;
05974 return 0;
05975 }
05976
05977 static int
05978 elf_link_sort_cmp2 (const void *A, const void *B)
05979 {
05980 const struct elf_link_sort_rela *a = A;
05981 const struct elf_link_sort_rela *b = B;
05982 int copya, copyb;
05983
05984 if (a->u.offset < b->u.offset)
05985 return -1;
05986 if (a->u.offset > b->u.offset)
05987 return 1;
05988 copya = (a->type == reloc_class_copy) * 2 + (a->type == reloc_class_plt);
05989 copyb = (b->type == reloc_class_copy) * 2 + (b->type == reloc_class_plt);
05990 if (copya < copyb)
05991 return -1;
05992 if (copya > copyb)
05993 return 1;
05994 if (a->rela->r_offset < b->rela->r_offset)
05995 return -1;
05996 if (a->rela->r_offset > b->rela->r_offset)
05997 return 1;
05998 return 0;
05999 }
06000
06001 static size_t
06002 elf_link_sort_relocs (bfd *abfd, struct bfd_link_info *info, asection **psec)
06003 {
06004 asection *reldyn;
06005 bfd_size_type count, size;
06006 size_t i, ret, sort_elt, ext_size;
06007 bfd_byte *sort, *s_non_relative, *p;
06008 struct elf_link_sort_rela *sq;
06009 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
06010 int i2e = bed->s->int_rels_per_ext_rel;
06011 void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
06012 void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
06013 struct bfd_link_order *lo;
06014 bfd_vma r_sym_mask;
06015
06016 reldyn = bfd_get_section_by_name (abfd, ".rela.dyn");
06017 if (reldyn == NULL || reldyn->size == 0)
06018 {
06019 reldyn = bfd_get_section_by_name (abfd, ".rel.dyn");
06020 if (reldyn == NULL || reldyn->size == 0)
06021 return 0;
06022 ext_size = bed->s->sizeof_rel;
06023 swap_in = bed->s->swap_reloc_in;
06024 swap_out = bed->s->swap_reloc_out;
06025 }
06026 else
06027 {
06028 ext_size = bed->s->sizeof_rela;
06029 swap_in = bed->s->swap_reloca_in;
06030 swap_out = bed->s->swap_reloca_out;
06031 }
06032 count = reldyn->size / ext_size;
06033
06034 size = 0;
06035 for (lo = reldyn->link_order_head; lo != NULL; lo = lo->next)
06036 if (lo->type == bfd_indirect_link_order)
06037 {
06038 asection *o = lo->u.indirect.section;
06039 size += o->size;
06040 }
06041
06042 if (size != reldyn->size)
06043 return 0;
06044
06045 sort_elt = (sizeof (struct elf_link_sort_rela)
06046 + (i2e - 1) * sizeof (Elf_Internal_Rela));
06047 sort = bfd_zmalloc (sort_elt * count);
06048 if (sort == NULL)
06049 {
06050 (*info->callbacks->warning)
06051 (info, _("Not enough memory to sort relocations"), 0, abfd, 0, 0);
06052 return 0;
06053 }
06054
06055 if (bed->s->arch_size == 32)
06056 r_sym_mask = ~(bfd_vma) 0xff;
06057 else
06058 r_sym_mask = ~(bfd_vma) 0xffffffff;
06059
06060 for (lo = reldyn->link_order_head; lo != NULL; lo = lo->next)
06061 if (lo->type == bfd_indirect_link_order)
06062 {
06063 bfd_byte *erel, *erelend;
06064 asection *o = lo->u.indirect.section;
06065
06066 if (o->contents == NULL && o->size != 0)
06067 {
06068
06069
06070
06071 free (sort);
06072 return 0;
06073 }
06074 erel = o->contents;
06075 erelend = o->contents + o->size;
06076 p = sort + o->output_offset / ext_size * sort_elt;
06077 while (erel < erelend)
06078 {
06079 struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p;
06080 (*swap_in) (abfd, erel, s->rela);
06081 s->type = (*bed->elf_backend_reloc_type_class) (s->rela);
06082 s->u.sym_mask = r_sym_mask;
06083 p += sort_elt;
06084 erel += ext_size;
06085 }
06086 }
06087
06088 qsort (sort, count, sort_elt, elf_link_sort_cmp1);
06089
06090 for (i = 0, p = sort; i < count; i++, p += sort_elt)
06091 {
06092 struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p;
06093 if (s->type != reloc_class_relative)
06094 break;
06095 }
06096 ret = i;
06097 s_non_relative = p;
06098
06099 sq = (struct elf_link_sort_rela *) s_non_relative;
06100 for (; i < count; i++, p += sort_elt)
06101 {
06102 struct elf_link_sort_rela *sp = (struct elf_link_sort_rela *) p;
06103 if (((sp->rela->r_info ^ sq->rela->r_info) & r_sym_mask) != 0)
06104 sq = sp;
06105 sp->u.offset = sq->rela->r_offset;
06106 }
06107
06108 qsort (s_non_relative, count - ret, sort_elt, elf_link_sort_cmp2);
06109
06110 for (lo = reldyn->link_order_head; lo != NULL; lo = lo->next)
06111 if (lo->type == bfd_indirect_link_order)
06112 {
06113 bfd_byte *erel, *erelend;
06114 asection *o = lo->u.indirect.section;
06115
06116 erel = o->contents;
06117 erelend = o->contents + o->size;
06118 p = sort + o->output_offset / ext_size * sort_elt;
06119 while (erel < erelend)
06120 {
06121 struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p;
06122 (*swap_out) (abfd, s->rela, erel);
06123 p += sort_elt;
06124 erel += ext_size;
06125 }
06126 }
06127
06128 free (sort);
06129 *psec = reldyn;
06130 return ret;
06131 }
06132
06133
06134
06135 static bfd_boolean
06136 elf_link_flush_output_syms (struct elf_final_link_info *finfo,
06137 const struct elf_backend_data *bed)
06138 {
06139 if (finfo->symbuf_count > 0)
06140 {
06141 Elf_Internal_Shdr *hdr;
06142 file_ptr pos;
06143 bfd_size_type amt;
06144
06145 hdr = &elf_tdata (finfo->output_bfd)->symtab_hdr;
06146 pos = hdr->sh_offset + hdr->sh_size;
06147 amt = finfo->symbuf_count * bed->s->sizeof_sym;
06148 if (bfd_seek (finfo->output_bfd, pos, SEEK_SET) != 0
06149 || bfd_bwrite (finfo->symbuf, amt, finfo->output_bfd) != amt)
06150 return FALSE;
06151
06152 hdr->sh_size += amt;
06153 finfo->symbuf_count = 0;
06154 }
06155
06156 return TRUE;
06157 }
06158
06159
06160
06161 static bfd_boolean
06162 elf_link_output_sym (struct elf_final_link_info *finfo,
06163 const char *name,
06164 Elf_Internal_Sym *elfsym,
06165 asection *input_sec,
06166 struct elf_link_hash_entry *h)
06167 {
06168 bfd_byte *dest;
06169 Elf_External_Sym_Shndx *destshndx;
06170 bfd_boolean (*output_symbol_hook)
06171 (struct bfd_link_info *, const char *, Elf_Internal_Sym *, asection *,
06172 struct elf_link_hash_entry *);
06173 const struct elf_backend_data *bed;
06174
06175 bed = get_elf_backend_data (finfo->output_bfd);
06176 output_symbol_hook = bed->elf_backend_link_output_symbol_hook;
06177 if (output_symbol_hook != NULL)
06178 {
06179 if (! (*output_symbol_hook) (finfo->info, name, elfsym, input_sec, h))
06180 return FALSE;
06181 }
06182
06183 if (name == NULL || *name == '\0')
06184 elfsym->st_name = 0;
06185 else if (input_sec->flags & SEC_EXCLUDE)
06186 elfsym->st_name = 0;
06187 else
06188 {
06189 elfsym->st_name = (unsigned long) _bfd_stringtab_add (finfo->symstrtab,
06190 name, TRUE, FALSE);
06191 if (elfsym->st_name == (unsigned long) -1)
06192 return FALSE;
06193 }
06194
06195 if (finfo->symbuf_count >= finfo->symbuf_size)
06196 {
06197 if (! elf_link_flush_output_syms (finfo, bed))
06198 return FALSE;
06199 }
06200
06201 dest = finfo->symbuf + finfo->symbuf_count * bed->s->sizeof_sym;
06202 destshndx = finfo->symshndxbuf;
06203 if (destshndx != NULL)
06204 {
06205 if (bfd_get_symcount (finfo->output_bfd) >= finfo->shndxbuf_size)
06206 {
06207 bfd_size_type amt;
06208
06209 amt = finfo->shndxbuf_size * sizeof (Elf_External_Sym_Shndx);
06210 finfo->symshndxbuf = destshndx = bfd_realloc (destshndx, amt * 2);
06211 if (destshndx == NULL)
06212 return FALSE;
06213 memset ((char *) destshndx + amt, 0, amt);
06214 finfo->shndxbuf_size *= 2;
06215 }
06216 destshndx += bfd_get_symcount (finfo->output_bfd);
06217 }
06218
06219 bed->s->swap_symbol_out (finfo->output_bfd, elfsym, dest, destshndx);
06220 finfo->symbuf_count += 1;
06221 bfd_get_symcount (finfo->output_bfd) += 1;
06222
06223 return TRUE;
06224 }
06225
06226
06227
06228
06229
06230
06231
06232 static bfd_boolean
06233 elf_link_check_versioned_symbol (struct bfd_link_info *info,
06234 const struct elf_backend_data *bed,
06235 struct elf_link_hash_entry *h)
06236 {
06237 bfd *abfd;
06238 struct elf_link_loaded_list *loaded;
06239
06240 if (!is_elf_hash_table (info->hash))
06241 return FALSE;
06242
06243 switch (h->root.type)
06244 {
06245 default:
06246 abfd = NULL;
06247 break;
06248
06249 case bfd_link_hash_undefined:
06250 case bfd_link_hash_undefweak:
06251 abfd = h->root.u.undef.abfd;
06252 if ((abfd->flags & DYNAMIC) == 0
06253 || (elf_dyn_lib_class (abfd) & DYN_DT_NEEDED) == 0)
06254 return FALSE;
06255 break;
06256
06257 case bfd_link_hash_defined:
06258 case bfd_link_hash_defweak:
06259 abfd = h->root.u.def.section->owner;
06260 break;
06261
06262 case bfd_link_hash_common:
06263 abfd = h->root.u.c.p->section->owner;
06264 break;
06265 }
06266 BFD_ASSERT (abfd != NULL);
06267
06268 for (loaded = elf_hash_table (info)->loaded;
06269 loaded != NULL;
06270 loaded = loaded->next)
06271 {
06272 bfd *input;
06273 Elf_Internal_Shdr *hdr;
06274 bfd_size_type symcount;
06275 bfd_size_type extsymcount;
06276 bfd_size_type extsymoff;
06277 Elf_Internal_Shdr *versymhdr;
06278 Elf_Internal_Sym *isym;
06279 Elf_Internal_Sym *isymend;
06280 Elf_Internal_Sym *isymbuf;
06281 Elf_External_Versym *ever;
06282 Elf_External_Versym *extversym;
06283
06284 input = loaded->abfd;
06285
06286
06287 if (input == abfd
06288 || (input->flags & DYNAMIC) == 0
06289 || elf_dynversym (input) == 0)
06290 continue;
06291
06292 hdr = &elf_tdata (input)->dynsymtab_hdr;
06293
06294 symcount = hdr->sh_size / bed->s->sizeof_sym;
06295 if (elf_bad_symtab (input))
06296 {
06297 extsymcount = symcount;
06298 extsymoff = 0;
06299 }
06300 else
06301 {
06302 extsymcount = symcount - hdr->sh_info;
06303 extsymoff = hdr->sh_info;
06304 }
06305
06306 if (extsymcount == 0)
06307 continue;
06308
06309 isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
06310 NULL, NULL, NULL);
06311 if (isymbuf == NULL)
06312 return FALSE;
06313
06314
06315 versymhdr = &elf_tdata (input)->dynversym_hdr;
06316 extversym = bfd_malloc (versymhdr->sh_size);
06317 if (extversym == NULL)
06318 goto error_ret;
06319
06320 if (bfd_seek (input, versymhdr->sh_offset, SEEK_SET) != 0
06321 || (bfd_bread (extversym, versymhdr->sh_size, input)
06322 != versymhdr->sh_size))
06323 {
06324 free (extversym);
06325 error_ret:
06326 free (isymbuf);
06327 return FALSE;
06328 }
06329
06330 ever = extversym + extsymoff;
06331 isymend = isymbuf + extsymcount;
06332 for (isym = isymbuf; isym < isymend; isym++, ever++)
06333 {
06334 const char *name;
06335 Elf_Internal_Versym iver;
06336 unsigned short version_index;
06337
06338 if (ELF_ST_BIND (isym->st_info) == STB_LOCAL
06339 || isym->st_shndx == SHN_UNDEF)
06340 continue;
06341
06342 name = bfd_elf_string_from_elf_section (input,
06343 hdr->sh_link,
06344 isym->st_name);
06345 if (strcmp (name, h->root.root.string) != 0)
06346 continue;
06347
06348 _bfd_elf_swap_versym_in (input, ever, &iver);
06349
06350 if ((iver.vs_vers & VERSYM_HIDDEN) == 0)
06351 {
06352
06353
06354 abort ();
06355 }
06356
06357 version_index = iver.vs_vers & VERSYM_VERSION;
06358 if (version_index == 1 || version_index == 2)
06359 {
06360
06361 free (extversym);
06362 free (isymbuf);
06363 return TRUE;
06364 }
06365 }
06366
06367 free (extversym);
06368 free (isymbuf);
06369 }
06370
06371 return FALSE;
06372 }
06373
06374
06375
06376
06377
06378
06379
06380
06381 static bfd_boolean
06382 elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
06383 {
06384 struct elf_outext_info *eoinfo = data;
06385 struct elf_final_link_info *finfo = eoinfo->finfo;
06386 bfd_boolean strip;
06387 Elf_Internal_Sym sym;
06388 asection *input_sec;
06389 const struct elf_backend_data *bed;
06390
06391 if (h->root.type == bfd_link_hash_warning)
06392 {
06393 h = (struct elf_link_hash_entry *) h->root.u.i.link;
06394 if (h->root.type == bfd_link_hash_new)
06395 return TRUE;
06396 }
06397
06398
06399 if (eoinfo->localsyms)
06400 {
06401 if (!h->forced_local)
06402 return TRUE;
06403 }
06404 else
06405 {
06406 if (h->forced_local)
06407 return TRUE;
06408 }
06409
06410 bed = get_elf_backend_data (finfo->output_bfd);
06411
06412
06413
06414
06415
06416 if (h->root.type == bfd_link_hash_undefined
06417 && h->ref_dynamic
06418 && !h->ref_regular
06419 && ! elf_link_check_versioned_symbol (finfo->info, bed, h)
06420 && finfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
06421 {
06422 if (! ((*finfo->info->callbacks->undefined_symbol)
06423 (finfo->info, h->root.root.string, h->root.u.undef.abfd,
06424 NULL, 0, finfo->info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)))
06425 {
06426 eoinfo->failed = TRUE;
06427 return FALSE;
06428 }
06429 }
06430
06431
06432
06433 if (! finfo->info->relocatable
06434 && (! finfo->info->shared)
06435 && h->forced_local
06436 && h->ref_dynamic
06437 && !h->dynamic_def
06438 && !h->dynamic_weak
06439 && ! elf_link_check_versioned_symbol (finfo->info, bed, h))
06440 {
06441 (*_bfd_error_handler)
06442 (_("%B: %s symbol `%s' in %B is referenced by DSO"),
06443 finfo->output_bfd, h->root.u.def.section->owner,
06444 ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
06445 ? "internal"
06446 : ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
06447 ? "hidden" : "local",
06448 h->root.root.string);
06449 eoinfo->failed = TRUE;
06450 return FALSE;
06451 }
06452
06453
06454
06455
06456
06457 if (h->indx == -2)
06458 strip = FALSE;
06459 else if ((h->def_dynamic
06460 || h->ref_dynamic
06461 || h->root.type == bfd_link_hash_new)
06462 && !h->def_regular
06463 && !h->ref_regular)
06464 strip = TRUE;
06465 else if (finfo->info->strip == strip_all)
06466 strip = TRUE;
06467 else if (finfo->info->strip == strip_some
06468 && bfd_hash_lookup (finfo->info->keep_hash,
06469 h->root.root.string, FALSE, FALSE) == NULL)
06470 strip = TRUE;
06471 else if (finfo->info->strip_discarded
06472 && (h->root.type == bfd_link_hash_defined
06473 || h->root.type == bfd_link_hash_defweak)
06474 && elf_discarded_section (h->root.u.def.section))
06475 strip = TRUE;
06476 else
06477 strip = FALSE;
06478
06479
06480
06481 if (strip
06482 && h->dynindx == -1
06483 && !h->forced_local)
06484 return TRUE;
06485
06486 sym.st_value = 0;
06487 sym.st_size = h->size;
06488 sym.st_other = h->other;
06489 if (h->forced_local)
06490 sym.st_info = ELF_ST_INFO (STB_LOCAL, h->type);
06491 else if (h->root.type == bfd_link_hash_undefweak
06492 || h->root.type == bfd_link_hash_defweak)
06493 sym.st_info = ELF_ST_INFO (STB_WEAK, h->type);
06494 else
06495 sym.st_info = ELF_ST_INFO (STB_GLOBAL, h->type);
06496
06497 switch (h->root.type)
06498 {
06499 default:
06500 case bfd_link_hash_new:
06501 case bfd_link_hash_warning:
06502 abort ();
06503 return FALSE;
06504
06505 case bfd_link_hash_undefined:
06506 case bfd_link_hash_undefweak:
06507 input_sec = bfd_und_section_ptr;
06508 sym.st_shndx = SHN_UNDEF;
06509 break;
06510
06511 case bfd_link_hash_defined:
06512 case bfd_link_hash_defweak:
06513 {
06514 input_sec = h->root.u.def.section;
06515 if (input_sec->output_section != NULL)
06516 {
06517 sym.st_shndx =
06518 _bfd_elf_section_from_bfd_section (finfo->output_bfd,
06519 input_sec->output_section);
06520 if (sym.st_shndx == SHN_BAD)
06521 {
06522 (*_bfd_error_handler)
06523 (_("%B: could not find output section %A for input section %A"),
06524 finfo->output_bfd, input_sec->output_section, input_sec);
06525 eoinfo->failed = TRUE;
06526 return FALSE;
06527 }
06528
06529
06530
06531
06532 sym.st_value = h->root.u.def.value + input_sec->output_offset;
06533 if (! finfo->info->relocatable)
06534 {
06535 sym.st_value += input_sec->output_section->vma;
06536 if (h->type == STT_TLS)
06537 {
06538
06539
06540 BFD_ASSERT (elf_hash_table (finfo->info)->tls_sec != NULL);
06541 sym.st_value -= elf_hash_table (finfo->info)->tls_sec->vma;
06542 }
06543 }
06544 }
06545 else
06546 {
06547 BFD_ASSERT (input_sec->owner == NULL
06548 || (input_sec->owner->flags & DYNAMIC) != 0);
06549 sym.st_shndx = SHN_UNDEF;
06550 input_sec = bfd_und_section_ptr;
06551 }
06552 }
06553 break;
06554
06555 case bfd_link_hash_common:
06556 input_sec = h->root.u.c.p->section;
06557 sym.st_shndx = SHN_COMMON;
06558 sym.st_value = 1 << h->root.u.c.p->alignment_power;
06559 break;
06560
06561 case bfd_link_hash_indirect:
06562
06563
06564
06565
06566
06567
06568 return TRUE;
06569 }
06570
06571
06572
06573
06574
06575 if ((h->dynindx != -1
06576 || h->forced_local)
06577 && ((finfo->info->shared
06578 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
06579 || h->root.type != bfd_link_hash_undefweak))
06580 || !h->forced_local)
06581 && elf_hash_table (finfo->info)->dynamic_sections_created)
06582 {
06583 if (! ((*bed->elf_backend_finish_dynamic_symbol)
06584 (finfo->output_bfd, finfo->info, h, &sym)))
06585 {
06586 eoinfo->failed = TRUE;
06587 return FALSE;
06588 }
06589 }
06590
06591
06592
06593
06594
06595
06596
06597 if (sym.st_shndx == SHN_UNDEF
06598 && h->ref_regular
06599 && (ELF_ST_BIND (sym.st_info) == STB_GLOBAL
06600 || ELF_ST_BIND (sym.st_info) == STB_WEAK))
06601 {
06602 int bindtype;
06603
06604 if (h->ref_regular_nonweak)
06605 bindtype = STB_GLOBAL;
06606 else
06607 bindtype = STB_WEAK;
06608 sym.st_info = ELF_ST_INFO (bindtype, ELF_ST_TYPE (sym.st_info));
06609 }
06610
06611
06612
06613 if (! finfo->info->relocatable
06614 && ELF_ST_VISIBILITY (sym.st_other) != STV_DEFAULT
06615 && ELF_ST_BIND (sym.st_info) != STB_WEAK
06616 && h->root.type == bfd_link_hash_undefined
06617 && !h->def_regular)
06618 {
06619 (*_bfd_error_handler)
06620 (_("%B: %s symbol `%s' isn't defined"),
06621 finfo->output_bfd,
06622 ELF_ST_VISIBILITY (sym.st_other) == STV_PROTECTED
06623 ? "protected"
06624 : ELF_ST_VISIBILITY (sym.st_other) == STV_INTERNAL
06625 ? "internal" : "hidden",
06626 h->root.root.string);
06627 eoinfo->failed = TRUE;
06628 return FALSE;
06629 }
06630
06631
06632
06633
06634 if (h->dynindx != -1
06635 && elf_hash_table (finfo->info)->dynamic_sections_created)
06636 {
06637 size_t bucketcount;
06638 size_t bucket;
06639 size_t hash_entry_size;
06640 bfd_byte *bucketpos;
06641 bfd_vma chain;
06642 bfd_byte *esym;
06643
06644 sym.st_name = h->dynstr_index;
06645 esym = finfo->dynsym_sec->contents + h->dynindx * bed->s->sizeof_sym;
06646 bed->s->swap_symbol_out (finfo->output_bfd, &sym, esym, 0);
06647
06648 bucketcount = elf_hash_table (finfo->info)->bucketcount;
06649 bucket = h->u.elf_hash_value % bucketcount;
06650 hash_entry_size
06651 = elf_section_data (finfo->hash_sec)->this_hdr.sh_entsize;
06652 bucketpos = ((bfd_byte *) finfo->hash_sec->contents
06653 + (bucket + 2) * hash_entry_size);
06654 chain = bfd_get (8 * hash_entry_size, finfo->output_bfd, bucketpos);
06655 bfd_put (8 * hash_entry_size, finfo->output_bfd, h->dynindx, bucketpos);
06656 bfd_put (8 * hash_entry_size, finfo->output_bfd, chain,
06657 ((bfd_byte *) finfo->hash_sec->contents
06658 + (bucketcount + 2 + h->dynindx) * hash_entry_size));
06659
06660 if (finfo->symver_sec != NULL && finfo->symver_sec->contents != NULL)
06661 {
06662 Elf_Internal_Versym iversym;
06663 Elf_External_Versym *eversym;
06664
06665 if (!h->def_regular)
06666 {
06667 if (h->verinfo.verdef == NULL)
06668 iversym.vs_vers = 0;
06669 else
06670 iversym.vs_vers = h->verinfo.verdef->vd_exp_refno + 1;
06671 }
06672 else
06673 {
06674 if (h->verinfo.vertree == NULL)
06675 iversym.vs_vers = 1;
06676 else
06677 iversym.vs_vers = h->verinfo.vertree->vernum + 1;
06678 if (finfo->info->create_default_symver)
06679 iversym.vs_vers++;
06680 }
06681
06682 if (h->hidden)
06683 iversym.vs_vers |= VERSYM_HIDDEN;
06684
06685 eversym = (Elf_External_Versym *) finfo->symver_sec->contents;
06686 eversym += h->dynindx;
06687 _bfd_elf_swap_versym_out (finfo->output_bfd, &iversym, eversym);
06688 }
06689 }
06690
06691
06692
06693 if (strip || (input_sec->flags & SEC_EXCLUDE) != 0)
06694 return TRUE;
06695
06696 h->indx = bfd_get_symcount (finfo->output_bfd);
06697
06698 if (! elf_link_output_sym (finfo, h->root.root.string, &sym, input_sec, h))
06699 {
06700 eoinfo->failed = TRUE;
06701 return FALSE;
06702 }
06703
06704 return TRUE;
06705 }
06706
06707
06708
06709
06710 static bfd_boolean
06711 elf_section_ignore_discarded_relocs (asection *sec)
06712 {
06713 const struct elf_backend_data *bed;
06714
06715 switch (sec->sec_info_type)
06716 {
06717 case ELF_INFO_TYPE_STABS:
06718 case ELF_INFO_TYPE_EH_FRAME:
06719 return TRUE;
06720 default:
06721 break;
06722 }
06723
06724 bed = get_elf_backend_data (sec->owner);
06725 if (bed->elf_backend_ignore_discarded_relocs != NULL
06726 && (*bed->elf_backend_ignore_discarded_relocs) (sec))
06727 return TRUE;
06728
06729 return FALSE;
06730 }
06731
06732 enum action_discarded
06733 {
06734 COMPLAIN = 1,
06735 PRETEND = 2
06736 };
06737
06738
06739
06740
06741
06742
06743
06744
06745
06746
06747 static unsigned int
06748 elf_action_discarded (asection *sec)
06749 {
06750 if (sec->flags & SEC_DEBUGGING)
06751 return PRETEND;
06752
06753 if (strcmp (".eh_frame", sec->name) == 0)
06754 return 0;
06755
06756 if (strcmp (".gcc_except_table", sec->name) == 0)
06757 return 0;
06758
06759 if (strcmp (".PARISC.unwind", sec->name) == 0)
06760 return 0;
06761
06762 if (strcmp (".fixup", sec->name) == 0)
06763 return 0;
06764
06765 return COMPLAIN | PRETEND;
06766 }
06767
06768
06769
06770 static asection *
06771 match_group_member (asection *sec, asection *group)
06772 {
06773 asection *first = elf_next_in_group (group);
06774 asection *s = first;
06775
06776 while (s != NULL)
06777 {
06778 if (bfd_elf_match_symbols_in_sections (s, sec))
06779 return s;
06780
06781 if (s == first)
06782 break;
06783 }
06784
06785 return NULL;
06786 }
06787
06788
06789
06790
06791
06792
06793 static bfd_boolean
06794 elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd)
06795 {
06796 bfd_boolean (*relocate_section)
06797 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
06798 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
06799 bfd *output_bfd;
06800 Elf_Internal_Shdr *symtab_hdr;
06801 size_t locsymcount;
06802 size_t extsymoff;
06803 Elf_Internal_Sym *isymbuf;
06804 Elf_Internal_Sym *isym;
06805 Elf_Internal_Sym *isymend;
06806 long *pindex;
06807 asection **ppsection;
06808 asection *o;
06809 const struct elf_backend_data *bed;
06810 bfd_boolean emit_relocs;
06811 struct elf_link_hash_entry **sym_hashes;
06812
06813 output_bfd = finfo->output_bfd;
06814 bed = get_elf_backend_data (output_bfd);
06815 relocate_section = bed->elf_backend_relocate_section;
06816
06817
06818
06819
06820 if ((input_bfd->flags & DYNAMIC) != 0)
06821 return TRUE;
06822
06823 emit_relocs = (finfo->info->relocatable
06824 || finfo->info->emitrelocations
06825 || bed->elf_backend_emit_relocs);
06826
06827 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
06828 if (elf_bad_symtab (input_bfd))
06829 {
06830 locsymcount = symtab_hdr->sh_size / bed->s->sizeof_sym;
06831 extsymoff = 0;
06832 }
06833 else
06834 {
06835 locsymcount = symtab_hdr->sh_info;
06836 extsymoff = symtab_hdr->sh_info;
06837 }
06838
06839
06840 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
06841 if (isymbuf == NULL && locsymcount != 0)
06842 {
06843 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
06844 finfo->internal_syms,
06845 finfo->external_syms,
06846 finfo->locsym_shndx);
06847 if (isymbuf == NULL)
06848 return FALSE;
06849 }
06850
06851
06852
06853
06854 isymend = isymbuf + locsymcount;
06855 for (isym = isymbuf, pindex = finfo->indices, ppsection = finfo->sections;
06856 isym < isymend;
06857 isym++, pindex++, ppsection++)
06858 {
06859 asection *isec;
06860 const char *name;
06861 Elf_Internal_Sym osym;
06862
06863 *pindex = -1;
06864
06865 if (elf_bad_symtab (input_bfd))
06866 {
06867 if (ELF_ST_BIND (isym->st_info) != STB_LOCAL)
06868 {
06869 *ppsection = NULL;
06870 continue;
06871 }
06872 }
06873
06874 if (isym->st_shndx == SHN_UNDEF)
06875 isec = bfd_und_section_ptr;
06876 else if (isym->st_shndx < SHN_LORESERVE
06877 || isym->st_shndx > SHN_HIRESERVE)
06878 {
06879 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
06880 if (isec
06881 && isec->sec_info_type == ELF_INFO_TYPE_MERGE
06882 && ELF_ST_TYPE (isym->st_info) != STT_SECTION)
06883 isym->st_value =
06884 _bfd_merged_section_offset (output_bfd, &isec,
06885 elf_section_data (isec)->sec_info,
06886 isym->st_value);
06887 }
06888 else if (isym->st_shndx == SHN_ABS)
06889 isec = bfd_abs_section_ptr;
06890 else if (isym->st_shndx == SHN_COMMON)
06891 isec = bfd_com_section_ptr;
06892 else
06893 {
06894
06895 isec = NULL;
06896 }
06897
06898 *ppsection = isec;
06899
06900
06901 if (ppsection == finfo->sections)
06902 continue;
06903
06904 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
06905 {
06906
06907
06908
06909 continue;
06910 }
06911
06912
06913
06914 if (finfo->info->strip == strip_all)
06915 continue;
06916
06917
06918
06919
06920
06921
06922 if (finfo->info->discard == discard_all)
06923 continue;
06924
06925
06926
06927
06928
06929
06930 if ((isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE)
06931 && (isec == NULL
06932 || (! isec->linker_mark && (isec->flags & SEC_HAS_CONTENTS) != 0)
06933 || (! finfo->info->relocatable
06934 && (isec->flags & SEC_EXCLUDE) != 0)))
06935 continue;
06936
06937
06938 name = bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link,
06939 isym->st_name);
06940 if (name == NULL)
06941 return FALSE;
06942
06943
06944 if ((finfo->info->strip == strip_some
06945 && (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE)
06946 == NULL))
06947 || (((finfo->info->discard == discard_sec_merge
06948 && (isec->flags & SEC_MERGE) && ! finfo->info->relocatable)
06949 || finfo->info->discard == discard_l)
06950 && bfd_is_local_label_name (input_bfd, name)))
06951 continue;
06952
06953
06954
06955 osym = *isym;
06956
06957
06958 osym.st_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
06959 isec->output_section);
06960 if (osym.st_shndx == SHN_BAD)
06961 return FALSE;
06962
06963 *pindex = bfd_get_symcount (output_bfd);
06964
06965
06966
06967
06968
06969
06970
06971
06972 osym.st_value += isec->output_offset;
06973 if (! finfo->info->relocatable)
06974 {
06975 osym.st_value += isec->output_section->vma;
06976 if (ELF_ST_TYPE (osym.st_info) == STT_TLS)
06977 {
06978
06979 BFD_ASSERT (elf_hash_table (finfo->info)->tls_sec != NULL);
06980 osym.st_value -= elf_hash_table (finfo->info)->tls_sec->vma;
06981 }
06982 }
06983
06984 if (! elf_link_output_sym (finfo, name, &osym, isec, NULL))
06985 return FALSE;
06986 }
06987
06988
06989 sym_hashes = elf_sym_hashes (input_bfd);
06990 for (o = input_bfd->sections; o != NULL; o = o->next)
06991 {
06992 bfd_byte *contents;
06993
06994 if (! o->linker_mark)
06995 {
06996
06997 continue;
06998 }
06999
07000 if ((o->flags & SEC_HAS_CONTENTS) == 0
07001 || (o->size == 0 && (o->flags & SEC_RELOC) == 0))
07002 continue;
07003
07004 if ((o->flags & SEC_LINKER_CREATED) != 0)
07005 {
07006
07007
07008 continue;
07009 }
07010
07011
07012
07013
07014
07015 if (elf_section_data (o)->this_hdr.contents != NULL)
07016 contents = elf_section_data (o)->this_hdr.contents;
07017 else
07018 {
07019 bfd_size_type amt = o->rawsize ? o->rawsize : o->size;
07020
07021 contents = finfo->contents;
07022 if (! bfd_get_section_contents (input_bfd, o, contents, 0, amt))
07023 return FALSE;
07024 }
07025
07026 if ((o->flags & SEC_RELOC) != 0)
07027 {
07028 Elf_Internal_Rela *internal_relocs;
07029 bfd_vma r_type_mask;
07030 int r_sym_shift;
07031
07032
07033 internal_relocs
07034 = _bfd_elf_link_read_relocs (input_bfd, o, finfo->external_relocs,
07035 finfo->internal_relocs, FALSE);
07036 if (internal_relocs == NULL
07037 && o->reloc_count > 0)
07038 return FALSE;
07039
07040 if (bed->s->arch_size == 32)
07041 {
07042 r_type_mask = 0xff;
07043 r_sym_shift = 8;
07044 }
07045 else
07046 {
07047 r_type_mask = 0xffffffff;
07048 r_sym_shift = 32;
07049 }
07050
07051
07052
07053
07054
07055
07056
07057 if (!elf_section_ignore_discarded_relocs (o))
07058 {
07059 Elf_Internal_Rela *rel, *relend;
07060 unsigned int action = elf_action_discarded (o);
07061
07062 rel = internal_relocs;
07063 relend = rel + o->reloc_count * bed->s->int_rels_per_ext_rel;
07064 for ( ; rel < relend; rel++)
07065 {
07066 unsigned long r_symndx = rel->r_info >> r_sym_shift;
07067 asection **ps, *sec;
07068 struct elf_link_hash_entry *h = NULL;
07069 const char *sym_name