summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrans Meulenbroeks <fransmeulenbroeks@gmail.com>2010-07-06 21:17:14 +0200
committerFrans Meulenbroeks <fransmeulenbroeks@gmail.com>2010-07-06 21:21:00 +0200
commitefaed573357cafd2cd54c700ae2eab18014882e7 (patch)
tree597e009583c6f8e1f094b022992ad376f39f4d4f
parent9101746564c9d3b9a9c6fec8020bd6d304634543 (diff)
binutils 2.17.50.0.12: added nios2 support
added nios2 support this is based upon the windriver toolchain (see http://www.nioswiki.com/Build_the_gcc4_toolchain for details). The nios2 changes are lifted from the wrs toolchain and ported to 2.17.50.0.12. Also solved a few bugs As there is no functional change for other platforms no PR bump is needed (the patches are only applied for nios2 machines) Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
-rw-r--r--recipes/binutils/binutils-2.17.50.0.12/binutils-nios2-files.patch41015
-rw-r--r--recipes/binutils/binutils-2.17.50.0.12/binutils-nios2.patch576
-rw-r--r--recipes/binutils/binutils_2.17.50.0.12.bb5
3 files changed, 41596 insertions, 0 deletions
diff --git a/recipes/binutils/binutils-2.17.50.0.12/binutils-nios2-files.patch b/recipes/binutils/binutils-2.17.50.0.12/binutils-nios2-files.patch
new file mode 100644
index 0000000000..fc77ca2fea
--- /dev/null
+++ b/recipes/binutils/binutils-2.17.50.0.12/binutils-nios2-files.patch
@@ -0,0 +1,41015 @@
+Index: binutils-2.17.50.0.12/bfd/cpu-nios2.c
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ binutils-2.17.50.0.12/bfd/cpu-nios2.c 2010-06-30 15:06:08.000000000 +0200
+@@ -0,0 +1,71 @@
++/* NOT ASSIGNED TO FSF. COPYRIGHT ALTERA. */
++/* bfd back-end for Altera Nios II support
++
++ Copyright (C) 2003
++ by Nigel Gray (ngray@altera.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
++
++#include "bfd.h"
++#include "sysdep.h"
++#include "libbfd.h"
++
++static const bfd_arch_info_type *nios2_compatible
++ (const bfd_arch_info_type *, const bfd_arch_info_type *);
++
++/* The default routine tests bits_per_word, which is wrong on mips as
++ mips word size doesn't correlate with reloc size. */
++
++static const bfd_arch_info_type *
++nios2_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
++{
++ if (a->arch != b->arch)
++ return NULL;
++
++ /* Machine compatibility is checked in
++ _bfd_mips_elf_merge_private_bfd_data. */
++
++ return a;
++}
++
++#define N(BITS_WORD, BITS_ADDR, NUMBER, PRINT, DEFAULT, NEXT) \
++ { \
++ BITS_WORD, /* bits in a word */ \
++ BITS_ADDR, /* bits in an address */ \
++ 8, /* 8 bits in a byte */ \
++ bfd_arch_nios2, \
++ NUMBER, \
++ "nios2", \
++ PRINT, \
++ 3, \
++ DEFAULT, \
++ nios2_compatible, \
++ bfd_default_scan, \
++ NEXT, \
++ }
++
++#define NN(index) (&arch_info_struct[(index) + 1])
++
++static const bfd_arch_info_type arch_info_struct[] =
++{
++ N (32, 32, bfd_mach_nios2, "nios2", FALSE, 0),
++};
++
++/* There is only one architecture - but we give the default a machine number of 0
++ so the linker can distinguish it */
++const bfd_arch_info_type bfd_nios2_arch =
++N (32, 32, 0, "nios2", TRUE, &arch_info_struct[0]);
+Index: binutils-2.17.50.0.12/bfd/elf32-nios2.c
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ binutils-2.17.50.0.12/bfd/elf32-nios2.c 2010-06-30 15:06:08.000000000 +0200
+@@ -0,0 +1,4992 @@
++/* NOT ASSIGNED TO FSF. COPYRIGHT ALTERA. */
++/* New Jersey-specific support for 32-bit ELF
++
++ Copyright (C) 2005
++ by Nigel Gray (ngray@altera.com).
++
++ Copyright (C) 2008, CodeSourcery Inc.
++
++
++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. */
++
++/* This file handles Altera New Jersey ELF targets */
++
++#include "bfd.h"
++#include "sysdep.h"
++#include "libbfd.h"
++#include "bfdlink.h"
++#include "genlink.h"
++#include "elf-bfd.h"
++#include "elf/nios2.h"
++#include "opcode/nios2.h"
++
++/* Use RELA relocations. */
++#ifndef USE_RELA
++#define USE_RELA
++#endif
++
++#ifdef USE_REL
++#undef USE_REL
++#endif
++
++/* Function prototypes. */
++
++static reloc_howto_type *nios2_elf32_bfd_reloc_type_lookup
++ (bfd *, bfd_reloc_code_real_type);
++
++static bfd_boolean nios2_elf32_relax_section
++ (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
++#if 0
++static bfd_boolean nios2_elf32_relax_delete_bytes
++ (bfd *, asection *, bfd_vma, int);
++#endif
++static reloc_howto_type *nios2_elf32_rtype_to_howto
++ (unsigned int r_type, bfd_boolean rela_p);
++
++static void nios2_elf32_info_to_howto
++ (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst);
++
++static bfd_boolean nios2_elf32_relocate_section
++ (bfd * output_bfd, struct bfd_link_info * info, bfd * input_bfd,
++ asection * input_section, bfd_byte * contents,
++ Elf_Internal_Rela * relocs, Elf_Internal_Sym * local_syms,
++ asection ** local_sections);
++
++static reloc_howto_type *lookup_howto (unsigned int rtype);
++
++static bfd_reloc_status_type nios2_elf_final_gp
++ (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *,
++ struct bfd_link_info *);
++
++static bfd_boolean nios2_elf_assign_gp
++ (bfd *, bfd_vma *, struct bfd_link_info *);
++
++static bfd_reloc_status_type nios2_elf32_ignore_reloc
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_hi16_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_lo16_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_hiadj16_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_pcrel_lo16_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_pcrel_hiadj16_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_pcrel16_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_call26_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_gprel_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_ujmp_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_cjmp_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_callr_relocate
++ (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
++
++static bfd_reloc_status_type nios2_elf32_do_hi16_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_lo16_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_hiadj16_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_pcrel_lo16_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_pcrel_hiadj16_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_pcrel16_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_call26_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_gprel_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_ujmp_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_cjmp_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_reloc_status_type nios2_elf32_do_callr_relocate
++ (bfd *, reloc_howto_type *, asection *,
++ bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
++
++static bfd_boolean nios2_elf32_section_from_shdr
++ (bfd *, Elf_Internal_Shdr *, const char *name, int shindex);
++
++static bfd_boolean nios2_elf32_section_flags
++ (flagword *, const Elf_Internal_Shdr *);
++
++static bfd_boolean nios2_elf32_fake_sections
++ (bfd *, Elf_Internal_Shdr *, asection *);
++
++
++
++static bfd_boolean nios2_elf32_check_relocs
++ (bfd *, struct bfd_link_info *, asection *,
++ const Elf_Internal_Rela *);
++
++static asection *nios2_elf32_gc_mark_hook (asection * sec,
++ struct bfd_link_info *
++ info,
++ Elf_Internal_Rela * rel,
++ struct elf_link_hash_entry
++ * h,
++ Elf_Internal_Sym * sym);
++
++void
++_bfd_set_link_info (struct bfd_link_info *info);
++
++void
++_bfd_set_force_make_executable (bfd_boolean force);
++
++
++/* Target vector. */
++extern const bfd_target bfd_elf32_littlenios2_vec;
++extern const bfd_target bfd_elf32_bignios2_vec;
++
++/* Offset of tp and dtp pointers from start of TLS block. */
++#define TP_OFFSET 0x7000
++#define DTP_OFFSET 0x8000
++
++/* The relocation table used for SHT_REL sections. */
++
++static reloc_howto_type elf_nios2_howto_table_rel[] = {
++ /* No relocation. */
++ HOWTO (R_NIOS2_NONE, /* type */
++ 0, /* rightshift */
++ 0, /* size (0 = byte, 1 = short, 2 = long) */
++ 0, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_dont, /* complain_on_overflow */
++ bfd_elf_generic_reloc, /* special_function */
++ "R_NIOS2_NONE", /* name */
++ FALSE, /* partial_inplace */
++ 0, /* src_mask */
++ 0, /* dst_mask */
++ FALSE), /* pcrel_offset */
++
++ /* 16-bit signed immediate relocation */
++ HOWTO (R_NIOS2_S16, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ FALSE, /* pc_relative */
++ 6, /* bitpos */
++ complain_overflow_signed, /* complain on overflow */
++ bfd_elf_generic_reloc, /* special function */
++ "R_NIOS2_S16", /* name */
++ FALSE, /* partial_inplace */
++ 0x003fffc0, /* src_mask */
++ 0x003fffc0, /* dest_mask */
++ FALSE), /* pcrel_offset */
++
++ /* 16-bit unsigned immediate relocation */
++ HOWTO (R_NIOS2_U16, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ FALSE, /* pc_relative */
++ 6, /* bitpos */
++ complain_overflow_unsigned, /* complain on overflow */
++ bfd_elf_generic_reloc, /* special function */
++ "R_NIOS2_U16", /* name */
++ FALSE, /* partial_inplace */
++ 0x003fffc0, /* src_mask */
++ 0x003fffc0, /* dest_mask */
++ FALSE), /* pcrel_offset */
++
++ HOWTO (R_NIOS2_PCREL16, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ TRUE, /* pc_relative */
++ 6, /* bitpos */
++ complain_overflow_signed, /* complain on overflow */
++ nios2_elf32_pcrel16_relocate, /* special function */
++ "R_NIOS2_PCREL16", /* name */
++ FALSE, /* partial_inplace */
++ 0x003fffc0, /* src_mask */
++ 0x003fffc0, /* dest_mask */
++ TRUE), /* pcrel_offset */
++
++ HOWTO (R_NIOS2_CALL26, /* type */
++ 2, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 26, /* bitsize */
++ FALSE, /* pc_relative */
++ 6, /* bitpos */
++ complain_overflow_dont, /* complain on overflow */
++ nios2_elf32_call26_relocate, /* special function */
++ "R_NIOS2_CALL26", /* name */
++ FALSE, /* partial_inplace */
++ 0xffffffc0, /* src_mask */
++ 0xffffffc0, /* dst_mask */
++ FALSE), /* pcrel_offset */
++
++ HOWTO (R_NIOS2_IMM5,
++ 0,
++ 2,
++ 5,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_IMM5",
++ FALSE,
++ 0x000007c0,
++ 0x000007c0,
++ FALSE),
++
++ HOWTO (R_NIOS2_CACHE_OPX,
++ 0,
++ 2,
++ 5,
++ FALSE,
++ 22,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_CACHE_OPX",
++ FALSE,
++ 0x07c00000,
++ 0x07c00000,
++ FALSE),
++
++ HOWTO (R_NIOS2_IMM6,
++ 0,
++ 2,
++ 6,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_IMM6",
++ FALSE,
++ 0x00000fc0,
++ 0x00000fc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_IMM8,
++ 0,
++ 2,
++ 8,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_IMM8",
++ FALSE,
++ 0x00003fc0,
++ 0x00003fc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_HI16,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_hi16_relocate,
++ "R_NIOS2_HI16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_LO16,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_lo16_relocate,
++ "R_NIOS2_LO16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_HIADJ16,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_hiadj16_relocate,
++ "R_NIOS2_HIADJ16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_BFD_RELOC_32,
++ 0,
++ 2, /* long */
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_BFD_RELOC32",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_BFD_RELOC_16,
++ 0,
++ 1, /* short */
++ 16,
++ FALSE,
++ 0,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_BFD_RELOC16",
++ FALSE,
++ 0x0000ffff,
++ 0x0000ffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_BFD_RELOC_8,
++ 0,
++ 0, /* byte */
++ 8,
++ FALSE,
++ 0,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_BFD_RELOC8",
++ FALSE,
++ 0x000000ff,
++ 0x000000ff,
++ FALSE),
++
++ HOWTO (R_NIOS2_GPREL,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_gprel_relocate,
++ "R_NIOS2_GPREL",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_GNU_VTINHERIT,
++ 0,
++ 2, /* short */
++ 0,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ NULL,
++ "R_NIOS2_GNU_VTINHERIT",
++ FALSE,
++ 0,
++ 0,
++ FALSE),
++
++ HOWTO (R_NIOS2_GNU_VTENTRY,
++ 0,
++ 2, /* byte */
++ 0,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ _bfd_elf_rel_vtable_reloc_fn,
++ "R_NIOS2_GNU_VTENTRY",
++ FALSE,
++ 0,
++ 0,
++ FALSE),
++
++ HOWTO (R_NIOS2_UJMP,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_ujmp_relocate,
++ "R_NIOS2_UJMP",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_CJMP,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_cjmp_relocate,
++ "R_NIOS2_CJMP",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_CALLR,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_callr_relocate,
++ "R_NIOS2_CALLR",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_ALIGN,
++ 0,
++ 2,
++ 0,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ nios2_elf32_ignore_reloc,
++ "R_NIOS2_ALIGN",
++ FALSE,
++ 0,
++ 0,
++ TRUE),
++
++
++ HOWTO (R_NIOS2_GOT16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_GOT16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_CALL16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_CALL16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_GOTOFF_LO,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_GOTOFF_LO",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_GOTOFF_HA,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_GOTOFF_HA",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_PCREL_LO,
++ 0,
++ 2,
++ 16,
++ TRUE,
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_pcrel_lo16_relocate,
++ "R_NIOS2_PCREL_LO",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ TRUE),
++
++ HOWTO (R_NIOS2_PCREL_HA,
++ 0,
++ 2,
++ 16,
++ FALSE, /* This is a PC-relative relocation, but we need to subtract
++ PC ourselves before the HIADJ. */
++ 6,
++ complain_overflow_dont,
++ nios2_elf32_pcrel_hiadj16_relocate,
++ "R_NIOS2_PCREL_HA",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ TRUE),
++
++ HOWTO (R_NIOS2_TLS_GD16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_GD16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_LDM16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_LDM16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_LDO16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_LDO16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_IE16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_IE16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_LE16,
++ 0,
++ 2,
++ 16,
++ FALSE,
++ 6,
++ complain_overflow_bitfield,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_LE16",
++ FALSE,
++ 0x003fffc0,
++ 0x003fffc0,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_DTPMOD,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_DTPMOD",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_DTPREL,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_DTPREL",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_TLS_TPREL,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_TLS_TPREL",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_COPY,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_COPY",
++ FALSE,
++ 0,
++ 0,
++ FALSE),
++
++ HOWTO (R_NIOS2_GLOB_DAT,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_GLOB_DAT",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_JUMP_SLOT,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_JUMP_SLOT",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_RELATIVE,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_RELATIVE",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++ HOWTO (R_NIOS2_GOTOFF,
++ 0,
++ 2,
++ 32,
++ FALSE,
++ 0,
++ complain_overflow_dont,
++ bfd_elf_generic_reloc,
++ "R_NIOS2_GOTOFF",
++ FALSE,
++ 0xffffffff,
++ 0xffffffff,
++ FALSE),
++
++/* Add other relocations here. */
++};
++
++static unsigned char elf_code_to_howto_index[R_NIOS2_ILLEGAL + 1];
++
++static reloc_howto_type *
++lookup_howto (unsigned int rtype)
++{
++ static int initialized = 0;
++ int i;
++ int howto_tbl_size = (int) (sizeof (elf_nios2_howto_table_rel)
++ / sizeof (elf_nios2_howto_table_rel[0]));
++
++ if (!initialized)
++ {
++ initialized = 1;
++ memset (elf_code_to_howto_index, 0xff,
++ sizeof (elf_code_to_howto_index));
++ for (i = 0; i < howto_tbl_size; i++)
++ elf_code_to_howto_index[elf_nios2_howto_table_rel[i].type] = i;
++ }
++
++ BFD_ASSERT (rtype <= R_NIOS2_ILLEGAL);
++ i = elf_code_to_howto_index[rtype];
++ if (i >= howto_tbl_size)
++ return 0;
++ return elf_nios2_howto_table_rel + i;
++}
++
++/* Map for converting BFD reloc types to New Jersey reloc types. */
++struct elf_reloc_map
++{
++ bfd_reloc_code_real_type bfd_val;
++ enum elf_nios2_reloc_type elf_val;
++};
++
++static const struct elf_reloc_map nios2_reloc_map[] = {
++ {BFD_RELOC_NIOS2_S16, R_NIOS2_S16},
++ {BFD_RELOC_NIOS2_U16, R_NIOS2_U16},
++ {BFD_RELOC_16_PCREL, R_NIOS2_PCREL16},
++ {BFD_RELOC_NIOS2_CALL26, R_NIOS2_CALL26},
++ {BFD_RELOC_NIOS2_IMM5, R_NIOS2_IMM5},
++ {BFD_RELOC_NIOS2_CACHE_OPX, R_NIOS2_CACHE_OPX},
++ {BFD_RELOC_NIOS2_IMM6, R_NIOS2_IMM6},
++ {BFD_RELOC_NIOS2_IMM8, R_NIOS2_IMM8},
++ {BFD_RELOC_NIOS2_HI16, R_NIOS2_HI16},
++ {BFD_RELOC_NIOS2_LO16, R_NIOS2_LO16},
++ {BFD_RELOC_NIOS2_HIADJ16, R_NIOS2_HIADJ16},
++ {BFD_RELOC_32, R_NIOS2_BFD_RELOC_32},
++ {BFD_RELOC_16, R_NIOS2_BFD_RELOC_16},
++ {BFD_RELOC_8, R_NIOS2_BFD_RELOC_8},
++ {BFD_RELOC_NIOS2_GPREL, R_NIOS2_GPREL},
++ {BFD_RELOC_VTABLE_INHERIT, R_NIOS2_GNU_VTINHERIT},
++ {BFD_RELOC_VTABLE_ENTRY, R_NIOS2_GNU_VTENTRY},
++ {BFD_RELOC_NIOS2_UJMP, R_NIOS2_UJMP},
++ {BFD_RELOC_NIOS2_CJMP, R_NIOS2_CJMP},
++ {BFD_RELOC_NIOS2_CALLR, R_NIOS2_CALLR},
++ {BFD_RELOC_NIOS2_ALIGN, R_NIOS2_ALIGN},
++ {BFD_RELOC_NIOS2_GOT16, R_NIOS2_GOT16},
++ {BFD_RELOC_NIOS2_CALL16, R_NIOS2_CALL16},
++ {BFD_RELOC_NIOS2_GOTOFF_LO, R_NIOS2_GOTOFF_LO},
++ {BFD_RELOC_NIOS2_GOTOFF_HA, R_NIOS2_GOTOFF_HA},
++ {BFD_RELOC_NIOS2_PCREL_LO, R_NIOS2_PCREL_LO},
++ {BFD_RELOC_NIOS2_PCREL_HA, R_NIOS2_PCREL_HA},
++ {BFD_RELOC_NIOS2_TLS_GD16, R_NIOS2_TLS_GD16},
++ {BFD_RELOC_NIOS2_TLS_LDM16, R_NIOS2_TLS_LDM16},
++ {BFD_RELOC_NIOS2_TLS_LDO16, R_NIOS2_TLS_LDO16},
++ {BFD_RELOC_NIOS2_TLS_IE16, R_NIOS2_TLS_IE16},
++ {BFD_RELOC_NIOS2_TLS_LE16, R_NIOS2_TLS_LE16},
++ {BFD_RELOC_NIOS2_TLS_DTPMOD, R_NIOS2_TLS_DTPMOD},
++ {BFD_RELOC_NIOS2_TLS_DTPREL, R_NIOS2_TLS_DTPREL},
++ {BFD_RELOC_NIOS2_TLS_TPREL, R_NIOS2_TLS_TPREL},
++ {BFD_RELOC_NIOS2_COPY, R_NIOS2_COPY},
++ {BFD_RELOC_NIOS2_GLOB_DAT, R_NIOS2_GLOB_DAT},
++ {BFD_RELOC_NIOS2_JUMP_SLOT, R_NIOS2_JUMP_SLOT},
++ {BFD_RELOC_NIOS2_RELATIVE, R_NIOS2_RELATIVE},
++ {BFD_RELOC_NIOS2_GOTOFF, R_NIOS2_GOTOFF}
++};
++
++/* The Nios II linker needs to keep track of the number of relocs that it
++ decides to copy as dynamic relocs in check_relocs for each symbol.
++ This is so that it can later discard them if they are found to be
++ unnecessary. We store the information in a field extending the
++ regular ELF linker hash table. */
++
++struct elf32_nios2_dyn_relocs
++{
++ struct elf32_nios2_dyn_relocs *next;
++
++ /* The input section of the reloc. */
++ asection *sec;
++
++ /* Total number of relocs copied for the input section. */
++ bfd_size_type count;
++
++ /* Number of pc-relative relocs copied for the input section. */
++ bfd_size_type pc_count;
++};
++
++/* Nios II ELF linker hash entry. */
++
++struct elf32_nios2_link_hash_entry
++{
++ struct elf_link_hash_entry root;
++
++ /* Track dynamic relocs copied for this symbol. */
++ struct elf32_nios2_dyn_relocs *dyn_relocs;
++
++#define GOT_UNKNOWN 0
++#define GOT_NORMAL 1
++#define GOT_TLS_GD 2
++#define GOT_TLS_IE 4
++ unsigned char tls_type;
++
++ /* We need to detect and take special action for symbols which are only
++ referenced with %call() and not with %got(). Such symbols do not need
++ a dynamic GOT reloc in shared objects, only a dynamic PLT reloc. Lazy
++ linking will not work if the dynamic GOT reloc exists.
++ To check for this condition efficiently, we compare got_types_used against
++ CALL16_USED, meaning
++ (got_types_used & (GOT16_USED | CALL16_USED)) == CALL16_USED. */
++#define GOT16_USED 1
++#define CALL16_USED 2
++ unsigned char got_types_used;
++};
++
++#define elf32_nios2_hash_entry(ent) \
++ ((struct elf32_nios2_link_hash_entry *) (ent))
++
++/* Get the Nios II elf linker hash table from a link_info structure. */
++#define elf32_nios2_hash_table(info) \
++ ((struct elf32_nios2_link_hash_table *) ((info)->hash))
++
++/* Nios II ELF linker hash table. */
++struct elf32_nios2_link_hash_table
++ {
++ /* The main hash table. */
++ struct elf_link_hash_table root;
++
++ /* Short-cuts to get to dynamic linker sections. */
++ asection *sgot;
++ asection *sgotplt;
++ asection *srelgot;
++ asection *splt;
++ asection *srelplt;
++ asection *sdynbss;
++ asection *srelbss;
++ asection *sbss;
++
++ union {
++ bfd_signed_vma refcount;
++ bfd_vma offset;
++ } tls_ldm_got;
++
++ /* Small local sym to section mapping cache. */
++ struct sym_sec_cache sym_sec;
++
++ bfd_vma res_n_size;
++ };
++
++struct nios2_elf32_obj_tdata
++{
++ struct elf_obj_tdata root;
++
++ /* tls_type for each local got entry. */
++ char *local_got_tls_type;
++
++ /* TRUE if TLS GD relocs have been seen for this object. */
++ bfd_boolean has_tlsgd;
++};
++
++#define elf32_nios2_tdata(abfd) \
++ ((struct nios2_elf32_obj_tdata *) (abfd)->tdata.any)
++
++#define elf32_nios2_local_got_tls_type(abfd) \
++ (elf32_nios2_tdata (abfd)->local_got_tls_type)
++
++/* The name of the dynamic interpreter. This is put in the .interp
++ section. */
++
++#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
++
++/* PLT implementation for position-dependent code. */
++
++static const bfd_vma nios2_plt_entry[] = { /* .PLTn: */
++ 0x03c00034, /* movhi r15, %hiadj(plt_got_slot_address) */
++ 0x7bc00017, /* ldw r15, %lo(plt_got_slot_address)(r15) */
++ 0x7800683a /* jmp r15 */
++};
++
++static const bfd_vma nios2_plt0_entry[] = { /* .PLTresolve */
++ 0x03800034, /* movhi r14, %hiadj(res_0) */
++ 0x73800004, /* addi r14, r14, %lo(res_0) */
++ 0x7b9fc83a, /* sub r15, r15, r14 */
++ 0x03400034, /* movhi r13, %hiadj(_GLOBAL_OFFSET_TABLE_) */
++ 0x6b800017, /* ldw r14, %lo(_GLOBAL_OFFSET_TABLE_+4)(r13) */
++ 0x6b400017, /* ldw r13, %lo(_GLOBAL_OFFSET_TABLE_+8)(r13) */
++ 0x6800683a /* jmp r13 */
++};
++
++/* PLT implementation for position-independent code. */
++
++static const bfd_vma nios2_so_plt_entry[] = { /* .PLTn */
++ 0x03c00034, /* movhi r15, %hiadj(index * 4) */
++ 0x7bc00004, /* addi r15, r15, %lo(index * 4) */
++ 0x00000006 /* br .PLTresolve */
++};
++
++static const bfd_vma nios2_so_plt0_entry[] = { /* .PLTresolve */
++ 0x001ce03a, /* nextpc r14 */
++ 0x03400034, /* movhi r13, %hiadj(_GLOBAL_OFFSET_TABLE_) */
++ 0x6b9b883a, /* add r13, r13, r14 */
++ 0x6b800017, /* ldw r14, %lo(_GLOBAL_OFFSET_TABLE_+4)(r13) */
++ 0x6b400017, /* ldw r13, %lo(_GLOBAL_OFFSET_TABLE_+8)(r13) */
++ 0x6800683a /* jmp r13 */
++};
++
++/* Support for core dump NOTE sections */
++static bfd_boolean
++nios2_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
++{
++ int offset;
++ size_t size;
++
++ switch (note->descsz)
++ {
++ default:
++ return FALSE;
++
++ case 212: /* Linux/Nios II */
++ /* pr_cursig */
++ elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
++
++ /* pr_pid */
++ elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
++
++ /* pr_reg */
++ offset = 72;
++ size = 136;
++
++ break;
++ }
++
++ /* Make a ".reg/999" section. */
++ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
++ size, note->descpos + offset);
++}
++
++static bfd_boolean
++nios2_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
++{
++ switch (note->descsz)
++ {
++ default:
++ return FALSE;
++
++ case 124: /* Linux/Nios II elf_prpsinfo */
++ elf_tdata (abfd)->core_program
++ = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
++ elf_tdata (abfd)->core_command
++ = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
++ }
++
++ /* Note that for some reason, a spurious space is tacked
++ onto the end of the args in some (at least one anyway)
++ implementations, so strip it off if it exists. */
++
++ {
++ char *command = elf_tdata (abfd)->core_command;
++ int n = strlen (command);
++
++ if (0 < n && command[n - 1] == ' ')
++ command[n - 1] = '\0';
++ }
++
++ return TRUE;
++}
++
++/* Create an entry in a Nios II ELF linker hash table. */
++
++static struct bfd_hash_entry *
++link_hash_newfunc (struct bfd_hash_entry *entry,
++ struct bfd_hash_table *table, const char *string)
++{
++ /* Allocate the structure if it has not already been allocated by a
++ subclass. */
++ if (entry == NULL)
++ {
++ entry = bfd_hash_allocate (table,
++ sizeof (struct elf32_nios2_link_hash_entry));
++ if (entry == NULL)
++ return entry;
++ }
++
++ /* Call the allocation method of the superclass. */
++ entry = _bfd_elf_link_hash_newfunc (entry, table, string);
++ if (entry != NULL)
++ {
++ struct elf32_nios2_link_hash_entry *eh;
++
++ eh = (struct elf32_nios2_link_hash_entry *) entry;
++ eh->dyn_relocs = NULL;
++ eh->tls_type = GOT_UNKNOWN;
++ eh->got_types_used = 0;
++ }
++
++ return entry;
++}
++
++/* Given a BFD reloc type, return a howto structure. */
++
++static reloc_howto_type *
++nios2_elf32_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
++ bfd_reloc_code_real_type code)
++{
++ int i;
++ for (i = 0;
++ i < (int) (sizeof (nios2_reloc_map) / sizeof (struct elf_reloc_map));
++ ++i)
++ {
++ if (nios2_reloc_map[i].bfd_val == code)
++ return &elf_nios2_howto_table_rel[(int) nios2_reloc_map[i].elf_val];
++ }
++
++ return NULL;
++}
++
++/* Given a reloc name, return a howto structure. */
++
++static reloc_howto_type *
++nios2_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
++ const char *r_name)
++{
++ unsigned int i;
++ for (i = 0;
++ i < (sizeof (elf_nios2_howto_table_rel)
++ / sizeof (elf_nios2_howto_table_rel[0]));
++ i++)
++ if (elf_nios2_howto_table_rel[i].name != NULL
++ && strcasecmp (elf_nios2_howto_table_rel[i].name, r_name) == 0)
++ return &elf_nios2_howto_table_rel[i];
++
++ return NULL;
++}
++
++/* Helper function for nios2_elf32_info_to_howto. */
++