*** empty log message ***
[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 struct stat;
362 \f
363 /** Error handling */
364
365 typedef enum {no_error = 0, system_call_error, invalid_target,
366 wrong_format, invalid_operation, no_memory,
367 no_symbols, no_relocation_info,
368 no_more_archived_files, malformed_archive,
369 symbol_not_found, file_not_recognized,
370 file_ambiguously_recognized, no_contents,
371 bfd_error_nonrepresentable_section,
372 invalid_error_code} bfd_ec;
373
374 extern bfd_ec bfd_error;
375
376 typedef struct bfd_error_vector {
377 PROTO(void,(* nonrepresentable_section ),(CONST bfd *CONST abfd,
378 CONST char *CONST name));
379 } bfd_error_vector_type;
380
381 PROTO (char *, bfd_errmsg, ());
382 PROTO (void, bfd_perror, (CONST char *message));
383 \f
384
385 typedef enum
386 {
387 bfd_print_symbol_name_enum,
388 bfd_print_symbol_type_enum,
389 bfd_print_symbol_all_enum,
390 } bfd_print_symbol_enum_type;
391
392 \f
393 /* The BFD target structure.
394
395 This structure is how to find out everything BFD knows about a target.
396 It includes things like its byte order, name, what routines to call
397 to do various operations, etc.
398
399 Every BFD points to a target structure with its "xvec" member. */
400
401 /* Shortcut for declaring fields which are prototyped function pointers,
402 while avoiding anguish on compilers that don't support protos. */
403
404 #define SDEF(ret, name, arglist) PROTO(ret,(*name),arglist)
405 #define SDEF_FMT(ret, name, arglist) PROTO(ret,(*name[bfd_type_end]),arglist)
406
407 /* These macros are used to dispatch to functions through the bfd_target
408 vector. They are used in a number of macros further down in bfd.h,
409 and are also used when calling various routines by hand inside the
410 bfd implementation. The "arglist" argument must be parenthesized;
411 it contains all the arguments to the called function. */
412
413 #define BFD_SEND(bfd, message, arglist) ((*((bfd)->xvec->message)) arglist)
414 /* For operations which index on the bfd format */
415 #define BFD_SEND_FMT(bfd, message, arglist) \
416 (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
417
418 /* FIXME, these names should be rationalised with the names of the entry points
419 which call them. Too bad we can't have one macro to define them both! */
420 typedef struct bfd_target
421 {
422 /* identifies the kind of target, eg SunOS4, Ultrix, etc */
423 char *name;
424
425 /* This is bogus. Anything that can be told from the "flavour"
426 by some user program should be an independent attribute that can
427 be queried instead. FIXME. -- gnu@cygnus.com */
428 enum target_flavour_enum {
429 bfd_target_aout_flavour_enum,
430 bfd_target_coff_flavour_enum,
431 bfd_target_ieee_flavour_enum,
432 bfd_target_oasys_flavour_enum,
433 bfd_target_srec_flavour_enum} flavour;
434
435 boolean byteorder_big_p; /* Order of bytes in data sections */
436 boolean header_byteorder_big_p; /* Order of bytes in header */
437
438 flagword object_flags; /* these are the ones that may be set */
439 flagword section_flags; /* ditto */
440
441 char ar_pad_char; /* filenames in archives padded w/this char */
442 unsigned short ar_max_namelen; /* this could be a char too! */
443
444 /* Byte swapping for data */
445 /* Note that these don't take bfd as first arg. Certain other handlers
446 could do the same. */
447 SDEF (long, bfd_getxlong, (bfd_byte *));
448 SDEF (void, bfd_putxlong, (unsigned long, bfd_byte *));
449 SDEF (short, bfd_getxshort, (bfd_byte *));
450 SDEF (void, bfd_putxshort, (int, bfd_byte *));
451
452 /* Byte swapping for headers */
453 SDEF (long, bfd_h_getxlong, (bfd_byte *));
454 SDEF (void, bfd_h_putxlong, (unsigned long, bfd_byte *));
455 SDEF (short, bfd_h_getxshort, (bfd_byte *));
456 SDEF (void, bfd_h_putxshort, (int, bfd_byte *));
457
458 /* Format-dependent */
459 SDEF_FMT (struct bfd_target *, _bfd_check_format, (bfd *));/* file fmt or 0 */
460 SDEF_FMT (boolean, _bfd_set_format, (bfd *)); /* make it an object file. */
461
462 /* All these are defined in JUMP_TABLE */
463 /* Core files */
464 SDEF (char *, _core_file_failing_command, (bfd *));
465 SDEF (int, _core_file_failing_signal, (bfd *));
466 SDEF (boolean, _core_file_matches_executable_p, (bfd *, bfd *));
467
468 /* Archives */
469 SDEF (boolean, _bfd_slurp_armap, (bfd *));
470 SDEF (boolean, _bfd_slurp_extended_name_table, (bfd *));
471 SDEF (void, _bfd_truncate_arname, (bfd *, CONST char *, char *));
472 SDEF (boolean, write_armap, (bfd *arch, unsigned int elength,
473 struct orl *map, int orl_count, int
474 stridx));
475
476 /* All the standard stuff */
477 SDEF (boolean, _close_and_cleanup, (bfd *)); /* free any allocated data */
478 SDEF (boolean, _bfd_set_section_contents, (bfd *, sec_ptr, PTR,
479 file_ptr, int));
480 SDEF (boolean, _bfd_get_section_contents, (bfd *, sec_ptr, PTR,
481 file_ptr, int));
482 SDEF (boolean, _new_section_hook, (bfd *, sec_ptr));
483
484 /* Symbols and relocation */
485 SDEF (unsigned int, _get_symtab_upper_bound, (bfd *));
486 SDEF (unsigned int, _bfd_canonicalize_symtab, (bfd *, asymbol **));
487 SDEF (unsigned int, _get_reloc_upper_bound, (bfd *, sec_ptr));
488 SDEF (unsigned int, _bfd_canonicalize_reloc, (bfd *, sec_ptr, arelent **,
489 asymbol**));
490
491 /* FIXME: For steve -- clean up later */
492 SDEF (asymbol *, _bfd_make_empty_symbol, (bfd *));
493 SDEF (void, _bfd_print_symbol, (bfd *, PTR, asymbol *,
494 bfd_print_symbol_enum_type));
495 SDEF (alent *, _get_lineno, (bfd *, asymbol *));
496
497 SDEF (boolean, _bfd_set_arch_mach, (bfd *, enum bfd_architecture,
498 unsigned long));
499
500 SDEF (bfd *, openr_next_archived_file, (bfd *arch, bfd *prev));
501 SDEF (boolean, _bfd_find_nearest_line,
502 (bfd *abfd, asection *section, asymbol **symbols,bfd_vma offset,
503 CONST char **file, CONST char **func, unsigned int *line));
504 SDEF (int, _bfd_stat_arch_elt, (bfd *, struct stat *));
505 SDEF (int, _bfd_sizeof_headers, (bfd *, boolean));
506 } bfd_target;
507 \f
508 /* The code that implements targets can initialize a jump table with this
509 macro. It must name all its routines the same way (a prefix plus
510 the standard routine suffix), or it must #define the routines that
511 are not so named, before calling JUMP_TABLE in the initializer. */
512
513 /* Semi-portable string concatenation in cpp */
514 #ifndef CAT
515 #ifdef __STDC__
516 #define CAT(a,b) a##b
517 #else
518 #define CAT(a,b) a/**/b
519 #endif
520 #endif
521
522 #define JUMP_TABLE(NAME)\
523 CAT(NAME,_core_file_failing_command),\
524 CAT(NAME,_core_file_failing_signal),\
525 CAT(NAME,_core_file_matches_executable_p),\
526 CAT(NAME,_slurp_armap),\
527 CAT(NAME,_slurp_extended_name_table),\
528 CAT(NAME,_truncate_arname),\
529 CAT(NAME,_write_armap),\
530 CAT(NAME,_close_and_cleanup), \
531 CAT(NAME,_set_section_contents),\
532 CAT(NAME,_get_section_contents),\
533 CAT(NAME,_new_section_hook),\
534 CAT(NAME,_get_symtab_upper_bound),\
535 CAT(NAME,_get_symtab),\
536 CAT(NAME,_get_reloc_upper_bound),\
537 CAT(NAME,_canonicalize_reloc),\
538 CAT(NAME,_make_empty_symbol),\
539 CAT(NAME,_print_symbol),\
540 CAT(NAME,_get_lineno),\
541 CAT(NAME,_set_arch_mach),\
542 CAT(NAME,_openr_next_archived_file),\
543 CAT(NAME,_find_nearest_line),\
544 CAT(NAME,_generic_stat_arch_elt),\
545 CAT(NAME,_sizeof_headers)
546 \f
547 /* User program access to BFD facilities */
548
549 extern CONST short _bfd_host_big_endian;
550 #define HOST_BYTE_ORDER_BIG_P (*(char *)&_bfd_host_big_endian)
551
552 /* The bfd itself */
553
554 #define bfd_get_filename(abfd) ((abfd)->filename)
555 #define bfd_get_format(abfd) ((abfd)->format)
556 #define bfd_get_target(abfd) ((abfd)->xvec->name)
557 #define bfd_get_file_flags(abfd) ((abfd)->flags)
558 #define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
559 #define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
560 #define bfd_my_archive(abfd) ((abfd)->my_archive);
561 #define bfd_has_map(abfd) ((abfd)->has_armap)
562 #define bfd_header_twiddle_required(abfd) \
563 ((((abfd)->xvec->header_byteorder_big_p) \
564 != (boolean)HOST_BYTE_ORDER_BIG_P) ? true:false)
565
566 #define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
567 #define bfd_usrdata(abfd) ((abfd)->usrdata)
568
569 #define bfd_get_start_address(abfd) ((abfd)->start_address)
570 #define bfd_get_symcount(abfd) ((abfd)->symcount)
571 #define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
572 #define bfd_count_sections(abfd) ((abfd)->section_count)
573 #define bfd_get_architecture(abfd) ((abfd)->obj_arch)
574 #define bfd_get_machine(abfd) ((abfd)->obj_machine)
575
576 /* Finally! The BFD struct itself. This contains the major data about
577 the file, and contains pointers to the rest of the data.
578
579 To avoid dragging too many header files into every file that
580 includes bfd.h, IOSTREAM has been declared as a "char *", and MTIME
581 as a "long". Their correct types, to which they are cast when used,
582 are "FILE *" and "time_t". If these had been declared as structs
583 rather than typedefs, we wouldn't have this problem. */
584
585 struct _bfd
586 {
587
588 CONST char *filename; /* could be null; filename user opened with */
589 bfd_target *xvec; /* operation jump table */
590 char *iostream; /* stdio FILE *, unless an archive element */
591
592 boolean cacheable; /* iostream can be closed if desired */
593 struct _bfd *lru_prev; /* Used for file caching */
594 struct _bfd *lru_next; /* Used for file caching */
595 file_ptr where; /* Where the file was when closed */
596 boolean opened_once;
597 boolean mtime_set; /* Flag indicating mtime is available */
598 long mtime; /* File modified time */
599 int ifd; /* for output files, channel we locked. */
600 bfd_format format;
601 enum bfd_direction {no_direction = 0,
602 read_direction = 1,
603 write_direction = 2,
604 both_direction = 3} direction;
605
606 flagword flags; /* format_specific */
607 /*
608 Currently my_archive is tested before adding origin to anything. I
609 believe that this can become always an add of origin, with origin set
610 to 0 for non archive files
611 */
612
613 file_ptr origin; /* for archive contents */
614 boolean output_has_begun; /* cf bfd_set_section_size */
615 asection *sections; /* Pointer to linked list of sections */
616 unsigned int section_count; /* The number of sections */
617
618 /* Some object file stuff */
619 bfd_vma start_address; /* for object files only, of course */
620 unsigned int symcount; /* used for input and output */
621 asymbol **outsymbols; /* symtab for output bfd */
622 enum bfd_architecture obj_arch; /* Architecture of object machine, eg m68k */
623 unsigned long obj_machine; /* Particular machine within arch, e.g. 68010 */
624
625 /* Archive stuff. strictly speaking we don't need all three bfd* vars,
626 but doing so would allow recursive archives! */
627 PTR arelt_data; /* needed if this came from an archive */
628 struct _bfd *my_archive; /* if this is an archive element */
629 struct _bfd *next; /* output chain pointer */
630 struct _bfd *archive_head; /* for output archive */
631 boolean has_armap; /* if an arch; has it an armap? */
632
633 PTR tdata; /* target-specific storage */
634 PTR usrdata; /* application-specific storage */
635
636 /* Should probably be enabled here always, so that library may be changed
637 to switch this on and off, while user code may remain unchanged */
638 #ifdef BFD_LOCKS
639 struct flock *lock;
640 char *actual_name; /* for output files, name given to open() */
641 #endif
642
643 /* Where all the allocated stuff under this BFD goes */
644 struct obstack memory;
645 };
646 \f
647 /* The various callable routines */
648 PROTO(bfd_size_type, bfd_alloc_size,(bfd *abfd));
649 PROTO (char *, bfd_printable_arch_mach,(enum bfd_architecture, unsigned long));
650 PROTO (char *, bfd_format_string, (bfd_format format));
651
652 PROTO (char**, bfd_target_list, ());
653 PROTO (bfd *, bfd_openr, (CONST char *filename, CONST char *target));
654 PROTO (bfd *, bfd_fdopenr, (CONST char *filename, CONST char *target, int fd));
655 PROTO (bfd *, bfd_openw, (CONST char *filename, CONST char *target));
656 PROTO (bfd *, bfd_create, (CONST char *filename, CONST bfd *abfd));
657 PROTO (boolean, bfd_close, (bfd *abfd));
658 PROTO (long, bfd_get_mtime, (bfd *abfd));
659 PROTO (bfd *, bfd_openr_next_archived_file, (bfd *obfd, bfd *last_file));
660 PROTO (boolean, bfd_set_archive_head, (bfd *output_archive, bfd *new_head));
661 PROTO (boolean, bfd_check_format, (bfd *abfd, bfd_format format));
662 PROTO (boolean, bfd_set_format, (bfd *abfd, bfd_format format));
663 PROTO (char *, bfd_core_file_failing_command, (bfd *abfd));
664 PROTO (int, bfd_core_file_failing_signal, (bfd *abfd));
665 PROTO (boolean, core_file_matches_executable_p, (bfd *core_bfd, bfd *exec_bfd));
666 PROTO (sec_ptr, bfd_get_section_by_name, (bfd *abfd, CONST char *name));
667 PROTO (void, bfd_map_over_sections, (bfd *abfd, void (*operation)(),
668 PTR user_storage));
669 PROTO (sec_ptr, bfd_make_section, (bfd *abfd, CONST char *CONST name));
670 PROTO (boolean, bfd_set_section_flags, (bfd *abfd, sec_ptr section,
671 flagword flags));
672 PROTO (boolean, bfd_set_file_flags, (bfd *abfd, flagword flags));
673 PROTO (boolean, bfd_arch_compatible, (bfd *abfd, bfd *bbfd,
674 enum bfd_architecture *res_arch,
675 unsigned long *res_machine));
676
677 PROTO (boolean, bfd_set_section_size, (bfd *abfd, sec_ptr ptr,
678 unsigned long val));
679 PROTO (boolean, bfd_get_section_contents, (bfd *abfd, sec_ptr section,
680 PTR location,
681 file_ptr offset, int count));
682 PROTO (boolean, bfd_set_section_contents, (bfd *abfd, sec_ptr section,
683 PTR location,
684 file_ptr offset, int count));
685
686 PROTO (unsigned long, bfd_get_next_mapent, (bfd *abfd, symindex prev, carsym **entry));
687 PROTO (bfd *, bfd_get_elt_at_index, (bfd *abfd, int index));
688 PROTO (boolean, bfd_set_symtab, (bfd *abfd, asymbol **location,
689 unsigned int symcount));
690 PROTO (unsigned int, get_reloc_upper_bound, (bfd *abfd, sec_ptr asect));
691 PROTO (unsigned int, bfd_canonicalize_reloc, (bfd *abfd, sec_ptr asect,
692 arelent **location,
693 asymbol **canon));
694 PROTO (void, bfd_set_reloc, (bfd *abfd, sec_ptr asect, arelent **location,
695 unsigned int count));
696 PROTO (boolean, bfd_set_start_address, (bfd *,bfd_vma));
697
698 PROTO (void, bfd_print_symbol_vandf, (PTR, asymbol *));
699 PROTO (bfd_reloc_status_enum_type, bfd_perform_relocation,
700 (bfd *, arelent*, PTR, asection *, bfd*));
701
702 PROTO (bfd_vma, bfd_log2, (bfd_vma));
703 #define bfd_symbol_same_target(abfd, symbol) \
704 ( ( ((symbol)->the_bfd->xvec) == (abfd)->xvec) ? true:false)
705
706 PROTO(boolean, bfd_scan_arch_mach,(CONST char *, enum bfd_architecture *,
707 unsigned long *));
708
709 /* For speed we turn calls to these interface routines directly into
710 jumps through the transfer vector. This makes error-checking somewhat
711 confusing; the user basically has to read the documentation since there
712 are no longer prototypes, only declarations in the xfer vector (which
713 should be enough for some compilers).
714
715 To bad the preprocessor is too dumb to allow us to clean this up with
716 a macro. */
717
718 #define bfd_set_arch_mach(abfd, arch, mach) \
719 BFD_SEND (abfd, _bfd_set_arch_mach, (abfd, arch, mach))
720
721 #define bfd_sizeof_headers(abfd, reloc) \
722 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
723
724 #define bfd_symbol_value(abfd, idx) \
725 BFD_SEND (abfd, _bfd_symbol_value, (abfd, idx))
726
727 #define bfd_symbol_name(abfd, idx) \
728 BFD_SEND (abfd, _bfd_symbol_name, (abfd, idx))
729
730
731 #define bfd_get_first_symbol(abfd) \
732 BFD_SEND (abfd, _bfd_get_first_symbol, (abfd))
733
734 #define bfd_get_next_symbol(abfd, oidx) \
735 BFD_SEND (abfd, _bfd_get_next_symbol, (abfd, oidx))
736
737 #define bfd_classify_symbol(abfd, idx) \
738 BFD_SEND (abfd, _bfd_classify_symbol, (abfd, idx))
739
740 #define bfd_symbol_hasclass(abfd, idx, class) \
741 BFD_SEND (abfd, _bfd_symbol_hasclass, (abfd, idx, class))
742
743 #define get_symtab_upper_bound(abfd) \
744 BFD_SEND (abfd, _get_symtab_upper_bound, (abfd))
745
746 #define bfd_canonicalize_symtab(abfd, location) \
747 BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
748
749
750 #define bfd_make_empty_symbol(abfd) \
751 BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
752
753 #define bfd_print_symbol(abfd, file, symbol, how) \
754 BFD_SEND (abfd, _bfd_print_symbol, (abfd, file, symbol, how))
755
756 #define bfd_get_lineno(abfd, symbol) \
757 BFD_SEND (abfd, _get_lineno, (abfd, symbol))
758
759 #define bfd_stat_arch_elt(abfd, buf) \
760 BFD_SEND(abfd, _bfd_stat_arch_elt, (abfd, buf))
761
762 #define bfd_find_nearest_line(abfd, section, symbols, offset,filename_ptr, func, line_ptr) \
763 BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, section,symbols, offset, filename_ptr, func, line_ptr))
764
765 \f
766 /* Some byte-swapping i/o operations */
767 #define LONG_SIZE 4
768 #define SHORT_SIZE 2
769 #define BYTE_SIZE 1
770 #define bfd_putchar(abfd, val, ptr) (*((char *)ptr) = (char)val)
771 #define bfd_getchar(abfd, ptr) (*((char *)ptr))
772
773 #define bfd_putlong(abfd, val, ptr) BFD_SEND(abfd, bfd_putxlong, (val,ptr))
774 #define bfd_getlong(abfd, ptr) BFD_SEND(abfd, bfd_getxlong, (ptr))
775
776 #define bfd_putshort(abfd, val, ptr) BFD_SEND(abfd, bfd_putxshort, (val,ptr))
777 #define bfd_getshort(abfd, ptr) BFD_SEND(abfd, bfd_getxshort, (ptr))
778
779 #define bfd_h_putchar(abfd, val, ptr) bfd_putchar (abfd, val, ptr)
780 #define bfd_h_getchar(abfd, ptr) bfd_getchar (abfd, ptr)
781
782 #define bfd_h_putlong(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putxlong, (val, (bfd_byte *) ptr))
783 #define bfd_h_getlong(abfd, ptr) BFD_SEND(abfd, bfd_h_getxlong, ((bfd_byte *) ptr))
784
785 #define bfd_h_putshort(abfd, val, ptr) BFD_SEND(abfd, bfd_h_putxshort,(val,ptr))
786 #define bfd_h_getshort(abfd, ptr) BFD_SEND(abfd, bfd_h_getxshort,(ptr))
787
788 /* General purpose one fits all. The do { } while (0) makes a single
789 statement out of it, for use in things like nested if-statements.
790
791 USE OF THESE MACROS IS DISCOURAGED. THEY ASSUME THAT THE HOST AND
792 TARGET FIELD ALIGNMENT AND SIZES ARE THE SAME. TARGET STRUCTS SHOULD
793 BE MODELED AS BYTE ARRAYS INSTEAD, TO AVOID THESE ASSUMPTIONS. */
794
795 #define bfd_h_put_x(abfd, val, ptr) \
796 do { \
797 if (sizeof(*(ptr)) == LONG_SIZE) \
798 bfd_h_putlong (abfd, val, (bfd_byte*)(ptr));\
799 else if (sizeof(*(ptr)) == SHORT_SIZE) \
800 bfd_h_putshort (abfd, val, (bfd_byte *)(ptr));\
801 else if (sizeof(*(ptr)) == BYTE_SIZE) \
802 bfd_h_putchar (abfd, val, (bfd_byte *)(ptr));\
803 else abort(); } while (0)
804
805 #define bfd_h_get_x(abfd, ptr) \
806 ((sizeof(*(ptr))==LONG_SIZE) ? bfd_h_getlong (abfd, (bfd_byte *)(ptr)):\
807 (sizeof(*(ptr))==SHORT_SIZE) ? bfd_h_getshort(abfd, (bfd_byte *)(ptr)):\
808 (sizeof(*(ptr))==BYTE_SIZE) ? bfd_h_getchar (abfd, (bfd_byte *)(ptr)):\
809 (abort(),1) )
810 \f
811 #ifdef GNU960
812
813 #define BFD_COFF_FORMAT bfd_target_coff_flavour_enum
814 #define BFD_BOUT_FORMAT bfd_target_aout_flavour_enum
815
816 /*
817 * Return nonzero iff specified bfd is for big-endian target
818 */
819 #define BFD_BIG_ENDIAN_FILE_P(abfd) \
820 ((abfd)->xvec->header_byteorder_big_p == true)
821
822 /*
823 * Return nonzero iff specified bfd is for coff target
824 */
825 #define BFD_COFF_FILE_P(abfd) ((abfd)->xvec->flavour == BFD_COFF_FORMAT)
826
827 /*
828 * The names of the only targets the GNU/960 release cares about
829 */
830 #define BFD_BIG_COFF_TARG "coff-Intel-big"
831 #define BFD_LITTLE_COFF_TARG "coff-Intel-little"
832 #define BFD_BIG_BOUT_TARG "b.out.big"
833 #define BFD_LITTLE_BOUT_TARG "b.out.little"
834
835 extern PROTO (char *, bfd_make_targ_name,( enum target_flavour_enum format, int bigendian));
836
837 #endif /* GNU960 */
838
839 #endif /* __BFD_H_SEEN__ */
This page took 0.048841 seconds and 4 git commands to generate.