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
00027
00028
00029
00030
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 #ifdef COFF_WITH_PE
00309 #include "peicode.h"
00310 #else
00311 #include "coffswap.h"
00312 #endif
00313
00314 #define STRING_SIZE_SIZE (4)
00315
00316 #define DOT_DEBUG ".debug"
00317 #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
00318
00319 static long sec_to_styp_flags
00320 PARAMS ((const char *, flagword));
00321 static bfd_boolean styp_to_sec_flags
00322 PARAMS ((bfd *, PTR, const char *, asection *, flagword *));
00323 static bfd_boolean coff_bad_format_hook
00324 PARAMS ((bfd *, PTR));
00325 static void coff_set_custom_section_alignment
00326 PARAMS ((bfd *, asection *, const struct coff_section_alignment_entry *,
00327 const unsigned int));
00328 static bfd_boolean coff_new_section_hook
00329 PARAMS ((bfd *, asection *));
00330 static bfd_boolean coff_set_arch_mach_hook
00331 PARAMS ((bfd *, PTR));
00332 static bfd_boolean coff_write_relocs
00333 PARAMS ((bfd *, int));
00334 static bfd_boolean coff_set_flags
00335 PARAMS ((bfd *, unsigned int *, unsigned short *));
00336 static bfd_boolean coff_set_arch_mach
00337 PARAMS ((bfd *, enum bfd_architecture, unsigned long)) ATTRIBUTE_UNUSED;
00338 static bfd_boolean coff_compute_section_file_positions
00339 PARAMS ((bfd *));
00340 static bfd_boolean coff_write_object_contents
00341 PARAMS ((bfd *)) ATTRIBUTE_UNUSED;
00342 static bfd_boolean coff_set_section_contents
00343 PARAMS ((bfd *, asection *, const PTR, file_ptr, bfd_size_type));
00344 static PTR buy_and_read
00345 PARAMS ((bfd *, file_ptr, bfd_size_type));
00346 static bfd_boolean coff_slurp_line_table
00347 PARAMS ((bfd *, asection *));
00348 static bfd_boolean coff_slurp_symbol_table
00349 PARAMS ((bfd *));
00350 static enum coff_symbol_classification coff_classify_symbol
00351 PARAMS ((bfd *, struct internal_syment *));
00352 static bfd_boolean coff_slurp_reloc_table
00353 PARAMS ((bfd *, asection *, asymbol **));
00354 static long coff_canonicalize_reloc
00355 PARAMS ((bfd *, asection *, arelent **, asymbol **));
00356 #ifndef coff_mkobject_hook
00357 static PTR coff_mkobject_hook
00358 PARAMS ((bfd *, PTR, PTR));
00359 #endif
00360 #ifdef COFF_WITH_PE
00361 static flagword handle_COMDAT
00362 PARAMS ((bfd *, flagword, PTR, const char *, asection *));
00363 #endif
00364 #ifdef COFF_IMAGE_WITH_PE
00365 static bfd_boolean coff_read_word
00366 PARAMS ((bfd *, unsigned int *));
00367 static unsigned int coff_compute_checksum
00368 PARAMS ((bfd *));
00369 static bfd_boolean coff_apply_checksum
00370 PARAMS ((bfd *));
00371 #endif
00372 #ifdef TICOFF
00373 static bfd_boolean ticoff0_bad_format_hook
00374 PARAMS ((bfd *, PTR ));
00375 static bfd_boolean ticoff1_bad_format_hook
00376 PARAMS ((bfd *, PTR ));
00377 #endif
00378
00379
00380
00381
00382
00383
00384
00385
00386 #ifndef COFF_WITH_PE
00387
00388
00389 #ifdef STYP_DEBUG
00390 #define STYP_XCOFF_DEBUG STYP_DEBUG
00391 #else
00392 #define STYP_XCOFF_DEBUG STYP_INFO
00393 #endif
00394
00395 #ifdef COFF_ALIGN_IN_S_FLAGS
00396 #define STYP_DEBUG_INFO STYP_DSECT
00397 #else
00398 #define STYP_DEBUG_INFO STYP_INFO
00399 #endif
00400
00401 static long
00402 sec_to_styp_flags (sec_name, sec_flags)
00403 const char *sec_name;
00404 flagword sec_flags;
00405 {
00406 long styp_flags = 0;
00407
00408 if (!strcmp (sec_name, _TEXT))
00409 {
00410 styp_flags = STYP_TEXT;
00411 }
00412 else if (!strcmp (sec_name, _DATA))
00413 {
00414 styp_flags = STYP_DATA;
00415 }
00416 else if (!strcmp (sec_name, _BSS))
00417 {
00418 styp_flags = STYP_BSS;
00419 #ifdef _COMMENT
00420 }
00421 else if (!strcmp (sec_name, _COMMENT))
00422 {
00423 styp_flags = STYP_INFO;
00424 #endif
00425 #ifdef _LIB
00426 }
00427 else if (!strcmp (sec_name, _LIB))
00428 {
00429 styp_flags = STYP_LIB;
00430 #endif
00431 #ifdef _LIT
00432 }
00433 else if (!strcmp (sec_name, _LIT))
00434 {
00435 styp_flags = STYP_LIT;
00436 #endif
00437 }
00438 else if (!strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1))
00439 {
00440
00441 if (!sec_name[6])
00442 styp_flags = STYP_XCOFF_DEBUG;
00443 else
00444 styp_flags = STYP_DEBUG_INFO;
00445 }
00446 else if (!strncmp (sec_name, ".stab", 5))
00447 {
00448 styp_flags = STYP_DEBUG_INFO;
00449 }
00450 #ifdef COFF_LONG_SECTION_NAMES
00451 else if (!strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1))
00452 {
00453 styp_flags = STYP_DEBUG_INFO;
00454 }
00455 #endif
00456 #ifdef RS6000COFF_C
00457 else if (!strcmp (sec_name, _PAD))
00458 {
00459 styp_flags = STYP_PAD;
00460 }
00461 else if (!strcmp (sec_name, _LOADER))
00462 {
00463 styp_flags = STYP_LOADER;
00464 }
00465 else if (!strcmp (sec_name, _EXCEPT))
00466 {
00467 styp_flags = STYP_EXCEPT;
00468 }
00469 else if (!strcmp (sec_name, _TYPCHK))
00470 {
00471 styp_flags = STYP_TYPCHK;
00472 }
00473 #endif
00474
00475 else if (sec_flags & SEC_CODE)
00476 {
00477 styp_flags = STYP_TEXT;
00478 }
00479 else if (sec_flags & SEC_DATA)
00480 {
00481 styp_flags = STYP_DATA;
00482 }
00483 else if (sec_flags & SEC_READONLY)
00484 {
00485 #ifdef STYP_LIT
00486 styp_flags = STYP_LIT;
00487 #else
00488 styp_flags = STYP_TEXT;
00489 #endif
00490 }
00491 else if (sec_flags & SEC_LOAD)
00492 {
00493 styp_flags = STYP_TEXT;
00494 }
00495 else if (sec_flags & SEC_ALLOC)
00496 {
00497 styp_flags = STYP_BSS;
00498 }
00499
00500 #ifdef STYP_CLINK
00501 if (sec_flags & SEC_TIC54X_CLINK)
00502 styp_flags |= STYP_CLINK;
00503 #endif
00504
00505 #ifdef STYP_BLOCK
00506 if (sec_flags & SEC_TIC54X_BLOCK)
00507 styp_flags |= STYP_BLOCK;
00508 #endif
00509
00510 #ifdef STYP_NOLOAD
00511 if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
00512 styp_flags |= STYP_NOLOAD;
00513 #endif
00514
00515 return styp_flags;
00516 }
00517
00518 #else
00519
00520
00521
00522
00523
00524
00525
00526 static long
00527 sec_to_styp_flags (sec_name, sec_flags)
00528 const char *sec_name;
00529 flagword sec_flags;
00530 {
00531 long styp_flags = 0;
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542 if (strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
00543 || strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0)
00544 sec_flags = SEC_READONLY | SEC_DEBUGGING;
00545
00546
00547
00548
00549 if ((sec_flags & SEC_CODE) != 0)
00550 styp_flags |= IMAGE_SCN_CNT_CODE;
00551 if ((sec_flags & SEC_DATA) != 0)
00552 styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
00553 if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
00554 styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;
00555
00556
00557
00558 #ifdef STYP_NOLOAD
00559 if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
00560 styp_flags |= STYP_NOLOAD;
00561 #endif
00562 if ((sec_flags & SEC_IS_COMMON) != 0)
00563 styp_flags |= IMAGE_SCN_LNK_COMDAT;
00564 if ((sec_flags & SEC_DEBUGGING) != 0)
00565 styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
00566 if ((sec_flags & SEC_EXCLUDE) != 0)
00567 styp_flags |= IMAGE_SCN_LNK_REMOVE;
00568 if ((sec_flags & SEC_NEVER_LOAD) != 0)
00569 styp_flags |= IMAGE_SCN_LNK_REMOVE;
00570
00571
00572 if (sec_flags & SEC_LINK_ONCE)
00573 styp_flags |= IMAGE_SCN_LNK_COMDAT;
00574
00575
00576
00577
00578
00579
00580
00581 styp_flags |= IMAGE_SCN_MEM_READ;
00582 if ((sec_flags & SEC_READONLY) == 0)
00583 styp_flags |= IMAGE_SCN_MEM_WRITE;
00584 if (sec_flags & SEC_CODE)
00585 styp_flags |= IMAGE_SCN_MEM_EXECUTE;
00586 if (sec_flags & SEC_COFF_SHARED)
00587 styp_flags |= IMAGE_SCN_MEM_SHARED;
00588
00589 return styp_flags;
00590 }
00591
00592 #endif
00593
00594
00595
00596
00597
00598
00599 #ifndef COFF_WITH_PE
00600
00601 static bfd_boolean
00602 styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
00603 bfd *abfd ATTRIBUTE_UNUSED;
00604 PTR hdr;
00605 const char *name;
00606 asection *section ATTRIBUTE_UNUSED;
00607 flagword *flags_ptr;
00608 {
00609 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
00610 long styp_flags = internal_s->s_flags;
00611 flagword sec_flags = 0;
00612
00613 #ifdef STYP_BLOCK
00614 if (styp_flags & STYP_BLOCK)
00615 sec_flags |= SEC_TIC54X_BLOCK;
00616 #endif
00617
00618 #ifdef STYP_CLINK
00619 if (styp_flags & STYP_CLINK)
00620 sec_flags |= SEC_TIC54X_CLINK;
00621 #endif
00622
00623 #ifdef STYP_NOLOAD
00624 if (styp_flags & STYP_NOLOAD)
00625 sec_flags |= SEC_NEVER_LOAD;
00626 #endif
00627
00628
00629
00630 if (styp_flags & STYP_TEXT)
00631 {
00632 if (sec_flags & SEC_NEVER_LOAD)
00633 sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
00634 else
00635 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
00636 }
00637 else if (styp_flags & STYP_DATA)
00638 {
00639 if (sec_flags & SEC_NEVER_LOAD)
00640 sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
00641 else
00642 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
00643 }
00644 else if (styp_flags & STYP_BSS)
00645 {
00646 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
00647 if (sec_flags & SEC_NEVER_LOAD)
00648 sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
00649 else
00650 #endif
00651 sec_flags |= SEC_ALLOC;
00652 }
00653 else if (styp_flags & STYP_INFO)
00654 {
00655
00656
00657
00658
00659
00660
00661 #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
00662 sec_flags |= SEC_DEBUGGING;
00663 #endif
00664 }
00665 else if (styp_flags & STYP_PAD)
00666 sec_flags = 0;
00667 else if (strcmp (name, _TEXT) == 0)
00668 {
00669 if (sec_flags & SEC_NEVER_LOAD)
00670 sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
00671 else
00672 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
00673 }
00674 else if (strcmp (name, _DATA) == 0)
00675 {
00676 if (sec_flags & SEC_NEVER_LOAD)
00677 sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
00678 else
00679 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
00680 }
00681 else if (strcmp (name, _BSS) == 0)
00682 {
00683 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
00684 if (sec_flags & SEC_NEVER_LOAD)
00685 sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
00686 else
00687 #endif
00688 sec_flags |= SEC_ALLOC;
00689 }
00690 else if (strncmp (name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
00691 #ifdef _COMMENT
00692 || strcmp (name, _COMMENT) == 0
00693 #endif
00694 #ifdef COFF_LONG_SECTION_NAMES
00695 || strncmp (name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0
00696 #endif
00697 || strncmp (name, ".stab", 5) == 0)
00698 {
00699 #ifdef COFF_PAGE_SIZE
00700 sec_flags |= SEC_DEBUGGING;
00701 #endif
00702 }
00703 #ifdef _LIB
00704 else if (strcmp (name, _LIB) == 0)
00705 ;
00706 #endif
00707 #ifdef _LIT
00708 else if (strcmp (name, _LIT) == 0)
00709 sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
00710 #endif
00711 else
00712 sec_flags |= SEC_ALLOC | SEC_LOAD;
00713
00714 #ifdef STYP_LIT
00715 if ((styp_flags & STYP_LIT) == STYP_LIT)
00716 sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
00717 #endif
00718
00719 #ifdef STYP_OTHER_LOAD
00720 if (styp_flags & STYP_OTHER_LOAD)
00721 sec_flags = (SEC_LOAD | SEC_ALLOC);
00722 #endif
00723
00724 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
00725
00726
00727
00728
00729
00730
00731 if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
00732 sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
00733 #endif
00734
00735 if (flags_ptr == NULL)
00736 return FALSE;
00737
00738 * flags_ptr = sec_flags;
00739 return TRUE;
00740 }
00741
00742 #else
00743
00744 static flagword
00745 handle_COMDAT (abfd, sec_flags, hdr, name, section)
00746 bfd * abfd;
00747 flagword sec_flags;
00748 PTR hdr;
00749 const char *name;
00750 asection *section;
00751 {
00752 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
00753 bfd_byte *esymstart, *esym, *esymend;
00754 int seen_state = 0;
00755 char *target_name = NULL;
00756
00757 sec_flags |= SEC_LINK_ONCE;
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776 if (! _bfd_coff_get_external_symbols (abfd))
00777 return sec_flags;
00778
00779 esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
00780 esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
00781
00782 while (esym < esymend)
00783 {
00784 struct internal_syment isym;
00785 char buf[SYMNMLEN + 1];
00786 const char *symname;
00787
00788 bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &isym);
00789
00790 if (sizeof (internal_s->s_name) > SYMNMLEN)
00791 {
00792
00793
00794 abort ();
00795 }
00796
00797 if (isym.n_scnum == section->target_index)
00798 {
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824 symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
00825
00826 if (symname == NULL)
00827 abort ();
00828
00829 switch (seen_state)
00830 {
00831 case 0:
00832 {
00833
00834 union internal_auxent aux;
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852 if (! (isym.n_sclass == C_STAT
00853 && isym.n_type == T_NULL
00854 && isym.n_value == 0))
00855 abort ();
00856
00857
00858
00859
00860
00861
00862 if (strcmp (name, symname) != 0)
00863 _bfd_error_handler (_("%B: warning: COMDAT symbol '%s' does not match section name '%s'"),
00864 abfd, symname, name);
00865
00866 seen_state = 1;
00867
00868
00869 bfd_coff_swap_aux_in (abfd, (PTR) (esym + bfd_coff_symesz (abfd)),
00870 isym.n_type, isym.n_sclass,
00871 0, isym.n_numaux, (PTR) &aux);
00872
00873 target_name = strchr (name, '$');
00874 if (target_name != NULL)
00875 {
00876
00877 seen_state = 2;
00878
00879 target_name += 1;
00880 }
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898 switch (aux.x_scn.x_comdat)
00899 {
00900 case IMAGE_COMDAT_SELECT_NODUPLICATES:
00901 #ifdef STRICT_PE_FORMAT
00902 sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
00903 #else
00904 sec_flags &= ~SEC_LINK_ONCE;
00905 #endif
00906 break;
00907
00908 case IMAGE_COMDAT_SELECT_ANY:
00909 sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
00910 break;
00911
00912 case IMAGE_COMDAT_SELECT_SAME_SIZE:
00913 sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
00914 break;
00915
00916 case IMAGE_COMDAT_SELECT_EXACT_MATCH:
00917
00918 sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
00919 break;
00920
00921
00922
00923
00924
00925
00926
00927
00928 case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
00929 #ifdef STRICT_PE_FORMAT
00930
00931 sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
00932 #else
00933 sec_flags &= ~SEC_LINK_ONCE;
00934 #endif
00935 break;
00936
00937 default:
00938
00939
00940 sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
00941 break;
00942 }
00943 }
00944 break;
00945
00946 case 2:
00947
00948
00949 #ifndef TARGET_UNDERSCORE
00950 #define TARGET_UNDERSCORE 0
00951 #endif
00952
00953 if (strcmp (target_name,
00954 symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
00955 {
00956
00957 esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
00958 continue;
00959 }
00960
00961 case 1:
00962
00963
00964 {
00965 char *newname;
00966 bfd_size_type amt;
00967
00968
00969
00970
00971
00972
00973 amt = sizeof (struct coff_comdat_info);
00974 coff_section_data (abfd, section)->comdat
00975 = bfd_alloc (abfd, amt);
00976 if (coff_section_data (abfd, section)->comdat == NULL)
00977 abort ();
00978
00979 coff_section_data (abfd, section)->comdat->symbol =
00980 (esym - esymstart) / bfd_coff_symesz (abfd);
00981
00982 amt = strlen (symname) + 1;
00983 newname = bfd_alloc (abfd, amt);
00984 if (newname == NULL)
00985 abort ();
00986
00987 strcpy (newname, symname);
00988 coff_section_data (abfd, section)->comdat->name
00989 = newname;
00990 }
00991
00992 goto breakloop;
00993 }
00994 }
00995
00996 esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
00997 }
00998
00999 breakloop:
01000 return sec_flags;
01001 }
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013 static bfd_boolean
01014 styp_to_sec_flags (abfd, hdr, name, section, flags_ptr)
01015 bfd *abfd;
01016 PTR hdr;
01017 const char *name;
01018 asection *section;
01019 flagword *flags_ptr;
01020 {
01021 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
01022 long styp_flags = internal_s->s_flags;
01023 flagword sec_flags;
01024 bfd_boolean result = TRUE;
01025
01026
01027 sec_flags = SEC_READONLY;
01028
01029
01030 while (styp_flags)
01031 {
01032 long flag = styp_flags & - styp_flags;
01033 char * unhandled = NULL;
01034
01035 styp_flags &= ~ flag;
01036
01037
01038
01039
01040
01041 switch (flag)
01042 {
01043 case STYP_DSECT:
01044 unhandled = "STYP_DSECT";
01045 break;
01046 case STYP_GROUP:
01047 unhandled = "STYP_GROUP";
01048 break;
01049 case STYP_COPY:
01050 unhandled = "STYP_COPY";
01051 break;
01052 case STYP_OVER:
01053 unhandled = "STYP_OVER";
01054 break;
01055 #ifdef SEC_NEVER_LOAD
01056 case STYP_NOLOAD:
01057 sec_flags |= SEC_NEVER_LOAD;
01058 break;
01059 #endif
01060 case IMAGE_SCN_MEM_READ:
01061
01062 break;
01063 case IMAGE_SCN_TYPE_NO_PAD:
01064
01065 break;
01066 case IMAGE_SCN_LNK_OTHER:
01067 unhandled = "IMAGE_SCN_LNK_OTHER";
01068 break;
01069 case IMAGE_SCN_MEM_NOT_CACHED:
01070 unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
01071 break;
01072 case IMAGE_SCN_MEM_NOT_PAGED:
01073
01074
01075
01076 _bfd_error_handler (_("%B: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section %s"),
01077 abfd, name);
01078 break;
01079 case IMAGE_SCN_MEM_EXECUTE:
01080 sec_flags |= SEC_CODE;
01081 break;
01082 case IMAGE_SCN_MEM_WRITE:
01083 sec_flags &= ~ SEC_READONLY;
01084 break;
01085 case IMAGE_SCN_MEM_DISCARDABLE:
01086
01087
01088
01089 if (strncmp (name, ".reloc", sizeof ".reloc" - 1) != 0)
01090 sec_flags |= SEC_DEBUGGING;
01091 break;
01092 case IMAGE_SCN_MEM_SHARED:
01093 sec_flags |= SEC_COFF_SHARED;
01094 break;
01095 case IMAGE_SCN_LNK_REMOVE:
01096 sec_flags |= SEC_EXCLUDE;
01097 break;
01098 case IMAGE_SCN_CNT_CODE:
01099 sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
01100 break;
01101 case IMAGE_SCN_CNT_INITIALIZED_DATA:
01102 sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
01103 break;
01104 case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
01105 sec_flags |= SEC_ALLOC;
01106 break;
01107 case IMAGE_SCN_LNK_INFO:
01108
01109
01110
01111
01112
01113
01114 #ifdef COFF_PAGE_SIZE
01115 sec_flags |= SEC_DEBUGGING;
01116 #endif
01117 break;
01118 case IMAGE_SCN_LNK_COMDAT:
01119
01120 sec_flags = handle_COMDAT (abfd, sec_flags, hdr, name, section);
01121 break;
01122 default:
01123
01124 break;
01125 }
01126
01127
01128 if (unhandled != NULL)
01129 {
01130 (*_bfd_error_handler)
01131 (_("%B (%s): Section flag %s (0x%x) ignored"),
01132 abfd, name, unhandled, flag);
01133 result = FALSE;
01134 }
01135 }
01136
01137 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
01138
01139
01140
01141
01142
01143
01144 if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
01145 sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
01146 #endif
01147
01148 if (flags_ptr)
01149 * flags_ptr = sec_flags;
01150
01151 return result;
01152 }
01153
01154 #endif
01155
01156 #define get_index(symbol) ((symbol)->udata.i)
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445 static bfd_boolean
01446 coff_bad_format_hook (abfd, filehdr)
01447 bfd * abfd ATTRIBUTE_UNUSED;
01448 PTR filehdr;
01449 {
01450 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01451
01452 if (BADMAG (*internal_f))
01453 return FALSE;
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463 #if defined(M88) || defined(I960)
01464 if (internal_f->f_opthdr != 0 && bfd_coff_aoutsz (abfd) != internal_f->f_opthdr)
01465 return FALSE;
01466 #endif
01467
01468 return TRUE;
01469 }
01470
01471 #ifdef TICOFF
01472 static bfd_boolean
01473 ticoff0_bad_format_hook (abfd, filehdr)
01474 bfd *abfd ATTRIBUTE_UNUSED;
01475 PTR filehdr;
01476 {
01477 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01478
01479 if (COFF0_BADMAG (*internal_f))
01480 return FALSE;
01481
01482 return TRUE;
01483 }
01484 #endif
01485
01486 #ifdef TICOFF
01487 static bfd_boolean
01488 ticoff1_bad_format_hook (abfd, filehdr)
01489 bfd *abfd ATTRIBUTE_UNUSED;
01490 PTR filehdr;
01491 {
01492 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01493
01494 if (COFF1_BADMAG (*internal_f))
01495 return FALSE;
01496
01497 return TRUE;
01498 }
01499 #endif
01500
01501
01502
01503
01504 static void
01505 coff_set_custom_section_alignment (abfd, section, alignment_table, table_size)
01506 bfd *abfd ATTRIBUTE_UNUSED;
01507 asection *section;
01508 const struct coff_section_alignment_entry *alignment_table;
01509 const unsigned int table_size;
01510 {
01511 const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
01512 unsigned int i;
01513
01514 for (i = 0; i < table_size; ++i)
01515 {
01516 const char *secname = bfd_get_section_name (abfd, section);
01517
01518 if (alignment_table[i].comparison_length == (unsigned int) -1
01519 ? strcmp (alignment_table[i].name, secname) == 0
01520 : strncmp (alignment_table[i].name, secname,
01521 alignment_table[i].comparison_length) == 0)
01522 break;
01523 }
01524 if (i >= table_size)
01525 return;
01526
01527 if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
01528 && default_alignment < alignment_table[i].default_alignment_min)
01529 return;
01530
01531 if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
01532 #if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
01533 && default_alignment > alignment_table[i].default_alignment_max
01534 #endif
01535 )
01536 return;
01537
01538 section->alignment_power = alignment_table[i].alignment_power;
01539 }
01540
01541
01542
01543 static const struct coff_section_alignment_entry
01544 coff_section_alignment_table[] =
01545 {
01546 #ifdef COFF_SECTION_ALIGNMENT_ENTRIES
01547 COFF_SECTION_ALIGNMENT_ENTRIES,
01548 #endif
01549
01550 { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
01551 1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
01552
01553 { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
01554 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
01555
01556 { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
01557 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
01558 { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
01559 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
01560 };
01561
01562 static const unsigned int coff_section_alignment_table_size =
01563 sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
01564
01565
01566
01567
01568 static bfd_boolean
01569 coff_new_section_hook (abfd, section)
01570 bfd * abfd;
01571 asection * section;
01572 {
01573 combined_entry_type *native;
01574 bfd_size_type amt;
01575
01576 section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
01577
01578 #ifdef RS6000COFF_C
01579 if (bfd_xcoff_text_align_power (abfd) != 0
01580 && strcmp (bfd_get_section_name (abfd, section), ".text") == 0)
01581 section->alignment_power = bfd_xcoff_text_align_power (abfd);
01582 if (bfd_xcoff_data_align_power (abfd) != 0
01583 && strcmp (bfd_get_section_name (abfd, section), ".data") == 0)
01584 section->alignment_power = bfd_xcoff_data_align_power (abfd);
01585 #endif
01586
01587
01588
01589
01590
01591
01592 amt = sizeof (combined_entry_type) * 10;
01593 native = (combined_entry_type *) bfd_zalloc (abfd, amt);
01594 if (native == NULL)
01595 return FALSE;
01596
01597
01598
01599
01600
01601
01602
01603 native->u.syment.n_type = T_NULL;
01604 native->u.syment.n_sclass = C_STAT;
01605
01606 coffsymbol (section->symbol)->native = native;
01607
01608 coff_set_custom_section_alignment (abfd, section,
01609 coff_section_alignment_table,
01610 coff_section_alignment_table_size);
01611
01612 return TRUE;
01613 }
01614
01615 #ifdef COFF_ALIGN_IN_SECTION_HEADER
01616
01617
01618
01619 static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR));
01620
01621 static void
01622 coff_set_alignment_hook (abfd, section, scnhdr)
01623 bfd * abfd ATTRIBUTE_UNUSED;
01624 asection * section;
01625 PTR scnhdr;
01626 {
01627 struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
01628 unsigned int i;
01629
01630 #ifdef I960
01631
01632 for (i = 0; i < 32; i++)
01633 if ((1 << i) >= hdr->s_align)
01634 break;
01635 #endif
01636 #ifdef TIC80COFF
01637
01638 i = (hdr->s_flags >> 8) & 0xF ;
01639 #endif
01640 #ifdef COFF_DECODE_ALIGNMENT
01641 i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
01642 #endif
01643 section->alignment_power = i;
01644
01645 #ifdef coff_set_section_load_page
01646 coff_set_section_load_page (section, hdr->s_page);
01647 #endif
01648 }
01649
01650 #else
01651 #ifdef COFF_WITH_PE
01652
01653
01654 #define ALIGN_SET(field,x,y) \
01655 if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x )\
01656 {\
01657 section->alignment_power = y;\
01658 }
01659
01660 #define ELIFALIGN_SET(field,x,y) \
01661 else if (( (field) & IMAGE_SCN_ALIGN_64BYTES) == x ) \
01662 {\
01663 section->alignment_power = y;\
01664 }
01665
01666 static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR));
01667
01668 static void
01669 coff_set_alignment_hook (abfd, section, scnhdr)
01670 bfd * abfd ATTRIBUTE_UNUSED;
01671 asection * section;
01672 PTR scnhdr;
01673 {
01674 struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
01675 bfd_size_type amt;
01676
01677 ALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
01678 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
01679 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4)
01680 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES, 3)
01681 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES, 2)
01682 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES, 1)
01683 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES, 0)
01684
01685
01686
01687
01688
01689 if (coff_section_data (abfd, section) == NULL)
01690 {
01691 amt = sizeof (struct coff_section_tdata);
01692 section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
01693 if (section->used_by_bfd == NULL)
01694 {
01695
01696 abort ();
01697 }
01698 }
01699 if (pei_section_data (abfd, section) == NULL)
01700 {
01701 amt = sizeof (struct pei_section_tdata);
01702 coff_section_data (abfd, section)->tdata = (PTR) bfd_zalloc (abfd, amt);
01703 if (coff_section_data (abfd, section)->tdata == NULL)
01704 {
01705
01706 abort ();
01707 }
01708 }
01709 pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
01710 pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
01711
01712 section->lma = hdr->s_vaddr;
01713
01714
01715 if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
01716 {
01717 struct external_reloc dst;
01718 struct internal_reloc n;
01719 file_ptr oldpos = bfd_tell (abfd);
01720 bfd_size_type relsz = bfd_coff_relsz (abfd);
01721
01722 bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0);
01723 if (bfd_bread ((PTR) &dst, relsz, abfd) != relsz)
01724 return;
01725
01726 coff_swap_reloc_in (abfd, &dst, &n);
01727 bfd_seek (abfd, oldpos, 0);
01728 section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
01729 section->rel_filepos += relsz;
01730 }
01731 else if (hdr->s_nreloc == 0xffff)
01732 (*_bfd_error_handler)
01733 ("%s: warning: claims to have 0xffff relocs, without overflow",
01734 bfd_get_filename (abfd));
01735 }
01736 #undef ALIGN_SET
01737 #undef ELIFALIGN_SET
01738
01739 #else
01740 #ifdef RS6000COFF_C
01741
01742
01743
01744
01745
01746 static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR));
01747
01748 static void
01749 coff_set_alignment_hook (abfd, section, scnhdr)
01750 bfd *abfd;
01751 asection *section;
01752 PTR scnhdr;
01753 {
01754 struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
01755 asection *real_sec;
01756 asection **ps;
01757
01758 if ((hdr->s_flags & STYP_OVRFLO) == 0)
01759 return;
01760
01761 real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
01762 if (real_sec == NULL)
01763 return;
01764
01765 real_sec->reloc_count = hdr->s_paddr;
01766 real_sec->lineno_count = hdr->s_vaddr;
01767
01768 for (ps = &abfd->sections; *ps != NULL; ps = &(*ps)->next)
01769 {
01770 if (*ps == section)
01771 {
01772 bfd_section_list_remove (abfd, ps);
01773 --abfd->section_count;
01774 break;
01775 }
01776 }
01777 }
01778
01779 #else
01780
01781 #define coff_set_alignment_hook \
01782 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
01783
01784 #endif
01785 #endif
01786 #endif
01787
01788 #ifndef coff_mkobject
01789
01790 static bfd_boolean coff_mkobject PARAMS ((bfd *));
01791
01792 static bfd_boolean
01793 coff_mkobject (abfd)
01794 bfd * abfd;
01795 {
01796 coff_data_type *coff;
01797 bfd_size_type amt = sizeof (coff_data_type);
01798
01799 abfd->tdata.coff_obj_data = (struct coff_tdata *) bfd_zalloc (abfd, amt);
01800 if (abfd->tdata.coff_obj_data == 0)
01801 return FALSE;
01802 coff = coff_data (abfd);
01803 coff->symbols = (coff_symbol_type *) NULL;
01804 coff->conversion_table = (unsigned int *) NULL;
01805 coff->raw_syments = (struct coff_ptr_struct *) NULL;
01806 coff->relocbase = 0;
01807 coff->local_toc_sym_map = 0;
01808
01809
01810
01811 return TRUE;
01812 }
01813 #endif
01814
01815
01816
01817 #ifndef coff_mkobject_hook
01818 static PTR
01819 coff_mkobject_hook (abfd, filehdr, aouthdr)
01820 bfd * abfd;
01821 PTR filehdr;
01822 PTR aouthdr ATTRIBUTE_UNUSED;
01823 {
01824 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01825 coff_data_type *coff;
01826
01827 if (! coff_mkobject (abfd))
01828 return NULL;
01829
01830 coff = coff_data (abfd);
01831
01832 coff->sym_filepos = internal_f->f_symptr;
01833
01834
01835
01836
01837 coff->local_n_btmask = N_BTMASK;
01838 coff->local_n_btshft = N_BTSHFT;
01839 coff->local_n_tmask = N_TMASK;
01840 coff->local_n_tshift = N_TSHIFT;
01841 coff->local_symesz = bfd_coff_symesz (abfd);
01842 coff->local_auxesz = bfd_coff_auxesz (abfd);
01843 coff->local_linesz = bfd_coff_linesz (abfd);
01844
01845 coff->timestamp = internal_f->f_timdat;
01846
01847 obj_raw_syment_count (abfd) =
01848 obj_conv_table_size (abfd) =
01849 internal_f->f_nsyms;
01850
01851 #ifdef RS6000COFF_C
01852 if ((internal_f->f_flags & F_SHROBJ) != 0)
01853 abfd->flags |= DYNAMIC;
01854 if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
01855 {
01856 struct internal_aouthdr *internal_a =
01857 (struct internal_aouthdr *) aouthdr;
01858 struct xcoff_tdata *xcoff;
01859
01860 xcoff = xcoff_data (abfd);
01861 # ifdef U803XTOCMAGIC
01862 xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
01863 # else
01864 xcoff->xcoff64 = 0;
01865 # endif
01866 xcoff->full_aouthdr = TRUE;
01867 xcoff->toc = internal_a->o_toc;
01868 xcoff->sntoc = internal_a->o_sntoc;
01869 xcoff->snentry = internal_a->o_snentry;
01870 bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
01871 bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
01872 xcoff->modtype = internal_a->o_modtype;
01873 xcoff->cputype = internal_a->o_cputype;
01874 xcoff->maxdata = internal_a->o_maxdata;
01875 xcoff->maxstack = internal_a->o_maxstack;
01876 }
01877 #endif
01878
01879 #ifdef ARM
01880
01881 if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
01882 coff->flags = 0;
01883 #endif
01884
01885 #ifdef COFF_WITH_PE
01886
01887
01888 if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
01889 abfd->flags |= HAS_DEBUG;
01890 #endif
01891
01892 return (PTR) coff;
01893 }
01894 #endif
01895
01896
01897
01898
01899
01900
01901
01902
01903 static bfd_boolean
01904 coff_set_arch_mach_hook (abfd, filehdr)
01905 bfd *abfd;
01906 PTR filehdr;
01907 {
01908 unsigned long machine;
01909 enum bfd_architecture arch;
01910 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01911
01912
01913 machine = 0;
01914 switch (internal_f->f_magic)
01915 {
01916 #ifdef OR32_MAGIC_BIG
01917 case OR32_MAGIC_BIG:
01918 case OR32_MAGIC_LITTLE:
01919 arch = bfd_arch_or32;
01920 break;
01921 #endif
01922 #ifdef PPCMAGIC
01923 case PPCMAGIC:
01924 arch = bfd_arch_powerpc;
01925 break;
01926 #endif
01927 #ifdef I386MAGIC
01928 case I386MAGIC:
01929 case I386PTXMAGIC:
01930 case I386AIXMAGIC:
01931 case LYNXCOFFMAGIC:
01932 arch = bfd_arch_i386;
01933 break;
01934 #endif
01935 #ifdef IA64MAGIC
01936 case IA64MAGIC:
01937 arch = bfd_arch_ia64;
01938 break;
01939 #endif
01940 #ifdef A29K_MAGIC_BIG
01941 case A29K_MAGIC_BIG:
01942 case A29K_MAGIC_LITTLE:
01943 arch = bfd_arch_a29k;
01944 break;
01945 #endif
01946 #ifdef ARMMAGIC
01947 case ARMMAGIC:
01948 case ARMPEMAGIC:
01949 case THUMBPEMAGIC:
01950 arch = bfd_arch_arm;
01951 machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
01952 if (machine == bfd_mach_arm_unknown)
01953 {
01954 switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
01955 {
01956 case F_ARM_2: machine = bfd_mach_arm_2; break;
01957 case F_ARM_2a: machine = bfd_mach_arm_2a; break;
01958 case F_ARM_3: machine = bfd_mach_arm_3; break;
01959 default:
01960 case F_ARM_3M: machine = bfd_mach_arm_3M; break;
01961 case F_ARM_4: machine = bfd_mach_arm_4; break;
01962 case F_ARM_4T: machine = bfd_mach_arm_4T; break;
01963
01964
01965
01966
01967
01968 case F_ARM_5: machine = bfd_mach_arm_XScale; break;
01969 }
01970 }
01971 break;
01972 #endif
01973 #ifdef MC68MAGIC
01974 case MC68MAGIC:
01975 case M68MAGIC:
01976 #ifdef MC68KBCSMAGIC
01977 case MC68KBCSMAGIC:
01978 #endif
01979 #ifdef APOLLOM68KMAGIC
01980 case APOLLOM68KMAGIC:
01981 #endif
01982 #ifdef LYNXCOFFMAGIC
01983 case LYNXCOFFMAGIC:
01984 #endif
01985 arch = bfd_arch_m68k;
01986 machine = bfd_mach_m68020;
01987 break;
01988 #endif
01989 #ifdef MAXQ20MAGIC
01990 case MAXQ20MAGIC:
01991 arch = bfd_arch_maxq;
01992 switch (internal_f->f_flags & F_MACHMASK)
01993 {
01994 case F_MAXQ10:
01995 machine = bfd_mach_maxq10;
01996 break;
01997 case F_MAXQ20:
01998 machine = bfd_mach_maxq20;
01999 break;
02000 default:
02001 return FALSE;
02002 }
02003 break;
02004 #endif
02005 #ifdef MC88MAGIC
02006 case MC88MAGIC:
02007 case MC88DMAGIC:
02008 case MC88OMAGIC:
02009 arch = bfd_arch_m88k;
02010 machine = 88100;
02011 break;
02012 #endif
02013 #ifdef Z8KMAGIC
02014 case Z8KMAGIC:
02015 arch = bfd_arch_z8k;
02016 switch (internal_f->f_flags & F_MACHMASK)
02017 {
02018 case F_Z8001:
02019 machine = bfd_mach_z8001;
02020 break;
02021 case F_Z8002:
02022 machine = bfd_mach_z8002;
02023 break;
02024 default:
02025 return FALSE;
02026 }
02027 break;
02028 #endif
02029 #ifdef I860
02030 case I860MAGIC:
02031 arch = bfd_arch_i860;
02032 break;
02033 #endif
02034 #ifdef I960
02035 #ifdef I960ROMAGIC
02036 case I960ROMAGIC:
02037 case I960RWMAGIC:
02038 arch = bfd_arch_i960;
02039 switch (F_I960TYPE & internal_f->f_flags)
02040 {
02041 default:
02042 case F_I960CORE:
02043 machine = bfd_mach_i960_core;
02044 break;
02045 case F_I960KB:
02046 machine = bfd_mach_i960_kb_sb;
02047 break;
02048 case F_I960MC:
02049 machine = bfd_mach_i960_mc;
02050 break;
02051 case F_I960XA:
02052 machine = bfd_mach_i960_xa;
02053 break;
02054 case F_I960CA:
02055 machine = bfd_mach_i960_ca;
02056 break;
02057 case F_I960KA:
02058 machine = bfd_mach_i960_ka_sa;
02059 break;
02060 case F_I960JX:
02061 machine = bfd_mach_i960_jx;
02062 break;
02063 case F_I960HX:
02064 machine = bfd_mach_i960_hx;
02065 break;
02066 }
02067 break;
02068 #endif
02069 #endif
02070
02071 #ifdef RS6000COFF_C
02072 #ifdef XCOFF64
02073 case U64_TOCMAGIC:
02074 case U803XTOCMAGIC:
02075 #else
02076 case U802ROMAGIC:
02077 case U802WRMAGIC:
02078 case U802TOCMAGIC:
02079 #endif
02080 {
02081 int cputype;
02082
02083 if (xcoff_data (abfd)->cputype != -1)
02084 cputype = xcoff_data (abfd)->cputype & 0xff;
02085 else
02086 {
02087
02088
02089
02090
02091 if (obj_raw_syment_count (abfd) == 0)
02092 cputype = 0;
02093 else
02094 {
02095 bfd_byte *buf;
02096 struct internal_syment sym;
02097 bfd_size_type amt = bfd_coff_symesz (abfd);
02098
02099 buf = (bfd_byte *) bfd_malloc (amt);
02100 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
02101 || bfd_bread (buf, amt, abfd) != amt)
02102 {
02103 free (buf);
02104 return FALSE;
02105 }
02106 bfd_coff_swap_sym_in (abfd, (PTR) buf, (PTR) &sym);
02107 if (sym.n_sclass == C_FILE)
02108 cputype = sym.n_type & 0xff;
02109 else
02110 cputype = 0;
02111 free (buf);
02112 }
02113 }
02114
02115
02116 switch (cputype)
02117 {
02118 default:
02119 case 0:
02120 arch = bfd_xcoff_architecture (abfd);
02121 machine = bfd_xcoff_machine (abfd);
02122 break;
02123
02124 case 1:
02125 arch = bfd_arch_powerpc;
02126 machine = bfd_mach_ppc_601;
02127 break;
02128 case 2:
02129 arch = bfd_arch_powerpc;
02130 machine = bfd_mach_ppc_620;
02131 break;
02132 case 3:
02133 arch = bfd_arch_powerpc;
02134 machine = bfd_mach_ppc;
02135 break;
02136 case 4:
02137 arch = bfd_arch_rs6000;
02138 machine = bfd_mach_rs6k;
02139 break;
02140 }
02141 }
02142 break;
02143 #endif
02144
02145 #ifdef WE32KMAGIC
02146 case WE32KMAGIC:
02147 arch = bfd_arch_we32k;
02148 break;
02149 #endif
02150
02151 #ifdef H8300MAGIC
02152 case H8300MAGIC:
02153 arch = bfd_arch_h8300;
02154 machine = bfd_mach_h8300;
02155
02156 abfd->flags |= BFD_IS_RELAXABLE;
02157 break;
02158 #endif
02159
02160 #ifdef H8300HMAGIC
02161 case H8300HMAGIC:
02162 arch = bfd_arch_h8300;
02163 machine = bfd_mach_h8300h;
02164
02165 abfd->flags |= BFD_IS_RELAXABLE;
02166 break;
02167 #endif
02168
02169 #ifdef H8300SMAGIC
02170 case H8300SMAGIC:
02171 arch = bfd_arch_h8300;
02172 machine = bfd_mach_h8300s;
02173
02174 abfd->flags |= BFD_IS_RELAXABLE;
02175 break;
02176 #endif
02177
02178 #ifdef H8300HNMAGIC
02179 case H8300HNMAGIC:
02180 arch = bfd_arch_h8300;
02181 machine = bfd_mach_h8300hn;
02182
02183 abfd->flags |= BFD_IS_RELAXABLE;
02184 break;
02185 #endif
02186
02187 #ifdef H8300SNMAGIC
02188 case H8300SNMAGIC:
02189 arch = bfd_arch_h8300;
02190 machine = bfd_mach_h8300sn;
02191
02192 abfd->flags |= BFD_IS_RELAXABLE;
02193 break;
02194 #endif
02195
02196 #ifdef SH_ARCH_MAGIC_BIG
02197 case SH_ARCH_MAGIC_BIG:
02198 case SH_ARCH_MAGIC_LITTLE:
02199 #ifdef COFF_WITH_PE
02200 case SH_ARCH_MAGIC_WINCE:
02201 #endif
02202 arch = bfd_arch_sh;
02203 break;
02204 #endif
02205
02206 #ifdef MIPS_ARCH_MAGIC_WINCE
02207 case MIPS_ARCH_MAGIC_WINCE:
02208 arch = bfd_arch_mips;
02209 break;
02210 #endif
02211
02212 #ifdef H8500MAGIC
02213 case H8500MAGIC:
02214 arch = bfd_arch_h8500;
02215 break;
02216 #endif
02217
02218 #ifdef SPARCMAGIC
02219 case SPARCMAGIC:
02220 #ifdef LYNXCOFFMAGIC
02221 case LYNXCOFFMAGIC:
02222 #endif
02223 arch = bfd_arch_sparc;
02224 break;
02225 #endif
02226
02227 #ifdef TIC30MAGIC
02228 case TIC30MAGIC:
02229 arch = bfd_arch_tic30;
02230 break;
02231 #endif
02232
02233 #ifdef TICOFF0MAGIC
02234 #ifdef TICOFF_TARGET_ARCH
02235
02236 case TICOFF0MAGIC:
02237 arch = TICOFF_TARGET_ARCH;
02238 machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
02239 break;
02240 #endif
02241 #endif
02242
02243 #ifdef TICOFF1MAGIC
02244
02245
02246 case TICOFF1MAGIC:
02247 case TICOFF2MAGIC:
02248 switch (internal_f->f_target_id)
02249 {
02250 #ifdef TI_TARGET_ID
02251 case TI_TARGET_ID:
02252 arch = TICOFF_TARGET_ARCH;
02253 machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
02254 break;
02255 #endif
02256 default:
02257 arch = bfd_arch_obscure;
02258 (*_bfd_error_handler)
02259 (_("Unrecognized TI COFF target id '0x%x'"),
02260 internal_f->f_target_id);
02261 break;
02262 }
02263 break;
02264 #endif
02265
02266 #ifdef TIC80_ARCH_MAGIC
02267 case TIC80_ARCH_MAGIC:
02268 arch = bfd_arch_tic80;
02269 break;
02270 #endif
02271
02272 #ifdef MCOREMAGIC
02273 case MCOREMAGIC:
02274 arch = bfd_arch_mcore;
02275 break;
02276 #endif
02277
02278 #ifdef W65MAGIC
02279 case W65MAGIC:
02280 arch = bfd_arch_w65;
02281 break;
02282 #endif
02283
02284 default:
02285 arch = bfd_arch_obscure;
02286 break;
02287 }
02288
02289 bfd_default_set_arch_mach (abfd, arch, machine);
02290 return TRUE;
02291 }
02292
02293 #ifdef SYMNAME_IN_DEBUG
02294
02295 static bfd_boolean symname_in_debug_hook
02296 PARAMS ((bfd *, struct internal_syment *));
02297
02298 static bfd_boolean
02299 symname_in_debug_hook (abfd, sym)
02300 bfd * abfd ATTRIBUTE_UNUSED;
02301 struct internal_syment *sym;
02302 {
02303 return SYMNAME_IN_DEBUG (sym) != 0;
02304 }
02305
02306 #else
02307
02308 #define symname_in_debug_hook \
02309 (bfd_boolean (*) PARAMS ((bfd *, struct internal_syment *))) bfd_false
02310
02311 #endif
02312
02313 #ifdef RS6000COFF_C
02314
02315 #ifdef XCOFF64
02316 #define FORCE_SYMNAMES_IN_STRINGS
02317 #endif
02318
02319
02320
02321 static bfd_boolean coff_pointerize_aux_hook
02322 PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
02323 unsigned int, combined_entry_type *));
02324
02325 static bfd_boolean
02326 coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux)
02327 bfd *abfd ATTRIBUTE_UNUSED;
02328 combined_entry_type *table_base;
02329 combined_entry_type *symbol;
02330 unsigned int indaux;
02331 combined_entry_type *aux;
02332 {
02333 int class = symbol->u.syment.n_sclass;
02334
02335 if ((class == C_EXT || class == C_HIDEXT)
02336 && indaux + 1 == symbol->u.syment.n_numaux)
02337 {
02338 if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD)
02339 {
02340 aux->u.auxent.x_csect.x_scnlen.p =
02341 table_base + aux->u.auxent.x_csect.x_scnlen.l;
02342 aux->fix_scnlen = 1;
02343 }
02344
02345
02346
02347 return TRUE;
02348 }
02349
02350
02351
02352 return FALSE;
02353 }
02354
02355 #else
02356 #ifdef I960
02357
02358
02359
02360 static bfd_boolean coff_pointerize_aux_hook
02361 PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
02362 unsigned int, combined_entry_type *));
02363
02364 static bfd_boolean
02365 coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux)
02366 bfd *abfd ATTRIBUTE_UNUSED;
02367 combined_entry_type *table_base ATTRIBUTE_UNUSED;
02368 combined_entry_type *symbol;
02369 unsigned int indaux;
02370 combined_entry_type *aux ATTRIBUTE_UNUSED;
02371 {
02372
02373
02374 return (indaux == 1
02375 && (symbol->u.syment.n_sclass == C_LEAFPROC
02376 || symbol->u.syment.n_sclass == C_LEAFSTAT
02377 || symbol->u.syment.n_sclass == C_LEAFEXT));
02378 }
02379
02380 #else
02381
02382 #define coff_pointerize_aux_hook 0
02383
02384 #endif
02385 #endif
02386
02387
02388
02389 static bfd_boolean coff_print_aux
02390 PARAMS ((bfd *, FILE *, combined_entry_type *, combined_entry_type *,
02391 combined_entry_type *, unsigned int));
02392
02393 static bfd_boolean
02394 coff_print_aux (abfd, file, table_base, symbol, aux, indaux)
02395 bfd *abfd ATTRIBUTE_UNUSED;
02396 FILE *file ATTRIBUTE_UNUSED;
02397 combined_entry_type *table_base ATTRIBUTE_UNUSED;
02398 combined_entry_type *symbol ATTRIBUTE_UNUSED;
02399 combined_entry_type *aux ATTRIBUTE_UNUSED;
02400 unsigned int indaux ATTRIBUTE_UNUSED;
02401 {
02402 #ifdef RS6000COFF_C
02403 if ((symbol->u.syment.n_sclass == C_EXT
02404 || symbol->u.syment.n_sclass == C_HIDEXT)
02405 && indaux + 1 == symbol->u.syment.n_numaux)
02406 {
02407
02408 fprintf (file, "AUX ");
02409 if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
02410 {
02411 BFD_ASSERT (! aux->fix_scnlen);
02412 #ifdef XCOFF64
02413 fprintf (file, "val %5lld",
02414 (long long) aux->u.auxent.x_csect.x_scnlen.l);
02415 #else
02416 fprintf (file, "val %5ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
02417 #endif
02418 }
02419 else
02420 {
02421 fprintf (file, "indx ");
02422 if (! aux->fix_scnlen)
02423 #ifdef XCOFF64
02424 fprintf (file, "%4lld",
02425 (long long) aux->u.auxent.x_csect.x_scnlen.l);
02426 #else
02427 fprintf (file, "%4ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
02428 #endif
02429 else
02430 fprintf (file, "%4ld",
02431 (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
02432 }
02433 fprintf (file,
02434 " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u",
02435 aux->u.auxent.x_csect.x_parmhash,
02436 (unsigned int) aux->u.auxent.x_csect.x_snhash,
02437 SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
02438 SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
02439 (unsigned int) aux->u.auxent.x_csect.x_smclas,
02440 aux->u.auxent.x_csect.x_stab,
02441 (unsigned int) aux->u.auxent.x_csect.x_snstab);
02442 return TRUE;
02443 }
02444 #endif
02445
02446
02447 return FALSE;
02448 }
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466 #ifdef TARG_AUX
02467
02468 static int compare_arelent_ptr PARAMS ((const PTR, const PTR));
02469
02470
02471 static int
02472 compare_arelent_ptr (x, y)
02473 const PTR x;
02474 const PTR y;
02475 {
02476 const arelent **a = (const arelent **) x;
02477 const arelent **b = (const arelent **) y;
02478 bfd_size_type aadr = (*a)->address;
02479 bfd_size_type badr = (*b)->address;
02480
02481 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
02482 }
02483
02484 #endif
02485
02486 static bfd_boolean
02487 coff_write_relocs (abfd, first_undef)
02488 bfd * abfd;
02489 int first_undef;
02490 {
02491 asection *s;
02492
02493 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
02494 {
02495 unsigned int i;
02496 struct external_reloc dst;
02497 arelent **p;
02498
02499 #ifndef TARG_AUX
02500 p = s->orelocation;
02501 #else
02502 {
02503
02504 bfd_size_type amt;
02505
02506 amt = s->reloc_count;
02507 amt *= sizeof (arelent *);
02508 p = (arelent **) bfd_malloc (amt);
02509 if (p == NULL && s->reloc_count > 0)
02510 return FALSE;
02511 memcpy (p, s->orelocation, (size_t) amt);
02512 qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
02513 }
02514 #endif
02515
02516 if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
02517 return FALSE;
02518
02519 #ifdef COFF_WITH_PE
02520 if (obj_pe (abfd) && s->reloc_count >= 0xffff)
02521 {
02522
02523 struct internal_reloc n;
02524
02525 memset ((PTR) & n, 0, sizeof (n));
02526
02527 n.r_vaddr = s->reloc_count + 1;
02528 coff_swap_reloc_out (abfd, &n, &dst);
02529 if (bfd_bwrite ((PTR) & dst, (bfd_size_type) bfd_coff_relsz (abfd),
02530 abfd) != bfd_coff_relsz (abfd))
02531 return FALSE;
02532 }
02533 #endif
02534
02535 for (i = 0; i < s->reloc_count; i++)
02536 {
02537 struct internal_reloc n;
02538 arelent *q = p[i];
02539
02540 memset ((PTR) & n, 0, sizeof (n));
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552 if (q->sym_ptr_ptr[0]->the_bfd != abfd)
02553 {
02554 int j;
02555 const char *sname = q->sym_ptr_ptr[0]->name;
02556 asymbol **outsyms = abfd->outsymbols;
02557
02558 for (j = first_undef; outsyms[j]; j++)
02559 {
02560 const char *intable = outsyms[j]->name;
02561
02562 if (strcmp (intable, sname) == 0) {
02563
02564 q->sym_ptr_ptr = outsyms + j;
02565 break;
02566 }
02567 }
02568 }
02569
02570 n.r_vaddr = q->address + s->vma;
02571
02572 #ifdef R_IHCONST
02573
02574
02575
02576 if (q->howto->type == R_IHCONST)
02577 n.r_symndx = q->addend;
02578 else
02579 #endif
02580 if (q->sym_ptr_ptr)
02581 {
02582 #ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
02583 if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q,s))
02584 #else
02585 if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
02586 && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
02587 #endif
02588
02589 n.r_symndx = -1;
02590 else
02591 {
02592 n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
02593
02594
02595
02596 if (n.r_symndx > obj_conv_table_size (abfd))
02597 abort ();
02598 }
02599 }
02600
02601 #ifdef SWAP_OUT_RELOC_OFFSET
02602 n.r_offset = q->addend;
02603 #endif
02604
02605 #ifdef SELECT_RELOC
02606
02607 SELECT_RELOC (n, q->howto);
02608 #else
02609 n.r_type = q->howto->type;
02610 #endif
02611 coff_swap_reloc_out (abfd, &n, &dst);
02612
02613 if (bfd_bwrite ((PTR) & dst, (bfd_size_type) bfd_coff_relsz (abfd),
02614 abfd) != bfd_coff_relsz (abfd))
02615 return FALSE;
02616 }
02617
02618 #ifdef TARG_AUX
02619 if (p != NULL)
02620 free (p);
02621 #endif
02622 }
02623
02624 return TRUE;
02625 }
02626
02627
02628
02629
02630 static bfd_boolean
02631 coff_set_flags (abfd, magicp, flagsp)
02632 bfd * abfd;
02633 unsigned int *magicp ATTRIBUTE_UNUSED;
02634 unsigned short *flagsp ATTRIBUTE_UNUSED;
02635 {
02636 switch (bfd_get_arch (abfd))
02637 {
02638 #ifdef Z8KMAGIC
02639 case bfd_arch_z8k:
02640 *magicp = Z8KMAGIC;
02641 switch (bfd_get_mach (abfd))
02642 {
02643 case bfd_mach_z8001:
02644 *flagsp = F_Z8001;
02645 break;
02646 case bfd_mach_z8002:
02647 *flagsp = F_Z8002;
02648 break;
02649 default:
02650 return FALSE;
02651 }
02652 return TRUE;
02653 #endif
02654 #ifdef I960ROMAGIC
02655
02656 case bfd_arch_i960:
02657
02658 {
02659 unsigned flags;
02660 *magicp = I960ROMAGIC;
02661
02662
02663
02664
02665 switch (bfd_get_mach (abfd))
02666 {
02667 case bfd_mach_i960_core:
02668 flags = F_I960CORE;
02669 break;
02670 case bfd_mach_i960_kb_sb:
02671 flags = F_I960KB;
02672 break;
02673 case bfd_mach_i960_mc:
02674 flags = F_I960MC;
02675 break;
02676 case bfd_mach_i960_xa:
02677 flags = F_I960XA;
02678 break;
02679 case bfd_mach_i960_ca:
02680 flags = F_I960CA;
02681 break;
02682 case bfd_mach_i960_ka_sa:
02683 flags = F_I960KA;
02684 break;
02685 case bfd_mach_i960_jx:
02686 flags = F_I960JX;
02687 break;
02688 case bfd_mach_i960_hx:
02689 flags = F_I960HX;
02690 break;
02691 default:
02692 return FALSE;
02693 }
02694 *flagsp = flags;
02695 return TRUE;
02696 }
02697 break;
02698 #endif
02699
02700 #ifdef TIC30MAGIC
02701 case bfd_arch_tic30:
02702 *magicp = TIC30MAGIC;
02703 return TRUE;
02704 #endif
02705
02706 #ifdef TICOFF_DEFAULT_MAGIC
02707 case TICOFF_TARGET_ARCH:
02708
02709 if (!abfd->xvec )
02710 *magicp = TICOFF_DEFAULT_MAGIC;
02711 else
02712 {
02713
02714 switch (abfd->xvec->name[4])
02715 {
02716 case '0':
02717 *magicp = TICOFF0MAGIC;
02718 break;
02719 case '1':
02720 *magicp = TICOFF1MAGIC;
02721 break;
02722 case '2':
02723 *magicp = TICOFF2MAGIC;
02724 break;
02725 default:
02726 return FALSE;
02727 }
02728 }
02729 TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
02730 return TRUE;
02731 #endif
02732
02733 #ifdef TIC80_ARCH_MAGIC
02734 case bfd_arch_tic80:
02735 *magicp = TIC80_ARCH_MAGIC;
02736 return TRUE;
02737 #endif
02738 #ifdef ARMMAGIC
02739 case bfd_arch_arm:
02740 #ifdef ARM_WINCE
02741 * magicp = ARMPEMAGIC;
02742 #else
02743 * magicp = ARMMAGIC;
02744 #endif
02745 * flagsp = 0;
02746 if (APCS_SET (abfd))
02747 {
02748 if (APCS_26_FLAG (abfd))
02749 * flagsp |= F_APCS26;
02750
02751 if (APCS_FLOAT_FLAG (abfd))
02752 * flagsp |= F_APCS_FLOAT;
02753
02754 if (PIC_FLAG (abfd))
02755 * flagsp |= F_PIC;
02756 }
02757 if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
02758 * flagsp |= F_INTERWORK;
02759 switch (bfd_get_mach (abfd))
02760 {
02761 case bfd_mach_arm_2: * flagsp |= F_ARM_2; break;
02762 case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
02763 case bfd_mach_arm_3: * flagsp |= F_ARM_3; break;
02764 case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
02765 case bfd_mach_arm_4: * flagsp |= F_ARM_4; break;
02766 case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
02767 case bfd_mach_arm_5: * flagsp |= F_ARM_5; break;
02768
02769
02770 case bfd_mach_arm_5T: * flagsp |= F_ARM_5; break;
02771 case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
02772 case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
02773 }
02774 return TRUE;
02775 #endif
02776 #ifdef PPCMAGIC
02777 case bfd_arch_powerpc:
02778 *magicp = PPCMAGIC;
02779 return TRUE;
02780 break;
02781 #endif
02782 #ifdef I386MAGIC
02783 case bfd_arch_i386:
02784 *magicp = I386MAGIC;
02785 #ifdef LYNXOS
02786
02787 *magicp = LYNXCOFFMAGIC;
02788 #endif
02789 return TRUE;
02790 break;
02791 #endif
02792 #ifdef I860MAGIC
02793 case bfd_arch_i860:
02794 *magicp = I860MAGIC;
02795 return TRUE;
02796 break;
02797 #endif
02798 #ifdef IA64MAGIC
02799 case bfd_arch_ia64:
02800 *magicp = IA64MAGIC;
02801 return TRUE;
02802 break;
02803 #endif
02804 #ifdef MC68MAGIC
02805 case bfd_arch_m68k:
02806 #ifdef APOLLOM68KMAGIC
02807 *magicp = APOLLO_COFF_VERSION_NUMBER;
02808 #else
02809
02810 #ifdef NAMES_HAVE_UNDERSCORE
02811 *magicp = MC68KBCSMAGIC;
02812 #else
02813 *magicp = MC68MAGIC;
02814 #endif
02815 #endif
02816 #ifdef LYNXOS
02817
02818 *magicp = LYNXCOFFMAGIC;
02819 #endif
02820 return TRUE;
02821 break;
02822 #endif
02823
02824 #ifdef MC88MAGIC
02825 case bfd_arch_m88k:
02826 *magicp = MC88OMAGIC;
02827 return TRUE;
02828 break;
02829 #endif
02830 #ifdef H8300MAGIC
02831 case bfd_arch_h8300:
02832 switch (bfd_get_mach (abfd))
02833 {
02834 case bfd_mach_h8300:
02835 *magicp = H8300MAGIC;
02836 return TRUE;
02837 case bfd_mach_h8300h:
02838 *magicp = H8300HMAGIC;
02839 return TRUE;
02840 case bfd_mach_h8300s:
02841 *magicp = H8300SMAGIC;
02842 return TRUE;
02843 case bfd_mach_h8300hn:
02844 *magicp = H8300HNMAGIC;
02845 return TRUE;
02846 case bfd_mach_h8300sn:
02847 *magicp = H8300SNMAGIC;
02848 return TRUE;
02849 }
02850 break;
02851 #endif
02852
02853 #ifdef SH_ARCH_MAGIC_BIG
02854 case bfd_arch_sh:
02855 #ifdef COFF_IMAGE_WITH_PE
02856 *magicp = SH_ARCH_MAGIC_WINCE;
02857 #else
02858 if (bfd_big_endian (abfd))
02859 *magicp = SH_ARCH_MAGIC_BIG;
02860 else
02861 *magicp = SH_ARCH_MAGIC_LITTLE;
02862 #endif
02863 return TRUE;
02864 break;
02865 #endif
02866
02867 #ifdef MIPS_ARCH_MAGIC_WINCE
02868 case bfd_arch_mips:
02869 *magicp = MIPS_ARCH_MAGIC_WINCE;
02870 return TRUE;
02871 break;
02872 #endif
02873
02874 #ifdef SPARCMAGIC
02875 case bfd_arch_sparc:
02876 *magicp = SPARCMAGIC;
02877 #ifdef LYNXOS
02878
02879 *magicp = LYNXCOFFMAGIC;
02880 #endif
02881 return TRUE;
02882 break;
02883 #endif
02884
02885 #ifdef H8500MAGIC
02886 case bfd_arch_h8500:
02887 *magicp = H8500MAGIC;
02888 return TRUE;
02889 break;
02890 #endif
02891 #ifdef A29K_MAGIC_BIG
02892 case bfd_arch_a29k:
02893 if (bfd_big_endian (abfd))
02894 *magicp = A29K_MAGIC_BIG;
02895 else
02896 *magicp = A29K_MAGIC_LITTLE;
02897 return TRUE;
02898 break;
02899 #endif
02900
02901 #ifdef WE32KMAGIC
02902 case bfd_arch_we32k:
02903 *magicp = WE32KMAGIC;
02904 return TRUE;
02905 break;
02906 #endif
02907
02908 #ifdef RS6000COFF_C
02909 case bfd_arch_rs6000:
02910 #ifndef PPCMAGIC
02911 case bfd_arch_powerpc:
02912 #endif
02913 BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
02914 *magicp = bfd_xcoff_magic_number (abfd);
02915 return TRUE;
02916 break;
02917 #endif
02918
02919 #ifdef MCOREMAGIC
02920 case bfd_arch_mcore:
02921 * magicp = MCOREMAGIC;
02922 return TRUE;
02923 #endif
02924
02925 #ifdef W65MAGIC
02926 case bfd_arch_w65:
02927 *magicp = W65MAGIC;
02928 return TRUE;
02929 #endif
02930
02931 #ifdef OR32_MAGIC_BIG
02932 case bfd_arch_or32:
02933 if (bfd_big_endian (abfd))
02934 * magicp = OR32_MAGIC_BIG;
02935 else
02936 * magicp = OR32_MAGIC_LITTLE;
02937 return TRUE;
02938 #endif
02939
02940 #ifdef MAXQ20MAGIC
02941 case bfd_arch_maxq:
02942 * magicp = MAXQ20MAGIC;
02943 switch (bfd_get_mach (abfd))
02944 {
02945 case bfd_mach_maxq10:
02946 * flagsp = F_MAXQ10;
02947 return TRUE;
02948 case bfd_mach_maxq20:
02949 * flagsp = F_MAXQ20;
02950 return TRUE;
02951 default:
02952 return FALSE;
02953 }
02954 #endif
02955
02956 default:
02957
02958
02959 break;
02960 }
02961
02962 return FALSE;
02963 }
02964
02965 static bfd_boolean
02966 coff_set_arch_mach (abfd, arch, machine)
02967 bfd * abfd;
02968 enum bfd_architecture arch;
02969 unsigned long machine;
02970 {
02971 unsigned dummy1;
02972 unsigned short dummy2;
02973
02974 if (! bfd_default_set_arch_mach (abfd, arch, machine))
02975 return FALSE;
02976
02977 if (arch != bfd_arch_unknown
02978 && ! coff_set_flags (abfd, &dummy1, &dummy2))
02979 return FALSE;
02980
02981 return TRUE;
02982 }
02983
02984 #ifdef COFF_IMAGE_WITH_PE
02985
02986
02987
02988
02989 static int sort_by_secaddr PARAMS ((const PTR, const PTR));
02990
02991 static int
02992 sort_by_secaddr (arg1, arg2)
02993 const PTR arg1;
02994 const PTR arg2;
02995 {
02996 const asection *a = *(const asection **) arg1;
02997 const asection *b = *(const asection **) arg2;
02998
02999 if (a->vma < b->vma)
03000 return -1;
03001 else if (a->vma > b->vma)
03002 return 1;
03003 else
03004 return 0;
03005 }
03006
03007 #endif
03008
03009
03010
03011 #ifndef I960
03012 #define ALIGN_SECTIONS_IN_FILE
03013 #endif
03014 #if defined(TIC80COFF) || defined(TICOFF)
03015 #undef ALIGN_SECTIONS_IN_FILE
03016 #endif
03017
03018 static bfd_boolean
03019 coff_compute_section_file_positions (abfd)
03020 bfd * abfd;
03021 {
03022 asection *current;
03023 asection *previous = (asection *) NULL;
03024 file_ptr sofar = bfd_coff_filhsz (abfd);
03025 bfd_boolean align_adjust;
03026 #ifdef ALIGN_SECTIONS_IN_FILE
03027 file_ptr old_sofar;
03028 #endif
03029
03030 #ifdef RS6000COFF_C
03031
03032 if (bfd_get_symcount (abfd) > 0)
03033 {
03034 bfd_size_type sz;
03035 bfd_size_type i, symcount;
03036 asymbol **symp;
03037
03038 sz = 0;
03039 symcount = bfd_get_symcount (abfd);
03040 for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
03041 {
03042 coff_symbol_type *cf;
03043
03044 cf = coff_symbol_from (abfd, *symp);
03045 if (cf != NULL
03046 && cf->native != NULL
03047 && SYMNAME_IN_DEBUG (&cf->native->u.syment))
03048 {
03049 size_t len;
03050
03051 len = strlen (bfd_asymbol_name (*symp));
03052 if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
03053 sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
03054 }
03055 }
03056 if (sz > 0)
03057 {
03058 asection *dsec;
03059
03060 dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
03061 if (dsec == NULL)
03062 abort ();
03063 dsec->size = sz;
03064 dsec->flags |= SEC_HAS_CONTENTS;
03065 }
03066 }
03067 #endif
03068
03069 #ifdef COFF_IMAGE_WITH_PE
03070 int page_size;
03071 if (coff_data (abfd)->link_info)
03072 {
03073 page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
03074
03075
03076
03077 if (page_size == 0)
03078 page_size = 1;
03079 }
03080 else
03081 page_size = PE_DEF_FILE_ALIGNMENT;
03082 #else
03083 #ifdef COFF_PAGE_SIZE
03084 int page_size = COFF_PAGE_SIZE;
03085 #endif
03086 #endif
03087
03088 if (bfd_get_start_address (abfd))
03089 {
03090
03091
03092 abfd->flags |= EXEC_P;
03093 }
03094
03095 if (abfd->flags & EXEC_P)
03096 sofar += bfd_coff_aoutsz (abfd);
03097 #ifdef RS6000COFF_C
03098 else if (xcoff_data (abfd)->full_aouthdr)
03099 sofar += bfd_coff_aoutsz (abfd);
03100 else
03101 sofar += SMALL_AOUTSZ;
03102 #endif
03103
03104 sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
03105
03106 #ifdef RS6000COFF_C
03107
03108
03109 for (current = abfd->sections; current != NULL; current = current->next)
03110 if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
03111 sofar += bfd_coff_scnhsz (abfd);
03112 #endif
03113
03114 #ifdef COFF_IMAGE_WITH_PE
03115 {
03116
03117
03118
03119
03120
03121
03122 unsigned int count;
03123 asection **section_list;
03124 unsigned int i;
03125 int target_index;
03126 bfd_size_type amt;
03127
03128 count = 0;
03129 for (current = abfd->sections; current != NULL; current = current->next)
03130 ++count;
03131
03132
03133 amt = sizeof (struct asection *) * (count + 1);
03134 section_list = bfd_malloc (amt);
03135 if (section_list == NULL)
03136 return FALSE;
03137
03138 i = 0;
03139 for (current = abfd->sections; current != NULL; current = current->next)
03140 {
03141 section_list[i] = current;
03142 ++i;
03143 }
03144 section_list[i] = NULL;
03145
03146 qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
03147
03148
03149
03150 target_index = 1;
03151 abfd->sections = section_list[0];
03152 for (i = 0; i < count; i++)
03153 {
03154 current = section_list[i];
03155 current->next = section_list[i + 1];
03156
03157
03158
03159
03160
03161
03162 if (current->size == 0)
03163 {
03164
03165
03166
03167
03168
03169 current->target_index = 1;
03170 }
03171 else
03172 current->target_index = target_index++;
03173 }
03174 abfd->section_tail = ¤t->next;
03175
03176 free (section_list);
03177 }
03178 #else
03179 {
03180
03181 int target_index;
03182
03183 target_index = 1;
03184 for (current = abfd->sections; current != NULL; current = current->next)
03185 current->target_index = target_index++;
03186 }
03187 #endif
03188
03189 align_adjust = FALSE;
03190 for (current = abfd->sections;
03191 current != (asection *) NULL;
03192 current = current->next)
03193 {
03194 #ifdef COFF_IMAGE_WITH_PE
03195
03196
03197 if (coff_section_data (abfd, current) == NULL)
03198 {
03199 bfd_size_type amt = sizeof (struct coff_section_tdata);
03200 current->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
03201 if (current->used_by_bfd == NULL)
03202 return FALSE;
03203 }
03204 if (pei_section_data (abfd, current) == NULL)
03205 {
03206 bfd_size_type amt = sizeof (struct pei_section_tdata);
03207 coff_section_data (abfd, current)->tdata
03208 = (PTR) bfd_zalloc (abfd, amt);
03209 if (coff_section_data (abfd, current)->tdata == NULL)
03210 return FALSE;
03211 }
03212 if (pei_section_data (abfd, current)->virt_size == 0)
03213 pei_section_data (abfd, current)->virt_size = current->size;
03214 #endif
03215
03216
03217 if (!(current->flags & SEC_HAS_CONTENTS))
03218 continue;
03219
03220 #ifdef COFF_IMAGE_WITH_PE
03221
03222 if (current->size == 0)
03223 continue;
03224 #endif
03225
03226
03227
03228
03229
03230 #ifdef ALIGN_SECTIONS_IN_FILE
03231 if ((abfd->flags & EXEC_P) != 0)
03232 {
03233
03234
03235
03236 old_sofar = sofar;
03237 #ifdef RS6000COFF_C
03238
03239
03240
03241
03242
03243
03244
03245
03246 if (!strcmp (current->name, _TEXT)
03247 || !strcmp (current->name, _DATA))
03248 {
03249 bfd_vma pad;
03250 bfd_vma align;
03251
03252 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
03253
03254 align = 1 << current->alignment_power;
03255 pad = abs (current->vma - sofar) % align;
03256
03257 if (pad)
03258 {
03259 pad = align - pad;
03260 sofar += pad;
03261 }
03262 }
03263 else
03264 #else
03265 {
03266 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
03267 }
03268 #endif
03269 if (previous != (asection *) NULL)
03270 previous->size += sofar - old_sofar;
03271 }
03272
03273 #endif
03274
03275
03276
03277 #ifdef COFF_PAGE_SIZE
03278 if ((abfd->flags & D_PAGED) != 0
03279 && (current->flags & SEC_ALLOC) != 0)
03280 sofar += (current->vma - (bfd_vma) sofar) % page_size;
03281 #endif
03282 current->filepos = sofar;
03283
03284 #ifdef COFF_IMAGE_WITH_PE
03285
03286 current->size = (current->size + page_size -1) & -page_size;
03287 #endif
03288
03289 sofar += current->size;
03290
03291 #ifdef ALIGN_SECTIONS_IN_FILE
03292
03293 if ((abfd->flags & EXEC_P) == 0)
03294 {
03295 bfd_size_type old_size;
03296
03297 old_size = current->size;
03298 current->size = BFD_ALIGN (current->size,
03299 1 << current->alignment_power);
03300 align_adjust = current->size != old_size;
03301 sofar += current->size - old_size;
03302 }
03303 else
03304 {
03305 old_sofar = sofar;
03306 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
03307 align_adjust = sofar != old_sofar;
03308 current->size += sofar - old_sofar;
03309 }
03310 #endif
03311
03312 #ifdef COFF_IMAGE_WITH_PE
03313
03314
03315
03316 if (pei_section_data (abfd, current)->virt_size < current->size)
03317 align_adjust = TRUE;
03318 #endif
03319
03320 #ifdef _LIB
03321
03322
03323
03324 if (strcmp (current->name, _LIB) == 0)
03325 bfd_set_section_vma (abfd, current, 0);
03326 #endif
03327
03328 previous = current;
03329 }
03330
03331
03332
03333
03334
03335
03336 if (align_adjust)
03337 {
03338 bfd_byte b;
03339
03340 b = 0;
03341 if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
03342 || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
03343 return FALSE;
03344 }
03345
03346
03347
03348
03349 sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
03350
03351 obj_relocbase (abfd) = sofar;
03352 abfd->output_has_begun = TRUE;
03353
03354 return TRUE;
03355 }
03356
03357 #ifdef COFF_IMAGE_WITH_PE
03358
03359 static unsigned int pelength;
03360 static unsigned int peheader;
03361
03362 static bfd_boolean
03363 coff_read_word (abfd, value)
03364 bfd *abfd;
03365 unsigned int *value;
03366 {
03367 unsigned char b[2];
03368 int status;
03369
03370 status = bfd_bread (b, (bfd_size_type) 2, abfd);
03371 if (status < 1)
03372 {
03373 *value = 0;
03374 return FALSE;
03375 }
03376
03377 if (status == 1)
03378 *value = (unsigned int) b[0];
03379 else
03380 *value = (unsigned int) (b[0] + (b[1] << 8));
03381
03382 pelength += (unsigned int) status;
03383
03384 return TRUE;
03385 }
03386
03387 static unsigned int
03388 coff_compute_checksum (abfd)
03389 bfd *abfd;
03390 {
03391 bfd_boolean more_data;
03392 file_ptr filepos;
03393 unsigned int value;
03394 unsigned int total;
03395
03396 total = 0;
03397 pelength = 0;
03398 filepos = (file_ptr) 0;
03399
03400 do
03401 {
03402 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
03403 return 0;
03404
03405 more_data = coff_read_word (abfd, &value);
03406 total += value;
03407 total = 0xffff & (total + (total >> 0x10));
03408 filepos += 2;
03409 }
03410 while (more_data);
03411
03412 return (0xffff & (total + (total >> 0x10)));
03413 }
03414
03415 static bfd_boolean
03416 coff_apply_checksum (abfd)
03417 bfd *abfd;
03418 {
03419 unsigned int computed;
03420 unsigned int checksum = 0;
03421
03422 if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
03423 return FALSE;
03424
03425 if (!coff_read_word (abfd, &peheader))
03426 return FALSE;
03427
03428 if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
03429 return FALSE;
03430
03431 checksum = 0;
03432 bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
03433
03434 if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
03435 return FALSE;
03436
03437 computed = coff_compute_checksum (abfd);
03438
03439 checksum = computed + pelength;
03440
03441 if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
03442 return FALSE;
03443
03444 bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
03445
03446 return TRUE;
03447 }
03448
03449 #endif
03450
03451
03452
03453 static bfd_boolean
03454 coff_write_object_contents (abfd)
03455 bfd * abfd;
03456 {
03457 asection *current;
03458 bfd_boolean hasrelocs = FALSE;
03459 bfd_boolean haslinno = FALSE;
03460 bfd_boolean hasdebug = FALSE;
03461 file_ptr scn_base;
03462 file_ptr reloc_base;
03463 file_ptr lineno_base;
03464 file_ptr sym_base;
03465 unsigned long reloc_size = 0, reloc_count = 0;
03466 unsigned long lnno_size = 0;
03467 bfd_boolean long_section_names;
03468 asection *text_sec = NULL;
03469 asection *data_sec = NULL;
03470 asection *bss_sec = NULL;
03471 struct internal_filehdr internal_f;
03472 struct internal_aouthdr internal_a;
03473 #ifdef COFF_LONG_SECTION_NAMES
03474 size_t string_size = STRING_SIZE_SIZE;
03475 #endif
03476
03477 bfd_set_error (bfd_error_system_call);
03478
03479
03480
03481
03482 lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
03483
03484 if (! abfd->output_has_begun)
03485 {
03486 if (! coff_compute_section_file_positions (abfd))
03487 return FALSE;
03488 }
03489
03490 reloc_base = obj_relocbase (abfd);
03491
03492
03493
03494 for (current = abfd->sections; current != NULL; current =
03495 current->next)
03496 {
03497 #ifdef COFF_WITH_PE
03498
03499 if (obj_pe (abfd) && current->reloc_count >= 0xffff)
03500 reloc_count ++;
03501 #endif
03502 reloc_count += current->reloc_count;
03503 }
03504
03505 reloc_size = reloc_count * bfd_coff_relsz (abfd);
03506
03507 lineno_base = reloc_base + reloc_size;
03508 sym_base = lineno_base + lnno_size;
03509
03510
03511 for (current = abfd->sections; current != NULL; current =
03512 current->next)
03513 {
03514 if (current->lineno_count)
03515 {
03516 current->line_filepos = lineno_base;
03517 current->moving_line_filepos = lineno_base;
03518 lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
03519 }
03520 else
03521 {
03522 current->line_filepos = 0;
03523 }
03524 if (current->reloc_count)
03525 {
03526 current->rel_filepos = reloc_base;
03527 reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
03528 #ifdef COFF_WITH_PE
03529
03530 if (obj_pe (abfd) && current->reloc_count >= 0xffff)
03531 reloc_base += bfd_coff_relsz (abfd);
03532 #endif
03533 }
03534 else
03535 {
03536 current->rel_filepos = 0;
03537 }
03538 }
03539
03540
03541 internal_f.f_nscns = 0;
03542
03543 if ((abfd->flags & EXEC_P) != 0)
03544 scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
03545 else
03546 {
03547 scn_base = bfd_coff_filhsz (abfd);
03548 #ifdef RS6000COFF_C
03549 #ifndef XCOFF64
03550 if (xcoff_data (abfd)->full_aouthdr)
03551 scn_base += bfd_coff_aoutsz (abfd);
03552 else
03553 scn_base += SMALL_AOUTSZ;
03554 #endif
03555 #endif
03556 }
03557
03558 if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
03559 return FALSE;
03560
03561 long_section_names = FALSE;
03562 for (current = abfd->sections;
03563 current != NULL;
03564 current = current->next)
03565 {
03566 struct internal_scnhdr section;
03567 bfd_boolean is_reloc_section = FALSE;
03568
03569 #ifdef COFF_IMAGE_WITH_PE
03570 if (strcmp (current->name, ".reloc") == 0)
03571 {
03572 is_reloc_section = TRUE;
03573 hasrelocs = TRUE;
03574 pe_data (abfd)->has_reloc_section = 1;
03575 }
03576 #endif
03577
03578 internal_f.f_nscns++;
03579
03580 strncpy (section.s_name, current->name, SCNNMLEN);
03581
03582 #ifdef COFF_LONG_SECTION_NAMES
03583
03584
03585 {
03586 size_t len;
03587
03588 len = strlen (current->name);
03589 if (len > SCNNMLEN)
03590 {
03591 memset (section.s_name, 0, SCNNMLEN);
03592 sprintf (section.s_name, "/%lu", (unsigned long) string_size);
03593 string_size += len + 1;
03594 long_section_names = TRUE;
03595 }
03596 }
03597 #endif
03598
03599 #ifdef _LIB
03600
03601
03602 if (strcmp (current->name, _LIB) == 0)
03603 section.s_vaddr = 0;
03604 else
03605 #endif
03606 section.s_vaddr = current->vma;
03607 section.s_paddr = current->lma;
03608 section.s_size = current->size;
03609 #ifdef coff_get_section_load_page
03610 section.s_page = coff_get_section_load_page (current);
03611 #endif
03612
03613 #ifdef COFF_WITH_PE
03614 section.s_paddr = 0;
03615 #endif
03616 #ifdef COFF_IMAGE_WITH_PE
03617
03618 if (coff_section_data (abfd, current) != NULL
03619 && pei_section_data (abfd, current) != NULL)
03620 section.s_paddr = pei_section_data (abfd, current)->virt_size;
03621 else
03622 section.s_paddr = 0;
03623 #endif
03624
03625
03626
03627 if (current->size == 0
03628 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
03629 section.s_scnptr = 0;
03630 else
03631 section.s_scnptr = current->filepos;
03632
03633 section.s_relptr = current->rel_filepos;
03634 section.s_lnnoptr = current->line_filepos;
03635 section.s_nreloc = current->reloc_count;
03636 section.s_nlnno = current->lineno_count;
03637 #ifndef COFF_IMAGE_WITH_PE
03638
03639 if (current->reloc_count != 0)
03640 hasrelocs = TRUE;
03641 #endif
03642 if (current->lineno_count != 0)
03643 haslinno = TRUE;
03644 if ((current->flags & SEC_DEBUGGING) != 0
03645 && ! is_reloc_section)
03646 hasdebug = TRUE;
03647
03648 #ifdef RS6000COFF_C
03649 #ifndef XCOFF64
03650
03651 if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
03652 {
03653 section.s_nreloc = 0xffff;
03654 section.s_nlnno = 0xffff;
03655 }
03656 #endif
03657 #endif
03658
03659 section.s_flags = sec_to_styp_flags (current->name, current->flags);
03660
03661 if (!strcmp (current->name, _TEXT))
03662 text_sec = current;
03663 else if (!strcmp (current->name, _DATA))
03664 data_sec = current;
03665 else if (!strcmp (current->name, _BSS))
03666 bss_sec = current;
03667
03668 #ifdef I960
03669 section.s_align = (current->alignment_power
03670 ? 1 << current->alignment_power
03671 : 0);
03672 #endif
03673 #ifdef TIC80COFF
03674
03675 section.s_flags |= (current->alignment_power & 0xF) << 8;
03676 #endif
03677 #ifdef COFF_ENCODE_ALIGNMENT
03678 COFF_ENCODE_ALIGNMENT(section, current->alignment_power);
03679 #endif
03680
03681 #ifdef COFF_IMAGE_WITH_PE
03682
03683
03684
03685
03686
03687 if (section.s_size == 0)
03688 internal_f.f_nscns--;
03689 else
03690 #endif
03691 {
03692 SCNHDR buff;
03693 bfd_size_type amt = bfd_coff_scnhsz (abfd);
03694
03695 if (coff_swap_scnhdr_out (abfd, §ion, &buff) == 0
03696 || bfd_bwrite ((PTR) &buff, amt, abfd) != amt)
03697 return FALSE;
03698 }
03699
03700 #ifdef COFF_WITH_PE
03701
03702
03703
03704 if ((current->flags & SEC_LINK_ONCE) != 0)
03705 {
03706 unsigned int i, count;
03707 asymbol **psym;
03708 coff_symbol_type *csym = NULL;
03709 asymbol **psymsec;
03710
03711 psymsec = NULL;
03712 count = bfd_get_symcount (abfd);
03713 for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
03714 {
03715 if ((*psym)->section != current)
03716 continue;
03717
03718
03719
03720 if (psymsec == NULL)
03721 psymsec = psym;
03722
03723
03724 if (strcmp ((*psym)->name, current->name) == 0)
03725 {
03726 csym = coff_symbol_from (abfd, *psym);
03727 if (csym == NULL
03728 || csym->native == NULL
03729 || csym->native->u.syment.n_numaux < 1
03730 || csym->native->u.syment.n_sclass != C_STAT
03731 || csym->native->u.syment.n_type != T_NULL)
03732 continue;
03733
03734
03735
03736 break;
03737 }
03738 }
03739
03740
03741
03742
03743 if (i < count)
03744 {
03745 combined_entry_type *aux;
03746
03747
03748
03749
03750 aux = csym->native + 1;
03751 switch (current->flags & SEC_LINK_DUPLICATES)
03752 {
03753 case SEC_LINK_DUPLICATES_DISCARD:
03754 aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
03755 break;
03756
03757 case SEC_LINK_DUPLICATES_ONE_ONLY:
03758 aux->u.auxent.x_scn.x_comdat =
03759 IMAGE_COMDAT_SELECT_NODUPLICATES;
03760 break;
03761
03762 case SEC_LINK_DUPLICATES_SAME_SIZE:
03763 aux->u.auxent.x_scn.x_comdat =
03764 IMAGE_COMDAT_SELECT_SAME_SIZE;
03765 break;
03766
03767 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
03768 aux->u.auxent.x_scn.x_comdat =
03769 IMAGE_COMDAT_SELECT_EXACT_MATCH;
03770 break;
03771 }
03772
03773
03774
03775
03776
03777
03778
03779
03780 if (psym != psymsec)
03781 {
03782 asymbol *hold;
03783 asymbol **pcopy;
03784
03785 hold = *psym;
03786 for (pcopy = psym; pcopy > psymsec; pcopy--)
03787 pcopy[0] = pcopy[-1];
03788 *psymsec = hold;
03789 }
03790 }
03791 }
03792 #endif
03793 }
03794
03795 #ifdef RS6000COFF_C
03796 #ifndef XCOFF64
03797
03798
03799 for (current = abfd->sections; current != NULL; current = current->next)
03800 {
03801 if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
03802 {
03803 struct internal_scnhdr scnhdr;
03804 SCNHDR buff;
03805 bfd_size_type amt;
03806
03807 internal_f.f_nscns++;
03808 strncpy (&(scnhdr.s_name[0]), current->name, 8);
03809 scnhdr.s_paddr = current->reloc_count;
03810 scnhdr.s_vaddr = current->lineno_count;
03811 scnhdr.s_size = 0;
03812 scnhdr.s_scnptr = 0;
03813 scnhdr.s_relptr = current->rel_filepos;
03814 scnhdr.s_lnnoptr = current->line_filepos;
03815 scnhdr.s_nreloc = current->target_index;
03816 scnhdr.s_nlnno = current->target_index;
03817 scnhdr.s_flags = STYP_OVRFLO;
03818 amt = bfd_coff_scnhsz (abfd);
03819 if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
03820 || bfd_bwrite ((PTR) &buff, amt, abfd) != amt)
03821 return FALSE;
03822 }
03823 }
03824 #endif
03825 #endif
03826
03827
03828
03829
03830
03831
03832
03833
03834
03835 internal_f.f_timdat = 0;
03836 internal_f.f_flags = 0;
03837
03838 if (abfd->flags & EXEC_P)
03839 internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
03840 else
03841 {
03842 internal_f.f_opthdr = 0;
03843 #ifdef RS6000COFF_C
03844 #ifndef XCOFF64
03845 if (xcoff_data (abfd)->full_aouthdr)
03846 internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
03847 else
03848 internal_f.f_opthdr = SMALL_AOUTSZ;
03849 #endif
03850 #endif
03851 }
03852
03853 if (!hasrelocs)
03854 internal_f.f_flags |= F_RELFLG;
03855 if (!haslinno)
03856 internal_f.f_flags |= F_LNNO;
03857 if (abfd->flags & EXEC_P)
03858 internal_f.f_flags |= F_EXEC;
03859 #ifdef COFF_IMAGE_WITH_PE
03860 if (! hasdebug)
03861 internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
03862 if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
03863 internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
03864 #endif
03865
03866 #ifdef COFF_WITH_PE
03867 internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
03868 #else
03869 if (bfd_little_endian (abfd))
03870 internal_f.f_flags |= F_AR32WR;
03871 else
03872 internal_f.f_flags |= F_AR32W;
03873 #endif
03874
03875 #ifdef TI_TARGET_ID
03876
03877
03878 internal_f.f_target_id = TI_TARGET_ID;
03879 #endif
03880 #ifdef TIC80_TARGET_ID
03881 internal_f.f_target_id = TIC80_TARGET_ID;
03882 #endif
03883
03884
03885
03886
03887 #ifdef RS6000COFF_C
03888 if ((abfd->flags & DYNAMIC) != 0)
03889 internal_f.f_flags |= F_SHROBJ;
03890 if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
03891 internal_f.f_flags |= F_DYNLOAD;
03892 #endif
03893
03894 memset (&internal_a, 0, sizeof internal_a);
03895
03896
03897 {
03898 unsigned int magic = 0;
03899 unsigned short flags = 0;
03900
03901 coff_set_flags (abfd, &magic, &flags);
03902 internal_f.f_magic = magic;
03903 internal_f.f_flags |= flags;
03904
03905
03906 #ifdef A29K
03907 #ifdef ULTRA3
03908
03909
03910
03911 if (internal_f.f_nscns >= 7)
03912 internal_a.magic = SHMAGIC;
03913 else
03914 #endif
03915 internal_a.magic = NMAGIC;
03916 #define __A_MAGIC_SET__
03917 #endif
03918 #ifdef TICOFF_AOUT_MAGIC
03919 internal_a.magic = TICOFF_AOUT_MAGIC;
03920 #define __A_MAGIC_SET__
03921 #endif
03922 #ifdef TIC80COFF
03923 internal_a.magic = TIC80_ARCH_MAGIC;
03924 #define __A_MAGIC_SET__
03925 #endif
03926 #ifdef I860
03927
03928 internal_a.magic = 0;
03929 #define __A_MAGIC_SET__
03930 #endif
03931 #ifdef I960
03932 internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
03933 #define __A_MAGIC_SET__
03934 #endif
03935 #if M88
03936 #define __A_MAGIC_SET__
03937 internal_a.magic = PAGEMAGICBCS;
03938 #endif
03939
03940 #if APOLLO_M68
03941 #define __A_MAGIC_SET__
03942 internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
03943 #endif
03944
03945 #if defined(M68) || defined(WE32K) || defined(M68K)
03946 #define __A_MAGIC_SET__
03947 #if defined(LYNXOS)
03948 internal_a.magic = LYNXCOFFMAGIC;
03949 #else
03950 #if defined(TARG_AUX)
03951 internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED :
03952 abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED :
03953 PAGEMAGICEXECSWAPPED);
03954 #else
03955 #if defined (PAGEMAGICPEXECPAGED)
03956 internal_a.magic = PAGEMAGICPEXECPAGED;
03957 #endif
03958 #endif
03959 #endif
03960 #endif
03961
03962 #if defined(ARM)
03963 #define __A_MAGIC_SET__
03964 internal_a.magic = ZMAGIC;
03965 #endif
03966
03967 #if defined(PPC_PE)
03968 #define __A_MAGIC_SET__
03969 internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
03970 #endif
03971
03972 #if defined MCORE_PE
03973 #define __A_MAGIC_SET__
03974 internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
03975 #endif
03976
03977 #if defined(I386)
03978 #define __A_MAGIC_SET__
03979 #if defined(LYNXOS)
03980 internal_a.magic = LYNXCOFFMAGIC;
03981 #else
03982 internal_a.magic = ZMAGIC;
03983 #endif
03984 #endif
03985
03986 #if defined(IA64)
03987 #define __A_MAGIC_SET__
03988 internal_a.magic = ZMAGIC;
03989 #endif
03990
03991 #if defined(SPARC)
03992 #define __A_MAGIC_SET__
03993 #if defined(LYNXOS)
03994 internal_a.magic = LYNXCOFFMAGIC;
03995 #endif
03996 #endif
03997
03998 #ifdef RS6000COFF_C
03999 #define __A_MAGIC_SET__
04000 internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
04001 (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
04002 RS6K_AOUTHDR_OMAGIC;
04003 #endif
04004
04005 #if defined(SH) && defined(COFF_WITH_PE)
04006 #define __A_MAGIC_SET__
04007 internal_a.magic = SH_PE_MAGIC;
04008 #endif
04009
04010 #if defined(MIPS) && defined(COFF_WITH_PE)
04011 #define __A_MAGIC_SET__
04012 internal_a.magic = MIPS_PE_MAGIC;
04013 #endif
04014
04015 #ifdef OR32
04016 #define __A_MAGIC_SET__
04017 internal_a.magic = NMAGIC;
04018 #endif
04019
04020 #ifdef MAXQ20MAGIC
04021 #define __A_MAGIC_SET__
04022 internal_a.magic = MAXQ20MAGIC;
04023 #endif
04024
04025 #ifndef __A_MAGIC_SET__
04026 #include "Your aouthdr magic number is not being set!"
04027 #else
04028 #undef __A_MAGIC_SET__
04029 #endif
04030 }
04031
04032
04033 internal_a.vstamp = 0;
04034
04035
04036 obj_sym_filepos (abfd) = sym_base;
04037
04038 if (bfd_get_symcount (abfd) != 0)
04039 {
04040 int firstundef;
04041
04042 if (!coff_renumber_symbols (abfd, &firstundef))
04043 return FALSE;
04044 coff_mangle_symbols (abfd);
04045 if (! coff_write_symbols (abfd))
04046 return FALSE;
04047 if (! coff_write_linenumbers (abfd))
04048 return FALSE;
04049 if (! coff_write_relocs (abfd, firstundef))
04050 return FALSE;
04051 }
04052 #ifdef COFF_LONG_SECTION_NAMES
04053 else if (long_section_names && ! obj_coff_strings_written (abfd))
04054 {
04055
04056
04057 if (! coff_write_symbols (abfd))
04058 return FALSE;
04059 }
04060 #endif
04061 #ifdef COFF_IMAGE_WITH_PE
04062 #ifdef PPC_PE
04063 else if ((abfd->flags & EXEC_P) != 0)
04064 {
04065 bfd_byte b;
04066
04067
04068
04069 b = 0;
04070 if (bfd_seek (abfd,
04071 (file_ptr) BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
04072 SEEK_SET) != 0
04073 || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
04074 return FALSE;
04075 }
04076 #endif
04077 #endif
04078
04079
04080
04081
04082 if (obj_raw_syment_count (abfd) != 0)
04083 {
04084 internal_f.f_symptr = sym_base;
04085 #ifdef RS6000COFF_C
04086
04087
04088 internal_f.f_flags &=~ F_RELFLG;
04089 #endif
04090 }
04091 else
04092 {
04093 if (long_section_names)
04094 internal_f.f_symptr = sym_base;
04095 else
04096 internal_f.f_symptr = 0;
04097 internal_f.f_flags |= F_LSYMS;
04098 }
04099
04100 if (text_sec)
04101 {
04102 internal_a.tsize = text_sec->size;
04103 internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
04104 }
04105 if (data_sec)
04106 {
04107 internal_a.dsize = data_sec->size;
04108 internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
04109 }
04110 if (bss_sec)
04111 {
04112 internal_a.bsize = bss_sec->size;
04113 if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
04114 internal_a.data_start = bss_sec->vma;
04115 }
04116
04117 internal_a.entry = bfd_get_start_address (abfd);
04118 internal_f.f_nsyms = obj_raw_syment_count (abfd);
04119
04120 #ifdef RS6000COFF_C
04121 if (xcoff_data (abfd)->full_aouthdr)
04122 {
04123 bfd_vma toc;
04124 asection *loader_sec;
04125
04126 internal_a.vstamp = 1;
04127
04128 internal_a.o_snentry = xcoff_data (abfd)->snentry;
04129 if (internal_a.o_snentry == 0)
04130 internal_a.entry = (bfd_vma) -1;
04131
04132 if (text_sec != NULL)
04133 {
04134 internal_a.o_sntext = text_sec->target_index;
04135 internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
04136 }
04137 else
04138 {
04139 internal_a.o_sntext = 0;
04140 internal_a.o_algntext = 0;
04141 }
04142 if (data_sec != NULL)
04143 {
04144 internal_a.o_sndata = data_sec->target_index;
04145 internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
04146 }
04147 else
04148 {
04149 internal_a.o_sndata = 0;
04150 internal_a.o_algndata = 0;
04151 }
04152 loader_sec = bfd_get_section_by_name (abfd, ".loader");
04153 if (loader_sec != NULL)
04154 internal_a.o_snloader = loader_sec->target_index;
04155 else
04156 internal_a.o_snloader = 0;
04157 if (bss_sec != NULL)
04158 internal_a.o_snbss = bss_sec->target_index;
04159 else
04160 internal_a.o_snbss = 0;
04161
04162 toc = xcoff_data (abfd)->toc;
04163 internal_a.o_toc = toc;
04164 internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
04165
04166 internal_a.o_modtype = xcoff_data (abfd)->modtype;
04167 if (xcoff_data (abfd)->cputype != -1)
04168 internal_a.o_cputype = xcoff_data (abfd)->cputype;
04169 else
04170 {
04171 switch (bfd_get_arch (abfd))
04172 {
04173 case bfd_arch_rs6000:
04174 internal_a.o_cputype = 4;
04175 break;
04176 case bfd_arch_powerpc:
04177 if (bfd_get_mach (abfd) == bfd_mach_ppc)
04178 internal_a.o_cputype = 3;
04179 else
04180 internal_a.o_cputype = 1;
04181 break;
04182 default:
04183 abort ();
04184 }
04185 }
04186 internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
04187 internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
04188 }
04189 #endif
04190
04191
04192 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
04193 return FALSE;
04194
04195 {
04196 char * buff;
04197 bfd_size_type amount = bfd_coff_filhsz (abfd);
04198
04199 buff = bfd_malloc (amount);
04200 if (buff == NULL)
04201 return FALSE;
04202
04203 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) buff);
04204 amount = bfd_bwrite ((PTR) buff, amount, abfd);
04205
04206 free (buff);
04207
04208 if (amount != bfd_coff_filhsz (abfd))
04209 return FALSE;
04210 }
04211
04212 if (abfd->flags & EXEC_P)
04213 {
04214
04215
04216 char * buff;
04217 bfd_size_type amount = bfd_coff_aoutsz (abfd);
04218
04219 buff = bfd_malloc (amount);
04220 if (buff == NULL)
04221 return FALSE;
04222
04223 coff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) buff);
04224 amount = bfd_bwrite ((PTR) buff, amount, abfd);
04225
04226 free (buff);
04227
04228 if (amount != bfd_coff_aoutsz (abfd))
04229 return FALSE;
04230
04231 #ifdef COFF_IMAGE_WITH_PE
04232 if (! coff_apply_checksum (abfd))
04233 return FALSE;
04234 #endif
04235 }
04236 #ifdef RS6000COFF_C
04237 else
04238 {
04239 AOUTHDR buff;
04240 size_t size;
04241
04242
04243 coff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff);
04244 if (xcoff_data (abfd)->full_aouthdr)
04245 size = bfd_coff_aoutsz (abfd);
04246 else
04247 size = SMALL_AOUTSZ;
04248 if (bfd_bwrite ((PTR) &buff, (bfd_size_type) size, abfd) != size)
04249 return FALSE;
04250 }
04251 #endif
04252
04253 return TRUE;
04254 }
04255
04256 static bfd_boolean
04257 coff_set_section_contents (abfd, section, location, offset, count)
04258 bfd * abfd;
04259 sec_ptr section;
04260 const PTR location;
04261 file_ptr offset;
04262 bfd_size_type count;
04263 {
04264 if (! abfd->output_has_begun)
04265 {
04266 if (! coff_compute_section_file_positions (abfd))
04267 return FALSE;
04268 }
04269
04270 #if defined(_LIB) && !defined(TARG_AUX)
04271
04272
04273
04274
04275
04276
04277
04278
04279
04280
04281
04282
04283
04284
04285
04286
04287
04288
04289
04290
04291
04292
04293 if (strcmp (section->name, _LIB) == 0)
04294 {
04295 bfd_byte *rec, *recend;
04296
04297 rec = (bfd_byte *) location;
04298 recend = rec + count;
04299 while (rec < recend)
04300 {
04301 ++section->lma;
04302 rec += bfd_get_32 (abfd, rec) * 4;
04303 }
04304
04305 BFD_ASSERT (rec == recend);
04306 }
04307
04308 #endif
04309
04310
04311
04312 if (section->filepos == 0)
04313 return TRUE;
04314
04315 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
04316 return FALSE;
04317
04318 if (count == 0)
04319 return TRUE;
04320
04321 return bfd_bwrite (location, count, abfd) == count;
04322 }
04323
04324 static PTR
04325 buy_and_read (abfd, where, size)
04326 bfd *abfd;
04327 file_ptr where;
04328 bfd_size_type size;
04329 {
04330 PTR area = (PTR) bfd_alloc (abfd, size);
04331 if (!area)
04332 return (NULL);
04333 if (bfd_seek (abfd, where, SEEK_SET) != 0
04334 || bfd_bread (area, size, abfd) != size)
04335 return (NULL);
04336 return (area);
04337 }
04338
04339
04340
04341
04342
04343
04344
04345
04346
04347
04348
04349
04350
04351
04352
04353
04354
04355
04356
04357
04358
04359
04360
04361
04362
04363 static bfd_boolean
04364 coff_slurp_line_table (abfd, asect)
04365 bfd *abfd;
04366 asection *asect;
04367 {
04368 LINENO *native_lineno;
04369 alent *lineno_cache;
04370 bfd_size_type amt;
04371
04372 BFD_ASSERT (asect->lineno == (alent *) NULL);
04373
04374 amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
04375 native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
04376 if (native_lineno == NULL)
04377 {
04378 (*_bfd_error_handler)
04379 (_("%B: warning: line number table read failed"), abfd);
04380 return FALSE;
04381 }
04382 amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
04383 lineno_cache = (alent *) bfd_alloc (abfd, amt);
04384 if (lineno_cache == NULL)
04385 return FALSE;
04386 else
04387 {
04388 unsigned int counter = 0;
04389 alent *cache_ptr = lineno_cache;
04390 LINENO *src = native_lineno;
04391
04392 while (counter < asect->lineno_count)
04393 {
04394 struct internal_lineno dst;
04395
04396 bfd_coff_swap_lineno_in (abfd, src, &dst);
04397 cache_ptr->line_number = dst.l_lnno;
04398
04399 if (cache_ptr->line_number == 0)
04400 {
04401 bfd_boolean warned;
04402 bfd_signed_vma symndx;
04403 coff_symbol_type *sym;
04404
04405 warned = FALSE;
04406 symndx = dst.l_addr.l_symndx;
04407 if (symndx < 0
04408 || (bfd_vma) symndx >= obj_raw_syment_count (abfd))
04409 {
04410 (*_bfd_error_handler)
04411 (_("%B: warning: illegal symbol index %ld in line numbers"),
04412 abfd, dst.l_addr.l_symndx);
04413 symndx = 0;
04414 warned = TRUE;
04415 }
04416
04417
04418 sym = ((coff_symbol_type *)
04419 ((symndx + obj_raw_syments (abfd))
04420 ->u.syment._n._n_n._n_zeroes));
04421 cache_ptr->u.sym = (asymbol *) sym;
04422 if (sym->lineno != NULL && ! warned)
04423 {
04424 (*_bfd_error_handler)
04425 (_("%B: warning: duplicate line number information for `%s'"),
04426 abfd, bfd_asymbol_name (&sym->symbol));
04427 }
04428 sym->lineno = cache_ptr;
04429 }
04430 else
04431 {
04432 cache_ptr->u.offset = dst.l_addr.l_paddr
04433 - bfd_section_vma (abfd, asect);
04434 }
04435
04436 cache_ptr++;
04437 src++;
04438 counter++;
04439 }
04440 cache_ptr->line_number = 0;
04441
04442 }
04443 asect->lineno = lineno_cache;
04444
04445 return TRUE;
04446 }
04447
04448
04449
04450
04451
04452 static bfd_boolean
04453 coff_slurp_symbol_table (abfd)
04454 bfd * abfd;
04455 {
04456 combined_entry_type *native_symbols;
04457 coff_symbol_type *cached_area;
04458 unsigned int *table_ptr;
04459 bfd_size_type amt;
04460 unsigned int number_of_symbols = 0;
04461
04462 if (obj_symbols (abfd))
04463 return TRUE;
04464
04465
04466 if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
04467 return FALSE;
04468
04469
04470 amt = obj_raw_syment_count (abfd);
04471 amt *= sizeof (coff_symbol_type);
04472 cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
04473 if (cached_area == NULL)
04474 return FALSE;
04475
04476 amt = obj_raw_syment_count (abfd);
04477 amt *= sizeof (unsigned int);
04478 table_ptr = (unsigned int *) bfd_alloc (abfd, amt);
04479
04480 if (table_ptr == NULL)
04481 return FALSE;
04482 else
04483 {
04484 coff_symbol_type *dst = cached_area;
04485 unsigned int last_native_index = obj_raw_syment_count (abfd);
04486 unsigned int this_index = 0;
04487
04488 while (this_index < last_native_index)
04489 {
04490 combined_entry_type *src = native_symbols + this_index;
04491 table_ptr[this_index] = number_of_symbols;
04492 dst->symbol.the_bfd = abfd;
04493
04494 dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
04495
04496 src->u.syment._n._n_n._n_zeroes = (long) dst;
04497 dst->symbol.section = coff_section_from_bfd_index (abfd,
04498 src->u.syment.n_scnum);
04499 dst->symbol.flags = 0;
04500 dst->done_lineno = FALSE;
04501
04502 switch (src->u.syment.n_sclass)
04503 {
04504 #ifdef I960
04505 case C_LEAFEXT:
04506
04507 #endif
04508
04509 case C_EXT:
04510 case C_WEAKEXT:
04511 #if defined ARM
04512 case C_THUMBEXT:
04513 case C_THUMBEXTFUNC:
04514 #endif
04515 #ifdef RS6000COFF_C
04516 case C_HIDEXT:
04517 #endif
04518 #ifdef C_SYSTEM
04519 case C_SYSTEM:
04520 #endif
04521 #ifdef COFF_WITH_PE
04522
04523 case C_SECTION:
04524
04525 case C_NT_WEAK:
04526 #endif
04527 switch (coff_classify_symbol (abfd, &src->u.syment))
04528 {
04529 case COFF_SYMBOL_GLOBAL:
04530 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
04531 #if defined COFF_WITH_PE
04532
04533
04534 dst->symbol.value = src->u.syment.n_value;
04535 #else
04536 dst->symbol.value = (src->u.syment.n_value
04537 - dst->symbol.section->vma);
04538 #endif
04539 if (ISFCN ((src->u.syment.n_type)))
04540 {
04541
04542
04543 dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
04544 }
04545 break;
04546
04547 case COFF_SYMBOL_COMMON:
04548 dst->symbol.section = bfd_com_section_ptr;
04549 dst->symbol.value = src->u.syment.n_value;
04550 break;
04551
04552 case COFF_SYMBOL_UNDEFINED:
04553 dst->symbol.section = bfd_und_section_ptr;
04554 dst->symbol.value = 0;
04555 break;
04556
04557 case COFF_SYMBOL_PE_SECTION:
04558 dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
04559 dst->symbol.value = 0;
04560 break;
04561
04562 case COFF_SYMBOL_LOCAL:
04563 dst->symbol.flags = BSF_LOCAL;
04564 #if defined COFF_WITH_PE
04565
04566
04567 dst->symbol.value = src->u.syment.n_value;
04568 #else
04569 dst->symbol.value = (src->u.syment.n_value
04570 - dst->symbol.section->vma);
04571 #endif
04572 if (ISFCN ((src->u.syment.n_type)))
04573 dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
04574 break;
04575 }
04576
04577 #ifdef RS6000COFF_C
04578
04579 if (src->u.syment.n_numaux > 0)
04580 dst->symbol.flags |= BSF_NOT_AT_END;
04581 #endif
04582
04583 #ifdef COFF_WITH_PE
04584 if (src->u.syment.n_sclass == C_NT_WEAK)
04585 dst->symbol.flags |= BSF_WEAK;
04586
04587 if (src->u.syment.n_sclass == C_SECTION
04588 && src->u.syment.n_scnum > 0)
04589 dst->symbol.flags = BSF_LOCAL;
04590 #endif
04591 if (src->u.syment.n_sclass == C_WEAKEXT)
04592 dst->symbol.flags |= BSF_WEAK;
04593
04594 break;
04595
04596 case C_STAT:
04597 #ifdef I960
04598 case C_LEAFSTAT:
04599 #endif
04600 #if defined ARM
04601 case C_THUMBSTAT:
04602 case C_THUMBLABEL:
04603 case C_THUMBSTATFUNC:
04604 #endif
04605 case C_LABEL:
04606 if (src->u.syment.n_scnum == N_DEBUG)
04607 dst->symbol.flags = BSF_DEBUGGING;
04608 else
04609 dst->symbol.flags = BSF_LOCAL;
04610
04611
04612
04613 if (dst->symbol.section)
04614 {
04615 #if defined COFF_WITH_PE
04616
04617
04618 dst->symbol.value = src->u.syment.n_value;
04619 #else
04620 dst->symbol.value = (src->u.syment.n_value
04621 - dst->symbol.section->vma);
04622 #endif
04623 }
04624 else
04625 dst->symbol.value = src->u.syment.n_value;
04626 break;
04627
04628 case C_MOS:
04629 case C_EOS:
04630 #ifdef NOTDEF
04631 #ifdef C_GLBLREG
04632 case C_GLBLREG:
04633 #endif
04634 #endif
04635 case C_REGPARM:
04636 case C_REG:
04637
04638 #if !defined (TIC80COFF) && !defined (TICOFF)
04639 #ifdef C_AUTOARG
04640 case C_AUTOARG:
04641 #endif
04642 #endif
04643 case C_TPDEF:
04644 case C_ARG:
04645 case C_AUTO:
04646 case C_FIELD:
04647 case C_ENTAG:
04648 case C_MOE:
04649 case C_MOU:
04650 case C_UNTAG:
04651 dst->symbol.flags = BSF_DEBUGGING;
04652 dst->symbol.value = (src->u.syment.n_value);
04653 break;
04654
04655 case C_FILE:
04656 case C_STRTAG:
04657 #ifdef RS6000COFF_C
04658 case C_GSYM:
04659 case C_LSYM:
04660 case C_PSYM:
04661 case C_RSYM:
04662 case C_RPSYM:
04663 case C_STSYM:
04664 case C_TCSYM:
04665 case C_BCOMM:
04666 case C_ECOML:
04667 case C_ECOMM:
04668 case C_DECL:
04669 case C_ENTRY:
04670 case C_FUN:
04671 case C_ESTAT:
04672 #endif
04673 dst->symbol.flags = BSF_DEBUGGING;
04674 dst->symbol.value = (src->u.syment.n_value);
04675 break;
04676
04677 #ifdef RS6000COFF_C
04678 case C_BINCL:
04679 case C_EINCL:
04680
04681
04682
04683
04684 {
04685 asection *sec;
04686
04687 dst->symbol.flags = BSF_DEBUGGING;
04688 for (sec = abfd->sections; sec != NULL; sec = sec->next)
04689 if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
04690 && ((file_ptr) (sec->line_filepos
04691 + sec->lineno_count * bfd_coff_linesz (abfd))
04692 > (file_ptr) src->u.syment.n_value))
04693 break;
04694 if (sec == NULL)
04695 dst->symbol.value = 0;
04696 else
04697 {
04698 dst->symbol.section = sec;
04699 dst->symbol.value = ((src->u.syment.n_value
04700 - sec->line_filepos)
04701 / bfd_coff_linesz (abfd));
04702 src->fix_line = 1;
04703 }
04704 }
04705 break;
04706
04707 case C_BSTAT:
04708 dst->symbol.flags = BSF_DEBUGGING;
04709
04710
04711
04712
04713 src->u.syment.n_value =
04714 (long) (native_symbols + src->u.syment.n_value);
04715 dst->symbol.value = src->u.syment.n_value;
04716 src->fix_value = 1;
04717 break;
04718 #endif
04719
04720 case C_BLOCK:
04721 case C_FCN:
04722 case C_EFCN:
04723 #if defined COFF_WITH_PE
04724
04725
04726 dst->symbol.value = src->u.syment.n_value;
04727 if (strcmp (dst->symbol.name, ".bf") != 0)
04728 {
04729
04730
04731 dst->symbol.flags = BSF_DEBUGGING;
04732 }
04733 else
04734 dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
04735 #else
04736
04737
04738 dst->symbol.flags = BSF_LOCAL;
04739 dst->symbol.value = (src->u.syment.n_value
04740 - dst->symbol.section->vma);
04741 #endif
04742 break;
04743
04744 case C_STATLAB:
04745 dst->symbol.value = src->u.syment.n_value;
04746 dst->symbol.flags = BSF_GLOBAL;
04747 break;
04748
04749 case C_NULL:
04750
04751
04752 if (src->u.syment.n_type == 0
04753 && src->u.syment.n_value == 0
04754 && src->u.syment.n_scnum == 0)
04755 break;
04756
04757 case C_EXTDEF:
04758 case C_ULABEL:
04759 case C_USTATIC:
04760 #ifndef COFF_WITH_PE
04761
04762
04763 case C_LINE:
04764
04765 case C_ALIAS:
04766 #endif
04767
04768 #if defined(TIC80COFF) || defined(TICOFF)
04769 case C_UEXT:
04770 #endif
04771 case C_EXTLAB:
04772 case C_HIDDEN:
04773 default:
04774 (*_bfd_error_handler)
04775 (_("%B: Unrecognized storage class %d for %s symbol `%s'"),
04776 abfd, src->u.syment.n_sclass,
04777 dst->symbol.section->name, dst->symbol.name);
04778 dst->symbol.flags = BSF_DEBUGGING;
04779 dst->symbol.value = (src->u.syment.n_value);
04780 break;
04781 }
04782
04783
04784
04785 dst->native = src;
04786
04787 dst->symbol.udata.i = 0;
04788 dst->lineno = (alent *) NULL;
04789 this_index += (src->u.syment.n_numaux) + 1;
04790 dst++;
04791 number_of_symbols++;
04792 }
04793 }
04794
04795 obj_symbols (abfd) = cached_area;
04796 obj_raw_syments (abfd) = native_symbols;
04797
04798 bfd_get_symcount (abfd) = number_of_symbols;
04799 obj_convert (abfd) = table_ptr;
04800
04801 {
04802 asection *p;
04803
04804 p = abfd->sections;
04805 while (p)
04806 {
04807 coff_slurp_line_table (abfd, p);
04808 p = p->next;
04809 }
04810 }
04811
04812 return TRUE;
04813 }
04814
04815
04816
04817
04818
04819 static enum coff_symbol_classification
04820 coff_classify_symbol (abfd, syment)
04821 bfd *abfd;
04822 struct internal_syment *syment;
04823 {
04824
04825
04826 switch (syment->n_sclass)
04827 {
04828 case C_EXT:
04829 case C_WEAKEXT:
04830 #ifdef I960
04831 case C_LEAFEXT:
04832 #endif
04833 #ifdef ARM
04834 case C_THUMBEXT:
04835 case C_THUMBEXTFUNC:
04836 #endif
04837 #ifdef C_SYSTEM
04838 case C_SYSTEM:
04839 #endif
04840 #ifdef COFF_WITH_PE
04841 case C_NT_WEAK:
04842 #endif
04843 if (syment->n_scnum == 0)
04844 {
04845 if (syment->n_value == 0)
04846 return COFF_SYMBOL_UNDEFINED;
04847 else
04848 return COFF_SYMBOL_COMMON;
04849 }
04850 return COFF_SYMBOL_GLOBAL;
04851
04852 default:
04853 break;
04854 }
04855
04856 #ifdef COFF_WITH_PE
04857 if (syment->n_sclass == C_STAT)
04858 {
04859 if (syment->n_scnum == 0)
04860 {
04861
04862
04863
04864
04865 return COFF_SYMBOL_LOCAL;
04866 }
04867
04868 #ifdef STRICT_PE_FORMAT
04869
04870
04871
04872 if (syment->n_value == 0)
04873 {
04874 asection *sec;
04875 char buf[SYMNMLEN + 1];
04876
04877 sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
04878 if (sec != NULL
04879 && (strcmp (bfd_get_section_name (abfd, sec),
04880 _bfd_coff_internal_syment_name (abfd, syment, buf))
04881 == 0))
04882 return COFF_SYMBOL_PE_SECTION;
04883 }
04884 #endif
04885
04886 return COFF_SYMBOL_LOCAL;
04887 }
04888
04889 if (syment->n_sclass == C_SECTION)
04890 {
04891
04892
04893
04894 syment->n_value = 0;
04895 if (syment->n_scnum == 0)
04896 return COFF_SYMBOL_UNDEFINED;
04897 return COFF_SYMBOL_PE_SECTION;
04898 }
04899 #endif
04900
04901
04902
04903 if (syment->n_scnum == 0)
04904 {
04905 char buf[SYMNMLEN + 1];
04906
04907 (*_bfd_error_handler)
04908 (_("warning: %B: local symbol `%s' has no section"),
04909 abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
04910 }
04911
04912 return COFF_SYMBOL_LOCAL;
04913 }
04914
04915
04916
04917
04918
04919
04920
04921
04922
04923
04924
04925
04926
04927
04928
04929
04930
04931
04932
04933
04934
04935
04936
04937
04938
04939
04940
04941
04942
04943 #ifndef CALC_ADDEND
04944 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
04945 { \
04946 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
04947 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
04948 coffsym = (obj_symbols (abfd) \
04949 + (cache_ptr->sym_ptr_ptr - symbols)); \
04950 else if (ptr) \
04951 coffsym = coff_symbol_from (abfd, ptr); \
04952 if (coffsym != (coff_symbol_type *) NULL \
04953 && coffsym->native->u.syment.n_scnum == 0) \
04954 cache_ptr->addend = 0; \
04955 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
04956 && ptr->section != (asection *) NULL) \
04957 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
04958 else \
04959 cache_ptr->addend = 0; \
04960 }
04961 #endif
04962
04963 static bfd_boolean
04964 coff_slurp_reloc_table (abfd, asect, symbols)
04965 bfd * abfd;
04966 sec_ptr asect;
04967 asymbol ** symbols;
04968 {
04969 RELOC *native_relocs;
04970 arelent *reloc_cache;
04971 arelent *cache_ptr;
04972 unsigned int idx;
04973 bfd_size_type amt;
04974
04975 if (asect->relocation)
04976 return TRUE;
04977 if (asect->reloc_count == 0)
04978 return TRUE;
04979 if (asect->flags & SEC_CONSTRUCTOR)
04980 return TRUE;
04981 if (!coff_slurp_symbol_table (abfd))
04982 return FALSE;
04983 amt = (bfd_size_type) bfd_coff_relsz (abfd) * asect->reloc_count;
04984 native_relocs = (RELOC *) buy_and_read (abfd, asect->rel_filepos, amt);
04985 amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
04986 reloc_cache = (arelent *) bfd_alloc (abfd, amt);
04987
04988 if (reloc_cache == NULL)
04989 return FALSE;
04990
04991 for (idx = 0; idx < asect->reloc_count; idx++)
04992 {
04993 struct internal_reloc dst;
04994 struct external_reloc *src;
04995 #ifndef RELOC_PROCESSING
04996 asymbol *ptr;
04997 #endif
04998
04999 cache_ptr = reloc_cache + idx;
05000 src = native_relocs + idx;
05001
05002 coff_swap_reloc_in (abfd, src, &dst);
05003
05004 #ifdef RELOC_PROCESSING
05005 RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
05006 #else
05007 cache_ptr->address = dst.r_vaddr;
05008
05009 if (dst.r_symndx != -1)
05010 {
05011 if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
05012 {
05013 (*_bfd_error_handler)
05014 (_("%B: warning: illegal symbol index %ld in relocs"),
05015 abfd, dst.r_symndx);
05016 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
05017 ptr = NULL;
05018 }
05019 else
05020 {
05021 cache_ptr->sym_ptr_ptr = (symbols
05022 + obj_convert (abfd)[dst.r_symndx]);
05023 ptr = *(cache_ptr->sym_ptr_ptr);
05024 }
05025 }
05026 else
05027 {
05028 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
05029 ptr = NULL;
05030 }
05031
05032
05033
05034
05035
05036
05037
05038
05039
05040 CALC_ADDEND (abfd, ptr, dst, cache_ptr);
05041
05042 cache_ptr->address -= asect->vma;
05043
05044
05045
05046 RTYPE2HOWTO (cache_ptr, &dst);
05047 #endif
05048
05049 if (cache_ptr->howto == NULL)
05050 {
05051 (*_bfd_error_handler)
05052 (_("%B: illegal relocation type %d at address 0x%lx"),
05053 abfd, dst.r_type, (long) dst.r_vaddr);
05054 bfd_set_error (bfd_error_bad_value);
05055 return FALSE;
05056 }
05057 }
05058
05059 asect->relocation = reloc_cache;
05060 return TRUE;
05061 }
05062
05063 #ifndef coff_rtype_to_howto
05064 #ifdef RTYPE2HOWTO
05065
05066
05067
05068
05069
05070
05071
05072 static reloc_howto_type *coff_rtype_to_howto
05073 PARAMS ((bfd *, asection *, struct internal_reloc *,
05074 struct coff_link_hash_entry *, struct internal_syment *,
05075 bfd_vma *));
05076
05077 static reloc_howto_type *
05078 coff_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
05079 bfd *abfd ATTRIBUTE_UNUSED;
05080 asection *sec ATTRIBUTE_UNUSED;
05081 struct internal_reloc *rel;
05082 struct coff_link_hash_entry *h ATTRIBUTE_UNUSED;
05083 struct internal_syment *sym ATTRIBUTE_UNUSED;
05084 bfd_vma *addendp ATTRIBUTE_UNUSED;
05085 {
05086 arelent genrel;
05087
05088 RTYPE2HOWTO (&genrel, rel);
05089 return genrel.howto;
05090 }
05091
05092 #else
05093
05094 #define coff_rtype_to_howto NULL
05095
05096 #endif
05097 #endif
05098
05099
05100 static long
05101 coff_canonicalize_reloc (abfd, section, relptr, symbols)
05102 bfd * abfd;
05103 sec_ptr section;
05104 arelent ** relptr;
05105 asymbol ** symbols;
05106 {
05107 arelent *tblptr = section->relocation;
05108 unsigned int count = 0;
05109
05110 if (section->flags & SEC_CONSTRUCTOR)
05111 {
05112
05113
05114
05115 arelent_chain *chain = section->constructor_chain;
05116
05117 for (count = 0; count < section->reloc_count; count++)
05118 {
05119 *relptr++ = &chain->relent;
05120 chain = chain->next;
05121 }
05122 }
05123 else
05124 {
05125 if (! coff_slurp_reloc_table (abfd, section, symbols))
05126 return -1;
05127
05128 tblptr = section->relocation;
05129
05130 for (; count++ < section->reloc_count;)
05131 *relptr++ = tblptr++;
05132 }
05133 *relptr = 0;
05134 return section->reloc_count;
05135 }
05136
05137 #ifndef coff_reloc16_estimate
05138 #define coff_reloc16_estimate dummy_reloc16_estimate
05139
05140 static int dummy_reloc16_estimate
05141 PARAMS ((bfd *, asection *, arelent *, unsigned int,
05142 struct bfd_link_info *));
05143
05144 static int
05145 dummy_reloc16_estimate (abfd, input_section, reloc, shrink, link_info)
05146 bfd *abfd ATTRIBUTE_UNUSED;
05147 asection *input_section ATTRIBUTE_UNUSED;
05148 arelent *reloc ATTRIBUTE_UNUSED;
05149 unsigned int shrink ATTRIBUTE_UNUSED;
05150 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
05151 {
05152 abort ();
05153 return 0;
05154 }
05155
05156 #endif
05157
05158 #ifndef coff_reloc16_extra_cases
05159
05160 #define coff_reloc16_extra_cases dummy_reloc16_extra_cases
05161
05162
05163
05164 static void dummy_reloc16_extra_cases
05165 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
05166 bfd_byte *, unsigned int *, unsigned int *));
05167
05168 static void
05169 dummy_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
05170 dst_ptr)
05171 bfd *abfd ATTRIBUTE_UNUSED;
05172 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
05173 struct bfd_link_order *link_order ATTRIBUTE_UNUSED;
05174 arelent *reloc ATTRIBUTE_UNUSED;
05175 bfd_byte *data ATTRIBUTE_UNUSED;
05176 unsigned int *src_ptr ATTRIBUTE_UNUSED;
05177 unsigned int *dst_ptr ATTRIBUTE_UNUSED;
05178 {
05179 abort ();
05180 }
05181 #endif
05182
05183 #ifndef coff_bfd_link_hash_table_free
05184 #define coff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
05185 #endif
05186
05187
05188
05189 #ifdef coff_relocate_section
05190 #ifndef coff_bfd_link_hash_table_create
05191 #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
05192 #endif
05193 #ifndef coff_bfd_link_add_symbols
05194 #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
05195 #endif
05196 #ifndef coff_bfd_final_link
05197 #define coff_bfd_final_link _bfd_coff_final_link
05198 #endif
05199 #else
05200 #define coff_relocate_section NULL
05201 #ifndef coff_bfd_link_hash_table_create
05202 #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
05203 #endif
05204 #ifndef coff_bfd_link_add_symbols
05205 #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
05206 #endif
05207 #define coff_bfd_final_link _bfd_generic_final_link
05208 #endif
05209
05210 #define coff_bfd_link_just_syms _bfd_generic_link_just_syms
05211 #define coff_bfd_link_split_section _bfd_generic_link_split_section
05212
05213 #ifndef coff_start_final_link
05214 #define coff_start_final_link NULL
05215 #endif
05216
05217 #ifndef coff_adjust_symndx
05218 #define coff_adjust_symndx NULL
05219 #endif
05220
05221 #ifndef coff_link_add_one_symbol
05222 #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
05223 #endif
05224
05225 #ifndef coff_link_output_has_begun
05226
05227 static bfd_boolean coff_link_output_has_begun
05228 PARAMS ((bfd *, struct coff_final_link_info *));
05229
05230 static bfd_boolean
05231 coff_link_output_has_begun (abfd, info)
05232 bfd * abfd;
05233 struct coff_final_link_info * info ATTRIBUTE_UNUSED;
05234 {
05235 return abfd->output_has_begun;
05236 }
05237 #endif
05238
05239 #ifndef coff_final_link_postscript
05240
05241 static bfd_boolean coff_final_link_postscript
05242 PARAMS ((bfd *, struct coff_final_link_info *));
05243
05244 static bfd_boolean
05245 coff_final_link_postscript (abfd, pfinfo)
05246 bfd * abfd ATTRIBUTE_UNUSED;
05247 struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED;
05248 {
05249 return TRUE;
05250 }
05251 #endif
05252
05253 #ifndef coff_SWAP_aux_in
05254 #define coff_SWAP_aux_in coff_swap_aux_in
05255 #endif
05256 #ifndef coff_SWAP_sym_in
05257 #define coff_SWAP_sym_in coff_swap_sym_in
05258 #endif
05259 #ifndef coff_SWAP_lineno_in
05260 #define coff_SWAP_lineno_in coff_swap_lineno_in
05261 #endif
05262 #ifndef coff_SWAP_aux_out
05263 #define coff_SWAP_aux_out coff_swap_aux_out
05264 #endif
05265 #ifndef coff_SWAP_sym_out
05266 #define coff_SWAP_sym_out coff_swap_sym_out
05267 #endif
05268 #ifndef coff_SWAP_lineno_out
05269 #define coff_SWAP_lineno_out coff_swap_lineno_out
05270 #endif
05271 #ifndef coff_SWAP_reloc_out
05272 #define coff_SWAP_reloc_out coff_swap_reloc_out
05273 #endif
05274 #ifndef coff_SWAP_filehdr_out
05275 #define coff_SWAP_filehdr_out coff_swap_filehdr_out
05276 #endif
05277 #ifndef coff_SWAP_aouthdr_out
05278 #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
05279 #endif
05280 #ifndef coff_SWAP_scnhdr_out
05281 #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
05282 #endif
05283 #ifndef coff_SWAP_reloc_in
05284 #define coff_SWAP_reloc_in coff_swap_reloc_in
05285 #endif
05286 #ifndef coff_SWAP_filehdr_in
05287 #define coff_SWAP_filehdr_in coff_swap_filehdr_in
05288 #endif
05289 #ifndef coff_SWAP_aouthdr_in
05290 #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
05291 #endif
05292 #ifndef coff_SWAP_scnhdr_in
05293 #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
05294 #endif
05295
05296 static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
05297 {
05298 coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
05299 coff_SWAP_aux_out, coff_SWAP_sym_out,
05300 coff_SWAP_lineno_out, coff_SWAP_reloc_out,
05301 coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
05302 coff_SWAP_scnhdr_out,
05303 FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
05304 #ifdef COFF_LONG_FILENAMES
05305 TRUE,
05306 #else
05307 FALSE,
05308 #endif
05309 #ifdef COFF_LONG_SECTION_NAMES
05310 TRUE,
05311 #else
05312 FALSE,
05313 #endif
05314 COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
05315 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
05316 TRUE,
05317 #else
05318 FALSE,
05319 #endif
05320 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
05321 4,
05322 #else
05323 2,
05324 #endif
05325 coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
05326 coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
05327 coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
05328 coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
05329 coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
05330 coff_classify_symbol, coff_compute_section_file_positions,
05331 coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
05332 coff_adjust_symndx, coff_link_add_one_symbol,
05333 coff_link_output_has_begun, coff_final_link_postscript
05334 };
05335
05336 #ifdef TICOFF
05337
05338 static const bfd_coff_backend_data ticoff0_swap_table =
05339 {
05340 coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
05341 coff_SWAP_aux_out, coff_SWAP_sym_out,
05342 coff_SWAP_lineno_out, coff_SWAP_reloc_out,
05343 coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
05344 coff_SWAP_scnhdr_out,
05345 FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
05346 #ifdef COFF_LONG_FILENAMES
05347 TRUE,
05348 #else
05349 FALSE,
05350 #endif
05351 #ifdef COFF_LONG_SECTION_NAMES
05352 TRUE,
05353 #else
05354 FALSE,
05355 #endif
05356 COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
05357 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
05358 TRUE,
05359 #else
05360 FALSE,
05361 #endif
05362 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
05363 4,
05364 #else
05365 2,
05366 #endif
05367 coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
05368 coff_SWAP_reloc_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
05369 coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
05370 coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
05371 coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
05372 coff_classify_symbol, coff_compute_section_file_positions,
05373 coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
05374 coff_adjust_symndx, coff_link_add_one_symbol,
05375 coff_link_output_has_begun, coff_final_link_postscript
05376 };
05377 #endif
05378
05379 #ifdef TICOFF
05380
05381 static const bfd_coff_backend_data ticoff1_swap_table =
05382 {
05383 coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
05384 coff_SWAP_aux_out, coff_SWAP_sym_out,
05385 coff_SWAP_lineno_out, coff_SWAP_reloc_out,
05386 coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
05387 coff_SWAP_scnhdr_out,
05388 FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
05389 #ifdef COFF_LONG_FILENAMES
05390 TRUE,
05391 #else
05392 FALSE,
05393 #endif
05394 #ifdef COFF_LONG_SECTION_NAMES
05395 TRUE,
05396 #else
05397 FALSE,
05398 #endif
05399 COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
05400 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
05401 TRUE,
05402 #else
05403 FALSE,
05404 #endif
05405 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
05406 4,
05407 #else
05408 2,
05409 #endif
05410 coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
05411 coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
05412 coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
05413 coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
05414 coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
05415 coff_classify_symbol, coff_compute_section_file_positions,
05416 coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
05417 coff_adjust_symndx, coff_link_add_one_symbol,
05418 coff_link_output_has_begun, coff_final_link_postscript
05419 };
05420 #endif
05421
05422 #ifndef coff_close_and_cleanup
05423 #define coff_close_and_cleanup _bfd_generic_close_and_cleanup
05424 #endif
05425
05426 #ifndef coff_bfd_free_cached_info
05427 #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
05428 #endif
05429
05430 #ifndef coff_get_section_contents
05431 #define coff_get_section_contents _bfd_generic_get_section_contents
05432 #endif
05433
05434 #ifndef coff_bfd_copy_private_symbol_data
05435 #define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
05436 #endif
05437
05438 #ifndef coff_bfd_copy_private_header_data
05439 #define coff_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
05440 #endif
05441
05442 #ifndef coff_bfd_copy_private_section_data
05443 #define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
05444 #endif
05445
05446 #ifndef coff_bfd_copy_private_bfd_data
05447 #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
05448 #endif
05449
05450 #ifndef coff_bfd_merge_private_bfd_data
05451 #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
05452 #endif
05453
05454 #ifndef coff_bfd_set_private_flags
05455 #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
05456 #endif
05457
05458 #ifndef coff_bfd_print_private_bfd_data
05459 #define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
05460 #endif
05461
05462 #ifndef coff_bfd_is_local_label_name
05463 #define coff_bfd_is_local_label_name _bfd_coff_is_local_label_name
05464 #endif
05465
05466 #ifndef coff_bfd_is_target_special_symbol
05467 #define coff_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
05468 #endif
05469
05470 #ifndef coff_read_minisymbols
05471 #define coff_read_minisymbols _bfd_generic_read_minisymbols
05472 #endif
05473
05474 #ifndef coff_minisymbol_to_symbol
05475 #define coff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
05476 #endif
05477
05478
05479
05480 #ifndef coff_bfd_reloc_type_lookup
05481 #define coff_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
05482 #endif
05483
05484 #ifndef coff_bfd_get_relocated_section_contents
05485 #define coff_bfd_get_relocated_section_contents \
05486 bfd_generic_get_relocated_section_contents
05487 #endif
05488
05489 #ifndef coff_bfd_relax_section
05490 #define coff_bfd_relax_section bfd_generic_relax_section
05491 #endif
05492
05493 #ifndef coff_bfd_gc_sections
05494 #define coff_bfd_gc_sections bfd_generic_gc_sections
05495 #endif
05496
05497 #ifndef coff_bfd_merge_sections
05498 #define coff_bfd_merge_sections bfd_generic_merge_sections
05499 #endif
05500
05501 #ifndef coff_bfd_is_group_section
05502 #define coff_bfd_is_group_section bfd_generic_is_group_section
05503 #endif
05504
05505 #ifndef coff_bfd_discard_group
05506 #define coff_bfd_discard_group bfd_generic_discard_group
05507 #endif
05508
05509 #ifndef coff_section_already_linked
05510 #define coff_section_already_linked \
05511 _bfd_generic_section_already_linked
05512 #endif
05513
05514 #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
05515 const bfd_target VAR = \
05516 { \
05517 NAME , \
05518 bfd_target_coff_flavour, \
05519 BFD_ENDIAN_BIG, \
05520 BFD_ENDIAN_BIG, \
05521 \
05522 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
05523 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
05524 \
05525 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
05526 UNDER, \
05527 '/', \
05528 15, \
05529 \
05530 \
05531 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
05532 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
05533 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
05534 \
05535 \
05536 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
05537 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
05538 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
05539 \
05540 \
05541 { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
05542 _bfd_dummy_target }, \
05543 \
05544 { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
05545 \
05546 { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
05547 bfd_false }, \
05548 \
05549 BFD_JUMP_TABLE_GENERIC (coff), \
05550 BFD_JUMP_TABLE_COPY (coff), \
05551 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
05552 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
05553 BFD_JUMP_TABLE_SYMBOLS (coff), \
05554 BFD_JUMP_TABLE_RELOCS (coff), \
05555 BFD_JUMP_TABLE_WRITE (coff), \
05556 BFD_JUMP_TABLE_LINK (coff), \
05557 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
05558 \
05559 ALTERNATIVE, \
05560 \
05561 SWAP_TABLE \
05562 };
05563
05564 #define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
05565 const bfd_target VAR = \
05566 { \
05567 NAME , \
05568 bfd_target_coff_flavour, \
05569 BFD_ENDIAN_LITTLE, \
05570 BFD_ENDIAN_BIG, \
05571 \
05572 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
05573 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
05574 \
05575 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
05576 UNDER, \
05577 '/', \
05578 15, \
05579 \
05580 \
05581 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
05582 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
05583 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
05584 \
05585 \
05586 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
05587 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
05588 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
05589 \
05590 \
05591 { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
05592 _bfd_dummy_target }, \
05593 \
05594 { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
05595 \
05596 { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
05597 bfd_false }, \
05598 \
05599 BFD_JUMP_TABLE_GENERIC (coff), \
05600 BFD_JUMP_TABLE_COPY (coff), \
05601 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
05602 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
05603 BFD_JUMP_TABLE_SYMBOLS (coff), \
05604 BFD_JUMP_TABLE_RELOCS (coff), \
05605 BFD_JUMP_TABLE_WRITE (coff), \
05606 BFD_JUMP_TABLE_LINK (coff), \
05607 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
05608 \
05609 ALTERNATIVE, \
05610 \
05611 SWAP_TABLE \
05612 };
05613
05614 #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
05615 const bfd_target VAR = \
05616 { \
05617 NAME , \
05618 bfd_target_coff_flavour, \
05619 BFD_ENDIAN_LITTLE, \
05620 BFD_ENDIAN_LITTLE, \
05621 \
05622 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
05623 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
05624 \
05625 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
05626 UNDER, \
05627 '/', \
05628 15, \
05629 \
05630 \
05631 bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
05632 bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
05633 bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
05634 \
05635 bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
05636 bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
05637 bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
05638 \
05639 { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
05640 _bfd_dummy_target }, \
05641 \
05642 { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
05643 \
05644 { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
05645 bfd_false }, \
05646 \
05647 BFD_JUMP_TABLE_GENERIC (coff), \
05648 BFD_JUMP_TABLE_COPY (coff), \
05649 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
05650 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
05651 BFD_JUMP_TABLE_SYMBOLS (coff), \
05652 BFD_JUMP_TABLE_RELOCS (coff), \
05653 BFD_JUMP_TABLE_WRITE (coff), \
05654 BFD_JUMP_TABLE_LINK (coff), \
05655 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
05656 \
05657 ALTERNATIVE, \
05658 \
05659 SWAP_TABLE \
05660 };