/* BFD semi-generic back-end for a.out binaries.
- Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+ Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
#define KEEPIT udata.i
#include <string.h> /* For strchr and friends */
+#include <ctype.h>
#include "bfd.h"
#include <sysdep.h>
#include "bfdlink.h"
PARAMS ((bfd *, aout_symbol_type *));
static boolean translate_to_native_sym_flags
PARAMS ((bfd *, asymbol *, struct external_nlist *));
+static void adjust_o_magic PARAMS ((bfd *, struct internal_exec *));
+static void adjust_z_magic PARAMS ((bfd *, struct internal_exec *));
+static void adjust_n_magic PARAMS ((bfd *, struct internal_exec *));
/*
SUBSECTION
HOWTO(RELOC_LO10, 0, 2, 10, false, 0, complain_overflow_dont,0,"LO10", false, 0,0x000003ff, false),
HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, complain_overflow_bitfield,0,"SFA_BASE", false, 0,0xffffffff, false),
HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, complain_overflow_bitfield,0,"SFA_OFF13",false, 0,0xffffffff, false),
- HOWTO(RELOC_BASE10, 0, 2, 16, false, 0, complain_overflow_bitfield,0,"BASE10", false, 0,0x0000ffff, false),
+ HOWTO(RELOC_BASE10, 0, 2, 10, false, 0, complain_overflow_dont,0,"BASE10", false, 0,0x000003ff, false),
HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, complain_overflow_bitfield,0,"BASE13", false, 0,0x00001fff, false),
- HOWTO(RELOC_BASE22, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"BASE22", false, 0,0x00000000, false),
+ HOWTO(RELOC_BASE22, 10, 2, 22, false, 0, complain_overflow_bitfield,0,"BASE22", false, 0,0x003fffff, false),
HOWTO(RELOC_PC10, 0, 2, 10, true, 0, complain_overflow_dont,0,"PC10", false, 0,0x000003ff, true),
HOWTO(RELOC_PC22, 10, 2, 22, true, 0, complain_overflow_signed,0,"PC22", false, 0,0x003fffff, true),
HOWTO(RELOC_JMP_TBL,2, 2, 30, true, 0, complain_overflow_signed,0,"JMP_TBL", false, 0,0x3fffffff, false),
execp = abfd->tdata.aout_data->a.hdr;
/* Set the file flags */
- abfd->flags = NO_FLAGS;
+ abfd->flags = BFD_NO_FLAGS;
if (execp->a_drsize || execp->a_trsize)
abfd->flags |= HAS_RELOC;
/* Setting of EXEC_P has been deferred to the bottom of this function */
guess at whether the file is executable. If the entry point
is within the text segment, assume it is. (This makes files
executable even if their entry point address is 0, as long as
- their text starts at zero.). */
- if ((execp->a_entry >= obj_textsec(abfd)->vma) &&
- (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
+ their text starts at zero.).
+
+ This test had to be changed to deal with systems where the text segment
+ runs at a different location than the default. The problem is that the
+ entry address can appear to be outside the text segment, thus causing an
+ erroneous conclusion that the file isn't executable.
+
+ To fix this, we now accept any non-zero entry point as an indication of
+ executability. This will work most of the time, since only the linker
+ sets the entry point, and that is likely to be non-zero for most systems. */
+
+ if (execp->a_entry != 0
+ || (execp->a_entry >= obj_textsec(abfd)->vma
+ && execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
abfd->flags |= EXEC_P;
#ifdef STAT_FOR_EXEC
else
the default text start (obj_textsec(abfd)->vma) and
(obj_textsec(abfd)->vma) + text size. This is not just a mach
issue. Many kernels are loaded at non standard addresses. */
- if (abfd->iostream
+ if (abfd->iostream != NULL
+ && (abfd->flags & BFD_IN_MEMORY) == 0
&& (fstat(fileno((FILE *) (abfd->iostream)), &stat_buf) == 0)
&& ((stat_buf.st_mode & 0111) != 0))
abfd->flags |= EXEC_P;
case bfd_arch_sparc:
if (machine == 0
|| machine == bfd_mach_sparc
- || machine == bfd_mach_sparc64)
+ || machine == bfd_mach_sparc_sparclite
+ || machine == bfd_mach_sparc_v9)
arch_flags = M_SPARC;
+ else if (machine == bfd_mach_sparc_sparclet)
+ arch_flags = M_SPARCLET;
break;
case bfd_arch_m68k:
*unknown = false;
break;
- /* start-sanitize-rce */
- case bfd_arch_rce:
- arch_flags = M_RCE;
- break;
- /* end-sanitize-rce */
-
default:
arch_flags = M_UNKNOWN;
}
syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
#else
/* We allocate using malloc to make the values easy to free
- later on. If we put them on the obstack it might not be
+ later on. If we put them on the objalloc it might not be
possible to free them. */
syms = ((struct external_nlist *)
bfd_malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
case N_SETD: case N_SETD | N_EXT:
case N_SETB: case N_SETB | N_EXT:
{
+ /* This code is no longer needed. It used to be used to make
+ the linker handle set symbols, but they are now handled in
+ the add_symbols routine instead. */
+#if 0
asection *section;
arelent_chain *reloc;
asection *into_section;
reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO(abfd);
+#endif /* 0 */
+
+ switch (cache_ptr->type & N_TYPE)
+ {
+ case N_SETA:
+ cache_ptr->symbol.section = bfd_abs_section_ptr;
+ break;
+ case N_SETT:
+ cache_ptr->symbol.section = obj_textsec (abfd);
+ break;
+ case N_SETD:
+ cache_ptr->symbol.section = obj_datasec (abfd);
+ break;
+ case N_SETB:
+ cache_ptr->symbol.section = obj_bsssec (abfd);
+ break;
+ }
+
cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
}
break;
/* This case occurs, e.g., for the *DEBUG* section of a COFF
file. */
(*_bfd_error_handler)
- ("%s: can not represent section `%s' in a.out object file format",
- bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
+ ("%s: can not represent section for symbol `%s' in a.out object file format",
+ bfd_get_filename (abfd),
+ cache_ptr->name != NULL ? cache_ptr->name : "*unknown*");
bfd_set_error (bfd_error_nonrepresentable_section);
return false;
}
/* Standard reloc stuff */
/* Output standard relocation information to a file in target byte order. */
+extern void NAME(aout,swap_std_reloc_out)
+ PARAMS ((bfd *, arelent *, struct reloc_std_external *));
+
void
NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
bfd *abfd;
{
/* Whoops, looked like an abs symbol, but is really an offset
from the abs section */
- r_index = 0;
+ r_index = N_ABS;
r_extern = 0;
}
else
}
/* now the fun stuff */
- if (abfd->xvec->header_byteorder_big_p != false) {
+ if (bfd_header_big_endian (abfd)) {
natptr->r_index[0] = r_index >> 16;
natptr->r_index[1] = r_index >> 8;
natptr->r_index[2] = r_index;
/* Extended stuff */
/* Output extended relocation information to a file in target byte order. */
+extern void NAME(aout,swap_ext_reloc_out)
+ PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
+
void
NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
bfd *abfd;
if (bfd_is_abs_section (bfd_get_section (sym)))
{
r_extern = 0;
- r_index = 0;
+ r_index = N_ABS;
}
else if ((sym->flags & BSF_SECTION_SYM) == 0)
{
}
/* now the fun stuff */
- if (abfd->xvec->header_byteorder_big_p != false) {
+ if (bfd_header_big_endian (abfd)) {
natptr->r_index[0] = r_index >> 16;
natptr->r_index[1] = r_index >> 8;
natptr->r_index[2] = r_index;
cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
/* now the fun stuff */
- if (abfd->xvec->header_byteorder_big_p != false) {
+ if (bfd_header_big_endian (abfd)) {
r_index = (bytes->r_index[0] << 16)
| (bytes->r_index[1] << 8)
| bytes->r_index[2];
cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address);
/* now the fun stuff */
- if (abfd->xvec->header_byteorder_big_p != false) {
+ if (bfd_header_big_endian (abfd)) {
r_index = (bytes->r_index[0] << 16)
| (bytes->r_index[1] << 8)
| bytes->r_index[2];
unsigned int count = section->reloc_count;
size_t natsize;
- if (count == 0) return true;
+ if (count == 0 || section->orelocation == NULL)
+ return true;
each_size = obj_reloc_entry_size (abfd);
natsize = each_size * count;
if (ret->type == '?')
{
int type_code = aout_symbol(symbol)->type & 0xff;
- CONST char *stab_name = aout_stab_name(type_code);
+ const char *stab_name = bfd_get_stab_name (type_code);
static char buf[10];
if (stab_name == NULL)
stab_name = buf;
}
ret->type = '-';
+ ret->stab_type = type_code;
ret->stab_other = (unsigned)(aout_symbol(symbol)->other & 0xff);
ret->stab_desc = (unsigned)(aout_symbol(symbol)->desc & 0xffff);
ret->stab_name = stab_name;
aout_symbol_type *q = (aout_symbol_type *)(*p);
next:
switch (q->type){
+ case N_TEXT:
+ /* If this looks like a file name symbol, and it comes after
+ the line number we have found so far, but before the
+ offset, then we have probably not found the right line
+ number. */
+ if (q->symbol.value <= offset
+ && ((q->symbol.value > low_line_vma
+ && (line_file_name != NULL
+ || *line_ptr != 0))
+ || (q->symbol.value > low_func_vma
+ && func != NULL)))
+ {
+ const char *symname;
+
+ symname = q->symbol.name;
+ if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
+ {
+ if (q->symbol.value > low_line_vma)
+ {
+ *line_ptr = 0;
+ line_file_name = NULL;
+ }
+ if (q->symbol.value > low_func_vma)
+ func = NULL;
+ }
+ }
+ break;
+
case N_SO:
+ /* If this symbol is less than the offset, but greater than
+ the line number we have found so far, then we have not
+ found the right line number. */
+ if (q->symbol.value <= offset)
+ {
+ if (q->symbol.value > low_line_vma)
+ {
+ *line_ptr = 0;
+ line_file_name = NULL;
+ }
+ if (q->symbol.value > low_func_vma)
+ func = NULL;
+ }
+
main_file_name = current_file_name = q->symbol.name;
/* Look ahead to next symbol to check if that too is an N_SO. */
p++;
adata (abfd).line_buf = buf = NULL;
else
{
- buf = (char *) bfd_malloc (filelen + funclen + 2);
+ buf = (char *) bfd_malloc (filelen + funclen + 3);
adata (abfd).line_buf = buf;
if (buf == NULL)
return false;
else
copy = true;
- if ((abfd->flags & DYNAMIC) != 0
- && aout_backend_info (abfd)->add_dynamic_symbols != NULL)
+ if (aout_backend_info (abfd)->add_dynamic_symbols != NULL)
{
if (! ((*aout_backend_info (abfd)->add_dynamic_symbols)
(abfd, info, &syms, &sym_count, &strings)))
return true;
}
+\f
+/* A hash table used for header files with N_BINCL entries. */
+
+struct aout_link_includes_table
+{
+ struct bfd_hash_table root;
+};
+
+/* A linked list of totals that we have found for a particular header
+ file. */
+
+struct aout_link_includes_totals
+{
+ struct aout_link_includes_totals *next;
+ bfd_vma total;
+};
+
+/* An entry in the header file hash table. */
+
+struct aout_link_includes_entry
+{
+ struct bfd_hash_entry root;
+ /* List of totals we have found for this file. */
+ struct aout_link_includes_totals *totals;
+};
+
+/* Look up an entry in an the header file hash table. */
+
+#define aout_link_includes_lookup(table, string, create, copy) \
+ ((struct aout_link_includes_entry *) \
+ bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
/* During the final link step we need to pass around a bunch of
information, so we do it in an instance of this structure. */
file_ptr symoff;
/* String table. */
struct bfd_strtab_hash *strtab;
+ /* Header file hash table. */
+ struct aout_link_includes_table includes;
/* A buffer large enough to hold the contents of any section. */
bfd_byte *contents;
/* A buffer large enough to hold the relocs of any section. */
struct external_nlist *output_syms;
};
+static struct bfd_hash_entry *aout_link_includes_newfunc
+ PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
static boolean aout_link_input_bfd
PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
static boolean aout_link_write_symbols
PARAMS ((struct aout_final_link_info *, asection *,
struct bfd_link_order *));
+/* The function to create a new entry in the header file hash table. */
+
+static struct bfd_hash_entry *
+aout_link_includes_newfunc (entry, table, string)
+ struct bfd_hash_entry *entry;
+ struct bfd_hash_table *table;
+ const char *string;
+{
+ struct aout_link_includes_entry *ret =
+ (struct aout_link_includes_entry *) entry;
+
+ /* Allocate the structure if it has not already been allocated by a
+ subclass. */
+ if (ret == (struct aout_link_includes_entry *) NULL)
+ ret = ((struct aout_link_includes_entry *)
+ bfd_hash_allocate (table,
+ sizeof (struct aout_link_includes_entry)));
+ if (ret == (struct aout_link_includes_entry *) NULL)
+ return (struct bfd_hash_entry *) ret;
+
+ /* Call the allocation method of the superclass. */
+ ret = ((struct aout_link_includes_entry *)
+ bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
+ if (ret)
+ {
+ /* Set local fields. */
+ ret->totals = NULL;
+ }
+
+ return (struct bfd_hash_entry *) ret;
+}
+
/* Do the final link step. This is called on the output BFD. The
INFO structure should point to a list of BFDs linked through the
link_next field which can be used to find each BFD which takes part
void (*callback) PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
{
struct aout_final_link_info aout_info;
+ boolean includes_hash_initialized = false;
register bfd *sub;
bfd_size_type trsize, drsize;
size_t max_contents_size;
aout_info.output_bfd = abfd;
aout_info.contents = NULL;
aout_info.relocs = NULL;
+ aout_info.symbol_map = NULL;
+ aout_info.output_syms = NULL;
+
+ if (! bfd_hash_table_init_n (&aout_info.includes.root,
+ aout_link_includes_newfunc,
+ 251))
+ goto error_return;
+ includes_hash_initialized = true;
/* Figure out the largest section size. Also, if generating
relocateable output, count the relocs. */
for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
sub->output_has_begun = false;
+ /* Mark all sections which are to be included in the link. This
+ will normally be every section. We need to do this so that we
+ can identify any sections which the linker has decided to not
+ include. */
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ for (p = o->link_order_head; p != NULL; p = p->next)
+ {
+ if (p->type == bfd_indirect_link_order)
+ p->u.indirect.section->linker_mark = true;
+ }
+ }
+
have_link_order_relocs = false;
for (o = abfd->sections; o != (asection *) NULL; o = o->next)
{
free (aout_info.output_syms);
aout_info.output_syms = NULL;
}
+ if (includes_hash_initialized)
+ {
+ bfd_hash_table_free (&aout_info.includes.root);
+ includes_hash_initialized = false;
+ }
/* Finish up any dynamic linking we may be doing. */
if (aout_backend_info (abfd)->finish_dynamic_link != NULL)
obj_datasec (abfd)->reloc_count =
exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
- /* Write out the string table. */
- if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0)
- goto error_return;
- return emit_stringtab (abfd, aout_info.strtab);
+ /* Write out the string table, unless there are no symbols. */
+ if (abfd->symcount > 0)
+ {
+ if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
+ || ! emit_stringtab (abfd, aout_info.strtab))
+ goto error_return;
+ }
+
+ return true;
error_return:
if (aout_info.contents != NULL)
free (aout_info.symbol_map);
if (aout_info.output_syms != NULL)
free (aout_info.output_syms);
+ if (includes_hash_initialized)
+ bfd_hash_table_free (&aout_info.includes.root);
return false;
}
return false;
/* Relocate and write out the sections. These functions use the
- symbol map created by aout_link_write_symbols. */
- if (! aout_link_input_section (finfo, input_bfd,
- obj_textsec (input_bfd),
- &finfo->treloff,
- exec_hdr (input_bfd)->a_trsize)
- || ! aout_link_input_section (finfo, input_bfd,
- obj_datasec (input_bfd),
- &finfo->dreloff,
- exec_hdr (input_bfd)->a_drsize))
- return false;
+ symbol map created by aout_link_write_symbols. The linker_mark
+ field will be set if these sections are to be included in the
+ link, which will normally be the case. */
+ if (obj_textsec (input_bfd)->linker_mark)
+ {
+ if (! aout_link_input_section (finfo, input_bfd,
+ obj_textsec (input_bfd),
+ &finfo->treloff,
+ exec_hdr (input_bfd)->a_trsize))
+ return false;
+ }
+ if (obj_datasec (input_bfd)->linker_mark)
+ {
+ if (! aout_link_input_section (finfo, input_bfd,
+ obj_datasec (input_bfd),
+ &finfo->dreloff,
+ exec_hdr (input_bfd)->a_drsize))
+ return false;
+ }
/* If we are not keeping memory, we don't need the symbols any
longer. We still need them if we are keeping memory, because the
sym_end = sym + sym_count;
sym_hash = obj_aout_sym_hashes (input_bfd);
symbol_map = finfo->symbol_map;
+ memset (symbol_map, 0, sym_count * sizeof *symbol_map);
for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
{
const char *name;
bfd_vma val = 0;
boolean copy;
+ /* We set *symbol_map to 0 above for all symbols. If it has
+ already been set to -1 for this symbol, it means that we are
+ discarding it because it appears in a duplicate header file.
+ See the N_BINCL code below. */
+ if (*symbol_map == -1)
+ continue;
+
+ /* Initialize *symbol_map to -1, which means that the symbol was
+ not copied into the output file. We will change it later if
+ we do copy the symbol over. */
*symbol_map = -1;
type = bfd_h_get_8 (input_bfd, sym->e_type);
external symbol. */
h = *sym_hash;
+ /* Use the name from the hash table, in case the symbol was
+ wrapped. */
+ if (h != NULL)
+ name = h->root.root.string;
+
/* If this is an indirect or warning symbol, then change
hresolve to the base symbol. We also change *sym_hash so
that the relocation routines relocate against the real
case discard_none:
break;
case discard_l:
- if (*name == *finfo->info->lprefix
- && (finfo->info->lprefix_len == 1
- || strncmp (name, finfo->info->lprefix,
- finfo->info->lprefix_len) == 0))
+ if ((type & N_STAB) == 0
+ && bfd_is_local_label_name (input_bfd, name))
skip = true;
break;
case discard_all:
continue;
}
}
+
+ /* An N_BINCL symbol indicates the start of the stabs
+ entries for a header file. We need to scan ahead to the
+ next N_EINCL symbol, ignoring nesting, adding up all the
+ characters in the symbol names, not including the file
+ numbers in types (the first number after an open
+ parenthesis). */
+ if (type == N_BINCL)
+ {
+ struct external_nlist *incl_sym;
+ int nest;
+ struct aout_link_includes_entry *incl_entry;
+ struct aout_link_includes_totals *t;
+
+ val = 0;
+ nest = 0;
+ for (incl_sym = sym + 1; incl_sym < sym_end; incl_sym++)
+ {
+ int incl_type;
+
+ incl_type = bfd_h_get_8 (input_bfd, incl_sym->e_type);
+ if (incl_type == N_EINCL)
+ {
+ if (nest == 0)
+ break;
+ --nest;
+ }
+ else if (incl_type == N_BINCL)
+ ++nest;
+ else if (nest == 0)
+ {
+ const char *s;
+
+ s = strings + GET_WORD (input_bfd, incl_sym->e_strx);
+ for (; *s != '\0'; s++)
+ {
+ val += *s;
+ if (*s == '(')
+ {
+ /* Skip the file number. */
+ ++s;
+ while (isdigit ((unsigned char) *s))
+ ++s;
+ --s;
+ }
+ }
+ }
+ }
+
+ /* If we have already included a header file with the
+ same value, then replace this one with an N_EXCL
+ symbol. */
+ copy = ! finfo->info->keep_memory;
+ incl_entry = aout_link_includes_lookup (&finfo->includes,
+ name, true, copy);
+ if (incl_entry == NULL)
+ return false;
+ for (t = incl_entry->totals; t != NULL; t = t->next)
+ if (t->total == val)
+ break;
+ if (t == NULL)
+ {
+ /* This is the first time we have seen this header
+ file with this set of stabs strings. */
+ t = ((struct aout_link_includes_totals *)
+ bfd_hash_allocate (&finfo->includes.root,
+ sizeof *t));
+ if (t == NULL)
+ return false;
+ t->total = val;
+ t->next = incl_entry->totals;
+ incl_entry->totals = t;
+ }
+ else
+ {
+ int *incl_map;
+
+ /* This is a duplicate header file. We must change
+ it to be an N_EXCL entry, and mark all the
+ included symbols to prevent outputting them. */
+ type = N_EXCL;
+
+ nest = 0;
+ for (incl_sym = sym + 1, incl_map = symbol_map + 1;
+ incl_sym < sym_end;
+ incl_sym++, incl_map++)
+ {
+ int incl_type;
+
+ incl_type = bfd_h_get_8 (input_bfd, incl_sym->e_type);
+ if (incl_type == N_EINCL)
+ {
+ if (nest == 0)
+ {
+ *incl_map = -1;
+ break;
+ }
+ --nest;
+ }
+ else if (incl_type == N_BINCL)
+ ++nest;
+ else if (nest == 0)
+ *incl_map = -1;
+ }
+ }
+ }
}
/* Copy this symbol into the list of symbols we are going to
check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
- BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p
- == output_bfd->xvec->header_byteorder_big_p);
+ BFD_ASSERT (input_bfd->xvec->header_byteorder
+ == output_bfd->xvec->header_byteorder);
relocateable = finfo->info->relocateable;
syms = obj_aout_external_syms (input_bfd);
int r_length;
unsigned int howto_idx;
- if (input_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (input_bfd))
{
r_index = ((rel->r_index[0] << 16)
| (rel->r_index[1] << 8)
asection *output_section;
/* Change the r_extern value. */
- if (output_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (output_bfd))
rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG;
else
rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE;
}
/* Write out the new r_index value. */
- if (output_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (output_bfd))
{
rel->r_index[0] = r_index >> 16;
rel->r_index[1] = r_index >> 8;
{
const char *name;
- name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
+ if (h != NULL)
+ name = h->root.root.string;
+ else
+ name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
if (! ((*finfo->info->callbacks->undefined_symbol)
(finfo->info, name, input_bfd, input_section, r_addr)))
return false;
}
r = MY_final_link_relocate (howto,
- input_bfd, input_section,
- contents, r_addr, relocation,
- (bfd_vma) 0);
+ input_bfd, input_section,
+ contents, r_addr, relocation,
+ (bfd_vma) 0);
}
if (r != bfd_reloc_ok)
{
const char *name;
- if (r_extern)
+ if (h != NULL)
+ name = h->root.root.string;
+ else if (r_extern)
name = strings + GET_WORD (input_bfd,
syms[r_index].e_strx);
else
check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
- BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p
- == output_bfd->xvec->header_byteorder_big_p);
+ BFD_ASSERT (input_bfd->xvec->header_byteorder
+ == output_bfd->xvec->header_byteorder);
relocateable = finfo->info->relocateable;
syms = obj_aout_external_syms (input_bfd);
r_addr = GET_SWORD (input_bfd, rel->r_address);
- if (input_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (input_bfd))
{
r_index = ((rel->r_index[0] << 16)
| (rel->r_index[1] << 8)
{
/* We are generating a relocateable output file, and must
modify the reloc accordingly. */
- if (r_extern)
+ if (r_extern
+ || r_type == RELOC_BASE10
+ || r_type == RELOC_BASE13
+ || r_type == RELOC_BASE22)
{
/* If we know the symbol this relocation is against,
convert it into a relocation against a section. This
is what the native linker does. */
- h = sym_hashes[r_index];
+ if (r_type == RELOC_BASE10
+ || r_type == RELOC_BASE13
+ || r_type == RELOC_BASE22)
+ h = NULL;
+ else
+ h = sym_hashes[r_index];
if (h != (struct aout_link_hash_entry *) NULL
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak))
asection *output_section;
/* Change the r_extern value. */
- if (output_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (output_bfd))
rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG;
else
rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE;
}
/* Write out the new r_index value. */
- if (output_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (output_bfd))
{
rel->r_index[0] = r_index >> 16;
rel->r_index[1] = r_index >> 8;
}
/* As described above, we must always adjust a PC relative
- reloc by the change in VMA of the source. */
- if (howto_table_ext[r_type].pc_relative)
+ reloc by the change in VMA of the source. However, if
+ pcrel_offset is set, then the addend does not include the
+ location within the section, in which case we don't need
+ to adjust anything. */
+ if (howto_table_ext[r_type].pc_relative
+ && ! howto_table_ext[r_type].pcrel_offset)
relocation -= (input_section->output_section->vma
+ input_section->output_offset
- input_section->vma);
{
const char *name;
- name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
+ if (h != NULL)
+ name = h->root.root.string;
+ else
+ name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
if (! ((*finfo->info->callbacks->undefined_symbol)
(finfo->info, name, input_bfd, input_section, r_addr)))
return false;
}
r = MY_final_link_relocate (howto_table_ext + r_type,
- input_bfd, input_section,
- contents, r_addr, relocation,
- r_addend);
+ input_bfd, input_section,
+ contents, r_addr, relocation,
+ r_addend);
if (r != bfd_reloc_ok)
{
switch (r)
{
const char *name;
- if (r_extern
- || r_type == RELOC_BASE10
- || r_type == RELOC_BASE13
- || r_type == RELOC_BASE22)
+ if (h != NULL)
+ name = h->root.root.string;
+ else if (r_extern
+ || r_type == RELOC_BASE10
+ || r_type == RELOC_BASE13
+ || r_type == RELOC_BASE22)
name = strings + GET_WORD (input_bfd,
syms[r_index].e_strx);
else
BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
r_extern = 1;
- h = aout_link_hash_lookup (aout_hash_table (finfo->info),
- pr->u.name, false, false, true);
+ h = ((struct aout_link_hash_entry *)
+ bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
+ pr->u.name, false, false, true));
if (h != (struct aout_link_hash_entry *) NULL
&& h->indx >= 0)
r_index = h->indx;
r_length = howto->size;
PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
- if (finfo->output_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (finfo->output_bfd))
{
srel.r_index[0] = r_index >> 16;
srel.r_index[1] = r_index >> 8;
{
PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
- if (finfo->output_bfd->xvec->header_byteorder_big_p)
+ if (bfd_header_big_endian (finfo->output_bfd))
{
erel.r_index[0] = r_index >> 16;
erel.r_index[1] = r_index >> 8;