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
00026 #include "bfd.h"
00027 #include "sysdep.h"
00028 #include "libbfd.h"
00029 #include "bfdlink.h"
00030 #include "genlink.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 static bfd_boolean generic_link_add_object_symbols
00414 (bfd *, struct bfd_link_info *, bfd_boolean collect);
00415 static bfd_boolean generic_link_add_symbols
00416 (bfd *, struct bfd_link_info *, bfd_boolean);
00417 static bfd_boolean generic_link_check_archive_element_no_collect
00418 (bfd *, struct bfd_link_info *, bfd_boolean *);
00419 static bfd_boolean generic_link_check_archive_element_collect
00420 (bfd *, struct bfd_link_info *, bfd_boolean *);
00421 static bfd_boolean generic_link_check_archive_element
00422 (bfd *, struct bfd_link_info *, bfd_boolean *, bfd_boolean);
00423 static bfd_boolean generic_link_add_symbol_list
00424 (bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **,
00425 bfd_boolean);
00426 static bfd_boolean generic_add_output_symbol
00427 (bfd *, size_t *psymalloc, asymbol *);
00428 static bfd_boolean default_data_link_order
00429 (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *);
00430 static bfd_boolean default_indirect_link_order
00431 (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *,
00432 bfd_boolean);
00433
00434 #ifdef IPA_LINK
00435 extern bfd_boolean ipa_is_whirl(bfd *) __attribute__((weak));
00436 bfd_boolean is_ipa __attribute__((weak)) = 0;
00437 #endif
00438
00439
00440
00441
00442
00443
00444
00445 struct bfd_hash_entry *
00446 _bfd_link_hash_newfunc (struct bfd_hash_entry *entry,
00447 struct bfd_hash_table *table,
00448 const char *string)
00449 {
00450
00451
00452 if (entry == NULL)
00453 {
00454 entry = bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry));
00455 if (entry == NULL)
00456 return entry;
00457 }
00458
00459
00460 entry = bfd_hash_newfunc (entry, table, string);
00461 if (entry)
00462 {
00463 struct bfd_link_hash_entry *h = (struct bfd_link_hash_entry *) entry;
00464
00465
00466 h->type = bfd_link_hash_new;
00467 memset (&h->u.undef.next, 0,
00468 (sizeof (struct bfd_link_hash_entry)
00469 - offsetof (struct bfd_link_hash_entry, u.undef.next)));
00470 }
00471
00472 return entry;
00473 }
00474
00475
00476
00477
00478 bfd_boolean
00479 _bfd_link_hash_table_init
00480 (struct bfd_link_hash_table *table,
00481 bfd *abfd,
00482 struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *,
00483 struct bfd_hash_table *,
00484 const char *))
00485 {
00486 table->creator = abfd->xvec;
00487 table->undefs = NULL;
00488 table->undefs_tail = NULL;
00489 table->type = bfd_link_generic_hash_table;
00490
00491 return bfd_hash_table_init (&table->table, newfunc);
00492 }
00493
00494
00495
00496
00497
00498 struct bfd_link_hash_entry *
00499 bfd_link_hash_lookup (struct bfd_link_hash_table *table,
00500 const char *string,
00501 bfd_boolean create,
00502 bfd_boolean copy,
00503 bfd_boolean follow)
00504 {
00505 struct bfd_link_hash_entry *ret;
00506
00507 ret = ((struct bfd_link_hash_entry *)
00508 bfd_hash_lookup (&table->table, string, create, copy));
00509
00510 if (follow && ret != NULL)
00511 {
00512 while (ret->type == bfd_link_hash_indirect
00513 || ret->type == bfd_link_hash_warning)
00514 ret = ret->u.i.link;
00515 }
00516
00517 return ret;
00518 }
00519
00520
00521
00522
00523
00524 struct bfd_link_hash_entry *
00525 bfd_wrapped_link_hash_lookup (bfd *abfd,
00526 struct bfd_link_info *info,
00527 const char *string,
00528 bfd_boolean create,
00529 bfd_boolean copy,
00530 bfd_boolean follow)
00531 {
00532 bfd_size_type amt;
00533
00534 if (info->wrap_hash != NULL)
00535 {
00536 const char *l;
00537 char prefix = '\0';
00538
00539 l = string;
00540 if (*l == bfd_get_symbol_leading_char (abfd) || *l == info->wrap_char)
00541 {
00542 prefix = *l;
00543 ++l;
00544 }
00545
00546 #undef WRAP
00547 #define WRAP "__wrap_"
00548
00549 if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL)
00550 {
00551 char *n;
00552 struct bfd_link_hash_entry *h;
00553
00554
00555
00556
00557 amt = strlen (l) + sizeof WRAP + 1;
00558 n = bfd_malloc (amt);
00559 if (n == NULL)
00560 return NULL;
00561
00562 n[0] = prefix;
00563 n[1] = '\0';
00564 strcat (n, WRAP);
00565 strcat (n, l);
00566 h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow);
00567 free (n);
00568 return h;
00569 }
00570
00571 #undef WRAP
00572
00573 #undef REAL
00574 #define REAL "__real_"
00575
00576 if (*l == '_'
00577 && strncmp (l, REAL, sizeof REAL - 1) == 0
00578 && bfd_hash_lookup (info->wrap_hash, l + sizeof REAL - 1,
00579 FALSE, FALSE) != NULL)
00580 {
00581 char *n;
00582 struct bfd_link_hash_entry *h;
00583
00584
00585
00586
00587
00588 amt = strlen (l + sizeof REAL - 1) + 2;
00589 n = bfd_malloc (amt);
00590 if (n == NULL)
00591 return NULL;
00592
00593 n[0] = prefix;
00594 n[1] = '\0';
00595 strcat (n, l + sizeof REAL - 1);
00596 h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow);
00597 free (n);
00598 return h;
00599 }
00600
00601 #undef REAL
00602 }
00603
00604 return bfd_link_hash_lookup (info->hash, string, create, copy, follow);
00605 }
00606
00607
00608
00609
00610
00611
00612
00613 void
00614 bfd_link_hash_traverse
00615 (struct bfd_link_hash_table *table,
00616 bfd_boolean (*func) (struct bfd_link_hash_entry *, void *),
00617 void *info)
00618 {
00619 bfd_hash_traverse (&table->table,
00620 (bfd_boolean (*) (struct bfd_hash_entry *, void *)) func,
00621 info);
00622 }
00623
00624
00625
00626 void
00627 bfd_link_add_undef (struct bfd_link_hash_table *table,
00628 struct bfd_link_hash_entry *h)
00629 {
00630 BFD_ASSERT (h->u.undef.next == NULL);
00631 if (table->undefs_tail != NULL)
00632 table->undefs_tail->u.undef.next = h;
00633 if (table->undefs == NULL)
00634 table->undefs = h;
00635 table->undefs_tail = h;
00636 }
00637
00638
00639
00640
00641
00642
00643
00644
00645 void
00646 bfd_link_repair_undef_list (struct bfd_link_hash_table *table)
00647 {
00648 struct bfd_link_hash_entry **pun;
00649
00650 pun = &table->undefs;
00651 while (*pun != NULL)
00652 {
00653 struct bfd_link_hash_entry *h = *pun;
00654
00655 if (h->type == bfd_link_hash_new
00656 || h->type == bfd_link_hash_undefweak)
00657 {
00658 *pun = h->u.undef.next;
00659 h->u.undef.next = NULL;
00660 if (h == table->undefs_tail)
00661 {
00662 if (pun == &table->undefs)
00663 table->undefs_tail = NULL;
00664 else
00665
00666
00667 table->undefs_tail = (struct bfd_link_hash_entry *)
00668 ((char *) pun - ((char *) &h->u.undef.next - (char *) h));
00669 break;
00670 }
00671 }
00672 else
00673 pun = &h->u.undef.next;
00674 }
00675 }
00676
00677
00678
00679 struct bfd_hash_entry *
00680 _bfd_generic_link_hash_newfunc (struct bfd_hash_entry *entry,
00681 struct bfd_hash_table *table,
00682 const char *string)
00683 {
00684
00685
00686 if (entry == NULL)
00687 {
00688 entry =
00689 bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry));
00690 if (entry == NULL)
00691 return entry;
00692 }
00693
00694
00695 entry = _bfd_link_hash_newfunc (entry, table, string);
00696 if (entry)
00697 {
00698 struct generic_link_hash_entry *ret;
00699
00700
00701 ret = (struct generic_link_hash_entry *) entry;
00702 ret->written = FALSE;
00703 ret->sym = NULL;
00704 }
00705
00706 return entry;
00707 }
00708
00709
00710
00711 struct bfd_link_hash_table *
00712 _bfd_generic_link_hash_table_create (bfd *abfd)
00713 {
00714 struct generic_link_hash_table *ret;
00715 bfd_size_type amt = sizeof (struct generic_link_hash_table);
00716
00717 ret = bfd_malloc (amt);
00718 if (ret == NULL)
00719 return NULL;
00720 if (! _bfd_link_hash_table_init (&ret->root, abfd,
00721 _bfd_generic_link_hash_newfunc))
00722 {
00723 free (ret);
00724 return NULL;
00725 }
00726 return &ret->root;
00727 }
00728
00729 void
00730 _bfd_generic_link_hash_table_free (struct bfd_link_hash_table *hash)
00731 {
00732 struct generic_link_hash_table *ret
00733 = (struct generic_link_hash_table *) hash;
00734
00735 bfd_hash_table_free (&ret->root.table);
00736 free (ret);
00737 }
00738
00739
00740
00741
00742
00743
00744
00745
00746 static bfd_boolean
00747 generic_link_read_symbols (bfd *abfd)
00748 {
00749 if (bfd_get_outsymbols (abfd) == NULL)
00750 {
00751 long symsize;
00752 long symcount;
00753
00754 symsize = bfd_get_symtab_upper_bound (abfd);
00755 if (symsize < 0)
00756 return FALSE;
00757 bfd_get_outsymbols (abfd) = bfd_alloc (abfd, symsize);
00758 if (bfd_get_outsymbols (abfd) == NULL && symsize != 0)
00759 return FALSE;
00760 symcount = bfd_canonicalize_symtab (abfd, bfd_get_outsymbols (abfd));
00761 if (symcount < 0)
00762 return FALSE;
00763 bfd_get_symcount (abfd) = symcount;
00764 }
00765
00766 return TRUE;
00767 }
00768
00769
00770
00771
00772
00773 bfd_boolean
00774 _bfd_generic_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
00775 {
00776 return generic_link_add_symbols (abfd, info, FALSE);
00777 }
00778
00779
00780
00781
00782
00783
00784
00785
00786 bfd_boolean
00787 _bfd_generic_link_add_symbols_collect (bfd *abfd, struct bfd_link_info *info)
00788 {
00789 return generic_link_add_symbols (abfd, info, TRUE);
00790 }
00791
00792
00793
00794
00795
00796 void
00797 _bfd_generic_link_just_syms (asection *sec,
00798 struct bfd_link_info *info ATTRIBUTE_UNUSED)
00799 {
00800 sec->output_section = bfd_abs_section_ptr;
00801 sec->output_offset = sec->vma;
00802 }
00803
00804
00805
00806 static bfd_boolean
00807 generic_link_add_symbols (bfd *abfd,
00808 struct bfd_link_info *info,
00809 bfd_boolean collect)
00810 {
00811 bfd_boolean ret;
00812
00813 switch (bfd_get_format (abfd))
00814 {
00815 case bfd_object:
00816 ret = generic_link_add_object_symbols (abfd, info, collect);
00817 break;
00818 case bfd_archive:
00819 ret = (_bfd_generic_link_add_archive_symbols
00820 (abfd, info,
00821 (collect
00822 ? generic_link_check_archive_element_collect
00823 : generic_link_check_archive_element_no_collect)));
00824 break;
00825 default:
00826 bfd_set_error (bfd_error_wrong_format);
00827 ret = FALSE;
00828 }
00829
00830 return ret;
00831 }
00832
00833
00834
00835 static bfd_boolean
00836 generic_link_add_object_symbols (bfd *abfd,
00837 struct bfd_link_info *info,
00838 bfd_boolean collect)
00839 {
00840 bfd_size_type symcount;
00841 struct bfd_symbol **outsyms;
00842
00843 if (! generic_link_read_symbols (abfd))
00844 return FALSE;
00845 symcount = _bfd_generic_link_get_symcount (abfd);
00846 outsyms = _bfd_generic_link_get_symbols (abfd);
00847 return generic_link_add_symbol_list (abfd, info, symcount, outsyms, collect);
00848 }
00849
00850
00851
00852
00853
00854
00855 struct archive_list
00856 {
00857 struct archive_list *next;
00858 unsigned int indx;
00859 };
00860
00861
00862
00863 struct archive_hash_entry
00864 {
00865 struct bfd_hash_entry root;
00866
00867 struct archive_list *defs;
00868 };
00869
00870
00871
00872 struct archive_hash_table
00873 {
00874 struct bfd_hash_table table;
00875 };
00876
00877
00878
00879 static struct bfd_hash_entry *
00880 archive_hash_newfunc (struct bfd_hash_entry *entry,
00881 struct bfd_hash_table *table,
00882 const char *string)
00883 {
00884 struct archive_hash_entry *ret = (struct archive_hash_entry *) entry;
00885
00886
00887
00888 if (ret == NULL)
00889 ret = bfd_hash_allocate (table, sizeof (struct archive_hash_entry));
00890 if (ret == NULL)
00891 return NULL;
00892
00893
00894 ret = ((struct archive_hash_entry *)
00895 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
00896
00897 if (ret)
00898 {
00899
00900 ret->defs = NULL;
00901 }
00902
00903 return &ret->root;
00904 }
00905
00906
00907
00908 static bfd_boolean
00909 archive_hash_table_init
00910 (struct archive_hash_table *table,
00911 struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *,
00912 struct bfd_hash_table *,
00913 const char *))
00914 {
00915 return bfd_hash_table_init (&table->table, newfunc);
00916 }
00917
00918
00919
00920 #define archive_hash_lookup(t, string, create, copy) \
00921 ((struct archive_hash_entry *) \
00922 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
00923
00924
00925
00926 #define archive_hash_allocate(t, size) bfd_hash_allocate (&(t)->table, (size))
00927
00928
00929
00930 #define archive_hash_table_free(t) bfd_hash_table_free (&(t)->table)
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965 bfd_boolean
00966 _bfd_generic_link_add_archive_symbols
00967 (bfd *abfd,
00968 struct bfd_link_info *info,
00969 bfd_boolean (*checkfn) (bfd *, struct bfd_link_info *, bfd_boolean *))
00970 {
00971 carsym *arsyms;
00972 carsym *arsym_end;
00973 register carsym *arsym;
00974 int pass;
00975 struct archive_hash_table arsym_hash;
00976 unsigned int indx;
00977 struct bfd_link_hash_entry **pundef;
00978
00979 if (! bfd_has_map (abfd))
00980 {
00981
00982 if (bfd_openr_next_archived_file (abfd, NULL) == NULL)
00983 return TRUE;
00984 bfd_set_error (bfd_error_no_armap);
00985 return FALSE;
00986 }
00987
00988 arsyms = bfd_ardata (abfd)->symdefs;
00989 arsym_end = arsyms + bfd_ardata (abfd)->symdef_count;
00990
00991
00992
00993 if (! archive_hash_table_init (&arsym_hash, archive_hash_newfunc))
00994 return FALSE;
00995 for (arsym = arsyms, indx = 0; arsym < arsym_end; arsym++, indx++)
00996 {
00997 struct archive_hash_entry *arh;
00998 struct archive_list *l, **pp;
00999
01000 arh = archive_hash_lookup (&arsym_hash, arsym->name, TRUE, FALSE);
01001 if (arh == NULL)
01002 goto error_return;
01003 l = ((struct archive_list *)
01004 archive_hash_allocate (&arsym_hash, sizeof (struct archive_list)));
01005 if (l == NULL)
01006 goto error_return;
01007 l->indx = indx;
01008 for (pp = &arh->defs; *pp != NULL; pp = &(*pp)->next)
01009 ;
01010 *pp = l;
01011 l->next = NULL;
01012 }
01013
01014
01015
01016
01017 pass = abfd->archive_pass + 1;
01018
01019
01020
01021 pundef = &info->hash->undefs;
01022 while (*pundef != NULL)
01023 {
01024 struct bfd_link_hash_entry *h;
01025 struct archive_hash_entry *arh;
01026 struct archive_list *l;
01027
01028 h = *pundef;
01029
01030
01031
01032 if (h->type != bfd_link_hash_undefined
01033 && h->type != bfd_link_hash_common)
01034 {
01035
01036
01037
01038
01039
01040
01041
01042 if (*pundef != info->hash->undefs_tail)
01043 *pundef = (*pundef)->u.undef.next;
01044 else
01045 pundef = &(*pundef)->u.undef.next;
01046 continue;
01047 }
01048
01049
01050 arh = archive_hash_lookup (&arsym_hash, h->root.string, FALSE, FALSE);
01051 if (arh == NULL)
01052 {
01053
01054
01055 if (info->pei386_auto_import)
01056 {
01057 bfd_size_type amt = strlen (h->root.string) + 10;
01058 char *buf = bfd_malloc (amt);
01059 if (buf == NULL)
01060 return FALSE;
01061
01062 sprintf (buf, "__imp_%s", h->root.string);
01063 arh = archive_hash_lookup (&arsym_hash, buf, FALSE, FALSE);
01064 free(buf);
01065 }
01066 if (arh == NULL)
01067 {
01068 pundef = &(*pundef)->u.undef.next;
01069 continue;
01070 }
01071 }
01072
01073 for (l = arh->defs; l != NULL; l = l->next)
01074 {
01075 bfd *element;
01076 bfd_boolean needed;
01077
01078
01079 if (h->type != bfd_link_hash_undefined
01080 && h->type != bfd_link_hash_common)
01081 break;
01082
01083 element = bfd_get_elt_at_index (abfd, l->indx);
01084 if (element == NULL)
01085 goto error_return;
01086
01087
01088
01089 if (element->archive_pass == -1
01090 || element->archive_pass == pass)
01091 continue;
01092
01093
01094 if (! bfd_check_format (element, bfd_object))
01095 {
01096 element->archive_pass = -1;
01097 continue;
01098 }
01099
01100
01101
01102 if (! (*checkfn) (element, info, &needed))
01103 goto error_return;
01104
01105 if (! needed)
01106 element->archive_pass = pass;
01107 else
01108 {
01109 element->archive_pass = -1;
01110
01111
01112
01113 ++pass;
01114 }
01115 }
01116
01117 pundef = &(*pundef)->u.undef.next;
01118 }
01119
01120 archive_hash_table_free (&arsym_hash);
01121
01122
01123 abfd->archive_pass = pass;
01124
01125 return TRUE;
01126
01127 error_return:
01128 archive_hash_table_free (&arsym_hash);
01129 return FALSE;
01130 }
01131
01132
01133
01134
01135
01136
01137 static bfd_boolean
01138 generic_link_check_archive_element_no_collect (
01139 bfd *abfd,
01140 struct bfd_link_info *info,
01141 bfd_boolean *pneeded)
01142 {
01143 return generic_link_check_archive_element (abfd, info, pneeded, FALSE);
01144 }
01145
01146
01147
01148
01149
01150 static bfd_boolean
01151 generic_link_check_archive_element_collect (bfd *abfd,
01152 struct bfd_link_info *info,
01153 bfd_boolean *pneeded)
01154 {
01155 return generic_link_check_archive_element (abfd, info, pneeded, TRUE);
01156 }
01157
01158
01159
01160
01161 static bfd_boolean
01162 generic_link_check_archive_element (bfd *abfd,
01163 struct bfd_link_info *info,
01164 bfd_boolean *pneeded,
01165 bfd_boolean collect)
01166 {
01167 asymbol **pp, **ppend;
01168
01169 *pneeded = FALSE;
01170
01171 if (! generic_link_read_symbols (abfd))
01172 return FALSE;
01173
01174 pp = _bfd_generic_link_get_symbols (abfd);
01175 ppend = pp + _bfd_generic_link_get_symcount (abfd);
01176 for (; pp < ppend; pp++)
01177 {
01178 asymbol *p;
01179 struct bfd_link_hash_entry *h;
01180
01181 p = *pp;
01182
01183
01184 if (! bfd_is_com_section (p->section)
01185 && (p->flags & (BSF_GLOBAL | BSF_INDIRECT | BSF_WEAK)) == 0)
01186 continue;
01187
01188
01189
01190
01191
01192
01193 h = bfd_link_hash_lookup (info->hash, bfd_asymbol_name (p), FALSE,
01194 FALSE, TRUE);
01195 if (h == NULL
01196 || (h->type != bfd_link_hash_undefined
01197 && h->type != bfd_link_hash_common))
01198 continue;
01199
01200
01201
01202 if (! bfd_is_com_section (p->section))
01203 {
01204 bfd_size_type symcount;
01205 asymbol **symbols;
01206
01207
01208 if (! (*info->callbacks->add_archive_element) (info, abfd,
01209 bfd_asymbol_name (p)))
01210 return FALSE;
01211 symcount = _bfd_generic_link_get_symcount (abfd);
01212 symbols = _bfd_generic_link_get_symbols (abfd);
01213 if (! generic_link_add_symbol_list (abfd, info, symcount,
01214 symbols, collect))
01215 return FALSE;
01216 *pneeded = TRUE;
01217 return TRUE;
01218 }
01219
01220
01221
01222 if (h->type == bfd_link_hash_undefined)
01223 {
01224 bfd *symbfd;
01225 bfd_vma size;
01226 unsigned int power;
01227
01228 symbfd = h->u.undef.abfd;
01229 if (symbfd == NULL)
01230 {
01231
01232
01233
01234 if (! (*info->callbacks->add_archive_element)
01235 (info, abfd, bfd_asymbol_name (p)))
01236 return FALSE;
01237 *pneeded = TRUE;
01238 return TRUE;
01239 }
01240
01241
01242
01243
01244
01245
01246
01247
01248 h->type = bfd_link_hash_common;
01249 h->u.c.p =
01250 bfd_hash_allocate (&info->hash->table,
01251 sizeof (struct bfd_link_hash_common_entry));
01252 if (h->u.c.p == NULL)
01253 return FALSE;
01254
01255 size = bfd_asymbol_value (p);
01256 h->u.c.size = size;
01257
01258 power = bfd_log2 (size);
01259 if (power > 4)
01260 power = 4;
01261 h->u.c.p->alignment_power = power;
01262
01263 if (p->section == bfd_com_section_ptr)
01264 h->u.c.p->section = bfd_make_section_old_way (symbfd, "COMMON");
01265 else
01266 h->u.c.p->section = bfd_make_section_old_way (symbfd,
01267 p->section->name);
01268 h->u.c.p->section->flags = SEC_ALLOC;
01269 }
01270 else
01271 {
01272
01273
01274
01275
01276 if (bfd_asymbol_value (p) > h->u.c.size)
01277 h->u.c.size = bfd_asymbol_value (p);
01278 }
01279 }
01280
01281
01282 return TRUE;
01283 }
01284
01285
01286
01287
01288
01289
01290
01291 static bfd_boolean
01292 generic_link_add_symbol_list (bfd *abfd,
01293 struct bfd_link_info *info,
01294 bfd_size_type symbol_count,
01295 asymbol **symbols,
01296 bfd_boolean collect)
01297 {
01298 asymbol **pp, **ppend;
01299
01300 pp = symbols;
01301 ppend = symbols + symbol_count;
01302 for (; pp < ppend; pp++)
01303 {
01304 asymbol *p;
01305
01306 p = *pp;
01307
01308 if ((p->flags & (BSF_INDIRECT
01309 | BSF_WARNING
01310 | BSF_GLOBAL
01311 | BSF_CONSTRUCTOR
01312 | BSF_WEAK)) != 0
01313 || bfd_is_und_section (bfd_get_section (p))
01314 || bfd_is_com_section (bfd_get_section (p))
01315 || bfd_is_ind_section (bfd_get_section (p)))
01316 {
01317 const char *name;
01318 const char *string;
01319 struct generic_link_hash_entry *h;
01320 struct bfd_link_hash_entry *bh;
01321
01322 name = bfd_asymbol_name (p);
01323 if (((p->flags & BSF_INDIRECT) != 0
01324 || bfd_is_ind_section (p->section))
01325 && pp + 1 < ppend)
01326 {
01327 pp++;
01328 string = bfd_asymbol_name (*pp);
01329 }
01330 else if ((p->flags & BSF_WARNING) != 0
01331 && pp + 1 < ppend)
01332 {
01333
01334
01335 string = name;
01336 pp++;
01337 name = bfd_asymbol_name (*pp);
01338 }
01339 else
01340 string = NULL;
01341
01342 bh = NULL;
01343 if (! (_bfd_generic_link_add_one_symbol
01344 (info, abfd, name, p->flags, bfd_get_section (p),
01345 p->value, string, FALSE, collect, &bh)))
01346 return FALSE;
01347 h = (struct generic_link_hash_entry *) bh;
01348
01349
01350
01351
01352
01353 if ((p->flags & BSF_CONSTRUCTOR) != 0
01354 && (h == NULL || h->root.type == bfd_link_hash_new))
01355 {
01356 p->udata.p = NULL;
01357 continue;
01358 }
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368 if (info->hash->creator == abfd->xvec)
01369 {
01370 if (h->sym == NULL
01371 || (! bfd_is_und_section (bfd_get_section (p))
01372 && (! bfd_is_com_section (bfd_get_section (p))
01373 || bfd_is_und_section (bfd_get_section (h->sym)))))
01374 {
01375 h->sym = p;
01376
01377
01378
01379 if (bfd_is_com_section (bfd_get_section (p)))
01380 p->flags |= BSF_OLD_COMMON;
01381 }
01382 }
01383
01384
01385
01386
01387
01388
01389 p->udata.p = h;
01390 }
01391 }
01392
01393 return TRUE;
01394 }
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404 enum link_row
01405 {
01406 UNDEF_ROW,
01407 UNDEFW_ROW,
01408 DEF_ROW,
01409 DEFW_ROW,
01410 COMMON_ROW,
01411 INDR_ROW,
01412 WARN_ROW,
01413 SET_ROW
01414 };
01415
01416
01417 #undef FAIL
01418
01419
01420
01421 enum link_action
01422 {
01423 FAIL,
01424 UND,
01425 WEAK,
01426 DEF,
01427 DEFW,
01428 COM,
01429 REF,
01430 CREF,
01431 CDEF,
01432 NOACT,
01433 BIG,
01434 MDEF,
01435 MIND,
01436 IND,
01437 CIND,
01438 SET,
01439 MWARN,
01440 WARN,
01441 CWARN,
01442 CYCLE,
01443 REFC,
01444 WARNC
01445 };
01446
01447
01448
01449
01450 static const enum link_action link_action[8][8] =
01451 {
01452
01453 {UND, NOACT, UND, REF, REF, NOACT, REFC, WARNC },
01454 {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC },
01455 {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE },
01456 {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE },
01457 {COM, COM, COM, CREF, COM, BIG, REFC, WARNC },
01458 {IND, IND, IND, MDEF, IND, CIND, MIND, CYCLE },
01459 {MWARN, WARN, WARN, CWARN, CWARN, WARN, CWARN, NOACT },
01460 {SET, SET, SET, SET, SET, SET, CYCLE, CYCLE }
01461 };
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488 static bfd *
01489 hash_entry_bfd (struct bfd_link_hash_entry *h)
01490 {
01491 while (h->type == bfd_link_hash_warning)
01492 h = h->u.i.link;
01493 switch (h->type)
01494 {
01495 default:
01496 return NULL;
01497 case bfd_link_hash_undefined:
01498 case bfd_link_hash_undefweak:
01499 return h->u.undef.abfd;
01500 case bfd_link_hash_defined:
01501 case bfd_link_hash_defweak:
01502 return h->u.def.section->owner;
01503 case bfd_link_hash_common:
01504 return h->u.c.p->section->owner;
01505 }
01506
01507 }
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527 bfd_boolean
01528 _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
01529 bfd *abfd,
01530 const char *name,
01531 flagword flags,
01532 asection *section,
01533 bfd_vma value,
01534 const char *string,
01535 bfd_boolean copy,
01536 bfd_boolean collect,
01537 struct bfd_link_hash_entry **hashp)
01538 {
01539 enum link_row row;
01540 struct bfd_link_hash_entry *h;
01541 bfd_boolean cycle;
01542
01543 if (bfd_is_ind_section (section)
01544 || (flags & BSF_INDIRECT) != 0)
01545 row = INDR_ROW;
01546 else if ((flags & BSF_WARNING) != 0)
01547 row = WARN_ROW;
01548 else if ((flags & BSF_CONSTRUCTOR) != 0)
01549 row = SET_ROW;
01550 else if (bfd_is_und_section (section))
01551 {
01552 if ((flags & BSF_WEAK) != 0)
01553 row = UNDEFW_ROW;
01554 else
01555 row = UNDEF_ROW;
01556 }
01557 else if ((flags & BSF_WEAK) != 0)
01558 row = DEFW_ROW;
01559 else if (bfd_is_com_section (section))
01560 row = COMMON_ROW;
01561 else
01562 row = DEF_ROW;
01563
01564 if (hashp != NULL && *hashp != NULL)
01565 h = *hashp;
01566 else
01567 {
01568 if (row == UNDEF_ROW || row == UNDEFW_ROW)
01569 h = bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, copy, FALSE);
01570 else
01571 h = bfd_link_hash_lookup (info->hash, name, TRUE, copy, FALSE);
01572 if (h == NULL)
01573 {
01574 if (hashp != NULL)
01575 *hashp = NULL;
01576 return FALSE;
01577 }
01578 }
01579
01580 if (info->notice_all
01581 || (info->notice_hash != NULL
01582 && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL))
01583 {
01584 if (! (*info->callbacks->notice) (info, h->root.string, abfd, section,
01585 value))
01586 return FALSE;
01587 }
01588
01589 if (hashp != NULL)
01590 *hashp = h;
01591
01592 do
01593 {
01594 enum link_action action;
01595
01596 cycle = FALSE;
01597 action = link_action[(int) row][(int) h->type];
01598 switch (action)
01599 {
01600 case FAIL:
01601 abort ();
01602
01603 case NOACT:
01604
01605 break;
01606
01607 case UND:
01608
01609 h->type = bfd_link_hash_undefined;
01610 h->u.undef.abfd = abfd;
01611 bfd_link_add_undef (info->hash, h);
01612 break;
01613
01614 case WEAK:
01615
01616 h->type = bfd_link_hash_undefweak;
01617 h->u.undef.abfd = abfd;
01618 h->u.undef.weak = abfd;
01619 break;
01620
01621 case CDEF:
01622
01623
01624 BFD_ASSERT (h->type == bfd_link_hash_common);
01625 if (! ((*info->callbacks->multiple_common)
01626 (info, h->root.string,
01627 h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,
01628 abfd, bfd_link_hash_defined, 0)))
01629 return FALSE;
01630
01631 case DEF:
01632 case DEFW:
01633 {
01634 enum bfd_link_hash_type oldtype;
01635
01636 #ifdef IPA_LINK
01637 if (is_ipa && !ipa_is_whirl(abfd))
01638
01639 break;
01640 #endif
01641
01642 oldtype = h->type;
01643 if (action == DEFW)
01644 h->type = bfd_link_hash_defweak;
01645 else
01646 h->type = bfd_link_hash_defined;
01647 h->u.def.section = section;
01648 #ifdef IPA_LINK
01649 if (is_ipa)
01650 {
01651 h->u.def.section = (asection *) abfd;
01652 #ifdef KEY
01653
01654 h->u.def.section_is_invalid = 1;
01655 #endif
01656 }
01657 #endif
01658 h->u.def.value = value;
01659
01660
01661
01662
01663
01664
01665
01666 if (collect && name[0] == '_')
01667 {
01668 const char *s;
01669
01670
01671
01672
01673
01674
01675
01676 #define CONS_PREFIX "GLOBAL_"
01677 #define CONS_PREFIX_LEN (sizeof CONS_PREFIX - 1)
01678
01679 s = name + 1;
01680 while (*s == '_')
01681 ++s;
01682 if (s[0] == 'G'
01683 && strncmp (s, CONS_PREFIX, CONS_PREFIX_LEN - 1) == 0)
01684 {
01685 char c;
01686
01687 c = s[CONS_PREFIX_LEN + 1];
01688 if ((c == 'I' || c == 'D')
01689 && s[CONS_PREFIX_LEN] == s[CONS_PREFIX_LEN + 2])
01690 {
01691
01692
01693
01694
01695
01696
01697
01698 if (oldtype == bfd_link_hash_defweak)
01699 abort ();
01700
01701 if (! ((*info->callbacks->constructor)
01702 (info, c == 'I',
01703 h->root.string, abfd, section, value)))
01704 return FALSE;
01705 }
01706 }
01707 }
01708 }
01709
01710 break;
01711
01712 case COM:
01713
01714 if (h->type == bfd_link_hash_new)
01715 bfd_link_add_undef (info->hash, h);
01716 h->type = bfd_link_hash_common;
01717 h->u.c.p =
01718 bfd_hash_allocate (&info->hash->table,
01719 sizeof (struct bfd_link_hash_common_entry));
01720 if (h->u.c.p == NULL)
01721 return FALSE;
01722
01723 h->u.c.size = value;
01724
01725
01726
01727 {
01728 unsigned int power;
01729
01730 power = bfd_log2 (value);
01731 if (power > 4)
01732 power = 4;
01733 h->u.c.p->alignment_power = power;
01734 }
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746 if (section == bfd_com_section_ptr)
01747 {
01748 h->u.c.p->section = bfd_make_section_old_way (abfd, "COMMON");
01749 h->u.c.p->section->flags = SEC_ALLOC;
01750 }
01751 else if (section->owner != abfd)
01752 {
01753 h->u.c.p->section = bfd_make_section_old_way (abfd,
01754 section->name);
01755 h->u.c.p->section->flags = SEC_ALLOC;
01756 }
01757 else
01758 h->u.c.p->section = section;
01759 break;
01760
01761 case REF:
01762
01763 if (h->u.undef.next == NULL && info->hash->undefs_tail != h)
01764 h->u.undef.next = h;
01765 break;
01766
01767 case BIG:
01768
01769
01770
01771 BFD_ASSERT (h->type == bfd_link_hash_common);
01772 if (! ((*info->callbacks->multiple_common)
01773 (info, h->root.string,
01774 h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,
01775 abfd, bfd_link_hash_common, value)))
01776 return FALSE;
01777 if (value > h->u.c.size)
01778 {
01779 unsigned int power;
01780
01781 h->u.c.size = value;
01782
01783
01784
01785 power = bfd_log2 (value);
01786 if (power > 4)
01787 power = 4;
01788 h->u.c.p->alignment_power = power;
01789
01790
01791
01792
01793
01794 if (section == bfd_com_section_ptr)
01795 {
01796 h->u.c.p->section
01797 = bfd_make_section_old_way (abfd, "COMMON");
01798 h->u.c.p->section->flags = SEC_ALLOC;
01799 }
01800 else if (section->owner != abfd)
01801 {
01802 h->u.c.p->section
01803 = bfd_make_section_old_way (abfd, section->name);
01804 h->u.c.p->section->flags = SEC_ALLOC;
01805 }
01806 else
01807 h->u.c.p->section = section;
01808 }
01809 break;
01810
01811 case CREF:
01812 {
01813 bfd *obfd;
01814
01815
01816
01817
01818
01819 if (h->type == bfd_link_hash_defined
01820 || h->type == bfd_link_hash_defweak)
01821 obfd = h->u.def.section->owner;
01822 else
01823 obfd = NULL;
01824 if (! ((*info->callbacks->multiple_common)
01825 (info, h->root.string, obfd, h->type, 0,
01826 abfd, bfd_link_hash_common, value)))
01827 return FALSE;
01828 }
01829 break;
01830
01831 case MIND:
01832
01833
01834 if (strcmp (h->u.i.link->root.string, string) == 0)
01835 break;
01836
01837 case MDEF:
01838
01839 if (!info->allow_multiple_definition)
01840 {
01841 asection *msec = NULL;
01842 bfd_vma mval = 0;
01843 bfd *mbfd = NULL;
01844
01845 switch (h->type)
01846 {
01847 case bfd_link_hash_defined:
01848 #ifdef KEY
01849 if ( !h->u.def.section_is_invalid ) {
01850 #endif
01851 msec = h->u.def.section;
01852 mbfd = msec->owner;
01853 #ifdef KEY
01854 }
01855 #endif
01856 mval = h->u.def.value;
01857 break;
01858 case bfd_link_hash_indirect:
01859 #ifdef KEY
01860 if ( !h->u.def.section_is_invalid ) {
01861 #endif
01862 msec = bfd_ind_section_ptr;
01863 mbfd = msec->owner;
01864 #ifdef KEY
01865 }
01866 #endif
01867 mval = 0;
01868 break;
01869 default:
01870 abort ();
01871 }
01872
01873
01874
01875 if (h->type == bfd_link_hash_defined
01876 && bfd_is_abs_section (msec)
01877 && bfd_is_abs_section (section)
01878 && value == mval)
01879 break;
01880
01881 if (! ((*info->callbacks->multiple_definition)
01882 (info, h->root.string, mbfd, msec, mval,
01883 abfd, section, value)))
01884 return FALSE;
01885 }
01886 break;
01887
01888 case CIND:
01889
01890 BFD_ASSERT (h->type == bfd_link_hash_common);
01891 if (! ((*info->callbacks->multiple_common)
01892 (info, h->root.string,
01893 h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,
01894 abfd, bfd_link_hash_indirect, 0)))
01895 return FALSE;
01896
01897 case IND:
01898
01899 {
01900 struct bfd_link_hash_entry *inh;
01901
01902
01903
01904 inh = bfd_wrapped_link_hash_lookup (abfd, info, string, TRUE,
01905 copy, FALSE);
01906 if (inh == NULL)
01907 return FALSE;
01908 if (inh->type == bfd_link_hash_indirect
01909 && inh->u.i.link == h)
01910 {
01911 (*_bfd_error_handler)
01912 (_("%B: indirect symbol `%s' to `%s' is a loop"),
01913 abfd, name, string);
01914 bfd_set_error (bfd_error_invalid_operation);
01915 return FALSE;
01916 }
01917 if (inh->type == bfd_link_hash_new)
01918 {
01919 inh->type = bfd_link_hash_undefined;
01920 inh->u.undef.abfd = abfd;
01921 bfd_link_add_undef (info->hash, inh);
01922 }
01923
01924
01925
01926
01927 if (h->type != bfd_link_hash_new)
01928 {
01929 row = UNDEF_ROW;
01930 cycle = TRUE;
01931 }
01932
01933 h->type = bfd_link_hash_indirect;
01934 h->u.i.link = inh;
01935 }
01936 break;
01937
01938 case SET:
01939
01940 if (! (*info->callbacks->add_to_set) (info, h, BFD_RELOC_CTOR,
01941 abfd, section, value))
01942 return FALSE;
01943 break;
01944
01945 case WARNC:
01946
01947 if (h->u.i.warning != NULL)
01948 {
01949 if (! (*info->callbacks->warning) (info, h->u.i.warning,
01950 h->root.string, abfd,
01951 NULL, 0))
01952 return FALSE;
01953
01954 h->u.i.warning = NULL;
01955 }
01956
01957 case CYCLE:
01958
01959 h = h->u.i.link;
01960 cycle = TRUE;
01961 break;
01962
01963 case REFC:
01964
01965 if (h->u.undef.next == NULL && info->hash->undefs_tail != h)
01966 h->u.undef.next = h;
01967 h = h->u.i.link;
01968 cycle = TRUE;
01969 break;
01970
01971 case WARN:
01972
01973 if (! (*info->callbacks->warning) (info, string, h->root.string,
01974 hash_entry_bfd (h), NULL, 0))
01975 return FALSE;
01976 break;
01977
01978 case CWARN:
01979
01980
01981
01982
01983
01984 if (h->u.undef.next != NULL || info->hash->undefs_tail == h)
01985 {
01986 if (! (*info->callbacks->warning) (info, string, h->root.string,
01987 hash_entry_bfd (h), NULL, 0))
01988 return FALSE;
01989 break;
01990 }
01991
01992 case MWARN:
01993
01994 {
01995 struct bfd_link_hash_entry *sub;
01996
01997
01998 sub = ((struct bfd_link_hash_entry *)
01999 ((*info->hash->table.newfunc)
02000 (NULL, &info->hash->table, h->root.string)));
02001 if (sub == NULL)
02002 return FALSE;
02003 *sub = *h;
02004 sub->type = bfd_link_hash_warning;
02005 sub->u.i.link = h;
02006 if (! copy)
02007 sub->u.i.warning = string;
02008 else
02009 {
02010 char *w;
02011 size_t len = strlen (string) + 1;
02012
02013 w = bfd_hash_allocate (&info->hash->table, len);
02014 if (w == NULL)
02015 return FALSE;
02016 memcpy (w, string, len);
02017 sub->u.i.warning = w;
02018 }
02019
02020 bfd_hash_replace (&info->hash->table,
02021 (struct bfd_hash_entry *) h,
02022 (struct bfd_hash_entry *) sub);
02023 if (hashp != NULL)
02024 *hashp = sub;
02025 }
02026 break;
02027 }
02028 }
02029 while (cycle);
02030
02031 return TRUE;
02032 }
02033
02034
02035
02036 bfd_boolean
02037 _bfd_generic_final_link (bfd *abfd, struct bfd_link_info *info)
02038 {
02039 bfd *sub;
02040 asection *o;
02041 struct bfd_link_order *p;
02042 size_t outsymalloc;
02043 struct generic_write_global_symbol_info wginfo;
02044
02045 bfd_get_outsymbols (abfd) = NULL;
02046 bfd_get_symcount (abfd) = 0;
02047 outsymalloc = 0;
02048
02049
02050 for (o = abfd->sections; o != NULL; o = o->next)
02051 for (p = o->link_order_head; p != NULL; p = p->next)
02052 if (p->type == bfd_indirect_link_order)
02053 p->u.indirect.section->linker_mark = TRUE;
02054
02055
02056 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
02057 if (! _bfd_generic_link_output_symbols (abfd, sub, info, &outsymalloc))
02058 return FALSE;
02059
02060
02061 wginfo.info = info;
02062 wginfo.output_bfd = abfd;
02063 wginfo.psymalloc = &outsymalloc;
02064 _bfd_generic_link_hash_traverse (_bfd_generic_hash_table (info),
02065 _bfd_generic_link_write_global_symbol,
02066 &wginfo);
02067
02068
02069
02070
02071 if (! generic_add_output_symbol (abfd, &outsymalloc, NULL))
02072 return FALSE;
02073
02074 if (info->relocatable)
02075 {
02076
02077 for (o = abfd->sections; o != NULL; o = o->next)
02078 {
02079 o->reloc_count = 0;
02080 for (p = o->link_order_head; p != NULL; p = p->next)
02081 {
02082 if (p->type == bfd_section_reloc_link_order
02083 || p->type == bfd_symbol_reloc_link_order)
02084 ++o->reloc_count;
02085 else if (p->type == bfd_indirect_link_order)
02086 {
02087 asection *input_section;
02088 bfd *input_bfd;
02089 long relsize;
02090 arelent **relocs;
02091 asymbol **symbols;
02092 long reloc_count;
02093
02094 input_section = p->u.indirect.section;
02095 input_bfd = input_section->owner;
02096 relsize = bfd_get_reloc_upper_bound (input_bfd,
02097 input_section);
02098 if (relsize < 0)
02099 return FALSE;
02100 relocs = bfd_malloc (relsize);
02101 if (!relocs && relsize != 0)
02102 return FALSE;
02103 symbols = _bfd_generic_link_get_symbols (input_bfd);
02104 reloc_count = bfd_canonicalize_reloc (input_bfd,
02105 input_section,
02106 relocs,
02107 symbols);
02108 free (relocs);
02109 if (reloc_count < 0)
02110 return FALSE;
02111 BFD_ASSERT ((unsigned long) reloc_count
02112 == input_section->reloc_count);
02113 o->reloc_count += reloc_count;
02114 }
02115 }
02116 if (o->reloc_count > 0)
02117 {
02118 bfd_size_type amt;
02119
02120 amt = o->reloc_count;
02121 amt *= sizeof (arelent *);
02122 o->orelocation = bfd_alloc (abfd, amt);
02123 if (!o->orelocation)
02124 return FALSE;
02125 o->flags |= SEC_RELOC;
02126
02127
02128 o->reloc_count = 0;
02129 }
02130 }
02131 }
02132
02133
02134 for (o = abfd->sections; o != NULL; o = o->next)
02135 {
02136 for (p = o->link_order_head; p != NULL; p = p->next)
02137 {
02138 switch (p->type)
02139 {
02140 case bfd_section_reloc_link_order:
02141 case bfd_symbol_reloc_link_order:
02142 if (! _bfd_generic_reloc_link_order (abfd, info, o, p))
02143 return FALSE;
02144 break;
02145 case bfd_indirect_link_order:
02146 if (! default_indirect_link_order (abfd, info, o, p, TRUE))
02147 return FALSE;
02148 break;
02149 default:
02150 if (! _bfd_default_link_order (abfd, info, o, p))
02151 return FALSE;
02152 break;
02153 }
02154 }
02155 }
02156
02157 return TRUE;
02158 }
02159
02160
02161
02162 static bfd_boolean
02163 generic_add_output_symbol (bfd *output_bfd, size_t *psymalloc, asymbol *sym)
02164 {
02165 if (bfd_get_symcount (output_bfd) >= *psymalloc)
02166 {
02167 asymbol **newsyms;
02168 bfd_size_type amt;
02169
02170 if (*psymalloc == 0)
02171 *psymalloc = 124;
02172 else
02173 *psymalloc *= 2;
02174 amt = *psymalloc;
02175 amt *= sizeof (asymbol *);
02176 newsyms = bfd_realloc (bfd_get_outsymbols (output_bfd), amt);
02177 if (newsyms == NULL)
02178 return FALSE;
02179 bfd_get_outsymbols (output_bfd) = newsyms;
02180 }
02181
02182 bfd_get_outsymbols (output_bfd) [bfd_get_symcount (output_bfd)] = sym;
02183 if (sym != NULL)
02184 ++ bfd_get_symcount (output_bfd);
02185
02186 return TRUE;
02187 }
02188
02189
02190
02191 bfd_boolean
02192 _bfd_generic_link_output_symbols (bfd *output_bfd,
02193 bfd *input_bfd,
02194 struct bfd_link_info *info,
02195 size_t *psymalloc)
02196 {
02197 asymbol **sym_ptr;
02198 asymbol **sym_end;
02199
02200 if (! generic_link_read_symbols (input_bfd))
02201 return FALSE;
02202
02203
02204 if (info->create_object_symbols_section != NULL)
02205 {
02206 asection *sec;
02207
02208 for (sec = input_bfd->sections; sec != NULL; sec = sec->next)
02209 {
02210 if (sec->output_section == info->create_object_symbols_section)
02211 {
02212 asymbol *newsym;
02213
02214 newsym = bfd_make_empty_symbol (input_bfd);
02215 if (!newsym)
02216 return FALSE;
02217 newsym->name = input_bfd->filename;
02218 newsym->value = 0;
02219 newsym->flags = BSF_LOCAL | BSF_FILE;
02220 newsym->section = sec;
02221
02222 if (! generic_add_output_symbol (output_bfd, psymalloc,
02223 newsym))
02224 return FALSE;
02225
02226 break;
02227 }
02228 }
02229 }
02230
02231
02232
02233 sym_ptr = _bfd_generic_link_get_symbols (input_bfd);
02234 sym_end = sym_ptr + _bfd_generic_link_get_symcount (input_bfd);
02235 for (; sym_ptr < sym_end; sym_ptr++)
02236 {
02237 asymbol *sym;
02238 struct generic_link_hash_entry *h;
02239 bfd_boolean output;
02240
02241 h = NULL;
02242 sym = *sym_ptr;
02243 if ((sym->flags & (BSF_INDIRECT
02244 | BSF_WARNING
02245 | BSF_GLOBAL
02246 | BSF_CONSTRUCTOR
02247 | BSF_WEAK)) != 0
02248 || bfd_is_und_section (bfd_get_section (sym))
02249 || bfd_is_com_section (bfd_get_section (sym))
02250 || bfd_is_ind_section (bfd_get_section (sym)))
02251 {
02252 if (sym->udata.p != NULL)
02253 h = sym->udata.p;
02254 else if ((sym->flags & BSF_CONSTRUCTOR) != 0)
02255 {
02256
02257
02258
02259
02260
02261
02262
02263
02264 h = NULL;
02265 }
02266 else if (bfd_is_und_section (bfd_get_section (sym)))
02267 h = ((struct generic_link_hash_entry *)
02268 bfd_wrapped_link_hash_lookup (output_bfd, info,
02269 bfd_asymbol_name (sym),
02270 FALSE, FALSE, TRUE));
02271 else
02272 h = _bfd_generic_link_hash_lookup (_bfd_generic_hash_table (info),
02273 bfd_asymbol_name (sym),
02274 FALSE, FALSE, TRUE);
02275
02276 if (h != NULL)
02277 {
02278
02279
02280
02281
02282
02283 if (info->hash->creator == input_bfd->xvec)
02284 {
02285 if (h->sym != NULL)
02286 *sym_ptr = sym = h->sym;
02287 }
02288
02289 switch (h->root.type)
02290 {
02291 default:
02292 case bfd_link_hash_new:
02293 abort ();
02294 case bfd_link_hash_undefined:
02295 break;
02296 case bfd_link_hash_undefweak:
02297 sym->flags |= BSF_WEAK;
02298 break;
02299 case bfd_link_hash_indirect:
02300 h = (struct generic_link_hash_entry *) h->root.u.i.link;
02301
02302 case bfd_link_hash_defined:
02303 sym->flags |= BSF_GLOBAL;
02304 sym->flags &=~ BSF_CONSTRUCTOR;
02305 sym->value = h->root.u.def.value;
02306 sym->section = h->root.u.def.section;
02307 break;
02308 case bfd_link_hash_defweak:
02309 sym->flags |= BSF_WEAK;
02310 sym->flags &=~ BSF_CONSTRUCTOR;
02311 sym->value = h->root.u.def.value;
02312 sym->section = h->root.u.def.section;
02313 break;
02314 case bfd_link_hash_common:
02315 sym->value = h->root.u.c.size;
02316 sym->flags |= BSF_GLOBAL;
02317 if (! bfd_is_com_section (sym->section))
02318 {
02319 BFD_ASSERT (bfd_is_und_section (sym->section));
02320 sym->section = bfd_com_section_ptr;
02321 }
02322
02323
02324
02325
02326
02327
02328 break;
02329 }
02330 }
02331 }
02332
02333
02334
02335 if (info->strip == strip_all
02336 || (info->strip == strip_some
02337 && bfd_hash_lookup (info->keep_hash, bfd_asymbol_name (sym),
02338 FALSE, FALSE) == NULL))
02339 output = FALSE;
02340 else if ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
02341 {
02342
02343
02344
02345
02346 if (bfd_asymbol_bfd (sym) == input_bfd
02347 && (sym->flags & BSF_NOT_AT_END) != 0)
02348 output = TRUE;
02349 else
02350 output = FALSE;
02351 }
02352 else if (bfd_is_ind_section (sym->section))
02353 output = FALSE;
02354 else if ((sym->flags & BSF_DEBUGGING) != 0)
02355 {
02356 if (info->strip == strip_none)
02357 output = TRUE;
02358 else
02359 output = FALSE;
02360 }
02361 else if (bfd_is_und_section (sym->section)
02362 || bfd_is_com_section (sym->section))
02363 output = FALSE;
02364 else if ((sym->flags & BSF_LOCAL) != 0)
02365 {
02366 if ((sym->flags & BSF_WARNING) != 0)
02367 output = FALSE;
02368 else
02369 {
02370 switch (info->discard)
02371 {
02372 default:
02373 case discard_all:
02374 output = FALSE;
02375 break;
02376 case discard_sec_merge:
02377 output = TRUE;
02378 if (info->relocatable
02379 || ! (sym->section->flags & SEC_MERGE))
02380 break;
02381
02382 case discard_l:
02383 if (bfd_is_local_label (input_bfd, sym))
02384 output = FALSE;
02385 else
02386 output = TRUE;
02387 break;
02388 case discard_none:
02389 output = TRUE;
02390 break;
02391 }
02392 }
02393 }
02394 else if ((sym->flags & BSF_CONSTRUCTOR))
02395 {
02396 if (info->strip != strip_all)
02397 output = TRUE;
02398 else
02399 output = FALSE;
02400 }
02401 else
02402 abort ();
02403
02404
02405
02406
02407
02408
02409 if ((sym->section->flags & SEC_HAS_CONTENTS) != 0
02410 && ! sym->section->linker_mark)
02411 output = FALSE;
02412
02413 if (output)
02414 {
02415 if (! generic_add_output_symbol (output_bfd, psymalloc, sym))
02416 return FALSE;
02417 if (h != NULL)
02418 h->written = TRUE;
02419 }
02420 }
02421
02422 return TRUE;
02423 }
02424
02425
02426
02427
02428 static void
02429 set_symbol_from_hash (asymbol *sym, struct bfd_link_hash_entry *h)
02430 {
02431 switch (h->type)
02432 {
02433 default:
02434 abort ();
02435 break;
02436 case bfd_link_hash_new:
02437
02438
02439 if (sym->section != NULL)
02440 {
02441 BFD_ASSERT ((sym->flags & BSF_CONSTRUCTOR) != 0);
02442 }
02443 else
02444 {
02445 sym->flags |= BSF_CONSTRUCTOR;
02446 sym->section = bfd_abs_section_ptr;
02447 sym->value = 0;
02448 }
02449 break;
02450 case bfd_link_hash_undefined:
02451 sym->section = bfd_und_section_ptr;
02452 sym->value = 0;
02453 break;
02454 case bfd_link_hash_undefweak:
02455 sym->section = bfd_und_section_ptr;
02456 sym->value = 0;
02457 sym->flags |= BSF_WEAK;
02458 break;
02459 case bfd_link_hash_defined:
02460 sym->section = h->u.def.section;
02461 sym->value = h->u.def.value;
02462 break;
02463 case bfd_link_hash_defweak:
02464 sym->flags |= BSF_WEAK;
02465 sym->section = h->u.def.section;
02466 sym->value = h->u.def.value;
02467 break;
02468 case bfd_link_hash_common:
02469 sym->value = h->u.c.size;
02470 if (sym->section == NULL)
02471 sym->section = bfd_com_section_ptr;
02472 else if (! bfd_is_com_section (sym->section))
02473 {
02474 BFD_ASSERT (bfd_is_und_section (sym->section));
02475 sym->section = bfd_com_section_ptr;
02476 }
02477
02478 break;
02479 case bfd_link_hash_indirect:
02480 case bfd_link_hash_warning:
02481
02482 break;
02483 }
02484 }
02485
02486
02487
02488
02489 bfd_boolean
02490 _bfd_generic_link_write_global_symbol (struct generic_link_hash_entry *h,
02491 void *data)
02492 {
02493 struct generic_write_global_symbol_info *wginfo = data;
02494 asymbol *sym;
02495
02496 if (h->root.type == bfd_link_hash_warning)
02497 h = (struct generic_link_hash_entry *) h->root.u.i.link;
02498
02499 if (h->written)
02500 return TRUE;
02501
02502 h->written = TRUE;
02503
02504 if (wginfo->info->strip == strip_all
02505 || (wginfo->info->strip == strip_some
02506 && bfd_hash_lookup (wginfo->info->keep_hash, h->root.root.string,
02507 FALSE, FALSE) == NULL))
02508 return TRUE;
02509
02510 if (h->sym != NULL)
02511 sym = h->sym;
02512 else
02513 {
02514 sym = bfd_make_empty_symbol (wginfo->output_bfd);
02515 if (!sym)
02516 return FALSE;
02517 sym->name = h->root.root.string;
02518 sym->flags = 0;
02519 }
02520
02521 set_symbol_from_hash (sym, &h->root);
02522
02523 sym->flags |= BSF_GLOBAL;
02524
02525 if (! generic_add_output_symbol (wginfo->output_bfd, wginfo->psymalloc,
02526 sym))
02527 {
02528
02529 abort ();
02530 }
02531
02532 return TRUE;
02533 }
02534
02535
02536
02537 bfd_boolean
02538 _bfd_generic_reloc_link_order (bfd *abfd,
02539 struct bfd_link_info *info,
02540 asection *sec,
02541 struct bfd_link_order *link_order)
02542 {
02543 arelent *r;
02544
02545 if (! info->relocatable)
02546 abort ();
02547 if (sec->orelocation == NULL)
02548 abort ();
02549
02550 r = bfd_alloc (abfd, sizeof (arelent));
02551 if (r == NULL)
02552 return FALSE;
02553
02554 r->address = link_order->offset;
02555 r->howto = bfd_reloc_type_lookup (abfd, link_order->u.reloc.p->reloc);
02556 if (r->howto == 0)
02557 {
02558 bfd_set_error (bfd_error_bad_value);
02559 return FALSE;
02560 }
02561
02562
02563 if (link_order->type == bfd_section_reloc_link_order)
02564 r->sym_ptr_ptr = link_order->u.reloc.p->u.section->symbol_ptr_ptr;
02565 else
02566 {
02567 struct generic_link_hash_entry *h;
02568
02569 h = ((struct generic_link_hash_entry *)
02570 bfd_wrapped_link_hash_lookup (abfd, info,
02571 link_order->u.reloc.p->u.name,
02572 FALSE, FALSE, TRUE));
02573 if (h == NULL
02574 || ! h->written)
02575 {
02576 if (! ((*info->callbacks->unattached_reloc)
02577 (info, link_order->u.reloc.p->u.name, NULL, NULL, 0)))
02578 return FALSE;
02579 bfd_set_error (bfd_error_bad_value);
02580 return FALSE;
02581 }
02582 r->sym_ptr_ptr = &h->sym;
02583 }
02584
02585
02586
02587 if (! r->howto->partial_inplace)
02588 r->addend = link_order->u.reloc.p->addend;
02589 else
02590 {
02591 bfd_size_type size;
02592 bfd_reloc_status_type rstat;
02593 bfd_byte *buf;
02594 bfd_boolean ok;
02595 file_ptr loc;
02596
02597 size = bfd_get_reloc_size (r->howto);
02598 buf = bfd_zmalloc (size);
02599 if (buf == NULL)
02600 return FALSE;
02601 rstat = _bfd_relocate_contents (r->howto, abfd,
02602 (bfd_vma) link_order->u.reloc.p->addend,
02603 buf);
02604 switch (rstat)
02605 {
02606 case bfd_reloc_ok:
02607 break;
02608 default:
02609 case bfd_reloc_outofrange:
02610 abort ();
02611 case bfd_reloc_overflow:
02612 if (! ((*info->callbacks->reloc_overflow)
02613 (info, NULL,
02614 (link_order->type == bfd_section_reloc_link_order
02615 ? bfd_section_name (abfd, link_order->u.reloc.p->u.section)
02616 : link_order->u.reloc.p->u.name),
02617 r->howto->name, link_order->u.reloc.p->addend,
02618 NULL, NULL, 0)))
02619 {
02620 free (buf);
02621 return FALSE;
02622 }
02623 break;
02624 }
02625 loc = link_order->offset * bfd_octets_per_byte (abfd);
02626 ok = bfd_set_section_contents (abfd, sec, buf, loc, size);
02627 free (buf);
02628 if (! ok)
02629 return FALSE;
02630
02631 r->addend = 0;
02632 }
02633
02634 sec->orelocation[sec->reloc_count] = r;
02635 ++sec->reloc_count;
02636
02637 return TRUE;
02638 }
02639
02640
02641
02642 struct bfd_link_order *
02643 bfd_new_link_order (bfd *abfd, asection *section)
02644 {
02645 bfd_size_type amt = sizeof (struct bfd_link_order);
02646 struct bfd_link_order *new;
02647
02648 new = bfd_zalloc (abfd, amt);
02649 if (!new)
02650 return NULL;
02651
02652 new->type = bfd_undefined_link_order;
02653
02654 if (section->link_order_tail != NULL)
02655 section->link_order_tail->next = new;
02656 else
02657 section->link_order_head = new;
02658 section->link_order_tail = new;
02659
02660 return new;
02661 }
02662
02663
02664
02665
02666
02667 bfd_boolean
02668 _bfd_default_link_order (bfd *abfd,
02669 struct bfd_link_info *info,
02670 asection *sec,
02671 struct bfd_link_order *link_order)
02672 {
02673 switch (link_order->type)
02674 {
02675 case bfd_undefined_link_order:
02676 case bfd_section_reloc_link_order:
02677 case bfd_symbol_reloc_link_order:
02678 default:
02679 abort ();
02680 case bfd_indirect_link_order:
02681 return default_indirect_link_order (abfd, info, sec, link_order,
02682 FALSE);
02683 case bfd_data_link_order:
02684 return default_data_link_order (abfd, info, sec, link_order);
02685 }
02686 }
02687
02688
02689
02690 static bfd_boolean
02691 default_data_link_order (bfd *abfd,
02692 struct bfd_link_info *info ATTRIBUTE_UNUSED,
02693 asection *sec,
02694 struct bfd_link_order *link_order)
02695 {
02696 bfd_size_type size;
02697 size_t fill_size;
02698 bfd_byte *fill;
02699 file_ptr loc;
02700 bfd_boolean result;
02701
02702 BFD_ASSERT ((sec->flags & SEC_HAS_CONTENTS) != 0);
02703
02704 size = link_order->size;
02705 if (size == 0)
02706 return TRUE;
02707
02708 fill = link_order->u.data.contents;
02709 fill_size = link_order->u.data.size;
02710 if (fill_size != 0 && fill_size < size)
02711 {
02712 bfd_byte *p;
02713 fill = bfd_malloc (size);
02714 if (fill == NULL)
02715 return FALSE;
02716 p = fill;
02717 if (fill_size == 1)
02718 memset (p, (int) link_order->u.data.contents[0], (size_t) size);
02719 else
02720 {
02721 do
02722 {
02723 memcpy (p, link_order->u.data.contents, fill_size);
02724 p += fill_size;
02725 size -= fill_size;
02726 }
02727 while (size >= fill_size);
02728 if (size != 0)
02729 memcpy (p, link_order->u.data.contents, (size_t) size);
02730 size = link_order->size;
02731 }
02732 }
02733
02734 loc = link_order->offset * bfd_octets_per_byte (abfd);
02735 result = bfd_set_section_contents (abfd, sec, fill, loc, size);
02736
02737 if (fill != link_order->u.data.contents)
02738 free (fill);
02739 return result;
02740 }
02741
02742
02743
02744 static bfd_boolean
02745 default_indirect_link_order (bfd *output_bfd,
02746 struct bfd_link_info *info,
02747 asection *output_section,
02748 struct bfd_link_order *link_order,
02749 bfd_boolean generic_linker)
02750 {
02751 asection *input_section;
02752 bfd *input_bfd;
02753 bfd_byte *contents = NULL;
02754 bfd_byte *new_contents;
02755 bfd_size_type sec_size;
02756 file_ptr loc;
02757
02758 BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
02759
02760 if (link_order->size == 0)
02761 return TRUE;
02762
02763 input_section = link_order->u.indirect.section;
02764 input_bfd = input_section->owner;
02765
02766 BFD_ASSERT (input_section->output_section == output_section);
02767 BFD_ASSERT (input_section->output_offset == link_order->offset);
02768 BFD_ASSERT (input_section->size == link_order->size);
02769
02770 if (info->relocatable
02771 && input_section->reloc_count > 0
02772 && output_section->orelocation == NULL)
02773 {
02774
02775
02776
02777
02778
02779 (*_bfd_error_handler)
02780 (_("Attempt to do relocatable link with %s input and %s output"),
02781 bfd_get_target (input_bfd), bfd_get_target (output_bfd));
02782 bfd_set_error (bfd_error_wrong_format);
02783 return FALSE;
02784 }
02785
02786 if (! generic_linker)
02787 {
02788 asymbol **sympp;
02789 asymbol **symppend;
02790
02791
02792
02793
02794
02795 if (! generic_link_read_symbols (input_bfd))
02796 return FALSE;
02797
02798
02799
02800
02801
02802
02803 sympp = _bfd_generic_link_get_symbols (input_bfd);
02804 symppend = sympp + _bfd_generic_link_get_symcount (input_bfd);
02805 for (; sympp < symppend; sympp++)
02806 {
02807 asymbol *sym;
02808 struct bfd_link_hash_entry *h;
02809
02810 sym = *sympp;
02811
02812 if ((sym->flags & (BSF_INDIRECT
02813 | BSF_WARNING
02814 | BSF_GLOBAL
02815 | BSF_CONSTRUCTOR
02816 | BSF_WEAK)) != 0
02817 || bfd_is_und_section (bfd_get_section (sym))
02818 || bfd_is_com_section (bfd_get_section (sym))
02819 || bfd_is_ind_section (bfd_get_section (sym)))
02820 {
02821
02822
02823 if (sym->udata.p != NULL)
02824 h = sym->udata.p;
02825 else if (bfd_is_und_section (bfd_get_section (sym)))
02826 h = bfd_wrapped_link_hash_lookup (output_bfd, info,
02827 bfd_asymbol_name (sym),
02828 FALSE, FALSE, TRUE);
02829 else
02830 h = bfd_link_hash_lookup (info->hash,
02831 bfd_asymbol_name (sym),
02832 FALSE, FALSE, TRUE);
02833 if (h != NULL)
02834 set_symbol_from_hash (sym, h);
02835 }
02836 }
02837 }
02838
02839
02840 sec_size = (input_section->rawsize > input_section->size
02841 ? input_section->rawsize
02842 : input_section->size);
02843 contents = bfd_malloc (sec_size);
02844 if (contents == NULL && sec_size != 0)
02845 goto error_return;
02846 new_contents = (bfd_get_relocated_section_contents
02847 (output_bfd, info, link_order, contents, info->relocatable,
02848 _bfd_generic_link_get_symbols (input_bfd)));
02849 if (!new_contents)
02850 goto error_return;
02851
02852
02853 loc = link_order->offset * bfd_octets_per_byte (output_bfd);
02854 if (! bfd_set_section_contents (output_bfd, output_section,
02855 new_contents, loc, link_order->size))
02856 goto error_return;
02857
02858 if (contents != NULL)
02859 free (contents);
02860 return TRUE;
02861
02862 error_return:
02863 if (contents != NULL)
02864 free (contents);
02865 return FALSE;
02866 }
02867
02868
02869
02870
02871 unsigned int
02872 _bfd_count_link_order_relocs (struct bfd_link_order *link_order)
02873 {
02874 register unsigned int c;
02875 register struct bfd_link_order *l;
02876
02877 c = 0;
02878 for (l = link_order; l != NULL; l = l->next)
02879 {
02880 if (l->type == bfd_section_reloc_link_order
02881 || l->type == bfd_symbol_reloc_link_order)
02882 ++c;
02883 }
02884
02885 return c;
02886 }
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905 bfd_boolean
02906 _bfd_generic_link_split_section (bfd *abfd ATTRIBUTE_UNUSED,
02907 asection *sec ATTRIBUTE_UNUSED)
02908 {
02909 return FALSE;
02910 }
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939 static struct bfd_hash_table _bfd_section_already_linked_table;
02940
02941
02942
02943
02944
02945 void
02946 bfd_section_already_linked_table_traverse
02947 (bfd_boolean (*func) (struct bfd_section_already_linked_hash_entry *,
02948 void *), void *info)
02949 {
02950 bfd_hash_traverse (&_bfd_section_already_linked_table,
02951 (bfd_boolean (*) (struct bfd_hash_entry *,
02952 void *)) func,
02953 info);
02954 }
02955
02956 struct bfd_section_already_linked_hash_entry *
02957 bfd_section_already_linked_table_lookup (const char *name)
02958 {
02959 return ((struct bfd_section_already_linked_hash_entry *)
02960 bfd_hash_lookup (&_bfd_section_already_linked_table, name,
02961 TRUE, FALSE));
02962 }
02963
02964 void
02965 bfd_section_already_linked_table_insert
02966 (struct bfd_section_already_linked_hash_entry *already_linked_list,
02967 asection *sec)
02968 {
02969 struct bfd_section_already_linked *l;
02970
02971
02972
02973 l = bfd_hash_allocate (&_bfd_section_already_linked_table, sizeof *l);
02974 l->sec = sec;
02975 l->next = already_linked_list->entry;
02976 already_linked_list->entry = l;
02977 }
02978
02979 static struct bfd_hash_entry *
02980 already_linked_newfunc (struct bfd_hash_entry *entry ATTRIBUTE_UNUSED,
02981 struct bfd_hash_table *table,
02982 const char *string ATTRIBUTE_UNUSED)
02983 {
02984 struct bfd_section_already_linked_hash_entry *ret =
02985 bfd_hash_allocate (table, sizeof *ret);
02986
02987 ret->entry = NULL;
02988
02989 return &ret->root;
02990 }
02991
02992 bfd_boolean
02993 bfd_section_already_linked_table_init (void)
02994 {
02995 return bfd_hash_table_init_n (&_bfd_section_already_linked_table,
02996 already_linked_newfunc, 42);
02997 }
02998
02999 void
03000 bfd_section_already_linked_table_free (void)
03001 {
03002 bfd_hash_table_free (&_bfd_section_already_linked_table);
03003 }
03004
03005
03006
03007 void
03008 _bfd_generic_section_already_linked (bfd *abfd, asection *sec)
03009 {
03010 flagword flags;
03011 const char *name;
03012 struct bfd_section_already_linked *l;
03013 struct bfd_section_already_linked_hash_entry *already_linked_list;
03014
03015 flags = sec->flags;
03016 if ((flags & SEC_LINK_ONCE) == 0)
03017 return;
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032 name = bfd_get_section_name (abfd, sec);
03033
03034 already_linked_list = bfd_section_already_linked_table_lookup (name);
03035
03036 for (l = already_linked_list->entry; l != NULL; l = l->next)
03037 {
03038 bfd_boolean skip = FALSE;
03039 struct coff_comdat_info *s_comdat
03040 = bfd_coff_get_comdat_section (abfd, sec);
03041 struct coff_comdat_info *l_comdat
03042 = bfd_coff_get_comdat_section (l->sec->owner, l->sec);
03043
03044
03045
03046
03047
03048
03049
03050
03051 if ((l->sec->flags & SEC_GROUP) != 0)
03052 skip = TRUE;
03053 else if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
03054 {
03055 if (s_comdat != NULL
03056 && l_comdat != NULL
03057 && strcmp (s_comdat->name, l_comdat->name) != 0)
03058 skip = TRUE;
03059 }
03060 else if (l_comdat != NULL)
03061 skip = TRUE;
03062
03063 if (!skip)
03064 {
03065
03066
03067 switch (flags & SEC_LINK_DUPLICATES)
03068 {
03069 default:
03070 abort ();
03071
03072 case SEC_LINK_DUPLICATES_DISCARD:
03073 break;
03074
03075 case SEC_LINK_DUPLICATES_ONE_ONLY:
03076 (*_bfd_error_handler)
03077 (_("%B: warning: ignoring duplicate section `%A'\n"),
03078 abfd, sec);
03079 break;
03080
03081 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
03082
03083
03084
03085
03086
03087
03088 case SEC_LINK_DUPLICATES_SAME_SIZE:
03089 if (sec->size != l->sec->size)
03090 (*_bfd_error_handler)
03091 (_("%B: warning: duplicate section `%A' has different size\n"),
03092 abfd, sec);
03093 break;
03094 }
03095
03096
03097
03098
03099
03100
03101 sec->output_section = bfd_abs_section_ptr;
03102 sec->kept_section = l->sec;
03103
03104 return;
03105 }
03106 }
03107
03108
03109 bfd_section_already_linked_table_insert (already_linked_list, sec);
03110 }