Add target_defaulted to bfd struct. Fix formatting in various places.
[deliverable/binutils-gdb.git] / include / bfd.h
1 /* A -*- C -*- header file for the bfd library */
2
3 /* bfd.h -- The only header file required by users of the bfd library */
4
5 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
6
7 This file is part of BFD, the Binary File Diddler.
8
9 BFD is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 1, or (at your option)
12 any later version.
13
14 BFD is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with BFD; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23 #ifndef __BFD_H_SEEN__
24 #define __BFD_H_SEEN__
25
26 #include "ansidecl.h"
27 #include "obstack.h"
28
29 /* Make it easier to declare prototypes (puts conditional here) */
30 #ifndef PROTO
31 # if __STDC__
32 # define PROTO(type, name, arglist) type name arglist
33 # else
34 # define PROTO(type, name, arglist) type name ()
35 # endif
36 #endif
37
38 #define BFD_VERSION "1.10"
39
40 /* forward declaration */
41 typedef struct _bfd bfd;
42
43 /* General rules: functions which are boolean return true on success
44 and false on failure (unless they're a predicate). -- bfd.doc */
45 /* I'm sure this is going to break something and someone is going to
46 force me to change it. */
47 typedef enum boolean {false, true} boolean;
48
49 /* Try to avoid breaking stuff */
50 typedef long int file_ptr;
51
52 /* Support for different sizes of target format ints and addresses */
53
54 #ifdef HOST_64_BIT
55 typedef HOST_64_BIT rawdata_offset;
56 typedef HOST_64_BIT bfd_vma;
57 typedef HOST_64_BIT bfd_word;
58 typedef HOST_64_BIT bfd_offset;
59 typedef HOST_64_BIT bfd_size_type;
60 typedef HOST_64_BIT symvalue;
61 typedef HOST_64_BIT bfd_64_type;
62 #define fprintf_vma(s,x) \
63 fprintf(s,"%08x%08x", uint64_typeHIGH(x), uint64_typeLOW(x))
64 #define printf_vma(x) \
65 printf( "%08x%08x", uint64_typeHIGH(x), uint64_typeLOW(x))
66 #else
67 typedef struct {int a,b;} bfd_64_type;
68 typedef unsigned long rawdata_offset;
69 typedef unsigned long bfd_vma;
70 typedef unsigned long bfd_offset;
71 typedef unsigned long bfd_word;
72 typedef unsigned long bfd_size;
73 typedef unsigned long symvalue;
74 typedef unsigned long bfd_size_type;
75 #define printf_vma(x) printf( "%08x", x)
76 #define fprintf_vma(s,x) fprintf(s, "%08x", x)
77 #endif
78
79 typedef unsigned int flagword; /* 32 bits of flags */
80 \f
81 /** File formats */
82
83 typedef enum bfd_format {
84 bfd_unknown = 0, /* file format is unknown */
85 bfd_object, /* linker/assember/compiler output */
86 bfd_archive, /* object archive file */
87 bfd_core, /* core dump */
88 bfd_type_end} /* marks the end; don't use it! */
89 bfd_format;
90
91 /* Object file flag values */
92 #define NO_FLAGS 0
93 #define HAS_RELOC 001
94 #define EXEC_P 002
95 #define HAS_LINENO 004
96 #define HAS_DEBUG 010
97 #define HAS_SYMS 020
98 #define HAS_LOCALS 040
99 #define DYNAMIC 0100
100 #define WP_TEXT 0200
101 #define D_PAGED 0400
102
103 /* This enum gives the object file's CPU architecture, in a global sense.
104 E.g. what processor family does it belong to? There is another field,
105 which indicates what processor within the family is in use. */
106 enum bfd_architecture {
107 bfd_arch_unknown, /* File arch not known */
108 bfd_arch_obscure, /* File arch known, not one of these */
109 bfd_arch_m68k, /* Motorola 68xxx */
110 bfd_arch_vax, /* DEC Vax */
111 bfd_arch_i960, /* Intel 960 */
112
113 /* The order of the following is important.
114 * A lower number indicates a machine type
115 * that only accepts a subset of the
116 * instructions available to machines with
117 * higher numbers.
118 *
119 * The exception is the "ca", which is
120 * incompatible with all other machines except
121 * "core".
122 */
123 #define bfd_mach_i960_core 1
124 #define bfd_mach_i960_ka_sa 2
125 #define bfd_mach_i960_kb_sb 3
126 #define bfd_mach_i960_mc 4
127 #define bfd_mach_i960_xa 5
128 #define bfd_mach_i960_ca 6
129
130 bfd_arch_a29k, /* AMD 29000 */
131 bfd_arch_sparc, /* Sun (SPARC International) SPARC */
132 bfd_arch_mips, /* MIPS Rxxxx */
133 bfd_arch_i386, /* Intel 386 */
134 bfd_arch_ns32k, /* National Semiconductor 32xxx */
135 bfd_arch_tahoe, /* CCI/Harris Tahoe */
136 bfd_arch_i860, /* Intel 860 */
137 bfd_arch_romp, /* IBM ROMP RS/6000 */
138 bfd_arch_alliant, /* Alliant */
139 bfd_arch_convex, /* Convex */
140 bfd_arch_m88k, /* Motorola 88xxx */
141 bfd_arch_pyramid, /* Pyramid Technology */
142 bfd_arch_h8_300, /* Hitachi H8/300 */
143 bfd_arch_last
144 };
145 \f
146 /* symbols and relocation */
147
148 typedef unsigned long symindex;
149
150 #define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
151
152 typedef enum {bfd_symclass_unknown = 0,
153 bfd_symclass_fcommon, /* fortran common symbols */
154 bfd_symclass_global, /* global symbol, what a surprise */
155 bfd_symclass_debugger, /* some debugger symbol */
156 bfd_symclass_undefined /* none known */
157 } symclass;
158
159
160 typedef int symtype; /* Who knows, yet? */
161
162 /* Symbol cache classifications: (Bfd-Symbol-Flag_FOOBAR) */
163 #define BSF_NO_FLAGS 0x00
164 #define BSF_LOCAL 0x01 /* bfd_symclass_unknown */
165 #define BSF_GLOBAL 0x02 /* bfd_symclass_global */
166 #define BSF_IMPORT 0x04
167 #define BSF_EXPORT 0x08
168 #define BSF_UNDEFINED 0x10 /* bfd_symclass_undefined */
169 #define BSF_FORT_COMM 0x20 /* bfd_symclass_fcommon */
170 #define BSF_DEBUGGING 0x40 /* bfd_symclass_debugger */
171 #define BSF_ABSOLUTE 0x80
172 #define BSF_KEEP 0x10000
173 #define BSF_WARNING 0x20000
174 #define BSF_KEEP_G 0x80000
175 #define BSF_WEAK 0x100000
176 #define BSF_CTOR 0x200000 /* Symbol is a con/destructor */
177 #define BSF_FAKE 0x400000 /* Symbol doesn't really exist */
178 #define BSF_OLD_COMMON 0x800000 /* Symbol used to be common,
179 but now is allocated */
180
181 /* If symbol is fort_comm, then value is size, and this is the contents */
182 #define BFD_FORT_COMM_DEFAULT_VALUE 0
183
184 /* in some files the type of a symbol sometimes alters its location
185 in an output file - ie in coff a ISFCN symbol which is also C_EXT
186 symbol appears where it was declared and not at the end of a section.
187 This bit is set by the target bfd part to convey this information. */
188 #define BSF_NOT_AT_END 0x40000
189
190
191 /* general purpose part of a symbol;
192 target specific parts will be found in libcoff.h, liba.out.h etc */
193 typedef struct symbol_cache_entry
194 {
195 struct _bfd *the_bfd; /* Just a way to find out host type */
196 CONST char *name;
197 symvalue value;
198 flagword flags;
199 struct sec *section;
200 PTR udata; /* Target-specific stuff */
201 } asymbol;
202
203 #define bfd_get_section(x) ((x)->section)
204 #define bfd_get_output_section(x) ((x)->section->output_section)
205 #define bfd_set_section(x,y) ((x)->section) = (y)
206 #define bfd_asymbol_base(x) ((x)->section?((x)->section->vma):0)
207 #define bfd_asymbol_value(x) (bfd_asymbol_base(x) + x->value)
208 #define bfd_asymbol_name(x) ((x)->name)
209
210 /* This is a type pun with struct ranlib on purpose! */
211 typedef struct carsym {
212 char *name;
213 file_ptr file_offset; /* look here to find the file */
214 } carsym; /* to make these you call a carsymogen */
215
216 /* Relocation stuff */
217
218 /* Either: sym will point to a symbol and isextern will be 0, *OR*
219 sym will be NULL and isextern will be a symbol type (eg N_TEXT)
220 which means the location should be relocated relative to the
221 segment origin. This is because we won't necessarily have a symbol
222 which is guaranteed to point to the segment origin. */
223
224 typedef enum bfd_reloc_status {
225 bfd_reloc_ok,
226 bfd_reloc_overflow,
227 bfd_reloc_outofrange,
228 bfd_reloc_continue,
229 bfd_reloc_notsupported,
230 bfd_reloc_other,
231 bfd_reloc_undefined,
232 bfd_reloc_dangerous}
233 bfd_reloc_status_enum_type;
234
235 typedef CONST struct rint
236 {
237 unsigned int type;
238 unsigned int rightshift;
239 unsigned int size;
240 unsigned int bitsize;
241 boolean pc_relative;
242 unsigned int bitpos;
243
244 boolean absolute;
245 boolean complain_on_overflow;
246 bfd_reloc_status_enum_type (*special_function)();
247 char *name;
248 boolean partial_inplace;
249 /* Two mask fields,
250 the src_mask is used to select what parts of the read in data are to
251 be used in the relocation sum. Eg, if this was an 8 bit bit of data
252 which we read and relocated, this would be 0x000000ff. When we have
253 relocs which have an addend, such as sun4 extended relocs, the value
254 in the offset part of a relocating field is garbage so we never use
255 it. In this case the mask would be 0x00000000.
256
257 The dst_mask is what parts of the instruction are replaced into the
258 instruction. In most cases src_mask == dst_mask, except in the above
259 special case, where dst_mask would be 0x000000ff, and src_mask would
260 be 0x00000000.
261 */
262 bfd_word src_mask; /* What things to take from the source */
263 bfd_word dst_mask; /* What things to put into the dest */
264
265 /* Does a pc rel offset already have the offset of the jump from the
266 beginnining of the module in place - eg on the sun3, a pcrel
267 instruction always has a negative number in place, containing the
268 displacement from the beginning of the module. 88k bcs has a zero
269 in there, so you have to work out the offset yourself. */
270 boolean pcrel_offset;
271 } reloc_howto_type;
272
273 #define HOWTO(CODE, RT,SIZE,BITSIZE, PCREL, BITPOS, ABS, OVERFLOW, SF, NAME, INPLACE, MASKSRC, MASKDST, PCRELDONE) \
274 {(unsigned)CODE,RT,SIZE,BITSIZE, PCREL, BITPOS,ABS,OVERFLOW,SF,NAME,INPLACE,MASKSRC,MASKDST,PCRELDONE}
275
276 typedef unsigned char bfd_byte;
277
278 typedef struct reloc_cache_entry
279 {
280 /* A pointer into the canonicalized table for the symbol */
281 asymbol **sym_ptr_ptr;
282
283 rawdata_offset address; /* offset in section */
284 bfd_vma addend; /* addend for relocation value */
285 struct sec *section; /* if sym is null this is the section */
286 reloc_howto_type *howto;
287
288 } arelent;
289
290 typedef struct relent_chain {
291 arelent relent;
292 struct relent_chain *next;
293 } arelent_chain;
294
295 /* Used in generating armaps. Perhaps just a forward definition would do? */
296 struct orl { /* output ranlib */
297 char **name; /* symbol name */
298 file_ptr pos; /* element number or file position */
299 int namidx; /* index into string table */
300 };
301
302 \f
303
304 /* Linenumber stuff */
305 typedef struct lineno_cache_entry {
306 unsigned int line_number; /* Linenumber from start of function*/
307 union {
308 asymbol *sym; /* Function name */
309 unsigned long offset; /* Offset into section */
310 } u;
311 } alent;
312 \f
313 /* object and core file sections */
314
315 /* Section flag definitions */
316 #define SEC_NO_FLAGS 000
317 #define SEC_ALLOC 001
318 #define SEC_LOAD 002
319 #define SEC_RELOC 004
320 #define SEC_BALIGN 010
321 #define SEC_READONLY 020
322 #define SEC_CODE 040
323 #define SEC_DATA 0100
324 #define SEC_ROM 0200
325 #define SEC_CONSTRUCTOR 0400
326 #define SEC_HAS_CONTENTS (0x200)
327
328 typedef struct sec
329 {
330 CONST char *name;
331 struct sec *next;
332 flagword flags;
333
334 bfd_vma vma;
335 bfd_size_type size;
336
337 /* The output_offset is the indent into the output section of
338 this section. If this is the first section to go into
339 an output section, this value will be 0... */
340 bfd_vma output_offset;
341 struct sec *output_section;
342 unsigned int alignment_power; /* eg 4 aligns to 2^4*/
343
344 arelent *relocation; /* for input files */
345 arelent **orelocation; /* for output files */
346
347 unsigned reloc_count;
348 file_ptr filepos; /* File position of section data */
349 file_ptr rel_filepos; /* File position of relocation info */
350 file_ptr line_filepos;
351 PTR *userdata;
352 struct lang_output_section *otheruserdata;
353 int index; /* Which section is it 0..nth */
354 alent *lineno;
355 unsigned int lineno_count;
356
357 /* When a section is being output, this value changes as more
358 linenumbers are written out */
359 file_ptr moving_line_filepos;
360
361 /* what the section number is in the target world */
362 unsigned int target_index;
363
364 PTR used_by_bfd;
365
366 /* If this is a constructor section then here is a list of relents */
367 arelent_chain *constructor_chain;
368 } asection;
369
370 #define align_power(addr, align) \
371 ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
372
373 typedef struct sec *sec_ptr;
374
375 #define bfd_section_name(bfd, ptr) ((ptr)->name)
376 #define bfd_section_size(bfd, ptr) ((ptr)->size)
377 #define bfd_section_vma(bfd, ptr) ((ptr)->vma)
378 #define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
379 #define bfd_get_section_flags(bfd, ptr) ((ptr)->flags)
380 #define bfd_get_section_userdata(bfd, ptr) ((ptr)->userdata)
381
382 #define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (val)), true)
383 #define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),true)
384 #define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),true)
385
386 typedef struct stat stat_type;
387 \f
388 /** Error handling */
389
390 typedef enum {no_error = 0, system_call_error, invalid_target,
391 wrong_format, invalid_operation, no_memory,
392 no_symbols, no_relocation_info,
393 no_more_archived_files, malformed_archive,
394 symbol_not_found, file_not_recognized,
395 file_ambiguously_recognized, no_contents,
396 bfd_error_nonrepresentable_section,
397 invalid_error_code} bfd_ec;
398
399 extern bfd_ec bfd_error;
400
401 typedef struct bfd_error_vector {
402 PROTO(void,(* nonrepresentable_section ),(CONST bfd *CONST abfd,
403 CONST char *CONST name));
404 } bfd_error_vector_type;
405
406 PROTO (char *, bfd_errmsg, ());
407 PROTO (void, bfd_perror, (CONST char *message));
408 \f
409
410 typedef enum bfd_print_symbol
411 {
412 bfd_print_symbol_name_enum,
413 bfd_print_symbol_type_enum,
414 bfd_print_symbol_all_enum
415 } bfd_print_symbol_enum_type;
416
417 \f
418 /* The BFD target structure.
419
420 This structure is how to find out everything BFD knows about a target.
421 It includes things like its byte order, name, what routines to call
422 to do various operations, etc.
423
424 Every BFD points to a target structure with its "xvec" member. */
425
426 /* Shortcut for declaring fields which are prototyped function pointers,
427 while avoiding anguish on compilers that don't support protos. */
428
429 #define SDEF(ret, name, arglist) PROTO(ret,(*name),arglist)
430 #define SDEF_FMT(ret, name, arglist) PROTO(ret,(*name[bfd_type_end]),arglist)
431
432 /* These macros are used to dispatch to functions through the bfd_target
433 vector. They are used in a number of macros further down in bfd.h,
434 and are also used when calling various routines by hand inside the
435 bfd implementation. The "arglist" argument must be parenthesized;
436 it contains all the arguments to the called function. */
437
438 #define BFD_SEND(bfd, message, arglist) ((*((bfd)->xvec->message)) arglist)
439 /* For operations which index on the bfd format */
440 #define BFD_SEND_FMT(bfd, message, arglist) \
441 (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
442
443 /* This is the struct which defines the type of BFD this is. The
444 "xvec" member of the struct bfd itself points here. Each module
445 that implements access to a different target under BFD, defines
446 one of these. */
447
448 /* FIXME, these names should be rationalised with the names of the entry points
449 which call them. Too bad we can't have one macro to define them both! */
450 typedef struct bfd_target
451 {
452 /* identifies the kind of target, eg SunOS4, Ultrix, etc */
453 char *name;
454
455 /* This is bogus. Anything that can be told from the "flavour"
456 by some user program should be an independent attribute that can
457 be queried instead. FIXME. -- gnu@cygnus.com */
458 enum target_flavour_enum {
459 bfd_target_aout_flavour_enum,
460 bfd_target_coff_flavour_enum,
461 bfd_target_ieee_flavour_enum,
462 bfd_target_oasys_flavour_enum,
463 bfd_target_srec_flavour_enum} flavour;
464
465 boolean byteorder_big_p; /* Order of bytes in data sections */
466 boolean header_byteorder_big_p; /* Order of bytes in header */
467
468 flagword object_flags; /* these are the ones that may be set */
469 flagword section_flags; /* ditto */
470
471 char ar_pad_char; /* filenames in archives padded w/this char */
472 unsigned short ar_max_namelen; /* this could be a char too! */
473
474 /* Byte swapping for data */
475 /* Note that these don't take bfd as first arg. Certain other handlers
476 could do the same. */
477 SDEF (bfd_64_type, bfd_getx64, (bfd_byte *));
478 SDEF (void, bfd_putx64, (bfd_64_type, bfd_byte *));
479 SDEF (unsigned int, bfd_getx32, (bfd_byte *));
480 SDEF (void, bfd_putx32, (unsigned long, bfd_byte *));
481 SDEF (unsigned int, bfd_getx16, (bfd_byte *));
482 SDEF (void, bfd_putx16, (int, bfd_byte *));
483
484 /* Byte swapping for headers */
485 SDEF (bfd_64_type, bfd_h_getx64, (bfd_byte *));
486 SDEF (void, bfd_h_putx64, (bfd_64_type, bfd_byte *));
487 SDEF (unsigned int, bfd_h_getx32, (bfd_byte *));
488 SDEF (void, bfd_h_putx32, (unsigned long, bfd_byte *));
489 SDEF (unsigned int, bfd_h_getx16, (bfd_byte *));
490 SDEF (void, bfd_h_putx16, (int, bfd_byte *));
491
492 /* Format-dependent */
493 /* Check the format of a file being read. Return bfd_target * or zero. */
494 SDEF_FMT (struct bfd_target *, _bfd_check_format, (bfd *));
495 /* Set the format of a file being written. */
496 SDEF_FMT (boolean, _bfd_set_format, (bfd *));
497 /* Write cached information into a file being written, at bfd_close. */
498 SDEF_FMT (boolean, _bfd_write_contents, (bfd *));
499
500 /* All these are defined in JUMP_TABLE */
501 /* Core files */
502 SDEF (char *, _core_file_failing_command, (bfd *));
503 SDEF (int, _core_file_failing_signal, (bfd *));
504 SDEF (boolean, _core_file_matches_executable_p, (bfd *, bfd *));
505
506 /* Archives */
507 SDEF (boolean, _bfd_slurp_armap, (bfd *));
508 SDEF (boolean, _bfd_slurp_extended_name_table, (bfd *));
509 SDEF (void, _bfd_truncate_arname, (bfd *, CONST char *, char *));
510 SDEF (boolean, write_armap, (bfd *arch, unsigned int elength,
511 struct orl *map, int orl_count, int
512 stridx));
513
514 /* All the standard stuff */
515 SDEF (boolean, _close_and_cleanup, (bfd *)); /* free any allocated data */
516 SDEF (boolean, _bfd_set_section_contents, (bfd *, sec_ptr, PTR,
517 file_ptr, bfd_size_type));
518 SDEF (boolean, _bfd_get_section_contents, (bfd *, sec_ptr, PTR,
519 file_ptr, bfd_size_type));
520 SDEF (boolean, _new_section_hook, (bfd *, sec_ptr));
521
522 /* Symbols and relocation */
523 SDEF (unsigned int, _get_symtab_upper_bound, (bfd *));
524 SDEF (unsigned int, _bfd_canonicalize_symtab, (bfd *, asymbol **));
525 SDEF (unsigned int, _get_reloc_upper_bound, (bfd *, sec_ptr));
526 SDEF (unsigned int, _bfd_canonicalize_reloc, (bfd *, sec_ptr, arelent **,
527 asymbol**));
528
529 /* FIXME: For steve -- clean up later */
530 SDEF (asymbol *, _bfd_make_empty_symbol, (bfd *));
531 SDEF (void, _bfd_print_symbol, (bfd *, PTR, asymbol *,
532 bfd_print_symbol_enum_type));
533 SDEF (alent *, _get_lineno, (bfd *, asymbol *));
534
535 SDEF (boolean, _bfd_set_arch_mach, (bfd *, enum bfd_architecture,
536 unsigned long));
537
538 SDEF (bfd *, openr_next_archived_file, (bfd *arch, bfd *prev));
539 SDEF (boolean, _bfd_find_nearest_line,
540 (bfd *abfd, asection *section, asymbol **symbols,bfd_vma offset,
541 CONST char **file, CONST char **func, unsigned int *line));
542 SDEF (int, _bfd_stat_arch_elt, (bfd *, struct stat *));
543
544 SDEF (int, _bfd_sizeof_headers, (bfd *, boolean));
545 } bfd_target;
546 \f
547 /* The code that implements targets can initialize a jump table with this
548 macro. It must name all its routines the same way (a prefix plus
549 the standard routine suffix), or it must #define the routines that
550 are not so named, before calling JUMP_TABLE in the initializer. */
551
552 /* Semi-portable string concatenation in cpp */
553 #ifndef CAT
554 #ifdef __STDC__
555 #define CAT(a,b) a##b
556 #else
557 #define CAT(a,b) a/**/b
558 #endif
559 #endif
560
561 #define JUMP_TABLE(NAME)\
562 CAT(NAME,_core_file_failing_command),\
563 CAT(NAME,_core_file_failing_signal),\
564 CAT(NAME,_core_file_matches_executable_p),\
565 CAT(NAME,_slurp_armap),\
566 CAT(NAME,_slurp_extended_name_table),\
567 CAT(NAME,_truncate_arname),\
568 CAT(NAME,_write_armap),\
569 CAT(NAME,_close_and_cleanup), \
570 CAT(NAME,_set_section_contents),\
571 CAT(NAME,_get_section_contents),\
572 CAT(NAME,_new_section_hook),\
573 CAT(NAME,_get_symtab_upper_bound),\
574 CAT(NAME,_get_symtab),\
575 CAT(NAME,_get_reloc_upper_bound),\
576 CAT(NAME,_canonicalize_reloc),\
577 CAT(NAME,_make_empty_symbol),\
578 CAT(NAME,_print_symbol),\
579 CAT(NAME,_get_lineno),\
580 CAT(NAME,_set_arch_mach),\
581 CAT(NAME,_openr_next_archived_file),\
582 CAT(NAME,_find_nearest_line),\
583 CAT(NAME,_generic_stat_arch_elt),\
584 CAT(NAME,_sizeof_headers)
585 \f
586 /* User program access to BFD facilities */
587
588 extern CONST short _bfd_host_big_endian;
589 #define HOST_BYTE_ORDER_BIG_P (*(char *)&_bfd_host_big_endian)
590
591 /* The bfd itself */
592
593 /* Cast from const char * to char * so that caller can assign to
594 a char * without a warning. */
595 #define bfd_get_filename(abfd) ((char *) (abfd)->filename)
596 #define bfd_get_format(abfd) ((abfd)->format)
597 #define bfd_get_target(abfd) ((abfd)->xvec->name)
598 #define bfd_get_file_flags(abfd) ((abfd)->flags)
599 #define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
600 #define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
601 #define bfd_my_archive(abfd) ((abfd)->my_archive);
602 #define bfd_has_map(abfd) ((abfd)->has_armap)
603 #define bfd_header_twiddle_required(abfd) \
604 ((((abfd)->xvec->header_byteorder_big_p) \
605 != (boolean)HOST_BYTE_ORDER_BIG_P) ? true:false)
606
607 #define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
608 #define bfd_usrdata(abfd) ((abfd)->usrdata)
609
610 #define bfd_get_start_address(abfd) ((abfd)->start_address)
611 #define bfd_get_symcount(abfd) ((abfd)->symcount)
612 #define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
613 #define bfd_count_sections(abfd) ((abfd)->section_count)
614 #define bfd_get_architecture(abfd) ((abfd)->obj_arch)
615 #define bfd_get_machine(abfd) ((abfd)->obj_machine)
616
617 /* Finally! The BFD struct itself. This contains the major data about
618 the file, and contains pointers to the rest of the data.
619
620 To avoid dragging too many header files into every file that
621 includes bfd.h, IOSTREAM has been declared as a "char *", and MTIME
622 as a "long". Their correct types, to which they are cast when used,
623 are "FILE *" and "time_t". */
624
625 struct _bfd
626 {
627 CONST char *filename; /* could be null; filename user opened with */
628 bfd_target *xvec; /* operation jump table */
629 char *iostream; /* stdio FILE *, unless an archive element */
630
631 boolean cacheable; /* iostream can be closed if desired */
632 boolean target_defaulted; /* Target type was default, not specific,
633 so we can try all the targets if needed. */
634 struct _bfd *lru_prev; /* Used for file caching */
635 struct _bfd *lru_next; /* Used for file caching */
636 file_ptr where; /* Where the file was when closed */
637 boolean opened_once;
638 boolean mtime_set; /* Flag indicating mtime is available */
639 long mtime; /* File modified time */
640 int ifd; /* for output files, channel we locked. */
641 bfd_format format;
642 enum bfd_direction {no_direction = 0,
643 read_direction = 1,
644 write_direction = 2,
645 both_direction = 3} direction;
646
647 flagword flags; /* format_specific */
648
649 /* Currently my_archive is tested before adding origin to anything. I
650 believe that this can become always an add of origin, with origin set
651 to 0 for non archive files. FIXME-soon. */
652 file_ptr origin; /* for archive contents */
653 boolean output_has_begun; /* cf bfd_set_section_size */
654 asection *sections; /* Pointer to linked list of sections */
655 unsigned int section_count; /* The number of sections */
656
657 /* Some object file stuff */
658 bfd_vma start_address; /* for object files only, of course */
659 unsigned int symcount; /* used for input and output */
660 asymbol **outsymbols; /* symtab for output bfd */
661 enum bfd_architecture obj_arch; /* Architecture of object machine, eg m68k */
662 unsigned long obj_machine; /* Particular machine within arch, e.g. 68010 */
663
664 /* Archive stuff. strictly speaking we don't need all three bfd* vars,
665 but doing so would allow recursive archives! */
666 PTR arelt_data; /* needed if this came from an archive */
667 struct _bfd *my_archive; /* if this is an archive element */
668 struct _bfd *next; /* output chain pointer */
669 struct _bfd *archive_head; /* for output archive */
670 boolean has_armap; /* if an arch; has it an armap? */
671
672 PTR tdata; /* target-specific storage */
673 PTR usrdata; /* application-specific storage */
674
675 /* Should probably be enabled here always, so that library may be changed
676 to switch this on and off, while user code may remain unchanged */
677 #ifdef BFD_LOCKS
678 struct flock *lock;
679 char *actual_name; /* for output files, name given to open() */
680 #endif
681
682 /* Where all the allocated stuff under this BFD goes */
683 struct obstack memory;
684 };
685 \f
686 /* The various callable routines */
687 PROTO (bfd_size_type, bfd_alloc_size,(bfd *abfd));
688 PROTO (char *, bfd_printable_arch_mach,(enum bfd_architecture, unsigned long));
689 PROTO (char *, bfd_format_string, (bfd_format format));
690
691 PROTO (char**, bfd_target_list, ());
692 PROTO (bfd *, bfd_openr, (CONST char *filename, CONST char *target));
693 PROTO (bfd *, bfd_fdopenr,(CONST char *filename, CONST char *target, int fd));
694 PROTO (bfd *, bfd_openw, (CONST char *filename, CONST char *target));
695 PROTO (bfd *, bfd_create, (CONST char *filename, CONST bfd *abfd));
696 PROTO (boolean, bfd_close, (bfd *abfd));
697 PROTO (long, bfd_get_mtime, (bfd *abfd));
698 PROTO (bfd *, bfd_openr_next_archived_file, (bfd *obfd, bfd *last_file));
699 PROTO (boolean, bfd_set_archive_head, (bfd *output_archive, bfd *new_head));
700 PROTO (boolean, bfd_check_format, (bfd *abfd, bfd_format format));
701 PROTO (boolean, bfd_set_format, (bfd *abfd, bfd_format format));
702 PROTO (char *, bfd_core_file_failing_command, (bfd *abfd));
703 PROTO (int, bfd_core_file_failing_signal, (bfd *abfd));
704 PROTO (boolean, core_file_matches_executable_p, (bfd *core_bfd, bfd *exec_bfd));
705 PROTO (sec_ptr, bfd_get_section_by_name, (bfd *abfd, CONST char *name));
706 PROTO (void, bfd_map_over_sections, (bfd *abfd, void (*operation)(),
707 PTR user_storage));
708 PROTO (sec_ptr, bfd_make_section, (bfd *abfd, CONST char *CONST name));
709 PROTO (boolean, bfd_set_section_flags, (bfd *abfd, sec_ptr section,
710 flagword flags));
711 PROTO (boolean, bfd_set_file_flags, (bfd *abfd, flagword flags));
712 PROTO (boolean, bfd_arch_compatible, (bfd *abfd, bfd *bbfd,
713 enum bfd_architecture *res_arch,
714 unsigned long *res_machine));
715
716 PROTO (boolean, bfd_set_section_size, (bfd *abfd, sec_ptr ptr,
717 unsigned long val));
718 PROTO (boolean, bfd_get_section_contents, (bfd *abfd, sec_ptr section,
719 PTR location, file_ptr offset,
720 bfd_size_type count));
721 PROTO (boolean, bfd_set_section_contents, (bfd *abfd, sec_ptr section,
722 PTR location, file_ptr offset,
723 bfd_size_type count));
724
725 PROTO (unsigned long, bfd_get_next_mapent, (bfd *abfd, symindex prev,
726 carsym **entry));
727 PROTO (bfd *, bfd_get_elt_at_index, (bfd *abfd, int index));
728 PROTO (boolean, bfd_set_symtab, (bfd *abfd, asymbol **location,
729 unsigned int symcount));
730 PROTO (unsigned int, get_reloc_upper_bound, (bfd *abfd, sec_ptr asect));
731 PROTO (unsigned int, bfd_canonicalize_reloc, (bfd *abfd, sec_ptr asect,
732 arelent **location,
733 asymbol **canon));
734 PROTO (void, bfd_set_reloc, (bfd *abfd, sec_ptr asect, arelent **location,
735 unsigned int count));
736 PROTO (boolean, bfd_set_start_address, (bfd *,bfd_vma));
737
738 PROTO (void, bfd_print_symbol_vandf, (PTR, asymbol *));
739 PROTO (bfd_reloc_status_enum_type, bfd_perform_relocation,
740 (bfd *, arelent*, PTR, asection *, bfd*));
741
742 PROTO (bfd_vma, bfd_log2, (bfd_vma));
743 #define bfd_symbol_same_target(abfd, symbol) \
744 ( ( ((symbol)->the_bfd->xvec) == (abfd)->xvec) ? true:false)
745
746 PROTO(boolean, bfd_scan_arch_mach,(CONST char *, enum bfd_architecture *,
747 unsigned long *));
748
749 /* For speed and simplicity, we turn calls to these interface routines
750 directly into jumps through the transfer vector. */
751
752 #define bfd_set_arch_mach(abfd, arch, mach) \
753 BFD_SEND (abfd, _bfd_set_arch_mach, (abfd, arch, mach))
754
755 #define bfd_sizeof_headers(abfd, reloc) \
756 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
757
758
759 #define get_symtab_upper_bound(abfd) \
760 BFD_SEND (abfd, _get_symtab_upper_bound, (abfd))
761
762 #define bfd_canonicalize_symtab(abfd, location) \
763 BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
764
765
766 #define bfd_make_empty_symbol(abfd) \
767 BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
768
769 #define bfd_print_symbol(abfd, file, symbol, how) \
770 BFD_SEND (abfd, _bfd_print_symbol, (abfd, file, symbol, how))
771
772 #define bfd_get_lineno(abfd, symbol) \
773 BFD_SEND (abfd, _get_lineno, (abfd, symbol))
774
775 #define bfd_stat_arch_elt(abfd, buf) \
776 BFD_SEND (abfd, _bfd_stat_arch_elt, (abfd, buf))
777
778 #define bfd_find_nearest_line(abfd, section, symbols, offset, filename_ptr, func, line_ptr) \
779 BFD_SEND (abfd, _bfd_find_nearest_line, \
780 (abfd, section,symbols, offset, filename_ptr, func, line_ptr))
781 \f
782 /* Some byte-swapping i/o operations */
783 #define LONGLONG_SIZE 8
784 #define LONG_SIZE 4
785 #define SHORT_SIZE 2
786 #define BYTE_SIZE 1
787
788 #define bfd_put_8(abfd, val, ptr) (*((char *)ptr) = (char)val)
789 #define bfd_get_8(abfd, ptr) (*((char *)ptr))
790
791 #define bfd_put_32(abfd, val, ptr) BFD_SEND(abfd, bfd_putx32, (val,ptr))
792 #define bfd_get_32(abfd, ptr) BFD_SEND(abfd, bfd_getx32, (ptr))
793
794 #define bfd_put_64(abfd, val, ptr) BFD_SEND(abfd, bfd_putx64, (val,ptr))
795 #define bfd_get_64(abfd, ptr) BFD_SEND(abfd, bfd_getx64, (ptr))
796
797 #define bfd_put_16(abfd, val, ptr) BFD_SEND(abfd, bfd_putx16, (val,ptr))
798 #define bfd_get_16(abfd, ptr) BFD_SEND(abfd, bfd_getx16, (ptr))
799
800 #define bfd_h_put_8(abfd, val, ptr) bfd_put_8 (abfd, val, ptr)
801 #define bfd_h_get_8(abfd, ptr) bfd_get_8 (abfd, ptr)
802
803 #define bfd_h_put_32(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putx32, \
804 (val, (bfd_byte *) ptr))
805 #define bfd_h_get_32(abfd, ptr) BFD_SEND(abfd, bfd_h_getx32, \
806 ((bfd_byte *) ptr))
807
808 #define bfd_h_put_64(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putx64, \
809 (val, (bfd_byte *) ptr))
810 #define bfd_h_get_64(abfd, ptr) BFD_SEND(abfd, bfd_h_getx64, \
811 ((bfd_byte *) ptr))
812
813 #define bfd_h_put_16(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putx16, \
814 (val, (bfd_byte *) ptr))
815 #define bfd_h_get_16(abfd, ptr) BFD_SEND(abfd, bfd_h_getx16, \
816 ((bfd_byte *) ptr))
817
818 /* General purpose one fits all. The do { } while (0) makes a single
819 statement out of it, for use in things like nested if-statements.
820
821 The idea is to create your external ref as a byte array of the
822 right size eg:
823 char foo[4];
824 char bar[2];
825 then you may do things like:
826 bfd_h_put_x(abfd, 1, &foo);
827 and bfd_h_get_x(abfd,& bar);
828 */
829
830 #define bfd_h_put_x(abfd, val, ptr) \
831 do { \
832 if (sizeof((ptr)) == LONGLONG_SIZE) \
833 bfd_h_put_64 (abfd, val, (ptr));\
834 if (sizeof((ptr)) == LONG_SIZE) \
835 bfd_h_put_32 (abfd, val, (ptr));\
836 else if (sizeof((ptr)) == SHORT_SIZE) \
837 bfd_h_put_16 (abfd, val, (ptr));\
838 else if (sizeof((ptr)) == BYTE_SIZE) \
839 bfd_h_put_8 (abfd, val, (ptr));\
840 else abort(); } while (0)
841
842 #define bfd_h_get_x(abfd, ptr) \
843 ((sizeof((ptr))==LONGLONG_SIZE) ? bfd_h_get_64 (abfd, &(ptr[0])):\
844 (sizeof((ptr))==LONG_SIZE) ? bfd_h_get_32 (abfd, &(ptr[0])):\
845 (sizeof((ptr))==SHORT_SIZE) ? bfd_h_get_16(abfd, &(ptr[0])):\
846 bfd_h_get_8 (abfd, &(ptr[0])))
847 #ifdef GNU960
848
849 #define BFD_COFF_FORMAT bfd_target_coff_flavour_enum
850 #define BFD_BOUT_FORMAT bfd_target_aout_flavour_enum
851
852 /*
853 * Return nonzero iff specified bfd is for big-endian target
854 */
855 #define BFD_BIG_ENDIAN_FILE_P(abfd) \
856 ((abfd)->xvec->header_byteorder_big_p == true)
857
858 /*
859 * Return nonzero iff specified bfd is for coff target
860 */
861 #define BFD_COFF_FILE_P(abfd) ((abfd)->xvec->flavour == BFD_COFF_FORMAT)
862
863 /*
864 * The names of the only targets the GNU/960 release cares about
865 */
866 #define BFD_BIG_COFF_TARG "coff-Intel-big"
867 #define BFD_LITTLE_COFF_TARG "coff-Intel-little"
868 #define BFD_BIG_BOUT_TARG "b.out.big"
869 #define BFD_LITTLE_BOUT_TARG "b.out.little"
870
871 extern PROTO (char *, bfd_make_targ_name,( enum target_flavour_enum format, int bigendian));
872
873 #endif /* GNU960 */
874
875 #endif /* __BFD_H_SEEN__ */
This page took 0.096118 seconds and 5 git commands to generate.