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