13d8817e4Smiod /* Support for the generic parts of most COFF variants, for BFD.
23d8817e4Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
33d8817e4Smiod 2000, 2001, 2002, 2003, 2004, 2005
43d8817e4Smiod Free Software Foundation, Inc.
53d8817e4Smiod Written by Cygnus Support.
63d8817e4Smiod
73d8817e4Smiod This file is part of BFD, the Binary File Descriptor library.
83d8817e4Smiod
93d8817e4Smiod This program is free software; you can redistribute it and/or modify
103d8817e4Smiod it under the terms of the GNU General Public License as published by
113d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
123d8817e4Smiod (at your option) any later version.
133d8817e4Smiod
143d8817e4Smiod This program is distributed in the hope that it will be useful,
153d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
163d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
173d8817e4Smiod GNU General Public License for more details.
183d8817e4Smiod
193d8817e4Smiod You should have received a copy of the GNU General Public License
203d8817e4Smiod along with this program; if not, write to the Free Software
213d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
223d8817e4Smiod
233d8817e4Smiod /* Most of this hacked by Steve Chamberlain,
243d8817e4Smiod sac@cygnus.com. */
253d8817e4Smiod /*
263d8817e4Smiod SECTION
273d8817e4Smiod coff backends
283d8817e4Smiod
293d8817e4Smiod BFD supports a number of different flavours of coff format.
303d8817e4Smiod The major differences between formats are the sizes and
313d8817e4Smiod alignments of fields in structures on disk, and the occasional
323d8817e4Smiod extra field.
333d8817e4Smiod
343d8817e4Smiod Coff in all its varieties is implemented with a few common
353d8817e4Smiod files and a number of implementation specific files. For
363d8817e4Smiod example, The 88k bcs coff format is implemented in the file
373d8817e4Smiod @file{coff-m88k.c}. This file @code{#include}s
383d8817e4Smiod @file{coff/m88k.h} which defines the external structure of the
393d8817e4Smiod coff format for the 88k, and @file{coff/internal.h} which
403d8817e4Smiod defines the internal structure. @file{coff-m88k.c} also
413d8817e4Smiod defines the relocations used by the 88k format
423d8817e4Smiod @xref{Relocations}.
433d8817e4Smiod
443d8817e4Smiod The Intel i960 processor version of coff is implemented in
453d8817e4Smiod @file{coff-i960.c}. This file has the same structure as
463d8817e4Smiod @file{coff-m88k.c}, except that it includes @file{coff/i960.h}
473d8817e4Smiod rather than @file{coff-m88k.h}.
483d8817e4Smiod
493d8817e4Smiod SUBSECTION
503d8817e4Smiod Porting to a new version of coff
513d8817e4Smiod
523d8817e4Smiod The recommended method is to select from the existing
533d8817e4Smiod implementations the version of coff which is most like the one
543d8817e4Smiod you want to use. For example, we'll say that i386 coff is
553d8817e4Smiod the one you select, and that your coff flavour is called foo.
563d8817e4Smiod Copy @file{i386coff.c} to @file{foocoff.c}, copy
573d8817e4Smiod @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
583d8817e4Smiod and add the lines to @file{targets.c} and @file{Makefile.in}
593d8817e4Smiod so that your new back end is used. Alter the shapes of the
603d8817e4Smiod structures in @file{../include/coff/foo.h} so that they match
613d8817e4Smiod what you need. You will probably also have to add
623d8817e4Smiod @code{#ifdef}s to the code in @file{coff/internal.h} and
633d8817e4Smiod @file{coffcode.h} if your version of coff is too wild.
643d8817e4Smiod
653d8817e4Smiod You can verify that your new BFD backend works quite simply by
663d8817e4Smiod building @file{objdump} from the @file{binutils} directory,
673d8817e4Smiod and making sure that its version of what's going on and your
683d8817e4Smiod host system's idea (assuming it has the pretty standard coff
693d8817e4Smiod dump utility, usually called @code{att-dump} or just
703d8817e4Smiod @code{dump}) are the same. Then clean up your code, and send
713d8817e4Smiod what you've done to Cygnus. Then your stuff will be in the
723d8817e4Smiod next release, and you won't have to keep integrating it.
733d8817e4Smiod
743d8817e4Smiod SUBSECTION
753d8817e4Smiod How the coff backend works
763d8817e4Smiod
773d8817e4Smiod SUBSUBSECTION
783d8817e4Smiod File layout
793d8817e4Smiod
803d8817e4Smiod The Coff backend is split into generic routines that are
813d8817e4Smiod applicable to any Coff target and routines that are specific
823d8817e4Smiod to a particular target. The target-specific routines are
833d8817e4Smiod further split into ones which are basically the same for all
843d8817e4Smiod Coff targets except that they use the external symbol format
853d8817e4Smiod or use different values for certain constants.
863d8817e4Smiod
873d8817e4Smiod The generic routines are in @file{coffgen.c}. These routines
883d8817e4Smiod work for any Coff target. They use some hooks into the target
893d8817e4Smiod specific code; the hooks are in a @code{bfd_coff_backend_data}
903d8817e4Smiod structure, one of which exists for each target.
913d8817e4Smiod
923d8817e4Smiod The essentially similar target-specific routines are in
933d8817e4Smiod @file{coffcode.h}. This header file includes executable C code.
943d8817e4Smiod The various Coff targets first include the appropriate Coff
953d8817e4Smiod header file, make any special defines that are needed, and
963d8817e4Smiod then include @file{coffcode.h}.
973d8817e4Smiod
983d8817e4Smiod Some of the Coff targets then also have additional routines in
993d8817e4Smiod the target source file itself.
1003d8817e4Smiod
1013d8817e4Smiod For example, @file{coff-i960.c} includes
1023d8817e4Smiod @file{coff/internal.h} and @file{coff/i960.h}. It then
1033d8817e4Smiod defines a few constants, such as @code{I960}, and includes
1043d8817e4Smiod @file{coffcode.h}. Since the i960 has complex relocation
1053d8817e4Smiod types, @file{coff-i960.c} also includes some code to
1063d8817e4Smiod manipulate the i960 relocs. This code is not in
1073d8817e4Smiod @file{coffcode.h} because it would not be used by any other
1083d8817e4Smiod target.
1093d8817e4Smiod
1103d8817e4Smiod SUBSUBSECTION
1113d8817e4Smiod Bit twiddling
1123d8817e4Smiod
1133d8817e4Smiod Each flavour of coff supported in BFD has its own header file
1143d8817e4Smiod describing the external layout of the structures. There is also
1153d8817e4Smiod an internal description of the coff layout, in
1163d8817e4Smiod @file{coff/internal.h}. A major function of the
1173d8817e4Smiod coff backend is swapping the bytes and twiddling the bits to
1183d8817e4Smiod translate the external form of the structures into the normal
1193d8817e4Smiod internal form. This is all performed in the
1203d8817e4Smiod @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
1213d8817e4Smiod elements are different sizes between different versions of
1223d8817e4Smiod coff; it is the duty of the coff version specific include file
1233d8817e4Smiod to override the definitions of various packing routines in
1243d8817e4Smiod @file{coffcode.h}. E.g., the size of line number entry in coff is
1253d8817e4Smiod sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
1263d8817e4Smiod @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
1273d8817e4Smiod correct one. No doubt, some day someone will find a version of
1283d8817e4Smiod coff which has a varying field size not catered to at the
1293d8817e4Smiod moment. To port BFD, that person will have to add more @code{#defines}.
1303d8817e4Smiod Three of the bit twiddling routines are exported to
1313d8817e4Smiod @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
1323d8817e4Smiod and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
1333d8817e4Smiod table on its own, but uses BFD to fix things up. More of the
1343d8817e4Smiod bit twiddlers are exported for @code{gas};
1353d8817e4Smiod @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
1363d8817e4Smiod @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
1373d8817e4Smiod @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
1383d8817e4Smiod @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
1393d8817e4Smiod of all the symbol table and reloc drudgery itself, thereby
1403d8817e4Smiod saving the internal BFD overhead, but uses BFD to swap things
1413d8817e4Smiod on the way out, making cross ports much safer. Doing so also
1423d8817e4Smiod allows BFD (and thus the linker) to use the same header files
1433d8817e4Smiod as @code{gas}, which makes one avenue to disaster disappear.
1443d8817e4Smiod
1453d8817e4Smiod SUBSUBSECTION
1463d8817e4Smiod Symbol reading
1473d8817e4Smiod
1483d8817e4Smiod The simple canonical form for symbols used by BFD is not rich
1493d8817e4Smiod enough to keep all the information available in a coff symbol
1503d8817e4Smiod table. The back end gets around this problem by keeping the original
1513d8817e4Smiod symbol table around, "behind the scenes".
1523d8817e4Smiod
1533d8817e4Smiod When a symbol table is requested (through a call to
1543d8817e4Smiod @code{bfd_canonicalize_symtab}), a request gets through to
1553d8817e4Smiod @code{coff_get_normalized_symtab}. This reads the symbol table from
1563d8817e4Smiod the coff file and swaps all the structures inside into the
1573d8817e4Smiod internal form. It also fixes up all the pointers in the table
1583d8817e4Smiod (represented in the file by offsets from the first symbol in
1593d8817e4Smiod the table) into physical pointers to elements in the new
1603d8817e4Smiod internal table. This involves some work since the meanings of
1613d8817e4Smiod fields change depending upon context: a field that is a
1623d8817e4Smiod pointer to another structure in the symbol table at one moment
1633d8817e4Smiod may be the size in bytes of a structure at the next. Another
1643d8817e4Smiod pass is made over the table. All symbols which mark file names
1653d8817e4Smiod (<<C_FILE>> symbols) are modified so that the internal
1663d8817e4Smiod string points to the value in the auxent (the real filename)
1673d8817e4Smiod rather than the normal text associated with the symbol
1683d8817e4Smiod (@code{".file"}).
1693d8817e4Smiod
1703d8817e4Smiod At this time the symbol names are moved around. Coff stores
1713d8817e4Smiod all symbols less than nine characters long physically
1723d8817e4Smiod within the symbol table; longer strings are kept at the end of
1733d8817e4Smiod the file in the string table. This pass moves all strings
1743d8817e4Smiod into memory and replaces them with pointers to the strings.
1753d8817e4Smiod
1763d8817e4Smiod The symbol table is massaged once again, this time to create
1773d8817e4Smiod the canonical table used by the BFD application. Each symbol
1783d8817e4Smiod is inspected in turn, and a decision made (using the
1793d8817e4Smiod @code{sclass} field) about the various flags to set in the
1803d8817e4Smiod @code{asymbol}. @xref{Symbols}. The generated canonical table
1813d8817e4Smiod shares strings with the hidden internal symbol table.
1823d8817e4Smiod
1833d8817e4Smiod Any linenumbers are read from the coff file too, and attached
1843d8817e4Smiod to the symbols which own the functions the linenumbers belong to.
1853d8817e4Smiod
1863d8817e4Smiod SUBSUBSECTION
1873d8817e4Smiod Symbol writing
1883d8817e4Smiod
1893d8817e4Smiod Writing a symbol to a coff file which didn't come from a coff
1903d8817e4Smiod file will lose any debugging information. The @code{asymbol}
1913d8817e4Smiod structure remembers the BFD from which the symbol was taken, and on
1923d8817e4Smiod output the back end makes sure that the same destination target as
1933d8817e4Smiod source target is present.
1943d8817e4Smiod
1953d8817e4Smiod When the symbols have come from a coff file then all the
1963d8817e4Smiod debugging information is preserved.
1973d8817e4Smiod
1983d8817e4Smiod Symbol tables are provided for writing to the back end in a
1993d8817e4Smiod vector of pointers to pointers. This allows applications like
2003d8817e4Smiod the linker to accumulate and output large symbol tables
2013d8817e4Smiod without having to do too much byte copying.
2023d8817e4Smiod
2033d8817e4Smiod This function runs through the provided symbol table and
2043d8817e4Smiod patches each symbol marked as a file place holder
2053d8817e4Smiod (@code{C_FILE}) to point to the next file place holder in the
2063d8817e4Smiod list. It also marks each @code{offset} field in the list with
2073d8817e4Smiod the offset from the first symbol of the current symbol.
2083d8817e4Smiod
2093d8817e4Smiod Another function of this procedure is to turn the canonical
2103d8817e4Smiod value form of BFD into the form used by coff. Internally, BFD
2113d8817e4Smiod expects symbol values to be offsets from a section base; so a
2123d8817e4Smiod symbol physically at 0x120, but in a section starting at
2133d8817e4Smiod 0x100, would have the value 0x20. Coff expects symbols to
2143d8817e4Smiod contain their final value, so symbols have their values
2153d8817e4Smiod changed at this point to reflect their sum with their owning
2163d8817e4Smiod section. This transformation uses the
2173d8817e4Smiod <<output_section>> field of the @code{asymbol}'s
2183d8817e4Smiod @code{asection} @xref{Sections}.
2193d8817e4Smiod
2203d8817e4Smiod o <<coff_mangle_symbols>>
2213d8817e4Smiod
2223d8817e4Smiod This routine runs though the provided symbol table and uses
2233d8817e4Smiod the offsets generated by the previous pass and the pointers
2243d8817e4Smiod generated when the symbol table was read in to create the
2253d8817e4Smiod structured hierarchy required by coff. It changes each pointer
2263d8817e4Smiod to a symbol into the index into the symbol table of the asymbol.
2273d8817e4Smiod
2283d8817e4Smiod o <<coff_write_symbols>>
2293d8817e4Smiod
2303d8817e4Smiod This routine runs through the symbol table and patches up the
2313d8817e4Smiod symbols from their internal form into the coff way, calls the
2323d8817e4Smiod bit twiddlers, and writes out the table to the file.
2333d8817e4Smiod
2343d8817e4Smiod */
2353d8817e4Smiod
2363d8817e4Smiod /*
2373d8817e4Smiod INTERNAL_DEFINITION
2383d8817e4Smiod coff_symbol_type
2393d8817e4Smiod
2403d8817e4Smiod DESCRIPTION
2413d8817e4Smiod The hidden information for an <<asymbol>> is described in a
2423d8817e4Smiod <<combined_entry_type>>:
2433d8817e4Smiod
2443d8817e4Smiod CODE_FRAGMENT
2453d8817e4Smiod .
2463d8817e4Smiod .typedef struct coff_ptr_struct
2473d8817e4Smiod .{
2483d8817e4Smiod . {* Remembers the offset from the first symbol in the file for
2493d8817e4Smiod . this symbol. Generated by coff_renumber_symbols. *}
2503d8817e4Smiod . unsigned int offset;
2513d8817e4Smiod .
2523d8817e4Smiod . {* Should the value of this symbol be renumbered. Used for
2533d8817e4Smiod . XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. *}
2543d8817e4Smiod . unsigned int fix_value : 1;
2553d8817e4Smiod .
2563d8817e4Smiod . {* Should the tag field of this symbol be renumbered.
2573d8817e4Smiod . Created by coff_pointerize_aux. *}
2583d8817e4Smiod . unsigned int fix_tag : 1;
2593d8817e4Smiod .
2603d8817e4Smiod . {* Should the endidx field of this symbol be renumbered.
2613d8817e4Smiod . Created by coff_pointerize_aux. *}
2623d8817e4Smiod . unsigned int fix_end : 1;
2633d8817e4Smiod .
2643d8817e4Smiod . {* Should the x_csect.x_scnlen field be renumbered.
2653d8817e4Smiod . Created by coff_pointerize_aux. *}
2663d8817e4Smiod . unsigned int fix_scnlen : 1;
2673d8817e4Smiod .
2683d8817e4Smiod . {* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
2693d8817e4Smiod . index into the line number entries. Set by coff_slurp_symbol_table. *}
2703d8817e4Smiod . unsigned int fix_line : 1;
2713d8817e4Smiod .
2723d8817e4Smiod . {* The container for the symbol structure as read and translated
2733d8817e4Smiod . from the file. *}
2743d8817e4Smiod . union
2753d8817e4Smiod . {
2763d8817e4Smiod . union internal_auxent auxent;
2773d8817e4Smiod . struct internal_syment syment;
2783d8817e4Smiod . } u;
2793d8817e4Smiod .} combined_entry_type;
2803d8817e4Smiod .
2813d8817e4Smiod .
2823d8817e4Smiod .{* Each canonical asymbol really looks like this: *}
2833d8817e4Smiod .
2843d8817e4Smiod .typedef struct coff_symbol_struct
2853d8817e4Smiod .{
2863d8817e4Smiod . {* The actual symbol which the rest of BFD works with *}
2873d8817e4Smiod . asymbol symbol;
2883d8817e4Smiod .
2893d8817e4Smiod . {* A pointer to the hidden information for this symbol *}
2903d8817e4Smiod . combined_entry_type *native;
2913d8817e4Smiod .
2923d8817e4Smiod . {* A pointer to the linenumber information for this symbol *}
2933d8817e4Smiod . struct lineno_cache_entry *lineno;
2943d8817e4Smiod .
2953d8817e4Smiod . {* Have the line numbers been relocated yet ? *}
2963d8817e4Smiod . bfd_boolean done_lineno;
2973d8817e4Smiod .} coff_symbol_type;
2983d8817e4Smiod
2993d8817e4Smiod */
3003d8817e4Smiod
3013d8817e4Smiod #ifdef COFF_WITH_PE
3023d8817e4Smiod #include "peicode.h"
3033d8817e4Smiod #else
3043d8817e4Smiod #include "coffswap.h"
3053d8817e4Smiod #endif
3063d8817e4Smiod
3073d8817e4Smiod #define STRING_SIZE_SIZE 4
3083d8817e4Smiod
3093d8817e4Smiod #define DOT_DEBUG ".debug"
3103d8817e4Smiod #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
3113d8817e4Smiod
3123d8817e4Smiod static long sec_to_styp_flags
3133d8817e4Smiod (const char *, flagword);
3143d8817e4Smiod static bfd_boolean styp_to_sec_flags
3153d8817e4Smiod (bfd *, void *, const char *, asection *, flagword *);
3163d8817e4Smiod static bfd_boolean coff_bad_format_hook
3173d8817e4Smiod (bfd *, void *);
3183d8817e4Smiod static void coff_set_custom_section_alignment
3193d8817e4Smiod (bfd *, asection *, const struct coff_section_alignment_entry *,
3203d8817e4Smiod const unsigned int);
3213d8817e4Smiod static bfd_boolean coff_new_section_hook
3223d8817e4Smiod (bfd *, asection *);
3233d8817e4Smiod static bfd_boolean coff_set_arch_mach_hook
3243d8817e4Smiod (bfd *, void *);
3253d8817e4Smiod static bfd_boolean coff_write_relocs
3263d8817e4Smiod (bfd *, int);
3273d8817e4Smiod static bfd_boolean coff_set_flags
3283d8817e4Smiod (bfd *, unsigned int *, unsigned short *);
3293d8817e4Smiod static bfd_boolean coff_set_arch_mach
3303d8817e4Smiod (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_UNUSED;
3313d8817e4Smiod static bfd_boolean coff_compute_section_file_positions
3323d8817e4Smiod (bfd *);
3333d8817e4Smiod static bfd_boolean coff_write_object_contents
3343d8817e4Smiod (bfd *) ATTRIBUTE_UNUSED;
3353d8817e4Smiod static bfd_boolean coff_set_section_contents
3363d8817e4Smiod (bfd *, asection *, const void *, file_ptr, bfd_size_type);
3373d8817e4Smiod static void * buy_and_read
3383d8817e4Smiod (bfd *, file_ptr, bfd_size_type);
3393d8817e4Smiod static bfd_boolean coff_slurp_line_table
3403d8817e4Smiod (bfd *, asection *);
3413d8817e4Smiod static bfd_boolean coff_slurp_symbol_table
3423d8817e4Smiod (bfd *);
3433d8817e4Smiod static enum coff_symbol_classification coff_classify_symbol
3443d8817e4Smiod (bfd *, struct internal_syment *);
3453d8817e4Smiod static bfd_boolean coff_slurp_reloc_table
3463d8817e4Smiod (bfd *, asection *, asymbol **);
3473d8817e4Smiod static long coff_canonicalize_reloc
3483d8817e4Smiod (bfd *, asection *, arelent **, asymbol **);
3493d8817e4Smiod #ifndef coff_mkobject_hook
3503d8817e4Smiod static void * coff_mkobject_hook
3513d8817e4Smiod (bfd *, void *, void *);
3523d8817e4Smiod #endif
3533d8817e4Smiod #ifdef COFF_WITH_PE
3543d8817e4Smiod static flagword handle_COMDAT
3553d8817e4Smiod (bfd *, flagword, void *, const char *, asection *);
3563d8817e4Smiod #endif
3573d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
3583d8817e4Smiod static bfd_boolean coff_read_word
3593d8817e4Smiod (bfd *, unsigned int *);
3603d8817e4Smiod static unsigned int coff_compute_checksum
3613d8817e4Smiod (bfd *);
3623d8817e4Smiod static bfd_boolean coff_apply_checksum
3633d8817e4Smiod (bfd *);
3643d8817e4Smiod #endif
3653d8817e4Smiod #ifdef TICOFF
3663d8817e4Smiod static bfd_boolean ticoff0_bad_format_hook
3673d8817e4Smiod (bfd *, void * );
3683d8817e4Smiod static bfd_boolean ticoff1_bad_format_hook
3693d8817e4Smiod (bfd *, void * );
3703d8817e4Smiod #endif
3713d8817e4Smiod
3723d8817e4Smiod /* void warning(); */
3733d8817e4Smiod
3743d8817e4Smiod /* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
3753d8817e4Smiod the incoming SEC_* flags. The inverse of this function is
3763d8817e4Smiod styp_to_sec_flags(). NOTE: If you add to/change this routine, you
3773d8817e4Smiod should probably mirror the changes in styp_to_sec_flags(). */
3783d8817e4Smiod
3793d8817e4Smiod #ifndef COFF_WITH_PE
3803d8817e4Smiod
3813d8817e4Smiod /* Macros for setting debugging flags. */
3823d8817e4Smiod
3833d8817e4Smiod #ifdef STYP_DEBUG
3843d8817e4Smiod #define STYP_XCOFF_DEBUG STYP_DEBUG
3853d8817e4Smiod #else
3863d8817e4Smiod #define STYP_XCOFF_DEBUG STYP_INFO
3873d8817e4Smiod #endif
3883d8817e4Smiod
3893d8817e4Smiod #ifdef COFF_ALIGN_IN_S_FLAGS
3903d8817e4Smiod #define STYP_DEBUG_INFO STYP_DSECT
3913d8817e4Smiod #else
3923d8817e4Smiod #define STYP_DEBUG_INFO STYP_INFO
3933d8817e4Smiod #endif
3943d8817e4Smiod
3953d8817e4Smiod static long
sec_to_styp_flags(const char * sec_name,flagword sec_flags)3963d8817e4Smiod sec_to_styp_flags (const char *sec_name, flagword sec_flags)
3973d8817e4Smiod {
3983d8817e4Smiod long styp_flags = 0;
3993d8817e4Smiod
4003d8817e4Smiod if (!strcmp (sec_name, _TEXT))
4013d8817e4Smiod {
4023d8817e4Smiod styp_flags = STYP_TEXT;
4033d8817e4Smiod }
4043d8817e4Smiod else if (!strcmp (sec_name, _DATA))
4053d8817e4Smiod {
4063d8817e4Smiod styp_flags = STYP_DATA;
4073d8817e4Smiod }
4083d8817e4Smiod else if (!strcmp (sec_name, _BSS))
4093d8817e4Smiod {
4103d8817e4Smiod styp_flags = STYP_BSS;
4113d8817e4Smiod #ifdef _COMMENT
4123d8817e4Smiod }
4133d8817e4Smiod else if (!strcmp (sec_name, _COMMENT))
4143d8817e4Smiod {
4153d8817e4Smiod styp_flags = STYP_INFO;
4163d8817e4Smiod #endif /* _COMMENT */
4173d8817e4Smiod #ifdef _LIB
4183d8817e4Smiod }
4193d8817e4Smiod else if (!strcmp (sec_name, _LIB))
4203d8817e4Smiod {
4213d8817e4Smiod styp_flags = STYP_LIB;
4223d8817e4Smiod #endif /* _LIB */
4233d8817e4Smiod #ifdef _LIT
4243d8817e4Smiod }
4253d8817e4Smiod else if (!strcmp (sec_name, _LIT))
4263d8817e4Smiod {
4273d8817e4Smiod styp_flags = STYP_LIT;
4283d8817e4Smiod #endif /* _LIT */
4293d8817e4Smiod }
4303d8817e4Smiod else if (!strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1))
4313d8817e4Smiod {
4323d8817e4Smiod /* Handle the XCOFF debug section and DWARF2 debug sections. */
4333d8817e4Smiod if (!sec_name[6])
4343d8817e4Smiod styp_flags = STYP_XCOFF_DEBUG;
4353d8817e4Smiod else
4363d8817e4Smiod styp_flags = STYP_DEBUG_INFO;
4373d8817e4Smiod }
4383d8817e4Smiod else if (!strncmp (sec_name, ".stab", 5))
4393d8817e4Smiod {
4403d8817e4Smiod styp_flags = STYP_DEBUG_INFO;
4413d8817e4Smiod }
4423d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
4433d8817e4Smiod else if (!strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1))
4443d8817e4Smiod {
4453d8817e4Smiod styp_flags = STYP_DEBUG_INFO;
4463d8817e4Smiod }
4473d8817e4Smiod #endif
4483d8817e4Smiod #ifdef RS6000COFF_C
4493d8817e4Smiod else if (!strcmp (sec_name, _PAD))
4503d8817e4Smiod {
4513d8817e4Smiod styp_flags = STYP_PAD;
4523d8817e4Smiod }
4533d8817e4Smiod else if (!strcmp (sec_name, _LOADER))
4543d8817e4Smiod {
4553d8817e4Smiod styp_flags = STYP_LOADER;
4563d8817e4Smiod }
4573d8817e4Smiod else if (!strcmp (sec_name, _EXCEPT))
4583d8817e4Smiod {
4593d8817e4Smiod styp_flags = STYP_EXCEPT;
4603d8817e4Smiod }
4613d8817e4Smiod else if (!strcmp (sec_name, _TYPCHK))
4623d8817e4Smiod {
4633d8817e4Smiod styp_flags = STYP_TYPCHK;
4643d8817e4Smiod }
4653d8817e4Smiod #endif
4663d8817e4Smiod /* Try and figure out what it should be */
4673d8817e4Smiod else if (sec_flags & SEC_CODE)
4683d8817e4Smiod {
4693d8817e4Smiod styp_flags = STYP_TEXT;
4703d8817e4Smiod }
4713d8817e4Smiod else if (sec_flags & SEC_DATA)
4723d8817e4Smiod {
4733d8817e4Smiod styp_flags = STYP_DATA;
4743d8817e4Smiod }
4753d8817e4Smiod else if (sec_flags & SEC_READONLY)
4763d8817e4Smiod {
4773d8817e4Smiod #ifdef STYP_LIT /* 29k readonly text/data section */
4783d8817e4Smiod styp_flags = STYP_LIT;
4793d8817e4Smiod #else
4803d8817e4Smiod styp_flags = STYP_TEXT;
4813d8817e4Smiod #endif /* STYP_LIT */
4823d8817e4Smiod }
4833d8817e4Smiod else if (sec_flags & SEC_LOAD)
4843d8817e4Smiod {
4853d8817e4Smiod styp_flags = STYP_TEXT;
4863d8817e4Smiod }
4873d8817e4Smiod else if (sec_flags & SEC_ALLOC)
4883d8817e4Smiod {
4893d8817e4Smiod styp_flags = STYP_BSS;
4903d8817e4Smiod }
4913d8817e4Smiod
4923d8817e4Smiod #ifdef STYP_CLINK
4933d8817e4Smiod if (sec_flags & SEC_TIC54X_CLINK)
4943d8817e4Smiod styp_flags |= STYP_CLINK;
4953d8817e4Smiod #endif
4963d8817e4Smiod
4973d8817e4Smiod #ifdef STYP_BLOCK
4983d8817e4Smiod if (sec_flags & SEC_TIC54X_BLOCK)
4993d8817e4Smiod styp_flags |= STYP_BLOCK;
5003d8817e4Smiod #endif
5013d8817e4Smiod
5023d8817e4Smiod #ifdef STYP_NOLOAD
5033d8817e4Smiod if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
5043d8817e4Smiod styp_flags |= STYP_NOLOAD;
5053d8817e4Smiod #endif
5063d8817e4Smiod
5073d8817e4Smiod return styp_flags;
5083d8817e4Smiod }
5093d8817e4Smiod
5103d8817e4Smiod #else /* COFF_WITH_PE */
5113d8817e4Smiod
5123d8817e4Smiod /* The PE version; see above for the general comments. The non-PE
5133d8817e4Smiod case seems to be more guessing, and breaks PE format; specifically,
5143d8817e4Smiod .rdata is readonly, but it sure ain't text. Really, all this
5153d8817e4Smiod should be set up properly in gas (or whatever assembler is in use),
5163d8817e4Smiod and honor whatever objcopy/strip, etc. sent us as input. */
5173d8817e4Smiod
5183d8817e4Smiod static long
sec_to_styp_flags(const char * sec_name,flagword sec_flags)5193d8817e4Smiod sec_to_styp_flags (const char *sec_name, flagword sec_flags)
5203d8817e4Smiod {
5213d8817e4Smiod long styp_flags = 0;
5223d8817e4Smiod
5233d8817e4Smiod /* caution: there are at least three groups of symbols that have
5243d8817e4Smiod very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
5253d8817e4Smiod SEC_* are the BFD internal flags, used for generic BFD
5263d8817e4Smiod information. STYP_* are the COFF section flags which appear in
5273d8817e4Smiod COFF files. IMAGE_SCN_* are the PE section flags which appear in
5283d8817e4Smiod PE files. The STYP_* flags and the IMAGE_SCN_* flags overlap,
5293d8817e4Smiod but there are more IMAGE_SCN_* flags. */
5303d8817e4Smiod
5313d8817e4Smiod /* FIXME: There is no gas syntax to specify the debug section flag. */
5323d8817e4Smiod if (strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
5333d8817e4Smiod || strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0)
5343d8817e4Smiod sec_flags = SEC_DEBUGGING;
5353d8817e4Smiod
5363d8817e4Smiod /* skip LOAD */
5373d8817e4Smiod /* READONLY later */
5383d8817e4Smiod /* skip RELOC */
5393d8817e4Smiod if ((sec_flags & SEC_CODE) != 0)
5403d8817e4Smiod styp_flags |= IMAGE_SCN_CNT_CODE;
5413d8817e4Smiod if ((sec_flags & SEC_DATA) != 0)
5423d8817e4Smiod styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
5433d8817e4Smiod if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
5443d8817e4Smiod styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA; /* ==STYP_BSS */
5453d8817e4Smiod /* skip ROM */
5463d8817e4Smiod /* skip constRUCTOR */
5473d8817e4Smiod /* skip CONTENTS */
5483d8817e4Smiod if ((sec_flags & SEC_IS_COMMON) != 0)
5493d8817e4Smiod styp_flags |= IMAGE_SCN_LNK_COMDAT;
5503d8817e4Smiod if ((sec_flags & SEC_DEBUGGING) != 0)
5513d8817e4Smiod styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
5523d8817e4Smiod if ((sec_flags & SEC_EXCLUDE) != 0)
5533d8817e4Smiod styp_flags |= IMAGE_SCN_LNK_REMOVE;
5543d8817e4Smiod if ((sec_flags & SEC_NEVER_LOAD) != 0)
5553d8817e4Smiod styp_flags |= IMAGE_SCN_LNK_REMOVE;
5563d8817e4Smiod /* skip IN_MEMORY */
5573d8817e4Smiod /* skip SORT */
5583d8817e4Smiod if (sec_flags & SEC_LINK_ONCE)
5593d8817e4Smiod styp_flags |= IMAGE_SCN_LNK_COMDAT;
5603d8817e4Smiod /* skip LINK_DUPLICATES */
5613d8817e4Smiod /* skip LINKER_CREATED */
5623d8817e4Smiod
5633d8817e4Smiod if (sec_flags & (SEC_ALLOC | SEC_LOAD))
5643d8817e4Smiod {
5653d8817e4Smiod /* For now, the read/write bits are mapped onto SEC_READONLY, even
5663d8817e4Smiod though the semantics don't quite match. The bits from the input
5673d8817e4Smiod are retained in pei_section_data(abfd, section)->pe_flags. */
5683d8817e4Smiod styp_flags |= IMAGE_SCN_MEM_READ; /* Always readable. */
5693d8817e4Smiod if ((sec_flags & SEC_READONLY) == 0)
5703d8817e4Smiod styp_flags |= IMAGE_SCN_MEM_WRITE; /* Invert READONLY for write. */
5713d8817e4Smiod if (sec_flags & SEC_CODE)
5723d8817e4Smiod styp_flags |= IMAGE_SCN_MEM_EXECUTE; /* CODE->EXECUTE. */
5733d8817e4Smiod if (sec_flags & SEC_COFF_SHARED)
5743d8817e4Smiod styp_flags |= IMAGE_SCN_MEM_SHARED; /* Shared remains meaningful. */
5753d8817e4Smiod }
5763d8817e4Smiod
5773d8817e4Smiod return styp_flags;
5783d8817e4Smiod }
5793d8817e4Smiod
5803d8817e4Smiod #endif /* COFF_WITH_PE */
5813d8817e4Smiod
5823d8817e4Smiod /* Return a word with SEC_* flags set to represent the incoming STYP_*
5833d8817e4Smiod flags (from scnhdr.s_flags). The inverse of this function is
5843d8817e4Smiod sec_to_styp_flags(). NOTE: If you add to/change this routine, you
5853d8817e4Smiod should probably mirror the changes in sec_to_styp_flags(). */
5863d8817e4Smiod
5873d8817e4Smiod #ifndef COFF_WITH_PE
5883d8817e4Smiod
5893d8817e4Smiod static bfd_boolean
styp_to_sec_flags(bfd * abfd ATTRIBUTE_UNUSED,void * hdr,const char * name,asection * section ATTRIBUTE_UNUSED,flagword * flags_ptr)5903d8817e4Smiod styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
5913d8817e4Smiod void * hdr,
5923d8817e4Smiod const char *name,
5933d8817e4Smiod asection *section ATTRIBUTE_UNUSED,
5943d8817e4Smiod flagword *flags_ptr)
5953d8817e4Smiod {
5963d8817e4Smiod struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
5973d8817e4Smiod long styp_flags = internal_s->s_flags;
5983d8817e4Smiod flagword sec_flags = 0;
5993d8817e4Smiod
6003d8817e4Smiod #ifdef STYP_BLOCK
6013d8817e4Smiod if (styp_flags & STYP_BLOCK)
6023d8817e4Smiod sec_flags |= SEC_TIC54X_BLOCK;
6033d8817e4Smiod #endif
6043d8817e4Smiod
6053d8817e4Smiod #ifdef STYP_CLINK
6063d8817e4Smiod if (styp_flags & STYP_CLINK)
6073d8817e4Smiod sec_flags |= SEC_TIC54X_CLINK;
6083d8817e4Smiod #endif
6093d8817e4Smiod
6103d8817e4Smiod #ifdef STYP_NOLOAD
6113d8817e4Smiod if (styp_flags & STYP_NOLOAD)
6123d8817e4Smiod sec_flags |= SEC_NEVER_LOAD;
6133d8817e4Smiod #endif /* STYP_NOLOAD */
6143d8817e4Smiod
6153d8817e4Smiod /* For 386 COFF, at least, an unloadable text or data section is
6163d8817e4Smiod actually a shared library section. */
6173d8817e4Smiod if (styp_flags & STYP_TEXT)
6183d8817e4Smiod {
6193d8817e4Smiod if (sec_flags & SEC_NEVER_LOAD)
6203d8817e4Smiod sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
6213d8817e4Smiod else
6223d8817e4Smiod sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
6233d8817e4Smiod }
6243d8817e4Smiod else if (styp_flags & STYP_DATA)
6253d8817e4Smiod {
6263d8817e4Smiod if (sec_flags & SEC_NEVER_LOAD)
6273d8817e4Smiod sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
6283d8817e4Smiod else
6293d8817e4Smiod sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
6303d8817e4Smiod }
6313d8817e4Smiod else if (styp_flags & STYP_BSS)
6323d8817e4Smiod {
6333d8817e4Smiod #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
6343d8817e4Smiod if (sec_flags & SEC_NEVER_LOAD)
6353d8817e4Smiod sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
6363d8817e4Smiod else
6373d8817e4Smiod #endif
6383d8817e4Smiod sec_flags |= SEC_ALLOC;
6393d8817e4Smiod }
6403d8817e4Smiod else if (styp_flags & STYP_INFO)
6413d8817e4Smiod {
6423d8817e4Smiod /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
6433d8817e4Smiod defined. coff_compute_section_file_positions uses
6443d8817e4Smiod COFF_PAGE_SIZE to ensure that the low order bits of the
6453d8817e4Smiod section VMA and the file offset match. If we don't know
6463d8817e4Smiod COFF_PAGE_SIZE, we can't ensure the correct correspondence,
6473d8817e4Smiod and demand page loading of the file will fail. */
6483d8817e4Smiod #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
6493d8817e4Smiod sec_flags |= SEC_DEBUGGING;
6503d8817e4Smiod #endif
6513d8817e4Smiod }
6523d8817e4Smiod else if (styp_flags & STYP_PAD)
6533d8817e4Smiod sec_flags = 0;
6543d8817e4Smiod else if (strcmp (name, _TEXT) == 0)
6553d8817e4Smiod {
6563d8817e4Smiod if (sec_flags & SEC_NEVER_LOAD)
6573d8817e4Smiod sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
6583d8817e4Smiod else
6593d8817e4Smiod sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
6603d8817e4Smiod }
6613d8817e4Smiod else if (strcmp (name, _DATA) == 0)
6623d8817e4Smiod {
6633d8817e4Smiod if (sec_flags & SEC_NEVER_LOAD)
6643d8817e4Smiod sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
6653d8817e4Smiod else
6663d8817e4Smiod sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
6673d8817e4Smiod }
6683d8817e4Smiod else if (strcmp (name, _BSS) == 0)
6693d8817e4Smiod {
6703d8817e4Smiod #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
6713d8817e4Smiod if (sec_flags & SEC_NEVER_LOAD)
6723d8817e4Smiod sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
6733d8817e4Smiod else
6743d8817e4Smiod #endif
6753d8817e4Smiod sec_flags |= SEC_ALLOC;
6763d8817e4Smiod }
6773d8817e4Smiod else if (strncmp (name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
6783d8817e4Smiod #ifdef _COMMENT
6793d8817e4Smiod || strcmp (name, _COMMENT) == 0
6803d8817e4Smiod #endif
6813d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
6823d8817e4Smiod || strncmp (name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0
6833d8817e4Smiod #endif
6843d8817e4Smiod || strncmp (name, ".stab", 5) == 0)
6853d8817e4Smiod {
6863d8817e4Smiod #ifdef COFF_PAGE_SIZE
6873d8817e4Smiod sec_flags |= SEC_DEBUGGING;
6883d8817e4Smiod #endif
6893d8817e4Smiod }
6903d8817e4Smiod #ifdef _LIB
6913d8817e4Smiod else if (strcmp (name, _LIB) == 0)
6923d8817e4Smiod ;
6933d8817e4Smiod #endif
6943d8817e4Smiod #ifdef _LIT
6953d8817e4Smiod else if (strcmp (name, _LIT) == 0)
6963d8817e4Smiod sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
6973d8817e4Smiod #endif
6983d8817e4Smiod else
6993d8817e4Smiod sec_flags |= SEC_ALLOC | SEC_LOAD;
7003d8817e4Smiod
7013d8817e4Smiod #ifdef STYP_LIT /* A29k readonly text/data section type. */
7023d8817e4Smiod if ((styp_flags & STYP_LIT) == STYP_LIT)
7033d8817e4Smiod sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
7043d8817e4Smiod #endif /* STYP_LIT */
7053d8817e4Smiod
7063d8817e4Smiod #ifdef STYP_OTHER_LOAD /* Other loaded sections. */
7073d8817e4Smiod if (styp_flags & STYP_OTHER_LOAD)
7083d8817e4Smiod sec_flags = (SEC_LOAD | SEC_ALLOC);
7093d8817e4Smiod #endif /* STYP_SDATA */
7103d8817e4Smiod
7113d8817e4Smiod #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
7123d8817e4Smiod /* As a GNU extension, if the name begins with .gnu.linkonce, we
7133d8817e4Smiod only link a single copy of the section. This is used to support
7143d8817e4Smiod g++. g++ will emit each template expansion in its own section.
7153d8817e4Smiod The symbols will be defined as weak, so that multiple definitions
7163d8817e4Smiod are permitted. The GNU linker extension is to actually discard
7173d8817e4Smiod all but one of the sections. */
7183d8817e4Smiod if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
7193d8817e4Smiod sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
7203d8817e4Smiod #endif
7213d8817e4Smiod
7223d8817e4Smiod if (flags_ptr == NULL)
7233d8817e4Smiod return FALSE;
7243d8817e4Smiod
7253d8817e4Smiod * flags_ptr = sec_flags;
7263d8817e4Smiod return TRUE;
7273d8817e4Smiod }
7283d8817e4Smiod
7293d8817e4Smiod #else /* COFF_WITH_PE */
7303d8817e4Smiod
7313d8817e4Smiod static flagword
handle_COMDAT(bfd * abfd,flagword sec_flags,void * hdr,const char * name,asection * section)7323d8817e4Smiod handle_COMDAT (bfd * abfd,
7333d8817e4Smiod flagword sec_flags,
7343d8817e4Smiod void * hdr,
7353d8817e4Smiod const char *name,
7363d8817e4Smiod asection *section)
7373d8817e4Smiod {
7383d8817e4Smiod struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
7393d8817e4Smiod bfd_byte *esymstart, *esym, *esymend;
7403d8817e4Smiod int seen_state = 0;
7413d8817e4Smiod char *target_name = NULL;
7423d8817e4Smiod
7433d8817e4Smiod sec_flags |= SEC_LINK_ONCE;
7443d8817e4Smiod
7453d8817e4Smiod /* Unfortunately, the PE format stores essential information in
7463d8817e4Smiod the symbol table, of all places. We need to extract that
7473d8817e4Smiod information now, so that objdump and the linker will know how
7483d8817e4Smiod to handle the section without worrying about the symbols. We
7493d8817e4Smiod can't call slurp_symtab, because the linker doesn't want the
7503d8817e4Smiod swapped symbols. */
7513d8817e4Smiod
7523d8817e4Smiod /* COMDAT sections are special. The first symbol is the section
7533d8817e4Smiod symbol, which tells what kind of COMDAT section it is. The
7543d8817e4Smiod second symbol is the "comdat symbol" - the one with the
7553d8817e4Smiod unique name. GNU uses the section symbol for the unique
7563d8817e4Smiod name; MS uses ".text" for every comdat section. Sigh. - DJ */
7573d8817e4Smiod
7583d8817e4Smiod /* This is not mirrored in sec_to_styp_flags(), but there
7593d8817e4Smiod doesn't seem to be a need to, either, and it would at best be
7603d8817e4Smiod rather messy. */
7613d8817e4Smiod
7623d8817e4Smiod if (! _bfd_coff_get_external_symbols (abfd))
7633d8817e4Smiod return sec_flags;
7643d8817e4Smiod
7653d8817e4Smiod esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
7663d8817e4Smiod esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
7673d8817e4Smiod
7683d8817e4Smiod while (esym < esymend)
7693d8817e4Smiod {
7703d8817e4Smiod struct internal_syment isym;
7713d8817e4Smiod char buf[SYMNMLEN + 1];
7723d8817e4Smiod const char *symname;
7733d8817e4Smiod
7743d8817e4Smiod bfd_coff_swap_sym_in (abfd, esym, & isym);
7753d8817e4Smiod
7763d8817e4Smiod if (sizeof (internal_s->s_name) > SYMNMLEN)
7773d8817e4Smiod {
7783d8817e4Smiod /* This case implies that the matching
7793d8817e4Smiod symbol name will be in the string table. */
7803d8817e4Smiod abort ();
7813d8817e4Smiod }
7823d8817e4Smiod
7833d8817e4Smiod if (isym.n_scnum == section->target_index)
7843d8817e4Smiod {
7853d8817e4Smiod /* According to the MSVC documentation, the first
7863d8817e4Smiod TWO entries with the section # are both of
7873d8817e4Smiod interest to us. The first one is the "section
7883d8817e4Smiod symbol" (section name). The second is the comdat
7893d8817e4Smiod symbol name. Here, we've found the first
7903d8817e4Smiod qualifying entry; we distinguish it from the
7913d8817e4Smiod second with a state flag.
7923d8817e4Smiod
7933d8817e4Smiod In the case of gas-generated (at least until that
7943d8817e4Smiod is fixed) .o files, it isn't necessarily the
7953d8817e4Smiod second one. It may be some other later symbol.
7963d8817e4Smiod
7973d8817e4Smiod Since gas also doesn't follow MS conventions and
7983d8817e4Smiod emits the section similar to .text$<name>, where
7993d8817e4Smiod <something> is the name we're looking for, we
8003d8817e4Smiod distinguish the two as follows:
8013d8817e4Smiod
8023d8817e4Smiod If the section name is simply a section name (no
8033d8817e4Smiod $) we presume it's MS-generated, and look at
8043d8817e4Smiod precisely the second symbol for the comdat name.
8053d8817e4Smiod If the section name has a $, we assume it's
8063d8817e4Smiod gas-generated, and look for <something> (whatever
8073d8817e4Smiod follows the $) as the comdat symbol. */
8083d8817e4Smiod
8093d8817e4Smiod /* All 3 branches use this. */
8103d8817e4Smiod symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
8113d8817e4Smiod
8123d8817e4Smiod if (symname == NULL)
8133d8817e4Smiod abort ();
8143d8817e4Smiod
8153d8817e4Smiod switch (seen_state)
8163d8817e4Smiod {
8173d8817e4Smiod case 0:
8183d8817e4Smiod {
8193d8817e4Smiod /* The first time we've seen the symbol. */
8203d8817e4Smiod union internal_auxent aux;
8213d8817e4Smiod
8223d8817e4Smiod /* If it isn't the stuff we're expecting, die;
8233d8817e4Smiod The MS documentation is vague, but it
8243d8817e4Smiod appears that the second entry serves BOTH
8253d8817e4Smiod as the comdat symbol and the defining
8263d8817e4Smiod symbol record (either C_STAT or C_EXT,
8273d8817e4Smiod possibly with an aux entry with debug
8283d8817e4Smiod information if it's a function.) It
8293d8817e4Smiod appears the only way to find the second one
8303d8817e4Smiod is to count. (On Intel, they appear to be
8313d8817e4Smiod adjacent, but on Alpha, they have been
8323d8817e4Smiod found separated.)
8333d8817e4Smiod
8343d8817e4Smiod Here, we think we've found the first one,
8353d8817e4Smiod but there's some checking we can do to be
8363d8817e4Smiod sure. */
8373d8817e4Smiod
8383d8817e4Smiod if (! (isym.n_sclass == C_STAT
8393d8817e4Smiod && isym.n_type == T_NULL
8403d8817e4Smiod && isym.n_value == 0))
8413d8817e4Smiod abort ();
8423d8817e4Smiod
8433d8817e4Smiod /* FIXME LATER: MSVC generates section names
8443d8817e4Smiod like .text for comdats. Gas generates
8453d8817e4Smiod names like .text$foo__Fv (in the case of a
8463d8817e4Smiod function). See comment above for more. */
8473d8817e4Smiod
8483d8817e4Smiod if (strcmp (name, symname) != 0)
8493d8817e4Smiod _bfd_error_handler (_("%B: warning: COMDAT symbol '%s' does not match section name '%s'"),
8503d8817e4Smiod abfd, symname, name);
8513d8817e4Smiod
8523d8817e4Smiod seen_state = 1;
8533d8817e4Smiod
8543d8817e4Smiod /* This is the section symbol. */
8553d8817e4Smiod bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
8563d8817e4Smiod isym.n_type, isym.n_sclass,
8573d8817e4Smiod 0, isym.n_numaux, & aux);
8583d8817e4Smiod
8593d8817e4Smiod target_name = strchr (name, '$');
8603d8817e4Smiod if (target_name != NULL)
8613d8817e4Smiod {
8623d8817e4Smiod /* Gas mode. */
8633d8817e4Smiod seen_state = 2;
8643d8817e4Smiod /* Skip the `$'. */
8653d8817e4Smiod target_name += 1;
8663d8817e4Smiod }
8673d8817e4Smiod
8683d8817e4Smiod /* FIXME: Microsoft uses NODUPLICATES and
8693d8817e4Smiod ASSOCIATIVE, but gnu uses ANY and
8703d8817e4Smiod SAME_SIZE. Unfortunately, gnu doesn't do
8713d8817e4Smiod the comdat symbols right. So, until we can
8723d8817e4Smiod fix it to do the right thing, we are
8733d8817e4Smiod temporarily disabling comdats for the MS
8743d8817e4Smiod types (they're used in DLLs and C++, but we
8753d8817e4Smiod don't support *their* C++ libraries anyway
8763d8817e4Smiod - DJ. */
8773d8817e4Smiod
8783d8817e4Smiod /* Cygwin does not follow the MS style, and
8793d8817e4Smiod uses ANY and SAME_SIZE where NODUPLICATES
8803d8817e4Smiod and ASSOCIATIVE should be used. For
8813d8817e4Smiod Interix, we just do the right thing up
8823d8817e4Smiod front. */
8833d8817e4Smiod
8843d8817e4Smiod switch (aux.x_scn.x_comdat)
8853d8817e4Smiod {
8863d8817e4Smiod case IMAGE_COMDAT_SELECT_NODUPLICATES:
8873d8817e4Smiod #ifdef STRICT_PE_FORMAT
8883d8817e4Smiod sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
8893d8817e4Smiod #else
8903d8817e4Smiod sec_flags &= ~SEC_LINK_ONCE;
8913d8817e4Smiod #endif
8923d8817e4Smiod break;
8933d8817e4Smiod
8943d8817e4Smiod case IMAGE_COMDAT_SELECT_ANY:
8953d8817e4Smiod sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
8963d8817e4Smiod break;
8973d8817e4Smiod
8983d8817e4Smiod case IMAGE_COMDAT_SELECT_SAME_SIZE:
8993d8817e4Smiod sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
9003d8817e4Smiod break;
9013d8817e4Smiod
9023d8817e4Smiod case IMAGE_COMDAT_SELECT_EXACT_MATCH:
9033d8817e4Smiod /* Not yet fully implemented ??? */
9043d8817e4Smiod sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
9053d8817e4Smiod break;
9063d8817e4Smiod
9073d8817e4Smiod /* debug$S gets this case; other
9083d8817e4Smiod implications ??? */
9093d8817e4Smiod
9103d8817e4Smiod /* There may be no symbol... we'll search
9113d8817e4Smiod the whole table... Is this the right
9123d8817e4Smiod place to play this game? Or should we do
9133d8817e4Smiod it when reading it in. */
9143d8817e4Smiod case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
9153d8817e4Smiod #ifdef STRICT_PE_FORMAT
9163d8817e4Smiod /* FIXME: This is not currently implemented. */
9173d8817e4Smiod sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
9183d8817e4Smiod #else
9193d8817e4Smiod sec_flags &= ~SEC_LINK_ONCE;
9203d8817e4Smiod #endif
9213d8817e4Smiod break;
9223d8817e4Smiod
9233d8817e4Smiod default: /* 0 means "no symbol" */
9243d8817e4Smiod /* debug$F gets this case; other
9253d8817e4Smiod implications ??? */
9263d8817e4Smiod sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
9273d8817e4Smiod break;
9283d8817e4Smiod }
9293d8817e4Smiod }
9303d8817e4Smiod break;
9313d8817e4Smiod
9323d8817e4Smiod case 2:
9333d8817e4Smiod /* Gas mode: the first matching on partial name. */
9343d8817e4Smiod
9353d8817e4Smiod #ifndef TARGET_UNDERSCORE
9363d8817e4Smiod #define TARGET_UNDERSCORE 0
9373d8817e4Smiod #endif
9383d8817e4Smiod /* Is this the name we're looking for ? */
9393d8817e4Smiod if (strcmp (target_name,
9403d8817e4Smiod symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
9413d8817e4Smiod {
9423d8817e4Smiod /* Not the name we're looking for */
9433d8817e4Smiod esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
9443d8817e4Smiod continue;
9453d8817e4Smiod }
9463d8817e4Smiod /* Fall through. */
9473d8817e4Smiod case 1:
9483d8817e4Smiod /* MSVC mode: the lexically second symbol (or
9493d8817e4Smiod drop through from the above). */
9503d8817e4Smiod {
9513d8817e4Smiod char *newname;
9523d8817e4Smiod bfd_size_type amt;
9533d8817e4Smiod
9543d8817e4Smiod /* This must the second symbol with the
9553d8817e4Smiod section #. It is the actual symbol name.
9563d8817e4Smiod Intel puts the two adjacent, but Alpha (at
9573d8817e4Smiod least) spreads them out. */
9583d8817e4Smiod
9593d8817e4Smiod amt = sizeof (struct coff_comdat_info);
9603d8817e4Smiod coff_section_data (abfd, section)->comdat
9613d8817e4Smiod = bfd_alloc (abfd, amt);
9623d8817e4Smiod if (coff_section_data (abfd, section)->comdat == NULL)
9633d8817e4Smiod abort ();
9643d8817e4Smiod
9653d8817e4Smiod coff_section_data (abfd, section)->comdat->symbol =
9663d8817e4Smiod (esym - esymstart) / bfd_coff_symesz (abfd);
9673d8817e4Smiod
9683d8817e4Smiod amt = strlen (symname) + 1;
9693d8817e4Smiod newname = bfd_alloc (abfd, amt);
9703d8817e4Smiod if (newname == NULL)
9713d8817e4Smiod abort ();
9723d8817e4Smiod
9733d8817e4Smiod strcpy (newname, symname);
9743d8817e4Smiod coff_section_data (abfd, section)->comdat->name
9753d8817e4Smiod = newname;
9763d8817e4Smiod }
9773d8817e4Smiod
9783d8817e4Smiod goto breakloop;
9793d8817e4Smiod }
9803d8817e4Smiod }
9813d8817e4Smiod
9823d8817e4Smiod esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
9833d8817e4Smiod }
9843d8817e4Smiod
9853d8817e4Smiod breakloop:
9863d8817e4Smiod return sec_flags;
9873d8817e4Smiod }
9883d8817e4Smiod
9893d8817e4Smiod
9903d8817e4Smiod /* The PE version; see above for the general comments.
9913d8817e4Smiod
9923d8817e4Smiod Since to set the SEC_LINK_ONCE and associated flags, we have to
9933d8817e4Smiod look at the symbol table anyway, we return the symbol table index
9943d8817e4Smiod of the symbol being used as the COMDAT symbol. This is admittedly
9953d8817e4Smiod ugly, but there's really nowhere else that we have access to the
9963d8817e4Smiod required information. FIXME: Is the COMDAT symbol index used for
9973d8817e4Smiod any purpose other than objdump? */
9983d8817e4Smiod
9993d8817e4Smiod static bfd_boolean
styp_to_sec_flags(bfd * abfd,void * hdr,const char * name,asection * section,flagword * flags_ptr)10003d8817e4Smiod styp_to_sec_flags (bfd *abfd,
10013d8817e4Smiod void * hdr,
10023d8817e4Smiod const char *name,
10033d8817e4Smiod asection *section,
10043d8817e4Smiod flagword *flags_ptr)
10053d8817e4Smiod {
10063d8817e4Smiod struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
10073d8817e4Smiod long styp_flags = internal_s->s_flags;
10083d8817e4Smiod flagword sec_flags;
10093d8817e4Smiod bfd_boolean result = TRUE;
10103d8817e4Smiod
10113d8817e4Smiod /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified. */
10123d8817e4Smiod sec_flags = SEC_READONLY;
10133d8817e4Smiod
10143d8817e4Smiod /* Process each flag bit in styp_flags in turn. */
10153d8817e4Smiod while (styp_flags)
10163d8817e4Smiod {
10173d8817e4Smiod long flag = styp_flags & - styp_flags;
10183d8817e4Smiod char * unhandled = NULL;
10193d8817e4Smiod
10203d8817e4Smiod styp_flags &= ~ flag;
10213d8817e4Smiod
10223d8817e4Smiod /* We infer from the distinct read/write/execute bits the settings
10233d8817e4Smiod of some of the bfd flags; the actual values, should we need them,
10243d8817e4Smiod are also in pei_section_data (abfd, section)->pe_flags. */
10253d8817e4Smiod
10263d8817e4Smiod switch (flag)
10273d8817e4Smiod {
10283d8817e4Smiod case STYP_DSECT:
10293d8817e4Smiod unhandled = "STYP_DSECT";
10303d8817e4Smiod break;
10313d8817e4Smiod case STYP_GROUP:
10323d8817e4Smiod unhandled = "STYP_GROUP";
10333d8817e4Smiod break;
10343d8817e4Smiod case STYP_COPY:
10353d8817e4Smiod unhandled = "STYP_COPY";
10363d8817e4Smiod break;
10373d8817e4Smiod case STYP_OVER:
10383d8817e4Smiod unhandled = "STYP_OVER";
10393d8817e4Smiod break;
10403d8817e4Smiod #ifdef SEC_NEVER_LOAD
10413d8817e4Smiod case STYP_NOLOAD:
10423d8817e4Smiod sec_flags |= SEC_NEVER_LOAD;
10433d8817e4Smiod break;
10443d8817e4Smiod #endif
10453d8817e4Smiod case IMAGE_SCN_MEM_READ:
10463d8817e4Smiod /* Ignored, assume it always to be true. */
10473d8817e4Smiod break;
10483d8817e4Smiod case IMAGE_SCN_TYPE_NO_PAD:
10493d8817e4Smiod /* Skip. */
10503d8817e4Smiod break;
10513d8817e4Smiod case IMAGE_SCN_LNK_OTHER:
10523d8817e4Smiod unhandled = "IMAGE_SCN_LNK_OTHER";
10533d8817e4Smiod break;
10543d8817e4Smiod case IMAGE_SCN_MEM_NOT_CACHED:
10553d8817e4Smiod unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
10563d8817e4Smiod break;
10573d8817e4Smiod case IMAGE_SCN_MEM_NOT_PAGED:
10583d8817e4Smiod /* Generate a warning message rather using the 'unhandled'
10593d8817e4Smiod variable as this will allow some .sys files generate by
10603d8817e4Smiod other toolchains to be processed. See bugzilla issue 196. */
10613d8817e4Smiod _bfd_error_handler (_("%B: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section %s"),
10623d8817e4Smiod abfd, name);
10633d8817e4Smiod break;
10643d8817e4Smiod case IMAGE_SCN_MEM_EXECUTE:
10653d8817e4Smiod sec_flags |= SEC_CODE;
10663d8817e4Smiod break;
10673d8817e4Smiod case IMAGE_SCN_MEM_WRITE:
10683d8817e4Smiod sec_flags &= ~ SEC_READONLY;
10693d8817e4Smiod break;
10703d8817e4Smiod case IMAGE_SCN_MEM_DISCARDABLE:
10713d8817e4Smiod /* The MS PE spec sets the DISCARDABLE flag on .reloc sections
10723d8817e4Smiod but we do not want them to be labelled as debug section, since
10733d8817e4Smiod then strip would remove them. */
10743d8817e4Smiod if (strncmp (name, ".reloc", sizeof ".reloc" - 1) != 0)
10753d8817e4Smiod sec_flags |= SEC_DEBUGGING;
10763d8817e4Smiod break;
10773d8817e4Smiod case IMAGE_SCN_MEM_SHARED:
10783d8817e4Smiod sec_flags |= SEC_COFF_SHARED;
10793d8817e4Smiod break;
10803d8817e4Smiod case IMAGE_SCN_LNK_REMOVE:
10813d8817e4Smiod sec_flags |= SEC_EXCLUDE;
10823d8817e4Smiod break;
10833d8817e4Smiod case IMAGE_SCN_CNT_CODE:
10843d8817e4Smiod sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
10853d8817e4Smiod break;
10863d8817e4Smiod case IMAGE_SCN_CNT_INITIALIZED_DATA:
10873d8817e4Smiod sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
10883d8817e4Smiod break;
10893d8817e4Smiod case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
10903d8817e4Smiod sec_flags |= SEC_ALLOC;
10913d8817e4Smiod break;
10923d8817e4Smiod case IMAGE_SCN_LNK_INFO:
10933d8817e4Smiod /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
10943d8817e4Smiod defined. coff_compute_section_file_positions uses
10953d8817e4Smiod COFF_PAGE_SIZE to ensure that the low order bits of the
10963d8817e4Smiod section VMA and the file offset match. If we don't know
10973d8817e4Smiod COFF_PAGE_SIZE, we can't ensure the correct correspondence,
10983d8817e4Smiod and demand page loading of the file will fail. */
10993d8817e4Smiod #ifdef COFF_PAGE_SIZE
11003d8817e4Smiod sec_flags |= SEC_DEBUGGING;
11013d8817e4Smiod #endif
11023d8817e4Smiod break;
11033d8817e4Smiod case IMAGE_SCN_LNK_COMDAT:
11043d8817e4Smiod /* COMDAT gets very special treatment. */
11053d8817e4Smiod sec_flags = handle_COMDAT (abfd, sec_flags, hdr, name, section);
11063d8817e4Smiod break;
11073d8817e4Smiod default:
11083d8817e4Smiod /* Silently ignore for now. */
11093d8817e4Smiod break;
11103d8817e4Smiod }
11113d8817e4Smiod
11123d8817e4Smiod /* If the section flag was not handled, report it here. */
11133d8817e4Smiod if (unhandled != NULL)
11143d8817e4Smiod {
11153d8817e4Smiod (*_bfd_error_handler)
11163d8817e4Smiod (_("%B (%s): Section flag %s (0x%x) ignored"),
11173d8817e4Smiod abfd, name, unhandled, flag);
11183d8817e4Smiod result = FALSE;
11193d8817e4Smiod }
11203d8817e4Smiod }
11213d8817e4Smiod
11223d8817e4Smiod #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
11233d8817e4Smiod /* As a GNU extension, if the name begins with .gnu.linkonce, we
11243d8817e4Smiod only link a single copy of the section. This is used to support
11253d8817e4Smiod g++. g++ will emit each template expansion in its own section.
11263d8817e4Smiod The symbols will be defined as weak, so that multiple definitions
11273d8817e4Smiod are permitted. The GNU linker extension is to actually discard
11283d8817e4Smiod all but one of the sections. */
11293d8817e4Smiod if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
11303d8817e4Smiod sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
11313d8817e4Smiod #endif
11323d8817e4Smiod
11333d8817e4Smiod if (flags_ptr)
11343d8817e4Smiod * flags_ptr = sec_flags;
11353d8817e4Smiod
11363d8817e4Smiod return result;
11373d8817e4Smiod }
11383d8817e4Smiod
11393d8817e4Smiod #endif /* COFF_WITH_PE */
11403d8817e4Smiod
11413d8817e4Smiod #define get_index(symbol) ((symbol)->udata.i)
11423d8817e4Smiod
11433d8817e4Smiod /*
11443d8817e4Smiod INTERNAL_DEFINITION
11453d8817e4Smiod bfd_coff_backend_data
11463d8817e4Smiod
11473d8817e4Smiod CODE_FRAGMENT
11483d8817e4Smiod
11493d8817e4Smiod .{* COFF symbol classifications. *}
11503d8817e4Smiod .
11513d8817e4Smiod .enum coff_symbol_classification
11523d8817e4Smiod .{
11533d8817e4Smiod . {* Global symbol. *}
11543d8817e4Smiod . COFF_SYMBOL_GLOBAL,
11553d8817e4Smiod . {* Common symbol. *}
11563d8817e4Smiod . COFF_SYMBOL_COMMON,
11573d8817e4Smiod . {* Undefined symbol. *}
11583d8817e4Smiod . COFF_SYMBOL_UNDEFINED,
11593d8817e4Smiod . {* Local symbol. *}
11603d8817e4Smiod . COFF_SYMBOL_LOCAL,
11613d8817e4Smiod . {* PE section symbol. *}
11623d8817e4Smiod . COFF_SYMBOL_PE_SECTION
11633d8817e4Smiod .};
11643d8817e4Smiod .
11653d8817e4Smiod Special entry points for gdb to swap in coff symbol table parts:
11663d8817e4Smiod .typedef struct
11673d8817e4Smiod .{
11683d8817e4Smiod . void (*_bfd_coff_swap_aux_in)
11693d8817e4Smiod . (bfd *, void *, int, int, int, int, void *);
11703d8817e4Smiod .
11713d8817e4Smiod . void (*_bfd_coff_swap_sym_in)
11723d8817e4Smiod . (bfd *, void *, void *);
11733d8817e4Smiod .
11743d8817e4Smiod . void (*_bfd_coff_swap_lineno_in)
11753d8817e4Smiod . (bfd *, void *, void *);
11763d8817e4Smiod .
11773d8817e4Smiod . unsigned int (*_bfd_coff_swap_aux_out)
11783d8817e4Smiod . (bfd *, void *, int, int, int, int, void *);
11793d8817e4Smiod .
11803d8817e4Smiod . unsigned int (*_bfd_coff_swap_sym_out)
11813d8817e4Smiod . (bfd *, void *, void *);
11823d8817e4Smiod .
11833d8817e4Smiod . unsigned int (*_bfd_coff_swap_lineno_out)
11843d8817e4Smiod . (bfd *, void *, void *);
11853d8817e4Smiod .
11863d8817e4Smiod . unsigned int (*_bfd_coff_swap_reloc_out)
11873d8817e4Smiod . (bfd *, void *, void *);
11883d8817e4Smiod .
11893d8817e4Smiod . unsigned int (*_bfd_coff_swap_filehdr_out)
11903d8817e4Smiod . (bfd *, void *, void *);
11913d8817e4Smiod .
11923d8817e4Smiod . unsigned int (*_bfd_coff_swap_aouthdr_out)
11933d8817e4Smiod . (bfd *, void *, void *);
11943d8817e4Smiod .
11953d8817e4Smiod . unsigned int (*_bfd_coff_swap_scnhdr_out)
11963d8817e4Smiod . (bfd *, void *, void *);
11973d8817e4Smiod .
11983d8817e4Smiod . unsigned int _bfd_filhsz;
11993d8817e4Smiod . unsigned int _bfd_aoutsz;
12003d8817e4Smiod . unsigned int _bfd_scnhsz;
12013d8817e4Smiod . unsigned int _bfd_symesz;
12023d8817e4Smiod . unsigned int _bfd_auxesz;
12033d8817e4Smiod . unsigned int _bfd_relsz;
12043d8817e4Smiod . unsigned int _bfd_linesz;
12053d8817e4Smiod . unsigned int _bfd_filnmlen;
12063d8817e4Smiod . bfd_boolean _bfd_coff_long_filenames;
12073d8817e4Smiod . bfd_boolean _bfd_coff_long_section_names;
12083d8817e4Smiod . unsigned int _bfd_coff_default_section_alignment_power;
12093d8817e4Smiod . bfd_boolean _bfd_coff_force_symnames_in_strings;
12103d8817e4Smiod . unsigned int _bfd_coff_debug_string_prefix_length;
12113d8817e4Smiod .
12123d8817e4Smiod . void (*_bfd_coff_swap_filehdr_in)
12133d8817e4Smiod . (bfd *, void *, void *);
12143d8817e4Smiod .
12153d8817e4Smiod . void (*_bfd_coff_swap_aouthdr_in)
12163d8817e4Smiod . (bfd *, void *, void *);
12173d8817e4Smiod .
12183d8817e4Smiod . void (*_bfd_coff_swap_scnhdr_in)
12193d8817e4Smiod . (bfd *, void *, void *);
12203d8817e4Smiod .
12213d8817e4Smiod . void (*_bfd_coff_swap_reloc_in)
12223d8817e4Smiod . (bfd *abfd, void *, void *);
12233d8817e4Smiod .
12243d8817e4Smiod . bfd_boolean (*_bfd_coff_bad_format_hook)
12253d8817e4Smiod . (bfd *, void *);
12263d8817e4Smiod .
12273d8817e4Smiod . bfd_boolean (*_bfd_coff_set_arch_mach_hook)
12283d8817e4Smiod . (bfd *, void *);
12293d8817e4Smiod .
12303d8817e4Smiod . void * (*_bfd_coff_mkobject_hook)
12313d8817e4Smiod . (bfd *, void *, void *);
12323d8817e4Smiod .
12333d8817e4Smiod . bfd_boolean (*_bfd_styp_to_sec_flags_hook)
12343d8817e4Smiod . (bfd *, void *, const char *, asection *, flagword *);
12353d8817e4Smiod .
12363d8817e4Smiod . void (*_bfd_set_alignment_hook)
12373d8817e4Smiod . (bfd *, asection *, void *);
12383d8817e4Smiod .
12393d8817e4Smiod . bfd_boolean (*_bfd_coff_slurp_symbol_table)
12403d8817e4Smiod . (bfd *);
12413d8817e4Smiod .
12423d8817e4Smiod . bfd_boolean (*_bfd_coff_symname_in_debug)
12433d8817e4Smiod . (bfd *, struct internal_syment *);
12443d8817e4Smiod .
12453d8817e4Smiod . bfd_boolean (*_bfd_coff_pointerize_aux_hook)
12463d8817e4Smiod . (bfd *, combined_entry_type *, combined_entry_type *,
12473d8817e4Smiod . unsigned int, combined_entry_type *);
12483d8817e4Smiod .
12493d8817e4Smiod . bfd_boolean (*_bfd_coff_print_aux)
12503d8817e4Smiod . (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
12513d8817e4Smiod . combined_entry_type *, unsigned int);
12523d8817e4Smiod .
12533d8817e4Smiod . void (*_bfd_coff_reloc16_extra_cases)
12543d8817e4Smiod . (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
12553d8817e4Smiod . bfd_byte *, unsigned int *, unsigned int *);
12563d8817e4Smiod .
12573d8817e4Smiod . int (*_bfd_coff_reloc16_estimate)
12583d8817e4Smiod . (bfd *, asection *, arelent *, unsigned int,
12593d8817e4Smiod . struct bfd_link_info *);
12603d8817e4Smiod .
12613d8817e4Smiod . enum coff_symbol_classification (*_bfd_coff_classify_symbol)
12623d8817e4Smiod . (bfd *, struct internal_syment *);
12633d8817e4Smiod .
12643d8817e4Smiod . bfd_boolean (*_bfd_coff_compute_section_file_positions)
12653d8817e4Smiod . (bfd *);
12663d8817e4Smiod .
12673d8817e4Smiod . bfd_boolean (*_bfd_coff_start_final_link)
12683d8817e4Smiod . (bfd *, struct bfd_link_info *);
12693d8817e4Smiod .
12703d8817e4Smiod . bfd_boolean (*_bfd_coff_relocate_section)
12713d8817e4Smiod . (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
12723d8817e4Smiod . struct internal_reloc *, struct internal_syment *, asection **);
12733d8817e4Smiod .
12743d8817e4Smiod . reloc_howto_type *(*_bfd_coff_rtype_to_howto)
12753d8817e4Smiod . (bfd *, asection *, struct internal_reloc *,
12763d8817e4Smiod . struct coff_link_hash_entry *, struct internal_syment *,
12773d8817e4Smiod . bfd_vma *);
12783d8817e4Smiod .
12793d8817e4Smiod . bfd_boolean (*_bfd_coff_adjust_symndx)
12803d8817e4Smiod . (bfd *, struct bfd_link_info *, bfd *, asection *,
12813d8817e4Smiod . struct internal_reloc *, bfd_boolean *);
12823d8817e4Smiod .
12833d8817e4Smiod . bfd_boolean (*_bfd_coff_link_add_one_symbol)
12843d8817e4Smiod . (struct bfd_link_info *, bfd *, const char *, flagword,
12853d8817e4Smiod . asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
12863d8817e4Smiod . struct bfd_link_hash_entry **);
12873d8817e4Smiod .
12883d8817e4Smiod . bfd_boolean (*_bfd_coff_link_output_has_begun)
12893d8817e4Smiod . (bfd *, struct coff_final_link_info *);
12903d8817e4Smiod .
12913d8817e4Smiod . bfd_boolean (*_bfd_coff_final_link_postscript)
12923d8817e4Smiod . (bfd *, struct coff_final_link_info *);
12933d8817e4Smiod .
12943d8817e4Smiod .} bfd_coff_backend_data;
12953d8817e4Smiod .
12963d8817e4Smiod .#define coff_backend_info(abfd) \
12973d8817e4Smiod . ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
12983d8817e4Smiod .
12993d8817e4Smiod .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
13003d8817e4Smiod . ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
13013d8817e4Smiod .
13023d8817e4Smiod .#define bfd_coff_swap_sym_in(a,e,i) \
13033d8817e4Smiod . ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
13043d8817e4Smiod .
13053d8817e4Smiod .#define bfd_coff_swap_lineno_in(a,e,i) \
13063d8817e4Smiod . ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
13073d8817e4Smiod .
13083d8817e4Smiod .#define bfd_coff_swap_reloc_out(abfd, i, o) \
13093d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
13103d8817e4Smiod .
13113d8817e4Smiod .#define bfd_coff_swap_lineno_out(abfd, i, o) \
13123d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
13133d8817e4Smiod .
13143d8817e4Smiod .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
13153d8817e4Smiod . ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
13163d8817e4Smiod .
13173d8817e4Smiod .#define bfd_coff_swap_sym_out(abfd, i,o) \
13183d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
13193d8817e4Smiod .
13203d8817e4Smiod .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
13213d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
13223d8817e4Smiod .
13233d8817e4Smiod .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
13243d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
13253d8817e4Smiod .
13263d8817e4Smiod .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
13273d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
13283d8817e4Smiod .
13293d8817e4Smiod .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
13303d8817e4Smiod .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
13313d8817e4Smiod .#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
13323d8817e4Smiod .#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
13333d8817e4Smiod .#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
13343d8817e4Smiod .#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
13353d8817e4Smiod .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
13363d8817e4Smiod .#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
13373d8817e4Smiod .#define bfd_coff_long_filenames(abfd) \
13383d8817e4Smiod . (coff_backend_info (abfd)->_bfd_coff_long_filenames)
13393d8817e4Smiod .#define bfd_coff_long_section_names(abfd) \
13403d8817e4Smiod . (coff_backend_info (abfd)->_bfd_coff_long_section_names)
13413d8817e4Smiod .#define bfd_coff_default_section_alignment_power(abfd) \
13423d8817e4Smiod . (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
13433d8817e4Smiod .#define bfd_coff_swap_filehdr_in(abfd, i,o) \
13443d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
13453d8817e4Smiod .
13463d8817e4Smiod .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
13473d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
13483d8817e4Smiod .
13493d8817e4Smiod .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
13503d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
13513d8817e4Smiod .
13523d8817e4Smiod .#define bfd_coff_swap_reloc_in(abfd, i, o) \
13533d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
13543d8817e4Smiod .
13553d8817e4Smiod .#define bfd_coff_bad_format_hook(abfd, filehdr) \
13563d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
13573d8817e4Smiod .
13583d8817e4Smiod .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
13593d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
13603d8817e4Smiod .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
13613d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
13623d8817e4Smiod . (abfd, filehdr, aouthdr))
13633d8817e4Smiod .
13643d8817e4Smiod .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
13653d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
13663d8817e4Smiod . (abfd, scnhdr, name, section, flags_ptr))
13673d8817e4Smiod .
13683d8817e4Smiod .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
13693d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
13703d8817e4Smiod .
13713d8817e4Smiod .#define bfd_coff_slurp_symbol_table(abfd)\
13723d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
13733d8817e4Smiod .
13743d8817e4Smiod .#define bfd_coff_symname_in_debug(abfd, sym)\
13753d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
13763d8817e4Smiod .
13773d8817e4Smiod .#define bfd_coff_force_symnames_in_strings(abfd)\
13783d8817e4Smiod . (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
13793d8817e4Smiod .
13803d8817e4Smiod .#define bfd_coff_debug_string_prefix_length(abfd)\
13813d8817e4Smiod . (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
13823d8817e4Smiod .
13833d8817e4Smiod .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
13843d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
13853d8817e4Smiod . (abfd, file, base, symbol, aux, indaux))
13863d8817e4Smiod .
13873d8817e4Smiod .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
13883d8817e4Smiod . reloc, data, src_ptr, dst_ptr)\
13893d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
13903d8817e4Smiod . (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
13913d8817e4Smiod .
13923d8817e4Smiod .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
13933d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
13943d8817e4Smiod . (abfd, section, reloc, shrink, link_info))
13953d8817e4Smiod .
13963d8817e4Smiod .#define bfd_coff_classify_symbol(abfd, sym)\
13973d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
13983d8817e4Smiod . (abfd, sym))
13993d8817e4Smiod .
14003d8817e4Smiod .#define bfd_coff_compute_section_file_positions(abfd)\
14013d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
14023d8817e4Smiod . (abfd))
14033d8817e4Smiod .
14043d8817e4Smiod .#define bfd_coff_start_final_link(obfd, info)\
14053d8817e4Smiod . ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
14063d8817e4Smiod . (obfd, info))
14073d8817e4Smiod .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
14083d8817e4Smiod . ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
14093d8817e4Smiod . (obfd, info, ibfd, o, con, rel, isyms, secs))
14103d8817e4Smiod .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
14113d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
14123d8817e4Smiod . (abfd, sec, rel, h, sym, addendp))
14133d8817e4Smiod .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
14143d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
14153d8817e4Smiod . (obfd, info, ibfd, sec, rel, adjustedp))
14163d8817e4Smiod .#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
14173d8817e4Smiod . value, string, cp, coll, hashp)\
14183d8817e4Smiod . ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
14193d8817e4Smiod . (info, abfd, name, flags, section, value, string, cp, coll, hashp))
14203d8817e4Smiod .
14213d8817e4Smiod .#define bfd_coff_link_output_has_begun(a,p) \
14223d8817e4Smiod . ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
14233d8817e4Smiod .#define bfd_coff_final_link_postscript(a,p) \
14243d8817e4Smiod . ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
14253d8817e4Smiod .
14263d8817e4Smiod */
14273d8817e4Smiod
14283d8817e4Smiod /* See whether the magic number matches. */
14293d8817e4Smiod
14303d8817e4Smiod static bfd_boolean
coff_bad_format_hook(bfd * abfd ATTRIBUTE_UNUSED,void * filehdr)14313d8817e4Smiod coff_bad_format_hook (bfd * abfd ATTRIBUTE_UNUSED, void * filehdr)
14323d8817e4Smiod {
14333d8817e4Smiod struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
14343d8817e4Smiod
14353d8817e4Smiod if (BADMAG (*internal_f))
14363d8817e4Smiod return FALSE;
14373d8817e4Smiod
14383d8817e4Smiod /* If the optional header is NULL or not the correct size then
14393d8817e4Smiod quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
14403d8817e4Smiod and Intel 960 readwrite headers (I960WRMAGIC) is that the
14413d8817e4Smiod optional header is of a different size.
14423d8817e4Smiod
14433d8817e4Smiod But the mips keeps extra stuff in it's opthdr, so dont check
14443d8817e4Smiod when doing that. */
14453d8817e4Smiod
14463d8817e4Smiod #if defined(M88) || defined(I960)
14473d8817e4Smiod if (internal_f->f_opthdr != 0 && bfd_coff_aoutsz (abfd) != internal_f->f_opthdr)
14483d8817e4Smiod return FALSE;
14493d8817e4Smiod #endif
14503d8817e4Smiod
14513d8817e4Smiod return TRUE;
14523d8817e4Smiod }
14533d8817e4Smiod
14543d8817e4Smiod #ifdef TICOFF
14553d8817e4Smiod static bfd_boolean
ticoff0_bad_format_hook(bfd * abfd ATTRIBUTE_UNUSED,void * filehdr)14563d8817e4Smiod ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
14573d8817e4Smiod {
14583d8817e4Smiod struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
14593d8817e4Smiod
14603d8817e4Smiod if (COFF0_BADMAG (*internal_f))
14613d8817e4Smiod return FALSE;
14623d8817e4Smiod
14633d8817e4Smiod return TRUE;
14643d8817e4Smiod }
14653d8817e4Smiod #endif
14663d8817e4Smiod
14673d8817e4Smiod #ifdef TICOFF
14683d8817e4Smiod static bfd_boolean
ticoff1_bad_format_hook(bfd * abfd ATTRIBUTE_UNUSED,void * filehdr)14693d8817e4Smiod ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
14703d8817e4Smiod {
14713d8817e4Smiod struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
14723d8817e4Smiod
14733d8817e4Smiod if (COFF1_BADMAG (*internal_f))
14743d8817e4Smiod return FALSE;
14753d8817e4Smiod
14763d8817e4Smiod return TRUE;
14773d8817e4Smiod }
14783d8817e4Smiod #endif
14793d8817e4Smiod
14803d8817e4Smiod /* Check whether this section uses an alignment other than the
14813d8817e4Smiod default. */
14823d8817e4Smiod
14833d8817e4Smiod static void
coff_set_custom_section_alignment(bfd * abfd ATTRIBUTE_UNUSED,asection * section,const struct coff_section_alignment_entry * alignment_table,const unsigned int table_size)14843d8817e4Smiod coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED,
14853d8817e4Smiod asection *section,
14863d8817e4Smiod const struct coff_section_alignment_entry *alignment_table,
14873d8817e4Smiod const unsigned int table_size)
14883d8817e4Smiod {
14893d8817e4Smiod const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
14903d8817e4Smiod unsigned int i;
14913d8817e4Smiod
14923d8817e4Smiod for (i = 0; i < table_size; ++i)
14933d8817e4Smiod {
14943d8817e4Smiod const char *secname = bfd_get_section_name (abfd, section);
14953d8817e4Smiod
14963d8817e4Smiod if (alignment_table[i].comparison_length == (unsigned int) -1
14973d8817e4Smiod ? strcmp (alignment_table[i].name, secname) == 0
14983d8817e4Smiod : strncmp (alignment_table[i].name, secname,
14993d8817e4Smiod alignment_table[i].comparison_length) == 0)
15003d8817e4Smiod break;
15013d8817e4Smiod }
15023d8817e4Smiod if (i >= table_size)
15033d8817e4Smiod return;
15043d8817e4Smiod
15053d8817e4Smiod if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
15063d8817e4Smiod && default_alignment < alignment_table[i].default_alignment_min)
15073d8817e4Smiod return;
15083d8817e4Smiod
15093d8817e4Smiod if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
15103d8817e4Smiod #if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
15113d8817e4Smiod && default_alignment > alignment_table[i].default_alignment_max
15123d8817e4Smiod #endif
15133d8817e4Smiod )
15143d8817e4Smiod return;
15153d8817e4Smiod
15163d8817e4Smiod section->alignment_power = alignment_table[i].alignment_power;
15173d8817e4Smiod }
15183d8817e4Smiod
15193d8817e4Smiod /* Custom section alignment records. */
15203d8817e4Smiod
15213d8817e4Smiod static const struct coff_section_alignment_entry
15223d8817e4Smiod coff_section_alignment_table[] =
15233d8817e4Smiod {
15243d8817e4Smiod #ifdef COFF_SECTION_ALIGNMENT_ENTRIES
15253d8817e4Smiod COFF_SECTION_ALIGNMENT_ENTRIES,
15263d8817e4Smiod #endif
15273d8817e4Smiod /* There must not be any gaps between .stabstr sections. */
15283d8817e4Smiod { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
15293d8817e4Smiod 1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
15303d8817e4Smiod /* The .stab section must be aligned to 2**2 at most, to avoid gaps. */
15313d8817e4Smiod { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
15323d8817e4Smiod 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
15333d8817e4Smiod /* Similarly for the .ctors and .dtors sections. */
15343d8817e4Smiod { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
15353d8817e4Smiod 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
15363d8817e4Smiod { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
15373d8817e4Smiod 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
15383d8817e4Smiod };
15393d8817e4Smiod
15403d8817e4Smiod static const unsigned int coff_section_alignment_table_size =
15413d8817e4Smiod sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
15423d8817e4Smiod
15433d8817e4Smiod /* Initialize a section structure with information peculiar to this
15443d8817e4Smiod particular implementation of COFF. */
15453d8817e4Smiod
15463d8817e4Smiod static bfd_boolean
coff_new_section_hook(bfd * abfd,asection * section)15473d8817e4Smiod coff_new_section_hook (bfd * abfd, asection * section)
15483d8817e4Smiod {
15493d8817e4Smiod combined_entry_type *native;
15503d8817e4Smiod bfd_size_type amt;
15513d8817e4Smiod
15523d8817e4Smiod section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
15533d8817e4Smiod
15543d8817e4Smiod #ifdef RS6000COFF_C
15553d8817e4Smiod if (bfd_xcoff_text_align_power (abfd) != 0
15563d8817e4Smiod && strcmp (bfd_get_section_name (abfd, section), ".text") == 0)
15573d8817e4Smiod section->alignment_power = bfd_xcoff_text_align_power (abfd);
15583d8817e4Smiod if (bfd_xcoff_data_align_power (abfd) != 0
15593d8817e4Smiod && strcmp (bfd_get_section_name (abfd, section), ".data") == 0)
15603d8817e4Smiod section->alignment_power = bfd_xcoff_data_align_power (abfd);
15613d8817e4Smiod #endif
15623d8817e4Smiod
15633d8817e4Smiod /* Allocate aux records for section symbols, to store size and
15643d8817e4Smiod related info.
15653d8817e4Smiod
15663d8817e4Smiod @@ The 10 is a guess at a plausible maximum number of aux entries
15673d8817e4Smiod (but shouldn't be a constant). */
15683d8817e4Smiod amt = sizeof (combined_entry_type) * 10;
15693d8817e4Smiod native = bfd_zalloc (abfd, amt);
15703d8817e4Smiod if (native == NULL)
15713d8817e4Smiod return FALSE;
15723d8817e4Smiod
15733d8817e4Smiod /* We don't need to set up n_name, n_value, or n_scnum in the native
15743d8817e4Smiod symbol information, since they'll be overridden by the BFD symbol
15753d8817e4Smiod anyhow. However, we do need to set the type and storage class,
15763d8817e4Smiod in case this symbol winds up getting written out. The value 0
15773d8817e4Smiod for n_numaux is already correct. */
15783d8817e4Smiod
15793d8817e4Smiod native->u.syment.n_type = T_NULL;
15803d8817e4Smiod native->u.syment.n_sclass = C_STAT;
15813d8817e4Smiod
15823d8817e4Smiod coffsymbol (section->symbol)->native = native;
15833d8817e4Smiod
15843d8817e4Smiod coff_set_custom_section_alignment (abfd, section,
15853d8817e4Smiod coff_section_alignment_table,
15863d8817e4Smiod coff_section_alignment_table_size);
15873d8817e4Smiod
15883d8817e4Smiod return TRUE;
15893d8817e4Smiod }
15903d8817e4Smiod
15913d8817e4Smiod #ifdef COFF_ALIGN_IN_SECTION_HEADER
15923d8817e4Smiod
15933d8817e4Smiod /* Set the alignment of a BFD section. */
15943d8817e4Smiod
15953d8817e4Smiod static void
coff_set_alignment_hook(bfd * abfd ATTRIBUTE_UNUSED,asection * section,void * scnhdr)15963d8817e4Smiod coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
15973d8817e4Smiod asection * section,
15983d8817e4Smiod void * scnhdr)
15993d8817e4Smiod {
16003d8817e4Smiod struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
16013d8817e4Smiod unsigned int i;
16023d8817e4Smiod
16033d8817e4Smiod #ifdef I960
16043d8817e4Smiod /* Extract ALIGN from 2**ALIGN stored in section header. */
16053d8817e4Smiod for (i = 0; i < 32; i++)
16063d8817e4Smiod if ((1 << i) >= hdr->s_align)
16073d8817e4Smiod break;
16083d8817e4Smiod #endif
16093d8817e4Smiod #ifdef TIC80COFF
16103d8817e4Smiod /* TI tools puts the alignment power in bits 8-11. */
16113d8817e4Smiod i = (hdr->s_flags >> 8) & 0xF ;
16123d8817e4Smiod #endif
16133d8817e4Smiod #ifdef COFF_DECODE_ALIGNMENT
16143d8817e4Smiod i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
16153d8817e4Smiod #endif
16163d8817e4Smiod section->alignment_power = i;
16173d8817e4Smiod
16183d8817e4Smiod #ifdef coff_set_section_load_page
16193d8817e4Smiod coff_set_section_load_page (section, hdr->s_page);
16203d8817e4Smiod #endif
16213d8817e4Smiod }
16223d8817e4Smiod
16233d8817e4Smiod #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
16243d8817e4Smiod #ifdef COFF_WITH_PE
16253d8817e4Smiod
16263d8817e4Smiod /* A couple of macros to help setting the alignment power field. */
16273d8817e4Smiod #define ALIGN_SET(field, x, y) \
16283d8817e4Smiod if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x)\
16293d8817e4Smiod {\
16303d8817e4Smiod section->alignment_power = y;\
16313d8817e4Smiod }
16323d8817e4Smiod
16333d8817e4Smiod #define ELIFALIGN_SET(field, x, y) \
16343d8817e4Smiod else if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x) \
16353d8817e4Smiod {\
16363d8817e4Smiod section->alignment_power = y;\
16373d8817e4Smiod }
16383d8817e4Smiod
16393d8817e4Smiod static void
coff_set_alignment_hook(bfd * abfd ATTRIBUTE_UNUSED,asection * section,void * scnhdr)16403d8817e4Smiod coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
16413d8817e4Smiod asection * section,
16423d8817e4Smiod void * scnhdr)
16433d8817e4Smiod {
16443d8817e4Smiod struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
16453d8817e4Smiod bfd_size_type amt;
16463d8817e4Smiod
16473d8817e4Smiod ALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
16483d8817e4Smiod ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
16493d8817e4Smiod ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4)
16503d8817e4Smiod ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES, 3)
16513d8817e4Smiod ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES, 2)
16523d8817e4Smiod ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES, 1)
16533d8817e4Smiod ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES, 0)
16543d8817e4Smiod
16553d8817e4Smiod /* In a PE image file, the s_paddr field holds the virtual size of a
16563d8817e4Smiod section, while the s_size field holds the raw size. We also keep
16573d8817e4Smiod the original section flag value, since not every bit can be
16583d8817e4Smiod mapped onto a generic BFD section bit. */
16593d8817e4Smiod if (coff_section_data (abfd, section) == NULL)
16603d8817e4Smiod {
16613d8817e4Smiod amt = sizeof (struct coff_section_tdata);
16623d8817e4Smiod section->used_by_bfd = bfd_zalloc (abfd, amt);
16633d8817e4Smiod if (section->used_by_bfd == NULL)
16643d8817e4Smiod /* FIXME: Return error. */
16653d8817e4Smiod abort ();
16663d8817e4Smiod }
16673d8817e4Smiod
16683d8817e4Smiod if (pei_section_data (abfd, section) == NULL)
16693d8817e4Smiod {
16703d8817e4Smiod amt = sizeof (struct pei_section_tdata);
16713d8817e4Smiod coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
16723d8817e4Smiod if (coff_section_data (abfd, section)->tdata == NULL)
16733d8817e4Smiod /* FIXME: Return error. */
16743d8817e4Smiod abort ();
16753d8817e4Smiod }
16763d8817e4Smiod pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
16773d8817e4Smiod pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
16783d8817e4Smiod
16793d8817e4Smiod section->lma = hdr->s_vaddr;
16803d8817e4Smiod
16813d8817e4Smiod /* Check for extended relocs. */
16823d8817e4Smiod if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
16833d8817e4Smiod {
16843d8817e4Smiod struct external_reloc dst;
16853d8817e4Smiod struct internal_reloc n;
16863d8817e4Smiod file_ptr oldpos = bfd_tell (abfd);
16873d8817e4Smiod bfd_size_type relsz = bfd_coff_relsz (abfd);
16883d8817e4Smiod
16893d8817e4Smiod bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0);
16903d8817e4Smiod if (bfd_bread (& dst, relsz, abfd) != relsz)
16913d8817e4Smiod return;
16923d8817e4Smiod
16933d8817e4Smiod coff_swap_reloc_in (abfd, &dst, &n);
16943d8817e4Smiod bfd_seek (abfd, oldpos, 0);
16953d8817e4Smiod section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
16963d8817e4Smiod section->rel_filepos += relsz;
16973d8817e4Smiod }
16983d8817e4Smiod else if (hdr->s_nreloc == 0xffff)
16993d8817e4Smiod (*_bfd_error_handler)
17003d8817e4Smiod ("%s: warning: claims to have 0xffff relocs, without overflow",
17013d8817e4Smiod bfd_get_filename (abfd));
17023d8817e4Smiod }
17033d8817e4Smiod #undef ALIGN_SET
17043d8817e4Smiod #undef ELIFALIGN_SET
17053d8817e4Smiod
17063d8817e4Smiod #else /* ! COFF_WITH_PE */
17073d8817e4Smiod #ifdef RS6000COFF_C
17083d8817e4Smiod
17093d8817e4Smiod /* We grossly abuse this function to handle XCOFF overflow headers.
17103d8817e4Smiod When we see one, we correct the reloc and line number counts in the
17113d8817e4Smiod real header, and remove the section we just created. */
17123d8817e4Smiod
17133d8817e4Smiod static void
coff_set_alignment_hook(bfd * abfd,asection * section,void * scnhdr)17143d8817e4Smiod coff_set_alignment_hook (bfd *abfd, asection *section, void * scnhdr)
17153d8817e4Smiod {
17163d8817e4Smiod struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
17173d8817e4Smiod asection *real_sec;
17183d8817e4Smiod
17193d8817e4Smiod if ((hdr->s_flags & STYP_OVRFLO) == 0)
17203d8817e4Smiod return;
17213d8817e4Smiod
17223d8817e4Smiod real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
17233d8817e4Smiod if (real_sec == NULL)
17243d8817e4Smiod return;
17253d8817e4Smiod
17263d8817e4Smiod real_sec->reloc_count = hdr->s_paddr;
17273d8817e4Smiod real_sec->lineno_count = hdr->s_vaddr;
17283d8817e4Smiod
17293d8817e4Smiod if (!bfd_section_removed_from_list (abfd, section))
17303d8817e4Smiod {
17313d8817e4Smiod bfd_section_list_remove (abfd, section);
17323d8817e4Smiod --abfd->section_count;
17333d8817e4Smiod }
17343d8817e4Smiod }
17353d8817e4Smiod
17363d8817e4Smiod #else /* ! RS6000COFF_C */
17373d8817e4Smiod
17383d8817e4Smiod #define coff_set_alignment_hook \
17393d8817e4Smiod ((void (*) (bfd *, asection *, void *)) bfd_void)
17403d8817e4Smiod
17413d8817e4Smiod #endif /* ! RS6000COFF_C */
17423d8817e4Smiod #endif /* ! COFF_WITH_PE */
17433d8817e4Smiod #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
17443d8817e4Smiod
17453d8817e4Smiod #ifndef coff_mkobject
17463d8817e4Smiod
17473d8817e4Smiod static bfd_boolean
coff_mkobject(bfd * abfd)17483d8817e4Smiod coff_mkobject (bfd * abfd)
17493d8817e4Smiod {
17503d8817e4Smiod coff_data_type *coff;
17513d8817e4Smiod bfd_size_type amt = sizeof (coff_data_type);
17523d8817e4Smiod
17533d8817e4Smiod abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
17543d8817e4Smiod if (abfd->tdata.coff_obj_data == NULL)
17553d8817e4Smiod return FALSE;
17563d8817e4Smiod coff = coff_data (abfd);
17573d8817e4Smiod coff->symbols = NULL;
17583d8817e4Smiod coff->conversion_table = NULL;
17593d8817e4Smiod coff->raw_syments = NULL;
17603d8817e4Smiod coff->relocbase = 0;
17613d8817e4Smiod coff->local_toc_sym_map = 0;
17623d8817e4Smiod
17633d8817e4Smiod /* make_abs_section(abfd);*/
17643d8817e4Smiod
17653d8817e4Smiod return TRUE;
17663d8817e4Smiod }
17673d8817e4Smiod #endif
17683d8817e4Smiod
17693d8817e4Smiod /* Create the COFF backend specific information. */
17703d8817e4Smiod
17713d8817e4Smiod #ifndef coff_mkobject_hook
17723d8817e4Smiod static void *
coff_mkobject_hook(bfd * abfd,void * filehdr,void * aouthdr ATTRIBUTE_UNUSED)17733d8817e4Smiod coff_mkobject_hook (bfd * abfd,
17743d8817e4Smiod void * filehdr,
17753d8817e4Smiod void * aouthdr ATTRIBUTE_UNUSED)
17763d8817e4Smiod {
17773d8817e4Smiod struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
17783d8817e4Smiod coff_data_type *coff;
17793d8817e4Smiod
17803d8817e4Smiod if (! coff_mkobject (abfd))
17813d8817e4Smiod return NULL;
17823d8817e4Smiod
17833d8817e4Smiod coff = coff_data (abfd);
17843d8817e4Smiod
17853d8817e4Smiod coff->sym_filepos = internal_f->f_symptr;
17863d8817e4Smiod
17873d8817e4Smiod /* These members communicate important constants about the symbol
17883d8817e4Smiod table to GDB's symbol-reading code. These `constants'
17893d8817e4Smiod unfortunately vary among coff implementations... */
17903d8817e4Smiod coff->local_n_btmask = N_BTMASK;
17913d8817e4Smiod coff->local_n_btshft = N_BTSHFT;
17923d8817e4Smiod coff->local_n_tmask = N_TMASK;
17933d8817e4Smiod coff->local_n_tshift = N_TSHIFT;
17943d8817e4Smiod coff->local_symesz = bfd_coff_symesz (abfd);
17953d8817e4Smiod coff->local_auxesz = bfd_coff_auxesz (abfd);
17963d8817e4Smiod coff->local_linesz = bfd_coff_linesz (abfd);
17973d8817e4Smiod
17983d8817e4Smiod coff->timestamp = internal_f->f_timdat;
17993d8817e4Smiod
18003d8817e4Smiod obj_raw_syment_count (abfd) =
18013d8817e4Smiod obj_conv_table_size (abfd) =
18023d8817e4Smiod internal_f->f_nsyms;
18033d8817e4Smiod
18043d8817e4Smiod #ifdef RS6000COFF_C
18053d8817e4Smiod if ((internal_f->f_flags & F_SHROBJ) != 0)
18063d8817e4Smiod abfd->flags |= DYNAMIC;
18073d8817e4Smiod if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
18083d8817e4Smiod {
18093d8817e4Smiod struct internal_aouthdr *internal_a =
18103d8817e4Smiod (struct internal_aouthdr *) aouthdr;
18113d8817e4Smiod struct xcoff_tdata *xcoff;
18123d8817e4Smiod
18133d8817e4Smiod xcoff = xcoff_data (abfd);
18143d8817e4Smiod # ifdef U803XTOCMAGIC
18153d8817e4Smiod xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
18163d8817e4Smiod # else
18173d8817e4Smiod xcoff->xcoff64 = 0;
18183d8817e4Smiod # endif
18193d8817e4Smiod xcoff->full_aouthdr = TRUE;
18203d8817e4Smiod xcoff->toc = internal_a->o_toc;
18213d8817e4Smiod xcoff->sntoc = internal_a->o_sntoc;
18223d8817e4Smiod xcoff->snentry = internal_a->o_snentry;
18233d8817e4Smiod bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
18243d8817e4Smiod bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
18253d8817e4Smiod xcoff->modtype = internal_a->o_modtype;
18263d8817e4Smiod xcoff->cputype = internal_a->o_cputype;
18273d8817e4Smiod xcoff->maxdata = internal_a->o_maxdata;
18283d8817e4Smiod xcoff->maxstack = internal_a->o_maxstack;
18293d8817e4Smiod }
18303d8817e4Smiod #endif
18313d8817e4Smiod
18323d8817e4Smiod #ifdef ARM
18333d8817e4Smiod /* Set the flags field from the COFF header read in. */
18343d8817e4Smiod if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
18353d8817e4Smiod coff->flags = 0;
18363d8817e4Smiod #endif
18373d8817e4Smiod
18383d8817e4Smiod #ifdef COFF_WITH_PE
18393d8817e4Smiod /* FIXME: I'm not sure this is ever executed, since peicode.h
18403d8817e4Smiod defines coff_mkobject_hook. */
18413d8817e4Smiod if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
18423d8817e4Smiod abfd->flags |= HAS_DEBUG;
18433d8817e4Smiod #endif
18443d8817e4Smiod
18453d8817e4Smiod return coff;
18463d8817e4Smiod }
18473d8817e4Smiod #endif
18483d8817e4Smiod
18493d8817e4Smiod /* Determine the machine architecture and type. FIXME: This is target
18503d8817e4Smiod dependent because the magic numbers are defined in the target
18513d8817e4Smiod dependent header files. But there is no particular need for this.
18523d8817e4Smiod If the magic numbers were moved to a separate file, this function
18533d8817e4Smiod would be target independent and would also be much more successful
18543d8817e4Smiod at linking together COFF files for different architectures. */
18553d8817e4Smiod
18563d8817e4Smiod static bfd_boolean
coff_set_arch_mach_hook(bfd * abfd,void * filehdr)18573d8817e4Smiod coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
18583d8817e4Smiod {
18593d8817e4Smiod unsigned long machine;
18603d8817e4Smiod enum bfd_architecture arch;
18613d8817e4Smiod struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
18623d8817e4Smiod
18633d8817e4Smiod /* Zero selects the default machine for an arch. */
18643d8817e4Smiod machine = 0;
18653d8817e4Smiod switch (internal_f->f_magic)
18663d8817e4Smiod {
18673d8817e4Smiod #ifdef OR32_MAGIC_BIG
18683d8817e4Smiod case OR32_MAGIC_BIG:
18693d8817e4Smiod case OR32_MAGIC_LITTLE:
18703d8817e4Smiod arch = bfd_arch_or32;
18713d8817e4Smiod break;
18723d8817e4Smiod #endif
18733d8817e4Smiod #ifdef PPCMAGIC
18743d8817e4Smiod case PPCMAGIC:
18753d8817e4Smiod arch = bfd_arch_powerpc;
18763d8817e4Smiod break;
18773d8817e4Smiod #endif
18783d8817e4Smiod #ifdef I386MAGIC
18793d8817e4Smiod case I386MAGIC:
18803d8817e4Smiod case I386PTXMAGIC:
18813d8817e4Smiod case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler */
18823d8817e4Smiod case LYNXCOFFMAGIC: /* shadows the m68k Lynx number below, sigh */
18833d8817e4Smiod arch = bfd_arch_i386;
18843d8817e4Smiod break;
18853d8817e4Smiod #endif
18866e5cc252Skettenis #ifdef AMD64MAGIC
18876e5cc252Skettenis case AMD64MAGIC:
18886e5cc252Skettenis arch = bfd_arch_i386;
18896e5cc252Skettenis machine = bfd_mach_x86_64;
18906e5cc252Skettenis break;
18916e5cc252Skettenis #endif
18923d8817e4Smiod #ifdef IA64MAGIC
18933d8817e4Smiod case IA64MAGIC:
18943d8817e4Smiod arch = bfd_arch_ia64;
18953d8817e4Smiod break;
18963d8817e4Smiod #endif
18973d8817e4Smiod #ifdef ARMMAGIC
18983d8817e4Smiod case ARMMAGIC:
18993d8817e4Smiod case ARMPEMAGIC:
19003d8817e4Smiod case THUMBPEMAGIC:
19013d8817e4Smiod arch = bfd_arch_arm;
19023d8817e4Smiod machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
19033d8817e4Smiod if (machine == bfd_mach_arm_unknown)
19043d8817e4Smiod {
19053d8817e4Smiod switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
19063d8817e4Smiod {
19073d8817e4Smiod case F_ARM_2: machine = bfd_mach_arm_2; break;
19083d8817e4Smiod case F_ARM_2a: machine = bfd_mach_arm_2a; break;
19093d8817e4Smiod case F_ARM_3: machine = bfd_mach_arm_3; break;
19103d8817e4Smiod default:
19113d8817e4Smiod case F_ARM_3M: machine = bfd_mach_arm_3M; break;
19123d8817e4Smiod case F_ARM_4: machine = bfd_mach_arm_4; break;
19133d8817e4Smiod case F_ARM_4T: machine = bfd_mach_arm_4T; break;
19143d8817e4Smiod /* The COFF header does not have enough bits available
19153d8817e4Smiod to cover all the different ARM architectures. So
19163d8817e4Smiod we interpret F_ARM_5, the highest flag value to mean
19173d8817e4Smiod "the highest ARM architecture known to BFD" which is
19183d8817e4Smiod currently the XScale. */
19193d8817e4Smiod case F_ARM_5: machine = bfd_mach_arm_XScale; break;
19203d8817e4Smiod }
19213d8817e4Smiod }
19223d8817e4Smiod break;
19233d8817e4Smiod #endif
19243d8817e4Smiod #ifdef MC68MAGIC
19253d8817e4Smiod case MC68MAGIC:
19263d8817e4Smiod case M68MAGIC:
19273d8817e4Smiod #ifdef MC68KBCSMAGIC
19283d8817e4Smiod case MC68KBCSMAGIC:
19293d8817e4Smiod #endif
19303d8817e4Smiod #ifdef APOLLOM68KMAGIC
19313d8817e4Smiod case APOLLOM68KMAGIC:
19323d8817e4Smiod #endif
19333d8817e4Smiod #ifdef LYNXCOFFMAGIC
19343d8817e4Smiod case LYNXCOFFMAGIC:
19353d8817e4Smiod #endif
19363d8817e4Smiod arch = bfd_arch_m68k;
19373d8817e4Smiod machine = bfd_mach_m68020;
19383d8817e4Smiod break;
19393d8817e4Smiod #endif
19403d8817e4Smiod #ifdef MAXQ20MAGIC
19413d8817e4Smiod case MAXQ20MAGIC:
19423d8817e4Smiod arch = bfd_arch_maxq;
19433d8817e4Smiod switch (internal_f->f_flags & F_MACHMASK)
19443d8817e4Smiod {
19453d8817e4Smiod case F_MAXQ10:
19463d8817e4Smiod machine = bfd_mach_maxq10;
19473d8817e4Smiod break;
19483d8817e4Smiod case F_MAXQ20:
19493d8817e4Smiod machine = bfd_mach_maxq20;
19503d8817e4Smiod break;
19513d8817e4Smiod default:
19523d8817e4Smiod return FALSE;
19533d8817e4Smiod }
19543d8817e4Smiod break;
19553d8817e4Smiod #endif
19563d8817e4Smiod #ifdef MC88MAGIC
19573d8817e4Smiod case MC88MAGIC:
19583d8817e4Smiod case MC88DMAGIC:
19593d8817e4Smiod case MC88OMAGIC:
19603d8817e4Smiod arch = bfd_arch_m88k;
19613d8817e4Smiod machine = 88100;
19623d8817e4Smiod break;
19633d8817e4Smiod #endif
19643d8817e4Smiod #ifdef Z80MAGIC
19653d8817e4Smiod case Z80MAGIC:
19663d8817e4Smiod arch = bfd_arch_z80;
19673d8817e4Smiod switch (internal_f->f_flags & F_MACHMASK)
19683d8817e4Smiod {
19693d8817e4Smiod case 0:
19703d8817e4Smiod case bfd_mach_z80strict << 12:
19713d8817e4Smiod case bfd_mach_z80 << 12:
19723d8817e4Smiod case bfd_mach_z80full << 12:
19733d8817e4Smiod case bfd_mach_r800 << 12:
19743d8817e4Smiod machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
19753d8817e4Smiod break;
19763d8817e4Smiod default:
19773d8817e4Smiod return FALSE;
19783d8817e4Smiod }
19793d8817e4Smiod break;
19803d8817e4Smiod #endif
19813d8817e4Smiod #ifdef Z8KMAGIC
19823d8817e4Smiod case Z8KMAGIC:
19833d8817e4Smiod arch = bfd_arch_z8k;
19843d8817e4Smiod switch (internal_f->f_flags & F_MACHMASK)
19853d8817e4Smiod {
19863d8817e4Smiod case F_Z8001:
19873d8817e4Smiod machine = bfd_mach_z8001;
19883d8817e4Smiod break;
19893d8817e4Smiod case F_Z8002:
19903d8817e4Smiod machine = bfd_mach_z8002;
19913d8817e4Smiod break;
19923d8817e4Smiod default:
19933d8817e4Smiod return FALSE;
19943d8817e4Smiod }
19953d8817e4Smiod break;
19963d8817e4Smiod #endif
19973d8817e4Smiod #ifdef I860
19983d8817e4Smiod case I860MAGIC:
19993d8817e4Smiod arch = bfd_arch_i860;
20003d8817e4Smiod break;
20013d8817e4Smiod #endif
20023d8817e4Smiod #ifdef I960
20033d8817e4Smiod #ifdef I960ROMAGIC
20043d8817e4Smiod case I960ROMAGIC:
20053d8817e4Smiod case I960RWMAGIC:
20063d8817e4Smiod arch = bfd_arch_i960;
20073d8817e4Smiod switch (F_I960TYPE & internal_f->f_flags)
20083d8817e4Smiod {
20093d8817e4Smiod default:
20103d8817e4Smiod case F_I960CORE:
20113d8817e4Smiod machine = bfd_mach_i960_core;
20123d8817e4Smiod break;
20133d8817e4Smiod case F_I960KB:
20143d8817e4Smiod machine = bfd_mach_i960_kb_sb;
20153d8817e4Smiod break;
20163d8817e4Smiod case F_I960MC:
20173d8817e4Smiod machine = bfd_mach_i960_mc;
20183d8817e4Smiod break;
20193d8817e4Smiod case F_I960XA:
20203d8817e4Smiod machine = bfd_mach_i960_xa;
20213d8817e4Smiod break;
20223d8817e4Smiod case F_I960CA:
20233d8817e4Smiod machine = bfd_mach_i960_ca;
20243d8817e4Smiod break;
20253d8817e4Smiod case F_I960KA:
20263d8817e4Smiod machine = bfd_mach_i960_ka_sa;
20273d8817e4Smiod break;
20283d8817e4Smiod case F_I960JX:
20293d8817e4Smiod machine = bfd_mach_i960_jx;
20303d8817e4Smiod break;
20313d8817e4Smiod case F_I960HX:
20323d8817e4Smiod machine = bfd_mach_i960_hx;
20333d8817e4Smiod break;
20343d8817e4Smiod }
20353d8817e4Smiod break;
20363d8817e4Smiod #endif
20373d8817e4Smiod #endif
20383d8817e4Smiod
20393d8817e4Smiod #ifdef RS6000COFF_C
20403d8817e4Smiod #ifdef XCOFF64
20413d8817e4Smiod case U64_TOCMAGIC:
20423d8817e4Smiod case U803XTOCMAGIC:
20433d8817e4Smiod #else
20443d8817e4Smiod case U802ROMAGIC:
20453d8817e4Smiod case U802WRMAGIC:
20463d8817e4Smiod case U802TOCMAGIC:
20473d8817e4Smiod #endif
20483d8817e4Smiod {
20493d8817e4Smiod int cputype;
20503d8817e4Smiod
20513d8817e4Smiod if (xcoff_data (abfd)->cputype != -1)
20523d8817e4Smiod cputype = xcoff_data (abfd)->cputype & 0xff;
20533d8817e4Smiod else
20543d8817e4Smiod {
20553d8817e4Smiod /* We did not get a value from the a.out header. If the
20563d8817e4Smiod file has not been stripped, we may be able to get the
20573d8817e4Smiod architecture information from the first symbol, if it
20583d8817e4Smiod is a .file symbol. */
20593d8817e4Smiod if (obj_raw_syment_count (abfd) == 0)
20603d8817e4Smiod cputype = 0;
20613d8817e4Smiod else
20623d8817e4Smiod {
20633d8817e4Smiod bfd_byte *buf;
20643d8817e4Smiod struct internal_syment sym;
20653d8817e4Smiod bfd_size_type amt = bfd_coff_symesz (abfd);
20663d8817e4Smiod
20673d8817e4Smiod buf = bfd_malloc (amt);
20683d8817e4Smiod if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
20693d8817e4Smiod || bfd_bread (buf, amt, abfd) != amt)
20703d8817e4Smiod {
20713d8817e4Smiod free (buf);
20723d8817e4Smiod return FALSE;
20733d8817e4Smiod }
20743d8817e4Smiod bfd_coff_swap_sym_in (abfd, buf, & sym);
20753d8817e4Smiod if (sym.n_sclass == C_FILE)
20763d8817e4Smiod cputype = sym.n_type & 0xff;
20773d8817e4Smiod else
20783d8817e4Smiod cputype = 0;
20793d8817e4Smiod free (buf);
20803d8817e4Smiod }
20813d8817e4Smiod }
20823d8817e4Smiod
20833d8817e4Smiod /* FIXME: We don't handle all cases here. */
20843d8817e4Smiod switch (cputype)
20853d8817e4Smiod {
20863d8817e4Smiod default:
20873d8817e4Smiod case 0:
20883d8817e4Smiod arch = bfd_xcoff_architecture (abfd);
20893d8817e4Smiod machine = bfd_xcoff_machine (abfd);
20903d8817e4Smiod break;
20913d8817e4Smiod
20923d8817e4Smiod case 1:
20933d8817e4Smiod arch = bfd_arch_powerpc;
20943d8817e4Smiod machine = bfd_mach_ppc_601;
20953d8817e4Smiod break;
20963d8817e4Smiod case 2: /* 64 bit PowerPC */
20973d8817e4Smiod arch = bfd_arch_powerpc;
20983d8817e4Smiod machine = bfd_mach_ppc_620;
20993d8817e4Smiod break;
21003d8817e4Smiod case 3:
21013d8817e4Smiod arch = bfd_arch_powerpc;
21023d8817e4Smiod machine = bfd_mach_ppc;
21033d8817e4Smiod break;
21043d8817e4Smiod case 4:
21053d8817e4Smiod arch = bfd_arch_rs6000;
21063d8817e4Smiod machine = bfd_mach_rs6k;
21073d8817e4Smiod break;
21083d8817e4Smiod }
21093d8817e4Smiod }
21103d8817e4Smiod break;
21113d8817e4Smiod #endif
21123d8817e4Smiod
21133d8817e4Smiod #ifdef WE32KMAGIC
21143d8817e4Smiod case WE32KMAGIC:
21153d8817e4Smiod arch = bfd_arch_we32k;
21163d8817e4Smiod break;
21173d8817e4Smiod #endif
21183d8817e4Smiod
21193d8817e4Smiod #ifdef H8300MAGIC
21203d8817e4Smiod case H8300MAGIC:
21213d8817e4Smiod arch = bfd_arch_h8300;
21223d8817e4Smiod machine = bfd_mach_h8300;
21233d8817e4Smiod /* !! FIXME this probably isn't the right place for this. */
21243d8817e4Smiod abfd->flags |= BFD_IS_RELAXABLE;
21253d8817e4Smiod break;
21263d8817e4Smiod #endif
21273d8817e4Smiod
21283d8817e4Smiod #ifdef H8300HMAGIC
21293d8817e4Smiod case H8300HMAGIC:
21303d8817e4Smiod arch = bfd_arch_h8300;
21313d8817e4Smiod machine = bfd_mach_h8300h;
21323d8817e4Smiod /* !! FIXME this probably isn't the right place for this. */
21333d8817e4Smiod abfd->flags |= BFD_IS_RELAXABLE;
21343d8817e4Smiod break;
21353d8817e4Smiod #endif
21363d8817e4Smiod
21373d8817e4Smiod #ifdef H8300SMAGIC
21383d8817e4Smiod case H8300SMAGIC:
21393d8817e4Smiod arch = bfd_arch_h8300;
21403d8817e4Smiod machine = bfd_mach_h8300s;
21413d8817e4Smiod /* !! FIXME this probably isn't the right place for this. */
21423d8817e4Smiod abfd->flags |= BFD_IS_RELAXABLE;
21433d8817e4Smiod break;
21443d8817e4Smiod #endif
21453d8817e4Smiod
21463d8817e4Smiod #ifdef H8300HNMAGIC
21473d8817e4Smiod case H8300HNMAGIC:
21483d8817e4Smiod arch = bfd_arch_h8300;
21493d8817e4Smiod machine = bfd_mach_h8300hn;
21503d8817e4Smiod /* !! FIXME this probably isn't the right place for this. */
21513d8817e4Smiod abfd->flags |= BFD_IS_RELAXABLE;
21523d8817e4Smiod break;
21533d8817e4Smiod #endif
21543d8817e4Smiod
21553d8817e4Smiod #ifdef H8300SNMAGIC
21563d8817e4Smiod case H8300SNMAGIC:
21573d8817e4Smiod arch = bfd_arch_h8300;
21583d8817e4Smiod machine = bfd_mach_h8300sn;
21593d8817e4Smiod /* !! FIXME this probably isn't the right place for this. */
21603d8817e4Smiod abfd->flags |= BFD_IS_RELAXABLE;
21613d8817e4Smiod break;
21623d8817e4Smiod #endif
21633d8817e4Smiod
21643d8817e4Smiod #ifdef SH_ARCH_MAGIC_BIG
21653d8817e4Smiod case SH_ARCH_MAGIC_BIG:
21663d8817e4Smiod case SH_ARCH_MAGIC_LITTLE:
21673d8817e4Smiod #ifdef COFF_WITH_PE
21683d8817e4Smiod case SH_ARCH_MAGIC_WINCE:
21693d8817e4Smiod #endif
21703d8817e4Smiod arch = bfd_arch_sh;
21713d8817e4Smiod break;
21723d8817e4Smiod #endif
21733d8817e4Smiod
21743d8817e4Smiod #ifdef MIPS_ARCH_MAGIC_WINCE
21753d8817e4Smiod case MIPS_ARCH_MAGIC_WINCE:
21763d8817e4Smiod arch = bfd_arch_mips;
21773d8817e4Smiod break;
21783d8817e4Smiod #endif
21793d8817e4Smiod
21803d8817e4Smiod #ifdef H8500MAGIC
21813d8817e4Smiod case H8500MAGIC:
21823d8817e4Smiod arch = bfd_arch_h8500;
21833d8817e4Smiod break;
21843d8817e4Smiod #endif
21853d8817e4Smiod
21863d8817e4Smiod #ifdef SPARCMAGIC
21873d8817e4Smiod case SPARCMAGIC:
21883d8817e4Smiod #ifdef LYNXCOFFMAGIC
21893d8817e4Smiod case LYNXCOFFMAGIC:
21903d8817e4Smiod #endif
21913d8817e4Smiod arch = bfd_arch_sparc;
21923d8817e4Smiod break;
21933d8817e4Smiod #endif
21943d8817e4Smiod
21953d8817e4Smiod #ifdef TIC30MAGIC
21963d8817e4Smiod case TIC30MAGIC:
21973d8817e4Smiod arch = bfd_arch_tic30;
21983d8817e4Smiod break;
21993d8817e4Smiod #endif
22003d8817e4Smiod
22013d8817e4Smiod #ifdef TICOFF0MAGIC
22023d8817e4Smiod #ifdef TICOFF_TARGET_ARCH
22033d8817e4Smiod /* This TI COFF section should be used by all new TI COFF v0 targets. */
22043d8817e4Smiod case TICOFF0MAGIC:
22053d8817e4Smiod arch = TICOFF_TARGET_ARCH;
22063d8817e4Smiod machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
22073d8817e4Smiod break;
22083d8817e4Smiod #endif
22093d8817e4Smiod #endif
22103d8817e4Smiod
22113d8817e4Smiod #ifdef TICOFF1MAGIC
22123d8817e4Smiod /* This TI COFF section should be used by all new TI COFF v1/2 targets. */
22133d8817e4Smiod /* TI COFF1 and COFF2 use the target_id field to specify which arch. */
22143d8817e4Smiod case TICOFF1MAGIC:
22153d8817e4Smiod case TICOFF2MAGIC:
22163d8817e4Smiod switch (internal_f->f_target_id)
22173d8817e4Smiod {
22183d8817e4Smiod #ifdef TI_TARGET_ID
22193d8817e4Smiod case TI_TARGET_ID:
22203d8817e4Smiod arch = TICOFF_TARGET_ARCH;
22213d8817e4Smiod machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
22223d8817e4Smiod break;
22233d8817e4Smiod #endif
22243d8817e4Smiod default:
22253d8817e4Smiod arch = bfd_arch_obscure;
22263d8817e4Smiod (*_bfd_error_handler)
22273d8817e4Smiod (_("Unrecognized TI COFF target id '0x%x'"),
22283d8817e4Smiod internal_f->f_target_id);
22293d8817e4Smiod break;
22303d8817e4Smiod }
22313d8817e4Smiod break;
22323d8817e4Smiod #endif
22333d8817e4Smiod
22343d8817e4Smiod #ifdef TIC80_ARCH_MAGIC
22353d8817e4Smiod case TIC80_ARCH_MAGIC:
22363d8817e4Smiod arch = bfd_arch_tic80;
22373d8817e4Smiod break;
22383d8817e4Smiod #endif
22393d8817e4Smiod
22403d8817e4Smiod #ifdef MCOREMAGIC
22413d8817e4Smiod case MCOREMAGIC:
22423d8817e4Smiod arch = bfd_arch_mcore;
22433d8817e4Smiod break;
22443d8817e4Smiod #endif
22453d8817e4Smiod
22463d8817e4Smiod #ifdef W65MAGIC
22473d8817e4Smiod case W65MAGIC:
22483d8817e4Smiod arch = bfd_arch_w65;
22493d8817e4Smiod break;
22503d8817e4Smiod #endif
22513d8817e4Smiod
22523d8817e4Smiod default: /* Unreadable input file type. */
22533d8817e4Smiod arch = bfd_arch_obscure;
22543d8817e4Smiod break;
22553d8817e4Smiod }
22563d8817e4Smiod
22573d8817e4Smiod bfd_default_set_arch_mach (abfd, arch, machine);
22583d8817e4Smiod return TRUE;
22593d8817e4Smiod }
22603d8817e4Smiod
22613d8817e4Smiod #ifdef SYMNAME_IN_DEBUG
22623d8817e4Smiod
22633d8817e4Smiod static bfd_boolean
symname_in_debug_hook(bfd * abfd ATTRIBUTE_UNUSED,struct internal_syment * sym)22643d8817e4Smiod symname_in_debug_hook (bfd * abfd ATTRIBUTE_UNUSED, struct internal_syment *sym)
22653d8817e4Smiod {
22663d8817e4Smiod return SYMNAME_IN_DEBUG (sym) != 0;
22673d8817e4Smiod }
22683d8817e4Smiod
22693d8817e4Smiod #else
22703d8817e4Smiod
22713d8817e4Smiod #define symname_in_debug_hook \
22723d8817e4Smiod (bfd_boolean (*) (bfd *, struct internal_syment *)) bfd_false
22733d8817e4Smiod
22743d8817e4Smiod #endif
22753d8817e4Smiod
22763d8817e4Smiod #ifdef RS6000COFF_C
22773d8817e4Smiod
22783d8817e4Smiod #ifdef XCOFF64
22793d8817e4Smiod #define FORCE_SYMNAMES_IN_STRINGS
22803d8817e4Smiod #endif
22813d8817e4Smiod
22823d8817e4Smiod /* Handle the csect auxent of a C_EXT or C_HIDEXT symbol. */
22833d8817e4Smiod
22843d8817e4Smiod static bfd_boolean
coff_pointerize_aux_hook(bfd * abfd ATTRIBUTE_UNUSED,combined_entry_type * table_base,combined_entry_type * symbol,unsigned int indaux,combined_entry_type * aux)22853d8817e4Smiod coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
22863d8817e4Smiod combined_entry_type *table_base,
22873d8817e4Smiod combined_entry_type *symbol,
22883d8817e4Smiod unsigned int indaux,
22893d8817e4Smiod combined_entry_type *aux)
22903d8817e4Smiod {
22913d8817e4Smiod int class = symbol->u.syment.n_sclass;
22923d8817e4Smiod
22933d8817e4Smiod if ((class == C_EXT || class == C_HIDEXT)
22943d8817e4Smiod && indaux + 1 == symbol->u.syment.n_numaux)
22953d8817e4Smiod {
22963d8817e4Smiod if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD)
22973d8817e4Smiod {
22983d8817e4Smiod aux->u.auxent.x_csect.x_scnlen.p =
22993d8817e4Smiod table_base + aux->u.auxent.x_csect.x_scnlen.l;
23003d8817e4Smiod aux->fix_scnlen = 1;
23013d8817e4Smiod }
23023d8817e4Smiod
23033d8817e4Smiod /* Return TRUE to indicate that the caller should not do any
23043d8817e4Smiod further work on this auxent. */
23053d8817e4Smiod return TRUE;
23063d8817e4Smiod }
23073d8817e4Smiod
23083d8817e4Smiod /* Return FALSE to indicate that this auxent should be handled by
23093d8817e4Smiod the caller. */
23103d8817e4Smiod return FALSE;
23113d8817e4Smiod }
23123d8817e4Smiod
23133d8817e4Smiod #else
23143d8817e4Smiod #ifdef I960
23153d8817e4Smiod
23163d8817e4Smiod /* We don't want to pointerize bal entries. */
23173d8817e4Smiod
23183d8817e4Smiod static bfd_boolean
coff_pointerize_aux_hook(bfd * abfd ATTRIBUTE_UNUSED,combined_entry_type * table_base ATTRIBUTE_UNUSED,combined_entry_type * symbol,unsigned int indaux,combined_entry_type * aux ATTRIBUTE_UNUSED)23193d8817e4Smiod coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
23203d8817e4Smiod combined_entry_type *table_base ATTRIBUTE_UNUSED,
23213d8817e4Smiod combined_entry_type *symbol,
23223d8817e4Smiod unsigned int indaux,
23233d8817e4Smiod combined_entry_type *aux ATTRIBUTE_UNUSED)
23243d8817e4Smiod {
23253d8817e4Smiod /* Return TRUE if we don't want to pointerize this aux entry, which
23263d8817e4Smiod is the case for the lastfirst aux entry for a C_LEAFPROC symbol. */
23273d8817e4Smiod return (indaux == 1
23283d8817e4Smiod && (symbol->u.syment.n_sclass == C_LEAFPROC
23293d8817e4Smiod || symbol->u.syment.n_sclass == C_LEAFSTAT
23303d8817e4Smiod || symbol->u.syment.n_sclass == C_LEAFEXT));
23313d8817e4Smiod }
23323d8817e4Smiod
23333d8817e4Smiod #else /* ! I960 */
23343d8817e4Smiod
23353d8817e4Smiod #define coff_pointerize_aux_hook 0
23363d8817e4Smiod
23373d8817e4Smiod #endif /* ! I960 */
23383d8817e4Smiod #endif /* ! RS6000COFF_C */
23393d8817e4Smiod
23403d8817e4Smiod /* Print an aux entry. This returns TRUE if it has printed it. */
23413d8817e4Smiod
23423d8817e4Smiod static bfd_boolean
coff_print_aux(bfd * abfd ATTRIBUTE_UNUSED,FILE * file ATTRIBUTE_UNUSED,combined_entry_type * table_base ATTRIBUTE_UNUSED,combined_entry_type * symbol ATTRIBUTE_UNUSED,combined_entry_type * aux ATTRIBUTE_UNUSED,unsigned int indaux ATTRIBUTE_UNUSED)23433d8817e4Smiod coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
23443d8817e4Smiod FILE *file ATTRIBUTE_UNUSED,
23453d8817e4Smiod combined_entry_type *table_base ATTRIBUTE_UNUSED,
23463d8817e4Smiod combined_entry_type *symbol ATTRIBUTE_UNUSED,
23473d8817e4Smiod combined_entry_type *aux ATTRIBUTE_UNUSED,
23483d8817e4Smiod unsigned int indaux ATTRIBUTE_UNUSED)
23493d8817e4Smiod {
23503d8817e4Smiod #ifdef RS6000COFF_C
23513d8817e4Smiod if ((symbol->u.syment.n_sclass == C_EXT
23523d8817e4Smiod || symbol->u.syment.n_sclass == C_HIDEXT)
23533d8817e4Smiod && indaux + 1 == symbol->u.syment.n_numaux)
23543d8817e4Smiod {
23553d8817e4Smiod /* This is a csect entry. */
23563d8817e4Smiod fprintf (file, "AUX ");
23573d8817e4Smiod if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
23583d8817e4Smiod {
23593d8817e4Smiod BFD_ASSERT (! aux->fix_scnlen);
23603d8817e4Smiod #ifdef XCOFF64
23613d8817e4Smiod fprintf (file, "val %5lld",
23623d8817e4Smiod (long long) aux->u.auxent.x_csect.x_scnlen.l);
23633d8817e4Smiod #else
23643d8817e4Smiod fprintf (file, "val %5ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
23653d8817e4Smiod #endif
23663d8817e4Smiod }
23673d8817e4Smiod else
23683d8817e4Smiod {
23693d8817e4Smiod fprintf (file, "indx ");
23703d8817e4Smiod if (! aux->fix_scnlen)
23713d8817e4Smiod #ifdef XCOFF64
23723d8817e4Smiod fprintf (file, "%4lld",
23733d8817e4Smiod (long long) aux->u.auxent.x_csect.x_scnlen.l);
23743d8817e4Smiod #else
23753d8817e4Smiod fprintf (file, "%4ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
23763d8817e4Smiod #endif
23773d8817e4Smiod else
23783d8817e4Smiod fprintf (file, "%4ld",
23793d8817e4Smiod (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
23803d8817e4Smiod }
23813d8817e4Smiod fprintf (file,
23823d8817e4Smiod " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u",
23833d8817e4Smiod aux->u.auxent.x_csect.x_parmhash,
23843d8817e4Smiod (unsigned int) aux->u.auxent.x_csect.x_snhash,
23853d8817e4Smiod SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
23863d8817e4Smiod SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
23873d8817e4Smiod (unsigned int) aux->u.auxent.x_csect.x_smclas,
23883d8817e4Smiod aux->u.auxent.x_csect.x_stab,
23893d8817e4Smiod (unsigned int) aux->u.auxent.x_csect.x_snstab);
23903d8817e4Smiod return TRUE;
23913d8817e4Smiod }
23923d8817e4Smiod #endif
23933d8817e4Smiod
23943d8817e4Smiod /* Return FALSE to indicate that no special action was taken. */
23953d8817e4Smiod return FALSE;
23963d8817e4Smiod }
23973d8817e4Smiod
23983d8817e4Smiod /*
23993d8817e4Smiod SUBSUBSECTION
24003d8817e4Smiod Writing relocations
24013d8817e4Smiod
24023d8817e4Smiod To write relocations, the back end steps though the
24033d8817e4Smiod canonical relocation table and create an
24043d8817e4Smiod @code{internal_reloc}. The symbol index to use is removed from
24053d8817e4Smiod the @code{offset} field in the symbol table supplied. The
24063d8817e4Smiod address comes directly from the sum of the section base
24073d8817e4Smiod address and the relocation offset; the type is dug directly
24083d8817e4Smiod from the howto field. Then the @code{internal_reloc} is
24093d8817e4Smiod swapped into the shape of an @code{external_reloc} and written
24103d8817e4Smiod out to disk.
24113d8817e4Smiod
24123d8817e4Smiod */
24133d8817e4Smiod
24143d8817e4Smiod #ifdef TARG_AUX
24153d8817e4Smiod
24163d8817e4Smiod
24173d8817e4Smiod /* AUX's ld wants relocations to be sorted. */
24183d8817e4Smiod static int
compare_arelent_ptr(const void * x,const void * y)24193d8817e4Smiod compare_arelent_ptr (const void * x, const void * y)
24203d8817e4Smiod {
24213d8817e4Smiod const arelent **a = (const arelent **) x;
24223d8817e4Smiod const arelent **b = (const arelent **) y;
24233d8817e4Smiod bfd_size_type aadr = (*a)->address;
24243d8817e4Smiod bfd_size_type badr = (*b)->address;
24253d8817e4Smiod
24263d8817e4Smiod return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
24273d8817e4Smiod }
24283d8817e4Smiod
24293d8817e4Smiod #endif /* TARG_AUX */
24303d8817e4Smiod
24313d8817e4Smiod static bfd_boolean
coff_write_relocs(bfd * abfd,int first_undef)24323d8817e4Smiod coff_write_relocs (bfd * abfd, int first_undef)
24333d8817e4Smiod {
24343d8817e4Smiod asection *s;
24353d8817e4Smiod
24363d8817e4Smiod for (s = abfd->sections; s != NULL; s = s->next)
24373d8817e4Smiod {
24383d8817e4Smiod unsigned int i;
24393d8817e4Smiod struct external_reloc dst;
24403d8817e4Smiod arelent **p;
24413d8817e4Smiod
24423d8817e4Smiod #ifndef TARG_AUX
24433d8817e4Smiod p = s->orelocation;
24443d8817e4Smiod #else
24453d8817e4Smiod {
24463d8817e4Smiod /* Sort relocations before we write them out. */
24473d8817e4Smiod bfd_size_type amt;
24483d8817e4Smiod
24493d8817e4Smiod amt = s->reloc_count;
24503d8817e4Smiod amt *= sizeof (arelent *);
24513d8817e4Smiod p = bfd_malloc (amt);
24523d8817e4Smiod if (p == NULL && s->reloc_count > 0)
24533d8817e4Smiod return FALSE;
24543d8817e4Smiod memcpy (p, s->orelocation, (size_t) amt);
24553d8817e4Smiod qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
24563d8817e4Smiod }
24573d8817e4Smiod #endif
24583d8817e4Smiod
24593d8817e4Smiod if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
24603d8817e4Smiod return FALSE;
24613d8817e4Smiod
24623d8817e4Smiod #ifdef COFF_WITH_PE
24633d8817e4Smiod if (obj_pe (abfd) && s->reloc_count >= 0xffff)
24643d8817e4Smiod {
24653d8817e4Smiod /* Encode real count here as first reloc. */
24663d8817e4Smiod struct internal_reloc n;
24673d8817e4Smiod
24683d8817e4Smiod memset (& n, 0, sizeof (n));
24693d8817e4Smiod /* Add one to count *this* reloc (grr). */
24703d8817e4Smiod n.r_vaddr = s->reloc_count + 1;
24713d8817e4Smiod coff_swap_reloc_out (abfd, &n, &dst);
24723d8817e4Smiod if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
24733d8817e4Smiod abfd) != bfd_coff_relsz (abfd))
24743d8817e4Smiod return FALSE;
24753d8817e4Smiod }
24763d8817e4Smiod #endif
24773d8817e4Smiod
24783d8817e4Smiod for (i = 0; i < s->reloc_count; i++)
24793d8817e4Smiod {
24803d8817e4Smiod struct internal_reloc n;
24813d8817e4Smiod arelent *q = p[i];
24823d8817e4Smiod
24833d8817e4Smiod memset (& n, 0, sizeof (n));
24843d8817e4Smiod
24853d8817e4Smiod /* Now we've renumbered the symbols we know where the
24863d8817e4Smiod undefined symbols live in the table. Check the reloc
24873d8817e4Smiod entries for symbols who's output bfd isn't the right one.
24883d8817e4Smiod This is because the symbol was undefined (which means
24893d8817e4Smiod that all the pointers are never made to point to the same
24903d8817e4Smiod place). This is a bad thing,'cause the symbols attached
24913d8817e4Smiod to the output bfd are indexed, so that the relocation
24923d8817e4Smiod entries know which symbol index they point to. So we
24933d8817e4Smiod have to look up the output symbol here. */
24943d8817e4Smiod
24953d8817e4Smiod if (q->sym_ptr_ptr[0]->the_bfd != abfd)
24963d8817e4Smiod {
24973d8817e4Smiod int j;
24983d8817e4Smiod const char *sname = q->sym_ptr_ptr[0]->name;
24993d8817e4Smiod asymbol **outsyms = abfd->outsymbols;
25003d8817e4Smiod
25013d8817e4Smiod for (j = first_undef; outsyms[j]; j++)
25023d8817e4Smiod {
25033d8817e4Smiod const char *intable = outsyms[j]->name;
25043d8817e4Smiod
25053d8817e4Smiod if (strcmp (intable, sname) == 0)
25063d8817e4Smiod {
25073d8817e4Smiod /* Got a hit, so repoint the reloc. */
25083d8817e4Smiod q->sym_ptr_ptr = outsyms + j;
25093d8817e4Smiod break;
25103d8817e4Smiod }
25113d8817e4Smiod }
25123d8817e4Smiod }
25133d8817e4Smiod
25143d8817e4Smiod n.r_vaddr = q->address + s->vma;
25153d8817e4Smiod
25163d8817e4Smiod #ifdef R_IHCONST
25173d8817e4Smiod /* The 29k const/consth reloc pair is a real kludge. The consth
25183d8817e4Smiod part doesn't have a symbol; it has an offset. So rebuilt
25193d8817e4Smiod that here. */
25203d8817e4Smiod if (q->howto->type == R_IHCONST)
25213d8817e4Smiod n.r_symndx = q->addend;
25223d8817e4Smiod else
25233d8817e4Smiod #endif
25243d8817e4Smiod if (q->sym_ptr_ptr)
25253d8817e4Smiod {
25263d8817e4Smiod #ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
25273d8817e4Smiod if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
25283d8817e4Smiod #else
25293d8817e4Smiod if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
25303d8817e4Smiod && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
25313d8817e4Smiod #endif
25323d8817e4Smiod /* This is a relocation relative to the absolute symbol. */
25333d8817e4Smiod n.r_symndx = -1;
25343d8817e4Smiod else
25353d8817e4Smiod {
25363d8817e4Smiod n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
25373d8817e4Smiod /* Take notice if the symbol reloc points to a symbol
25383d8817e4Smiod we don't have in our symbol table. What should we
25393d8817e4Smiod do for this?? */
25403d8817e4Smiod if (n.r_symndx > obj_conv_table_size (abfd))
25413d8817e4Smiod abort ();
25423d8817e4Smiod }
25433d8817e4Smiod }
25443d8817e4Smiod
25453d8817e4Smiod #ifdef SWAP_OUT_RELOC_OFFSET
25463d8817e4Smiod n.r_offset = q->addend;
25473d8817e4Smiod #endif
25483d8817e4Smiod
25493d8817e4Smiod #ifdef SELECT_RELOC
25503d8817e4Smiod /* Work out reloc type from what is required. */
25513d8817e4Smiod SELECT_RELOC (n, q->howto);
25523d8817e4Smiod #else
25533d8817e4Smiod n.r_type = q->howto->type;
25543d8817e4Smiod #endif
25553d8817e4Smiod coff_swap_reloc_out (abfd, &n, &dst);
25563d8817e4Smiod
25573d8817e4Smiod if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
25583d8817e4Smiod abfd) != bfd_coff_relsz (abfd))
25593d8817e4Smiod return FALSE;
25603d8817e4Smiod }
25613d8817e4Smiod
25623d8817e4Smiod #ifdef TARG_AUX
25633d8817e4Smiod if (p != NULL)
25643d8817e4Smiod free (p);
25653d8817e4Smiod #endif
25663d8817e4Smiod }
25673d8817e4Smiod
25683d8817e4Smiod return TRUE;
25693d8817e4Smiod }
25703d8817e4Smiod
25713d8817e4Smiod /* Set flags and magic number of a coff file from architecture and machine
25723d8817e4Smiod type. Result is TRUE if we can represent the arch&type, FALSE if not. */
25733d8817e4Smiod
25743d8817e4Smiod static bfd_boolean
coff_set_flags(bfd * abfd,unsigned int * magicp ATTRIBUTE_UNUSED,unsigned short * flagsp ATTRIBUTE_UNUSED)25753d8817e4Smiod coff_set_flags (bfd * abfd,
25763d8817e4Smiod unsigned int *magicp ATTRIBUTE_UNUSED,
25773d8817e4Smiod unsigned short *flagsp ATTRIBUTE_UNUSED)
25783d8817e4Smiod {
25793d8817e4Smiod switch (bfd_get_arch (abfd))
25803d8817e4Smiod {
25813d8817e4Smiod #ifdef Z80MAGIC
25823d8817e4Smiod case bfd_arch_z80:
25833d8817e4Smiod *magicp = Z80MAGIC;
25843d8817e4Smiod switch (bfd_get_mach (abfd))
25853d8817e4Smiod {
25863d8817e4Smiod case 0:
25873d8817e4Smiod case bfd_mach_z80strict:
25883d8817e4Smiod case bfd_mach_z80:
25893d8817e4Smiod case bfd_mach_z80full:
25903d8817e4Smiod case bfd_mach_r800:
25913d8817e4Smiod *flagsp = bfd_get_mach (abfd) << 12;
25923d8817e4Smiod break;
25933d8817e4Smiod default:
25943d8817e4Smiod return FALSE;
25953d8817e4Smiod }
25963d8817e4Smiod return TRUE;
25973d8817e4Smiod #endif
25983d8817e4Smiod
25993d8817e4Smiod #ifdef Z8KMAGIC
26003d8817e4Smiod case bfd_arch_z8k:
26013d8817e4Smiod *magicp = Z8KMAGIC;
26023d8817e4Smiod
26033d8817e4Smiod switch (bfd_get_mach (abfd))
26043d8817e4Smiod {
26053d8817e4Smiod case bfd_mach_z8001: *flagsp = F_Z8001; break;
26063d8817e4Smiod case bfd_mach_z8002: *flagsp = F_Z8002; break;
26073d8817e4Smiod default: return FALSE;
26083d8817e4Smiod }
26093d8817e4Smiod return TRUE;
26103d8817e4Smiod #endif
26113d8817e4Smiod
26123d8817e4Smiod #ifdef I960ROMAGIC
26133d8817e4Smiod case bfd_arch_i960:
26143d8817e4Smiod
26153d8817e4Smiod {
26163d8817e4Smiod unsigned flags;
26173d8817e4Smiod
26183d8817e4Smiod *magicp = I960ROMAGIC;
26193d8817e4Smiod
26203d8817e4Smiod switch (bfd_get_mach (abfd))
26213d8817e4Smiod {
26223d8817e4Smiod case bfd_mach_i960_core: flags = F_I960CORE; break;
26233d8817e4Smiod case bfd_mach_i960_kb_sb: flags = F_I960KB; break;
26243d8817e4Smiod case bfd_mach_i960_mc: flags = F_I960MC; break;
26253d8817e4Smiod case bfd_mach_i960_xa: flags = F_I960XA; break;
26263d8817e4Smiod case bfd_mach_i960_ca: flags = F_I960CA; break;
26273d8817e4Smiod case bfd_mach_i960_ka_sa: flags = F_I960KA; break;
26283d8817e4Smiod case bfd_mach_i960_jx: flags = F_I960JX; break;
26293d8817e4Smiod case bfd_mach_i960_hx: flags = F_I960HX; break;
26303d8817e4Smiod default: return FALSE;
26313d8817e4Smiod }
26323d8817e4Smiod *flagsp = flags;
26333d8817e4Smiod return TRUE;
26343d8817e4Smiod }
26353d8817e4Smiod break;
26363d8817e4Smiod #endif
26373d8817e4Smiod
26383d8817e4Smiod #ifdef TIC30MAGIC
26393d8817e4Smiod case bfd_arch_tic30:
26403d8817e4Smiod *magicp = TIC30MAGIC;
26413d8817e4Smiod return TRUE;
26423d8817e4Smiod #endif
26433d8817e4Smiod
26443d8817e4Smiod #ifdef TICOFF_DEFAULT_MAGIC
26453d8817e4Smiod case TICOFF_TARGET_ARCH:
26463d8817e4Smiod /* If there's no indication of which version we want, use the default. */
26473d8817e4Smiod if (!abfd->xvec )
26483d8817e4Smiod *magicp = TICOFF_DEFAULT_MAGIC;
26493d8817e4Smiod else
26503d8817e4Smiod {
26513d8817e4Smiod /* We may want to output in a different COFF version. */
26523d8817e4Smiod switch (abfd->xvec->name[4])
26533d8817e4Smiod {
26543d8817e4Smiod case '0':
26553d8817e4Smiod *magicp = TICOFF0MAGIC;
26563d8817e4Smiod break;
26573d8817e4Smiod case '1':
26583d8817e4Smiod *magicp = TICOFF1MAGIC;
26593d8817e4Smiod break;
26603d8817e4Smiod case '2':
26613d8817e4Smiod *magicp = TICOFF2MAGIC;
26623d8817e4Smiod break;
26633d8817e4Smiod default:
26643d8817e4Smiod return FALSE;
26653d8817e4Smiod }
26663d8817e4Smiod }
26673d8817e4Smiod TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
26683d8817e4Smiod return TRUE;
26693d8817e4Smiod #endif
26703d8817e4Smiod
26713d8817e4Smiod #ifdef TIC80_ARCH_MAGIC
26723d8817e4Smiod case bfd_arch_tic80:
26733d8817e4Smiod *magicp = TIC80_ARCH_MAGIC;
26743d8817e4Smiod return TRUE;
26753d8817e4Smiod #endif
26763d8817e4Smiod
26773d8817e4Smiod #ifdef ARMMAGIC
26783d8817e4Smiod case bfd_arch_arm:
26793d8817e4Smiod #ifdef ARM_WINCE
26803d8817e4Smiod * magicp = ARMPEMAGIC;
26813d8817e4Smiod #else
26823d8817e4Smiod * magicp = ARMMAGIC;
26833d8817e4Smiod #endif
26843d8817e4Smiod * flagsp = 0;
26853d8817e4Smiod if (APCS_SET (abfd))
26863d8817e4Smiod {
26873d8817e4Smiod if (APCS_26_FLAG (abfd))
26883d8817e4Smiod * flagsp |= F_APCS26;
26893d8817e4Smiod
26903d8817e4Smiod if (APCS_FLOAT_FLAG (abfd))
26913d8817e4Smiod * flagsp |= F_APCS_FLOAT;
26923d8817e4Smiod
26933d8817e4Smiod if (PIC_FLAG (abfd))
26943d8817e4Smiod * flagsp |= F_PIC;
26953d8817e4Smiod }
26963d8817e4Smiod if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
26973d8817e4Smiod * flagsp |= F_INTERWORK;
26983d8817e4Smiod switch (bfd_get_mach (abfd))
26993d8817e4Smiod {
27003d8817e4Smiod case bfd_mach_arm_2: * flagsp |= F_ARM_2; break;
27013d8817e4Smiod case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
27023d8817e4Smiod case bfd_mach_arm_3: * flagsp |= F_ARM_3; break;
27033d8817e4Smiod case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
27043d8817e4Smiod case bfd_mach_arm_4: * flagsp |= F_ARM_4; break;
27053d8817e4Smiod case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
27063d8817e4Smiod case bfd_mach_arm_5: * flagsp |= F_ARM_5; break;
27073d8817e4Smiod /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
27083d8817e4Smiod See also the comment in coff_set_arch_mach_hook(). */
27093d8817e4Smiod case bfd_mach_arm_5T: * flagsp |= F_ARM_5; break;
27103d8817e4Smiod case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
27113d8817e4Smiod case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
27123d8817e4Smiod }
27133d8817e4Smiod return TRUE;
27143d8817e4Smiod #endif
27153d8817e4Smiod
27163d8817e4Smiod #ifdef PPCMAGIC
27173d8817e4Smiod case bfd_arch_powerpc:
27183d8817e4Smiod *magicp = PPCMAGIC;
27193d8817e4Smiod return TRUE;
27203d8817e4Smiod #endif
27213d8817e4Smiod
27226e5cc252Skettenis #if defined(I386MAGIC) || defined(AMD64MAGIC)
27233d8817e4Smiod case bfd_arch_i386:
27246e5cc252Skettenis #if defined(I386MAGIC)
27253d8817e4Smiod *magicp = I386MAGIC;
27266e5cc252Skettenis #endif
27273d8817e4Smiod #ifdef LYNXOS
27283d8817e4Smiod /* Just overwrite the usual value if we're doing Lynx. */
27293d8817e4Smiod *magicp = LYNXCOFFMAGIC;
27303d8817e4Smiod #endif
27316e5cc252Skettenis #if defined AMD64MAGIC
27326e5cc252Skettenis *magicp = AMD64MAGIC;
27336e5cc252Skettenis #endif
27343d8817e4Smiod return TRUE;
27353d8817e4Smiod #endif
27363d8817e4Smiod
27373d8817e4Smiod #ifdef I860MAGIC
27383d8817e4Smiod case bfd_arch_i860:
27393d8817e4Smiod *magicp = I860MAGIC;
27403d8817e4Smiod return TRUE;
27413d8817e4Smiod #endif
27423d8817e4Smiod
27433d8817e4Smiod #ifdef IA64MAGIC
27443d8817e4Smiod case bfd_arch_ia64:
27453d8817e4Smiod *magicp = IA64MAGIC;
27463d8817e4Smiod return TRUE;
27473d8817e4Smiod #endif
27483d8817e4Smiod
27493d8817e4Smiod #ifdef MC68MAGIC
27503d8817e4Smiod case bfd_arch_m68k:
27513d8817e4Smiod #ifdef APOLLOM68KMAGIC
27523d8817e4Smiod *magicp = APOLLO_COFF_VERSION_NUMBER;
27533d8817e4Smiod #else
27543d8817e4Smiod /* NAMES_HAVE_UNDERSCORE may be defined by coff-u68k.c. */
27553d8817e4Smiod #ifdef NAMES_HAVE_UNDERSCORE
27563d8817e4Smiod *magicp = MC68KBCSMAGIC;
27573d8817e4Smiod #else
27583d8817e4Smiod *magicp = MC68MAGIC;
27593d8817e4Smiod #endif
27603d8817e4Smiod #endif
27613d8817e4Smiod #ifdef LYNXOS
27623d8817e4Smiod /* Just overwrite the usual value if we're doing Lynx. */
27633d8817e4Smiod *magicp = LYNXCOFFMAGIC;
27643d8817e4Smiod #endif
27653d8817e4Smiod return TRUE;
27663d8817e4Smiod #endif
27673d8817e4Smiod
27683d8817e4Smiod #ifdef MC88MAGIC
27693d8817e4Smiod case bfd_arch_m88k:
27703d8817e4Smiod *magicp = MC88OMAGIC;
27713d8817e4Smiod return TRUE;
27723d8817e4Smiod #endif
27733d8817e4Smiod
27743d8817e4Smiod #ifdef H8300MAGIC
27753d8817e4Smiod case bfd_arch_h8300:
27763d8817e4Smiod switch (bfd_get_mach (abfd))
27773d8817e4Smiod {
27783d8817e4Smiod case bfd_mach_h8300: *magicp = H8300MAGIC; return TRUE;
27793d8817e4Smiod case bfd_mach_h8300h: *magicp = H8300HMAGIC; return TRUE;
27803d8817e4Smiod case bfd_mach_h8300s: *magicp = H8300SMAGIC; return TRUE;
27813d8817e4Smiod case bfd_mach_h8300hn: *magicp = H8300HNMAGIC; return TRUE;
27823d8817e4Smiod case bfd_mach_h8300sn: *magicp = H8300SNMAGIC; return TRUE;
27833d8817e4Smiod default: break;
27843d8817e4Smiod }
27853d8817e4Smiod break;
27863d8817e4Smiod #endif
27873d8817e4Smiod
27883d8817e4Smiod #ifdef SH_ARCH_MAGIC_BIG
27893d8817e4Smiod case bfd_arch_sh:
27903d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
27913d8817e4Smiod *magicp = SH_ARCH_MAGIC_WINCE;
27923d8817e4Smiod #else
27933d8817e4Smiod if (bfd_big_endian (abfd))
27943d8817e4Smiod *magicp = SH_ARCH_MAGIC_BIG;
27953d8817e4Smiod else
27963d8817e4Smiod *magicp = SH_ARCH_MAGIC_LITTLE;
27973d8817e4Smiod #endif
27983d8817e4Smiod return TRUE;
27993d8817e4Smiod #endif
28003d8817e4Smiod
28013d8817e4Smiod #ifdef MIPS_ARCH_MAGIC_WINCE
28023d8817e4Smiod case bfd_arch_mips:
28033d8817e4Smiod *magicp = MIPS_ARCH_MAGIC_WINCE;
28043d8817e4Smiod return TRUE;
28053d8817e4Smiod #endif
28063d8817e4Smiod
28073d8817e4Smiod #ifdef SPARCMAGIC
28083d8817e4Smiod case bfd_arch_sparc:
28093d8817e4Smiod *magicp = SPARCMAGIC;
28103d8817e4Smiod #ifdef LYNXOS
28113d8817e4Smiod /* Just overwrite the usual value if we're doing Lynx. */
28123d8817e4Smiod *magicp = LYNXCOFFMAGIC;
28133d8817e4Smiod #endif
28143d8817e4Smiod return TRUE;
28153d8817e4Smiod #endif
28163d8817e4Smiod
28173d8817e4Smiod #ifdef H8500MAGIC
28183d8817e4Smiod case bfd_arch_h8500:
28193d8817e4Smiod *magicp = H8500MAGIC;
28203d8817e4Smiod return TRUE;
28213d8817e4Smiod break;
28223d8817e4Smiod #endif
28233d8817e4Smiod
28243d8817e4Smiod #ifdef WE32KMAGIC
28253d8817e4Smiod case bfd_arch_we32k:
28263d8817e4Smiod *magicp = WE32KMAGIC;
28273d8817e4Smiod return TRUE;
28283d8817e4Smiod #endif
28293d8817e4Smiod
28303d8817e4Smiod #ifdef RS6000COFF_C
28313d8817e4Smiod case bfd_arch_rs6000:
28323d8817e4Smiod #ifndef PPCMAGIC
28333d8817e4Smiod case bfd_arch_powerpc:
28343d8817e4Smiod #endif
28353d8817e4Smiod BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
28363d8817e4Smiod *magicp = bfd_xcoff_magic_number (abfd);
28373d8817e4Smiod return TRUE;
28383d8817e4Smiod #endif
28393d8817e4Smiod
28403d8817e4Smiod #ifdef MCOREMAGIC
28413d8817e4Smiod case bfd_arch_mcore:
28423d8817e4Smiod * magicp = MCOREMAGIC;
28433d8817e4Smiod return TRUE;
28443d8817e4Smiod #endif
28453d8817e4Smiod
28463d8817e4Smiod #ifdef W65MAGIC
28473d8817e4Smiod case bfd_arch_w65:
28483d8817e4Smiod *magicp = W65MAGIC;
28493d8817e4Smiod return TRUE;
28503d8817e4Smiod #endif
28513d8817e4Smiod
28523d8817e4Smiod #ifdef OR32_MAGIC_BIG
28533d8817e4Smiod case bfd_arch_or32:
28543d8817e4Smiod if (bfd_big_endian (abfd))
28553d8817e4Smiod * magicp = OR32_MAGIC_BIG;
28563d8817e4Smiod else
28573d8817e4Smiod * magicp = OR32_MAGIC_LITTLE;
28583d8817e4Smiod return TRUE;
28593d8817e4Smiod #endif
28603d8817e4Smiod
28613d8817e4Smiod #ifdef MAXQ20MAGIC
28623d8817e4Smiod case bfd_arch_maxq:
28633d8817e4Smiod * magicp = MAXQ20MAGIC;
28643d8817e4Smiod switch (bfd_get_mach (abfd))
28653d8817e4Smiod {
28663d8817e4Smiod case bfd_mach_maxq10: * flagsp = F_MAXQ10; return TRUE;
28673d8817e4Smiod case bfd_mach_maxq20: * flagsp = F_MAXQ20; return TRUE;
28683d8817e4Smiod default: return FALSE;
28693d8817e4Smiod }
28703d8817e4Smiod #endif
28713d8817e4Smiod
28723d8817e4Smiod default: /* Unknown architecture. */
28733d8817e4Smiod /* Fall through to "return FALSE" below, to avoid
28743d8817e4Smiod "statement never reached" errors on the one below. */
28753d8817e4Smiod break;
28763d8817e4Smiod }
28773d8817e4Smiod
28783d8817e4Smiod return FALSE;
28793d8817e4Smiod }
28803d8817e4Smiod
28813d8817e4Smiod static bfd_boolean
coff_set_arch_mach(bfd * abfd,enum bfd_architecture arch,unsigned long machine)28823d8817e4Smiod coff_set_arch_mach (bfd * abfd,
28833d8817e4Smiod enum bfd_architecture arch,
28843d8817e4Smiod unsigned long machine)
28853d8817e4Smiod {
28863d8817e4Smiod unsigned dummy1;
28873d8817e4Smiod unsigned short dummy2;
28883d8817e4Smiod
28893d8817e4Smiod if (! bfd_default_set_arch_mach (abfd, arch, machine))
28903d8817e4Smiod return FALSE;
28913d8817e4Smiod
28923d8817e4Smiod if (arch != bfd_arch_unknown
28933d8817e4Smiod && ! coff_set_flags (abfd, &dummy1, &dummy2))
28943d8817e4Smiod return FALSE; /* We can't represent this type. */
28953d8817e4Smiod
28963d8817e4Smiod return TRUE; /* We're easy... */
28973d8817e4Smiod }
28983d8817e4Smiod
28993d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
29003d8817e4Smiod
29013d8817e4Smiod /* This is used to sort sections by VMA, as required by PE image
29023d8817e4Smiod files. */
29033d8817e4Smiod
29043d8817e4Smiod static int
sort_by_secaddr(const void * arg1,const void * arg2)29053d8817e4Smiod sort_by_secaddr (const void * arg1, const void * arg2)
29063d8817e4Smiod {
29073d8817e4Smiod const asection *a = *(const asection **) arg1;
29083d8817e4Smiod const asection *b = *(const asection **) arg2;
29093d8817e4Smiod
29103d8817e4Smiod if (a->vma < b->vma)
29113d8817e4Smiod return -1;
29123d8817e4Smiod else if (a->vma > b->vma)
29133d8817e4Smiod return 1;
29143d8817e4Smiod
29153d8817e4Smiod return 0;
29163d8817e4Smiod }
29173d8817e4Smiod
29183d8817e4Smiod #endif /* COFF_IMAGE_WITH_PE */
29193d8817e4Smiod
29203d8817e4Smiod /* Calculate the file position for each section. */
29213d8817e4Smiod
29223d8817e4Smiod #ifndef I960
29233d8817e4Smiod #define ALIGN_SECTIONS_IN_FILE
29243d8817e4Smiod #endif
29253d8817e4Smiod #if defined(TIC80COFF) || defined(TICOFF)
29263d8817e4Smiod #undef ALIGN_SECTIONS_IN_FILE
29273d8817e4Smiod #endif
29283d8817e4Smiod
29293d8817e4Smiod static bfd_boolean
coff_compute_section_file_positions(bfd * abfd)29303d8817e4Smiod coff_compute_section_file_positions (bfd * abfd)
29313d8817e4Smiod {
29323d8817e4Smiod asection *current;
29333d8817e4Smiod asection *previous = NULL;
29343d8817e4Smiod file_ptr sofar = bfd_coff_filhsz (abfd);
29353d8817e4Smiod bfd_boolean align_adjust;
29363d8817e4Smiod #ifdef ALIGN_SECTIONS_IN_FILE
29373d8817e4Smiod file_ptr old_sofar;
29383d8817e4Smiod #endif
29393d8817e4Smiod
29403d8817e4Smiod #ifdef RS6000COFF_C
29413d8817e4Smiod /* On XCOFF, if we have symbols, set up the .debug section. */
29423d8817e4Smiod if (bfd_get_symcount (abfd) > 0)
29433d8817e4Smiod {
29443d8817e4Smiod bfd_size_type sz;
29453d8817e4Smiod bfd_size_type i, symcount;
29463d8817e4Smiod asymbol **symp;
29473d8817e4Smiod
29483d8817e4Smiod sz = 0;
29493d8817e4Smiod symcount = bfd_get_symcount (abfd);
29503d8817e4Smiod for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
29513d8817e4Smiod {
29523d8817e4Smiod coff_symbol_type *cf;
29533d8817e4Smiod
29543d8817e4Smiod cf = coff_symbol_from (abfd, *symp);
29553d8817e4Smiod if (cf != NULL
29563d8817e4Smiod && cf->native != NULL
29573d8817e4Smiod && SYMNAME_IN_DEBUG (&cf->native->u.syment))
29583d8817e4Smiod {
29593d8817e4Smiod size_t len;
29603d8817e4Smiod
29613d8817e4Smiod len = strlen (bfd_asymbol_name (*symp));
29623d8817e4Smiod if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
29633d8817e4Smiod sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
29643d8817e4Smiod }
29653d8817e4Smiod }
29663d8817e4Smiod if (sz > 0)
29673d8817e4Smiod {
29683d8817e4Smiod asection *dsec;
29693d8817e4Smiod
29703d8817e4Smiod dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
29713d8817e4Smiod if (dsec == NULL)
29723d8817e4Smiod abort ();
29733d8817e4Smiod dsec->size = sz;
29743d8817e4Smiod dsec->flags |= SEC_HAS_CONTENTS;
29753d8817e4Smiod }
29763d8817e4Smiod }
29773d8817e4Smiod #endif
29783d8817e4Smiod
29793d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
29803d8817e4Smiod int page_size;
29813d8817e4Smiod
29823d8817e4Smiod if (coff_data (abfd)->link_info)
29833d8817e4Smiod {
29843d8817e4Smiod page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
29853d8817e4Smiod
29863d8817e4Smiod /* If no file alignment has been set, default to one.
29873d8817e4Smiod This repairs 'ld -r' for arm-wince-pe target. */
29883d8817e4Smiod if (page_size == 0)
29893d8817e4Smiod page_size = 1;
29903d8817e4Smiod }
29913d8817e4Smiod else
29923d8817e4Smiod page_size = PE_DEF_FILE_ALIGNMENT;
29933d8817e4Smiod #else
29943d8817e4Smiod #ifdef COFF_PAGE_SIZE
29953d8817e4Smiod int page_size = COFF_PAGE_SIZE;
29963d8817e4Smiod #endif
29973d8817e4Smiod #endif
29983d8817e4Smiod
29993d8817e4Smiod if (bfd_get_start_address (abfd))
30003d8817e4Smiod /* A start address may have been added to the original file. In this
30013d8817e4Smiod case it will need an optional header to record it. */
30023d8817e4Smiod abfd->flags |= EXEC_P;
30033d8817e4Smiod
30043d8817e4Smiod if (abfd->flags & EXEC_P)
30053d8817e4Smiod sofar += bfd_coff_aoutsz (abfd);
30063d8817e4Smiod #ifdef RS6000COFF_C
30073d8817e4Smiod else if (xcoff_data (abfd)->full_aouthdr)
30083d8817e4Smiod sofar += bfd_coff_aoutsz (abfd);
30093d8817e4Smiod else
30103d8817e4Smiod sofar += SMALL_AOUTSZ;
30113d8817e4Smiod #endif
30123d8817e4Smiod
30133d8817e4Smiod sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
30143d8817e4Smiod
30153d8817e4Smiod #ifdef RS6000COFF_C
30163d8817e4Smiod /* XCOFF handles overflows in the reloc and line number count fields
30173d8817e4Smiod by allocating a new section header to hold the correct counts. */
30183d8817e4Smiod for (current = abfd->sections; current != NULL; current = current->next)
30193d8817e4Smiod if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
30203d8817e4Smiod sofar += bfd_coff_scnhsz (abfd);
30213d8817e4Smiod #endif
30223d8817e4Smiod
30233d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
30243d8817e4Smiod {
30253d8817e4Smiod /* PE requires the sections to be in memory order when listed in
30263d8817e4Smiod the section headers. It also does not like empty loadable
30273d8817e4Smiod sections. The sections apparently do not have to be in the
30283d8817e4Smiod right order in the image file itself, but we do need to get the
30293d8817e4Smiod target_index values right. */
30303d8817e4Smiod
30313d8817e4Smiod unsigned int count;
30323d8817e4Smiod asection **section_list;
30333d8817e4Smiod unsigned int i;
30343d8817e4Smiod int target_index;
30353d8817e4Smiod bfd_size_type amt;
30363d8817e4Smiod
30373d8817e4Smiod count = 0;
30383d8817e4Smiod for (current = abfd->sections; current != NULL; current = current->next)
30393d8817e4Smiod ++count;
30403d8817e4Smiod
30413d8817e4Smiod /* We allocate an extra cell to simplify the final loop. */
30423d8817e4Smiod amt = sizeof (struct asection *) * (count + 1);
30433d8817e4Smiod section_list = bfd_malloc (amt);
30443d8817e4Smiod if (section_list == NULL)
30453d8817e4Smiod return FALSE;
30463d8817e4Smiod
30473d8817e4Smiod i = 0;
30483d8817e4Smiod for (current = abfd->sections; current != NULL; current = current->next)
30493d8817e4Smiod {
30503d8817e4Smiod section_list[i] = current;
30513d8817e4Smiod ++i;
30523d8817e4Smiod }
30533d8817e4Smiod section_list[i] = NULL;
30543d8817e4Smiod
30553d8817e4Smiod qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
30563d8817e4Smiod
30573d8817e4Smiod /* Rethread the linked list into sorted order; at the same time,
30583d8817e4Smiod assign target_index values. */
30593d8817e4Smiod target_index = 1;
30603d8817e4Smiod abfd->sections = NULL;
30613d8817e4Smiod abfd->section_last = NULL;
30623d8817e4Smiod for (i = 0; i < count; i++)
30633d8817e4Smiod {
30643d8817e4Smiod current = section_list[i];
30653d8817e4Smiod bfd_section_list_append (abfd, current);
30663d8817e4Smiod
30673d8817e4Smiod /* Later, if the section has zero size, we'll be throwing it
30683d8817e4Smiod away, so we don't want to number it now. Note that having
30693d8817e4Smiod a zero size and having real contents are different
30703d8817e4Smiod concepts: .bss has no contents, but (usually) non-zero
30713d8817e4Smiod size. */
30723d8817e4Smiod if (current->size == 0)
30733d8817e4Smiod {
30743d8817e4Smiod /* Discard. However, it still might have (valid) symbols
30753d8817e4Smiod in it, so arbitrarily set it to section 1 (indexing is
30763d8817e4Smiod 1-based here; usually .text). __end__ and other
30773d8817e4Smiod contents of .endsection really have this happen.
30783d8817e4Smiod FIXME: This seems somewhat dubious. */
30793d8817e4Smiod current->target_index = 1;
30803d8817e4Smiod }
30813d8817e4Smiod else
30823d8817e4Smiod current->target_index = target_index++;
30833d8817e4Smiod }
30843d8817e4Smiod
30853d8817e4Smiod free (section_list);
30863d8817e4Smiod }
30873d8817e4Smiod #else /* ! COFF_IMAGE_WITH_PE */
30883d8817e4Smiod {
30893d8817e4Smiod /* Set the target_index field. */
30903d8817e4Smiod int target_index;
30913d8817e4Smiod
30923d8817e4Smiod target_index = 1;
30933d8817e4Smiod for (current = abfd->sections; current != NULL; current = current->next)
30943d8817e4Smiod current->target_index = target_index++;
30953d8817e4Smiod }
30963d8817e4Smiod #endif /* ! COFF_IMAGE_WITH_PE */
30973d8817e4Smiod
30983d8817e4Smiod align_adjust = FALSE;
30993d8817e4Smiod for (current = abfd->sections;
31003d8817e4Smiod current != NULL;
31013d8817e4Smiod current = current->next)
31023d8817e4Smiod {
31033d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
31043d8817e4Smiod /* With PE we have to pad each section to be a multiple of its
31053d8817e4Smiod page size too, and remember both sizes. */
31063d8817e4Smiod if (coff_section_data (abfd, current) == NULL)
31073d8817e4Smiod {
31083d8817e4Smiod bfd_size_type amt = sizeof (struct coff_section_tdata);
31093d8817e4Smiod
31103d8817e4Smiod current->used_by_bfd = bfd_zalloc (abfd, amt);
31113d8817e4Smiod if (current->used_by_bfd == NULL)
31123d8817e4Smiod return FALSE;
31133d8817e4Smiod }
31143d8817e4Smiod if (pei_section_data (abfd, current) == NULL)
31153d8817e4Smiod {
31163d8817e4Smiod bfd_size_type amt = sizeof (struct pei_section_tdata);
31173d8817e4Smiod
31183d8817e4Smiod coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
31193d8817e4Smiod if (coff_section_data (abfd, current)->tdata == NULL)
31203d8817e4Smiod return FALSE;
31213d8817e4Smiod }
31223d8817e4Smiod if (pei_section_data (abfd, current)->virt_size == 0)
31233d8817e4Smiod pei_section_data (abfd, current)->virt_size = current->size;
31243d8817e4Smiod #endif
31253d8817e4Smiod
31263d8817e4Smiod /* Only deal with sections which have contents. */
31273d8817e4Smiod if (!(current->flags & SEC_HAS_CONTENTS))
31283d8817e4Smiod continue;
31293d8817e4Smiod
31303d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
31313d8817e4Smiod /* Make sure we skip empty sections in a PE image. */
31323d8817e4Smiod if (current->size == 0)
31333d8817e4Smiod continue;
31343d8817e4Smiod #endif
31353d8817e4Smiod
31363d8817e4Smiod /* Align the sections in the file to the same boundary on
31373d8817e4Smiod which they are aligned in virtual memory. I960 doesn't
31383d8817e4Smiod do this (FIXME) so we can stay in sync with Intel. 960
31393d8817e4Smiod doesn't yet page from files... */
31403d8817e4Smiod #ifdef ALIGN_SECTIONS_IN_FILE
31413d8817e4Smiod if ((abfd->flags & EXEC_P) != 0)
31423d8817e4Smiod {
31433d8817e4Smiod /* Make sure this section is aligned on the right boundary - by
31443d8817e4Smiod padding the previous section up if necessary. */
31453d8817e4Smiod old_sofar = sofar;
31463d8817e4Smiod
31473d8817e4Smiod #ifdef RS6000COFF_C
31483d8817e4Smiod /* AIX loader checks the text section alignment of (vma - filepos)
31493d8817e4Smiod So even though the filepos may be aligned wrt the o_algntext, for
31503d8817e4Smiod AIX executables, this check fails. This shows up when a native
31513d8817e4Smiod AIX executable is stripped with gnu strip because the default vma
31523d8817e4Smiod of native is 0x10000150 but default for gnu is 0x10000140. Gnu
31533d8817e4Smiod stripped gnu excutable passes this check because the filepos is
31543d8817e4Smiod 0x0140. This problem also show up with 64 bit shared objects. The
31553d8817e4Smiod data section must also be aligned. */
31563d8817e4Smiod if (!strcmp (current->name, _TEXT)
31573d8817e4Smiod || !strcmp (current->name, _DATA))
31583d8817e4Smiod {
31593d8817e4Smiod bfd_vma pad;
31603d8817e4Smiod bfd_vma align;
31613d8817e4Smiod
31623d8817e4Smiod sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
31633d8817e4Smiod
31643d8817e4Smiod align = 1 << current->alignment_power;
3165*3474c532Skettenis pad = llabs (current->vma - sofar) % align;
31663d8817e4Smiod
31673d8817e4Smiod if (pad)
31683d8817e4Smiod {
31693d8817e4Smiod pad = align - pad;
31703d8817e4Smiod sofar += pad;
31713d8817e4Smiod }
31723d8817e4Smiod }
31733d8817e4Smiod else
31743d8817e4Smiod #else
31753d8817e4Smiod {
31763d8817e4Smiod sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
31773d8817e4Smiod }
31783d8817e4Smiod #endif
31793d8817e4Smiod if (previous != NULL)
31803d8817e4Smiod previous->size += sofar - old_sofar;
31813d8817e4Smiod }
31823d8817e4Smiod
31833d8817e4Smiod #endif
31843d8817e4Smiod
31853d8817e4Smiod /* In demand paged files the low order bits of the file offset
31863d8817e4Smiod must match the low order bits of the virtual address. */
31873d8817e4Smiod #ifdef COFF_PAGE_SIZE
31883d8817e4Smiod if ((abfd->flags & D_PAGED) != 0
31893d8817e4Smiod && (current->flags & SEC_ALLOC) != 0)
31903d8817e4Smiod sofar += (current->vma - (bfd_vma) sofar) % page_size;
31913d8817e4Smiod #endif
31923d8817e4Smiod current->filepos = sofar;
31933d8817e4Smiod
31943d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
31953d8817e4Smiod /* Set the padded size. */
31963d8817e4Smiod current->size = (current->size + page_size -1) & -page_size;
31973d8817e4Smiod #endif
31983d8817e4Smiod
31993d8817e4Smiod sofar += current->size;
32003d8817e4Smiod
32013d8817e4Smiod #ifdef ALIGN_SECTIONS_IN_FILE
32023d8817e4Smiod /* Make sure that this section is of the right size too. */
32033d8817e4Smiod if ((abfd->flags & EXEC_P) == 0)
32043d8817e4Smiod {
32053d8817e4Smiod bfd_size_type old_size;
32063d8817e4Smiod
32073d8817e4Smiod old_size = current->size;
32083d8817e4Smiod current->size = BFD_ALIGN (current->size,
32093d8817e4Smiod 1 << current->alignment_power);
32103d8817e4Smiod align_adjust = current->size != old_size;
32113d8817e4Smiod sofar += current->size - old_size;
32123d8817e4Smiod }
32133d8817e4Smiod else
32143d8817e4Smiod {
32153d8817e4Smiod old_sofar = sofar;
32163d8817e4Smiod sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
32173d8817e4Smiod align_adjust = sofar != old_sofar;
32183d8817e4Smiod current->size += sofar - old_sofar;
32193d8817e4Smiod }
32203d8817e4Smiod #endif
32213d8817e4Smiod
32223d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
32233d8817e4Smiod /* For PE we need to make sure we pad out to the aligned
32243d8817e4Smiod size, in case the caller only writes out data to the
32253d8817e4Smiod unaligned size. */
32263d8817e4Smiod if (pei_section_data (abfd, current)->virt_size < current->size)
32273d8817e4Smiod align_adjust = TRUE;
32283d8817e4Smiod #endif
32293d8817e4Smiod
32303d8817e4Smiod #ifdef _LIB
32313d8817e4Smiod /* Force .lib sections to start at zero. The vma is then
32323d8817e4Smiod incremented in coff_set_section_contents. This is right for
32333d8817e4Smiod SVR3.2. */
32343d8817e4Smiod if (strcmp (current->name, _LIB) == 0)
32353d8817e4Smiod bfd_set_section_vma (abfd, current, 0);
32363d8817e4Smiod #endif
32373d8817e4Smiod
32383d8817e4Smiod previous = current;
32393d8817e4Smiod }
32403d8817e4Smiod
32413d8817e4Smiod /* It is now safe to write to the output file. If we needed an
32423d8817e4Smiod alignment adjustment for the last section, then make sure that
32433d8817e4Smiod there is a byte at offset sofar. If there are no symbols and no
32443d8817e4Smiod relocs, then nothing follows the last section. If we don't force
32453d8817e4Smiod the last byte out, then the file may appear to be truncated. */
32463d8817e4Smiod if (align_adjust)
32473d8817e4Smiod {
32483d8817e4Smiod bfd_byte b;
32493d8817e4Smiod
32503d8817e4Smiod b = 0;
32513d8817e4Smiod if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
32523d8817e4Smiod || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
32533d8817e4Smiod return FALSE;
32543d8817e4Smiod }
32553d8817e4Smiod
32563d8817e4Smiod /* Make sure the relocations are aligned. We don't need to make
32573d8817e4Smiod sure that this byte exists, because it will only matter if there
32583d8817e4Smiod really are relocs. */
32593d8817e4Smiod sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
32603d8817e4Smiod
32613d8817e4Smiod obj_relocbase (abfd) = sofar;
32623d8817e4Smiod abfd->output_has_begun = TRUE;
32633d8817e4Smiod
32643d8817e4Smiod return TRUE;
32653d8817e4Smiod }
32663d8817e4Smiod
32673d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
32683d8817e4Smiod
32693d8817e4Smiod static unsigned int pelength;
32703d8817e4Smiod static unsigned int peheader;
32713d8817e4Smiod
32723d8817e4Smiod static bfd_boolean
coff_read_word(bfd * abfd,unsigned int * value)32733d8817e4Smiod coff_read_word (bfd *abfd, unsigned int *value)
32743d8817e4Smiod {
32753d8817e4Smiod unsigned char b[2];
32763d8817e4Smiod int status;
32773d8817e4Smiod
32783d8817e4Smiod status = bfd_bread (b, (bfd_size_type) 2, abfd);
32793d8817e4Smiod if (status < 1)
32803d8817e4Smiod {
32813d8817e4Smiod *value = 0;
32823d8817e4Smiod return FALSE;
32833d8817e4Smiod }
32843d8817e4Smiod
32853d8817e4Smiod if (status == 1)
32863d8817e4Smiod *value = (unsigned int) b[0];
32873d8817e4Smiod else
32883d8817e4Smiod *value = (unsigned int) (b[0] + (b[1] << 8));
32893d8817e4Smiod
32903d8817e4Smiod pelength += (unsigned int) status;
32913d8817e4Smiod
32923d8817e4Smiod return TRUE;
32933d8817e4Smiod }
32943d8817e4Smiod
32953d8817e4Smiod static unsigned int
coff_compute_checksum(bfd * abfd)32963d8817e4Smiod coff_compute_checksum (bfd *abfd)
32973d8817e4Smiod {
32983d8817e4Smiod bfd_boolean more_data;
32993d8817e4Smiod file_ptr filepos;
33003d8817e4Smiod unsigned int value;
33013d8817e4Smiod unsigned int total;
33023d8817e4Smiod
33033d8817e4Smiod total = 0;
33043d8817e4Smiod pelength = 0;
33053d8817e4Smiod filepos = (file_ptr) 0;
33063d8817e4Smiod
33073d8817e4Smiod do
33083d8817e4Smiod {
33093d8817e4Smiod if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
33103d8817e4Smiod return 0;
33113d8817e4Smiod
33123d8817e4Smiod more_data = coff_read_word (abfd, &value);
33133d8817e4Smiod total += value;
33143d8817e4Smiod total = 0xffff & (total + (total >> 0x10));
33153d8817e4Smiod filepos += 2;
33163d8817e4Smiod }
33173d8817e4Smiod while (more_data);
33183d8817e4Smiod
33193d8817e4Smiod return (0xffff & (total + (total >> 0x10)));
33203d8817e4Smiod }
33213d8817e4Smiod
33223d8817e4Smiod static bfd_boolean
coff_apply_checksum(bfd * abfd)33233d8817e4Smiod coff_apply_checksum (bfd *abfd)
33243d8817e4Smiod {
33253d8817e4Smiod unsigned int computed;
33263d8817e4Smiod unsigned int checksum = 0;
33273d8817e4Smiod
33283d8817e4Smiod if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
33293d8817e4Smiod return FALSE;
33303d8817e4Smiod
33313d8817e4Smiod if (!coff_read_word (abfd, &peheader))
33323d8817e4Smiod return FALSE;
33333d8817e4Smiod
33343d8817e4Smiod if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
33353d8817e4Smiod return FALSE;
33363d8817e4Smiod
33373d8817e4Smiod checksum = 0;
33383d8817e4Smiod bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
33393d8817e4Smiod
33403d8817e4Smiod if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
33413d8817e4Smiod return FALSE;
33423d8817e4Smiod
33433d8817e4Smiod computed = coff_compute_checksum (abfd);
33443d8817e4Smiod
33453d8817e4Smiod checksum = computed + pelength;
33463d8817e4Smiod
33473d8817e4Smiod if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
33483d8817e4Smiod return FALSE;
33493d8817e4Smiod
33503d8817e4Smiod bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
33513d8817e4Smiod
33523d8817e4Smiod return TRUE;
33533d8817e4Smiod }
33543d8817e4Smiod
33553d8817e4Smiod #endif /* COFF_IMAGE_WITH_PE */
33563d8817e4Smiod
33573d8817e4Smiod static bfd_boolean
coff_write_object_contents(bfd * abfd)33583d8817e4Smiod coff_write_object_contents (bfd * abfd)
33593d8817e4Smiod {
33603d8817e4Smiod asection *current;
33613d8817e4Smiod bfd_boolean hasrelocs = FALSE;
33623d8817e4Smiod bfd_boolean haslinno = FALSE;
33633d8817e4Smiod bfd_boolean hasdebug = FALSE;
33643d8817e4Smiod file_ptr scn_base;
33653d8817e4Smiod file_ptr reloc_base;
33663d8817e4Smiod file_ptr lineno_base;
33673d8817e4Smiod file_ptr sym_base;
33683d8817e4Smiod unsigned long reloc_size = 0, reloc_count = 0;
33693d8817e4Smiod unsigned long lnno_size = 0;
33703d8817e4Smiod bfd_boolean long_section_names;
33713d8817e4Smiod asection *text_sec = NULL;
33723d8817e4Smiod asection *data_sec = NULL;
33733d8817e4Smiod asection *bss_sec = NULL;
33743d8817e4Smiod struct internal_filehdr internal_f;
33753d8817e4Smiod struct internal_aouthdr internal_a;
33763d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
33773d8817e4Smiod size_t string_size = STRING_SIZE_SIZE;
33783d8817e4Smiod #endif
33793d8817e4Smiod
33803d8817e4Smiod bfd_set_error (bfd_error_system_call);
33813d8817e4Smiod
33823d8817e4Smiod /* Make a pass through the symbol table to count line number entries and
33833d8817e4Smiod put them into the correct asections. */
33843d8817e4Smiod lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
33853d8817e4Smiod
33863d8817e4Smiod if (! abfd->output_has_begun)
33873d8817e4Smiod {
33883d8817e4Smiod if (! coff_compute_section_file_positions (abfd))
33893d8817e4Smiod return FALSE;
33903d8817e4Smiod }
33913d8817e4Smiod
33923d8817e4Smiod reloc_base = obj_relocbase (abfd);
33933d8817e4Smiod
33943d8817e4Smiod /* Work out the size of the reloc and linno areas. */
33953d8817e4Smiod
33963d8817e4Smiod for (current = abfd->sections; current != NULL; current =
33973d8817e4Smiod current->next)
33983d8817e4Smiod {
33993d8817e4Smiod #ifdef COFF_WITH_PE
34003d8817e4Smiod /* We store the actual reloc count in the first reloc's addr. */
34013d8817e4Smiod if (obj_pe (abfd) && current->reloc_count >= 0xffff)
34023d8817e4Smiod reloc_count ++;
34033d8817e4Smiod #endif
34043d8817e4Smiod reloc_count += current->reloc_count;
34053d8817e4Smiod }
34063d8817e4Smiod
34073d8817e4Smiod reloc_size = reloc_count * bfd_coff_relsz (abfd);
34083d8817e4Smiod
34093d8817e4Smiod lineno_base = reloc_base + reloc_size;
34103d8817e4Smiod sym_base = lineno_base + lnno_size;
34113d8817e4Smiod
34123d8817e4Smiod /* Indicate in each section->line_filepos its actual file address. */
34133d8817e4Smiod for (current = abfd->sections; current != NULL; current =
34143d8817e4Smiod current->next)
34153d8817e4Smiod {
34163d8817e4Smiod if (current->lineno_count)
34173d8817e4Smiod {
34183d8817e4Smiod current->line_filepos = lineno_base;
34193d8817e4Smiod current->moving_line_filepos = lineno_base;
34203d8817e4Smiod lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
34213d8817e4Smiod }
34223d8817e4Smiod else
34233d8817e4Smiod current->line_filepos = 0;
34243d8817e4Smiod
34253d8817e4Smiod if (current->reloc_count)
34263d8817e4Smiod {
34273d8817e4Smiod current->rel_filepos = reloc_base;
34283d8817e4Smiod reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
34293d8817e4Smiod #ifdef COFF_WITH_PE
34303d8817e4Smiod /* Extra reloc to hold real count. */
34313d8817e4Smiod if (obj_pe (abfd) && current->reloc_count >= 0xffff)
34323d8817e4Smiod reloc_base += bfd_coff_relsz (abfd);
34333d8817e4Smiod #endif
34343d8817e4Smiod }
34353d8817e4Smiod else
34363d8817e4Smiod current->rel_filepos = 0;
34373d8817e4Smiod }
34383d8817e4Smiod
34393d8817e4Smiod /* Write section headers to the file. */
34403d8817e4Smiod internal_f.f_nscns = 0;
34413d8817e4Smiod
34423d8817e4Smiod if ((abfd->flags & EXEC_P) != 0)
34433d8817e4Smiod scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
34443d8817e4Smiod else
34453d8817e4Smiod {
34463d8817e4Smiod scn_base = bfd_coff_filhsz (abfd);
34473d8817e4Smiod #ifdef RS6000COFF_C
34483d8817e4Smiod #ifndef XCOFF64
34493d8817e4Smiod if (xcoff_data (abfd)->full_aouthdr)
34503d8817e4Smiod scn_base += bfd_coff_aoutsz (abfd);
34513d8817e4Smiod else
34523d8817e4Smiod scn_base += SMALL_AOUTSZ;
34533d8817e4Smiod #endif
34543d8817e4Smiod #endif
34553d8817e4Smiod }
34563d8817e4Smiod
34573d8817e4Smiod if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
34583d8817e4Smiod return FALSE;
34593d8817e4Smiod
34603d8817e4Smiod long_section_names = FALSE;
34613d8817e4Smiod for (current = abfd->sections;
34623d8817e4Smiod current != NULL;
34633d8817e4Smiod current = current->next)
34643d8817e4Smiod {
34653d8817e4Smiod struct internal_scnhdr section;
34663d8817e4Smiod bfd_boolean is_reloc_section = FALSE;
34673d8817e4Smiod
34683d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
34693d8817e4Smiod if (strcmp (current->name, ".reloc") == 0)
34703d8817e4Smiod {
34713d8817e4Smiod is_reloc_section = TRUE;
34723d8817e4Smiod hasrelocs = TRUE;
34733d8817e4Smiod pe_data (abfd)->has_reloc_section = 1;
34743d8817e4Smiod }
34753d8817e4Smiod #endif
34763d8817e4Smiod
34773d8817e4Smiod internal_f.f_nscns++;
34783d8817e4Smiod
34793d8817e4Smiod strncpy (section.s_name, current->name, SCNNMLEN);
34803d8817e4Smiod
34813d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
34823d8817e4Smiod /* Handle long section names as in PE. This must be compatible
34833d8817e4Smiod with the code in coff_write_symbols and _bfd_coff_final_link. */
34843d8817e4Smiod {
34853d8817e4Smiod size_t len;
34863d8817e4Smiod
34873d8817e4Smiod len = strlen (current->name);
34883d8817e4Smiod if (len > SCNNMLEN)
34893d8817e4Smiod {
34903d8817e4Smiod memset (section.s_name, 0, SCNNMLEN);
34913d8817e4Smiod sprintf (section.s_name, "/%lu", (unsigned long) string_size);
34923d8817e4Smiod string_size += len + 1;
34933d8817e4Smiod long_section_names = TRUE;
34943d8817e4Smiod }
34953d8817e4Smiod }
34963d8817e4Smiod #endif
34973d8817e4Smiod
34983d8817e4Smiod #ifdef _LIB
34993d8817e4Smiod /* Always set s_vaddr of .lib to 0. This is right for SVR3.2
35003d8817e4Smiod Ian Taylor <ian@cygnus.com>. */
35013d8817e4Smiod if (strcmp (current->name, _LIB) == 0)
35023d8817e4Smiod section.s_vaddr = 0;
35033d8817e4Smiod else
35043d8817e4Smiod #endif
35053d8817e4Smiod section.s_vaddr = current->vma;
35063d8817e4Smiod section.s_paddr = current->lma;
35073d8817e4Smiod section.s_size = current->size;
35083d8817e4Smiod #ifdef coff_get_section_load_page
35093d8817e4Smiod section.s_page = coff_get_section_load_page (current);
35103d8817e4Smiod #endif
35113d8817e4Smiod
35123d8817e4Smiod #ifdef COFF_WITH_PE
35133d8817e4Smiod section.s_paddr = 0;
35143d8817e4Smiod #endif
35153d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
35163d8817e4Smiod /* Reminder: s_paddr holds the virtual size of the section. */
35173d8817e4Smiod if (coff_section_data (abfd, current) != NULL
35183d8817e4Smiod && pei_section_data (abfd, current) != NULL)
35193d8817e4Smiod section.s_paddr = pei_section_data (abfd, current)->virt_size;
35203d8817e4Smiod else
35213d8817e4Smiod section.s_paddr = 0;
35223d8817e4Smiod #endif
35233d8817e4Smiod
35243d8817e4Smiod /* If this section has no size or is unloadable then the scnptr
35253d8817e4Smiod will be 0 too. */
35263d8817e4Smiod if (current->size == 0
35273d8817e4Smiod || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
35283d8817e4Smiod section.s_scnptr = 0;
35293d8817e4Smiod else
35303d8817e4Smiod section.s_scnptr = current->filepos;
35313d8817e4Smiod
35323d8817e4Smiod section.s_relptr = current->rel_filepos;
35333d8817e4Smiod section.s_lnnoptr = current->line_filepos;
35343d8817e4Smiod section.s_nreloc = current->reloc_count;
35353d8817e4Smiod section.s_nlnno = current->lineno_count;
35363d8817e4Smiod #ifndef COFF_IMAGE_WITH_PE
35373d8817e4Smiod /* In PEI, relocs come in the .reloc section. */
35383d8817e4Smiod if (current->reloc_count != 0)
35393d8817e4Smiod hasrelocs = TRUE;
35403d8817e4Smiod #endif
35413d8817e4Smiod if (current->lineno_count != 0)
35423d8817e4Smiod haslinno = TRUE;
35433d8817e4Smiod if ((current->flags & SEC_DEBUGGING) != 0
35443d8817e4Smiod && ! is_reloc_section)
35453d8817e4Smiod hasdebug = TRUE;
35463d8817e4Smiod
35473d8817e4Smiod #ifdef RS6000COFF_C
35483d8817e4Smiod #ifndef XCOFF64
35493d8817e4Smiod /* Indicate the use of an XCOFF overflow section header. */
35503d8817e4Smiod if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
35513d8817e4Smiod {
35523d8817e4Smiod section.s_nreloc = 0xffff;
35533d8817e4Smiod section.s_nlnno = 0xffff;
35543d8817e4Smiod }
35553d8817e4Smiod #endif
35563d8817e4Smiod #endif
35573d8817e4Smiod
35583d8817e4Smiod section.s_flags = sec_to_styp_flags (current->name, current->flags);
35593d8817e4Smiod
35603d8817e4Smiod if (!strcmp (current->name, _TEXT))
35613d8817e4Smiod text_sec = current;
35623d8817e4Smiod else if (!strcmp (current->name, _DATA))
35633d8817e4Smiod data_sec = current;
35643d8817e4Smiod else if (!strcmp (current->name, _BSS))
35653d8817e4Smiod bss_sec = current;
35663d8817e4Smiod
35673d8817e4Smiod #ifdef I960
35683d8817e4Smiod section.s_align = (current->alignment_power
35693d8817e4Smiod ? 1 << current->alignment_power
35703d8817e4Smiod : 0);
35713d8817e4Smiod #endif
35723d8817e4Smiod #ifdef TIC80COFF
35733d8817e4Smiod /* TI COFF puts the alignment power in bits 8-11 of the flags. */
35743d8817e4Smiod section.s_flags |= (current->alignment_power & 0xF) << 8;
35753d8817e4Smiod #endif
35763d8817e4Smiod #ifdef COFF_ENCODE_ALIGNMENT
35773d8817e4Smiod COFF_ENCODE_ALIGNMENT(section, current->alignment_power);
35783d8817e4Smiod #endif
35793d8817e4Smiod
35803d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
35813d8817e4Smiod /* Suppress output of the sections if they are null. ld
35823d8817e4Smiod includes the bss and data sections even if there is no size
35833d8817e4Smiod assigned to them. NT loader doesn't like it if these section
35843d8817e4Smiod headers are included if the sections themselves are not
35853d8817e4Smiod needed. See also coff_compute_section_file_positions. */
35863d8817e4Smiod if (section.s_size == 0)
35873d8817e4Smiod internal_f.f_nscns--;
35883d8817e4Smiod else
35893d8817e4Smiod #endif
35903d8817e4Smiod {
35913d8817e4Smiod SCNHDR buff;
35923d8817e4Smiod bfd_size_type amt = bfd_coff_scnhsz (abfd);
35933d8817e4Smiod
35943d8817e4Smiod if (coff_swap_scnhdr_out (abfd, §ion, &buff) == 0
35953d8817e4Smiod || bfd_bwrite (& buff, amt, abfd) != amt)
35963d8817e4Smiod return FALSE;
35973d8817e4Smiod }
35983d8817e4Smiod
35993d8817e4Smiod #ifdef COFF_WITH_PE
36003d8817e4Smiod /* PE stores COMDAT section information in the symbol table. If
36013d8817e4Smiod this section is supposed to have some COMDAT info, track down
36023d8817e4Smiod the symbol in the symbol table and modify it. */
36033d8817e4Smiod if ((current->flags & SEC_LINK_ONCE) != 0)
36043d8817e4Smiod {
36053d8817e4Smiod unsigned int i, count;
36063d8817e4Smiod asymbol **psym;
36073d8817e4Smiod coff_symbol_type *csym = NULL;
36083d8817e4Smiod asymbol **psymsec;
36093d8817e4Smiod
36103d8817e4Smiod psymsec = NULL;
36113d8817e4Smiod count = bfd_get_symcount (abfd);
36123d8817e4Smiod for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
36133d8817e4Smiod {
36143d8817e4Smiod if ((*psym)->section != current)
36153d8817e4Smiod continue;
36163d8817e4Smiod
36173d8817e4Smiod /* Remember the location of the first symbol in this
36183d8817e4Smiod section. */
36193d8817e4Smiod if (psymsec == NULL)
36203d8817e4Smiod psymsec = psym;
36213d8817e4Smiod
36223d8817e4Smiod /* See if this is the section symbol. */
36233d8817e4Smiod if (strcmp ((*psym)->name, current->name) == 0)
36243d8817e4Smiod {
36253d8817e4Smiod csym = coff_symbol_from (abfd, *psym);
36263d8817e4Smiod if (csym == NULL
36273d8817e4Smiod || csym->native == NULL
36283d8817e4Smiod || csym->native->u.syment.n_numaux < 1
36293d8817e4Smiod || csym->native->u.syment.n_sclass != C_STAT
36303d8817e4Smiod || csym->native->u.syment.n_type != T_NULL)
36313d8817e4Smiod continue;
36323d8817e4Smiod
36333d8817e4Smiod /* Here *PSYM is the section symbol for CURRENT. */
36343d8817e4Smiod
36353d8817e4Smiod break;
36363d8817e4Smiod }
36373d8817e4Smiod }
36383d8817e4Smiod
36393d8817e4Smiod /* Did we find it?
36403d8817e4Smiod Note that we might not if we're converting the file from
36413d8817e4Smiod some other object file format. */
36423d8817e4Smiod if (i < count)
36433d8817e4Smiod {
36443d8817e4Smiod combined_entry_type *aux;
36453d8817e4Smiod
36463d8817e4Smiod /* We don't touch the x_checksum field. The
36473d8817e4Smiod x_associated field is not currently supported. */
36483d8817e4Smiod
36493d8817e4Smiod aux = csym->native + 1;
36503d8817e4Smiod switch (current->flags & SEC_LINK_DUPLICATES)
36513d8817e4Smiod {
36523d8817e4Smiod case SEC_LINK_DUPLICATES_DISCARD:
36533d8817e4Smiod aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
36543d8817e4Smiod break;
36553d8817e4Smiod
36563d8817e4Smiod case SEC_LINK_DUPLICATES_ONE_ONLY:
36573d8817e4Smiod aux->u.auxent.x_scn.x_comdat =
36583d8817e4Smiod IMAGE_COMDAT_SELECT_NODUPLICATES;
36593d8817e4Smiod break;
36603d8817e4Smiod
36613d8817e4Smiod case SEC_LINK_DUPLICATES_SAME_SIZE:
36623d8817e4Smiod aux->u.auxent.x_scn.x_comdat =
36633d8817e4Smiod IMAGE_COMDAT_SELECT_SAME_SIZE;
36643d8817e4Smiod break;
36653d8817e4Smiod
36663d8817e4Smiod case SEC_LINK_DUPLICATES_SAME_CONTENTS:
36673d8817e4Smiod aux->u.auxent.x_scn.x_comdat =
36683d8817e4Smiod IMAGE_COMDAT_SELECT_EXACT_MATCH;
36693d8817e4Smiod break;
36703d8817e4Smiod }
36713d8817e4Smiod
36723d8817e4Smiod /* The COMDAT symbol must be the first symbol from this
36733d8817e4Smiod section in the symbol table. In order to make this
36743d8817e4Smiod work, we move the COMDAT symbol before the first
36753d8817e4Smiod symbol we found in the search above. It's OK to
36763d8817e4Smiod rearrange the symbol table at this point, because
36773d8817e4Smiod coff_renumber_symbols is going to rearrange it
36783d8817e4Smiod further and fix up all the aux entries. */
36793d8817e4Smiod if (psym != psymsec)
36803d8817e4Smiod {
36813d8817e4Smiod asymbol *hold;
36823d8817e4Smiod asymbol **pcopy;
36833d8817e4Smiod
36843d8817e4Smiod hold = *psym;
36853d8817e4Smiod for (pcopy = psym; pcopy > psymsec; pcopy--)
36863d8817e4Smiod pcopy[0] = pcopy[-1];
36873d8817e4Smiod *psymsec = hold;
36883d8817e4Smiod }
36893d8817e4Smiod }
36903d8817e4Smiod }
36913d8817e4Smiod #endif /* COFF_WITH_PE */
36923d8817e4Smiod }
36933d8817e4Smiod
36943d8817e4Smiod #ifdef RS6000COFF_C
36953d8817e4Smiod #ifndef XCOFF64
36963d8817e4Smiod /* XCOFF handles overflows in the reloc and line number count fields
36973d8817e4Smiod by creating a new section header to hold the correct values. */
36983d8817e4Smiod for (current = abfd->sections; current != NULL; current = current->next)
36993d8817e4Smiod {
37003d8817e4Smiod if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
37013d8817e4Smiod {
37023d8817e4Smiod struct internal_scnhdr scnhdr;
37033d8817e4Smiod SCNHDR buff;
37043d8817e4Smiod bfd_size_type amt;
37053d8817e4Smiod
37063d8817e4Smiod internal_f.f_nscns++;
37073d8817e4Smiod strncpy (&(scnhdr.s_name[0]), current->name, 8);
37083d8817e4Smiod scnhdr.s_paddr = current->reloc_count;
37093d8817e4Smiod scnhdr.s_vaddr = current->lineno_count;
37103d8817e4Smiod scnhdr.s_size = 0;
37113d8817e4Smiod scnhdr.s_scnptr = 0;
37123d8817e4Smiod scnhdr.s_relptr = current->rel_filepos;
37133d8817e4Smiod scnhdr.s_lnnoptr = current->line_filepos;
37143d8817e4Smiod scnhdr.s_nreloc = current->target_index;
37153d8817e4Smiod scnhdr.s_nlnno = current->target_index;
37163d8817e4Smiod scnhdr.s_flags = STYP_OVRFLO;
37173d8817e4Smiod amt = bfd_coff_scnhsz (abfd);
37183d8817e4Smiod if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
37193d8817e4Smiod || bfd_bwrite (& buff, amt, abfd) != amt)
37203d8817e4Smiod return FALSE;
37213d8817e4Smiod }
37223d8817e4Smiod }
37233d8817e4Smiod #endif
37243d8817e4Smiod #endif
37253d8817e4Smiod
37263d8817e4Smiod /* OK, now set up the filehdr... */
37273d8817e4Smiod
37283d8817e4Smiod /* Don't include the internal abs section in the section count */
37293d8817e4Smiod
37303d8817e4Smiod /* We will NOT put a fucking timestamp in the header here. Every time you
37313d8817e4Smiod put it back, I will come in and take it out again. I'm sorry. This
37323d8817e4Smiod field does not belong here. We fill it with a 0 so it compares the
37333d8817e4Smiod same but is not a reasonable time. -- gnu@cygnus.com */
37343d8817e4Smiod internal_f.f_timdat = 0;
37353d8817e4Smiod internal_f.f_flags = 0;
37363d8817e4Smiod
37373d8817e4Smiod if (abfd->flags & EXEC_P)
37383d8817e4Smiod internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
37393d8817e4Smiod else
37403d8817e4Smiod {
37413d8817e4Smiod internal_f.f_opthdr = 0;
37423d8817e4Smiod #ifdef RS6000COFF_C
37433d8817e4Smiod #ifndef XCOFF64
37443d8817e4Smiod if (xcoff_data (abfd)->full_aouthdr)
37453d8817e4Smiod internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
37463d8817e4Smiod else
37473d8817e4Smiod internal_f.f_opthdr = SMALL_AOUTSZ;
37483d8817e4Smiod #endif
37493d8817e4Smiod #endif
37503d8817e4Smiod }
37513d8817e4Smiod
37523d8817e4Smiod if (!hasrelocs)
37533d8817e4Smiod internal_f.f_flags |= F_RELFLG;
37543d8817e4Smiod if (!haslinno)
37553d8817e4Smiod internal_f.f_flags |= F_LNNO;
37563d8817e4Smiod if (abfd->flags & EXEC_P)
37573d8817e4Smiod internal_f.f_flags |= F_EXEC;
37583d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
37593d8817e4Smiod if (! hasdebug)
37603d8817e4Smiod internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
37613d8817e4Smiod if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
37623d8817e4Smiod internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
37633d8817e4Smiod #endif
37643d8817e4Smiod
37656e5cc252Skettenis #ifndef COFF_WITH_pex64
37663d8817e4Smiod #ifdef COFF_WITH_PE
37673d8817e4Smiod internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
37683d8817e4Smiod #else
37693d8817e4Smiod if (bfd_little_endian (abfd))
37703d8817e4Smiod internal_f.f_flags |= F_AR32WR;
37713d8817e4Smiod else
37723d8817e4Smiod internal_f.f_flags |= F_AR32W;
37733d8817e4Smiod #endif
37746e5cc252Skettenis #endif
37753d8817e4Smiod
37763d8817e4Smiod #ifdef TI_TARGET_ID
37773d8817e4Smiod /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
37783d8817e4Smiod but it doesn't hurt to set it internally. */
37793d8817e4Smiod internal_f.f_target_id = TI_TARGET_ID;
37803d8817e4Smiod #endif
37813d8817e4Smiod #ifdef TIC80_TARGET_ID
37823d8817e4Smiod internal_f.f_target_id = TIC80_TARGET_ID;
37833d8817e4Smiod #endif
37843d8817e4Smiod
37853d8817e4Smiod /* FIXME, should do something about the other byte orders and
37863d8817e4Smiod architectures. */
37873d8817e4Smiod
37883d8817e4Smiod #ifdef RS6000COFF_C
37893d8817e4Smiod if ((abfd->flags & DYNAMIC) != 0)
37903d8817e4Smiod internal_f.f_flags |= F_SHROBJ;
37913d8817e4Smiod if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
37923d8817e4Smiod internal_f.f_flags |= F_DYNLOAD;
37933d8817e4Smiod #endif
37943d8817e4Smiod
37953d8817e4Smiod memset (&internal_a, 0, sizeof internal_a);
37963d8817e4Smiod
37973d8817e4Smiod /* Set up architecture-dependent stuff. */
37983d8817e4Smiod {
37993d8817e4Smiod unsigned int magic = 0;
38003d8817e4Smiod unsigned short flags = 0;
38013d8817e4Smiod
38023d8817e4Smiod coff_set_flags (abfd, &magic, &flags);
38033d8817e4Smiod internal_f.f_magic = magic;
38043d8817e4Smiod internal_f.f_flags |= flags;
38053d8817e4Smiod /* ...and the "opt"hdr... */
38063d8817e4Smiod
38073d8817e4Smiod #ifdef TICOFF_AOUT_MAGIC
38083d8817e4Smiod internal_a.magic = TICOFF_AOUT_MAGIC;
38093d8817e4Smiod #define __A_MAGIC_SET__
38103d8817e4Smiod #endif
38113d8817e4Smiod #ifdef TIC80COFF
38123d8817e4Smiod internal_a.magic = TIC80_ARCH_MAGIC;
38133d8817e4Smiod #define __A_MAGIC_SET__
38143d8817e4Smiod #endif /* TIC80 */
38153d8817e4Smiod #ifdef I860
38163d8817e4Smiod /* FIXME: What are the a.out magic numbers for the i860? */
38173d8817e4Smiod internal_a.magic = 0;
38183d8817e4Smiod #define __A_MAGIC_SET__
38193d8817e4Smiod #endif /* I860 */
38203d8817e4Smiod #ifdef I960
38213d8817e4Smiod internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
38223d8817e4Smiod #define __A_MAGIC_SET__
38233d8817e4Smiod #endif /* I960 */
38243d8817e4Smiod #if M88
38253d8817e4Smiod #define __A_MAGIC_SET__
38263d8817e4Smiod internal_a.magic = PAGEMAGICBCS;
38273d8817e4Smiod #endif /* M88 */
38283d8817e4Smiod
38293d8817e4Smiod #if APOLLO_M68
38303d8817e4Smiod #define __A_MAGIC_SET__
38313d8817e4Smiod internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
38323d8817e4Smiod #endif
38333d8817e4Smiod
38343d8817e4Smiod #if defined(M68) || defined(WE32K) || defined(M68K)
38353d8817e4Smiod #define __A_MAGIC_SET__
38363d8817e4Smiod #if defined(LYNXOS)
38373d8817e4Smiod internal_a.magic = LYNXCOFFMAGIC;
38383d8817e4Smiod #else
38393d8817e4Smiod #if defined(TARG_AUX)
38403d8817e4Smiod internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED :
38413d8817e4Smiod abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED :
38423d8817e4Smiod PAGEMAGICEXECSWAPPED);
38433d8817e4Smiod #else
38443d8817e4Smiod #if defined (PAGEMAGICPEXECPAGED)
38453d8817e4Smiod internal_a.magic = PAGEMAGICPEXECPAGED;
38463d8817e4Smiod #endif
38473d8817e4Smiod #endif /* TARG_AUX */
38483d8817e4Smiod #endif /* LYNXOS */
38493d8817e4Smiod #endif /* M68 || WE32K || M68K */
38503d8817e4Smiod
38513d8817e4Smiod #if defined(ARM)
38523d8817e4Smiod #define __A_MAGIC_SET__
38533d8817e4Smiod internal_a.magic = ZMAGIC;
38543d8817e4Smiod #endif
38553d8817e4Smiod
38563d8817e4Smiod #if defined(PPC_PE)
38573d8817e4Smiod #define __A_MAGIC_SET__
38583d8817e4Smiod internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
38593d8817e4Smiod #endif
38603d8817e4Smiod
38613d8817e4Smiod #if defined MCORE_PE
38623d8817e4Smiod #define __A_MAGIC_SET__
38633d8817e4Smiod internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
38643d8817e4Smiod #endif
38653d8817e4Smiod
38663d8817e4Smiod #if defined(I386)
38673d8817e4Smiod #define __A_MAGIC_SET__
38683d8817e4Smiod #if defined(LYNXOS)
38693d8817e4Smiod internal_a.magic = LYNXCOFFMAGIC;
38706e5cc252Skettenis #elif defined AMD64
38716e5cc252Skettenis internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
38723d8817e4Smiod #else /* LYNXOS */
38733d8817e4Smiod internal_a.magic = ZMAGIC;
38743d8817e4Smiod #endif /* LYNXOS */
38753d8817e4Smiod #endif /* I386 */
38763d8817e4Smiod
38773d8817e4Smiod #if defined(IA64)
38783d8817e4Smiod #define __A_MAGIC_SET__
38793d8817e4Smiod internal_a.magic = ZMAGIC;
38803d8817e4Smiod #endif /* IA64 */
38813d8817e4Smiod
38823d8817e4Smiod #if defined(SPARC)
38833d8817e4Smiod #define __A_MAGIC_SET__
38843d8817e4Smiod #if defined(LYNXOS)
38853d8817e4Smiod internal_a.magic = LYNXCOFFMAGIC;
38863d8817e4Smiod #endif /* LYNXOS */
38873d8817e4Smiod #endif /* SPARC */
38883d8817e4Smiod
38893d8817e4Smiod #ifdef RS6000COFF_C
38903d8817e4Smiod #define __A_MAGIC_SET__
38913d8817e4Smiod internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
38923d8817e4Smiod (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
38933d8817e4Smiod RS6K_AOUTHDR_OMAGIC;
38943d8817e4Smiod #endif
38953d8817e4Smiod
38963d8817e4Smiod #if defined(SH) && defined(COFF_WITH_PE)
38973d8817e4Smiod #define __A_MAGIC_SET__
38983d8817e4Smiod internal_a.magic = SH_PE_MAGIC;
38993d8817e4Smiod #endif
39003d8817e4Smiod
39013d8817e4Smiod #if defined(MIPS) && defined(COFF_WITH_PE)
39023d8817e4Smiod #define __A_MAGIC_SET__
39033d8817e4Smiod internal_a.magic = MIPS_PE_MAGIC;
39043d8817e4Smiod #endif
39053d8817e4Smiod
39063d8817e4Smiod #ifdef OR32
39073d8817e4Smiod #define __A_MAGIC_SET__
39083d8817e4Smiod internal_a.magic = NMAGIC; /* Assume separate i/d. */
39093d8817e4Smiod #endif
39103d8817e4Smiod
39113d8817e4Smiod #ifdef MAXQ20MAGIC
39123d8817e4Smiod #define __A_MAGIC_SET__
39133d8817e4Smiod internal_a.magic = MAXQ20MAGIC;
39143d8817e4Smiod #endif
39153d8817e4Smiod
39163d8817e4Smiod #ifndef __A_MAGIC_SET__
39173d8817e4Smiod #include "Your aouthdr magic number is not being set!"
39183d8817e4Smiod #else
39193d8817e4Smiod #undef __A_MAGIC_SET__
39203d8817e4Smiod #endif
39213d8817e4Smiod }
39223d8817e4Smiod
39233d8817e4Smiod /* FIXME: Does anybody ever set this to another value? */
39243d8817e4Smiod internal_a.vstamp = 0;
39253d8817e4Smiod
39263d8817e4Smiod /* Now should write relocs, strings, syms. */
39273d8817e4Smiod obj_sym_filepos (abfd) = sym_base;
39283d8817e4Smiod
39293d8817e4Smiod if (bfd_get_symcount (abfd) != 0)
39303d8817e4Smiod {
39313d8817e4Smiod int firstundef;
39323d8817e4Smiod
39333d8817e4Smiod if (!coff_renumber_symbols (abfd, &firstundef))
39343d8817e4Smiod return FALSE;
39353d8817e4Smiod coff_mangle_symbols (abfd);
39363d8817e4Smiod if (! coff_write_symbols (abfd))
39373d8817e4Smiod return FALSE;
39383d8817e4Smiod if (! coff_write_linenumbers (abfd))
39393d8817e4Smiod return FALSE;
39403d8817e4Smiod if (! coff_write_relocs (abfd, firstundef))
39413d8817e4Smiod return FALSE;
39423d8817e4Smiod }
39433d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
39443d8817e4Smiod else if (long_section_names && ! obj_coff_strings_written (abfd))
39453d8817e4Smiod {
39463d8817e4Smiod /* If we have long section names we have to write out the string
39473d8817e4Smiod table even if there are no symbols. */
39483d8817e4Smiod if (! coff_write_symbols (abfd))
39493d8817e4Smiod return FALSE;
39503d8817e4Smiod }
39513d8817e4Smiod #endif
39523d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
39533d8817e4Smiod #ifdef PPC_PE
39543d8817e4Smiod else if ((abfd->flags & EXEC_P) != 0)
39553d8817e4Smiod {
39563d8817e4Smiod bfd_byte b;
39573d8817e4Smiod
39583d8817e4Smiod /* PowerPC PE appears to require that all executable files be
39593d8817e4Smiod rounded up to the page size. */
39603d8817e4Smiod b = 0;
39613d8817e4Smiod if (bfd_seek (abfd,
39623d8817e4Smiod (file_ptr) BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
39633d8817e4Smiod SEEK_SET) != 0
39643d8817e4Smiod || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
39653d8817e4Smiod return FALSE;
39663d8817e4Smiod }
39673d8817e4Smiod #endif
39683d8817e4Smiod #endif
39693d8817e4Smiod
39703d8817e4Smiod /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
39713d8817e4Smiod backend linker, and obj_raw_syment_count is not valid until after
39723d8817e4Smiod coff_write_symbols is called. */
39733d8817e4Smiod if (obj_raw_syment_count (abfd) != 0)
39743d8817e4Smiod {
39753d8817e4Smiod internal_f.f_symptr = sym_base;
39763d8817e4Smiod #ifdef RS6000COFF_C
39773d8817e4Smiod /* AIX appears to require that F_RELFLG not be set if there are
39783d8817e4Smiod local symbols but no relocations. */
39793d8817e4Smiod internal_f.f_flags &=~ F_RELFLG;
39803d8817e4Smiod #endif
39813d8817e4Smiod }
39823d8817e4Smiod else
39833d8817e4Smiod {
39843d8817e4Smiod if (long_section_names)
39853d8817e4Smiod internal_f.f_symptr = sym_base;
39863d8817e4Smiod else
39873d8817e4Smiod internal_f.f_symptr = 0;
39883d8817e4Smiod internal_f.f_flags |= F_LSYMS;
39893d8817e4Smiod }
39903d8817e4Smiod
39913d8817e4Smiod if (text_sec)
39923d8817e4Smiod {
39933d8817e4Smiod internal_a.tsize = text_sec->size;
39943d8817e4Smiod internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
39953d8817e4Smiod }
39963d8817e4Smiod if (data_sec)
39973d8817e4Smiod {
39983d8817e4Smiod internal_a.dsize = data_sec->size;
39993d8817e4Smiod internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
40003d8817e4Smiod }
40013d8817e4Smiod if (bss_sec)
40023d8817e4Smiod {
40033d8817e4Smiod internal_a.bsize = bss_sec->size;
40043d8817e4Smiod if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
40053d8817e4Smiod internal_a.data_start = bss_sec->vma;
40063d8817e4Smiod }
40073d8817e4Smiod
40083d8817e4Smiod internal_a.entry = bfd_get_start_address (abfd);
40093d8817e4Smiod internal_f.f_nsyms = obj_raw_syment_count (abfd);
40103d8817e4Smiod
40113d8817e4Smiod #ifdef RS6000COFF_C
40123d8817e4Smiod if (xcoff_data (abfd)->full_aouthdr)
40133d8817e4Smiod {
40143d8817e4Smiod bfd_vma toc;
40153d8817e4Smiod asection *loader_sec;
40163d8817e4Smiod
40173d8817e4Smiod internal_a.vstamp = 1;
40183d8817e4Smiod
40193d8817e4Smiod internal_a.o_snentry = xcoff_data (abfd)->snentry;
40203d8817e4Smiod if (internal_a.o_snentry == 0)
40213d8817e4Smiod internal_a.entry = (bfd_vma) -1;
40223d8817e4Smiod
40233d8817e4Smiod if (text_sec != NULL)
40243d8817e4Smiod {
40253d8817e4Smiod internal_a.o_sntext = text_sec->target_index;
40263d8817e4Smiod internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
40273d8817e4Smiod }
40283d8817e4Smiod else
40293d8817e4Smiod {
40303d8817e4Smiod internal_a.o_sntext = 0;
40313d8817e4Smiod internal_a.o_algntext = 0;
40323d8817e4Smiod }
40333d8817e4Smiod if (data_sec != NULL)
40343d8817e4Smiod {
40353d8817e4Smiod internal_a.o_sndata = data_sec->target_index;
40363d8817e4Smiod internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
40373d8817e4Smiod }
40383d8817e4Smiod else
40393d8817e4Smiod {
40403d8817e4Smiod internal_a.o_sndata = 0;
40413d8817e4Smiod internal_a.o_algndata = 0;
40423d8817e4Smiod }
40433d8817e4Smiod loader_sec = bfd_get_section_by_name (abfd, ".loader");
40443d8817e4Smiod if (loader_sec != NULL)
40453d8817e4Smiod internal_a.o_snloader = loader_sec->target_index;
40463d8817e4Smiod else
40473d8817e4Smiod internal_a.o_snloader = 0;
40483d8817e4Smiod if (bss_sec != NULL)
40493d8817e4Smiod internal_a.o_snbss = bss_sec->target_index;
40503d8817e4Smiod else
40513d8817e4Smiod internal_a.o_snbss = 0;
40523d8817e4Smiod
40533d8817e4Smiod toc = xcoff_data (abfd)->toc;
40543d8817e4Smiod internal_a.o_toc = toc;
40553d8817e4Smiod internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
40563d8817e4Smiod
40573d8817e4Smiod internal_a.o_modtype = xcoff_data (abfd)->modtype;
40583d8817e4Smiod if (xcoff_data (abfd)->cputype != -1)
40593d8817e4Smiod internal_a.o_cputype = xcoff_data (abfd)->cputype;
40603d8817e4Smiod else
40613d8817e4Smiod {
40623d8817e4Smiod switch (bfd_get_arch (abfd))
40633d8817e4Smiod {
40643d8817e4Smiod case bfd_arch_rs6000:
40653d8817e4Smiod internal_a.o_cputype = 4;
40663d8817e4Smiod break;
40673d8817e4Smiod case bfd_arch_powerpc:
40683d8817e4Smiod if (bfd_get_mach (abfd) == bfd_mach_ppc)
40693d8817e4Smiod internal_a.o_cputype = 3;
40703d8817e4Smiod else
40713d8817e4Smiod internal_a.o_cputype = 1;
40723d8817e4Smiod break;
40733d8817e4Smiod default:
40743d8817e4Smiod abort ();
40753d8817e4Smiod }
40763d8817e4Smiod }
40773d8817e4Smiod internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
40783d8817e4Smiod internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
40793d8817e4Smiod }
40803d8817e4Smiod #endif
40813d8817e4Smiod
40823d8817e4Smiod /* Now write them. */
40833d8817e4Smiod if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
40843d8817e4Smiod return FALSE;
40853d8817e4Smiod
40863d8817e4Smiod {
40873d8817e4Smiod char * buff;
40883d8817e4Smiod bfd_size_type amount = bfd_coff_filhsz (abfd);
40893d8817e4Smiod
40903d8817e4Smiod buff = bfd_malloc (amount);
40913d8817e4Smiod if (buff == NULL)
40923d8817e4Smiod return FALSE;
40933d8817e4Smiod
40943d8817e4Smiod bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
40953d8817e4Smiod amount = bfd_bwrite (buff, amount, abfd);
40963d8817e4Smiod
40973d8817e4Smiod free (buff);
40983d8817e4Smiod
40993d8817e4Smiod if (amount != bfd_coff_filhsz (abfd))
41003d8817e4Smiod return FALSE;
41013d8817e4Smiod }
41023d8817e4Smiod
41033d8817e4Smiod if (abfd->flags & EXEC_P)
41043d8817e4Smiod {
41053d8817e4Smiod /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
41063d8817e4Smiod include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)). */
41073d8817e4Smiod char * buff;
41083d8817e4Smiod bfd_size_type amount = bfd_coff_aoutsz (abfd);
41093d8817e4Smiod
41103d8817e4Smiod buff = bfd_malloc (amount);
41113d8817e4Smiod if (buff == NULL)
41123d8817e4Smiod return FALSE;
41133d8817e4Smiod
41143d8817e4Smiod coff_swap_aouthdr_out (abfd, & internal_a, buff);
41153d8817e4Smiod amount = bfd_bwrite (buff, amount, abfd);
41163d8817e4Smiod
41173d8817e4Smiod free (buff);
41183d8817e4Smiod
41193d8817e4Smiod if (amount != bfd_coff_aoutsz (abfd))
41203d8817e4Smiod return FALSE;
41213d8817e4Smiod
41223d8817e4Smiod #ifdef COFF_IMAGE_WITH_PE
41233d8817e4Smiod if (! coff_apply_checksum (abfd))
41243d8817e4Smiod return FALSE;
41253d8817e4Smiod #endif
41263d8817e4Smiod }
41273d8817e4Smiod #ifdef RS6000COFF_C
41283d8817e4Smiod else
41293d8817e4Smiod {
41303d8817e4Smiod AOUTHDR buff;
41313d8817e4Smiod size_t size;
41323d8817e4Smiod
41333d8817e4Smiod /* XCOFF seems to always write at least a small a.out header. */
41343d8817e4Smiod coff_swap_aouthdr_out (abfd, & internal_a, & buff);
41353d8817e4Smiod if (xcoff_data (abfd)->full_aouthdr)
41363d8817e4Smiod size = bfd_coff_aoutsz (abfd);
41373d8817e4Smiod else
41383d8817e4Smiod size = SMALL_AOUTSZ;
41393d8817e4Smiod if (bfd_bwrite (& buff, (bfd_size_type) size, abfd) != size)
41403d8817e4Smiod return FALSE;
41413d8817e4Smiod }
41423d8817e4Smiod #endif
41433d8817e4Smiod
41443d8817e4Smiod return TRUE;
41453d8817e4Smiod }
41463d8817e4Smiod
41473d8817e4Smiod static bfd_boolean
coff_set_section_contents(bfd * abfd,sec_ptr section,const void * location,file_ptr offset,bfd_size_type count)41483d8817e4Smiod coff_set_section_contents (bfd * abfd,
41493d8817e4Smiod sec_ptr section,
41503d8817e4Smiod const void * location,
41513d8817e4Smiod file_ptr offset,
41523d8817e4Smiod bfd_size_type count)
41533d8817e4Smiod {
41543d8817e4Smiod if (! abfd->output_has_begun) /* Set by bfd.c handler. */
41553d8817e4Smiod {
41563d8817e4Smiod if (! coff_compute_section_file_positions (abfd))
41573d8817e4Smiod return FALSE;
41583d8817e4Smiod }
41593d8817e4Smiod
41603d8817e4Smiod #if defined(_LIB) && !defined(TARG_AUX)
41613d8817e4Smiod /* The physical address field of a .lib section is used to hold the
41623d8817e4Smiod number of shared libraries in the section. This code counts the
41633d8817e4Smiod number of sections being written, and increments the lma field
41643d8817e4Smiod with the number.
41653d8817e4Smiod
41663d8817e4Smiod I have found no documentation on the contents of this section.
41673d8817e4Smiod Experimentation indicates that the section contains zero or more
41683d8817e4Smiod records, each of which has the following structure:
41693d8817e4Smiod
41703d8817e4Smiod - a (four byte) word holding the length of this record, in words,
41713d8817e4Smiod - a word that always seems to be set to "2",
41723d8817e4Smiod - the path to a shared library, null-terminated and then padded
41733d8817e4Smiod to a whole word boundary.
41743d8817e4Smiod
41753d8817e4Smiod bfd_assert calls have been added to alert if an attempt is made
41763d8817e4Smiod to write a section which doesn't follow these assumptions. The
41773d8817e4Smiod code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
41783d8817e4Smiod <robertl@arnet.com> (Thanks!).
41793d8817e4Smiod
41803d8817e4Smiod Gvran Uddeborg <gvran@uddeborg.pp.se>. */
41813d8817e4Smiod if (strcmp (section->name, _LIB) == 0)
41823d8817e4Smiod {
41833d8817e4Smiod bfd_byte *rec, *recend;
41843d8817e4Smiod
41853d8817e4Smiod rec = (bfd_byte *) location;
41863d8817e4Smiod recend = rec + count;
41873d8817e4Smiod while (rec < recend)
41883d8817e4Smiod {
41893d8817e4Smiod ++section->lma;
41903d8817e4Smiod rec += bfd_get_32 (abfd, rec) * 4;
41913d8817e4Smiod }
41923d8817e4Smiod
41933d8817e4Smiod BFD_ASSERT (rec == recend);
41943d8817e4Smiod }
41953d8817e4Smiod #endif
41963d8817e4Smiod
41973d8817e4Smiod /* Don't write out bss sections - one way to do this is to
41983d8817e4Smiod see if the filepos has not been set. */
41993d8817e4Smiod if (section->filepos == 0)
42003d8817e4Smiod return TRUE;
42013d8817e4Smiod
42023d8817e4Smiod if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
42033d8817e4Smiod return FALSE;
42043d8817e4Smiod
42053d8817e4Smiod if (count == 0)
42063d8817e4Smiod return TRUE;
42073d8817e4Smiod
42083d8817e4Smiod return bfd_bwrite (location, count, abfd) == count;
42093d8817e4Smiod }
42103d8817e4Smiod
42113d8817e4Smiod static void *
buy_and_read(bfd * abfd,file_ptr where,bfd_size_type size)42123d8817e4Smiod buy_and_read (bfd *abfd, file_ptr where, bfd_size_type size)
42133d8817e4Smiod {
42143d8817e4Smiod void * area = bfd_alloc (abfd, size);
42153d8817e4Smiod
42163d8817e4Smiod if (!area)
42173d8817e4Smiod return (NULL);
42183d8817e4Smiod if (bfd_seek (abfd, where, SEEK_SET) != 0
42193d8817e4Smiod || bfd_bread (area, size, abfd) != size)
42203d8817e4Smiod return (NULL);
42213d8817e4Smiod return (area);
42223d8817e4Smiod }
42233d8817e4Smiod
42243d8817e4Smiod /*
42253d8817e4Smiod SUBSUBSECTION
42263d8817e4Smiod Reading linenumbers
42273d8817e4Smiod
42283d8817e4Smiod Creating the linenumber table is done by reading in the entire
42293d8817e4Smiod coff linenumber table, and creating another table for internal use.
42303d8817e4Smiod
42313d8817e4Smiod A coff linenumber table is structured so that each function
42323d8817e4Smiod is marked as having a line number of 0. Each line within the
42333d8817e4Smiod function is an offset from the first line in the function. The
42343d8817e4Smiod base of the line number information for the table is stored in
42353d8817e4Smiod the symbol associated with the function.
42363d8817e4Smiod
42373d8817e4Smiod Note: The PE format uses line number 0 for a flag indicating a
42383d8817e4Smiod new source file.
42393d8817e4Smiod
42403d8817e4Smiod The information is copied from the external to the internal
42413d8817e4Smiod table, and each symbol which marks a function is marked by
42423d8817e4Smiod pointing its...
42433d8817e4Smiod
42443d8817e4Smiod How does this work ?
42453d8817e4Smiod */
42463d8817e4Smiod
42473d8817e4Smiod static bfd_boolean
coff_slurp_line_table(bfd * abfd,asection * asect)42483d8817e4Smiod coff_slurp_line_table (bfd *abfd, asection *asect)
42493d8817e4Smiod {
42503d8817e4Smiod LINENO *native_lineno;
42513d8817e4Smiod alent *lineno_cache;
42523d8817e4Smiod bfd_size_type amt;
42533d8817e4Smiod
42543d8817e4Smiod BFD_ASSERT (asect->lineno == NULL);
42553d8817e4Smiod
42563d8817e4Smiod amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
42573d8817e4Smiod native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
42583d8817e4Smiod if (native_lineno == NULL)
42593d8817e4Smiod {
42603d8817e4Smiod (*_bfd_error_handler)
42613d8817e4Smiod (_("%B: warning: line number table read failed"), abfd);
42623d8817e4Smiod return FALSE;
42633d8817e4Smiod }
42643d8817e4Smiod amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
42653d8817e4Smiod lineno_cache = bfd_alloc (abfd, amt);
42663d8817e4Smiod if (lineno_cache == NULL)
42673d8817e4Smiod return FALSE;
42683d8817e4Smiod else
42693d8817e4Smiod {
42703d8817e4Smiod unsigned int counter = 0;
42713d8817e4Smiod alent *cache_ptr = lineno_cache;
42723d8817e4Smiod LINENO *src = native_lineno;
42733d8817e4Smiod
42743d8817e4Smiod while (counter < asect->lineno_count)
42753d8817e4Smiod {
42763d8817e4Smiod struct internal_lineno dst;
42773d8817e4Smiod
42783d8817e4Smiod bfd_coff_swap_lineno_in (abfd, src, &dst);
42793d8817e4Smiod cache_ptr->line_number = dst.l_lnno;
42803d8817e4Smiod
42813d8817e4Smiod if (cache_ptr->line_number == 0)
42823d8817e4Smiod {
42833d8817e4Smiod bfd_boolean warned;
42843d8817e4Smiod bfd_signed_vma symndx;
42853d8817e4Smiod coff_symbol_type *sym;
42863d8817e4Smiod
42873d8817e4Smiod warned = FALSE;
42883d8817e4Smiod symndx = dst.l_addr.l_symndx;
42893d8817e4Smiod if (symndx < 0
42903d8817e4Smiod || (bfd_vma) symndx >= obj_raw_syment_count (abfd))
42913d8817e4Smiod {
42923d8817e4Smiod (*_bfd_error_handler)
42933d8817e4Smiod (_("%B: warning: illegal symbol index %ld in line numbers"),
42943d8817e4Smiod abfd, dst.l_addr.l_symndx);
42953d8817e4Smiod symndx = 0;
42963d8817e4Smiod warned = TRUE;
42973d8817e4Smiod }
42983d8817e4Smiod /* FIXME: We should not be casting between ints and
42993d8817e4Smiod pointers like this. */
43003d8817e4Smiod sym = ((coff_symbol_type *)
43013d8817e4Smiod ((symndx + obj_raw_syments (abfd))
43023d8817e4Smiod ->u.syment._n._n_n._n_zeroes));
43033d8817e4Smiod cache_ptr->u.sym = (asymbol *) sym;
43043d8817e4Smiod if (sym->lineno != NULL && ! warned)
43053d8817e4Smiod {
43063d8817e4Smiod (*_bfd_error_handler)
43073d8817e4Smiod (_("%B: warning: duplicate line number information for `%s'"),
43083d8817e4Smiod abfd, bfd_asymbol_name (&sym->symbol));
43093d8817e4Smiod }
43103d8817e4Smiod sym->lineno = cache_ptr;
43113d8817e4Smiod }
43123d8817e4Smiod else
43133d8817e4Smiod cache_ptr->u.offset = dst.l_addr.l_paddr
43143d8817e4Smiod - bfd_section_vma (abfd, asect);
43153d8817e4Smiod
43163d8817e4Smiod cache_ptr++;
43173d8817e4Smiod src++;
43183d8817e4Smiod counter++;
43193d8817e4Smiod }
43203d8817e4Smiod cache_ptr->line_number = 0;
43213d8817e4Smiod
43223d8817e4Smiod }
43233d8817e4Smiod asect->lineno = lineno_cache;
43243d8817e4Smiod /* FIXME, free native_lineno here, or use alloca or something. */
43253d8817e4Smiod return TRUE;
43263d8817e4Smiod }
43273d8817e4Smiod
43283d8817e4Smiod /* Slurp in the symbol table, converting it to generic form. Note
43293d8817e4Smiod that if coff_relocate_section is defined, the linker will read
43303d8817e4Smiod symbols via coff_link_add_symbols, rather than via this routine. */
43313d8817e4Smiod
43323d8817e4Smiod static bfd_boolean
coff_slurp_symbol_table(bfd * abfd)43333d8817e4Smiod coff_slurp_symbol_table (bfd * abfd)
43343d8817e4Smiod {
43353d8817e4Smiod combined_entry_type *native_symbols;
43363d8817e4Smiod coff_symbol_type *cached_area;
43373d8817e4Smiod unsigned int *table_ptr;
43383d8817e4Smiod bfd_size_type amt;
43393d8817e4Smiod unsigned int number_of_symbols = 0;
43403d8817e4Smiod
43413d8817e4Smiod if (obj_symbols (abfd))
43423d8817e4Smiod return TRUE;
43433d8817e4Smiod
43443d8817e4Smiod /* Read in the symbol table. */
43453d8817e4Smiod if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
43463d8817e4Smiod return FALSE;
43473d8817e4Smiod
43483d8817e4Smiod /* Allocate enough room for all the symbols in cached form. */
43493d8817e4Smiod amt = obj_raw_syment_count (abfd);
43503d8817e4Smiod amt *= sizeof (coff_symbol_type);
43513d8817e4Smiod cached_area = bfd_alloc (abfd, amt);
43523d8817e4Smiod if (cached_area == NULL)
43533d8817e4Smiod return FALSE;
43543d8817e4Smiod
43553d8817e4Smiod amt = obj_raw_syment_count (abfd);
43563d8817e4Smiod amt *= sizeof (unsigned int);
43573d8817e4Smiod table_ptr = bfd_alloc (abfd, amt);
43583d8817e4Smiod
43593d8817e4Smiod if (table_ptr == NULL)
43603d8817e4Smiod return FALSE;
43613d8817e4Smiod else
43623d8817e4Smiod {
43633d8817e4Smiod coff_symbol_type *dst = cached_area;
43643d8817e4Smiod unsigned int last_native_index = obj_raw_syment_count (abfd);
43653d8817e4Smiod unsigned int this_index = 0;
43663d8817e4Smiod
43673d8817e4Smiod while (this_index < last_native_index)
43683d8817e4Smiod {
43693d8817e4Smiod combined_entry_type *src = native_symbols + this_index;
43703d8817e4Smiod table_ptr[this_index] = number_of_symbols;
43713d8817e4Smiod dst->symbol.the_bfd = abfd;
43723d8817e4Smiod
43733d8817e4Smiod dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
43743d8817e4Smiod /* We use the native name field to point to the cached field. */
43753d8817e4Smiod src->u.syment._n._n_n._n_zeroes = (long) dst;
43763d8817e4Smiod dst->symbol.section = coff_section_from_bfd_index (abfd,
43773d8817e4Smiod src->u.syment.n_scnum);
43783d8817e4Smiod dst->symbol.flags = 0;
43793d8817e4Smiod dst->done_lineno = FALSE;
43803d8817e4Smiod
43813d8817e4Smiod switch (src->u.syment.n_sclass)
43823d8817e4Smiod {
43833d8817e4Smiod #ifdef I960
43843d8817e4Smiod case C_LEAFEXT:
43853d8817e4Smiod /* Fall through to next case. */
43863d8817e4Smiod #endif
43873d8817e4Smiod
43883d8817e4Smiod case C_EXT:
43893d8817e4Smiod case C_WEAKEXT:
43903d8817e4Smiod #if defined ARM
43913d8817e4Smiod case C_THUMBEXT:
43923d8817e4Smiod case C_THUMBEXTFUNC:
43933d8817e4Smiod #endif
43943d8817e4Smiod #ifdef RS6000COFF_C
43953d8817e4Smiod case C_HIDEXT:
43963d8817e4Smiod #endif
43973d8817e4Smiod #ifdef C_SYSTEM
43983d8817e4Smiod case C_SYSTEM: /* System Wide variable. */
43993d8817e4Smiod #endif
44003d8817e4Smiod #ifdef COFF_WITH_PE
44013d8817e4Smiod /* In PE, 0x68 (104) denotes a section symbol. */
44023d8817e4Smiod case C_SECTION:
44033d8817e4Smiod /* In PE, 0x69 (105) denotes a weak external symbol. */
44043d8817e4Smiod case C_NT_WEAK:
44053d8817e4Smiod #endif
44063d8817e4Smiod switch (coff_classify_symbol (abfd, &src->u.syment))
44073d8817e4Smiod {
44083d8817e4Smiod case COFF_SYMBOL_GLOBAL:
44093d8817e4Smiod dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
44103d8817e4Smiod #if defined COFF_WITH_PE
44113d8817e4Smiod /* PE sets the symbol to a value relative to the
44123d8817e4Smiod start of the section. */
44133d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
44143d8817e4Smiod #else
44153d8817e4Smiod dst->symbol.value = (src->u.syment.n_value
44163d8817e4Smiod - dst->symbol.section->vma);
44173d8817e4Smiod #endif
44183d8817e4Smiod if (ISFCN ((src->u.syment.n_type)))
44193d8817e4Smiod /* A function ext does not go at the end of a
44203d8817e4Smiod file. */
44213d8817e4Smiod dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
44223d8817e4Smiod break;
44233d8817e4Smiod
44243d8817e4Smiod case COFF_SYMBOL_COMMON:
44253d8817e4Smiod dst->symbol.section = bfd_com_section_ptr;
44263d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
44273d8817e4Smiod break;
44283d8817e4Smiod
44293d8817e4Smiod case COFF_SYMBOL_UNDEFINED:
44303d8817e4Smiod dst->symbol.section = bfd_und_section_ptr;
44313d8817e4Smiod dst->symbol.value = 0;
44323d8817e4Smiod break;
44333d8817e4Smiod
44343d8817e4Smiod case COFF_SYMBOL_PE_SECTION:
44353d8817e4Smiod dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
44363d8817e4Smiod dst->symbol.value = 0;
44373d8817e4Smiod break;
44383d8817e4Smiod
44393d8817e4Smiod case COFF_SYMBOL_LOCAL:
44403d8817e4Smiod dst->symbol.flags = BSF_LOCAL;
44413d8817e4Smiod #if defined COFF_WITH_PE
44423d8817e4Smiod /* PE sets the symbol to a value relative to the
44433d8817e4Smiod start of the section. */
44443d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
44453d8817e4Smiod #else
44463d8817e4Smiod dst->symbol.value = (src->u.syment.n_value
44473d8817e4Smiod - dst->symbol.section->vma);
44483d8817e4Smiod #endif
44493d8817e4Smiod if (ISFCN ((src->u.syment.n_type)))
44503d8817e4Smiod dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
44513d8817e4Smiod break;
44523d8817e4Smiod }
44533d8817e4Smiod
44543d8817e4Smiod #ifdef RS6000COFF_C
44553d8817e4Smiod /* A symbol with a csect entry should not go at the end. */
44563d8817e4Smiod if (src->u.syment.n_numaux > 0)
44573d8817e4Smiod dst->symbol.flags |= BSF_NOT_AT_END;
44583d8817e4Smiod #endif
44593d8817e4Smiod
44603d8817e4Smiod #ifdef COFF_WITH_PE
44613d8817e4Smiod if (src->u.syment.n_sclass == C_NT_WEAK)
44623d8817e4Smiod dst->symbol.flags |= BSF_WEAK;
44633d8817e4Smiod
44643d8817e4Smiod if (src->u.syment.n_sclass == C_SECTION
44653d8817e4Smiod && src->u.syment.n_scnum > 0)
44663d8817e4Smiod dst->symbol.flags = BSF_LOCAL;
44673d8817e4Smiod #endif
44683d8817e4Smiod if (src->u.syment.n_sclass == C_WEAKEXT)
44693d8817e4Smiod dst->symbol.flags |= BSF_WEAK;
44703d8817e4Smiod
44713d8817e4Smiod break;
44723d8817e4Smiod
44733d8817e4Smiod case C_STAT: /* Static. */
44743d8817e4Smiod #ifdef I960
44753d8817e4Smiod case C_LEAFSTAT: /* Static leaf procedure. */
44763d8817e4Smiod #endif
44773d8817e4Smiod #if defined ARM
44783d8817e4Smiod case C_THUMBSTAT: /* Thumb static. */
44793d8817e4Smiod case C_THUMBLABEL: /* Thumb label. */
44803d8817e4Smiod case C_THUMBSTATFUNC:/* Thumb static function. */
44813d8817e4Smiod #endif
44823d8817e4Smiod case C_LABEL: /* Label. */
44833d8817e4Smiod if (src->u.syment.n_scnum == N_DEBUG)
44843d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
44853d8817e4Smiod else
44863d8817e4Smiod dst->symbol.flags = BSF_LOCAL;
44873d8817e4Smiod
44883d8817e4Smiod /* Base the value as an index from the base of the
44893d8817e4Smiod section, if there is one. */
44903d8817e4Smiod if (dst->symbol.section)
44913d8817e4Smiod {
44923d8817e4Smiod #if defined COFF_WITH_PE
44933d8817e4Smiod /* PE sets the symbol to a value relative to the
44943d8817e4Smiod start of the section. */
44953d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
44963d8817e4Smiod #else
44973d8817e4Smiod dst->symbol.value = (src->u.syment.n_value
44983d8817e4Smiod - dst->symbol.section->vma);
44993d8817e4Smiod #endif
45003d8817e4Smiod }
45013d8817e4Smiod else
45023d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
45033d8817e4Smiod break;
45043d8817e4Smiod
45053d8817e4Smiod case C_MOS: /* Member of structure. */
45063d8817e4Smiod case C_EOS: /* End of structure. */
45073d8817e4Smiod case C_REGPARM: /* Register parameter. */
45083d8817e4Smiod case C_REG: /* register variable. */
45093d8817e4Smiod /* C_AUTOARG conflicts with TI COFF C_UEXT. */
45103d8817e4Smiod #if !defined (TIC80COFF) && !defined (TICOFF)
45113d8817e4Smiod #ifdef C_AUTOARG
45123d8817e4Smiod case C_AUTOARG: /* 960-specific storage class. */
45133d8817e4Smiod #endif
45143d8817e4Smiod #endif
45153d8817e4Smiod case C_TPDEF: /* Type definition. */
45163d8817e4Smiod case C_ARG:
45173d8817e4Smiod case C_AUTO: /* Automatic variable. */
45183d8817e4Smiod case C_FIELD: /* Bit field. */
45193d8817e4Smiod case C_ENTAG: /* Enumeration tag. */
45203d8817e4Smiod case C_MOE: /* Member of enumeration. */
45213d8817e4Smiod case C_MOU: /* Member of union. */
45223d8817e4Smiod case C_UNTAG: /* Union tag. */
45233d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
45243d8817e4Smiod dst->symbol.value = (src->u.syment.n_value);
45253d8817e4Smiod break;
45263d8817e4Smiod
45273d8817e4Smiod case C_FILE: /* File name. */
45283d8817e4Smiod case C_STRTAG: /* Structure tag. */
45293d8817e4Smiod #ifdef RS6000COFF_C
45303d8817e4Smiod case C_GSYM:
45313d8817e4Smiod case C_LSYM:
45323d8817e4Smiod case C_PSYM:
45333d8817e4Smiod case C_RSYM:
45343d8817e4Smiod case C_RPSYM:
45353d8817e4Smiod case C_STSYM:
45363d8817e4Smiod case C_TCSYM:
45373d8817e4Smiod case C_BCOMM:
45383d8817e4Smiod case C_ECOML:
45393d8817e4Smiod case C_ECOMM:
45403d8817e4Smiod case C_DECL:
45413d8817e4Smiod case C_ENTRY:
45423d8817e4Smiod case C_FUN:
45433d8817e4Smiod case C_ESTAT:
45443d8817e4Smiod #endif
45453d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
45463d8817e4Smiod dst->symbol.value = (src->u.syment.n_value);
45473d8817e4Smiod break;
45483d8817e4Smiod
45493d8817e4Smiod #ifdef RS6000COFF_C
45503d8817e4Smiod case C_BINCL: /* Beginning of include file. */
45513d8817e4Smiod case C_EINCL: /* Ending of include file. */
45523d8817e4Smiod /* The value is actually a pointer into the line numbers
45533d8817e4Smiod of the file. We locate the line number entry, and
45543d8817e4Smiod set the section to the section which contains it, and
45553d8817e4Smiod the value to the index in that section. */
45563d8817e4Smiod {
45573d8817e4Smiod asection *sec;
45583d8817e4Smiod
45593d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
45603d8817e4Smiod for (sec = abfd->sections; sec != NULL; sec = sec->next)
45613d8817e4Smiod if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
45623d8817e4Smiod && ((file_ptr) (sec->line_filepos
45633d8817e4Smiod + sec->lineno_count * bfd_coff_linesz (abfd))
45643d8817e4Smiod > (file_ptr) src->u.syment.n_value))
45653d8817e4Smiod break;
45663d8817e4Smiod if (sec == NULL)
45673d8817e4Smiod dst->symbol.value = 0;
45683d8817e4Smiod else
45693d8817e4Smiod {
45703d8817e4Smiod dst->symbol.section = sec;
45713d8817e4Smiod dst->symbol.value = ((src->u.syment.n_value
45723d8817e4Smiod - sec->line_filepos)
45733d8817e4Smiod / bfd_coff_linesz (abfd));
45743d8817e4Smiod src->fix_line = 1;
45753d8817e4Smiod }
45763d8817e4Smiod }
45773d8817e4Smiod break;
45783d8817e4Smiod
45793d8817e4Smiod case C_BSTAT:
45803d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
45813d8817e4Smiod
45823d8817e4Smiod /* The value is actually a symbol index. Save a pointer
45833d8817e4Smiod to the symbol instead of the index. FIXME: This
45843d8817e4Smiod should use a union. */
45853d8817e4Smiod src->u.syment.n_value =
45863d8817e4Smiod (long) (native_symbols + src->u.syment.n_value);
45873d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
45883d8817e4Smiod src->fix_value = 1;
45893d8817e4Smiod break;
45903d8817e4Smiod #endif
45913d8817e4Smiod
45923d8817e4Smiod case C_BLOCK: /* ".bb" or ".eb". */
45933d8817e4Smiod case C_FCN: /* ".bf" or ".ef" (or PE ".lf"). */
45943d8817e4Smiod case C_EFCN: /* Physical end of function. */
45953d8817e4Smiod #if defined COFF_WITH_PE
45963d8817e4Smiod /* PE sets the symbol to a value relative to the start
45973d8817e4Smiod of the section. */
45983d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
45993d8817e4Smiod if (strcmp (dst->symbol.name, ".bf") != 0)
46003d8817e4Smiod {
46013d8817e4Smiod /* PE uses funny values for .ef and .lf; don't
46023d8817e4Smiod relocate them. */
46033d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
46043d8817e4Smiod }
46053d8817e4Smiod else
46063d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
46073d8817e4Smiod #else
46083d8817e4Smiod /* Base the value as an index from the base of the
46093d8817e4Smiod section. */
46103d8817e4Smiod dst->symbol.flags = BSF_LOCAL;
46113d8817e4Smiod dst->symbol.value = (src->u.syment.n_value
46123d8817e4Smiod - dst->symbol.section->vma);
46133d8817e4Smiod #endif
46143d8817e4Smiod break;
46153d8817e4Smiod
46163d8817e4Smiod case C_STATLAB: /* Static load time label. */
46173d8817e4Smiod dst->symbol.value = src->u.syment.n_value;
46183d8817e4Smiod dst->symbol.flags = BSF_GLOBAL;
46193d8817e4Smiod break;
46203d8817e4Smiod
46213d8817e4Smiod case C_NULL:
46223d8817e4Smiod /* PE DLLs sometimes have zeroed out symbols for some
46233d8817e4Smiod reason. Just ignore them without a warning. */
46243d8817e4Smiod if (src->u.syment.n_type == 0
46253d8817e4Smiod && src->u.syment.n_value == 0
46263d8817e4Smiod && src->u.syment.n_scnum == 0)
46273d8817e4Smiod break;
46283d8817e4Smiod /* Fall through. */
46293d8817e4Smiod case C_EXTDEF: /* External definition. */
46303d8817e4Smiod case C_ULABEL: /* Undefined label. */
46313d8817e4Smiod case C_USTATIC: /* Undefined static. */
46323d8817e4Smiod #ifndef COFF_WITH_PE
46333d8817e4Smiod /* C_LINE in regular coff is 0x68. NT has taken over this storage
46343d8817e4Smiod class to represent a section symbol. */
46353d8817e4Smiod case C_LINE: /* line # reformatted as symbol table entry. */
46363d8817e4Smiod /* NT uses 0x67 for a weak symbol, not C_ALIAS. */
46373d8817e4Smiod case C_ALIAS: /* Duplicate tag. */
46383d8817e4Smiod #endif
46393d8817e4Smiod /* New storage classes for TI COFF. */
46403d8817e4Smiod #if defined(TIC80COFF) || defined(TICOFF)
46413d8817e4Smiod case C_UEXT: /* Tentative external definition. */
46423d8817e4Smiod #endif
46433d8817e4Smiod case C_EXTLAB: /* External load time label. */
46443d8817e4Smiod case C_HIDDEN: /* Ext symbol in dmert public lib. */
46453d8817e4Smiod default:
46463d8817e4Smiod (*_bfd_error_handler)
46473d8817e4Smiod (_("%B: Unrecognized storage class %d for %s symbol `%s'"),
46483d8817e4Smiod abfd, src->u.syment.n_sclass,
46493d8817e4Smiod dst->symbol.section->name, dst->symbol.name);
46503d8817e4Smiod dst->symbol.flags = BSF_DEBUGGING;
46513d8817e4Smiod dst->symbol.value = (src->u.syment.n_value);
46523d8817e4Smiod break;
46533d8817e4Smiod }
46543d8817e4Smiod
46553d8817e4Smiod dst->native = src;
46563d8817e4Smiod
46573d8817e4Smiod dst->symbol.udata.i = 0;
46583d8817e4Smiod dst->lineno = NULL;
46593d8817e4Smiod this_index += (src->u.syment.n_numaux) + 1;
46603d8817e4Smiod dst++;
46613d8817e4Smiod number_of_symbols++;
46623d8817e4Smiod }
46633d8817e4Smiod }
46643d8817e4Smiod
46653d8817e4Smiod obj_symbols (abfd) = cached_area;
46663d8817e4Smiod obj_raw_syments (abfd) = native_symbols;
46673d8817e4Smiod
46683d8817e4Smiod bfd_get_symcount (abfd) = number_of_symbols;
46693d8817e4Smiod obj_convert (abfd) = table_ptr;
46703d8817e4Smiod /* Slurp the line tables for each section too. */
46713d8817e4Smiod {
46723d8817e4Smiod asection *p;
46733d8817e4Smiod
46743d8817e4Smiod p = abfd->sections;
46753d8817e4Smiod while (p)
46763d8817e4Smiod {
46773d8817e4Smiod coff_slurp_line_table (abfd, p);
46783d8817e4Smiod p = p->next;
46793d8817e4Smiod }
46803d8817e4Smiod }
46813d8817e4Smiod
46823d8817e4Smiod return TRUE;
46833d8817e4Smiod }
46843d8817e4Smiod
46853d8817e4Smiod /* Classify a COFF symbol. A couple of targets have globally visible
46863d8817e4Smiod symbols which are not class C_EXT, and this handles those. It also
46873d8817e4Smiod recognizes some special PE cases. */
46883d8817e4Smiod
46893d8817e4Smiod static enum coff_symbol_classification
coff_classify_symbol(bfd * abfd,struct internal_syment * syment)46903d8817e4Smiod coff_classify_symbol (bfd *abfd,
46913d8817e4Smiod struct internal_syment *syment)
46923d8817e4Smiod {
46933d8817e4Smiod /* FIXME: This partially duplicates the switch in
46943d8817e4Smiod coff_slurp_symbol_table. */
46953d8817e4Smiod switch (syment->n_sclass)
46963d8817e4Smiod {
46973d8817e4Smiod case C_EXT:
46983d8817e4Smiod case C_WEAKEXT:
46993d8817e4Smiod #ifdef I960
47003d8817e4Smiod case C_LEAFEXT:
47013d8817e4Smiod #endif
47023d8817e4Smiod #ifdef ARM
47033d8817e4Smiod case C_THUMBEXT:
47043d8817e4Smiod case C_THUMBEXTFUNC:
47053d8817e4Smiod #endif
47063d8817e4Smiod #ifdef C_SYSTEM
47073d8817e4Smiod case C_SYSTEM:
47083d8817e4Smiod #endif
47093d8817e4Smiod #ifdef COFF_WITH_PE
47103d8817e4Smiod case C_NT_WEAK:
47113d8817e4Smiod #endif
47123d8817e4Smiod if (syment->n_scnum == 0)
47133d8817e4Smiod {
47143d8817e4Smiod if (syment->n_value == 0)
47153d8817e4Smiod return COFF_SYMBOL_UNDEFINED;
47163d8817e4Smiod else
47173d8817e4Smiod return COFF_SYMBOL_COMMON;
47183d8817e4Smiod }
47193d8817e4Smiod return COFF_SYMBOL_GLOBAL;
47203d8817e4Smiod
47213d8817e4Smiod default:
47223d8817e4Smiod break;
47233d8817e4Smiod }
47243d8817e4Smiod
47253d8817e4Smiod #ifdef COFF_WITH_PE
47263d8817e4Smiod if (syment->n_sclass == C_STAT)
47273d8817e4Smiod {
47283d8817e4Smiod if (syment->n_scnum == 0)
47293d8817e4Smiod /* The Microsoft compiler sometimes generates these if a
47303d8817e4Smiod small static function is inlined every time it is used.
47313d8817e4Smiod The function is discarded, but the symbol table entry
47323d8817e4Smiod remains. */
47333d8817e4Smiod return COFF_SYMBOL_LOCAL;
47343d8817e4Smiod
47353d8817e4Smiod #ifdef STRICT_PE_FORMAT
47363d8817e4Smiod /* This is correct for Microsoft generated objects, but it
47373d8817e4Smiod breaks gas generated objects. */
47383d8817e4Smiod if (syment->n_value == 0)
47393d8817e4Smiod {
47403d8817e4Smiod asection *sec;
47413d8817e4Smiod char buf[SYMNMLEN + 1];
47423d8817e4Smiod
47433d8817e4Smiod sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
47443d8817e4Smiod if (sec != NULL
47453d8817e4Smiod && (strcmp (bfd_get_section_name (abfd, sec),
47463d8817e4Smiod _bfd_coff_internal_syment_name (abfd, syment, buf))
47473d8817e4Smiod == 0))
47483d8817e4Smiod return COFF_SYMBOL_PE_SECTION;
47493d8817e4Smiod }
47503d8817e4Smiod #endif
47513d8817e4Smiod
47523d8817e4Smiod return COFF_SYMBOL_LOCAL;
47533d8817e4Smiod }
47543d8817e4Smiod
47553d8817e4Smiod if (syment->n_sclass == C_SECTION)
47563d8817e4Smiod {
47573d8817e4Smiod /* In some cases in a DLL generated by the Microsoft linker, the
47583d8817e4Smiod n_value field will contain garbage. FIXME: This should
47593d8817e4Smiod probably be handled by the swapping function instead. */
47603d8817e4Smiod syment->n_value = 0;
47613d8817e4Smiod if (syment->n_scnum == 0)
47623d8817e4Smiod return COFF_SYMBOL_UNDEFINED;
47633d8817e4Smiod return COFF_SYMBOL_PE_SECTION;
47643d8817e4Smiod }
47653d8817e4Smiod #endif /* COFF_WITH_PE */
47663d8817e4Smiod
47673d8817e4Smiod /* If it is not a global symbol, we presume it is a local symbol. */
47683d8817e4Smiod if (syment->n_scnum == 0)
47693d8817e4Smiod {
47703d8817e4Smiod char buf[SYMNMLEN + 1];
47713d8817e4Smiod
47723d8817e4Smiod (*_bfd_error_handler)
47733d8817e4Smiod (_("warning: %B: local symbol `%s' has no section"),
47743d8817e4Smiod abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
47753d8817e4Smiod }
47763d8817e4Smiod
47773d8817e4Smiod return COFF_SYMBOL_LOCAL;
47783d8817e4Smiod }
47793d8817e4Smiod
47803d8817e4Smiod /*
47813d8817e4Smiod SUBSUBSECTION
47823d8817e4Smiod Reading relocations
47833d8817e4Smiod
47843d8817e4Smiod Coff relocations are easily transformed into the internal BFD form
47853d8817e4Smiod (@code{arelent}).
47863d8817e4Smiod
47873d8817e4Smiod Reading a coff relocation table is done in the following stages:
47883d8817e4Smiod
47893d8817e4Smiod o Read the entire coff relocation table into memory.
47903d8817e4Smiod
47913d8817e4Smiod o Process each relocation in turn; first swap it from the
47923d8817e4Smiod external to the internal form.
47933d8817e4Smiod
47943d8817e4Smiod o Turn the symbol referenced in the relocation's symbol index
47953d8817e4Smiod into a pointer into the canonical symbol table.
47963d8817e4Smiod This table is the same as the one returned by a call to
47973d8817e4Smiod @code{bfd_canonicalize_symtab}. The back end will call that
47983d8817e4Smiod routine and save the result if a canonicalization hasn't been done.
47993d8817e4Smiod
48003d8817e4Smiod o The reloc index is turned into a pointer to a howto
48013d8817e4Smiod structure, in a back end specific way. For instance, the 386
48023d8817e4Smiod and 960 use the @code{r_type} to directly produce an index
48033d8817e4Smiod into a howto table vector; the 88k subtracts a number from the
48043d8817e4Smiod @code{r_type} field and creates an addend field.
48053d8817e4Smiod */
48063d8817e4Smiod
48073d8817e4Smiod #ifndef CALC_ADDEND
48083d8817e4Smiod #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
48093d8817e4Smiod { \
48103d8817e4Smiod coff_symbol_type *coffsym = NULL; \
48113d8817e4Smiod \
48123d8817e4Smiod if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
48133d8817e4Smiod coffsym = (obj_symbols (abfd) \
48143d8817e4Smiod + (cache_ptr->sym_ptr_ptr - symbols)); \
48153d8817e4Smiod else if (ptr) \
48163d8817e4Smiod coffsym = coff_symbol_from (abfd, ptr); \
48173d8817e4Smiod if (coffsym != NULL \
48183d8817e4Smiod && coffsym->native->u.syment.n_scnum == 0) \
48193d8817e4Smiod cache_ptr->addend = 0; \
48203d8817e4Smiod else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
48213d8817e4Smiod && ptr->section != NULL) \
48223d8817e4Smiod cache_ptr->addend = - (ptr->section->vma + ptr->value); \
48233d8817e4Smiod else \
48243d8817e4Smiod cache_ptr->addend = 0; \
48253d8817e4Smiod }
48263d8817e4Smiod #endif
48273d8817e4Smiod
48283d8817e4Smiod static bfd_boolean
coff_slurp_reloc_table(bfd * abfd,sec_ptr asect,asymbol ** symbols)48293d8817e4Smiod coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
48303d8817e4Smiod {
48313d8817e4Smiod RELOC *native_relocs;
48323d8817e4Smiod arelent *reloc_cache;
48333d8817e4Smiod arelent *cache_ptr;
48343d8817e4Smiod unsigned int idx;
48353d8817e4Smiod bfd_size_type amt;
48363d8817e4Smiod
48373d8817e4Smiod if (asect->relocation)
48383d8817e4Smiod return TRUE;
48393d8817e4Smiod if (asect->reloc_count == 0)
48403d8817e4Smiod return TRUE;
48413d8817e4Smiod if (asect->flags & SEC_CONSTRUCTOR)
48423d8817e4Smiod return TRUE;
48433d8817e4Smiod if (!coff_slurp_symbol_table (abfd))
48443d8817e4Smiod return FALSE;
48453d8817e4Smiod
48463d8817e4Smiod amt = (bfd_size_type) bfd_coff_relsz (abfd) * asect->reloc_count;
48473d8817e4Smiod native_relocs = (RELOC *) buy_and_read (abfd, asect->rel_filepos, amt);
48483d8817e4Smiod amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
48493d8817e4Smiod reloc_cache = bfd_alloc (abfd, amt);
48503d8817e4Smiod
48513d8817e4Smiod if (reloc_cache == NULL || native_relocs == NULL)
48523d8817e4Smiod return FALSE;
48533d8817e4Smiod
48543d8817e4Smiod for (idx = 0; idx < asect->reloc_count; idx++)
48553d8817e4Smiod {
48563d8817e4Smiod struct internal_reloc dst;
48573d8817e4Smiod struct external_reloc *src;
48583d8817e4Smiod #ifndef RELOC_PROCESSING
48593d8817e4Smiod asymbol *ptr;
48603d8817e4Smiod #endif
48613d8817e4Smiod
48623d8817e4Smiod cache_ptr = reloc_cache + idx;
48633d8817e4Smiod src = native_relocs + idx;
48643d8817e4Smiod
48653d8817e4Smiod coff_swap_reloc_in (abfd, src, &dst);
48663d8817e4Smiod
48673d8817e4Smiod #ifdef RELOC_PROCESSING
48683d8817e4Smiod RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
48693d8817e4Smiod #else
48703d8817e4Smiod cache_ptr->address = dst.r_vaddr;
48713d8817e4Smiod
48723d8817e4Smiod if (dst.r_symndx != -1)
48733d8817e4Smiod {
48743d8817e4Smiod if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
48753d8817e4Smiod {
48763d8817e4Smiod (*_bfd_error_handler)
48773d8817e4Smiod (_("%B: warning: illegal symbol index %ld in relocs"),
48783d8817e4Smiod abfd, dst.r_symndx);
48793d8817e4Smiod cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
48803d8817e4Smiod ptr = NULL;
48813d8817e4Smiod }
48823d8817e4Smiod else
48833d8817e4Smiod {
48843d8817e4Smiod cache_ptr->sym_ptr_ptr = (symbols
48853d8817e4Smiod + obj_convert (abfd)[dst.r_symndx]);
48863d8817e4Smiod ptr = *(cache_ptr->sym_ptr_ptr);
48873d8817e4Smiod }
48883d8817e4Smiod }
48893d8817e4Smiod else
48903d8817e4Smiod {
48913d8817e4Smiod cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
48923d8817e4Smiod ptr = NULL;
48933d8817e4Smiod }
48943d8817e4Smiod
48953d8817e4Smiod /* The symbols definitions that we have read in have been
48963d8817e4Smiod relocated as if their sections started at 0. But the offsets
48973d8817e4Smiod refering to the symbols in the raw data have not been
48983d8817e4Smiod modified, so we have to have a negative addend to compensate.
48993d8817e4Smiod
49003d8817e4Smiod Note that symbols which used to be common must be left alone. */
49013d8817e4Smiod
49023d8817e4Smiod /* Calculate any reloc addend by looking at the symbol. */
49033d8817e4Smiod CALC_ADDEND (abfd, ptr, dst, cache_ptr);
49043d8817e4Smiod
49053d8817e4Smiod cache_ptr->address -= asect->vma;
49063d8817e4Smiod /* !! cache_ptr->section = NULL;*/
49073d8817e4Smiod
49083d8817e4Smiod /* Fill in the cache_ptr->howto field from dst.r_type. */
49093d8817e4Smiod RTYPE2HOWTO (cache_ptr, &dst);
49103d8817e4Smiod #endif /* RELOC_PROCESSING */
49113d8817e4Smiod
49123d8817e4Smiod if (cache_ptr->howto == NULL)
49133d8817e4Smiod {
49143d8817e4Smiod (*_bfd_error_handler)
49153d8817e4Smiod (_("%B: illegal relocation type %d at address 0x%lx"),
49163d8817e4Smiod abfd, dst.r_type, (long) dst.r_vaddr);
49173d8817e4Smiod bfd_set_error (bfd_error_bad_value);
49183d8817e4Smiod return FALSE;
49193d8817e4Smiod }
49203d8817e4Smiod }
49213d8817e4Smiod
49223d8817e4Smiod asect->relocation = reloc_cache;
49233d8817e4Smiod return TRUE;
49243d8817e4Smiod }
49253d8817e4Smiod
49263d8817e4Smiod #ifndef coff_rtype_to_howto
49273d8817e4Smiod #ifdef RTYPE2HOWTO
49283d8817e4Smiod
49293d8817e4Smiod /* Get the howto structure for a reloc. This is only used if the file
49303d8817e4Smiod including this one defines coff_relocate_section to be
49313d8817e4Smiod _bfd_coff_generic_relocate_section, so it is OK if it does not
49323d8817e4Smiod always work. It is the responsibility of the including file to
49333d8817e4Smiod make sure it is reasonable if it is needed. */
49343d8817e4Smiod
49353d8817e4Smiod static reloc_howto_type *
coff_rtype_to_howto(bfd * abfd ATTRIBUTE_UNUSED,asection * sec ATTRIBUTE_UNUSED,struct internal_reloc * rel,struct coff_link_hash_entry * h ATTRIBUTE_UNUSED,struct internal_syment * sym ATTRIBUTE_UNUSED,bfd_vma * addendp ATTRIBUTE_UNUSED)49363d8817e4Smiod coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
49373d8817e4Smiod asection *sec ATTRIBUTE_UNUSED,
49383d8817e4Smiod struct internal_reloc *rel,
49393d8817e4Smiod struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
49403d8817e4Smiod struct internal_syment *sym ATTRIBUTE_UNUSED,
49413d8817e4Smiod bfd_vma *addendp ATTRIBUTE_UNUSED)
49423d8817e4Smiod {
49433d8817e4Smiod arelent genrel;
49443d8817e4Smiod
49453d8817e4Smiod RTYPE2HOWTO (&genrel, rel);
49463d8817e4Smiod return genrel.howto;
49473d8817e4Smiod }
49483d8817e4Smiod
49493d8817e4Smiod #else /* ! defined (RTYPE2HOWTO) */
49503d8817e4Smiod
49513d8817e4Smiod #define coff_rtype_to_howto NULL
49523d8817e4Smiod
49533d8817e4Smiod #endif /* ! defined (RTYPE2HOWTO) */
49543d8817e4Smiod #endif /* ! defined (coff_rtype_to_howto) */
49553d8817e4Smiod
49563d8817e4Smiod /* This is stupid. This function should be a boolean predicate. */
49573d8817e4Smiod
49583d8817e4Smiod static long
coff_canonicalize_reloc(bfd * abfd,sec_ptr section,arelent ** relptr,asymbol ** symbols)49593d8817e4Smiod coff_canonicalize_reloc (bfd * abfd,
49603d8817e4Smiod sec_ptr section,
49613d8817e4Smiod arelent ** relptr,
49623d8817e4Smiod asymbol ** symbols)
49633d8817e4Smiod {
49643d8817e4Smiod arelent *tblptr = section->relocation;
49653d8817e4Smiod unsigned int count = 0;
49663d8817e4Smiod
49673d8817e4Smiod if (section->flags & SEC_CONSTRUCTOR)
49683d8817e4Smiod {
49693d8817e4Smiod /* This section has relocs made up by us, they are not in the
49703d8817e4Smiod file, so take them out of their chain and place them into
49713d8817e4Smiod the data area provided. */
49723d8817e4Smiod arelent_chain *chain = section->constructor_chain;
49733d8817e4Smiod
49743d8817e4Smiod for (count = 0; count < section->reloc_count; count++)
49753d8817e4Smiod {
49763d8817e4Smiod *relptr++ = &chain->relent;
49773d8817e4Smiod chain = chain->next;
49783d8817e4Smiod }
49793d8817e4Smiod }
49803d8817e4Smiod else
49813d8817e4Smiod {
49823d8817e4Smiod if (! coff_slurp_reloc_table (abfd, section, symbols))
49833d8817e4Smiod return -1;
49843d8817e4Smiod
49853d8817e4Smiod tblptr = section->relocation;
49863d8817e4Smiod
49873d8817e4Smiod for (; count++ < section->reloc_count;)
49883d8817e4Smiod *relptr++ = tblptr++;
49893d8817e4Smiod }
49903d8817e4Smiod *relptr = 0;
49913d8817e4Smiod return section->reloc_count;
49923d8817e4Smiod }
49933d8817e4Smiod
49943d8817e4Smiod #ifndef coff_reloc16_estimate
49953d8817e4Smiod #define coff_reloc16_estimate dummy_reloc16_estimate
49963d8817e4Smiod
49973d8817e4Smiod static int
dummy_reloc16_estimate(bfd * abfd ATTRIBUTE_UNUSED,asection * input_section ATTRIBUTE_UNUSED,arelent * reloc ATTRIBUTE_UNUSED,unsigned int shrink ATTRIBUTE_UNUSED,struct bfd_link_info * link_info ATTRIBUTE_UNUSED)49983d8817e4Smiod dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED,
49993d8817e4Smiod asection *input_section ATTRIBUTE_UNUSED,
50003d8817e4Smiod arelent *reloc ATTRIBUTE_UNUSED,
50013d8817e4Smiod unsigned int shrink ATTRIBUTE_UNUSED,
50023d8817e4Smiod struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
50033d8817e4Smiod {
50043d8817e4Smiod abort ();
50053d8817e4Smiod return 0;
50063d8817e4Smiod }
50073d8817e4Smiod
50083d8817e4Smiod #endif
50093d8817e4Smiod
50103d8817e4Smiod #ifndef coff_reloc16_extra_cases
50113d8817e4Smiod
50123d8817e4Smiod #define coff_reloc16_extra_cases dummy_reloc16_extra_cases
50133d8817e4Smiod
50143d8817e4Smiod /* This works even if abort is not declared in any header file. */
50153d8817e4Smiod
50163d8817e4Smiod static void
dummy_reloc16_extra_cases(bfd * abfd ATTRIBUTE_UNUSED,struct bfd_link_info * link_info ATTRIBUTE_UNUSED,struct bfd_link_order * link_order ATTRIBUTE_UNUSED,arelent * reloc ATTRIBUTE_UNUSED,bfd_byte * data ATTRIBUTE_UNUSED,unsigned int * src_ptr ATTRIBUTE_UNUSED,unsigned int * dst_ptr ATTRIBUTE_UNUSED)50173d8817e4Smiod dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
50183d8817e4Smiod struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
50193d8817e4Smiod struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
50203d8817e4Smiod arelent *reloc ATTRIBUTE_UNUSED,
50213d8817e4Smiod bfd_byte *data ATTRIBUTE_UNUSED,
50223d8817e4Smiod unsigned int *src_ptr ATTRIBUTE_UNUSED,
50233d8817e4Smiod unsigned int *dst_ptr ATTRIBUTE_UNUSED)
50243d8817e4Smiod {
50253d8817e4Smiod abort ();
50263d8817e4Smiod }
50273d8817e4Smiod #endif
50283d8817e4Smiod
50293d8817e4Smiod #ifndef coff_bfd_link_hash_table_free
50303d8817e4Smiod #define coff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
50313d8817e4Smiod #endif
50323d8817e4Smiod
50333d8817e4Smiod /* If coff_relocate_section is defined, we can use the optimized COFF
50343d8817e4Smiod backend linker. Otherwise we must continue to use the old linker. */
50353d8817e4Smiod
50363d8817e4Smiod #ifdef coff_relocate_section
50373d8817e4Smiod
50383d8817e4Smiod #ifndef coff_bfd_link_hash_table_create
50393d8817e4Smiod #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
50403d8817e4Smiod #endif
50413d8817e4Smiod #ifndef coff_bfd_link_add_symbols
50423d8817e4Smiod #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
50433d8817e4Smiod #endif
50443d8817e4Smiod #ifndef coff_bfd_final_link
50453d8817e4Smiod #define coff_bfd_final_link _bfd_coff_final_link
50463d8817e4Smiod #endif
50473d8817e4Smiod
50483d8817e4Smiod #else /* ! defined (coff_relocate_section) */
50493d8817e4Smiod
50503d8817e4Smiod #define coff_relocate_section NULL
50513d8817e4Smiod #ifndef coff_bfd_link_hash_table_create
50523d8817e4Smiod #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
50533d8817e4Smiod #endif
50543d8817e4Smiod #ifndef coff_bfd_link_add_symbols
50553d8817e4Smiod #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
50563d8817e4Smiod #endif
50573d8817e4Smiod #define coff_bfd_final_link _bfd_generic_final_link
50583d8817e4Smiod
50593d8817e4Smiod #endif /* ! defined (coff_relocate_section) */
50603d8817e4Smiod
50613d8817e4Smiod #define coff_bfd_link_just_syms _bfd_generic_link_just_syms
50623d8817e4Smiod #define coff_bfd_link_split_section _bfd_generic_link_split_section
50633d8817e4Smiod
50643d8817e4Smiod #ifndef coff_start_final_link
50653d8817e4Smiod #define coff_start_final_link NULL
50663d8817e4Smiod #endif
50673d8817e4Smiod
50683d8817e4Smiod #ifndef coff_adjust_symndx
50693d8817e4Smiod #define coff_adjust_symndx NULL
50703d8817e4Smiod #endif
50713d8817e4Smiod
50723d8817e4Smiod #ifndef coff_link_add_one_symbol
50733d8817e4Smiod #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
50743d8817e4Smiod #endif
50753d8817e4Smiod
50763d8817e4Smiod #ifndef coff_link_output_has_begun
50773d8817e4Smiod
50783d8817e4Smiod static bfd_boolean
coff_link_output_has_begun(bfd * abfd,struct coff_final_link_info * info ATTRIBUTE_UNUSED)50793d8817e4Smiod coff_link_output_has_begun (bfd * abfd,
50803d8817e4Smiod struct coff_final_link_info * info ATTRIBUTE_UNUSED)
50813d8817e4Smiod {
50823d8817e4Smiod return abfd->output_has_begun;
50833d8817e4Smiod }
50843d8817e4Smiod #endif
50853d8817e4Smiod
50863d8817e4Smiod #ifndef coff_final_link_postscript
50873d8817e4Smiod
50883d8817e4Smiod static bfd_boolean
coff_final_link_postscript(bfd * abfd ATTRIBUTE_UNUSED,struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)50893d8817e4Smiod coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
50903d8817e4Smiod struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)
50913d8817e4Smiod {
50923d8817e4Smiod return TRUE;
50933d8817e4Smiod }
50943d8817e4Smiod #endif
50953d8817e4Smiod
50963d8817e4Smiod #ifndef coff_SWAP_aux_in
50973d8817e4Smiod #define coff_SWAP_aux_in coff_swap_aux_in
50983d8817e4Smiod #endif
50993d8817e4Smiod #ifndef coff_SWAP_sym_in
51003d8817e4Smiod #define coff_SWAP_sym_in coff_swap_sym_in
51013d8817e4Smiod #endif
51023d8817e4Smiod #ifndef coff_SWAP_lineno_in
51033d8817e4Smiod #define coff_SWAP_lineno_in coff_swap_lineno_in
51043d8817e4Smiod #endif
51053d8817e4Smiod #ifndef coff_SWAP_aux_out
51063d8817e4Smiod #define coff_SWAP_aux_out coff_swap_aux_out
51073d8817e4Smiod #endif
51083d8817e4Smiod #ifndef coff_SWAP_sym_out
51093d8817e4Smiod #define coff_SWAP_sym_out coff_swap_sym_out
51103d8817e4Smiod #endif
51113d8817e4Smiod #ifndef coff_SWAP_lineno_out
51123d8817e4Smiod #define coff_SWAP_lineno_out coff_swap_lineno_out
51133d8817e4Smiod #endif
51143d8817e4Smiod #ifndef coff_SWAP_reloc_out
51153d8817e4Smiod #define coff_SWAP_reloc_out coff_swap_reloc_out
51163d8817e4Smiod #endif
51173d8817e4Smiod #ifndef coff_SWAP_filehdr_out
51183d8817e4Smiod #define coff_SWAP_filehdr_out coff_swap_filehdr_out
51193d8817e4Smiod #endif
51203d8817e4Smiod #ifndef coff_SWAP_aouthdr_out
51213d8817e4Smiod #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
51223d8817e4Smiod #endif
51233d8817e4Smiod #ifndef coff_SWAP_scnhdr_out
51243d8817e4Smiod #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
51253d8817e4Smiod #endif
51263d8817e4Smiod #ifndef coff_SWAP_reloc_in
51273d8817e4Smiod #define coff_SWAP_reloc_in coff_swap_reloc_in
51283d8817e4Smiod #endif
51293d8817e4Smiod #ifndef coff_SWAP_filehdr_in
51303d8817e4Smiod #define coff_SWAP_filehdr_in coff_swap_filehdr_in
51313d8817e4Smiod #endif
51323d8817e4Smiod #ifndef coff_SWAP_aouthdr_in
51333d8817e4Smiod #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
51343d8817e4Smiod #endif
51353d8817e4Smiod #ifndef coff_SWAP_scnhdr_in
51363d8817e4Smiod #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
51373d8817e4Smiod #endif
51383d8817e4Smiod
51393d8817e4Smiod static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
51403d8817e4Smiod {
51413d8817e4Smiod coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
51423d8817e4Smiod coff_SWAP_aux_out, coff_SWAP_sym_out,
51433d8817e4Smiod coff_SWAP_lineno_out, coff_SWAP_reloc_out,
51443d8817e4Smiod coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
51453d8817e4Smiod coff_SWAP_scnhdr_out,
51463d8817e4Smiod FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
51473d8817e4Smiod #ifdef COFF_LONG_FILENAMES
51483d8817e4Smiod TRUE,
51493d8817e4Smiod #else
51503d8817e4Smiod FALSE,
51513d8817e4Smiod #endif
51523d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
51533d8817e4Smiod TRUE,
51543d8817e4Smiod #else
51553d8817e4Smiod FALSE,
51563d8817e4Smiod #endif
51573d8817e4Smiod COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
51583d8817e4Smiod #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
51593d8817e4Smiod TRUE,
51603d8817e4Smiod #else
51613d8817e4Smiod FALSE,
51623d8817e4Smiod #endif
51633d8817e4Smiod #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
51643d8817e4Smiod 4,
51653d8817e4Smiod #else
51663d8817e4Smiod 2,
51673d8817e4Smiod #endif
51683d8817e4Smiod coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
51693d8817e4Smiod coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
51703d8817e4Smiod coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
51713d8817e4Smiod coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
51723d8817e4Smiod coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
51733d8817e4Smiod coff_classify_symbol, coff_compute_section_file_positions,
51743d8817e4Smiod coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
51753d8817e4Smiod coff_adjust_symndx, coff_link_add_one_symbol,
51763d8817e4Smiod coff_link_output_has_begun, coff_final_link_postscript
51773d8817e4Smiod };
51783d8817e4Smiod
51793d8817e4Smiod #ifdef TICOFF
51803d8817e4Smiod /* COFF0 differs in file/section header size and relocation entry size. */
51813d8817e4Smiod
51823d8817e4Smiod static const bfd_coff_backend_data ticoff0_swap_table =
51833d8817e4Smiod {
51843d8817e4Smiod coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
51853d8817e4Smiod coff_SWAP_aux_out, coff_SWAP_sym_out,
51863d8817e4Smiod coff_SWAP_lineno_out, coff_SWAP_reloc_out,
51873d8817e4Smiod coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
51883d8817e4Smiod coff_SWAP_scnhdr_out,
51893d8817e4Smiod FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
51903d8817e4Smiod #ifdef COFF_LONG_FILENAMES
51913d8817e4Smiod TRUE,
51923d8817e4Smiod #else
51933d8817e4Smiod FALSE,
51943d8817e4Smiod #endif
51953d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
51963d8817e4Smiod TRUE,
51973d8817e4Smiod #else
51983d8817e4Smiod FALSE,
51993d8817e4Smiod #endif
52003d8817e4Smiod COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
52013d8817e4Smiod #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
52023d8817e4Smiod TRUE,
52033d8817e4Smiod #else
52043d8817e4Smiod FALSE,
52053d8817e4Smiod #endif
52063d8817e4Smiod #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
52073d8817e4Smiod 4,
52083d8817e4Smiod #else
52093d8817e4Smiod 2,
52103d8817e4Smiod #endif
52113d8817e4Smiod coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
52123d8817e4Smiod coff_SWAP_reloc_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
52133d8817e4Smiod coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
52143d8817e4Smiod coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
52153d8817e4Smiod coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
52163d8817e4Smiod coff_classify_symbol, coff_compute_section_file_positions,
52173d8817e4Smiod coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
52183d8817e4Smiod coff_adjust_symndx, coff_link_add_one_symbol,
52193d8817e4Smiod coff_link_output_has_begun, coff_final_link_postscript
52203d8817e4Smiod };
52213d8817e4Smiod #endif
52223d8817e4Smiod
52233d8817e4Smiod #ifdef TICOFF
52243d8817e4Smiod /* COFF1 differs in section header size. */
52253d8817e4Smiod
52263d8817e4Smiod static const bfd_coff_backend_data ticoff1_swap_table =
52273d8817e4Smiod {
52283d8817e4Smiod coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
52293d8817e4Smiod coff_SWAP_aux_out, coff_SWAP_sym_out,
52303d8817e4Smiod coff_SWAP_lineno_out, coff_SWAP_reloc_out,
52313d8817e4Smiod coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
52323d8817e4Smiod coff_SWAP_scnhdr_out,
52333d8817e4Smiod FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
52343d8817e4Smiod #ifdef COFF_LONG_FILENAMES
52353d8817e4Smiod TRUE,
52363d8817e4Smiod #else
52373d8817e4Smiod FALSE,
52383d8817e4Smiod #endif
52393d8817e4Smiod #ifdef COFF_LONG_SECTION_NAMES
52403d8817e4Smiod TRUE,
52413d8817e4Smiod #else
52423d8817e4Smiod FALSE,
52433d8817e4Smiod #endif
52443d8817e4Smiod COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
52453d8817e4Smiod #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
52463d8817e4Smiod TRUE,
52473d8817e4Smiod #else
52483d8817e4Smiod FALSE,
52493d8817e4Smiod #endif
52503d8817e4Smiod #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
52513d8817e4Smiod 4,
52523d8817e4Smiod #else
52533d8817e4Smiod 2,
52543d8817e4Smiod #endif
52553d8817e4Smiod coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
52563d8817e4Smiod coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
52573d8817e4Smiod coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
52583d8817e4Smiod coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
52593d8817e4Smiod coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
52603d8817e4Smiod coff_classify_symbol, coff_compute_section_file_positions,
52613d8817e4Smiod coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
52623d8817e4Smiod coff_adjust_symndx, coff_link_add_one_symbol,
52633d8817e4Smiod coff_link_output_has_begun, coff_final_link_postscript
52643d8817e4Smiod };
52653d8817e4Smiod #endif
52663d8817e4Smiod
52673d8817e4Smiod #ifndef coff_close_and_cleanup
52683d8817e4Smiod #define coff_close_and_cleanup _bfd_generic_close_and_cleanup
52693d8817e4Smiod #endif
52703d8817e4Smiod
52713d8817e4Smiod #ifndef coff_bfd_free_cached_info
52723d8817e4Smiod #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
52733d8817e4Smiod #endif
52743d8817e4Smiod
52753d8817e4Smiod #ifndef coff_get_section_contents
52763d8817e4Smiod #define coff_get_section_contents _bfd_generic_get_section_contents
52773d8817e4Smiod #endif
52783d8817e4Smiod
52793d8817e4Smiod #ifndef coff_bfd_copy_private_symbol_data
52803d8817e4Smiod #define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
52813d8817e4Smiod #endif
52823d8817e4Smiod
52833d8817e4Smiod #ifndef coff_bfd_copy_private_header_data
52843d8817e4Smiod #define coff_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
52853d8817e4Smiod #endif
52863d8817e4Smiod
52873d8817e4Smiod #ifndef coff_bfd_copy_private_section_data
52883d8817e4Smiod #define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
52893d8817e4Smiod #endif
52903d8817e4Smiod
52913d8817e4Smiod #ifndef coff_bfd_copy_private_bfd_data
52923d8817e4Smiod #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
52933d8817e4Smiod #endif
52943d8817e4Smiod
52953d8817e4Smiod #ifndef coff_bfd_merge_private_bfd_data
52963d8817e4Smiod #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
52973d8817e4Smiod #endif
52983d8817e4Smiod
52993d8817e4Smiod #ifndef coff_bfd_set_private_flags
53003d8817e4Smiod #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
53013d8817e4Smiod #endif
53023d8817e4Smiod
53033d8817e4Smiod #ifndef coff_bfd_print_private_bfd_data
53043d8817e4Smiod #define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
53053d8817e4Smiod #endif
53063d8817e4Smiod
53073d8817e4Smiod #ifndef coff_bfd_is_local_label_name
53083d8817e4Smiod #define coff_bfd_is_local_label_name _bfd_coff_is_local_label_name
53093d8817e4Smiod #endif
53103d8817e4Smiod
53113d8817e4Smiod #ifndef coff_bfd_is_target_special_symbol
53123d8817e4Smiod #define coff_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
53133d8817e4Smiod #endif
53143d8817e4Smiod
53153d8817e4Smiod #ifndef coff_read_minisymbols
53163d8817e4Smiod #define coff_read_minisymbols _bfd_generic_read_minisymbols
53173d8817e4Smiod #endif
53183d8817e4Smiod
53193d8817e4Smiod #ifndef coff_minisymbol_to_symbol
53203d8817e4Smiod #define coff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
53213d8817e4Smiod #endif
53223d8817e4Smiod
53233d8817e4Smiod /* The reloc lookup routine must be supplied by each individual COFF
53243d8817e4Smiod backend. */
53253d8817e4Smiod #ifndef coff_bfd_reloc_type_lookup
53263d8817e4Smiod #define coff_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
53273d8817e4Smiod #endif
53283d8817e4Smiod
53293d8817e4Smiod #ifndef coff_bfd_get_relocated_section_contents
53303d8817e4Smiod #define coff_bfd_get_relocated_section_contents \
53313d8817e4Smiod bfd_generic_get_relocated_section_contents
53323d8817e4Smiod #endif
53333d8817e4Smiod
53343d8817e4Smiod #ifndef coff_bfd_relax_section
53353d8817e4Smiod #define coff_bfd_relax_section bfd_generic_relax_section
53363d8817e4Smiod #endif
53373d8817e4Smiod
53383d8817e4Smiod #ifndef coff_bfd_gc_sections
53393d8817e4Smiod #define coff_bfd_gc_sections bfd_generic_gc_sections
53403d8817e4Smiod #endif
53413d8817e4Smiod
53423d8817e4Smiod #ifndef coff_bfd_merge_sections
53433d8817e4Smiod #define coff_bfd_merge_sections bfd_generic_merge_sections
53443d8817e4Smiod #endif
53453d8817e4Smiod
53463d8817e4Smiod #ifndef coff_bfd_is_group_section
53473d8817e4Smiod #define coff_bfd_is_group_section bfd_generic_is_group_section
53483d8817e4Smiod #endif
53493d8817e4Smiod
53503d8817e4Smiod #ifndef coff_bfd_discard_group
53513d8817e4Smiod #define coff_bfd_discard_group bfd_generic_discard_group
53523d8817e4Smiod #endif
53533d8817e4Smiod
53543d8817e4Smiod #ifndef coff_section_already_linked
53553d8817e4Smiod #define coff_section_already_linked \
53563d8817e4Smiod _bfd_generic_section_already_linked
53573d8817e4Smiod #endif
53583d8817e4Smiod
53593d8817e4Smiod #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
53603d8817e4Smiod const bfd_target VAR = \
53613d8817e4Smiod { \
53623d8817e4Smiod NAME , \
53633d8817e4Smiod bfd_target_coff_flavour, \
53643d8817e4Smiod BFD_ENDIAN_BIG, /* Data byte order is big. */ \
53653d8817e4Smiod BFD_ENDIAN_BIG, /* Header byte order is big. */ \
53663d8817e4Smiod /* object flags */ \
53673d8817e4Smiod (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
53683d8817e4Smiod HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
53693d8817e4Smiod /* section flags */ \
53703d8817e4Smiod (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
53713d8817e4Smiod UNDER, /* Leading symbol underscore. */ \
53723d8817e4Smiod '/', /* AR_pad_char. */ \
53733d8817e4Smiod 15, /* AR_max_namelen. */ \
53743d8817e4Smiod \
53753d8817e4Smiod /* Data conversion functions. */ \
53763d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
53773d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
53783d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
53793d8817e4Smiod \
53803d8817e4Smiod /* Header conversion functions. */ \
53813d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
53823d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
53833d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
53843d8817e4Smiod \
53853d8817e4Smiod /* bfd_check_format. */ \
53863d8817e4Smiod { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
53873d8817e4Smiod _bfd_dummy_target }, \
53883d8817e4Smiod /* bfd_set_format. */ \
53893d8817e4Smiod { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
53903d8817e4Smiod /* bfd_write_contents. */ \
53913d8817e4Smiod { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
53923d8817e4Smiod bfd_false }, \
53933d8817e4Smiod \
53943d8817e4Smiod BFD_JUMP_TABLE_GENERIC (coff), \
53953d8817e4Smiod BFD_JUMP_TABLE_COPY (coff), \
53963d8817e4Smiod BFD_JUMP_TABLE_CORE (_bfd_nocore), \
53973d8817e4Smiod BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
53983d8817e4Smiod BFD_JUMP_TABLE_SYMBOLS (coff), \
53993d8817e4Smiod BFD_JUMP_TABLE_RELOCS (coff), \
54003d8817e4Smiod BFD_JUMP_TABLE_WRITE (coff), \
54013d8817e4Smiod BFD_JUMP_TABLE_LINK (coff), \
54023d8817e4Smiod BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
54033d8817e4Smiod \
54043d8817e4Smiod ALTERNATIVE, \
54053d8817e4Smiod \
54063d8817e4Smiod SWAP_TABLE \
54073d8817e4Smiod };
54083d8817e4Smiod
54093d8817e4Smiod #define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
54103d8817e4Smiod const bfd_target VAR = \
54113d8817e4Smiod { \
54123d8817e4Smiod NAME , \
54133d8817e4Smiod bfd_target_coff_flavour, \
54143d8817e4Smiod BFD_ENDIAN_LITTLE, /* Data byte order is little. */ \
54153d8817e4Smiod BFD_ENDIAN_BIG, /* Header byte order is big. */ \
54163d8817e4Smiod /* object flags */ \
54173d8817e4Smiod (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
54183d8817e4Smiod HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
54193d8817e4Smiod /* section flags */ \
54203d8817e4Smiod (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
54213d8817e4Smiod UNDER, /* Leading symbol underscore. */ \
54223d8817e4Smiod '/', /* AR_pad_char. */ \
54233d8817e4Smiod 15, /* AR_max_namelen. */ \
54243d8817e4Smiod \
54253d8817e4Smiod /* Data conversion functions. */ \
54263d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
54273d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
54283d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
54293d8817e4Smiod \
54303d8817e4Smiod /* Header conversion functions. */ \
54313d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
54323d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
54333d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
54343d8817e4Smiod \
54353d8817e4Smiod /* bfd_check_format. */ \
54363d8817e4Smiod { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
54373d8817e4Smiod _bfd_dummy_target }, \
54383d8817e4Smiod /* bfd_set_format. */ \
54393d8817e4Smiod { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
54403d8817e4Smiod /* bfd_write_contents. */ \
54413d8817e4Smiod { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
54423d8817e4Smiod bfd_false }, \
54433d8817e4Smiod \
54443d8817e4Smiod BFD_JUMP_TABLE_GENERIC (coff), \
54453d8817e4Smiod BFD_JUMP_TABLE_COPY (coff), \
54463d8817e4Smiod BFD_JUMP_TABLE_CORE (_bfd_nocore), \
54473d8817e4Smiod BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
54483d8817e4Smiod BFD_JUMP_TABLE_SYMBOLS (coff), \
54493d8817e4Smiod BFD_JUMP_TABLE_RELOCS (coff), \
54503d8817e4Smiod BFD_JUMP_TABLE_WRITE (coff), \
54513d8817e4Smiod BFD_JUMP_TABLE_LINK (coff), \
54523d8817e4Smiod BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
54533d8817e4Smiod \
54543d8817e4Smiod ALTERNATIVE, \
54553d8817e4Smiod \
54563d8817e4Smiod SWAP_TABLE \
54573d8817e4Smiod };
54583d8817e4Smiod
54593d8817e4Smiod #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
54603d8817e4Smiod const bfd_target VAR = \
54613d8817e4Smiod { \
54623d8817e4Smiod NAME , \
54633d8817e4Smiod bfd_target_coff_flavour, \
54643d8817e4Smiod BFD_ENDIAN_LITTLE, /* Data byte order is little. */ \
54653d8817e4Smiod BFD_ENDIAN_LITTLE, /* Header byte order is little. */ \
54663d8817e4Smiod /* object flags */ \
54673d8817e4Smiod (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
54683d8817e4Smiod HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
54693d8817e4Smiod /* section flags */ \
54703d8817e4Smiod (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
54713d8817e4Smiod UNDER, /* Leading symbol underscore. */ \
54723d8817e4Smiod '/', /* AR_pad_char. */ \
54733d8817e4Smiod 15, /* AR_max_namelen. */ \
54743d8817e4Smiod \
54753d8817e4Smiod /* Data conversion functions. */ \
54763d8817e4Smiod bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
54773d8817e4Smiod bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
54783d8817e4Smiod bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
54793d8817e4Smiod /* Header conversion functions. */ \
54803d8817e4Smiod bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
54813d8817e4Smiod bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
54823d8817e4Smiod bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
54833d8817e4Smiod /* bfd_check_format. */ \
54843d8817e4Smiod { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
54853d8817e4Smiod _bfd_dummy_target }, \
54863d8817e4Smiod /* bfd_set_format. */ \
54873d8817e4Smiod { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
54883d8817e4Smiod /* bfd_write_contents. */ \
54893d8817e4Smiod { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
54903d8817e4Smiod bfd_false }, \
54913d8817e4Smiod \
54923d8817e4Smiod BFD_JUMP_TABLE_GENERIC (coff), \
54933d8817e4Smiod BFD_JUMP_TABLE_COPY (coff), \
54943d8817e4Smiod BFD_JUMP_TABLE_CORE (_bfd_nocore), \
54953d8817e4Smiod BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
54963d8817e4Smiod BFD_JUMP_TABLE_SYMBOLS (coff), \
54973d8817e4Smiod BFD_JUMP_TABLE_RELOCS (coff), \
54983d8817e4Smiod BFD_JUMP_TABLE_WRITE (coff), \
54993d8817e4Smiod BFD_JUMP_TABLE_LINK (coff), \
55003d8817e4Smiod BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
55013d8817e4Smiod \
55023d8817e4Smiod ALTERNATIVE, \
55033d8817e4Smiod \
55043d8817e4Smiod SWAP_TABLE \
55053d8817e4Smiod };
5506