1 /* Support for the generic parts of most COFF variants, for BFD.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 Most of this hacked by Steve Chamberlain,
31 BFD supports a number of different flavours of coff format.
32 The major differences between formats are the sizes and
33 alignments of fields in structures on disk, and the occasional
36 Coff in all its varieties is implemented with a few common
37 files and a number of implementation specific files. For
38 example, The 88k bcs coff format is implemented in the file
39 @file{coff-m88k.c}. This file @code{#include}s
40 @file{coff/m88k.h} which defines the external structure of the
41 coff format for the 88k, and @file{coff/internal.h} which
42 defines the internal structure. @file{coff-m88k.c} also
43 defines the relocations used by the 88k format
46 The Intel i960 processor version of coff is implemented in
47 @file{coff-i960.c}. This file has the same structure as
48 @file{coff-m88k.c}, except that it includes @file{coff/i960.h}
49 rather than @file{coff-m88k.h}.
52 Porting to a new version of coff
54 The recommended method is to select from the existing
55 implementations the version of coff which is most like the one
56 you want to use. For example, we'll say that i386 coff is
57 the one you select, and that your coff flavour is called foo.
58 Copy @file{i386coff.c} to @file{foocoff.c}, copy
59 @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
60 and add the lines to @file{targets.c} and @file{Makefile.in}
61 so that your new back end is used. Alter the shapes of the
62 structures in @file{../include/coff/foo.h} so that they match
63 what you need. You will probably also have to add
64 @code{#ifdef}s to the code in @file{coff/internal.h} and
65 @file{coffcode.h} if your version of coff is too wild.
67 You can verify that your new BFD backend works quite simply by
68 building @file{objdump} from the @file{binutils} directory,
69 and making sure that its version of what's going on and your
70 host system's idea (assuming it has the pretty standard coff
71 dump utility, usually called @code{att-dump} or just
72 @code{dump}) are the same. Then clean up your code, and send
73 what you've done to Cygnus. Then your stuff will be in the
74 next release, and you won't have to keep integrating it.
77 How the coff backend works
82 The Coff backend is split into generic routines that are
83 applicable to any Coff target and routines that are specific
84 to a particular target. The target-specific routines are
85 further split into ones which are basically the same for all
86 Coff targets except that they use the external symbol format
87 or use different values for certain constants.
89 The generic routines are in @file{coffgen.c}. These routines
90 work for any Coff target. They use some hooks into the target
91 specific code; the hooks are in a @code{bfd_coff_backend_data}
92 structure, one of which exists for each target.
94 The essentially similar target-specific routines are in
95 @file{coffcode.h}. This header file includes executable C code.
96 The various Coff targets first include the appropriate Coff
97 header file, make any special defines that are needed, and
98 then include @file{coffcode.h}.
100 Some of the Coff targets then also have additional routines in
101 the target source file itself.
103 For example, @file{coff-i960.c} includes
104 @file{coff/internal.h} and @file{coff/i960.h}. It then
105 defines a few constants, such as @code{I960}, and includes
106 @file{coffcode.h}. Since the i960 has complex relocation
107 types, @file{coff-i960.c} also includes some code to
108 manipulate the i960 relocs. This code is not in
109 @file{coffcode.h} because it would not be used by any other
115 Each flavour of coff supported in BFD has its own header file
116 describing the external layout of the structures. There is also
117 an internal description of the coff layout, in
118 @file{coff/internal.h}. A major function of the
119 coff backend is swapping the bytes and twiddling the bits to
120 translate the external form of the structures into the normal
121 internal form. This is all performed in the
122 @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
123 elements are different sizes between different versions of
124 coff; it is the duty of the coff version specific include file
125 to override the definitions of various packing routines in
126 @file{coffcode.h}. E.g., the size of line number entry in coff is
127 sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
128 @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
129 correct one. No doubt, some day someone will find a version of
130 coff which has a varying field size not catered to at the
131 moment. To port BFD, that person will have to add more @code{#defines}.
132 Three of the bit twiddling routines are exported to
133 @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
134 and @code{coff_swap_linno_in}. @code{GDB} reads the symbol
135 table on its own, but uses BFD to fix things up. More of the
136 bit twiddlers are exported for @code{gas};
137 @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
138 @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
139 @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
140 @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
141 of all the symbol table and reloc drudgery itself, thereby
142 saving the internal BFD overhead, but uses BFD to swap things
143 on the way out, making cross ports much safer. Doing so also
144 allows BFD (and thus the linker) to use the same header files
145 as @code{gas}, which makes one avenue to disaster disappear.
150 The simple canonical form for symbols used by BFD is not rich
151 enough to keep all the information available in a coff symbol
152 table. The back end gets around this problem by keeping the original
153 symbol table around, "behind the scenes".
155 When a symbol table is requested (through a call to
156 @code{bfd_canonicalize_symtab}), a request gets through to
157 @code{coff_get_normalized_symtab}. This reads the symbol table from
158 the coff file and swaps all the structures inside into the
159 internal form. It also fixes up all the pointers in the table
160 (represented in the file by offsets from the first symbol in
161 the table) into physical pointers to elements in the new
162 internal table. This involves some work since the meanings of
163 fields change depending upon context: a field that is a
164 pointer to another structure in the symbol table at one moment
165 may be the size in bytes of a structure at the next. Another
166 pass is made over the table. All symbols which mark file names
167 (<<C_FILE>> symbols) are modified so that the internal
168 string points to the value in the auxent (the real filename)
169 rather than the normal text associated with the symbol
172 At this time the symbol names are moved around. Coff stores
173 all symbols less than nine characters long physically
174 within the symbol table; longer strings are kept at the end of
175 the file in the string table. This pass moves all strings
176 into memory and replaces them with pointers to the strings.
179 The symbol table is massaged once again, this time to create
180 the canonical table used by the BFD application. Each symbol
181 is inspected in turn, and a decision made (using the
182 @code{sclass} field) about the various flags to set in the
183 @code{asymbol}. @xref{Symbols}. The generated canonical table
184 shares strings with the hidden internal symbol table.
186 Any linenumbers are read from the coff file too, and attached
187 to the symbols which own the functions the linenumbers belong to.
192 Writing a symbol to a coff file which didn't come from a coff
193 file will lose any debugging information. The @code{asymbol}
194 structure remembers the BFD from which the symbol was taken, and on
195 output the back end makes sure that the same destination target as
196 source target is present.
198 When the symbols have come from a coff file then all the
199 debugging information is preserved.
201 Symbol tables are provided for writing to the back end in a
202 vector of pointers to pointers. This allows applications like
203 the linker to accumulate and output large symbol tables
204 without having to do too much byte copying.
206 This function runs through the provided symbol table and
207 patches each symbol marked as a file place holder
208 (@code{C_FILE}) to point to the next file place holder in the
209 list. It also marks each @code{offset} field in the list with
210 the offset from the first symbol of the current symbol.
212 Another function of this procedure is to turn the canonical
213 value form of BFD into the form used by coff. Internally, BFD
214 expects symbol values to be offsets from a section base; so a
215 symbol physically at 0x120, but in a section starting at
216 0x100, would have the value 0x20. Coff expects symbols to
217 contain their final value, so symbols have their values
218 changed at this point to reflect their sum with their owning
219 section. This transformation uses the
220 <<output_section>> field of the @code{asymbol}'s
221 @code{asection} @xref{Sections}.
223 o <<coff_mangle_symbols>>
225 This routine runs though the provided symbol table and uses
226 the offsets generated by the previous pass and the pointers
227 generated when the symbol table was read in to create the
228 structured hierachy required by coff. It changes each pointer
229 to a symbol into the index into the symbol table of the asymbol.
231 o <<coff_write_symbols>>
233 This routine runs through the symbol table and patches up the
234 symbols from their internal form into the coff way, calls the
235 bit twiddlers, and writes out the table to the file.
244 The hidden information for an <<asymbol>> is described in a
245 <<combined_entry_type>>:
249 .typedef struct coff_ptr_struct
252 . {* Remembers the offset from the first symbol in the file for
253 . this symbol. Generated by coff_renumber_symbols. *}
254 .unsigned int offset;
256 . {* Should the value of this symbol be renumbered. Used for
257 . XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. *}
258 .unsigned int fix_value : 1;
260 . {* Should the tag field of this symbol be renumbered.
261 . Created by coff_pointerize_aux. *}
262 .unsigned int fix_tag : 1;
264 . {* Should the endidx field of this symbol be renumbered.
265 . Created by coff_pointerize_aux. *}
266 .unsigned int fix_end : 1;
268 . {* Should the x_csect.x_scnlen field be renumbered.
269 . Created by coff_pointerize_aux. *}
270 .unsigned int fix_scnlen : 1;
272 . {* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
273 . index into the line number entries. Set by
274 . coff_slurp_symbol_table. *}
275 .unsigned int fix_line : 1;
277 . {* The container for the symbol structure as read and translated
281 . union internal_auxent auxent;
282 . struct internal_syment syment;
284 .} combined_entry_type;
287 .{* Each canonical asymbol really looks like this: *}
289 .typedef struct coff_symbol_struct
291 . {* The actual symbol which the rest of BFD works with *}
294 . {* A pointer to the hidden information for this symbol *}
295 .combined_entry_type *native;
297 . {* A pointer to the linenumber information for this symbol *}
298 .struct lineno_cache_entry *lineno;
300 . {* Have the line numbers been relocated yet ? *}
301 .boolean done_lineno;
310 #include "coffswap.h"
313 #define STRING_SIZE_SIZE (4)
315 static long sec_to_styp_flags PARAMS ((const char *, flagword));
316 static flagword styp_to_sec_flags PARAMS ((bfd *, PTR, const char *));
317 static boolean coff_bad_format_hook PARAMS ((bfd *, PTR));
318 static void coff_set_custom_section_alignment
319 PARAMS ((bfd *, asection *, const struct coff_section_alignment_entry *,
321 static boolean coff_new_section_hook PARAMS ((bfd *, asection *));
322 static boolean coff_set_arch_mach_hook PARAMS ((bfd *, PTR));
323 static boolean coff_write_relocs PARAMS ((bfd *, int));
324 static boolean coff_set_flags
325 PARAMS ((bfd *, unsigned int *, unsigned short *));
326 static boolean coff_set_arch_mach
327 PARAMS ((bfd *, enum bfd_architecture, unsigned long));
328 static boolean coff_compute_section_file_positions PARAMS ((bfd *));
329 static boolean coff_write_object_contents PARAMS ((bfd *));
330 static boolean coff_set_section_contents
331 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
332 static PTR buy_and_read PARAMS ((bfd *, file_ptr, int, size_t));
333 static boolean coff_slurp_line_table PARAMS ((bfd *, asection *));
334 static boolean coff_slurp_symbol_table PARAMS ((bfd *));
335 static enum coff_symbol_classification coff_classify_symbol
336 PARAMS ((bfd *, struct internal_syment *));
337 static boolean coff_slurp_reloc_table PARAMS ((bfd *, asection *, asymbol **));
338 static long coff_canonicalize_reloc
339 PARAMS ((bfd *, asection *, arelent **, asymbol **));
340 #ifndef coff_mkobject_hook
341 static PTR coff_mkobject_hook PARAMS ((bfd *, PTR, PTR));
344 /* void warning(); */
347 * Return a word with STYP_* (scnhdr.s_flags) flags set to represent the
348 * incoming SEC_* flags. The inverse of this function is styp_to_sec_flags().
349 * NOTE: If you add to/change this routine, you should mirror the changes
350 * in styp_to_sec_flags().
353 sec_to_styp_flags (sec_name, sec_flags)
354 CONST char *sec_name;
359 if (!strcmp (sec_name, _TEXT))
361 styp_flags = STYP_TEXT;
363 else if (!strcmp (sec_name, _DATA))
365 styp_flags = STYP_DATA;
367 else if (!strcmp (sec_name, _BSS))
369 styp_flags = STYP_BSS;
372 else if (!strcmp (sec_name, _COMMENT))
374 styp_flags = STYP_INFO;
375 #endif /* _COMMENT */
378 else if (!strcmp (sec_name, _LIB))
380 styp_flags = STYP_LIB;
384 else if (!strcmp (sec_name, _LIT))
386 styp_flags = STYP_LIT;
389 else if (!strcmp (sec_name, ".debug"))
392 styp_flags = STYP_DEBUG;
394 styp_flags = STYP_INFO;
397 else if (!strncmp (sec_name, ".stab", 5))
399 styp_flags = STYP_INFO;
402 else if (!strcmp (sec_name, ".edata"))
404 styp_flags = STYP_DATA;
408 else if (!strcmp (sec_name, _PAD))
410 styp_flags = STYP_PAD;
412 else if (!strcmp (sec_name, _LOADER))
414 styp_flags = STYP_LOADER;
417 /* Try and figure out what it should be */
418 else if (sec_flags & SEC_CODE)
420 styp_flags = STYP_TEXT;
422 else if (sec_flags & SEC_DATA)
424 styp_flags = STYP_DATA;
426 else if (sec_flags & SEC_READONLY)
428 #ifdef STYP_LIT /* 29k readonly text/data section */
429 styp_flags = STYP_LIT;
431 styp_flags = STYP_TEXT;
432 #endif /* STYP_LIT */
434 else if (sec_flags & SEC_LOAD)
436 styp_flags = STYP_TEXT;
438 else if (sec_flags & SEC_ALLOC)
440 styp_flags = STYP_BSS;
444 if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
445 styp_flags |= STYP_NOLOAD;
449 if (sec_flags & SEC_LINK_ONCE)
450 styp_flags |= IMAGE_SCN_LNK_COMDAT;
451 if (sec_flags & SEC_SHARED)
452 styp_flags |= IMAGE_SCN_MEM_SHARED;
458 * Return a word with SEC_* flags set to represent the incoming
459 * STYP_* flags (from scnhdr.s_flags). The inverse of this
460 * function is sec_to_styp_flags().
461 * NOTE: If you add to/change this routine, you should mirror the changes
462 * in sec_to_styp_flags().
465 styp_to_sec_flags (abfd, hdr, name)
466 bfd *abfd ATTRIBUTE_UNUSED;
470 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
471 long styp_flags = internal_s->s_flags;
472 flagword sec_flags = 0;
475 if (styp_flags & STYP_NOLOAD)
477 sec_flags |= SEC_NEVER_LOAD;
479 #endif /* STYP_NOLOAD */
481 /* For 386 COFF, at least, an unloadable text or data section is
482 actually a shared library section. */
483 if (styp_flags & STYP_TEXT)
485 if (sec_flags & SEC_NEVER_LOAD)
486 sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
488 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
490 else if (styp_flags & STYP_DATA)
492 if (sec_flags & SEC_NEVER_LOAD)
493 sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
495 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
497 else if (styp_flags & STYP_BSS)
499 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
500 if (sec_flags & SEC_NEVER_LOAD)
501 sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
504 sec_flags |= SEC_ALLOC;
506 else if (styp_flags & STYP_INFO)
508 /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
509 defined. coff_compute_section_file_positions uses
510 COFF_PAGE_SIZE to ensure that the low order bits of the
511 section VMA and the file offset match. If we don't know
512 COFF_PAGE_SIZE, we can't ensure the correct correspondence,
513 and demand page loading of the file will fail. */
514 #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
515 sec_flags |= SEC_DEBUGGING;
518 else if (styp_flags & STYP_PAD)
522 else if (strcmp (name, _TEXT) == 0)
524 if (sec_flags & SEC_NEVER_LOAD)
525 sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
527 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
529 else if (strcmp (name, _DATA) == 0)
531 if (sec_flags & SEC_NEVER_LOAD)
532 sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
534 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
536 else if (strcmp (name, _BSS) == 0)
538 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
539 if (sec_flags & SEC_NEVER_LOAD)
540 sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
543 sec_flags |= SEC_ALLOC;
545 else if (strcmp (name, ".debug") == 0
547 || strcmp (name, _COMMENT) == 0
549 || strncmp (name, ".stab", 5) == 0)
551 #ifdef COFF_PAGE_SIZE
552 sec_flags |= SEC_DEBUGGING;
556 else if (strcmp (name, _LIB) == 0)
560 else if (strcmp (name, _LIT) == 0)
562 sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
567 sec_flags |= SEC_ALLOC | SEC_LOAD;
570 #ifdef STYP_LIT /* A29k readonly text/data section type */
571 if ((styp_flags & STYP_LIT) == STYP_LIT)
573 sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
575 #endif /* STYP_LIT */
576 #ifdef STYP_OTHER_LOAD /* Other loaded sections */
577 if (styp_flags & STYP_OTHER_LOAD)
579 sec_flags = (SEC_LOAD | SEC_ALLOC);
581 #endif /* STYP_SDATA */
584 if (styp_flags & IMAGE_SCN_LNK_REMOVE)
585 sec_flags |= SEC_EXCLUDE;
587 if (styp_flags & IMAGE_SCN_MEM_SHARED)
588 sec_flags |= SEC_SHARED;
590 if (styp_flags & IMAGE_SCN_LNK_COMDAT)
592 sec_flags |= SEC_LINK_ONCE;
594 /* Unfortunately, the PE format stores essential information in
595 the symbol table, of all places. We need to extract that
596 information now, so that objdump and the linker will know how
597 to handle the section without worrying about the symbols. We
598 can't call slurp_symtab, because the linker doesn't want the
601 /* COMDAT sections are special. The first symbol is the section
602 symbol, which tells what kind of COMDAT section it is. The
603 *second* symbol is the "comdat symbol" - the one with the
604 unique name. GNU uses the section symbol for the unique
605 name; MS uses ".text" for every comdat section. Sigh. - DJ */
607 if (_bfd_coff_get_external_symbols (abfd))
609 bfd_byte *esym, *esymend;
611 esym = (bfd_byte *) obj_coff_external_syms (abfd);
612 esymend = esym + obj_raw_syment_count (abfd) * SYMESZ;
614 while (esym < esymend)
616 struct internal_syment isym;
618 bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &isym);
620 if (sizeof (internal_s->s_name) > SYMNMLEN)
622 /* This case implies that the matching symbol name
623 will be in the string table. */
627 if (isym.n_sclass == C_STAT
628 && isym.n_type == T_NULL
629 && isym.n_numaux == 1)
631 char buf[SYMNMLEN + 1];
634 symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
638 if (strcmp (name, symname) == 0)
640 union internal_auxent aux;
642 /* This is the section symbol. */
644 bfd_coff_swap_aux_in (abfd, (PTR) (esym + SYMESZ),
645 isym.n_type, isym.n_sclass,
646 0, isym.n_numaux, (PTR) &aux);
648 /* FIXME: Microsoft uses NODUPLICATES and
649 ASSOCIATIVE, but gnu uses ANY and SAME_SIZE.
650 Unfortunately, gnu doesn't do the comdat
651 symbols right. So, until we can fix it to do
652 the right thing, we are temporarily disabling
653 comdats for the MS types (they're used in
654 DLLs and C++, but we don't support *their*
655 C++ libraries anyway - DJ */
657 switch (aux.x_scn.x_comdat)
659 case IMAGE_COMDAT_SELECT_NODUPLICATES:
661 sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
663 sec_flags &= ~SEC_LINK_ONCE;
668 case IMAGE_COMDAT_SELECT_ANY:
669 sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
672 case IMAGE_COMDAT_SELECT_SAME_SIZE:
673 sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
676 case IMAGE_COMDAT_SELECT_EXACT_MATCH:
677 sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
680 case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
682 /* FIXME: This is not currently implemented. */
683 sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
685 sec_flags &= ~SEC_LINK_ONCE;
694 esym += (isym.n_numaux + 1) * SYMESZ;
700 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
701 /* As a GNU extension, if the name begins with .gnu.linkonce, we
702 only link a single copy of the section. This is used to support
703 g++. g++ will emit each template expansion in its own section.
704 The symbols will be defined as weak, so that multiple definitions
705 are permitted. The GNU linker extension is to actually discard
706 all but one of the sections. */
707 if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
708 sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
714 #define get_index(symbol) ((symbol)->udata.i)
718 bfd_coff_backend_data
722 .{* COFF symbol classifications. *}
724 .enum coff_symbol_classification
726 . {* Global symbol. *}
727 . COFF_SYMBOL_GLOBAL,
728 . {* Common symbol. *}
729 . COFF_SYMBOL_COMMON,
730 . {* Undefined symbol. *}
731 . COFF_SYMBOL_UNDEFINED,
732 . {* Local symbol. *}
734 . {* PE section symbol. *}
735 . COFF_SYMBOL_PE_SECTION
738 Special entry points for gdb to swap in coff symbol table parts:
741 . void (*_bfd_coff_swap_aux_in) PARAMS ((
750 . void (*_bfd_coff_swap_sym_in) PARAMS ((
755 . void (*_bfd_coff_swap_lineno_in) PARAMS ((
761 Special entry points for gas to swap out coff parts:
763 . unsigned int (*_bfd_coff_swap_aux_out) PARAMS ((
772 . unsigned int (*_bfd_coff_swap_sym_out) PARAMS ((
777 . unsigned int (*_bfd_coff_swap_lineno_out) PARAMS ((
782 . unsigned int (*_bfd_coff_swap_reloc_out) PARAMS ((
787 . unsigned int (*_bfd_coff_swap_filehdr_out) PARAMS ((
792 . unsigned int (*_bfd_coff_swap_aouthdr_out) PARAMS ((
797 . unsigned int (*_bfd_coff_swap_scnhdr_out) PARAMS ((
803 Special entry points for generic COFF routines to call target
804 dependent COFF routines:
806 . unsigned int _bfd_filhsz;
807 . unsigned int _bfd_aoutsz;
808 . unsigned int _bfd_scnhsz;
809 . unsigned int _bfd_symesz;
810 . unsigned int _bfd_auxesz;
811 . unsigned int _bfd_relsz;
812 . unsigned int _bfd_linesz;
813 . boolean _bfd_coff_long_filenames;
814 . boolean _bfd_coff_long_section_names;
815 . unsigned int _bfd_coff_default_section_alignment_power;
816 . void (*_bfd_coff_swap_filehdr_in) PARAMS ((
820 . void (*_bfd_coff_swap_aouthdr_in) PARAMS ((
824 . void (*_bfd_coff_swap_scnhdr_in) PARAMS ((
828 . void (*_bfd_coff_swap_reloc_in) PARAMS ((
832 . boolean (*_bfd_coff_bad_format_hook) PARAMS ((
834 . PTR internal_filehdr));
835 . boolean (*_bfd_coff_set_arch_mach_hook) PARAMS ((
837 . PTR internal_filehdr));
838 . PTR (*_bfd_coff_mkobject_hook) PARAMS ((
840 . PTR internal_filehdr,
841 . PTR internal_aouthdr));
842 . flagword (*_bfd_styp_to_sec_flags_hook) PARAMS ((
844 . PTR internal_scnhdr,
845 . const char *name));
846 . void (*_bfd_set_alignment_hook) PARAMS ((
849 . PTR internal_scnhdr));
850 . boolean (*_bfd_coff_slurp_symbol_table) PARAMS ((
852 . boolean (*_bfd_coff_symname_in_debug) PARAMS ((
854 . struct internal_syment *sym));
855 . boolean (*_bfd_coff_pointerize_aux_hook) PARAMS ((
857 . combined_entry_type *table_base,
858 . combined_entry_type *symbol,
859 . unsigned int indaux,
860 . combined_entry_type *aux));
861 . boolean (*_bfd_coff_print_aux) PARAMS ((
864 . combined_entry_type *table_base,
865 . combined_entry_type *symbol,
866 . combined_entry_type *aux,
867 . unsigned int indaux));
868 . void (*_bfd_coff_reloc16_extra_cases) PARAMS ((
870 . struct bfd_link_info *link_info,
871 . struct bfd_link_order *link_order,
874 . unsigned int *src_ptr,
875 . unsigned int *dst_ptr));
876 . int (*_bfd_coff_reloc16_estimate) PARAMS ((
878 . asection *input_section,
880 . unsigned int shrink,
881 . struct bfd_link_info *link_info));
882 . enum coff_symbol_classification (*_bfd_coff_classify_symbol) PARAMS ((
884 . struct internal_syment *));
885 . boolean (*_bfd_coff_compute_section_file_positions) PARAMS ((
887 . boolean (*_bfd_coff_start_final_link) PARAMS ((
889 . struct bfd_link_info *info));
890 . boolean (*_bfd_coff_relocate_section) PARAMS ((
892 . struct bfd_link_info *info,
894 . asection *input_section,
895 . bfd_byte *contents,
896 . struct internal_reloc *relocs,
897 . struct internal_syment *syms,
898 . asection **sections));
899 . reloc_howto_type *(*_bfd_coff_rtype_to_howto) PARAMS ((
902 . struct internal_reloc *rel,
903 . struct coff_link_hash_entry *h,
904 . struct internal_syment *sym,
905 . bfd_vma *addendp));
906 . boolean (*_bfd_coff_adjust_symndx) PARAMS ((
908 . struct bfd_link_info *info,
911 . struct internal_reloc *reloc,
912 . boolean *adjustedp));
913 . boolean (*_bfd_coff_link_add_one_symbol) PARAMS ((
914 . struct bfd_link_info *info,
920 . const char *string,
923 . struct bfd_link_hash_entry **hashp));
925 . boolean (*_bfd_coff_link_output_has_begun) PARAMS ((
927 . struct coff_final_link_info * pfinfo));
928 . boolean (*_bfd_coff_final_link_postscript) PARAMS ((
930 . struct coff_final_link_info * pfinfo));
932 .} bfd_coff_backend_data;
934 .#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
936 .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
937 . ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
939 .#define bfd_coff_swap_sym_in(a,e,i) \
940 . ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
942 .#define bfd_coff_swap_lineno_in(a,e,i) \
943 . ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
945 .#define bfd_coff_swap_reloc_out(abfd, i, o) \
946 . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
948 .#define bfd_coff_swap_lineno_out(abfd, i, o) \
949 . ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
951 .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
952 . ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
954 .#define bfd_coff_swap_sym_out(abfd, i,o) \
955 . ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
957 .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
958 . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
960 .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
961 . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
963 .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
964 . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
966 .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
967 .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
968 .#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
969 .#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
970 .#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
971 .#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
972 .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
973 .#define bfd_coff_long_filenames(abfd) (coff_backend_info (abfd)->_bfd_coff_long_filenames)
974 .#define bfd_coff_long_section_names(abfd) \
975 . (coff_backend_info (abfd)->_bfd_coff_long_section_names)
976 .#define bfd_coff_default_section_alignment_power(abfd) \
977 . (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
978 .#define bfd_coff_swap_filehdr_in(abfd, i,o) \
979 . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
981 .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
982 . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
984 .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
985 . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
987 .#define bfd_coff_swap_reloc_in(abfd, i, o) \
988 . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
990 .#define bfd_coff_bad_format_hook(abfd, filehdr) \
991 . ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
993 .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
994 . ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
995 .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
996 . ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
998 .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name)\
999 . ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook) (abfd, scnhdr, name))
1001 .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
1002 . ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
1004 .#define bfd_coff_slurp_symbol_table(abfd)\
1005 . ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
1007 .#define bfd_coff_symname_in_debug(abfd, sym)\
1008 . ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
1010 .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
1011 . ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
1012 . (abfd, file, base, symbol, aux, indaux))
1014 .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\
1015 . ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
1016 . (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
1018 .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
1019 . ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
1020 . (abfd, section, reloc, shrink, link_info))
1022 .#define bfd_coff_classify_symbol(abfd, sym)\
1023 . ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
1026 .#define bfd_coff_compute_section_file_positions(abfd)\
1027 . ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
1030 .#define bfd_coff_start_final_link(obfd, info)\
1031 . ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
1033 .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
1034 . ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
1035 . (obfd, info, ibfd, o, con, rel, isyms, secs))
1036 .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
1037 . ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
1038 . (abfd, sec, rel, h, sym, addendp))
1039 .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
1040 . ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
1041 . (obfd, info, ibfd, sec, rel, adjustedp))
1042 .#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\
1043 . ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
1044 . (info, abfd, name, flags, section, value, string, cp, coll, hashp))
1046 .#define bfd_coff_link_output_has_begun(a,p) \
1047 . ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p))
1048 .#define bfd_coff_final_link_postscript(a,p) \
1049 . ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p))
1053 /* See whether the magic number matches. */
1056 coff_bad_format_hook (abfd, filehdr)
1057 bfd * abfd ATTRIBUTE_UNUSED;
1060 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1062 if (BADMAG (*internal_f))
1065 /* if the optional header is NULL or not the correct size then
1066 quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
1067 and Intel 960 readwrite headers (I960WRMAGIC) is that the
1068 optional header is of a different size.
1070 But the mips keeps extra stuff in it's opthdr, so dont check
1074 #if defined(M88) || defined(I960)
1075 if (internal_f->f_opthdr != 0 && AOUTSZ != internal_f->f_opthdr)
1082 /* Check whether this section uses an alignment other than the
1086 coff_set_custom_section_alignment (abfd, section, alignment_table, table_size)
1087 bfd *abfd ATTRIBUTE_UNUSED;
1089 const struct coff_section_alignment_entry *alignment_table;
1090 const unsigned int table_size;
1092 const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1095 for (i = 0; i < table_size; ++i)
1097 const char *secname = bfd_get_section_name (abfd, section);
1098 if (alignment_table[i].comparison_length == (unsigned int) -1
1099 ? strcmp (alignment_table[i].name, secname) == 0
1100 : strncmp (alignment_table[i].name, secname,
1101 alignment_table[i].comparison_length) == 0)
1104 if (i >= table_size)
1107 if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1108 && default_alignment < alignment_table[i].default_alignment_min)
1111 if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1112 && default_alignment > alignment_table[i].default_alignment_max)
1115 section->alignment_power = alignment_table[i].alignment_power;
1118 /* Custom section alignment records. */
1120 static const struct coff_section_alignment_entry
1121 coff_section_alignment_table[] =
1123 #ifdef COFF_SECTION_ALIGNMENT_ENTRIES
1124 COFF_SECTION_ALIGNMENT_ENTRIES,
1126 /* There must not be any gaps between .stabstr sections. */
1127 { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
1128 1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
1129 /* The .stab section must be aligned to 2**2 at most, to avoid gaps. */
1130 { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
1131 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1132 /* Similarly for the .ctors and .dtors sections. */
1133 { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
1134 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1135 { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
1136 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
1139 static const unsigned int coff_section_alignment_table_size =
1140 sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
1142 /* Initialize a section structure with information peculiar to this
1143 particular implementation of COFF. */
1146 coff_new_section_hook (abfd, section)
1150 combined_entry_type *native;
1152 section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1155 if (xcoff_data (abfd)->text_align_power != 0
1156 && strcmp (bfd_get_section_name (abfd, section), ".text") == 0)
1157 section->alignment_power = xcoff_data (abfd)->text_align_power;
1158 if (xcoff_data (abfd)->data_align_power != 0
1159 && strcmp (bfd_get_section_name (abfd, section), ".data") == 0)
1160 section->alignment_power = xcoff_data (abfd)->data_align_power;
1163 /* Allocate aux records for section symbols, to store size and
1166 @@ The 10 is a guess at a plausible maximum number of aux entries
1167 (but shouldn't be a constant). */
1168 native = ((combined_entry_type *)
1169 bfd_zalloc (abfd, sizeof (combined_entry_type) * 10));
1173 /* We don't need to set up n_name, n_value, or n_scnum in the native
1174 symbol information, since they'll be overriden by the BFD symbol
1175 anyhow. However, we do need to set the type and storage class,
1176 in case this symbol winds up getting written out. The value 0
1177 for n_numaux is already correct. */
1179 native->u.syment.n_type = T_NULL;
1180 native->u.syment.n_sclass = C_STAT;
1182 coffsymbol (section->symbol)->native = native;
1184 coff_set_custom_section_alignment (abfd, section,
1185 coff_section_alignment_table,
1186 coff_section_alignment_table_size);
1191 #ifdef COFF_ALIGN_IN_SECTION_HEADER
1193 /* Set the alignment of a BFD section. */
1195 static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR));
1198 coff_set_alignment_hook (abfd, section, scnhdr)
1199 bfd * abfd ATTRIBUTE_UNUSED;
1203 struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1207 /* Extract ALIGN from 2**ALIGN stored in section header */
1208 for (i = 0; i < 32; i++)
1209 if ((1 << i) >= hdr->s_align)
1213 /* TI tools hijack bits 8-11 for the alignment */
1214 i = (hdr->s_flags >> 8) & 0xF ;
1216 section->alignment_power = i;
1219 #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
1222 /* a couple of macros to help setting the alignment power field */
1223 #define ALIGN_SET(field,x,y) \
1224 if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x )\
1226 section->alignment_power = y;\
1229 #define ELIFALIGN_SET(field,x,y) \
1230 else if (( (field) & IMAGE_SCN_ALIGN_64BYTES) == x ) \
1232 section->alignment_power = y;\
1235 static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR));
1238 coff_set_alignment_hook (abfd, section, scnhdr)
1239 bfd * abfd ATTRIBUTE_UNUSED;
1243 struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1245 ALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
1246 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
1247 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4)
1248 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES, 3)
1249 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES, 2)
1250 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES, 1)
1251 ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES, 0)
1253 #ifdef POWERPC_LE_PE
1254 if (strcmp (section->name, ".idata$2") == 0)
1256 section->alignment_power = 0;
1258 else if (strcmp (section->name, ".idata$3") == 0)
1260 section->alignment_power = 0;
1262 else if (strcmp (section->name, ".idata$4") == 0)
1264 section->alignment_power = 2;
1266 else if (strcmp (section->name, ".idata$5") == 0)
1268 section->alignment_power = 2;
1270 else if (strcmp (section->name, ".idata$6") == 0)
1272 section->alignment_power = 1;
1274 else if (strcmp (section->name, ".reloc") == 0)
1276 section->alignment_power = 1;
1278 else if (strncmp (section->name, ".stab", 5) == 0)
1280 section->alignment_power = 2;
1284 #ifdef COFF_IMAGE_WITH_PE
1285 /* In a PE image file, the s_paddr field holds the virtual size of a
1286 section, while the s_size field holds the raw size. */
1287 if (hdr->s_paddr != 0)
1289 if (coff_section_data (abfd, section) == NULL)
1291 section->used_by_bfd =
1292 (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
1293 if (section->used_by_bfd == NULL)
1295 /* FIXME: Return error. */
1299 if (pei_section_data (abfd, section) == NULL)
1301 coff_section_data (abfd, section)->tdata =
1302 (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata));
1303 if (coff_section_data (abfd, section)->tdata == NULL)
1305 /* FIXME: Return error. */
1309 pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1314 section->lma = hdr->s_vaddr;
1318 #undef ELIFALIGN_SET
1320 #else /* ! COFF_WITH_PE */
1323 /* We grossly abuse this function to handle XCOFF overflow headers.
1324 When we see one, we correct the reloc and line number counts in the
1325 real header, and remove the section we just created. */
1327 static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR));
1330 coff_set_alignment_hook (abfd, section, scnhdr)
1335 struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1339 if ((hdr->s_flags & STYP_OVRFLO) == 0)
1342 real_sec = coff_section_from_bfd_index (abfd, hdr->s_nreloc);
1343 if (real_sec == NULL)
1346 real_sec->reloc_count = hdr->s_paddr;
1347 real_sec->lineno_count = hdr->s_vaddr;
1349 for (ps = &abfd->sections; *ps != NULL; ps = &(*ps)->next)
1354 --abfd->section_count;
1360 #else /* ! RS6000COFF_C */
1362 #define coff_set_alignment_hook \
1363 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
1365 #endif /* ! RS6000COFF_C */
1366 #endif /* ! COFF_WITH_PE */
1367 #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
1369 #ifndef coff_mkobject
1371 static boolean coff_mkobject PARAMS ((bfd *));
1374 coff_mkobject (abfd)
1377 coff_data_type *coff;
1379 abfd->tdata.coff_obj_data = (struct coff_tdata *) bfd_zalloc (abfd, sizeof (coff_data_type));
1380 if (abfd->tdata.coff_obj_data == 0)
1382 coff = coff_data (abfd);
1383 coff->symbols = (coff_symbol_type *) NULL;
1384 coff->conversion_table = (unsigned int *) NULL;
1385 coff->raw_syments = (struct coff_ptr_struct *) NULL;
1386 coff->relocbase = 0;
1387 coff->local_toc_sym_map = 0;
1389 /* make_abs_section(abfd);*/
1395 /* Create the COFF backend specific information. */
1396 #ifndef coff_mkobject_hook
1398 coff_mkobject_hook (abfd, filehdr, aouthdr)
1401 PTR aouthdr ATTRIBUTE_UNUSED;
1403 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1404 coff_data_type *coff;
1406 if (coff_mkobject (abfd) == false)
1409 coff = coff_data (abfd);
1411 coff->sym_filepos = internal_f->f_symptr;
1413 /* These members communicate important constants about the symbol
1414 table to GDB's symbol-reading code. These `constants'
1415 unfortunately vary among coff implementations... */
1416 coff->local_n_btmask = N_BTMASK;
1417 coff->local_n_btshft = N_BTSHFT;
1418 coff->local_n_tmask = N_TMASK;
1419 coff->local_n_tshift = N_TSHIFT;
1420 coff->local_symesz = SYMESZ;
1421 coff->local_auxesz = AUXESZ;
1422 coff->local_linesz = LINESZ;
1424 obj_raw_syment_count (abfd) =
1425 obj_conv_table_size (abfd) =
1426 internal_f->f_nsyms;
1429 if ((internal_f->f_flags & F_SHROBJ) != 0)
1430 abfd->flags |= DYNAMIC;
1431 if (aouthdr != NULL && internal_f->f_opthdr >= AOUTSZ)
1433 struct internal_aouthdr *internal_a =
1434 (struct internal_aouthdr *) aouthdr;
1435 struct xcoff_tdata *xcoff;
1437 xcoff = xcoff_data (abfd);
1438 xcoff->full_aouthdr = true;
1439 xcoff->toc = internal_a->o_toc;
1440 xcoff->sntoc = internal_a->o_sntoc;
1441 xcoff->snentry = internal_a->o_snentry;
1442 xcoff->text_align_power = internal_a->o_algntext;
1443 xcoff->data_align_power = internal_a->o_algndata;
1444 xcoff->modtype = internal_a->o_modtype;
1445 xcoff->cputype = internal_a->o_cputype;
1446 xcoff->maxdata = internal_a->o_maxdata;
1447 xcoff->maxstack = internal_a->o_maxstack;
1452 /* Set the flags field from the COFF header read in */
1453 if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
1461 /* Determine the machine architecture and type. FIXME: This is target
1462 dependent because the magic numbers are defined in the target
1463 dependent header files. But there is no particular need for this.
1464 If the magic numbers were moved to a separate file, this function
1465 would be target independent and would also be much more successful
1466 at linking together COFF files for different architectures. */
1469 coff_set_arch_mach_hook (abfd, filehdr)
1474 enum bfd_architecture arch;
1475 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1478 switch (internal_f->f_magic)
1482 arch = bfd_arch_powerpc;
1483 machine = 0; /* what does this mean? (krk) */
1489 case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler */
1490 case LYNXCOFFMAGIC: /* shadows the m68k Lynx number below, sigh */
1491 arch = bfd_arch_i386;
1495 #ifdef A29K_MAGIC_BIG
1496 case A29K_MAGIC_BIG:
1497 case A29K_MAGIC_LITTLE:
1498 arch = bfd_arch_a29k;
1504 arch = bfd_arch_arm;
1505 switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
1507 case F_ARM_2: machine = bfd_mach_arm_2; break;
1508 case F_ARM_2a: machine = bfd_mach_arm_2a; break;
1509 case F_ARM_3: machine = bfd_mach_arm_3; break;
1511 case F_ARM_3M: machine = bfd_mach_arm_3M; break;
1512 case F_ARM_4: machine = bfd_mach_arm_4; break;
1513 case F_ARM_4T: machine = bfd_mach_arm_4T; break;
1514 case F_ARM_5: machine = bfd_mach_arm_5; break;
1521 #ifdef MC68KBCSMAGIC
1524 #ifdef APOLLOM68KMAGIC
1525 case APOLLOM68KMAGIC:
1527 #ifdef LYNXCOFFMAGIC
1530 arch = bfd_arch_m68k;
1531 machine = bfd_mach_m68020;
1538 arch = bfd_arch_m88k;
1544 arch = bfd_arch_z8k;
1545 switch (internal_f->f_flags & F_MACHMASK)
1548 machine = bfd_mach_z8001;
1551 machine = bfd_mach_z8002;
1560 arch = bfd_arch_i860;
1567 arch = bfd_arch_i960;
1568 switch (F_I960TYPE & internal_f->f_flags)
1572 machine = bfd_mach_i960_core;
1575 machine = bfd_mach_i960_kb_sb;
1578 machine = bfd_mach_i960_mc;
1581 machine = bfd_mach_i960_xa;
1584 machine = bfd_mach_i960_ca;
1587 machine = bfd_mach_i960_ka_sa;
1590 machine = bfd_mach_i960_jx;
1593 machine = bfd_mach_i960_hx;
1607 if (xcoff_data (abfd)->cputype != -1)
1608 cputype = xcoff_data (abfd)->cputype & 0xff;
1611 /* We did not get a value from the a.out header. If the
1612 file has not been stripped, we may be able to get the
1613 architecture information from the first symbol, if it
1614 is a .file symbol. */
1615 if (obj_raw_syment_count (abfd) == 0)
1619 bfd_byte buf[SYMESZ];
1620 struct internal_syment sym;
1622 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
1623 || bfd_read (buf, 1, SYMESZ, abfd) != SYMESZ)
1625 coff_swap_sym_in (abfd, (PTR) buf, (PTR) &sym);
1626 if (sym.n_sclass == C_FILE)
1627 cputype = sym.n_type & 0xff;
1633 /* FIXME: We don't handle all cases here. */
1639 /* PowerPC Macs use the same magic numbers as RS/6000
1640 (because that's how they were bootstrapped originally),
1641 but they are always PowerPC architecture. */
1642 arch = bfd_arch_powerpc;
1645 arch = bfd_arch_rs6000;
1647 #endif /* POWERMAC */
1651 arch = bfd_arch_powerpc;
1654 case 2: /* 64 bit PowerPC */
1655 arch = bfd_arch_powerpc;
1659 arch = bfd_arch_powerpc;
1663 arch = bfd_arch_rs6000;
1673 arch = bfd_arch_we32k;
1680 arch = bfd_arch_h8300;
1681 machine = bfd_mach_h8300;
1682 /* !! FIXME this probably isn't the right place for this */
1683 abfd->flags |= BFD_IS_RELAXABLE;
1689 arch = bfd_arch_h8300;
1690 machine = bfd_mach_h8300h;
1691 /* !! FIXME this probably isn't the right place for this */
1692 abfd->flags |= BFD_IS_RELAXABLE;
1698 arch = bfd_arch_h8300;
1699 machine = bfd_mach_h8300s;
1700 /* !! FIXME this probably isn't the right place for this */
1701 abfd->flags |= BFD_IS_RELAXABLE;
1705 #ifdef SH_ARCH_MAGIC_BIG
1706 case SH_ARCH_MAGIC_BIG:
1707 case SH_ARCH_MAGIC_LITTLE:
1715 arch = bfd_arch_h8500;
1722 #ifdef LYNXCOFFMAGIC
1725 arch = bfd_arch_sparc;
1732 arch = bfd_arch_tic30;
1736 #ifdef TIC80_ARCH_MAGIC
1737 case TIC80_ARCH_MAGIC:
1738 arch = bfd_arch_tic80;
1744 arch = bfd_arch_mcore;
1747 default: /* Unreadable input file type */
1748 arch = bfd_arch_obscure;
1752 bfd_default_set_arch_mach (abfd, arch, machine);
1756 #ifdef SYMNAME_IN_DEBUG
1758 static boolean symname_in_debug_hook
1759 PARAMS ((bfd *, struct internal_syment *));
1762 symname_in_debug_hook (abfd, sym)
1763 bfd * abfd ATTRIBUTE_UNUSED;
1764 struct internal_syment *sym;
1766 return SYMNAME_IN_DEBUG (sym) ? true : false;
1771 #define symname_in_debug_hook \
1772 (boolean (*) PARAMS ((bfd *, struct internal_syment *))) bfd_false
1778 /* Handle the csect auxent of a C_EXT or C_HIDEXT symbol. */
1780 static boolean coff_pointerize_aux_hook
1781 PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
1782 unsigned int, combined_entry_type *));
1786 coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux)
1787 bfd *abfd ATTRIBUTE_UNUSED;
1788 combined_entry_type *table_base;
1789 combined_entry_type *symbol;
1790 unsigned int indaux;
1791 combined_entry_type *aux;
1793 int class = symbol->u.syment.n_sclass;
1795 if ((class == C_EXT || class == C_HIDEXT)
1796 && indaux + 1 == symbol->u.syment.n_numaux)
1798 if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD)
1800 aux->u.auxent.x_csect.x_scnlen.p =
1801 table_base + aux->u.auxent.x_csect.x_scnlen.l;
1802 aux->fix_scnlen = 1;
1805 /* Return true to indicate that the caller should not do any
1806 further work on this auxent. */
1810 /* Return false to indicate that this auxent should be handled by
1818 /* We don't want to pointerize bal entries. */
1820 static boolean coff_pointerize_aux_hook
1821 PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
1822 unsigned int, combined_entry_type *));
1826 coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux)
1827 bfd *abfd ATTRIBUTE_UNUSED;
1828 combined_entry_type *table_base ATTRIBUTE_UNUSED;
1829 combined_entry_type *symbol;
1830 unsigned int indaux;
1831 combined_entry_type *aux ATTRIBUTE_UNUSED;
1833 /* Return true if we don't want to pointerize this aux entry, which
1834 is the case for the lastfirst aux entry for a C_LEAFPROC symbol. */
1836 && (symbol->u.syment.n_sclass == C_LEAFPROC
1837 || symbol->u.syment.n_sclass == C_LEAFSTAT
1838 || symbol->u.syment.n_sclass == C_LEAFEXT));
1843 #define coff_pointerize_aux_hook 0
1846 #endif /* ! RS6000COFF_C */
1848 /* Print an aux entry. This returns true if it has printed it. */
1850 static boolean coff_print_aux
1851 PARAMS ((bfd *, FILE *, combined_entry_type *, combined_entry_type *,
1852 combined_entry_type *, unsigned int));
1855 coff_print_aux (abfd, file, table_base, symbol, aux, indaux)
1856 bfd *abfd ATTRIBUTE_UNUSED;
1857 FILE *file ATTRIBUTE_UNUSED;
1858 combined_entry_type *table_base ATTRIBUTE_UNUSED;
1859 combined_entry_type *symbol ATTRIBUTE_UNUSED;
1860 combined_entry_type *aux ATTRIBUTE_UNUSED;
1861 unsigned int indaux ATTRIBUTE_UNUSED;
1864 if ((symbol->u.syment.n_sclass == C_EXT
1865 || symbol->u.syment.n_sclass == C_HIDEXT)
1866 && indaux + 1 == symbol->u.syment.n_numaux)
1868 /* This is a csect entry. */
1869 fprintf (file, "AUX ");
1870 if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
1872 BFD_ASSERT (! aux->fix_scnlen);
1873 fprintf (file, "val %5ld", aux->u.auxent.x_csect.x_scnlen.l);
1877 fprintf (file, "indx ");
1878 if (! aux->fix_scnlen)
1879 fprintf (file, "%4ld", aux->u.auxent.x_csect.x_scnlen.l);
1881 fprintf (file, "%4ld",
1882 (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
1885 " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u",
1886 aux->u.auxent.x_csect.x_parmhash,
1887 (unsigned int) aux->u.auxent.x_csect.x_snhash,
1888 SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
1889 SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
1890 (unsigned int) aux->u.auxent.x_csect.x_smclas,
1891 aux->u.auxent.x_csect.x_stab,
1892 (unsigned int) aux->u.auxent.x_csect.x_snstab);
1897 /* Return false to indicate that no special action was taken. */
1905 To write relocations, the back end steps though the
1906 canonical relocation table and create an
1907 @code{internal_reloc}. The symbol index to use is removed from
1908 the @code{offset} field in the symbol table supplied. The
1909 address comes directly from the sum of the section base
1910 address and the relocation offset; the type is dug directly
1911 from the howto field. Then the @code{internal_reloc} is
1912 swapped into the shape of an @code{external_reloc} and written
1919 static int compare_arelent_ptr PARAMS ((const PTR, const PTR));
1921 /* AUX's ld wants relocations to be sorted */
1923 compare_arelent_ptr (x, y)
1927 const arelent **a = (const arelent **) x;
1928 const arelent **b = (const arelent **) y;
1929 bfd_size_type aadr = (*a)->address;
1930 bfd_size_type badr = (*b)->address;
1932 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
1935 #endif /* TARG_AUX */
1938 coff_write_relocs (abfd, first_undef)
1944 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1947 struct external_reloc dst;
1953 /* sort relocations before we write them out */
1954 p = (arelent **) bfd_malloc (s->reloc_count * sizeof (arelent *));
1955 if (p == NULL && s->reloc_count > 0)
1957 memcpy (p, s->orelocation, s->reloc_count * sizeof (arelent *));
1958 qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
1961 if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
1963 for (i = 0; i < s->reloc_count; i++)
1965 struct internal_reloc n;
1967 memset ((PTR) & n, 0, sizeof (n));
1969 /* Now we've renumbered the symbols we know where the
1970 undefined symbols live in the table. Check the reloc
1971 entries for symbols who's output bfd isn't the right one.
1972 This is because the symbol was undefined (which means
1973 that all the pointers are never made to point to the same
1974 place). This is a bad thing,'cause the symbols attached
1975 to the output bfd are indexed, so that the relocation
1976 entries know which symbol index they point to. So we
1977 have to look up the output symbol here. */
1979 if (q->sym_ptr_ptr[0]->the_bfd != abfd)
1982 const char *sname = q->sym_ptr_ptr[0]->name;
1983 asymbol **outsyms = abfd->outsymbols;
1984 for (i = first_undef; outsyms[i]; i++)
1986 const char *intable = outsyms[i]->name;
1987 if (strcmp (intable, sname) == 0) {
1988 /* got a hit, so repoint the reloc */
1989 q->sym_ptr_ptr = outsyms + i;
1995 n.r_vaddr = q->address + s->vma;
1998 /* The 29k const/consth reloc pair is a real kludge. The consth
1999 part doesn't have a symbol; it has an offset. So rebuilt
2001 if (q->howto->type == R_IHCONST)
2002 n.r_symndx = q->addend;
2007 if (q->sym_ptr_ptr == bfd_abs_section_ptr->symbol_ptr_ptr)
2008 /* This is a relocation relative to the absolute symbol. */
2012 n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2013 /* Take notice if the symbol reloc points to a symbol
2014 we don't have in our symbol table. What should we
2016 if (n.r_symndx > obj_conv_table_size (abfd))
2021 #ifdef SWAP_OUT_RELOC_OFFSET
2022 n.r_offset = q->addend;
2026 /* Work out reloc type from what is required */
2027 SELECT_RELOC (n, q->howto);
2029 n.r_type = q->howto->type;
2031 coff_swap_reloc_out (abfd, &n, &dst);
2032 if (bfd_write ((PTR) & dst, 1, RELSZ, abfd) != RELSZ)
2045 /* Set flags and magic number of a coff file from architecture and machine
2046 type. Result is true if we can represent the arch&type, false if not. */
2049 coff_set_flags (abfd, magicp, flagsp)
2051 unsigned int *magicp ATTRIBUTE_UNUSED;
2052 unsigned short *flagsp ATTRIBUTE_UNUSED;
2054 switch (bfd_get_arch (abfd))
2059 switch (bfd_get_mach (abfd))
2061 case bfd_mach_z8001:
2064 case bfd_mach_z8002:
2078 *magicp = I960ROMAGIC;
2080 ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC :
2081 I960RWMAGIC); FIXME???
2083 switch (bfd_get_mach (abfd))
2085 case bfd_mach_i960_core:
2088 case bfd_mach_i960_kb_sb:
2091 case bfd_mach_i960_mc:
2094 case bfd_mach_i960_xa:
2097 case bfd_mach_i960_ca:
2100 case bfd_mach_i960_ka_sa:
2103 case bfd_mach_i960_jx:
2106 case bfd_mach_i960_hx:
2119 case bfd_arch_tic30:
2120 *magicp = TIC30MAGIC;
2123 #ifdef TIC80_ARCH_MAGIC
2124 case bfd_arch_tic80:
2125 *magicp = TIC80_ARCH_MAGIC;
2130 * magicp = ARMMAGIC;
2132 if (APCS_SET (abfd))
2134 if (APCS_26_FLAG (abfd))
2135 * flagsp |= F_APCS26;
2137 if (APCS_FLOAT_FLAG (abfd))
2138 * flagsp |= F_APCS_FLOAT;
2140 if (PIC_FLAG (abfd))
2143 if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2144 * flagsp |= F_INTERWORK;
2145 switch (bfd_get_mach (abfd))
2147 case bfd_mach_arm_2: * flagsp |= F_ARM_2; break;
2148 case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2149 case bfd_mach_arm_3: * flagsp |= F_ARM_3; break;
2150 case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2151 case bfd_mach_arm_4: * flagsp |= F_ARM_4; break;
2152 case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2153 case bfd_mach_arm_5: * flagsp |= F_ARM_5; break;
2154 case bfd_mach_arm_5T: * flagsp |= F_ARM_5; break; /* XXX - we do not have an F_ARM_5T */
2159 case bfd_arch_powerpc:
2166 *magicp = I386MAGIC;
2168 /* Just overwrite the usual value if we're doing Lynx. */
2169 *magicp = LYNXCOFFMAGIC;
2176 *magicp = I860MAGIC;
2182 #ifdef APOLLOM68KMAGIC
2183 *magicp = APOLLO_COFF_VERSION_NUMBER;
2185 /* NAMES_HAVE_UNDERSCORE may be defined by coff-u68k.c. */
2186 #ifdef NAMES_HAVE_UNDERSCORE
2187 *magicp = MC68KBCSMAGIC;
2189 *magicp = MC68MAGIC;
2193 /* Just overwrite the usual value if we're doing Lynx. */
2194 *magicp = LYNXCOFFMAGIC;
2202 *magicp = MC88OMAGIC;
2207 case bfd_arch_h8300:
2208 switch (bfd_get_mach (abfd))
2210 case bfd_mach_h8300:
2211 *magicp = H8300MAGIC;
2213 case bfd_mach_h8300h:
2214 *magicp = H8300HMAGIC;
2216 case bfd_mach_h8300s:
2217 *magicp = H8300SMAGIC;
2223 #ifdef SH_ARCH_MAGIC_BIG
2225 if (bfd_big_endian (abfd))
2226 *magicp = SH_ARCH_MAGIC_BIG;
2228 *magicp = SH_ARCH_MAGIC_LITTLE;
2234 case bfd_arch_sparc:
2235 *magicp = SPARCMAGIC;
2237 /* Just overwrite the usual value if we're doing Lynx. */
2238 *magicp = LYNXCOFFMAGIC;
2245 case bfd_arch_h8500:
2246 *magicp = H8500MAGIC;
2250 #ifdef A29K_MAGIC_BIG
2252 if (bfd_big_endian (abfd))
2253 *magicp = A29K_MAGIC_BIG;
2255 *magicp = A29K_MAGIC_LITTLE;
2261 case bfd_arch_we32k:
2262 *magicp = WE32KMAGIC;
2268 case bfd_arch_rs6000:
2270 case bfd_arch_powerpc:
2272 *magicp = U802TOCMAGIC;
2278 case bfd_arch_mcore:
2279 * magicp = MCOREMAGIC;
2283 default: /* Unknown architecture */
2284 /* return false; -- fall through to "return false" below, to avoid
2285 "statement never reached" errors on the one below. */
2294 coff_set_arch_mach (abfd, arch, machine)
2296 enum bfd_architecture arch;
2297 unsigned long machine;
2300 unsigned short dummy2;
2302 if (! bfd_default_set_arch_mach (abfd, arch, machine))
2305 if (arch != bfd_arch_unknown &&
2306 coff_set_flags (abfd, &dummy1, &dummy2) != true)
2307 return false; /* We can't represent this type */
2309 return true; /* We're easy ... */
2313 /* Calculate the file position for each section. */
2316 #define ALIGN_SECTIONS_IN_FILE
2319 #undef ALIGN_SECTIONS_IN_FILE
2323 coff_compute_section_file_positions (abfd)
2327 asection *previous = (asection *) NULL;
2328 file_ptr sofar = FILHSZ;
2329 boolean align_adjust;
2331 #ifdef ALIGN_SECTIONS_IN_FILE
2336 /* On XCOFF, if we have symbols, set up the .debug section. */
2337 if (bfd_get_symcount (abfd) > 0)
2340 bfd_size_type i, symcount;
2344 symcount = bfd_get_symcount (abfd);
2345 for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
2347 coff_symbol_type *cf;
2349 cf = coff_symbol_from (abfd, *symp);
2351 && cf->native != NULL
2352 && SYMNAME_IN_DEBUG (&cf->native->u.syment))
2356 len = strlen (bfd_asymbol_name (*symp));
2365 dsec = bfd_make_section_old_way (abfd, ".debug");
2368 dsec->_raw_size = sz;
2369 dsec->flags |= SEC_HAS_CONTENTS;
2374 #ifdef COFF_IMAGE_WITH_PE
2376 if (coff_data (abfd)->link_info)
2378 page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2381 page_size = PE_DEF_FILE_ALIGNMENT;
2383 #ifdef COFF_PAGE_SIZE
2384 int page_size = COFF_PAGE_SIZE;
2388 if (bfd_get_start_address (abfd))
2390 /* A start address may have been added to the original file. In this
2391 case it will need an optional header to record it. */
2392 abfd->flags |= EXEC_P;
2395 if (abfd->flags & EXEC_P)
2398 else if (xcoff_data (abfd)->full_aouthdr)
2401 sofar += SMALL_AOUTSZ;
2404 sofar += abfd->section_count * SCNHSZ;
2407 /* XCOFF handles overflows in the reloc and line number count fields
2408 by allocating a new section header to hold the correct counts. */
2409 for (current = abfd->sections; current != NULL; current = current->next)
2410 if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
2414 align_adjust = false;
2415 for (current = abfd->sections, count = 1;
2416 current != (asection *) NULL;
2417 current = current->next, ++count)
2419 #ifdef COFF_IMAGE_WITH_PE
2420 /* The NT loader does not want empty section headers, so we omit
2421 them. We don't actually remove the section from the BFD,
2422 although we probably should. This matches code in
2423 coff_write_object_contents. */
2424 if (current->_raw_size == 0)
2426 current->target_index = -1;
2432 current->target_index = count;
2434 /* Only deal with sections which have contents */
2435 if (!(current->flags & SEC_HAS_CONTENTS))
2438 /* Align the sections in the file to the same boundary on
2439 which they are aligned in virtual memory. I960 doesn't
2440 do this (FIXME) so we can stay in sync with Intel. 960
2441 doesn't yet page from files... */
2442 #ifdef ALIGN_SECTIONS_IN_FILE
2443 if ((abfd->flags & EXEC_P) != 0)
2445 /* make sure this section is aligned on the right boundary - by
2446 padding the previous section up if necessary */
2449 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
2450 if (previous != (asection *) NULL)
2452 previous->_raw_size += sofar - old_sofar;
2458 /* In demand paged files the low order bits of the file offset
2459 must match the low order bits of the virtual address. */
2460 #ifdef COFF_PAGE_SIZE
2461 if ((abfd->flags & D_PAGED) != 0
2462 && (current->flags & SEC_ALLOC) != 0)
2463 sofar += (current->vma - sofar) % page_size;
2465 current->filepos = sofar;
2467 #ifdef COFF_IMAGE_WITH_PE
2468 /* With PE we have to pad each section to be a multiple of its
2469 page size too, and remember both sizes. */
2471 if (coff_section_data (abfd, current) == NULL)
2473 current->used_by_bfd =
2474 (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
2475 if (current->used_by_bfd == NULL)
2478 if (pei_section_data (abfd, current) == NULL)
2480 coff_section_data (abfd, current)->tdata =
2481 (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata));
2482 if (coff_section_data (abfd, current)->tdata == NULL)
2485 if (pei_section_data (abfd, current)->virt_size == 0)
2486 pei_section_data (abfd, current)->virt_size = current->_raw_size;
2488 current->_raw_size = (current->_raw_size + page_size -1) & -page_size;
2491 sofar += current->_raw_size;
2493 #ifdef ALIGN_SECTIONS_IN_FILE
2494 /* make sure that this section is of the right size too */
2495 if ((abfd->flags & EXEC_P) == 0)
2497 bfd_size_type old_size;
2499 old_size = current->_raw_size;
2500 current->_raw_size = BFD_ALIGN (current->_raw_size,
2501 1 << current->alignment_power);
2502 align_adjust = current->_raw_size != old_size;
2503 sofar += current->_raw_size - old_size;
2508 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
2509 align_adjust = sofar != old_sofar;
2510 current->_raw_size += sofar - old_sofar;
2514 #ifdef COFF_IMAGE_WITH_PE
2515 /* For PE we need to make sure we pad out to the aligned
2516 _raw_size, in case the caller only writes out data to the
2517 unaligned _raw_size. */
2518 if (pei_section_data (abfd, current)->virt_size < current->_raw_size)
2519 align_adjust = true;
2523 /* Force .lib sections to start at zero. The vma is then
2524 incremented in coff_set_section_contents. This is right for
2526 if (strcmp (current->name, _LIB) == 0)
2527 bfd_set_section_vma (abfd, current, 0);
2533 /* It is now safe to write to the output file. If we needed an
2534 alignment adjustment for the last section, then make sure that
2535 there is a byte at offset sofar. If there are no symbols and no
2536 relocs, then nothing follows the last section. If we don't force
2537 the last byte out, then the file may appear to be truncated. */
2543 if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
2544 || bfd_write (&b, 1, 1, abfd) != 1)
2548 /* Make sure the relocations are aligned. We don't need to make
2549 sure that this byte exists, because it will only matter if there
2550 really are relocs. */
2551 sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
2553 obj_relocbase (abfd) = sofar;
2554 abfd->output_has_begun = true;
2561 /* This can never work, because it is called too late--after the
2562 section positions have been set. I can't figure out what it is
2563 for, so I am going to disable it--Ian Taylor 20 March 1996. */
2565 /* If .file, .text, .data, .bss symbols are missing, add them. */
2566 /* @@ Should we only be adding missing symbols, or overriding the aux
2567 values for existing section symbols? */
2569 coff_add_missing_symbols (abfd)
2572 unsigned int nsyms = bfd_get_symcount (abfd);
2573 asymbol **sympp = abfd->outsymbols;
2576 int need_text = 1, need_data = 1, need_bss = 1, need_file = 1;
2578 for (i = 0; i < nsyms; i++)
2580 coff_symbol_type *csym = coff_symbol_from (abfd, sympp[i]);
2584 /* only do this if there is a coff representation of the input
2586 if (csym->native && csym->native->u.syment.n_sclass == C_FILE)
2591 name = csym->symbol.name;
2594 if (!strcmp (name, _TEXT))
2597 else if (!strcmp (name, ".wtext"))
2600 else if (!strcmp (name, _DATA))
2602 else if (!strcmp (name, _BSS))
2606 /* Now i == bfd_get_symcount (abfd). */
2607 /* @@ For now, don't deal with .file symbol. */
2610 if (!need_text && !need_data && !need_bss && !need_file)
2612 nsyms += need_text + need_data + need_bss + need_file;
2613 sympp2 = (asymbol **) bfd_alloc (abfd, nsyms * sizeof (asymbol *));
2616 memcpy (sympp2, sympp, i * sizeof (asymbol *));
2619 /* @@ Generate fake .file symbol, in sympp2[i], and increment i. */
2623 sympp2[i++] = coff_section_symbol (abfd, _TEXT);
2625 sympp2[i++] = coff_section_symbol (abfd, _DATA);
2627 sympp2[i++] = coff_section_symbol (abfd, _BSS);
2628 BFD_ASSERT (i == nsyms);
2629 bfd_set_symtab (abfd, sympp2, nsyms);
2638 coff_write_object_contents (abfd)
2642 boolean hasrelocs = false;
2643 boolean haslinno = false;
2645 file_ptr reloc_base;
2646 file_ptr lineno_base;
2648 unsigned long reloc_size = 0;
2649 unsigned long lnno_size = 0;
2650 boolean long_section_names;
2651 asection *text_sec = NULL;
2652 asection *data_sec = NULL;
2653 asection *bss_sec = NULL;
2654 struct internal_filehdr internal_f;
2655 struct internal_aouthdr internal_a;
2656 #ifdef COFF_LONG_SECTION_NAMES
2657 size_t string_size = STRING_SIZE_SIZE;
2660 bfd_set_error (bfd_error_system_call);
2662 /* Make a pass through the symbol table to count line number entries and
2663 put them into the correct asections */
2665 lnno_size = coff_count_linenumbers (abfd) * LINESZ;
2667 if (abfd->output_has_begun == false)
2669 if (! coff_compute_section_file_positions (abfd))
2673 reloc_base = obj_relocbase (abfd);
2675 /* Work out the size of the reloc and linno areas */
2677 for (current = abfd->sections; current != NULL; current =
2679 reloc_size += current->reloc_count * RELSZ;
2681 lineno_base = reloc_base + reloc_size;
2682 sym_base = lineno_base + lnno_size;
2684 /* Indicate in each section->line_filepos its actual file address */
2685 for (current = abfd->sections; current != NULL; current =
2688 if (current->lineno_count)
2690 current->line_filepos = lineno_base;
2691 current->moving_line_filepos = lineno_base;
2692 lineno_base += current->lineno_count * LINESZ;
2696 current->line_filepos = 0;
2698 if (current->reloc_count)
2700 current->rel_filepos = reloc_base;
2701 reloc_base += current->reloc_count * RELSZ;
2705 current->rel_filepos = 0;
2709 /* Write section headers to the file. */
2710 internal_f.f_nscns = 0;
2712 if ((abfd->flags & EXEC_P) != 0)
2713 scn_base = FILHSZ + AOUTSZ;
2718 if (xcoff_data (abfd)->full_aouthdr)
2721 scn_base += SMALL_AOUTSZ;
2725 if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
2728 long_section_names = false;
2729 for (current = abfd->sections;
2731 current = current->next)
2733 struct internal_scnhdr section;
2736 /* If we've got a .reloc section, remember. */
2738 #ifdef COFF_IMAGE_WITH_PE
2739 if (strcmp (current->name, ".reloc") == 0)
2741 pe_data (abfd)->has_reloc_section = 1;
2746 internal_f.f_nscns++;
2748 strncpy (section.s_name, current->name, SCNNMLEN);
2750 #ifdef COFF_LONG_SECTION_NAMES
2751 /* Handle long section names as in PE. This must be compatible
2752 with the code in coff_write_symbols. */
2756 len = strlen (current->name);
2759 memset (section.s_name, 0, SCNNMLEN);
2760 sprintf (section.s_name, "/%lu", (unsigned long) string_size);
2761 string_size += len + 1;
2762 long_section_names = true;
2768 /* Always set s_vaddr of .lib to 0. This is right for SVR3.2
2769 Ian Taylor <ian@cygnus.com>. */
2770 if (strcmp (current->name, _LIB) == 0)
2771 section.s_vaddr = 0;
2774 section.s_vaddr = current->vma;
2775 section.s_paddr = current->lma;
2776 section.s_size = current->_raw_size;
2779 section.s_paddr = 0;
2781 #ifdef COFF_IMAGE_WITH_PE
2782 /* Reminder: s_paddr holds the virtual size of the section. */
2783 if (coff_section_data (abfd, current) != NULL
2784 && pei_section_data (abfd, current) != NULL)
2785 section.s_paddr = pei_section_data (abfd, current)->virt_size;
2787 section.s_paddr = 0;
2791 If this section has no size or is unloadable then the scnptr
2794 if (current->_raw_size == 0 ||
2795 (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2797 section.s_scnptr = 0;
2801 section.s_scnptr = current->filepos;
2803 section.s_relptr = current->rel_filepos;
2804 section.s_lnnoptr = current->line_filepos;
2805 section.s_nreloc = current->reloc_count;
2806 section.s_nlnno = current->lineno_count;
2807 if (current->reloc_count != 0)
2809 if (current->lineno_count != 0)
2813 /* Indicate the use of an XCOFF overflow section header. */
2814 if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
2816 section.s_nreloc = 0xffff;
2817 section.s_nlnno = 0xffff;
2821 section.s_flags = sec_to_styp_flags (current->name, current->flags);
2823 if (!strcmp (current->name, _TEXT))
2827 else if (!strcmp (current->name, _DATA))
2831 else if (!strcmp (current->name, _BSS))
2837 section.s_align = (current->alignment_power
2838 ? 1 << current->alignment_power
2842 section.s_flags |= (current->alignment_power & 0xF) << 8;
2846 #ifdef COFF_IMAGE_WITH_PE
2847 /* suppress output of the sections if they are null. ld includes
2848 the bss and data sections even if there is no size assigned
2849 to them. NT loader doesn't like it if these section headers are
2850 included if the sections themselves are not needed */
2851 if (section.s_size == 0)
2852 internal_f.f_nscns--;
2857 if (coff_swap_scnhdr_out (abfd, §ion, &buff) == 0
2858 || bfd_write ((PTR) (&buff), 1, SCNHSZ, abfd) != SCNHSZ)
2863 /* PE stores COMDAT section information in the symbol table. If
2864 this section is supposed to have some COMDAT info, track down
2865 the symbol in the symbol table and modify it. */
2866 if ((current->flags & SEC_LINK_ONCE) != 0)
2868 unsigned int i, count;
2870 coff_symbol_type *csym = NULL;
2874 count = bfd_get_symcount (abfd);
2875 for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
2877 if ((*psym)->section != current)
2880 /* Remember the location of the first symbol in this
2882 if (psymsec == NULL)
2885 /* See if this is the section symbol. */
2886 if (strcmp ((*psym)->name, current->name) == 0)
2888 csym = coff_symbol_from (abfd, *psym);
2890 || csym->native == NULL
2891 || csym->native->u.syment.n_numaux < 1
2892 || csym->native->u.syment.n_sclass != C_STAT
2893 || csym->native->u.syment.n_type != T_NULL)
2896 /* Here *PSYM is the section symbol for CURRENT. */
2903 Note that we might not if we're converting the file from
2904 some other object file format. */
2907 combined_entry_type *aux;
2909 /* We don't touch the x_checksum field. The
2910 x_associated field is not currently supported. */
2912 aux = csym->native + 1;
2913 switch (current->flags & SEC_LINK_DUPLICATES)
2915 case SEC_LINK_DUPLICATES_DISCARD:
2916 aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
2919 case SEC_LINK_DUPLICATES_ONE_ONLY:
2920 aux->u.auxent.x_scn.x_comdat =
2921 IMAGE_COMDAT_SELECT_NODUPLICATES;
2924 case SEC_LINK_DUPLICATES_SAME_SIZE:
2925 aux->u.auxent.x_scn.x_comdat =
2926 IMAGE_COMDAT_SELECT_SAME_SIZE;
2929 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
2930 aux->u.auxent.x_scn.x_comdat =
2931 IMAGE_COMDAT_SELECT_EXACT_MATCH;
2935 /* The COMDAT symbol must be the first symbol from this
2936 section in the symbol table. In order to make this
2937 work, we move the COMDAT symbol before the first
2938 symbol we found in the search above. It's OK to
2939 rearrange the symbol table at this point, because
2940 coff_renumber_symbols is going to rearrange it
2941 further and fix up all the aux entries. */
2942 if (psym != psymsec)
2948 for (pcopy = psym; pcopy > psymsec; pcopy--)
2949 pcopy[0] = pcopy[-1];
2954 #endif /* COFF_WITH_PE */
2958 /* XCOFF handles overflows in the reloc and line number count fields
2959 by creating a new section header to hold the correct values. */
2960 for (current = abfd->sections; current != NULL; current = current->next)
2962 if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
2964 struct internal_scnhdr scnhdr;
2967 internal_f.f_nscns++;
2968 strncpy (&(scnhdr.s_name[0]), current->name, 8);
2969 scnhdr.s_paddr = current->reloc_count;
2970 scnhdr.s_vaddr = current->lineno_count;
2972 scnhdr.s_scnptr = 0;
2973 scnhdr.s_relptr = current->rel_filepos;
2974 scnhdr.s_lnnoptr = current->line_filepos;
2975 scnhdr.s_nreloc = current->target_index;
2976 scnhdr.s_nlnno = current->target_index;
2977 scnhdr.s_flags = STYP_OVRFLO;
2978 if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
2979 || bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ)
2985 /* OK, now set up the filehdr... */
2987 /* Don't include the internal abs section in the section count */
2990 We will NOT put a fucking timestamp in the header here. Every time you
2991 put it back, I will come in and take it out again. I'm sorry. This
2992 field does not belong here. We fill it with a 0 so it compares the
2993 same but is not a reasonable time. -- gnu@cygnus.com
2995 internal_f.f_timdat = 0;
2997 internal_f.f_flags = 0;
2999 if (abfd->flags & EXEC_P)
3000 internal_f.f_opthdr = AOUTSZ;
3003 internal_f.f_opthdr = 0;
3005 if (xcoff_data (abfd)->full_aouthdr)
3006 internal_f.f_opthdr = AOUTSZ;
3008 internal_f.f_opthdr = SMALL_AOUTSZ;
3013 internal_f.f_flags |= F_RELFLG;
3015 internal_f.f_flags |= F_LNNO;
3016 if (abfd->flags & EXEC_P)
3017 internal_f.f_flags |= F_EXEC;
3019 /* FIXME: this is wrong for PPC_PE! */
3020 if (bfd_little_endian (abfd))
3021 internal_f.f_flags |= F_AR32WR;
3023 internal_f.f_flags |= F_AR32W;
3025 #ifdef TIC80_TARGET_ID
3026 internal_f.f_target_id = TIC80_TARGET_ID;
3030 FIXME, should do something about the other byte orders and
3035 if ((abfd->flags & DYNAMIC) != 0)
3036 internal_f.f_flags |= F_SHROBJ;
3037 if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
3038 internal_f.f_flags |= F_DYNLOAD;
3041 memset (&internal_a, 0, sizeof internal_a);
3043 /* Set up architecture-dependent stuff */
3046 unsigned int magic = 0;
3047 unsigned short flags = 0;
3048 coff_set_flags (abfd, &magic, &flags);
3049 internal_f.f_magic = magic;
3050 internal_f.f_flags |= flags;
3051 /* ...and the "opt"hdr... */
3054 #ifdef ULTRA3 /* NYU's machine */
3055 /* FIXME: This is a bogus check. I really want to see if there
3056 * is a .shbss or a .shdata section, if so then set the magic
3057 * number to indicate a shared data executable.
3059 if (internal_f.f_nscns >= 7)
3060 internal_a.magic = SHMAGIC; /* Shared magic */
3063 internal_a.magic = NMAGIC; /* Assume separate i/d */
3064 #define __A_MAGIC_SET__
3067 internal_a.magic = TIC80_ARCH_MAGIC;
3068 #define __A_MAGIC_SET__
3071 /* FIXME: What are the a.out magic numbers for the i860? */
3072 internal_a.magic = 0;
3073 #define __A_MAGIC_SET__
3076 internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
3077 #define __A_MAGIC_SET__
3080 #define __A_MAGIC_SET__
3081 internal_a.magic = PAGEMAGICBCS;
3085 #define __A_MAGIC_SET__
3086 internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
3089 #if defined(M68) || defined(WE32K) || defined(M68K)
3090 #define __A_MAGIC_SET__
3092 internal_a.magic = LYNXCOFFMAGIC;
3094 #if defined(TARG_AUX)
3095 internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED :
3096 abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED :
3097 PAGEMAGICEXECSWAPPED);
3099 #if defined (PAGEMAGICPEXECPAGED)
3100 internal_a.magic = PAGEMAGICPEXECPAGED;
3102 #endif /* TARG_AUX */
3104 #endif /* M68 || WE32K || M68K */
3107 #define __A_MAGIC_SET__
3108 internal_a.magic = ZMAGIC;
3112 #define __A_MAGIC_SET__
3113 internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
3116 #if defined MCORE_PE
3117 #define __A_MAGIC_SET__
3118 internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
3122 #define __A_MAGIC_SET__
3124 internal_a.magic = LYNXCOFFMAGIC;
3126 internal_a.magic = ZMAGIC;
3131 #define __A_MAGIC_SET__
3133 internal_a.magic = LYNXCOFFMAGIC;
3138 #define __A_MAGIC_SET__
3139 internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
3140 (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
3141 RS6K_AOUTHDR_OMAGIC;
3144 #ifndef __A_MAGIC_SET__
3145 #include "Your aouthdr magic number is not being set!"
3147 #undef __A_MAGIC_SET__
3151 /* FIXME: Does anybody ever set this to another value? */
3152 internal_a.vstamp = 0;
3154 /* Now should write relocs, strings, syms */
3155 obj_sym_filepos (abfd) = sym_base;
3157 if (bfd_get_symcount (abfd) != 0)
3161 if (!coff_add_missing_symbols (abfd))
3164 if (!coff_renumber_symbols (abfd, &firstundef))
3166 coff_mangle_symbols (abfd);
3167 if (! coff_write_symbols (abfd))
3169 if (! coff_write_linenumbers (abfd))
3171 if (! coff_write_relocs (abfd, firstundef))
3174 #ifdef COFF_LONG_SECTION_NAMES
3175 else if (long_section_names)
3177 /* If we have long section names we have to write out the string
3178 table even if there are no symbols. */
3179 if (! coff_write_symbols (abfd))
3183 #ifdef COFF_IMAGE_WITH_PE
3185 else if ((abfd->flags & EXEC_P) != 0)
3189 /* PowerPC PE appears to require that all executable files be
3190 rounded up to the page size. */
3193 BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
3195 || bfd_write (&b, 1, 1, abfd) != 1)
3201 /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
3202 backend linker, and obj_raw_syment_count is not valid until after
3203 coff_write_symbols is called. */
3204 if (obj_raw_syment_count (abfd) != 0)
3206 internal_f.f_symptr = sym_base;
3208 /* AIX appears to require that F_RELFLG not be set if there are
3209 local symbols but no relocations. */
3210 internal_f.f_flags &=~ F_RELFLG;
3215 if (long_section_names)
3216 internal_f.f_symptr = sym_base;
3218 internal_f.f_symptr = 0;
3219 internal_f.f_flags |= F_LSYMS;
3224 internal_a.tsize = bfd_get_section_size_before_reloc (text_sec);
3225 internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
3229 internal_a.dsize = bfd_get_section_size_before_reloc (data_sec);
3230 internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
3234 internal_a.bsize = bfd_get_section_size_before_reloc (bss_sec);
3235 if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
3236 internal_a.data_start = bss_sec->vma;
3239 internal_a.entry = bfd_get_start_address (abfd);
3240 internal_f.f_nsyms = obj_raw_syment_count (abfd);
3243 if (xcoff_data (abfd)->full_aouthdr)
3246 asection *loader_sec;
3248 internal_a.vstamp = 1;
3250 internal_a.o_snentry = xcoff_data (abfd)->snentry;
3251 if (internal_a.o_snentry == 0)
3252 internal_a.entry = (bfd_vma) -1;
3254 if (text_sec != NULL)
3256 internal_a.o_sntext = text_sec->target_index;
3257 internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
3261 internal_a.o_sntext = 0;
3262 internal_a.o_algntext = 0;
3264 if (data_sec != NULL)
3266 internal_a.o_sndata = data_sec->target_index;
3267 internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
3271 internal_a.o_sndata = 0;
3272 internal_a.o_algndata = 0;
3274 loader_sec = bfd_get_section_by_name (abfd, ".loader");
3275 if (loader_sec != NULL)
3276 internal_a.o_snloader = loader_sec->target_index;
3278 internal_a.o_snloader = 0;
3279 if (bss_sec != NULL)
3280 internal_a.o_snbss = bss_sec->target_index;
3282 internal_a.o_snbss = 0;
3284 toc = xcoff_data (abfd)->toc;
3285 internal_a.o_toc = toc;
3286 internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
3288 internal_a.o_modtype = xcoff_data (abfd)->modtype;
3289 if (xcoff_data (abfd)->cputype != -1)
3290 internal_a.o_cputype = xcoff_data (abfd)->cputype;
3293 switch (bfd_get_arch (abfd))
3295 case bfd_arch_rs6000:
3296 internal_a.o_cputype = 4;
3298 case bfd_arch_powerpc:
3299 if (bfd_get_mach (abfd) == 0)
3300 internal_a.o_cputype = 3;
3302 internal_a.o_cputype = 1;
3308 internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
3309 internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
3313 /* now write them */
3314 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3318 coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) buff);
3319 if (bfd_write ((PTR) buff, 1, FILHSZ, abfd) != FILHSZ)
3322 if (abfd->flags & EXEC_P)
3324 /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
3325 include/coff/pe.h sets AOUTSZ == sizeof(PEAOUTHDR)) */
3327 coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff);
3328 if (bfd_write ((PTR) buff, 1, AOUTSZ, abfd) != AOUTSZ)
3337 /* XCOFF seems to always write at least a small a.out header. */
3338 coff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff);
3339 if (xcoff_data (abfd)->full_aouthdr)
3342 size = SMALL_AOUTSZ;
3343 if (bfd_write ((PTR) &buff, 1, size, abfd) != size)
3352 coff_set_section_contents (abfd, section, location, offset, count)
3357 bfd_size_type count;
3359 if (abfd->output_has_begun == false) /* set by bfd.c handler */
3361 if (! coff_compute_section_file_positions (abfd))
3365 #if defined(_LIB) && !defined(TARG_AUX)
3367 /* The physical address field of a .lib section is used to hold the
3368 number of shared libraries in the section. This code counts the
3369 number of sections being written, and increments the lma field
3372 I have found no documentation on the contents of this section.
3373 Experimentation indicates that the section contains zero or more
3374 records, each of which has the following structure:
3376 - a (four byte) word holding the length of this record, in words,
3377 - a word that always seems to be set to "2",
3378 - the path to a shared library, null-terminated and then padded
3379 to a whole word boundary.
3381 bfd_assert calls have been added to alert if an attempt is made
3382 to write a section which doesn't follow these assumptions. The
3383 code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
3384 <robertl@arnet.com> (Thanks!).
3386 Gvran Uddeborg <gvran@uddeborg.pp.se> */
3388 if (strcmp (section->name, _LIB) == 0)
3390 bfd_byte *rec, *recend;
3392 rec = (bfd_byte *) location;
3393 recend = rec + count;
3394 while (rec < recend)
3397 rec += bfd_get_32 (abfd, rec) * 4;
3400 BFD_ASSERT (rec == recend);
3405 /* Don't write out bss sections - one way to do this is to
3406 see if the filepos has not been set. */
3407 if (section->filepos == 0)
3410 if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) != 0)
3415 return (bfd_write (location, 1, count, abfd) == count) ? true : false;
3421 coff_close_and_cleanup (abfd)
3424 if (!bfd_read_p (abfd))
3425 switch (abfd->format)
3428 if (!_bfd_write_archive_contents (abfd))
3432 if (!coff_write_object_contents (abfd))
3436 bfd_set_error (bfd_error_invalid_operation);
3440 /* We depend on bfd_close to free all the memory on the objalloc. */
3447 buy_and_read (abfd, where, seek_direction, size)
3453 PTR area = (PTR) bfd_alloc (abfd, size);
3456 if (bfd_seek (abfd, where, seek_direction) != 0
3457 || bfd_read (area, 1, size, abfd) != size)
3460 } /* buy_and_read() */
3466 Creating the linenumber table is done by reading in the entire
3467 coff linenumber table, and creating another table for internal use.
3469 A coff linenumber table is structured so that each function
3470 is marked as having a line number of 0. Each line within the
3471 function is an offset from the first line in the function. The
3472 base of the line number information for the table is stored in
3473 the symbol associated with the function.
3475 The information is copied from the external to the internal
3476 table, and each symbol which marks a function is marked by
3479 How does this work ?
3484 coff_slurp_line_table (abfd, asect)
3488 LINENO *native_lineno;
3489 alent *lineno_cache;
3491 BFD_ASSERT (asect->lineno == (alent *) NULL);
3493 native_lineno = (LINENO *) buy_and_read (abfd,
3494 asect->line_filepos,
3497 asect->lineno_count));
3499 (alent *) bfd_alloc (abfd, (size_t) ((asect->lineno_count + 1) * sizeof (alent)));
3500 if (lineno_cache == NULL)
3504 unsigned int counter = 0;
3505 alent *cache_ptr = lineno_cache;
3506 LINENO *src = native_lineno;
3508 while (counter < asect->lineno_count)
3510 struct internal_lineno dst;
3511 coff_swap_lineno_in (abfd, src, &dst);
3512 cache_ptr->line_number = dst.l_lnno;
3514 if (cache_ptr->line_number == 0)
3518 coff_symbol_type *sym;
3521 symndx = dst.l_addr.l_symndx;
3523 || (unsigned long) symndx >= obj_raw_syment_count (abfd))
3525 (*_bfd_error_handler)
3526 (_("%s: warning: illegal symbol index %ld in line numbers"),
3527 bfd_get_filename (abfd), dst.l_addr.l_symndx);
3531 /* FIXME: We should not be casting between ints and
3532 pointers like this. */
3533 sym = ((coff_symbol_type *)
3534 ((symndx + obj_raw_syments (abfd))
3535 ->u.syment._n._n_n._n_zeroes));
3536 cache_ptr->u.sym = (asymbol *) sym;
3537 if (sym->lineno != NULL && ! warned)
3539 (*_bfd_error_handler)
3540 (_("%s: warning: duplicate line number information for `%s'"),
3541 bfd_get_filename (abfd),
3542 bfd_asymbol_name (&sym->symbol));
3544 sym->lineno = cache_ptr;
3548 cache_ptr->u.offset = dst.l_addr.l_paddr
3549 - bfd_section_vma (abfd, asect);
3550 } /* If no linenumber expect a symbol index */
3556 cache_ptr->line_number = 0;
3559 asect->lineno = lineno_cache;
3560 /* FIXME, free native_lineno here, or use alloca or something. */
3565 coff_slurp_symbol_table (abfd)
3568 combined_entry_type *native_symbols;
3569 coff_symbol_type *cached_area;
3570 unsigned int *table_ptr;
3572 unsigned int number_of_symbols = 0;
3574 if (obj_symbols (abfd))
3577 /* Read in the symbol table */
3578 if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
3583 /* Allocate enough room for all the symbols in cached form */
3584 cached_area = ((coff_symbol_type *)
3586 (obj_raw_syment_count (abfd)
3587 * sizeof (coff_symbol_type))));
3589 if (cached_area == NULL)
3591 table_ptr = ((unsigned int *)
3593 (obj_raw_syment_count (abfd)
3594 * sizeof (unsigned int))));
3596 if (table_ptr == NULL)
3600 coff_symbol_type *dst = cached_area;
3601 unsigned int last_native_index = obj_raw_syment_count (abfd);
3602 unsigned int this_index = 0;
3603 while (this_index < last_native_index)
3605 combined_entry_type *src = native_symbols + this_index;
3606 table_ptr[this_index] = number_of_symbols;
3607 dst->symbol.the_bfd = abfd;
3609 dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
3610 /* We use the native name field to point to the cached field. */
3611 src->u.syment._n._n_n._n_zeroes = (long) dst;
3612 dst->symbol.section = coff_section_from_bfd_index (abfd,
3613 src->u.syment.n_scnum);
3614 dst->symbol.flags = 0;
3615 dst->done_lineno = false;
3617 switch (src->u.syment.n_sclass)
3622 dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
3623 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
3624 dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
3626 /* Fall through to next case */
3634 case C_THUMBEXTFUNC:
3640 case C_SYSTEM: /* System Wide variable */
3643 /* In PE, 0x68 (104) denotes a section symbol */
3645 /* In PE, 0x69 (105) denotes a weak external symbol. */
3648 switch (coff_classify_symbol (abfd, &src->u.syment))
3650 case COFF_SYMBOL_GLOBAL:
3651 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
3652 #if defined COFF_WITH_PE
3653 /* PE sets the symbol to a value relative to the
3654 start of the section. */
3655 dst->symbol.value = src->u.syment.n_value;
3657 dst->symbol.value = (src->u.syment.n_value
3658 - dst->symbol.section->vma);
3660 if (ISFCN ((src->u.syment.n_type)))
3662 /* A function ext does not go at the end of a
3664 dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
3668 case COFF_SYMBOL_COMMON:
3669 dst->symbol.section = bfd_com_section_ptr;
3670 dst->symbol.value = src->u.syment.n_value;
3673 case COFF_SYMBOL_UNDEFINED:
3674 dst->symbol.section = bfd_und_section_ptr;
3675 dst->symbol.value = 0;
3678 case COFF_SYMBOL_PE_SECTION:
3679 dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
3680 dst->symbol.value = 0;
3683 case COFF_SYMBOL_LOCAL:
3684 dst->symbol.flags = BSF_LOCAL;
3685 #if defined COFF_WITH_PE
3686 /* PE sets the symbol to a value relative to the
3687 start of the section. */
3688 dst->symbol.value = src->u.syment.n_value;
3690 dst->symbol.value = (src->u.syment.n_value
3691 - dst->symbol.section->vma);
3693 if (ISFCN ((src->u.syment.n_type)))
3694 dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
3699 /* A symbol with a csect entry should not go at the end. */
3700 if (src->u.syment.n_numaux > 0)
3701 dst->symbol.flags |= BSF_NOT_AT_END;
3705 if (src->u.syment.n_sclass == C_NT_WEAK)
3706 dst->symbol.flags = BSF_WEAK;
3707 if (src->u.syment.n_sclass == C_SECTION
3708 && src->u.syment.n_scnum > 0)
3710 dst->symbol.flags = BSF_LOCAL;
3714 if (src->u.syment.n_sclass == C_WEAKEXT)
3715 dst->symbol.flags = BSF_WEAK;
3719 case C_STAT: /* static */
3721 case C_LEAFSTAT: /* static leaf procedure */
3724 case C_THUMBSTAT: /* Thumb static */
3725 case C_THUMBLABEL: /* Thumb label */
3726 case C_THUMBSTATFUNC:/* Thumb static function */
3728 case C_LABEL: /* label */
3729 if (src->u.syment.n_scnum == -2)
3730 dst->symbol.flags = BSF_DEBUGGING;
3732 dst->symbol.flags = BSF_LOCAL;
3734 /* Base the value as an index from the base of the
3735 section, if there is one. */
3736 if (dst->symbol.section)
3738 #if defined COFF_WITH_PE
3739 /* PE sets the symbol to a value relative to the
3740 start of the section. */
3741 dst->symbol.value = src->u.syment.n_value;
3743 dst->symbol.value = (src->u.syment.n_value
3744 - dst->symbol.section->vma);
3748 dst->symbol.value = src->u.syment.n_value;
3751 case C_MOS: /* member of structure */
3752 case C_EOS: /* end of structure */
3753 #ifdef NOTDEF /* C_AUTOARG has the same value */
3755 case C_GLBLREG: /* A29k-specific storage class */
3758 case C_REGPARM: /* register parameter */
3759 case C_REG: /* register variable */
3762 case C_AUTOARG: /* 960-specific storage class */
3765 case C_TPDEF: /* type definition */
3767 case C_AUTO: /* automatic variable */
3768 case C_FIELD: /* bit field */
3769 case C_ENTAG: /* enumeration tag */
3770 case C_MOE: /* member of enumeration */
3771 case C_MOU: /* member of union */
3772 case C_UNTAG: /* union tag */
3773 dst->symbol.flags = BSF_DEBUGGING;
3774 dst->symbol.value = (src->u.syment.n_value);
3777 case C_FILE: /* file name */
3778 case C_STRTAG: /* structure tag */
3793 dst->symbol.flags = BSF_DEBUGGING;
3794 dst->symbol.value = (src->u.syment.n_value);
3798 case C_BINCL: /* beginning of include file */
3799 case C_EINCL: /* ending of include file */
3800 /* The value is actually a pointer into the line numbers
3801 of the file. We locate the line number entry, and
3802 set the section to the section which contains it, and
3803 the value to the index in that section. */
3807 dst->symbol.flags = BSF_DEBUGGING;
3808 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3809 if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
3810 && ((file_ptr) (sec->line_filepos
3811 + sec->lineno_count * LINESZ)
3812 > (file_ptr) src->u.syment.n_value))
3815 dst->symbol.value = 0;
3818 dst->symbol.section = sec;
3819 dst->symbol.value = ((src->u.syment.n_value
3820 - sec->line_filepos)
3828 dst->symbol.flags = BSF_DEBUGGING;
3830 /* The value is actually a symbol index. Save a pointer
3831 to the symbol instead of the index. FIXME: This
3832 should use a union. */
3833 src->u.syment.n_value =
3834 (long) (native_symbols + src->u.syment.n_value);
3835 dst->symbol.value = src->u.syment.n_value;
3840 case C_BLOCK: /* ".bb" or ".eb" */
3841 case C_FCN: /* ".bf" or ".ef" */
3842 case C_EFCN: /* physical end of function */
3843 dst->symbol.flags = BSF_LOCAL;
3844 #if defined COFF_WITH_PE
3845 /* PE sets the symbol to a value relative to the start
3847 dst->symbol.value = src->u.syment.n_value;
3849 /* Base the value as an index from the base of the
3851 dst->symbol.value = (src->u.syment.n_value
3852 - dst->symbol.section->vma);
3857 case C_EXTDEF: /* external definition */
3858 case C_ULABEL: /* undefined label */
3859 case C_USTATIC: /* undefined static */
3860 #ifndef COFF_WITH_PE
3861 /* C_LINE in regular coff is 0x68. NT has taken over this storage
3862 class to represent a section symbol */
3863 case C_LINE: /* line # reformatted as symbol table entry */
3864 /* NT uses 0x67 for a weak symbol, not C_ALIAS. */
3865 case C_ALIAS: /* duplicate tag */
3867 /* New storage classes for TIc80 */
3869 case C_UEXT: /* Tentative external definition */
3871 case C_STATLAB: /* Static load time label */
3872 case C_EXTLAB: /* External load time label */
3873 case C_HIDDEN: /* ext symbol in dmert public lib */
3875 (*_bfd_error_handler)
3876 (_("%s: Unrecognized storage class %d for %s symbol `%s'"),
3877 bfd_get_filename (abfd), src->u.syment.n_sclass,
3878 dst->symbol.section->name, dst->symbol.name);
3879 dst->symbol.flags = BSF_DEBUGGING;
3880 dst->symbol.value = (src->u.syment.n_value);
3884 /* BFD_ASSERT(dst->symbol.flags != 0);*/
3888 dst->symbol.udata.i = 0;
3889 dst->lineno = (alent *) NULL;
3890 this_index += (src->u.syment.n_numaux) + 1;
3892 number_of_symbols++;
3893 } /* walk the native symtab */
3894 } /* bfdize the native symtab */
3896 obj_symbols (abfd) = cached_area;
3897 obj_raw_syments (abfd) = native_symbols;
3899 bfd_get_symcount (abfd) = number_of_symbols;
3900 obj_convert (abfd) = table_ptr;
3901 /* Slurp the line tables for each section too */
3907 coff_slurp_line_table (abfd, p);
3912 } /* coff_slurp_symbol_table() */
3914 /* Classify a COFF symbol. A couple of targets have globally visible
3915 symbols which are not class C_EXT, and this handles those. It also
3916 recognizes some special PE cases. */
3918 static enum coff_symbol_classification
3919 coff_classify_symbol (abfd, syment)
3921 struct internal_syment *syment;
3923 /* FIXME: This partially duplicates the switch in
3924 coff_slurp_symbol_table. */
3925 switch (syment->n_sclass)
3934 case C_THUMBEXTFUNC:
3942 if (syment->n_scnum == 0)
3944 if (syment->n_value == 0)
3945 return COFF_SYMBOL_UNDEFINED;
3947 return COFF_SYMBOL_COMMON;
3949 return COFF_SYMBOL_GLOBAL;
3956 if (syment->n_sclass == C_STAT)
3958 if (syment->n_scnum == 0)
3960 /* The Microsoft compiler sometimes generates these if a
3961 small static function is inlined every time it is used.
3962 The function is discarded, but the symbol table entry
3964 return COFF_SYMBOL_LOCAL;
3968 /* This is correct for Microsoft generated objects, but it
3969 breaks gas generated objects. */
3971 if (syment->n_value == 0)
3974 char buf[SYMNMLEN + 1];
3976 sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
3978 && (strcmp (bfd_get_section_name (abfd, sec),
3979 _bfd_coff_internal_syment_name (abfd, syment, buf))
3981 return COFF_SYMBOL_PE_SECTION;
3985 return COFF_SYMBOL_LOCAL;
3988 if (syment->n_sclass == C_SECTION)
3990 /* In some cases in a DLL generated by the Microsoft linker, the
3991 n_value field will contain garbage. FIXME: This should
3992 probably be handled by the swapping function instead. */
3993 syment->n_value = 0;
3994 if (syment->n_scnum == 0)
3995 return COFF_SYMBOL_UNDEFINED;
3996 return COFF_SYMBOL_PE_SECTION;
3998 #endif /* COFF_WITH_PE */
4000 /* If it is not a global symbol, we presume it is a local symbol. */
4002 if (syment->n_scnum == 0)
4004 char buf[SYMNMLEN + 1];
4006 (*_bfd_error_handler)
4007 (_("warning: %s: local symbol `%s' has no section"),
4008 bfd_get_filename (abfd),
4009 _bfd_coff_internal_syment_name (abfd, syment, buf));
4012 return COFF_SYMBOL_LOCAL;
4019 Coff relocations are easily transformed into the internal BFD form
4022 Reading a coff relocation table is done in the following stages:
4024 o Read the entire coff relocation table into memory.
4026 o Process each relocation in turn; first swap it from the
4027 external to the internal form.
4029 o Turn the symbol referenced in the relocation's symbol index
4030 into a pointer into the canonical symbol table.
4031 This table is the same as the one returned by a call to
4032 @code{bfd_canonicalize_symtab}. The back end will call that
4033 routine and save the result if a canonicalization hasn't been done.
4035 o The reloc index is turned into a pointer to a howto
4036 structure, in a back end specific way. For instance, the 386
4037 and 960 use the @code{r_type} to directly produce an index
4038 into a howto table vector; the 88k subtracts a number from the
4039 @code{r_type} field and creates an addend field.
4045 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
4047 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
4048 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
4049 coffsym = (obj_symbols (abfd) \
4050 + (cache_ptr->sym_ptr_ptr - symbols)); \
4052 coffsym = coff_symbol_from (abfd, ptr); \
4053 if (coffsym != (coff_symbol_type *) NULL \
4054 && coffsym->native->u.syment.n_scnum == 0) \
4055 cache_ptr->addend = 0; \
4056 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
4057 && ptr->section != (asection *) NULL) \
4058 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
4060 cache_ptr->addend = 0; \
4065 coff_slurp_reloc_table (abfd, asect, symbols)
4070 RELOC *native_relocs;
4071 arelent *reloc_cache;
4076 if (asect->relocation)
4078 if (asect->reloc_count == 0)
4080 if (asect->flags & SEC_CONSTRUCTOR)
4082 if (!coff_slurp_symbol_table (abfd))
4085 (RELOC *) buy_and_read (abfd,
4089 asect->reloc_count));
4090 reloc_cache = (arelent *)
4091 bfd_alloc (abfd, (size_t) (asect->reloc_count * sizeof (arelent)));
4093 if (reloc_cache == NULL)
4097 for (idx = 0; idx < asect->reloc_count; idx++)
4099 struct internal_reloc dst;
4100 struct external_reloc *src;
4101 #ifndef RELOC_PROCESSING
4105 cache_ptr = reloc_cache + idx;
4106 src = native_relocs + idx;
4108 coff_swap_reloc_in (abfd, src, &dst);
4110 #ifdef RELOC_PROCESSING
4111 RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
4113 cache_ptr->address = dst.r_vaddr;
4115 if (dst.r_symndx != -1)
4117 if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
4119 (*_bfd_error_handler)
4120 (_("%s: warning: illegal symbol index %ld in relocs"),
4121 bfd_get_filename (abfd), dst.r_symndx);
4122 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4127 cache_ptr->sym_ptr_ptr = (symbols
4128 + obj_convert (abfd)[dst.r_symndx]);
4129 ptr = *(cache_ptr->sym_ptr_ptr);
4134 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4138 /* The symbols definitions that we have read in have been
4139 relocated as if their sections started at 0. But the offsets
4140 refering to the symbols in the raw data have not been
4141 modified, so we have to have a negative addend to compensate.
4143 Note that symbols which used to be common must be left alone */
4145 /* Calculate any reloc addend by looking at the symbol */
4146 CALC_ADDEND (abfd, ptr, dst, cache_ptr);
4148 cache_ptr->address -= asect->vma;
4149 /* !! cache_ptr->section = (asection *) NULL;*/
4151 /* Fill in the cache_ptr->howto field from dst.r_type */
4152 RTYPE2HOWTO (cache_ptr, &dst);
4153 #endif /* RELOC_PROCESSING */
4155 if (cache_ptr->howto == NULL)
4157 (*_bfd_error_handler)
4158 (_("%s: illegal relocation type %d at address 0x%lx"),
4159 bfd_get_filename (abfd), dst.r_type, (long) dst.r_vaddr);
4160 bfd_set_error (bfd_error_bad_value);
4165 asect->relocation = reloc_cache;
4169 #ifndef coff_rtype_to_howto
4172 /* Get the howto structure for a reloc. This is only used if the file
4173 including this one defines coff_relocate_section to be
4174 _bfd_coff_generic_relocate_section, so it is OK if it does not
4175 always work. It is the responsibility of the including file to
4176 make sure it is reasonable if it is needed. */
4178 static reloc_howto_type *coff_rtype_to_howto
4179 PARAMS ((bfd *, asection *, struct internal_reloc *,
4180 struct coff_link_hash_entry *, struct internal_syment *,
4184 static reloc_howto_type *
4185 coff_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
4186 bfd *abfd ATTRIBUTE_UNUSED;
4187 asection *sec ATTRIBUTE_UNUSED;
4188 struct internal_reloc *rel;
4189 struct coff_link_hash_entry *h ATTRIBUTE_UNUSED;
4190 struct internal_syment *sym ATTRIBUTE_UNUSED;
4191 bfd_vma *addendp ATTRIBUTE_UNUSED;
4195 RTYPE2HOWTO (&genrel, rel);
4196 return genrel.howto;
4199 #else /* ! defined (RTYPE2HOWTO) */
4201 #define coff_rtype_to_howto NULL
4203 #endif /* ! defined (RTYPE2HOWTO) */
4204 #endif /* ! defined (coff_rtype_to_howto) */
4206 /* This is stupid. This function should be a boolean predicate. */
4208 coff_canonicalize_reloc (abfd, section, relptr, symbols)
4214 arelent *tblptr = section->relocation;
4215 unsigned int count = 0;
4218 if (section->flags & SEC_CONSTRUCTOR)
4220 /* this section has relocs made up by us, they are not in the
4221 file, so take them out of their chain and place them into
4222 the data area provided */
4223 arelent_chain *chain = section->constructor_chain;
4224 for (count = 0; count < section->reloc_count; count++)
4226 *relptr++ = &chain->relent;
4227 chain = chain->next;
4233 if (! coff_slurp_reloc_table (abfd, section, symbols))
4236 tblptr = section->relocation;
4238 for (; count++ < section->reloc_count;)
4239 *relptr++ = tblptr++;
4244 return section->reloc_count;
4249 coff_sym_filepos (abfd)
4252 return obj_sym_filepos (abfd);
4256 #ifndef coff_reloc16_estimate
4257 #define coff_reloc16_estimate dummy_reloc16_estimate
4259 static int dummy_reloc16_estimate
4260 PARAMS ((bfd *, asection *, arelent *, unsigned int,
4261 struct bfd_link_info *));
4264 dummy_reloc16_estimate (abfd, input_section, reloc, shrink, link_info)
4265 bfd *abfd ATTRIBUTE_UNUSED;
4266 asection *input_section ATTRIBUTE_UNUSED;
4267 arelent *reloc ATTRIBUTE_UNUSED;
4268 unsigned int shrink ATTRIBUTE_UNUSED;
4269 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
4276 #ifndef coff_reloc16_extra_cases
4278 #define coff_reloc16_extra_cases dummy_reloc16_extra_cases
4280 /* This works even if abort is not declared in any header file. */
4282 static void dummy_reloc16_extra_cases
4283 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
4284 bfd_byte *, unsigned int *, unsigned int *));
4287 dummy_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
4289 bfd *abfd ATTRIBUTE_UNUSED;
4290 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
4291 struct bfd_link_order *link_order ATTRIBUTE_UNUSED;
4292 arelent *reloc ATTRIBUTE_UNUSED;
4293 bfd_byte *data ATTRIBUTE_UNUSED;
4294 unsigned int *src_ptr ATTRIBUTE_UNUSED;
4295 unsigned int *dst_ptr ATTRIBUTE_UNUSED;
4301 /* If coff_relocate_section is defined, we can use the optimized COFF
4302 backend linker. Otherwise we must continue to use the old linker. */
4303 #ifdef coff_relocate_section
4304 #ifndef coff_bfd_link_hash_table_create
4305 #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
4307 #ifndef coff_bfd_link_add_symbols
4308 #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
4310 #ifndef coff_bfd_final_link
4311 #define coff_bfd_final_link _bfd_coff_final_link
4313 #else /* ! defined (coff_relocate_section) */
4314 #define coff_relocate_section NULL
4315 #ifndef coff_bfd_link_hash_table_create
4316 #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
4318 #ifndef coff_bfd_link_add_symbols
4319 #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
4321 #define coff_bfd_final_link _bfd_generic_final_link
4322 #endif /* ! defined (coff_relocate_section) */
4324 #define coff_bfd_link_split_section _bfd_generic_link_split_section
4326 #ifndef coff_start_final_link
4327 #define coff_start_final_link NULL
4330 #ifndef coff_adjust_symndx
4331 #define coff_adjust_symndx NULL
4334 #ifndef coff_link_add_one_symbol
4335 #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
4338 #ifndef coff_link_output_has_begun
4340 static boolean coff_link_output_has_begun
4341 PARAMS ((bfd *, struct coff_final_link_info *));
4344 coff_link_output_has_begun (abfd, info)
4346 struct coff_final_link_info * info ATTRIBUTE_UNUSED;
4348 return abfd->output_has_begun;
4352 #ifndef coff_final_link_postscript
4354 static boolean coff_final_link_postscript
4355 PARAMS ((bfd *, struct coff_final_link_info *));
4358 coff_final_link_postscript (abfd, pfinfo)
4359 bfd * abfd ATTRIBUTE_UNUSED;
4360 struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED;
4366 #ifndef coff_SWAP_aux_in
4367 #define coff_SWAP_aux_in coff_swap_aux_in
4369 #ifndef coff_SWAP_sym_in
4370 #define coff_SWAP_sym_in coff_swap_sym_in
4372 #ifndef coff_SWAP_lineno_in
4373 #define coff_SWAP_lineno_in coff_swap_lineno_in
4375 #ifndef coff_SWAP_aux_out
4376 #define coff_SWAP_aux_out coff_swap_aux_out
4378 #ifndef coff_SWAP_sym_out
4379 #define coff_SWAP_sym_out coff_swap_sym_out
4381 #ifndef coff_SWAP_lineno_out
4382 #define coff_SWAP_lineno_out coff_swap_lineno_out
4384 #ifndef coff_SWAP_reloc_out
4385 #define coff_SWAP_reloc_out coff_swap_reloc_out
4387 #ifndef coff_SWAP_filehdr_out
4388 #define coff_SWAP_filehdr_out coff_swap_filehdr_out
4390 #ifndef coff_SWAP_aouthdr_out
4391 #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
4393 #ifndef coff_SWAP_scnhdr_out
4394 #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
4396 #ifndef coff_SWAP_reloc_in
4397 #define coff_SWAP_reloc_in coff_swap_reloc_in
4399 #ifndef coff_SWAP_filehdr_in
4400 #define coff_SWAP_filehdr_in coff_swap_filehdr_in
4402 #ifndef coff_SWAP_aouthdr_in
4403 #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
4405 #ifndef coff_SWAP_scnhdr_in
4406 #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
4411 static CONST bfd_coff_backend_data bfd_coff_std_swap_table =
4413 coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
4414 coff_SWAP_aux_out, coff_SWAP_sym_out,
4415 coff_SWAP_lineno_out, coff_SWAP_reloc_out,
4416 coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
4417 coff_SWAP_scnhdr_out,
4418 FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ,
4419 #ifdef COFF_LONG_FILENAMES
4424 #ifdef COFF_LONG_SECTION_NAMES
4429 COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
4430 coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
4431 coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
4432 coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
4433 coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
4434 coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
4435 coff_classify_symbol, coff_compute_section_file_positions,
4436 coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
4437 coff_adjust_symndx, coff_link_add_one_symbol,
4438 coff_link_output_has_begun, coff_final_link_postscript
4441 #ifndef coff_close_and_cleanup
4442 #define coff_close_and_cleanup _bfd_generic_close_and_cleanup
4445 #ifndef coff_bfd_free_cached_info
4446 #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
4449 #ifndef coff_get_section_contents
4450 #define coff_get_section_contents _bfd_generic_get_section_contents
4453 #ifndef coff_bfd_copy_private_symbol_data
4454 #define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
4457 #ifndef coff_bfd_copy_private_section_data
4458 #define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
4461 #ifndef coff_bfd_copy_private_bfd_data
4462 #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
4465 #ifndef coff_bfd_merge_private_bfd_data
4466 #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
4469 #ifndef coff_bfd_set_private_flags
4470 #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
4473 #ifndef coff_bfd_print_private_bfd_data
4474 #define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
4477 #ifndef coff_bfd_is_local_label_name
4478 #define coff_bfd_is_local_label_name _bfd_coff_is_local_label_name
4481 #ifndef coff_read_minisymbols
4482 #define coff_read_minisymbols _bfd_generic_read_minisymbols
4485 #ifndef coff_minisymbol_to_symbol
4486 #define coff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4489 /* The reloc lookup routine must be supplied by each individual COFF
4491 #ifndef coff_bfd_reloc_type_lookup
4492 #define coff_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
4495 #ifndef coff_bfd_get_relocated_section_contents
4496 #define coff_bfd_get_relocated_section_contents \
4497 bfd_generic_get_relocated_section_contents
4500 #ifndef coff_bfd_relax_section
4501 #define coff_bfd_relax_section bfd_generic_relax_section
4504 #ifndef coff_bfd_gc_sections
4505 #define coff_bfd_gc_sections bfd_generic_gc_sections
4508 #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE) \
4509 const bfd_target VAR = \
4512 bfd_target_coff_flavour, \
4513 BFD_ENDIAN_BIG, /* data byte order is big */ \
4514 BFD_ENDIAN_BIG, /* header byte order is big */ \
4515 /* object flags */ \
4516 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
4517 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
4518 /* section flags */ \
4519 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS), \
4520 UNDER, /* leading symbol underscore */ \
4521 '/', /* ar_pad_char */ \
4522 15, /* ar_max_namelen */ \
4524 /* Data conversion functions. */ \
4525 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
4526 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
4527 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
4529 /* Header conversion functions. */ \
4530 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
4531 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
4532 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
4534 /* bfd_check_format */ \
4535 { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target }, \
4536 /* bfd_set_format */ \
4537 { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
4538 /* bfd_write_contents */ \
4539 { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, bfd_false }, \
4541 BFD_JUMP_TABLE_GENERIC (coff), \
4542 BFD_JUMP_TABLE_COPY (coff), \
4543 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
4544 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
4545 BFD_JUMP_TABLE_SYMBOLS (coff), \
4546 BFD_JUMP_TABLE_RELOCS (coff), \
4547 BFD_JUMP_TABLE_WRITE (coff), \
4548 BFD_JUMP_TABLE_LINK (coff), \
4549 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
4556 #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE) \
4557 const bfd_target VAR = \
4560 bfd_target_coff_flavour, \
4561 BFD_ENDIAN_LITTLE, /* data byte order is little */ \
4562 BFD_ENDIAN_LITTLE, /* header byte order is little */ \
4563 /* object flags */ \
4564 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
4565 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
4566 /* section flags */ \
4567 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS), \
4568 UNDER, /* leading symbol underscore */ \
4569 '/', /* ar_pad_char */ \
4570 15, /* ar_max_namelen */ \
4572 /* Data conversion functions. */ \
4573 bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
4574 bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
4575 bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
4576 /* Header conversion functions. */ \
4577 bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
4578 bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
4579 bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
4580 /* bfd_check_format */ \
4581 { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target }, \
4582 /* bfd_set_format */ \
4583 { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
4584 /* bfd_write_contents */ \
4585 { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, bfd_false }, \
4587 BFD_JUMP_TABLE_GENERIC (coff), \
4588 BFD_JUMP_TABLE_COPY (coff), \
4589 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
4590 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
4591 BFD_JUMP_TABLE_SYMBOLS (coff), \
4592 BFD_JUMP_TABLE_RELOCS (coff), \
4593 BFD_JUMP_TABLE_WRITE (coff), \
4594 BFD_JUMP_TABLE_LINK (coff), \
4595 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \