1 /* Generic BFD library interface and support routines.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 A BFD is has type <<bfd>>; objects of this type are the
29 cornerstone of any application using <<libbfd>>. References
30 though the BFD and to data in the BFD give the entire BFD
33 Here is the struct used to define the type <<bfd>>. This
34 contains he major data about the file, and contains pointers
35 to the rest of the data.
39 The filename the application opened the BFD with.
41 . CONST char *filename;
43 A pointer to the target jump table.
45 . struct bfd_target *xvec;
47 To avoid dragging too many header files into every file that
48 includes @file{bfd.h}, IOSTREAM has been declared as a "char
49 *", and MTIME as a "long". Their correct types, to which they
50 are cast when used, are "FILE *" and "time_t". The iostream
51 is the result of an fopen on the filename.
55 Is the file being cached @xref{File Caching}.
59 Marks whether there was a default target specified when the
60 BFD was opened. This is used to select what matching algorithm
61 to use to chose the back end.
63 . boolean target_defaulted;
65 The caching routines use these to maintain a
66 least-recently-used list of BFDs (@pxref{File Caching}).
68 . struct _bfd *lru_prev, *lru_next;
70 When a file is closed by the caching routines, BFD retains
71 state information on the file here:
77 . boolean opened_once;
85 Reserved for an unimplemented file locking extension.
89 The format which belongs to the BFD.
93 The direction the BFD was opened with
95 . enum bfd_direction {no_direction = 0,
97 . write_direction = 2,
98 . both_direction = 3} direction;
100 Format_specific flags
104 Currently my_archive is tested before adding origin to
105 anything. I believe that this can become always an add of
106 origin, with origin set to 0 for non archive files.
110 Remember when output has begun, to stop strange things happening.
112 . boolean output_has_begun;
114 Pointer to linked list of sections
116 . struct sec *sections;
118 The number of sections
120 . unsigned int section_count;
122 Stuff only useful for object files:
125 . bfd_vma start_address;
127 Used for input and output
129 . unsigned int symcount;
131 Symbol table for output BFD
133 . struct symbol_cache_entry **outsymbols;
135 Pointer to structure which contains architecture information
137 . struct bfd_arch_info *arch_info;
139 Stuff only useful for archives:
142 . struct _bfd *my_archive;
144 . struct _bfd *archive_head;
147 Used by the back end to hold private data.
151 Used by the application to hold private data
155 Where all the allocated stuff under this BFD goes
156 (@pxref{Memory Usage}).
158 . struct obstack memory;
167 extern char *strerror();
170 CONST
short _bfd_host_big_endian
= 0x0100;
171 /* Accessing the above as (*(char*)&_bfd_host_big_endian), will
172 return 1 if the host is big-endian, 0 otherwise.
173 (assuming that a short is two bytes long!!! FIXME)
174 (See HOST_IS_BIG_ENDIAN_P in bfd.h.) */
177 o - Most functions return nonzero on success (check doc for
178 precise semantics); 0 or NULL on error.
179 o - Internal errors are documented by the value of bfd_error.
180 If that is system_call_error then check errno.
181 o - The easiest way to report this to the user is to use bfd_perror.
184 bfd_ec bfd_error
= no_error
;
186 char *bfd_errmsgs
[] = { "No error",
189 "File in wrong format",
193 "No relocation info",
194 "No more archived files",
197 "File format not recognized",
198 "File format is ambiguous",
199 "Section has no contents",
200 "Nonrepresentable section on output",
201 "Symbol needs debug section which does not exist",
202 "#<Invalid error code>"
207 DEFUN(bfd_nonrepresentable_section
,(abfd
, name
),
208 CONST bfd
* CONST abfd AND
209 CONST
char * CONST name
)
211 printf("bfd error writing file %s, format %s can't represent section %s\n",
218 bfd_error_vector_type bfd_error_vector
=
220 bfd_nonrepresentable_section
224 bfd_errmsg (error_tag
)
230 if (error_tag
== system_call_error
)
231 return strerror (errno
);
233 if ((((int)error_tag
<(int) no_error
) ||
234 ((int)error_tag
> (int)invalid_error_code
)))
235 error_tag
= invalid_error_code
;/* sanity check */
237 return bfd_errmsgs
[(int)error_tag
];
241 void bfd_default_error_trap(error_tag
)
244 printf("bfd assert fail (%s)\n", bfd_errmsg(error_tag
));
247 void (*bfd_error_trap
)() = bfd_default_error_trap
;
248 void (*bfd_error_nonrepresentabltrap
)() = bfd_default_error_trap
;
251 DEFUN(bfd_perror
,(message
),
254 if (bfd_error
== system_call_error
)
255 perror((char *)message
); /* must be system error then... */
257 if (message
== NULL
|| *message
== '\0')
258 fprintf (stderr
, "%s\n", bfd_errmsg (bfd_error
));
260 fprintf (stderr
, "%s: %s\n", message
, bfd_errmsg (bfd_error
));
267 /* returns the number of octets of storage required */
270 get_reloc_upper_bound (abfd
, asect
)
274 if (abfd
->format
!= bfd_object
) {
275 bfd_error
= invalid_operation
;
279 return BFD_SEND (abfd
, _get_reloc_upper_bound
, (abfd
, asect
));
283 DEFUN(bfd_canonicalize_reloc
,(abfd
, asect
, location
, symbols
),
286 arelent
**location AND
289 if (abfd
->format
!= bfd_object
) {
290 bfd_error
= invalid_operation
;
293 return BFD_SEND (abfd
, _bfd_canonicalize_reloc
, (abfd
, asect
, location
, symbols
));
298 bfd_set_file_flags (abfd
, flags
)
302 if (abfd
->format
!= bfd_object
) {
303 bfd_error
= wrong_format
;
307 if (bfd_read_p (abfd
)) {
308 bfd_error
= invalid_operation
;
312 if ((flags
& bfd_applicable_file_flags (abfd
)) != flags
) {
313 bfd_error
= invalid_operation
;
317 bfd_get_file_flags (abfd
) = flags
;
323 bfd_set_reloc (ignore_abfd
, asect
, location
, count
)
329 asect
->orelocation
= location
;
330 asect
->reloc_count
= count
;
334 bfd_assert(file
, line
)
338 printf("bfd assertion fail %s:%d\n",file
,line
);
344 bfd_set_start_address
348 Marks the entry point of an output BFD.
351 Returns <<true>> on success, <<false>> otherwise.
354 boolean bfd_set_start_address(bfd *, bfd_vma);
358 bfd_set_start_address(abfd
, vma
)
362 abfd
->start_address
= vma
;
372 Return cached file modification time (e.g. as read from
373 archive header for archive members, or from file system if we
374 have been called before); else determine modify time, cache
378 long bfd_get_mtime(bfd *);
391 fp
= bfd_cache_lookup (abfd
);
392 if (0 != fstat (fileno (fp
), &buf
))
395 abfd
->mtime_set
= true;
396 abfd
->mtime
= buf
.st_mtime
;
405 stuff which should be documented
407 .#define bfd_sizeof_headers(abfd, reloc) \
408 . BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
410 .#define bfd_find_nearest_line(abfd, section, symbols, offset, filename_ptr, func, line_ptr) \
411 . BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, section, symbols, offset, filename_ptr, func, line_ptr))
413 .#define bfd_debug_info_start(abfd) \
414 . BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
416 .#define bfd_debug_info_end(abfd) \
417 . BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
419 .#define bfd_debug_info_accumulate(abfd, section) \
420 . BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
422 .#define bfd_stat_arch_elt(abfd, stat) \
423 . BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
425 .#define bfd_coff_swap_aux_in(a,e,t,c,i) \
426 . BFD_SEND (a, _bfd_coff_swap_aux_in, (a,e,t,c,i))
428 .#define bfd_coff_swap_sym_in(a,e,i) \
429 . BFD_SEND (a, _bfd_coff_swap_sym_in, (a,e,i))
431 .#define bfd_coff_swap_lineno_in(a,e,i) \
432 . BFD_SEND ( a, _bfd_coff_swap_lineno_in, (a,e,i))
434 .#define bfd_set_arch_mach(abfd, arch, mach)\
435 . BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
437 .#define bfd_coff_swap_reloc_out(abfd, i, o) \
438 . BFD_SEND (abfd, _bfd_coff_swap_reloc_out, (abfd, i, o))
440 .#define bfd_coff_swap_lineno_out(abfd, i, o) \
441 . BFD_SEND (abfd, _bfd_coff_swap_lineno_out, (abfd, i, o))
443 .#define bfd_coff_swap_aux_out(abfd, i, t,c,o) \
444 . BFD_SEND (abfd, _bfd_coff_swap_aux_out, (abfd, i,t,c, o))
446 .#define bfd_coff_swap_sym_out(abfd, i,o) \
447 . BFD_SEND (abfd, _bfd_coff_swap_sym_out, (abfd, i, o))
449 .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
450 . BFD_SEND (abfd, _bfd_coff_swap_scnhdr_out, (abfd, i, o))
452 .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
453 . BFD_SEND (abfd, _bfd_coff_swap_filehdr_out, (abfd, i, o))
455 .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
456 . BFD_SEND (abfd, _bfd_coff_swap_aouthdr_out, (abfd, i, o))