diff options
-rw-r--r-- | bfd/ChangeLog | 14 | ||||
-rw-r--r-- | bfd/aout-ns32k.c | 398 | ||||
-rw-r--r-- | bfd/aoutx.h | 31 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 7 | ||||
-rw-r--r-- | bfd/cf-m68klynx.c | 2 | ||||
-rw-r--r-- | bfd/coff-i386.c | 74 | ||||
-rw-r--r-- | bfd/coff-m68k.c | 13 | ||||
-rw-r--r-- | bfd/elf32-arc.c | 159 | ||||
-rw-r--r-- | bfd/elf32-i386.c | 2 | ||||
-rw-r--r-- | bfd/elf32-mips.c | 17 | ||||
-rw-r--r-- | bfd/elf32-sparc.c | 2 | ||||
-rw-r--r-- | bfd/libbfd.h | 10 | ||||
-rw-r--r-- | bfd/reloc.c | 26 |
13 files changed, 716 insertions, 39 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ecb0782..d8e16b0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,17 @@ +Wed Jan 11 21:31:41 1995 Ken Raeburn <raeburn@cujo.cygnus.com> + + * reloc.c (reloc_howto_type): Make typedef include `const'. + * aout-ns32k.c, aoutx.h, bout.c, cf-m68klynx.c, coff-i386.c, + coff-i960.c, coff-m68k.c, cofflink.c, cpu-ns32k.c, ecoff.c, + elf32-hppa.c, elf32-i386.c, elf32-mips.c, elf32-sparc.c, + elfcode.h, libbfd-in.h, linker.c, mipsbsd.c, nlm32-ppc.c, oasys.c, + reloc.c, som.c: Don't use `const' in combination with + `reloc_howto_type'. +start-sanitize-arc + * elf32-arc.c: Ditto. +end-sanitize-arc + * bfd-in2.h, libbfd.h: Regenerated. + Wed Jan 11 14:36:41 1995 Ian Lance Taylor <ian@sanguine.cygnus.com> * sunos.c (sunos_add_one_symbol): Don't core dump if a multiple diff --git a/bfd/aout-ns32k.c b/bfd/aout-ns32k.c new file mode 100644 index 0000000..dcba191 --- /dev/null +++ b/bfd/aout-ns32k.c @@ -0,0 +1,398 @@ +/* BFD back-end for ns32k a.out-ish binaries. + Copyright (C) 1990, 1991, 1992, 1994 Free Software Foundation, Inc. + Contributed by Ian Dall (idall@eleceng.adelaide.edu.au). + +This file is part of BFD, the Binary File Descriptor library. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#define BYTES_IN_WORD 4 + +#include "bfd.h" +#include "aout/aout64.h" + +#define MYNS(OP) CAT(ns32kaout_,OP) +CONST struct reloc_howto_struct * +MYNS(bfd_reloc_type_lookup) + PARAMS((bfd *abfd AND + bfd_reloc_code_real_type code)); + +boolean +MYNS(write_object_contents) + PARAMS((bfd *abfd)); + +/* Avoid multiple definitions from aoutx if supporting standard a.out format(s) + * as well as this one + */ +#define NAME(x,y) CAT3(ns32kaout,_32_,y) + +void bfd_ns32k_arch PARAMS ((void)); +long ns32k_get_displacement PARAMS ((bfd_byte *buffer, long offset, long size)); +int ns32k_put_displacement PARAMS ((long value, bfd_byte *buffer, long offset, long size)); +long ns32k_get_immediate PARAMS ((bfd_byte *buffer, long offset, long size)); +int ns32k_put_immediate PARAMS ((long value, bfd_byte *buffer, long offset, long size)); +bfd_reloc_status_type + ns32k_reloc_disp PARAMS ((bfd *abfd, arelent *reloc_entry, + struct symbol_cache_entry *symbol, + PTR data, + asection *input_section, + bfd *output_bfd, + char **error_message)); +bfd_reloc_status_type + ns32k_reloc_imm PARAMS ((bfd *abfd, + arelent *reloc_entry, + struct symbol_cache_entry *symbol, + PTR data, + asection *input_section, + bfd *output_bfd, + char **error_message)); +bfd_reloc_status_type + ns32k_final_link_relocate PARAMS ((reloc_howto_type *howto, + bfd *input_bfd, + asection *input_section, + bfd_byte *contents, + bfd_vma address, + bfd_vma value, + bfd_vma addend )); +bfd_reloc_status_type + ns32k_relocate_contents PARAMS ((reloc_howto_type *howto, + bfd *input_bfd, + bfd_vma relocation, + bfd_byte *location)); + +#include "libaout.h" + +#define MY(OP) MYNS(OP) + +#define MY_swap_std_reloc_in MY(swap_std_reloc_in) +#define MY_swap_std_reloc_out MY(swap_std_reloc_out) + +static void +MY_swap_std_reloc_in PARAMS ((bfd *abfd, struct reloc_std_external *bytes, + arelent *cache_ptr, asymbol **symbols)); + +static void +MY_swap_std_reloc_out PARAMS ((bfd *abfd, arelent *g, + struct reloc_std_external *natptr)); + +/* The ns32k series is ah, unusual, when it comes to relocation. + * There are three storage methods for relocateable objects. There + * are displacements, immediate operands and ordinary twos complement + * data. Of these, only the last fits into the standard relocation + * scheme. Immediate operands are stored huffman encoded and + * immediate operands are stored big endian (where as the natural byte + * order is little endian for this achitecture). + + * Note that the ns32k displacement storage method is orthogonal to + * whether the relocation is pc relative or not. The "displacement" + * storage scheme is used for essentially all address constants. The + * displacement can be relative to zero (absolute displacement), + * relative to the pc (pc relative), the stack pointer, the frame + * pointer, the static base register and general purpose register etc. + + * For example: + * + * sym1: .long . # pc relative 2's complement + * sym1: .long foo # 2's complement not pc relative + * + * self: movd @self, r0 # pc relative displacement + * movd foo, r0 # non pc relative displacement + * + * self: movd self, r0 # pc relative immediate + * movd foo, r0 # non pc relative immediate + * + * In addition, for historical reasons the encoding of the relocation types + * in the a.out format relocation entries is such that even the relocation + * methods which are standard are not encoded the standard way. + * + */ + +reloc_howto_type MY(howto_table)[] = +{ +/* ns32k immediate operands */ +HOWTO(BFD_RELOC_NS32K_IMM_8, 0, 0, 8, false, 0, true, + ns32k_reloc_imm, "NS32K_IMM_8", + true, 0x000000ff,0x000000ff, false), +HOWTO(BFD_RELOC_NS32K_IMM_16, 0, 1, 16, false, 0, true, + ns32k_reloc_imm, "NS32K_IMM_16", + true, 0x0000ffff,0x0000ffff, false), +HOWTO(BFD_RELOC_NS32K_IMM_32, 0, 2, 32, false, 0, true, + ns32k_reloc_imm, "NS32K_IMM_32", + true, 0xffffffff,0xffffffff, false), +HOWTO(BFD_RELOC_NS32K_IMM_8_PCREL, 0, 0, 8, true, 0, false, + ns32k_reloc_imm, "PCREL_NS32K_IMM_8", + true, 0x000000ff, 0x000000ff, false), +HOWTO(BFD_RELOC_NS32K_IMM_16_PCREL, 0, 1, 16, true, 0, false, + ns32k_reloc_imm, "PCREL_NS32K_IMM_16", + true, 0x0000ffff,0x0000ffff, false), +HOWTO(BFD_RELOC_NS32K_IMM_32_PCREL, 0, 2, 32, true, 0, false, + ns32k_reloc_imm, "PCREL_NS32K_IMM_32", + true, 0xffffffff,0xffffffff, false), + +/* ns32k displacements */ +HOWTO(BFD_RELOC_NS32K_DISP_8, 0, 0, 8, false, 0, true, + ns32k_reloc_disp, "NS32K_DISP_8", + true, 0x000000ff,0x000000ff, false), +HOWTO(BFD_RELOC_NS32K_DISP_16, 0, 1, 16, false, 0, true, + ns32k_reloc_disp, "NS32K_DISP_16", + true, 0x0000ffff, 0x0000ffff, false), +HOWTO(BFD_RELOC_NS32K_DISP_32, 0, 2, 32, false, 0, true, + ns32k_reloc_disp, "NS32K_DISP_32", + true, 0xffffffff, 0xffffffff, false), +HOWTO(BFD_RELOC_NS32K_DISP_8_PCREL, 0, 0, 8, true, 0, false, + ns32k_reloc_disp, "PCREL_NS32K_DISP_8", + true, 0x000000ff,0x000000ff, false), +HOWTO(BFD_RELOC_NS32K_DISP_16_PCREL, 0, 1, 16, true, 0, false, + ns32k_reloc_disp, "PCREL_NS32K_DISP_16", + true, 0x0000ffff,0x0000ffff, false), +HOWTO(BFD_RELOC_NS32K_DISP_32_PCREL, 0, 2, 32, true, 0, false, + ns32k_reloc_disp, "PCREL_NS32K_DISP_32", + true, 0xffffffff,0xffffffff, false), + +/* Normal 2's complement */ +HOWTO(BFD_RELOC_8, 0, 0, 8, false, 0, complain_overflow_bitfield,0, + "8", true, 0x000000ff,0x000000ff, false), +HOWTO(BFD_RELOC_16, 0, 1, 16, false, 0, complain_overflow_bitfield,0, + "16", true, 0x0000ffff,0x0000ffff, false), +HOWTO(BFD_RELOC_32, 0, 2, 32, false, 0, complain_overflow_bitfield,0, + "32", true, 0xffffffff,0xffffffff, false), +HOWTO(BFD_RELOC_8_PCREL, 0, 0, 8, true, 0, complain_overflow_signed, 0, + "PCREL_8", true, 0x000000ff,0x000000ff, false), +HOWTO(BFD_RELOC_16_PCREL, 0, 1, 16, true, 0, complain_overflow_signed, 0, + "PCREL_16", true, 0x0000ffff,0x0000ffff, false), +HOWTO(BFD_RELOC_32_PCREL, 0, 2, 32, true, 0, complain_overflow_signed, 0, + "PCREL_32", true, 0xffffffff,0xffffffff, false), +}; + +#define RELOC_STD_BITS_NS32K_TYPE_BIG 0x06 +#define RELOC_STD_BITS_NS32K_TYPE_LITTLE 0x60 +#define RELOC_STD_BITS_NS32K_TYPE_SH_BIG 1 +#define RELOC_STD_BITS_NS32K_TYPE_SH_LITTLE 5 + +reloc_howto_type * +MY(reloc_howto)(abfd, rel, r_index, r_extern, r_pcrel) + bfd *abfd; + struct reloc_std_external *rel; + int *r_index; + int *r_extern; + int *r_pcrel; +{ + unsigned int r_length; + int r_ns32k_type; +/* BFD_ASSERT(abfd->xvec->header_byteorder_big_p == false); */ + *r_index = ((rel->r_index[2] << 16) + | (rel->r_index[1] << 8) + | rel->r_index[0] ); + *r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); + *r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); + r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) + >> RELOC_STD_BITS_LENGTH_SH_LITTLE); + r_ns32k_type = ((rel->r_type[0] & RELOC_STD_BITS_NS32K_TYPE_LITTLE) + >> RELOC_STD_BITS_NS32K_TYPE_SH_LITTLE); + return (MY(howto_table) + r_length + 3 * (*r_pcrel) + 6 * r_ns32k_type); +} + +#define MY_reloc_howto(BFD,REL,IN,EX,PC) MY(reloc_howto)(BFD, REL, &IN, &EX, &PC) + +void +MY(put_reloc)(abfd, r_extern, r_index, value, howto, reloc) + bfd *abfd; + int r_extern; + int r_index; + long value; + reloc_howto_type *howto; + struct reloc_std_external *reloc; +{ + unsigned int r_length; + int r_pcrel; + int r_ns32k_type; + PUT_WORD (abfd, value, reloc->r_address); + r_length = howto->size ; /* Size as a power of two */ + r_pcrel = (int) howto->pc_relative; /* Relative to PC? */ + r_ns32k_type = (howto - MY(howto_table) )/6; +/* BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false); */ + reloc->r_index[2] = r_index >> 16; + reloc->r_index[1] = r_index >> 8; + reloc->r_index[0] = r_index; + reloc->r_type[0] = + (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0) + | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0) + | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE) + | (r_ns32k_type << RELOC_STD_BITS_NS32K_TYPE_SH_LITTLE); +} + +#define MY_put_reloc(BFD, EXT, IDX, VAL, HOWTO, RELOC) \ + MY(put_reloc)(BFD, EXT, IDX, VAL, HOWTO, RELOC) + +#define STAT_FOR_EXEC + +#define MY_final_link_relocate ns32k_final_link_relocate +#define MY_relocate_contents ns32k_relocate_contents + +#include <aoutx.h> + +CONST struct reloc_howto_struct * + MY(bfd_reloc_type_lookup)(abfd,code) + bfd *abfd; + bfd_reloc_code_real_type code; +{ + +#define ENTRY(i,j) case i: return &MY(howto_table)[j] + + int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE; + + BFD_ASSERT(ext == 0); + if (code == BFD_RELOC_CTOR) + switch (bfd_get_arch_info (abfd)->bits_per_address) + { + case 32: + code = BFD_RELOC_32; + break; + } + switch (code) + { + ENTRY(BFD_RELOC_NS32K_IMM_8, 0); + ENTRY(BFD_RELOC_NS32K_IMM_16, 1); + ENTRY(BFD_RELOC_NS32K_IMM_32, 2); + ENTRY(BFD_RELOC_NS32K_IMM_8_PCREL, 3); + ENTRY(BFD_RELOC_NS32K_IMM_16_PCREL, 4); + ENTRY(BFD_RELOC_NS32K_IMM_32_PCREL, 5); + ENTRY(BFD_RELOC_NS32K_DISP_8, 6); + ENTRY(BFD_RELOC_NS32K_DISP_16, 7); + ENTRY(BFD_RELOC_NS32K_DISP_32, 8); + ENTRY(BFD_RELOC_NS32K_DISP_8_PCREL, 9); + ENTRY(BFD_RELOC_NS32K_DISP_16_PCREL, 10); + ENTRY(BFD_RELOC_NS32K_DISP_32_PCREL, 11); + ENTRY(BFD_RELOC_8, 12); + ENTRY(BFD_RELOC_16, 13); + ENTRY(BFD_RELOC_32, 14); + ENTRY(BFD_RELOC_8_PCREL, 15); + ENTRY(BFD_RELOC_16_PCREL, 16); + ENTRY(BFD_RELOC_32_PCREL, 17); + default: return (CONST struct reloc_howto_struct *) 0; + } +#undef ENTRY +} + + +static void +MY_swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) + bfd *abfd; + struct reloc_std_external *bytes; + arelent *cache_ptr; + asymbol **symbols; +{ + int r_index; + int r_extern; + unsigned int r_length; + int r_pcrel; + int r_ns32k_type; + struct aoutdata *su = &(abfd->tdata.aout_data->a); + + cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address); + + /* now the fun stuff */ + + cache_ptr->howto = MY_reloc_howto(abfd, bytes, r_index, r_extern, r_pcrel); + + MOVE_ADDRESS(0); +} + +static void +MY_swap_std_reloc_out (abfd, g, natptr) + bfd *abfd; + arelent *g; + struct reloc_std_external *natptr; +{ + int r_index; + asymbol *sym = *(g->sym_ptr_ptr); + int r_extern; + unsigned int r_length; + int r_pcrel; + int r_ns32k_type; + unsigned int r_addend; + asection *output_section = sym->section->output_section; + + r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma; + + /* name was clobbered by aout_write_syms to be symbol index */ + + /* If this relocation is relative to a symbol then set the + r_index to the symbols index, and the r_extern bit. + + Absolute symbols can come in in two ways, either as an offset + from the abs section, or as a symbol which has an abs value. + Check for that here. */ + + if (bfd_is_com_section (output_section) + || output_section == &bfd_abs_section + || output_section == &bfd_und_section) + { + if (bfd_abs_section.symbol == sym) + { + /* Whoops, looked like an abs symbol, but is really an offset + from the abs section */ + r_index = 0; + r_extern = 0; + } + else + { + /* Fill in symbol */ + r_extern = 1; +#define KEEPIT flags + r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT); +#undef KEEPIT + } + } + else + { + /* Just an ordinary section */ + r_extern = 0; + r_index = output_section->target_index; + } + + MY_put_reloc (abfd, r_extern, r_index, g->address, g->howto, natptr); +} + +bfd_reloc_status_type +ns32k_relocate_contents (howto, input_bfd, relocation, location) + reloc_howto_type *howto; + bfd *input_bfd; + bfd_vma relocation; + bfd_byte *location; +{ + int r_ns32k_type = (howto - MY(howto_table)) / 6; + long (*get_data)(); + int (*put_data)(); + + switch (r_ns32k_type) + { + case 0: + get_data = ns32k_get_immediate; + put_data = ns32k_put_immediate; + break; + case 1: + get_data = ns32k_get_displacement; + put_data = ns32k_put_displacement; + break; + case 2: + return _bfd_relocate_contents (howto, input_bfd, relocation, + location); + /* NOT REACHED */ + break; + } + return do_ns32k_reloc_contents (howto, input_bfd, relocation, + location, get_data, put_data); +} diff --git a/bfd/aoutx.h b/bfd/aoutx.h index c0d934e..47dd37b 100644 --- a/bfd/aoutx.h +++ b/bfd/aoutx.h @@ -723,6 +723,16 @@ NAME(aout,machine_type) (arch, machine, unknown) } break; + case bfd_arch_vax: + *unknown = false; + break; + + /* start-sanitize-rce */ + case bfd_arch_rce: + arch_flags = M_RCE; + break; + /* end-sanitize-rce */ + default: arch_flags = M_UNKNOWN; } @@ -813,6 +823,8 @@ adjust_o_magic (abfd, execp) vma += pad; obj_datasec(abfd)->vma = vma; } + else + vma = obj_datasec(abfd)->vma; obj_datasec(abfd)->filepos = pos; pos += obj_datasec(abfd)->_raw_size; vma += obj_datasec(abfd)->_raw_size; @@ -2729,11 +2741,26 @@ NAME(aout,link_add_symbols) (abfd, info) bfd *abfd; struct bfd_link_info *info; { + bfd *first; + switch (bfd_get_format (abfd)) { case bfd_object: return aout_link_add_object_symbols (abfd, info); case bfd_archive: + first = bfd_openr_next_archived_file (abfd, (bfd *) NULL); + if (first == NULL) + return false; + if (! bfd_check_format (first, bfd_object)) + return false; + if (bfd_get_flavour (first) != bfd_target_aout_flavour) + { + /* On Linux, we may have an ELF archive which got recognized + as an a.out archive. Therefore, we treat all archives as + though they were actually of the flavour of their first + element. */ + return (*first->xvec->_bfd_link_add_symbols) (abfd, info); + } return _bfd_generic_link_add_archive_symbols (abfd, info, aout_link_check_archive_element); default: @@ -4844,7 +4871,7 @@ aout_link_reloc_link_order (finfo, o, p) struct bfd_link_order_reloc *pr; int r_index; int r_extern; - const reloc_howto_type *howto; + reloc_howto_type *howto; file_ptr *reloff_ptr; struct reloc_std_external srel; struct reloc_ext_external erel; @@ -4897,7 +4924,7 @@ aout_link_reloc_link_order (finfo, o, p) } howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc); - if (howto == (const reloc_howto_type *) NULL) + if (howto == 0) { bfd_set_error (bfd_error_bad_value); return false; diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 6a25c59..3ea5cc7 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -537,6 +537,9 @@ extern boolean bfd_ecoff_write_accumulated_debug PARAMS ((PTR handle, bfd *abfd, struct ecoff_debug_info *debug, const struct ecoff_debug_swap *swap, struct bfd_link_info *info, file_ptr where)); +extern boolean bfd_mips_ecoff_create_embedded_relocs + PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *, + char **)); /* Externally visible ELF routines. */ @@ -1168,7 +1171,7 @@ enum complain_overflow }; typedef unsigned char bfd_byte; -typedef struct reloc_howto_struct reloc_howto_type; +typedef const struct reloc_howto_struct reloc_howto_type; struct reloc_howto_struct { @@ -1267,7 +1270,7 @@ struct reloc_howto_struct } \ } int -bfd_get_reloc_size PARAMS ((const reloc_howto_type *)); +bfd_get_reloc_size PARAMS ((reloc_howto_type *)); typedef struct relent_chain { arelent relent; diff --git a/bfd/cf-m68klynx.c b/bfd/cf-m68klynx.c index bc6cb29..0a4dc09 100644 --- a/bfd/cf-m68klynx.c +++ b/bfd/cf-m68klynx.c @@ -104,7 +104,7 @@ _bfd_m68klynx_special_fn (abfd, reloc_entry, symbol, data, input_section, if (diff != 0) { - const reloc_howto_type *howto = reloc_entry->howto; + reloc_howto_type *howto = reloc_entry->howto; unsigned char *addr = (unsigned char *) data + reloc_entry->address; switch (howto->size) diff --git a/bfd/coff-i386.c b/bfd/coff-i386.c index da8d0d8..f3af8f1 100644 --- a/bfd/coff-i386.c +++ b/bfd/coff-i386.c @@ -26,13 +26,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "coff/internal.h" #include "libcoff.h" -static bfd_reloc_status_type coff_i386_reloc PARAMS ((bfd *abfd, - arelent *reloc_entry, - asymbol *symbol, - PTR data, - asection *input_section, - bfd *output_bfd, - char **error_message)); +static bfd_reloc_status_type coff_i386_reloc + PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); +static const struct reloc_howto_struct *coff_i386_rtype_to_howto + PARAMS ((bfd *, asection *, struct internal_reloc *, + struct coff_link_hash_entry *, struct internal_syment *, + bfd_vma *)); + +#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) + +/* The page size is a guess based on ELF. */ +#define COFF_PAGE_SIZE 0x1000 /* For some reason when using i386 COFF the value stored in the .text section for a reference to a common symbol is the value itself plus @@ -88,7 +92,7 @@ coff_i386_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, if (diff != 0) { - const reloc_howto_type *howto = reloc_entry->howto; + reloc_howto_type *howto = reloc_entry->howto; unsigned char *addr = (unsigned char *) data + reloc_entry->address; switch (howto->size) @@ -242,7 +246,7 @@ static reloc_howto_type howto_table[] = #define I386 1 /* Customize coffcode.h */ #define RTYPE2HOWTO(cache_ptr, dst) \ - cache_ptr->howto = howto_table + (dst)->r_type; + (cache_ptr)->howto = howto_table + (dst)->r_type; /* On SCO Unix 3.2.2 the native assembler generates two .data sections. We handle that by renaming the second one to .data2. It @@ -287,16 +291,57 @@ static reloc_howto_type howto_table[] = cache_ptr->addend += asect->vma; \ } +/* We use the special COFF backend linker. */ +#define coff_relocate_section _bfd_coff_generic_relocate_section + +static const struct reloc_howto_struct * +coff_i386_rtype_to_howto (abfd, sec, rel, h, sym, addendp) + bfd *abfd; + asection *sec; + struct internal_reloc *rel; + struct coff_link_hash_entry *h; + struct internal_syment *sym; + bfd_vma *addendp; +{ + const struct reloc_howto_struct *howto; + + howto = howto_table + rel->r_type; + + if (howto->pc_relative) + *addendp += sec->vma; + + if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0) + { + /* This is a common symbol. The section contents include the + size (sym->n_value) as an addend. The relocate_section + function will be adding in the final value of the symbol. We + need to subtract out the current size in order to get the + correct result. */ + BFD_ASSERT (h != NULL); + *addendp -= sym->n_value; + } + + /* If the output symbol is common (in which case this must be a + relocateable link), we need to add in the final size of the + common symbol. */ + if (h != NULL && h->root.type == bfd_link_hash_common) + *addendp += h->root.u.c.size; + + return howto; +} + +#define coff_rtype_to_howto coff_i386_rtype_to_howto + #include "coffcode.h" -static bfd_target * +static const bfd_target * i3coff_object_p(a) bfd *a; { return coff_object_p(a); } -bfd_target +const bfd_target #ifdef TARGET_SYM TARGET_SYM = #else @@ -314,10 +359,14 @@ bfd_target (HAS_RELOC | EXEC_P | /* object flags */ HAS_LINENO | HAS_DEBUG | - HAS_SYMS | HAS_LOCALS | WP_TEXT), + HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ +#ifdef TARGET_UNDERSCORE + TARGET_UNDERSCORE, /* leading underscore */ +#else 0, /* leading underscore */ +#endif '/', /* ar_pad_char */ 15, /* ar_max_namelen */ @@ -345,6 +394,7 @@ bfd_target BFD_JUMP_TABLE_RELOCS (coff), BFD_JUMP_TABLE_WRITE (coff), BFD_JUMP_TABLE_LINK (coff), + BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), COFF_SWAP_TABLE, }; diff --git a/bfd/coff-m68k.c b/bfd/coff-m68k.c index 773a514..dfd38ee 100644 --- a/bfd/coff-m68k.c +++ b/bfd/coff-m68k.c @@ -30,6 +30,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define LYNX_SPECIAL_FN 0 #endif +#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1) + /* The page size is a guess based on ELF. */ #define COFF_PAGE_SIZE 0x2000 @@ -37,6 +39,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define m68kcoff_howto_table _bfd_m68kcoff_howto_table #define m68k_rtype2howto _bfd_m68kcoff_rtype2howto #define m68k_howto2rtype _bfd_m68kcoff_howto2rtype +#define m68k_reloc_type_lookup _bfd_m68kcoff_reloc_type_lookup #ifdef ONLY_DECLARE_RELOCS extern reloc_howto_type m68kcoff_howto_table[]; @@ -63,7 +66,7 @@ reloc_howto_type m68kcoff_howto_table[] = #ifdef ONLY_DECLARE_RELOCS extern void m68k_rtype2howto PARAMS ((arelent *internal, int relocentry)); extern int m68k_howto2rtype PARAMS ((CONST struct reloc_howto_struct *)); -extern const reloc_howto_type *_bfd_coff_m68k_reloc_type_lookup +extern reloc_howto_type *m68k_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_code_real_type)); #else void @@ -108,8 +111,8 @@ m68k_howto2rtype (internal) return R_RELLONG; } -const reloc_howto_type * -_bfd_coff_m68k_reloc_type_lookup (abfd, code) +reloc_howto_type * +m68k_reloc_type_lookup (abfd, code) bfd *abfd; bfd_reloc_code_real_type code; { @@ -136,7 +139,9 @@ _bfd_coff_m68k_reloc_type_lookup (abfd, code) #define SELECT_RELOC(external, internal) \ external.r_type = m68k_howto2rtype(internal); -#define coff_bfd_reloc_type_lookup _bfd_coff_m68k_reloc_type_lookup +#define coff_bfd_reloc_type_lookup m68k_reloc_type_lookup + +#define coff_relocate_section _bfd_coff_generic_relocate_section #include "coffcode.h" diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c new file mode 100644 index 0000000..7db11ad --- /dev/null +++ b/bfd/elf32-arc.c @@ -0,0 +1,159 @@ +/* ARC-specific support for 32-bit ELF + Copyright (C) 1994 Free Software Foundation, Inc. + Contributed by Doug Evans (dje@cygnus.com). + +This file is part of BFD, the Binary File Descriptor library. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" +#include "libelf.h" + +static bfd_reloc_status_type arc_elf_unsupported_reloc + PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); +static const struct reloc_howto_struct *bfd_elf32_bfd_reloc_type_lookup + PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); +static void arc_info_to_howto + PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst)); + +enum reloc_type +{ + R_ARC_NONE = 0, + R_ARC_ADDR32, + R_ARC_B22_PCREL, + R_ARC_max +}; + +static reloc_howto_type elf_arc_howto_table[] = +{ + /* This reloc does nothing. */ + HOWTO (R_ARC_NONE, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARC_NONE", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + 0, /* dst_mask */ + false), /* pcrel_offset */ + + /* A standard 32 bit relocation. */ + HOWTO (R_ARC_ADDR32, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARC_ADDR32", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + 0xffffffff, /* dst_mask */ + false), /* pcrel_offset */ + + /* A relative 22 bit branch; the lower two bits must be zero. */ + HOWTO (R_ARC_B22_PCREL, /* type */ + 2, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 22, /* bitsize */ + true, /* pc_relative */ + 7, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARC_B22_PCREL", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + 0x07ffff80, /* dst_mask */ + true), /* pcrel_offset */ + +}; + +/* Don't pretend we can deal with unsupported relocs. */ + +static bfd_reloc_status_type +arc_elf_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section, + output_bfd, error_message) + bfd *abfd; + arelent *reloc_entry; + asymbol *symbol; + PTR data; + asection *input_section; + bfd *output_bfd; + char **error_message; +{ + abort (); +} + +/* Map BFD reloc types to PowerPC ELF reloc types. */ + +struct arc_reloc_map +{ + unsigned char bfd_reloc_val; + unsigned char elf_reloc_val; +}; + +static const struct arc_reloc_map arc_reloc_map[] = +{ + { BFD_RELOC_NONE, R_ARC_NONE, }, + { BFD_RELOC_32, R_ARC_ADDR32 }, + { BFD_RELOC_CTOR, R_ARC_ADDR32 }, + { BFD_RELOC_ARC_B22_PCREL, R_ARC_B22_PCREL }, +}; + +static const struct reloc_howto_struct * +bfd_elf32_bfd_reloc_type_lookup (abfd, code) + bfd *abfd; + bfd_reloc_code_real_type code; +{ + int i; + + for (i = 0; + i < sizeof (arc_reloc_map) / sizeof (struct arc_reloc_map); + i++) + { + if (arc_reloc_map[i].bfd_reloc_val == code) + return &elf_arc_howto_table[arc_reloc_map[i].elf_reloc_val]; + } + + return NULL; +} + +/* Set the howto pointer for an ARC ELF reloc. */ + +static void +arc_info_to_howto (abfd, cache_ptr, dst) + bfd *abfd; + arelent *cache_ptr; + Elf32_Internal_Rela *dst; +{ + BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_ARC_max); + cache_ptr->howto = &elf_arc_howto_table[ELF32_R_TYPE (dst->r_info)]; +} + +#define TARGET_BIG_SYM bfd_elf32_arc_vec +#define TARGET_BIG_NAME "elf32-arc" +#define ELF_ARCH bfd_arch_arc +#define ELF_MACHINE_CODE EM_CYGNUS_ARC +#define ELF_MAXPAGESIZE 0x10000 +#define elf_info_to_howto arc_info_to_howto + +#include "elf32-target.h" diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index a80cf70..81d7540 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -973,7 +973,7 @@ elf_i386_relocate_section (output_bfd, info, input_bfd, input_section, for (; rel < relend; rel++) { int r_type; - const reloc_howto_type *howto; + reloc_howto_type *howto; long r_symndx; struct elf_link_hash_entry *h; Elf_Internal_Sym *sym; diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index 08d2d7f..544d0cd 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -96,7 +96,7 @@ static void mips_elf_relocate_hi16 bfd_vma)); static boolean mips_elf_relocate_section PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, - Elf_Internal_Rela *, Elf_Internal_Sym *, asection **, char *)); + Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); static boolean mips_elf_add_symbol_hook PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, const char **, flagword *, asection **, bfd_vma *)); @@ -1045,6 +1045,11 @@ mips_elf_section_from_bfd_section (abfd, hdr, sec, retval) *retval = SHN_MIPS_SCOMMON; return true; } + if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0) + { + *retval = SHN_MIPS_ACOMMON; + return true; + } return false; } @@ -2151,8 +2156,7 @@ mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend) static boolean mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, - contents, relocs, local_syms, local_sections, - output_names) + contents, relocs, local_syms, local_sections) bfd *output_bfd; struct bfd_link_info *info; bfd *input_bfd; @@ -2161,7 +2165,6 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, Elf_Internal_Rela *relocs; Elf_Internal_Sym *local_syms; asection **local_sections; - char *output_names; { Elf_Internal_Shdr *symtab_hdr; size_t locsymcount; @@ -2187,7 +2190,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, for (; rel < relend; rel++) { int r_type; - const reloc_howto_type *howto; + reloc_howto_type *howto; long r_symndx; bfd_vma addend; struct elf_link_hash_entry *h; @@ -2375,7 +2378,9 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, name = h->root.root.string; else { - name = output_names + sym->st_name; + name = elf_string_from_elf_section (input_bfd, + symtab_hdr->sh_link, + sym->st_name); if (name == NULL) return false; if (*name == '\0') diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c index 006db67..fdb19f1 100644 --- a/bfd/elf32-sparc.c +++ b/bfd/elf32-sparc.c @@ -952,7 +952,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section, for (; rel < relend; rel++) { int r_type; - const reloc_howto_type *howto; + reloc_howto_type *howto; long r_symndx; struct elf_link_hash_entry *h; Elf_Internal_Sym *sym; diff --git a/bfd/libbfd.h b/bfd/libbfd.h index a9484ee..9d1cc25 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -242,7 +242,7 @@ extern boolean _bfd_archive_coff_construct_extended_name_table #define _bfd_norelocs_canonicalize_reloc \ ((long (*) PARAMS ((bfd *, asection *, arelent **, asymbol **))) _bfd_n1) #define _bfd_norelocs_bfd_reloc_type_lookup \ - ((const reloc_howto_type *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) \ + ((reloc_howto_type *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) \ bfd_nullvoidptr) /* Routines to use for BFD_JUMP_TABLE_WRITE for targets which may not @@ -358,12 +358,12 @@ extern unsigned int _bfd_count_link_order_relocs /* Final link relocation routine. */ extern bfd_reloc_status_type _bfd_final_link_relocate - PARAMS ((const reloc_howto_type *, bfd *, asection *, bfd_byte *, + PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma address, bfd_vma value, bfd_vma addend)); /* Relocate a particular location by a howto and a value. */ extern bfd_reloc_status_type _bfd_relocate_contents - PARAMS ((const reloc_howto_type *, bfd *, bfd_vma, bfd_byte *)); + PARAMS ((reloc_howto_type *, bfd *, bfd_vma, bfd_byte *)); /* Create a string table. */ extern struct bfd_strtab_hash *_bfd_stringtab_init PARAMS ((void)); @@ -553,6 +553,10 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_ARM_SWI", "BFD_RELOC_ARM_MULTI", "BFD_RELOC_ARM_CP_OFF_IMM", +/* start-sanitize-arc */ + "BFD_RELOC_ARC_B22_PCREL", +/* end-sanitize-arc */ + "@@overflow: BFD_RELOC_UNUSED@@", }; #endif diff --git a/bfd/reloc.c b/bfd/reloc.c index ade22e2..3285252 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -287,7 +287,7 @@ CODE_FRAGMENT .struct symbol_cache_entry; {* Forward declaration *} . .typedef unsigned char bfd_byte; -.typedef struct reloc_howto_struct reloc_howto_type; +.typedef const struct reloc_howto_struct reloc_howto_type; . .struct reloc_howto_struct .{ @@ -413,7 +413,7 @@ FUNCTION bfd_get_reloc_size SYNOPSIS - int bfd_get_reloc_size (const reloc_howto_type *); + int bfd_get_reloc_size (reloc_howto_type *); DESCRIPTION For a reloc_howto_type that operates on a fixed number of bytes, @@ -422,7 +422,7 @@ DESCRIPTION int bfd_get_reloc_size (howto) - const reloc_howto_type *howto; + reloc_howto_type *howto; { switch (howto->size) { @@ -500,7 +500,7 @@ bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd, bfd_reloc_status_type flag = bfd_reloc_ok; bfd_size_type addr = reloc_entry->address; bfd_vma output_base = 0; - const reloc_howto_type *howto = reloc_entry->howto; + reloc_howto_type *howto = reloc_entry->howto; asection *reloc_target_output_section; asymbol *symbol; @@ -961,7 +961,7 @@ bfd_install_relocation (abfd, reloc_entry, data_start, data_start_offset, bfd_reloc_status_type flag = bfd_reloc_ok; bfd_size_type addr = reloc_entry->address; bfd_vma output_base = 0; - const reloc_howto_type *howto = reloc_entry->howto; + reloc_howto_type *howto = reloc_entry->howto; asection *reloc_target_output_section; asymbol *symbol; bfd_byte *data; @@ -1395,7 +1395,7 @@ space consuming. For each target: bfd_reloc_status_type _bfd_final_link_relocate (howto, input_bfd, input_section, contents, address, value, addend) - const reloc_howto_type *howto; + reloc_howto_type *howto; bfd *input_bfd; asection *input_section; bfd_byte *contents; @@ -1441,7 +1441,7 @@ _bfd_final_link_relocate (howto, input_bfd, input_section, contents, address, bfd_reloc_status_type _bfd_relocate_contents (howto, input_bfd, relocation, location) - const reloc_howto_type *howto; + reloc_howto_type *howto; bfd *input_bfd; bfd_vma relocation; bfd_byte *location; @@ -2006,6 +2006,18 @@ ENUMDOC These relocs are only used within the ARM assembler. They are not (at present) written to any object files. +COMMENT +{* start-sanitize-arc *} +ENUM + BFD_RELOC_ARC_B22_PCREL +ENUMDOC + Argonaut RISC Core (ARC) relocs. + ARC 22 bit pc-relative branch. The lowest two bits must be zero and are + not stored in the instruction. High 20 bits installed in bits 7 through 26 + of instruction. +COMMENT +{* end-sanitize-arc *} + ENDSENUM BFD_RELOC_UNUSED |