1999-05-03 09:29:11 +02:00
|
|
|
/* BFD back-end for Sparc COFF files.
|
* aout-target.h, aoutf1.h, bfdio.c, bfdwin.c: Update copyright date.
* coff-apollo.c, coff-sparc.c, coff-w65.c, coff-we32k.c: Ditto.
* coff-z8k.c, coffgen.c, cpu-frv.c, cpu-h8500.c, cpu-hppa.c: Ditto.
* cpu-ia64-opc.c, cpu-m10300.c, cpu-mips.c, cpu-msp430.c: Ditto.
* cpu-rs6000.c, cpu-z8k.c, efi-app-ia32.c, elf32-am33lin.c: Ditto.
* gen-aout.c, hash.c, hp300hpux.c, init.c, mach-o.c: Ditto.
* nlm-target.h, nlm.c, som.h, stabs.c, sysdep.h, xsym.h: Ditto.
2003-11-04 12:30:54 +01:00
|
|
|
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
|
|
|
|
2002, 2003 Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
Written by Cygnus Support.
|
|
|
|
|
|
|
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
#include "bfd.h"
|
|
|
|
#include "sysdep.h"
|
|
|
|
#include "libbfd.h"
|
|
|
|
#include "coff/sparc.h"
|
|
|
|
#include "coff/internal.h"
|
|
|
|
#include "libcoff.h"
|
|
|
|
|
|
|
|
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
|
|
|
|
|
|
|
|
#define BADMAG(x) ((x).f_magic != SPARCMAGIC && (x).f_magic != LYNXCOFFMAGIC)
|
|
|
|
|
|
|
|
/* The page size is a guess based on ELF. */
|
|
|
|
#define COFF_PAGE_SIZE 0x10000
|
|
|
|
|
2001-08-21 10:40:23 +02:00
|
|
|
|
|
|
|
static reloc_howto_type *coff_sparc_reloc_type_lookup
|
|
|
|
PARAMS ((bfd *, bfd_reloc_code_real_type));
|
|
|
|
static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
|
Touches most files in bfd/, so likely will be blamed for everything..
o bfd_read and bfd_write lose an unnecessary param and become
bfd_bread and bfd_bwrite.
o bfd_*alloc now all take a bfd_size_type arg, and will error if
size_t is too small. eg. 32 bit host, 64 bit bfd, verrry big files
or bugs in linker scripts etc.
o file_ptr becomes a bfd_signed_vma. Besides matching sizes with
various other types involved in handling sections, this should make
it easier for bfd to support a 64 bit off_t on 32 bit hosts that
provide it.
o I've made the H_GET_* and H_PUT_* macros (which invoke bfd_h_{get,put}_*)
generally available. They now cast their args to bfd_vma and
bfd_byte * as appropriate, which removes a swag of casts from the
source.
o Bug fixes to bfd_get8, aix386_core_vec, elf32_h8_relax_section, and
aout-encap.c.
o Zillions of formatting and -Wconversion fixes.
2001-09-18 11:57:26 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
enum reloc_type
|
|
|
|
{
|
|
|
|
R_SPARC_NONE = 0,
|
2000-11-16 01:54:12 +01:00
|
|
|
R_SPARC_8, R_SPARC_16, R_SPARC_32,
|
|
|
|
R_SPARC_DISP8, R_SPARC_DISP16, R_SPARC_DISP32,
|
1999-05-03 09:29:11 +02:00
|
|
|
R_SPARC_WDISP30, R_SPARC_WDISP22,
|
|
|
|
R_SPARC_HI22, R_SPARC_22,
|
|
|
|
R_SPARC_13, R_SPARC_LO10,
|
|
|
|
R_SPARC_GOT10, R_SPARC_GOT13, R_SPARC_GOT22,
|
|
|
|
R_SPARC_PC10, R_SPARC_PC22,
|
|
|
|
R_SPARC_WPLT30,
|
|
|
|
R_SPARC_COPY,
|
|
|
|
R_SPARC_GLOB_DAT, R_SPARC_JMP_SLOT,
|
|
|
|
R_SPARC_RELATIVE,
|
|
|
|
R_SPARC_UA32,
|
|
|
|
R_SPARC_max
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is stolen pretty directly from elf.c. */
|
|
|
|
static bfd_reloc_status_type
|
|
|
|
bfd_coff_generic_reloc PARAMS ((bfd *, arelent *, asymbol *, PTR,
|
|
|
|
asection *, bfd *, char **));
|
|
|
|
|
|
|
|
static bfd_reloc_status_type
|
|
|
|
bfd_coff_generic_reloc (abfd, reloc_entry, symbol, data, input_section,
|
|
|
|
output_bfd, error_message)
|
1999-07-12 12:30:21 +02:00
|
|
|
bfd *abfd ATTRIBUTE_UNUSED;
|
1999-05-03 09:29:11 +02:00
|
|
|
arelent *reloc_entry;
|
|
|
|
asymbol *symbol;
|
1999-07-12 12:30:21 +02:00
|
|
|
PTR data ATTRIBUTE_UNUSED;
|
1999-05-03 09:29:11 +02:00
|
|
|
asection *input_section;
|
|
|
|
bfd *output_bfd;
|
1999-07-12 12:30:21 +02:00
|
|
|
char **error_message ATTRIBUTE_UNUSED;
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
if (output_bfd != (bfd *) NULL
|
|
|
|
&& (symbol->flags & BSF_SECTION_SYM) == 0)
|
|
|
|
{
|
|
|
|
reloc_entry->address += input_section->output_offset;
|
|
|
|
return bfd_reloc_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfd_reloc_continue;
|
|
|
|
}
|
|
|
|
|
2000-11-16 01:54:12 +01:00
|
|
|
static reloc_howto_type coff_sparc_howto_table[] =
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2002-11-30 09:39:46 +01:00
|
|
|
HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
|
|
|
HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_8", FALSE,0,0x000000ff,TRUE),
|
|
|
|
HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_32", FALSE,0,0xffffffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
|
|
|
|
HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_DISP32", FALSE,0,0x00ffffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_22", FALSE,0,0x003fffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_13", FALSE,0,0x00001fff,TRUE),
|
|
|
|
HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
|
|
|
|
HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
|
|
|
|
HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
|
|
|
|
HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_PC10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
|
|
|
|
HOWTO(R_SPARC_PC22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
|
|
|
|
HOWTO(R_SPARC_WPLT30, 0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_WPLT30", FALSE,0,0x00000000,TRUE),
|
|
|
|
HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
|
|
|
|
HOWTO(R_SPARC_GLOB_DAT,0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_GLOB_DAT",FALSE,0,0x00000000,TRUE),
|
|
|
|
HOWTO(R_SPARC_JMP_SLOT,0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_JMP_SLOT",FALSE,0,0x00000000,TRUE),
|
|
|
|
HOWTO(R_SPARC_RELATIVE,0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
|
|
|
|
HOWTO(R_SPARC_UA32, 0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_UA32", FALSE,0,0x00000000,TRUE),
|
1999-05-03 09:29:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct coff_reloc_map {
|
|
|
|
bfd_reloc_code_real_type bfd_reloc_val;
|
|
|
|
unsigned char coff_reloc_val;
|
|
|
|
};
|
|
|
|
|
Touches most files in bfd/, so likely will be blamed for everything..
o bfd_read and bfd_write lose an unnecessary param and become
bfd_bread and bfd_bwrite.
o bfd_*alloc now all take a bfd_size_type arg, and will error if
size_t is too small. eg. 32 bit host, 64 bit bfd, verrry big files
or bugs in linker scripts etc.
o file_ptr becomes a bfd_signed_vma. Besides matching sizes with
various other types involved in handling sections, this should make
it easier for bfd to support a 64 bit off_t on 32 bit hosts that
provide it.
o I've made the H_GET_* and H_PUT_* macros (which invoke bfd_h_{get,put}_*)
generally available. They now cast their args to bfd_vma and
bfd_byte * as appropriate, which removes a swag of casts from the
source.
o Bug fixes to bfd_get8, aix386_core_vec, elf32_h8_relax_section, and
aout-encap.c.
o Zillions of formatting and -Wconversion fixes.
2001-09-18 11:57:26 +02:00
|
|
|
static const struct coff_reloc_map sparc_reloc_map[] =
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
{ BFD_RELOC_NONE, R_SPARC_NONE, },
|
|
|
|
{ BFD_RELOC_16, R_SPARC_16, },
|
|
|
|
{ BFD_RELOC_8, R_SPARC_8 },
|
|
|
|
{ BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
|
|
|
|
{ BFD_RELOC_CTOR, R_SPARC_32 }, /* @@ Assumes 32 bits. */
|
|
|
|
{ BFD_RELOC_32, R_SPARC_32 },
|
|
|
|
{ BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
|
|
|
|
{ BFD_RELOC_HI22, R_SPARC_HI22 },
|
|
|
|
{ BFD_RELOC_LO10, R_SPARC_LO10, },
|
|
|
|
{ BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
|
|
|
|
{ BFD_RELOC_SPARC22, R_SPARC_22 },
|
|
|
|
{ BFD_RELOC_SPARC13, R_SPARC_13 },
|
|
|
|
{ BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
|
|
|
|
{ BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
|
|
|
|
{ BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
|
|
|
|
{ BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
|
|
|
|
{ BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
|
|
|
|
{ BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
|
|
|
|
{ BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
|
|
|
|
{ BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
|
|
|
|
{ BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
|
|
|
|
{ BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
|
|
|
|
{ BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
|
|
|
|
/* { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
|
|
|
|
};
|
|
|
|
|
|
|
|
static reloc_howto_type *
|
|
|
|
coff_sparc_reloc_type_lookup (abfd, code)
|
1999-07-12 12:30:21 +02:00
|
|
|
bfd *abfd ATTRIBUTE_UNUSED;
|
1999-05-03 09:29:11 +02:00
|
|
|
bfd_reloc_code_real_type code;
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct coff_reloc_map); i++)
|
|
|
|
{
|
|
|
|
if (sparc_reloc_map[i].bfd_reloc_val == code)
|
|
|
|
return &coff_sparc_howto_table[(int) sparc_reloc_map[i].coff_reloc_val];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#define coff_bfd_reloc_type_lookup coff_sparc_reloc_type_lookup
|
|
|
|
|
|
|
|
static void
|
|
|
|
rtype2howto (cache_ptr, dst)
|
|
|
|
arelent *cache_ptr;
|
|
|
|
struct internal_reloc *dst;
|
|
|
|
{
|
|
|
|
BFD_ASSERT (dst->r_type < (unsigned int) R_SPARC_max);
|
|
|
|
cache_ptr->howto = &coff_sparc_howto_table[dst->r_type];
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
|
|
|
|
|
Touches most files in bfd/, so likely will be blamed for everything..
o bfd_read and bfd_write lose an unnecessary param and become
bfd_bread and bfd_bwrite.
o bfd_*alloc now all take a bfd_size_type arg, and will error if
size_t is too small. eg. 32 bit host, 64 bit bfd, verrry big files
or bugs in linker scripts etc.
o file_ptr becomes a bfd_signed_vma. Besides matching sizes with
various other types involved in handling sections, this should make
it easier for bfd to support a 64 bit off_t on 32 bit hosts that
provide it.
o I've made the H_GET_* and H_PUT_* macros (which invoke bfd_h_{get,put}_*)
generally available. They now cast their args to bfd_vma and
bfd_byte * as appropriate, which removes a swag of casts from the
source.
o Bug fixes to bfd_get8, aix386_core_vec, elf32_h8_relax_section, and
aout-encap.c.
o Zillions of formatting and -Wconversion fixes.
2001-09-18 11:57:26 +02:00
|
|
|
#define SWAP_IN_RELOC_OFFSET H_GET_32
|
|
|
|
#define SWAP_OUT_RELOC_OFFSET H_PUT_32
|
1999-05-03 09:29:11 +02:00
|
|
|
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
|
|
|
|
cache_ptr->addend = reloc.r_offset;
|
|
|
|
|
|
|
|
/* Clear the r_spare field in relocs. */
|
|
|
|
#define SWAP_OUT_RELOC_EXTRA(abfd,src,dst) \
|
|
|
|
do { \
|
|
|
|
dst->r_spare[0] = 0; \
|
|
|
|
dst->r_spare[1] = 0; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define __A_MAGIC_SET__
|
|
|
|
|
2000-11-16 01:54:12 +01:00
|
|
|
/* Enable Sparc-specific hacks in coffcode.h. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#define COFF_SPARC
|
|
|
|
|
|
|
|
#include "coffcode.h"
|
|
|
|
|
1999-07-19 16:55:16 +02:00
|
|
|
#ifndef TARGET_SYM
|
|
|
|
#define TARGET_SYM sparccoff_vec
|
1999-05-03 09:29:11 +02:00
|
|
|
#endif
|
|
|
|
|
1999-07-19 16:55:16 +02:00
|
|
|
#ifndef TARGET_NAME
|
|
|
|
#define TARGET_NAME "coff-sparc"
|
|
|
|
#endif
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2003-06-04 12:47:33 +02:00
|
|
|
CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM, TARGET_NAME, D_PAGED, 0, '_', NULL, COFF_SWAP_TABLE)
|