/* Generic BFD library interface and support routines.
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
+ Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
. includes `<<bfd.h>>', IOSTREAM has been declared as a "char
. *", and MTIME as a "long". Their correct types, to which they
. are cast when used, are "FILE *" and "time_t". The iostream
-. is the result of an fopen on the filename. *}
-. char *iostream;
+. is the result of an fopen on the filename. However, if the
+. BFD_IN_MEMORY flag is set, then iostream is actually a pointer
+. to a bfd_in_memory struct. *}
+. PTR iostream;
.
. {* Is the file descriptor being cached? That is, can it be closed as
. needed, and re-opened when accessed later? *}
. struct symbol_cache_entry **outsymbols;
.
. {* Pointer to structure which contains architecture information*}
-. struct bfd_arch_info *arch_info;
+. const struct bfd_arch_info *arch_info;
.
. {* Stuff only useful for archives:*}
. PTR arelt_data;
. struct _oasys_ar_data *oasys_ar_data;
. struct coff_tdata *coff_obj_data;
. struct pe_tdata *pe_obj_data;
+. struct xcoff_tdata *xcoff_obj_data;
. struct ecoff_tdata *ecoff_obj_data;
. struct ieee_data_struct *ieee_data;
. struct ieee_ar_data_struct *ieee_ar_data;
. struct srec_data_struct *srec_data;
+. struct ihex_data_struct *ihex_data;
. struct tekhex_data_struct *tekhex_data;
. struct elf_obj_tdata *elf_obj_data;
. struct nlm_obj_tdata *nlm_obj_data;
. struct bout_data_struct *bout_data;
. struct sun_core_struct *sun_core_data;
+. struct sco5_core_struct *sco5_core_data;
. struct trad_core_struct *trad_core_data;
. struct som_data_struct *som_data;
. struct hpux_core_struct *hpux_core_data;
. struct osf_core_struct *osf_core_data;
. struct cisco_core_struct *cisco_core_data;
. struct versados_data_struct *versados_data;
+. struct netbsd_core_struct *netbsd_core_data;
. PTR any;
. } tdata;
.
. {* Used by the application to hold private data*}
. PTR usrdata;
.
-. {* Where all the allocated stuff under this BFD goes *}
-. struct obstack memory;
+. {* Where all the allocated stuff under this BFD goes. This is a
+. struct objalloc *, but we use PTR to avoid requiring the inclusion of
+. objalloc.h. *}
+. PTR memory;
.};
.
*/
#include <varargs.h>
#endif
+#include "libiberty.h"
#include "bfdlink.h"
#include "libbfd.h"
#include "coff/internal.h"
#include "libcoff.h"
#include "libecoff.h"
#undef obj_symbols
-#include "libelf.h"
+#include "elf-bfd.h"
#include <ctype.h>
\f
.
*/
-#undef strerror
-extern char *strerror();
-
static bfd_error_type bfd_error = bfd_error_no_error;
CONST char *CONST bfd_errmsgs[] = {
- "No error",
- "System call error",
- "Invalid bfd target",
- "File in wrong format",
- "Invalid operation",
- "Memory exhausted",
- "No symbols",
- "Archive has no index; run ranlib to add one",
- "No more archived files",
- "Malformed archive",
- "File format not recognized",
- "File format is ambiguous",
- "Section has no contents",
- "Nonrepresentable section on output",
- "Symbol needs debug section which does not exist",
- "Bad value",
- "File truncated",
- "File too big",
- "#<Invalid error code>"
+ N_("No error"),
+ N_("System call error"),
+ N_("Invalid bfd target"),
+ N_("File in wrong format"),
+ N_("Invalid operation"),
+ N_("Memory exhausted"),
+ N_("No symbols"),
+ N_("Archive has no index; run ranlib to add one"),
+ N_("No more archived files"),
+ N_("Malformed archive"),
+ N_("File format not recognized"),
+ N_("File format is ambiguous"),
+ N_("Section has no contents"),
+ N_("Nonrepresentable section on output"),
+ N_("Symbol needs debug section which does not exist"),
+ N_("Bad value"),
+ N_("File truncated"),
+ N_("File too big"),
+ N_("#<Invalid error code>")
};
/*
extern int errno;
#endif
if (error_tag == bfd_error_system_call)
- return strerror (errno);
+ return xstrerror (errno);
if ((((int)error_tag <(int) bfd_error_no_error) ||
((int)error_tag > (int)bfd_error_invalid_error_code)))
error_tag = bfd_error_invalid_error_code;/* sanity check */
- return bfd_errmsgs [(int)error_tag];
+ return _(bfd_errmsgs [(int)error_tag]);
}
/*
if (_bfd_error_program_name != NULL)
fprintf (stderr, "%s: ", _bfd_error_program_name);
+ else
+ fprintf (stderr, "BFD: ");
va_start (p, s);
if (_bfd_error_program_name != NULL)
fprintf (stderr, "%s: ", _bfd_error_program_name);
+ else
+ fprintf (stderr, "BFD: ");
va_start (p);
{
_bfd_error_program_name = name;
}
+
+
+/*
+FUNCTION
+ bfd_get_error_handler
+
+SYNOPSIS
+ bfd_error_handler_type bfd_get_error_handler (void);
+
+DESCRIPTION
+ Return the BFD error handler function.
+*/
+
+bfd_error_handler_type
+bfd_get_error_handler ()
+{
+ return _bfd_error_handler;
+}
\f
/*
SECTION
/*ARGSUSED*/
void
bfd_set_reloc (ignore_abfd, asect, location, count)
- bfd *ignore_abfd;
+ bfd *ignore_abfd ATTRIBUTE_UNUSED;
sec_ptr asect;
arelent **location;
unsigned int count;
{
- asect->orelocation = location;
+ asect->orelocation = location;
asect->reloc_count = count;
}
}
void
-bfd_assert(file, line)
-char *file;
-int line;
+bfd_assert (file, line)
+ const char *file;
+ int line;
{
- fprintf(stderr, "bfd assertion fail %s:%d\n",file,line);
+ (*_bfd_error_handler) (_("bfd assertion fail %s:%d"), file, line);
}
+/* A more or less friendly abort message. In libbfd.h abort is
+ defined to call this function. */
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+void
+_bfd_abort (file, line, fn)
+ const char *file;
+ int line;
+ const char *fn;
+{
+ if (fn != NULL)
+ (*_bfd_error_handler)
+ (_("BFD internal error, aborting at %s line %d in %s\n"),
+ file, line, fn);
+ else
+ (*_bfd_error_handler)
+ (_("BFD internal error, aborting at %s line %d\n"),
+ file, line);
+ (*_bfd_error_handler) (_("Please report this bug.\n"));
+ xexit (EXIT_FAILURE);
+}
+
+/*
+FUNCTION
+ bfd_get_arch_size
+
+SYNOPSIS
+ int bfd_get_arch_size (bfd *abfd);
+
+DESCRIPTION
+ Returns the architecture address size, in bits, as determined
+ by the object file's format. For ELF, this information is
+ included in the header.
+
+RETURNS
+ Returns the arch size in bits if known, <<-1>> otherwise.
+*/
+
+int
+bfd_get_arch_size (abfd)
+ bfd *abfd;
+{
+ if (abfd->xvec->flavour == bfd_target_elf_flavour)
+ return (get_elf_backend_data (abfd))->s->arch_size;
+
+ bfd_set_error (bfd_error_wrong_format);
+ return -1;
+}
+
+/*
+FUNCTION
+ bfd_get_sign_extend_vma
+
+SYNOPSIS
+ int bfd_get_sign_extend_vma (bfd *abfd);
+
+DESCRIPTION
+ Indicates if the target architecture "naturally" sign extends
+ an address. Some architectures implicitly sign extend address
+ values when they are converted to types larger than the size
+ of an address. For instance, bfd_get_start_address() will
+ return an address sign extended to fill a bfd_vma when this is
+ the case.
+
+RETURNS
+ Returns <<1>> if the target architecture is known to sign
+ extend addresses, <<0>> if the target architecture is known to
+ not sign extend addresses, and <<-1>> otherwise.
+*/
+
+int
+bfd_get_sign_extend_vma (abfd)
+ bfd *abfd;
+{
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ return (get_elf_backend_data (abfd)->sign_extend_vma);
+
+ bfd_set_error (bfd_error_wrong_format);
+ return -1;
+}
/*
FUNCTION
FILE *fp;
struct stat buf;
+ if ((abfd->flags & BFD_IN_MEMORY) != 0)
+ return ((struct bfd_in_memory *) abfd->iostream)->size;
+
fp = bfd_cache_lookup (abfd);
if (0 != fstat (fileno (fp), &buf))
return 0;
elf_gp_size (abfd) = i;
}
+/* Get the GP value. This is an internal function used by some of the
+ relocation special_function routines on targets which support a GP
+ register. */
+
+bfd_vma
+_bfd_get_gp_value (abfd)
+ bfd *abfd;
+{
+ if (abfd->format == bfd_object)
+ {
+ if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
+ return ecoff_data (abfd)->gp;
+ else if (abfd->xvec->flavour == bfd_target_elf_flavour)
+ return elf_gp (abfd);
+ }
+ return 0;
+}
+
+/* Set the GP value. */
+
+void
+_bfd_set_gp_value (abfd, v)
+ bfd *abfd;
+ bfd_vma v;
+{
+ if (abfd->format != bfd_object)
+ return;
+ if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
+ ecoff_data (abfd)->gp = v;
+ else if (abfd->xvec->flavour == bfd_target_elf_flavour)
+ elf_gp (abfd) = v;
+}
+
/*
FUNCTION
bfd_scan_vma
/* Speed could be improved with a table like hex_value[] in gas. */
#define HEX_VALUE(c) \
- (isxdigit(c) ? \
- (isdigit(c) ? \
- (c - '0') : \
- (10 + c - (islower(c) ? 'a' : 'A'))) : \
- 42)
+ (isxdigit ((unsigned char) c) \
+ ? (isdigit ((unsigned char) c) \
+ ? (c - '0') \
+ : (10 + c - (islower ((unsigned char) c) ? 'a' : 'A'))) \
+ : 42)
for (value = 0; (digit = HEX_VALUE(*string)) < base; string++)
{
Not enough memory exists to create private data for @var{obfd}.
.#define bfd_copy_private_bfd_data(ibfd, obfd) \
-. BFD_SEND (ibfd, _bfd_copy_private_bfd_data, \
+. BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
. (ibfd, obfd))
*/
Not enough memory exists to create private data for @var{obfd}.
.#define bfd_merge_private_bfd_data(ibfd, obfd) \
-. BFD_SEND (ibfd, _bfd_merge_private_bfd_data, \
+. BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
. (ibfd, obfd))
*/
.#define bfd_relax_section(abfd, section, link_info, again) \
. BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
.
+.#define bfd_gc_sections(abfd, link_info) \
+. BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
+.
.#define bfd_link_hash_table_create(abfd) \
. BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
.
return (*fn) (abfd, link_info, link_order, data, relocateable, symbols);
}
+/* Record information about an ELF program header. */
+boolean
+bfd_record_phdr (abfd, type, flags_valid, flags, at_valid, at,
+ includes_filehdr, includes_phdrs, count, secs)
+ bfd *abfd;
+ unsigned long type;
+ boolean flags_valid;
+ flagword flags;
+ boolean at_valid;
+ bfd_vma at;
+ boolean includes_filehdr;
+ boolean includes_phdrs;
+ unsigned int count;
+ asection **secs;
+{
+ struct elf_segment_map *m, **pm;
+
+ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ return true;
+ m = ((struct elf_segment_map *)
+ bfd_alloc (abfd,
+ (sizeof (struct elf_segment_map)
+ + ((size_t) count - 1) * sizeof (asection *))));
+ if (m == NULL)
+ return false;
+
+ m->next = NULL;
+ m->p_type = type;
+ m->p_flags = flags;
+ m->p_paddr = at;
+ m->p_flags_valid = flags_valid;
+ m->p_paddr_valid = at_valid;
+ m->includes_filehdr = includes_filehdr;
+ m->includes_phdrs = includes_phdrs;
+ m->count = count;
+ if (count > 0)
+ memcpy (m->sections, secs, count * sizeof (asection *));
+
+ for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
+ ;
+ *pm = m;
+
+ return true;
+}