1 /* Support for the generic parts of most COFF variants, for BFD.
2 Copyright (C) 1990-2023 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 /* Most of this hacked by Steve Chamberlain,
28 BFD supports a number of different flavours of coff format.
29 The major differences between formats are the sizes and
30 alignments of fields in structures on disk, and the occasional
33 Coff in all its varieties is implemented with a few common
34 files and a number of implementation specific files. For
35 example, the i386 coff format is implemented in the file
36 @file{coff-i386.c}. This file @code{#include}s
37 @file{coff/i386.h} which defines the external structure of the
38 coff format for the i386, and @file{coff/internal.h} which
39 defines the internal structure. @file{coff-i386.c} also
40 defines the relocations used by the i386 coff format
44 Porting to a new version of coff
46 The recommended method is to select from the existing
47 implementations the version of coff which is most like the one
48 you want to use. For example, we'll say that i386 coff is
49 the one you select, and that your coff flavour is called foo.
50 Copy @file{i386coff.c} to @file{foocoff.c}, copy
51 @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
52 and add the lines to @file{targets.c} and @file{Makefile.in}
53 so that your new back end is used. Alter the shapes of the
54 structures in @file{../include/coff/foo.h} so that they match
55 what you need. You will probably also have to add
56 @code{#ifdef}s to the code in @file{coff/internal.h} and
57 @file{coffcode.h} if your version of coff is too wild.
59 You can verify that your new BFD backend works quite simply by
60 building @file{objdump} from the @file{binutils} directory,
61 and making sure that its version of what's going on and your
62 host system's idea (assuming it has the pretty standard coff
63 dump utility, usually called @code{att-dump} or just
64 @code{dump}) are the same. Then clean up your code, and send
65 what you've done to Cygnus. Then your stuff will be in the
66 next release, and you won't have to keep integrating it.
69 How the coff backend works
74 The Coff backend is split into generic routines that are
75 applicable to any Coff target and routines that are specific
76 to a particular target. The target-specific routines are
77 further split into ones which are basically the same for all
78 Coff targets except that they use the external symbol format
79 or use different values for certain constants.
81 The generic routines are in @file{coffgen.c}. These routines
82 work for any Coff target. They use some hooks into the target
83 specific code; the hooks are in a @code{bfd_coff_backend_data}
84 structure, one of which exists for each target.
86 The essentially similar target-specific routines are in
87 @file{coffcode.h}. This header file includes executable C code.
88 The various Coff targets first include the appropriate Coff
89 header file, make any special defines that are needed, and
90 then include @file{coffcode.h}.
92 Some of the Coff targets then also have additional routines in
93 the target source file itself.
96 Coff long section names
98 In the standard Coff object format, section names are limited to
99 the eight bytes available in the @code{s_name} field of the
100 @code{SCNHDR} section header structure. The format requires the
101 field to be NUL-padded, but not necessarily NUL-terminated, so
102 the longest section names permitted are a full eight characters.
104 The Microsoft PE variants of the Coff object file format add
105 an extension to support the use of long section names. This
106 extension is defined in section 4 of the Microsoft PE/COFF
107 specification (rev 8.1). If a section name is too long to fit
108 into the section header's @code{s_name} field, it is instead
109 placed into the string table, and the @code{s_name} field is
110 filled with a slash ("/") followed by the ASCII decimal
111 representation of the offset of the full name relative to the
114 Note that this implies that the extension can only be used in object
115 files, as executables do not contain a string table. The standard
116 specifies that long section names from objects emitted into executable
117 images are to be truncated.
119 However, as a GNU extension, BFD can generate executable images
120 that contain a string table and long section names. This
121 would appear to be technically valid, as the standard only says
122 that Coff debugging information is deprecated, not forbidden,
123 and in practice it works, although some tools that parse PE files
124 expecting the MS standard format may become confused; @file{PEview} is
127 The functionality is supported in BFD by code implemented under
128 the control of the macro @code{COFF_LONG_SECTION_NAMES}. If not
129 defined, the format does not support long section names in any way.
130 If defined, it is used to initialise a flag,
131 @code{_bfd_coff_long_section_names}, and a hook function pointer,
132 @code{_bfd_coff_set_long_section_names}, in the Coff backend data
133 structure. The flag controls the generation of long section names
134 in output BFDs at runtime; if it is false, as it will be by default
135 when generating an executable image, long section names are truncated;
136 if true, the long section names extension is employed. The hook
137 points to a function that allows the value of a copy of the flag
138 in coff object tdata to be altered at runtime, on formats that
139 support long section names at all; on other formats it points
140 to a stub that returns an error indication.
142 With input BFDs, the flag is set according to whether any long section
143 names are detected while reading the section headers. For a completely
144 new BFD, the flag is set to the default for the target format. This
145 information can be used by a client of the BFD library when deciding
146 what output format to generate, and means that a BFD that is opened
147 for read and subsequently converted to a writeable BFD and modified
148 in-place will retain whatever format it had on input.
150 If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is
151 defined to the value "1", then long section names are enabled by
152 default; if it is defined to the value zero, they are disabled by
153 default (but still accepted in input BFDs). The header @file{coffcode.h}
154 defines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is
155 used in the backends to initialise the backend data structure fields
156 appropriately; see the comments for further detail.
161 Each flavour of coff supported in BFD has its own header file
162 describing the external layout of the structures. There is also
163 an internal description of the coff layout, in
164 @file{coff/internal.h}. A major function of the
165 coff backend is swapping the bytes and twiddling the bits to
166 translate the external form of the structures into the normal
167 internal form. This is all performed in the
168 @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
169 elements are different sizes between different versions of
170 coff; it is the duty of the coff version specific include file
171 to override the definitions of various packing routines in
172 @file{coffcode.h}. E.g., the size of line number entry in coff is
173 sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
174 @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
175 correct one. No doubt, some day someone will find a version of
176 coff which has a varying field size not catered to at the
177 moment. To port BFD, that person will have to add more @code{#defines}.
178 Three of the bit twiddling routines are exported to
179 @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
180 and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
181 table on its own, but uses BFD to fix things up. More of the
182 bit twiddlers are exported for @code{gas};
183 @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
184 @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
185 @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
186 @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
187 of all the symbol table and reloc drudgery itself, thereby
188 saving the internal BFD overhead, but uses BFD to swap things
189 on the way out, making cross ports much safer. Doing so also
190 allows BFD (and thus the linker) to use the same header files
191 as @code{gas}, which makes one avenue to disaster disappear.
196 The simple canonical form for symbols used by BFD is not rich
197 enough to keep all the information available in a coff symbol
198 table. The back end gets around this problem by keeping the original
199 symbol table around, "behind the scenes".
201 When a symbol table is requested (through a call to
202 @code{bfd_canonicalize_symtab}), a request gets through to
203 @code{coff_get_normalized_symtab}. This reads the symbol table from
204 the coff file and swaps all the structures inside into the
205 internal form. It also fixes up all the pointers in the table
206 (represented in the file by offsets from the first symbol in
207 the table) into physical pointers to elements in the new
208 internal table. This involves some work since the meanings of
209 fields change depending upon context: a field that is a
210 pointer to another structure in the symbol table at one moment
211 may be the size in bytes of a structure at the next. Another
212 pass is made over the table. All symbols which mark file names
213 (<<C_FILE>> symbols) are modified so that the internal
214 string points to the value in the auxent (the real filename)
215 rather than the normal text associated with the symbol
218 At this time the symbol names are moved around. Coff stores
219 all symbols less than nine characters long physically
220 within the symbol table; longer strings are kept at the end of
221 the file in the string table. This pass moves all strings
222 into memory and replaces them with pointers to the strings.
224 The symbol table is massaged once again, this time to create
225 the canonical table used by the BFD application. Each symbol
226 is inspected in turn, and a decision made (using the
227 @code{sclass} field) about the various flags to set in the
228 @code{asymbol}. @xref{Symbols}. The generated canonical table
229 shares strings with the hidden internal symbol table.
231 Any linenumbers are read from the coff file too, and attached
232 to the symbols which own the functions the linenumbers belong to.
237 Writing a symbol to a coff file which didn't come from a coff
238 file will lose any debugging information. The @code{asymbol}
239 structure remembers the BFD from which the symbol was taken, and on
240 output the back end makes sure that the same destination target as
241 source target is present.
243 When the symbols have come from a coff file then all the
244 debugging information is preserved.
246 Symbol tables are provided for writing to the back end in a
247 vector of pointers to pointers. This allows applications like
248 the linker to accumulate and output large symbol tables
249 without having to do too much byte copying.
251 This function runs through the provided symbol table and
252 patches each symbol marked as a file place holder
253 (@code{C_FILE}) to point to the next file place holder in the
254 list. It also marks each @code{offset} field in the list with
255 the offset from the first symbol of the current symbol.
257 Another function of this procedure is to turn the canonical
258 value form of BFD into the form used by coff. Internally, BFD
259 expects symbol values to be offsets from a section base; so a
260 symbol physically at 0x120, but in a section starting at
261 0x100, would have the value 0x20. Coff expects symbols to
262 contain their final value, so symbols have their values
263 changed at this point to reflect their sum with their owning
264 section. This transformation uses the
265 <<output_section>> field of the @code{asymbol}'s
266 @code{asection} @xref{Sections}.
268 o <<coff_mangle_symbols>>
270 This routine runs though the provided symbol table and uses
271 the offsets generated by the previous pass and the pointers
272 generated when the symbol table was read in to create the
273 structured hierarchy required by coff. It changes each pointer
274 to a symbol into the index into the symbol table of the asymbol.
276 o <<coff_write_symbols>>
278 This routine runs through the symbol table and patches up the
279 symbols from their internal form into the coff way, calls the
280 bit twiddlers, and writes out the table to the file.
289 The hidden information for an <<asymbol>> is described in a
290 <<combined_entry_type>>:
293 .typedef struct coff_ptr_struct
295 . {* Remembers the offset from the first symbol in the file for
296 . this symbol. Generated by coff_renumber_symbols. *}
297 . unsigned int offset;
299 . {* Selects between the elements of the union below. *}
300 . unsigned int is_sym : 1;
302 . {* Selects between the elements of the x_sym.x_tagndx union. If set,
303 . p is valid and the field will be renumbered. *}
304 . unsigned int fix_tag : 1;
306 . {* Selects between the elements of the x_sym.x_fcnary.x_fcn.x_endndx
307 . union. If set, p is valid and the field will be renumbered. *}
308 . unsigned int fix_end : 1;
310 . {* Selects between the elements of the x_csect.x_scnlen union. If set,
311 . p is valid and the field will be renumbered. *}
312 . unsigned int fix_scnlen : 1;
314 . {* If set, u.syment.n_value contains a pointer to a symbol. The final
315 . value will be the offset field. Used for XCOFF C_BSTAT symbols. *}
316 . unsigned int fix_value : 1;
318 . {* If set, u.syment.n_value is an index into the line number entries.
319 . Used for XCOFF C_BINCL/C_EINCL symbols. *}
320 . unsigned int fix_line : 1;
322 . {* The container for the symbol structure as read and translated
326 . union internal_auxent auxent;
327 . struct internal_syment syment;
330 . {* An extra pointer which can used by format based on COFF (like XCOFF)
331 . to provide extra information to their backend. *}
333 .} combined_entry_type;
335 .{* Each canonical asymbol really looks like this: *}
337 .typedef struct coff_symbol_struct
339 . {* The actual symbol which the rest of BFD works with *}
342 . {* A pointer to the hidden information for this symbol *}
343 . combined_entry_type *native;
345 . {* A pointer to the linenumber information for this symbol *}
346 . struct lineno_cache_entry *lineno;
348 . {* Have the line numbers been relocated yet ? *}
354 #include "libiberty.h"
359 #include "coffswap.h"
362 #define STRING_SIZE_SIZE 4
364 #define DOT_DEBUG ".debug"
365 #define DOT_ZDEBUG ".zdebug"
366 #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
367 #define GNU_LINKONCE_WT ".gnu.linkonce.wt."
368 #define DOT_RELOC ".reloc"
370 #if defined(COFF_WITH_PE) || defined(COFF_GO32_EXE) || defined(COFF_GO32)
371 # define COFF_WITH_EXTENDED_RELOC_COUNTER
374 #if defined (COFF_LONG_SECTION_NAMES)
375 /* Needed to expand the inputs to BLANKOR1TOODD. */
376 #define COFFLONGSECTIONCATHELPER(x,y) x ## y
377 /* If the input macro Y is blank or '1', return an odd number; if it is
378 '0', return an even number. Result undefined in all other cases. */
379 #define BLANKOR1TOODD(y) COFFLONGSECTIONCATHELPER(1,y)
380 /* Defined to numerical 0 or 1 according to whether generation of long
381 section names is disabled or enabled by default. */
382 #define COFF_ENABLE_LONG_SECTION_NAMES (BLANKOR1TOODD(COFF_LONG_SECTION_NAMES) & 1)
383 /* Where long section names are supported, we allow them to be enabled
384 and disabled at runtime, so select an appropriate hook function for
385 _bfd_coff_set_long_section_names. */
386 #define COFF_LONG_SECTION_NAMES_SETTER bfd_coff_set_long_section_names_allowed
387 #else /* !defined (COFF_LONG_SECTION_NAMES) */
388 /* If long section names are not supported, this stub disallows any
389 attempt to enable them at run-time. */
390 #define COFF_LONG_SECTION_NAMES_SETTER bfd_coff_set_long_section_names_disallowed
391 #endif /* defined (COFF_LONG_SECTION_NAMES) */
393 /* Define a macro that can be used to initialise both the fields relating
394 to long section names in the backend data struct simultaneously. */
395 #if COFF_ENABLE_LONG_SECTION_NAMES
396 #define COFF_DEFAULT_LONG_SECTION_NAMES (true), COFF_LONG_SECTION_NAMES_SETTER
397 #else /* !COFF_ENABLE_LONG_SECTION_NAMES */
398 #define COFF_DEFAULT_LONG_SECTION_NAMES (false), COFF_LONG_SECTION_NAMES_SETTER
399 #endif /* COFF_ENABLE_LONG_SECTION_NAMES */
401 #if defined (COFF_LONG_SECTION_NAMES)
402 static bool bfd_coff_set_long_section_names_allowed
404 #else /* !defined (COFF_LONG_SECTION_NAMES) */
405 static bool bfd_coff_set_long_section_names_disallowed
407 #endif /* defined (COFF_LONG_SECTION_NAMES) */
408 static long sec_to_styp_flags
409 (const char *, flagword
);
410 static bool styp_to_sec_flags
411 (bfd
*, void *, const char *, asection
*, flagword
*);
412 static bool coff_bad_format_hook
414 static void coff_set_custom_section_alignment
415 (bfd
*, asection
*, const struct coff_section_alignment_entry
*,
417 static bool coff_new_section_hook
419 static bool coff_set_arch_mach_hook
421 static bool coff_write_relocs
423 static bool coff_set_flags
424 (bfd
*, unsigned int *, unsigned short *);
425 static bool coff_set_arch_mach
426 (bfd
*, enum bfd_architecture
, unsigned long) ATTRIBUTE_UNUSED
;
427 static bool coff_compute_section_file_positions
429 static bool coff_write_object_contents
430 (bfd
*) ATTRIBUTE_UNUSED
;
431 static bool coff_set_section_contents
432 (bfd
*, asection
*, const void *, file_ptr
, bfd_size_type
);
433 static bool coff_slurp_line_table
435 static bool coff_slurp_symbol_table
437 static enum coff_symbol_classification coff_classify_symbol
438 (bfd
*, struct internal_syment
*);
439 static bool coff_slurp_reloc_table
440 (bfd
*, asection
*, asymbol
**);
441 static long coff_canonicalize_reloc
442 (bfd
*, asection
*, arelent
**, asymbol
**);
443 #ifndef coff_mkobject_hook
444 static void * coff_mkobject_hook
445 (bfd
*, void *, void *);
448 static flagword handle_COMDAT
449 (bfd
*, flagword
, void *, const char *, asection
*);
452 static bool ticoff0_bad_format_hook
454 static bool ticoff1_bad_format_hook
458 /* void warning(); */
460 #if defined (COFF_LONG_SECTION_NAMES)
462 bfd_coff_set_long_section_names_allowed (bfd
*abfd
, int enable
)
464 bfd_coff_long_section_names (abfd
) = enable
;
467 #else /* !defined (COFF_LONG_SECTION_NAMES) */
469 bfd_coff_set_long_section_names_disallowed (bfd
*abfd ATTRIBUTE_UNUSED
,
470 int enable ATTRIBUTE_UNUSED
)
474 #endif /* defined (COFF_LONG_SECTION_NAMES) */
476 /* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
477 the incoming SEC_* flags. The inverse of this function is
478 styp_to_sec_flags(). NOTE: If you add to/change this routine, you
479 should probably mirror the changes in styp_to_sec_flags(). */
483 /* Macros for setting debugging flags. */
486 #define STYP_XCOFF_DEBUG STYP_DEBUG
488 #define STYP_XCOFF_DEBUG STYP_INFO
491 #ifdef COFF_ALIGN_IN_S_FLAGS
492 #define STYP_DEBUG_INFO STYP_DSECT
494 #define STYP_DEBUG_INFO STYP_INFO
498 sec_to_styp_flags (const char *sec_name
, flagword sec_flags
)
502 if (!strcmp (sec_name
, _TEXT
))
504 styp_flags
= STYP_TEXT
;
506 else if (!strcmp (sec_name
, _DATA
))
508 styp_flags
= STYP_DATA
;
510 else if (!strcmp (sec_name
, _BSS
))
512 styp_flags
= STYP_BSS
;
515 else if (!strcmp (sec_name
, _COMMENT
))
517 styp_flags
= STYP_INFO
;
518 #endif /* _COMMENT */
521 else if (!strcmp (sec_name
, _LIB
))
523 styp_flags
= STYP_LIB
;
527 else if (!strcmp (sec_name
, _LIT
))
529 styp_flags
= STYP_LIT
;
532 else if (startswith (sec_name
, DOT_DEBUG
)
533 || startswith (sec_name
, DOT_ZDEBUG
))
535 /* Handle the XCOFF debug section and DWARF2 debug sections. */
537 styp_flags
= STYP_XCOFF_DEBUG
;
539 styp_flags
= STYP_DEBUG_INFO
;
541 else if (startswith (sec_name
, ".stab"))
543 styp_flags
= STYP_DEBUG_INFO
;
545 #ifdef COFF_LONG_SECTION_NAMES
546 else if (startswith (sec_name
, GNU_LINKONCE_WI
)
547 || startswith (sec_name
, GNU_LINKONCE_WT
))
549 styp_flags
= STYP_DEBUG_INFO
;
553 else if (!strcmp (sec_name
, _TDATA
))
555 styp_flags
= STYP_TDATA
;
557 else if (!strcmp (sec_name
, _TBSS
))
559 styp_flags
= STYP_TBSS
;
561 else if (!strcmp (sec_name
, _PAD
))
563 styp_flags
= STYP_PAD
;
565 else if (!strcmp (sec_name
, _LOADER
))
567 styp_flags
= STYP_LOADER
;
569 else if (!strcmp (sec_name
, _EXCEPT
))
571 styp_flags
= STYP_EXCEPT
;
573 else if (!strcmp (sec_name
, _TYPCHK
))
575 styp_flags
= STYP_TYPCHK
;
577 else if (sec_flags
& SEC_DEBUGGING
)
581 for (i
= 0; i
< XCOFF_DWSECT_NBR_NAMES
; i
++)
582 if (!strcmp (sec_name
, xcoff_dwsect_names
[i
].xcoff_name
))
584 styp_flags
= STYP_DWARF
| xcoff_dwsect_names
[i
].flag
;
589 /* Try and figure out what it should be */
590 else if (sec_flags
& SEC_CODE
)
592 styp_flags
= STYP_TEXT
;
594 else if (sec_flags
& SEC_DATA
)
596 styp_flags
= STYP_DATA
;
598 else if (sec_flags
& SEC_READONLY
)
600 #ifdef STYP_LIT /* 29k readonly text/data section */
601 styp_flags
= STYP_LIT
;
603 styp_flags
= STYP_TEXT
;
604 #endif /* STYP_LIT */
606 else if (sec_flags
& SEC_LOAD
)
608 styp_flags
= STYP_TEXT
;
610 else if (sec_flags
& SEC_ALLOC
)
612 styp_flags
= STYP_BSS
;
616 if (sec_flags
& SEC_TIC54X_CLINK
)
617 styp_flags
|= STYP_CLINK
;
621 if (sec_flags
& SEC_TIC54X_BLOCK
)
622 styp_flags
|= STYP_BLOCK
;
626 if ((sec_flags
& (SEC_NEVER_LOAD
| SEC_COFF_SHARED_LIBRARY
)) != 0)
627 styp_flags
|= STYP_NOLOAD
;
633 #else /* COFF_WITH_PE */
635 /* The PE version; see above for the general comments. The non-PE
636 case seems to be more guessing, and breaks PE format; specifically,
637 .rdata is readonly, but it sure ain't text. Really, all this
638 should be set up properly in gas (or whatever assembler is in use),
639 and honor whatever objcopy/strip, etc. sent us as input. */
642 sec_to_styp_flags (const char *sec_name
, flagword sec_flags
)
647 if (startswith (sec_name
, DOT_DEBUG
)
648 || startswith (sec_name
, DOT_ZDEBUG
)
649 #ifdef COFF_LONG_SECTION_NAMES
650 || startswith (sec_name
, GNU_LINKONCE_WI
)
651 || startswith (sec_name
, GNU_LINKONCE_WT
)
653 || startswith (sec_name
, ".stab"))
656 /* caution: there are at least three groups of symbols that have
657 very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
658 SEC_* are the BFD internal flags, used for generic BFD
659 information. STYP_* are the COFF section flags which appear in
660 COFF files. IMAGE_SCN_* are the PE section flags which appear in
661 PE files. The STYP_* flags and the IMAGE_SCN_* flags overlap,
662 but there are more IMAGE_SCN_* flags. */
664 /* FIXME: There is no gas syntax to specify the debug section flag. */
667 sec_flags
&= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
668 | SEC_LINK_DUPLICATES_SAME_CONTENTS
669 | SEC_LINK_DUPLICATES_SAME_SIZE
);
670 sec_flags
|= SEC_DEBUGGING
| SEC_READONLY
;
676 if ((sec_flags
& SEC_CODE
) != 0)
677 styp_flags
|= IMAGE_SCN_CNT_CODE
;
678 if ((sec_flags
& (SEC_DATA
| SEC_DEBUGGING
)) != 0)
679 styp_flags
|= IMAGE_SCN_CNT_INITIALIZED_DATA
;
680 if ((sec_flags
& SEC_ALLOC
) != 0 && (sec_flags
& SEC_LOAD
) == 0)
681 styp_flags
|= IMAGE_SCN_CNT_UNINITIALIZED_DATA
; /* ==STYP_BSS */
683 /* skip constRUCTOR */
685 #ifndef COFF_IMAGE_WITH_PE
686 /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
687 when the output is PE. Only object files should have them, for the linker
689 if ((sec_flags
& SEC_IS_COMMON
) != 0)
690 styp_flags
|= IMAGE_SCN_LNK_COMDAT
;
692 if ((sec_flags
& SEC_DEBUGGING
) != 0)
693 styp_flags
|= IMAGE_SCN_MEM_DISCARDABLE
;
694 if ((sec_flags
& (SEC_EXCLUDE
| SEC_NEVER_LOAD
)) != 0 && !is_dbg
)
695 #ifdef COFF_IMAGE_WITH_PE
696 styp_flags
|= IMAGE_SCN_MEM_DISCARDABLE
;
698 styp_flags
|= IMAGE_SCN_LNK_REMOVE
;
702 #ifndef COFF_IMAGE_WITH_PE
703 if (sec_flags
& SEC_LINK_ONCE
)
704 styp_flags
|= IMAGE_SCN_LNK_COMDAT
;
706 & (SEC_LINK_DUPLICATES_DISCARD
| SEC_LINK_DUPLICATES_SAME_CONTENTS
707 | SEC_LINK_DUPLICATES_SAME_SIZE
)) != 0)
708 styp_flags
|= IMAGE_SCN_LNK_COMDAT
;
711 /* skip LINKER_CREATED */
713 if ((sec_flags
& SEC_COFF_NOREAD
) == 0)
714 styp_flags
|= IMAGE_SCN_MEM_READ
; /* Invert NOREAD for read. */
715 if ((sec_flags
& SEC_READONLY
) == 0)
716 styp_flags
|= IMAGE_SCN_MEM_WRITE
; /* Invert READONLY for write. */
717 if (sec_flags
& SEC_CODE
)
718 styp_flags
|= IMAGE_SCN_MEM_EXECUTE
; /* CODE->EXECUTE. */
719 if (sec_flags
& SEC_COFF_SHARED
)
720 styp_flags
|= IMAGE_SCN_MEM_SHARED
; /* Shared remains meaningful. */
725 #endif /* COFF_WITH_PE */
727 /* Return a word with SEC_* flags set to represent the incoming STYP_*
728 flags (from scnhdr.s_flags). The inverse of this function is
729 sec_to_styp_flags(). NOTE: If you add to/change this routine, you
730 should probably mirror the changes in sec_to_styp_flags(). */
735 styp_to_sec_flags (bfd
*abfd
,
738 asection
*section ATTRIBUTE_UNUSED
,
741 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
742 unsigned long styp_flags
= internal_s
->s_flags
;
743 flagword sec_flags
= 0;
746 if (styp_flags
& STYP_BLOCK
)
747 sec_flags
|= SEC_TIC54X_BLOCK
;
751 if (styp_flags
& STYP_CLINK
)
752 sec_flags
|= SEC_TIC54X_CLINK
;
756 if (styp_flags
& STYP_NOLOAD
)
757 sec_flags
|= SEC_NEVER_LOAD
;
758 #endif /* STYP_NOLOAD */
760 /* For 386 COFF, at least, an unloadable text or data section is
761 actually a shared library section. */
762 if (styp_flags
& STYP_TEXT
)
764 if (sec_flags
& SEC_NEVER_LOAD
)
765 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
767 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
769 else if (styp_flags
& STYP_DATA
)
771 if (sec_flags
& SEC_NEVER_LOAD
)
772 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
774 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
776 else if (styp_flags
& STYP_BSS
)
778 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
779 if (sec_flags
& SEC_NEVER_LOAD
)
780 sec_flags
|= SEC_ALLOC
| SEC_COFF_SHARED_LIBRARY
;
783 sec_flags
|= SEC_ALLOC
;
785 else if (styp_flags
& STYP_INFO
)
787 /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
788 defined. coff_compute_section_file_positions uses
789 COFF_PAGE_SIZE to ensure that the low order bits of the
790 section VMA and the file offset match. If we don't know
791 COFF_PAGE_SIZE, we can't ensure the correct correspondence,
792 and demand page loading of the file will fail. */
793 #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
794 sec_flags
|= SEC_DEBUGGING
;
797 else if (styp_flags
& STYP_PAD
)
800 else if (styp_flags
& STYP_TDATA
)
802 if (sec_flags
& SEC_NEVER_LOAD
)
803 sec_flags
|= SEC_DATA
| SEC_THREAD_LOCAL
| SEC_COFF_SHARED_LIBRARY
;
805 sec_flags
|= SEC_DATA
| SEC_THREAD_LOCAL
| SEC_LOAD
| SEC_ALLOC
;
807 else if (styp_flags
& STYP_TBSS
)
809 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
810 if (sec_flags
& SEC_NEVER_LOAD
)
811 sec_flags
|= SEC_ALLOC
| SEC_THREAD_LOCAL
| SEC_COFF_SHARED_LIBRARY
;
814 sec_flags
|= SEC_ALLOC
| SEC_THREAD_LOCAL
;
816 else if (styp_flags
& STYP_EXCEPT
)
817 sec_flags
|= SEC_LOAD
;
818 else if (styp_flags
& STYP_LOADER
)
819 sec_flags
|= SEC_LOAD
;
820 else if (styp_flags
& STYP_TYPCHK
)
821 sec_flags
|= SEC_LOAD
;
822 else if (styp_flags
& STYP_DWARF
)
823 sec_flags
|= SEC_DEBUGGING
;
825 else if (strcmp (name
, _TEXT
) == 0)
827 if (sec_flags
& SEC_NEVER_LOAD
)
828 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
830 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
832 else if (strcmp (name
, _DATA
) == 0)
834 if (sec_flags
& SEC_NEVER_LOAD
)
835 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
837 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
839 else if (strcmp (name
, _BSS
) == 0)
841 #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
842 if (sec_flags
& SEC_NEVER_LOAD
)
843 sec_flags
|= SEC_ALLOC
| SEC_COFF_SHARED_LIBRARY
;
846 sec_flags
|= SEC_ALLOC
;
848 else if (startswith (name
, DOT_DEBUG
)
849 || startswith (name
, DOT_ZDEBUG
)
851 || strcmp (name
, _COMMENT
) == 0
853 #ifdef COFF_LONG_SECTION_NAMES
854 || startswith (name
, GNU_LINKONCE_WI
)
855 || startswith (name
, GNU_LINKONCE_WT
)
857 || startswith (name
, ".stab"))
859 #ifdef COFF_PAGE_SIZE
860 sec_flags
|= SEC_DEBUGGING
;
864 else if (strcmp (name
, _LIB
) == 0)
868 else if (strcmp (name
, _LIT
) == 0)
869 sec_flags
= SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
872 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
874 #ifdef STYP_LIT /* A29k readonly text/data section type. */
875 if ((styp_flags
& STYP_LIT
) == STYP_LIT
)
876 sec_flags
= (SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
);
877 #endif /* STYP_LIT */
879 #ifdef STYP_OTHER_LOAD /* Other loaded sections. */
880 if (styp_flags
& STYP_OTHER_LOAD
)
881 sec_flags
= (SEC_LOAD
| SEC_ALLOC
);
882 #endif /* STYP_SDATA */
884 if ((bfd_applicable_section_flags (abfd
) & SEC_SMALL_DATA
) != 0
885 && (startswith (name
, ".sbss")
886 || startswith (name
, ".sdata")))
887 sec_flags
|= SEC_SMALL_DATA
;
889 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
890 /* As a GNU extension, if the name begins with .gnu.linkonce, we
891 only link a single copy of the section. This is used to support
892 g++. g++ will emit each template expansion in its own section.
893 The symbols will be defined as weak, so that multiple definitions
894 are permitted. The GNU linker extension is to actually discard
895 all but one of the sections. */
896 if (startswith (name
, ".gnu.linkonce"))
897 sec_flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
900 if (flags_ptr
== NULL
)
903 * flags_ptr
= sec_flags
;
907 #else /* COFF_WITH_PE */
910 handle_COMDAT (bfd
* abfd
,
916 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
917 bfd_byte
*esymstart
, *esym
, *esymend
;
919 char *target_name
= NULL
;
921 sec_flags
|= SEC_LINK_ONCE
;
923 /* Unfortunately, the PE format stores essential information in
924 the symbol table, of all places. We need to extract that
925 information now, so that objdump and the linker will know how
926 to handle the section without worrying about the symbols. We
927 can't call slurp_symtab, because the linker doesn't want the
930 /* COMDAT sections are special. The first symbol is the section
931 symbol, which tells what kind of COMDAT section it is. The
932 second symbol is the "comdat symbol" - the one with the
933 unique name. GNU uses the section symbol for the unique
934 name; MS uses ".text" for every comdat section. Sigh. - DJ */
936 /* This is not mirrored in sec_to_styp_flags(), but there
937 doesn't seem to be a need to, either, and it would at best be
940 if (! _bfd_coff_get_external_symbols (abfd
))
943 esymstart
= esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
944 esymend
= esym
+ obj_raw_syment_count (abfd
) * bfd_coff_symesz (abfd
);
946 while (esym
< esymend
)
948 struct internal_syment isym
;
949 char buf
[SYMNMLEN
+ 1];
952 bfd_coff_swap_sym_in (abfd
, esym
, & isym
);
954 BFD_ASSERT (sizeof (internal_s
->s_name
) <= SYMNMLEN
);
956 if (isym
.n_scnum
== section
->target_index
)
958 /* According to the MSVC documentation, the first
959 TWO entries with the section # are both of
960 interest to us. The first one is the "section
961 symbol" (section name). The second is the comdat
962 symbol name. Here, we've found the first
963 qualifying entry; we distinguish it from the
964 second with a state flag.
966 In the case of gas-generated (at least until that
967 is fixed) .o files, it isn't necessarily the
968 second one. It may be some other later symbol.
970 Since gas also doesn't follow MS conventions and
971 emits the section similar to .text$<name>, where
972 <something> is the name we're looking for, we
973 distinguish the two as follows:
975 If the section name is simply a section name (no
976 $) we presume it's MS-generated, and look at
977 precisely the second symbol for the comdat name.
978 If the section name has a $, we assume it's
979 gas-generated, and look for <something> (whatever
980 follows the $) as the comdat symbol. */
982 /* All 3 branches use this. */
983 symname
= _bfd_coff_internal_syment_name (abfd
, &isym
, buf
);
985 /* PR 17512 file: 078-11867-0.004 */
988 _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
997 /* The first time we've seen the symbol. */
998 union internal_auxent aux
;
1000 /* If it isn't the stuff we're expecting, die;
1001 The MS documentation is vague, but it
1002 appears that the second entry serves BOTH
1003 as the comdat symbol and the defining
1004 symbol record (either C_STAT or C_EXT,
1005 possibly with an aux entry with debug
1006 information if it's a function.) It
1007 appears the only way to find the second one
1008 is to count. (On Intel, they appear to be
1009 adjacent, but on Alpha, they have been
1012 Here, we think we've found the first one,
1013 but there's some checking we can do to be
1016 if (! ((isym
.n_sclass
== C_STAT
1017 || isym
.n_sclass
== C_EXT
)
1018 && BTYPE (isym
.n_type
) == T_NULL
1019 && isym
.n_value
== 0))
1021 /* Malformed input files can trigger this test.
1023 _bfd_error_handler (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1028 /* FIXME LATER: MSVC generates section names
1029 like .text for comdats. Gas generates
1030 names like .text$foo__Fv (in the case of a
1031 function). See comment above for more. */
1033 if (isym
.n_sclass
== C_STAT
&& strcmp (name
, symname
) != 0)
1034 /* xgettext:c-format */
1035 _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1036 " does not match section name '%s'"),
1037 abfd
, symname
, name
);
1041 /* PR 17512: file: e2cfe54f. */
1042 if (esym
+ bfd_coff_symesz (abfd
) >= esymend
)
1044 /* xgettext:c-format */
1045 _bfd_error_handler (_("%pB: warning: no symbol for"
1046 " section '%s' found"),
1050 /* This is the section symbol. */
1051 bfd_coff_swap_aux_in (abfd
, (esym
+ bfd_coff_symesz (abfd
)),
1052 isym
.n_type
, isym
.n_sclass
,
1053 0, isym
.n_numaux
, & aux
);
1055 target_name
= strchr (name
, '$');
1056 if (target_name
!= NULL
)
1064 /* FIXME: Microsoft uses NODUPLICATES and
1065 ASSOCIATIVE, but gnu uses ANY and
1066 SAME_SIZE. Unfortunately, gnu doesn't do
1067 the comdat symbols right. So, until we can
1068 fix it to do the right thing, we are
1069 temporarily disabling comdats for the MS
1070 types (they're used in DLLs and C++, but we
1071 don't support *their* C++ libraries anyway
1074 /* Cygwin does not follow the MS style, and
1075 uses ANY and SAME_SIZE where NODUPLICATES
1076 and ASSOCIATIVE should be used. For
1077 Interix, we just do the right thing up
1080 switch (aux
.x_scn
.x_comdat
)
1082 case IMAGE_COMDAT_SELECT_NODUPLICATES
:
1083 #ifdef STRICT_PE_FORMAT
1084 sec_flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
1086 sec_flags
&= ~SEC_LINK_ONCE
;
1090 case IMAGE_COMDAT_SELECT_ANY
:
1091 sec_flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1094 case IMAGE_COMDAT_SELECT_SAME_SIZE
:
1095 sec_flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
1098 case IMAGE_COMDAT_SELECT_EXACT_MATCH
:
1099 /* Not yet fully implemented ??? */
1100 sec_flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
1103 /* debug$S gets this case; other
1106 /* There may be no symbol... we'll search
1107 the whole table... Is this the right
1108 place to play this game? Or should we do
1109 it when reading it in. */
1110 case IMAGE_COMDAT_SELECT_ASSOCIATIVE
:
1111 #ifdef STRICT_PE_FORMAT
1112 /* FIXME: This is not currently implemented. */
1113 sec_flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1115 sec_flags
&= ~SEC_LINK_ONCE
;
1119 default: /* 0 means "no symbol" */
1120 /* debug$F gets this case; other
1122 sec_flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1129 /* Gas mode: the first matching on partial name. */
1131 #ifndef TARGET_UNDERSCORE
1132 #define TARGET_UNDERSCORE 0
1134 /* Is this the name we're looking for ? */
1135 if (strcmp (target_name
,
1136 symname
+ (TARGET_UNDERSCORE
? 1 : 0)) != 0)
1138 /* Not the name we're looking for */
1139 esym
+= (isym
.n_numaux
+ 1) * bfd_coff_symesz (abfd
);
1144 /* MSVC mode: the lexically second symbol (or
1145 drop through from the above). */
1150 /* This must the second symbol with the
1151 section #. It is the actual symbol name.
1152 Intel puts the two adjacent, but Alpha (at
1153 least) spreads them out. */
1155 amt
= sizeof (struct coff_comdat_info
);
1156 coff_section_data (abfd
, section
)->comdat
1157 = (struct coff_comdat_info
*) bfd_alloc (abfd
, amt
);
1158 if (coff_section_data (abfd
, section
)->comdat
== NULL
)
1161 coff_section_data (abfd
, section
)->comdat
->symbol
=
1162 (esym
- esymstart
) / bfd_coff_symesz (abfd
);
1164 amt
= strlen (symname
) + 1;
1165 newname
= (char *) bfd_alloc (abfd
, amt
);
1166 if (newname
== NULL
)
1169 strcpy (newname
, symname
);
1170 coff_section_data (abfd
, section
)->comdat
->name
1178 esym
+= (isym
.n_numaux
+ 1) * bfd_coff_symesz (abfd
);
1186 /* The PE version; see above for the general comments.
1188 Since to set the SEC_LINK_ONCE and associated flags, we have to
1189 look at the symbol table anyway, we return the symbol table index
1190 of the symbol being used as the COMDAT symbol. This is admittedly
1191 ugly, but there's really nowhere else that we have access to the
1192 required information. FIXME: Is the COMDAT symbol index used for
1193 any purpose other than objdump? */
1196 styp_to_sec_flags (bfd
*abfd
,
1200 flagword
*flags_ptr
)
1202 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
1203 unsigned long styp_flags
= internal_s
->s_flags
;
1206 bool is_dbg
= false;
1208 if (startswith (name
, DOT_DEBUG
)
1209 || startswith (name
, DOT_ZDEBUG
)
1210 #ifdef COFF_LONG_SECTION_NAMES
1211 || startswith (name
, GNU_LINKONCE_WI
)
1212 || startswith (name
, GNU_LINKONCE_WT
)
1213 /* FIXME: These definitions ought to be in a header file. */
1214 #define GNU_DEBUGLINK ".gnu_debuglink"
1215 #define GNU_DEBUGALTLINK ".gnu_debugaltlink"
1216 || startswith (name
, GNU_DEBUGLINK
)
1217 || startswith (name
, GNU_DEBUGALTLINK
)
1219 || startswith (name
, ".stab"))
1221 /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified. */
1222 sec_flags
= SEC_READONLY
;
1224 /* If section disallows read, then set the NOREAD flag. */
1225 if ((styp_flags
& IMAGE_SCN_MEM_READ
) == 0)
1226 sec_flags
|= SEC_COFF_NOREAD
;
1228 /* Process each flag bit in styp_flags in turn. */
1231 unsigned long flag
= styp_flags
& - styp_flags
;
1232 char * unhandled
= NULL
;
1234 styp_flags
&= ~ flag
;
1236 /* We infer from the distinct read/write/execute bits the settings
1237 of some of the bfd flags; the actual values, should we need them,
1238 are also in pei_section_data (abfd, section)->pe_flags. */
1243 unhandled
= "STYP_DSECT";
1246 unhandled
= "STYP_GROUP";
1249 unhandled
= "STYP_COPY";
1252 unhandled
= "STYP_OVER";
1254 #ifdef SEC_NEVER_LOAD
1256 sec_flags
|= SEC_NEVER_LOAD
;
1259 case IMAGE_SCN_MEM_READ
:
1260 sec_flags
&= ~SEC_COFF_NOREAD
;
1262 case IMAGE_SCN_TYPE_NO_PAD
:
1265 case IMAGE_SCN_LNK_OTHER
:
1266 unhandled
= "IMAGE_SCN_LNK_OTHER";
1268 case IMAGE_SCN_MEM_NOT_CACHED
:
1269 unhandled
= "IMAGE_SCN_MEM_NOT_CACHED";
1271 case IMAGE_SCN_MEM_NOT_PAGED
:
1272 /* Generate a warning message rather using the 'unhandled'
1273 variable as this will allow some .sys files generate by
1274 other toolchains to be processed. See bugzilla issue 196. */
1275 /* xgettext:c-format */
1276 _bfd_error_handler (_("%pB: warning: ignoring section flag"
1277 " %s in section %s"),
1278 abfd
, "IMAGE_SCN_MEM_NOT_PAGED", name
);
1280 case IMAGE_SCN_MEM_EXECUTE
:
1281 sec_flags
|= SEC_CODE
;
1283 case IMAGE_SCN_MEM_WRITE
:
1284 sec_flags
&= ~ SEC_READONLY
;
1286 case IMAGE_SCN_MEM_DISCARDABLE
:
1287 /* The MS PE spec says that debug sections are DISCARDABLE,
1288 but the presence of a DISCARDABLE flag does not necessarily
1289 mean that a given section contains debug information. Thus
1290 we only set the SEC_DEBUGGING flag on sections that we
1291 recognise as containing debug information. */
1294 || strcmp (name
, _COMMENT
) == 0
1298 sec_flags
|= SEC_DEBUGGING
| SEC_READONLY
;
1301 case IMAGE_SCN_MEM_SHARED
:
1302 sec_flags
|= SEC_COFF_SHARED
;
1304 case IMAGE_SCN_LNK_REMOVE
:
1306 sec_flags
|= SEC_EXCLUDE
;
1308 case IMAGE_SCN_CNT_CODE
:
1309 sec_flags
|= SEC_CODE
| SEC_ALLOC
| SEC_LOAD
;
1311 case IMAGE_SCN_CNT_INITIALIZED_DATA
:
1313 sec_flags
|= SEC_DEBUGGING
;
1315 sec_flags
|= SEC_DATA
| SEC_ALLOC
| SEC_LOAD
;
1317 case IMAGE_SCN_CNT_UNINITIALIZED_DATA
:
1318 sec_flags
|= SEC_ALLOC
;
1320 case IMAGE_SCN_LNK_INFO
:
1321 /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1322 defined. coff_compute_section_file_positions uses
1323 COFF_PAGE_SIZE to ensure that the low order bits of the
1324 section VMA and the file offset match. If we don't know
1325 COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1326 and demand page loading of the file will fail. */
1327 #ifdef COFF_PAGE_SIZE
1328 sec_flags
|= SEC_DEBUGGING
;
1331 case IMAGE_SCN_LNK_COMDAT
:
1332 /* COMDAT gets very special treatment. */
1333 sec_flags
= handle_COMDAT (abfd
, sec_flags
, hdr
, name
, section
);
1336 /* Silently ignore for now. */
1340 /* If the section flag was not handled, report it here. */
1341 if (unhandled
!= NULL
)
1344 /* xgettext:c-format */
1345 (_("%pB (%s): section flag %s (%#lx) ignored"),
1346 abfd
, name
, unhandled
, flag
);
1351 if ((bfd_applicable_section_flags (abfd
) & SEC_SMALL_DATA
) != 0
1352 && (startswith (name
, ".sbss")
1353 || startswith (name
, ".sdata")))
1354 sec_flags
|= SEC_SMALL_DATA
;
1356 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1357 /* As a GNU extension, if the name begins with .gnu.linkonce, we
1358 only link a single copy of the section. This is used to support
1359 g++. g++ will emit each template expansion in its own section.
1360 The symbols will be defined as weak, so that multiple definitions
1361 are permitted. The GNU linker extension is to actually discard
1362 all but one of the sections. */
1363 if (startswith (name
, ".gnu.linkonce"))
1364 sec_flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1368 * flags_ptr
= sec_flags
;
1373 #endif /* COFF_WITH_PE */
1375 #define get_index(symbol) ((symbol)->udata.i)
1379 bfd_coff_backend_data
1382 .{* COFF symbol classifications. *}
1384 .enum coff_symbol_classification
1386 . {* Global symbol. *}
1387 . COFF_SYMBOL_GLOBAL,
1388 . {* Common symbol. *}
1389 . COFF_SYMBOL_COMMON,
1390 . {* Undefined symbol. *}
1391 . COFF_SYMBOL_UNDEFINED,
1392 . {* Local symbol. *}
1393 . COFF_SYMBOL_LOCAL,
1394 . {* PE section symbol. *}
1395 . COFF_SYMBOL_PE_SECTION
1398 .typedef asection * (*coff_gc_mark_hook_fn)
1399 . (asection *, struct bfd_link_info *, struct internal_reloc *,
1400 . struct coff_link_hash_entry *, struct internal_syment *);
1403 Special entry points for gdb to swap in coff symbol table parts:
1408 . void (*_bfd_coff_swap_aux_in)
1409 . (bfd *, void *, int, int, int, int, void *);
1411 . void (*_bfd_coff_swap_sym_in)
1412 . (bfd *, void *, void *);
1414 . void (*_bfd_coff_swap_lineno_in)
1415 . (bfd *, void *, void *);
1417 . unsigned int (*_bfd_coff_swap_aux_out)
1418 . (bfd *, void *, int, int, int, int, void *);
1420 . unsigned int (*_bfd_coff_swap_sym_out)
1421 . (bfd *, void *, void *);
1423 . unsigned int (*_bfd_coff_swap_lineno_out)
1424 . (bfd *, void *, void *);
1426 . unsigned int (*_bfd_coff_swap_reloc_out)
1427 . (bfd *, void *, void *);
1429 . unsigned int (*_bfd_coff_swap_filehdr_out)
1430 . (bfd *, void *, void *);
1432 . unsigned int (*_bfd_coff_swap_aouthdr_out)
1433 . (bfd *, void *, void *);
1435 . unsigned int (*_bfd_coff_swap_scnhdr_out)
1436 . (bfd *, void *, void *);
1438 . unsigned int _bfd_filhsz;
1439 . unsigned int _bfd_aoutsz;
1440 . unsigned int _bfd_scnhsz;
1441 . unsigned int _bfd_symesz;
1442 . unsigned int _bfd_auxesz;
1443 . unsigned int _bfd_relsz;
1444 . unsigned int _bfd_linesz;
1445 . unsigned int _bfd_filnmlen;
1446 . bool _bfd_coff_long_filenames;
1448 . bool _bfd_coff_long_section_names;
1449 . bool (*_bfd_coff_set_long_section_names)
1452 . unsigned int _bfd_coff_default_section_alignment_power;
1453 . bool _bfd_coff_force_symnames_in_strings;
1454 . unsigned int _bfd_coff_debug_string_prefix_length;
1455 . unsigned int _bfd_coff_max_nscns;
1457 . void (*_bfd_coff_swap_filehdr_in)
1458 . (bfd *, void *, void *);
1460 . void (*_bfd_coff_swap_aouthdr_in)
1461 . (bfd *, void *, void *);
1463 . void (*_bfd_coff_swap_scnhdr_in)
1464 . (bfd *, void *, void *);
1466 . void (*_bfd_coff_swap_reloc_in)
1467 . (bfd *abfd, void *, void *);
1469 . bool (*_bfd_coff_bad_format_hook)
1472 . bool (*_bfd_coff_set_arch_mach_hook)
1475 . void * (*_bfd_coff_mkobject_hook)
1476 . (bfd *, void *, void *);
1478 . bool (*_bfd_styp_to_sec_flags_hook)
1479 . (bfd *, void *, const char *, asection *, flagword *);
1481 . void (*_bfd_set_alignment_hook)
1482 . (bfd *, asection *, void *);
1484 . bool (*_bfd_coff_slurp_symbol_table)
1487 . bool (*_bfd_coff_symname_in_debug)
1488 . (bfd *, struct internal_syment *);
1490 . bool (*_bfd_coff_pointerize_aux_hook)
1491 . (bfd *, combined_entry_type *, combined_entry_type *,
1492 . unsigned int, combined_entry_type *);
1494 . bool (*_bfd_coff_print_aux)
1495 . (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
1496 . combined_entry_type *, unsigned int);
1498 . bool (*_bfd_coff_reloc16_extra_cases)
1499 . (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
1500 . bfd_byte *, size_t *, size_t *);
1502 . int (*_bfd_coff_reloc16_estimate)
1503 . (bfd *, asection *, arelent *, unsigned int,
1504 . struct bfd_link_info *);
1506 . enum coff_symbol_classification (*_bfd_coff_classify_symbol)
1507 . (bfd *, struct internal_syment *);
1509 . bool (*_bfd_coff_compute_section_file_positions)
1512 . bool (*_bfd_coff_start_final_link)
1513 . (bfd *, struct bfd_link_info *);
1515 . bool (*_bfd_coff_relocate_section)
1516 . (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
1517 . struct internal_reloc *, struct internal_syment *, asection **);
1519 . reloc_howto_type *(*_bfd_coff_rtype_to_howto)
1520 . (bfd *, asection *, struct internal_reloc *,
1521 . struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *);
1523 . bool (*_bfd_coff_adjust_symndx)
1524 . (bfd *, struct bfd_link_info *, bfd *, asection *,
1525 . struct internal_reloc *, bool *);
1527 . bool (*_bfd_coff_link_add_one_symbol)
1528 . (struct bfd_link_info *, bfd *, const char *, flagword,
1529 . asection *, bfd_vma, const char *, bool, bool,
1530 . struct bfd_link_hash_entry **);
1532 . bool (*_bfd_coff_link_output_has_begun)
1533 . (bfd *, struct coff_final_link_info *);
1535 . bool (*_bfd_coff_final_link_postscript)
1536 . (bfd *, struct coff_final_link_info *);
1538 . bool (*_bfd_coff_print_pdata)
1541 .} bfd_coff_backend_data;
1545 .#define coff_backend_info(abfd) \
1546 . ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data)
1548 .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
1549 . ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
1551 .#define bfd_coff_swap_sym_in(a,e,i) \
1552 . ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
1554 .#define bfd_coff_swap_lineno_in(a,e,i) \
1555 . ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
1557 .#define bfd_coff_swap_reloc_out(abfd, i, o) \
1558 . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
1560 .#define bfd_coff_swap_lineno_out(abfd, i, o) \
1561 . ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
1563 .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
1564 . ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
1566 .#define bfd_coff_swap_sym_out(abfd, i,o) \
1567 . ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
1569 .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
1570 . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
1572 .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
1573 . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
1575 .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
1576 . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
1578 .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
1579 .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
1580 .#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
1581 .#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
1582 .#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
1583 .#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
1584 .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
1585 .#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
1586 .#define bfd_coff_long_filenames(abfd) \
1587 . (coff_backend_info (abfd)->_bfd_coff_long_filenames)
1588 .#define bfd_coff_long_section_names(abfd) \
1589 . (coff_data (abfd)->long_section_names)
1590 .#define bfd_coff_set_long_section_names(abfd, enable) \
1591 . ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
1592 .#define bfd_coff_default_section_alignment_power(abfd) \
1593 . (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
1594 .#define bfd_coff_max_nscns(abfd) \
1595 . (coff_backend_info (abfd)->_bfd_coff_max_nscns)
1597 .#define bfd_coff_swap_filehdr_in(abfd, i,o) \
1598 . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
1600 .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
1601 . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
1603 .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
1604 . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
1606 .#define bfd_coff_swap_reloc_in(abfd, i, o) \
1607 . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
1609 .#define bfd_coff_bad_format_hook(abfd, filehdr) \
1610 . ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
1612 .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
1613 . ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
1614 .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
1615 . ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
1616 . (abfd, filehdr, aouthdr))
1618 .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
1619 . ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
1620 . (abfd, scnhdr, name, section, flags_ptr))
1622 .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
1623 . ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
1625 .#define bfd_coff_slurp_symbol_table(abfd)\
1626 . ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
1628 .#define bfd_coff_symname_in_debug(abfd, sym)\
1629 . ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
1631 .#define bfd_coff_force_symnames_in_strings(abfd)\
1632 . (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
1634 .#define bfd_coff_debug_string_prefix_length(abfd)\
1635 . (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
1637 .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
1638 . ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
1639 . (abfd, file, base, symbol, aux, indaux))
1641 .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
1642 . reloc, data, src_ptr, dst_ptr)\
1643 . ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
1644 . (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
1646 .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
1647 . ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
1648 . (abfd, section, reloc, shrink, link_info))
1650 .#define bfd_coff_classify_symbol(abfd, sym)\
1651 . ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
1654 .#define bfd_coff_compute_section_file_positions(abfd)\
1655 . ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
1658 .#define bfd_coff_start_final_link(obfd, info)\
1659 . ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
1661 .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
1662 . ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
1663 . (obfd, info, ibfd, o, con, rel, isyms, secs))
1664 .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
1665 . ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
1666 . (abfd, sec, rel, h, sym, addendp))
1667 .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
1668 . ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
1669 . (obfd, info, ibfd, sec, rel, adjustedp))
1670 .#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
1671 . value, string, cp, coll, hashp)\
1672 . ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
1673 . (info, abfd, name, flags, section, value, string, cp, coll, hashp))
1675 .#define bfd_coff_link_output_has_begun(a,p) \
1676 . ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
1677 .#define bfd_coff_final_link_postscript(a,p) \
1678 . ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
1680 .#define bfd_coff_have_print_pdata(a) \
1681 . (coff_backend_info (a)->_bfd_coff_print_pdata)
1682 .#define bfd_coff_print_pdata(a,p) \
1683 . ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
1685 .{* Macro: Returns true if the bfd is a PE executable as opposed to a
1686 . PE object file. *}
1687 .#define bfd_pei_p(abfd) \
1688 . (startswith ((abfd)->xvec->name, "pei-"))
1691 /* See whether the magic number matches. */
1694 coff_bad_format_hook (bfd
* abfd ATTRIBUTE_UNUSED
, void * filehdr
)
1696 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
1698 if (BADMAG (*internal_f
))
1706 ticoff0_bad_format_hook (bfd
*abfd ATTRIBUTE_UNUSED
, void * filehdr
)
1708 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
1710 if (COFF0_BADMAG (*internal_f
))
1719 ticoff1_bad_format_hook (bfd
*abfd ATTRIBUTE_UNUSED
, void * filehdr
)
1721 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
1723 if (COFF1_BADMAG (*internal_f
))
1730 /* Check whether this section uses an alignment other than the
1734 coff_set_custom_section_alignment (bfd
*abfd ATTRIBUTE_UNUSED
,
1736 const struct coff_section_alignment_entry
*alignment_table
,
1737 const unsigned int table_size
)
1739 const unsigned int default_alignment
= COFF_DEFAULT_SECTION_ALIGNMENT_POWER
;
1742 for (i
= 0; i
< table_size
; ++i
)
1744 const char *secname
= bfd_section_name (section
);
1746 if (alignment_table
[i
].comparison_length
== (unsigned int) -1
1747 ? strcmp (alignment_table
[i
].name
, secname
) == 0
1748 : strncmp (alignment_table
[i
].name
, secname
,
1749 alignment_table
[i
].comparison_length
) == 0)
1752 if (i
>= table_size
)
1755 if (alignment_table
[i
].default_alignment_min
!= COFF_ALIGNMENT_FIELD_EMPTY
1756 && default_alignment
< alignment_table
[i
].default_alignment_min
)
1759 if (alignment_table
[i
].default_alignment_max
!= COFF_ALIGNMENT_FIELD_EMPTY
1760 #if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1761 && default_alignment
> alignment_table
[i
].default_alignment_max
1766 section
->alignment_power
= alignment_table
[i
].alignment_power
;
1769 /* Custom section alignment records. */
1771 static const struct coff_section_alignment_entry
1772 coff_section_alignment_table
[] =
1774 #ifdef COFF_SECTION_ALIGNMENT_ENTRIES
1775 COFF_SECTION_ALIGNMENT_ENTRIES
,
1777 /* There must not be any gaps between .stabstr sections. */
1778 { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
1779 1, COFF_ALIGNMENT_FIELD_EMPTY
, 0 },
1780 /* The .stab section must be aligned to 2**2 at most, to avoid gaps. */
1781 { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
1782 3, COFF_ALIGNMENT_FIELD_EMPTY
, 2 },
1783 /* Similarly for the .ctors and .dtors sections. */
1784 { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
1785 3, COFF_ALIGNMENT_FIELD_EMPTY
, 2 },
1786 { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
1787 3, COFF_ALIGNMENT_FIELD_EMPTY
, 2 }
1790 static const unsigned int coff_section_alignment_table_size
=
1791 sizeof coff_section_alignment_table
/ sizeof coff_section_alignment_table
[0];
1793 /* Initialize a section structure with information peculiar to this
1794 particular implementation of COFF. */
1797 coff_new_section_hook (bfd
* abfd
, asection
* section
)
1799 combined_entry_type
*native
;
1801 unsigned char sclass
= C_STAT
;
1803 section
->alignment_power
= COFF_DEFAULT_SECTION_ALIGNMENT_POWER
;
1806 if (bfd_xcoff_text_align_power (abfd
) != 0
1807 && strcmp (bfd_section_name (section
), ".text") == 0)
1808 section
->alignment_power
= bfd_xcoff_text_align_power (abfd
);
1809 else if (bfd_xcoff_data_align_power (abfd
) != 0
1810 && strcmp (bfd_section_name (section
), ".data") == 0)
1811 section
->alignment_power
= bfd_xcoff_data_align_power (abfd
);
1816 for (i
= 0; i
< XCOFF_DWSECT_NBR_NAMES
; i
++)
1817 if (strcmp (bfd_section_name (section
),
1818 xcoff_dwsect_names
[i
].xcoff_name
) == 0)
1820 section
->alignment_power
= 0;
1827 /* Set up the section symbol. */
1828 if (!_bfd_generic_new_section_hook (abfd
, section
))
1831 /* Allocate aux records for section symbols, to store size and
1834 @@ The 10 is a guess at a plausible maximum number of aux entries
1835 (but shouldn't be a constant). */
1836 amt
= sizeof (combined_entry_type
) * 10;
1837 native
= (combined_entry_type
*) bfd_zalloc (abfd
, amt
);
1841 /* We don't need to set up n_name, n_value, or n_scnum in the native
1842 symbol information, since they'll be overridden by the BFD symbol
1843 anyhow. However, we do need to set the type and storage class,
1844 in case this symbol winds up getting written out. The value 0
1845 for n_numaux is already correct. */
1847 native
->is_sym
= true;
1848 native
->u
.syment
.n_type
= T_NULL
;
1849 native
->u
.syment
.n_sclass
= sclass
;
1851 coffsymbol (section
->symbol
)->native
= native
;
1853 coff_set_custom_section_alignment (abfd
, section
,
1854 coff_section_alignment_table
,
1855 coff_section_alignment_table_size
);
1860 #ifdef COFF_ALIGN_IN_SECTION_HEADER
1862 /* Set the alignment of a BFD section. */
1865 coff_set_alignment_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
1869 struct internal_scnhdr
*hdr
= (struct internal_scnhdr
*) scnhdr
;
1872 #ifdef COFF_DECODE_ALIGNMENT
1873 i
= COFF_DECODE_ALIGNMENT(hdr
->s_flags
);
1875 section
->alignment_power
= i
;
1877 #ifdef coff_set_section_load_page
1878 coff_set_section_load_page (section
, hdr
->s_page
);
1882 #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
1886 coff_set_alignment_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
1890 struct internal_scnhdr
*hdr
= (struct internal_scnhdr
*) scnhdr
;
1892 unsigned int alignment_power_const
1893 = hdr
->s_flags
& IMAGE_SCN_ALIGN_POWER_BIT_MASK
;
1895 switch (alignment_power_const
)
1897 case IMAGE_SCN_ALIGN_8192BYTES
:
1898 case IMAGE_SCN_ALIGN_4096BYTES
:
1899 case IMAGE_SCN_ALIGN_2048BYTES
:
1900 case IMAGE_SCN_ALIGN_1024BYTES
:
1901 case IMAGE_SCN_ALIGN_512BYTES
:
1902 case IMAGE_SCN_ALIGN_256BYTES
:
1903 case IMAGE_SCN_ALIGN_128BYTES
:
1904 case IMAGE_SCN_ALIGN_64BYTES
:
1905 case IMAGE_SCN_ALIGN_32BYTES
:
1906 case IMAGE_SCN_ALIGN_16BYTES
:
1907 case IMAGE_SCN_ALIGN_8BYTES
:
1908 case IMAGE_SCN_ALIGN_4BYTES
:
1909 case IMAGE_SCN_ALIGN_2BYTES
:
1910 case IMAGE_SCN_ALIGN_1BYTES
:
1911 section
->alignment_power
1912 = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const
);
1918 /* In a PE image file, the s_paddr field holds the virtual size of a
1919 section, while the s_size field holds the raw size. We also keep
1920 the original section flag value, since not every bit can be
1921 mapped onto a generic BFD section bit. */
1922 if (coff_section_data (abfd
, section
) == NULL
)
1924 amt
= sizeof (struct coff_section_tdata
);
1925 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
1926 if (section
->used_by_bfd
== NULL
)
1927 /* FIXME: Return error. */
1931 if (pei_section_data (abfd
, section
) == NULL
)
1933 amt
= sizeof (struct pei_section_tdata
);
1934 coff_section_data (abfd
, section
)->tdata
= bfd_zalloc (abfd
, amt
);
1935 if (coff_section_data (abfd
, section
)->tdata
== NULL
)
1936 /* FIXME: Return error. */
1939 pei_section_data (abfd
, section
)->virt_size
= hdr
->s_paddr
;
1940 pei_section_data (abfd
, section
)->pe_flags
= hdr
->s_flags
;
1942 section
->lma
= hdr
->s_vaddr
;
1944 /* Check for extended relocs. */
1945 if (hdr
->s_flags
& IMAGE_SCN_LNK_NRELOC_OVFL
)
1947 struct external_reloc dst
;
1948 struct internal_reloc n
;
1949 file_ptr oldpos
= bfd_tell (abfd
);
1950 bfd_size_type relsz
= bfd_coff_relsz (abfd
);
1952 if (bfd_seek (abfd
, (file_ptr
) hdr
->s_relptr
, 0) != 0)
1954 if (bfd_bread (& dst
, relsz
, abfd
) != relsz
)
1957 bfd_coff_swap_reloc_in (abfd
, &dst
, &n
);
1958 if (bfd_seek (abfd
, oldpos
, 0) != 0)
1960 if (n
.r_vaddr
< 0x10000)
1962 _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd
);
1963 bfd_set_error (bfd_error_bad_value
);
1966 section
->reloc_count
= hdr
->s_nreloc
= n
.r_vaddr
- 1;
1967 section
->rel_filepos
+= relsz
;
1969 else if (hdr
->s_nreloc
== 0xffff)
1971 (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1975 #undef ELIFALIGN_SET
1977 #else /* ! COFF_WITH_PE */
1980 /* We grossly abuse this function to handle XCOFF overflow headers.
1981 When we see one, we correct the reloc and line number counts in the
1982 real header, and remove the section we just created. */
1985 coff_set_alignment_hook (bfd
*abfd
, asection
*section
, void * scnhdr
)
1987 struct internal_scnhdr
*hdr
= (struct internal_scnhdr
*) scnhdr
;
1990 if ((hdr
->s_flags
& STYP_OVRFLO
) == 0)
1993 real_sec
= coff_section_from_bfd_index (abfd
, (int) hdr
->s_nreloc
);
1994 if (real_sec
== NULL
)
1997 real_sec
->reloc_count
= hdr
->s_paddr
;
1998 real_sec
->lineno_count
= hdr
->s_vaddr
;
2000 if (!bfd_section_removed_from_list (abfd
, section
))
2002 bfd_section_list_remove (abfd
, section
);
2003 --abfd
->section_count
;
2007 #else /* ! RS6000COFF_C */
2008 #if defined (COFF_GO32_EXE) || defined (COFF_GO32)
2011 coff_set_alignment_hook (bfd
* abfd
, asection
* section
, void * scnhdr
)
2013 struct internal_scnhdr
*hdr
= (struct internal_scnhdr
*) scnhdr
;
2015 /* Check for extended relocs. */
2016 if (hdr
->s_flags
& IMAGE_SCN_LNK_NRELOC_OVFL
)
2018 struct external_reloc dst
;
2019 struct internal_reloc n
;
2020 const file_ptr oldpos
= bfd_tell (abfd
);
2021 const bfd_size_type relsz
= bfd_coff_relsz (abfd
);
2023 if (bfd_seek (abfd
, (file_ptr
) hdr
->s_relptr
, 0) != 0)
2025 if (bfd_bread (& dst
, relsz
, abfd
) != relsz
)
2028 bfd_coff_swap_reloc_in (abfd
, &dst
, &n
);
2029 if (bfd_seek (abfd
, oldpos
, 0) != 0)
2031 section
->reloc_count
= hdr
->s_nreloc
= n
.r_vaddr
- 1;
2032 section
->rel_filepos
+= relsz
;
2034 else if (hdr
->s_nreloc
== 0xffff)
2036 (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2040 #else /* ! COFF_GO32_EXE && ! COFF_GO32 */
2043 coff_set_alignment_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
2044 asection
*section ATTRIBUTE_UNUSED
,
2045 void *scnhdr ATTRIBUTE_UNUSED
)
2049 #endif /* ! COFF_GO32_EXE && ! COFF_GO32 */
2050 #endif /* ! RS6000COFF_C */
2051 #endif /* ! COFF_WITH_PE */
2052 #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
2054 #ifndef coff_mkobject
2057 coff_mkobject (bfd
* abfd
)
2059 coff_data_type
*coff
;
2060 size_t amt
= sizeof (coff_data_type
);
2062 abfd
->tdata
.coff_obj_data
= bfd_zalloc (abfd
, amt
);
2063 if (abfd
->tdata
.coff_obj_data
== NULL
)
2065 coff
= coff_data (abfd
);
2066 coff
->symbols
= NULL
;
2067 coff
->conversion_table
= NULL
;
2068 coff
->raw_syments
= NULL
;
2069 coff
->relocbase
= 0;
2070 coff
->local_toc_sym_map
= 0;
2072 bfd_coff_long_section_names (abfd
)
2073 = coff_backend_info (abfd
)->_bfd_coff_long_section_names
;
2075 /* make_abs_section(abfd);*/
2081 /* Create the COFF backend specific information. */
2083 #ifndef coff_mkobject_hook
2085 coff_mkobject_hook (bfd
* abfd
,
2087 void * aouthdr ATTRIBUTE_UNUSED
)
2089 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
2090 coff_data_type
*coff
;
2092 if (! coff_mkobject (abfd
))
2095 coff
= coff_data (abfd
);
2097 coff
->sym_filepos
= internal_f
->f_symptr
;
2099 /* These members communicate important constants about the symbol
2100 table to GDB's symbol-reading code. These `constants'
2101 unfortunately vary among coff implementations... */
2102 coff
->local_n_btmask
= N_BTMASK
;
2103 coff
->local_n_btshft
= N_BTSHFT
;
2104 coff
->local_n_tmask
= N_TMASK
;
2105 coff
->local_n_tshift
= N_TSHIFT
;
2106 coff
->local_symesz
= bfd_coff_symesz (abfd
);
2107 coff
->local_auxesz
= bfd_coff_auxesz (abfd
);
2108 coff
->local_linesz
= bfd_coff_linesz (abfd
);
2110 coff
->timestamp
= internal_f
->f_timdat
;
2112 obj_raw_syment_count (abfd
) =
2113 obj_conv_table_size (abfd
) =
2114 internal_f
->f_nsyms
;
2117 if ((internal_f
->f_flags
& F_SHROBJ
) != 0)
2118 abfd
->flags
|= DYNAMIC
;
2119 if (aouthdr
!= NULL
&& internal_f
->f_opthdr
>= bfd_coff_aoutsz (abfd
))
2121 struct internal_aouthdr
*internal_a
=
2122 (struct internal_aouthdr
*) aouthdr
;
2123 struct xcoff_tdata
*xcoff
;
2125 xcoff
= xcoff_data (abfd
);
2126 # ifdef U803XTOCMAGIC
2127 xcoff
->xcoff64
= internal_f
->f_magic
== U803XTOCMAGIC
;
2131 xcoff
->full_aouthdr
= true;
2132 xcoff
->toc
= internal_a
->o_toc
;
2133 xcoff
->sntoc
= internal_a
->o_sntoc
;
2134 xcoff
->snentry
= internal_a
->o_snentry
;
2135 bfd_xcoff_text_align_power (abfd
) = internal_a
->o_algntext
;
2136 bfd_xcoff_data_align_power (abfd
) = internal_a
->o_algndata
;
2137 xcoff
->modtype
= internal_a
->o_modtype
;
2138 xcoff
->cputype
= internal_a
->o_cputype
;
2139 xcoff
->maxdata
= internal_a
->o_maxdata
;
2140 xcoff
->maxstack
= internal_a
->o_maxstack
;
2145 /* Set the flags field from the COFF header read in. */
2146 if (! _bfd_coff_arm_set_private_flags (abfd
, internal_f
->f_flags
))
2151 /* FIXME: I'm not sure this is ever executed, since peicode.h
2152 defines coff_mkobject_hook. */
2153 if ((internal_f
->f_flags
& IMAGE_FILE_DEBUG_STRIPPED
) == 0)
2154 abfd
->flags
|= HAS_DEBUG
;
2161 /* Determine the machine architecture and type. FIXME: This is target
2162 dependent because the magic numbers are defined in the target
2163 dependent header files. But there is no particular need for this.
2164 If the magic numbers were moved to a separate file, this function
2165 would be target independent and would also be much more successful
2166 at linking together COFF files for different architectures. */
2169 coff_set_arch_mach_hook (bfd
*abfd
, void * filehdr
)
2171 unsigned long machine
;
2172 enum bfd_architecture arch
;
2173 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
2175 /* Zero selects the default machine for an arch. */
2177 switch (internal_f
->f_magic
)
2182 case I386AIXMAGIC
: /* Danbury PS/2 AIX C Compiler. */
2184 case I386_APPLE_MAGIC
:
2185 case I386_FREEBSD_MAGIC
:
2186 case I386_LINUX_MAGIC
:
2187 case I386_NETBSD_MAGIC
:
2188 arch
= bfd_arch_i386
;
2193 case AMD64_APPLE_MAGIC
:
2194 case AMD64_FREEBSD_MAGIC
:
2195 case AMD64_LINUX_MAGIC
:
2196 case AMD64_NETBSD_MAGIC
:
2197 arch
= bfd_arch_i386
;
2198 machine
= bfd_mach_x86_64
;
2203 arch
= bfd_arch_ia64
;
2210 arch
= bfd_arch_arm
;
2211 machine
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
2212 if (machine
== bfd_mach_arm_unknown
)
2214 switch (internal_f
->f_flags
& F_ARM_ARCHITECTURE_MASK
)
2216 case F_ARM_2
: machine
= bfd_mach_arm_2
; break;
2217 case F_ARM_2a
: machine
= bfd_mach_arm_2a
; break;
2218 case F_ARM_3
: machine
= bfd_mach_arm_3
; break;
2220 case F_ARM_3M
: machine
= bfd_mach_arm_3M
; break;
2221 case F_ARM_4
: machine
= bfd_mach_arm_4
; break;
2222 case F_ARM_4T
: machine
= bfd_mach_arm_4T
; break;
2223 /* The COFF header does not have enough bits available
2224 to cover all the different ARM architectures. So
2225 we interpret F_ARM_5, the highest flag value to mean
2226 "the highest ARM architecture known to BFD" which is
2227 currently the XScale. */
2228 case F_ARM_5
: machine
= bfd_mach_arm_XScale
; break;
2235 arch
= bfd_arch_aarch64
;
2236 machine
= internal_f
->f_flags
& F_AARCH64_ARCHITECTURE_MASK
;
2239 #ifdef LOONGARCH64MAGIC
2240 case LOONGARCH64MAGIC
:
2241 arch
= bfd_arch_loongarch
;
2242 machine
= internal_f
->f_flags
& F_LOONGARCH64_ARCHITECTURE_MASK
;
2247 arch
= bfd_arch_z80
;
2248 switch (internal_f
->f_flags
& F_MACHMASK
)
2250 case bfd_mach_z80strict
<< 12:
2251 case bfd_mach_z80
<< 12:
2252 case bfd_mach_z80n
<< 12:
2253 case bfd_mach_z80full
<< 12:
2254 case bfd_mach_r800
<< 12:
2255 case bfd_mach_gbz80
<< 12:
2256 case bfd_mach_z180
<< 12:
2257 case bfd_mach_ez80_z80
<< 12:
2258 case bfd_mach_ez80_adl
<< 12:
2259 machine
= ((unsigned)internal_f
->f_flags
& F_MACHMASK
) >> 12;
2268 arch
= bfd_arch_z8k
;
2269 switch (internal_f
->f_flags
& F_MACHMASK
)
2272 machine
= bfd_mach_z8001
;
2275 machine
= bfd_mach_z8002
;
2295 if (xcoff_data (abfd
)->cputype
!= -1)
2296 cputype
= xcoff_data (abfd
)->cputype
& 0xff;
2299 /* We did not get a value from the a.out header. If the
2300 file has not been stripped, we may be able to get the
2301 architecture information from the first symbol, if it
2302 is a .file symbol. */
2303 if (obj_raw_syment_count (abfd
) == 0)
2308 struct internal_syment sym
;
2309 bfd_size_type amt
= bfd_coff_symesz (abfd
);
2311 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0)
2313 buf
= _bfd_malloc_and_read (abfd
, amt
, amt
);
2316 bfd_coff_swap_sym_in (abfd
, buf
, & sym
);
2317 if (sym
.n_sclass
== C_FILE
)
2318 cputype
= sym
.n_type
& 0xff;
2325 /* FIXME: We don't handle all cases here. */
2330 arch
= bfd_xcoff_architecture (abfd
);
2331 machine
= bfd_xcoff_machine (abfd
);
2335 arch
= bfd_arch_powerpc
;
2336 machine
= bfd_mach_ppc_601
;
2338 case 2: /* 64 bit PowerPC */
2339 arch
= bfd_arch_powerpc
;
2340 machine
= bfd_mach_ppc_620
;
2343 arch
= bfd_arch_powerpc
;
2344 machine
= bfd_mach_ppc
;
2347 arch
= bfd_arch_rs6000
;
2348 machine
= bfd_mach_rs6k
;
2355 #ifdef SH_ARCH_MAGIC_BIG
2356 case SH_ARCH_MAGIC_BIG
:
2357 case SH_ARCH_MAGIC_LITTLE
:
2359 case SH_ARCH_MAGIC_WINCE
:
2365 #ifdef MIPS_ARCH_MAGIC_WINCE
2366 case MIPS_ARCH_MAGIC_WINCE
:
2367 arch
= bfd_arch_mips
;
2373 #ifdef LYNXCOFFMAGIC
2376 arch
= bfd_arch_sparc
;
2382 arch
= bfd_arch_tic30
;
2387 #ifdef TICOFF_TARGET_ARCH
2388 /* This TI COFF section should be used by all new TI COFF v0 targets. */
2390 arch
= TICOFF_TARGET_ARCH
;
2391 machine
= TICOFF_TARGET_MACHINE_GET (internal_f
->f_flags
);
2397 /* This TI COFF section should be used by all new TI COFF v1/2 targets. */
2398 /* TI COFF1 and COFF2 use the target_id field to specify which arch. */
2401 switch (internal_f
->f_target_id
)
2405 arch
= TICOFF_TARGET_ARCH
;
2406 machine
= TICOFF_TARGET_MACHINE_GET (internal_f
->f_flags
);
2410 arch
= bfd_arch_obscure
;
2412 (_("unrecognized TI COFF target id '0x%x'"),
2413 internal_f
->f_target_id
);
2421 arch
= bfd_arch_mcore
;
2425 default: /* Unreadable input file type. */
2426 arch
= bfd_arch_obscure
;
2430 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2435 symname_in_debug_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
2436 struct internal_syment
*sym ATTRIBUTE_UNUSED
)
2438 #ifdef SYMNAME_IN_DEBUG
2439 return SYMNAME_IN_DEBUG (sym
) != 0;
2448 #define FORCE_SYMNAMES_IN_STRINGS
2451 /* Handle the csect auxent of a C_EXT, C_AIX_WEAKEXT or C_HIDEXT symbol. */
2454 coff_pointerize_aux_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
2455 combined_entry_type
*table_base
,
2456 combined_entry_type
*symbol
,
2457 unsigned int indaux
,
2458 combined_entry_type
*aux
)
2460 BFD_ASSERT (symbol
->is_sym
);
2461 int n_sclass
= symbol
->u
.syment
.n_sclass
;
2463 if (CSECT_SYM_P (n_sclass
)
2464 && indaux
+ 1 == symbol
->u
.syment
.n_numaux
)
2466 BFD_ASSERT (! aux
->is_sym
);
2467 if (SMTYP_SMTYP (aux
->u
.auxent
.x_csect
.x_smtyp
) == XTY_LD
2468 && aux
->u
.auxent
.x_csect
.x_scnlen
.u64
< obj_raw_syment_count (abfd
))
2470 aux
->u
.auxent
.x_csect
.x_scnlen
.p
=
2471 table_base
+ aux
->u
.auxent
.x_csect
.x_scnlen
.u64
;
2472 aux
->fix_scnlen
= 1;
2475 /* Return TRUE to indicate that the caller should not do any
2476 further work on this auxent. */
2480 /* Return FALSE to indicate that this auxent should be handled by
2486 #define coff_pointerize_aux_hook 0
2487 #endif /* ! RS6000COFF_C */
2489 /* Print an aux entry. This returns TRUE if it has printed it. */
2492 coff_print_aux (bfd
*abfd ATTRIBUTE_UNUSED
,
2493 FILE *file ATTRIBUTE_UNUSED
,
2494 combined_entry_type
*table_base ATTRIBUTE_UNUSED
,
2495 combined_entry_type
*symbol ATTRIBUTE_UNUSED
,
2496 combined_entry_type
*aux ATTRIBUTE_UNUSED
,
2497 unsigned int indaux ATTRIBUTE_UNUSED
)
2499 BFD_ASSERT (symbol
->is_sym
);
2500 BFD_ASSERT (! aux
->is_sym
);
2502 if (CSECT_SYM_P (symbol
->u
.syment
.n_sclass
)
2503 && indaux
+ 1 == symbol
->u
.syment
.n_numaux
)
2505 /* This is a csect entry. */
2506 fprintf (file
, "AUX ");
2507 if (SMTYP_SMTYP (aux
->u
.auxent
.x_csect
.x_smtyp
) != XTY_LD
)
2509 BFD_ASSERT (! aux
->fix_scnlen
);
2510 fprintf (file
, "val %5" PRIu64
,
2511 aux
->u
.auxent
.x_csect
.x_scnlen
.u64
);
2515 fprintf (file
, "indx ");
2516 if (! aux
->fix_scnlen
)
2517 fprintf (file
, "%4" PRIu64
,
2518 aux
->u
.auxent
.x_csect
.x_scnlen
.u64
);
2520 fprintf (file
, "%4ld",
2521 (long) (aux
->u
.auxent
.x_csect
.x_scnlen
.p
- table_base
));
2524 " prmhsh %u snhsh %u typ %d algn %d clss %u stb %u snstb %u",
2525 aux
->u
.auxent
.x_csect
.x_parmhash
,
2526 (unsigned int) aux
->u
.auxent
.x_csect
.x_snhash
,
2527 SMTYP_SMTYP (aux
->u
.auxent
.x_csect
.x_smtyp
),
2528 SMTYP_ALIGN (aux
->u
.auxent
.x_csect
.x_smtyp
),
2529 (unsigned int) aux
->u
.auxent
.x_csect
.x_smclas
,
2530 aux
->u
.auxent
.x_csect
.x_stab
,
2531 (unsigned int) aux
->u
.auxent
.x_csect
.x_snstab
);
2536 /* Return FALSE to indicate that no special action was taken. */
2544 To write relocations, the back end steps though the
2545 canonical relocation table and create an
2546 @code{internal_reloc}. The symbol index to use is removed from
2547 the @code{offset} field in the symbol table supplied. The
2548 address comes directly from the sum of the section base
2549 address and the relocation offset; the type is dug directly
2550 from the howto field. Then the @code{internal_reloc} is
2551 swapped into the shape of an @code{external_reloc} and written
2559 /* AUX's ld wants relocations to be sorted. */
2561 compare_arelent_ptr (const void * x
, const void * y
)
2563 const arelent
**a
= (const arelent
**) x
;
2564 const arelent
**b
= (const arelent
**) y
;
2565 bfd_size_type aadr
= (*a
)->address
;
2566 bfd_size_type badr
= (*b
)->address
;
2568 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
2571 #endif /* TARG_AUX */
2574 coff_write_relocs (bfd
* abfd
, int first_undef
)
2578 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2581 struct external_reloc dst
;
2588 /* Sort relocations before we write them out. */
2591 amt
= s
->reloc_count
;
2592 amt
*= sizeof (arelent
*);
2593 p
= bfd_malloc (amt
);
2596 if (s
->reloc_count
> 0)
2601 memcpy (p
, s
->orelocation
, (size_t) amt
);
2602 qsort (p
, s
->reloc_count
, sizeof (arelent
*), compare_arelent_ptr
);
2607 if (bfd_seek (abfd
, s
->rel_filepos
, SEEK_SET
) != 0)
2610 #ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2611 if ((obj_pe (abfd
) || obj_go32 (abfd
)) && s
->reloc_count
>= 0xffff)
2613 /* Encode real count here as first reloc. */
2614 struct internal_reloc n
;
2616 memset (& n
, 0, sizeof (n
));
2617 /* Add one to count *this* reloc (grr). */
2618 n
.r_vaddr
= s
->reloc_count
+ 1;
2619 coff_swap_reloc_out (abfd
, &n
, &dst
);
2620 if (bfd_bwrite (& dst
, (bfd_size_type
) bfd_coff_relsz (abfd
),
2621 abfd
) != bfd_coff_relsz (abfd
))
2626 for (i
= 0; i
< s
->reloc_count
; i
++)
2628 struct internal_reloc n
;
2631 memset (& n
, 0, sizeof (n
));
2633 /* Now we've renumbered the symbols we know where the
2634 undefined symbols live in the table. Check the reloc
2635 entries for symbols who's output bfd isn't the right one.
2636 This is because the symbol was undefined (which means
2637 that all the pointers are never made to point to the same
2638 place). This is a bad thing,'cause the symbols attached
2639 to the output bfd are indexed, so that the relocation
2640 entries know which symbol index they point to. So we
2641 have to look up the output symbol here. */
2643 if (q
->sym_ptr_ptr
[0] != NULL
&& q
->sym_ptr_ptr
[0]->the_bfd
!= abfd
)
2646 const char *sname
= q
->sym_ptr_ptr
[0]->name
;
2647 asymbol
**outsyms
= abfd
->outsymbols
;
2649 for (j
= first_undef
; outsyms
[j
]; j
++)
2651 const char *intable
= outsyms
[j
]->name
;
2653 if (strcmp (intable
, sname
) == 0)
2655 /* Got a hit, so repoint the reloc. */
2656 q
->sym_ptr_ptr
= outsyms
+ j
;
2662 n
.r_vaddr
= q
->address
+ s
->vma
;
2665 /* The 29k const/consth reloc pair is a real kludge. The consth
2666 part doesn't have a symbol; it has an offset. So rebuilt
2668 if (q
->howto
->type
== R_IHCONST
)
2669 n
.r_symndx
= q
->addend
;
2672 if (q
->sym_ptr_ptr
&& q
->sym_ptr_ptr
[0] != NULL
)
2674 #ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2675 if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q
, s
))
2677 if ((*q
->sym_ptr_ptr
)->section
== bfd_abs_section_ptr
2678 && ((*q
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0)
2680 /* This is a relocation relative to the absolute symbol. */
2684 n
.r_symndx
= get_index ((*(q
->sym_ptr_ptr
)));
2685 /* Check to see if the symbol reloc points to a symbol
2686 we don't have in our symbol table. */
2687 if (n
.r_symndx
> obj_conv_table_size (abfd
))
2689 bfd_set_error (bfd_error_bad_value
);
2690 /* xgettext:c-format */
2691 _bfd_error_handler (_("%pB: reloc against a non-existent"
2692 " symbol index: %ld"),
2699 #ifdef SWAP_OUT_RELOC_OFFSET
2700 n
.r_offset
= q
->addend
;
2704 /* Work out reloc type from what is required. */
2706 SELECT_RELOC (n
, q
->howto
);
2709 n
.r_type
= q
->howto
->type
;
2711 coff_swap_reloc_out (abfd
, &n
, &dst
);
2713 if (bfd_bwrite (& dst
, (bfd_size_type
) bfd_coff_relsz (abfd
),
2714 abfd
) != bfd_coff_relsz (abfd
))
2726 /* Set flags and magic number of a coff file from architecture and machine
2727 type. Result is TRUE if we can represent the arch&type, FALSE if not. */
2730 coff_set_flags (bfd
* abfd
,
2731 unsigned int *magicp ATTRIBUTE_UNUSED
,
2732 unsigned short *flagsp ATTRIBUTE_UNUSED
)
2734 switch (bfd_get_arch (abfd
))
2739 switch (bfd_get_mach (abfd
))
2741 case bfd_mach_z80strict
:
2744 case bfd_mach_z80full
:
2746 case bfd_mach_gbz80
:
2748 case bfd_mach_ez80_z80
:
2749 case bfd_mach_ez80_adl
:
2750 *flagsp
= bfd_get_mach (abfd
) << 12;
2762 switch (bfd_get_mach (abfd
))
2764 case bfd_mach_z8001
: *flagsp
= F_Z8001
; break;
2765 case bfd_mach_z8002
: *flagsp
= F_Z8002
; break;
2766 default: return false;
2772 case bfd_arch_tic30
:
2773 *magicp
= TIC30MAGIC
;
2777 #ifdef TICOFF_DEFAULT_MAGIC
2778 case TICOFF_TARGET_ARCH
:
2779 /* If there's no indication of which version we want, use the default. */
2781 *magicp
= TICOFF_DEFAULT_MAGIC
;
2784 /* We may want to output in a different COFF version. */
2785 switch (abfd
->xvec
->name
[4])
2788 *magicp
= TICOFF0MAGIC
;
2791 *magicp
= TICOFF1MAGIC
;
2794 *magicp
= TICOFF2MAGIC
;
2800 TICOFF_TARGET_MACHINE_SET (flagsp
, bfd_get_mach (abfd
));
2805 case bfd_arch_aarch64
:
2806 * magicp
= AARCH64MAGIC
;
2810 #ifdef LOONGARCH64MAGIC
2811 case bfd_arch_loongarch
:
2812 * magicp
= LOONGARCH64MAGIC
;
2819 * magicp
= ARMPEMAGIC
;
2821 * magicp
= ARMMAGIC
;
2824 if (APCS_SET (abfd
))
2826 if (APCS_26_FLAG (abfd
))
2827 * flagsp
|= F_APCS26
;
2829 if (APCS_FLOAT_FLAG (abfd
))
2830 * flagsp
|= F_APCS_FLOAT
;
2832 if (PIC_FLAG (abfd
))
2835 if (INTERWORK_SET (abfd
) && INTERWORK_FLAG (abfd
))
2836 * flagsp
|= F_INTERWORK
;
2837 switch (bfd_get_mach (abfd
))
2839 case bfd_mach_arm_2
: * flagsp
|= F_ARM_2
; break;
2840 case bfd_mach_arm_2a
: * flagsp
|= F_ARM_2a
; break;
2841 case bfd_mach_arm_3
: * flagsp
|= F_ARM_3
; break;
2842 case bfd_mach_arm_3M
: * flagsp
|= F_ARM_3M
; break;
2843 case bfd_mach_arm_4
: * flagsp
|= F_ARM_4
; break;
2844 case bfd_mach_arm_4T
: * flagsp
|= F_ARM_4T
; break;
2845 case bfd_mach_arm_5
: * flagsp
|= F_ARM_5
; break;
2846 /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2847 See also the comment in coff_set_arch_mach_hook(). */
2848 case bfd_mach_arm_5T
: * flagsp
|= F_ARM_5
; break;
2849 case bfd_mach_arm_5TE
: * flagsp
|= F_ARM_5
; break;
2850 case bfd_mach_arm_XScale
: * flagsp
|= F_ARM_5
; break;
2855 #if defined(I386MAGIC) || defined(AMD64MAGIC)
2857 #if defined(I386MAGIC)
2858 *magicp
= I386MAGIC
;
2861 /* Just overwrite the usual value if we're doing Lynx. */
2862 *magicp
= LYNXCOFFMAGIC
;
2864 #if defined AMD64MAGIC
2865 *magicp
= AMD64MAGIC
;
2872 *magicp
= IA64MAGIC
;
2876 #ifdef SH_ARCH_MAGIC_BIG
2878 #ifdef COFF_IMAGE_WITH_PE
2879 *magicp
= SH_ARCH_MAGIC_WINCE
;
2881 if (bfd_big_endian (abfd
))
2882 *magicp
= SH_ARCH_MAGIC_BIG
;
2884 *magicp
= SH_ARCH_MAGIC_LITTLE
;
2889 #ifdef MIPS_ARCH_MAGIC_WINCE
2891 *magicp
= MIPS_ARCH_MAGIC_WINCE
;
2896 case bfd_arch_sparc
:
2897 *magicp
= SPARCMAGIC
;
2899 /* Just overwrite the usual value if we're doing Lynx. */
2900 *magicp
= LYNXCOFFMAGIC
;
2906 case bfd_arch_rs6000
:
2907 case bfd_arch_powerpc
:
2908 BFD_ASSERT (bfd_get_flavour (abfd
) == bfd_target_xcoff_flavour
);
2909 *magicp
= bfd_xcoff_magic_number (abfd
);
2914 case bfd_arch_mcore
:
2915 * magicp
= MCOREMAGIC
;
2919 default: /* Unknown architecture. */
2927 coff_set_arch_mach (bfd
* abfd
,
2928 enum bfd_architecture arch
,
2929 unsigned long machine
)
2932 unsigned short dummy2
;
2934 if (! bfd_default_set_arch_mach (abfd
, arch
, machine
))
2937 if (arch
!= bfd_arch_unknown
2938 && ! coff_set_flags (abfd
, &dummy1
, &dummy2
))
2939 return false; /* We can't represent this type. */
2941 return true; /* We're easy... */
2944 #ifdef COFF_IMAGE_WITH_PE
2946 /* This is used to sort sections by VMA, as required by PE image
2950 sort_by_secaddr (const void * arg1
, const void * arg2
)
2952 const asection
*a
= *(const asection
**) arg1
;
2953 const asection
*b
= *(const asection
**) arg2
;
2955 if (a
->vma
< b
->vma
)
2957 else if (a
->vma
> b
->vma
)
2963 #endif /* COFF_IMAGE_WITH_PE */
2965 /* Calculate the file position for each section. */
2967 #define ALIGN_SECTIONS_IN_FILE
2969 #undef ALIGN_SECTIONS_IN_FILE
2973 coff_compute_section_file_positions (bfd
* abfd
)
2976 file_ptr sofar
= bfd_coff_filhsz (abfd
);
2978 unsigned int target_index
;
2979 #ifdef ALIGN_SECTIONS_IN_FILE
2980 asection
*previous
= NULL
;
2984 #ifdef COFF_IMAGE_WITH_PE
2985 unsigned int page_size
;
2987 if (coff_data (abfd
)->link_info
2988 || (pe_data (abfd
) && pe_data (abfd
)->pe_opthdr
.FileAlignment
))
2990 page_size
= pe_data (abfd
)->pe_opthdr
.FileAlignment
;
2992 /* If no file alignment has been set, default to one.
2993 This repairs 'ld -r' for arm-wince-pe target. */
2998 page_size
= PE_DEF_FILE_ALIGNMENT
;
3000 #ifdef COFF_PAGE_SIZE
3001 unsigned int page_size
= COFF_PAGE_SIZE
;
3006 /* On XCOFF, if we have symbols, set up the .debug section. */
3007 if (bfd_get_symcount (abfd
) > 0)
3010 bfd_size_type i
, symcount
;
3014 symcount
= bfd_get_symcount (abfd
);
3015 for (symp
= abfd
->outsymbols
, i
= 0; i
< symcount
; symp
++, i
++)
3017 coff_symbol_type
*cf
;
3019 cf
= coff_symbol_from (*symp
);
3021 && cf
->native
!= NULL
3022 && cf
->native
->is_sym
3023 && SYMNAME_IN_DEBUG (&cf
->native
->u
.syment
))
3027 len
= strlen (bfd_asymbol_name (*symp
));
3028 if (len
> SYMNMLEN
|| bfd_coff_force_symnames_in_strings (abfd
))
3029 sz
+= len
+ 1 + bfd_coff_debug_string_prefix_length (abfd
);
3036 dsec
= bfd_make_section_old_way (abfd
, DOT_DEBUG
);
3040 dsec
->flags
|= SEC_HAS_CONTENTS
;
3045 if (bfd_get_start_address (abfd
))
3046 /* A start address may have been added to the original file. In this
3047 case it will need an optional header to record it. */
3048 abfd
->flags
|= EXEC_P
;
3050 if (abfd
->flags
& EXEC_P
)
3051 sofar
+= bfd_coff_aoutsz (abfd
);
3053 else if (xcoff_data (abfd
)->full_aouthdr
)
3054 sofar
+= bfd_coff_aoutsz (abfd
);
3056 sofar
+= SMALL_AOUTSZ
;
3059 sofar
+= abfd
->section_count
* bfd_coff_scnhsz (abfd
);
3062 /* XCOFF handles overflows in the reloc and line number count fields
3063 by allocating a new section header to hold the correct counts. */
3064 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
)
3065 if (current
->reloc_count
>= 0xffff || current
->lineno_count
>= 0xffff)
3066 sofar
+= bfd_coff_scnhsz (abfd
);
3069 #ifdef COFF_IMAGE_WITH_PE
3071 /* PE requires the sections to be in memory order when listed in
3072 the section headers. It also does not like empty loadable
3073 sections. The sections apparently do not have to be in the
3074 right order in the image file itself, but we do need to get the
3075 target_index values right. */
3078 asection
**section_list
;
3082 #ifdef COFF_PAGE_SIZE
3083 /* Clear D_PAGED if section / file alignment aren't suitable for
3084 paging at COFF_PAGE_SIZE granularity. */
3085 if (pe_data (abfd
)->pe_opthdr
.SectionAlignment
< COFF_PAGE_SIZE
3086 || page_size
< COFF_PAGE_SIZE
)
3087 abfd
->flags
&= ~D_PAGED
;
3091 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
)
3094 /* We allocate an extra cell to simplify the final loop. */
3095 amt
= sizeof (struct asection
*) * (count
+ 1);
3096 section_list
= (asection
**) bfd_malloc (amt
);
3097 if (section_list
== NULL
)
3101 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
)
3103 section_list
[i
] = current
;
3106 section_list
[i
] = NULL
;
3108 qsort (section_list
, count
, sizeof (asection
*), sort_by_secaddr
);
3110 /* Rethread the linked list into sorted order; at the same time,
3111 assign target_index values. */
3113 abfd
->sections
= NULL
;
3114 abfd
->section_last
= NULL
;
3115 for (i
= 0; i
< count
; i
++)
3117 current
= section_list
[i
];
3118 bfd_section_list_append (abfd
, current
);
3120 /* Later, if the section has zero size, we'll be throwing it
3121 away, so we don't want to number it now. Note that having
3122 a zero size and having real contents are different
3123 concepts: .bss has no contents, but (usually) non-zero
3125 if (current
->size
== 0)
3127 /* Discard. However, it still might have (valid) symbols
3128 in it, so arbitrarily set it to section 1 (indexing is
3129 1-based here; usually .text). __end__ and other
3130 contents of .endsection really have this happen.
3131 FIXME: This seems somewhat dubious. */
3132 current
->target_index
= 1;
3135 current
->target_index
= target_index
++;
3138 free (section_list
);
3140 #else /* ! COFF_IMAGE_WITH_PE */
3142 /* Set the target_index field. */
3144 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
)
3145 current
->target_index
= target_index
++;
3147 #endif /* ! COFF_IMAGE_WITH_PE */
3149 if (target_index
>= bfd_coff_max_nscns (abfd
))
3151 bfd_set_error (bfd_error_file_too_big
);
3153 /* xgettext:c-format */
3154 (_("%pB: too many sections (%d)"), abfd
, target_index
);
3158 align_adjust
= false;
3159 for (current
= abfd
->sections
;
3161 current
= current
->next
)
3163 #ifdef COFF_IMAGE_WITH_PE
3164 /* With PE we have to pad each section to be a multiple of its
3165 page size too, and remember both sizes. */
3166 if (coff_section_data (abfd
, current
) == NULL
)
3168 size_t amt
= sizeof (struct coff_section_tdata
);
3170 current
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
3171 if (current
->used_by_bfd
== NULL
)
3174 if (pei_section_data (abfd
, current
) == NULL
)
3176 size_t amt
= sizeof (struct pei_section_tdata
);
3178 coff_section_data (abfd
, current
)->tdata
= bfd_zalloc (abfd
, amt
);
3179 if (coff_section_data (abfd
, current
)->tdata
== NULL
)
3182 if (pei_section_data (abfd
, current
)->virt_size
== 0)
3183 pei_section_data (abfd
, current
)->virt_size
= current
->size
;
3186 /* Only deal with sections which have contents. */
3187 if (!(current
->flags
& SEC_HAS_CONTENTS
))
3190 current
->rawsize
= current
->size
;
3192 #ifdef COFF_IMAGE_WITH_PE
3193 /* Make sure we skip empty sections in a PE image. */
3194 if (current
->size
== 0)
3198 /* Align the sections in the file to the same boundary on
3199 which they are aligned in virtual memory. */
3200 #ifdef ALIGN_SECTIONS_IN_FILE
3201 if ((abfd
->flags
& EXEC_P
) != 0)
3203 /* Make sure this section is aligned on the right boundary - by
3204 padding the previous section up if necessary. */
3207 #ifdef COFF_IMAGE_WITH_PE
3208 sofar
= BFD_ALIGN (sofar
, page_size
);
3210 sofar
= BFD_ALIGN (sofar
, (bfd_vma
) 1 << current
->alignment_power
);
3214 /* Make sure the file offset and the vma of .text/.data are at the
3215 same page offset, so that the file can be mmap'ed without being
3216 relocated. Failing that, AIX is able to load and execute the
3217 program, but it will be silently relocated (possible as
3218 executables are PIE). But the relocation is slightly costly and
3219 complexify the use of addr2line or gdb. So better to avoid it,
3220 like does the native linker. Usually gnu ld makes sure that
3221 the vma of .text is the file offset so this issue shouldn't
3222 appear unless you are stripping such an executable.
3224 AIX loader checks the text section alignment of (vma - filepos),
3225 and the native linker doesn't try to align the text sections.
3228 0 .text 000054cc 10000128 10000128 00000128 2**5
3229 CONTENTS, ALLOC, LOAD, CODE
3231 Don't perform the above tweak if the previous one is .tdata,
3232 as it will increase the memory allocated for every threads
3233 created and not just improve performances with gdb.
3236 if ((!strcmp (current
->name
, _TEXT
)
3237 || !strcmp (current
->name
, _DATA
))
3238 && (previous
== NULL
|| strcmp(previous
->name
, _TDATA
)))
3240 bfd_vma align
= 4096;
3241 bfd_vma sofar_off
= sofar
% align
;
3242 bfd_vma vma_off
= current
->vma
% align
;
3244 if (vma_off
> sofar_off
)
3245 sofar
+= vma_off
- sofar_off
;
3246 else if (vma_off
< sofar_off
)
3247 sofar
+= align
+ vma_off
- sofar_off
;
3250 if (previous
!= NULL
)
3251 previous
->size
+= sofar
- old_sofar
;
3256 /* In demand paged files the low order bits of the file offset
3257 must match the low order bits of the virtual address. */
3258 #ifdef COFF_PAGE_SIZE
3259 if ((abfd
->flags
& D_PAGED
) != 0
3260 && (current
->flags
& SEC_ALLOC
) != 0)
3261 sofar
+= (current
->vma
- (bfd_vma
) sofar
) % page_size
;
3263 current
->filepos
= sofar
;
3265 #ifdef COFF_IMAGE_WITH_PE
3266 /* Set the padded size. */
3267 current
->size
= (current
->size
+ page_size
- 1) & -page_size
;
3270 sofar
+= current
->size
;
3272 #ifdef ALIGN_SECTIONS_IN_FILE
3273 /* Make sure that this section is of the right size too. */
3274 if ((abfd
->flags
& EXEC_P
) == 0)
3276 bfd_size_type old_size
;
3278 old_size
= current
->size
;
3279 current
->size
= BFD_ALIGN (current
->size
,
3280 (bfd_vma
) 1 << current
->alignment_power
);
3281 align_adjust
= current
->size
!= old_size
;
3282 sofar
+= current
->size
- old_size
;
3287 #ifdef COFF_IMAGE_WITH_PE
3288 sofar
= BFD_ALIGN (sofar
, page_size
);
3290 sofar
= BFD_ALIGN (sofar
, (bfd_vma
) 1 << current
->alignment_power
);
3292 align_adjust
= sofar
!= old_sofar
;
3293 current
->size
+= sofar
- old_sofar
;
3297 #ifdef COFF_IMAGE_WITH_PE
3298 /* For PE we need to make sure we pad out to the aligned
3299 size, in case the caller only writes out data to the
3301 if (pei_section_data (abfd
, current
)->virt_size
< current
->size
)
3302 align_adjust
= true;
3306 /* Force .lib sections to start at zero. The vma is then
3307 incremented in coff_set_section_contents. This is right for
3309 if (strcmp (current
->name
, _LIB
) == 0)
3310 bfd_set_section_vma (current
, 0);
3313 #ifdef ALIGN_SECTIONS_IN_FILE
3318 /* It is now safe to write to the output file. If we needed an
3319 alignment adjustment for the last section, then make sure that
3320 there is a byte at offset sofar. If there are no symbols and no
3321 relocs, then nothing follows the last section. If we don't force
3322 the last byte out, then the file may appear to be truncated. */
3328 if (bfd_seek (abfd
, sofar
- 1, SEEK_SET
) != 0
3329 || bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
3333 /* Make sure the relocations are aligned. We don't need to make
3334 sure that this byte exists, because it will only matter if there
3335 really are relocs. */
3336 sofar
= BFD_ALIGN (sofar
,
3337 (bfd_vma
) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER
);
3339 obj_relocbase (abfd
) = sofar
;
3340 abfd
->output_has_begun
= true;
3345 #ifdef COFF_IMAGE_WITH_PE
3348 coff_read_word (bfd
*abfd
, unsigned int *value
, unsigned int *pelength
)
3353 status
= bfd_bread (b
, (bfd_size_type
) 2, abfd
);
3361 *value
= (unsigned int) b
[0];
3363 *value
= (unsigned int) (b
[0] + (b
[1] << 8));
3365 *pelength
+= status
;
3371 coff_compute_checksum (bfd
*abfd
, unsigned int *pelength
)
3380 filepos
= (file_ptr
) 0;
3384 if (bfd_seek (abfd
, filepos
, SEEK_SET
) != 0)
3387 more_data
= coff_read_word (abfd
, &value
, pelength
);
3389 total
= 0xffff & (total
+ (total
>> 0x10));
3394 return (0xffff & (total
+ (total
>> 0x10)));
3398 coff_apply_checksum (bfd
*abfd
)
3400 unsigned int computed
;
3401 unsigned int checksum
= 0;
3402 unsigned int peheader
;
3403 unsigned int pelength
;
3405 if (bfd_seek (abfd
, 0x3c, SEEK_SET
) != 0)
3408 if (!coff_read_word (abfd
, &peheader
, &pelength
))
3411 if (bfd_seek (abfd
, peheader
+ 0x58, SEEK_SET
) != 0)
3415 bfd_bwrite (&checksum
, (bfd_size_type
) 4, abfd
);
3417 if (bfd_seek (abfd
, peheader
, SEEK_SET
) != 0)
3420 computed
= coff_compute_checksum (abfd
, &pelength
);
3422 checksum
= computed
+ pelength
;
3424 if (bfd_seek (abfd
, peheader
+ 0x58, SEEK_SET
) != 0)
3427 bfd_bwrite (&checksum
, (bfd_size_type
) 4, abfd
);
3432 #endif /* COFF_IMAGE_WITH_PE */
3435 coff_write_object_contents (bfd
* abfd
)
3438 bool hasrelocs
= false;
3439 bool haslinno
= false;
3440 #ifdef COFF_IMAGE_WITH_PE
3441 bool hasdebug
= false;
3444 file_ptr reloc_base
;
3445 file_ptr lineno_base
;
3447 unsigned long reloc_size
= 0, reloc_count
= 0;
3448 unsigned long lnno_size
= 0;
3449 bool long_section_names
;
3450 asection
*text_sec
= NULL
;
3451 asection
*data_sec
= NULL
;
3452 asection
*bss_sec
= NULL
;
3454 asection
*tdata_sec
= NULL
;
3455 asection
*tbss_sec
= NULL
;
3457 struct internal_filehdr internal_f
;
3458 struct internal_aouthdr internal_a
;
3459 #ifdef COFF_LONG_SECTION_NAMES
3460 size_t string_size
= STRING_SIZE_SIZE
;
3463 bfd_set_error (bfd_error_system_call
);
3465 /* Make a pass through the symbol table to count line number entries and
3466 put them into the correct asections. */
3467 lnno_size
= coff_count_linenumbers (abfd
) * bfd_coff_linesz (abfd
);
3469 if (! abfd
->output_has_begun
)
3471 if (! coff_compute_section_file_positions (abfd
))
3475 reloc_base
= obj_relocbase (abfd
);
3477 /* Work out the size of the reloc and linno areas. */
3479 for (current
= abfd
->sections
; current
!= NULL
; current
=
3482 #ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3483 /* We store the actual reloc count in the first reloc's addr. */
3484 if ((obj_pe (abfd
) || obj_go32 (abfd
)) && current
->reloc_count
>= 0xffff)
3487 reloc_count
+= current
->reloc_count
;
3490 reloc_size
= reloc_count
* bfd_coff_relsz (abfd
);
3492 lineno_base
= reloc_base
+ reloc_size
;
3493 sym_base
= lineno_base
+ lnno_size
;
3495 /* Indicate in each section->line_filepos its actual file address. */
3496 for (current
= abfd
->sections
; current
!= NULL
; current
=
3499 if (current
->lineno_count
)
3501 current
->line_filepos
= lineno_base
;
3502 current
->moving_line_filepos
= lineno_base
;
3503 lineno_base
+= current
->lineno_count
* bfd_coff_linesz (abfd
);
3506 current
->line_filepos
= 0;
3508 if (current
->reloc_count
)
3510 current
->rel_filepos
= reloc_base
;
3511 reloc_base
+= current
->reloc_count
* bfd_coff_relsz (abfd
);
3512 #ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3513 /* Extra reloc to hold real count. */
3514 if ((obj_pe (abfd
) || obj_go32 (abfd
)) && current
->reloc_count
>= 0xffff)
3515 reloc_base
+= bfd_coff_relsz (abfd
);
3519 current
->rel_filepos
= 0;
3522 /* Write section headers to the file. */
3523 internal_f
.f_nscns
= 0;
3525 if ((abfd
->flags
& EXEC_P
) != 0)
3526 scn_base
= bfd_coff_filhsz (abfd
) + bfd_coff_aoutsz (abfd
);
3529 scn_base
= bfd_coff_filhsz (abfd
);
3532 if (xcoff_data (abfd
)->full_aouthdr
)
3533 scn_base
+= bfd_coff_aoutsz (abfd
);
3535 scn_base
+= SMALL_AOUTSZ
;
3540 if (bfd_seek (abfd
, scn_base
, SEEK_SET
) != 0)
3543 long_section_names
= false;
3544 for (current
= abfd
->sections
;
3546 current
= current
->next
)
3548 struct internal_scnhdr section
;
3549 #ifdef COFF_IMAGE_WITH_PE
3550 bool is_reloc_section
= false;
3552 if (strcmp (current
->name
, DOT_RELOC
) == 0)
3554 is_reloc_section
= true;
3556 pe_data (abfd
)->has_reloc_section
= 1;
3560 internal_f
.f_nscns
++;
3562 strncpy (section
.s_name
, current
->name
, SCNNMLEN
);
3564 #ifdef COFF_LONG_SECTION_NAMES
3565 /* Handle long section names as in PE. This must be compatible
3566 with the code in coff_write_symbols and _bfd_coff_final_link. */
3567 if (bfd_coff_long_section_names (abfd
))
3571 len
= strlen (current
->name
);
3574 /* The s_name field is defined to be NUL-padded but need not be
3575 NUL-terminated. We use a temporary buffer so that we can still
3576 sprintf all eight chars without splatting a terminating NUL
3577 over the first byte of the following member (s_paddr). */
3578 /* PR 21096: The +20 is to stop a bogus warning from gcc7 about
3579 a possible buffer overflow. */
3580 char s_name_buf
[SCNNMLEN
+ 1 + 20];
3582 /* An inherent limitation of the /nnnnnnn notation used to indicate
3583 the offset of the long name in the string table is that we
3584 cannot address entries beyone the ten million byte boundary. */
3585 if (string_size
>= 10000000)
3587 bfd_set_error (bfd_error_file_too_big
);
3589 /* xgettext:c-format */
3590 (_("%pB: section %pA: string table overflow at offset %ld"),
3591 abfd
, current
, (unsigned long) string_size
);
3595 /* We do not need to use snprintf here as we have already verfied
3596 that string_size is not too big, plus we have an overlarge
3597 buffer, just in case. */
3598 sprintf (s_name_buf
, "/%lu", (unsigned long) string_size
);
3599 /* Then strncpy takes care of any padding for us. */
3600 strncpy (section
.s_name
, s_name_buf
, SCNNMLEN
);
3601 string_size
+= len
+ 1;
3602 long_section_names
= true;
3608 /* Always set s_vaddr of .lib to 0. This is right for SVR3.2
3609 Ian Taylor <ian@cygnus.com>. */
3610 if (strcmp (current
->name
, _LIB
) == 0)
3611 section
.s_vaddr
= 0;
3614 section
.s_vaddr
= current
->vma
;
3615 section
.s_paddr
= current
->lma
;
3616 section
.s_size
= current
->size
;
3617 #ifdef coff_get_section_load_page
3618 section
.s_page
= coff_get_section_load_page (current
);
3624 section
.s_paddr
= 0;
3626 #ifdef COFF_IMAGE_WITH_PE
3627 /* Reminder: s_paddr holds the virtual size of the section. */
3628 if (coff_section_data (abfd
, current
) != NULL
3629 && pei_section_data (abfd
, current
) != NULL
)
3630 section
.s_paddr
= pei_section_data (abfd
, current
)->virt_size
;
3632 section
.s_paddr
= 0;
3635 /* If this section has no size or is unloadable then the scnptr
3637 if (current
->size
== 0
3638 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3639 section
.s_scnptr
= 0;
3641 section
.s_scnptr
= current
->filepos
;
3643 section
.s_relptr
= current
->rel_filepos
;
3644 section
.s_lnnoptr
= current
->line_filepos
;
3645 section
.s_nreloc
= current
->reloc_count
;
3646 section
.s_nlnno
= current
->lineno_count
;
3647 #ifndef COFF_IMAGE_WITH_PE
3648 /* In PEI, relocs come in the .reloc section. */
3649 if (current
->reloc_count
!= 0)
3652 if (current
->lineno_count
!= 0)
3654 #ifdef COFF_IMAGE_WITH_PE
3655 if ((current
->flags
& SEC_DEBUGGING
) != 0
3656 && ! is_reloc_section
)
3662 /* Indicate the use of an XCOFF overflow section header. */
3663 if (current
->reloc_count
>= 0xffff || current
->lineno_count
>= 0xffff)
3665 section
.s_nreloc
= 0xffff;
3666 section
.s_nlnno
= 0xffff;
3671 section
.s_flags
= sec_to_styp_flags (current
->name
, current
->flags
);
3673 if (!strcmp (current
->name
, _TEXT
))
3675 else if (!strcmp (current
->name
, _DATA
))
3677 else if (!strcmp (current
->name
, _BSS
))
3680 else if (!strcmp (current
->name
, _TDATA
))
3681 tdata_sec
= current
;
3682 else if (!strcmp (current
->name
, _TBSS
))
3687 #ifdef COFF_ENCODE_ALIGNMENT
3688 if (COFF_ENCODE_ALIGNMENT (abfd
, section
, current
->alignment_power
)
3689 && (COFF_DECODE_ALIGNMENT (section
.s_flags
)
3690 != current
->alignment_power
))
3692 bool warn
= (coff_data (abfd
)->link_info
3693 && !bfd_link_relocatable (coff_data (abfd
)->link_info
));
3696 /* xgettext:c-format */
3697 (_("%pB:%s section %s: alignment 2**%u not representable"),
3698 abfd
, warn
? " warning:" : "", current
->name
,
3699 current
->alignment_power
);
3702 bfd_set_error (bfd_error_nonrepresentable_section
);
3708 #ifdef COFF_IMAGE_WITH_PE
3709 /* Suppress output of the sections if they are null. ld
3710 includes the bss and data sections even if there is no size
3711 assigned to them. NT loader doesn't like it if these section
3712 headers are included if the sections themselves are not
3713 needed. See also coff_compute_section_file_positions. */
3714 if (section
.s_size
== 0)
3715 internal_f
.f_nscns
--;
3720 bfd_size_type amt
= bfd_coff_scnhsz (abfd
);
3722 if (bfd_coff_swap_scnhdr_out (abfd
, §ion
, &buff
) == 0
3723 || bfd_bwrite (& buff
, amt
, abfd
) != amt
)
3728 /* PE stores COMDAT section information in the symbol table. If
3729 this section is supposed to have some COMDAT info, track down
3730 the symbol in the symbol table and modify it. */
3731 if ((current
->flags
& SEC_LINK_ONCE
) != 0)
3733 unsigned int i
, count
;
3735 coff_symbol_type
*csym
= NULL
;
3739 count
= bfd_get_symcount (abfd
);
3740 for (i
= 0, psym
= abfd
->outsymbols
; i
< count
; i
++, psym
++)
3742 if ((*psym
)->section
!= current
)
3745 /* Remember the location of the first symbol in this
3747 if (psymsec
== NULL
)
3750 /* See if this is the section symbol. */
3751 if (strcmp ((*psym
)->name
, current
->name
) == 0)
3753 csym
= coff_symbol_from (*psym
);
3755 || csym
->native
== NULL
3756 || ! csym
->native
->is_sym
3757 || csym
->native
->u
.syment
.n_numaux
< 1
3758 || csym
->native
->u
.syment
.n_sclass
!= C_STAT
3759 || csym
->native
->u
.syment
.n_type
!= T_NULL
)
3762 /* Here *PSYM is the section symbol for CURRENT. */
3769 Note that we might not if we're converting the file from
3770 some other object file format. */
3773 combined_entry_type
*aux
;
3775 /* We don't touch the x_checksum field. The
3776 x_associated field is not currently supported. */
3778 aux
= csym
->native
+ 1;
3779 BFD_ASSERT (! aux
->is_sym
);
3780 switch (current
->flags
& SEC_LINK_DUPLICATES
)
3782 case SEC_LINK_DUPLICATES_DISCARD
:
3783 aux
->u
.auxent
.x_scn
.x_comdat
= IMAGE_COMDAT_SELECT_ANY
;
3786 case SEC_LINK_DUPLICATES_ONE_ONLY
:
3787 aux
->u
.auxent
.x_scn
.x_comdat
=
3788 IMAGE_COMDAT_SELECT_NODUPLICATES
;
3791 case SEC_LINK_DUPLICATES_SAME_SIZE
:
3792 aux
->u
.auxent
.x_scn
.x_comdat
=
3793 IMAGE_COMDAT_SELECT_SAME_SIZE
;
3796 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
3797 aux
->u
.auxent
.x_scn
.x_comdat
=
3798 IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3802 /* The COMDAT symbol must be the first symbol from this
3803 section in the symbol table. In order to make this
3804 work, we move the COMDAT symbol before the first
3805 symbol we found in the search above. It's OK to
3806 rearrange the symbol table at this point, because
3807 coff_renumber_symbols is going to rearrange it
3808 further and fix up all the aux entries. */
3809 if (psym
!= psymsec
)
3815 for (pcopy
= psym
; pcopy
> psymsec
; pcopy
--)
3816 pcopy
[0] = pcopy
[-1];
3821 #endif /* COFF_WITH_PE */
3826 /* XCOFF handles overflows in the reloc and line number count fields
3827 by creating a new section header to hold the correct values. */
3828 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
)
3830 if (current
->reloc_count
>= 0xffff || current
->lineno_count
>= 0xffff)
3832 struct internal_scnhdr scnhdr
;
3836 internal_f
.f_nscns
++;
3837 memcpy (scnhdr
.s_name
, ".ovrflo", 8);
3838 scnhdr
.s_paddr
= current
->reloc_count
;
3839 scnhdr
.s_vaddr
= current
->lineno_count
;
3841 scnhdr
.s_scnptr
= 0;
3842 scnhdr
.s_relptr
= current
->rel_filepos
;
3843 scnhdr
.s_lnnoptr
= current
->line_filepos
;
3844 scnhdr
.s_nreloc
= current
->target_index
;
3845 scnhdr
.s_nlnno
= current
->target_index
;
3846 scnhdr
.s_flags
= STYP_OVRFLO
;
3847 amt
= bfd_coff_scnhsz (abfd
);
3848 if (bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, &buff
) == 0
3849 || bfd_bwrite (& buff
, amt
, abfd
) != amt
)
3856 #if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3857 /* Pad section headers. */
3858 if ((abfd
->flags
& EXEC_P
) && abfd
->sections
!= NULL
)
3860 file_ptr cur_ptr
= scn_base
3861 + abfd
->section_count
* bfd_coff_scnhsz (abfd
);
3862 long fill_size
= (abfd
->sections
->filepos
- cur_ptr
);
3863 bfd_byte
*b
= bfd_zmalloc (fill_size
);
3866 bfd_bwrite (b
, fill_size
, abfd
);
3872 /* OK, now set up the filehdr... */
3874 /* Don't include the internal abs section in the section count */
3876 /* We will NOT put a fucking timestamp in the header here. Every time you
3877 put it back, I will come in and take it out again. I'm sorry. This
3878 field does not belong here. We fill it with a 0 so it compares the
3879 same but is not a reasonable time. -- gnu@cygnus.com */
3880 internal_f
.f_timdat
= 0;
3881 internal_f
.f_flags
= 0;
3883 if (abfd
->flags
& EXEC_P
)
3884 internal_f
.f_opthdr
= bfd_coff_aoutsz (abfd
);
3887 internal_f
.f_opthdr
= 0;
3890 if (xcoff_data (abfd
)->full_aouthdr
)
3891 internal_f
.f_opthdr
= bfd_coff_aoutsz (abfd
);
3893 internal_f
.f_opthdr
= SMALL_AOUTSZ
;
3899 internal_f
.f_flags
|= F_RELFLG
;
3901 internal_f
.f_flags
|= F_LNNO
;
3902 if (abfd
->flags
& EXEC_P
)
3903 internal_f
.f_flags
|= F_EXEC
;
3904 #ifdef COFF_IMAGE_WITH_PE
3906 internal_f
.f_flags
|= IMAGE_FILE_DEBUG_STRIPPED
;
3907 if (pe_data (abfd
)->real_flags
& IMAGE_FILE_LARGE_ADDRESS_AWARE
)
3908 internal_f
.f_flags
|= IMAGE_FILE_LARGE_ADDRESS_AWARE
;
3911 #if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
3913 internal_f
.f_flags
|= IMAGE_FILE_32BIT_MACHINE
;
3915 if (bfd_little_endian (abfd
))
3916 internal_f
.f_flags
|= F_AR32WR
;
3918 internal_f
.f_flags
|= F_AR32W
;
3923 /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
3924 but it doesn't hurt to set it internally. */
3925 internal_f
.f_target_id
= TI_TARGET_ID
;
3928 /* FIXME, should do something about the other byte orders and
3932 if ((abfd
->flags
& DYNAMIC
) != 0)
3933 internal_f
.f_flags
|= F_SHROBJ
;
3934 if (bfd_get_section_by_name (abfd
, _LOADER
) != NULL
)
3935 internal_f
.f_flags
|= F_DYNLOAD
;
3938 memset (&internal_a
, 0, sizeof internal_a
);
3940 /* Set up architecture-dependent stuff. */
3942 unsigned int magic
= 0;
3943 unsigned short flags
= 0;
3945 coff_set_flags (abfd
, &magic
, &flags
);
3946 internal_f
.f_magic
= magic
;
3947 internal_f
.f_flags
|= flags
;
3948 /* ...and the "opt"hdr... */
3950 #ifdef TICOFF_AOUT_MAGIC
3951 internal_a
.magic
= TICOFF_AOUT_MAGIC
;
3952 #define __A_MAGIC_SET__
3956 #define __A_MAGIC_SET__
3957 internal_a
.magic
= ZMAGIC
;
3960 #if defined(AARCH64)
3961 #define __A_MAGIC_SET__
3962 internal_a
.magic
= ZMAGIC
;
3965 #if defined(LOONGARCH64)
3966 #define __A_MAGIC_SET__
3967 internal_a
.magic
= ZMAGIC
;
3970 #if defined MCORE_PE
3971 #define __A_MAGIC_SET__
3972 internal_a
.magic
= IMAGE_NT_OPTIONAL_HDR_MAGIC
;
3976 #define __A_MAGIC_SET__
3978 internal_a
.magic
= LYNXCOFFMAGIC
;
3980 internal_a
.magic
= IMAGE_NT_OPTIONAL_HDR64_MAGIC
;
3982 internal_a
.magic
= ZMAGIC
;
3987 #define __A_MAGIC_SET__
3988 internal_a
.magic
= PE32PMAGIC
;
3992 #define __A_MAGIC_SET__
3994 internal_a
.magic
= LYNXCOFFMAGIC
;
3999 #define __A_MAGIC_SET__
4000 internal_a
.magic
= (abfd
->flags
& D_PAGED
) ? RS6K_AOUTHDR_ZMAGIC
:
4001 (abfd
->flags
& WP_TEXT
) ? RS6K_AOUTHDR_NMAGIC
:
4002 RS6K_AOUTHDR_OMAGIC
;
4005 #if defined(SH) && defined(COFF_WITH_PE)
4006 #define __A_MAGIC_SET__
4007 internal_a
.magic
= SH_PE_MAGIC
;
4010 #if defined(MIPS) && defined(COFF_WITH_PE)
4011 #define __A_MAGIC_SET__
4012 internal_a
.magic
= MIPS_PE_MAGIC
;
4015 #ifndef __A_MAGIC_SET__
4016 #include "Your aouthdr magic number is not being set!"
4018 #undef __A_MAGIC_SET__
4023 /* XCOFF 32bit needs this to have new behaviour for n_type field. */
4024 internal_a
.vstamp
= 2;
4026 /* FIXME: Does anybody ever set this to another value? */
4027 internal_a
.vstamp
= 0;
4030 /* Now should write relocs, strings, syms. */
4031 obj_sym_filepos (abfd
) = sym_base
;
4033 if (bfd_get_symcount (abfd
) != 0)
4037 if (!coff_renumber_symbols (abfd
, &firstundef
))
4039 coff_mangle_symbols (abfd
);
4040 if (! coff_write_symbols (abfd
))
4042 if (! coff_write_linenumbers (abfd
))
4044 if (! coff_write_relocs (abfd
, firstundef
))
4047 #ifdef COFF_LONG_SECTION_NAMES
4048 else if (long_section_names
&& ! obj_coff_strings_written (abfd
))
4050 /* If we have long section names we have to write out the string
4051 table even if there are no symbols. */
4052 if (! coff_write_symbols (abfd
))
4056 /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4057 backend linker, and obj_raw_syment_count is not valid until after
4058 coff_write_symbols is called. */
4059 if (obj_raw_syment_count (abfd
) != 0)
4061 internal_f
.f_symptr
= sym_base
;
4063 /* AIX appears to require that F_RELFLG not be set if there are
4064 local symbols but no relocations. */
4065 internal_f
.f_flags
&=~ F_RELFLG
;
4070 if (long_section_names
)
4071 internal_f
.f_symptr
= sym_base
;
4073 internal_f
.f_symptr
= 0;
4074 internal_f
.f_flags
|= F_LSYMS
;
4079 internal_a
.tsize
= text_sec
->size
;
4080 internal_a
.text_start
= internal_a
.tsize
? text_sec
->vma
: 0;
4084 internal_a
.dsize
= data_sec
->size
;
4085 internal_a
.data_start
= internal_a
.dsize
? data_sec
->vma
: 0;
4089 internal_a
.bsize
= bss_sec
->size
;
4090 if (internal_a
.bsize
&& bss_sec
->vma
< internal_a
.data_start
)
4091 internal_a
.data_start
= bss_sec
->vma
;
4094 internal_a
.entry
= bfd_get_start_address (abfd
);
4095 internal_f
.f_nsyms
= obj_raw_syment_count (abfd
);
4098 if (xcoff_data (abfd
)->full_aouthdr
)
4101 asection
*loader_sec
;
4103 internal_a
.vstamp
= 2;
4105 internal_a
.o_snentry
= xcoff_data (abfd
)->snentry
;
4106 if (internal_a
.o_snentry
== 0)
4107 internal_a
.entry
= (bfd_vma
) -1;
4109 if (text_sec
!= NULL
)
4111 internal_a
.o_sntext
= text_sec
->target_index
;
4112 internal_a
.o_algntext
= bfd_section_alignment (text_sec
);
4116 internal_a
.o_sntext
= 0;
4117 internal_a
.o_algntext
= 0;
4119 if (data_sec
!= NULL
)
4121 internal_a
.o_sndata
= data_sec
->target_index
;
4122 internal_a
.o_algndata
= bfd_section_alignment (data_sec
);
4126 internal_a
.o_sndata
= 0;
4127 internal_a
.o_algndata
= 0;
4129 loader_sec
= bfd_get_section_by_name (abfd
, ".loader");
4130 if (loader_sec
!= NULL
)
4131 internal_a
.o_snloader
= loader_sec
->target_index
;
4133 internal_a
.o_snloader
= 0;
4134 if (bss_sec
!= NULL
)
4135 internal_a
.o_snbss
= bss_sec
->target_index
;
4137 internal_a
.o_snbss
= 0;
4139 if (tdata_sec
!= NULL
)
4141 internal_a
.o_sntdata
= tdata_sec
->target_index
;
4142 /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4143 if there is at least one R_TLS_LE relocations. */
4144 internal_a
.o_flags
= 0;
4146 internal_a
.o_x64flags
= 0;
4151 internal_a
.o_sntdata
= 0;
4152 internal_a
.o_flags
= 0;
4154 internal_a
.o_x64flags
= 0;
4157 if (tbss_sec
!= NULL
)
4158 internal_a
.o_sntbss
= tbss_sec
->target_index
;
4160 internal_a
.o_sntbss
= 0;
4162 toc
= xcoff_data (abfd
)->toc
;
4163 internal_a
.o_toc
= toc
;
4164 internal_a
.o_sntoc
= xcoff_data (abfd
)->sntoc
;
4166 internal_a
.o_modtype
= xcoff_data (abfd
)->modtype
;
4167 if (xcoff_data (abfd
)->cputype
!= -1)
4168 internal_a
.o_cputype
= xcoff_data (abfd
)->cputype
;
4171 switch (bfd_get_arch (abfd
))
4173 case bfd_arch_rs6000
:
4174 internal_a
.o_cputype
= 4;
4176 case bfd_arch_powerpc
:
4177 if (bfd_get_mach (abfd
) == bfd_mach_ppc
)
4178 internal_a
.o_cputype
= 3;
4179 else if (bfd_get_mach (abfd
) == bfd_mach_ppc_620
)
4180 internal_a
.o_cputype
= 2;
4182 internal_a
.o_cputype
= 1;
4188 internal_a
.o_maxstack
= xcoff_data (abfd
)->maxstack
;
4189 internal_a
.o_maxdata
= xcoff_data (abfd
)->maxdata
;
4195 /* After object contents are finalized so we can compute a reasonable hash,
4196 but before header is written so we can update it to point to debug directory. */
4197 struct pe_tdata
*pe
= pe_data (abfd
);
4199 if (pe
->build_id
.after_write_object_contents
!= NULL
)
4200 (*pe
->build_id
.after_write_object_contents
) (abfd
);
4204 /* Now write header. */
4205 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
4210 bfd_size_type amount
= bfd_coff_filhsz (abfd
);
4212 buff
= (char *) bfd_malloc (amount
);
4216 bfd_coff_swap_filehdr_out (abfd
, & internal_f
, buff
);
4217 amount
= bfd_bwrite (buff
, amount
, abfd
);
4221 if (amount
!= bfd_coff_filhsz (abfd
))
4225 if (abfd
->flags
& EXEC_P
)
4227 /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4228 include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)). */
4230 bfd_size_type amount
= bfd_coff_aoutsz (abfd
);
4232 buff
= (char *) bfd_malloc (amount
);
4236 coff_swap_aouthdr_out (abfd
, & internal_a
, buff
);
4237 amount
= bfd_bwrite (buff
, amount
, abfd
);
4241 if (amount
!= bfd_coff_aoutsz (abfd
))
4244 #ifdef COFF_IMAGE_WITH_PE
4245 if (! coff_apply_checksum (abfd
))
4256 /* XCOFF32 seems to always write at least a small a.out header. */
4257 coff_swap_aouthdr_out (abfd
, & internal_a
, & buff
);
4258 if (xcoff_data (abfd
)->full_aouthdr
)
4259 size
= bfd_coff_aoutsz (abfd
);
4261 size
= SMALL_AOUTSZ
;
4262 if (bfd_bwrite (& buff
, (bfd_size_type
) size
, abfd
) != size
)
4272 coff_set_section_contents (bfd
* abfd
,
4274 const void * location
,
4276 bfd_size_type count
)
4278 if (! abfd
->output_has_begun
) /* Set by bfd.c handler. */
4280 if (! coff_compute_section_file_positions (abfd
))
4284 #if defined(_LIB) && !defined(TARG_AUX)
4285 /* The physical address field of a .lib section is used to hold the
4286 number of shared libraries in the section. This code counts the
4287 number of sections being written, and increments the lma field
4290 I have found no documentation on the contents of this section.
4291 Experimentation indicates that the section contains zero or more
4292 records, each of which has the following structure:
4294 - a (four byte) word holding the length of this record, in words,
4295 - a word that always seems to be set to "2",
4296 - the path to a shared library, null-terminated and then padded
4297 to a whole word boundary.
4299 bfd_assert calls have been added to alert if an attempt is made
4300 to write a section which doesn't follow these assumptions. The
4301 code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4302 <robertl@arnet.com> (Thanks!).
4304 Gvran Uddeborg <gvran@uddeborg.pp.se>. */
4305 if (strcmp (section
->name
, _LIB
) == 0)
4307 bfd_byte
*rec
, *recend
;
4309 rec
= (bfd_byte
*) location
;
4310 recend
= rec
+ count
;
4311 while (recend
- rec
>= 4)
4313 size_t len
= bfd_get_32 (abfd
, rec
);
4314 if (len
== 0 || len
> (size_t) (recend
- rec
) / 4)
4320 BFD_ASSERT (rec
== recend
);
4324 /* Don't write out bss sections - one way to do this is to
4325 see if the filepos has not been set. */
4326 if (section
->filepos
== 0)
4329 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0)
4335 return bfd_bwrite (location
, count
, abfd
) == count
;
4339 buy_and_read (bfd
*abfd
, file_ptr where
,
4340 bfd_size_type nmemb
, bfd_size_type size
)
4344 if (_bfd_mul_overflow (nmemb
, size
, &amt
))
4346 bfd_set_error (bfd_error_file_too_big
);
4349 if (bfd_seek (abfd
, where
, SEEK_SET
) != 0)
4351 return _bfd_malloc_and_read (abfd
, amt
, amt
);
4358 Creating the linenumber table is done by reading in the entire
4359 coff linenumber table, and creating another table for internal use.
4361 A coff linenumber table is structured so that each function
4362 is marked as having a line number of 0. Each line within the
4363 function is an offset from the first line in the function. The
4364 base of the line number information for the table is stored in
4365 the symbol associated with the function.
4367 Note: The PE format uses line number 0 for a flag indicating a
4370 The information is copied from the external to the internal
4371 table, and each symbol which marks a function is marked by
4374 How does this work ?
4378 coff_sort_func_alent (const void * arg1
, const void * arg2
)
4380 const alent
*al1
= *(const alent
**) arg1
;
4381 const alent
*al2
= *(const alent
**) arg2
;
4382 const coff_symbol_type
*s1
= (const coff_symbol_type
*) (al1
->u
.sym
);
4383 const coff_symbol_type
*s2
= (const coff_symbol_type
*) (al2
->u
.sym
);
4385 if (s1
== NULL
|| s2
== NULL
)
4387 if (s1
->symbol
.value
< s2
->symbol
.value
)
4389 else if (s1
->symbol
.value
> s2
->symbol
.value
)
4396 coff_slurp_line_table (bfd
*abfd
, asection
*asect
)
4398 LINENO
*native_lineno
;
4399 alent
*lineno_cache
;
4400 unsigned int counter
;
4402 bfd_vma prev_offset
= 0;
4403 bool ordered
= true;
4404 unsigned int nbr_func
;
4410 if (asect
->lineno_count
== 0)
4413 BFD_ASSERT (asect
->lineno
== NULL
);
4415 native_lineno
= (LINENO
*) buy_and_read (abfd
, asect
->line_filepos
,
4416 asect
->lineno_count
,
4417 bfd_coff_linesz (abfd
));
4418 if (native_lineno
== NULL
)
4421 (_("%pB: warning: line number table read failed"), abfd
);
4425 if (_bfd_mul_overflow (asect
->lineno_count
+ 1, sizeof (alent
), &amt
))
4427 bfd_set_error (bfd_error_file_too_big
);
4428 free (native_lineno
);
4431 lineno_cache
= (alent
*) bfd_alloc (abfd
, amt
);
4432 if (lineno_cache
== NULL
)
4434 free (native_lineno
);
4438 cache_ptr
= lineno_cache
;
4439 asect
->lineno
= lineno_cache
;
4440 src
= native_lineno
;
4444 for (counter
= 0; counter
< asect
->lineno_count
; counter
++, src
++)
4446 struct internal_lineno dst
;
4448 bfd_coff_swap_lineno_in (abfd
, src
, &dst
);
4449 cache_ptr
->line_number
= dst
.l_lnno
;
4450 /* Appease memory checkers that get all excited about
4451 uninitialised memory when copying alents if u.offset is
4452 larger than u.sym. (64-bit BFD on 32-bit host.) */
4453 memset (&cache_ptr
->u
, 0, sizeof (cache_ptr
->u
));
4455 if (cache_ptr
->line_number
== 0)
4457 combined_entry_type
* ent
;
4458 unsigned long symndx
;
4459 coff_symbol_type
*sym
;
4462 symndx
= dst
.l_addr
.l_symndx
;
4463 if (symndx
>= obj_raw_syment_count (abfd
))
4466 /* xgettext:c-format */
4467 (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4468 abfd
, symndx
, counter
);
4469 cache_ptr
->line_number
= -1;
4474 ent
= obj_raw_syments (abfd
) + symndx
;
4475 /* FIXME: We should not be casting between ints and
4476 pointers like this. */
4480 /* xgettext:c-format */
4481 (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4482 abfd
, symndx
, counter
);
4483 cache_ptr
->line_number
= -1;
4487 sym
= (coff_symbol_type
*) (ent
->u
.syment
._n
._n_n
._n_zeroes
);
4489 /* PR 17512 file: 078-10659-0.004 */
4490 if (sym
< obj_symbols (abfd
)
4491 || sym
>= obj_symbols (abfd
) + bfd_get_symcount (abfd
))
4494 /* xgettext:c-format */
4495 (_("%pB: warning: illegal symbol in line number entry %d"),
4497 cache_ptr
->line_number
= -1;
4504 cache_ptr
->u
.sym
= (asymbol
*) sym
;
4505 if (sym
->lineno
!= NULL
)
4507 /* xgettext:c-format */
4508 (_("%pB: warning: duplicate line number information for `%s'"),
4509 abfd
, bfd_asymbol_name (&sym
->symbol
));
4511 sym
->lineno
= cache_ptr
;
4512 if (sym
->symbol
.value
< prev_offset
)
4514 prev_offset
= sym
->symbol
.value
;
4516 else if (!have_func
)
4517 /* Drop line information that has no associated function.
4518 PR 17521: file: 078-10659-0.004. */
4521 cache_ptr
->u
.offset
= dst
.l_addr
.l_paddr
- bfd_section_vma (asect
);
4525 asect
->lineno_count
= cache_ptr
- lineno_cache
;
4526 memset (cache_ptr
, 0, sizeof (*cache_ptr
));
4527 free (native_lineno
);
4529 /* On some systems (eg AIX5.3) the lineno table may not be sorted. */
4532 /* Sort the table. */
4534 alent
*n_lineno_cache
;
4536 /* Create a table of functions. */
4537 if (_bfd_mul_overflow (nbr_func
, sizeof (alent
*), &amt
))
4539 bfd_set_error (bfd_error_file_too_big
);
4542 else if ((func_table
= (alent
**) bfd_alloc (abfd
, amt
)) != NULL
)
4544 alent
**p
= func_table
;
4547 for (i
= 0; i
< asect
->lineno_count
; i
++)
4548 if (lineno_cache
[i
].line_number
== 0)
4549 *p
++ = &lineno_cache
[i
];
4551 BFD_ASSERT ((unsigned int) (p
- func_table
) == nbr_func
);
4553 /* Sort by functions. */
4554 qsort (func_table
, nbr_func
, sizeof (alent
*), coff_sort_func_alent
);
4556 /* Create the new sorted table. */
4557 if (_bfd_mul_overflow (asect
->lineno_count
, sizeof (alent
), &amt
))
4559 bfd_set_error (bfd_error_file_too_big
);
4562 else if ((n_lineno_cache
= (alent
*) bfd_alloc (abfd
, amt
)) != NULL
)
4564 alent
*n_cache_ptr
= n_lineno_cache
;
4566 for (i
= 0; i
< nbr_func
; i
++)
4568 coff_symbol_type
*sym
;
4569 alent
*old_ptr
= func_table
[i
];
4571 /* Update the function entry. */
4572 sym
= (coff_symbol_type
*) old_ptr
->u
.sym
;
4573 /* PR binutils/17512: Point the lineno to where
4574 this entry will be after the memcpy below. */
4575 sym
->lineno
= lineno_cache
+ (n_cache_ptr
- n_lineno_cache
);
4576 /* Copy the function and line number entries. */
4578 *n_cache_ptr
++ = *old_ptr
++;
4579 while (old_ptr
->line_number
!= 0);
4582 memcpy (lineno_cache
, n_lineno_cache
,
4583 asect
->lineno_count
* sizeof (alent
));
4587 bfd_release (abfd
, func_table
);
4596 /* Slurp in the symbol table, converting it to generic form. Note
4597 that if coff_relocate_section is defined, the linker will read
4598 symbols via coff_link_add_symbols, rather than via this routine. */
4601 coff_slurp_symbol_table (bfd
* abfd
)
4603 combined_entry_type
*native_symbols
;
4604 coff_symbol_type
*cached_area
;
4605 unsigned int *table_ptr
;
4606 unsigned int number_of_symbols
= 0;
4610 if (obj_symbols (abfd
))
4613 /* Read in the symbol table. */
4614 if ((native_symbols
= coff_get_normalized_symtab (abfd
)) == NULL
)
4617 /* Allocate enough room for all the symbols in cached form. */
4618 if (_bfd_mul_overflow (obj_raw_syment_count (abfd
),
4619 sizeof (*cached_area
), &amt
))
4621 bfd_set_error (bfd_error_file_too_big
);
4624 cached_area
= (coff_symbol_type
*) bfd_alloc (abfd
, amt
);
4625 if (cached_area
== NULL
)
4628 if (_bfd_mul_overflow (obj_raw_syment_count (abfd
),
4629 sizeof (*table_ptr
), &amt
))
4631 bfd_set_error (bfd_error_file_too_big
);
4634 table_ptr
= (unsigned int *) bfd_zalloc (abfd
, amt
);
4635 if (table_ptr
== NULL
)
4639 coff_symbol_type
*dst
= cached_area
;
4640 unsigned int last_native_index
= obj_raw_syment_count (abfd
);
4641 unsigned int this_index
= 0;
4643 while (this_index
< last_native_index
)
4645 combined_entry_type
*src
= native_symbols
+ this_index
;
4646 table_ptr
[this_index
] = number_of_symbols
;
4648 dst
->symbol
.the_bfd
= abfd
;
4649 BFD_ASSERT (src
->is_sym
);
4650 dst
->symbol
.name
= (char *) (src
->u
.syment
._n
._n_n
._n_offset
);
4651 /* We use the native name field to point to the cached field. */
4652 src
->u
.syment
._n
._n_n
._n_zeroes
= (uintptr_t) dst
;
4653 dst
->symbol
.section
= coff_section_from_bfd_index (abfd
,
4654 src
->u
.syment
.n_scnum
);
4655 dst
->symbol
.flags
= 0;
4656 /* PR 17512: file: 079-7098-0.001:0.1. */
4657 dst
->symbol
.value
= 0;
4658 dst
->done_lineno
= false;
4660 switch (src
->u
.syment
.n_sclass
)
4666 case C_THUMBEXTFUNC
:
4670 #if ! defined _AIX52 && ! defined AIX_WEAK_SUPPORT
4675 case C_SYSTEM
: /* System Wide variable. */
4678 /* In PE, 0x68 (104) denotes a section symbol. */
4680 /* In PE, 0x69 (105) denotes a weak external symbol. */
4683 switch (coff_classify_symbol (abfd
, &src
->u
.syment
))
4685 case COFF_SYMBOL_GLOBAL
:
4686 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
;
4687 #if defined COFF_WITH_PE
4688 /* PE sets the symbol to a value relative to the
4689 start of the section. */
4690 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4692 dst
->symbol
.value
= (src
->u
.syment
.n_value
4693 - dst
->symbol
.section
->vma
);
4695 if (ISFCN ((src
->u
.syment
.n_type
)))
4696 /* A function ext does not go at the end of a
4698 dst
->symbol
.flags
|= BSF_NOT_AT_END
| BSF_FUNCTION
;
4701 case COFF_SYMBOL_COMMON
:
4702 dst
->symbol
.section
= bfd_com_section_ptr
;
4703 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4706 case COFF_SYMBOL_UNDEFINED
:
4707 dst
->symbol
.section
= bfd_und_section_ptr
;
4708 dst
->symbol
.value
= 0;
4711 case COFF_SYMBOL_PE_SECTION
:
4712 dst
->symbol
.flags
|= BSF_EXPORT
| BSF_SECTION_SYM
;
4713 dst
->symbol
.value
= 0;
4716 case COFF_SYMBOL_LOCAL
:
4717 dst
->symbol
.flags
= BSF_LOCAL
;
4718 #if defined COFF_WITH_PE
4719 /* PE sets the symbol to a value relative to the
4720 start of the section. */
4721 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4723 dst
->symbol
.value
= (src
->u
.syment
.n_value
4724 - dst
->symbol
.section
->vma
);
4726 if (ISFCN ((src
->u
.syment
.n_type
)))
4727 dst
->symbol
.flags
|= BSF_NOT_AT_END
| BSF_FUNCTION
;
4732 /* A symbol with a csect entry should not go at the end. */
4733 if (src
->u
.syment
.n_numaux
> 0)
4734 dst
->symbol
.flags
|= BSF_NOT_AT_END
;
4738 if (src
->u
.syment
.n_sclass
== C_NT_WEAK
)
4739 dst
->symbol
.flags
|= BSF_WEAK
;
4741 if (src
->u
.syment
.n_sclass
== C_SECTION
4742 && src
->u
.syment
.n_scnum
> 0)
4743 dst
->symbol
.flags
= BSF_LOCAL
;
4745 if (src
->u
.syment
.n_sclass
== C_WEAKEXT
4747 || src
->u
.syment
.n_sclass
== C_AIX_WEAKEXT
4750 dst
->symbol
.flags
|= BSF_WEAK
;
4754 case C_STAT
: /* Static. */
4756 case C_THUMBSTAT
: /* Thumb static. */
4757 case C_THUMBLABEL
: /* Thumb label. */
4758 case C_THUMBSTATFUNC
:/* Thumb static function. */
4761 case C_DWARF
: /* A label in a dwarf section. */
4762 case C_INFO
: /* A label in a comment section. */
4764 case C_LABEL
: /* Label. */
4765 if (src
->u
.syment
.n_scnum
== N_DEBUG
)
4766 dst
->symbol
.flags
= BSF_DEBUGGING
;
4768 dst
->symbol
.flags
= BSF_LOCAL
;
4770 /* Base the value as an index from the base of the
4771 section, if there is one. */
4772 if (dst
->symbol
.section
)
4774 #if defined COFF_WITH_PE
4775 /* PE sets the symbol to a value relative to the
4776 start of the section. */
4777 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4779 dst
->symbol
.value
= (src
->u
.syment
.n_value
4780 - dst
->symbol
.section
->vma
);
4784 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4787 case C_FILE
: /* File name. */
4788 dst
->symbol
.flags
= BSF_FILE
;
4790 case C_MOS
: /* Member of structure. */
4791 case C_EOS
: /* End of structure. */
4792 case C_REGPARM
: /* Register parameter. */
4793 case C_REG
: /* register variable. */
4794 /* C_AUTOARG conflicts with TI COFF C_UEXT. */
4795 case C_TPDEF
: /* Type definition. */
4797 case C_AUTO
: /* Automatic variable. */
4798 case C_FIELD
: /* Bit field. */
4799 case C_ENTAG
: /* Enumeration tag. */
4800 case C_MOE
: /* Member of enumeration. */
4801 case C_MOU
: /* Member of union. */
4802 case C_UNTAG
: /* Union tag. */
4803 case C_STRTAG
: /* Structure tag. */
4820 dst
->symbol
.flags
|= BSF_DEBUGGING
;
4821 dst
->symbol
.value
= (src
->u
.syment
.n_value
);
4825 case C_BINCL
: /* Beginning of include file. */
4826 case C_EINCL
: /* Ending of include file. */
4827 /* The value is actually a pointer into the line numbers
4828 of the file. We locate the line number entry, and
4829 set the section to the section which contains it, and
4830 the value to the index in that section. */
4834 dst
->symbol
.flags
= BSF_DEBUGGING
;
4835 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4836 if (sec
->line_filepos
<= (file_ptr
) src
->u
.syment
.n_value
4837 && ((file_ptr
) (sec
->line_filepos
4838 + sec
->lineno_count
* bfd_coff_linesz (abfd
))
4839 > (file_ptr
) src
->u
.syment
.n_value
))
4842 dst
->symbol
.value
= 0;
4845 dst
->symbol
.section
= sec
;
4846 dst
->symbol
.value
= ((src
->u
.syment
.n_value
4847 - sec
->line_filepos
)
4848 / bfd_coff_linesz (abfd
));
4855 dst
->symbol
.flags
= BSF_DEBUGGING
;
4857 if (src
->u
.syment
.n_value
>= obj_raw_syment_count (abfd
))
4858 dst
->symbol
.value
= 0;
4861 /* The value is actually a symbol index. Save a pointer
4862 to the symbol instead of the index. FIXME: This
4863 should use a union. */
4864 src
->u
.syment
.n_value
4865 = (uintptr_t) (native_symbols
+ src
->u
.syment
.n_value
);
4866 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4872 case C_BLOCK
: /* ".bb" or ".eb". */
4873 case C_FCN
: /* ".bf" or ".ef" (or PE ".lf"). */
4874 case C_EFCN
: /* Physical end of function. */
4875 #if defined COFF_WITH_PE
4876 /* PE sets the symbol to a value relative to the start
4878 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4879 if (strcmp (dst
->symbol
.name
, ".bf") != 0)
4881 /* PE uses funny values for .ef and .lf; don't
4883 dst
->symbol
.flags
= BSF_DEBUGGING
;
4886 dst
->symbol
.flags
= BSF_DEBUGGING
| BSF_DEBUGGING_RELOC
;
4888 /* Base the value as an index from the base of the
4890 dst
->symbol
.flags
= BSF_LOCAL
;
4891 dst
->symbol
.value
= (src
->u
.syment
.n_value
4892 - dst
->symbol
.section
->vma
);
4896 case C_STATLAB
: /* Static load time label. */
4897 dst
->symbol
.value
= src
->u
.syment
.n_value
;
4898 dst
->symbol
.flags
= BSF_GLOBAL
;
4902 /* PE DLLs sometimes have zeroed out symbols for some
4903 reason. Just ignore them without a warning. */
4904 if (src
->u
.syment
.n_type
== 0
4905 && src
->u
.syment
.n_value
== 0
4906 && src
->u
.syment
.n_scnum
== 0)
4909 /* XCOFF specific: deleted entry. */
4910 if (src
->u
.syment
.n_value
== C_NULL_VALUE
)
4914 case C_EXTDEF
: /* External definition. */
4915 case C_ULABEL
: /* Undefined label. */
4916 case C_USTATIC
: /* Undefined static. */
4917 #ifndef COFF_WITH_PE
4918 /* C_LINE in regular coff is 0x68. NT has taken over this storage
4919 class to represent a section symbol. */
4920 case C_LINE
: /* line # reformatted as symbol table entry. */
4921 /* NT uses 0x67 for a weak symbol, not C_ALIAS. */
4922 case C_ALIAS
: /* Duplicate tag. */
4924 /* New storage classes for TI COFF. */
4926 case C_UEXT
: /* Tentative external definition. */
4928 case C_EXTLAB
: /* External load time label. */
4931 /* xgettext:c-format */
4932 (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
4933 abfd
, src
->u
.syment
.n_sclass
,
4934 dst
->symbol
.section
->name
, dst
->symbol
.name
);
4937 case C_HIDDEN
: /* Ext symbol in dmert public lib. */
4938 /* PR 20722: These symbols can also be generated by
4939 building DLLs with --gc-sections enabled. */
4940 dst
->symbol
.flags
= BSF_DEBUGGING
;
4941 dst
->symbol
.value
= (src
->u
.syment
.n_value
);
4946 dst
->symbol
.udata
.i
= 0;
4949 this_index
+= (src
->u
.syment
.n_numaux
) + 1;
4951 number_of_symbols
++;
4955 obj_symbols (abfd
) = cached_area
;
4956 obj_raw_syments (abfd
) = native_symbols
;
4958 abfd
->symcount
= number_of_symbols
;
4959 obj_convert (abfd
) = table_ptr
;
4960 /* Slurp the line tables for each section too. */
4967 if (! coff_slurp_line_table (abfd
, p
))
4976 /* Classify a COFF symbol. A couple of targets have globally visible
4977 symbols which are not class C_EXT, and this handles those. It also
4978 recognizes some special PE cases. */
4980 static enum coff_symbol_classification
4981 coff_classify_symbol (bfd
*abfd
,
4982 struct internal_syment
*syment
)
4984 /* FIXME: This partially duplicates the switch in
4985 coff_slurp_symbol_table. */
4986 switch (syment
->n_sclass
)
4992 case C_THUMBEXTFUNC
:
4996 #if ! defined _AIX52 && ! defined AIX_WEAK_SUPPORT
5006 if (syment
->n_scnum
== 0)
5008 if (syment
->n_value
== 0)
5009 return COFF_SYMBOL_UNDEFINED
;
5011 return COFF_SYMBOL_COMMON
;
5014 if (syment
->n_sclass
== C_HIDEXT
)
5015 return COFF_SYMBOL_LOCAL
;
5017 return COFF_SYMBOL_GLOBAL
;
5024 if (syment
->n_sclass
== C_STAT
)
5026 if (syment
->n_scnum
== 0)
5027 /* The Microsoft compiler sometimes generates these if a
5028 small static function is inlined every time it is used.
5029 The function is discarded, but the symbol table entry
5031 return COFF_SYMBOL_LOCAL
;
5033 #ifdef STRICT_PE_FORMAT
5034 /* This is correct for Microsoft generated objects, but it
5035 breaks gas generated objects. */
5036 if (syment
->n_value
== 0)
5038 const asection
*sec
;
5040 char buf
[SYMNMLEN
+ 1];
5042 name
= _bfd_coff_internal_syment_name (abfd
, syment
, buf
);
5043 sec
= coff_section_from_bfd_index (abfd
, syment
->n_scnum
);
5044 if (sec
!= NULL
&& name
!= NULL
5045 && (strcmp (bfd_section_name (sec
), name
) == 0))
5046 return COFF_SYMBOL_PE_SECTION
;
5050 return COFF_SYMBOL_LOCAL
;
5053 if (syment
->n_sclass
== C_SECTION
)
5055 /* In some cases in a DLL generated by the Microsoft linker, the
5056 n_value field will contain garbage. FIXME: This should
5057 probably be handled by the swapping function instead. */
5058 syment
->n_value
= 0;
5059 if (syment
->n_scnum
== 0)
5060 return COFF_SYMBOL_UNDEFINED
;
5061 return COFF_SYMBOL_PE_SECTION
;
5063 #endif /* COFF_WITH_PE */
5065 /* If it is not a global symbol, we presume it is a local symbol. */
5066 if (syment
->n_scnum
== 0)
5068 char buf
[SYMNMLEN
+ 1];
5071 /* xgettext:c-format */
5072 (_("warning: %pB: local symbol `%s' has no section"),
5073 abfd
, _bfd_coff_internal_syment_name (abfd
, syment
, buf
));
5076 return COFF_SYMBOL_LOCAL
;
5083 Coff relocations are easily transformed into the internal BFD form
5086 Reading a coff relocation table is done in the following stages:
5088 o Read the entire coff relocation table into memory.
5090 o Process each relocation in turn; first swap it from the
5091 external to the internal form.
5093 o Turn the symbol referenced in the relocation's symbol index
5094 into a pointer into the canonical symbol table.
5095 This table is the same as the one returned by a call to
5096 @code{bfd_canonicalize_symtab}. The back end will call that
5097 routine and save the result if a canonicalization hasn't been done.
5099 o The reloc index is turned into a pointer to a howto
5100 structure, in a back end specific way. For instance, the 386
5101 uses the @code{r_type} to directly produce an index
5102 into a howto table vector.
5104 o Note that @code{arelent.addend} for COFF is often not what
5105 most people understand as a relocation addend, but rather an
5106 adjustment to the relocation addend stored in section contents
5107 of relocatable object files. The value found in section
5108 contents may also be confusing, depending on both symbol value
5109 and addend somewhat similar to the field value for a
5110 final-linked object. See @code{CALC_ADDEND}.
5114 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
5116 coff_symbol_type *coffsym = NULL; \
5118 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
5119 coffsym = (obj_symbols (abfd) \
5120 + (cache_ptr->sym_ptr_ptr - symbols)); \
5122 coffsym = coff_symbol_from (ptr); \
5123 if (coffsym != NULL \
5124 && coffsym->native->is_sym \
5125 && coffsym->native->u.syment.n_scnum == 0) \
5126 cache_ptr->addend = 0; \
5127 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
5128 && ptr->section != NULL) \
5129 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
5131 cache_ptr->addend = 0; \
5136 coff_slurp_reloc_table (bfd
* abfd
, sec_ptr asect
, asymbol
** symbols
)
5138 bfd_byte
*native_relocs
;
5139 arelent
*reloc_cache
;
5144 if (asect
->relocation
)
5146 if (asect
->reloc_count
== 0)
5148 if (asect
->flags
& SEC_CONSTRUCTOR
)
5150 if (!coff_slurp_symbol_table (abfd
))
5153 native_relocs
= (bfd_byte
*) buy_and_read (abfd
, asect
->rel_filepos
,
5155 bfd_coff_relsz (abfd
));
5156 if (native_relocs
== NULL
)
5159 if (_bfd_mul_overflow (asect
->reloc_count
, sizeof (arelent
), &amt
))
5161 bfd_set_error (bfd_error_file_too_big
);
5164 reloc_cache
= (arelent
*) bfd_alloc (abfd
, amt
);
5165 if (reloc_cache
== NULL
)
5167 free (native_relocs
);
5171 for (idx
= 0; idx
< asect
->reloc_count
; idx
++)
5173 struct internal_reloc dst
;
5175 #ifndef RELOC_PROCESSING
5179 cache_ptr
= reloc_cache
+ idx
;
5180 src
= native_relocs
+ idx
* (size_t) bfd_coff_relsz (abfd
);
5183 bfd_coff_swap_reloc_in (abfd
, src
, &dst
);
5185 #ifdef RELOC_PROCESSING
5186 RELOC_PROCESSING (cache_ptr
, &dst
, symbols
, abfd
, asect
);
5188 cache_ptr
->address
= dst
.r_vaddr
;
5190 if (dst
.r_symndx
!= -1 && symbols
!= NULL
)
5192 if (dst
.r_symndx
< 0 || dst
.r_symndx
>= obj_conv_table_size (abfd
))
5195 /* xgettext:c-format */
5196 (_("%pB: warning: illegal symbol index %ld in relocs"),
5197 abfd
, dst
.r_symndx
);
5198 cache_ptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
5203 cache_ptr
->sym_ptr_ptr
= (symbols
5204 + obj_convert (abfd
)[dst
.r_symndx
]);
5205 ptr
= *(cache_ptr
->sym_ptr_ptr
);
5210 cache_ptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
5214 /* The symbols definitions that we have read in have been
5215 relocated as if their sections started at 0. But the offsets
5216 refering to the symbols in the raw data have not been
5217 modified, so we have to have a negative addend to compensate.
5219 Note that symbols which used to be common must be left alone. */
5221 /* Calculate any reloc addend by looking at the symbol. */
5222 CALC_ADDEND (abfd
, ptr
, dst
, cache_ptr
);
5225 cache_ptr
->address
-= asect
->vma
;
5226 /* !! cache_ptr->section = NULL;*/
5228 /* Fill in the cache_ptr->howto field from dst.r_type. */
5229 RTYPE2HOWTO (cache_ptr
, &dst
);
5230 #endif /* RELOC_PROCESSING */
5232 if (cache_ptr
->howto
== NULL
)
5235 /* xgettext:c-format */
5236 (_("%pB: illegal relocation type %d at address %#" PRIx64
),
5237 abfd
, dst
.r_type
, (uint64_t) dst
.r_vaddr
);
5238 bfd_set_error (bfd_error_bad_value
);
5239 free (native_relocs
);
5244 free (native_relocs
);
5245 asect
->relocation
= reloc_cache
;
5249 #ifndef coff_rtype_to_howto
5252 /* Get the howto structure for a reloc. This is only used if the file
5253 including this one defines coff_relocate_section to be
5254 _bfd_coff_generic_relocate_section, so it is OK if it does not
5255 always work. It is the responsibility of the including file to
5256 make sure it is reasonable if it is needed. */
5258 static reloc_howto_type
*
5259 coff_rtype_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
5260 asection
*sec ATTRIBUTE_UNUSED
,
5261 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
5262 struct coff_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5263 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
5264 bfd_vma
*addendp ATTRIBUTE_UNUSED
)
5268 genrel
.howto
= NULL
;
5269 RTYPE2HOWTO (&genrel
, rel
);
5270 return genrel
.howto
;
5273 #else /* ! defined (RTYPE2HOWTO) */
5275 #define coff_rtype_to_howto NULL
5277 #endif /* ! defined (RTYPE2HOWTO) */
5278 #endif /* ! defined (coff_rtype_to_howto) */
5280 /* This is stupid. This function should be a boolean predicate. */
5283 coff_canonicalize_reloc (bfd
* abfd
,
5288 arelent
*tblptr
= section
->relocation
;
5289 unsigned int count
= 0;
5291 if (section
->flags
& SEC_CONSTRUCTOR
)
5293 /* This section has relocs made up by us, they are not in the
5294 file, so take them out of their chain and place them into
5295 the data area provided. */
5296 arelent_chain
*chain
= section
->constructor_chain
;
5298 for (count
= 0; count
< section
->reloc_count
; count
++)
5300 *relptr
++ = &chain
->relent
;
5301 chain
= chain
->next
;
5306 if (! coff_slurp_reloc_table (abfd
, section
, symbols
))
5309 tblptr
= section
->relocation
;
5311 for (; count
++ < section
->reloc_count
;)
5312 *relptr
++ = tblptr
++;
5315 return section
->reloc_count
;
5318 #ifndef coff_set_reloc
5319 #define coff_set_reloc _bfd_generic_set_reloc
5322 #ifndef coff_reloc16_estimate
5323 #define coff_reloc16_estimate dummy_reloc16_estimate
5326 dummy_reloc16_estimate (bfd
*abfd ATTRIBUTE_UNUSED
,
5327 asection
*input_section ATTRIBUTE_UNUSED
,
5328 arelent
*reloc ATTRIBUTE_UNUSED
,
5329 unsigned int shrink ATTRIBUTE_UNUSED
,
5330 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
5338 #ifndef coff_reloc16_extra_cases
5340 #define coff_reloc16_extra_cases dummy_reloc16_extra_cases
5343 dummy_reloc16_extra_cases (bfd
*abfd ATTRIBUTE_UNUSED
,
5344 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
5345 struct bfd_link_order
*link_order ATTRIBUTE_UNUSED
,
5346 arelent
*reloc ATTRIBUTE_UNUSED
,
5347 bfd_byte
*data ATTRIBUTE_UNUSED
,
5348 size_t *src_ptr ATTRIBUTE_UNUSED
,
5349 size_t *dst_ptr ATTRIBUTE_UNUSED
)
5355 /* If coff_relocate_section is defined, we can use the optimized COFF
5356 backend linker. Otherwise we must continue to use the old linker. */
5358 #ifdef coff_relocate_section
5360 #ifndef coff_bfd_link_hash_table_create
5361 #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
5363 #ifndef coff_bfd_link_add_symbols
5364 #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
5366 #ifndef coff_bfd_final_link
5367 #define coff_bfd_final_link _bfd_coff_final_link
5370 #else /* ! defined (coff_relocate_section) */
5372 #define coff_relocate_section NULL
5373 #ifndef coff_bfd_link_hash_table_create
5374 #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5376 #ifndef coff_bfd_link_add_symbols
5377 #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
5379 #define coff_bfd_final_link _bfd_generic_final_link
5381 #endif /* ! defined (coff_relocate_section) */
5383 #define coff_bfd_link_just_syms _bfd_generic_link_just_syms
5384 #define coff_bfd_copy_link_hash_symbol_type \
5385 _bfd_generic_copy_link_hash_symbol_type
5386 #define coff_bfd_link_split_section _bfd_generic_link_split_section
5388 #define coff_bfd_link_check_relocs _bfd_generic_link_check_relocs
5390 #ifndef coff_start_final_link
5391 #define coff_start_final_link NULL
5394 #ifndef coff_adjust_symndx
5395 #define coff_adjust_symndx NULL
5398 #ifndef coff_link_add_one_symbol
5399 #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
5402 #ifndef coff_link_output_has_begun
5405 coff_link_output_has_begun (bfd
* abfd
,
5406 struct coff_final_link_info
* info ATTRIBUTE_UNUSED
)
5408 return abfd
->output_has_begun
;
5412 #ifndef coff_final_link_postscript
5415 coff_final_link_postscript (bfd
* abfd ATTRIBUTE_UNUSED
,
5416 struct coff_final_link_info
* pfinfo ATTRIBUTE_UNUSED
)
5422 #ifndef coff_SWAP_aux_in
5423 #define coff_SWAP_aux_in coff_swap_aux_in
5425 #ifndef coff_SWAP_sym_in
5426 #define coff_SWAP_sym_in coff_swap_sym_in
5428 #ifndef coff_SWAP_lineno_in
5429 #define coff_SWAP_lineno_in coff_swap_lineno_in
5431 #ifndef coff_SWAP_aux_out
5432 #define coff_SWAP_aux_out coff_swap_aux_out
5434 #ifndef coff_SWAP_sym_out
5435 #define coff_SWAP_sym_out coff_swap_sym_out
5437 #ifndef coff_SWAP_lineno_out
5438 #define coff_SWAP_lineno_out coff_swap_lineno_out
5440 #ifndef coff_SWAP_reloc_out
5441 #define coff_SWAP_reloc_out coff_swap_reloc_out
5443 #ifndef coff_SWAP_filehdr_out
5444 #define coff_SWAP_filehdr_out coff_swap_filehdr_out
5446 #ifndef coff_SWAP_aouthdr_out
5447 #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
5449 #ifndef coff_SWAP_scnhdr_out
5450 #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
5452 #ifndef coff_SWAP_reloc_in
5453 #define coff_SWAP_reloc_in coff_swap_reloc_in
5455 #ifndef coff_SWAP_filehdr_in
5456 #define coff_SWAP_filehdr_in coff_swap_filehdr_in
5458 #ifndef coff_SWAP_aouthdr_in
5459 #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
5461 #ifndef coff_SWAP_scnhdr_in
5462 #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
5465 #define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
5467 static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED
=
5469 coff_SWAP_aux_in
, coff_SWAP_sym_in
, coff_SWAP_lineno_in
,
5470 coff_SWAP_aux_out
, coff_SWAP_sym_out
,
5471 coff_SWAP_lineno_out
, coff_SWAP_reloc_out
,
5472 coff_SWAP_filehdr_out
, coff_SWAP_aouthdr_out
,
5473 coff_SWAP_scnhdr_out
,
5474 FILHSZ
, AOUTSZ
, SCNHSZ
, SYMESZ
, AUXESZ
, RELSZ
, LINESZ
, FILNMLEN
,
5475 #ifdef COFF_LONG_FILENAMES
5480 COFF_DEFAULT_LONG_SECTION_NAMES
,
5481 COFF_DEFAULT_SECTION_ALIGNMENT_POWER
,
5482 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5487 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5493 coff_SWAP_filehdr_in
, coff_SWAP_aouthdr_in
, coff_SWAP_scnhdr_in
,
5494 coff_SWAP_reloc_in
, coff_bad_format_hook
, coff_set_arch_mach_hook
,
5495 coff_mkobject_hook
, styp_to_sec_flags
, coff_set_alignment_hook
,
5496 coff_slurp_symbol_table
, symname_in_debug_hook
, coff_pointerize_aux_hook
,
5497 coff_print_aux
, coff_reloc16_extra_cases
, coff_reloc16_estimate
,
5498 coff_classify_symbol
, coff_compute_section_file_positions
,
5499 coff_start_final_link
, coff_relocate_section
, coff_rtype_to_howto
,
5500 coff_adjust_symndx
, coff_link_add_one_symbol
,
5501 coff_link_output_has_begun
, coff_final_link_postscript
,
5506 /* COFF0 differs in file/section header size and relocation entry size. */
5508 static const bfd_coff_backend_data ticoff0_swap_table
=
5510 coff_SWAP_aux_in
, coff_SWAP_sym_in
, coff_SWAP_lineno_in
,
5511 coff_SWAP_aux_out
, coff_SWAP_sym_out
,
5512 coff_SWAP_lineno_out
, coff_swap_reloc_v0_out
,
5513 coff_SWAP_filehdr_out
, coff_SWAP_aouthdr_out
,
5514 coff_SWAP_scnhdr_out
,
5515 FILHSZ_V0
, AOUTSZ
, SCNHSZ_V01
, SYMESZ
, AUXESZ
, RELSZ_V0
, LINESZ
, FILNMLEN
,
5516 #ifdef COFF_LONG_FILENAMES
5521 COFF_DEFAULT_LONG_SECTION_NAMES
,
5522 COFF_DEFAULT_SECTION_ALIGNMENT_POWER
,
5523 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5528 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5534 coff_SWAP_filehdr_in
, coff_SWAP_aouthdr_in
, coff_SWAP_scnhdr_in
,
5535 coff_swap_reloc_v0_in
, ticoff0_bad_format_hook
, coff_set_arch_mach_hook
,
5536 coff_mkobject_hook
, styp_to_sec_flags
, coff_set_alignment_hook
,
5537 coff_slurp_symbol_table
, symname_in_debug_hook
, coff_pointerize_aux_hook
,
5538 coff_print_aux
, coff_reloc16_extra_cases
, coff_reloc16_estimate
,
5539 coff_classify_symbol
, coff_compute_section_file_positions
,
5540 coff_start_final_link
, coff_relocate_section
, coff_rtype_to_howto
,
5541 coff_adjust_symndx
, coff_link_add_one_symbol
,
5542 coff_link_output_has_begun
, coff_final_link_postscript
,
5548 /* COFF1 differs in section header size. */
5550 static const bfd_coff_backend_data ticoff1_swap_table
=
5552 coff_SWAP_aux_in
, coff_SWAP_sym_in
, coff_SWAP_lineno_in
,
5553 coff_SWAP_aux_out
, coff_SWAP_sym_out
,
5554 coff_SWAP_lineno_out
, coff_SWAP_reloc_out
,
5555 coff_SWAP_filehdr_out
, coff_SWAP_aouthdr_out
,
5556 coff_SWAP_scnhdr_out
,
5557 FILHSZ
, AOUTSZ
, SCNHSZ_V01
, SYMESZ
, AUXESZ
, RELSZ
, LINESZ
, FILNMLEN
,
5558 #ifdef COFF_LONG_FILENAMES
5563 COFF_DEFAULT_LONG_SECTION_NAMES
,
5564 COFF_DEFAULT_SECTION_ALIGNMENT_POWER
,
5565 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5570 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5576 coff_SWAP_filehdr_in
, coff_SWAP_aouthdr_in
, coff_SWAP_scnhdr_in
,
5577 coff_SWAP_reloc_in
, ticoff1_bad_format_hook
, coff_set_arch_mach_hook
,
5578 coff_mkobject_hook
, styp_to_sec_flags
, coff_set_alignment_hook
,
5579 coff_slurp_symbol_table
, symname_in_debug_hook
, coff_pointerize_aux_hook
,
5580 coff_print_aux
, coff_reloc16_extra_cases
, coff_reloc16_estimate
,
5581 coff_classify_symbol
, coff_compute_section_file_positions
,
5582 coff_start_final_link
, coff_relocate_section
, coff_rtype_to_howto
,
5583 coff_adjust_symndx
, coff_link_add_one_symbol
,
5584 coff_link_output_has_begun
, coff_final_link_postscript
,
5585 bfd_pe_print_pdata
/* huh */
5589 #ifdef COFF_WITH_PE_BIGOBJ
5590 /* The UID for bigobj files. */
5592 static const char header_bigobj_classid
[16] =
5594 0xC7, 0xA1, 0xBA, 0xD1,
5598 0xFA, 0xF6, 0x6A, 0xA4, 0xDC, 0xB8
5601 /* Swap routines. */
5604 coff_bigobj_swap_filehdr_in (bfd
* abfd
, void * src
, void * dst
)
5606 struct external_ANON_OBJECT_HEADER_BIGOBJ
*filehdr_src
=
5607 (struct external_ANON_OBJECT_HEADER_BIGOBJ
*) src
;
5608 struct internal_filehdr
*filehdr_dst
= (struct internal_filehdr
*) dst
;
5610 filehdr_dst
->f_magic
= H_GET_16 (abfd
, filehdr_src
->Machine
);
5611 filehdr_dst
->f_nscns
= H_GET_32 (abfd
, filehdr_src
->NumberOfSections
);
5612 filehdr_dst
->f_timdat
= H_GET_32 (abfd
, filehdr_src
->TimeDateStamp
);
5613 filehdr_dst
->f_symptr
=
5614 GET_FILEHDR_SYMPTR (abfd
, filehdr_src
->PointerToSymbolTable
);
5615 filehdr_dst
->f_nsyms
= H_GET_32 (abfd
, filehdr_src
->NumberOfSymbols
);
5616 filehdr_dst
->f_opthdr
= 0;
5617 filehdr_dst
->f_flags
= 0;
5619 /* Check other magic numbers. */
5620 if (H_GET_16 (abfd
, filehdr_src
->Sig1
) != IMAGE_FILE_MACHINE_UNKNOWN
5621 || H_GET_16 (abfd
, filehdr_src
->Sig2
) != 0xffff
5622 || H_GET_16 (abfd
, filehdr_src
->Version
) != 2
5623 || memcmp (filehdr_src
->ClassID
, header_bigobj_classid
, 16) != 0)
5624 filehdr_dst
->f_opthdr
= 0xffff;
5626 /* Note that CLR metadata are ignored. */
5630 coff_bigobj_swap_filehdr_out (bfd
*abfd
, void * in
, void * out
)
5632 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*) in
;
5633 struct external_ANON_OBJECT_HEADER_BIGOBJ
*filehdr_out
=
5634 (struct external_ANON_OBJECT_HEADER_BIGOBJ
*) out
;
5636 memset (filehdr_out
, 0, sizeof (*filehdr_out
));
5638 H_PUT_16 (abfd
, IMAGE_FILE_MACHINE_UNKNOWN
, filehdr_out
->Sig1
);
5639 H_PUT_16 (abfd
, 0xffff, filehdr_out
->Sig2
);
5640 H_PUT_16 (abfd
, 2, filehdr_out
->Version
);
5641 memcpy (filehdr_out
->ClassID
, header_bigobj_classid
, 16);
5642 H_PUT_16 (abfd
, filehdr_in
->f_magic
, filehdr_out
->Machine
);
5643 H_PUT_32 (abfd
, filehdr_in
->f_nscns
, filehdr_out
->NumberOfSections
);
5644 H_PUT_32 (abfd
, filehdr_in
->f_timdat
, filehdr_out
->TimeDateStamp
);
5645 PUT_FILEHDR_SYMPTR (abfd
, filehdr_in
->f_symptr
,
5646 filehdr_out
->PointerToSymbolTable
);
5647 H_PUT_32 (abfd
, filehdr_in
->f_nsyms
, filehdr_out
->NumberOfSymbols
);
5649 return bfd_coff_filhsz (abfd
);
5653 coff_bigobj_swap_sym_in (bfd
* abfd
, void * ext1
, void * in1
)
5655 SYMENT_BIGOBJ
*ext
= (SYMENT_BIGOBJ
*) ext1
;
5656 struct internal_syment
*in
= (struct internal_syment
*) in1
;
5658 if (ext
->e
.e_name
[0] == 0)
5660 in
->_n
._n_n
._n_zeroes
= 0;
5661 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
5665 #if SYMNMLEN != E_SYMNMLEN
5666 #error we need to cope with truncating or extending SYMNMLEN
5668 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
5672 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
5673 BFD_ASSERT (sizeof (in
->n_scnum
) >= 4);
5674 in
->n_scnum
= H_GET_32 (abfd
, ext
->e_scnum
);
5675 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
5676 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
5677 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
5681 coff_bigobj_swap_sym_out (bfd
* abfd
, void * inp
, void * extp
)
5683 struct internal_syment
*in
= (struct internal_syment
*) inp
;
5684 SYMENT_BIGOBJ
*ext
= (SYMENT_BIGOBJ
*) extp
;
5686 if (in
->_n
._n_name
[0] == 0)
5688 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
5689 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
5693 #if SYMNMLEN != E_SYMNMLEN
5694 #error we need to cope with truncating or extending SYMNMLEN
5696 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
5700 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
5701 H_PUT_32 (abfd
, in
->n_scnum
, ext
->e_scnum
);
5703 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
5704 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
5705 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
5707 return SYMESZ_BIGOBJ
;
5711 coff_bigobj_swap_aux_in (bfd
*abfd
,
5719 AUXENT_BIGOBJ
*ext
= (AUXENT_BIGOBJ
*) ext1
;
5720 union internal_auxent
*in
= (union internal_auxent
*) in1
;
5722 /* Make sure that all fields in the aux structure are
5724 memset (in
, 0, sizeof * in
);
5731 memcpy (in
->x_file
.x_n
.x_fname
, ext
->File
.Name
,
5732 numaux
* sizeof (AUXENT_BIGOBJ
));
5735 memcpy (in
->x_file
.x_n
.x_fname
, ext
->File
.Name
, sizeof (ext
->File
.Name
));
5743 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->Section
.Length
);
5744 in
->x_scn
.x_nreloc
=
5745 H_GET_16 (abfd
, ext
->Section
.NumberOfRelocations
);
5746 in
->x_scn
.x_nlinno
=
5747 H_GET_16 (abfd
, ext
->Section
.NumberOfLinenumbers
);
5748 in
->x_scn
.x_checksum
= H_GET_32 (abfd
, ext
->Section
.Checksum
);
5749 in
->x_scn
.x_associated
= H_GET_16 (abfd
, ext
->Section
.Number
)
5750 | (H_GET_16 (abfd
, ext
->Section
.HighNumber
) << 16);
5751 in
->x_scn
.x_comdat
= H_GET_8 (abfd
, ext
->Section
.Selection
);
5757 in
->x_sym
.x_tagndx
.u32
= H_GET_32 (abfd
, ext
->Sym
.WeakDefaultSymIndex
);
5758 /* Characteristics is ignored. */
5764 coff_bigobj_swap_aux_out (bfd
* abfd
,
5768 int indx ATTRIBUTE_UNUSED
,
5769 int numaux ATTRIBUTE_UNUSED
,
5772 union internal_auxent
* in
= (union internal_auxent
*) inp
;
5773 AUXENT_BIGOBJ
*ext
= (AUXENT_BIGOBJ
*) extp
;
5775 memset (ext
, 0, AUXESZ
);
5780 memcpy (ext
->File
.Name
, in
->x_file
.x_n
.x_fname
, sizeof (ext
->File
.Name
));
5789 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->Section
.Length
);
5790 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
,
5791 ext
->Section
.NumberOfRelocations
);
5792 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
,
5793 ext
->Section
.NumberOfLinenumbers
);
5794 H_PUT_32 (abfd
, in
->x_scn
.x_checksum
, ext
->Section
.Checksum
);
5795 H_PUT_16 (abfd
, in
->x_scn
.x_associated
& 0xffff,
5796 ext
->Section
.Number
);
5797 H_PUT_16 (abfd
, (in
->x_scn
.x_associated
>> 16),
5798 ext
->Section
.HighNumber
);
5799 H_PUT_8 (abfd
, in
->x_scn
.x_comdat
, ext
->Section
.Selection
);
5805 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.u32
, ext
->Sym
.WeakDefaultSymIndex
);
5806 H_PUT_32 (abfd
, 1, ext
->Sym
.WeakSearchType
);
5811 static const bfd_coff_backend_data bigobj_swap_table
=
5813 coff_bigobj_swap_aux_in
, coff_bigobj_swap_sym_in
, coff_SWAP_lineno_in
,
5814 coff_bigobj_swap_aux_out
, coff_bigobj_swap_sym_out
,
5815 coff_SWAP_lineno_out
, coff_SWAP_reloc_out
,
5816 coff_bigobj_swap_filehdr_out
, coff_SWAP_aouthdr_out
,
5817 coff_SWAP_scnhdr_out
,
5818 FILHSZ_BIGOBJ
, AOUTSZ
, SCNHSZ
, SYMESZ_BIGOBJ
, AUXESZ_BIGOBJ
,
5819 RELSZ
, LINESZ
, FILNMLEN_BIGOBJ
,
5821 COFF_DEFAULT_LONG_SECTION_NAMES
,
5822 COFF_DEFAULT_SECTION_ALIGNMENT_POWER
,
5826 coff_bigobj_swap_filehdr_in
, coff_SWAP_aouthdr_in
, coff_SWAP_scnhdr_in
,
5827 coff_SWAP_reloc_in
, coff_bad_format_hook
, coff_set_arch_mach_hook
,
5828 coff_mkobject_hook
, styp_to_sec_flags
, coff_set_alignment_hook
,
5829 coff_slurp_symbol_table
, symname_in_debug_hook
, coff_pointerize_aux_hook
,
5830 coff_print_aux
, coff_reloc16_extra_cases
, coff_reloc16_estimate
,
5831 coff_classify_symbol
, coff_compute_section_file_positions
,
5832 coff_start_final_link
, coff_relocate_section
, coff_rtype_to_howto
,
5833 coff_adjust_symndx
, coff_link_add_one_symbol
,
5834 coff_link_output_has_begun
, coff_final_link_postscript
,
5835 bfd_pe_print_pdata
/* huh */
5838 #endif /* COFF_WITH_PE_BIGOBJ */
5840 #ifndef coff_close_and_cleanup
5841 #define coff_close_and_cleanup _bfd_coff_close_and_cleanup
5844 #ifndef coff_bfd_free_cached_info
5845 #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
5848 #ifndef coff_get_section_contents
5849 #define coff_get_section_contents _bfd_generic_get_section_contents
5852 #ifndef coff_bfd_copy_private_symbol_data
5853 #define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
5856 #ifndef coff_bfd_copy_private_header_data
5857 #define coff_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
5860 #ifndef coff_bfd_copy_private_section_data
5861 #define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
5864 #ifndef coff_bfd_copy_private_bfd_data
5865 #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
5868 #ifndef coff_bfd_merge_private_bfd_data
5869 #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
5872 #ifndef coff_bfd_set_private_flags
5873 #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
5876 #ifndef coff_bfd_print_private_bfd_data
5877 #define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
5880 #ifndef coff_bfd_is_local_label_name
5881 #define coff_bfd_is_local_label_name _bfd_coff_is_local_label_name
5884 #ifndef coff_bfd_is_target_special_symbol
5885 #define coff_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
5888 #ifndef coff_read_minisymbols
5889 #define coff_read_minisymbols _bfd_generic_read_minisymbols
5892 #ifndef coff_minisymbol_to_symbol
5893 #define coff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
5896 /* The reloc lookup routine must be supplied by each individual COFF
5898 #ifndef coff_bfd_reloc_type_lookup
5899 #define coff_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
5901 #ifndef coff_bfd_reloc_name_lookup
5902 #define coff_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
5905 #ifndef coff_bfd_get_relocated_section_contents
5906 #define coff_bfd_get_relocated_section_contents \
5907 bfd_generic_get_relocated_section_contents
5910 #ifndef coff_bfd_relax_section
5911 #define coff_bfd_relax_section bfd_generic_relax_section
5914 #ifndef coff_bfd_gc_sections
5915 #define coff_bfd_gc_sections bfd_coff_gc_sections
5918 #ifndef coff_bfd_lookup_section_flags
5919 #define coff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
5922 #ifndef coff_bfd_merge_sections
5923 #define coff_bfd_merge_sections bfd_generic_merge_sections
5926 #ifndef coff_bfd_is_group_section
5927 #define coff_bfd_is_group_section bfd_generic_is_group_section
5930 #ifndef coff_bfd_group_name
5931 #define coff_bfd_group_name bfd_coff_group_name
5934 #ifndef coff_bfd_discard_group
5935 #define coff_bfd_discard_group bfd_generic_discard_group
5938 #ifndef coff_section_already_linked
5939 #define coff_section_already_linked \
5940 _bfd_coff_section_already_linked
5943 #ifndef coff_bfd_define_common_symbol
5944 #define coff_bfd_define_common_symbol bfd_generic_define_common_symbol
5947 #ifndef coff_bfd_link_hide_symbol
5948 #define coff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
5951 #ifndef coff_bfd_define_start_stop
5952 #define coff_bfd_define_start_stop bfd_generic_define_start_stop
5955 #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
5956 const bfd_target VAR = \
5959 bfd_target_coff_flavour, \
5960 BFD_ENDIAN_BIG, /* Data byte order is big. */ \
5961 BFD_ENDIAN_BIG, /* Header byte order is big. */ \
5962 /* object flags */ \
5963 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
5964 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
5965 /* section flags */ \
5966 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
5967 UNDER, /* Leading symbol underscore. */ \
5968 '/', /* AR_pad_char. */ \
5969 15, /* AR_max_namelen. */ \
5970 0, /* match priority. */ \
5971 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ \
5973 /* Data conversion functions. */ \
5974 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
5975 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
5976 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
5978 /* Header conversion functions. */ \
5979 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
5980 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
5981 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
5983 { /* bfd_check_format. */ \
5984 _bfd_dummy_target, \
5986 bfd_generic_archive_p, \
5989 { /* bfd_set_format. */ \
5990 _bfd_bool_bfd_false_error, \
5992 _bfd_generic_mkarchive, \
5993 _bfd_bool_bfd_false_error \
5995 { /* bfd_write_contents. */ \
5996 _bfd_bool_bfd_false_error, \
5997 coff_write_object_contents, \
5998 _bfd_write_archive_contents, \
5999 _bfd_bool_bfd_false_error \
6002 BFD_JUMP_TABLE_GENERIC (coff), \
6003 BFD_JUMP_TABLE_COPY (coff), \
6004 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
6005 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
6006 BFD_JUMP_TABLE_SYMBOLS (coff), \
6007 BFD_JUMP_TABLE_RELOCS (coff), \
6008 BFD_JUMP_TABLE_WRITE (coff), \
6009 BFD_JUMP_TABLE_LINK (coff), \
6010 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
6017 #define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
6018 const bfd_target VAR = \
6021 bfd_target_coff_flavour, \
6022 BFD_ENDIAN_LITTLE, /* Data byte order is little. */ \
6023 BFD_ENDIAN_BIG, /* Header byte order is big. */ \
6024 /* object flags */ \
6025 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
6026 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
6027 /* section flags */ \
6028 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6029 UNDER, /* Leading symbol underscore. */ \
6030 '/', /* AR_pad_char. */ \
6031 15, /* AR_max_namelen. */ \
6032 0, /* match priority. */ \
6033 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ \
6035 /* Data conversion functions. */ \
6036 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
6037 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
6038 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
6040 /* Header conversion functions. */ \
6041 bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
6042 bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
6043 bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
6045 { /* bfd_check_format. */ \
6046 _bfd_dummy_target, \
6048 bfd_generic_archive_p, \
6051 { /* bfd_set_format. */ \
6052 _bfd_bool_bfd_false_error, \
6054 _bfd_generic_mkarchive, \
6055 _bfd_bool_bfd_false_error \
6057 { /* bfd_write_contents. */ \
6058 _bfd_bool_bfd_false_error, \
6059 coff_write_object_contents, \
6060 _bfd_write_archive_contents, \
6061 _bfd_bool_bfd_false_error \
6064 BFD_JUMP_TABLE_GENERIC (coff), \
6065 BFD_JUMP_TABLE_COPY (coff), \
6066 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
6067 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
6068 BFD_JUMP_TABLE_SYMBOLS (coff), \
6069 BFD_JUMP_TABLE_RELOCS (coff), \
6070 BFD_JUMP_TABLE_WRITE (coff), \
6071 BFD_JUMP_TABLE_LINK (coff), \
6072 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
6079 #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
6080 const bfd_target VAR = \
6083 bfd_target_coff_flavour, \
6084 BFD_ENDIAN_LITTLE, /* Data byte order is little. */ \
6085 BFD_ENDIAN_LITTLE, /* Header byte order is little. */ \
6086 /* object flags */ \
6087 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
6088 HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
6089 /* section flags */ \
6090 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6091 UNDER, /* Leading symbol underscore. */ \
6092 '/', /* AR_pad_char. */ \
6093 15, /* AR_max_namelen. */ \
6094 0, /* match priority. */ \
6095 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ \
6097 /* Data conversion functions. */ \
6098 bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
6099 bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
6100 bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
6101 /* Header conversion functions. */ \
6102 bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
6103 bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
6104 bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
6106 { /* bfd_check_format. */ \
6107 _bfd_dummy_target, \
6109 bfd_generic_archive_p, \
6112 { /* bfd_set_format. */ \
6113 _bfd_bool_bfd_false_error, \
6115 _bfd_generic_mkarchive, \
6116 _bfd_bool_bfd_false_error \
6118 { /* bfd_write_contents. */ \
6119 _bfd_bool_bfd_false_error, \
6120 coff_write_object_contents, \
6121 _bfd_write_archive_contents, \
6122 _bfd_bool_bfd_false_error \
6125 BFD_JUMP_TABLE_GENERIC (coff), \
6126 BFD_JUMP_TABLE_COPY (coff), \
6127 BFD_JUMP_TABLE_CORE (_bfd_nocore), \
6128 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
6129 BFD_JUMP_TABLE_SYMBOLS (coff), \
6130 BFD_JUMP_TABLE_RELOCS (coff), \
6131 BFD_JUMP_TABLE_WRITE (coff), \
6132 BFD_JUMP_TABLE_LINK (coff), \
6133 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \