1999-05-03 09:29:11 +02:00
|
|
|
/* BFD back-end for TMS320C30 coff binaries.
|
2012-07-13 16:22:50 +02:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2005, 2007, 2008, 2011, 2012
|
2007-03-26 14:23:03 +02:00
|
|
|
Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
Contributed by Steven Haworth (steve@pm.cse.rmit.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
|
2007-07-03 16:26:43 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-05-03 09:29:11 +02:00
|
|
|
(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
|
2005-05-04 17:53:43 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
|
2005-05-04 09:19:45 +02:00
|
|
|
02110-1301, USA. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#include "sysdep.h"
|
2007-04-26 16:47:00 +02:00
|
|
|
#include "bfd.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
#include "libbfd.h"
|
|
|
|
#include "bfdlink.h"
|
|
|
|
#include "coff/tic30.h"
|
|
|
|
#include "coff/internal.h"
|
|
|
|
#include "libcoff.h"
|
|
|
|
|
|
|
|
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
|
|
|
|
|
|
|
|
reloc_howto_type tic30_coff_howto_table[] =
|
2001-08-23 19:05:52 +02:00
|
|
|
{
|
2002-11-30 09:39:46 +01:00
|
|
|
HOWTO (R_TIC30_ABS16, 2, 1, 16, FALSE, 0, 0, NULL,
|
|
|
|
"16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
|
|
|
|
HOWTO (R_TIC30_ABS24, 2, 2, 24, FALSE, 8, complain_overflow_bitfield, NULL,
|
|
|
|
"24", FALSE, 0xFFFFFF00, 0xFFFFFF00, FALSE),
|
|
|
|
HOWTO (R_TIC30_LDP, 18, 0, 24, FALSE, 0, complain_overflow_bitfield, NULL,
|
|
|
|
"LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
|
|
|
|
HOWTO (R_TIC30_ABS32, 2, 2, 32, FALSE, 0, complain_overflow_bitfield, NULL,
|
|
|
|
"32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
|
|
|
|
HOWTO (R_TIC30_PC16, 2, 1, 16, TRUE, 0, complain_overflow_signed, NULL,
|
|
|
|
"PCREL", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
|
2001-08-23 19:05:52 +02:00
|
|
|
EMPTY_HOWTO (-1)
|
|
|
|
};
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#ifndef coff_bfd_reloc_type_lookup
|
|
|
|
#define coff_bfd_reloc_type_lookup tic30_coff_reloc_type_lookup
|
2007-03-26 14:23:03 +02:00
|
|
|
#define coff_bfd_reloc_name_lookup tic30_coff_reloc_name_lookup
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
/* For the case statement use the code values used in tc_gen_reloc to
|
|
|
|
map to the howto table entries that match those in both the aout
|
2000-11-16 01:54:12 +01:00
|
|
|
and coff implementations. */
|
2001-08-23 19:05:52 +02:00
|
|
|
|
2012-07-13 16:22:50 +02:00
|
|
|
static reloc_howto_type *
|
|
|
|
tic30_coff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
|
|
|
|
bfd_reloc_code_real_type code)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case BFD_RELOC_8:
|
|
|
|
case BFD_RELOC_TIC30_LDP:
|
|
|
|
return &tic30_coff_howto_table[2];
|
|
|
|
case BFD_RELOC_16:
|
|
|
|
return &tic30_coff_howto_table[0];
|
|
|
|
case BFD_RELOC_24:
|
|
|
|
return &tic30_coff_howto_table[1];
|
|
|
|
case BFD_RELOC_16_PCREL:
|
|
|
|
return &tic30_coff_howto_table[4];
|
|
|
|
case BFD_RELOC_32:
|
|
|
|
return &tic30_coff_howto_table[3];
|
|
|
|
default:
|
|
|
|
return (reloc_howto_type *) NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-26 14:23:03 +02:00
|
|
|
static reloc_howto_type *
|
|
|
|
tic30_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
|
|
|
|
const char *r_name)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
i < (sizeof (tic30_coff_howto_table)
|
|
|
|
/ sizeof (tic30_coff_howto_table[0]));
|
|
|
|
i++)
|
|
|
|
if (tic30_coff_howto_table[i].name != NULL
|
|
|
|
&& strcasecmp (tic30_coff_howto_table[i].name, r_name) == 0)
|
|
|
|
return &tic30_coff_howto_table[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
#endif
|
|
|
|
|
2001-08-23 19:05:52 +02:00
|
|
|
/* Turn a howto into a reloc number. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
static int
|
2012-07-13 16:22:50 +02:00
|
|
|
coff_tic30_select_reloc (reloc_howto_type *howto)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
return howto->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SELECT_RELOC(x,howto) x.r_type = coff_tic30_select_reloc(howto)
|
|
|
|
|
|
|
|
#define BADMAG(x) TIC30BADMAG(x)
|
|
|
|
#define TIC30 1 /* Customize coffcode.h */
|
|
|
|
#define __A_MAGIC_SET__
|
|
|
|
|
|
|
|
/* Code to swap in the 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
|
|
|
#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 SWAP_OUT_RELOC_EXTRA(abfd, src, dst) dst->r_stuff[0] = 'S'; \
|
|
|
|
dst->r_stuff[1] = 'C';
|
|
|
|
|
2000-11-16 01:54:12 +01:00
|
|
|
/* Code to turn a r_type into a howto ptr, uses the above howto table. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
static void
|
2012-07-13 16:22:50 +02:00
|
|
|
rtype2howto (arelent *internal, struct internal_reloc *dst)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
switch (dst->r_type)
|
|
|
|
{
|
|
|
|
case R_TIC30_ABS16:
|
|
|
|
internal->howto = &tic30_coff_howto_table[0];
|
|
|
|
break;
|
|
|
|
case R_TIC30_ABS24:
|
|
|
|
internal->howto = &tic30_coff_howto_table[1];
|
|
|
|
break;
|
|
|
|
case R_TIC30_ABS32:
|
|
|
|
internal->howto = &tic30_coff_howto_table[3];
|
|
|
|
break;
|
|
|
|
case R_TIC30_LDP:
|
|
|
|
internal->howto = &tic30_coff_howto_table[2];
|
|
|
|
break;
|
|
|
|
case R_TIC30_PC16:
|
|
|
|
internal->howto = &tic30_coff_howto_table[4];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-23 19:05:52 +02:00
|
|
|
#define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
/* Perform any necessary magic to the addend in a reloc entry */
|
|
|
|
|
|
|
|
#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
|
|
|
|
cache_ptr->addend = ext_reloc.r_offset;
|
|
|
|
|
|
|
|
#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
|
|
|
|
reloc_processing(relent, reloc, symbols, abfd, section)
|
|
|
|
|
|
|
|
static void
|
2012-07-13 16:22:50 +02:00
|
|
|
reloc_processing (arelent *relent,
|
|
|
|
struct internal_reloc *reloc,
|
|
|
|
asymbol **symbols,
|
|
|
|
bfd *abfd,
|
|
|
|
asection *section)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
relent->address = reloc->r_vaddr;
|
|
|
|
rtype2howto (relent, reloc);
|
|
|
|
|
|
|
|
if (reloc->r_symndx > 0)
|
2001-08-23 19:05:52 +02:00
|
|
|
relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
|
1999-05-03 09:29:11 +02:00
|
|
|
else
|
2001-08-23 19:05:52 +02:00
|
|
|
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
relent->addend = reloc->r_offset;
|
|
|
|
relent->address -= section->vma;
|
|
|
|
}
|
|
|
|
|
2008-07-18 13:30:22 +02:00
|
|
|
#ifndef bfd_pe_print_pdata
|
|
|
|
#define bfd_pe_print_pdata NULL
|
|
|
|
#endif
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
#include "coffcode.h"
|
|
|
|
|
|
|
|
const bfd_target tic30_coff_vec =
|
|
|
|
{
|
|
|
|
"coff-tic30", /* name */
|
|
|
|
bfd_target_coff_flavour,
|
|
|
|
BFD_ENDIAN_BIG, /* data byte order is big */
|
|
|
|
BFD_ENDIAN_LITTLE, /* header byte order is little */
|
|
|
|
|
|
|
|
(HAS_RELOC | EXEC_P | /* object flags */
|
|
|
|
HAS_LINENO | HAS_DEBUG |
|
|
|
|
HAS_SYMS | HAS_LOCALS | WP_TEXT),
|
|
|
|
|
|
|
|
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
|
|
|
|
'_', /* leading symbol underscore */
|
|
|
|
'/', /* ar_pad_char */
|
|
|
|
15, /* ar_max_namelen */
|
* targets.c (bfd_target): Make ar_max_namelen an unsigned char.
Add match_priority.
* configure.in: Bump bfd version.
* elfcode.h (elf_object_p): Delete hacks preventing match of
EM_NONE and ELFOSABI_NONE targets when a better match exists.
* elfxx-target.h (elf_match_priority): Define and use.
* format.c (bfd_check_format_matches): Use target match_priority
to choose best of multiple matching targets. In cases with multiple
matches rerun _bfd_check_format if we don't choose the last match.
* aout-adobe.c, * aout-arm.c, * aout-target.h, * aout-tic30.c,
* binary.c, * bout.c, * coff-alpha.c, * coff-i386.c, * coff-i860.c,
* coff-i960.c, * coff-ia64.c, * coff-mips.c, * coff-or32.c,
* coff-ppc.c, * coff-rs6000.c, * coff-sh.c, * coff-tic30.c,
* coff-tic54x.c, * coff-x86_64.c, * coff64-rs6000.c, * coffcode.h,
* i386msdos.c, * i386os9k.c, * ieee.c, * ihex.c, * mach-o-target.c,
* mipsbsd.c, * mmo.c, * nlm-target.h, * oasys.c, * pdp11.c,
* pe-mips.c, * pef.c, * plugin.c, * ppcboot.c, * som.c, * srec.c,
* tekhex.c, * trad-core.c, * verilog.c, * versados.c, * vms-alpha.c,
* vms-lib.c, * xsym.c: Init match_priority field.
* configure: Regenerate.
* bfd-in2.h: Regenerate.
2011-06-06 03:26:05 +02:00
|
|
|
0, /* match priority. */
|
1999-05-03 09:29:11 +02:00
|
|
|
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
|
|
|
|
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
|
|
|
|
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
|
|
|
|
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
|
|
|
|
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
|
|
|
|
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
|
|
|
|
|
|
|
|
{_bfd_dummy_target, coff_object_p, /* bfd_check_format */
|
|
|
|
bfd_generic_archive_p, _bfd_dummy_target},
|
|
|
|
{bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
|
|
|
|
bfd_false},
|
|
|
|
{bfd_false, coff_write_object_contents, /* bfd_write_contents */
|
|
|
|
_bfd_write_archive_contents, bfd_false},
|
|
|
|
|
|
|
|
BFD_JUMP_TABLE_GENERIC (coff),
|
|
|
|
BFD_JUMP_TABLE_COPY (coff),
|
|
|
|
BFD_JUMP_TABLE_CORE (_bfd_nocore),
|
|
|
|
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
|
|
|
|
BFD_JUMP_TABLE_SYMBOLS (coff),
|
|
|
|
BFD_JUMP_TABLE_RELOCS (coff),
|
|
|
|
BFD_JUMP_TABLE_WRITE (coff),
|
|
|
|
BFD_JUMP_TABLE_LINK (coff),
|
|
|
|
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
|
|
|
|
|
1999-07-19 16:55:16 +02:00
|
|
|
NULL,
|
2000-11-16 01:54:12 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
COFF_SWAP_TABLE
|
|
|
|
};
|