]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/libcoff.h
Make coff backend data read-only
[thirdparty/binutils-gdb.git] / bfd / libcoff.h
CommitLineData
07d6d2b8 1/* DO NOT EDIT! -*- buffer-read-only: t -*- This file is automatically
59bc061d 2 generated from "libcoff-in.h" and "coffcode.h".
4eef72c7
AM
3 Run "make headers" in your build bfd/ to regenerate. */
4
252b5132 5/* BFD COFF object file private structure.
d87bef3a 6 Copyright (C) 1990-2023 Free Software Foundation, Inc.
252b5132
RH
7 Written by Cygnus Support.
8
7920ce38 9 This file is part of BFD, the Binary File Descriptor library.
252b5132 10
7920ce38
NC
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
cd123cb7 13 the Free Software Foundation; either version 3 of the License, or
7920ce38 14 (at your option) any later version.
252b5132 15
7920ce38
NC
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
252b5132 20
7920ce38
NC
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
cd123cb7
NC
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
252b5132 25
0b439543
AM
26#ifndef _LIBCOFF_H
27#define _LIBCOFF_H 1
28
252b5132 29#include "bfdlink.h"
f4943d82 30#include "coff-bfd.h"
252b5132 31
55172d69
PA
32#ifdef __cplusplus
33extern "C" {
34#endif
35
7920ce38
NC
36/* Object file tdata; access macros. */
37
38#define coff_data(bfd) ((bfd)->tdata.coff_obj_data)
07d6d2b8 39#define obj_pe(bfd) (coff_data (bfd)->pe)
f717994f 40#define obj_go32(bfd) (coff_data (bfd)->go32)
7920ce38 41#define obj_symbols(bfd) (coff_data (bfd)->symbols)
f717994f 42#define obj_sym_filepos(bfd) (coff_data (bfd)->sym_filepos)
7920ce38
NC
43#define obj_relocbase(bfd) (coff_data (bfd)->relocbase)
44#define obj_raw_syments(bfd) (coff_data (bfd)->raw_syments)
45#define obj_raw_syment_count(bfd) (coff_data (bfd)->raw_syment_count)
46#define obj_convert(bfd) (coff_data (bfd)->conversion_table)
47#define obj_conv_table_size(bfd) (coff_data (bfd)->conv_table_size)
48#define obj_coff_external_syms(bfd) (coff_data (bfd)->external_syms)
49#define obj_coff_keep_syms(bfd) (coff_data (bfd)->keep_syms)
50#define obj_coff_strings(bfd) (coff_data (bfd)->strings)
5a3f568b 51#define obj_coff_strings_len(bfd) (coff_data (bfd)->strings_len)
7920ce38
NC
52#define obj_coff_keep_strings(bfd) (coff_data (bfd)->keep_strings)
53#define obj_coff_sym_hashes(bfd) (coff_data (bfd)->sym_hashes)
d71f672e 54#define obj_coff_strings_written(bfd) (coff_data (bfd)->strings_written)
7920ce38 55#define obj_coff_local_toc_table(bfd) (coff_data (bfd)->local_toc_sym_map)
252b5132
RH
56
57/* `Tdata' information kept for COFF files. */
58
59typedef struct coff_tdata
60{
7920ce38 61 struct coff_symbol_struct *symbols; /* Symtab for input bfd. */
252b5132
RH
62 unsigned int *conversion_table;
63 int conv_table_size;
64 file_ptr sym_filepos;
65
66 struct coff_ptr_struct *raw_syments;
00692651 67 unsigned long raw_syment_count;
252b5132 68
7920ce38 69 /* These are only valid once writing has begun. */
bad1a9f7 70 unsigned long int relocbase;
252b5132
RH
71
72 /* These members communicate important constants about the symbol table
73 to GDB's symbol-reading code. These `constants' unfortunately vary
74 from coff implementation to implementation... */
75 unsigned local_n_btmask;
76 unsigned local_n_btshft;
77 unsigned local_n_tmask;
78 unsigned local_n_tshift;
79 unsigned local_symesz;
80 unsigned local_auxesz;
81 unsigned local_linesz;
82
83 /* The unswapped external symbols. May be NULL. Read by
84 _bfd_coff_get_external_symbols. */
7920ce38 85 void * external_syms;
252b5132
RH
86
87 /* The string table. May be NULL. Read by
88 _bfd_coff_read_string_table. */
89 char *strings;
5a3f568b
NC
90 /* The length of the strings table. For error checking. */
91 bfd_size_type strings_len;
22a95e1a
AM
92
93 /* Set if long section names are supported. A writable copy of the COFF
94 backend flag _bfd_coff_long_section_names. */
95 bool long_section_names;
96
97 /* If this is TRUE, the external_syms may not be freed. */
98 bool keep_syms;
b34976b6 99 /* If this is TRUE, the strings may not be freed. */
0a1b45a2 100 bool keep_strings;
b34976b6 101 /* If this is TRUE, the strings have been written out already. */
0a1b45a2 102 bool strings_written;
252b5132 103
22a95e1a
AM
104 /* Is this a GO32 coff file? */
105 bool go32;
106
7920ce38 107 /* Is this a PE format coff file? */
252b5132 108 int pe;
22a95e1a
AM
109
110 /* Copy of some of the f_flags bits in the COFF filehdr structure,
111 used by ARM code. */
112 flagword flags;
113
252b5132
RH
114 /* Used by the COFF backend linker. */
115 struct coff_link_hash_entry **sym_hashes;
116
7920ce38 117 /* Used by the pe linker for PowerPC. */
252b5132
RH
118 int *local_toc_sym_map;
119
120 struct bfd_link_info *link_info;
121
122 /* Used by coff_find_nearest_line. */
7920ce38 123 void * line_info;
252b5132 124
7920ce38
NC
125 /* A place to stash dwarf2 info for this bfd. */
126 void * dwarf2_find_line_info;
51db3708 127
00692651
ILT
128 /* The timestamp from the COFF file header. */
129 long timestamp;
130
4d095f5b
JJ
131 /* A stub (extra data prepended before the COFF image) and its size.
132 Used by coff-go32-exe, it contains executable data that loads the
133 COFF object into memory. */
134 char * stub;
135 bfd_size_type stub_size;
252b5132
RH
136} coff_data_type;
137
7920ce38 138/* Tdata for pe image files. */
252b5132
RH
139typedef struct pe_tdata
140{
141 coff_data_type coff;
142 struct internal_extra_pe_aouthdr pe_opthdr;
143 int dll;
144 int has_reloc_section;
441f34fa 145 int dont_strip_reloc;
70cf6834 146 int dos_message[16];
00386881
NC
147 /* The timestamp to insert into the output file.
148 If the timestamp is -1 then the current time is used. */
149 int timestamp;
0a1b45a2 150 bool (*in_reloc_p) (bfd *, reloc_howto_type *);
252b5132 151 flagword real_flags;
61e2488c 152
e30d16e9 153 /* Build-id info. */
61e2488c
JT
154 struct
155 {
0a1b45a2 156 bool (*after_write_object_contents) (bfd *);
61e2488c
JT
157 const char *style;
158 asection *sec;
159 } build_id;
252b5132
RH
160} pe_data_type;
161
162#define pe_data(bfd) ((bfd)->tdata.pe_obj_data)
163
164/* Tdata for XCOFF files. */
165
166struct xcoff_tdata
167{
168 /* Basic COFF information. */
169 coff_data_type coff;
170
b34976b6 171 /* TRUE if this is an XCOFF64 file. */
0a1b45a2 172 bool xcoff64;
a2fdf270 173
b34976b6 174 /* TRUE if a large a.out header should be generated. */
0a1b45a2 175 bool full_aouthdr;
252b5132
RH
176
177 /* TOC value. */
178 bfd_vma toc;
179
180 /* Index of section holding TOC. */
181 int sntoc;
182
183 /* Index of section holding entry point. */
184 int snentry;
185
186 /* .text alignment from optional header. */
187 int text_align_power;
188
189 /* .data alignment from optional header. */
190 int data_align_power;
191
192 /* modtype from optional header. */
193 short modtype;
194
195 /* cputype from optional header. */
196 short cputype;
197
198 /* maxdata from optional header. */
f34d8777 199 bfd_vma maxdata;
252b5132
RH
200
201 /* maxstack from optional header. */
f34d8777 202 bfd_vma maxstack;
252b5132
RH
203
204 /* Used by the XCOFF backend linker. */
205 asection **csects;
e450936a 206 long *debug_indices;
3df13c4a 207 unsigned int *lineno_counts;
252b5132
RH
208 unsigned int import_file_id;
209};
210
211#define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data)
212
08da05b0 213/* We take the address of the first element of an asymbol to ensure that the
7920ce38 214 macro is only ever applied to an asymbol. */
252b5132
RH
215#define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
216
252b5132
RH
217/* Tdata for sections in XCOFF files. This is used by the linker. */
218
219struct xcoff_section_tdata
220{
221 /* Used for XCOFF csects created by the linker; points to the real
222 XCOFF section which contains this csect. */
223 asection *enclosing;
224 /* The lineno_count field for the enclosing section, because we are
225 going to clobber it there. */
226 unsigned int lineno_count;
4cc02a02 227 /* The first and last symbol indices for symbols used by this csect. */
252b5132
RH
228 unsigned long first_symndx;
229 unsigned long last_symndx;
230};
231
232/* An accessor macro the xcoff_section_tdata structure. */
233#define xcoff_section_data(abfd, sec) \
234 ((struct xcoff_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
235
8d3ad4e1 236/* Tdata for sections in PE files. */
252b5132
RH
237
238struct pei_section_tdata
239{
240 /* The virtual size of the section. */
241 bfd_size_type virt_size;
8d3ad4e1
ILT
242 /* The PE section flags. */
243 long pe_flags;
252b5132
RH
244};
245
246/* An accessor macro for the pei_section_tdata structure. */
247#define pei_section_data(abfd, sec) \
248 ((struct pei_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
249
250/* COFF linker hash table entries. */
251
252struct coff_link_hash_entry
253{
254 struct bfd_link_hash_entry root;
255
75cfe082
AM
256 /* Symbol index in output file. This is initialized to -1. It is
257 set to -2 if the symbol is used by a reloc. It is set to -3 if
258 this symbol is defined in a discarded section. */
252b5132
RH
259 long indx;
260
261 /* Symbol type. */
262 unsigned short type;
263
264 /* Symbol class. */
96d56e9f 265 unsigned char symbol_class;
252b5132
RH
266
267 /* Number of auxiliary entries. */
268 char numaux;
269
270 /* BFD to take auxiliary entries from. */
271 bfd *auxbfd;
272
273 /* Pointer to array of auxiliary entries, if any. */
274 union internal_auxent *aux;
7fd9c191
ILT
275
276 /* Flag word; legal values follow. */
277 unsigned short coff_link_hash_flags;
278 /* Symbol is a PE section symbol. */
279#define COFF_LINK_HASH_PE_SECTION_SYMBOL (01)
252b5132
RH
280};
281
282/* COFF linker hash table. */
283
284struct coff_link_hash_table
285{
286 struct bfd_link_hash_table root;
287 /* A pointer to information used to link stabs in sections. */
3722b82f 288 struct stab_info stab_info;
252b5132
RH
289};
290
0f088b2a
KT
291struct coff_reloc_cookie
292{
07d6d2b8
AM
293 struct internal_reloc * rels;
294 struct internal_reloc * rel;
295 struct internal_reloc * relend;
296 struct coff_symbol_struct * symbols; /* Symtab for input bfd. */
297 bfd * abfd;
0f088b2a
KT
298 struct coff_link_hash_entry ** sym_hashes;
299};
300
252b5132
RH
301/* Look up an entry in a COFF linker hash table. */
302
303#define coff_link_hash_lookup(table, string, create, copy, follow) \
304 ((struct coff_link_hash_entry *) \
305 bfd_link_hash_lookup (&(table)->root, (string), (create), \
306 (copy), (follow)))
307
308/* Traverse a COFF linker hash table. */
309
310#define coff_link_hash_traverse(table, func, info) \
311 (bfd_link_hash_traverse \
312 (&(table)->root, \
0a1b45a2 313 (bool (*) (struct bfd_link_hash_entry *, void *)) (func), \
252b5132
RH
314 (info)))
315
316/* Get the COFF linker hash table from a link_info structure. */
317
318#define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
319
320/* Functions in coffgen.c. */
cb001c0d 321extern bfd_cleanup coff_object_p
7920ce38 322 (bfd *);
198beae2 323extern struct bfd_section *coff_section_from_bfd_index
7920ce38 324 (bfd *, int);
dc810e39 325extern long coff_get_symtab_upper_bound
7920ce38 326 (bfd *);
6cee3f79 327extern long coff_canonicalize_symtab
7920ce38 328 (bfd *, asymbol **);
dc810e39 329extern int coff_count_linenumbers
7920ce38 330 (bfd *);
0a1b45a2 331extern bool coff_renumber_symbols
7920ce38 332 (bfd *, int *);
dc810e39 333extern void coff_mangle_symbols
7920ce38 334 (bfd *);
0a1b45a2 335extern bool coff_write_symbols
7920ce38 336 (bfd *);
0a1b45a2 337extern bool coff_write_alien_symbol
20bed3bb
JB
338 (bfd *, asymbol *, struct internal_syment *, bfd_vma *,
339 struct bfd_strtab_hash *, bool, asection **, bfd_size_type *);
0a1b45a2 340extern bool coff_write_linenumbers
7920ce38 341 (bfd *);
dc810e39 342extern alent *coff_get_lineno
7920ce38 343 (bfd *, asymbol *);
dc810e39 344extern asymbol *coff_section_symbol
7920ce38 345 (bfd *, char *);
0a1b45a2 346extern bool _bfd_coff_get_external_symbols
7920ce38 347 (bfd *);
dc810e39 348extern const char *_bfd_coff_read_string_table
7920ce38 349 (bfd *);
0a1b45a2 350extern bool _bfd_coff_free_symbols
7920ce38 351 (bfd *);
dc810e39 352extern struct coff_ptr_struct *coff_get_normalized_symtab
7920ce38 353 (bfd *);
dc810e39 354extern long coff_get_reloc_upper_bound
7920ce38 355 (bfd *, sec_ptr);
dc810e39 356extern asymbol *coff_make_empty_symbol
7920ce38 357 (bfd *);
dc810e39 358extern void coff_print_symbol
7920ce38 359 (bfd *, void * filep, asymbol *, bfd_print_symbol_type);
dc810e39 360extern void coff_get_symbol_info
7920ce38 361 (bfd *, asymbol *, symbol_info *ret);
60bb06bc
L
362#define coff_get_symbol_version_string \
363 _bfd_nosymbols_get_symbol_version_string
0a1b45a2 364extern bool _bfd_coff_is_local_label_name
7920ce38 365 (bfd *, const char *);
dc810e39 366extern asymbol *coff_bfd_make_debug_symbol
7920ce38 367 (bfd *, void *, unsigned long);
0a1b45a2 368extern bool coff_find_nearest_line
fb167eb2
AM
369 (bfd *, asymbol **, asection *, bfd_vma,
370 const char **, const char **, unsigned int *, unsigned int *);
6e7a29c7
AM
371#define coff_find_nearest_line_with_alt \
372 _bfd_nosymbols_find_nearest_line_with_alt
9c461f7d 373#define coff_find_line _bfd_nosymbols_find_line
fc28f9aa 374struct dwarf_debug_section;
0a1b45a2 375extern bool coff_find_nearest_line_with_names
fb167eb2
AM
376 (bfd *, asymbol **, asection *, bfd_vma, const char **, const char **,
377 unsigned int *, const struct dwarf_debug_section *);
0a1b45a2 378extern bool coff_find_inliner_info
4ab527b0 379 (bfd *, const char **, const char **, unsigned int *);
dc810e39 380extern int coff_sizeof_headers
a6b96beb 381 (bfd *, struct bfd_link_info *);
0a1b45a2
AM
382extern bool bfd_coff_reloc16_relax_section
383 (bfd *, asection *, struct bfd_link_info *, bool *);
252b5132 384extern bfd_byte *bfd_coff_reloc16_get_relocated_section_contents
7920ce38 385 (bfd *, struct bfd_link_info *, struct bfd_link_order *,
0a1b45a2 386 bfd_byte *, bool, asymbol **);
dc810e39 387extern bfd_vma bfd_coff_reloc16_get_value
7920ce38 388 (arelent *, struct bfd_link_info *, asection *);
dc810e39 389extern void bfd_perform_slip
7920ce38 390 (bfd *, unsigned int, asection *, bfd_vma);
0a1b45a2 391extern bool _bfd_coff_close_and_cleanup
f5d35bb7 392 (bfd *);
252b5132
RH
393
394/* Functions and types in cofflink.c. */
395
ceae3e33 396#define STRING_SIZE_SIZE 4
252b5132
RH
397
398/* We use a hash table to merge identical enum, struct, and union
399 definitions in the linker. */
400
401/* Information we keep for a single element (an enum value, a
402 structure or union field) in the debug merge hash table. */
403
404struct coff_debug_merge_element
405{
406 /* Next element. */
407 struct coff_debug_merge_element *next;
408
409 /* Name. */
410 const char *name;
411
412 /* Type. */
413 unsigned int type;
414
415 /* Symbol index for complex type. */
416 long tagndx;
417};
418
419/* A linked list of debug merge entries for a given name. */
420
421struct coff_debug_merge_type
422{
423 /* Next type with the same name. */
424 struct coff_debug_merge_type *next;
425
426 /* Class of type. */
96d56e9f 427 int type_class;
252b5132
RH
428
429 /* Symbol index where this type is defined. */
430 long indx;
431
432 /* List of elements. */
433 struct coff_debug_merge_element *elements;
434};
435
436/* Information we store in the debug merge hash table. */
437
438struct coff_debug_merge_hash_entry
439{
440 struct bfd_hash_entry root;
441
442 /* A list of types with this name. */
443 struct coff_debug_merge_type *types;
444};
445
446/* The debug merge hash table. */
447
448struct coff_debug_merge_hash_table
449{
450 struct bfd_hash_table root;
451};
452
453/* Initialize a COFF debug merge hash table. */
454
455#define coff_debug_merge_hash_table_init(table) \
66eb6687
AM
456 (bfd_hash_table_init (&(table)->root, _bfd_coff_debug_merge_hash_newfunc, \
457 sizeof (struct coff_debug_merge_hash_entry)))
252b5132
RH
458
459/* Free a COFF debug merge hash table. */
460
461#define coff_debug_merge_hash_table_free(table) \
462 (bfd_hash_table_free (&(table)->root))
463
464/* Look up an entry in a COFF debug merge hash table. */
465
466#define coff_debug_merge_hash_lookup(table, string, create, copy) \
467 ((struct coff_debug_merge_hash_entry *) \
468 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
469
470/* Information we keep for each section in the output file when doing
1049f94e 471 a relocatable link. */
252b5132
RH
472
473struct coff_link_section_info
474{
475 /* The relocs to be output. */
476 struct internal_reloc *relocs;
477 /* For each reloc against a global symbol whose index was not known
478 when the reloc was handled, the global hash table entry. */
479 struct coff_link_hash_entry **rel_hashes;
480};
481
482/* Information that we pass around while doing the final link step. */
483
484struct coff_final_link_info
485{
486 /* General link information. */
487 struct bfd_link_info *info;
488 /* Output BFD. */
489 bfd *output_bfd;
490 /* Used to indicate failure in traversal routine. */
0a1b45a2 491 bool failed;
252b5132
RH
492 /* If doing "task linking" set only during the time when we want the
493 global symbol writer to convert the storage class of defined global
494 symbols from global to static. */
0a1b45a2 495 bool global_to_static;
252b5132
RH
496 /* Hash table for long symbol names. */
497 struct bfd_strtab_hash *strtab;
1049f94e 498 /* When doing a relocatable link, an array of information kept for
252b5132
RH
499 each output section, indexed by the target_index field. */
500 struct coff_link_section_info *section_info;
501 /* Symbol index of last C_FILE symbol (-1 if none). */
502 long last_file_index;
503 /* Contents of last C_FILE symbol. */
504 struct internal_syment last_file;
505 /* Symbol index of first aux entry of last .bf symbol with an empty
506 endndx field (-1 if none). */
507 long last_bf_index;
508 /* Contents of last_bf_index aux entry. */
509 union internal_auxent last_bf;
510 /* Hash table used to merge debug information. */
511 struct coff_debug_merge_hash_table debug_merge;
512 /* Buffer large enough to hold swapped symbols of any input file. */
513 struct internal_syment *internal_syms;
514 /* Buffer large enough to hold sections of symbols of any input file. */
515 asection **sec_ptrs;
516 /* Buffer large enough to hold output indices of symbols of any
517 input file. */
518 long *sym_indices;
519 /* Buffer large enough to hold output symbols for any input file. */
520 bfd_byte *outsyms;
521 /* Buffer large enough to hold external line numbers for any input
522 section. */
523 bfd_byte *linenos;
524 /* Buffer large enough to hold any input section. */
525 bfd_byte *contents;
526 /* Buffer large enough to hold external relocs of any input section. */
527 bfd_byte *external_relocs;
528 /* Buffer large enough to hold swapped relocs of any input section. */
529 struct internal_reloc *internal_relocs;
530};
531
5dccc1dd
ILT
532/* Most COFF variants have no way to record the alignment of a
533 section. This struct is used to set a specific alignment based on
534 the name of the section. */
535
536struct coff_section_alignment_entry
537{
538 /* The section name. */
539 const char *name;
540
541 /* This is either (unsigned int) -1, indicating that the section
542 name must match exactly, or it is the number of letters which
543 must match at the start of the name. */
544 unsigned int comparison_length;
545
546 /* These macros may be used to fill in the first two fields in a
547 structure initialization. */
548#define COFF_SECTION_NAME_EXACT_MATCH(name) (name), ((unsigned int) -1)
549#define COFF_SECTION_NAME_PARTIAL_MATCH(name) (name), (sizeof (name) - 1)
550
551 /* Only use this entry if the default section alignment for this
552 target is at least that much (as a power of two). If this field
553 is COFF_ALIGNMENT_FIELD_EMPTY, it should be ignored. */
554 unsigned int default_alignment_min;
555
556 /* Only use this entry if the default section alignment for this
557 target is no greater than this (as a power of two). If this
558 field is COFF_ALIGNMENT_FIELD_EMPTY, it should be ignored. */
559 unsigned int default_alignment_max;
560
561#define COFF_ALIGNMENT_FIELD_EMPTY ((unsigned int) -1)
562
563 /* The desired alignment for this section (as a power of two). */
564 unsigned int alignment_power;
565};
566
252b5132 567extern struct bfd_hash_entry *_bfd_coff_link_hash_newfunc
7920ce38 568 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
0a1b45a2 569extern bool _bfd_coff_link_hash_table_init
7920ce38
NC
570 (struct coff_link_hash_table *, bfd *,
571 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
572 struct bfd_hash_table *,
66eb6687
AM
573 const char *),
574 unsigned int);
252b5132 575extern struct bfd_link_hash_table *_bfd_coff_link_hash_table_create
7920ce38 576 (bfd *);
252b5132 577extern const char *_bfd_coff_internal_syment_name
7920ce38 578 (bfd *, const struct internal_syment *, char *);
0a1b45a2 579extern bool _bfd_coff_section_already_linked
c77ec726 580 (bfd *, asection *, struct bfd_link_info *);
0a1b45a2 581extern bool _bfd_coff_link_add_symbols
7920ce38 582 (bfd *, struct bfd_link_info *);
0a1b45a2 583extern bool _bfd_coff_final_link
7920ce38 584 (bfd *, struct bfd_link_info *);
252b5132 585extern struct internal_reloc *_bfd_coff_read_internal_relocs
0a1b45a2 586 (bfd *, asection *, bool, bfd_byte *, bool,
7920ce38 587 struct internal_reloc *);
0a1b45a2 588extern bool _bfd_coff_generic_relocate_section
7920ce38
NC
589 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
590 struct internal_reloc *, struct internal_syment *, asection **);
252b5132 591extern struct bfd_hash_entry *_bfd_coff_debug_merge_hash_newfunc
7920ce38 592 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
0a1b45a2 593extern bool _bfd_coff_write_global_sym
7686d77d 594 (struct bfd_hash_entry *, void *);
0a1b45a2 595extern bool _bfd_coff_write_task_globals
7920ce38 596 (struct coff_link_hash_entry *, void *);
0a1b45a2 597extern bool _bfd_coff_link_input_bfd
7920ce38 598 (struct coff_final_link_info *, bfd *);
0a1b45a2 599extern bool _bfd_coff_reloc_link_order
7920ce38
NC
600 (bfd *, struct coff_final_link_info *, asection *,
601 struct bfd_link_order *);
0a1b45a2 602extern bool bfd_coff_gc_sections
0f088b2a 603 (bfd *, struct bfd_link_info *);
cb7f4b29
AM
604extern const char *bfd_coff_group_name
605 (bfd *, const asection *);
252b5132
RH
606
607#define coff_get_section_contents_in_window \
608 _bfd_generic_get_section_contents_in_window
609
f34d8777
L
610/* Functions in xcofflink.c. */
611
dc810e39 612extern long _bfd_xcoff_get_dynamic_symtab_upper_bound
7920ce38 613 (bfd *);
f34d8777 614extern long _bfd_xcoff_canonicalize_dynamic_symtab
7920ce38 615 (bfd *, asymbol **);
dc810e39 616extern long _bfd_xcoff_get_dynamic_reloc_upper_bound
7920ce38 617 (bfd *);
f34d8777 618extern long _bfd_xcoff_canonicalize_dynamic_reloc
7920ce38 619 (bfd *, arelent **, asymbol **);
f34d8777 620extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create
7920ce38 621 (bfd *);
0a1b45a2 622extern bool _bfd_xcoff_bfd_link_add_symbols
7920ce38 623 (bfd *, struct bfd_link_info *);
0a1b45a2 624extern bool _bfd_xcoff_bfd_final_link
7920ce38 625 (bfd *, struct bfd_link_info *);
0a1b45a2 626extern bool _bfd_xcoff_define_common_symbol
3023e3f6 627 (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
0a1b45a2 628extern bool _bfd_ppc_xcoff_relocate_section
7920ce38
NC
629 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
630 struct internal_reloc *, struct internal_syment *, asection **);
e61463e1 631/* Extracted from coffcode.h. */
aaffae57 632
252b5132
RH
633typedef struct coff_ptr_struct
634{
dc810e39 635 /* Remembers the offset from the first symbol in the file for
a5c71af8 636 this symbol. Generated by coff_renumber_symbols. */
dc810e39
AM
637 unsigned int offset;
638
639 /* Should the value of this symbol be renumbered. Used for
640 XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */
641 unsigned int fix_value : 1;
642
643 /* Should the tag field of this symbol be renumbered.
a5c71af8 644 Created by coff_pointerize_aux. */
dc810e39
AM
645 unsigned int fix_tag : 1;
646
647 /* Should the endidx field of this symbol be renumbered.
a5c71af8 648 Created by coff_pointerize_aux. */
dc810e39
AM
649 unsigned int fix_end : 1;
650
651 /* Should the x_csect.x_scnlen field be renumbered.
a5c71af8 652 Created by coff_pointerize_aux. */
dc810e39
AM
653 unsigned int fix_scnlen : 1;
654
655 /* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
656 index into the line number entries. Set by coff_slurp_symbol_table. */
657 unsigned int fix_line : 1;
658
659 /* The container for the symbol structure as read and translated
a5c71af8 660 from the file. */
dc810e39
AM
661 union
662 {
663 union internal_auxent auxent;
664 struct internal_syment syment;
665 } u;
a5c71af8
NC
666
667 /* Selector for the union above. */
0a1b45a2 668 bool is_sym;
e86fc4a5
CC
669
670 /* An extra pointer which can used by format based on COFF (like XCOFF)
671 to provide extra information to their backend. */
672 void *extrap;
252b5132
RH
673} combined_entry_type;
674
675
52b219b5 676/* Each canonical asymbol really looks like this: */
252b5132
RH
677
678typedef struct coff_symbol_struct
679{
dc810e39
AM
680 /* The actual symbol which the rest of BFD works with */
681 asymbol symbol;
252b5132 682
dc810e39
AM
683 /* A pointer to the hidden information for this symbol */
684 combined_entry_type *native;
252b5132 685
dc810e39
AM
686 /* A pointer to the linenumber information for this symbol */
687 struct lineno_cache_entry *lineno;
252b5132 688
dc810e39 689 /* Have the line numbers been relocated yet ? */
0a1b45a2 690 bool done_lineno;
252b5132 691} coff_symbol_type;
52b219b5 692/* COFF symbol classifications. */
5d54c628
ILT
693
694enum coff_symbol_classification
695{
52b219b5 696 /* Global symbol. */
5d54c628 697 COFF_SYMBOL_GLOBAL,
52b219b5 698 /* Common symbol. */
5d54c628 699 COFF_SYMBOL_COMMON,
52b219b5 700 /* Undefined symbol. */
5d54c628 701 COFF_SYMBOL_UNDEFINED,
52b219b5 702 /* Local symbol. */
5d54c628 703 COFF_SYMBOL_LOCAL,
52b219b5 704 /* PE section symbol. */
5d54c628
ILT
705 COFF_SYMBOL_PE_SECTION
706};
707
0f088b2a
KT
708typedef asection * (*coff_gc_mark_hook_fn)
709 (asection *, struct bfd_link_info *, struct internal_reloc *,
710 struct coff_link_hash_entry *, struct internal_syment *);
711
252b5132
RH
712typedef struct
713{
dc810e39 714 void (*_bfd_coff_swap_aux_in)
7920ce38 715 (bfd *, void *, int, int, int, int, void *);
dc810e39
AM
716
717 void (*_bfd_coff_swap_sym_in)
7920ce38 718 (bfd *, void *, void *);
dc810e39
AM
719
720 void (*_bfd_coff_swap_lineno_in)
7920ce38 721 (bfd *, void *, void *);
dc810e39
AM
722
723 unsigned int (*_bfd_coff_swap_aux_out)
7920ce38 724 (bfd *, void *, int, int, int, int, void *);
dc810e39
AM
725
726 unsigned int (*_bfd_coff_swap_sym_out)
7920ce38 727 (bfd *, void *, void *);
dc810e39
AM
728
729 unsigned int (*_bfd_coff_swap_lineno_out)
7920ce38 730 (bfd *, void *, void *);
dc810e39
AM
731
732 unsigned int (*_bfd_coff_swap_reloc_out)
7920ce38 733 (bfd *, void *, void *);
dc810e39
AM
734
735 unsigned int (*_bfd_coff_swap_filehdr_out)
7920ce38 736 (bfd *, void *, void *);
dc810e39
AM
737
738 unsigned int (*_bfd_coff_swap_aouthdr_out)
7920ce38 739 (bfd *, void *, void *);
dc810e39
AM
740
741 unsigned int (*_bfd_coff_swap_scnhdr_out)
7920ce38 742 (bfd *, void *, void *);
dc810e39
AM
743
744 unsigned int _bfd_filhsz;
745 unsigned int _bfd_aoutsz;
746 unsigned int _bfd_scnhsz;
747 unsigned int _bfd_symesz;
748 unsigned int _bfd_auxesz;
749 unsigned int _bfd_relsz;
750 unsigned int _bfd_linesz;
751 unsigned int _bfd_filnmlen;
0a1b45a2 752 bool _bfd_coff_long_filenames;
88183869 753
0a1b45a2
AM
754 bool _bfd_coff_long_section_names;
755 bool (*_bfd_coff_set_long_section_names)
88183869 756 (bfd *, int);
68ffbac6 757
dc810e39 758 unsigned int _bfd_coff_default_section_alignment_power;
0a1b45a2 759 bool _bfd_coff_force_symnames_in_strings;
dc810e39 760 unsigned int _bfd_coff_debug_string_prefix_length;
167ad85b 761 unsigned int _bfd_coff_max_nscns;
dc810e39
AM
762
763 void (*_bfd_coff_swap_filehdr_in)
7920ce38 764 (bfd *, void *, void *);
dc810e39
AM
765
766 void (*_bfd_coff_swap_aouthdr_in)
7920ce38 767 (bfd *, void *, void *);
dc810e39
AM
768
769 void (*_bfd_coff_swap_scnhdr_in)
7920ce38 770 (bfd *, void *, void *);
dc810e39
AM
771
772 void (*_bfd_coff_swap_reloc_in)
7920ce38 773 (bfd *abfd, void *, void *);
dc810e39 774
0a1b45a2 775 bool (*_bfd_coff_bad_format_hook)
7920ce38 776 (bfd *, void *);
dc810e39 777
0a1b45a2 778 bool (*_bfd_coff_set_arch_mach_hook)
7920ce38 779 (bfd *, void *);
dc810e39 780
7920ce38
NC
781 void * (*_bfd_coff_mkobject_hook)
782 (bfd *, void *, void *);
dc810e39 783
0a1b45a2 784 bool (*_bfd_styp_to_sec_flags_hook)
7920ce38 785 (bfd *, void *, const char *, asection *, flagword *);
dc810e39
AM
786
787 void (*_bfd_set_alignment_hook)
7920ce38 788 (bfd *, asection *, void *);
dc810e39 789
0a1b45a2 790 bool (*_bfd_coff_slurp_symbol_table)
7920ce38 791 (bfd *);
dc810e39 792
0a1b45a2 793 bool (*_bfd_coff_symname_in_debug)
7920ce38 794 (bfd *, struct internal_syment *);
dc810e39 795
0a1b45a2 796 bool (*_bfd_coff_pointerize_aux_hook)
7920ce38 797 (bfd *, combined_entry_type *, combined_entry_type *,
07d6d2b8 798 unsigned int, combined_entry_type *);
dc810e39 799
0a1b45a2 800 bool (*_bfd_coff_print_aux)
7920ce38 801 (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
07d6d2b8 802 combined_entry_type *, unsigned int);
dc810e39
AM
803
804 void (*_bfd_coff_reloc16_extra_cases)
7920ce38 805 (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
07d6d2b8 806 bfd_byte *, unsigned int *, unsigned int *);
dc810e39
AM
807
808 int (*_bfd_coff_reloc16_estimate)
7920ce38 809 (bfd *, asection *, arelent *, unsigned int,
07d6d2b8 810 struct bfd_link_info *);
dc810e39
AM
811
812 enum coff_symbol_classification (*_bfd_coff_classify_symbol)
7920ce38 813 (bfd *, struct internal_syment *);
dc810e39 814
0a1b45a2 815 bool (*_bfd_coff_compute_section_file_positions)
7920ce38 816 (bfd *);
dc810e39 817
0a1b45a2 818 bool (*_bfd_coff_start_final_link)
7920ce38 819 (bfd *, struct bfd_link_info *);
dc810e39 820
0a1b45a2 821 bool (*_bfd_coff_relocate_section)
7920ce38 822 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
07d6d2b8 823 struct internal_reloc *, struct internal_syment *, asection **);
dc810e39
AM
824
825 reloc_howto_type *(*_bfd_coff_rtype_to_howto)
7920ce38 826 (bfd *, asection *, struct internal_reloc *,
07d6d2b8 827 struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *);
dc810e39 828
0a1b45a2 829 bool (*_bfd_coff_adjust_symndx)
7920ce38 830 (bfd *, struct bfd_link_info *, bfd *, asection *,
0a1b45a2 831 struct internal_reloc *, bool *);
dc810e39 832
0a1b45a2 833 bool (*_bfd_coff_link_add_one_symbol)
7920ce38 834 (struct bfd_link_info *, bfd *, const char *, flagword,
0a1b45a2 835 asection *, bfd_vma, const char *, bool, bool,
07d6d2b8 836 struct bfd_link_hash_entry **);
dc810e39 837
0a1b45a2 838 bool (*_bfd_coff_link_output_has_begun)
7920ce38 839 (bfd *, struct coff_final_link_info *);
dc810e39 840
0a1b45a2 841 bool (*_bfd_coff_final_link_postscript)
7920ce38 842 (bfd *, struct coff_final_link_info *);
252b5132 843
0a1b45a2 844 bool (*_bfd_coff_print_pdata)
2b5c217d
NC
845 (bfd *, void *);
846
252b5132
RH
847} bfd_coff_backend_data;
848
dc810e39 849#define coff_backend_info(abfd) \
22a95e1a 850 ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data)
252b5132
RH
851
852#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
dc810e39 853 ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
252b5132
RH
854
855#define bfd_coff_swap_sym_in(a,e,i) \
dc810e39 856 ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
252b5132
RH
857
858#define bfd_coff_swap_lineno_in(a,e,i) \
dc810e39 859 ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
252b5132
RH
860
861#define bfd_coff_swap_reloc_out(abfd, i, o) \
dc810e39 862 ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
252b5132
RH
863
864#define bfd_coff_swap_lineno_out(abfd, i, o) \
dc810e39 865 ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
252b5132
RH
866
867#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
dc810e39 868 ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
252b5132
RH
869
870#define bfd_coff_swap_sym_out(abfd, i,o) \
dc810e39 871 ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
252b5132
RH
872
873#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
dc810e39 874 ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
252b5132
RH
875
876#define bfd_coff_swap_filehdr_out(abfd, i,o) \
dc810e39 877 ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
252b5132
RH
878
879#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
dc810e39 880 ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
252b5132
RH
881
882#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
883#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
884#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
885#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
886#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
887#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
888#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
692b7d62 889#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
dc810e39
AM
890#define bfd_coff_long_filenames(abfd) \
891 (coff_backend_info (abfd)->_bfd_coff_long_filenames)
252b5132 892#define bfd_coff_long_section_names(abfd) \
22a95e1a 893 (coff_data (abfd)->long_section_names)
88183869
DK
894#define bfd_coff_set_long_section_names(abfd, enable) \
895 ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
252b5132 896#define bfd_coff_default_section_alignment_power(abfd) \
dc810e39 897 (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
167ad85b
TG
898#define bfd_coff_max_nscns(abfd) \
899 (coff_backend_info (abfd)->_bfd_coff_max_nscns)
900
252b5132 901#define bfd_coff_swap_filehdr_in(abfd, i,o) \
dc810e39 902 ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
252b5132
RH
903
904#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
dc810e39 905 ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
252b5132
RH
906
907#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
dc810e39 908 ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
252b5132
RH
909
910#define bfd_coff_swap_reloc_in(abfd, i, o) \
dc810e39 911 ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
252b5132
RH
912
913#define bfd_coff_bad_format_hook(abfd, filehdr) \
dc810e39 914 ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
252b5132
RH
915
916#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
dc810e39 917 ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
252b5132 918#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
ed781d5d
NC
919 ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
920 (abfd, filehdr, aouthdr))
252b5132 921
7c8ca0e4 922#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
dc810e39
AM
923 ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
924 (abfd, scnhdr, name, section, flags_ptr))
252b5132
RH
925
926#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
dc810e39 927 ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
252b5132
RH
928
929#define bfd_coff_slurp_symbol_table(abfd)\
dc810e39 930 ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
252b5132
RH
931
932#define bfd_coff_symname_in_debug(abfd, sym)\
dc810e39 933 ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
252b5132 934
7f6d05e8 935#define bfd_coff_force_symnames_in_strings(abfd)\
dc810e39 936 (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
7f6d05e8
CP
937
938#define bfd_coff_debug_string_prefix_length(abfd)\
dc810e39 939 (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
7f6d05e8 940
252b5132 941#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
dc810e39
AM
942 ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
943 (abfd, file, base, symbol, aux, indaux))
252b5132 944
ed781d5d
NC
945#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
946 reloc, data, src_ptr, dst_ptr)\
dc810e39
AM
947 ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
948 (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
252b5132
RH
949
950#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
dc810e39
AM
951 ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
952 (abfd, section, reloc, shrink, link_info))
252b5132 953
5d54c628 954#define bfd_coff_classify_symbol(abfd, sym)\
dc810e39
AM
955 ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
956 (abfd, sym))
252b5132
RH
957
958#define bfd_coff_compute_section_file_positions(abfd)\
dc810e39
AM
959 ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
960 (abfd))
252b5132
RH
961
962#define bfd_coff_start_final_link(obfd, info)\
dc810e39
AM
963 ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
964 (obfd, info))
252b5132 965#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
dc810e39
AM
966 ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
967 (obfd, info, ibfd, o, con, rel, isyms, secs))
252b5132 968#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
dc810e39
AM
969 ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
970 (abfd, sec, rel, h, sym, addendp))
252b5132 971#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
dc810e39
AM
972 ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
973 (obfd, info, ibfd, sec, rel, adjustedp))
ed781d5d
NC
974#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
975 value, string, cp, coll, hashp)\
dc810e39
AM
976 ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
977 (info, abfd, name, flags, section, value, string, cp, coll, hashp))
252b5132
RH
978
979#define bfd_coff_link_output_has_begun(a,p) \
7920ce38 980 ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
252b5132 981#define bfd_coff_final_link_postscript(a,p) \
7920ce38 982 ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
252b5132 983
2b5c217d
NC
984#define bfd_coff_have_print_pdata(a) \
985 (coff_backend_info (a)->_bfd_coff_print_pdata)
986#define bfd_coff_print_pdata(a,p) \
987 ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
988
92dd4511
L
989/* Macro: Returns true if the bfd is a PE executable as opposed to a
990 PE object file. */
991#define bfd_pei_p(abfd) \
08dedd66 992 (startswith ((abfd)->xvec->name, "pei-"))
55172d69
PA
993#ifdef __cplusplus
994}
995#endif
0b439543 996#endif