Back to index

cell-binutils  2.17cvs20070401
coffcode.h
Go to the documentation of this file.
00001 /* Support for the generic parts of most COFF variants, for BFD.
00002    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
00003    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00004    Free Software Foundation, Inc.
00005    Written by Cygnus Support.
00006 
00007    This file is part of BFD, the Binary File Descriptor library.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00022 
00023 /* Most of this hacked by  Steve Chamberlain,
00024                      sac@cygnus.com.  */
00025 /*
00026 SECTION
00027        coff backends
00028 
00029        BFD supports a number of different flavours of coff format.
00030        The major differences between formats are the sizes and
00031        alignments of fields in structures on disk, and the occasional
00032        extra field.
00033 
00034        Coff in all its varieties is implemented with a few common
00035        files and a number of implementation specific files. For
00036        example, The 88k bcs coff format is implemented in the file
00037        @file{coff-m88k.c}. This file @code{#include}s
00038        @file{coff/m88k.h} which defines the external structure of the
00039        coff format for the 88k, and @file{coff/internal.h} which
00040        defines the internal structure. @file{coff-m88k.c} also
00041        defines the relocations used by the 88k format
00042        @xref{Relocations}.
00043 
00044        The Intel i960 processor version of coff is implemented in
00045        @file{coff-i960.c}. This file has the same structure as
00046        @file{coff-m88k.c}, except that it includes @file{coff/i960.h}
00047        rather than @file{coff-m88k.h}.
00048 
00049 SUBSECTION
00050        Porting to a new version of coff
00051 
00052        The recommended method is to select from the existing
00053        implementations the version of coff which is most like the one
00054        you want to use.  For example, we'll say that i386 coff is
00055        the one you select, and that your coff flavour is called foo.
00056        Copy @file{i386coff.c} to @file{foocoff.c}, copy
00057        @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
00058        and add the lines to @file{targets.c} and @file{Makefile.in}
00059        so that your new back end is used. Alter the shapes of the
00060        structures in @file{../include/coff/foo.h} so that they match
00061        what you need. You will probably also have to add
00062        @code{#ifdef}s to the code in @file{coff/internal.h} and
00063        @file{coffcode.h} if your version of coff is too wild.
00064 
00065        You can verify that your new BFD backend works quite simply by
00066        building @file{objdump} from the @file{binutils} directory,
00067        and making sure that its version of what's going on and your
00068        host system's idea (assuming it has the pretty standard coff
00069        dump utility, usually called @code{att-dump} or just
00070        @code{dump}) are the same.  Then clean up your code, and send
00071        what you've done to Cygnus. Then your stuff will be in the
00072        next release, and you won't have to keep integrating it.
00073 
00074 SUBSECTION
00075        How the coff backend works
00076 
00077 SUBSUBSECTION
00078        File layout
00079 
00080        The Coff backend is split into generic routines that are
00081        applicable to any Coff target and routines that are specific
00082        to a particular target.  The target-specific routines are
00083        further split into ones which are basically the same for all
00084        Coff targets except that they use the external symbol format
00085        or use different values for certain constants.
00086 
00087        The generic routines are in @file{coffgen.c}.  These routines
00088        work for any Coff target.  They use some hooks into the target
00089        specific code; the hooks are in a @code{bfd_coff_backend_data}
00090        structure, one of which exists for each target.
00091 
00092        The essentially similar target-specific routines are in
00093        @file{coffcode.h}.  This header file includes executable C code.
00094        The various Coff targets first include the appropriate Coff
00095        header file, make any special defines that are needed, and
00096        then include @file{coffcode.h}.
00097 
00098        Some of the Coff targets then also have additional routines in
00099        the target source file itself.
00100 
00101        For example, @file{coff-i960.c} includes
00102        @file{coff/internal.h} and @file{coff/i960.h}.  It then
00103        defines a few constants, such as @code{I960}, and includes
00104        @file{coffcode.h}.  Since the i960 has complex relocation
00105        types, @file{coff-i960.c} also includes some code to
00106        manipulate the i960 relocs.  This code is not in
00107        @file{coffcode.h} because it would not be used by any other
00108        target.
00109 
00110 SUBSUBSECTION
00111        Bit twiddling
00112 
00113        Each flavour of coff supported in BFD has its own header file
00114        describing the external layout of the structures. There is also
00115        an internal description of the coff layout, in
00116        @file{coff/internal.h}. A major function of the
00117        coff backend is swapping the bytes and twiddling the bits to
00118        translate the external form of the structures into the normal
00119        internal form. This is all performed in the
00120        @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
00121        elements are different sizes between different versions of
00122        coff; it is the duty of the coff version specific include file
00123        to override the definitions of various packing routines in
00124        @file{coffcode.h}. E.g., the size of line number entry in coff is
00125        sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
00126        @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
00127        correct one. No doubt, some day someone will find a version of
00128        coff which has a varying field size not catered to at the
00129        moment. To port BFD, that person will have to add more @code{#defines}.
00130        Three of the bit twiddling routines are exported to
00131        @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
00132        and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
00133        table on its own, but uses BFD to fix things up.  More of the
00134        bit twiddlers are exported for @code{gas};
00135        @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
00136        @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
00137        @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
00138        @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
00139        of all the symbol table and reloc drudgery itself, thereby
00140        saving the internal BFD overhead, but uses BFD to swap things
00141        on the way out, making cross ports much safer.  Doing so also
00142        allows BFD (and thus the linker) to use the same header files
00143        as @code{gas}, which makes one avenue to disaster disappear.
00144 
00145 SUBSUBSECTION
00146        Symbol reading
00147 
00148        The simple canonical form for symbols used by BFD is not rich
00149        enough to keep all the information available in a coff symbol
00150        table. The back end gets around this problem by keeping the original
00151        symbol table around, "behind the scenes".
00152 
00153        When a symbol table is requested (through a call to
00154        @code{bfd_canonicalize_symtab}), a request gets through to
00155        @code{coff_get_normalized_symtab}. This reads the symbol table from
00156        the coff file and swaps all the structures inside into the
00157        internal form. It also fixes up all the pointers in the table
00158        (represented in the file by offsets from the first symbol in
00159        the table) into physical pointers to elements in the new
00160        internal table. This involves some work since the meanings of
00161        fields change depending upon context: a field that is a
00162        pointer to another structure in the symbol table at one moment
00163        may be the size in bytes of a structure at the next.  Another
00164        pass is made over the table. All symbols which mark file names
00165        (<<C_FILE>> symbols) are modified so that the internal
00166        string points to the value in the auxent (the real filename)
00167        rather than the normal text associated with the symbol
00168        (@code{".file"}).
00169 
00170        At this time the symbol names are moved around. Coff stores
00171        all symbols less than nine characters long physically
00172        within the symbol table; longer strings are kept at the end of
00173        the file in the string      table. This pass moves all strings
00174        into memory and replaces them with pointers to the strings.
00175 
00176        The symbol table is massaged once again, this time to create
00177        the canonical table used by the BFD application. Each symbol
00178        is inspected in turn, and a decision made (using the
00179        @code{sclass} field) about the various flags to set in the
00180        @code{asymbol}.  @xref{Symbols}. The generated canonical table
00181        shares strings with the hidden internal symbol table.
00182 
00183        Any linenumbers are read from the coff file too, and attached
00184        to the symbols which own the functions the linenumbers belong to.
00185 
00186 SUBSUBSECTION
00187        Symbol writing
00188 
00189        Writing a symbol to a coff file which didn't come from a coff
00190        file will lose any debugging information. The @code{asymbol}
00191        structure remembers the BFD from which the symbol was taken, and on
00192        output the back end makes sure that the same destination target as
00193        source target is present.
00194 
00195        When the symbols have come from a coff file then all the
00196        debugging information is preserved.
00197 
00198        Symbol tables are provided for writing to the back end in a
00199        vector of pointers to pointers. This allows applications like
00200        the linker to accumulate and output large symbol tables
00201        without having to do too much byte copying.
00202 
00203        This function runs through the provided symbol table and
00204        patches each symbol marked as a file place holder
00205        (@code{C_FILE}) to point to the next file place holder in the
00206        list. It also marks each @code{offset} field in the list with
00207        the offset from the first symbol of the current symbol.
00208 
00209        Another function of this procedure is to turn the canonical
00210        value form of BFD into the form used by coff. Internally, BFD
00211        expects symbol values to be offsets from a section base; so a
00212        symbol physically at 0x120, but in a section starting at
00213        0x100, would have the value 0x20. Coff expects symbols to
00214        contain their final value, so symbols have their values
00215        changed at this point to reflect their sum with their owning
00216        section.  This transformation uses the
00217        <<output_section>> field of the @code{asymbol}'s
00218        @code{asection} @xref{Sections}.
00219 
00220        o <<coff_mangle_symbols>>
00221 
00222        This routine runs though the provided symbol table and uses
00223        the offsets generated by the previous pass and the pointers
00224        generated when the symbol table was read in to create the
00225        structured hierarchy required by coff. It changes each pointer
00226        to a symbol into the index into the symbol table of the asymbol.
00227 
00228        o <<coff_write_symbols>>
00229 
00230        This routine runs through the symbol table and patches up the
00231        symbols from their internal form into the coff way, calls the
00232        bit twiddlers, and writes out the table to the file.
00233 
00234 */
00235 
00236 /*
00237 INTERNAL_DEFINITION
00238        coff_symbol_type
00239 
00240 DESCRIPTION
00241        The hidden information for an <<asymbol>> is described in a
00242        <<combined_entry_type>>:
00243 
00244 CODE_FRAGMENT
00245 .
00246 .typedef struct coff_ptr_struct
00247 .{
00248 .  {* Remembers the offset from the first symbol in the file for
00249 .     this symbol. Generated by coff_renumber_symbols. *}
00250 .  unsigned int offset;
00251 .
00252 .  {* Should the value of this symbol be renumbered.  Used for
00253 .     XCOFF C_BSTAT symbols.  Set by coff_slurp_symbol_table.  *}
00254 .  unsigned int fix_value : 1;
00255 .
00256 .  {* Should the tag field of this symbol be renumbered.
00257 .     Created by coff_pointerize_aux. *}
00258 .  unsigned int fix_tag : 1;
00259 .
00260 .  {* Should the endidx field of this symbol be renumbered.
00261 .     Created by coff_pointerize_aux. *}
00262 .  unsigned int fix_end : 1;
00263 .
00264 .  {* Should the x_csect.x_scnlen field be renumbered.
00265 .     Created by coff_pointerize_aux. *}
00266 .  unsigned int fix_scnlen : 1;
00267 .
00268 .  {* Fix up an XCOFF C_BINCL/C_EINCL symbol.  The value is the
00269 .     index into the line number entries.  Set by coff_slurp_symbol_table.  *}
00270 .  unsigned int fix_line : 1;
00271 .
00272 .  {* The container for the symbol structure as read and translated
00273 .     from the file. *}
00274 .  union
00275 .  {
00276 .    union internal_auxent auxent;
00277 .    struct internal_syment syment;
00278 .  } u;
00279 .} combined_entry_type;
00280 .
00281 .
00282 .{* Each canonical asymbol really looks like this: *}
00283 .
00284 .typedef struct coff_symbol_struct
00285 .{
00286 .  {* The actual symbol which the rest of BFD works with *}
00287 .  asymbol symbol;
00288 .
00289 .  {* A pointer to the hidden information for this symbol *}
00290 .  combined_entry_type *native;
00291 .
00292 .  {* A pointer to the linenumber information for this symbol *}
00293 .  struct lineno_cache_entry *lineno;
00294 .
00295 .  {* Have the line numbers been relocated yet ? *}
00296 .  bfd_boolean done_lineno;
00297 .} coff_symbol_type;
00298 
00299 */
00300 
00301 #ifdef COFF_WITH_PE
00302 #include "peicode.h"
00303 #else
00304 #include "coffswap.h"
00305 #endif
00306 
00307 #define STRING_SIZE_SIZE 4
00308 
00309 #define DOT_DEBUG    ".debug"
00310 #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
00311 
00312 static long sec_to_styp_flags
00313   (const char *, flagword);
00314 static bfd_boolean styp_to_sec_flags
00315   (bfd *, void *, const char *, asection *, flagword *);
00316 static bfd_boolean coff_bad_format_hook
00317   (bfd *, void *);
00318 static void coff_set_custom_section_alignment
00319   (bfd *, asection *, const struct coff_section_alignment_entry *,
00320    const unsigned int);
00321 static bfd_boolean coff_new_section_hook
00322   (bfd *, asection *);
00323 static bfd_boolean coff_set_arch_mach_hook
00324   (bfd *, void *);
00325 static bfd_boolean coff_write_relocs
00326   (bfd *, int);
00327 static bfd_boolean coff_set_flags
00328   (bfd *, unsigned int *, unsigned short *);
00329 static bfd_boolean coff_set_arch_mach
00330   (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_UNUSED;
00331 static bfd_boolean coff_compute_section_file_positions
00332   (bfd *);
00333 static bfd_boolean coff_write_object_contents
00334   (bfd *) ATTRIBUTE_UNUSED;
00335 static bfd_boolean coff_set_section_contents
00336   (bfd *, asection *, const void *, file_ptr, bfd_size_type);
00337 static void * buy_and_read
00338   (bfd *, file_ptr, bfd_size_type);
00339 static bfd_boolean coff_slurp_line_table
00340   (bfd *, asection *);
00341 static bfd_boolean coff_slurp_symbol_table
00342   (bfd *);
00343 static enum coff_symbol_classification coff_classify_symbol
00344   (bfd *, struct internal_syment *);
00345 static bfd_boolean coff_slurp_reloc_table
00346   (bfd *, asection *, asymbol **);
00347 static long coff_canonicalize_reloc
00348   (bfd *, asection *, arelent **, asymbol **);
00349 #ifndef coff_mkobject_hook
00350 static void * coff_mkobject_hook
00351   (bfd *, void *,  void *);
00352 #endif
00353 #ifdef COFF_WITH_PE
00354 static flagword handle_COMDAT
00355   (bfd *, flagword, void *, const char *, asection *);
00356 #endif
00357 #ifdef COFF_IMAGE_WITH_PE
00358 static bfd_boolean coff_read_word
00359   (bfd *, unsigned int *);
00360 static unsigned int coff_compute_checksum
00361   (bfd *);
00362 static bfd_boolean coff_apply_checksum
00363   (bfd *);
00364 #endif
00365 #ifdef TICOFF
00366 static bfd_boolean ticoff0_bad_format_hook
00367   (bfd *, void * );
00368 static bfd_boolean ticoff1_bad_format_hook
00369   (bfd *, void * );
00370 #endif
00371 
00372 /* void warning(); */
00373 
00374 /* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
00375    the incoming SEC_* flags.  The inverse of this function is
00376    styp_to_sec_flags().  NOTE: If you add to/change this routine, you
00377    should probably mirror the changes in styp_to_sec_flags().  */
00378 
00379 #ifndef COFF_WITH_PE
00380 
00381 /* Macros for setting debugging flags.  */
00382 
00383 #ifdef STYP_DEBUG
00384 #define STYP_XCOFF_DEBUG STYP_DEBUG
00385 #else
00386 #define STYP_XCOFF_DEBUG STYP_INFO
00387 #endif
00388 
00389 #ifdef COFF_ALIGN_IN_S_FLAGS
00390 #define STYP_DEBUG_INFO STYP_DSECT
00391 #else
00392 #define STYP_DEBUG_INFO STYP_INFO
00393 #endif
00394 
00395 static long
00396 sec_to_styp_flags (const char *sec_name, flagword sec_flags)
00397 {
00398   long styp_flags = 0;
00399 
00400   if (!strcmp (sec_name, _TEXT))
00401     {
00402       styp_flags = STYP_TEXT;
00403     }
00404   else if (!strcmp (sec_name, _DATA))
00405     {
00406       styp_flags = STYP_DATA;
00407     }
00408   else if (!strcmp (sec_name, _BSS))
00409     {
00410       styp_flags = STYP_BSS;
00411 #ifdef _COMMENT
00412     }
00413   else if (!strcmp (sec_name, _COMMENT))
00414     {
00415       styp_flags = STYP_INFO;
00416 #endif /* _COMMENT */
00417 #ifdef _LIB
00418     }
00419   else if (!strcmp (sec_name, _LIB))
00420     {
00421       styp_flags = STYP_LIB;
00422 #endif /* _LIB */
00423 #ifdef _LIT
00424     }
00425   else if (!strcmp (sec_name, _LIT))
00426     {
00427       styp_flags = STYP_LIT;
00428 #endif /* _LIT */
00429     }
00430   else if (CONST_STRNEQ (sec_name, DOT_DEBUG))
00431     {
00432       /* Handle the XCOFF debug section and DWARF2 debug sections.  */
00433       if (!sec_name[6])
00434         styp_flags = STYP_XCOFF_DEBUG;
00435       else
00436         styp_flags = STYP_DEBUG_INFO;
00437     }
00438   else if (CONST_STRNEQ (sec_name, ".stab"))
00439     {
00440       styp_flags = STYP_DEBUG_INFO;
00441     }
00442 #ifdef COFF_LONG_SECTION_NAMES
00443   else if (CONST_STRNEQ (sec_name, GNU_LINKONCE_WI))
00444     {
00445       styp_flags = STYP_DEBUG_INFO;
00446     }
00447 #endif
00448 #ifdef RS6000COFF_C
00449   else if (!strcmp (sec_name, _PAD))
00450     {
00451       styp_flags = STYP_PAD;
00452     }
00453   else if (!strcmp (sec_name, _LOADER))
00454     {
00455       styp_flags = STYP_LOADER;
00456     }
00457   else if (!strcmp (sec_name, _EXCEPT))
00458     {
00459       styp_flags = STYP_EXCEPT;
00460     }
00461   else if (!strcmp (sec_name, _TYPCHK))
00462     {
00463       styp_flags = STYP_TYPCHK;
00464     }
00465 #endif
00466   /* Try and figure out what it should be */
00467   else if (sec_flags & SEC_CODE)
00468     {
00469       styp_flags = STYP_TEXT;
00470     }
00471   else if (sec_flags & SEC_DATA)
00472     {
00473       styp_flags = STYP_DATA;
00474     }
00475   else if (sec_flags & SEC_READONLY)
00476     {
00477 #ifdef STYP_LIT                    /* 29k readonly text/data section */
00478       styp_flags = STYP_LIT;
00479 #else
00480       styp_flags = STYP_TEXT;
00481 #endif /* STYP_LIT */
00482     }
00483   else if (sec_flags & SEC_LOAD)
00484     {
00485       styp_flags = STYP_TEXT;
00486     }
00487   else if (sec_flags & SEC_ALLOC)
00488     {
00489       styp_flags = STYP_BSS;
00490     }
00491 
00492 #ifdef STYP_CLINK
00493   if (sec_flags & SEC_TIC54X_CLINK)
00494     styp_flags |= STYP_CLINK;
00495 #endif
00496 
00497 #ifdef STYP_BLOCK
00498   if (sec_flags & SEC_TIC54X_BLOCK)
00499     styp_flags |= STYP_BLOCK;
00500 #endif
00501 
00502 #ifdef STYP_NOLOAD
00503   if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
00504     styp_flags |= STYP_NOLOAD;
00505 #endif
00506 
00507   return styp_flags;
00508 }
00509 
00510 #else /* COFF_WITH_PE */
00511 
00512 /* The PE version; see above for the general comments.  The non-PE
00513    case seems to be more guessing, and breaks PE format; specifically,
00514    .rdata is readonly, but it sure ain't text.  Really, all this
00515    should be set up properly in gas (or whatever assembler is in use),
00516    and honor whatever objcopy/strip, etc. sent us as input.  */
00517 
00518 static long
00519 sec_to_styp_flags (const char *sec_name, flagword sec_flags)
00520 {
00521   long styp_flags = 0;
00522 
00523   /* caution: there are at least three groups of symbols that have
00524      very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
00525      SEC_* are the BFD internal flags, used for generic BFD
00526      information.  STYP_* are the COFF section flags which appear in
00527      COFF files.  IMAGE_SCN_* are the PE section flags which appear in
00528      PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
00529      but there are more IMAGE_SCN_* flags.  */
00530 
00531   /* FIXME: There is no gas syntax to specify the debug section flag.  */
00532   if (CONST_STRNEQ (sec_name, DOT_DEBUG)
00533       || CONST_STRNEQ (sec_name, GNU_LINKONCE_WI))
00534     sec_flags = SEC_DEBUGGING;
00535 
00536   /* skip LOAD */
00537   /* READONLY later */
00538   /* skip RELOC */
00539   if ((sec_flags & SEC_CODE) != 0)
00540     styp_flags |= IMAGE_SCN_CNT_CODE;
00541   if ((sec_flags & SEC_DATA) != 0)
00542     styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
00543   if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
00544     styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
00545   /* skip ROM */
00546   /* skip constRUCTOR */
00547   /* skip CONTENTS */
00548   if ((sec_flags & SEC_IS_COMMON) != 0)
00549     styp_flags |= IMAGE_SCN_LNK_COMDAT;
00550   if ((sec_flags & SEC_DEBUGGING) != 0)
00551     styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
00552   if ((sec_flags & SEC_EXCLUDE) != 0)
00553     styp_flags |= IMAGE_SCN_LNK_REMOVE;
00554   if ((sec_flags & SEC_NEVER_LOAD) != 0)
00555     styp_flags |= IMAGE_SCN_LNK_REMOVE;
00556   /* skip IN_MEMORY */
00557   /* skip SORT */
00558   if (sec_flags & SEC_LINK_ONCE)
00559     styp_flags |= IMAGE_SCN_LNK_COMDAT;
00560   /* skip LINK_DUPLICATES */
00561   /* skip LINKER_CREATED */
00562 
00563   if (sec_flags & (SEC_ALLOC | SEC_LOAD))
00564     {
00565       /* For now, the read/write bits are mapped onto SEC_READONLY, even
00566         though the semantics don't quite match.  The bits from the input
00567         are retained in pei_section_data(abfd, section)->pe_flags.  */
00568       styp_flags |= IMAGE_SCN_MEM_READ;       /* Always readable.  */
00569       if ((sec_flags & SEC_READONLY) == 0)
00570        styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
00571       if (sec_flags & SEC_CODE)
00572        styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
00573       if (sec_flags & SEC_COFF_SHARED)
00574        styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
00575     }
00576 
00577   return styp_flags;
00578 }
00579 
00580 #endif /* COFF_WITH_PE */
00581 
00582 /* Return a word with SEC_* flags set to represent the incoming STYP_*
00583    flags (from scnhdr.s_flags).  The inverse of this function is
00584    sec_to_styp_flags().  NOTE: If you add to/change this routine, you
00585    should probably mirror the changes in sec_to_styp_flags().  */
00586 
00587 #ifndef COFF_WITH_PE
00588 
00589 static bfd_boolean
00590 styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
00591                  void * hdr,
00592                  const char *name,
00593                  asection *section ATTRIBUTE_UNUSED,
00594                  flagword *flags_ptr)
00595 {
00596   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
00597   long styp_flags = internal_s->s_flags;
00598   flagword sec_flags = 0;
00599 
00600 #ifdef STYP_BLOCK
00601   if (styp_flags & STYP_BLOCK)
00602     sec_flags |= SEC_TIC54X_BLOCK;
00603 #endif
00604 
00605 #ifdef STYP_CLINK
00606   if (styp_flags & STYP_CLINK)
00607     sec_flags |= SEC_TIC54X_CLINK;
00608 #endif
00609 
00610 #ifdef STYP_NOLOAD
00611   if (styp_flags & STYP_NOLOAD)
00612     sec_flags |= SEC_NEVER_LOAD;
00613 #endif /* STYP_NOLOAD */
00614 
00615   /* For 386 COFF, at least, an unloadable text or data section is
00616      actually a shared library section.  */
00617   if (styp_flags & STYP_TEXT)
00618     {
00619       if (sec_flags & SEC_NEVER_LOAD)
00620        sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
00621       else
00622        sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
00623     }
00624   else if (styp_flags & STYP_DATA)
00625     {
00626       if (sec_flags & SEC_NEVER_LOAD)
00627        sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
00628       else
00629        sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
00630     }
00631   else if (styp_flags & STYP_BSS)
00632     {
00633 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
00634       if (sec_flags & SEC_NEVER_LOAD)
00635        sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
00636       else
00637 #endif
00638        sec_flags |= SEC_ALLOC;
00639     }
00640   else if (styp_flags & STYP_INFO)
00641     {
00642       /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
00643         defined.  coff_compute_section_file_positions uses
00644         COFF_PAGE_SIZE to ensure that the low order bits of the
00645         section VMA and the file offset match.  If we don't know
00646         COFF_PAGE_SIZE, we can't ensure the correct correspondence,
00647         and demand page loading of the file will fail.  */
00648 #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
00649       sec_flags |= SEC_DEBUGGING;
00650 #endif
00651     }
00652   else if (styp_flags & STYP_PAD)
00653     sec_flags = 0;
00654   else if (strcmp (name, _TEXT) == 0)
00655     {
00656       if (sec_flags & SEC_NEVER_LOAD)
00657        sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
00658       else
00659        sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
00660     }
00661   else if (strcmp (name, _DATA) == 0)
00662     {
00663       if (sec_flags & SEC_NEVER_LOAD)
00664        sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
00665       else
00666        sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
00667     }
00668   else if (strcmp (name, _BSS) == 0)
00669     {
00670 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
00671       if (sec_flags & SEC_NEVER_LOAD)
00672        sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
00673       else
00674 #endif
00675        sec_flags |= SEC_ALLOC;
00676     }
00677   else if (CONST_STRNEQ (name, DOT_DEBUG)
00678 #ifdef _COMMENT
00679           || strcmp (name, _COMMENT) == 0
00680 #endif
00681 #ifdef COFF_LONG_SECTION_NAMES
00682           || CONST_STRNEQ (name, GNU_LINKONCE_WI)
00683 #endif
00684           || CONST_STRNEQ (name, ".stab"))
00685     {
00686 #ifdef COFF_PAGE_SIZE
00687       sec_flags |= SEC_DEBUGGING;
00688 #endif
00689     }
00690 #ifdef _LIB
00691   else if (strcmp (name, _LIB) == 0)
00692     ;
00693 #endif
00694 #ifdef _LIT
00695   else if (strcmp (name, _LIT) == 0)
00696     sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
00697 #endif
00698   else
00699     sec_flags |= SEC_ALLOC | SEC_LOAD;
00700 
00701 #ifdef STYP_LIT                    /* A29k readonly text/data section type.  */
00702   if ((styp_flags & STYP_LIT) == STYP_LIT)
00703     sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
00704 #endif /* STYP_LIT */
00705 
00706 #ifdef STYP_OTHER_LOAD             /* Other loaded sections.  */
00707   if (styp_flags & STYP_OTHER_LOAD)
00708     sec_flags = (SEC_LOAD | SEC_ALLOC);
00709 #endif /* STYP_SDATA */
00710 
00711 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
00712   /* As a GNU extension, if the name begins with .gnu.linkonce, we
00713      only link a single copy of the section.  This is used to support
00714      g++.  g++ will emit each template expansion in its own section.
00715      The symbols will be defined as weak, so that multiple definitions
00716      are permitted.  The GNU linker extension is to actually discard
00717      all but one of the sections.  */
00718   if (CONST_STRNEQ (name, ".gnu.linkonce"))
00719     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
00720 #endif
00721 
00722   if (flags_ptr == NULL)
00723     return FALSE;
00724 
00725   * flags_ptr = sec_flags;
00726   return TRUE;
00727 }
00728 
00729 #else /* COFF_WITH_PE */
00730 
00731 static flagword
00732 handle_COMDAT (bfd * abfd,
00733               flagword sec_flags,
00734               void * hdr,
00735               const char *name,
00736               asection *section)
00737 {
00738   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
00739   bfd_byte *esymstart, *esym, *esymend;
00740   int seen_state = 0;
00741   char *target_name = NULL;
00742 
00743   sec_flags |= SEC_LINK_ONCE;
00744 
00745   /* Unfortunately, the PE format stores essential information in
00746      the symbol table, of all places.  We need to extract that
00747      information now, so that objdump and the linker will know how
00748      to handle the section without worrying about the symbols.  We
00749      can't call slurp_symtab, because the linker doesn't want the
00750      swapped symbols.  */
00751 
00752   /* COMDAT sections are special.  The first symbol is the section
00753      symbol, which tells what kind of COMDAT section it is.  The
00754      second symbol is the "comdat symbol" - the one with the
00755      unique name.  GNU uses the section symbol for the unique
00756      name; MS uses ".text" for every comdat section.  Sigh.  - DJ */
00757 
00758   /* This is not mirrored in sec_to_styp_flags(), but there
00759      doesn't seem to be a need to, either, and it would at best be
00760      rather messy.  */
00761 
00762   if (! _bfd_coff_get_external_symbols (abfd))
00763     return sec_flags;
00764 
00765   esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
00766   esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
00767 
00768   while (esym < esymend)
00769     {
00770       struct internal_syment isym;
00771       char buf[SYMNMLEN + 1];
00772       const char *symname;
00773 
00774       bfd_coff_swap_sym_in (abfd, esym, & isym);
00775 
00776       if (sizeof (internal_s->s_name) > SYMNMLEN)
00777        {
00778          /* This case implies that the matching
00779             symbol name will be in the string table.  */
00780          abort ();
00781        }
00782 
00783       if (isym.n_scnum == section->target_index)
00784        {
00785          /* According to the MSVC documentation, the first
00786             TWO entries with the section # are both of
00787             interest to us.  The first one is the "section
00788             symbol" (section name).  The second is the comdat
00789             symbol name.  Here, we've found the first
00790             qualifying entry; we distinguish it from the
00791             second with a state flag.
00792 
00793             In the case of gas-generated (at least until that
00794             is fixed) .o files, it isn't necessarily the
00795             second one.  It may be some other later symbol.
00796 
00797             Since gas also doesn't follow MS conventions and
00798             emits the section similar to .text$<name>, where
00799             <something> is the name we're looking for, we
00800             distinguish the two as follows:
00801 
00802             If the section name is simply a section name (no
00803             $) we presume it's MS-generated, and look at
00804             precisely the second symbol for the comdat name.
00805             If the section name has a $, we assume it's
00806             gas-generated, and look for <something> (whatever
00807             follows the $) as the comdat symbol.  */
00808 
00809          /* All 3 branches use this.  */
00810          symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
00811 
00812          if (symname == NULL)
00813            abort ();
00814 
00815          switch (seen_state)
00816            {
00817            case 0:
00818              {
00819               /* The first time we've seen the symbol.  */
00820               union internal_auxent aux;
00821 
00822               /* If it isn't the stuff we're expecting, die;
00823                  The MS documentation is vague, but it
00824                  appears that the second entry serves BOTH
00825                  as the comdat symbol and the defining
00826                  symbol record (either C_STAT or C_EXT,
00827                  possibly with an aux entry with debug
00828                  information if it's a function.)  It
00829                  appears the only way to find the second one
00830                  is to count.  (On Intel, they appear to be
00831                  adjacent, but on Alpha, they have been
00832                  found separated.)
00833 
00834                  Here, we think we've found the first one,
00835                  but there's some checking we can do to be
00836                  sure.  */
00837 
00838               if (! (isym.n_sclass == C_STAT
00839                      && isym.n_type == T_NULL
00840                      && isym.n_value == 0))
00841                 abort ();
00842 
00843               /* FIXME LATER: MSVC generates section names
00844                  like .text for comdats.  Gas generates
00845                  names like .text$foo__Fv (in the case of a
00846                  function).  See comment above for more.  */
00847 
00848               if (strcmp (name, symname) != 0)
00849                 _bfd_error_handler (_("%B: warning: COMDAT symbol '%s' does not match section name '%s'"),
00850                                   abfd, symname, name);
00851 
00852               seen_state = 1;
00853 
00854               /* This is the section symbol.  */
00855               bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
00856                                   isym.n_type, isym.n_sclass,
00857                                   0, isym.n_numaux, & aux);
00858 
00859               target_name = strchr (name, '$');
00860               if (target_name != NULL)
00861                 {
00862                   /* Gas mode.  */
00863                   seen_state = 2;
00864                   /* Skip the `$'.  */
00865                   target_name += 1;
00866                 }
00867 
00868               /* FIXME: Microsoft uses NODUPLICATES and
00869                  ASSOCIATIVE, but gnu uses ANY and
00870                  SAME_SIZE.  Unfortunately, gnu doesn't do
00871                  the comdat symbols right.  So, until we can
00872                  fix it to do the right thing, we are
00873                  temporarily disabling comdats for the MS
00874                  types (they're used in DLLs and C++, but we
00875                  don't support *their* C++ libraries anyway
00876                  - DJ.  */
00877 
00878               /* Cygwin does not follow the MS style, and
00879                  uses ANY and SAME_SIZE where NODUPLICATES
00880                  and ASSOCIATIVE should be used.  For
00881                  Interix, we just do the right thing up
00882                  front.  */
00883 
00884               switch (aux.x_scn.x_comdat)
00885                 {
00886                 case IMAGE_COMDAT_SELECT_NODUPLICATES:
00887 #ifdef STRICT_PE_FORMAT
00888                   sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
00889 #else
00890                   sec_flags &= ~SEC_LINK_ONCE;
00891 #endif
00892                   break;
00893 
00894                 case IMAGE_COMDAT_SELECT_ANY:
00895                   sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
00896                   break;
00897 
00898                 case IMAGE_COMDAT_SELECT_SAME_SIZE:
00899                   sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
00900                   break;
00901 
00902                 case IMAGE_COMDAT_SELECT_EXACT_MATCH:
00903                   /* Not yet fully implemented ??? */
00904                   sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
00905                   break;
00906 
00907                   /* debug$S gets this case; other
00908                      implications ??? */
00909 
00910                   /* There may be no symbol... we'll search
00911                      the whole table... Is this the right
00912                      place to play this game? Or should we do
00913                      it when reading it in.  */
00914                 case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
00915 #ifdef STRICT_PE_FORMAT
00916                   /* FIXME: This is not currently implemented.  */
00917                   sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
00918 #else
00919                   sec_flags &= ~SEC_LINK_ONCE;
00920 #endif
00921                   break;
00922 
00923                 default:  /* 0 means "no symbol" */
00924                   /* debug$F gets this case; other
00925                      implications ??? */
00926                   sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
00927                   break;
00928                 }
00929              }
00930              break;
00931 
00932            case 2:
00933              /* Gas mode: the first matching on partial name.  */
00934 
00935 #ifndef TARGET_UNDERSCORE
00936 #define TARGET_UNDERSCORE 0
00937 #endif
00938              /* Is this the name we're looking for ?  */
00939              if (strcmp (target_name,
00940                        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
00941               {
00942                 /* Not the name we're looking for */
00943                 esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
00944                 continue;
00945               }
00946              /* Fall through.  */
00947            case 1:
00948              /* MSVC mode: the lexically second symbol (or
00949                drop through from the above).  */
00950              {
00951               char *newname;
00952               bfd_size_type amt;
00953 
00954               /* This must the second symbol with the
00955                  section #.  It is the actual symbol name.
00956                  Intel puts the two adjacent, but Alpha (at
00957                  least) spreads them out.  */
00958 
00959               amt = sizeof (struct coff_comdat_info);
00960               coff_section_data (abfd, section)->comdat
00961                 = bfd_alloc (abfd, amt);
00962               if (coff_section_data (abfd, section)->comdat == NULL)
00963                 abort ();
00964 
00965               coff_section_data (abfd, section)->comdat->symbol =
00966                 (esym - esymstart) / bfd_coff_symesz (abfd);
00967 
00968               amt = strlen (symname) + 1;
00969               newname = bfd_alloc (abfd, amt);
00970               if (newname == NULL)
00971                 abort ();
00972 
00973               strcpy (newname, symname);
00974               coff_section_data (abfd, section)->comdat->name
00975                 = newname;
00976              }
00977 
00978              goto breakloop;
00979            }
00980        }
00981 
00982       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
00983     }
00984 
00985  breakloop:
00986   return sec_flags;
00987 }
00988 
00989 
00990 /* The PE version; see above for the general comments.
00991 
00992    Since to set the SEC_LINK_ONCE and associated flags, we have to
00993    look at the symbol table anyway, we return the symbol table index
00994    of the symbol being used as the COMDAT symbol.  This is admittedly
00995    ugly, but there's really nowhere else that we have access to the
00996    required information.  FIXME: Is the COMDAT symbol index used for
00997    any purpose other than objdump?  */
00998 
00999 static bfd_boolean
01000 styp_to_sec_flags (bfd *abfd,
01001                  void * hdr,
01002                  const char *name,
01003                  asection *section,
01004                  flagword *flags_ptr)
01005 {
01006   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
01007   long styp_flags = internal_s->s_flags;
01008   flagword sec_flags;
01009   bfd_boolean result = TRUE;
01010 
01011   /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
01012   sec_flags = SEC_READONLY;
01013 
01014   /* Process each flag bit in styp_flags in turn.  */
01015   while (styp_flags)
01016     {
01017       long flag = styp_flags & - styp_flags;
01018       char * unhandled = NULL;
01019 
01020       styp_flags &= ~ flag;
01021 
01022       /* We infer from the distinct read/write/execute bits the settings
01023         of some of the bfd flags; the actual values, should we need them,
01024         are also in pei_section_data (abfd, section)->pe_flags.  */
01025 
01026       switch (flag)
01027        {
01028        case STYP_DSECT:
01029          unhandled = "STYP_DSECT";
01030          break;
01031        case STYP_GROUP:
01032          unhandled = "STYP_GROUP";
01033          break;
01034        case STYP_COPY:
01035          unhandled = "STYP_COPY";
01036          break;
01037        case STYP_OVER:
01038          unhandled = "STYP_OVER";
01039          break;
01040 #ifdef SEC_NEVER_LOAD
01041        case STYP_NOLOAD:
01042          sec_flags |= SEC_NEVER_LOAD;
01043          break;
01044 #endif
01045        case IMAGE_SCN_MEM_READ:
01046          /* Ignored, assume it always to be true.  */
01047          break;
01048        case IMAGE_SCN_TYPE_NO_PAD:
01049          /* Skip.  */
01050          break;
01051        case IMAGE_SCN_LNK_OTHER:
01052          unhandled = "IMAGE_SCN_LNK_OTHER";
01053          break;
01054        case IMAGE_SCN_MEM_NOT_CACHED:
01055          unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
01056          break;
01057        case IMAGE_SCN_MEM_NOT_PAGED:
01058          /* Generate a warning message rather using the 'unhandled'
01059             variable as this will allow some .sys files generate by
01060             other toolchains to be processed.  See bugzilla issue 196.  */
01061          _bfd_error_handler (_("%B: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section %s"),
01062                            abfd, name);
01063          break;
01064        case IMAGE_SCN_MEM_EXECUTE:
01065          sec_flags |= SEC_CODE;
01066          break;
01067        case IMAGE_SCN_MEM_WRITE:
01068          sec_flags &= ~ SEC_READONLY;
01069          break;
01070        case IMAGE_SCN_MEM_DISCARDABLE:
01071          /* The MS PE spec sets the DISCARDABLE flag on .reloc sections
01072             but we do not want them to be labelled as debug section, since
01073             then strip would remove them.  */
01074          if (! CONST_STRNEQ (name, ".reloc"))
01075            sec_flags |= SEC_DEBUGGING;
01076          break;
01077        case IMAGE_SCN_MEM_SHARED:
01078          sec_flags |= SEC_COFF_SHARED;
01079          break;
01080        case IMAGE_SCN_LNK_REMOVE:
01081          sec_flags |= SEC_EXCLUDE;
01082          break;
01083        case IMAGE_SCN_CNT_CODE:
01084          sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
01085          break;
01086        case IMAGE_SCN_CNT_INITIALIZED_DATA:
01087          sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
01088          break;
01089        case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
01090          sec_flags |= SEC_ALLOC;
01091          break;
01092        case IMAGE_SCN_LNK_INFO:
01093          /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
01094             defined.  coff_compute_section_file_positions uses
01095             COFF_PAGE_SIZE to ensure that the low order bits of the
01096             section VMA and the file offset match.  If we don't know
01097             COFF_PAGE_SIZE, we can't ensure the correct correspondence,
01098             and demand page loading of the file will fail.  */
01099 #ifdef COFF_PAGE_SIZE
01100          sec_flags |= SEC_DEBUGGING;
01101 #endif
01102          break;
01103        case IMAGE_SCN_LNK_COMDAT:
01104          /* COMDAT gets very special treatment.  */
01105          sec_flags = handle_COMDAT (abfd, sec_flags, hdr, name, section);
01106          break;
01107        default:
01108          /* Silently ignore for now.  */
01109          break;
01110        }
01111 
01112       /* If the section flag was not handled, report it here.  */
01113       if (unhandled != NULL)
01114        {
01115          (*_bfd_error_handler)
01116            (_("%B (%s): Section flag %s (0x%x) ignored"),
01117             abfd, name, unhandled, flag);
01118          result = FALSE;
01119        }
01120     }
01121 
01122 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
01123   /* As a GNU extension, if the name begins with .gnu.linkonce, we
01124      only link a single copy of the section.  This is used to support
01125      g++.  g++ will emit each template expansion in its own section.
01126      The symbols will be defined as weak, so that multiple definitions
01127      are permitted.  The GNU linker extension is to actually discard
01128      all but one of the sections.  */
01129   if (CONST_STRNEQ (name, ".gnu.linkonce"))
01130     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
01131 #endif
01132 
01133   if (flags_ptr)
01134     * flags_ptr = sec_flags;
01135 
01136   return result;
01137 }
01138 
01139 #endif /* COFF_WITH_PE */
01140 
01141 #define       get_index(symbol)    ((symbol)->udata.i)
01142 
01143 /*
01144 INTERNAL_DEFINITION
01145        bfd_coff_backend_data
01146 
01147 CODE_FRAGMENT
01148 
01149 .{* COFF symbol classifications.  *}
01150 .
01151 .enum coff_symbol_classification
01152 .{
01153 .  {* Global symbol.  *}
01154 .  COFF_SYMBOL_GLOBAL,
01155 .  {* Common symbol.  *}
01156 .  COFF_SYMBOL_COMMON,
01157 .  {* Undefined symbol.  *}
01158 .  COFF_SYMBOL_UNDEFINED,
01159 .  {* Local symbol.  *}
01160 .  COFF_SYMBOL_LOCAL,
01161 .  {* PE section symbol.  *}
01162 .  COFF_SYMBOL_PE_SECTION
01163 .};
01164 .
01165 Special entry points for gdb to swap in coff symbol table parts:
01166 .typedef struct
01167 .{
01168 .  void (*_bfd_coff_swap_aux_in)
01169 .    (bfd *, void *, int, int, int, int, void *);
01170 .
01171 .  void (*_bfd_coff_swap_sym_in)
01172 .    (bfd *, void *, void *);
01173 .
01174 .  void (*_bfd_coff_swap_lineno_in)
01175 .    (bfd *, void *, void *);
01176 .
01177 .  unsigned int (*_bfd_coff_swap_aux_out)
01178 .    (bfd *, void *, int, int, int, int, void *);
01179 .
01180 .  unsigned int (*_bfd_coff_swap_sym_out)
01181 .    (bfd *, void *, void *);
01182 .
01183 .  unsigned int (*_bfd_coff_swap_lineno_out)
01184 .    (bfd *, void *, void *);
01185 .
01186 .  unsigned int (*_bfd_coff_swap_reloc_out)
01187 .    (bfd *, void *, void *);
01188 .
01189 .  unsigned int (*_bfd_coff_swap_filehdr_out)
01190 .    (bfd *, void *, void *);
01191 .
01192 .  unsigned int (*_bfd_coff_swap_aouthdr_out)
01193 .    (bfd *, void *, void *);
01194 .
01195 .  unsigned int (*_bfd_coff_swap_scnhdr_out)
01196 .    (bfd *, void *, void *);
01197 .
01198 .  unsigned int _bfd_filhsz;
01199 .  unsigned int _bfd_aoutsz;
01200 .  unsigned int _bfd_scnhsz;
01201 .  unsigned int _bfd_symesz;
01202 .  unsigned int _bfd_auxesz;
01203 .  unsigned int _bfd_relsz;
01204 .  unsigned int _bfd_linesz;
01205 .  unsigned int _bfd_filnmlen;
01206 .  bfd_boolean _bfd_coff_long_filenames;
01207 .  bfd_boolean _bfd_coff_long_section_names;
01208 .  unsigned int _bfd_coff_default_section_alignment_power;
01209 .  bfd_boolean _bfd_coff_force_symnames_in_strings;
01210 .  unsigned int _bfd_coff_debug_string_prefix_length;
01211 .
01212 .  void (*_bfd_coff_swap_filehdr_in)
01213 .    (bfd *, void *, void *);
01214 .
01215 .  void (*_bfd_coff_swap_aouthdr_in)
01216 .    (bfd *, void *, void *);
01217 .
01218 .  void (*_bfd_coff_swap_scnhdr_in)
01219 .    (bfd *, void *, void *);
01220 .
01221 .  void (*_bfd_coff_swap_reloc_in)
01222 .    (bfd *abfd, void *, void *);
01223 .
01224 .  bfd_boolean (*_bfd_coff_bad_format_hook)
01225 .    (bfd *, void *);
01226 .
01227 .  bfd_boolean (*_bfd_coff_set_arch_mach_hook)
01228 .    (bfd *, void *);
01229 .
01230 .  void * (*_bfd_coff_mkobject_hook)
01231 .    (bfd *, void *, void *);
01232 .
01233 .  bfd_boolean (*_bfd_styp_to_sec_flags_hook)
01234 .    (bfd *, void *, const char *, asection *, flagword *);
01235 .
01236 .  void (*_bfd_set_alignment_hook)
01237 .    (bfd *, asection *, void *);
01238 .
01239 .  bfd_boolean (*_bfd_coff_slurp_symbol_table)
01240 .    (bfd *);
01241 .
01242 .  bfd_boolean (*_bfd_coff_symname_in_debug)
01243 .    (bfd *, struct internal_syment *);
01244 .
01245 .  bfd_boolean (*_bfd_coff_pointerize_aux_hook)
01246 .    (bfd *, combined_entry_type *, combined_entry_type *,
01247 .           unsigned int, combined_entry_type *);
01248 .
01249 .  bfd_boolean (*_bfd_coff_print_aux)
01250 .    (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
01251 .           combined_entry_type *, unsigned int);
01252 .
01253 .  void (*_bfd_coff_reloc16_extra_cases)
01254 .    (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
01255 .          bfd_byte *, unsigned int *, unsigned int *);
01256 .
01257 .  int (*_bfd_coff_reloc16_estimate)
01258 .    (bfd *, asection *, arelent *, unsigned int,
01259 .           struct bfd_link_info *);
01260 .
01261 .  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
01262 .    (bfd *, struct internal_syment *);
01263 .
01264 .  bfd_boolean (*_bfd_coff_compute_section_file_positions)
01265 .    (bfd *);
01266 .
01267 .  bfd_boolean (*_bfd_coff_start_final_link)
01268 .    (bfd *, struct bfd_link_info *);
01269 .
01270 .  bfd_boolean (*_bfd_coff_relocate_section)
01271 .    (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
01272 .           struct internal_reloc *, struct internal_syment *, asection **);
01273 .
01274 .  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
01275 .    (bfd *, asection *, struct internal_reloc *,
01276 .           struct coff_link_hash_entry *, struct internal_syment *,
01277 .           bfd_vma *);
01278 .
01279 .  bfd_boolean (*_bfd_coff_adjust_symndx)
01280 .    (bfd *, struct bfd_link_info *, bfd *, asection *,
01281 .           struct internal_reloc *, bfd_boolean *);
01282 .
01283 .  bfd_boolean (*_bfd_coff_link_add_one_symbol)
01284 .    (struct bfd_link_info *, bfd *, const char *, flagword,
01285 .           asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
01286 .           struct bfd_link_hash_entry **);
01287 .
01288 .  bfd_boolean (*_bfd_coff_link_output_has_begun)
01289 .    (bfd *, struct coff_final_link_info *);
01290 .
01291 .  bfd_boolean (*_bfd_coff_final_link_postscript)
01292 .    (bfd *, struct coff_final_link_info *);
01293 .
01294 .} bfd_coff_backend_data;
01295 .
01296 .#define coff_backend_info(abfd) \
01297 .  ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
01298 .
01299 .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
01300 .  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
01301 .
01302 .#define bfd_coff_swap_sym_in(a,e,i) \
01303 .  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
01304 .
01305 .#define bfd_coff_swap_lineno_in(a,e,i) \
01306 .  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
01307 .
01308 .#define bfd_coff_swap_reloc_out(abfd, i, o) \
01309 .  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
01310 .
01311 .#define bfd_coff_swap_lineno_out(abfd, i, o) \
01312 .  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
01313 .
01314 .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
01315 .  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
01316 .
01317 .#define bfd_coff_swap_sym_out(abfd, i,o) \
01318 .  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
01319 .
01320 .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
01321 .  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
01322 .
01323 .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
01324 .  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
01325 .
01326 .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
01327 .  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
01328 .
01329 .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
01330 .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
01331 .#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
01332 .#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
01333 .#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
01334 .#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
01335 .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
01336 .#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
01337 .#define bfd_coff_long_filenames(abfd) \
01338 .  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
01339 .#define bfd_coff_long_section_names(abfd) \
01340 .  (coff_backend_info (abfd)->_bfd_coff_long_section_names)
01341 .#define bfd_coff_default_section_alignment_power(abfd) \
01342 .  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
01343 .#define bfd_coff_swap_filehdr_in(abfd, i,o) \
01344 .  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
01345 .
01346 .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
01347 .  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
01348 .
01349 .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
01350 .  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
01351 .
01352 .#define bfd_coff_swap_reloc_in(abfd, i, o) \
01353 .  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
01354 .
01355 .#define bfd_coff_bad_format_hook(abfd, filehdr) \
01356 .  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
01357 .
01358 .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
01359 .  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
01360 .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
01361 .  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
01362 .   (abfd, filehdr, aouthdr))
01363 .
01364 .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
01365 .  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
01366 .   (abfd, scnhdr, name, section, flags_ptr))
01367 .
01368 .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
01369 .  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
01370 .
01371 .#define bfd_coff_slurp_symbol_table(abfd)\
01372 .  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
01373 .
01374 .#define bfd_coff_symname_in_debug(abfd, sym)\
01375 .  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
01376 .
01377 .#define bfd_coff_force_symnames_in_strings(abfd)\
01378 .  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
01379 .
01380 .#define bfd_coff_debug_string_prefix_length(abfd)\
01381 .  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
01382 .
01383 .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
01384 .  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
01385 .   (abfd, file, base, symbol, aux, indaux))
01386 .
01387 .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
01388 .                                     reloc, data, src_ptr, dst_ptr)\
01389 .  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
01390 .   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
01391 .
01392 .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
01393 .  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
01394 .   (abfd, section, reloc, shrink, link_info))
01395 .
01396 .#define bfd_coff_classify_symbol(abfd, sym)\
01397 .  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
01398 .   (abfd, sym))
01399 .
01400 .#define bfd_coff_compute_section_file_positions(abfd)\
01401 .  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
01402 .   (abfd))
01403 .
01404 .#define bfd_coff_start_final_link(obfd, info)\
01405 .  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
01406 .   (obfd, info))
01407 .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
01408 .  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
01409 .   (obfd, info, ibfd, o, con, rel, isyms, secs))
01410 .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
01411 .  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
01412 .   (abfd, sec, rel, h, sym, addendp))
01413 .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
01414 .  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
01415 .   (obfd, info, ibfd, sec, rel, adjustedp))
01416 .#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
01417 .                                     value, string, cp, coll, hashp)\
01418 .  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
01419 .   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
01420 .
01421 .#define bfd_coff_link_output_has_begun(a,p) \
01422 .  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
01423 .#define bfd_coff_final_link_postscript(a,p) \
01424 .  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
01425 .
01426 */
01427 
01428 /* See whether the magic number matches.  */
01429 
01430 static bfd_boolean
01431 coff_bad_format_hook (bfd * abfd ATTRIBUTE_UNUSED, void * filehdr)
01432 {
01433   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01434 
01435   if (BADMAG (*internal_f))
01436     return FALSE;
01437 
01438   /* If the optional header is NULL or not the correct size then
01439      quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
01440      and Intel 960 readwrite headers (I960WRMAGIC) is that the
01441      optional header is of a different size.
01442 
01443      But the mips keeps extra stuff in it's opthdr, so dont check
01444      when doing that.  */
01445 
01446 #if defined(M88) || defined(I960)
01447   if (internal_f->f_opthdr != 0 && bfd_coff_aoutsz (abfd) != internal_f->f_opthdr)
01448     return FALSE;
01449 #endif
01450 
01451   return TRUE;
01452 }
01453 
01454 #ifdef TICOFF
01455 static bfd_boolean
01456 ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
01457 {
01458   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01459 
01460   if (COFF0_BADMAG (*internal_f))
01461     return FALSE;
01462 
01463   return TRUE;
01464 }
01465 #endif
01466 
01467 #ifdef TICOFF
01468 static bfd_boolean
01469 ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
01470 {
01471   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01472 
01473   if (COFF1_BADMAG (*internal_f))
01474     return FALSE;
01475 
01476   return TRUE;
01477 }
01478 #endif
01479 
01480 /* Check whether this section uses an alignment other than the
01481    default.  */
01482 
01483 static void
01484 coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED,
01485                                asection *section,
01486                                const struct coff_section_alignment_entry *alignment_table,
01487                                const unsigned int table_size)
01488 {
01489   const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
01490   unsigned int i;
01491 
01492   for (i = 0; i < table_size; ++i)
01493     {
01494       const char *secname = bfd_get_section_name (abfd, section);
01495 
01496       if (alignment_table[i].comparison_length == (unsigned int) -1
01497          ? strcmp (alignment_table[i].name, secname) == 0
01498          : strncmp (alignment_table[i].name, secname,
01499                    alignment_table[i].comparison_length) == 0)
01500        break;
01501     }
01502   if (i >= table_size)
01503     return;
01504 
01505   if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
01506       && default_alignment < alignment_table[i].default_alignment_min)
01507     return;
01508 
01509   if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
01510 #if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
01511       && default_alignment > alignment_table[i].default_alignment_max
01512 #endif
01513       )
01514     return;
01515 
01516   section->alignment_power = alignment_table[i].alignment_power;
01517 }
01518 
01519 /* Custom section alignment records.  */
01520 
01521 static const struct coff_section_alignment_entry
01522 coff_section_alignment_table[] =
01523 {
01524 #ifdef COFF_SECTION_ALIGNMENT_ENTRIES
01525   COFF_SECTION_ALIGNMENT_ENTRIES,
01526 #endif
01527   /* There must not be any gaps between .stabstr sections.  */
01528   { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
01529     1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
01530   /* The .stab section must be aligned to 2**2 at most, to avoid gaps.  */
01531   { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
01532     3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
01533   /* Similarly for the .ctors and .dtors sections.  */
01534   { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
01535     3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
01536   { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
01537     3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
01538 };
01539 
01540 static const unsigned int coff_section_alignment_table_size =
01541   sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
01542 
01543 /* Initialize a section structure with information peculiar to this
01544    particular implementation of COFF.  */
01545 
01546 static bfd_boolean
01547 coff_new_section_hook (bfd * abfd, asection * section)
01548 {
01549   combined_entry_type *native;
01550   bfd_size_type amt;
01551 
01552   section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
01553 
01554 #ifdef RS6000COFF_C
01555   if (bfd_xcoff_text_align_power (abfd) != 0
01556       && strcmp (bfd_get_section_name (abfd, section), ".text") == 0)
01557     section->alignment_power = bfd_xcoff_text_align_power (abfd);
01558   if (bfd_xcoff_data_align_power (abfd) != 0
01559       && strcmp (bfd_get_section_name (abfd, section), ".data") == 0)
01560     section->alignment_power = bfd_xcoff_data_align_power (abfd);
01561 #endif
01562 
01563   /* Set up the section symbol.  */
01564   if (!_bfd_generic_new_section_hook (abfd, section))
01565     return FALSE;
01566 
01567   /* Allocate aux records for section symbols, to store size and
01568      related info.
01569 
01570      @@ The 10 is a guess at a plausible maximum number of aux entries
01571      (but shouldn't be a constant).  */
01572   amt = sizeof (combined_entry_type) * 10;
01573   native = bfd_zalloc (abfd, amt);
01574   if (native == NULL)
01575     return FALSE;
01576 
01577   /* We don't need to set up n_name, n_value, or n_scnum in the native
01578      symbol information, since they'll be overridden by the BFD symbol
01579      anyhow.  However, we do need to set the type and storage class,
01580      in case this symbol winds up getting written out.  The value 0
01581      for n_numaux is already correct.  */
01582 
01583   native->u.syment.n_type = T_NULL;
01584   native->u.syment.n_sclass = C_STAT;
01585 
01586   coffsymbol (section->symbol)->native = native;
01587 
01588   coff_set_custom_section_alignment (abfd, section,
01589                                  coff_section_alignment_table,
01590                                  coff_section_alignment_table_size);
01591 
01592   return TRUE;
01593 }
01594 
01595 #ifdef COFF_ALIGN_IN_SECTION_HEADER
01596 
01597 /* Set the alignment of a BFD section.  */
01598 
01599 static void
01600 coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
01601                       asection * section,
01602                       void * scnhdr)
01603 {
01604   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
01605   unsigned int i;
01606 
01607 #ifdef I960
01608   /* Extract ALIGN from 2**ALIGN stored in section header.  */
01609   for (i = 0; i < 32; i++)
01610     if ((1 << i) >= hdr->s_align)
01611       break;
01612 #endif
01613 #ifdef TIC80COFF
01614   /* TI tools puts the alignment power in bits 8-11.  */
01615   i = (hdr->s_flags >> 8) & 0xF ;
01616 #endif
01617 #ifdef COFF_DECODE_ALIGNMENT
01618   i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
01619 #endif
01620   section->alignment_power = i;
01621 
01622 #ifdef coff_set_section_load_page
01623   coff_set_section_load_page (section, hdr->s_page);
01624 #endif
01625 }
01626 
01627 #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
01628 #ifdef COFF_WITH_PE
01629 
01630 /* A couple of macros to help setting the alignment power field.  */
01631 #define ALIGN_SET(field, x, y) \
01632   if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x)\
01633     {\
01634       section->alignment_power = y;\
01635     }
01636 
01637 #define ELIFALIGN_SET(field, x, y) \
01638   else if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x) \
01639     {\
01640       section->alignment_power = y;\
01641     }
01642 
01643 static void
01644 coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
01645                       asection * section,
01646                       void * scnhdr)
01647 {
01648   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
01649   bfd_size_type amt;
01650 
01651   ALIGN_SET     (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
01652   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
01653   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4)
01654   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES,  3)
01655   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES,  2)
01656   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES,  1)
01657   ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES,  0)
01658 
01659   /* In a PE image file, the s_paddr field holds the virtual size of a
01660      section, while the s_size field holds the raw size.  We also keep
01661      the original section flag value, since not every bit can be
01662      mapped onto a generic BFD section bit.  */
01663   if (coff_section_data (abfd, section) == NULL)
01664     {
01665       amt = sizeof (struct coff_section_tdata);
01666       section->used_by_bfd = bfd_zalloc (abfd, amt);
01667       if (section->used_by_bfd == NULL)
01668        /* FIXME: Return error.  */
01669        abort ();
01670     }
01671 
01672   if (pei_section_data (abfd, section) == NULL)
01673     {
01674       amt = sizeof (struct pei_section_tdata);
01675       coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
01676       if (coff_section_data (abfd, section)->tdata == NULL)
01677        /* FIXME: Return error.  */
01678        abort ();
01679     }
01680   pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
01681   pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
01682 
01683   section->lma = hdr->s_vaddr;
01684 
01685   /* Check for extended relocs.  */
01686   if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
01687     {
01688       struct external_reloc dst;
01689       struct internal_reloc n;
01690       file_ptr oldpos = bfd_tell (abfd);
01691       bfd_size_type relsz = bfd_coff_relsz (abfd);
01692       
01693       bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0);
01694       if (bfd_bread (& dst, relsz, abfd) != relsz)
01695        return;
01696 
01697       coff_swap_reloc_in (abfd, &dst, &n);
01698       bfd_seek (abfd, oldpos, 0);
01699       section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
01700       section->rel_filepos += relsz;
01701     }
01702   else if (hdr->s_nreloc == 0xffff)
01703     (*_bfd_error_handler)
01704       ("%s: warning: claims to have 0xffff relocs, without overflow",
01705        bfd_get_filename (abfd));
01706 }
01707 #undef ALIGN_SET
01708 #undef ELIFALIGN_SET
01709 
01710 #else /* ! COFF_WITH_PE */
01711 #ifdef RS6000COFF_C
01712 
01713 /* We grossly abuse this function to handle XCOFF overflow headers.
01714    When we see one, we correct the reloc and line number counts in the
01715    real header, and remove the section we just created.  */
01716 
01717 static void
01718 coff_set_alignment_hook (bfd *abfd, asection *section, void * scnhdr)
01719 {
01720   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
01721   asection *real_sec;
01722 
01723   if ((hdr->s_flags & STYP_OVRFLO) == 0)
01724     return;
01725 
01726   real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
01727   if (real_sec == NULL)
01728     return;
01729 
01730   real_sec->reloc_count = hdr->s_paddr;
01731   real_sec->lineno_count = hdr->s_vaddr;
01732 
01733   if (!bfd_section_removed_from_list (abfd, section))
01734     {
01735       bfd_section_list_remove (abfd, section);
01736       --abfd->section_count;
01737     }
01738 }
01739 
01740 #else /* ! RS6000COFF_C */
01741 
01742 #define coff_set_alignment_hook \
01743   ((void (*) (bfd *, asection *, void *)) bfd_void)
01744 
01745 #endif /* ! RS6000COFF_C */
01746 #endif /* ! COFF_WITH_PE */
01747 #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
01748 
01749 #ifndef coff_mkobject
01750 
01751 static bfd_boolean
01752 coff_mkobject (bfd * abfd)
01753 {
01754   coff_data_type *coff;
01755   bfd_size_type amt = sizeof (coff_data_type);
01756 
01757   abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
01758   if (abfd->tdata.coff_obj_data == NULL)
01759     return FALSE;
01760   coff = coff_data (abfd);
01761   coff->symbols = NULL;
01762   coff->conversion_table = NULL;
01763   coff->raw_syments = NULL;
01764   coff->relocbase = 0;
01765   coff->local_toc_sym_map = 0;
01766 
01767 /*  make_abs_section(abfd);*/
01768 
01769   return TRUE;
01770 }
01771 #endif
01772 
01773 /* Create the COFF backend specific information.  */
01774 
01775 #ifndef coff_mkobject_hook
01776 static void *
01777 coff_mkobject_hook (bfd * abfd,
01778                   void * filehdr,
01779                   void * aouthdr ATTRIBUTE_UNUSED)
01780 {
01781   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01782   coff_data_type *coff;
01783 
01784   if (! coff_mkobject (abfd))
01785     return NULL;
01786 
01787   coff = coff_data (abfd);
01788 
01789   coff->sym_filepos = internal_f->f_symptr;
01790 
01791   /* These members communicate important constants about the symbol
01792      table to GDB's symbol-reading code.  These `constants'
01793      unfortunately vary among coff implementations...  */
01794   coff->local_n_btmask = N_BTMASK;
01795   coff->local_n_btshft = N_BTSHFT;
01796   coff->local_n_tmask = N_TMASK;
01797   coff->local_n_tshift = N_TSHIFT;
01798   coff->local_symesz = bfd_coff_symesz (abfd);
01799   coff->local_auxesz = bfd_coff_auxesz (abfd);
01800   coff->local_linesz = bfd_coff_linesz (abfd);
01801 
01802   coff->timestamp = internal_f->f_timdat;
01803 
01804   obj_raw_syment_count (abfd) =
01805     obj_conv_table_size (abfd) =
01806       internal_f->f_nsyms;
01807 
01808 #ifdef RS6000COFF_C
01809   if ((internal_f->f_flags & F_SHROBJ) != 0)
01810     abfd->flags |= DYNAMIC;
01811   if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
01812     {
01813       struct internal_aouthdr *internal_a =
01814        (struct internal_aouthdr *) aouthdr;
01815       struct xcoff_tdata *xcoff;
01816 
01817       xcoff = xcoff_data (abfd);
01818 # ifdef U803XTOCMAGIC
01819       xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
01820 # else
01821       xcoff->xcoff64 = 0;
01822 # endif
01823       xcoff->full_aouthdr = TRUE;
01824       xcoff->toc = internal_a->o_toc;
01825       xcoff->sntoc = internal_a->o_sntoc;
01826       xcoff->snentry = internal_a->o_snentry;
01827       bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
01828       bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
01829       xcoff->modtype = internal_a->o_modtype;
01830       xcoff->cputype = internal_a->o_cputype;
01831       xcoff->maxdata = internal_a->o_maxdata;
01832       xcoff->maxstack = internal_a->o_maxstack;
01833     }
01834 #endif
01835 
01836 #ifdef ARM
01837   /* Set the flags field from the COFF header read in.  */
01838   if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
01839     coff->flags = 0;
01840 #endif
01841 
01842 #ifdef COFF_WITH_PE
01843   /* FIXME: I'm not sure this is ever executed, since peicode.h
01844      defines coff_mkobject_hook.  */
01845   if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
01846     abfd->flags |= HAS_DEBUG;
01847 #endif
01848 
01849   return coff;
01850 }
01851 #endif
01852 
01853 /* Determine the machine architecture and type.  FIXME: This is target
01854    dependent because the magic numbers are defined in the target
01855    dependent header files.  But there is no particular need for this.
01856    If the magic numbers were moved to a separate file, this function
01857    would be target independent and would also be much more successful
01858    at linking together COFF files for different architectures.  */
01859 
01860 static bfd_boolean
01861 coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
01862 {
01863   unsigned long machine;
01864   enum bfd_architecture arch;
01865   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
01866 
01867   /* Zero selects the default machine for an arch.  */
01868   machine = 0;
01869   switch (internal_f->f_magic)
01870     {
01871 #ifdef OR32_MAGIC_BIG
01872     case OR32_MAGIC_BIG:
01873     case OR32_MAGIC_LITTLE:
01874       arch = bfd_arch_or32;
01875       break;
01876 #endif
01877 #ifdef PPCMAGIC
01878     case PPCMAGIC:
01879       arch = bfd_arch_powerpc;
01880       break;
01881 #endif
01882 #ifdef I386MAGIC
01883     case I386MAGIC:
01884     case I386PTXMAGIC:
01885     case I386AIXMAGIC:             /* Danbury PS/2 AIX C Compiler.  */
01886     case LYNXCOFFMAGIC:            /* Shadows the m68k Lynx number below, sigh.  */
01887       arch = bfd_arch_i386;
01888       break;
01889 #endif
01890 #ifdef AMD64MAGIC
01891     case AMD64MAGIC:
01892       arch = bfd_arch_i386;
01893       machine = bfd_mach_x86_64;
01894       break;
01895 #endif
01896 #ifdef IA64MAGIC
01897     case IA64MAGIC:
01898       arch = bfd_arch_ia64;
01899       break;
01900 #endif
01901 #ifdef ARMMAGIC
01902     case ARMMAGIC:
01903     case ARMPEMAGIC:
01904     case THUMBPEMAGIC:
01905       arch = bfd_arch_arm;
01906       machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
01907       if (machine == bfd_mach_arm_unknown)
01908        {
01909          switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
01910            {
01911            case F_ARM_2:  machine = bfd_mach_arm_2;  break;
01912            case F_ARM_2a: machine = bfd_mach_arm_2a; break;
01913            case F_ARM_3:  machine = bfd_mach_arm_3;  break;
01914            default:
01915            case F_ARM_3M: machine = bfd_mach_arm_3M; break;
01916            case F_ARM_4:  machine = bfd_mach_arm_4;  break;
01917            case F_ARM_4T: machine = bfd_mach_arm_4T; break;
01918              /* The COFF header does not have enough bits available
01919                to cover all the different ARM architectures.  So
01920                we interpret F_ARM_5, the highest flag value to mean
01921                "the highest ARM architecture known to BFD" which is
01922                currently the XScale.  */
01923            case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
01924            }
01925        }
01926       break;
01927 #endif
01928 #ifdef MC68MAGIC
01929     case MC68MAGIC:
01930     case M68MAGIC:
01931 #ifdef MC68KBCSMAGIC
01932     case MC68KBCSMAGIC:
01933 #endif
01934 #ifdef APOLLOM68KMAGIC
01935     case APOLLOM68KMAGIC:
01936 #endif
01937 #ifdef LYNXCOFFMAGIC
01938     case LYNXCOFFMAGIC:
01939 #endif
01940       arch = bfd_arch_m68k;
01941       machine = bfd_mach_m68020;
01942       break;
01943 #endif
01944 #ifdef MAXQ20MAGIC
01945     case MAXQ20MAGIC:
01946       arch = bfd_arch_maxq;
01947       switch (internal_f->f_flags & F_MACHMASK)
01948        { 
01949         case F_MAXQ10:
01950           machine = bfd_mach_maxq10;
01951           break;
01952         case F_MAXQ20:
01953           machine = bfd_mach_maxq20;
01954           break;
01955         default:
01956           return FALSE;
01957        }
01958       break;
01959 #endif
01960 #ifdef MC88MAGIC
01961     case MC88MAGIC:
01962     case MC88DMAGIC:
01963     case MC88OMAGIC:
01964       arch = bfd_arch_m88k;
01965       machine = 88100;
01966       break;
01967 #endif
01968 #ifdef Z80MAGIC
01969     case Z80MAGIC:
01970       arch = bfd_arch_z80;
01971       switch (internal_f->f_flags & F_MACHMASK)
01972        {
01973        case 0:
01974        case bfd_mach_z80strict << 12:
01975        case bfd_mach_z80 << 12:
01976        case bfd_mach_z80full << 12:
01977        case bfd_mach_r800 << 12:
01978          machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
01979          break;
01980        default:
01981          return FALSE;
01982        }
01983       break;
01984 #endif
01985 #ifdef Z8KMAGIC
01986     case Z8KMAGIC:
01987       arch = bfd_arch_z8k;
01988       switch (internal_f->f_flags & F_MACHMASK)
01989        {
01990        case F_Z8001:
01991          machine = bfd_mach_z8001;
01992          break;
01993        case F_Z8002:
01994          machine = bfd_mach_z8002;
01995          break;
01996        default:
01997          return FALSE;
01998        }
01999       break;
02000 #endif
02001 #ifdef I860
02002     case I860MAGIC:
02003       arch = bfd_arch_i860;
02004       break;
02005 #endif
02006 #ifdef I960
02007 #ifdef I960ROMAGIC
02008     case I960ROMAGIC:
02009     case I960RWMAGIC:
02010       arch = bfd_arch_i960;
02011       switch (F_I960TYPE & internal_f->f_flags)
02012        {
02013        default:
02014        case F_I960CORE:
02015          machine = bfd_mach_i960_core;
02016          break;
02017        case F_I960KB:
02018          machine = bfd_mach_i960_kb_sb;
02019          break;
02020        case F_I960MC:
02021          machine = bfd_mach_i960_mc;
02022          break;
02023        case F_I960XA:
02024          machine = bfd_mach_i960_xa;
02025          break;
02026        case F_I960CA:
02027          machine = bfd_mach_i960_ca;
02028          break;
02029        case F_I960KA:
02030          machine = bfd_mach_i960_ka_sa;
02031          break;
02032        case F_I960JX:
02033          machine = bfd_mach_i960_jx;
02034          break;
02035        case F_I960HX:
02036          machine = bfd_mach_i960_hx;
02037          break;
02038        }
02039       break;
02040 #endif
02041 #endif
02042 
02043 #ifdef RS6000COFF_C
02044 #ifdef XCOFF64
02045     case U64_TOCMAGIC:
02046     case U803XTOCMAGIC:
02047 #else
02048     case U802ROMAGIC:
02049     case U802WRMAGIC:
02050     case U802TOCMAGIC:
02051 #endif
02052       {
02053        int cputype;
02054 
02055        if (xcoff_data (abfd)->cputype != -1)
02056          cputype = xcoff_data (abfd)->cputype & 0xff;
02057        else
02058          {
02059            /* We did not get a value from the a.out header.  If the
02060               file has not been stripped, we may be able to get the
02061               architecture information from the first symbol, if it
02062               is a .file symbol.  */
02063            if (obj_raw_syment_count (abfd) == 0)
02064              cputype = 0;
02065            else
02066              {
02067               bfd_byte *buf;
02068               struct internal_syment sym;
02069               bfd_size_type amt = bfd_coff_symesz (abfd);
02070 
02071               buf = bfd_malloc (amt);
02072               if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
02073                   || bfd_bread (buf, amt, abfd) != amt)
02074                 {
02075                   free (buf);
02076                   return FALSE;
02077                 }
02078               bfd_coff_swap_sym_in (abfd, buf, & sym);
02079               if (sym.n_sclass == C_FILE)
02080                 cputype = sym.n_type & 0xff;
02081               else
02082                 cputype = 0;
02083               free (buf);
02084              }
02085          }
02086 
02087        /* FIXME: We don't handle all cases here.  */
02088        switch (cputype)
02089          {
02090          default:
02091          case 0:
02092            arch = bfd_xcoff_architecture (abfd);
02093            machine = bfd_xcoff_machine (abfd);
02094            break;
02095 
02096          case 1:
02097            arch = bfd_arch_powerpc;
02098            machine = bfd_mach_ppc_601;
02099            break;
02100          case 2: /* 64 bit PowerPC */
02101            arch = bfd_arch_powerpc;
02102            machine = bfd_mach_ppc_620;
02103            break;
02104          case 3:
02105            arch = bfd_arch_powerpc;
02106            machine = bfd_mach_ppc;
02107            break;
02108          case 4:
02109            arch = bfd_arch_rs6000;
02110            machine = bfd_mach_rs6k;
02111            break;
02112          }
02113       }
02114       break;
02115 #endif
02116 
02117 #ifdef WE32KMAGIC
02118     case WE32KMAGIC:
02119       arch = bfd_arch_we32k;
02120       break;
02121 #endif
02122 
02123 #ifdef H8300MAGIC
02124     case H8300MAGIC:
02125       arch = bfd_arch_h8300;
02126       machine = bfd_mach_h8300;
02127       /* !! FIXME this probably isn't the right place for this.  */
02128       abfd->flags |= BFD_IS_RELAXABLE;
02129       break;
02130 #endif
02131 
02132 #ifdef H8300HMAGIC
02133     case H8300HMAGIC:
02134       arch = bfd_arch_h8300;
02135       machine = bfd_mach_h8300h;
02136       /* !! FIXME this probably isn't the right place for this.  */
02137       abfd->flags |= BFD_IS_RELAXABLE;
02138       break;
02139 #endif
02140 
02141 #ifdef H8300SMAGIC
02142     case H8300SMAGIC:
02143       arch = bfd_arch_h8300;
02144       machine = bfd_mach_h8300s;
02145       /* !! FIXME this probably isn't the right place for this.  */
02146       abfd->flags |= BFD_IS_RELAXABLE;
02147       break;
02148 #endif
02149 
02150 #ifdef H8300HNMAGIC
02151     case H8300HNMAGIC:
02152       arch = bfd_arch_h8300;
02153       machine = bfd_mach_h8300hn;
02154       /* !! FIXME this probably isn't the right place for this.  */
02155       abfd->flags |= BFD_IS_RELAXABLE;
02156       break;
02157 #endif
02158 
02159 #ifdef H8300SNMAGIC
02160     case H8300SNMAGIC:
02161       arch = bfd_arch_h8300;
02162       machine = bfd_mach_h8300sn;
02163       /* !! FIXME this probably isn't the right place for this.  */
02164       abfd->flags |= BFD_IS_RELAXABLE;
02165       break;
02166 #endif
02167 
02168 #ifdef SH_ARCH_MAGIC_BIG
02169     case SH_ARCH_MAGIC_BIG:
02170     case SH_ARCH_MAGIC_LITTLE:
02171 #ifdef COFF_WITH_PE
02172     case SH_ARCH_MAGIC_WINCE:
02173 #endif
02174       arch = bfd_arch_sh;
02175       break;
02176 #endif
02177 
02178 #ifdef MIPS_ARCH_MAGIC_WINCE
02179     case MIPS_ARCH_MAGIC_WINCE:
02180       arch = bfd_arch_mips;
02181       break;
02182 #endif
02183 
02184 #ifdef H8500MAGIC
02185     case H8500MAGIC:
02186       arch = bfd_arch_h8500;
02187       break;
02188 #endif
02189 
02190 #ifdef SPARCMAGIC
02191     case SPARCMAGIC:
02192 #ifdef LYNXCOFFMAGIC
02193     case LYNXCOFFMAGIC:
02194 #endif
02195       arch = bfd_arch_sparc;
02196       break;
02197 #endif
02198 
02199 #ifdef TIC30MAGIC
02200     case TIC30MAGIC:
02201       arch = bfd_arch_tic30;
02202       break;
02203 #endif
02204 
02205 #ifdef TICOFF0MAGIC
02206 #ifdef TICOFF_TARGET_ARCH
02207       /* This TI COFF section should be used by all new TI COFF v0 targets.  */
02208     case TICOFF0MAGIC:
02209       arch = TICOFF_TARGET_ARCH;
02210       machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
02211       break;
02212 #endif
02213 #endif
02214 
02215 #ifdef TICOFF1MAGIC
02216       /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
02217       /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
02218     case TICOFF1MAGIC:
02219     case TICOFF2MAGIC:
02220       switch (internal_f->f_target_id)
02221         {
02222 #ifdef TI_TARGET_ID
02223         case TI_TARGET_ID:
02224           arch = TICOFF_TARGET_ARCH;
02225          machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
02226           break;
02227 #endif
02228         default:
02229           arch = bfd_arch_obscure;
02230           (*_bfd_error_handler)
02231             (_("Unrecognized TI COFF target id '0x%x'"),
02232              internal_f->f_target_id);
02233           break;
02234         }
02235       break;
02236 #endif
02237 
02238 #ifdef TIC80_ARCH_MAGIC
02239     case TIC80_ARCH_MAGIC:
02240       arch = bfd_arch_tic80;
02241       break;
02242 #endif
02243 
02244 #ifdef MCOREMAGIC
02245     case MCOREMAGIC:
02246       arch = bfd_arch_mcore;
02247       break;
02248 #endif
02249 
02250 #ifdef W65MAGIC
02251     case W65MAGIC:
02252       arch = bfd_arch_w65;
02253       break;
02254 #endif
02255 
02256     default:                /* Unreadable input file type.  */
02257       arch = bfd_arch_obscure;
02258       break;
02259     }
02260 
02261   bfd_default_set_arch_mach (abfd, arch, machine);
02262   return TRUE;
02263 }
02264 
02265 #ifdef SYMNAME_IN_DEBUG
02266 
02267 static bfd_boolean
02268 symname_in_debug_hook (bfd * abfd ATTRIBUTE_UNUSED, struct internal_syment *sym)
02269 {
02270   return SYMNAME_IN_DEBUG (sym) != 0;
02271 }
02272 
02273 #else
02274 
02275 #define symname_in_debug_hook \
02276   (bfd_boolean (*) (bfd *, struct internal_syment *)) bfd_false
02277 
02278 #endif
02279 
02280 #ifdef RS6000COFF_C
02281 
02282 #ifdef XCOFF64
02283 #define FORCE_SYMNAMES_IN_STRINGS
02284 #endif
02285 
02286 /* Handle the csect auxent of a C_EXT or C_HIDEXT symbol.  */
02287 
02288 static bfd_boolean
02289 coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
02290                        combined_entry_type *table_base,
02291                        combined_entry_type *symbol,
02292                        unsigned int indaux,
02293                        combined_entry_type *aux)
02294 {
02295   int class = symbol->u.syment.n_sclass;
02296 
02297   if ((class == C_EXT || class == C_HIDEXT)
02298       && indaux + 1 == symbol->u.syment.n_numaux)
02299     {
02300       if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD)
02301        {
02302          aux->u.auxent.x_csect.x_scnlen.p =
02303            table_base + aux->u.auxent.x_csect.x_scnlen.l;
02304          aux->fix_scnlen = 1;
02305        }
02306 
02307       /* Return TRUE to indicate that the caller should not do any
02308          further work on this auxent.  */
02309       return TRUE;
02310     }
02311 
02312   /* Return FALSE to indicate that this auxent should be handled by
02313      the caller.  */
02314   return FALSE;
02315 }
02316 
02317 #else
02318 #ifdef I960
02319 
02320 /* We don't want to pointerize bal entries.  */
02321 
02322 static bfd_boolean
02323 coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
02324                        combined_entry_type *table_base ATTRIBUTE_UNUSED,
02325                        combined_entry_type *symbol,
02326                        unsigned int indaux,
02327                        combined_entry_type *aux ATTRIBUTE_UNUSED)
02328 {
02329   /* Return TRUE if we don't want to pointerize this aux entry, which
02330      is the case for the lastfirst aux entry for a C_LEAFPROC symbol.  */
02331   return (indaux == 1
02332          && (symbol->u.syment.n_sclass == C_LEAFPROC
02333              || symbol->u.syment.n_sclass == C_LEAFSTAT
02334              || symbol->u.syment.n_sclass == C_LEAFEXT));
02335 }
02336 
02337 #else /* ! I960 */
02338 
02339 #define coff_pointerize_aux_hook 0
02340 
02341 #endif /* ! I960 */
02342 #endif /* ! RS6000COFF_C */
02343 
02344 /* Print an aux entry.  This returns TRUE if it has printed it.  */
02345 
02346 static bfd_boolean
02347 coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
02348               FILE *file ATTRIBUTE_UNUSED,
02349               combined_entry_type *table_base ATTRIBUTE_UNUSED,
02350               combined_entry_type *symbol ATTRIBUTE_UNUSED,
02351               combined_entry_type *aux ATTRIBUTE_UNUSED,
02352               unsigned int indaux ATTRIBUTE_UNUSED)
02353 {
02354 #ifdef RS6000COFF_C
02355   if ((symbol->u.syment.n_sclass == C_EXT
02356        || symbol->u.syment.n_sclass == C_HIDEXT)
02357       && indaux + 1 == symbol->u.syment.n_numaux)
02358     {
02359       /* This is a csect entry.  */
02360       fprintf (file, "AUX ");
02361       if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
02362        {
02363          BFD_ASSERT (! aux->fix_scnlen);
02364 #ifdef XCOFF64
02365          fprintf (file, "val %5lld",
02366                  (long long) aux->u.auxent.x_csect.x_scnlen.l);
02367 #else
02368          fprintf (file, "val %5ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
02369 #endif
02370        }
02371       else
02372        {
02373          fprintf (file, "indx ");
02374          if (! aux->fix_scnlen)
02375 #ifdef XCOFF64
02376            fprintf (file, "%4lld",
02377                    (long long) aux->u.auxent.x_csect.x_scnlen.l);
02378 #else
02379            fprintf (file, "%4ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
02380 #endif
02381          else
02382            fprintf (file, "%4ld",
02383                    (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
02384        }
02385       fprintf (file,
02386               " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u",
02387               aux->u.auxent.x_csect.x_parmhash,
02388               (unsigned int) aux->u.auxent.x_csect.x_snhash,
02389               SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
02390               SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
02391               (unsigned int) aux->u.auxent.x_csect.x_smclas,
02392               aux->u.auxent.x_csect.x_stab,
02393               (unsigned int) aux->u.auxent.x_csect.x_snstab);
02394       return TRUE;
02395     }
02396 #endif
02397 
02398   /* Return FALSE to indicate that no special action was taken.  */
02399   return FALSE;
02400 }
02401 
02402 /*
02403 SUBSUBSECTION
02404        Writing relocations
02405 
02406        To write relocations, the back end steps though the
02407        canonical relocation table and create an
02408        @code{internal_reloc}. The symbol index to use is removed from
02409        the @code{offset} field in the symbol table supplied.  The
02410        address comes directly from the sum of the section base
02411        address and the relocation offset; the type is dug directly
02412        from the howto field.  Then the @code{internal_reloc} is
02413        swapped into the shape of an @code{external_reloc} and written
02414        out to disk.
02415 
02416 */
02417 
02418 #ifdef TARG_AUX
02419 
02420 
02421 /* AUX's ld wants relocations to be sorted.  */
02422 static int
02423 compare_arelent_ptr (const void * x, const void * y)
02424 {
02425   const arelent **a = (const arelent **) x;
02426   const arelent **b = (const arelent **) y;
02427   bfd_size_type aadr = (*a)->address;
02428   bfd_size_type badr = (*b)->address;
02429 
02430   return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
02431 }
02432 
02433 #endif /* TARG_AUX */
02434 
02435 static bfd_boolean
02436 coff_write_relocs (bfd * abfd, int first_undef)
02437 {
02438   asection *s;
02439 
02440   for (s = abfd->sections; s != NULL; s = s->next)
02441     {
02442       unsigned int i;
02443       struct external_reloc dst;
02444       arelent **p;
02445 
02446 #ifndef TARG_AUX
02447       p = s->orelocation;
02448 #else
02449       {
02450        /* Sort relocations before we write them out.  */
02451        bfd_size_type amt;
02452 
02453        amt = s->reloc_count;
02454        amt *= sizeof (arelent *);
02455        p = bfd_malloc (amt);
02456        if (p == NULL && s->reloc_count > 0)
02457          return FALSE;
02458        memcpy (p, s->orelocation, (size_t) amt);
02459        qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
02460       }
02461 #endif
02462 
02463       if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
02464        return FALSE;
02465 
02466 #ifdef COFF_WITH_PE
02467       if (obj_pe (abfd) && s->reloc_count >= 0xffff)
02468        {
02469          /* Encode real count here as first reloc.  */
02470          struct internal_reloc n;
02471 
02472          memset (& n, 0, sizeof (n));
02473          /* Add one to count *this* reloc (grr).  */
02474          n.r_vaddr = s->reloc_count + 1;
02475          coff_swap_reloc_out (abfd, &n, &dst);
02476          if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
02477                        abfd) != bfd_coff_relsz (abfd))
02478            return FALSE;
02479        }
02480 #endif
02481 
02482       for (i = 0; i < s->reloc_count; i++)
02483        {
02484          struct internal_reloc n;
02485          arelent *q = p[i];
02486 
02487          memset (& n, 0, sizeof (n));
02488 
02489          /* Now we've renumbered the symbols we know where the
02490             undefined symbols live in the table.  Check the reloc
02491             entries for symbols who's output bfd isn't the right one.
02492             This is because the symbol was undefined (which means
02493             that all the pointers are never made to point to the same
02494             place). This is a bad thing,'cause the symbols attached
02495             to the output bfd are indexed, so that the relocation
02496             entries know which symbol index they point to.  So we
02497             have to look up the output symbol here.  */
02498 
02499          if (q->sym_ptr_ptr[0]->the_bfd != abfd)
02500            {
02501              int j;
02502              const char *sname = q->sym_ptr_ptr[0]->name;
02503              asymbol **outsyms = abfd->outsymbols;
02504 
02505              for (j = first_undef; outsyms[j]; j++)
02506               {
02507                 const char *intable = outsyms[j]->name;
02508 
02509                 if (strcmp (intable, sname) == 0)
02510                   {
02511                     /* Got a hit, so repoint the reloc.  */
02512                     q->sym_ptr_ptr = outsyms + j;
02513                     break;
02514                   }
02515               }
02516            }
02517 
02518          n.r_vaddr = q->address + s->vma;
02519 
02520 #ifdef R_IHCONST
02521          /* The 29k const/consth reloc pair is a real kludge.  The consth
02522             part doesn't have a symbol; it has an offset.  So rebuilt
02523             that here.  */
02524          if (q->howto->type == R_IHCONST)
02525            n.r_symndx = q->addend;
02526          else
02527 #endif
02528            if (q->sym_ptr_ptr)
02529              {
02530 #ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
02531                 if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
02532 #else
02533               if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
02534                   && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
02535 #endif
02536                 /* This is a relocation relative to the absolute symbol.  */
02537                 n.r_symndx = -1;
02538               else
02539                 {
02540                   n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
02541                   /* Check to see if the symbol reloc points to a symbol
02542                      we don't have in our symbol table.  */
02543                   if (n.r_symndx > obj_conv_table_size (abfd))
02544                     {
02545                      bfd_set_error (bfd_error_bad_value);
02546                      _bfd_error_handler (_("%B: reloc against a non-existant symbol index: %ld"),
02547                                        abfd, n.r_symndx);
02548                      return FALSE;
02549                     }
02550                 }
02551              }
02552 
02553 #ifdef SWAP_OUT_RELOC_OFFSET
02554          n.r_offset = q->addend;
02555 #endif
02556 
02557 #ifdef SELECT_RELOC
02558          /* Work out reloc type from what is required.  */
02559          SELECT_RELOC (n, q->howto);
02560 #else
02561          n.r_type = q->howto->type;
02562 #endif
02563          coff_swap_reloc_out (abfd, &n, &dst);
02564 
02565          if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
02566                       abfd) != bfd_coff_relsz (abfd))
02567            return FALSE;
02568        }
02569 
02570 #ifdef TARG_AUX
02571       if (p != NULL)
02572        free (p);
02573 #endif
02574     }
02575 
02576   return TRUE;
02577 }
02578 
02579 /* Set flags and magic number of a coff file from architecture and machine
02580    type.  Result is TRUE if we can represent the arch&type, FALSE if not.  */
02581 
02582 static bfd_boolean
02583 coff_set_flags (bfd * abfd,
02584               unsigned int *magicp ATTRIBUTE_UNUSED,
02585               unsigned short *flagsp ATTRIBUTE_UNUSED)
02586 {
02587   switch (bfd_get_arch (abfd))
02588     {
02589 #ifdef Z80MAGIC
02590     case bfd_arch_z80:
02591       *magicp = Z80MAGIC;
02592       switch (bfd_get_mach (abfd))
02593        {
02594        case 0:
02595        case bfd_mach_z80strict:
02596        case bfd_mach_z80:
02597        case bfd_mach_z80full:
02598        case bfd_mach_r800:
02599          *flagsp = bfd_get_mach (abfd) << 12;
02600          break;
02601        default:
02602          return FALSE;
02603        }
02604       return TRUE;
02605 #endif
02606 
02607 #ifdef Z8KMAGIC
02608     case bfd_arch_z8k:
02609       *magicp = Z8KMAGIC;
02610 
02611       switch (bfd_get_mach (abfd))
02612        {
02613        case bfd_mach_z8001: *flagsp = F_Z8001;   break;
02614        case bfd_mach_z8002: *flagsp = F_Z8002;   break;
02615        default:           return FALSE;
02616        }
02617       return TRUE;
02618 #endif
02619 
02620 #ifdef I960ROMAGIC
02621     case bfd_arch_i960:
02622 
02623       {
02624        unsigned flags;
02625 
02626        *magicp = I960ROMAGIC;
02627 
02628        switch (bfd_get_mach (abfd))
02629          {
02630          case bfd_mach_i960_core:  flags = F_I960CORE; break;
02631          case bfd_mach_i960_kb_sb: flags = F_I960KB;    break;
02632          case bfd_mach_i960_mc:    flags = F_I960MC;    break;
02633          case bfd_mach_i960_xa:    flags = F_I960XA;    break;
02634          case bfd_mach_i960_ca:    flags = F_I960CA;    break;
02635          case bfd_mach_i960_ka_sa: flags = F_I960KA;    break;
02636          case bfd_mach_i960_jx:    flags = F_I960JX;    break;
02637          case bfd_mach_i960_hx:    flags = F_I960HX;    break;
02638          default:                return FALSE;
02639          }
02640        *flagsp = flags;
02641        return TRUE;
02642       }
02643       break;
02644 #endif
02645 
02646 #ifdef TIC30MAGIC
02647     case bfd_arch_tic30:
02648       *magicp = TIC30MAGIC;
02649       return TRUE;
02650 #endif
02651 
02652 #ifdef TICOFF_DEFAULT_MAGIC
02653     case TICOFF_TARGET_ARCH:
02654       /* If there's no indication of which version we want, use the default.  */
02655       if (!abfd->xvec )
02656         *magicp = TICOFF_DEFAULT_MAGIC;
02657       else
02658         {
02659           /* We may want to output in a different COFF version.  */
02660           switch (abfd->xvec->name[4])
02661             {
02662             case '0':
02663               *magicp = TICOFF0MAGIC;
02664               break;
02665             case '1':
02666               *magicp = TICOFF1MAGIC;
02667               break;
02668             case '2':
02669               *magicp = TICOFF2MAGIC;
02670               break;
02671             default:
02672               return FALSE;
02673             }
02674         }
02675       TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
02676       return TRUE;
02677 #endif
02678 
02679 #ifdef TIC80_ARCH_MAGIC
02680     case bfd_arch_tic80:
02681       *magicp = TIC80_ARCH_MAGIC;
02682       return TRUE;
02683 #endif
02684 
02685 #ifdef ARMMAGIC
02686     case bfd_arch_arm:
02687 #ifdef ARM_WINCE
02688       * magicp = ARMPEMAGIC;
02689 #else
02690       * magicp = ARMMAGIC;
02691 #endif
02692       * flagsp = 0;
02693       if (APCS_SET (abfd))
02694        {
02695          if (APCS_26_FLAG (abfd))
02696            * flagsp |= F_APCS26;
02697 
02698          if (APCS_FLOAT_FLAG (abfd))
02699            * flagsp |= F_APCS_FLOAT;
02700 
02701          if (PIC_FLAG (abfd))
02702            * flagsp |= F_PIC;
02703        }
02704       if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
02705        * flagsp |= F_INTERWORK;
02706       switch (bfd_get_mach (abfd))
02707        {
02708        case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
02709        case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
02710        case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
02711        case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
02712        case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
02713        case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
02714        case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
02715          /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
02716             See also the comment in coff_set_arch_mach_hook().  */
02717        case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
02718        case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
02719        case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
02720        }
02721       return TRUE;
02722 #endif
02723 
02724 #ifdef PPCMAGIC
02725     case bfd_arch_powerpc:
02726       *magicp = PPCMAGIC;
02727       return TRUE;
02728 #endif
02729 
02730 #if defined(I386MAGIC) || defined(AMD64MAGIC)
02731     case bfd_arch_i386:
02732 #if defined(I386MAGIC)
02733       *magicp = I386MAGIC;
02734 #endif
02735 #if defined LYNXOS
02736       /* Just overwrite the usual value if we're doing Lynx.  */
02737       *magicp = LYNXCOFFMAGIC;
02738 #endif
02739 #if defined AMD64MAGIC
02740       *magicp = AMD64MAGIC;
02741 #endif
02742       return TRUE;
02743 #endif
02744 
02745 #ifdef I860MAGIC
02746     case bfd_arch_i860:
02747       *magicp = I860MAGIC;
02748       return TRUE;
02749 #endif
02750 
02751 #ifdef IA64MAGIC
02752     case bfd_arch_ia64:
02753       *magicp = IA64MAGIC;
02754       return TRUE;
02755 #endif
02756 
02757 #ifdef MC68MAGIC
02758     case bfd_arch_m68k:
02759 #ifdef APOLLOM68KMAGIC
02760       *magicp = APOLLO_COFF_VERSION_NUMBER;
02761 #else
02762       /* NAMES_HAVE_UNDERSCORE may be defined by coff-u68k.c.  */
02763 #ifdef NAMES_HAVE_UNDERSCORE
02764       *magicp = MC68KBCSMAGIC;
02765 #else
02766       *magicp = MC68MAGIC;
02767 #endif
02768 #endif
02769 #ifdef LYNXOS
02770       /* Just overwrite the usual value if we're doing Lynx.  */
02771       *magicp = LYNXCOFFMAGIC;
02772 #endif
02773       return TRUE;
02774 #endif
02775 
02776 #ifdef MC88MAGIC
02777     case bfd_arch_m88k:
02778       *magicp = MC88OMAGIC;
02779       return TRUE;
02780 #endif
02781 
02782 #ifdef H8300MAGIC
02783     case bfd_arch_h8300:
02784       switch (bfd_get_mach (abfd))
02785        {
02786        case bfd_mach_h8300:   *magicp = H8300MAGIC;   return TRUE;
02787        case bfd_mach_h8300h:  *magicp = H8300HMAGIC;  return TRUE;
02788        case bfd_mach_h8300s:  *magicp = H8300SMAGIC;  return TRUE;
02789        case bfd_mach_h8300hn: *magicp = H8300HNMAGIC; return TRUE;
02790        case bfd_mach_h8300sn: *magicp = H8300SNMAGIC; return TRUE;
02791        default: break;
02792        }
02793       break;
02794 #endif
02795 
02796 #ifdef SH_ARCH_MAGIC_BIG
02797     case bfd_arch_sh:
02798 #ifdef COFF_IMAGE_WITH_PE
02799       *magicp = SH_ARCH_MAGIC_WINCE;
02800 #else
02801       if (bfd_big_endian (abfd))
02802        *magicp = SH_ARCH_MAGIC_BIG;
02803       else
02804        *magicp = SH_ARCH_MAGIC_LITTLE;
02805 #endif
02806       return TRUE;
02807 #endif
02808 
02809 #ifdef MIPS_ARCH_MAGIC_WINCE
02810     case bfd_arch_mips:
02811       *magicp = MIPS_ARCH_MAGIC_WINCE;
02812       return TRUE;
02813 #endif
02814 
02815 #ifdef SPARCMAGIC
02816     case bfd_arch_sparc:
02817       *magicp = SPARCMAGIC;
02818 #ifdef LYNXOS
02819       /* Just overwrite the usual value if we're doing Lynx.  */
02820       *magicp = LYNXCOFFMAGIC;
02821 #endif
02822       return TRUE;
02823 #endif
02824 
02825 #ifdef H8500MAGIC
02826     case bfd_arch_h8500:
02827       *magicp = H8500MAGIC;
02828       return TRUE;
02829       break;
02830 #endif
02831 
02832 #ifdef WE32KMAGIC
02833     case bfd_arch_we32k:
02834       *magicp = WE32KMAGIC;
02835       return TRUE;
02836 #endif
02837 
02838 #ifdef RS6000COFF_C
02839     case bfd_arch_rs6000:
02840 #ifndef PPCMAGIC
02841     case bfd_arch_powerpc:
02842 #endif
02843       BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
02844       *magicp = bfd_xcoff_magic_number (abfd);
02845       return TRUE;
02846 #endif
02847 
02848 #ifdef MCOREMAGIC
02849     case bfd_arch_mcore:
02850       * magicp = MCOREMAGIC;
02851       return TRUE;
02852 #endif
02853 
02854 #ifdef W65MAGIC
02855     case bfd_arch_w65:
02856       *magicp = W65MAGIC;
02857       return TRUE;
02858 #endif
02859 
02860 #ifdef OR32_MAGIC_BIG
02861     case bfd_arch_or32:
02862       if (bfd_big_endian (abfd))
02863         * magicp = OR32_MAGIC_BIG;
02864       else
02865         * magicp = OR32_MAGIC_LITTLE;
02866       return TRUE;
02867 #endif
02868 
02869 #ifdef MAXQ20MAGIC
02870     case bfd_arch_maxq:
02871       * magicp = MAXQ20MAGIC;
02872       switch (bfd_get_mach (abfd))
02873        {
02874        case bfd_mach_maxq10: * flagsp = F_MAXQ10; return TRUE;
02875        case bfd_mach_maxq20: * flagsp = F_MAXQ20; return TRUE;
02876        default:            return FALSE;
02877        }
02878 #endif
02879 
02880     default:                /* Unknown architecture.  */
02881       /* Fall through to "return FALSE" below, to avoid
02882         "statement never reached" errors on the one below.  */
02883       break;
02884     }
02885 
02886   return FALSE;
02887 }
02888 
02889 static bfd_boolean
02890 coff_set_arch_mach (bfd * abfd,
02891                   enum bfd_architecture arch,
02892                   unsigned long machine)
02893 {
02894   unsigned dummy1;
02895   unsigned short dummy2;
02896 
02897   if (! bfd_default_set_arch_mach (abfd, arch, machine))
02898     return FALSE;
02899 
02900   if (arch != bfd_arch_unknown
02901       && ! coff_set_flags (abfd, &dummy1, &dummy2))
02902     return FALSE;           /* We can't represent this type.  */
02903 
02904   return TRUE;                     /* We're easy...  */
02905 }
02906 
02907 #ifdef COFF_IMAGE_WITH_PE
02908 
02909 /* This is used to sort sections by VMA, as required by PE image
02910    files.  */
02911 
02912 static int
02913 sort_by_secaddr (const void * arg1, const void * arg2)
02914 {
02915   const asection *a = *(const asection **) arg1;
02916   const asection *b = *(const asection **) arg2;
02917 
02918   if (a->vma < b->vma)
02919     return -1;
02920   else if (a->vma > b->vma)
02921     return 1;
02922 
02923   return 0;
02924 }
02925 
02926 #endif /* COFF_IMAGE_WITH_PE */
02927 
02928 /* Calculate the file position for each section.  */
02929 
02930 #ifndef I960
02931 #define ALIGN_SECTIONS_IN_FILE
02932 #endif
02933 #if defined(TIC80COFF) || defined(TICOFF)
02934 #undef ALIGN_SECTIONS_IN_FILE
02935 #endif
02936 
02937 static bfd_boolean
02938 coff_compute_section_file_positions (bfd * abfd)
02939 {
02940   asection *current;
02941   asection *previous = NULL;
02942   file_ptr sofar = bfd_coff_filhsz (abfd);
02943   bfd_boolean align_adjust;
02944 #ifdef ALIGN_SECTIONS_IN_FILE
02945   file_ptr old_sofar;
02946 #endif
02947 
02948 #ifdef RS6000COFF_C
02949   /* On XCOFF, if we have symbols, set up the .debug section.  */
02950   if (bfd_get_symcount (abfd) > 0)
02951     {
02952       bfd_size_type sz;
02953       bfd_size_type i, symcount;
02954       asymbol **symp;
02955 
02956       sz = 0;
02957       symcount = bfd_get_symcount (abfd);
02958       for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
02959        {
02960          coff_symbol_type *cf;
02961 
02962          cf = coff_symbol_from (abfd, *symp);
02963          if (cf != NULL
02964              && cf->native != NULL
02965              && SYMNAME_IN_DEBUG (&cf->native->u.syment))
02966            {
02967              size_t len;
02968 
02969              len = strlen (bfd_asymbol_name (*symp));
02970              if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
02971               sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
02972            }
02973        }
02974       if (sz > 0)
02975        {
02976          asection *dsec;
02977 
02978          dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
02979          if (dsec == NULL)
02980            abort ();
02981          dsec->size = sz;
02982          dsec->flags |= SEC_HAS_CONTENTS;
02983        }
02984     }
02985 #endif
02986 
02987 #ifdef COFF_IMAGE_WITH_PE
02988   int page_size;
02989 
02990   if (coff_data (abfd)->link_info)
02991     {
02992       page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
02993 
02994       /* If no file alignment has been set, default to one.
02995         This repairs 'ld -r' for arm-wince-pe target.  */
02996       if (page_size == 0)
02997         page_size = 1;
02998     }
02999   else
03000     page_size = PE_DEF_FILE_ALIGNMENT;
03001 #else
03002 #ifdef COFF_PAGE_SIZE
03003   int page_size = COFF_PAGE_SIZE;
03004 #endif
03005 #endif
03006 
03007   if (bfd_get_start_address (abfd))
03008     /*  A start address may have been added to the original file. In this
03009        case it will need an optional header to record it.  */
03010     abfd->flags |= EXEC_P;
03011 
03012   if (abfd->flags & EXEC_P)
03013     sofar += bfd_coff_aoutsz (abfd);
03014 #ifdef RS6000COFF_C
03015   else if (xcoff_data (abfd)->full_aouthdr)
03016     sofar += bfd_coff_aoutsz (abfd);
03017   else
03018     sofar += SMALL_AOUTSZ;
03019 #endif
03020 
03021   sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
03022 
03023 #ifdef RS6000COFF_C
03024   /* XCOFF handles overflows in the reloc and line number count fields
03025      by allocating a new section header to hold the correct counts.  */
03026   for (current = abfd->sections; current != NULL; current = current->next)
03027     if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
03028       sofar += bfd_coff_scnhsz (abfd);
03029 #endif
03030 
03031 #ifdef COFF_IMAGE_WITH_PE
03032   {
03033     /* PE requires the sections to be in memory order when listed in
03034        the section headers.  It also does not like empty loadable
03035        sections.  The sections apparently do not have to be in the
03036        right order in the image file itself, but we do need to get the
03037        target_index values right.  */
03038 
03039     unsigned int count;
03040     asection **section_list;
03041     unsigned int i;
03042     int target_index;
03043     bfd_size_type amt;
03044 
03045     count = 0;
03046     for (current = abfd->sections; current != NULL; current = current->next)
03047       ++count;
03048 
03049     /* We allocate an extra cell to simplify the final loop.  */
03050     amt = sizeof (struct asection *) * (count + 1);
03051     section_list = bfd_malloc (amt);
03052     if (section_list == NULL)
03053       return FALSE;
03054 
03055     i = 0;
03056     for (current = abfd->sections; current != NULL; current = current->next)
03057       {
03058        section_list[i] = current;
03059        ++i;
03060       }
03061     section_list[i] = NULL;
03062 
03063     qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
03064 
03065     /* Rethread the linked list into sorted order; at the same time,
03066        assign target_index values.  */
03067     target_index = 1;
03068     abfd->sections = NULL;
03069     abfd->section_last = NULL;
03070     for (i = 0; i < count; i++)
03071       {
03072        current = section_list[i];
03073        bfd_section_list_append (abfd, current);
03074 
03075        /* Later, if the section has zero size, we'll be throwing it
03076           away, so we don't want to number it now.  Note that having
03077           a zero size and having real contents are different
03078           concepts: .bss has no contents, but (usually) non-zero
03079           size.  */
03080        if (current->size == 0)
03081          {
03082            /* Discard.  However, it still might have (valid) symbols
03083               in it, so arbitrarily set it to section 1 (indexing is
03084               1-based here; usually .text).  __end__ and other
03085               contents of .endsection really have this happen.
03086               FIXME: This seems somewhat dubious.  */
03087            current->target_index = 1;
03088          }
03089        else
03090          current->target_index = target_index++;
03091       }
03092 
03093     free (section_list);
03094   }
03095 #else /* ! COFF_IMAGE_WITH_PE */
03096   {
03097     /* Set the target_index field.  */
03098     int target_index;
03099 
03100     target_index = 1;
03101     for (current = abfd->sections; current != NULL; current = current->next)
03102       current->target_index = target_index++;
03103   }
03104 #endif /* ! COFF_IMAGE_WITH_PE */
03105 
03106   align_adjust = FALSE;
03107   for (current = abfd->sections;
03108        current != NULL;
03109        current = current->next)
03110     {
03111 #ifdef COFF_IMAGE_WITH_PE
03112       /* With PE we have to pad each section to be a multiple of its
03113         page size too, and remember both sizes.  */
03114       if (coff_section_data (abfd, current) == NULL)
03115        {
03116          bfd_size_type amt = sizeof (struct coff_section_tdata);
03117 
03118          current->used_by_bfd = bfd_zalloc (abfd, amt);
03119          if (current->used_by_bfd == NULL)
03120            return FALSE;
03121        }
03122       if (pei_section_data (abfd, current) == NULL)
03123        {
03124          bfd_size_type amt = sizeof (struct pei_section_tdata);
03125 
03126          coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
03127          if (coff_section_data (abfd, current)->tdata == NULL)
03128            return FALSE;
03129        }
03130       if (pei_section_data (abfd, current)->virt_size == 0)
03131        pei_section_data (abfd, current)->virt_size = current->size;
03132 #endif
03133 
03134       /* Only deal with sections which have contents.  */
03135       if (!(current->flags & SEC_HAS_CONTENTS))
03136        continue;
03137 
03138 #ifdef COFF_IMAGE_WITH_PE
03139       /* Make sure we skip empty sections in a PE image.  */
03140       if (current->size == 0)
03141        continue;
03142 #endif
03143 
03144       /* Align the sections in the file to the same boundary on
03145         which they are aligned in virtual memory.  I960 doesn't
03146         do this (FIXME) so we can stay in sync with Intel.  960
03147         doesn't yet page from files...  */
03148 #ifdef ALIGN_SECTIONS_IN_FILE
03149       if ((abfd->flags & EXEC_P) != 0)
03150        {
03151          /* Make sure this section is aligned on the right boundary - by
03152             padding the previous section up if necessary.  */
03153          old_sofar = sofar;
03154 
03155 #ifdef RS6000COFF_C
03156          /* AIX loader checks the text section alignment of (vma - filepos)
03157             So even though the filepos may be aligned wrt the o_algntext, for
03158             AIX executables, this check fails. This shows up when a native
03159             AIX executable is stripped with gnu strip because the default vma
03160             of native is 0x10000150 but default for gnu is 0x10000140.  Gnu
03161             stripped gnu excutable passes this check because the filepos is
03162             0x0140.  This problem also show up with 64 bit shared objects. The
03163             data section must also be aligned.  */
03164          if (!strcmp (current->name, _TEXT)
03165              || !strcmp (current->name, _DATA))
03166            {
03167              bfd_vma pad;
03168              bfd_vma align;
03169 
03170              sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
03171 
03172              align = 1 << current->alignment_power;
03173              pad = abs (current->vma - sofar) % align;
03174 
03175              if (pad)
03176               {
03177                 pad = align - pad;
03178                 sofar += pad;
03179               }
03180            }
03181          else
03182 #else
03183            {
03184              sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
03185            }
03186 #endif
03187          if (previous != NULL)
03188            previous->size += sofar - old_sofar;
03189        }
03190 
03191 #endif
03192 
03193       /* In demand paged files the low order bits of the file offset
03194         must match the low order bits of the virtual address.  */
03195 #ifdef COFF_PAGE_SIZE
03196       if ((abfd->flags & D_PAGED) != 0
03197          && (current->flags & SEC_ALLOC) != 0)
03198        sofar += (current->vma - (bfd_vma) sofar) % page_size;
03199 #endif
03200       current->filepos = sofar;
03201 
03202 #ifdef COFF_IMAGE_WITH_PE
03203       /* Set the padded size.  */
03204       current->size = (current->size + page_size -1) & -page_size;
03205 #endif
03206 
03207       sofar += current->size;
03208 
03209 #ifdef ALIGN_SECTIONS_IN_FILE
03210       /* Make sure that this section is of the right size too.  */
03211       if ((abfd->flags & EXEC_P) == 0)
03212        {
03213          bfd_size_type old_size;
03214 
03215          old_size = current->size;
03216          current->size = BFD_ALIGN (current->size,
03217                                  1 << current->alignment_power);
03218          align_adjust = current->size != old_size;
03219          sofar += current->size - old_size;
03220        }
03221       else
03222        {
03223          old_sofar = sofar;
03224          sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
03225          align_adjust = sofar != old_sofar;
03226          current->size += sofar - old_sofar;
03227        }
03228 #endif
03229 
03230 #ifdef COFF_IMAGE_WITH_PE
03231       /* For PE we need to make sure we pad out to the aligned
03232          size, in case the caller only writes out data to the
03233          unaligned size.  */
03234       if (pei_section_data (abfd, current)->virt_size < current->size)
03235        align_adjust = TRUE;
03236 #endif
03237 
03238 #ifdef _LIB
03239       /* Force .lib sections to start at zero.  The vma is then
03240         incremented in coff_set_section_contents.  This is right for
03241         SVR3.2.  */
03242       if (strcmp (current->name, _LIB) == 0)
03243        bfd_set_section_vma (abfd, current, 0);
03244 #endif
03245 
03246       previous = current;
03247     }
03248 
03249   /* It is now safe to write to the output file.  If we needed an
03250      alignment adjustment for the last section, then make sure that
03251      there is a byte at offset sofar.  If there are no symbols and no
03252      relocs, then nothing follows the last section.  If we don't force
03253      the last byte out, then the file may appear to be truncated.  */
03254   if (align_adjust)
03255     {
03256       bfd_byte b;
03257 
03258       b = 0;
03259       if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
03260          || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
03261        return FALSE;
03262     }
03263 
03264   /* Make sure the relocations are aligned.  We don't need to make
03265      sure that this byte exists, because it will only matter if there
03266      really are relocs.  */
03267   sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
03268 
03269   obj_relocbase (abfd) = sofar;
03270   abfd->output_has_begun = TRUE;
03271 
03272   return TRUE;
03273 }
03274 
03275 #ifdef COFF_IMAGE_WITH_PE
03276 
03277 static unsigned int pelength;
03278 static unsigned int peheader;
03279 
03280 static bfd_boolean
03281 coff_read_word (bfd *abfd, unsigned int *value)
03282 {
03283   unsigned char b[2];
03284   int status;
03285 
03286   status = bfd_bread (b, (bfd_size_type) 2, abfd);
03287   if (status < 1)
03288     {
03289       *value = 0;
03290       return FALSE;
03291     }
03292 
03293   if (status == 1)
03294     *value = (unsigned int) b[0];
03295   else
03296     *value = (unsigned int) (b[0] + (b[1] << 8));
03297 
03298   pelength += (unsigned int) status;
03299 
03300   return TRUE;
03301 }
03302 
03303 static unsigned int
03304 coff_compute_checksum (bfd *abfd)
03305 {
03306   bfd_boolean more_data;
03307   file_ptr filepos;
03308   unsigned int value;
03309   unsigned int total;
03310 
03311   total = 0;
03312   pelength = 0;
03313   filepos = (file_ptr) 0;
03314 
03315   do
03316     {
03317       if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
03318        return 0;
03319 
03320       more_data = coff_read_word (abfd, &value);
03321       total += value;
03322       total = 0xffff & (total + (total >> 0x10));
03323       filepos += 2;
03324     }
03325   while (more_data);
03326 
03327   return (0xffff & (total + (total >> 0x10)));
03328 }
03329 
03330 static bfd_boolean
03331 coff_apply_checksum (bfd *abfd)
03332 {
03333   unsigned int computed;
03334   unsigned int checksum = 0;
03335 
03336   if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
03337     return FALSE;
03338 
03339   if (!coff_read_word (abfd, &peheader))
03340     return FALSE;
03341 
03342   if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
03343     return FALSE;
03344 
03345   checksum = 0;
03346   bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
03347 
03348   if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
03349     return FALSE;
03350 
03351   computed = coff_compute_checksum (abfd);
03352 
03353   checksum = computed + pelength;
03354 
03355   if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
03356     return FALSE;
03357 
03358   bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
03359 
03360   return TRUE;
03361 }
03362 
03363 #endif /* COFF_IMAGE_WITH_PE */
03364 
03365 static bfd_boolean
03366 coff_write_object_contents (bfd * abfd)
03367 {
03368   asection *current;
03369   bfd_boolean hasrelocs = FALSE;
03370   bfd_boolean haslinno = FALSE;
03371   bfd_boolean hasdebug = FALSE;
03372   file_ptr scn_base;
03373   file_ptr reloc_base;
03374   file_ptr lineno_base;
03375   file_ptr sym_base;
03376   unsigned long reloc_size = 0, reloc_count = 0;
03377   unsigned long lnno_size = 0;
03378   bfd_boolean long_section_names;
03379   asection *text_sec = NULL;
03380   asection *data_sec = NULL;
03381   asection *bss_sec = NULL;
03382   struct internal_filehdr internal_f;
03383   struct internal_aouthdr internal_a;
03384 #ifdef COFF_LONG_SECTION_NAMES
03385   size_t string_size = STRING_SIZE_SIZE;
03386 #endif
03387 
03388   bfd_set_error (bfd_error_system_call);
03389 
03390   /* Make a pass through the symbol table to count line number entries and
03391      put them into the correct asections.  */
03392   lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
03393 
03394   if (! abfd->output_has_begun)
03395     {
03396       if (! coff_compute_section_file_positions (abfd))
03397        return FALSE;
03398     }
03399 
03400   reloc_base = obj_relocbase (abfd);
03401 
03402   /* Work out the size of the reloc and linno areas.  */
03403 
03404   for (current = abfd->sections; current != NULL; current =
03405        current->next)
03406     {
03407 #ifdef COFF_WITH_PE
03408       /* We store the actual reloc count in the first reloc's addr.  */
03409       if (obj_pe (abfd) && current->reloc_count >= 0xffff)
03410        reloc_count ++;
03411 #endif
03412       reloc_count += current->reloc_count;
03413     }
03414 
03415   reloc_size = reloc_count * bfd_coff_relsz (abfd);
03416 
03417   lineno_base = reloc_base + reloc_size;
03418   sym_base = lineno_base + lnno_size;
03419 
03420   /* Indicate in each section->line_filepos its actual file address.  */
03421   for (current = abfd->sections; current != NULL; current =
03422        current->next)
03423     {
03424       if (current->lineno_count)
03425        {
03426          current->line_filepos = lineno_base;
03427          current->moving_line_filepos = lineno_base;
03428          lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
03429        }
03430       else
03431        current->line_filepos = 0;
03432 
03433       if (current->reloc_count)
03434        {
03435          current->rel_filepos = reloc_base;
03436          reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
03437 #ifdef COFF_WITH_PE
03438          /* Extra reloc to hold real count.  */
03439          if (obj_pe (abfd) && current->reloc_count >= 0xffff)
03440            reloc_base += bfd_coff_relsz (abfd);
03441 #endif
03442        }
03443       else
03444        current->rel_filepos = 0;
03445     }
03446 
03447   /* Write section headers to the file.  */
03448   internal_f.f_nscns = 0;
03449 
03450   if ((abfd->flags & EXEC_P) != 0)
03451     scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
03452   else
03453     {
03454       scn_base = bfd_coff_filhsz (abfd);
03455 #ifdef RS6000COFF_C
03456 #ifndef XCOFF64
03457       if (xcoff_data (abfd)->full_aouthdr)
03458        scn_base += bfd_coff_aoutsz (abfd);
03459       else
03460        scn_base += SMALL_AOUTSZ;
03461 #endif
03462 #endif
03463     }
03464 
03465   if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
03466     return FALSE;
03467 
03468   long_section_names = FALSE;
03469   for (current = abfd->sections;
03470        current != NULL;
03471        current = current->next)
03472     {
03473       struct internal_scnhdr section;
03474       bfd_boolean is_reloc_section = FALSE;
03475 
03476 #ifdef COFF_IMAGE_WITH_PE
03477       if (strcmp (current->name, ".reloc") == 0)
03478        {
03479          is_reloc_section = TRUE;
03480          hasrelocs = TRUE;
03481          pe_data (abfd)->has_reloc_section = 1;
03482        }
03483 #endif
03484 
03485       internal_f.f_nscns++;
03486 
03487       strncpy (section.s_name, current->name, SCNNMLEN);
03488 
03489 #ifdef COFF_LONG_SECTION_NAMES
03490       /* Handle long section names as in PE.  This must be compatible
03491          with the code in coff_write_symbols and _bfd_coff_final_link.  */
03492       {
03493        size_t len;
03494 
03495        len = strlen (current->name);
03496        if (len > SCNNMLEN)
03497          {
03498            memset (section.s_name, 0, SCNNMLEN);
03499            sprintf (section.s_name, "/%lu", (unsigned long) string_size);
03500            string_size += len + 1;
03501            long_section_names = TRUE;
03502          }
03503       }
03504 #endif
03505 
03506 #ifdef _LIB
03507       /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
03508         Ian Taylor <ian@cygnus.com>.  */
03509       if (strcmp (current->name, _LIB) == 0)
03510        section.s_vaddr = 0;
03511       else
03512 #endif
03513       section.s_vaddr = current->vma;
03514       section.s_paddr = current->lma;
03515       section.s_size =  current->size;
03516 #ifdef coff_get_section_load_page
03517       section.s_page = coff_get_section_load_page (current);
03518 #endif
03519 
03520 #ifdef COFF_WITH_PE
03521       section.s_paddr = 0;
03522 #endif
03523 #ifdef COFF_IMAGE_WITH_PE
03524       /* Reminder: s_paddr holds the virtual size of the section.  */
03525       if (coff_section_data (abfd, current) != NULL
03526          && pei_section_data (abfd, current) != NULL)
03527        section.s_paddr = pei_section_data (abfd, current)->virt_size;
03528       else
03529        section.s_paddr = 0;
03530 #endif
03531 
03532       /* If this section has no size or is unloadable then the scnptr
03533         will be 0 too.  */
03534       if (current->size == 0
03535          || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
03536        section.s_scnptr = 0;
03537       else
03538        section.s_scnptr = current->filepos;
03539 
03540       section.s_relptr = current->rel_filepos;
03541       section.s_lnnoptr = current->line_filepos;
03542       section.s_nreloc = current->reloc_count;
03543       section.s_nlnno = current->lineno_count;
03544 #ifndef COFF_IMAGE_WITH_PE
03545       /* In PEI, relocs come in the .reloc section.  */
03546       if (current->reloc_count != 0)
03547        hasrelocs = TRUE;
03548 #endif
03549       if (current->lineno_count != 0)
03550        haslinno = TRUE;
03551       if ((current->flags & SEC_DEBUGGING) != 0
03552          && ! is_reloc_section)
03553        hasdebug = TRUE;
03554 
03555 #ifdef RS6000COFF_C
03556 #ifndef XCOFF64
03557       /* Indicate the use of an XCOFF overflow section header.  */
03558       if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
03559        {
03560          section.s_nreloc = 0xffff;
03561          section.s_nlnno = 0xffff;
03562        }
03563 #endif
03564 #endif
03565 
03566       section.s_flags = sec_to_styp_flags (current->name, current->flags);
03567 
03568       if (!strcmp (current->name, _TEXT))
03569        text_sec = current;
03570       else if (!strcmp (current->name, _DATA))
03571        data_sec = current;
03572       else if (!strcmp (current->name, _BSS))
03573        bss_sec = current;
03574 
03575 #ifdef I960
03576       section.s_align = (current->alignment_power
03577                       ? 1 << current->alignment_power
03578                       : 0);
03579 #endif
03580 #ifdef TIC80COFF
03581       /* TI COFF puts the alignment power in bits 8-11 of the flags.  */
03582       section.s_flags |= (current->alignment_power & 0xF) << 8;
03583 #endif
03584 #ifdef COFF_ENCODE_ALIGNMENT
03585       COFF_ENCODE_ALIGNMENT(section, current->alignment_power);
03586 #endif
03587 
03588 #ifdef COFF_IMAGE_WITH_PE
03589       /* Suppress output of the sections if they are null.  ld
03590         includes the bss and data sections even if there is no size
03591         assigned to them.  NT loader doesn't like it if these section
03592         headers are included if the sections themselves are not
03593         needed.  See also coff_compute_section_file_positions.  */
03594       if (section.s_size == 0)
03595        internal_f.f_nscns--;
03596       else
03597 #endif
03598        {
03599          SCNHDR buff;
03600          bfd_size_type amt = bfd_coff_scnhsz (abfd);
03601 
03602          if (coff_swap_scnhdr_out (abfd, &section, &buff) == 0
03603              || bfd_bwrite (& buff, amt, abfd) != amt)
03604            return FALSE;
03605        }
03606 
03607 #ifdef COFF_WITH_PE
03608       /* PE stores COMDAT section information in the symbol table.  If
03609          this section is supposed to have some COMDAT info, track down
03610          the symbol in the symbol table and modify it.  */
03611       if ((current->flags & SEC_LINK_ONCE) != 0)
03612        {
03613          unsigned int i, count;
03614          asymbol **psym;
03615          coff_symbol_type *csym = NULL;
03616          asymbol **psymsec;
03617 
03618          psymsec = NULL;
03619          count = bfd_get_symcount (abfd);
03620          for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
03621            {
03622              if ((*psym)->section != current)
03623               continue;
03624 
03625              /* Remember the location of the first symbol in this
03626                  section.  */
03627              if (psymsec == NULL)
03628               psymsec = psym;
03629 
03630              /* See if this is the section symbol.  */
03631              if (strcmp ((*psym)->name, current->name) == 0)
03632               {
03633                 csym = coff_symbol_from (abfd, *psym);
03634                 if (csym == NULL
03635                     || csym->native == NULL
03636                     || csym->native->u.syment.n_numaux < 1
03637                     || csym->native->u.syment.n_sclass != C_STAT
03638                     || csym->native->u.syment.n_type != T_NULL)
03639                   continue;
03640 
03641                 /* Here *PSYM is the section symbol for CURRENT.  */
03642 
03643                 break;
03644               }
03645            }
03646 
03647          /* Did we find it?
03648             Note that we might not if we're converting the file from
03649             some other object file format.  */
03650          if (i < count)
03651            {
03652              combined_entry_type *aux;
03653 
03654              /* We don't touch the x_checksum field.  The
03655                x_associated field is not currently supported.  */
03656 
03657              aux = csym->native + 1;
03658              switch (current->flags & SEC_LINK_DUPLICATES)
03659               {
03660               case SEC_LINK_DUPLICATES_DISCARD:
03661                 aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
03662                 break;
03663 
03664               case SEC_LINK_DUPLICATES_ONE_ONLY:
03665                 aux->u.auxent.x_scn.x_comdat =
03666                   IMAGE_COMDAT_SELECT_NODUPLICATES;
03667                 break;
03668 
03669               case SEC_LINK_DUPLICATES_SAME_SIZE:
03670                 aux->u.auxent.x_scn.x_comdat =
03671                   IMAGE_COMDAT_SELECT_SAME_SIZE;
03672                 break;
03673 
03674               case SEC_LINK_DUPLICATES_SAME_CONTENTS:
03675                 aux->u.auxent.x_scn.x_comdat =
03676                   IMAGE_COMDAT_SELECT_EXACT_MATCH;
03677                 break;
03678               }
03679 
03680              /* The COMDAT symbol must be the first symbol from this
03681                  section in the symbol table.  In order to make this
03682                  work, we move the COMDAT symbol before the first
03683                  symbol we found in the search above.  It's OK to
03684                  rearrange the symbol table at this point, because
03685                  coff_renumber_symbols is going to rearrange it
03686                  further and fix up all the aux entries.  */
03687              if (psym != psymsec)
03688               {
03689                 asymbol *hold;
03690                 asymbol **pcopy;
03691 
03692                 hold = *psym;
03693                 for (pcopy = psym; pcopy > psymsec; pcopy--)
03694                   pcopy[0] = pcopy[-1];
03695                 *psymsec = hold;
03696               }
03697            }
03698        }
03699 #endif /* COFF_WITH_PE */
03700     }
03701 
03702 #ifdef RS6000COFF_C
03703 #ifndef XCOFF64
03704   /* XCOFF handles overflows in the reloc and line number count fields
03705      by creating a new section header to hold the correct values.  */
03706   for (current = abfd->sections; current != NULL; current = current->next)
03707     {
03708       if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
03709        {
03710          struct internal_scnhdr scnhdr;
03711          SCNHDR buff;
03712          bfd_size_type amt;
03713 
03714          internal_f.f_nscns++;
03715          strncpy (&(scnhdr.s_name[0]), current->name, 8);
03716          scnhdr.s_paddr = current->reloc_count;
03717          scnhdr.s_vaddr = current->lineno_count;
03718          scnhdr.s_size = 0;
03719          scnhdr.s_scnptr = 0;
03720          scnhdr.s_relptr = current->rel_filepos;
03721          scnhdr.s_lnnoptr = current->line_filepos;
03722          scnhdr.s_nreloc = current->target_index;
03723          scnhdr.s_nlnno = current->target_index;
03724          scnhdr.s_flags = STYP_OVRFLO;
03725          amt = bfd_coff_scnhsz (abfd);
03726          if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
03727              || bfd_bwrite (& buff, amt, abfd) != amt)
03728            return FALSE;
03729        }
03730     }
03731 #endif
03732 #endif
03733 
03734   /* OK, now set up the filehdr...  */
03735 
03736   /* Don't include the internal abs section in the section count */
03737 
03738   /* We will NOT put a fucking timestamp in the header here. Every time you
03739      put it back, I will come in and take it out again.  I'm sorry.  This
03740      field does not belong here.  We fill it with a 0 so it compares the
03741      same but is not a reasonable time. -- gnu@cygnus.com  */
03742   internal_f.f_timdat = 0;
03743   internal_f.f_flags = 0;
03744 
03745   if (abfd->flags & EXEC_P)
03746     internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
03747   else
03748     {
03749       internal_f.f_opthdr = 0;
03750 #ifdef RS6000COFF_C
03751 #ifndef XCOFF64
03752       if (xcoff_data (abfd)->full_aouthdr)
03753        internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
03754       else
03755        internal_f.f_opthdr = SMALL_AOUTSZ;
03756 #endif
03757 #endif
03758     }
03759 
03760   if (!hasrelocs)
03761     internal_f.f_flags |= F_RELFLG;
03762   if (!haslinno)
03763     internal_f.f_flags |= F_LNNO;
03764   if (abfd->flags & EXEC_P)
03765     internal_f.f_flags |= F_EXEC;
03766 #ifdef COFF_IMAGE_WITH_PE
03767   if (! hasdebug)
03768     internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
03769   if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
03770     internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
03771 #endif
03772 
03773 #ifndef COFF_WITH_pex64
03774 #ifdef COFF_WITH_PE
03775   internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
03776 #else
03777   if (bfd_little_endian (abfd))
03778     internal_f.f_flags |= F_AR32WR;
03779   else
03780     internal_f.f_flags |= F_AR32W;
03781 #endif
03782 #endif
03783 
03784 #ifdef TI_TARGET_ID
03785   /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
03786      but it doesn't hurt to set it internally.  */
03787   internal_f.f_target_id = TI_TARGET_ID;
03788 #endif
03789 #ifdef TIC80_TARGET_ID
03790   internal_f.f_target_id = TIC80_TARGET_ID;
03791 #endif
03792 
03793   /* FIXME, should do something about the other byte orders and
03794      architectures.  */
03795 
03796 #ifdef RS6000COFF_C
03797   if ((abfd->flags & DYNAMIC) != 0)
03798     internal_f.f_flags |= F_SHROBJ;
03799   if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
03800     internal_f.f_flags |= F_DYNLOAD;
03801 #endif
03802 
03803   memset (&internal_a, 0, sizeof internal_a);
03804 
03805   /* Set up architecture-dependent stuff.  */
03806   {
03807     unsigned int magic = 0;
03808     unsigned short flags = 0;
03809 
03810     coff_set_flags (abfd, &magic, &flags);
03811     internal_f.f_magic = magic;
03812     internal_f.f_flags |= flags;
03813     /* ...and the "opt"hdr...  */
03814 
03815 #ifdef TICOFF_AOUT_MAGIC
03816     internal_a.magic = TICOFF_AOUT_MAGIC;
03817 #define __A_MAGIC_SET__
03818 #endif
03819 #ifdef TIC80COFF
03820     internal_a.magic = TIC80_ARCH_MAGIC;
03821 #define __A_MAGIC_SET__
03822 #endif /* TIC80 */
03823 #ifdef I860
03824     /* FIXME: What are the a.out magic numbers for the i860?  */
03825     internal_a.magic = 0;
03826 #define __A_MAGIC_SET__
03827 #endif /* I860 */
03828 #ifdef I960
03829     internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
03830 #define __A_MAGIC_SET__
03831 #endif /* I960 */
03832 #if M88
03833 #define __A_MAGIC_SET__
03834     internal_a.magic = PAGEMAGICBCS;
03835 #endif /* M88 */
03836 
03837 #if APOLLO_M68
03838 #define __A_MAGIC_SET__
03839     internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
03840 #endif
03841 
03842 #if defined(M68) || defined(WE32K) || defined(M68K)
03843 #define __A_MAGIC_SET__
03844 #if defined(LYNXOS)
03845     internal_a.magic = LYNXCOFFMAGIC;
03846 #else
03847 #if defined(TARG_AUX)
03848     internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED :
03849                      abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED :
03850                      PAGEMAGICEXECSWAPPED);
03851 #else
03852 #if defined (PAGEMAGICPEXECPAGED)
03853     internal_a.magic = PAGEMAGICPEXECPAGED;
03854 #endif
03855 #endif /* TARG_AUX */
03856 #endif /* LYNXOS */
03857 #endif /* M68 || WE32K || M68K */
03858 
03859 #if defined(ARM)
03860 #define __A_MAGIC_SET__
03861     internal_a.magic = ZMAGIC;
03862 #endif
03863 
03864 #if defined(PPC_PE)
03865 #define __A_MAGIC_SET__
03866     internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
03867 #endif
03868 
03869 #if defined MCORE_PE
03870 #define __A_MAGIC_SET__
03871     internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
03872 #endif
03873 
03874 #if defined(I386)
03875 #define __A_MAGIC_SET__
03876 #if defined LYNXOS
03877     internal_a.magic = LYNXCOFFMAGIC;
03878 #elif defined AMD64
03879     internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
03880 #else
03881     internal_a.magic = ZMAGIC;
03882 #endif
03883 #endif /* I386 */
03884 
03885 #if defined(IA64)
03886 #define __A_MAGIC_SET__
03887     internal_a.magic = PE32PMAGIC;
03888 #endif /* IA64 */
03889 
03890 #if defined(SPARC)
03891 #define __A_MAGIC_SET__
03892 #if defined(LYNXOS)
03893     internal_a.magic = LYNXCOFFMAGIC;
03894 #endif /* LYNXOS */
03895 #endif /* SPARC */
03896 
03897 #ifdef RS6000COFF_C
03898 #define __A_MAGIC_SET__
03899     internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
03900     (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
03901     RS6K_AOUTHDR_OMAGIC;
03902 #endif
03903 
03904 #if defined(SH) && defined(COFF_WITH_PE)
03905 #define __A_MAGIC_SET__
03906     internal_a.magic = SH_PE_MAGIC;
03907 #endif
03908 
03909 #if defined(MIPS) && defined(COFF_WITH_PE)
03910 #define __A_MAGIC_SET__
03911     internal_a.magic = MIPS_PE_MAGIC;
03912 #endif
03913 
03914 #ifdef OR32
03915 #define __A_MAGIC_SET__
03916     internal_a.magic = NMAGIC; /* Assume separate i/d.  */
03917 #endif
03918 
03919 #ifdef MAXQ20MAGIC
03920 #define __A_MAGIC_SET__
03921       internal_a.magic = MAXQ20MAGIC;
03922 #endif
03923  
03924 #ifndef __A_MAGIC_SET__
03925 #include "Your aouthdr magic number is not being set!"
03926 #else
03927 #undef __A_MAGIC_SET__
03928 #endif
03929   }
03930 
03931   /* FIXME: Does anybody ever set this to another value?  */
03932   internal_a.vstamp = 0;
03933 
03934   /* Now should write relocs, strings, syms.  */
03935   obj_sym_filepos (abfd) = sym_base;
03936 
03937   if (bfd_get_symcount (abfd) != 0)
03938     {
03939       int firstundef;
03940 
03941       if (!coff_renumber_symbols (abfd, &firstundef))
03942        return FALSE;
03943       coff_mangle_symbols (abfd);
03944       if (! coff_write_symbols (abfd))
03945        return FALSE;
03946       if (! coff_write_linenumbers (abfd))
03947        return FALSE;
03948       if (! coff_write_relocs (abfd, firstundef))
03949        return FALSE;
03950     }
03951 #ifdef COFF_LONG_SECTION_NAMES
03952   else if (long_section_names && ! obj_coff_strings_written (abfd))
03953     {
03954       /* If we have long section names we have to write out the string
03955          table even if there are no symbols.  */
03956       if (! coff_write_symbols (abfd))
03957        return FALSE;
03958     }
03959 #endif
03960 #ifdef COFF_IMAGE_WITH_PE
03961 #ifdef PPC_PE
03962   else if ((abfd->flags & EXEC_P) != 0)
03963     {
03964       bfd_byte b;
03965 
03966       /* PowerPC PE appears to require that all executable files be
03967          rounded up to the page size.  */
03968       b = 0;
03969       if (bfd_seek (abfd,
03970                   (file_ptr) BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
03971                   SEEK_SET) != 0
03972          || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
03973        return FALSE;
03974     }
03975 #endif
03976 #endif
03977 
03978   /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
03979      backend linker, and obj_raw_syment_count is not valid until after
03980      coff_write_symbols is called.  */
03981   if (obj_raw_syment_count (abfd) != 0)
03982     {
03983       internal_f.f_symptr = sym_base;
03984 #ifdef RS6000COFF_C
03985       /* AIX appears to require that F_RELFLG not be set if there are
03986          local symbols but no relocations.  */
03987       internal_f.f_flags &=~ F_RELFLG;
03988 #endif
03989     }
03990   else
03991     {
03992       if (long_section_names)
03993        internal_f.f_symptr = sym_base;
03994       else
03995        internal_f.f_symptr = 0;
03996       internal_f.f_flags |= F_LSYMS;
03997     }
03998 
03999   if (text_sec)
04000     {
04001       internal_a.tsize = text_sec->size;
04002       internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
04003     }
04004   if (data_sec)
04005     {
04006       internal_a.dsize = data_sec->size;
04007       internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
04008     }
04009   if (bss_sec)
04010     {
04011       internal_a.bsize = bss_sec->size;
04012       if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
04013        internal_a.data_start = bss_sec->vma;
04014     }
04015 
04016   internal_a.entry = bfd_get_start_address (abfd);
04017   internal_f.f_nsyms = obj_raw_syment_count (abfd);
04018 
04019 #ifdef RS6000COFF_C
04020   if (xcoff_data (abfd)->full_aouthdr)
04021     {
04022       bfd_vma toc;
04023       asection *loader_sec;
04024 
04025       internal_a.vstamp = 1;
04026 
04027       internal_a.o_snentry = xcoff_data (abfd)->snentry;
04028       if (internal_a.o_snentry == 0)
04029        internal_a.entry = (bfd_vma) -1;
04030 
04031       if (text_sec != NULL)
04032        {
04033          internal_a.o_sntext = text_sec->target_index;
04034          internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
04035        }
04036       else
04037        {
04038          internal_a.o_sntext = 0;
04039          internal_a.o_algntext = 0;
04040        }
04041       if (data_sec != NULL)
04042        {
04043          internal_a.o_sndata = data_sec->target_index;
04044          internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
04045        }
04046       else
04047        {
04048          internal_a.o_sndata = 0;
04049          internal_a.o_algndata = 0;
04050        }
04051       loader_sec = bfd_get_section_by_name (abfd, ".loader");
04052       if (loader_sec != NULL)
04053        internal_a.o_snloader = loader_sec->target_index;
04054       else
04055        internal_a.o_snloader = 0;
04056       if (bss_sec != NULL)
04057        internal_a.o_snbss = bss_sec->target_index;
04058       else
04059        internal_a.o_snbss = 0;
04060 
04061       toc = xcoff_data (abfd)->toc;
04062       internal_a.o_toc = toc;
04063       internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
04064 
04065       internal_a.o_modtype = xcoff_data (abfd)->modtype;
04066       if (xcoff_data (abfd)->cputype != -1)
04067        internal_a.o_cputype = xcoff_data (abfd)->cputype;
04068       else
04069        {
04070          switch (bfd_get_arch (abfd))
04071            {
04072            case bfd_arch_rs6000:
04073              internal_a.o_cputype = 4;
04074              break;
04075            case bfd_arch_powerpc:
04076              if (bfd_get_mach (abfd) == bfd_mach_ppc)
04077               internal_a.o_cputype = 3;
04078              else
04079               internal_a.o_cputype = 1;
04080              break;
04081            default:
04082              abort ();
04083            }
04084        }
04085       internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
04086       internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
04087     }
04088 #endif
04089 
04090   /* Now write them.  */
04091   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
04092     return FALSE;
04093 
04094   {
04095     char * buff;
04096     bfd_size_type amount = bfd_coff_filhsz (abfd);
04097 
04098     buff = bfd_malloc (amount);
04099     if (buff == NULL)
04100       return FALSE;
04101 
04102     bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
04103     amount = bfd_bwrite (buff, amount, abfd);
04104 
04105     free (buff);
04106 
04107     if (amount != bfd_coff_filhsz (abfd))
04108       return FALSE;
04109   }
04110 
04111   if (abfd->flags & EXEC_P)
04112     {
04113       /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
04114         include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
04115       char * buff;
04116       bfd_size_type amount = bfd_coff_aoutsz (abfd);
04117 
04118       buff = bfd_malloc (amount);
04119       if (buff == NULL)
04120        return FALSE;
04121 
04122       coff_swap_aouthdr_out (abfd, & internal_a, buff);
04123       amount = bfd_bwrite (buff, amount, abfd);
04124 
04125       free (buff);
04126 
04127       if (amount != bfd_coff_aoutsz (abfd))
04128        return FALSE;
04129 
04130 #ifdef COFF_IMAGE_WITH_PE
04131       if (! coff_apply_checksum (abfd))
04132        return FALSE;
04133 #endif
04134     }
04135 #ifdef RS6000COFF_C
04136   else
04137     {
04138       AOUTHDR buff;
04139       size_t size;
04140 
04141       /* XCOFF seems to always write at least a small a.out header.  */
04142       coff_swap_aouthdr_out (abfd, & internal_a, & buff);
04143       if (xcoff_data (abfd)->full_aouthdr)
04144        size = bfd_coff_aoutsz (abfd);
04145       else
04146        size = SMALL_AOUTSZ;
04147       if (bfd_bwrite (& buff, (bfd_size_type) size, abfd) != size)
04148        return FALSE;
04149     }
04150 #endif
04151 
04152   return TRUE;
04153 }
04154 
04155 static bfd_boolean
04156 coff_set_section_contents (bfd * abfd,
04157                         sec_ptr section,
04158                         const void * location,
04159                         file_ptr offset,
04160                         bfd_size_type count)
04161 {
04162   if (! abfd->output_has_begun)    /* Set by bfd.c handler.  */
04163     {
04164       if (! coff_compute_section_file_positions (abfd))
04165        return FALSE;
04166     }
04167 
04168 #if defined(_LIB) && !defined(TARG_AUX)
04169    /* The physical address field of a .lib section is used to hold the
04170       number of shared libraries in the section.  This code counts the
04171       number of sections being written, and increments the lma field
04172       with the number.
04173 
04174       I have found no documentation on the contents of this section.
04175       Experimentation indicates that the section contains zero or more
04176       records, each of which has the following structure:
04177 
04178       - a (four byte) word holding the length of this record, in words,
04179       - a word that always seems to be set to "2",
04180       - the path to a shared library, null-terminated and then padded
04181         to a whole word boundary.
04182 
04183       bfd_assert calls have been added to alert if an attempt is made
04184       to write a section which doesn't follow these assumptions.  The
04185       code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
04186       <robertl@arnet.com> (Thanks!).
04187 
04188       Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
04189     if (strcmp (section->name, _LIB) == 0)
04190       {
04191        bfd_byte *rec, *recend;
04192 
04193        rec = (bfd_byte *) location;
04194        recend = rec + count;
04195        while (rec < recend)
04196          {
04197            ++section->lma;
04198            rec += bfd_get_32 (abfd, rec) * 4;
04199          }
04200 
04201        BFD_ASSERT (rec == recend);
04202       }
04203 #endif
04204 
04205   /* Don't write out bss sections - one way to do this is to
04206        see if the filepos has not been set.  */
04207   if (section->filepos == 0)
04208     return TRUE;
04209 
04210   if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
04211     return FALSE;
04212 
04213   if (count == 0)
04214     return TRUE;
04215 
04216   return bfd_bwrite (location, count, abfd) == count;
04217 }
04218 
04219 static void *
04220 buy_and_read (bfd *abfd, file_ptr where, bfd_size_type size)
04221 {
04222   void * area = bfd_alloc (abfd, size);
04223 
04224   if (!area)
04225     return (NULL);
04226   if (bfd_seek (abfd, where, SEEK_SET) != 0
04227       || bfd_bread (area, size, abfd) != size)
04228     return (NULL);
04229   return (area);
04230 }
04231 
04232 /*
04233 SUBSUBSECTION
04234        Reading linenumbers
04235 
04236        Creating the linenumber table is done by reading in the entire
04237        coff linenumber table, and creating another table for internal use.
04238 
04239        A coff linenumber table is structured so that each function
04240        is marked as having a line number of 0. Each line within the
04241        function is an offset from the first line in the function. The
04242        base of the line number information for the table is stored in
04243        the symbol associated with the function.
04244 
04245        Note: The PE format uses line number 0 for a flag indicating a
04246        new source file.
04247 
04248        The information is copied from the external to the internal
04249        table, and each symbol which marks a function is marked by
04250        pointing its...
04251 
04252        How does this work ?
04253 */
04254 
04255 static bfd_boolean
04256 coff_slurp_line_table (bfd *abfd, asection *asect)
04257 {
04258   LINENO *native_lineno;
04259   alent *lineno_cache;
04260   bfd_size_type amt;
04261 
04262   BFD_ASSERT (asect->lineno == NULL);
04263 
04264   amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
04265   native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
04266   if (native_lineno == NULL)
04267     {
04268       (*_bfd_error_handler)
04269         (_("%B: warning: line number table read failed"), abfd);
04270       return FALSE;
04271     }
04272   amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
04273   lineno_cache = bfd_alloc (abfd, amt);
04274   if (lineno_cache == NULL)
04275     return FALSE;
04276   else
04277     {
04278       unsigned int counter = 0;
04279       alent *cache_ptr = lineno_cache;
04280       LINENO *src = native_lineno;
04281 
04282       while (counter < asect->lineno_count)
04283        {
04284          struct internal_lineno dst;
04285 
04286          bfd_coff_swap_lineno_in (abfd, src, &dst);
04287          cache_ptr->line_number = dst.l_lnno;
04288 
04289          if (cache_ptr->line_number == 0)
04290            {
04291              bfd_boolean warned;
04292              bfd_signed_vma symndx;
04293              coff_symbol_type *sym;
04294 
04295              warned = FALSE;
04296              symndx = dst.l_addr.l_symndx;
04297              if (symndx < 0
04298                 || (bfd_vma) symndx >= obj_raw_syment_count (abfd))
04299               {
04300                 (*_bfd_error_handler)
04301                   (_("%B: warning: illegal symbol index %ld in line numbers"),
04302                    abfd, dst.l_addr.l_symndx);
04303                 symndx = 0;
04304                 warned = TRUE;
04305               }
04306              /* FIXME: We should not be casting between ints and
04307                  pointers like this.  */
04308              sym = ((coff_symbol_type *)
04309                    ((symndx + obj_raw_syments (abfd))
04310                     ->u.syment._n._n_n._n_zeroes));
04311              cache_ptr->u.sym = (asymbol *) sym;
04312              if (sym->lineno != NULL && ! warned)
04313               {
04314                 (*_bfd_error_handler)
04315                   (_("%B: warning: duplicate line number information for `%s'"),
04316                    abfd, bfd_asymbol_name (&sym->symbol));
04317               }
04318              sym->lineno = cache_ptr;
04319            }
04320          else
04321            cache_ptr->u.offset = dst.l_addr.l_paddr
04322              - bfd_section_vma (abfd, asect);
04323 
04324          cache_ptr++;
04325          src++;
04326          counter++;
04327        }
04328       cache_ptr->line_number = 0;
04329 
04330     }
04331   asect->lineno = lineno_cache;
04332   /* FIXME, free native_lineno here, or use alloca or something.  */
04333   return TRUE;
04334 }
04335 
04336 /* Slurp in the symbol table, converting it to generic form.  Note
04337    that if coff_relocate_section is defined, the linker will read
04338    symbols via coff_link_add_symbols, rather than via this routine.  */
04339 
04340 static bfd_boolean
04341 coff_slurp_symbol_table (bfd * abfd)
04342 {
04343   combined_entry_type *native_symbols;
04344   coff_symbol_type *cached_area;
04345   unsigned int *table_ptr;
04346   bfd_size_type amt;
04347   unsigned int number_of_symbols = 0;
04348 
04349   if (obj_symbols (abfd))
04350     return TRUE;
04351 
04352   /* Read in the symbol table.  */
04353   if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
04354     return FALSE;
04355 
04356   /* Allocate enough room for all the symbols in cached form.  */
04357   amt = obj_raw_syment_count (abfd);
04358   amt *= sizeof (coff_symbol_type);
04359   cached_area = bfd_alloc (abfd, amt);
04360   if (cached_area == NULL)
04361     return FALSE;
04362 
04363   amt = obj_raw_syment_count (abfd);
04364   amt *= sizeof (unsigned int);
04365   table_ptr = bfd_alloc (abfd, amt);
04366 
04367   if (table_ptr == NULL)
04368     return FALSE;
04369   else
04370     {
04371       coff_symbol_type *dst = cached_area;
04372       unsigned int last_native_index = obj_raw_syment_count (abfd);
04373       unsigned int this_index = 0;
04374 
04375       while (this_index < last_native_index)
04376        {
04377          combined_entry_type *src = native_symbols + this_index;
04378          table_ptr[this_index] = number_of_symbols;
04379          dst->symbol.the_bfd = abfd;
04380 
04381          dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
04382          /* We use the native name field to point to the cached field.  */
04383          src->u.syment._n._n_n._n_zeroes = (long) dst;
04384          dst->symbol.section = coff_section_from_bfd_index (abfd,
04385                                                src->u.syment.n_scnum);
04386          dst->symbol.flags = 0;
04387          dst->done_lineno = FALSE;
04388 
04389          switch (src->u.syment.n_sclass)
04390            {
04391 #ifdef I960
04392            case C_LEAFEXT:
04393              /* Fall through to next case.  */
04394 #endif
04395 
04396            case C_EXT:
04397            case C_WEAKEXT:
04398 #if defined ARM
04399             case C_THUMBEXT:
04400             case C_THUMBEXTFUNC:
04401 #endif
04402 #ifdef RS6000COFF_C
04403            case C_HIDEXT:
04404 #endif
04405 #ifdef C_SYSTEM
04406            case C_SYSTEM:   /* System Wide variable.  */
04407 #endif
04408 #ifdef COFF_WITH_PE
04409             /* In PE, 0x68 (104) denotes a section symbol.  */
04410             case C_SECTION:
04411            /* In PE, 0x69 (105) denotes a weak external symbol.  */
04412            case C_NT_WEAK:
04413 #endif
04414              switch (coff_classify_symbol (abfd, &src->u.syment))
04415               {
04416               case COFF_SYMBOL_GLOBAL:
04417                 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
04418 #if defined COFF_WITH_PE
04419                 /* PE sets the symbol to a value relative to the
04420                      start of the section.  */
04421                 dst->symbol.value = src->u.syment.n_value;
04422 #else
04423                 dst->symbol.value = (src->u.syment.n_value
04424                                    - dst->symbol.section->vma);
04425 #endif
04426                 if (ISFCN ((src->u.syment.n_type)))
04427                   /* A function ext does not go at the end of a
04428                      file.  */
04429                   dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
04430                 break;
04431 
04432               case COFF_SYMBOL_COMMON:
04433                 dst->symbol.section = bfd_com_section_ptr;
04434                 dst->symbol.value = src->u.syment.n_value;
04435                 break;
04436 
04437               case COFF_SYMBOL_UNDEFINED:
04438                 dst->symbol.section = bfd_und_section_ptr;
04439                 dst->symbol.value = 0;
04440                 break;
04441 
04442               case COFF_SYMBOL_PE_SECTION:
04443                 dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
04444                 dst->symbol.value = 0;
04445                 break;
04446 
04447               case COFF_SYMBOL_LOCAL:
04448                 dst->symbol.flags = BSF_LOCAL;
04449 #if defined COFF_WITH_PE
04450                 /* PE sets the symbol to a value relative to the
04451                      start of the section.  */
04452                 dst->symbol.value = src->u.syment.n_value;
04453 #else
04454                 dst->symbol.value = (src->u.syment.n_value
04455                                    - dst->symbol.section->vma);
04456 #endif
04457                 if (ISFCN ((src->u.syment.n_type)))
04458                   dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
04459                 break;
04460               }
04461 
04462 #ifdef RS6000COFF_C
04463              /* A symbol with a csect entry should not go at the end.  */
04464              if (src->u.syment.n_numaux > 0)
04465               dst->symbol.flags |= BSF_NOT_AT_END;
04466 #endif
04467 
04468 #ifdef COFF_WITH_PE
04469              if (src->u.syment.n_sclass == C_NT_WEAK)
04470               dst->symbol.flags |= BSF_WEAK;
04471 
04472              if (src->u.syment.n_sclass == C_SECTION
04473                 && src->u.syment.n_scnum > 0)
04474               dst->symbol.flags = BSF_LOCAL;
04475 #endif
04476              if (src->u.syment.n_sclass == C_WEAKEXT)
04477               dst->symbol.flags |= BSF_WEAK;
04478 
04479              break;
04480 
04481            case C_STAT:      /* Static.  */
04482 #ifdef I960
04483            case C_LEAFSTAT:  /* Static leaf procedure.  */
04484 #endif
04485 #if defined ARM
04486             case C_THUMBSTAT:    /* Thumb static.  */
04487             case C_THUMBLABEL:   /* Thumb label.  */
04488             case C_THUMBSTATFUNC:/* Thumb static function.  */
04489 #endif
04490            case C_LABEL:     /* Label.  */
04491              if (src->u.syment.n_scnum == N_DEBUG)
04492               dst->symbol.flags = BSF_DEBUGGING;
04493              else
04494               dst->symbol.flags = BSF_LOCAL;
04495 
04496              /* Base the value as an index from the base of the
04497                section, if there is one.  */
04498              if (dst->symbol.section)
04499               {
04500 #if defined COFF_WITH_PE
04501                 /* PE sets the symbol to a value relative to the
04502                      start of the section.  */
04503                 dst->symbol.value = src->u.syment.n_value;
04504 #else
04505                 dst->symbol.value = (src->u.syment.n_value
04506                                    - dst->symbol.section->vma);
04507 #endif
04508               }
04509              else
04510               dst->symbol.value = src->u.syment.n_value;
04511              break;
04512 
04513            case C_MOS:             /* Member of structure.  */
04514            case C_EOS:             /* End of structure.  */
04515            case C_REGPARM:  /* Register parameter.  */
04516            case C_REG:             /* register variable.  */
04517               /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
04518 #if !defined (TIC80COFF) && !defined (TICOFF)
04519 #ifdef C_AUTOARG
04520            case C_AUTOARG:  /* 960-specific storage class.  */
04521 #endif
04522 #endif
04523            case C_TPDEF:    /* Type definition.  */
04524            case C_ARG:
04525            case C_AUTO:     /* Automatic variable.  */
04526            case C_FIELD:    /* Bit field.  */
04527            case C_ENTAG:    /* Enumeration tag.  */
04528            case C_MOE:             /* Member of enumeration.  */
04529            case C_MOU:             /* Member of union.  */
04530            case C_UNTAG:    /* Union tag.  */
04531              dst->symbol.flags = BSF_DEBUGGING;
04532              dst->symbol.value = (src->u.syment.n_value);
04533              break;
04534 
04535            case C_FILE:     /* File name.  */
04536            case C_STRTAG:   /* Structure tag.  */
04537 #ifdef RS6000COFF_C
04538            case C_GSYM:
04539            case C_LSYM:
04540            case C_PSYM:
04541            case C_RSYM:
04542            case C_RPSYM:
04543            case C_STSYM:
04544            case C_TCSYM:
04545            case C_BCOMM:
04546            case C_ECOML:
04547            case C_ECOMM:
04548            case C_DECL:
04549            case C_ENTRY:
04550            case C_FUN:
04551            case C_ESTAT:
04552 #endif
04553              dst->symbol.flags = BSF_DEBUGGING;
04554              dst->symbol.value = (src->u.syment.n_value);
04555              break;
04556 
04557 #ifdef RS6000COFF_C
04558            case C_BINCL:    /* Beginning of include file.  */
04559            case C_EINCL:    /* Ending of include file.  */
04560              /* The value is actually a pointer into the line numbers
04561                  of the file.  We locate the line number entry, and
04562                  set the section to the section which contains it, and
04563                  the value to the index in that section.  */
04564              {
04565               asection *sec;
04566 
04567               dst->symbol.flags = BSF_DEBUGGING;
04568               for (sec = abfd->sections; sec != NULL; sec = sec->next)
04569                 if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
04570                     && ((file_ptr) (sec->line_filepos
04571                                   + sec->lineno_count * bfd_coff_linesz (abfd))
04572                        > (file_ptr) src->u.syment.n_value))
04573                   break;
04574               if (sec == NULL)
04575                 dst->symbol.value = 0;
04576               else
04577                 {
04578                   dst->symbol.section = sec;
04579                   dst->symbol.value = ((src->u.syment.n_value
04580                                      - sec->line_filepos)
04581                                     / bfd_coff_linesz (abfd));
04582                   src->fix_line = 1;
04583                 }
04584              }
04585              break;
04586 
04587            case C_BSTAT:
04588              dst->symbol.flags = BSF_DEBUGGING;
04589 
04590              /* The value is actually a symbol index.  Save a pointer
04591                to the symbol instead of the index.  FIXME: This
04592                should use a union.  */
04593              src->u.syment.n_value =
04594               (long) (native_symbols + src->u.syment.n_value);
04595              dst->symbol.value = src->u.syment.n_value;
04596              src->fix_value = 1;
04597              break;
04598 #endif
04599 
04600            case C_BLOCK:    /* ".bb" or ".eb".  */
04601            case C_FCN:             /* ".bf" or ".ef" (or PE ".lf").  */
04602            case C_EFCN:     /* Physical end of function.  */
04603 #if defined COFF_WITH_PE
04604              /* PE sets the symbol to a value relative to the start
04605                of the section.  */
04606              dst->symbol.value = src->u.syment.n_value;
04607              if (strcmp (dst->symbol.name, ".bf") != 0)
04608               {
04609                 /* PE uses funny values for .ef and .lf; don't
04610                      relocate them.  */
04611                 dst->symbol.flags = BSF_DEBUGGING;
04612               }
04613              else
04614               dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
04615 #else
04616              /* Base the value as an index from the base of the
04617                section.  */
04618              dst->symbol.flags = BSF_LOCAL;
04619              dst->symbol.value = (src->u.syment.n_value
04620                                - dst->symbol.section->vma);
04621 #endif
04622              break;
04623 
04624            case C_STATLAB:  /* Static load time label.  */
04625               dst->symbol.value = src->u.syment.n_value;
04626               dst->symbol.flags = BSF_GLOBAL;
04627               break;
04628 
04629            case C_NULL:
04630              /* PE DLLs sometimes have zeroed out symbols for some
04631                  reason.  Just ignore them without a warning.  */
04632              if (src->u.syment.n_type == 0
04633                 && src->u.syment.n_value == 0
04634                 && src->u.syment.n_scnum == 0)
04635               break;
04636              /* Fall through.  */
04637            case C_EXTDEF:   /* External definition.  */
04638            case C_ULABEL:   /* Undefined label.  */
04639            case C_USTATIC:  /* Undefined static.  */
04640 #ifndef COFF_WITH_PE
04641             /* C_LINE in regular coff is 0x68.  NT has taken over this storage
04642                class to represent a section symbol.  */
04643            case C_LINE:     /* line # reformatted as symbol table entry.  */
04644              /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
04645            case C_ALIAS:    /* Duplicate tag.  */
04646 #endif
04647              /* New storage classes for TI COFF.  */
04648 #if defined(TIC80COFF) || defined(TICOFF)
04649            case C_UEXT:     /* Tentative external definition.  */
04650 #endif
04651            case C_EXTLAB:   /* External load time label.  */
04652            case C_HIDDEN:   /* Ext symbol in dmert public lib.  */
04653            default:
04654              (*_bfd_error_handler)
04655               (_("%B: Unrecognized storage class %d for %s symbol `%s'"),
04656                abfd, src->u.syment.n_sclass,
04657                dst->symbol.section->name, dst->symbol.name);
04658              dst->symbol.flags = BSF_DEBUGGING;
04659              dst->symbol.value = (src->u.syment.n_value);
04660              break;
04661            }
04662 
04663          dst->native = src;
04664 
04665          dst->symbol.udata.i = 0;
04666          dst->lineno = NULL;
04667          this_index += (src->u.syment.n_numaux) + 1;
04668          dst++;
04669          number_of_symbols++;
04670        }
04671     }
04672 
04673   obj_symbols (abfd) = cached_area;
04674   obj_raw_syments (abfd) = native_symbols;
04675 
04676   bfd_get_symcount (abfd) = number_of_symbols;
04677   obj_convert (abfd) = table_ptr;
04678   /* Slurp the line tables for each section too.  */
04679   {
04680     asection *p;
04681 
04682     p = abfd->sections;
04683     while (p)
04684       {
04685        coff_slurp_line_table (abfd, p);
04686        p = p->next;
04687       }
04688   }
04689 
04690   return TRUE;
04691 }
04692 
04693 /* Classify a COFF symbol.  A couple of targets have globally visible
04694    symbols which are not class C_EXT, and this handles those.  It also
04695    recognizes some special PE cases.  */
04696 
04697 static enum coff_symbol_classification
04698 coff_classify_symbol (bfd *abfd,
04699                     struct internal_syment *syment)
04700 {
04701   /* FIXME: This partially duplicates the switch in
04702      coff_slurp_symbol_table.  */
04703   switch (syment->n_sclass)
04704     {
04705     case C_EXT:
04706     case C_WEAKEXT:
04707 #ifdef I960
04708     case C_LEAFEXT:
04709 #endif
04710 #ifdef ARM
04711     case C_THUMBEXT:
04712     case C_THUMBEXTFUNC:
04713 #endif
04714 #ifdef C_SYSTEM
04715     case C_SYSTEM:
04716 #endif
04717 #ifdef COFF_WITH_PE
04718     case C_NT_WEAK:
04719 #endif
04720       if (syment->n_scnum == 0)
04721        {
04722          if (syment->n_value == 0)
04723            return COFF_SYMBOL_UNDEFINED;
04724          else
04725            return COFF_SYMBOL_COMMON;
04726        }
04727       return COFF_SYMBOL_GLOBAL;
04728 
04729     default:
04730       break;
04731     }
04732 
04733 #ifdef COFF_WITH_PE
04734   if (syment->n_sclass == C_STAT)
04735     {
04736       if (syment->n_scnum == 0)
04737        /* The Microsoft compiler sometimes generates these if a
04738           small static function is inlined every time it is used.
04739           The function is discarded, but the symbol table entry
04740           remains.  */
04741        return COFF_SYMBOL_LOCAL;
04742 
04743 #ifdef STRICT_PE_FORMAT
04744       /* This is correct for Microsoft generated objects, but it
04745          breaks gas generated objects.  */
04746       if (syment->n_value == 0)
04747        {
04748          asection *sec;
04749          char buf[SYMNMLEN + 1];
04750 
04751          sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
04752          if (sec != NULL
04753              && (strcmp (bfd_get_section_name (abfd, sec),
04754                        _bfd_coff_internal_syment_name (abfd, syment, buf))
04755                 == 0))
04756            return COFF_SYMBOL_PE_SECTION;
04757        }
04758 #endif
04759 
04760       return COFF_SYMBOL_LOCAL;
04761     }
04762 
04763   if (syment->n_sclass == C_SECTION)
04764     {
04765       /* In some cases in a DLL generated by the Microsoft linker, the
04766          n_value field will contain garbage.  FIXME: This should
04767          probably be handled by the swapping function instead.  */
04768       syment->n_value = 0;
04769       if (syment->n_scnum == 0)
04770        return COFF_SYMBOL_UNDEFINED;
04771       return COFF_SYMBOL_PE_SECTION;
04772     }
04773 #endif /* COFF_WITH_PE */
04774 
04775   /* If it is not a global symbol, we presume it is a local symbol.  */
04776   if (syment->n_scnum == 0)
04777     {
04778       char buf[SYMNMLEN + 1];
04779 
04780       (*_bfd_error_handler)
04781        (_("warning: %B: local symbol `%s' has no section"),
04782         abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
04783     }
04784 
04785   return COFF_SYMBOL_LOCAL;
04786 }
04787 
04788 /*
04789 SUBSUBSECTION
04790        Reading relocations
04791 
04792        Coff relocations are easily transformed into the internal BFD form
04793        (@code{arelent}).
04794 
04795        Reading a coff relocation table is done in the following stages:
04796 
04797        o Read the entire coff relocation table into memory.
04798 
04799        o Process each relocation in turn; first swap it from the
04800        external to the internal form.
04801 
04802        o Turn the symbol referenced in the relocation's symbol index
04803        into a pointer into the canonical symbol table.
04804        This table is the same as the one returned by a call to
04805        @code{bfd_canonicalize_symtab}. The back end will call that
04806        routine and save the result if a canonicalization hasn't been done.
04807 
04808        o The reloc index is turned into a pointer to a howto
04809        structure, in a back end specific way. For instance, the 386
04810        and 960 use the @code{r_type} to directly produce an index
04811        into a howto table vector; the 88k subtracts a number from the
04812        @code{r_type} field and creates an addend field.
04813 */
04814 
04815 #ifndef CALC_ADDEND
04816 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)                \
04817   {                                                             \
04818     coff_symbol_type *coffsym = NULL;                          \
04819                                                                 \
04820     if (ptr && bfd_asymbol_bfd (ptr) != abfd)                   \
04821       coffsym = (obj_symbols (abfd)                             \
04822                  + (cache_ptr->sym_ptr_ptr - symbols));         \
04823     else if (ptr)                                               \
04824       coffsym = coff_symbol_from (abfd, ptr);                   \
04825     if (coffsym != NULL                                          \
04826         && coffsym->native->u.syment.n_scnum == 0)              \
04827       cache_ptr->addend = 0;                                    \
04828     else if (ptr && bfd_asymbol_bfd (ptr) == abfd               \
04829              && ptr->section != NULL)                            \
04830       cache_ptr->addend = - (ptr->section->vma + ptr->value);   \
04831     else                                                        \
04832       cache_ptr->addend = 0;                                    \
04833   }
04834 #endif
04835 
04836 static bfd_boolean
04837 coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
04838 {
04839   RELOC *native_relocs;
04840   arelent *reloc_cache;
04841   arelent *cache_ptr;
04842   unsigned int idx;
04843   bfd_size_type amt;
04844 
04845   if (asect->relocation)
04846     return TRUE;
04847   if (asect->reloc_count == 0)
04848     return TRUE;
04849   if (asect->flags & SEC_CONSTRUCTOR)
04850     return TRUE;
04851   if (!coff_slurp_symbol_table (abfd))
04852     return FALSE;
04853 
04854   amt = (bfd_size_type) bfd_coff_relsz (abfd) * asect->reloc_count;
04855   native_relocs = (RELOC *) buy_and_read (abfd, asect->rel_filepos, amt);
04856   amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
04857   reloc_cache = bfd_alloc (abfd, amt);
04858 
04859   if (reloc_cache == NULL || native_relocs == NULL)
04860     return FALSE;
04861 
04862   for (idx = 0; idx < asect->reloc_count; idx++)
04863     {
04864       struct internal_reloc dst;
04865       struct external_reloc *src;
04866 #ifndef RELOC_PROCESSING
04867       asymbol *ptr;
04868 #endif
04869 
04870       cache_ptr = reloc_cache + idx;
04871       src = native_relocs + idx;
04872 
04873       coff_swap_reloc_in (abfd, src, &dst);
04874 
04875 #ifdef RELOC_PROCESSING
04876       RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
04877 #else
04878       cache_ptr->address = dst.r_vaddr;
04879 
04880       if (dst.r_symndx != -1)
04881        {
04882          if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
04883            {
04884              (*_bfd_error_handler)
04885               (_("%B: warning: illegal symbol index %ld in relocs"),
04886                abfd, dst.r_symndx);
04887              cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
04888              ptr = NULL;
04889            }
04890          else
04891            {
04892              cache_ptr->sym_ptr_ptr = (symbols
04893                                    + obj_convert (abfd)[dst.r_symndx]);
04894              ptr = *(cache_ptr->sym_ptr_ptr);
04895            }
04896        }
04897       else
04898        {
04899          cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
04900          ptr = NULL;
04901        }
04902 
04903       /* The symbols definitions that we have read in have been
04904         relocated as if their sections started at 0. But the offsets
04905         refering to the symbols in the raw data have not been
04906         modified, so we have to have a negative addend to compensate.
04907 
04908         Note that symbols which used to be common must be left alone.  */
04909 
04910       /* Calculate any reloc addend by looking at the symbol.  */
04911       CALC_ADDEND (abfd, ptr, dst, cache_ptr);
04912 
04913       cache_ptr->address -= asect->vma;
04914       /* !! cache_ptr->section = NULL;*/
04915 
04916       /* Fill in the cache_ptr->howto field from dst.r_type.  */
04917       RTYPE2HOWTO (cache_ptr, &dst);
04918 #endif /* RELOC_PROCESSING */
04919 
04920       if (cache_ptr->howto == NULL)
04921        {
04922          (*_bfd_error_handler)
04923            (_("%B: illegal relocation type %d at address 0x%lx"),
04924             abfd, dst.r_type, (long) dst.r_vaddr);
04925          bfd_set_error (bfd_error_bad_value);
04926          return FALSE;
04927        }
04928     }
04929 
04930   asect->relocation = reloc_cache;
04931   return TRUE;
04932 }
04933 
04934 #ifndef coff_rtype_to_howto
04935 #ifdef RTYPE2HOWTO
04936 
04937 /* Get the howto structure for a reloc.  This is only used if the file
04938    including this one defines coff_relocate_section to be
04939    _bfd_coff_generic_relocate_section, so it is OK if it does not
04940    always work.  It is the responsibility of the including file to
04941    make sure it is reasonable if it is needed.  */
04942 
04943 static reloc_howto_type *
04944 coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
04945                    asection *sec ATTRIBUTE_UNUSED,
04946                    struct internal_reloc *rel,
04947                    struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
04948                    struct internal_syment *sym ATTRIBUTE_UNUSED,
04949                    bfd_vma *addendp ATTRIBUTE_UNUSED)
04950 {
04951   arelent genrel;
04952 
04953   RTYPE2HOWTO (&genrel, rel);
04954   return genrel.howto;
04955 }
04956 
04957 #else /* ! defined (RTYPE2HOWTO) */
04958 
04959 #define coff_rtype_to_howto NULL
04960 
04961 #endif /* ! defined (RTYPE2HOWTO) */
04962 #endif /* ! defined (coff_rtype_to_howto) */
04963 
04964 /* This is stupid.  This function should be a boolean predicate.  */
04965 
04966 static long
04967 coff_canonicalize_reloc (bfd * abfd,
04968                       sec_ptr section,
04969                       arelent ** relptr,
04970                       asymbol ** symbols)
04971 {
04972   arelent *tblptr = section->relocation;
04973   unsigned int count = 0;
04974 
04975   if (section->flags & SEC_CONSTRUCTOR)
04976     {
04977       /* This section has relocs made up by us, they are not in the
04978         file, so take them out of their chain and place them into
04979         the data area provided.  */
04980       arelent_chain *chain = section->constructor_chain;
04981 
04982       for (count = 0; count < section->reloc_count; count++)
04983        {
04984          *relptr++ = &chain->relent;
04985          chain = chain->next;
04986        }
04987     }
04988   else
04989     {
04990       if (! coff_slurp_reloc_table (abfd, section, symbols))
04991        return -1;
04992 
04993       tblptr = section->relocation;
04994 
04995       for (; count++ < section->reloc_count;)
04996        *relptr++ = tblptr++;
04997     }
04998   *relptr = 0;
04999   return section->reloc_count;
05000 }
05001 
05002 #ifndef coff_reloc16_estimate
05003 #define coff_reloc16_estimate dummy_reloc16_estimate
05004 
05005 static int
05006 dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED,
05007                      asection *input_section ATTRIBUTE_UNUSED,
05008                      arelent *reloc ATTRIBUTE_UNUSED,
05009                      unsigned int shrink ATTRIBUTE_UNUSED,
05010                      struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
05011 {
05012   abort ();
05013   return 0;
05014 }
05015 
05016 #endif
05017 
05018 #ifndef coff_reloc16_extra_cases
05019 
05020 #define coff_reloc16_extra_cases dummy_reloc16_extra_cases
05021 
05022 /* This works even if abort is not declared in any header file.  */
05023 
05024 static void
05025 dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
05026                         struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
05027                         struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
05028                         arelent *reloc ATTRIBUTE_UNUSED,
05029                         bfd_byte *data ATTRIBUTE_UNUSED,
05030                         unsigned int *src_ptr ATTRIBUTE_UNUSED,
05031                         unsigned int *dst_ptr ATTRIBUTE_UNUSED)
05032 {
05033   abort ();
05034 }
05035 #endif
05036 
05037 #ifndef coff_bfd_link_hash_table_free
05038 #define coff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
05039 #endif
05040 
05041 /* If coff_relocate_section is defined, we can use the optimized COFF
05042    backend linker.  Otherwise we must continue to use the old linker.  */
05043 
05044 #ifdef coff_relocate_section
05045 
05046 #ifndef coff_bfd_link_hash_table_create
05047 #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
05048 #endif
05049 #ifndef coff_bfd_link_add_symbols
05050 #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
05051 #endif
05052 #ifndef coff_bfd_final_link
05053 #define coff_bfd_final_link _bfd_coff_final_link
05054 #endif
05055 
05056 #else /* ! defined (coff_relocate_section) */
05057 
05058 #define coff_relocate_section NULL
05059 #ifndef coff_bfd_link_hash_table_create
05060 #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
05061 #endif
05062 #ifndef coff_bfd_link_add_symbols
05063 #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
05064 #endif
05065 #define coff_bfd_final_link _bfd_generic_final_link
05066 
05067 #endif /* ! defined (coff_relocate_section) */
05068 
05069 #define coff_bfd_link_just_syms      _bfd_generic_link_just_syms
05070 #define coff_bfd_link_split_section  _bfd_generic_link_split_section
05071 
05072 #ifndef coff_start_final_link
05073 #define coff_start_final_link NULL
05074 #endif
05075 
05076 #ifndef coff_adjust_symndx
05077 #define coff_adjust_symndx NULL
05078 #endif
05079 
05080 #ifndef coff_link_add_one_symbol
05081 #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
05082 #endif
05083 
05084 #ifndef coff_link_output_has_begun
05085 
05086 static bfd_boolean
05087 coff_link_output_has_begun (bfd * abfd,
05088                          struct coff_final_link_info * info ATTRIBUTE_UNUSED)
05089 {
05090   return abfd->output_has_begun;
05091 }
05092 #endif
05093 
05094 #ifndef coff_final_link_postscript
05095 
05096 static bfd_boolean
05097 coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
05098                          struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)
05099 {
05100   return TRUE;
05101 }
05102 #endif
05103 
05104 #ifndef coff_SWAP_aux_in
05105 #define coff_SWAP_aux_in coff_swap_aux_in
05106 #endif
05107 #ifndef coff_SWAP_sym_in
05108 #define coff_SWAP_sym_in coff_swap_sym_in
05109 #endif
05110 #ifndef coff_SWAP_lineno_in
05111 #define coff_SWAP_lineno_in coff_swap_lineno_in
05112 #endif
05113 #ifndef coff_SWAP_aux_out
05114 #define coff_SWAP_aux_out coff_swap_aux_out
05115 #endif
05116 #ifndef coff_SWAP_sym_out
05117 #define coff_SWAP_sym_out coff_swap_sym_out
05118 #endif
05119 #ifndef coff_SWAP_lineno_out
05120 #define coff_SWAP_lineno_out coff_swap_lineno_out
05121 #endif
05122 #ifndef coff_SWAP_reloc_out
05123 #define coff_SWAP_reloc_out coff_swap_reloc_out
05124 #endif
05125 #ifndef coff_SWAP_filehdr_out
05126 #define coff_SWAP_filehdr_out coff_swap_filehdr_out
05127 #endif
05128 #ifndef coff_SWAP_aouthdr_out
05129 #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
05130 #endif
05131 #ifndef coff_SWAP_scnhdr_out
05132 #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
05133 #endif
05134 #ifndef coff_SWAP_reloc_in
05135 #define coff_SWAP_reloc_in coff_swap_reloc_in
05136 #endif
05137 #ifndef coff_SWAP_filehdr_in
05138 #define coff_SWAP_filehdr_in coff_swap_filehdr_in
05139 #endif
05140 #ifndef coff_SWAP_aouthdr_in
05141 #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
05142 #endif
05143 #ifndef coff_SWAP_scnhdr_in
05144 #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
05145 #endif
05146 
05147 static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
05148 {
05149   coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
05150   coff_SWAP_aux_out, coff_SWAP_sym_out,
05151   coff_SWAP_lineno_out, coff_SWAP_reloc_out,
05152   coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
05153   coff_SWAP_scnhdr_out,
05154   FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
05155 #ifdef COFF_LONG_FILENAMES
05156   TRUE,
05157 #else
05158   FALSE,
05159 #endif
05160 #ifdef COFF_LONG_SECTION_NAMES
05161   TRUE,
05162 #else
05163   FALSE,
05164 #endif
05165   COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
05166 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
05167   TRUE,
05168 #else
05169   FALSE,
05170 #endif
05171 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
05172   4,
05173 #else
05174   2,
05175 #endif
05176   coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
05177   coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
05178   coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
05179   coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
05180   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
05181   coff_classify_symbol, coff_compute_section_file_positions,
05182   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
05183   coff_adjust_symndx, coff_link_add_one_symbol,
05184   coff_link_output_has_begun, coff_final_link_postscript
05185 };
05186 
05187 #ifdef TICOFF
05188 /* COFF0 differs in file/section header size and relocation entry size.  */
05189 
05190 static const bfd_coff_backend_data ticoff0_swap_table =
05191 {
05192   coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
05193   coff_SWAP_aux_out, coff_SWAP_sym_out,
05194   coff_SWAP_lineno_out, coff_SWAP_reloc_out,
05195   coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
05196   coff_SWAP_scnhdr_out,
05197   FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
05198 #ifdef COFF_LONG_FILENAMES
05199   TRUE,
05200 #else
05201   FALSE,
05202 #endif
05203 #ifdef COFF_LONG_SECTION_NAMES
05204   TRUE,
05205 #else
05206   FALSE,
05207 #endif
05208   COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
05209 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
05210   TRUE,
05211 #else
05212   FALSE,
05213 #endif
05214 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
05215   4,
05216 #else
05217   2,
05218 #endif
05219   coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
05220   coff_SWAP_reloc_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
05221   coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
05222   coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
05223   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
05224   coff_classify_symbol, coff_compute_section_file_positions,
05225   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
05226   coff_adjust_symndx, coff_link_add_one_symbol,
05227   coff_link_output_has_begun, coff_final_link_postscript
05228 };
05229 #endif
05230 
05231 #ifdef TICOFF
05232 /* COFF1 differs in section header size.  */
05233 
05234 static const bfd_coff_backend_data ticoff1_swap_table =
05235 {
05236   coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
05237   coff_SWAP_aux_out, coff_SWAP_sym_out,
05238   coff_SWAP_lineno_out, coff_SWAP_reloc_out,
05239   coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
05240   coff_SWAP_scnhdr_out,
05241   FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
05242 #ifdef COFF_LONG_FILENAMES
05243   TRUE,
05244 #else
05245   FALSE,
05246 #endif
05247 #ifdef COFF_LONG_SECTION_NAMES
05248   TRUE,
05249 #else
05250   FALSE,
05251 #endif
05252   COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
05253 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
05254   TRUE,
05255 #else
05256   FALSE,
05257 #endif
05258 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
05259   4,
05260 #else
05261   2,
05262 #endif
05263   coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
05264   coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
05265   coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
05266   coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
05267   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
05268   coff_classify_symbol, coff_compute_section_file_positions,
05269   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
05270   coff_adjust_symndx, coff_link_add_one_symbol,
05271   coff_link_output_has_begun, coff_final_link_postscript
05272 };
05273 #endif
05274 
05275 #ifndef coff_close_and_cleanup
05276 #define       coff_close_and_cleanup              _bfd_generic_close_and_cleanup
05277 #endif
05278 
05279 #ifndef coff_bfd_free_cached_info
05280 #define coff_bfd_free_cached_info           _bfd_generic_bfd_free_cached_info
05281 #endif
05282 
05283 #ifndef coff_get_section_contents
05284 #define       coff_get_section_contents           _bfd_generic_get_section_contents
05285 #endif
05286 
05287 #ifndef coff_bfd_copy_private_symbol_data
05288 #define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
05289 #endif
05290 
05291 #ifndef coff_bfd_copy_private_header_data
05292 #define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
05293 #endif
05294 
05295 #ifndef coff_bfd_copy_private_section_data
05296 #define coff_bfd_copy_private_section_data  _bfd_generic_bfd_copy_private_section_data
05297 #endif
05298 
05299 #ifndef coff_bfd_copy_private_bfd_data
05300 #define coff_bfd_copy_private_bfd_data      _bfd_generic_bfd_copy_private_bfd_data
05301 #endif
05302 
05303 #ifndef coff_bfd_merge_private_bfd_data
05304 #define coff_bfd_merge_private_bfd_data     _bfd_generic_bfd_merge_private_bfd_data
05305 #endif
05306 
05307 #ifndef coff_bfd_set_private_flags
05308 #define coff_bfd_set_private_flags          _bfd_generic_bfd_set_private_flags
05309 #endif
05310 
05311 #ifndef coff_bfd_print_private_bfd_data
05312 #define coff_bfd_print_private_bfd_data     _bfd_generic_bfd_print_private_bfd_data
05313 #endif
05314 
05315 #ifndef coff_bfd_is_local_label_name
05316 #define coff_bfd_is_local_label_name          _bfd_coff_is_local_label_name
05317 #endif
05318 
05319 #ifndef coff_bfd_is_target_special_symbol
05320 #define coff_bfd_is_target_special_symbol   ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
05321 #endif
05322 
05323 #ifndef coff_read_minisymbols
05324 #define coff_read_minisymbols                 _bfd_generic_read_minisymbols
05325 #endif
05326 
05327 #ifndef coff_minisymbol_to_symbol
05328 #define coff_minisymbol_to_symbol      _bfd_generic_minisymbol_to_symbol
05329 #endif
05330 
05331 /* The reloc lookup routine must be supplied by each individual COFF
05332    backend.  */
05333 #ifndef coff_bfd_reloc_type_lookup
05334 #define coff_bfd_reloc_type_lookup     _bfd_norelocs_bfd_reloc_type_lookup
05335 #endif
05336 #ifndef coff_bfd_reloc_name_lookup
05337 #define coff_bfd_reloc_name_lookup    _bfd_norelocs_bfd_reloc_name_lookup
05338 #endif
05339 
05340 #ifndef coff_bfd_get_relocated_section_contents
05341 #define coff_bfd_get_relocated_section_contents \
05342   bfd_generic_get_relocated_section_contents
05343 #endif
05344 
05345 #ifndef coff_bfd_relax_section
05346 #define coff_bfd_relax_section                bfd_generic_relax_section
05347 #endif
05348 
05349 #ifndef coff_bfd_gc_sections
05350 #define coff_bfd_gc_sections                  bfd_generic_gc_sections
05351 #endif
05352 
05353 #ifndef coff_bfd_merge_sections
05354 #define coff_bfd_merge_sections               bfd_generic_merge_sections
05355 #endif
05356 
05357 #ifndef coff_bfd_is_group_section
05358 #define coff_bfd_is_group_section      bfd_generic_is_group_section
05359 #endif
05360 
05361 #ifndef coff_bfd_discard_group
05362 #define coff_bfd_discard_group                bfd_generic_discard_group
05363 #endif
05364 
05365 #ifndef coff_section_already_linked
05366 #define coff_section_already_linked \
05367   _bfd_generic_section_already_linked
05368 #endif
05369 
05370 #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)     \
05371 const bfd_target VAR =                                                \
05372 {                                                              \
05373   NAME ,                                                       \
05374   bfd_target_coff_flavour,                                     \
05375   BFD_ENDIAN_BIG,           /* Data byte order is big.  */            \
05376   BFD_ENDIAN_BIG,           /* Header byte order is big.  */   \
05377   /* object flags */                                           \
05378   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |               \
05379    HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),                  \
05380   /* section flags */                                                 \
05381   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
05382   UNDER,                    /* Leading symbol underscore.  */  \
05383   '/',                      /* AR_pad_char.  */                \
05384   15,                       /* AR_max_namelen.  */                    \
05385                                                                \
05386   /* Data conversion functions.  */                                   \
05387   bfd_getb64, bfd_getb_signed_64, bfd_putb64,                         \
05388   bfd_getb32, bfd_getb_signed_32, bfd_putb32,                         \
05389   bfd_getb16, bfd_getb_signed_16, bfd_putb16,                         \
05390                                                                \
05391   /* Header conversion functions.  */                                 \
05392   bfd_getb64, bfd_getb_signed_64, bfd_putb64,                         \
05393   bfd_getb32, bfd_getb_signed_32, bfd_putb32,                         \
05394   bfd_getb16, bfd_getb_signed_16, bfd_putb16,                         \
05395                                                                \
05396        /* bfd_check_format.  */                                \
05397   { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p,          \
05398     _bfd_dummy_target },                                       \
05399        /* bfd_set_format.  */                                         \
05400   { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false },    \
05401        /* bfd_write_contents.  */                              \
05402   { bfd_false, coff_write_object_contents, _bfd_write_archive_contents,      \
05403     bfd_false },                                               \
05404                                                                \
05405   BFD_JUMP_TABLE_GENERIC (coff),                               \
05406   BFD_JUMP_TABLE_COPY (coff),                                         \
05407   BFD_JUMP_TABLE_CORE (_bfd_nocore),                                  \
05408   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),                         \
05409   BFD_JUMP_TABLE_SYMBOLS (coff),                               \
05410   BFD_JUMP_TABLE_RELOCS (coff),                                       \
05411   BFD_JUMP_TABLE_WRITE (coff),                                        \
05412   BFD_JUMP_TABLE_LINK (coff),                                         \
05413   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),                            \
05414                                                                \
05415   ALTERNATIVE,                                                        \
05416                                                                \
05417   SWAP_TABLE                                                   \
05418 };
05419 
05420 #define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)  \
05421 const bfd_target VAR =                                                \
05422 {                                                              \
05423   NAME ,                                                       \
05424   bfd_target_coff_flavour,                                     \
05425   BFD_ENDIAN_LITTLE,        /* Data byte order is little.  */  \
05426   BFD_ENDIAN_BIG,           /* Header byte order is big.  */   \
05427   /* object flags */                                           \
05428   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |               \
05429    HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),                  \
05430   /* section flags */                                                 \
05431   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
05432   UNDER,                    /* Leading symbol underscore.  */  \
05433   '/',                      /* AR_pad_char.  */                \
05434   15,                       /* AR_max_namelen.  */                    \
05435                                                                \
05436   /* Data conversion functions.  */                                   \
05437   bfd_getb64, bfd_getb_signed_64, bfd_putb64,                         \
05438   bfd_getb32, bfd_getb_signed_32, bfd_putb32,                         \
05439   bfd_getb16, bfd_getb_signed_16, bfd_putb16,                         \
05440                                                                \
05441   /* Header conversion functions.  */                                 \
05442   bfd_getb64, bfd_getb_signed_64, bfd_putb64,                         \
05443   bfd_getb32, bfd_getb_signed_32, bfd_putb32,                         \
05444   bfd_getb16, bfd_getb_signed_16, bfd_putb16,                         \
05445                                                                \
05446        /* bfd_check_format.  */                                \
05447   { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p,          \
05448     _bfd_dummy_target },                                       \
05449        /* bfd_set_format.  */                                         \
05450   { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false },    \
05451        /* bfd_write_contents.  */                              \
05452   { bfd_false, coff_write_object_contents, _bfd_write_archive_contents,      \
05453     bfd_false },                                               \
05454                                                                \
05455   BFD_JUMP_TABLE_GENERIC (coff),                               \
05456   BFD_JUMP_TABLE_COPY (coff),                                         \
05457   BFD_JUMP_TABLE_CORE (_bfd_nocore),                                  \
05458   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),                         \
05459   BFD_JUMP_TABLE_SYMBOLS (coff),                               \
05460   BFD_JUMP_TABLE_RELOCS (coff),                                       \
05461   BFD_JUMP_TABLE_WRITE (coff),                                        \
05462   BFD_JUMP_TABLE_LINK (coff),                                         \
05463   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),                            \
05464                                                                \
05465   ALTERNATIVE,                                                        \
05466                                                                \
05467   SWAP_TABLE                                                   \
05468 };
05469 
05470 #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)  \
05471 const bfd_target VAR =                                                \
05472 {                                                              \
05473   NAME ,                                                       \
05474   bfd_target_coff_flavour,                                     \
05475   BFD_ENDIAN_LITTLE,        /* Data byte order is little.  */  \
05476   BFD_ENDIAN_LITTLE,        /* Header byte order is little.  */       \
05477        /* object flags */                                      \
05478   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |               \
05479    HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),                  \
05480        /* section flags */                                     \
05481   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
05482   UNDER,                    /* Leading symbol underscore.  */  \
05483   '/',                      /* AR_pad_char.  */                \
05484   15,                       /* AR_max_namelen.  */                    \
05485                                                                \
05486   /* Data conversion functions.  */                                   \
05487   bfd_getl64, bfd_getl_signed_64, bfd_putl64,                         \
05488   bfd_getl32, bfd_getl_signed_32, bfd_putl32,                         \
05489   bfd_getl16, bfd_getl_signed_16, bfd_putl16,                         \
05490   /* Header conversion functions.  */                                 \
05491   bfd_getl64, bfd_getl_signed_64, bfd_putl64,                         \
05492   bfd_getl32, bfd_getl_signed_32, bfd_putl32,                         \
05493   bfd_getl16, bfd_getl_signed_16, bfd_putl16,                         \
05494        /* bfd_check_format.  */                                \
05495   { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p,          \
05496     _bfd_dummy_target },                                       \
05497        /* bfd_set_format.  */                                         \
05498   { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false },    \
05499        /* bfd_write_contents.  */                              \
05500   { bfd_false, coff_write_object_contents, _bfd_write_archive_contents,      \
05501     bfd_false },                                               \
05502                                                                \
05503   BFD_JUMP_TABLE_GENERIC (coff),                               \
05504   BFD_JUMP_TABLE_COPY (coff),                                         \
05505   BFD_JUMP_TABLE_CORE (_bfd_nocore),                                  \
05506   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),                         \
05507   BFD_JUMP_TABLE_SYMBOLS (coff),                               \
05508   BFD_JUMP_TABLE_RELOCS (coff),                                       \
05509   BFD_JUMP_TABLE_WRITE (coff),                                        \
05510   BFD_JUMP_TABLE_LINK (coff),                                         \
05511   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),                            \
05512                                                                \
05513   ALTERNATIVE,                                                        \
05514                                                                \
05515   SWAP_TABLE                                                   \
05516 };