changed forward declaration struct stat; to reduce warnings. Changed
[deliverable/binutils-gdb.git] / include / bfd.h
CommitLineData
a07cc613
JG
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
7This file is part of BFD, the Binary File Diddler.
8
9BFD is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 1, or (at your option)
12any later version.
13
14BFD is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with BFD; see the file COPYING. If not, write to
21the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22
a07cc613
JG
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"
ec08b077 42
a07cc613 43/* forward declaration */
9c6a9c92 44typedef struct _bfd bfd;
a07cc613 45
ec08b077
JG
46/* General rules: functions which are boolean return true on success
47 and false on failure (unless they're a predicate). -- bfd.doc */
a07cc613
JG
48/* I'm sure this is going to break something and someone is going to
49 force me to change it. */
50typedef enum boolean {false, true} boolean;
a07cc613
JG
51
52/* Try to avoid breaking stuff */
53typedef long int file_ptr;
54
55/* This is used to refer to locations inside a section's rawdata */
56typedef unsigned long int rawdata_offset;
57
58typedef unsigned long bfd_vma;
59typedef unsigned long bfd_offset;
60
61typedef unsigned int flagword; /* 32 bits of flags */
62\f
63/** File formats */
64
65typedef 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. */
88enum 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
119typedef unsigned long symindex;
120
121#define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
122
123typedef 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
130typedef unsigned long symvalue; /* someday they may be 64-bit qtys */
131typedef int symtype; /* Who knows, yet? */
132typedef 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 */
166typedef struct symbol_cache_entry
167{
9c6a9c92 168 struct _bfd *the_bfd; /* Just a way to find out host type */
a07cc613
JG
169 CONST char *name;
170 symvalue value;
171 flagword flags;
9c6a9c92 172 struct sec *section;
a07cc613
JG
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! */
9c6a9c92 185typedef struct carsym {
a07cc613
JG
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
9c6a9c92 198typedef enum bfd_reloc_status {
a07cc613
JG
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
9c6a9c92 209typedef CONST struct rint {
a07cc613
JG
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
249typedef unsigned char bfd_byte;
250
251typedef 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 */
9c6a9c92 258 struct sec *section; /* if sym is null this is the section */
a07cc613
JG
259 reloc_howto_type *howto;
260
261} arelent;
262
9c6a9c92 263typedef struct relent_chain {
a07cc613 264 arelent relent;
9c6a9c92 265 struct relent_chain *next;
a07cc613
JG
266} arelent_chain;
267
268/* Used in generating armaps. Perhaps just a forward definition would do? */
269struct 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 */
278typedef 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
9c6a9c92 301typedef struct sec
a07cc613
JG
302{
303 CONST char *name;
9c6a9c92 304 struct sec *next;
a07cc613
JG
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;
9c6a9c92 315 struct sec *output_section;
a07cc613
JG
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;
9c6a9c92
JG
325 struct user_section *userdata;
326 struct lang_output_section *otheruserdata;
a07cc613
JG
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
9c6a9c92 332 linenumbers are written out */
a07cc613
JG
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
9c6a9c92 340 /* If this is a constructor section then here is a list of relents */
a07cc613
JG
341 arelent_chain *constructor_chain;
342} asection;
343
344#define align_power(addr, align) \
345 ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
346
347
348
9c6a9c92 349typedef struct sec *sec_ptr;
a07cc613
JG
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)
4322f04d
SC
361
362typedef struct stat stat_type;
a07cc613
JG
363\f
364/** Error handling */
365
366typedef 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
375extern bfd_ec bfd_error;
376
9c6a9c92 377typedef struct bfd_error_vector {
a07cc613
JG
378 PROTO(void,(* nonrepresentable_section ),(CONST bfd *CONST abfd,
379 CONST char *CONST name));
380} bfd_error_vector_type;
381
382PROTO (char *, bfd_errmsg, ());
383PROTO (void, bfd_perror, (CONST char *message));
384\f
385
386typedef 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/* FIXME, these names should be rationalised with the names of the entry points
420 which call them. Too bad we can't have one macro to define them both! */
421typedef struct bfd_target
422{
423 /* identifies the kind of target, eg SunOS4, Ultrix, etc */
424 char *name;
425
426 /* This is bogus. Anything that can be told from the "flavour"
427 by some user program should be an independent attribute that can
428 be queried instead. FIXME. -- gnu@cygnus.com */
429 enum target_flavour_enum {
430 bfd_target_aout_flavour_enum,
431 bfd_target_coff_flavour_enum,
432 bfd_target_ieee_flavour_enum,
433 bfd_target_oasys_flavour_enum,
434 bfd_target_srec_flavour_enum} flavour;
435
436 boolean byteorder_big_p; /* Order of bytes in data sections */
437 boolean header_byteorder_big_p; /* Order of bytes in header */
438
439 flagword object_flags; /* these are the ones that may be set */
440 flagword section_flags; /* ditto */
441
442 char ar_pad_char; /* filenames in archives padded w/this char */
443 unsigned short ar_max_namelen; /* this could be a char too! */
444
445 /* Byte swapping for data */
446 /* Note that these don't take bfd as first arg. Certain other handlers
447 could do the same. */
448 SDEF (long, bfd_getxlong, (bfd_byte *));
449 SDEF (void, bfd_putxlong, (unsigned long, bfd_byte *));
450 SDEF (short, bfd_getxshort, (bfd_byte *));
451 SDEF (void, bfd_putxshort, (int, bfd_byte *));
452
453 /* Byte swapping for headers */
454 SDEF (long, bfd_h_getxlong, (bfd_byte *));
455 SDEF (void, bfd_h_putxlong, (unsigned long, bfd_byte *));
456 SDEF (short, bfd_h_getxshort, (bfd_byte *));
457 SDEF (void, bfd_h_putxshort, (int, bfd_byte *));
458
459 /* Format-dependent */
460 SDEF_FMT (struct bfd_target *, _bfd_check_format, (bfd *));/* file fmt or 0 */
461 SDEF_FMT (boolean, _bfd_set_format, (bfd *)); /* make it an object file. */
462
463 /* All these are defined in JUMP_TABLE */
464 /* Core files */
465 SDEF (char *, _core_file_failing_command, (bfd *));
466 SDEF (int, _core_file_failing_signal, (bfd *));
467 SDEF (boolean, _core_file_matches_executable_p, (bfd *, bfd *));
468
469 /* Archives */
470 SDEF (boolean, _bfd_slurp_armap, (bfd *));
471 SDEF (boolean, _bfd_slurp_extended_name_table, (bfd *));
472 SDEF (void, _bfd_truncate_arname, (bfd *, CONST char *, char *));
473 SDEF (boolean, write_armap, (bfd *arch, unsigned int elength,
474 struct orl *map, int orl_count, int
475 stridx));
476
477 /* All the standard stuff */
478 SDEF (boolean, _close_and_cleanup, (bfd *)); /* free any allocated data */
479 SDEF (boolean, _bfd_set_section_contents, (bfd *, sec_ptr, PTR,
480 file_ptr, int));
481 SDEF (boolean, _bfd_get_section_contents, (bfd *, sec_ptr, PTR,
482 file_ptr, int));
483 SDEF (boolean, _new_section_hook, (bfd *, sec_ptr));
484
485 /* Symbols and relocation */
486 SDEF (unsigned int, _get_symtab_upper_bound, (bfd *));
487 SDEF (unsigned int, _bfd_canonicalize_symtab, (bfd *, asymbol **));
488 SDEF (unsigned int, _get_reloc_upper_bound, (bfd *, sec_ptr));
489 SDEF (unsigned int, _bfd_canonicalize_reloc, (bfd *, sec_ptr, arelent **,
490 asymbol**));
491
492 /* FIXME: For steve -- clean up later */
493 SDEF (asymbol *, _bfd_make_empty_symbol, (bfd *));
494 SDEF (void, _bfd_print_symbol, (bfd *, PTR, asymbol *,
495 bfd_print_symbol_enum_type));
9c6a9c92 496 SDEF (alent *, _get_lineno, (bfd *, asymbol *));
a07cc613 497
a07cc613
JG
498 SDEF (boolean, _bfd_set_arch_mach, (bfd *, enum bfd_architecture,
499 unsigned long));
500
501 SDEF (bfd *, openr_next_archived_file, (bfd *arch, bfd *prev));
502 SDEF (boolean, _bfd_find_nearest_line,
503 (bfd *abfd, asection *section, asymbol **symbols,bfd_vma offset,
504 CONST char **file, CONST char **func, unsigned int *line));
505 SDEF (int, _bfd_stat_arch_elt, (bfd *, struct stat *));
506 SDEF (int, _bfd_sizeof_headers, (bfd *, boolean));
507} bfd_target;
508\f
509/* The code that implements targets can initialize a jump table with this
510 macro. It must name all its routines the same way (a prefix plus
511 the standard routine suffix), or it must #define the routines that
512 are not so named, before calling JUMP_TABLE in the initializer. */
513
514/* Semi-portable string concatenation in cpp */
515#ifndef CAT
516#ifdef __STDC__
517#define CAT(a,b) a##b
518#else
519#define CAT(a,b) a/**/b
520#endif
521#endif
522
523#define JUMP_TABLE(NAME)\
524CAT(NAME,_core_file_failing_command),\
525CAT(NAME,_core_file_failing_signal),\
526CAT(NAME,_core_file_matches_executable_p),\
527CAT(NAME,_slurp_armap),\
528CAT(NAME,_slurp_extended_name_table),\
529CAT(NAME,_truncate_arname),\
530CAT(NAME,_write_armap),\
531CAT(NAME,_close_and_cleanup), \
532CAT(NAME,_set_section_contents),\
533CAT(NAME,_get_section_contents),\
534CAT(NAME,_new_section_hook),\
535CAT(NAME,_get_symtab_upper_bound),\
536CAT(NAME,_get_symtab),\
537CAT(NAME,_get_reloc_upper_bound),\
538CAT(NAME,_canonicalize_reloc),\
539CAT(NAME,_make_empty_symbol),\
540CAT(NAME,_print_symbol),\
541CAT(NAME,_get_lineno),\
542CAT(NAME,_set_arch_mach),\
543CAT(NAME,_openr_next_archived_file),\
544CAT(NAME,_find_nearest_line),\
545CAT(NAME,_generic_stat_arch_elt),\
546CAT(NAME,_sizeof_headers)
547\f
548/* User program access to BFD facilities */
549
550extern CONST short _bfd_host_big_endian;
551#define HOST_BYTE_ORDER_BIG_P (*(char *)&_bfd_host_big_endian)
552
553/* The bfd itself */
554
8c01a0ea
JK
555/* Cast from const char * to char * so that caller can assign to
556 a char * without a warning. */
557#define bfd_get_filename(abfd) ((char *) (abfd)->filename)
a07cc613
JG
558#define bfd_get_format(abfd) ((abfd)->format)
559#define bfd_get_target(abfd) ((abfd)->xvec->name)
560#define bfd_get_file_flags(abfd) ((abfd)->flags)
561#define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
562#define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
563#define bfd_my_archive(abfd) ((abfd)->my_archive);
564#define bfd_has_map(abfd) ((abfd)->has_armap)
565#define bfd_header_twiddle_required(abfd) \
566 ((((abfd)->xvec->header_byteorder_big_p) \
567 != (boolean)HOST_BYTE_ORDER_BIG_P) ? true:false)
568
569#define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
570#define bfd_usrdata(abfd) ((abfd)->usrdata)
571
572#define bfd_get_start_address(abfd) ((abfd)->start_address)
573#define bfd_get_symcount(abfd) ((abfd)->symcount)
574#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
575#define bfd_count_sections(abfd) ((abfd)->section_count)
576#define bfd_get_architecture(abfd) ((abfd)->obj_arch)
577#define bfd_get_machine(abfd) ((abfd)->obj_machine)
578
579/* Finally! The BFD struct itself. This contains the major data about
580 the file, and contains pointers to the rest of the data.
581
582 To avoid dragging too many header files into every file that
583 includes bfd.h, IOSTREAM has been declared as a "char *", and MTIME
584 as a "long". Their correct types, to which they are cast when used,
585 are "FILE *" and "time_t". If these had been declared as structs
586 rather than typedefs, we wouldn't have this problem. */
587
9c6a9c92 588struct _bfd
a07cc613
JG
589{
590
591 CONST char *filename; /* could be null; filename user opened with */
592 bfd_target *xvec; /* operation jump table */
593 char *iostream; /* stdio FILE *, unless an archive element */
594
595 boolean cacheable; /* iostream can be closed if desired */
9c6a9c92
JG
596 struct _bfd *lru_prev; /* Used for file caching */
597 struct _bfd *lru_next; /* Used for file caching */
a07cc613
JG
598 file_ptr where; /* Where the file was when closed */
599 boolean opened_once;
600 boolean mtime_set; /* Flag indicating mtime is available */
601 long mtime; /* File modified time */
602 int ifd; /* for output files, channel we locked. */
603 bfd_format format;
604 enum bfd_direction {no_direction = 0,
605 read_direction = 1,
606 write_direction = 2,
607 both_direction = 3} direction;
608
609 flagword flags; /* format_specific */
610/*
611Currently my_archive is tested before adding origin to anything. I
612believe that this can become always an add of origin, with origin set
613to 0 for non archive files
614*/
615
616 file_ptr origin; /* for archive contents */
617 boolean output_has_begun; /* cf bfd_set_section_size */
618 asection *sections; /* Pointer to linked list of sections */
619 unsigned int section_count; /* The number of sections */
620
621 /* Some object file stuff */
622 bfd_vma start_address; /* for object files only, of course */
623 unsigned int symcount; /* used for input and output */
624 asymbol **outsymbols; /* symtab for output bfd */
625 enum bfd_architecture obj_arch; /* Architecture of object machine, eg m68k */
626 unsigned long obj_machine; /* Particular machine within arch, e.g. 68010 */
627
628 /* Archive stuff. strictly speaking we don't need all three bfd* vars,
629 but doing so would allow recursive archives! */
630 PTR arelt_data; /* needed if this came from an archive */
9c6a9c92
JG
631 struct _bfd *my_archive; /* if this is an archive element */
632 struct _bfd *next; /* output chain pointer */
633 struct _bfd *archive_head; /* for output archive */
a07cc613
JG
634 boolean has_armap; /* if an arch; has it an armap? */
635
636 PTR tdata; /* target-specific storage */
637 PTR usrdata; /* application-specific storage */
638
639 /* Should probably be enabled here always, so that library may be changed
640 to switch this on and off, while user code may remain unchanged */
641#ifdef BFD_LOCKS
642 struct flock *lock;
643 char *actual_name; /* for output files, name given to open() */
644#endif
645
646 /* Where all the allocated stuff under this BFD goes */
647 struct obstack memory;
648};
649\f
9c6a9c92
JG
650/* The various callable routines */
651PROTO(bfd_size_type, bfd_alloc_size,(bfd *abfd));
a07cc613
JG
652PROTO (char *, bfd_printable_arch_mach,(enum bfd_architecture, unsigned long));
653PROTO (char *, bfd_format_string, (bfd_format format));
654
655PROTO (char**, bfd_target_list, ());
656PROTO (bfd *, bfd_openr, (CONST char *filename, CONST char *target));
657PROTO (bfd *, bfd_fdopenr, (CONST char *filename, CONST char *target, int fd));
658PROTO (bfd *, bfd_openw, (CONST char *filename, CONST char *target));
659PROTO (bfd *, bfd_create, (CONST char *filename, CONST bfd *abfd));
660PROTO (boolean, bfd_close, (bfd *abfd));
661PROTO (long, bfd_get_mtime, (bfd *abfd));
662PROTO (bfd *, bfd_openr_next_archived_file, (bfd *obfd, bfd *last_file));
663PROTO (boolean, bfd_set_archive_head, (bfd *output_archive, bfd *new_head));
664PROTO (boolean, bfd_check_format, (bfd *abfd, bfd_format format));
665PROTO (boolean, bfd_set_format, (bfd *abfd, bfd_format format));
666PROTO (char *, bfd_core_file_failing_command, (bfd *abfd));
667PROTO (int, bfd_core_file_failing_signal, (bfd *abfd));
668PROTO (boolean, core_file_matches_executable_p, (bfd *core_bfd, bfd *exec_bfd));
669PROTO (sec_ptr, bfd_get_section_by_name, (bfd *abfd, CONST char *name));
670PROTO (void, bfd_map_over_sections, (bfd *abfd, void (*operation)(),
671 PTR user_storage));
672PROTO (sec_ptr, bfd_make_section, (bfd *abfd, CONST char *CONST name));
673PROTO (boolean, bfd_set_section_flags, (bfd *abfd, sec_ptr section,
674 flagword flags));
675PROTO (boolean, bfd_set_file_flags, (bfd *abfd, flagword flags));
676PROTO (boolean, bfd_arch_compatible, (bfd *abfd, bfd *bbfd,
677 enum bfd_architecture *res_arch,
678 unsigned long *res_machine));
679
680PROTO (boolean, bfd_set_section_size, (bfd *abfd, sec_ptr ptr,
681 unsigned long val));
682PROTO (boolean, bfd_get_section_contents, (bfd *abfd, sec_ptr section,
683 PTR location,
684 file_ptr offset, int count));
685PROTO (boolean, bfd_set_section_contents, (bfd *abfd, sec_ptr section,
686 PTR location,
687 file_ptr offset, int count));
688
689PROTO (unsigned long, bfd_get_next_mapent, (bfd *abfd, symindex prev, carsym **entry));
690PROTO (bfd *, bfd_get_elt_at_index, (bfd *abfd, int index));
691PROTO (boolean, bfd_set_symtab, (bfd *abfd, asymbol **location,
692 unsigned int symcount));
693PROTO (unsigned int, get_reloc_upper_bound, (bfd *abfd, sec_ptr asect));
694PROTO (unsigned int, bfd_canonicalize_reloc, (bfd *abfd, sec_ptr asect,
695 arelent **location,
696 asymbol **canon));
697PROTO (void, bfd_set_reloc, (bfd *abfd, sec_ptr asect, arelent **location,
698 unsigned int count));
699PROTO (boolean, bfd_set_start_address, (bfd *,bfd_vma));
700
701PROTO (void, bfd_print_symbol_vandf, (PTR, asymbol *));
702PROTO (bfd_reloc_status_enum_type, bfd_perform_relocation,
703 (bfd *, arelent*, PTR, asection *, bfd*));
704
705PROTO (bfd_vma, bfd_log2, (bfd_vma));
706#define bfd_symbol_same_target(abfd, symbol) \
707( ( ((symbol)->the_bfd->xvec) == (abfd)->xvec) ? true:false)
708
709PROTO(boolean, bfd_scan_arch_mach,(CONST char *, enum bfd_architecture *,
710 unsigned long *));
711
712/* For speed we turn calls to these interface routines directly into
713 jumps through the transfer vector. This makes error-checking somewhat
714 confusing; the user basically has to read the documentation since there
715 are no longer prototypes, only declarations in the xfer vector (which
716 should be enough for some compilers).
717
718 To bad the preprocessor is too dumb to allow us to clean this up with
719 a macro. */
720
721#define bfd_set_arch_mach(abfd, arch, mach) \
722 BFD_SEND (abfd, _bfd_set_arch_mach, (abfd, arch, mach))
723
724#define bfd_sizeof_headers(abfd, reloc) \
725 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
726
727#define bfd_symbol_value(abfd, idx) \
728 BFD_SEND (abfd, _bfd_symbol_value, (abfd, idx))
729
730#define bfd_symbol_name(abfd, idx) \
731 BFD_SEND (abfd, _bfd_symbol_name, (abfd, idx))
732
733
734#define bfd_get_first_symbol(abfd) \
735 BFD_SEND (abfd, _bfd_get_first_symbol, (abfd))
736
737#define bfd_get_next_symbol(abfd, oidx) \
738 BFD_SEND (abfd, _bfd_get_next_symbol, (abfd, oidx))
739
740#define bfd_classify_symbol(abfd, idx) \
741 BFD_SEND (abfd, _bfd_classify_symbol, (abfd, idx))
742
743#define bfd_symbol_hasclass(abfd, idx, class) \
744 BFD_SEND (abfd, _bfd_symbol_hasclass, (abfd, idx, class))
745
746#define get_symtab_upper_bound(abfd) \
747 BFD_SEND (abfd, _get_symtab_upper_bound, (abfd))
748
749#define bfd_canonicalize_symtab(abfd, location) \
750 BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
751
752
753#define bfd_make_empty_symbol(abfd) \
754 BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
755
756#define bfd_print_symbol(abfd, file, symbol, how) \
757 BFD_SEND (abfd, _bfd_print_symbol, (abfd, file, symbol, how))
758
759#define bfd_get_lineno(abfd, symbol) \
760 BFD_SEND (abfd, _get_lineno, (abfd, symbol))
761
762#define bfd_stat_arch_elt(abfd, buf) \
763 BFD_SEND(abfd, _bfd_stat_arch_elt, (abfd, buf))
764
765#define bfd_find_nearest_line(abfd, section, symbols, offset,filename_ptr, func, line_ptr) \
766BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, section,symbols, offset, filename_ptr, func, line_ptr))
767
768\f
769/* Some byte-swapping i/o operations */
770#define LONG_SIZE 4
771#define SHORT_SIZE 2
772#define BYTE_SIZE 1
773#define bfd_putchar(abfd, val, ptr) (*((char *)ptr) = (char)val)
774#define bfd_getchar(abfd, ptr) (*((char *)ptr))
775
776#define bfd_putlong(abfd, val, ptr) BFD_SEND(abfd, bfd_putxlong, (val,ptr))
777#define bfd_getlong(abfd, ptr) BFD_SEND(abfd, bfd_getxlong, (ptr))
778
779#define bfd_putshort(abfd, val, ptr) BFD_SEND(abfd, bfd_putxshort, (val,ptr))
780#define bfd_getshort(abfd, ptr) BFD_SEND(abfd, bfd_getxshort, (ptr))
781
782#define bfd_h_putchar(abfd, val, ptr) bfd_putchar (abfd, val, ptr)
783#define bfd_h_getchar(abfd, ptr) bfd_getchar (abfd, ptr)
784
785#define bfd_h_putlong(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putxlong, (val, (bfd_byte *) ptr))
786#define bfd_h_getlong(abfd, ptr) BFD_SEND(abfd, bfd_h_getxlong, ((bfd_byte *) ptr))
787
788#define bfd_h_putshort(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putxshort,(val,ptr))
789#define bfd_h_getshort(abfd, ptr) BFD_SEND(abfd, bfd_h_getxshort,(ptr))
790
791/* General purpose one fits all. The do { } while (0) makes a single
792 statement out of it, for use in things like nested if-statements.
4322f04d
SC
793
794 The idea is to create your external ref as a byte array of the
795 right size eg:
796 char foo[4];
797 char bar[2];
798 then you may do things like:
799 bfd_h_put_x(abfd, 1, &foo);
800 and bfd_h_get_x(abfd,& bar);
801*/
a07cc613
JG
802
803#define bfd_h_put_x(abfd, val, ptr) \
804 do { \
805 if (sizeof(*(ptr)) == LONG_SIZE) \
806 bfd_h_putlong (abfd, val, (bfd_byte*)(ptr));\
807 else if (sizeof(*(ptr)) == SHORT_SIZE) \
808 bfd_h_putshort (abfd, val, (bfd_byte *)(ptr));\
809 else if (sizeof(*(ptr)) == BYTE_SIZE) \
810 bfd_h_putchar (abfd, val, (bfd_byte *)(ptr));\
811 else abort(); } while (0)
812
813#define bfd_h_get_x(abfd, ptr) \
814 ((sizeof(*(ptr))==LONG_SIZE) ? bfd_h_getlong (abfd, (bfd_byte *)(ptr)):\
815 (sizeof(*(ptr))==SHORT_SIZE) ? bfd_h_getshort(abfd, (bfd_byte *)(ptr)):\
816 (sizeof(*(ptr))==BYTE_SIZE) ? bfd_h_getchar (abfd, (bfd_byte *)(ptr)):\
817 (abort(),1) )
818\f
819#ifdef GNU960
820
821#define BFD_COFF_FORMAT bfd_target_coff_flavour_enum
822#define BFD_BOUT_FORMAT bfd_target_aout_flavour_enum
823
824/*
825 * Return nonzero iff specified bfd is for big-endian target
826 */
827#define BFD_BIG_ENDIAN_FILE_P(abfd) \
828 ((abfd)->xvec->header_byteorder_big_p == true)
829
830/*
831 * Return nonzero iff specified bfd is for coff target
832 */
833#define BFD_COFF_FILE_P(abfd) ((abfd)->xvec->flavour == BFD_COFF_FORMAT)
834
835/*
836 * The names of the only targets the GNU/960 release cares about
837 */
838#define BFD_BIG_COFF_TARG "coff-Intel-big"
839#define BFD_LITTLE_COFF_TARG "coff-Intel-little"
840#define BFD_BIG_BOUT_TARG "b.out.big"
841#define BFD_LITTLE_BOUT_TARG "b.out.little"
842
843extern PROTO (char *, bfd_make_targ_name,( enum target_flavour_enum format, int bigendian));
844
845#endif /* GNU960 */
846
847#endif /* __BFD_H_SEEN__ */
This page took 0.060817 seconds and 4 git commands to generate.