1 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
3 This file is part of BFD, the Binary File Diddler.
5 BFD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
10 BFD is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with BFD; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 Pointers to bfd structs are the cornerstone of any application using
26 libbfd. References though the bfd and to data in the bfd give the
27 entire bfd functionality.
29 Finally! The BFD struct itself. This contains the major data about
30 the file, and contains pointers to the rest of the data.
36 The filename the application opened the bfd with.
38 $ CONST char *filename;
40 A pointer to the target jump table.
42 $ struct bfd_target *xvec;
45 To avoid dragging too many header files into every file that
46 includes bfd.h, IOSTREAM has been declared as a "char *", and MTIME
47 as a "long". Their correct types, to which they are cast when used,
48 are "FILE *" and "time_t".
50 The iostream is the result of an fopen on the filename.
54 Is the file being cached @xref{File Caching}.
58 Marks whether there was a default target specified when the bfd was
59 opened. This is used to select what matching algorithm to use to chose
62 $ boolean target_defaulted;
64 The caching routines use these to maintain an LRU list of bfds.
66 $ struct _bfd *lru_prev, *lru_next;
68 When a file is closed by the caching routines, it retains the state
75 $ boolean opened_once;
82 For output files, channel we locked (is this used?).
86 The format which belongs to the bfd.
90 The direction the bfd was opened with
92 $ enum bfd_direction {no_direction = 0,
94 $ write_direction = 2,
95 $ both_direction = 3} direction;
101 Currently my_archive is tested before adding origin to anything. I
102 believe that this can become always an add of origin, with origin set
103 to 0 for non archive files.
107 Remember when output has begun, to stop strange things happening.
109 $ boolean output_has_begun;
111 Pointer to linked list of sections
113 $ struct sec *sections;
115 The number of sections
117 $ unsigned int section_count;
119 Stuff only usefull for object files:
122 $ bfd_vma start_address;
123 Used for input and output
125 $ unsigned int symcount;
126 Symtab for output bfd
128 $ struct symbol_cache_entry **outsymbols;
130 Architecture of object machine, eg m68k
132 $ enum bfd_architecture obj_arch;
134 Particular machine within arch, e.g. 68010
136 $ unsigned long obj_machine;
138 Stuff only usefull for archives:
141 $ struct _bfd *my_archive;
143 $ struct _bfd *archive_head;
146 Used by the back end to hold private data.
150 Used by the application to hold private data
154 Where all the allocated stuff under this BFD goes
156 $ struct obstack memory;
167 short _bfd_host_big_endian = 0x0100;
168 /* Accessing the above as (*(char*)&_bfd_host_big_endian), will
169 return 1 if the host is big-endian, 0 otherwise.
170 (assuming that a short is two bytes long!!! FIXME)
171 (See HOST_IS_BIG_ENDIAN_P in bfd.h.) */
174 o - Most functions return nonzero on success (check doc for
175 precise semantics); 0 or NULL on error.
176 o - Internal errors are documented by the value of bfd_error.
177 If that is system_call_error then check errno.
178 o - The easiest way to report this to the user is to use bfd_perror.
181 bfd_ec bfd_error = no_error;
183 char *bfd_errmsgs[] = { "No error",
186 "File in wrong format",
190 "No relocation info",
191 "No more archived files",
194 "File format not recognized",
195 "File format is ambiguous",
196 "Section has no contents",
197 "Nonrepresentable section on output",
198 "#<Invalid error code>"
203 DEFUN(bfd_nonrepresentable_section,(abfd, name),
204 CONST bfd * CONST abfd AND
205 CONST char * CONST name)
207 printf("bfd error writing file %s, format %s can't represent section %s\n",
214 bfd_error_vector_type bfd_error_vector =
216 bfd_nonrepresentable_section
219 #if 1 || !defined(ANSI_LIBRARIES) && !defined(__STDC__)
225 extern char *sys_errlist[];
227 return (((code < 0) || (code >= sys_nerr)) ? "(unknown error)" :
230 #endif /* not ANSI_LIBRARIES */
234 bfd_errmsg (error_tag)
240 if (error_tag == system_call_error)
241 return strerror (errno);
243 if ((((int)error_tag <(int) no_error) ||
244 ((int)error_tag > (int)invalid_error_code)))
245 error_tag = invalid_error_code;/* sanity check */
247 return bfd_errmsgs [(int)error_tag];
251 void bfd_default_error_trap(error_tag)
254 printf("bfd assert fail (%s)\n", bfd_errmsg(error_tag));
257 void (*bfd_error_trap)() = bfd_default_error_trap;
258 void (*bfd_error_nonrepresentabltrap)() = bfd_default_error_trap;
261 DEFUN(bfd_perror,(message),
264 if (bfd_error == system_call_error)
265 perror((char *)message); /* must be system error then... */
267 if (message == NULL || *message == '\0')
268 fprintf (stderr, "%s\n", bfd_errmsg (bfd_error));
270 fprintf (stderr, "%s: %s\n", message, bfd_errmsg (bfd_error));
277 /* returns the number of octets of storage required */
280 get_reloc_upper_bound (abfd, asect)
284 if (abfd->format != bfd_object) {
285 bfd_error = invalid_operation;
289 return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect));
293 bfd_canonicalize_reloc (abfd, asect, location, symbols)
299 if (abfd->format != bfd_object) {
300 bfd_error = invalid_operation;
304 return BFD_SEND (abfd, _bfd_canonicalize_reloc, (abfd, asect, location, symbols));
309 bfd_set_file_flags (abfd, flags)
313 if (abfd->format != bfd_object) {
314 bfd_error = wrong_format;
318 if (bfd_read_p (abfd)) {
319 bfd_error = invalid_operation;
323 if ((flags & bfd_applicable_file_flags (abfd)) != flags) {
324 bfd_error = invalid_operation;
328 bfd_get_file_flags (abfd) = flags;
334 bfd_set_reloc (ignore_abfd, asect, location, count)
340 asect->orelocation = location;
341 asect->reloc_count = count;
345 bfd_assert(file, line)
349 printf("bfd assertion fail %s:%d\n",file,line);
353 /*proto* bfd_set_start_address
355 Marks the entry point of an output bfd. Returns @code{true} on
356 success, @code{false} otherwise.
358 *; PROTO(boolean, bfd_set_start_address,(bfd *, bfd_vma));
362 bfd_set_start_address(abfd, vma)
366 abfd->start_address = vma;
371 /*proto* bfd_get_mtime
373 Return cached file modification time (e.g. as read from archive header
374 for archive members, or from file system if we have been called
375 before); else determine modify time, cache it, and return it.
377 *; PROTO(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;
403 #define bfd_sizeof_headers(abfd, reloc) \
404 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
406 #define bfd_find_nearest_line(abfd, section, symbols, offset, filename_ptr, func, line_ptr) \
407 BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, section, symbols, offset, filename_ptr, func, line_ptr))
409 #define bfd_debug_info_start(abfd) \
410 BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
412 #define bfd_debug_info_end(abfd) \
413 BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
415 #define bfd_debug_info_accumulate(abfd, section) \
416 BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
418 #define bfd_stat_arch_elt(abfd, stat) \
419 BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))