1 /* Generic BFD library interface and support routines.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program 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 2 of the License, or
12 (at your option) any later version.
14 This program 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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 A BFD has type <<bfd>>; objects of this type are the
28 cornerstone of any application using BFD. Using BFD
29 consists of making references though the BFD and to data in the BFD.
31 Here is the structure that defines the type <<bfd>>. It
32 contains the major data about the file and pointers
33 to the rest of the data.
39 . {* A unique identifier of the BFD *}
42 . {* The filename the application opened the BFD with. *}
43 . const char *filename;
45 . {* A pointer to the target jump table. *}
46 . const struct bfd_target *xvec;
48 . {* To avoid dragging too many header files into every file that
49 . includes `<<bfd.h>>', IOSTREAM has been declared as a "char *",
50 . and MTIME as a "long". Their correct types, to which they
51 . are cast when used, are "FILE *" and "time_t". The iostream
52 . is the result of an fopen on the filename. However, if the
53 . BFD_IN_MEMORY flag is set, then iostream is actually a pointer
54 . to a bfd_in_memory struct. *}
57 . {* Is the file descriptor being cached? That is, can it be closed as
58 . needed, and re-opened when accessed later? *}
59 . bfd_boolean cacheable;
61 . {* Marks whether there was a default target specified when the
62 . BFD was opened. This is used to select which matching algorithm
63 . to use to choose the back end. *}
64 . bfd_boolean target_defaulted;
66 . {* The caching routines use these to maintain a
67 . least-recently-used list of BFDs. *}
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... *}
74 . {* ... and here: (``once'' means at least once). *}
75 . bfd_boolean opened_once;
77 . {* Set if we have a locally maintained mtime value, rather than
78 . getting it from the file each time. *}
79 . bfd_boolean mtime_set;
81 . {* File modified time, if mtime_set is TRUE. *}
84 . {* Reserved for an unimplemented file locking extension. *}
87 . {* The format which belongs to the BFD. (object, core, etc.) *}
90 . {* The direction with which the BFD was opened. *}
95 . write_direction = 2,
100 . {* Format_specific flags. *}
103 . {* Currently my_archive is tested before adding origin to
104 . anything. I believe that this can become always an add of
105 . origin, with origin set to 0 for non archive files. *}
108 . {* Remember when output has begun, to stop strange things
110 . bfd_boolean output_has_begun;
112 . {* A hash table for section names. *}
113 . struct bfd_hash_table section_htab;
115 . {* Pointer to linked list of sections. *}
116 . struct sec *sections;
118 . {* The place where we add to the section list. *}
119 . struct sec **section_tail;
121 . {* The number of sections. *}
122 . unsigned int section_count;
124 . {* Stuff only useful for object files:
125 . The start address. *}
126 . bfd_vma start_address;
128 . {* Used for input and output. *}
129 . unsigned int symcount;
131 . {* Symbol table for output BFD (with symcount entries). *}
132 . struct symbol_cache_entry **outsymbols;
134 . {* Used for slurped dynamic symbol tables. *}
135 . unsigned int dynsymcount;
137 . {* Pointer to structure which contains architecture information. *}
138 . const struct bfd_arch_info *arch_info;
140 . {* Stuff only useful for archives. *}
142 . struct bfd *my_archive; {* The containing archive BFD. *}
143 . struct bfd *next; {* The next BFD in the archive. *}
144 . struct bfd *archive_head; {* The first BFD in the archive. *}
145 . bfd_boolean has_armap;
147 . {* A chain of BFD structures involved in a link. *}
148 . struct bfd *link_next;
150 . {* A field used by _bfd_generic_link_add_archive_symbols. This will
151 . be used only for archive elements. *}
154 . {* Used by the back end to hold private data. *}
157 . struct aout_data_struct *aout_data;
158 . struct artdata *aout_ar_data;
159 . struct _oasys_data *oasys_obj_data;
160 . struct _oasys_ar_data *oasys_ar_data;
161 . struct coff_tdata *coff_obj_data;
162 . struct pe_tdata *pe_obj_data;
163 . struct xcoff_tdata *xcoff_obj_data;
164 . struct ecoff_tdata *ecoff_obj_data;
165 . struct ieee_data_struct *ieee_data;
166 . struct ieee_ar_data_struct *ieee_ar_data;
167 . struct srec_data_struct *srec_data;
168 . struct ihex_data_struct *ihex_data;
169 . struct tekhex_data_struct *tekhex_data;
170 . struct elf_obj_tdata *elf_obj_data;
171 . struct nlm_obj_tdata *nlm_obj_data;
172 . struct bout_data_struct *bout_data;
173 . struct mmo_data_struct *mmo_data;
174 . struct sun_core_struct *sun_core_data;
175 . struct sco5_core_struct *sco5_core_data;
176 . struct trad_core_struct *trad_core_data;
177 . struct som_data_struct *som_data;
178 . struct hpux_core_struct *hpux_core_data;
179 . struct hppabsd_core_struct *hppabsd_core_data;
180 . struct sgi_core_struct *sgi_core_data;
181 . struct lynx_core_struct *lynx_core_data;
182 . struct osf_core_struct *osf_core_data;
183 . struct cisco_core_struct *cisco_core_data;
184 . struct versados_data_struct *versados_data;
185 . struct netbsd_core_struct *netbsd_core_data;
186 . struct mach_o_data_struct *mach_o_data;
187 . struct mach_o_fat_data_struct *mach_o_fat_data;
188 . struct bfd_pef_data_struct *pef_data;
189 . struct bfd_pef_xlib_data_struct *pef_xlib_data;
190 . struct bfd_sym_data_struct *sym_data;
195 . {* Used by the application to hold private data. *}
198 . {* Where all the allocated stuff under this BFD goes. This is a
199 . struct objalloc *, but we use PTR to avoid requiring the inclusion of
210 #ifdef ANSI_PROTOTYPES
216 #include "libiberty.h"
217 #include "safe-ctype.h"
220 #include "coff/internal.h"
221 #include "coff/sym.h"
223 #include "libecoff.h"
227 /* provide storage for subsystem, stack and heap data which may have been
228 passed in on the command line. Ld puts this data into a bfd_link_info
229 struct which ultimately gets passed in to the bfd. When it arrives, copy
230 it to the following struct so that the data will be available in coffcode.h
231 where it is needed. The typedef's used are defined in bfd.h */
237 Most BFD functions return nonzero on success (check their
238 individual documentation for precise semantics). On an error,
239 they call <<bfd_set_error>> to set an error condition that callers
240 can check by calling <<bfd_get_error>>.
241 If that returns <<bfd_error_system_call>>, then check
244 The easiest way to report a BFD error to the user is to
248 Type <<bfd_error_type>>
250 The values returned by <<bfd_get_error>> are defined by the
251 enumerated type <<bfd_error_type>>.
255 .typedef enum bfd_error
257 . bfd_error_no_error = 0,
258 . bfd_error_system_call,
259 . bfd_error_invalid_target,
260 . bfd_error_wrong_format,
261 . bfd_error_wrong_object_format,
262 . bfd_error_invalid_operation,
263 . bfd_error_no_memory,
264 . bfd_error_no_symbols,
265 . bfd_error_no_armap,
266 . bfd_error_no_more_archived_files,
267 . bfd_error_malformed_archive,
268 . bfd_error_file_not_recognized,
269 . bfd_error_file_ambiguously_recognized,
270 . bfd_error_no_contents,
271 . bfd_error_nonrepresentable_section,
272 . bfd_error_no_debug_section,
273 . bfd_error_bad_value,
274 . bfd_error_file_truncated,
275 . bfd_error_file_too_big,
276 . bfd_error_invalid_error_code
282 static bfd_error_type bfd_error
= bfd_error_no_error
;
284 const char *const bfd_errmsgs
[] =
287 N_("System call error"),
288 N_("Invalid bfd target"),
289 N_("File in wrong format"),
290 N_("Archive object file in wrong format"),
291 N_("Invalid operation"),
292 N_("Memory exhausted"),
294 N_("Archive has no index; run ranlib to add one"),
295 N_("No more archived files"),
296 N_("Malformed archive"),
297 N_("File format not recognized"),
298 N_("File format is ambiguous"),
299 N_("Section has no contents"),
300 N_("Nonrepresentable section on output"),
301 N_("Symbol needs debug section which does not exist"),
303 N_("File truncated"),
305 N_("#<Invalid error code>")
313 bfd_error_type bfd_get_error (void);
316 Return the current BFD error condition.
330 void bfd_set_error (bfd_error_type error_tag);
333 Set the BFD error condition to be @var{error_tag}.
337 bfd_set_error (error_tag
)
338 bfd_error_type error_tag
;
340 bfd_error
= error_tag
;
348 const char *bfd_errmsg (bfd_error_type error_tag);
351 Return a string describing the error @var{error_tag}, or
352 the system error if @var{error_tag} is <<bfd_error_system_call>>.
356 bfd_errmsg (error_tag
)
357 bfd_error_type error_tag
;
362 if (error_tag
== bfd_error_system_call
)
363 return xstrerror (errno
);
365 if ((((int) error_tag
< (int) bfd_error_no_error
) ||
366 ((int) error_tag
> (int) bfd_error_invalid_error_code
)))
367 error_tag
= bfd_error_invalid_error_code
;/* sanity check */
369 return _(bfd_errmsgs
[(int)error_tag
]);
377 void bfd_perror (const char *message);
380 Print to the standard error stream a string describing the
381 last BFD error that occurred, or the last system error if
382 the last BFD error was a system call failure. If @var{message}
383 is non-NULL and non-empty, the error string printed is preceded
384 by @var{message}, a colon, and a space. It is followed by a newline.
391 if (bfd_get_error () == bfd_error_system_call
)
392 /* Must be a system error then. */
393 perror ((char *)message
);
396 if (message
== NULL
|| *message
== '\0')
397 fprintf (stderr
, "%s\n", bfd_errmsg (bfd_get_error ()));
399 fprintf (stderr
, "%s: %s\n", message
, bfd_errmsg (bfd_get_error ()));
407 Some BFD functions want to print messages describing the
408 problem. They call a BFD error handler function. This
409 function may be overriden by the program.
411 The BFD error handler acts like printf.
415 .typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
419 /* The program name used when printing BFD error messages. */
421 static const char *_bfd_error_program_name
;
423 /* This is the default routine to handle BFD error messages. */
425 static void _bfd_default_error_handler
PARAMS ((const char *s
, ...));
428 _bfd_default_error_handler
VPARAMS ((const char *s
, ...))
430 if (_bfd_error_program_name
!= NULL
)
431 fprintf (stderr
, "%s: ", _bfd_error_program_name
);
433 fprintf (stderr
, "BFD: ");
436 VA_FIXEDARG (p
, const char *, s
);
437 vfprintf (stderr
, s
, p
);
440 fprintf (stderr
, "\n");
443 /* This is a function pointer to the routine which should handle BFD
444 error messages. It is called when a BFD routine encounters an
445 error for which it wants to print a message. Going through a
446 function pointer permits a program linked against BFD to intercept
447 the messages and deal with them itself. */
449 bfd_error_handler_type _bfd_error_handler
= _bfd_default_error_handler
;
453 bfd_set_error_handler
456 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
459 Set the BFD error handler function. Returns the previous
463 bfd_error_handler_type
464 bfd_set_error_handler (pnew
)
465 bfd_error_handler_type pnew
;
467 bfd_error_handler_type pold
;
469 pold
= _bfd_error_handler
;
470 _bfd_error_handler
= pnew
;
476 bfd_set_error_program_name
479 void bfd_set_error_program_name (const char *);
482 Set the program name to use when printing a BFD error. This
483 is printed before the error message followed by a colon and
484 space. The string must not be changed after it is passed to
489 bfd_set_error_program_name (name
)
492 _bfd_error_program_name
= name
;
497 bfd_get_error_handler
500 bfd_error_handler_type bfd_get_error_handler (void);
503 Return the BFD error handler function.
506 bfd_error_handler_type
507 bfd_get_error_handler ()
509 return _bfd_error_handler
;
517 const char *bfd_archive_filename (bfd *);
520 For a BFD that is a component of an archive, returns a string
521 with both the archive name and file name. For other BFDs, just
522 returns the file name.
526 bfd_archive_filename (abfd
)
529 if (abfd
->my_archive
)
531 static size_t curr
= 0;
535 needed
= (strlen (bfd_get_filename (abfd
->my_archive
))
536 + strlen (bfd_get_filename (abfd
)) + 3);
541 curr
= needed
+ (needed
>> 1);
542 buf
= bfd_malloc ((bfd_size_type
) curr
);
543 /* If we can't malloc, fail safe by returning just the file
544 name. This function is only used when building error
549 return bfd_get_filename (abfd
);
552 sprintf (buf
, "%s(%s)", bfd_get_filename (abfd
->my_archive
),
553 bfd_get_filename (abfd
));
557 return bfd_get_filename (abfd
);
567 bfd_get_reloc_upper_bound
570 long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
573 Return the number of bytes required to store the
574 relocation information associated with section @var{sect}
575 attached to bfd @var{abfd}. If an error occurs, return -1.
580 bfd_get_reloc_upper_bound (abfd
, asect
)
584 if (abfd
->format
!= bfd_object
)
586 bfd_set_error (bfd_error_invalid_operation
);
590 return BFD_SEND (abfd
, _get_reloc_upper_bound
, (abfd
, asect
));
595 bfd_canonicalize_reloc
598 long bfd_canonicalize_reloc
605 Call the back end associated with the open BFD
606 @var{abfd} and translate the external form of the relocation
607 information attached to @var{sec} into the internal canonical
608 form. Place the table into memory at @var{loc}, which has
609 been preallocated, usually by a call to
610 <<bfd_get_reloc_upper_bound>>. Returns the number of relocs, or
613 The @var{syms} table is also needed for horrible internal magic
618 bfd_canonicalize_reloc (abfd
, asect
, location
, symbols
)
624 if (abfd
->format
!= bfd_object
)
626 bfd_set_error (bfd_error_invalid_operation
);
630 return BFD_SEND (abfd
, _bfd_canonicalize_reloc
,
631 (abfd
, asect
, location
, symbols
));
640 (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
643 Set the relocation pointer and count within
644 section @var{sec} to the values @var{rel} and @var{count}.
645 The argument @var{abfd} is ignored.
650 bfd_set_reloc (ignore_abfd
, asect
, location
, count
)
651 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
656 asect
->orelocation
= location
;
657 asect
->reloc_count
= count
;
665 bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
668 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
671 o <<bfd_error_wrong_format>> - The target bfd was not of object format.
672 o <<bfd_error_invalid_operation>> - The target bfd was open for reading.
673 o <<bfd_error_invalid_operation>> -
674 The flag word contained a bit which was not applicable to the
675 type of file. E.g., an attempt was made to set the <<D_PAGED>> bit
676 on a BFD format which does not support demand paging.
681 bfd_set_file_flags (abfd
, flags
)
685 if (abfd
->format
!= bfd_object
)
687 bfd_set_error (bfd_error_wrong_format
);
691 if (bfd_read_p (abfd
))
693 bfd_set_error (bfd_error_invalid_operation
);
697 bfd_get_file_flags (abfd
) = flags
;
698 if ((flags
& bfd_applicable_file_flags (abfd
)) != flags
)
700 bfd_set_error (bfd_error_invalid_operation
);
708 bfd_assert (file
, line
)
712 (*_bfd_error_handler
) (_("BFD %s assertion fail %s:%d"),
713 BFD_VERSION_STRING
, file
, line
);
716 /* A more or less friendly abort message. In libbfd.h abort is
717 defined to call this function. */
720 #define EXIT_FAILURE 1
724 _bfd_abort (file
, line
, fn
)
730 (*_bfd_error_handler
)
731 (_("BFD %s internal error, aborting at %s line %d in %s\n"),
732 BFD_VERSION_STRING
, file
, line
, fn
);
734 (*_bfd_error_handler
)
735 (_("BFD %s internal error, aborting at %s line %d\n"),
736 BFD_VERSION_STRING
, file
, line
);
737 (*_bfd_error_handler
) (_("Please report this bug.\n"));
738 xexit (EXIT_FAILURE
);
746 int bfd_get_arch_size (bfd *abfd);
749 Returns the architecture address size, in bits, as determined
750 by the object file's format. For ELF, this information is
751 included in the header.
754 Returns the arch size in bits if known, <<-1>> otherwise.
758 bfd_get_arch_size (abfd
)
761 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
)
762 return (get_elf_backend_data (abfd
))->s
->arch_size
;
769 bfd_get_sign_extend_vma
772 int bfd_get_sign_extend_vma (bfd *abfd);
775 Indicates if the target architecture "naturally" sign extends
776 an address. Some architectures implicitly sign extend address
777 values when they are converted to types larger than the size
778 of an address. For instance, bfd_get_start_address() will
779 return an address sign extended to fill a bfd_vma when this is
783 Returns <<1>> if the target architecture is known to sign
784 extend addresses, <<0>> if the target architecture is known to
785 not sign extend addresses, and <<-1>> otherwise.
789 bfd_get_sign_extend_vma (abfd
)
794 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
795 return (get_elf_backend_data (abfd
)->sign_extend_vma
);
797 name
= bfd_get_target (abfd
);
799 /* Return a proper value for DJGPP COFF (an x86 COFF variant).
800 This function is required for DWARF2 support, but there is
801 no place to store this information in the COFF back end.
802 Should enough other COFF targets add support for DWARF2,
803 a place will have to be found. Until then, this hack will do. */
804 if (strncmp (name
, "coff-go32", sizeof ("coff-go32") - 1) == 0)
807 bfd_set_error (bfd_error_wrong_format
);
813 bfd_set_start_address
816 bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
819 Make @var{vma} the entry point of output BFD @var{abfd}.
822 Returns <<TRUE>> on success, <<FALSE>> otherwise.
826 bfd_set_start_address (abfd
, vma
)
830 abfd
->start_address
= vma
;
839 unsigned int bfd_get_gp_size (bfd *abfd);
842 Return the maximum size of objects to be optimized using the GP
843 register under MIPS ECOFF. This is typically set by the <<-G>>
844 argument to the compiler, assembler or linker.
848 bfd_get_gp_size (abfd
)
851 if (abfd
->format
== bfd_object
)
853 if (abfd
->xvec
->flavour
== bfd_target_ecoff_flavour
)
854 return ecoff_data (abfd
)->gp_size
;
855 else if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
)
856 return elf_gp_size (abfd
);
866 void bfd_set_gp_size (bfd *abfd, unsigned int i);
869 Set the maximum size of objects to be optimized using the GP
870 register under ECOFF or MIPS ELF. This is typically set by
871 the <<-G>> argument to the compiler, assembler or linker.
875 bfd_set_gp_size (abfd
, i
)
879 /* Don't try to set GP size on an archive or core file! */
880 if (abfd
->format
!= bfd_object
)
883 if (abfd
->xvec
->flavour
== bfd_target_ecoff_flavour
)
884 ecoff_data (abfd
)->gp_size
= i
;
885 else if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
)
886 elf_gp_size (abfd
) = i
;
889 /* Get the GP value. This is an internal function used by some of the
890 relocation special_function routines on targets which support a GP
894 _bfd_get_gp_value (abfd
)
897 if (abfd
->format
!= bfd_object
)
900 if (abfd
->xvec
->flavour
== bfd_target_ecoff_flavour
)
901 return ecoff_data (abfd
)->gp
;
902 else if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
)
903 return elf_gp (abfd
);
908 /* Set the GP value. */
911 _bfd_set_gp_value (abfd
, v
)
915 if (abfd
->format
!= bfd_object
)
918 if (abfd
->xvec
->flavour
== bfd_target_ecoff_flavour
)
919 ecoff_data (abfd
)->gp
= v
;
920 else if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
)
929 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
932 Convert, like <<strtoul>>, a numerical expression
933 @var{string} into a <<bfd_vma>> integer, and return that integer.
934 (Though without as many bells and whistles as <<strtoul>>.)
935 The expression is assumed to be unsigned (i.e., positive).
936 If given a @var{base}, it is used as the base for conversion.
937 A base of 0 causes the function to interpret the string
938 in hex if a leading "0x" or "0X" is found, otherwise
939 in octal if a leading zero is found, otherwise in decimal.
941 If the value would overflow, the maximum <<bfd_vma>> value is
946 bfd_scan_vma (string
, end
, base
)
956 /* Let the host do it if possible. */
957 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
958 return (bfd_vma
) strtoul (string
, (char **) end
, base
);
962 if (string
[0] == '0')
964 if ((string
[1] == 'x') || (string
[1] == 'X'))
971 if ((base
< 2) || (base
> 36))
976 && (string
[1] == 'x' || string
[1] == 'X')
977 && ISXDIGIT (string
[2]))
982 cutoff
= (~ (bfd_vma
) 0) / (bfd_vma
) base
;
983 cutlim
= (~ (bfd_vma
) 0) % (bfd_vma
) base
;
993 else if (ISALPHA (digit
))
994 digit
= TOUPPER (digit
) - 'A' + 10;
997 if (digit
>= (unsigned int) base
)
999 if (value
> cutoff
|| (value
== cutoff
&& digit
> cutlim
))
1001 value
= value
* base
+ digit
;
1006 value
= ~ (bfd_vma
) 0;
1016 bfd_copy_private_bfd_data
1019 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
1022 Copy private BFD information from the BFD @var{ibfd} to the
1023 the BFD @var{obfd}. Return <<TRUE>> on success, <<FALSE>> on error.
1024 Possible error returns are:
1026 o <<bfd_error_no_memory>> -
1027 Not enough memory exists to create private data for @var{obfd}.
1029 .#define bfd_copy_private_bfd_data(ibfd, obfd) \
1030 . BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
1037 bfd_merge_private_bfd_data
1040 bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
1043 Merge private BFD information from the BFD @var{ibfd} to the
1044 the output file BFD @var{obfd} when linking. Return <<TRUE>>
1045 on success, <<FALSE>> on error. Possible error returns are:
1047 o <<bfd_error_no_memory>> -
1048 Not enough memory exists to create private data for @var{obfd}.
1050 .#define bfd_merge_private_bfd_data(ibfd, obfd) \
1051 . BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
1058 bfd_set_private_flags
1061 bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
1064 Set private BFD flag information in the BFD @var{abfd}.
1065 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
1068 o <<bfd_error_no_memory>> -
1069 Not enough memory exists to create private data for @var{obfd}.
1071 .#define bfd_set_private_flags(abfd, flags) \
1072 . BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
1081 The following functions exist but have not yet been documented.
1083 .#define bfd_sizeof_headers(abfd, reloc) \
1084 . BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
1086 .#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
1087 . BFD_SEND (abfd, _bfd_find_nearest_line, \
1088 . (abfd, sec, syms, off, file, func, line))
1090 .#define bfd_debug_info_start(abfd) \
1091 . BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
1093 .#define bfd_debug_info_end(abfd) \
1094 . BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
1096 .#define bfd_debug_info_accumulate(abfd, section) \
1097 . BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
1099 .#define bfd_stat_arch_elt(abfd, stat) \
1100 . BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
1102 .#define bfd_update_armap_timestamp(abfd) \
1103 . BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
1105 .#define bfd_set_arch_mach(abfd, arch, mach)\
1106 . BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
1108 .#define bfd_relax_section(abfd, section, link_info, again) \
1109 . BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
1111 .#define bfd_gc_sections(abfd, link_info) \
1112 . BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
1114 .#define bfd_merge_sections(abfd, link_info) \
1115 . BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
1117 .#define bfd_discard_group(abfd, sec) \
1118 . BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
1120 .#define bfd_link_hash_table_create(abfd) \
1121 . BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
1123 .#define bfd_link_hash_table_free(abfd, hash) \
1124 . BFD_SEND (abfd, _bfd_link_hash_table_free, (hash))
1126 .#define bfd_link_add_symbols(abfd, info) \
1127 . BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
1129 .#define bfd_link_just_syms(sec, info) \
1130 . BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
1132 .#define bfd_final_link(abfd, info) \
1133 . BFD_SEND (abfd, _bfd_final_link, (abfd, info))
1135 .#define bfd_free_cached_info(abfd) \
1136 . BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
1138 .#define bfd_get_dynamic_symtab_upper_bound(abfd) \
1139 . BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
1141 .#define bfd_print_private_bfd_data(abfd, file)\
1142 . BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
1144 .#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
1145 . BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
1147 .#define bfd_get_dynamic_reloc_upper_bound(abfd) \
1148 . BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
1150 .#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
1151 . BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
1153 .extern bfd_byte *bfd_get_relocated_section_contents
1154 . PARAMS ((bfd *, struct bfd_link_info *,
1155 . struct bfd_link_order *, bfd_byte *,
1156 . bfd_boolean, asymbol **));
1162 bfd_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
1163 relocateable
, symbols
)
1165 struct bfd_link_info
*link_info
;
1166 struct bfd_link_order
*link_order
;
1168 bfd_boolean relocateable
;
1172 bfd_byte
*(*fn
) PARAMS ((bfd
*, struct bfd_link_info
*,
1173 struct bfd_link_order
*, bfd_byte
*, bfd_boolean
,
1176 if (link_order
->type
== bfd_indirect_link_order
)
1178 abfd2
= link_order
->u
.indirect
.section
->owner
;
1185 fn
= abfd2
->xvec
->_bfd_get_relocated_section_contents
;
1187 return (*fn
) (abfd
, link_info
, link_order
, data
, relocateable
, symbols
);
1190 /* Record information about an ELF program header. */
1193 bfd_record_phdr (abfd
, type
, flags_valid
, flags
, at_valid
, at
,
1194 includes_filehdr
, includes_phdrs
, count
, secs
)
1197 bfd_boolean flags_valid
;
1199 bfd_boolean at_valid
;
1201 bfd_boolean includes_filehdr
;
1202 bfd_boolean includes_phdrs
;
1206 struct elf_segment_map
*m
, **pm
;
1209 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
)
1212 amt
= sizeof (struct elf_segment_map
);
1213 amt
+= ((bfd_size_type
) count
- 1) * sizeof (asection
*);
1214 m
= (struct elf_segment_map
*) bfd_alloc (abfd
, amt
);
1222 m
->p_flags_valid
= (unsigned int) flags_valid
;
1223 m
->p_paddr_valid
= (unsigned int) at_valid
;
1224 m
->includes_filehdr
= (unsigned int) includes_filehdr
;
1225 m
->includes_phdrs
= (unsigned int) includes_phdrs
;
1228 memcpy (m
->sections
, secs
, count
* sizeof (asection
*));
1230 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
1238 bfd_sprintf_vma (abfd
, buf
, value
)
1243 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
1244 get_elf_backend_data (abfd
)->elf_backend_sprintf_vma (abfd
, buf
, value
);
1246 sprintf_vma (buf
, value
);
1250 bfd_fprintf_vma (abfd
, stream
, value
)
1255 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
1256 get_elf_backend_data (abfd
)->elf_backend_fprintf_vma (abfd
, stream
, value
);
1258 fprintf_vma ((FILE *) stream
, value
);
1266 bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
1270 When more than one machine code number is available for the
1271 same machine type, this function can be used to switch between
1272 the preferred one (alternative == 0) and any others. Currently,
1273 only ELF supports this feature, with up to two alternate
1278 bfd_alt_mach_code (abfd
, alternative
)
1282 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
1286 switch (alternative
)
1289 code
= get_elf_backend_data (abfd
)->elf_machine_code
;
1293 code
= get_elf_backend_data (abfd
)->elf_machine_alt1
;
1299 code
= get_elf_backend_data (abfd
)->elf_machine_alt2
;
1308 elf_elfheader (abfd
)->e_machine
= code
;
1319 .struct bfd_preserve
1324 . const struct bfd_arch_info *arch_info;
1325 . struct sec *sections;
1326 . struct sec **section_tail;
1327 . unsigned int section_count;
1328 . struct bfd_hash_table section_htab;
1338 bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
1341 When testing an object for compatibility with a particular
1342 target back-end, the back-end object_p function needs to set
1343 up certain fields in the bfd on successfully recognizing the
1344 object. This typically happens in a piecemeal fashion, with
1345 failures possible at many points. On failure, the bfd is
1346 supposed to be restored to its initial state, which is
1347 virtually impossible. However, restoring a subset of the bfd
1348 state works in practice. This function stores the subset and
1349 reinitializes the bfd.
1354 bfd_preserve_save (abfd
, preserve
)
1356 struct bfd_preserve
*preserve
;
1358 preserve
->tdata
= abfd
->tdata
.any
;
1359 preserve
->arch_info
= abfd
->arch_info
;
1360 preserve
->flags
= abfd
->flags
;
1361 preserve
->sections
= abfd
->sections
;
1362 preserve
->section_tail
= abfd
->section_tail
;
1363 preserve
->section_count
= abfd
->section_count
;
1364 preserve
->section_htab
= abfd
->section_htab
;
1366 if (! bfd_hash_table_init (&abfd
->section_htab
, bfd_section_hash_newfunc
))
1369 abfd
->tdata
.any
= NULL
;
1370 abfd
->arch_info
= &bfd_default_arch_struct
;
1371 abfd
->flags
&= BFD_IN_MEMORY
;
1372 abfd
->sections
= NULL
;
1373 abfd
->section_tail
= &abfd
->sections
;
1374 abfd
->section_count
= 0;
1381 bfd_preserve_restore
1384 void bfd_preserve_restore (bfd *, struct bfd_preserve *);
1387 This function restores bfd state saved by bfd_preserve_save.
1388 If MARKER is non-NULL in struct bfd_preserve then that block
1389 and all subsequently bfd_alloc'd memory is freed.
1394 bfd_preserve_restore (abfd
, preserve
)
1396 struct bfd_preserve
*preserve
;
1398 bfd_hash_table_free (&abfd
->section_htab
);
1400 abfd
->tdata
.any
= preserve
->tdata
;
1401 abfd
->arch_info
= preserve
->arch_info
;
1402 abfd
->flags
= preserve
->flags
;
1403 abfd
->section_htab
= preserve
->section_htab
;
1404 abfd
->sections
= preserve
->sections
;
1405 abfd
->section_tail
= preserve
->section_tail
;
1406 abfd
->section_count
= preserve
->section_count
;
1408 /* bfd_release frees all memory more recently bfd_alloc'd than
1409 its arg, as well as its arg. */
1410 if (preserve
->marker
!= NULL
)
1412 bfd_release (abfd
, preserve
->marker
);
1413 preserve
->marker
= NULL
;
1422 void bfd_preserve_finish (bfd *, struct bfd_preserve *);
1425 This function should be called when the bfd state saved by
1426 bfd_preserve_save is no longer needed. ie. when the back-end
1427 object_p function returns with success.
1432 bfd_preserve_finish (abfd
, preserve
)
1433 bfd
*abfd ATTRIBUTE_UNUSED
;
1434 struct bfd_preserve
*preserve
;
1436 /* It would be nice to be able to free more memory here, eg. old
1437 tdata, but that's not possible since these blocks are sitting
1438 inside bfd_alloc'd memory. The section hash is on a separate
1440 bfd_hash_table_free (&preserve
->section_htab
);