<ian@cygnus.com>.
N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
<mark@codesourcery.com>
+ Traditional MIPS targets support added by Koundinya.K, Dansk Data
+ Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
This file is part of BFD, the Binary File Descriptor library.
#include "coff/internal.h"
#include "coff/ecoff.h"
#include "coff/mips.h"
-#define ECOFF_32
+#define ECOFF_SIGNED_32
#include "ecoffswap.h"
/* This structure is used to hold .got information when linking. It
/* The global symbol in the GOT with the lowest index in the dynamic
symbol table. */
struct elf_link_hash_entry *global_gotsym;
+ /* The number of global .got entries. */
+ unsigned int global_gotno;
/* The number of local .got entries. */
unsigned int local_gotno;
/* The number of local .got entries we have used. */
/* External symbol information. */
EXTR esym;
- /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
- unsigned int mips_32_relocs;
+ /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
+ this symbol. */
+ unsigned int possibly_dynamic_relocs;
/* The index of the first dynamic relocation (in the .rel.dyn
section) against this symbol. */
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
PARAMS ((bfd *, bfd_reloc_code_real_type));
+static reloc_howto_type *mips_rtype_to_howto
+ PARAMS ((unsigned int));
static void mips_info_to_howto_rel
PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
static void mips_info_to_howto_rela
PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *));
static void bfd_mips_elf32_swap_gptab_out
PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *));
+#if 0
static void bfd_mips_elf_swap_msym_in
PARAMS ((bfd *, const Elf32_External_Msym *, Elf32_Internal_Msym *));
+#endif
static void bfd_mips_elf_swap_msym_out
PARAMS ((bfd *, const Elf32_Internal_Msym *, Elf32_External_Msym *));
static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
static struct bfd_hash_entry *mips_elf_link_hash_newfunc
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
static int gptab_compare PARAMS ((const void *, const void *));
-static void mips_elf_relocate_hi16
- PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *,
- bfd_vma));
-static boolean mips_elf_relocate_got_local
- PARAMS ((bfd *, bfd *, asection *, Elf_Internal_Rela *,
- Elf_Internal_Rela *, bfd_byte *, bfd_vma));
-static void mips_elf_relocate_global_got
- PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
static bfd_reloc_status_type mips16_jump_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static bfd_reloc_status_type mips16_gprel_reloc
struct mips_got_info *));
static bfd_vma mips_elf_got_page
PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, bfd_vma *));
-static boolean mips_elf_next_lo16_addend
- PARAMS ((const Elf_Internal_Rela *, const Elf_Internal_Rela *, bfd_vma *));
+static const Elf_Internal_Rela *mips_elf_next_relocation
+ PARAMS ((unsigned int, const Elf_Internal_Rela *,
+ const Elf_Internal_Rela *));
static bfd_reloc_status_type mips_elf_calculate_relocation
PARAMS ((bfd *, bfd *, asection *, struct bfd_link_info *,
const Elf_Internal_Rela *, bfd_vma, reloc_howto_type *,
- Elf_Internal_Sym *, asection **, bfd_vma *, const char **));
+ Elf_Internal_Sym *, asection **, bfd_vma *, const char **,
+ boolean *));
static bfd_vma mips_elf_obtain_contents
PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *));
-static void mips_elf_perform_relocation
- PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd_vma,
- bfd *, bfd_byte *));
+static boolean mips_elf_perform_relocation
+ PARAMS ((struct bfd_link_info *, reloc_howto_type *,
+ const Elf_Internal_Rela *, bfd_vma,
+ bfd *, asection *, bfd_byte *, boolean));
static boolean mips_elf_assign_gp PARAMS ((bfd *, bfd_vma *));
static boolean mips_elf_sort_hash_table_f
PARAMS ((struct mips_elf_link_hash_entry *, PTR));
static boolean mips_elf_sort_hash_table
- PARAMS ((struct bfd_link_info *));
+ PARAMS ((struct bfd_link_info *, unsigned long));
static asection * mips_elf_got_section PARAMS ((bfd *));
static struct mips_got_info *mips_elf_got_info
PARAMS ((bfd *, asection **));
+static boolean mips_elf_local_relocation_p
+ PARAMS ((bfd *, const Elf_Internal_Rela *, asection **, boolean));
static bfd_vma mips_elf_create_local_got_entry
PARAMS ((bfd *, struct mips_got_info *, asection *, bfd_vma));
static bfd_vma mips_elf_got16_entry
- PARAMS ((bfd *, struct bfd_link_info *, bfd_vma));
-static unsigned int mips_elf_create_dynamic_relocation
+ PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, boolean));
+static boolean mips_elf_create_dynamic_relocation
PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Rela *,
- long, bfd_vma, asection *));
+ struct mips_elf_link_hash_entry *, asection *,
+ bfd_vma, bfd_vma *, asection *));
static void mips_elf_allocate_dynamic_relocations
PARAMS ((bfd *, unsigned int));
+static boolean mips_elf_stub_section_p
+ PARAMS ((bfd *, asection *));
+static int sort_dynamic_relocs
+ PARAMS ((const void *, const void *));
+
+extern const bfd_target bfd_elf32_tradbigmips_vec;
/* The level of IRIX compatibility we're striving for. */
ict_irix6
} irix_compat_t;
+/* This will be used when we sort the dynamic relocation records. */
+static bfd *reldyn_sorting_bfd;
+
/* Nonzero if ABFD is using the N32 ABI. */
#define ABI_N32_P(abfd) \
#define ABI_64_P(abfd) \
((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
-/* What version of Irix we are trying to be compatible with. FIXME:
- At the moment, we never generate "normal" MIPS ELF ABI executables;
- we always use some version of Irix. */
+/* Depending on the target vector we generate some version of Irix
+ executables or "normal" MIPS ELF ABI executables. */
#define IRIX_COMPAT(abfd) \
- ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5)
+ (abfd->xvec == &bfd_elf32_tradbigmips_vec ? ict_none : \
+ ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
/* Whether we are trying to be compatible with IRIX at all. */
? (ABI_64_P (abfd) \
? 0xdf998010 /* ld t9,0x8010(gp) */ \
: 0x8f998010) /* lw t9,0x8010(gp) */ \
- : 0x8f998000) /* lw t9,0x8000(gp) */
-#define STUB_MOVE 0x03e07825 /* move t7,ra */
-#define STUB_JALR 0x0320f809 /* jal t9 */
-#define STUB_LI16 0x34180000 /* ori t8,zero,0 */
+ : 0x8f998010) /* lw t9,0x8000(gp) */
+#define STUB_MOVE(abfd) \
+ (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
+#define STUB_JALR 0x0320f809 /* jal t9 */
+#define STUB_LI16(abfd) \
+ (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
#define MIPS_FUNCTION_STUB_SIZE (16)
#if 0
_bfd_mips_elf_got16_reloc, /* special_function */
"R_MIPS_GOT16", /* name */
false, /* partial_inplace */
- 0, /* src_mask */
+ 0xffff, /* src_mask */
0xffff, /* dst_mask */
false), /* pcrel_offset */
true, /* partial_inplace */
0xffff, /* src_mask */
0xffff, /* dst_mask */
- false), /* pcrel_offset */
+ true), /* pcrel_offset */
/* 16 bit call through global offset table. */
HOWTO (R_MIPS_CALL16, /* type */
bfd_elf_generic_reloc, /* special_function */
"R_MIPS_CALL16", /* name */
false, /* partial_inplace */
- 0, /* src_mask */
+ 0xffff, /* src_mask */
0xffff, /* dst_mask */
false), /* pcrel_offset */
/* The remaining relocs are defined on Irix 5, although they are
not defined by the ABI. */
- { 13 },
- { 14 },
- { 15 },
+ EMPTY_HOWTO (13),
+ EMPTY_HOWTO (14),
+ EMPTY_HOWTO (15),
/* A 5 bit shift field. */
HOWTO (R_MIPS_SHIFT5, /* type */
0x000007c4, /* dst_mask */
false), /* pcrel_offset */
- /* A 64 bit relocation. This is used in 32 bit ELF when addresses
- are 64 bits long; the upper 32 bits are simply a sign extension.
- The fields of the howto should be the same as for R_MIPS_32,
- other than the type, name, and special_function. */
+ /* A 64 bit relocation. */
HOWTO (R_MIPS_64, /* type */
0, /* rightshift */
- 2, /* size (0 = byte, 1 = short, 2 = long) */
- 32, /* bitsize */
+ 4, /* size (0 = byte, 1 = short, 2 = long) */
+ 64, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
mips32_64bit_reloc, /* special_function */
"R_MIPS_64", /* name */
true, /* partial_inplace */
- 0xffffffff, /* src_mask */
- 0xffffffff, /* dst_mask */
+ MINUS_ONE, /* src_mask */
+ MINUS_ONE, /* dst_mask */
false), /* pcrel_offset */
/* Displacement in the global offset table. */
false), /* pcrel_offset */
/* Used to cause the linker to insert and delete instructions? */
- { R_MIPS_INSERT_A },
- { R_MIPS_INSERT_B },
- { R_MIPS_DELETE },
+ EMPTY_HOWTO (R_MIPS_INSERT_A),
+ EMPTY_HOWTO (R_MIPS_INSERT_B),
+ EMPTY_HOWTO (R_MIPS_DELETE),
/* Get the higher value of a 64 bit addend. */
HOWTO (R_MIPS_HIGHER, /* type */
0xffffffff, /* dst_mask */
false), /* pcrel_offset */
- { R_MIPS_REL16 },
- { R_MIPS_ADD_IMMEDIATE },
- { R_MIPS_PJUMP },
- { R_MIPS_RELGOT },
+ EMPTY_HOWTO (R_MIPS_REL16),
+ EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
+ EMPTY_HOWTO (R_MIPS_PJUMP),
+ EMPTY_HOWTO (R_MIPS_RELGOT),
/* Protected jump conversion. This is an optimization hint. No
relocation is required for correctness. */
0x3ffffff, /* dst_mask */
false); /* pcrel_offset */
-/* The reloc used for the mips16 gprel instruction. The src_mask and
- dsk_mask for this howto do not reflect the actual instruction, in
- which the value is not contiguous; the masks are for the
- convenience of the relocate_section routine. */
+/* The reloc used for the mips16 gprel instruction. */
static reloc_howto_type elf_mips16_gprel_howto =
HOWTO (R_MIPS16_GPREL, /* type */
0, /* rightshift */
mips16_gprel_reloc, /* special_function */
"R_MIPS16_GPREL", /* name */
true, /* partial_inplace */
+ 0x07ff001f, /* src_mask */
+ 0x07ff001f, /* dst_mask */
+ false); /* pcrel_offset */
+
+/* GNU extensions for embedded-pic. */
+/* High 16 bits of symbol value, pc-relative. */
+static reloc_howto_type elf_mips_gnu_rel_hi16 =
+ HOWTO (R_MIPS_GNU_REL_HI16, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ _bfd_mips_elf_hi16_reloc, /* special_function */
+ "R_MIPS_GNU_REL_HI16", /* name */
+ true, /* partial_inplace */
0xffff, /* src_mask */
0xffff, /* dst_mask */
- false); /* pcrel_offset */
+ true); /* pcrel_offset */
+
+/* Low 16 bits of symbol value, pc-relative. */
+static reloc_howto_type elf_mips_gnu_rel_lo16 =
+ HOWTO (R_MIPS_GNU_REL_LO16, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ _bfd_mips_elf_lo16_reloc, /* special_function */
+ "R_MIPS_GNU_REL_LO16", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ true); /* pcrel_offset */
+
+/* 16 bit offset for pc-relative branches. */
+static reloc_howto_type elf_mips_gnu_rel16_s2 =
+ HOWTO (R_MIPS_GNU_REL16_S2, /* type */
+ 2, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_MIPS_GNU_REL16_S2", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ true); /* pcrel_offset */
+
+/* 64 bit pc-relative. */
+static reloc_howto_type elf_mips_gnu_pcrel64 =
+ HOWTO (R_MIPS_PC64, /* type */
+ 0, /* rightshift */
+ 4, /* size (0 = byte, 1 = short, 2 = long) */
+ 64, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_MIPS_PC64", /* name */
+ true, /* partial_inplace */
+ MINUS_ONE, /* src_mask */
+ MINUS_ONE, /* dst_mask */
+ true); /* pcrel_offset */
+/* 32 bit pc-relative. */
+static reloc_howto_type elf_mips_gnu_pcrel32 =
+ HOWTO (R_MIPS_PC32, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_MIPS_PC32", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ true); /* pcrel_offset */
/* GNU extension to record C++ vtable hierarchy */
static reloc_howto_type elf_mips_gnu_vtinherit_howto =
input_section,
output_bfd,
error_message)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
reloc_entry->address += input_section->output_offset;
/* Make sure it fit in 16 bits. */
- if (val >= 0x8000 && val < 0xffff8000)
+ if ((long) val >= 0x8000 || (long) val < -0x8000)
return bfd_reloc_overflow;
return bfd_reloc_ok;
static bfd_reloc_status_type
mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
arelent *reloc_entry;
asymbol *symbol;
- PTR data;
+ PTR data ATTRIBUTE_UNUSED;
asection *input_section;
bfd *output_bfd;
- char **error_message;
+ char **error_message ATTRIBUTE_UNUSED;
{
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
return &elf_mips_gnu_vtinherit_howto;
case BFD_RELOC_VTABLE_ENTRY:
return &elf_mips_gnu_vtentry_howto;
+ case BFD_RELOC_PCREL_HI16_S:
+ return &elf_mips_gnu_rel_hi16;
+ case BFD_RELOC_PCREL_LO16:
+ return &elf_mips_gnu_rel_lo16;
+ case BFD_RELOC_16_PCREL_S2:
+ return &elf_mips_gnu_rel16_s2;
+ case BFD_RELOC_64_PCREL:
+ return &elf_mips_gnu_pcrel64;
+ case BFD_RELOC_32_PCREL:
+ return &elf_mips_gnu_pcrel32;
}
}
/* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
-static void
-mips_info_to_howto_rel (abfd, cache_ptr, dst)
- bfd *abfd;
- arelent *cache_ptr;
- Elf32_Internal_Rel *dst;
+static reloc_howto_type *
+mips_rtype_to_howto (r_type)
+ unsigned int r_type;
{
- unsigned int r_type;
-
- r_type = ELF32_R_TYPE (dst->r_info);
switch (r_type)
{
case R_MIPS16_26:
- cache_ptr->howto = &elf_mips16_jump_howto;
+ return &elf_mips16_jump_howto;
break;
case R_MIPS16_GPREL:
- cache_ptr->howto = &elf_mips16_gprel_howto;
+ return &elf_mips16_gprel_howto;
break;
case R_MIPS_GNU_VTINHERIT:
- cache_ptr->howto = &elf_mips_gnu_vtinherit_howto;
+ return &elf_mips_gnu_vtinherit_howto;
break;
case R_MIPS_GNU_VTENTRY:
- cache_ptr->howto = &elf_mips_gnu_vtentry_howto;
+ return &elf_mips_gnu_vtentry_howto;
+ break;
+ case R_MIPS_GNU_REL_HI16:
+ return &elf_mips_gnu_rel_hi16;
+ break;
+ case R_MIPS_GNU_REL_LO16:
+ return &elf_mips_gnu_rel_lo16;
+ break;
+ case R_MIPS_GNU_REL16_S2:
+ return &elf_mips_gnu_rel16_s2;
+ break;
+ case R_MIPS_PC64:
+ return &elf_mips_gnu_pcrel64;
+ break;
+ case R_MIPS_PC32:
+ return &elf_mips_gnu_pcrel32;
break;
default:
BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
- cache_ptr->howto = &elf_mips_howto_table[r_type];
+ return &elf_mips_howto_table[r_type];
break;
}
+}
+
+/* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
+
+static void
+mips_info_to_howto_rel (abfd, cache_ptr, dst)
+ bfd *abfd;
+ arelent *cache_ptr;
+ Elf32_Internal_Rel *dst;
+{
+ unsigned int r_type;
+
+ r_type = ELF32_R_TYPE (dst->r_info);
+ cache_ptr->howto = mips_rtype_to_howto (r_type);
/* The addend for a GPREL16 or LITERAL relocation comes from the GP
value for the object file. We get the addend now, rather than
bfd_h_put_16 (abfd, in->section, ex->section);
bfd_h_put_32 (abfd, in->info, ex->info);
}
-
+#if 0
/* Swap in an MSYM entry. */
static void
in->ms_hash_value = bfd_h_get_32 (abfd, ex->ms_hash_value);
in->ms_info = bfd_h_get_32 (abfd, ex->ms_info);
}
-
+#endif
/* Swap out an MSYM entry. */
static void
/*ARGSUSED*/
static boolean
mips_elf_sym_is_global (abfd, sym)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
asymbol *sym;
{
return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
void
_bfd_mips_elf_final_write_processing (abfd, linker)
bfd *abfd;
- boolean linker;
+ boolean linker ATTRIBUTE_UNUSED;
{
unsigned long val;
unsigned int i;
boolean ok;
/* Check if we have the same endianess */
- if (ibfd->xvec->byteorder != obfd->xvec->byteorder
- && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
- {
- const char *msg;
-
- if (bfd_big_endian (ibfd))
- msg = _("%s: compiled for a big endian system and target is little endian");
- else
- msg = _("%s: compiled for a little endian system and target is big endian");
-
- (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));
-
- bfd_set_error (bfd_error_wrong_format);
- return false;
- }
+ if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
+ return false;
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
hdr->sh_type = SHT_MIPS_REGINFO;
/* In a shared object on Irix 5.3, the .reginfo section has an
entsize of 0x18. FIXME: Does this matter? */
- if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
- hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
+ if (SGI_COMPAT (abfd))
+ {
+ if ((abfd->flags & DYNAMIC) != 0)
+ hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
+ else
+ hdr->sh_entsize = 1;
+ }
else
- hdr->sh_entsize = 1;
+ hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
}
else if (SGI_COMPAT (abfd)
&& (strcmp (name, ".hash") == 0
|| strcmp (name, ".dynamic") == 0
|| strcmp (name, ".dynstr") == 0))
{
- hdr->sh_entsize = 0;
+ if ( SGI_COMPAT(abfd))
+ hdr->sh_entsize = 0;
#if 0
/* This isn't how the Irix 6 linker behaves. */
hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
boolean
_bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
- bfd *abfd;
- Elf32_Internal_Shdr *hdr;
+ bfd *abfd ATTRIBUTE_UNUSED;
+ Elf32_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
asection *sec;
int *retval;
{
static asymbol mips_elf_acom_symbol;
static asymbol *mips_elf_acom_symbol_ptr;
-/* The Irix 5 support uses two virtual sections, which represent
- text/data symbols defined in dynamic objects. */
-static asection mips_elf_text_section;
-static asection *mips_elf_text_section_ptr;
-static asymbol mips_elf_text_symbol;
-static asymbol *mips_elf_text_symbol_ptr;
-
-static asection mips_elf_data_section;
-static asection *mips_elf_data_section_ptr;
-static asymbol mips_elf_data_symbol;
-static asymbol *mips_elf_data_symbol_ptr;
-
/* Handle the special MIPS section numbers that a symbol may use.
This is used for both the 32-bit and the 64-bit ABI. */
asection *s;
int ret = 0;
- if (!SGI_COMPAT (abfd))
- return 0;
-
/* See if we need a PT_MIPS_REGINFO segment. */
s = bfd_get_section_by_name (abfd, ".reginfo");
if (s && (s->flags & SEC_LOAD))
asection *s;
struct elf_segment_map *m, **pm;
- if (! SGI_COMPAT (abfd))
- return true;
-
/* If there is a .reginfo section, we need a PT_MIPS_REGINFO
segment. */
s = bfd_get_section_by_name (abfd, ".reginfo");
{
struct elf_segment_map *options_segment;
- for (m = elf_tdata (abfd)->segment_map; m; m = m->next)
- if (m->p_type == PT_PHDR)
+ /* Usually, there's a program header table. But, sometimes
+ there's not (like when running the `ld' testsuite). So,
+ if there's no program header table, we just put the
+ options segement at the end. */
+ for (pm = &elf_tdata (abfd)->segment_map;
+ *pm != NULL;
+ pm = &(*pm)->next)
+ if ((*pm)->p_type == PT_PHDR)
break;
- /* There should always be a program header table. */
- if (m == NULL)
- return false;
-
options_segment = bfd_zalloc (abfd,
sizeof (struct elf_segment_map));
- options_segment->next = m->next;
+ options_segment->next = *pm;
options_segment->p_type = PT_MIPS_OPTIONS;
options_segment->p_flags = PF_R;
options_segment->p_flags_valid = true;
options_segment->count = 1;
options_segment->sections[0] = s;
- m->next = options_segment;
+ *pm = options_segment;
}
}
else
{
- /* If there are .dynamic and .mdebug sections, we make a room
- for the RTPROC header. FIXME: Rewrite without section names. */
- if (bfd_get_section_by_name (abfd, ".interp") == NULL
- && bfd_get_section_by_name (abfd, ".dynamic") != NULL
- && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
+ if (IRIX_COMPAT (abfd) == ict_irix5)
{
- for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
- if (m->p_type == PT_MIPS_RTPROC)
- break;
- if (m == NULL)
+ /* If there are .dynamic and .mdebug sections, we make a room
+ for the RTPROC header. FIXME: Rewrite without section names. */
+ if (bfd_get_section_by_name (abfd, ".interp") == NULL
+ && bfd_get_section_by_name (abfd, ".dynamic") != NULL
+ && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
{
- m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
+ for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+ if (m->p_type == PT_MIPS_RTPROC)
+ break;
if (m == NULL)
- return false;
+ {
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
+ if (m == NULL)
+ return false;
- m->p_type = PT_MIPS_RTPROC;
+ m->p_type = PT_MIPS_RTPROC;
- s = bfd_get_section_by_name (abfd, ".rtproc");
- if (s == NULL)
- {
- m->count = 0;
- m->p_flags = 0;
- m->p_flags_valid = 1;
- }
- else
- {
- m->count = 1;
- m->sections[0] = s;
- }
+ s = bfd_get_section_by_name (abfd, ".rtproc");
+ if (s == NULL)
+ {
+ m->count = 0;
+ m->p_flags = 0;
+ m->p_flags_valid = 1;
+ }
+ else
+ {
+ m->count = 1;
+ m->sections[0] = s;
+ }
- /* We want to put it after the DYNAMIC segment. */
- pm = &elf_tdata (abfd)->segment_map;
- while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
- pm = &(*pm)->next;
- if (*pm != NULL)
- pm = &(*pm)->next;
+ /* We want to put it after the DYNAMIC segment. */
+ pm = &elf_tdata (abfd)->segment_map;
+ while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
+ pm = &(*pm)->next;
+ if (*pm != NULL)
+ pm = &(*pm)->next;
- m->next = *pm;
- *pm = m;
+ m->next = *pm;
+ *pm = m;
+ }
}
}
-
/* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
.dynstr, .dynsym, and .hash sections, and everything in
between. */
- for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
+ for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL;
+ pm = &(*pm)->next)
if ((*pm)->p_type == PT_DYNAMIC)
break;
m = *pm;
+ if (IRIX_COMPAT (abfd) == ict_none)
+ {
+ /* For a normal mips executable the permissions for the PT_DYNAMIC
+ segment are read, write and execute. We do that here since
+ the code in elf.c sets only the read permission. This matters
+ sometimes for the dynamic linker. */
+ if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
+ {
+ m->p_flags = PF_R | PF_W | PF_X;
+ m->p_flags_valid = 1;
+ }
+ }
if (m != NULL
- && m->count == 1
- && strcmp (m->sections[0]->name, ".dynamic") == 0)
+ && m->count == 1 && strcmp (m->sections[0]->name, ".dynamic") == 0)
{
static const char *sec_names[] =
{ ".dynamic", ".dynstr", ".dynsym", ".hash" };
if ((s->flags & SEC_LOAD) != 0
&& s->vma >= low
&& ((s->vma
- + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
- <= high))
+ + (s->_cooked_size !=
+ 0 ? s->_cooked_size : s->_raw_size)) <= high))
++c;
n = ((struct elf_segment_map *)
&& s->vma >= low
&& ((s->vma
+ (s->_cooked_size != 0 ?
- s->_cooked_size : s->_raw_size))
- <= high))
+ s->_cooked_size : s->_raw_size)) <= high))
{
n->sections[i] = s;
++i;
/* We use -2 as a marker to indicate that the information has
not been set. -1 means there is no associated ifd. */
ret->esym.ifd = -2;
- ret->mips_32_relocs = 0;
+ ret->possibly_dynamic_relocs = 0;
ret->min_dyn_reloc_index = 0;
ret->fn_stub = NULL;
ret->need_fn_stub = false;
return (struct bfd_hash_entry *) ret;
}
+void
+_bfd_mips_elf_hide_symbol(info, h)
+ struct bfd_link_info *info;
+ struct mips_elf_link_hash_entry *h;
+{
+ bfd *dynobj;
+ asection *got;
+ struct mips_got_info *g;
+ dynobj = elf_hash_table (info)->dynobj;
+ got = bfd_get_section_by_name (dynobj, ".got");
+ g = (struct mips_got_info *) elf_section_data (got)->tdata;
+
+ h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+ h->root.plt.offset = (bfd_vma) -1;
+ h->root.dynindx = -1;
+
+ /* FIXME: Do we allocate too much GOT space here? */
+ g->local_gotno++;
+ got->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
+}
+
/* Create a MIPS ELF linker hash table. */
struct bfd_link_hash_table *
struct bfd_link_info *info;
const Elf_Internal_Sym *sym;
const char **namep;
- flagword *flagsp;
+ flagword *flagsp ATTRIBUTE_UNUSED;
asection **secp;
bfd_vma *valp;
{
case SHN_MIPS_TEXT:
/* This section is used in a shared object. */
- if (mips_elf_text_section_ptr == NULL)
+ if (elf_tdata (abfd)->elf_text_section == NULL)
{
+ asymbol *elf_text_symbol;
+ asection *elf_text_section;
+
+ elf_text_section = bfd_zalloc (abfd, sizeof (asection));
+ if (elf_text_section == NULL)
+ return false;
+
+ elf_text_symbol = bfd_zalloc (abfd, sizeof (asymbol));
+ if (elf_text_symbol == NULL)
+ return false;
+
/* Initialize the section. */
- mips_elf_text_section.name = ".text";
- mips_elf_text_section.flags = SEC_NO_FLAGS;
- mips_elf_text_section.output_section = NULL;
- mips_elf_text_section.symbol = &mips_elf_text_symbol;
- mips_elf_text_section.symbol_ptr_ptr = &mips_elf_text_symbol_ptr;
- mips_elf_text_symbol.name = ".text";
- mips_elf_text_symbol.flags = BSF_SECTION_SYM;
- mips_elf_text_symbol.section = &mips_elf_text_section;
- mips_elf_text_symbol_ptr = &mips_elf_text_symbol;
- mips_elf_text_section_ptr = &mips_elf_text_section;
+
+ elf_tdata (abfd)->elf_text_section = elf_text_section;
+ elf_tdata (abfd)->elf_text_symbol = elf_text_symbol;
+
+ elf_text_section->symbol = elf_text_symbol;
+ elf_text_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_text_symbol;
+
+ elf_text_section->name = ".text";
+ elf_text_section->flags = SEC_NO_FLAGS;
+ elf_text_section->output_section = NULL;
+ elf_text_section->owner = abfd;
+ elf_text_symbol->name = ".text";
+ elf_text_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
+ elf_text_symbol->section = elf_text_section;
}
/* This code used to do *secp = bfd_und_section_ptr if
info->shared. I don't know why, and that doesn't make sense,
so I took it out. */
- *secp = mips_elf_text_section_ptr;
+ *secp = elf_tdata (abfd)->elf_text_section;
break;
case SHN_MIPS_ACOMMON:
/* Fall through. XXX Can we treat this as allocated data? */
case SHN_MIPS_DATA:
/* This section is used in a shared object. */
- if (mips_elf_data_section_ptr == NULL)
+ if (elf_tdata (abfd)->elf_data_section == NULL)
{
+ asymbol *elf_data_symbol;
+ asection *elf_data_section;
+
+ elf_data_section = bfd_zalloc (abfd, sizeof (asection));
+ if (elf_data_section == NULL)
+ return false;
+
+ elf_data_symbol = bfd_zalloc (abfd, sizeof (asymbol));
+ if (elf_data_symbol == NULL)
+ return false;
+
/* Initialize the section. */
- mips_elf_data_section.name = ".data";
- mips_elf_data_section.flags = SEC_NO_FLAGS;
- mips_elf_data_section.output_section = NULL;
- mips_elf_data_section.symbol = &mips_elf_data_symbol;
- mips_elf_data_section.symbol_ptr_ptr = &mips_elf_data_symbol_ptr;
- mips_elf_data_symbol.name = ".data";
- mips_elf_data_symbol.flags = BSF_SECTION_SYM;
- mips_elf_data_symbol.section = &mips_elf_data_section;
- mips_elf_data_symbol_ptr = &mips_elf_data_symbol;
- mips_elf_data_section_ptr = &mips_elf_data_section;
+
+ elf_tdata (abfd)->elf_data_section = elf_data_section;
+ elf_tdata (abfd)->elf_data_symbol = elf_data_symbol;
+
+ elf_data_section->symbol = elf_data_symbol;
+ elf_data_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_data_symbol;
+
+ elf_data_section->name = ".data";
+ elf_data_section->flags = SEC_NO_FLAGS;
+ elf_data_section->output_section = NULL;
+ elf_data_section->owner = abfd;
+ elf_data_symbol->name = ".data";
+ elf_data_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
+ elf_data_symbol->section = elf_data_section;
}
/* This code used to do *secp = bfd_und_section_ptr if
info->shared. I don't know why, and that doesn't make sense,
so I took it out. */
- *secp = mips_elf_data_section_ptr;
+ *secp = elf_tdata (abfd)->elf_data_section;
break;
case SHN_MIPS_SUNDEFINED:
h->esym.asym.value = 0;
h->esym.asym.st = stGlobal;
- if (SGI_COMPAT (einfo->abfd)
- && (h->root.root.type == bfd_link_hash_undefined
- || h->root.root.type == bfd_link_hash_undefweak))
+ if (h->root.root.type == bfd_link_hash_undefined
+ || h->root.root.type == bfd_link_hash_undefweak)
{
const char *name;
= get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
HDRR *symhdr = &debug.symbolic_header;
PTR mdebug_handle = NULL;
+ asection *s;
+ EXTR esym;
+ bfd_vma last;
+ unsigned int i;
+ static const char * const name[] =
+ { ".text", ".init", ".fini", ".data",
+ ".rodata", ".sdata", ".sbss", ".bss" };
+ static const int sc[] = { scText, scInit, scFini, scData,
+ scRData, scSData, scSBss, scBss };
/* If all the things we linked together were PIC, but we're
producing an executable (rather than a shared object), then the
elf_elfheader (abfd)->e_flags |= EF_MIPS_CPIC;
}
+ /* We'd carefully arranged the dynamic symbol indices, and then the
+ generic size_dynamic_sections renumbered them out from under us.
+ Rather than trying somehow to prevent the renumbering, just do
+ the sort again. */
+ if (elf_hash_table (info)->dynamic_sections_created)
+ {
+ bfd *dynobj;
+ asection *got;
+ struct mips_got_info *g;
+
+ /* When we resort, we must tell mips_elf_sort_hash_table what
+ the lowest index it may use is. That's the number of section
+ symbols we're going to add. The generic ELF linker only
+ adds these symbols when building a shared object. Note that
+ we count the sections after (possibly) removing the .options
+ section above. */
+ if (!mips_elf_sort_hash_table (info, (info->shared
+ ? bfd_count_sections (abfd) + 1
+ : 1)))
+ return false;
+
+ /* Make sure we didn't grow the global .got region. */
+ dynobj = elf_hash_table (info)->dynobj;
+ got = bfd_get_section_by_name (dynobj, ".got");
+ g = (struct mips_got_info *) elf_section_data (got)->tdata;
+
+ if (g->global_gotsym != NULL)
+ BFD_ASSERT ((elf_hash_table (info)->dynsymcount
+ - g->global_gotsym->dynindx)
+ <= g->global_gotno);
+ }
+
/* On IRIX5, we omit the .options section. On IRIX6, however, we
include it, even though we don't process it quite right. (Some
entries are supposed to be merged.) Empirically, we seem to be
better off including it then not. */
- if (IRIX_COMPAT (abfd) == ict_irix5)
+ if (IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
{
if (strcmp ((*secpp)->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
if (mdebug_handle == (PTR) NULL)
return false;
- if (SGI_COMPAT (abfd))
- {
- asection *s;
- EXTR esym;
- bfd_vma last;
- unsigned int i;
- static const char * const name[] =
- { ".text", ".init", ".fini", ".data",
- ".rodata", ".sdata", ".sbss", ".bss" };
- static const int sc[] = { scText, scInit, scFini, scData,
- scRData, scSData, scSBss, scBss };
-
- esym.jmptbl = 0;
- esym.cobol_main = 0;
- esym.weakext = 0;
- esym.reserved = 0;
- esym.ifd = ifdNil;
- esym.asym.iss = issNil;
- esym.asym.st = stLocal;
- esym.asym.reserved = 0;
- esym.asym.index = indexNil;
- last = 0;
- for (i = 0; i < 8; i++)
- {
- esym.asym.sc = sc[i];
- s = bfd_get_section_by_name (abfd, name[i]);
- if (s != NULL)
- {
- esym.asym.value = s->vma;
- last = s->vma + s->_raw_size;
- }
- else
- esym.asym.value = last;
-
- if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
- name[i], &esym))
- return false;
- }
- }
+ esym.jmptbl = 0;
+ esym.cobol_main = 0;
+ esym.weakext = 0;
+ esym.reserved = 0;
+ esym.ifd = ifdNil;
+ esym.asym.iss = issNil;
+ esym.asym.st = stLocal;
+ esym.asym.reserved = 0;
+ esym.asym.index = indexNil;
+ last = 0;
+ for (i = 0; i < 8; i++)
+ {
+ esym.asym.sc = sc[i];
+ s = bfd_get_section_by_name (abfd, name[i]);
+ if (s != NULL)
+ {
+ esym.asym.value = s->vma;
+ last = s->vma + s->_raw_size;
+ }
+ else
+ esym.asym.value = last;
+ if (!bfd_ecoff_debug_one_external (abfd, &debug, swap,
+ name[i], &esym))
+ return false;
+ }
for (p = o->link_order_head;
p != (struct bfd_link_order *) NULL;
return true;
}
-/* Handle a MIPS ELF HI16 reloc. */
+/* This function is called via qsort() to sort the dynamic relocation
+ entries by increasing r_symndx value. */
-static void
-mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
- bfd *input_bfd;
- Elf_Internal_Rela *relhi;
- Elf_Internal_Rela *rello;
- bfd_byte *contents;
- bfd_vma addend;
+static int
+sort_dynamic_relocs (arg1,arg2)
+ const PTR arg1;
+ const PTR arg2;
{
- bfd_vma insn;
- bfd_vma addlo;
+ const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1;
+ const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2;
- insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
+ Elf_Internal_Rel int_reloc1;
+ Elf_Internal_Rel int_reloc2;
- addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
- addlo &= 0xffff;
+ bfd_elf32_swap_reloc_in(reldyn_sorting_bfd, ext_reloc1, &int_reloc1);
+ bfd_elf32_swap_reloc_in(reldyn_sorting_bfd, ext_reloc2, &int_reloc2);
- addend += ((insn & 0xffff) << 16) + addlo;
+ return (ELF32_R_SYM(int_reloc1.r_info) - ELF32_R_SYM(int_reloc2.r_info));
+}
- if ((addlo & 0x8000) != 0)
- addend -= 0x10000;
- if ((addend & 0x8000) != 0)
- addend += 0x10000;
+/* Returns the GOT section for ABFD. */
- bfd_put_32 (input_bfd,
- (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
- contents + relhi->r_offset);
+static asection *
+mips_elf_got_section (abfd)
+ bfd *abfd;
+{
+ return bfd_get_section_by_name (abfd, ".got");
}
-/* Handle a MIPS ELF local GOT16 reloc. */
+/* Returns the GOT information associated with the link indicated by
+ INFO. If SGOTP is non-NULL, it is filled in with the GOT
+ section. */
-static boolean
-mips_elf_relocate_got_local (output_bfd, input_bfd, sgot, relhi, rello,
- contents, addend)
- bfd *output_bfd;
- bfd *input_bfd;
- asection *sgot;
- Elf_Internal_Rela *relhi;
- Elf_Internal_Rela *rello;
- bfd_byte *contents;
- bfd_vma addend;
+static struct mips_got_info *
+mips_elf_got_info (abfd, sgotp)
+ bfd *abfd;
+ asection **sgotp;
{
- unsigned int assigned_gotno;
- unsigned int i;
- bfd_vma insn;
- bfd_vma addlo;
- bfd_vma address;
- bfd_vma hipage;
- bfd_byte *got_contents;
+ asection *sgot;
struct mips_got_info *g;
- insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
+ sgot = mips_elf_got_section (abfd);
+ BFD_ASSERT (sgot != NULL);
+ BFD_ASSERT (elf_section_data (sgot) != NULL);
+ g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
+ BFD_ASSERT (g != NULL);
- addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
- addlo &= 0xffff;
+ if (sgotp)
+ *sgotp = sgot;
+ return g;
+}
- addend += ((insn & 0xffff) << 16) + addlo;
+/* Return whether a relocation is against a local symbol. */
- if ((addlo & 0x8000) != 0)
- addend -= 0x10000;
- if ((addend & 0x8000) != 0)
- addend += 0x10000;
+static boolean
+mips_elf_local_relocation_p (input_bfd, relocation, local_sections,
+ check_forced)
+ bfd *input_bfd;
+ const Elf_Internal_Rela *relocation;
+ asection **local_sections;
+ boolean check_forced;
+{
+ unsigned long r_symndx;
+ Elf_Internal_Shdr *symtab_hdr;
+ struct mips_elf_link_hash_entry* h;
+ size_t extsymoff;
- /* Get a got entry representing requested hipage. */
- BFD_ASSERT (elf_section_data (sgot) != NULL);
- g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
- BFD_ASSERT (g != NULL);
+ r_symndx = ELF32_R_SYM (relocation->r_info);
+ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+ extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
- assigned_gotno = g->assigned_gotno;
- got_contents = sgot->contents;
- hipage = addend & 0xffff0000;
+ if (r_symndx < extsymoff)
+ return true;
+ if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
+ return true;
- for (i = MIPS_RESERVED_GOTNO; i < assigned_gotno; i++)
+ if (check_forced)
{
- address = bfd_get_32 (input_bfd, got_contents + i * 4);
- if (hipage == (address & 0xffff0000))
- break;
+ /* Look up the hash table to check whether the symbol
+ was forced local. */
+ h = (struct mips_elf_link_hash_entry *)
+ elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
+ /* Find the real hash-table entry for this symbol. */
+ while (h->root.root.type == bfd_link_hash_indirect
+ || h->root.root.type == bfd_link_hash_warning)
+ h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
+ if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
+ return true;
}
- if (i == assigned_gotno)
- {
- if (assigned_gotno >= g->local_gotno)
- {
- (*_bfd_error_handler)
- (_("more got entries are needed for hipage relocations"));
- bfd_set_error (bfd_error_bad_value);
- return false;
- }
-
- bfd_put_32 (input_bfd, hipage, got_contents + assigned_gotno * 4);
- ++g->assigned_gotno;
- }
-
- i = - ELF_MIPS_GP_OFFSET (output_bfd) + i * 4;
- bfd_put_32 (input_bfd, (insn & 0xffff0000) | (i & 0xffff),
- contents + relhi->r_offset);
-
- return true;
-}
-
-/* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
-
-static void
-mips_elf_relocate_global_got (input_bfd, rel, contents, offset)
- bfd *input_bfd;
- Elf_Internal_Rela *rel;
- bfd_byte *contents;
- bfd_vma offset;
-{
- bfd_vma insn;
-
- insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
- bfd_put_32 (input_bfd,
- (insn & 0xffff0000) | (offset & 0xffff),
- contents + rel->r_offset);
-}
-
-/* Returns the GOT section for ABFD. */
-
-static asection *
-mips_elf_got_section (abfd)
- bfd *abfd;
-{
- return bfd_get_section_by_name (abfd, ".got");
-}
-
-/* Returns the GOT information associated with the link indicated by
- INFO. If SGOTP is non-NULL, it is filled in with the GOT
- section. */
-
-static struct mips_got_info *
-mips_elf_got_info (abfd, sgotp)
- bfd *abfd;
- asection **sgotp;
-{
- asection *sgot;
- struct mips_got_info *g;
-
- sgot = mips_elf_got_section (abfd);
- BFD_ASSERT (sgot != NULL);
- BFD_ASSERT (elf_section_data (sgot) != NULL);
- g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
- BFD_ASSERT (g != NULL);
-
- if (sgotp)
- *sgotp = sgot;
- return g;
+ return false;
}
/* Sign-extend VALUE, which has the indicated number of BITS. */
bfd_vma value;
int bits;
{
- if (value & (1 << (bits - 1)))
+ if (value & ((bfd_vma)1 << (bits - 1)))
/* VALUE is negative. */
value |= ((bfd_vma) - 1) << bits;
static bfd_vma
mips_elf_higher (value)
- bfd_vma value;
+ bfd_vma value ATTRIBUTE_UNUSED;
{
#ifdef BFD64
return ((value + (bfd_vma) 0x80008000) >> 32) & 0xffff;
static bfd_vma
mips_elf_highest (value)
- bfd_vma value;
+ bfd_vma value ATTRIBUTE_UNUSED;
{
#ifdef BFD64
- return ((value + (bfd_vma) 0x800080008000) > 48) & 0xffff;
+ return ((value + (bfd_vma) 0x800080008000) >> 48) & 0xffff;
#else
abort ();
return (bfd_vma) -1;
mips_elf_record_global_got_symbol (h, info, g)
struct elf_link_hash_entry *h;
struct bfd_link_info *info;
- struct mips_got_info *g;
+ struct mips_got_info *g ATTRIBUTE_UNUSED;
{
/* A global symbol in the GOT must also be in the dynamic symbol
table. */
/* Sort the dynamic symbol table so that symbols that need GOT entries
appear towards the end. This reduces the amount of GOT space
- required. */
+ required. MAX_LOCAL is used to set the number of local symbols
+ known to be in the dynamic symbol table. During
+ mips_elf_size_dynamic_sections, this value is 1. Afterward, the
+ section symbols are added and the count is higher. */
static boolean
-mips_elf_sort_hash_table (info)
+mips_elf_sort_hash_table (info, max_local)
struct bfd_link_info *info;
+ unsigned long max_local;
{
struct mips_elf_hash_sort_data hsd;
struct mips_got_info *g;
hsd.low = NULL;
hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount;
- hsd.max_non_got_dynindx = 1;
+ hsd.max_non_got_dynindx = max_local;
mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table *)
elf_hash_table (info)),
mips_elf_sort_hash_table_f,
/* There shoud have been enough room in the symbol table to
accomodate both the GOT and non-GOT symbols. */
- BFD_ASSERT (hsd.min_got_dynindx == hsd.max_non_got_dynindx);
+ BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
/* Now we know which dynamic symbol has the lowest dynamic symbol
table index in the GOT. */
struct mips_got_info *g;
bfd_byte *entry;
bfd_byte *last_entry;
- bfd_vma index;
+ bfd_vma index = 0;
bfd_vma address;
g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
for value. Return the index into the GOT for this entry. */
static bfd_vma
-mips_elf_got16_entry (abfd, info, value)
+mips_elf_got16_entry (abfd, info, value, external)
bfd *abfd;
struct bfd_link_info *info;
bfd_vma value;
+ boolean external;
{
asection *sgot;
struct mips_got_info *g;
bfd_byte *entry;
bfd_byte *last_entry;
- bfd_vma index;
+ bfd_vma index = 0;
bfd_vma address;
- value &= 0xffff0000;
+ if (! external)
+ {
+ /* Although the ABI says that it is "the high-order 16 bits" that we
+ want, it is really the %high value. The complete value is
+ calculated with a `addiu' of a LO16 relocation, just as with a
+ HI16/LO16 pair. */
+ value = mips_elf_high (value) << 16;
+ }
+
g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
/* Look to see if we already have an appropriate entry. */
entry += MIPS_ELF_GOT_SIZE (abfd))
{
address = MIPS_ELF_GET_WORD (abfd, entry);
- if ((address & 0xffff0000) == value)
+ if (address == value)
{
- /* This entry has the right high-order 16 bits. */
- index = MIPS_ELF_GOT_SIZE (abfd) * (entry - sgot->contents);
+ /* This entry has the right high-order 16 bits, and the low-order
+ 16 bits are set to zero. */
+ index = entry - sgot->contents;
break;
}
}
return index;
}
-/* Sets *ADDENDP to the addend for the first R_MIPS_LO16 relocation
- found, beginning with RELOCATION. RELEND is one-past-the-end of
- the relocation table. */
+/* Returns the first relocation of type r_type found, beginning with
+ RELOCATION. RELEND is one-past-the-end of the relocation table. */
-static boolean
-mips_elf_next_lo16_addend (relocation, relend, addendp)
+static const Elf_Internal_Rela *
+mips_elf_next_relocation (r_type, relocation, relend)
+ unsigned int r_type;
const Elf_Internal_Rela *relocation;
const Elf_Internal_Rela *relend;
- bfd_vma *addendp;
{
/* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
immediately following. However, for the IRIX6 ABI, the next
relocation may be a composed relocation consisting of several
relocations for the same address. In that case, the R_MIPS_LO16
- relo!scation may occur as one of these. We permit a similar
+ relocation may occur as one of these. We permit a similar
extension in general, as that is useful for GCC. */
while (relocation < relend)
{
- if (ELF32_R_TYPE (relocation->r_info) == R_MIPS_LO16)
- {
- *addendp = relocation->r_addend;
- return true;
- }
+ if (ELF32_R_TYPE (relocation->r_info) == r_type)
+ return relocation;
++relocation;
}
/* We didn't find it. */
- return false;
+ bfd_set_error (bfd_error_bad_value);
+ return NULL;
}
-/* Create a rel.dyn relocation for the dynamic linker to resolve. The
- relocatin is against the symbol with the dynamic symbol table index
- DYNINDX. REL is the original relocation, which is now being made
- dynamic. */
+/* Create a rel.dyn relocation for the dynamic linker to resolve. REL
+ is the original relocation, which is now being transformed into a
+ dynamic relocation. The ADDENDP is adjusted if necessary; the
+ caller should store the result in place of the original addend. */
-static unsigned int
-mips_elf_create_dynamic_relocation (output_bfd, info, rel, dynindx,
- addend, input_section)
+static boolean
+mips_elf_create_dynamic_relocation (output_bfd, info, rel, h, sec,
+ symbol, addendp, input_section)
bfd *output_bfd;
struct bfd_link_info *info;
const Elf_Internal_Rela *rel;
- long dynindx;
- bfd_vma addend;
+ struct mips_elf_link_hash_entry *h;
+ asection *sec;
+ bfd_vma symbol;
+ bfd_vma *addendp;
asection *input_section;
{
Elf_Internal_Rel outrel;
= bfd_get_section_by_name (dynobj,
MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd));
BFD_ASSERT (sreloc != NULL);
+ BFD_ASSERT (sreloc->contents != NULL);
skip = false;
- /* The symbol for the relocation is the same as it was for the
- original relocation. */
- outrel.r_info = ELF32_R_INFO (dynindx, R_MIPS_REL32);
-
- /* The offset for the dynamic relocation is the same as for the
- original relocation, adjusted by the offset at which the original
- section is output. */
+ /* We begin by assuming that the offset for the dynamic relocation
+ is the same as for the original relocation. We'll adjust this
+ later to reflect the correct output offsets. */
if (elf_section_data (input_section)->stab_info == NULL)
outrel.r_offset = rel->r_offset;
else
{
- bfd_vma off;
-
- off = (_bfd_stab_section_offset
- (output_bfd, &elf_hash_table (info)->stab_info,
- input_section,
- &elf_section_data (input_section)->stab_info,
- rel->r_offset));
- if (off == (bfd_vma) -1)
+ /* Except that in a stab section things are more complex.
+ Because we compress stab information, the offset given in the
+ relocation may not be the one we want; we must let the stabs
+ machinery tell us the offset. */
+ outrel.r_offset
+ = (_bfd_stab_section_offset
+ (output_bfd, &elf_hash_table (info)->stab_info,
+ input_section,
+ &elf_section_data (input_section)->stab_info,
+ rel->r_offset));
+ /* If we didn't need the relocation at all, this value will be
+ -1. */
+ if (outrel.r_offset == (bfd_vma) -1)
skip = true;
- outrel.r_offset = off;
}
- outrel.r_offset += (input_section->output_section->vma
- + input_section->output_offset);
- /* If we've decided to skip this relocation, just output an emtpy
- record. */
+ /* If we've decided to skip this relocation, just output an empty
+ record. Note that R_MIPS_NONE == 0, so that this call to memset
+ is a way of setting R_TYPE to R_MIPS_NONE. */
if (skip)
memset (&outrel, 0, sizeof (outrel));
+ else
+ {
+ long indx;
+ bfd_vma section_offset;
+
+ /* We must now calculate the dynamic symbol table index to use
+ in the relocation. */
+ if (h != NULL
+ && (! info->symbolic || (h->root.elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_REGULAR) == 0))
+ {
+ indx = h->root.dynindx;
+ /* h->root.dynindx may be -1 if this symbol was marked to
+ become local. */
+ if (indx == -1)
+ indx = 0;
+ }
+ else
+ {
+ if (sec != NULL && bfd_is_abs_section (sec))
+ indx = 0;
+ else if (sec == NULL || sec->owner == NULL)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+ else
+ {
+ indx = elf_section_data (sec->output_section)->dynindx;
+ if (indx == 0)
+ abort ();
+ }
+
+ /* Figure out how far the target of the relocation is from
+ the beginning of its section. */
+ section_offset = symbol - sec->output_section->vma;
+ /* The relocation we're building is section-relative.
+ Therefore, the original addend must be adjusted by the
+ section offset. */
+ *addendp += symbol - sec->output_section->vma;
+ /* Now, the relocation is just against the section. */
+ symbol = sec->output_section->vma;
+ }
+
+ /* If the relocation was previously an absolute relocation, we
+ must adjust it by the value we give it in the dynamic symbol
+ table. */
+ if (r_type != R_MIPS_REL32)
+ *addendp += symbol;
+
+ /* The relocation is always an REL32 relocation because we don't
+ know where the shared library will wind up at load-time. */
+ outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
+
+ /* Adjust the output offset of the relocation to reference the
+ correct location in the output file. */
+ outrel.r_offset += (input_section->output_section->vma
+ + input_section->output_offset);
+ }
+ /* Put the relocation back out. We have to use the special
+ relocation outputter in the 64-bit case since the 64-bit
+ relocation format is non-standard. */
if (ABI_64_P (output_bfd))
{
(*get_elf_backend_data (output_bfd)->s->swap_reloc_out)
(((Elf32_External_Rel *)
sreloc->contents)
+ sreloc->reloc_count));
+
+ /* Record the index of the first relocation referencing H. This
+ information is later emitted in the .msym section. */
+ if (h != NULL
+ && (h->min_dyn_reloc_index == 0
+ || sreloc->reloc_count < h->min_dyn_reloc_index))
+ h->min_dyn_reloc_index = sreloc->reloc_count;
+
+ /* We've now added another relocation. */
++sreloc->reloc_count;
/* Make sure the output section is writable. The dynamic linker
else
mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
mips_elf_set_cr_dist2to (cptrel, 0);
- cptrel.konst = addend;
+ cptrel.konst = *addendp;
cr = (scpt->contents
+ sizeof (Elf32_External_compact_rel));
}
}
- return sreloc->reloc_count - 1;
+ return true;
}
/* Calculate the value produced by the RELOCATION (which comes from
RELOCATION; RELOCATION->R_ADDEND is ignored.
The result of the relocation calculation is stored in VALUEP.
+ REQUIRE_JALXP indicates whether or not the opcode used with this
+ relocation must be JALX.
This function returns bfd_reloc_continue if the caller need take no
further action regarding this relocation, bfd_reloc_notsupported if
local_syms,
local_sections,
valuep,
- namep)
+ namep,
+ require_jalxp)
bfd *abfd;
bfd *input_bfd;
asection *input_section;
asection **local_sections;
bfd_vma *valuep;
const char **namep;
+ boolean *require_jalxp;
{
/* The eventual value we will return. */
bfd_vma value;
/* True if overflow occurred during the calculation of the
relocation value. */
boolean overflowed_p;
+ /* True if this relocation refers to a MIPS16 function. */
+ boolean target_is_16_bit_code_p = false;
/* Parse the relocation. */
r_symndx = ELF32_R_SYM (relocation->r_info);
/* Assume that there will be no overflow. */
overflowed_p = false;
- /* Figure out whether or not the symbol is local. */
+ /* Figure out whether or not the symbol is local, and get the offset
+ used in the array of hash table entries. */
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
- if (elf_bad_symtab (input_bfd))
+ local_p = mips_elf_local_relocation_p (input_bfd, relocation,
+ local_sections, false);
+ if (! elf_bad_symtab (input_bfd))
+ extsymoff = symtab_hdr->sh_info;
+ else
{
/* The symbol table does not follow the rule that local symbols
must come before globals. */
extsymoff = 0;
- local_p = local_sections[r_symndx] != NULL;
- }
- else
- {
- extsymoff = symtab_hdr->sh_info;
- local_p = r_symndx < extsymoff;
}
/* Figure out the value of the symbol. */
sym->st_name);
if (*namep == '\0')
*namep = bfd_section_name (input_bfd, sec);
+
+ target_is_16_bit_code_p = (sym->st_other == STO_MIPS16);
}
else
{
h = ((struct mips_elf_link_hash_entry *)
elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
/* Find the real hash-table entry for this symbol. */
- while (h->root.type == bfd_link_hash_indirect
- || h->root.type == bfd_link_hash_warning)
+ while (h->root.root.type == bfd_link_hash_indirect
+ || h->root.root.type == bfd_link_hash_warning)
h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
/* Record the name of this symbol, for our caller. */
gp_disp_p = true;
}
-
- /* If this symbol is defined, calculate its address. */
- if ((h->root.root.type == bfd_link_hash_defined
- || h->root.root.type == bfd_link_hash_defweak)
- && h->root.root.u.def.section)
+ /* If this symbol is defined, calculate its address. Note that
+ _gp_disp is a magic symbol, always implicitly defined by the
+ linker, so it's inappropriate to check to see whether or not
+ its defined. */
+ else if ((h->root.root.type == bfd_link_hash_defined
+ || h->root.root.type == bfd_link_hash_defweak)
+ && h->root.root.u.def.section)
{
sec = h->root.root.u.def.section;
if (sec->output_section)
else
symbol = h->root.root.u.def.value;
}
+ else if (h->root.root.type == bfd_link_hash_undefweak)
+ /* We allow relocations against undefined weak symbols, giving
+ it the value zero, so that you can undefined weak functions
+ and check to see if they exist by looking at their
+ addresses. */
+ symbol = 0;
+ else if (info->shared && !info->symbolic && !info->no_undefined
+ && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
+ symbol = 0;
+ else if (strcmp (h->root.root.root.string, "_DYNAMIC_LINK") == 0 ||
+ strcmp (h->root.root.root.string, "_DYNAMIC_LINKING") == 0)
+ {
+ /* If this is a dynamic link, we should have created a
+ _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
+ in in mips_elf_create_dynamic_sections.
+ Otherwise, we should define the symbol with a value of 0.
+ FIXME: It should probably get into the symbol table
+ somehow as well. */
+ BFD_ASSERT (! info->shared);
+ BFD_ASSERT (bfd_get_section_by_name (abfd, ".dynamic") == NULL);
+ symbol = 0;
+ }
else
{
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.root.string, input_bfd,
- input_section, relocation->r_offset);
- return bfd_reloc_undefined;
+ if (! ((*info->callbacks->undefined_symbol)
+ (info, h->root.root.root.string, input_bfd,
+ input_section, relocation->r_offset,
+ (!info->shared || info->no_undefined
+ || ELF_ST_VISIBILITY (h->root.other)))))
+ return bfd_reloc_undefined;
+ symbol = 0;
+ }
+
+ target_is_16_bit_code_p = (h->root.other == STO_MIPS16);
+ }
+
+ /* If this is a 32-bit call to a 16-bit function with a stub, we
+ need to redirect the call to the stub, unless we're already *in*
+ a stub. */
+ if (r_type != R_MIPS16_26 && !info->relocateable
+ && ((h != NULL && h->fn_stub != NULL)
+ || (local_p && elf_tdata (input_bfd)->local_stubs != NULL
+ && elf_tdata (input_bfd)->local_stubs[r_symndx] != NULL))
+ && !mips_elf_stub_section_p (input_bfd, input_section))
+ {
+ /* This is a 32-bit call to a 16-bit function. We should
+ have already noticed that we were going to need the
+ stub. */
+ if (local_p)
+ sec = elf_tdata (input_bfd)->local_stubs[r_symndx];
+ else
+ {
+ BFD_ASSERT (h->need_fn_stub);
+ sec = h->fn_stub;
+ }
+
+ symbol = sec->output_section->vma + sec->output_offset;
+ }
+ /* If this is a 16-bit call to a 32-bit function with a stub, we
+ need to redirect the call to the stub. */
+ else if (r_type == R_MIPS16_26 && !info->relocateable
+ && h != NULL
+ && (h->call_stub != NULL || h->call_fp_stub != NULL)
+ && !target_is_16_bit_code_p)
+ {
+ /* If both call_stub and call_fp_stub are defined, we can figure
+ out which one to use by seeing which one appears in the input
+ file. */
+ if (h->call_stub != NULL && h->call_fp_stub != NULL)
+ {
+ asection *o;
+
+ sec = NULL;
+ for (o = input_bfd->sections; o != NULL; o = o->next)
+ {
+ if (strncmp (bfd_get_section_name (input_bfd, o),
+ CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
+ {
+ sec = h->call_fp_stub;
+ break;
+ }
+ }
+ if (sec == NULL)
+ sec = h->call_stub;
}
+ else if (h->call_stub != NULL)
+ sec = h->call_stub;
+ else
+ sec = h->call_fp_stub;
+
+ BFD_ASSERT (sec->_raw_size > 0);
+ symbol = sec->output_section->vma + sec->output_offset;
}
+ /* Calls from 16-bit code to 32-bit code and vice versa require the
+ special jalx instruction. */
+ *require_jalxp = (!info->relocateable
+ && ((r_type == R_MIPS16_26) != target_is_16_bit_code_p));
+
+ local_p = mips_elf_local_relocation_p (input_bfd, relocation,
+ local_sections, true);
+
/* If we haven't already determined the GOT offset, or the GP value,
and we're going to need it, get it now. */
switch (r_type)
{
case R_MIPS_CALL16:
+ case R_MIPS_GOT16:
case R_MIPS_GOT_DISP:
case R_MIPS_GOT_HI16:
case R_MIPS_CALL_HI16:
case R_MIPS_GOT_LO16:
case R_MIPS_CALL_LO16:
/* Find the index into the GOT where this value is located. */
- if (h)
+ if (!local_p)
{
BFD_ASSERT (addend == 0);
g = mips_elf_global_got_index
(elf_hash_table (info)->dynobj,
(struct elf_link_hash_entry*) h);
+ if (! elf_hash_table(info)->dynamic_sections_created
+ || (info->shared
+ && (info->symbolic || h->root.dynindx == -1)
+ && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+ {
+ /* This is a static link or a -Bsymbolic link. The
+ symbol is defined locally, or was forced to be local.
+ We must initialize this entry in the GOT. */
+ asection *sgot = mips_elf_got_section(elf_hash_table
+ (info)->dynobj);
+ MIPS_ELF_PUT_WORD (elf_hash_table (info)->dynobj,
+ symbol + addend, sgot->contents + g);
+ }
}
+ else if (r_type == R_MIPS_GOT16)
+ /* There's no need to create a local GOT entry here; the
+ calculation for a local GOT16 entry does not involve G. */
+ break;
else
{
g = mips_elf_local_got_index (abfd, info, symbol + addend);
case R_MIPS_LO16:
case R_MIPS_GPREL16:
case R_MIPS_GPREL32:
+ case R_MIPS_LITERAL:
gp0 = _bfd_get_gp_value (input_bfd);
gp = _bfd_get_gp_value (abfd);
break;
case R_MIPS_32:
case R_MIPS_REL32:
- /* If we're creating a shared library, or this relocation is
- against a symbol in a shared library, then we can't know
- where the symbol will end up. So, we create a relocation
- record in the output, and leave the job up to the dynamic
- linker. */
- if (info->shared || !sec->output_section)
+ case R_MIPS_64:
+ if ((info->shared
+ || (elf_hash_table (info)->dynamic_sections_created
+ && h != NULL
+ && ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
+ != 0)))
+ && (input_section->flags & SEC_ALLOC) != 0)
{
- unsigned int reloc_index;
-
- BFD_ASSERT (h != NULL);
- reloc_index
- = mips_elf_create_dynamic_relocation (abfd,
+ /* If we're creating a shared library, or this relocation is
+ against a symbol in a shared library, then we can't know
+ where the symbol will end up. So, we create a relocation
+ record in the output, and leave the job up to the dynamic
+ linker. */
+ value = addend;
+ if (!mips_elf_create_dynamic_relocation (abfd,
info,
relocation,
- h->root.dynindx,
- addend,
- input_section);
- if (h->min_dyn_reloc_index == 0
- || reloc_index < h->min_dyn_reloc_index)
- h->min_dyn_reloc_index = reloc_index;
- value = symbol + addend;
+ h,
+ sec,
+ symbol,
+ &value,
+ input_section))
+ return false;
}
else
{
- if (r_type == R_MIPS_32)
+ if (r_type != R_MIPS_REL32)
value = symbol + addend;
else
value = addend;
value &= howto->dst_mask;
break;
+ case R_MIPS_PC32:
+ case R_MIPS_PC64:
+ case R_MIPS_GNU_REL_LO16:
+ value = symbol + addend - p;
+ value &= howto->dst_mask;
+ break;
+
+ case R_MIPS_GNU_REL16_S2:
+ value = symbol + mips_elf_sign_extend (addend << 2, 18) - p;
+ overflowed_p = mips_elf_overflow_p (value, 18);
+ value = (value >> 2) & howto->dst_mask;
+ break;
+
+ case R_MIPS_GNU_REL_HI16:
+ value = mips_elf_high (addend + symbol - p);
+ value &= howto->dst_mask;
+ break;
+
+ case R_MIPS16_26:
+ /* The calculation for R_MIPS_26 is just the same as for an
+ R_MIPS_26. It's only the storage of the relocated field into
+ the output file that's different. That's handled in
+ mips_elf_perform_relocation. So, we just fall through to the
+ R_MIPS_26 case here. */
case R_MIPS_26:
if (local_p)
value = (((addend << 2) | (p & 0xf0000000)) + symbol) >> 2;
else
{
value = addend + gp - p + 4;
- overflowed_p = mips_elf_overflow_p (value, 16);
+ /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
+ for overflow. But, on, say, Irix 5, relocations against
+ _gp_disp are normally generated from the .cpload
+ pseudo-op. It generates code that normally looks like
+ this:
+
+ lui $gp,%hi(_gp_disp)
+ addiu $gp,$gp,%lo(_gp_disp)
+ addu $gp,$gp,$t9
+
+ Here $t9 holds the address of the function being called,
+ as required by the MIPS ELF ABI. The R_MIPS_LO16
+ relocation can easily overflow in this situation, but the
+ R_MIPS_HI16 relocation will handle the overflow.
+ Therefore, we consider this a bug in the MIPS ABI, and do
+ not check for overflow here. */
}
break;
/* Fall through. */
+ case R_MIPS16_GPREL:
+ /* The R_MIPS16_GPREL performs the same calculation as
+ R_MIPS_GPREL16, but stores the relocated bits in a different
+ order. We don't need to do anything special here; the
+ differences are handled in mips_elf_perform_relocation. */
case R_MIPS_GPREL16:
if (local_p)
value = mips_elf_sign_extend (addend, 16) + symbol + gp0 - gp;
case R_MIPS_GOT16:
if (local_p)
{
- value = mips_elf_got16_entry (abfd, info, symbol + addend);
+ boolean forced;
+
+ /* The special case is when the symbol is forced to be local. We
+ need the full address in the GOT since no R_MIPS_LO16 relocation
+ follows. */
+ forced = ! mips_elf_local_relocation_p (input_bfd, relocation,
+ local_sections, false);
+ value = mips_elf_got16_entry (abfd, info, symbol + addend, forced);
if (value == (bfd_vma) -1)
return false;
value
case R_MIPS_PC16:
value = mips_elf_sign_extend (addend, 16) + symbol - p;
+ value = (bfd_vma) ((bfd_signed_vma) value / 4);
overflowed_p = mips_elf_overflow_p (value, 16);
break;
value = g & howto->dst_mask;
break;
- case R_MIPS_64:
- value = (symbol + addend) & howto->dst_mask;
- break;
-
case R_MIPS_GOT_PAGE:
value = mips_elf_got_page (abfd, info, symbol + addend, NULL);
if (value == (bfd_vma) -1)
/* We don't do anything with these at present. */
return bfd_reloc_continue;
- case R_MIPS16_26:
- case R_MIPS16_GPREL:
- /* These relocations, used for MIPS16, are not clearly
- documented anywhere. What do they do? */
- return bfd_reloc_notsupported;
-
default:
/* An unrecognized relocation type. */
return bfd_reloc_notsupported;
bfd_vma x;
bfd_byte *location = contents + relocation->r_offset;
- switch (bfd_get_reloc_size (howto))
- {
- case 0:
- x = 0;
- break;
-
- case 1:
- x = bfd_get_8 (input_bfd, location);
- break;
-
- case 2:
- x = bfd_get_16 (input_bfd, location);
- break;
-
- case 4:
- x = bfd_get_32 (input_bfd, location);
- break;
-
- case 8:
-#ifdef BFD64
- x = bfd_get_64 (input_bfd, location);
-#else
- abort ();
-#endif
- break;
+ /* Obtain the bytes. */
+ x = bfd_get (8 * bfd_get_reloc_size (howto), input_bfd, location);
- default:
- abort ();
- break;
- }
+ if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26
+ || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL)
+ && bfd_little_endian (input_bfd))
+ /* The two 16-bit words will be reversed on a little-endian
+ system. See mips_elf_perform_relocation for more details. */
+ x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
return x;
}
/* It has been determined that the result of the RELOCATION is the
VALUE. Use HOWTO to place VALUE into the output file at the
appropriate position. The SECTION is the section to which the
- relocatin applies.
+ relocation applies. If REQUIRE_JALX is true, then the opcode used
+ for the relocation must be either JAL or JALX, and it is
+ unconditionally converted to JALX.
Returns false if anything goes wrong. */
-static void
-mips_elf_perform_relocation (howto, relocation, value, input_bfd, contents)
+static boolean
+mips_elf_perform_relocation (info, howto, relocation, value,
+ input_bfd, input_section,
+ contents, require_jalx)
+ struct bfd_link_info *info;
reloc_howto_type *howto;
const Elf_Internal_Rela *relocation;
bfd_vma value;
bfd *input_bfd;
+ asection *input_section;
bfd_byte *contents;
+ boolean require_jalx;
{
bfd_vma x;
- bfd_byte *location = contents + relocation->r_offset;
+ bfd_byte *location;
+ int r_type = ELF32_R_TYPE (relocation->r_info);
+
+ /* Figure out where the relocation is occurring. */
+ location = contents + relocation->r_offset;
/* Obtain the current value. */
x = mips_elf_obtain_contents (howto, relocation, input_bfd, contents);
/* Clear the field we are setting. */
x &= ~howto->dst_mask;
+ /* If this is the R_MIPS16_26 relocation, we must store the
+ value in a funny way. */
+ if (r_type == R_MIPS16_26)
+ {
+ /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
+ Most mips16 instructions are 16 bits, but these instructions
+ are 32 bits.
+
+ The format of these instructions is:
+
+ +--------------+--------------------------------+
+ ! JALX ! X! Imm 20:16 ! Imm 25:21 !
+ +--------------+--------------------------------+
+ ! Immediate 15:0 !
+ +-----------------------------------------------+
+
+ JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
+ Note that the immediate value in the first word is swapped.
+
+ When producing a relocateable object file, R_MIPS16_26 is
+ handled mostly like R_MIPS_26. In particular, the addend is
+ stored as a straight 26-bit value in a 32-bit instruction.
+ (gas makes life simpler for itself by never adjusting a
+ R_MIPS16_26 reloc to be against a section, so the addend is
+ always zero). However, the 32 bit instruction is stored as 2
+ 16-bit values, rather than a single 32-bit value. In a
+ big-endian file, the result is the same; in a little-endian
+ file, the two 16-bit halves of the 32 bit value are swapped.
+ This is so that a disassembler can recognize the jal
+ instruction.
+
+ When doing a final link, R_MIPS16_26 is treated as a 32 bit
+ instruction stored as two 16-bit values. The addend A is the
+ contents of the targ26 field. The calculation is the same as
+ R_MIPS_26. When storing the calculated value, reorder the
+ immediate value as shown above, and don't forget to store the
+ value as two 16-bit values.
+
+ To put it in MIPS ABI terms, the relocation field is T-targ26-16,
+ defined as
+
+ big-endian:
+ +--------+----------------------+
+ | | |
+ | | targ26-16 |
+ |31 26|25 0|
+ +--------+----------------------+
+
+ little-endian:
+ +----------+------+-------------+
+ | | | |
+ | sub1 | | sub2 |
+ |0 9|10 15|16 31|
+ +----------+--------------------+
+ where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
+ ((sub1 << 16) | sub2)).
+
+ When producing a relocateable object file, the calculation is
+ (((A < 2) | (P & 0xf0000000) + S) >> 2)
+ When producing a fully linked file, the calculation is
+ let R = (((A < 2) | (P & 0xf0000000) + S) >> 2)
+ ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
+
+ if (!info->relocateable)
+ /* Shuffle the bits according to the formula above. */
+ value = (((value & 0x1f0000) << 5)
+ | ((value & 0x3e00000) >> 5)
+ | (value & 0xffff));
+
+ }
+ else if (r_type == R_MIPS16_GPREL)
+ {
+ /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
+ mode. A typical instruction will have a format like this:
+
+ +--------------+--------------------------------+
+ ! EXTEND ! Imm 10:5 ! Imm 15:11 !
+ +--------------+--------------------------------+
+ ! Major ! rx ! ry ! Imm 4:0 !
+ +--------------+--------------------------------+
+
+ EXTEND is the five bit value 11110. Major is the instruction
+ opcode.
+
+ This is handled exactly like R_MIPS_GPREL16, except that the
+ addend is retrieved and stored as shown in this diagram; that
+ is, the Imm fields above replace the V-rel16 field.
+
+ All we need to do here is shuffle the bits appropriately. As
+ above, the two 16-bit halves must be swapped on a
+ little-endian system. */
+ value = (((value & 0x7e0) << 16)
+ | ((value & 0xf800) << 5)
+ | (value & 0x1f));
+ }
+
/* Set the field. */
x |= (value & howto->dst_mask);
- /* Put the value into the output. */
- switch (bfd_get_reloc_size (howto))
+ /* If required, turn JAL into JALX. */
+ if (require_jalx)
{
- case 0:
- x = 0;
- break;
+ boolean ok;
+ bfd_vma opcode = x >> 26;
+ bfd_vma jalx_opcode;
- case 1:
- bfd_put_8 (input_bfd, x, location);
- break;
+ /* Check to see if the opcode is already JAL or JALX. */
+ if (r_type == R_MIPS16_26)
+ {
+ ok = ((opcode == 0x6) || (opcode == 0x7));
+ jalx_opcode = 0x7;
+ }
+ else
+ {
+ ok = ((opcode == 0x3) || (opcode == 0x1d));
+ jalx_opcode = 0x1d;
+ }
- case 2:
- bfd_put_16 (input_bfd, x, location);
- break;
+ /* If the opcode is not JAL or JALX, there's a problem. */
+ if (!ok)
+ {
+ (*_bfd_error_handler)
+ (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
+ bfd_get_filename (input_bfd),
+ input_section->name,
+ (unsigned long) relocation->r_offset);
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
- case 4:
- bfd_put_32 (input_bfd, x, location);
- break;
+ /* Make this the JALX opcode. */
+ x = (x & ~(0x3f << 26)) | (jalx_opcode << 26);
+ }
- case 8:
-#ifdef BFD64
- bfd_put_64 (input_bfd, x, location);
-#else
- abort ();
-#endif
- break;
+ /* Swap the high- and low-order 16 bits on little-endian systems
+ when doing a MIPS16 relocation. */
+ if ((r_type == R_MIPS16_GPREL || r_type == R_MIPS16_26)
+ && bfd_little_endian (input_bfd))
+ x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
+
+ /* Put the value into the output. */
+ bfd_put (8 * bfd_get_reloc_size (howto), input_bfd, x, location);
+ return true;
+}
- default:
- abort ();
- break;
- }
+/* Returns true if SECTION is a MIPS16 stub section. */
+
+static boolean
+mips_elf_stub_section_p (abfd, section)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ asection *section;
+{
+ const char *name = bfd_get_section_name (abfd, section);
+
+ return (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0
+ || strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
+ || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0);
}
/* Relocate a MIPS ELF section. */
Elf_Internal_Sym *local_syms;
asection **local_sections;
{
- const Elf_Internal_Rela *rel;
+ Elf_Internal_Rela *rel;
const Elf_Internal_Rela *relend;
- bfd_vma addend;
- bfd_vma last_hi16_addend;
+ bfd_vma addend = 0;
boolean use_saved_addend_p = false;
- boolean last_hi16_addend_valid_p = false;
struct elf_backend_data *bed;
bed = get_elf_backend_data (output_bfd);
const char *name;
bfd_vma value;
reloc_howto_type *howto;
+ boolean require_jalx;
+ /* True if the relocation is a RELA relocation, rather than a
+ REL relocation. */
+ boolean rela_relocation_p = true;
+ int r_type = ELF32_R_TYPE (rel->r_info);
/* Find the relocation howto for this relocation. */
- howto = elf_mips_howto_table + ELF32_R_TYPE (rel->r_info);
+ if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
+ {
+ /* Some 32-bit code uses R_MIPS_64. In particular, people use
+ 64-bit code, but make sure all their addresses are in the
+ lowermost or uppermost 32-bit section of the 64-bit address
+ space. Thus, when they use an R_MIPS_64 they mean what is
+ usually meant by R_MIPS_32, with the exception that the
+ stored value is sign-extended to 64 bits. */
+ howto = elf_mips_howto_table + R_MIPS_32;
+
+ /* On big-endian systems, we need to lie about the position
+ of the reloc. */
+ if (bfd_big_endian (input_bfd))
+ rel->r_offset += 4;
+ }
+ else
+ howto = mips_rtype_to_howto (r_type);
if (!use_saved_addend_p)
{
this is, we depend on the fact that the INPUT_SECTION's
REL_HDR is read before its REL_HDR2. */
rel_hdr = &elf_section_data (input_section)->rel_hdr;
- if (rel - relocs
+ if ((size_t) (rel - relocs)
>= (rel_hdr->sh_size / rel_hdr->sh_entsize
* bed->s->int_rels_per_ext_rel))
rel_hdr = elf_section_data (input_section)->rel_hdr2;
if (rel_hdr->sh_entsize == MIPS_ELF_REL_SIZE (input_bfd))
{
- int r_type = ELF32_R_TYPE (rel->r_info);
+ /* Note that this is a REL relocation. */
+ rela_relocation_p = false;
+ /* Get the addend, which is stored in the input file. */
addend = mips_elf_obtain_contents (howto,
rel,
input_bfd,
/* For some kinds of relocations, the ADDEND is a
combination of the addend stored in two different
relocations. */
- if (r_type == R_MIPS_HI16 || r_type == R_MIPS_GOT16)
+ if (r_type == R_MIPS_HI16
+ || r_type == R_MIPS_GNU_REL_HI16
+ || (r_type == R_MIPS_GOT16
+ && mips_elf_local_relocation_p (input_bfd, rel,
+ local_sections, false)))
{
- /* Scan ahead to find a matching R_MIPS_LO16
- relocation. */
bfd_vma l;
-
- if (!mips_elf_next_lo16_addend (rel, relend, &l))
+ const Elf_Internal_Rela *lo16_relocation;
+ reloc_howto_type *lo16_howto;
+ int lo;
+
+ /* The combined value is the sum of the HI16 addend,
+ left-shifted by sixteen bits, and the LO16
+ addend, sign extended. (Usually, the code does
+ a `lui' of the HI16 value, and then an `addiu' of
+ the LO16 value.)
+
+ Scan ahead to find a matching LO16 relocation. */
+ if (r_type == R_MIPS_GNU_REL_HI16)
+ lo = R_MIPS_GNU_REL_LO16;
+ else
+ lo = R_MIPS_LO16;
+ lo16_relocation
+ = mips_elf_next_relocation (lo, rel, relend);
+ if (lo16_relocation == NULL)
return false;
- /* Save the high-order bit for later. When we
- encounter the R_MIPS_LO16 relocation we will need
- them again. */
+ /* Obtain the addend kept there. */
+ lo16_howto = mips_rtype_to_howto (lo);
+ l = mips_elf_obtain_contents (lo16_howto,
+ lo16_relocation,
+ input_bfd, contents);
+ l &= lo16_howto->src_mask;
+ l = mips_elf_sign_extend (l, 16);
+
addend <<= 16;
- last_hi16_addend = addend;
- last_hi16_addend_valid_p = true;
/* Compute the combined addend. */
- addend |= l;
+ addend += l;
}
- else if (r_type == R_MIPS_LO16)
+ else if (r_type == R_MIPS16_GPREL)
{
- /* Used the saved HI16 addend. */
- if (!last_hi16_addend_valid_p)
- return false;
- addend |= last_hi16_addend;
+ /* The addend is scrambled in the object file. See
+ mips_elf_perform_relocation for details on the
+ format. */
+ addend = (((addend & 0x1f0000) >> 5)
+ | ((addend & 0x7e00000) >> 16)
+ | (addend & 0x1f));
}
}
else
addend = rel->r_addend;
}
+ if (info->relocateable)
+ {
+ Elf_Internal_Sym *sym;
+ unsigned long r_symndx;
+
+ if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)
+ && bfd_big_endian (input_bfd))
+ rel->r_offset -= 4;
+
+ /* Since we're just relocating, all we need to do is copy
+ the relocations back out to the object file, unless
+ they're against a section symbol, in which case we need
+ to adjust by the section offset, or unless they're GP
+ relative in which case we need to adjust by the amount
+ that we're adjusting GP in this relocateable object. */
+
+ if (!mips_elf_local_relocation_p (input_bfd, rel, local_sections,
+ false))
+ /* There's nothing to do for non-local relocations. */
+ continue;
+
+ if (r_type == R_MIPS16_GPREL
+ || r_type == R_MIPS_GPREL16
+ || r_type == R_MIPS_GPREL32
+ || r_type == R_MIPS_LITERAL)
+ addend -= (_bfd_get_gp_value (output_bfd)
+ - _bfd_get_gp_value (input_bfd));
+ else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
+ || r_type == R_MIPS_GNU_REL16_S2)
+ /* The addend is stored without its two least
+ significant bits (which are always zero.) In a
+ non-relocateable link, calculate_relocation will do
+ this shift; here, we must do it ourselves. */
+ addend <<= 2;
+
+ r_symndx = ELF32_R_SYM (rel->r_info);
+ sym = local_syms + r_symndx;
+ if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
+ /* Adjust the addend appropriately. */
+ addend += local_sections[r_symndx]->output_offset;
+
+ /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
+ then we only want to write out the high-order 16 bits.
+ The subsequent R_MIPS_LO16 will handle the low-order bits. */
+ if (r_type == R_MIPS_HI16 || r_type == R_MIPS_GOT16
+ || r_type == R_MIPS_GNU_REL_HI16)
+ addend = mips_elf_high (addend);
+ /* If the relocation is for an R_MIPS_26 relocation, then
+ the two low-order bits are not stored in the object file;
+ they are implicitly zero. */
+ else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
+ || r_type == R_MIPS_GNU_REL16_S2)
+ addend >>= 2;
+
+ if (rela_relocation_p)
+ /* If this is a RELA relocation, just update the addend.
+ We have to cast away constness for REL. */
+ rel->r_addend = addend;
+ else
+ {
+ /* Otherwise, we have to write the value back out. Note
+ that we use the source mask, rather than the
+ destination mask because the place to which we are
+ writing will be source of the addend in the final
+ link. */
+ addend &= howto->src_mask;
+
+ if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
+ /* See the comment above about using R_MIPS_64 in the 32-bit
+ ABI. Here, we need to update the addend. It would be
+ possible to get away with just using the R_MIPS_32 reloc
+ but for endianness. */
+ {
+ bfd_vma sign_bits;
+ bfd_vma low_bits;
+ bfd_vma high_bits;
+
+ if (addend & ((bfd_vma) 1 << 31))
+ sign_bits = ((bfd_vma) 1 << 32) - 1;
+ else
+ sign_bits = 0;
+
+ /* If we don't know that we have a 64-bit type,
+ do two separate stores. */
+ if (bfd_big_endian (input_bfd))
+ {
+ /* Store the sign-bits (which are most significant)
+ first. */
+ low_bits = sign_bits;
+ high_bits = addend;
+ }
+ else
+ {
+ low_bits = addend;
+ high_bits = sign_bits;
+ }
+ bfd_put_32 (input_bfd, low_bits,
+ contents + rel->r_offset);
+ bfd_put_32 (input_bfd, high_bits,
+ contents + rel->r_offset + 4);
+ continue;
+ }
+
+ if (!mips_elf_perform_relocation (info, howto, rel, addend,
+ input_bfd, input_section,
+ contents, false))
+ return false;
+ }
+
+ /* Go on to the next relocation. */
+ continue;
+ }
+
/* In the N32 and 64-bit ABIs there may be multiple consecutive
relocations for the same offset. In that case we are
supposed to treat the output of each relocation as the addend
local_syms,
local_sections,
&value,
- &name))
+ &name,
+ &require_jalx))
{
case bfd_reloc_continue:
/* There's nothing to do. */
continue;
case bfd_reloc_undefined:
- return false;
+ /* mips_elf_calculate_relocation already called the
+ undefined_symbol callback. There's no real point in
+ trying to perform the relocation at this point, so we
+ just skip ahead to the next relocation. */
+ continue;
case bfd_reloc_notsupported:
abort ();
/* Ignore overflow until we reach the last relocation for
a given location. */
;
- else if (!name
- || ! ((*info->callbacks->reloc_overflow)
- (info, name, howto->name, (bfd_vma) 0,
- input_bfd, input_section, rel->r_offset)))
- return false;
-
+ else
+ {
+ BFD_ASSERT (name != NULL);
+ if (! ((*info->callbacks->reloc_overflow)
+ (info, name, howto->name, (bfd_vma) 0,
+ input_bfd, input_section, rel->r_offset)))
+ return false;
+ }
break;
case bfd_reloc_ok:
continue;
}
+ if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
+ /* See the comment above about using R_MIPS_64 in the 32-bit
+ ABI. Until now, we've been using the HOWTO for R_MIPS_32;
+ that calculated the right value. Now, however, we
+ sign-extend the 32-bit result to 64-bits, and store it as a
+ 64-bit value. We are especially generous here in that we
+ go to extreme lengths to support this usage on systems with
+ only a 32-bit VMA. */
+ {
+ bfd_vma sign_bits;
+ bfd_vma low_bits;
+ bfd_vma high_bits;
+
+ if (value & ((bfd_vma) 1 << 31))
+ sign_bits = ((bfd_vma) 1 << 32) - 1;
+ else
+ sign_bits = 0;
+
+ /* If we don't know that we have a 64-bit type,
+ do two separate stores. */
+ if (bfd_big_endian (input_bfd))
+ {
+ /* Undo what we did above. */
+ rel->r_offset -= 4;
+ /* Store the sign-bits (which are most significant)
+ first. */
+ low_bits = sign_bits;
+ high_bits = value;
+ }
+ else
+ {
+ low_bits = value;
+ high_bits = sign_bits;
+ }
+ bfd_put_32 (input_bfd, low_bits,
+ contents + rel->r_offset);
+ bfd_put_32 (input_bfd, high_bits,
+ contents + rel->r_offset + 4);
+ continue;
+ }
+
/* Actually perform the relocation. */
- mips_elf_perform_relocation (howto, rel, value, input_bfd,
- contents);
+ if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd,
+ input_section, contents,
+ require_jalx))
+ return false;
}
return true;
/*ARGSIGNORED*/
boolean
_bfd_mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
- bfd *abfd;
- struct bfd_link_info *info;
- const char *name;
+ bfd *abfd ATTRIBUTE_UNUSED;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ const char *name ATTRIBUTE_UNUSED;
Elf_Internal_Sym *sym;
asection *input_sec;
{
return false;
}
- if (IRIX_COMPAT (abfd) == ict_irix5
+ if ((IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
&& !info->shared
&& bfd_get_section_by_name (abfd, ".rld_map") == NULL)
{
}
/* We need to create a .compact_rel section. */
- if (! mips_elf_create_compact_rel_section (abfd, info))
- return false;
+ if (SGI_COMPAT (abfd))
+ {
+ if (!mips_elf_create_compact_rel_section (abfd, info))
+ return false;
+ }
/* Change aligments of some sections. */
s = bfd_get_section_by_name (abfd, ".hash");
if (!info->shared)
{
h = NULL;
- if (! (_bfd_generic_link_add_one_symbol
+ if (SGI_COMPAT (abfd))
+ {
+ if (!(_bfd_generic_link_add_one_symbol
(info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr,
(bfd_vma) 0, (const char *) NULL, false,
get_elf_backend_data (abfd)->collect,
(struct bfd_link_hash_entry **) &h)))
- return false;
+ return false;
+ }
+ else
+ {
+ /* For normal mips it is _DYNAMIC_LINKING. */
+ if (!(_bfd_generic_link_add_one_symbol
+ (info, abfd, "_DYNAMIC_LINKING", BSF_GLOBAL,
+ bfd_abs_section_ptr, (bfd_vma) 0, (const char *) NULL, false,
+ get_elf_backend_data (abfd)->collect,
+ (struct bfd_link_hash_entry **) &h)))
+ return false;
+ }
h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_SECTION;
BFD_ASSERT (s != NULL);
h = NULL;
- if (! (_bfd_generic_link_add_one_symbol
+ if (SGI_COMPAT (abfd))
+ {
+ if (!(_bfd_generic_link_add_one_symbol
(info, abfd, "__rld_map", BSF_GLOBAL, s,
(bfd_vma) 0, (const char *) NULL, false,
get_elf_backend_data (abfd)->collect,
(struct bfd_link_hash_entry **) &h)))
- return false;
+ return false;
+ }
+ else
+ {
+ /* For normal mips the symbol is __RLD_MAP. */
+ if (!(_bfd_generic_link_add_one_symbol
+ (info, abfd, "__RLD_MAP", BSF_GLOBAL, s,
+ (bfd_vma) 0, (const char *) NULL, false,
+ get_elf_backend_data (abfd)->collect,
+ (struct bfd_link_hash_entry **) &h)))
+ return false;
+ }
h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
static boolean
mips_elf_create_compact_rel_section (abfd, info)
bfd *abfd;
- struct bfd_link_info *info;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
{
flagword flags;
register asection *s;
if (r_symndx < extsymoff)
h = NULL;
+ else if (r_symndx >= extsymoff + (symtab_hdr->sh_size / symtab_hdr->sh_entsize))
+ {
+ (*_bfd_error_handler)
+ (_("Malformed reloc detected for section %s"), name);
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
else
{
h = sym_hashes[r_symndx - extsymoff];
case R_MIPS_CALL_LO16:
case R_MIPS_GOT_HI16:
case R_MIPS_GOT_LO16:
+ case R_MIPS_GOT_PAGE:
+ case R_MIPS_GOT_OFST:
+ case R_MIPS_GOT_DISP:
if (dynobj == NULL)
elf_hash_table (info)->dynobj = dynobj = abfd;
if (! mips_elf_create_got_section (dynobj, info))
case R_MIPS_32:
case R_MIPS_REL32:
+ case R_MIPS_64:
if (dynobj == NULL
&& (info->shared || h != NULL)
&& (sec->flags & SEC_ALLOC) != 0)
|| r_type == R_MIPS_GOT_DISP))
{
/* We may need a local GOT entry for this relocation. We
- don't count R_MIPS_HI16 or R_MIPS_GOT16 relocations
- because they are always followed by a R_MIPS_LO16
- relocation for the value. We don't R_MIPS_GOT_PAGE
- because we can estimate the maximum number of pages
- needed by looking at the size of the segment.
+ don't count R_MIPS_GOT_PAGE because we can estimate the
+ maximum number of pages needed by looking at the size of
+ the segment. Similar comments apply to R_MIPS_GOT16. We
+ don't count R_MIPS_GOT_HI16, or R_MIPS_CALL_HI16 because
+ these are always followed by an R_MIPS_GOT_LO16 or
+ R_MIPS_CALL_LO16.
This estimation is very conservative since we can merge
duplicate entries in the GOT. In order to be less
conservative, we could actually build the GOT here,
rather than in relocate_section. */
g->local_gotno++;
- sgot->_raw_size += 4;
+ sgot->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
}
switch (r_type)
case R_MIPS_CALL_HI16:
case R_MIPS_CALL_LO16:
- /* This symbol requires a global offset table entry. */
- if (!mips_elf_record_global_got_symbol (h, info, g))
- return false;
-
- /* We need a stub, not a plt entry for the undefined
- function. But we record it as if it needs plt. See
- elf_adjust_dynamic_symbol in elflink.h. */
- h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
- h->type = STT_FUNC;
+ if (h != NULL)
+ {
+ /* This symbol requires a global offset table entry. */
+ if (!mips_elf_record_global_got_symbol (h, info, g))
+ return false;
+ /* We need a stub, not a plt entry for the undefined
+ function. But we record it as if it needs plt. See
+ elf_adjust_dynamic_symbol in elflink.h. */
+ h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+ h->type = STT_FUNC;
+ }
break;
case R_MIPS_GOT16:
case R_MIPS_32:
case R_MIPS_REL32:
+ case R_MIPS_64:
if ((info->shared || h != NULL)
&& (sec->flags & SEC_ALLOC) != 0)
{
/* We only need to copy this reloc if the symbol is
defined in a dynamic object. */
hmips = (struct mips_elf_link_hash_entry *) h;
- ++hmips->mips_32_relocs;
+ ++hmips->possibly_dynamic_relocs;
}
/* Even though we don't directly need a GOT entry for
this symbol, a symbol must have a dynamic symbol
- table index greater that DT_GOTSYM if there are
+ table index greater that DT_MIPS_GOTSYM if there are
dynamic relocations against it. */
- if (!mips_elf_record_global_got_symbol (h, info, g))
+ if (h != NULL
+ && !mips_elf_record_global_got_symbol (h, info, g))
return false;
}
- if (SGI_COMPAT (dynobj))
+ if (SGI_COMPAT (abfd))
mips_elf_hash_table (info)->compact_rel_size +=
sizeof (Elf32_External_crinfo);
break;
case R_MIPS_GPREL16:
case R_MIPS_LITERAL:
case R_MIPS_GPREL32:
- if (SGI_COMPAT (dynobj))
+ if (SGI_COMPAT (abfd))
mips_elf_hash_table (info)->compact_rel_size +=
sizeof (Elf32_External_crinfo);
break;
asection *
_bfd_mips_elf_gc_mark_hook (abfd, info, rel, h, sym)
bfd *abfd;
- struct bfd_link_info *info;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
Elf_Internal_Rela *rel;
struct elf_link_hash_entry *h;
Elf_Internal_Sym *sym;
boolean
_bfd_mips_elf_gc_sweep_hook (abfd, info, sec, relocs)
- bfd *abfd;
- struct bfd_link_info *info;
- asection *sec;
- const Elf_Internal_Rela *relocs;
+ bfd *abfd ATTRIBUTE_UNUSED;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ asection *sec ATTRIBUTE_UNUSED;
+ const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
{
#if 0
Elf_Internal_Shdr *symtab_hdr;
return true;
}
+/* Copy data from a MIPS ELF indirect symbol to its direct symbol,
+ hiding the old indirect symbol. Process additional relocation
+ information. */
+
+void
+_bfd_mips_elf_copy_indirect_symbol (dir, ind)
+ struct elf_link_hash_entry *dir, *ind;
+{
+ struct mips_elf_link_hash_entry *dirmips, *indmips;
+
+ _bfd_elf_link_hash_copy_indirect (dir, ind);
+
+ dirmips = (struct mips_elf_link_hash_entry *) dir;
+ indmips = (struct mips_elf_link_hash_entry *) ind;
+ dirmips->possibly_dynamic_relocs += indmips->possibly_dynamic_relocs;
+ if (dirmips->min_dyn_reloc_index == 0
+ || (indmips->min_dyn_reloc_index != 0
+ && indmips->min_dyn_reloc_index < dirmips->min_dyn_reloc_index))
+ dirmips->min_dyn_reloc_index = indmips->min_dyn_reloc_index;
+}
/* Adjust a symbol defined by a dynamic object and referenced by a
regular object. The current definition is in some section of the
file. */
hmips = (struct mips_elf_link_hash_entry *) h;
if (! info->relocateable
- && hmips->mips_32_relocs != 0
+ && hmips->possibly_dynamic_relocs != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
- mips_elf_allocate_dynamic_relocations (dynobj, hmips->mips_32_relocs);
+ mips_elf_allocate_dynamic_relocations (dynobj,
+ hmips->possibly_dynamic_relocs);
/* For a function, create a stub, if needed. */
- if (h->type == STT_FUNC
- || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
+ if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
if (! elf_hash_table (info)->dynamic_sections_created)
return true;
return true;
}
}
+ else if ((h->type == STT_FUNC)
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0)
+ {
+ /* This will set the entry for this symbol in the GOT to 0, and
+ the dynamic linker will take care of this. */
+ h->root.u.def.value = 0;
+ return true;
+ }
/* If this is a weak symbol, and there is a real definition, the
processor independent code will have arranged for us to see the
static boolean
mips_elf_check_mips16_stubs (h, data)
struct mips_elf_link_hash_entry *h;
- PTR data;
+ PTR data ATTRIBUTE_UNUSED;
{
if (h->fn_stub != NULL
&& ! h->need_fn_stub)
bfd *dynobj;
asection *s;
boolean reltext;
- struct mips_got_info *g;
+ struct mips_got_info *g = NULL;
dynobj = elf_hash_table (info)->dynobj;
BFD_ASSERT (dynobj != NULL);
loadable_size += MIPS_FUNCTION_STUB_SIZE;
/* Assume there are two loadable segments consisting of
- contiguous sections. Is 5 enough? */
+ contiguous sections. Is 5 enough? */
local_gotno = (loadable_size >> 16) + 5;
+ if (IRIX_COMPAT (output_bfd) == ict_irix6)
+ /* It's possible we will need GOT_PAGE entries as well as
+ GOT16 entries. Often, these will be able to share GOT
+ entries, but not always. */
+ local_gotno *= 2;
+
g->local_gotno += local_gotno;
s->_raw_size += local_gotno * MIPS_ELF_GOT_SIZE (dynobj);
higher. Therefore, it make sense to put those symbols
that need GOT entries at the end of the symbol table. We
do that here. */
- if (!mips_elf_sort_hash_table (info))
+ if (!mips_elf_sort_hash_table (info, 1))
return false;
- i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
+ if (g->global_gotsym != NULL)
+ i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
+ else
+ /* If there are no global symbols, or none requiring
+ relocations, then GLOBAL_GOTSYM will be NULL. */
+ i = 0;
+ g->global_gotno = i;
s->_raw_size += i * MIPS_ELF_GOT_SIZE (dynobj);
}
else if (strcmp (name, MIPS_ELF_STUB_SECTION_NAME (output_bfd)) == 0)
if (strip)
{
- _bfd_strip_section_from_output (s);
+ _bfd_strip_section_from_output (info, s);
continue;
}
dynamic linker and used by the debugger. */
if (! info->shared)
{
- if (SGI_COMPAT (output_bfd))
- {
- /* SGI object has the equivalence of DT_DEBUG in the
- DT_MIPS_RLD_MAP entry. */
- if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_MAP, 0))
- return false;
- }
- else
- if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
- return false;
- }
-
- if (reltext)
+ /* SGI object has the equivalence of DT_DEBUG in the
+ DT_MIPS_RLD_MAP entry. */
+ if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_MAP, 0))
+ return false;
+ if (!SGI_COMPAT (output_bfd))
+ {
+ if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
+ return false;
+ }
+ }
+ else
+ {
+ /* Shared libraries on traditional mips have DT_DEBUG. */
+ if (!SGI_COMPAT (output_bfd))
+ {
+ if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
+ return false;
+ }
+ }
+ if (reltext && SGI_COMPAT(output_bfd))
{
if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
return false;
+ info->flags |= DF_TEXTREL;
}
if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
return false;
}
- if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICTNO, 0))
- return false;
+ if (SGI_COMPAT (output_bfd))
+ {
+ if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICTNO, 0))
+ return false;
+ }
- if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLISTNO, 0))
- return false;
+ if (SGI_COMPAT (output_bfd))
+ {
+ if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLISTNO, 0))
+ return false;
+ }
if (bfd_get_section_by_name (dynobj, ".conflict") != NULL)
{
return false;
}
- /* If we use dynamic linking, we generate a section symbol for each
- output section. These are local symbols, which means that they
- must come first in the dynamic symbol table.
- That means we must increment the dynamic symbol index of every
- other dynamic symbol. */
- {
- unsigned int c, i;
-
- c = 0;
- if (elf_hash_table (info)->dynamic_sections_created)
- {
- c = bfd_count_sections (output_bfd);
- elf_link_hash_traverse (elf_hash_table (info),
- _bfd_elf_link_adjust_dynindx,
- (PTR) &c);
- elf_hash_table (info)->dynsymcount += c;
-
- for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
- {
- elf_section_data (s)->dynindx = i;
- /* These symbols will have no names, so we don't need to
- fiddle with dynstr_index. */
- }
- }
- }
-
return true;
}
static void
mips_elf_irix6_finish_dynamic_symbol (abfd, name, sym)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
const char *name;
Elf_Internal_Sym *sym;
{
p = stub;
bfd_put_32 (output_bfd, STUB_LW(output_bfd), p);
p += 4;
- bfd_put_32 (output_bfd, STUB_MOVE, p);
+ bfd_put_32 (output_bfd, STUB_MOVE(output_bfd), p);
p += 4;
/* FIXME: Can h->dynindex be more than 64K? */
bfd_put_32 (output_bfd, STUB_JALR, p);
p += 4;
- bfd_put_32 (output_bfd, STUB_LI16 + h->dynindx, p);
+ bfd_put_32 (output_bfd, STUB_LI16(output_bfd) + h->dynindx, p);
BFD_ASSERT (h->plt.offset <= s->_raw_size);
memcpy (s->contents + h->plt.offset, stub, MIPS_FUNCTION_STUB_SIZE);
sym->st_value = gval;
}
- BFD_ASSERT (h->dynindx != -1);
+ BFD_ASSERT (h->dynindx != -1
+ || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0);
sgot = mips_elf_got_section (dynobj);
BFD_ASSERT (sgot != NULL);
/* Run through the global symbol table, creating GOT entries for all
the symbols that need them. */
- if (h->dynindx >= g->global_gotsym->dynindx)
+ if (g->global_gotsym != NULL
+ && h->dynindx >= g->global_gotsym->dynindx)
{
bfd_vma offset;
bfd_vma value;
if (sym->st_value)
value = sym->st_value;
else
- /* For an entity defined in a shared object, this will be
- NULL. (For functions in shared objects for
- which we have created stubs, ST_VALUE will be non-NULL.
- That's because such the functions are now no longer defined
- in a shared object.) */
- value = h->root.u.def.value;
-
+ {
+ /* For an entity defined in a shared object, this will be
+ NULL. (For functions in shared objects for
+ which we have created stubs, ST_VALUE will be non-NULL.
+ That's because such the functions are now no longer defined
+ in a shared object.) */
+
+ if (info->shared && h->root.type == bfd_link_hash_undefined)
+ value = 0;
+ else
+ value = h->root.u.def.value;
+ }
offset = mips_elf_global_got_index (dynobj, h);
MIPS_ELF_PUT_WORD (output_bfd, value, sgot->contents + offset);
}
if (strcmp (name, "_DYNAMIC") == 0
|| strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
sym->st_shndx = SHN_ABS;
- else if (strcmp (name, "_DYNAMIC_LINK") == 0)
+ else if (strcmp (name, "_DYNAMIC_LINK") == 0
+ || strcmp (name, "_DYNAMIC_LINKING") == 0)
{
sym->st_shndx = SHN_ABS;
sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
sym->st_value = 1;
}
+ else if (strcmp (name, "_gp_disp") == 0)
+ {
+ sym->st_shndx = SHN_ABS;
+ sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
+ sym->st_value = elf_gp (output_bfd);
+ }
else if (SGI_COMPAT (output_bfd))
{
- if (strcmp (name, "_gp_disp") == 0)
- {
- sym->st_shndx = SHN_ABS;
- sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
- sym->st_value = elf_gp (output_bfd);
- }
- else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
+ if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
|| strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
{
sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
if (IRIX_COMPAT (output_bfd) == ict_irix6)
mips_elf_irix6_finish_dynamic_symbol (output_bfd, name, sym);
- if (SGI_COMPAT (output_bfd)
- && ! info->shared)
+ if (! info->shared)
{
if (! mips_elf_hash_table (info)->use_rld_obj_head
- && strcmp (name, "__rld_map") == 0)
+ && (strcmp (name, "__rld_map") == 0
+ || strcmp (name, "__RLD_MAP") == 0))
{
asection *s = bfd_get_section_by_name (dynobj, ".rld_map");
BFD_ASSERT (s != NULL);
&& strcmp (name, "__rld_obj_head") == 0)
{
/* IRIX6 does not use a .rld_map section. */
- if (IRIX_COMPAT (output_bfd) == ict_irix5)
+ if (IRIX_COMPAT (output_bfd) == ict_irix5
+ || IRIX_COMPAT (output_bfd) == ict_none)
BFD_ASSERT (bfd_get_section_by_name (dynobj, ".rld_map")
!= NULL);
mips_elf_hash_table (info)->rld_value = sym->st_value;
dyn.d_un.d_val = g->local_gotno;
break;
+ case DT_MIPS_UNREFEXTNO:
+ /* The index into the dynamic symbol table which is the
+ entry of the first external symbol that is not
+ referenced within the same object. */
+ dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
+ break;
+
+ case DT_MIPS_GOTSYM:
+ if (g->global_gotsym)
+ {
+ dyn.d_un.d_val = g->global_gotsym->dynindx;
+ break;
+ }
+ /* In case if we don't have global got symbols we default
+ to setting DT_MIPS_GOTSYM to the same value as
+ DT_MIPS_SYMTABNO, so we just fall through. */
+
case DT_MIPS_SYMTABNO:
name = ".dynsym";
elemsize = MIPS_ELF_SYM_SIZE (output_bfd);
dyn.d_un.d_val = s->_raw_size / elemsize;
break;
- case DT_MIPS_UNREFEXTNO:
- /* The index into the dynamic symbol table which is the
- entry of the first external symbol that is not
- referenced within the same object. */
- dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
- break;
-
- case DT_MIPS_GOTSYM:
- dyn.d_un.d_val = g->global_gotsym->dynindx;
- break;
-
case DT_MIPS_HIPAGENO:
dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
break;
= MIPS_ELF_GOT_SIZE (output_bfd);
{
- asection *sdynsym;
asection *smsym;
asection *s;
- Elf_Internal_Sym sym;
Elf32_compact_rel cpt;
- /* Set up the section symbols for the output sections. SGI sets
- the STT_NOTYPE attribute for these symbols. Should we do so? */
+ /* ??? The section symbols for the output sections were set up in
+ _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
+ symbols. Should we do so? */
- sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
smsym = bfd_get_section_by_name (dynobj,
MIPS_ELF_MSYM_SECTION_NAME (dynobj));
- if (sdynsym != NULL)
+ if (smsym != NULL)
{
Elf32_Internal_Msym msym;
- sym.st_size = 0;
- sym.st_name = 0;
- sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
- sym.st_other = 0;
-
msym.ms_hash_value = 0;
msym.ms_info = ELF32_MS_INFO (0, 1);
for (s = output_bfd->sections; s != NULL; s = s->next)
{
- int indx;
- long dynindx;
-
- sym.st_value = s->vma;
-
- indx = elf_section_data (s)->this_idx;
- BFD_ASSERT (indx > 0);
- sym.st_shndx = indx;
-
- dynindx = elf_section_data (s)->dynindx;
-
- (*get_elf_backend_data (output_bfd)->s->swap_symbol_out)
- (output_bfd, &sym,
- sdynsym->contents
- + (dynindx * MIPS_ELF_SYM_SIZE (output_bfd)));
-
- if (smsym)
- bfd_mips_elf_swap_msym_out
- (output_bfd, &msym,
- (((Elf32_External_Msym *) smsym->contents)
- + dynindx));
- }
+ long dynindx = elf_section_data (s)->dynindx;
- /* Set the sh_info field of the output .dynsym section to
- the index of the first global symbol. */
- elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
- bfd_count_sections (output_bfd) + 1;
+ bfd_mips_elf_swap_msym_out
+ (output_bfd, &msym,
+ (((Elf32_External_Msym *) smsym->contents)
+ + dynindx));
+ }
}
if (SGI_COMPAT (output_bfd))
}
}
+ /* We need to sort the entries of the dynamic relocation section. */
+
+ if (!ABI_64_P (output_bfd))
+ {
+ asection *reldyn;
+
+ reldyn = bfd_get_section_by_name (dynobj,
+ MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
+ if (reldyn != NULL && reldyn->reloc_count > 2)
+ {
+ reldyn_sorting_bfd = output_bfd;
+ qsort ((Elf32_External_Rel *) reldyn->contents + 1,
+ (size_t) reldyn->reloc_count - 1,
+ sizeof (Elf32_External_Rel), sort_dynamic_relocs);
+ }
+ }
+
/* Clean up a first relocation in .rel.dyn. */
s = bfd_get_section_by_name (dynobj,
MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
case bfd_reloc_undefined:
if (!((*link_info->callbacks->undefined_symbol)
(link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
- input_bfd, input_section, (*parent)->address)))
+ input_bfd, input_section, (*parent)->address,
+ true)))
goto error_return;
break;
case bfd_reloc_dangerous:
#define elf_backend_collect true
#define elf_backend_type_change_ok true
#define elf_backend_can_gc_sections true
+#define elf_backend_sign_extend_vma true
#define elf_info_to_howto mips_info_to_howto_rela
#define elf_info_to_howto_rel mips_info_to_howto_rel
#define elf_backend_sym_is_global mips_elf_sym_is_global
#define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
#define elf_backend_plt_header_size 0
+#define elf_backend_copy_indirect_symbol \
+ _bfd_mips_elf_copy_indirect_symbol
+
+#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
+
#define bfd_elf32_bfd_is_local_label_name \
mips_elf_is_local_label_name
#define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
#define bfd_elf32_bfd_print_private_bfd_data \
_bfd_mips_elf_print_private_bfd_data
#include "elf32-target.h"
+
+/* Support for traditional mips targets */
+
+#define INCLUDED_TARGET_FILE /* More a type of flag */
+
+#undef TARGET_LITTLE_SYM
+#undef TARGET_LITTLE_NAME
+#undef TARGET_BIG_SYM
+#undef TARGET_BIG_NAME
+
+#define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
+#define TARGET_LITTLE_NAME "elf32-tradlittlemips"
+#define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
+#define TARGET_BIG_NAME "elf32-tradbigmips"
+
+/* Include the target file again for this target */
+#include "elf32-target.h"