/* Generic BFD library interface and support routines.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Free Software Foundation, Inc.
Written by Cygnus Support.
CODE_FRAGMENT
.
+.enum bfd_direction
+. {
+. no_direction = 0,
+. read_direction = 1,
+. write_direction = 2,
+. both_direction = 3
+. };
+.
.struct bfd
.{
. {* A unique identifier of the BFD *}
. bfd_format format;
.
. {* The direction with which the BFD was opened. *}
-. enum bfd_direction
-. {
-. no_direction = 0,
-. read_direction = 1,
-. write_direction = 2,
-. both_direction = 3
-. }
-. direction;
+. enum bfd_direction direction;
.
. {* Format_specific flags. *}
. flagword flags;
. will be consistent from run to run. *}
.#define BFD_DETERMINISTIC_OUTPUT 0x4000
.
+. {* Compress sections in this BFD. *}
+.#define BFD_COMPRESS 0x8000
+.
+. {* Decompress sections in this BFD. *}
+.#define BFD_DECOMPRESS 0x10000
+.
+. {* BFD is a dummy, for plugins. *}
+.#define BFD_PLUGIN 0x20000
+.
+. {* Flags bits to be saved in bfd_preserve_save. *}
+.#define BFD_FLAGS_SAVED \
+. (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_PLUGIN)
+.
+. {* Flags bits which are for BFD use only. *}
+.#define BFD_FLAGS_FOR_BFD_USE_MASK \
+. (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_LINKER_CREATED \
+. | BFD_PLUGIN | BFD_TRADITIONAL_FORMAT | BFD_DETERMINISTIC_OUTPUT)
+.
. {* Currently my_archive is tested before adding origin to
. anything. I believe that this can become always an add of
. origin, with origin set to 0 for non archive files. *}
.
. {* Set if this is a thin archive. *}
. unsigned int is_thin_archive : 1;
+.
+. {* Set if only required symbols should be added in the link hash table for
+. this object. Used by VMS linkers. *}
+. unsigned int selective_search : 1;
.};
.
*/
va_start (ap, error_tag);
input_bfd = va_arg (ap, bfd *);
- input_error = va_arg (ap, int);
+ input_error = (bfd_error_type) va_arg (ap, int);
if (input_error >= bfd_error_on_input)
abort ();
va_end (ap);
void
bfd_perror (const char *message)
{
+ fflush (stdout);
if (message == NULL || *message == '\0')
fprintf (stderr, "%s\n", bfd_errmsg (bfd_get_error ()));
else
fprintf (stderr, "%s: %s\n", message, bfd_errmsg (bfd_get_error ()));
+ fflush (stderr);
}
/*
va_end (ap);
putc ('\n', stderr);
+ fflush (stderr);
}
/* This is a function pointer to the routine which should handle BFD
{
return _bfd_error_handler;
}
+
+/*
+SUBSECTION
+ BFD assert handler
+
+ If BFD finds an internal inconsistency, the bfd assert
+ handler is called with information on the BFD version, BFD
+ source file and line. If this happens, most programs linked
+ against BFD are expected to want to exit with an error, or mark
+ the current BFD operation as failed, so it is recommended to
+ override the default handler, which just calls
+ _bfd_error_handler and continues.
+
+CODE_FRAGMENT
+.
+.typedef void (*bfd_assert_handler_type) (const char *bfd_formatmsg,
+. const char *bfd_version,
+. const char *bfd_file,
+. int bfd_line);
+.
+*/
+
+/* Note the use of bfd_ prefix on the parameter names above: we want to
+ show which one is the message and which is the version by naming the
+ parameters, but avoid polluting the program-using-bfd namespace as
+ the typedef is visible in the exported headers that the program
+ includes. Below, it's just for consistency. */
+
+static void
+_bfd_default_assert_handler (const char *bfd_formatmsg,
+ const char *bfd_version,
+ const char *bfd_file,
+ int bfd_line)
+
+{
+ (*_bfd_error_handler) (bfd_formatmsg, bfd_version, bfd_file, bfd_line);
+}
+
+/* Similar to _bfd_error_handler, a program can decide to exit on an
+ internal BFD error. We use a non-variadic type to simplify passing
+ on parameters to other functions, e.g. _bfd_error_handler. */
+
+bfd_assert_handler_type _bfd_assert_handler = _bfd_default_assert_handler;
+
+/*
+FUNCTION
+ bfd_set_assert_handler
+
+SYNOPSIS
+ bfd_assert_handler_type bfd_set_assert_handler (bfd_assert_handler_type);
+
+DESCRIPTION
+ Set the BFD assert handler function. Returns the previous
+ function.
+*/
+
+bfd_assert_handler_type
+bfd_set_assert_handler (bfd_assert_handler_type pnew)
+{
+ bfd_assert_handler_type pold;
+
+ pold = _bfd_assert_handler;
+ _bfd_assert_handler = pnew;
+ return pold;
+}
+
+/*
+FUNCTION
+ bfd_get_assert_handler
+
+SYNOPSIS
+ bfd_assert_handler_type bfd_get_assert_handler (void);
+
+DESCRIPTION
+ Return the BFD assert handler function.
+*/
+
+bfd_assert_handler_type
+bfd_get_assert_handler (void)
+{
+ return _bfd_assert_handler;
+}
\f
/*
SECTION
void
bfd_assert (const char *file, int line)
{
- (*_bfd_error_handler) (_("BFD %s assertion fail %s:%d"),
- BFD_VERSION_STRING, file, line);
+ (*_bfd_assert_handler) (_("BFD %s assertion fail %s:%d"),
+ BFD_VERSION_STRING, file, line);
}
/* A more or less friendly abort message. In libbfd.h abort is
|| strcmp (name, "pe-x86-64") == 0
|| strcmp (name, "pei-x86-64") == 0
|| strcmp (name, "pe-arm-wince-little") == 0
- || strcmp (name, "pei-arm-wince-little") == 0)
+ || strcmp (name, "pei-arm-wince-little") == 0
+ || strcmp (name, "aixcoff-rs6000") == 0)
return 1;
if (CONST_STRNEQ (name, "mach-o"))
. BFD_SEND (abfd, _bfd_find_nearest_line, \
. (abfd, sec, syms, off, file, func, line))
.
+.#define bfd_find_nearest_line_discriminator(abfd, sec, syms, off, file, func, \
+. line, disc) \
+. BFD_SEND (abfd, _bfd_find_nearest_line_discriminator, \
+. (abfd, sec, syms, off, file, func, line, disc))
+.
.#define bfd_find_line(abfd, syms, sym, file, line) \
. BFD_SEND (abfd, _bfd_find_line, \
. (abfd, syms, sym, file, line))
.#define bfd_gc_sections(abfd, link_info) \
. BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
.
+.#define bfd_lookup_section_flags(link_info, flag_info, section) \
+. BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info, section))
+.
.#define bfd_merge_sections(abfd, link_info) \
. BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
.
amt = sizeof (struct elf_segment_map);
amt += ((bfd_size_type) count - 1) * sizeof (asection *);
- m = bfd_zalloc (abfd, amt);
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
if (m == NULL)
return FALSE;
if (count > 0)
memcpy (m->sections, secs, count * sizeof (asection *));
- for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
+ for (pm = &elf_seg_map (abfd); *pm != NULL; pm = &(*pm)->next)
;
*pm = m;
return FALSE;
}
-/*
-CODE_FRAGMENT
-
-.struct bfd_preserve
-.{
-. void *marker;
-. void *tdata;
-. flagword flags;
-. const struct bfd_arch_info *arch_info;
-. struct bfd_section *sections;
-. struct bfd_section *section_last;
-. unsigned int section_count;
-. struct bfd_hash_table section_htab;
-.};
-.
-*/
-
-/*
-FUNCTION
- bfd_preserve_save
-
-SYNOPSIS
- bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
-
-DESCRIPTION
- When testing an object for compatibility with a particular
- target back-end, the back-end object_p function needs to set
- up certain fields in the bfd on successfully recognizing the
- object. This typically happens in a piecemeal fashion, with
- failures possible at many points. On failure, the bfd is
- supposed to be restored to its initial state, which is
- virtually impossible. However, restoring a subset of the bfd
- state works in practice. This function stores the subset and
- reinitializes the bfd.
-
-*/
-
-bfd_boolean
-bfd_preserve_save (bfd *abfd, struct bfd_preserve *preserve)
-{
- preserve->tdata = abfd->tdata.any;
- preserve->arch_info = abfd->arch_info;
- preserve->flags = abfd->flags;
- preserve->sections = abfd->sections;
- preserve->section_last = abfd->section_last;
- preserve->section_count = abfd->section_count;
- preserve->section_htab = abfd->section_htab;
-
- if (! bfd_hash_table_init (&abfd->section_htab, bfd_section_hash_newfunc,
- sizeof (struct section_hash_entry)))
- return FALSE;
-
- abfd->tdata.any = NULL;
- abfd->arch_info = &bfd_default_arch_struct;
- abfd->flags &= BFD_IN_MEMORY;
- abfd->sections = NULL;
- abfd->section_last = NULL;
- abfd->section_count = 0;
-
- return TRUE;
-}
-
-/*
-FUNCTION
- bfd_preserve_restore
-
-SYNOPSIS
- void bfd_preserve_restore (bfd *, struct bfd_preserve *);
-
-DESCRIPTION
- This function restores bfd state saved by bfd_preserve_save.
- If MARKER is non-NULL in struct bfd_preserve then that block
- and all subsequently bfd_alloc'd memory is freed.
-
-*/
-
-void
-bfd_preserve_restore (bfd *abfd, struct bfd_preserve *preserve)
-{
- bfd_hash_table_free (&abfd->section_htab);
-
- abfd->tdata.any = preserve->tdata;
- abfd->arch_info = preserve->arch_info;
- abfd->flags = preserve->flags;
- abfd->section_htab = preserve->section_htab;
- abfd->sections = preserve->sections;
- abfd->section_last = preserve->section_last;
- abfd->section_count = preserve->section_count;
-
- /* bfd_release frees all memory more recently bfd_alloc'd than
- its arg, as well as its arg. */
- if (preserve->marker != NULL)
- {
- bfd_release (abfd, preserve->marker);
- preserve->marker = NULL;
- }
-}
-
-/*
-FUNCTION
- bfd_preserve_finish
-
-SYNOPSIS
- void bfd_preserve_finish (bfd *, struct bfd_preserve *);
-
-DESCRIPTION
- This function should be called when the bfd state saved by
- bfd_preserve_save is no longer needed. ie. when the back-end
- object_p function returns with success.
-
-*/
-
-void
-bfd_preserve_finish (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_preserve *preserve)
-{
- /* It would be nice to be able to free more memory here, eg. old
- tdata, but that's not possible since these blocks are sitting
- inside bfd_alloc'd memory. The section hash is on a separate
- objalloc. */
- bfd_hash_table_free (&preserve->section_htab);
-}
-
/*
FUNCTION
bfd_emul_get_maxpagesize
emulation.
RETURNS
- Returns the maximum page size in bytes for ELF, abort
- otherwise.
+ Returns the maximum page size in bytes for ELF, 0 otherwise.
*/
bfd_vma
&& target->flavour == bfd_target_elf_flavour)
return xvec_get_elf_backend_data (target)->maxpagesize;
- abort ();
return 0;
}
emulation.
RETURNS
- Returns the common page size in bytes for ELF, abort otherwise.
+ Returns the common page size in bytes for ELF, 0 otherwise.
*/
bfd_vma
&& target->flavour == bfd_target_elf_flavour)
return xvec_get_elf_backend_data (target)->commonpagesize;
- abort ();
return 0;
}
suf = strchr (name, '@');
if (suf != NULL)
{
- alloc = bfd_malloc (suf - name + 1);
+ alloc = (char *) bfd_malloc (suf - name + 1);
if (alloc == NULL)
return NULL;
memcpy (alloc, name, suf - name);
if (skip_lead)
{
size_t len = strlen (pre) + 1;
- alloc = bfd_malloc (len);
+ alloc = (char *) bfd_malloc (len);
if (alloc == NULL)
return NULL;
memcpy (alloc, pre, len);
if (suf == NULL)
suf = res + len;
suf_len = strlen (suf) + 1;
- final = bfd_malloc (pre_len + len + suf_len);
+ final = (char *) bfd_malloc (pre_len + len + suf_len);
if (final != NULL)
{
memcpy (final, pre, pre_len);