-/* BFD back-end for Hitachi Super-H COFF binaries.
- Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
- Free Software Foundation, Inc.
+/* BFD back-end for Renesas Super-H COFF binaries.
+ Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ 2003, 2004 Free Software Foundation, Inc.
Contributed by Cygnus Support.
Written by Steve Chamberlain, <sac@cygnus.com>.
Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>.
-This file is part of BFD, the Binary File Descriptor library.
+ 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 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.
+ 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. */
+ 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"
bfd_boolean *again;
{
struct internal_reloc *internal_relocs;
- struct internal_reloc *free_relocs = NULL;
bfd_boolean have_code;
struct internal_reloc *irel, *irelend;
bfd_byte *contents = NULL;
- bfd_byte *free_contents = NULL;
*again = FALSE;
- if (link_info->relocateable
+ if (link_info->relocatable
|| (sec->flags & SEC_RELOC) == 0
|| sec->reloc_count == 0)
return TRUE;
- /* If this is the first time we have been called for this section,
- initialize the cooked size. */
- if (sec->_cooked_size == 0)
- sec->_cooked_size = sec->_raw_size;
+ if (coff_section_data (abfd, sec) == NULL)
+ {
+ bfd_size_type amt = sizeof (struct coff_section_tdata);
+ sec->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
+ if (sec->used_by_bfd == NULL)
+ return FALSE;
+ }
internal_relocs = (_bfd_coff_read_internal_relocs
(abfd, sec, link_info->keep_memory,
(struct internal_reloc *) NULL));
if (internal_relocs == NULL)
goto error_return;
- if (! link_info->keep_memory)
- free_relocs = internal_relocs;
have_code = FALSE;
/* Get the section contents. */
if (contents == NULL)
{
- if (coff_section_data (abfd, sec) != NULL
- && coff_section_data (abfd, sec)->contents != NULL)
+ if (coff_section_data (abfd, sec)->contents != NULL)
contents = coff_section_data (abfd, sec)->contents;
else
{
- contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
- if (contents == NULL)
- goto error_return;
- free_contents = contents;
-
- if (! bfd_get_section_contents (abfd, sec, contents,
- (file_ptr) 0, sec->_raw_size))
+ if (!bfd_malloc_and_get_section (abfd, sec, &contents))
goto error_return;
}
}
laddr = irel->r_vaddr - sec->vma + 4;
/* Careful to sign extend the 32-bit offset. */
laddr += ((irel->r_offset & 0xffffffff) ^ 0x80000000) - 0x80000000;
- if (laddr >= sec->_raw_size)
+ if (laddr >= sec->size)
{
- (*_bfd_error_handler) ("%s: 0x%lx: warning: bad R_SH_USES offset",
- bfd_archive_filename (abfd),
- (unsigned long) irel->r_vaddr);
+ (*_bfd_error_handler) ("%B: 0x%lx: warning: bad R_SH_USES offset",
+ abfd, (unsigned long) irel->r_vaddr);
continue;
}
insn = bfd_get_16 (abfd, contents + laddr);
if ((insn & 0xf000) != 0xd000)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x",
- bfd_archive_filename (abfd), (unsigned long) irel->r_vaddr, insn));
+ ("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x",
+ abfd, (unsigned long) irel->r_vaddr, insn));
continue;
}
paddr = insn & 0xff;
paddr *= 4;
paddr += (laddr + 4) &~ (bfd_vma) 3;
- if (paddr >= sec->_raw_size)
+ if (paddr >= sec->size)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: warning: bad R_SH_USES load offset",
- bfd_archive_filename (abfd), (unsigned long) irel->r_vaddr));
+ ("%B: 0x%lx: warning: bad R_SH_USES load offset",
+ abfd, (unsigned long) irel->r_vaddr));
continue;
}
#ifdef COFF_WITH_PE
&& (irelfn->r_type == R_SH_IMM32
|| irelfn->r_type == R_SH_IMM32CE
- || irelfn->r_type == R_SH_IMAGEBASE))
+ || irelfn->r_type == R_SH_IMAGEBASE)
#else
- && irelfn->r_type == R_SH_IMM32)
+ && irelfn->r_type == R_SH_IMM32
#endif
+ )
break;
if (irelfn >= irelend)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: warning: could not find expected reloc",
- bfd_archive_filename (abfd), (unsigned long) paddr));
+ ("%B: 0x%lx: warning: could not find expected reloc",
+ abfd, (unsigned long) paddr));
continue;
}
if (sym.n_scnum != 0 && sym.n_scnum != sec->target_index)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: warning: symbol in unexpected section",
- bfd_archive_filename (abfd), (unsigned long) paddr));
+ ("%B: 0x%lx: warning: symbol in unexpected section",
+ abfd, (unsigned long) paddr));
continue;
}
that would be more work, but would require less memory when
the linker is run. */
- if (coff_section_data (abfd, sec) == NULL)
- {
- bfd_size_type amt = sizeof (struct coff_section_tdata);
- sec->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
- if (sec->used_by_bfd == NULL)
- goto error_return;
- }
-
coff_section_data (abfd, sec)->relocs = internal_relocs;
coff_section_data (abfd, sec)->keep_relocs = TRUE;
- free_relocs = NULL;
coff_section_data (abfd, sec)->contents = contents;
coff_section_data (abfd, sec)->keep_contents = TRUE;
- free_contents = NULL;
obj_coff_keep_syms (abfd) = TRUE;
if (irelcount >= irelend)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: warning: could not find expected COUNT reloc",
- bfd_archive_filename (abfd), (unsigned long) paddr));
+ ("%B: 0x%lx: warning: could not find expected COUNT reloc",
+ abfd, (unsigned long) paddr));
continue;
}
just deleted one. */
if (irelcount->r_offset == 0)
{
- ((*_bfd_error_handler) ("%s: 0x%lx: warning: bad count",
- bfd_archive_filename (abfd),
- (unsigned long) paddr));
+ ((*_bfd_error_handler) ("%B: 0x%lx: warning: bad count",
+ abfd, (unsigned long) paddr));
continue;
}
/* Get the section contents. */
if (contents == NULL)
{
- if (coff_section_data (abfd, sec) != NULL
- && coff_section_data (abfd, sec)->contents != NULL)
+ if (coff_section_data (abfd, sec)->contents != NULL)
contents = coff_section_data (abfd, sec)->contents;
else
{
- contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
- if (contents == NULL)
- goto error_return;
- free_contents = contents;
-
- if (! bfd_get_section_contents (abfd, sec, contents,
- (file_ptr) 0, sec->_raw_size))
+ if (!bfd_malloc_and_get_section (abfd, sec, &contents))
goto error_return;
}
}
if (swapped)
{
- if (coff_section_data (abfd, sec) == NULL)
- {
- bfd_size_type amt = sizeof (struct coff_section_tdata);
- sec->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
- if (sec->used_by_bfd == NULL)
- goto error_return;
- }
-
coff_section_data (abfd, sec)->relocs = internal_relocs;
coff_section_data (abfd, sec)->keep_relocs = TRUE;
- free_relocs = NULL;
coff_section_data (abfd, sec)->contents = contents;
coff_section_data (abfd, sec)->keep_contents = TRUE;
- free_contents = NULL;
obj_coff_keep_syms (abfd) = TRUE;
}
}
- if (free_relocs != NULL)
+ if (internal_relocs != NULL
+ && internal_relocs != coff_section_data (abfd, sec)->relocs)
{
- free (free_relocs);
- free_relocs = NULL;
+ if (! link_info->keep_memory)
+ free (internal_relocs);
+ else
+ coff_section_data (abfd, sec)->relocs = internal_relocs;
}
- if (free_contents != NULL)
+ if (contents != NULL && contents != coff_section_data (abfd, sec)->contents)
{
if (! link_info->keep_memory)
- free (free_contents);
+ free (contents);
else
- {
- /* Cache the section contents for coff_link_input_bfd. */
- if (coff_section_data (abfd, sec) == NULL)
- {
- bfd_size_type amt = sizeof (struct coff_section_tdata);
- sec->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
- if (sec->used_by_bfd == NULL)
- goto error_return;
- coff_section_data (abfd, sec)->relocs = NULL;
- }
- coff_section_data (abfd, sec)->contents = contents;
- }
+ /* Cache the section contents for coff_link_input_bfd. */
+ coff_section_data (abfd, sec)->contents = contents;
}
return TRUE;
error_return:
- if (free_relocs != NULL)
- free (free_relocs);
- if (free_contents != NULL)
- free (free_contents);
+ if (internal_relocs != NULL
+ && internal_relocs != coff_section_data (abfd, sec)->relocs)
+ free (internal_relocs);
+ if (contents != NULL && contents != coff_section_data (abfd, sec)->contents)
+ free (contents);
return FALSE;
}
power larger than the number of bytes we are deleting. */
irelalign = NULL;
- toaddr = sec->_cooked_size;
+ toaddr = sec->size;
irel = coff_section_data (abfd, sec)->relocs;
irelend = irel + sec->reloc_count;
memmove (contents + addr, contents + addr + count,
(size_t) (toaddr - addr - count));
if (irelalign == NULL)
- sec->_cooked_size -= count;
+ sec->size -= count;
else
{
int i;
if (overflow)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: fatal: reloc overflow while relaxing",
- bfd_archive_filename (abfd), (unsigned long) irel->r_vaddr));
+ ("%B: 0x%lx: fatal: reloc overflow while relaxing",
+ abfd, (unsigned long) irel->r_vaddr));
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
ocontents = coff_section_data (abfd, o)->contents;
else
{
+ if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
+ return FALSE;
/* We always cache the section contents.
Perhaps, if info->keep_memory is FALSE, we
should free them, if we are permitted to,
when we leave sh_coff_relax_section. */
- ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
- if (ocontents == NULL)
- return FALSE;
- if (! bfd_get_section_contents (abfd, o, ocontents,
- (file_ptr) 0,
- o->_raw_size))
- return FALSE;
coff_section_data (abfd, o)->contents = ocontents;
}
}
|| obj_raw_syments (abfd) != NULL)
{
((*_bfd_error_handler)
- ("%s: fatal: generic symbols retrieved before relaxing",
- bfd_archive_filename (abfd)));
+ ("%B: fatal: generic symbols retrieved before relaxing", abfd));
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
}
#define SETSAS (0x40000)
#define SETSAS_REG(x) USESAS_REG (x)
+#define MAP(a) a, sizeof a / sizeof a[0]
+
#ifndef COFF_IMAGE_WITH_PE
static bfd_boolean sh_insn_uses_reg
PARAMS ((unsigned int, const struct sh_opcode *, unsigned int));
static bfd_boolean sh_load_use
PARAMS ((unsigned int, const struct sh_opcode *, unsigned int,
const struct sh_opcode *));
-#endif
-/* The opcode maps. */
-#define MAP(a) a, sizeof a / sizeof a[0]
+/* The opcode maps. */
static const struct sh_opcode sh_opcode00[] =
{
{ MAP (sh_opcodef1), 0xf0ff }
};
-#ifndef COFF_IMAGE_WITH_PE
static struct sh_major_opcode sh_opcodes[] =
{
{ MAP (sh_opcode0) },
{ MAP (sh_opcodee) },
{ MAP (sh_opcodef) }
};
-#endif
/* The double data transfer / parallel processing insns are not
described here. This will cause sh_align_load_span to leave them alone. */
{ MAP (sh_dsp_opcodef0), 0xfc0d }
};
-#ifndef COFF_IMAGE_WITH_PE
/* Given an instruction, return a pointer to the corresponding
sh_opcode structure. Return NULL if the instruction is not
recognized. */
if (irel < irelend)
stop = irel->r_vaddr - sec->vma;
else
- stop = sec->_cooked_size;
+ stop = sec->size;
if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_swap_insns,
(PTR) internal_relocs, &label,
if (overflow)
{
((*_bfd_error_handler)
- ("%s: 0x%lx: fatal: reloc overflow while relaxing",
- bfd_archive_filename (abfd), (unsigned long) irel->r_vaddr));
+ ("%B: 0x%lx: fatal: reloc overflow while relaxing",
+ abfd, (unsigned long) irel->r_vaddr));
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
|| (unsigned long) symndx >= obj_raw_syment_count (input_bfd))
{
(*_bfd_error_handler)
- ("%s: illegal symbol index %ld in relocs",
- bfd_archive_filename (input_bfd), symndx);
+ ("%B: illegal symbol index %ld in relocs",
+ input_bfd, symndx);
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
+ sec->output_section->vma
+ sec->output_offset);
}
- else if (! info->relocateable)
+ else if (! info->relocatable)
{
if (! ((*info->callbacks->undefined_symbol)
(info, h->root.root.string, input_bfd, input_section,
if (symndx == -1)
name = "*ABS*";
else if (h != NULL)
- name = h->root.root.string;
+ name = NULL;
else if (sym->_n._n_n._n_zeroes == 0
&& sym->_n._n_n._n_offset != 0)
name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset;
}
if (! ((*info->callbacks->reloc_overflow)
- (info, name, howto->name, (bfd_vma) 0, input_bfd,
- input_section, rel->r_vaddr - input_section->vma)))
+ (info, (h ? &h->root : NULL), name, howto->name,
+ (bfd_vma) 0, input_bfd, input_section,
+ rel->r_vaddr - input_section->vma)))
return FALSE;
}
}
static bfd_byte *
sh_coff_get_relocated_section_contents (output_bfd, link_info, link_order,
- data, relocateable, symbols)
+ data, relocatable, symbols)
bfd *output_bfd;
struct bfd_link_info *link_info;
struct bfd_link_order *link_order;
bfd_byte *data;
- bfd_boolean relocateable;
+ bfd_boolean relocatable;
asymbol **symbols;
{
asection *input_section = link_order->u.indirect.section;
/* We only need to handle the case of relaxing, or of having a
particular set of section contents, specially. */
- if (relocateable
+ if (relocatable
|| coff_section_data (input_bfd, input_section) == NULL
|| coff_section_data (input_bfd, input_section)->contents == NULL)
return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
link_order, data,
- relocateable,
+ relocatable,
symbols);
memcpy (data, coff_section_data (input_bfd, input_section)->contents,
- (size_t) input_section->_raw_size);
+ (size_t) input_section->size);
if ((input_section->flags & SEC_RELOC) != 0
&& input_section->reloc_count > 0)
/* The target vectors. */
#ifndef TARGET_SHL_SYM
-CREATE_BIG_COFF_TARGET_VEC (shcoff_vec, "coff-sh", BFD_IS_RELAXABLE, 0, '_', NULL)
+CREATE_BIG_COFF_TARGET_VEC (shcoff_vec, "coff-sh", BFD_IS_RELAXABLE, 0, '_', NULL, COFF_SWAP_TABLE)
#endif
#ifdef TARGET_SHL_SYM
#ifdef COFF_WITH_PE
CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
- SEC_CODE | SEC_DATA, '_', NULL);
+ SEC_CODE | SEC_DATA, '_', NULL, COFF_SWAP_TABLE);
#else
CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
- 0, '_', NULL)
+ 0, '_', NULL, COFF_SWAP_TABLE)
#endif
#ifndef TARGET_SHL_SYM