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