/* Matsushita 10200 specific support for 32-bit ELF
- Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
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. */
+Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#include "bfd.h"
#include "sysdep.h"
PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
static void mn10200_info_to_howto
PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
-static boolean mn10200_elf_relax_delete_bytes
+static bfd_boolean mn10200_elf_relax_delete_bytes
PARAMS ((bfd *, asection *, bfd_vma, int));
-static boolean mn10200_elf_symbol_address_p
+static bfd_boolean mn10200_elf_symbol_address_p
PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
static bfd_reloc_status_type mn10200_elf_final_link_relocate
PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *,
bfd_byte *, bfd_vma, bfd_vma, bfd_vma,
struct bfd_link_info *, asection *, int));
-static boolean mn10200_elf_relocate_section
-PARAMS (( bfd *, struct bfd_link_info *, bfd *, asection *,
- bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *,
- asection **));
-static boolean mn10200_elf_relax_section
- PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
+static bfd_boolean mn10200_elf_relocate_section
+ PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
+ bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *,
+ asection **));
+static bfd_boolean mn10200_elf_relax_section
+ PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
static bfd_byte * mn10200_elf_get_relocated_section_contents
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
- bfd_byte *, boolean, asymbol **));
+ bfd_byte *, bfd_boolean, asymbol **));
enum reloc_type {
R_MN10200_NONE = 0,
0,
2,
16,
- false,
+ FALSE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_NONE",
- false,
+ FALSE,
0,
0,
- false),
+ FALSE),
/* Standard 32 bit reloc. */
HOWTO (R_MN10200_32,
0,
2,
32,
- false,
+ FALSE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_32",
- false,
+ FALSE,
0xffffffff,
0xffffffff,
- false),
+ FALSE),
/* Standard 16 bit reloc. */
HOWTO (R_MN10200_16,
0,
1,
16,
- false,
+ FALSE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_16",
- false,
+ FALSE,
0xffff,
0xffff,
- false),
+ FALSE),
/* Standard 8 bit reloc. */
HOWTO (R_MN10200_8,
0,
0,
8,
- false,
+ FALSE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_8",
- false,
+ FALSE,
0xff,
0xff,
- false),
+ FALSE),
/* Standard 24 bit reloc. */
HOWTO (R_MN10200_24,
0,
2,
24,
- false,
+ FALSE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_24",
- false,
+ FALSE,
0xffffff,
0xffffff,
- false),
+ FALSE),
/* Simple 8 pc-relative reloc. */
HOWTO (R_MN10200_PCREL8,
0,
0,
8,
- true,
+ TRUE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_PCREL8",
- false,
+ FALSE,
0xff,
0xff,
- true),
+ TRUE),
/* Simple 16 pc-relative reloc. */
HOWTO (R_MN10200_PCREL16,
0,
1,
16,
- true,
+ TRUE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_PCREL16",
- false,
+ FALSE,
0xffff,
0xffff,
- true),
+ TRUE),
/* Simple 32bit pc-relative reloc with a 1 byte adjustment
to get the pc-relative offset correct. */
HOWTO (R_MN10200_PCREL24,
0,
2,
24,
- true,
+ TRUE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_MN10200_PCREL24",
- false,
+ FALSE,
0xffffff,
0xffffff,
- true),
+ TRUE),
};
struct mn10200_reloc_map {
}
\f
/* Relocate an MN10200 ELF section. */
-static boolean
+static bfd_boolean
mn10200_elf_relocate_section (output_bfd, info, input_bfd, input_section,
contents, relocs, local_syms, local_sections)
bfd *output_bfd;
struct elf_link_hash_entry **sym_hashes;
Elf_Internal_Rela *rel, *relend;
- if (info->relocateable)
- return true;
+ if (info->relocatable)
+ return TRUE;
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (input_bfd);
{
sym = local_syms + r_symndx;
sec = local_sections[r_symndx];
- relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+ relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
}
else
{
- h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- while (h->root.type == bfd_link_hash_indirect
- || h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
- if (h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak)
- {
- sec = h->root.u.def.section;
- relocation = (h->root.u.def.value
- + sec->output_section->vma
- + sec->output_offset);
- }
- else if (h->root.type == bfd_link_hash_undefweak)
- relocation = 0;
- else
- {
- if (! ((*info->callbacks->undefined_symbol)
- (info, h->root.root.string, input_bfd,
- input_section, rel->r_offset, true)))
- return false;
- relocation = 0;
- }
+ bfd_boolean unresolved_reloc, warned;
+
+ RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
+ r_symndx, symtab_hdr, sym_hashes,
+ h, sec, relocation,
+ unresolved_reloc, warned);
}
r = mn10200_elf_final_link_relocate (howto, input_bfd, output_bfd,
{
case bfd_reloc_overflow:
if (! ((*info->callbacks->reloc_overflow)
- (info, name, howto->name, (bfd_vma) 0,
- input_bfd, input_section, rel->r_offset)))
- return false;
+ (info, (h ? &h->root : NULL), name, howto->name,
+ (bfd_vma) 0, input_bfd, input_section,
+ rel->r_offset)))
+ return FALSE;
break;
case bfd_reloc_undefined:
if (! ((*info->callbacks->undefined_symbol)
(info, name, input_bfd, input_section,
- rel->r_offset, true)))
- return false;
+ rel->r_offset, TRUE)))
+ return FALSE;
break;
case bfd_reloc_outofrange:
if (!((*info->callbacks->warning)
(info, msg, name, input_bfd, input_section,
rel->r_offset)))
- return false;
+ return FALSE;
break;
}
}
}
- return true;
+ return TRUE;
}
/* This function handles relaxing for the mn10200.
- There's quite a few relaxing opportunites available on the mn10200:
+ There are quite a few relaxing opportunities available on the mn10200:
* jsr:24 -> jsr:16 2 bytes
We don't handle imm16->imm8 or d16->d8 as they're very rare
and somewhat more difficult to support. */
-static boolean
+static bfd_boolean
mn10200_elf_relax_section (abfd, sec, link_info, again)
bfd *abfd;
asection *sec;
struct bfd_link_info *link_info;
- boolean *again;
+ bfd_boolean *again;
{
Elf_Internal_Shdr *symtab_hdr;
Elf_Internal_Rela *internal_relocs;
Elf_Internal_Sym *isymbuf = NULL;
/* Assume nothing changes. */
- *again = false;
+ *again = FALSE;
- /* We don't have to do anything for a relocateable link, if
+ /* We don't have to do anything for a relocatable link, if
this section does not have relocs, or if this is not a
code section. */
- if (link_info->relocateable
+ if (link_info->relocatable
|| (sec->flags & SEC_RELOC) == 0
|| sec->reloc_count == 0
|| (sec->flags & SEC_CODE) == 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;
+ return TRUE;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
/* Get a copy of the native relocations. */
- internal_relocs = (_bfd_elf32_link_read_relocs
+ internal_relocs = (_bfd_elf_link_read_relocs
(abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
link_info->keep_memory));
if (internal_relocs == NULL)
else
{
/* Go get them off disk. */
- contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
- if (contents == NULL)
- goto error_return;
-
- 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;
}
}
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
}
}
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
}
}
value += irel->r_addend;
/* Do nothing if this reloc is the last byte in the section. */
- if (irel->r_offset == sec->_cooked_size)
+ if (irel->r_offset == sec->size)
continue;
/* See if the next instruction is an unconditional pc-relative
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
}
/* Try to turn a 24bit immediate, displacement or absolute address
if (value & 0x8000)
continue;
- /* Note that we've changed the reldection contents, etc. */
+ /* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
elf_section_data (sec)->this_hdr.contents = contents;
symtab_hdr->contents = (unsigned char *) isymbuf;
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
break;
/* mov imm24,an -> mov imm16,an
case 0x40:
case 0x44:
case 0xc8:
- /* Note that we've changed the reldection contents, etc. */
+ /* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
elf_section_data (sec)->this_hdr.contents = contents;
symtab_hdr->contents = (unsigned char *) isymbuf;
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
break;
/* cmp imm24,dn -> cmp imm16,dn
&& (value & 0x8000) != 0)
continue;
- /* Note that we've changed the reldection contents, etc. */
+ /* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
elf_section_data (sec)->this_hdr.contents = contents;
symtab_hdr->contents = (unsigned char *) isymbuf;
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
break;
/* movb (abs24),dn ->movbu (abs16),dn extxb bn */
/* That will change things, so, we should relax again.
Note that this is not required, and it may be slow. */
- *again = true;
+ *again = TRUE;
break;
}
}
&& elf_section_data (sec)->relocs != internal_relocs)
free (internal_relocs);
- return true;
+ return TRUE;
error_return:
if (isymbuf != NULL
&& elf_section_data (sec)->relocs != internal_relocs)
free (internal_relocs);
- return false;
+ return FALSE;
}
/* Delete some bytes from a section while relaxing. */
-static boolean
+static bfd_boolean
mn10200_elf_relax_delete_bytes (abfd, sec, addr, count)
bfd *abfd;
asection *sec;
power larger than the number of bytes we are deleting. */
irelalign = NULL;
- toaddr = sec->_cooked_size;
+ toaddr = sec->size;
irel = elf_section_data (sec)->relocs;
irelend = irel + sec->reloc_count;
/* Actually delete the bytes. */
memmove (contents + addr, contents + addr + count,
(size_t) (toaddr - addr - count));
- sec->_cooked_size -= count;
+ sec->size -= count;
/* Adjust all the relocs. */
for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
}
}
- return true;
+ return TRUE;
}
-/* Return true if a symbol exists at the given address, else return
- false. */
-static boolean
+/* Return TRUE if a symbol exists at the given address, else return
+ FALSE. */
+static bfd_boolean
mn10200_elf_symbol_address_p (abfd, sec, isym, addr)
bfd *abfd;
asection *sec;
{
if (isym->st_shndx == sec_shndx
&& isym->st_value == addr)
- return true;
+ return TRUE;
}
symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
|| sym_hash->root.type == bfd_link_hash_defweak)
&& sym_hash->root.u.def.section == sec
&& sym_hash->root.u.def.value == addr)
- return true;
+ return TRUE;
}
- return false;
+ return FALSE;
}
/* This is a version of bfd_generic_get_relocated_section_contents
static bfd_byte *
mn10200_elf_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;
- boolean relocateable;
+ bfd_boolean relocatable;
asymbol **symbols;
{
Elf_Internal_Shdr *symtab_hdr;
/* We only need to handle the case of relaxing, or of having a
particular set of section contents, specially. */
- if (relocateable
+ if (relocatable
|| elf_section_data (input_section)->this_hdr.contents == NULL)
return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
link_order, data,
- relocateable,
+ relocatable,
symbols);
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
memcpy (data, elf_section_data (input_section)->this_hdr.contents,
- (size_t) input_section->_raw_size);
+ (size_t) input_section->size);
if ((input_section->flags & SEC_RELOC) != 0
&& input_section->reloc_count > 0)
asection **secpp;
bfd_size_type amt;
- internal_relocs = (_bfd_elf32_link_read_relocs
+ internal_relocs = (_bfd_elf_link_read_relocs
(input_bfd, input_section, (PTR) NULL,
- (Elf_Internal_Rela *) NULL, false));
+ (Elf_Internal_Rela *) NULL, FALSE));
if (internal_relocs == NULL)
goto error_return;