/* MIPS-specific support for 32-bit ELF
- Copyright 1993, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
+ Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
Most of the information added by Ian Lance Taylor, Cygnus Support,
<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
EXTR esym;
/* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
- this symbol. */
+ this symbol. */
unsigned int possibly_dynamic_relocs;
/* The index of the first dynamic relocation (in the .rel.dyn
section) against this symbol. */
unsigned int min_dyn_reloc_index;
+ /* We must not create a stub for a symbol that has relocations
+ related to taking the function's address, i.e. any but
+ R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
+ p. 4-20. */
+ boolean no_fn_stub;
+
/* If there is a stub that 32 bit functions should use to call this
16 bit function, this points to the section containing the stub. */
asection *fn_stub;
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
+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
static bfd_byte *elf32_mips_get_relocated_section_contents
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
bfd_byte *, boolean, asymbol **));
-static asection *mips_elf_create_msym_section
+static asection *mips_elf_create_msym_section
PARAMS ((bfd *));
-static void mips_elf_irix6_finish_dynamic_symbol
+static void mips_elf_irix6_finish_dynamic_symbol
PARAMS ((bfd *, const char *, Elf_Internal_Sym *));
static bfd_vma mips_elf_sign_extend PARAMS ((bfd_vma, int));
static boolean mips_elf_overflow_p PARAMS ((bfd_vma, int));
PARAMS ((bfd *, struct bfd_link_info *, bfd_vma));
static bfd_vma mips_elf_got_offset_from_index
PARAMS ((bfd *, bfd *, bfd_vma));
-static boolean mips_elf_record_global_got_symbol
+static boolean mips_elf_record_global_got_symbol
PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *,
struct mips_got_info *));
static bfd_vma mips_elf_got_page
PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, bfd_vma *));
static const Elf_Internal_Rela *mips_elf_next_relocation
- PARAMS ((unsigned int, const Elf_Internal_Rela *,
+ 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 *,
static bfd_vma mips_elf_obtain_contents
PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *));
static boolean mips_elf_perform_relocation
- PARAMS ((struct bfd_link_info *, reloc_howto_type *,
+ 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
+static boolean mips_elf_sort_hash_table_f
PARAMS ((struct mips_elf_link_hash_entry *, PTR));
-static boolean mips_elf_sort_hash_table
+static boolean mips_elf_sort_hash_table
PARAMS ((struct bfd_link_info *, unsigned long));
static asection * mips_elf_got_section PARAMS ((bfd *));
-static struct mips_got_info *mips_elf_got_info
+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 **));
-static bfd_vma mips_elf_create_local_got_entry
+ 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 boolean mips_elf_create_dynamic_relocation
+static bfd_vma mips_elf_got16_entry
+ 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 *,
struct mips_elf_link_hash_entry *, asection *,
bfd_vma, bfd_vma *, asection *));
-static void mips_elf_allocate_dynamic_relocations
+static void mips_elf_allocate_dynamic_relocations
PARAMS ((bfd *, unsigned int));
-static boolean mips_elf_stub_section_p
+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;
+extern const bfd_target bfd_elf32_tradlittlemips_vec;
+#ifdef BFD64
+extern const bfd_target bfd_elf64_tradbigmips_vec;
+extern const bfd_target bfd_elf64_tradlittlemips_vec;
+#endif
/* 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) \
((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
-/* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
- true, yet. */
+/* Nonzero if ABFD is using the 64-bit ABI. */
#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. */
+#ifdef BFD64
#define IRIX_COMPAT(abfd) \
- ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5)
-
+ (((abfd->xvec == &bfd_elf64_tradbigmips_vec) || \
+ (abfd->xvec == &bfd_elf64_tradlittlemips_vec) || \
+ (abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
+ (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
+ ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
+#else
+#define IRIX_COMPAT(abfd) \
+ (((abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
+ (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
+ ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
+#endif
/* Whether we are trying to be compatible with IRIX at all. */
#define SGI_COMPAT(abfd) \
? (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
typedef struct
{
unsigned int ctype : 1; /* 1: long 0: short format. See below. */
- unsigned int rtype : 4; /* Relocation types. See below. */
+ unsigned int rtype : 4; /* Relocation types. See below. */
unsigned int dist2to : 8;
unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
unsigned long konst; /* KONST field. See below. */
typedef struct
{
unsigned int ctype : 1; /* 1: long 0: short format. See below. */
- unsigned int rtype : 4; /* Relocation types. See below. */
+ unsigned int rtype : 4; /* Relocation types. See below. */
unsigned int dist2to : 8;
unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
unsigned long konst; /* KONST field. See below. */
0xffffffff, /* dst_mask */
false), /* pcrel_offset */
- /* 26 bit branch address. */
+ /* 26 bit jump address. */
HOWTO (R_MIPS_26, /* type */
2, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
complain_overflow_dont, /* complain_on_overflow */
/* This needs complex overflow
detection, because the upper four
- bits must match the PC. */
+ bits must match the PC + 4. */
bfd_elf_generic_reloc, /* special_function */
"R_MIPS_26", /* name */
true, /* partial_inplace */
EMPTY_HOWTO (R_MIPS_PJUMP),
EMPTY_HOWTO (R_MIPS_RELGOT),
- /* Protected jump conversion. This is an optimization hint. No
+ /* Protected jump conversion. This is an optimization hint. No
relocation is required for correctness. */
HOWTO (R_MIPS_JALR, /* type */
0, /* rightshift */
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 =
if ((val & 0x8000) != 0)
val += 0x10000;
- insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
+ insn = (insn & ~0xffff) | ((val >> 16) & 0xffff);
bfd_put_32 (abfd, insn, l->addr);
if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
|| (symbol->flags & BSF_SECTION_SYM) != 0)
val += relocation - gp;
- insn = (insn &~ 0xffff) | (val & 0xffff);
+ insn = (insn & ~0xffff) | (val & 0xffff);
bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
if (relocateable)
}
/* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
- generated when addreses are 64 bits. The upper 32 bits are a simle
+ generated when addresses are 64 bits. The upper 32 bits are a simple
sign extension. */
static bfd_reloc_status_type
return 3;
case E_MIPS_ARCH_4:
return 4;
+ case E_MIPS_ARCH_5:
+ return 5;
+ case E_MIPS_ARCH_32:
+ return 32;
+ case E_MIPS_ARCH_64:
+ return 64;
}
return 4;
}
case E_MIPS_MACH_4650:
return bfd_mach_mips4650;
+ case E_MIPS_MACH_MIPS32_4K:
+ return bfd_mach_mips32_4k;
+
+ case E_MIPS_MACH_SB1:
+ return bfd_mach_mips_sb1;
+
default:
switch (flags & EF_MIPS_ARCH)
{
case E_MIPS_ARCH_4:
return bfd_mach_mips8000;
break;
+
+ case E_MIPS_ARCH_5:
+ return bfd_mach_mips5;
+ break;
+
+ case E_MIPS_ARCH_32:
+ return bfd_mach_mips32;
+ break;
+
+ case E_MIPS_ARCH_64:
+ return bfd_mach_mips64;
+ break;
}
}
return 0;
}
-/* Return printable name for ABI. */
+/* Return printable name for ABI. */
-static INLINE char*
+static INLINE char *
elf_mips_abi_name (abfd)
bfd *abfd;
{
return "N32";
else if (ABI_64_P (abfd))
return "64";
-
+
flags = elf_elfheader (abfd)->e_flags;
switch (flags & EF_MIPS_ABI)
{
bfd_h_put_32 (abfd, in->ms_hash_value, ex->ms_hash_value);
bfd_h_put_32 (abfd, in->ms_info, ex->ms_info);
}
-
\f
/* Determine whether a symbol is global for the purposes of splitting
the symbol table into global symbols and local symbols. At least
symbols. On most ELF targets the split is between static symbols
and externally visible symbols. */
-/*ARGSUSED*/
static boolean
mips_elf_sym_is_global (abfd, sym)
bfd *abfd ATTRIBUTE_UNUSED;
asymbol *sym;
{
- return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
+ if (SGI_COMPAT(abfd))
+ return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
+ else
+ return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
+ || bfd_is_und_section (bfd_get_section (sym))
+ || bfd_is_com_section (bfd_get_section (sym)));
}
\f
/* Set the right machine number for a MIPS ELF file. This is used for
file. This gets the MIPS architecture right based on the machine
number. This is used by both the 32-bit and the 64-bit ABI. */
-/*ARGSUSED*/
void
_bfd_mips_elf_final_write_processing (abfd, linker)
bfd *abfd;
break;
case bfd_mach_mips8000:
+ case bfd_mach_mips10000:
+ case bfd_mach_mips12000:
val = E_MIPS_ARCH_4;
break;
+
+ case bfd_mach_mips32:
+ val = E_MIPS_ARCH_32;
+ break;
+
+ case bfd_mach_mips32_4k:
+ val = E_MIPS_ARCH_32 | E_MIPS_MACH_MIPS32_4K;
+ break;
+
+ case bfd_mach_mips5:
+ val = E_MIPS_ARCH_5;
+ break;
+
+ case bfd_mach_mips64:
+ val = E_MIPS_ARCH_64;
+ break;
+
+ case bfd_mach_mips_sb1:
+ val = E_MIPS_ARCH_64 | E_MIPS_MACH_SB1;
+ break;
}
- elf_elfheader (abfd)->e_flags &= ~ (EF_MIPS_ARCH | EF_MIPS_MACH);
+ elf_elfheader (abfd)->e_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
elf_elfheader (abfd)->e_flags |= val;
/* Set the sh_info field for .gptab sections and other appropriate
}
}
\f
-/* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
+/* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
boolean
_bfd_mips_elf_set_private_flags (abfd, flags)
flagword old_flags;
flagword new_flags;
boolean ok;
+ boolean null_input_bfd = true;
+ asection *sec;
/* 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)
{
elf_flags_init (obfd) = true;
elf_elfheader (obfd)->e_flags = new_flags;
- elf_elfheader (obfd)->e_ident[EI_CLASS]
+ elf_elfheader (obfd)->e_ident[EI_CLASS]
= elf_elfheader (ibfd)->e_ident[EI_CLASS];
if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
if (new_flags == old_flags)
return true;
+ /* Check to see if the input BFD actually contains any sections.
+ If not, its flags may not have been initialised either, but it cannot
+ actually cause any incompatibility. */
+ for (sec = ibfd->sections; sec != NULL; sec = sec->next)
+ {
+ /* Ignore synthetic sections and empty .text, .data and .bss sections
+ which are automatically generated by gas. */
+ if (strcmp (sec->name, ".reginfo")
+ && strcmp (sec->name, ".mdebug")
+ && ((!strcmp (sec->name, ".text")
+ || !strcmp (sec->name, ".data")
+ || !strcmp (sec->name, ".bss"))
+ && sec->_raw_size != 0))
+ {
+ null_input_bfd = false;
+ break;
+ }
+ }
+ if (null_input_bfd)
+ return true;
+
ok = true;
if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
ok = false;
}
- /* Compare the ISA's. */
+ /* Compare the ISA's. */
if ((new_flags & (EF_MIPS_ARCH | EF_MIPS_MACH))
!= (old_flags & (EF_MIPS_ARCH | EF_MIPS_MACH)))
{
int old_isa = elf_mips_isa (old_flags);
/* If either has no machine specified, just compare the general isa's.
- Some combinations of machines are ok, if the isa's match. */
- if (! new_mach
+ Some combinations of machines are ok, if the isa's match. */
+ if (! new_mach
|| ! old_mach
|| new_mach == old_mach
)
{
- /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
- and -mips4 code. They will normally use the same data sizes and
- calling conventions. */
+ /* Don't warn about mixing code using 32-bit ISAs, or mixing code
+ using 64-bit ISAs. They will normally use the same data sizes
+ and calling conventions. */
- if ((new_isa == 1 || new_isa == 2)
- ? (old_isa != 1 && old_isa != 2)
- : (old_isa == 1 || old_isa == 2))
+ if (( (new_isa == 1 || new_isa == 2 || new_isa == 32)
+ ^ (old_isa == 1 || old_isa == 2 || old_isa == 32)) != 0)
{
(*_bfd_error_handler)
(_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
ok = false;
}
- new_flags &= ~ (EF_MIPS_ARCH | EF_MIPS_MACH);
- old_flags &= ~ (EF_MIPS_ARCH | EF_MIPS_MACH);
+ new_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
+ old_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
}
/* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
does set EI_CLASS differently from any 32-bit ABI. */
if ((new_flags & EF_MIPS_ABI) != (old_flags & EF_MIPS_ABI)
- || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
+ || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
!= elf_elfheader (obfd)->e_ident[EI_CLASS]))
{
- /* Only error if both are set (to different values). */
+ /* Only error if both are set (to different values). */
if (((new_flags & EF_MIPS_ABI) && (old_flags & EF_MIPS_ABI))
- || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
+ || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
!= elf_elfheader (obfd)->e_ident[EI_CLASS]))
{
(*_bfd_error_handler)
_bfd_elf_print_private_bfd_data (abfd, ptr);
/* xgettext:c-format */
- fprintf (file, _ ("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
+ fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32)
- fprintf (file, _ (" [abi=O32]"));
+ fprintf (file, _(" [abi=O32]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O64)
- fprintf (file, _ (" [abi=O64]"));
+ fprintf (file, _(" [abi=O64]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI32)
- fprintf (file, _ (" [abi=EABI32]"));
+ fprintf (file, _(" [abi=EABI32]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64)
- fprintf (file, _ (" [abi=EABI64]"));
+ fprintf (file, _(" [abi=EABI64]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI))
- fprintf (file, _ (" [abi unknown]"));
+ fprintf (file, _(" [abi unknown]"));
else if (ABI_N32_P (abfd))
- fprintf (file, _ (" [abi=N32]"));
+ fprintf (file, _(" [abi=N32]"));
else if (ABI_64_P (abfd))
- fprintf (file, _ (" [abi=64]"));
+ fprintf (file, _(" [abi=64]"));
else
- fprintf (file, _ (" [no abi set]"));
+ fprintf (file, _(" [no abi set]"));
if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
- fprintf (file, _ (" [mips1]"));
+ fprintf (file, _(" [mips1]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
- fprintf (file, _ (" [mips2]"));
+ fprintf (file, _(" [mips2]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
- fprintf (file, _ (" [mips3]"));
+ fprintf (file, _(" [mips3]"));
else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
- fprintf (file, _ (" [mips4]"));
+ fprintf (file, _(" [mips4]"));
+ else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
+ fprintf (file, _ (" [mips5]"));
+ else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
+ fprintf (file, _ (" [mips32]"));
+ else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
+ fprintf (file, _ (" [mips64]"));
else
- fprintf (file, _ (" [unknown ISA]"));
+ fprintf (file, _(" [unknown ISA]"));
if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE)
- fprintf (file, _ (" [32bitmode]"));
+ fprintf (file, _(" [32bitmode]"));
else
- fprintf (file, _ (" [not 32bitmode]"));
+ fprintf (file, _(" [not 32bitmode]"));
fputc ('\n', file);
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;
esd = elf_section_data (sec);
BFD_ASSERT (esd->rel_hdr2 == NULL);
- esd->rel_hdr2
+ esd->rel_hdr2
= (Elf_Internal_Shdr *) bfd_zalloc (abfd, sizeof (Elf_Internal_Shdr));
if (!esd->rel_hdr2)
return false;
boolean
_bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
bfd *abfd ATTRIBUTE_UNUSED;
- Elf32_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
+ Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
asection *sec;
int *retval;
{
+ (l - contents)
+ sizeof (Elf_External_Options)
+ (sizeof (Elf32_External_RegInfo) - 4)),
- SEEK_SET) == -1)
+ SEEK_SET) == -1)
return false;
bfd_h_put_32 (abfd, elf_gp (abfd), buf);
if (bfd_write (buf, 1, 4, abfd) != 4)
return true;
}
-
\f
/* MIPS ELF uses two common sections. One is the usual one, and the
other is for small objects. All the small objects are kept
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))
/* See if we need a PT_MIPS_OPTIONS segment. */
if (IRIX_COMPAT (abfd) == ict_irix6
- && bfd_get_section_by_name (abfd,
+ && bfd_get_section_by_name (abfd,
MIPS_ELF_OPTIONS_SECTION_NAME (abfd)))
++ret;
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");
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;
+ for (pm = &elf_tdata (abfd)->segment_map;
*pm != NULL;
pm = &(*pm)->next)
if ((*pm)->p_type == PT_PHDR)
break;
- options_segment = bfd_zalloc (abfd,
+ options_segment = bfd_zalloc (abfd,
sizeof (struct elf_segment_map));
options_segment->next = *pm;
options_segment->p_type = PT_MIPS_OPTIONS;
}
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" };
+ {
+ ".dynamic", ".dynstr", ".dynsym", ".hash"
+ };
bfd_vma low, high;
unsigned int i, c;
struct elf_segment_map *n;
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;
long reserved;
struct exception_info *exception_info;/* pointer to exception array */
} RPDR, *pRPDR;
-#define cbRPDR sizeof(RPDR)
+#define cbRPDR sizeof (RPDR)
#define rpdNil ((pRPDR) 0)
/* Swap RPDR (runtime procedure table entry) for output. */
char *ext_hdr = NULL;
swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
- memset (debug, 0, sizeof(*debug));
+ memset (debug, 0, sizeof (*debug));
ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
if (ext_hdr == NULL && swap->external_hdr_size != 0)
\f
/* MIPS ELF local labels start with '$', not 'L'. */
-/*ARGSUSED*/
static boolean
mips_elf_is_local_label_name (abfd, name)
bfd *abfd;
if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
filename_ptr, functionname_ptr,
- line_ptr,
- ABI_64_P (abfd) ? 8 : 0))
+ line_ptr,
+ ABI_64_P (abfd) ? 8 : 0,
+ &elf_tdata (abfd)->dwarf2_find_line_info))
return true;
msec = bfd_get_section_by_name (abfd, ".mdebug");
/* The size of the .compact_rel section (if SGI_COMPAT). */
bfd_size_type compact_rel_size;
/* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
- entry is set to the address of __rld_obj_head as in Irix 5. */
+ entry is set to the address of __rld_obj_head as in Irix 5. */
boolean use_rld_obj_head;
/* This is the value of the __rld_map or __rld_obj_head symbol. */
bfd_vma rld_value;
- /* This is set if we see any mips16 stub sections. */
+ /* This is set if we see any mips16 stub sections. */
boolean mips16_stubs_seen;
};
ret->esym.ifd = -2;
ret->possibly_dynamic_relocs = 0;
ret->min_dyn_reloc_index = 0;
+ ret->no_fn_stub = false;
ret->fn_stub = NULL;
ret->need_fn_stub = false;
ret->call_stub = NULL;
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;
+ if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
+ 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 *
/* Hook called by the linker routine which adds symbols from an object
file. We must handle the special MIPS section numbers here. */
-/*ARGSUSED*/
boolean
_bfd_mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
bfd *abfd;
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 | BSF_DYNAMIC;
- 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 | BSF_DYNAMIC;
- 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:
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_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
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;
}
else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
- /* Set type and value for a symbol with a function stub. */
- h->esym.asym.st = stProc;
- sec = h->root.root.u.def.section;
- if (sec == NULL)
- h->esym.asym.value = 0;
- else
+ struct mips_elf_link_hash_entry *hd = h;
+ boolean no_fn_stub = h->no_fn_stub;
+
+ while (hd->root.root.type == bfd_link_hash_indirect)
{
- output_section = sec->output_section;
- if (output_section != NULL)
- h->esym.asym.value = (h->root.plt.offset
- + sec->output_offset
- + output_section->vma);
- else
- h->esym.asym.value = 0;
+ hd = (struct mips_elf_link_hash_entry *)h->root.root.u.i.link;
+ no_fn_stub = no_fn_stub || hd->no_fn_stub;
}
+
+ if (!no_fn_stub)
+ {
+ /* Set type and value for a symbol with a function stub. */
+ h->esym.asym.st = stProc;
+ sec = hd->root.root.u.def.section;
+ if (sec == NULL)
+ h->esym.asym.value = 0;
+ else
+ {
+ output_section = sec->output_section;
+ if (output_section != NULL)
+ h->esym.asym.value = (hd->root.plt.offset
+ + sec->output_offset
+ + output_section->vma);
+ else
+ h->esym.asym.value = 0;
+ }
#if 0 /* FIXME? */
- h->esym.ifd = 0;
+ h->esym.ifd = 0;
#endif
+ }
}
if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
= 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
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
+ if (!mips_elf_sort_hash_table (info, (info->shared
? bfd_count_sections (abfd) + 1
: 1)))
- return false;
+ return false;
/* Make sure we didn't grow the global .got region. */
dynobj = elf_hash_table (info)->dynobj;
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)
{
for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
if (p->type == bfd_indirect_link_order)
- p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
+ p->u.indirect.section->flags &= ~SEC_HAS_CONTENTS;
(*secpp)->link_order_head = NULL;
*secpp = (*secpp)->next;
--abfd->section_count;
-
+
break;
}
}
/* Find the GP-relative section with the lowest offset. */
lo = (bfd_vma) -1;
for (o = abfd->sections; o != (asection *) NULL; o = o->next)
- if (o->vma < lo
+ if (o->vma < lo
&& (elf_section_data (o)->this_hdr.sh_flags & SHF_MIPS_GPREL))
lo = o->vma;
/* Hack: reset the SEC_HAS_CONTENTS flag so that
elf_link_input_bfd ignores this section. */
- input_section->flags &=~ SEC_HAS_CONTENTS;
+ input_section->flags &= ~SEC_HAS_CONTENTS;
}
/* Size has been set in mips_elf_always_size_sections */
if (mdebug_handle == (PTR) NULL)
return false;
- if (SGI_COMPAT (abfd))
+ 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++)
{
- 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.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.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;
/* Hack: reset the SEC_HAS_CONTENTS flag so that
elf_link_input_bfd ignores this section. */
- input_section->flags &=~ SEC_HAS_CONTENTS;
+ input_section->flags &= ~SEC_HAS_CONTENTS;
}
if (SGI_COMPAT (abfd) && info->shared)
/* Hack: reset the SEC_HAS_CONTENTS flag so that
elf_link_input_bfd ignores this section. */
- input_section->flags &=~ SEC_HAS_CONTENTS;
+ input_section->flags &= ~SEC_HAS_CONTENTS;
}
/* Skip this section later on (I don't think this
/* Hack: reset the SEC_HAS_CONTENTS flag so that
elf_link_input_bfd ignores this section. */
- input_section->flags &=~ SEC_HAS_CONTENTS;
+ input_section->flags &= ~SEC_HAS_CONTENTS;
}
/* The table must be sorted by -G value. */
return true;
}
+/* This function is called via qsort() to sort the dynamic relocation
+ entries by increasing r_symndx value. */
+
+static int
+sort_dynamic_relocs (arg1, arg2)
+ const PTR arg1;
+ const PTR arg2;
+{
+ const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1;
+ const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2;
+
+ Elf_Internal_Rel int_reloc1;
+ Elf_Internal_Rel int_reloc2;
+
+ bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc1, &int_reloc1);
+ bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc2, &int_reloc2);
+
+ return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
+}
+
/* Returns the GOT section for ABFD. */
static asection *
}
/* Returns the GOT information associated with the link indicated by
- INFO. If SGOTP is non-NULL, it is filled in with the GOT
+ INFO. If SGOTP is non-NULL, it is filled in with the GOT
section. */
static struct mips_got_info *
/* Return whether a relocation is against a local symbol. */
static boolean
-mips_elf_local_relocation_p (input_bfd, relocation, local_sections)
+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;
r_symndx = ELF32_R_SYM (relocation->r_info);
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
- if (! elf_bad_symtab (input_bfd))
- return r_symndx < symtab_hdr->sh_info;
- else
+ extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
+
+ if (r_symndx < extsymoff)
+ return true;
+ if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
+ return true;
+
+ if (check_forced)
{
- /* The symbol table does not follow the rule that local symbols
- must come before globals. */
- return local_sections[r_symndx] != NULL;
+ /* 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;
}
+
+ return false;
}
/* Sign-extend VALUE, which has the indicated number of BITS. */
bfd_vma value;
int bits;
{
- if (value & ((bfd_vma)1 << (bits - 1)))
+ if (value & ((bfd_vma) 1 << (bits - 1)))
/* VALUE is negative. */
- value |= ((bfd_vma) - 1) << bits;
-
+ value |= ((bfd_vma) - 1) << bits;
+
return value;
}
else if (svalue < -(1 << (bits - 1)))
/* The value is too small. */
return true;
-
+
/* All is well. */
return false;
}
/* Calculate the %highest function. */
-static bfd_vma
+static bfd_vma
mips_elf_highest (value)
bfd_vma value ATTRIBUTE_UNUSED;
{
/* Returns the GOT index for the global symbol indicated by H. */
-static bfd_vma
+static bfd_vma
mips_elf_global_got_index (abfd, h)
bfd *abfd;
struct elf_link_hash_entry *h;
indices into the GOT. That makes it easy to calculate the GOT
offset. */
BFD_ASSERT (h->dynindx >= g->global_gotsym->dynindx);
- index = ((h->dynindx - g->global_gotsym->dynindx + g->local_gotno)
+ index = ((h->dynindx - g->global_gotsym->dynindx + g->local_gotno)
* MIPS_ELF_GOT_SIZE (abfd));
BFD_ASSERT (index < sgot->_raw_size);
sgot = mips_elf_got_section (dynobj);
gp = _bfd_get_gp_value (output_bfd);
- return (sgot->output_section->vma + sgot->output_offset + index -
+ return (sgot->output_section->vma + sgot->output_offset + index -
gp);
}
if (h->dynindx == -1
&& !bfd_elf32_link_record_dynamic_symbol (info, h))
return false;
-
+
/* If we've already marked this entry as need GOT space, we don't
need to do it again. */
if (h->got.offset != (bfd_vma) - 1)
/* This structure is passed to mips_elf_sort_hash_table_f when sorting
the dynamic symbols. */
-
+
struct mips_elf_hash_sort_data
{
/* The symbol in the global GOT with the lowest dynamic symbol table
};
/* If H needs a GOT entry, assign it the highest available dynamic
- index. Otherwise, assign it the lowest available dynamic
+ index. Otherwise, assign it the lowest available dynamic
index. */
static boolean
struct mips_elf_link_hash_entry *h;
PTR data;
{
- struct mips_elf_hash_sort_data *hsd
+ struct mips_elf_hash_sort_data *hsd
= (struct mips_elf_hash_sort_data *) data;
/* Symbols without dynamic symbol table entries aren't interesting
hsd.low = NULL;
hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount;
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,
+ mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table *)
+ elf_hash_table (info)),
+ mips_elf_sort_hash_table_f,
&hsd);
/* 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. */
}
MIPS_ELF_PUT_WORD (abfd, value,
- (sgot->contents
+ (sgot->contents
+ MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno));
return MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
}
g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
/* Look to see if we already have an appropriate entry. */
- for (entry = (sgot->contents
- + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
+ for (entry = (sgot->contents
+ + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
entry != sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
entry += MIPS_ELF_GOT_SIZE (abfd))
{
/* Look to see if we aleady have an appropriate entry. */
last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
- for (entry = (sgot->contents
+ for (entry = (sgot->contents
+ MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
entry != last_entry;
entry += MIPS_ELF_GOT_SIZE (abfd))
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_vma index = 0;
bfd_vma address;
- /* 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;
+ 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. */
last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
- for (entry = (sgot->contents
+ for (entry = (sgot->contents
+ MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
entry != last_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. */
+ /* This entry has the right high-order 16 bits, and the low-order
+ 16 bits are set to zero. */
index = entry - sgot->contents;
break;
}
/* Create a rel.dyn relocation for the dynamic linker to resolve. REL
is the original relocation, which is now being transformed into a
- dyanmic relocation. The ADDENDP is adjusted if necessary; the
+ dynamic relocation. The ADDENDP is adjusted if necessary; the
caller should store the result in place of the original addend. */
static boolean
r_type = ELF32_R_TYPE (rel->r_info);
dynobj = elf_hash_table (info)->dynobj;
- sreloc
+ sreloc
= 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;
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
+ outrel.r_offset
= (_bfd_stab_section_offset
(output_bfd, &elf_hash_table (info)->stab_info,
input_section,
skip = true;
}
- /* If we've decided to skip this relocation, just output an emtpy
+ /* 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)
& ELF_LINK_HASH_DEF_REGULAR) == 0))
{
indx = h->root.dynindx;
- BFD_ASSERT (indx != -1);
+ /* h->root.dynindx may be -1 if this symbol was marked to
+ become local. */
+ if (indx == -1)
+ indx = 0;
}
else
{
/* 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;
+ *addendp += section_offset;
/* 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)
+
+ /* If the relocation was previously an absolute relocation and
+ this symbol will not be referred to by the relocation, we must
+ adjust it by the value we give it in the dynamic symbol table.
+ Otherwise leave the job up to the dynamic linker. */
+ if (!indx && r_type != R_MIPS_REL32)
*addendp += symbol;
/* The relocation is always an REL32 relocation because we don't
{
(*get_elf_backend_data (output_bfd)->s->swap_reloc_out)
(output_bfd, &outrel,
- (sreloc->contents
+ (sreloc->contents
+ sreloc->reloc_count * sizeof (Elf64_Mips_External_Rel)));
}
else
/* 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
+ && (h->min_dyn_reloc_index == 0
|| sreloc->reloc_count < h->min_dyn_reloc_index))
h->min_dyn_reloc_index = sreloc->reloc_count;
/* On IRIX5, make an entry of compact relocation info. */
if (! skip && IRIX_COMPAT (output_bfd) == ict_irix5)
{
- asection* scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
+ asection *scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
bfd_byte *cr;
if (scpt)
overflow occurs, and bfd_reloc_ok to indicate success. */
static bfd_reloc_status_type
-mips_elf_calculate_relocation (abfd,
+mips_elf_calculate_relocation (abfd,
input_bfd,
input_section,
info,
local_sections,
valuep,
namep,
- require_jalxp)
+ require_jalxp)
bfd *abfd;
bfd *input_bfd;
asection *input_section;
/* The section in which the symbol referenced by the relocation is
located. */
asection *sec = NULL;
- struct mips_elf_link_hash_entry* h = NULL;
+ struct mips_elf_link_hash_entry *h = NULL;
/* True if the symbol referred to by this relocation is a local
symbol. */
boolean local_p;
/* Parse the relocation. */
r_symndx = ELF32_R_SYM (relocation->r_info);
r_type = ELF32_R_TYPE (relocation->r_info);
- p = (input_section->output_section->vma
+ p = (input_section->output_section->vma
+ input_section->output_offset
+ relocation->r_offset);
used in the array of hash table entries. */
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
local_p = mips_elf_local_relocation_p (input_bfd, relocation,
- local_sections);
+ local_sections, false);
if (! elf_bad_symtab (input_bfd))
extsymoff = symtab_hdr->sh_info;
else
must come before globals. */
extsymoff = 0;
}
-
+
/* Figure out the value of the symbol. */
if (local_p)
{
else
{
/* For global symbols we look up the symbol in the hash-table. */
- h = ((struct mips_elf_link_hash_entry *)
+ 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. */
*namep = h->root.root.root.string;
{
sec = h->root.root.u.def.section;
if (sec->output_section)
- symbol = (h->root.root.u.def.value
+ symbol = (h->root.root.u.def.value
+ sec->output_section->vma
+ sec->output_offset);
else
and check to see if they exist by looking at their
addresses. */
symbol = 0;
- else if (info->shared && !info->symbolic && !info->no_undefined)
+ 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)
+ 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 in mips_elf_create_dynamic_sections.
+ _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. */
if (! ((*info->callbacks->undefined_symbol)
(info, h->root.root.root.string, input_bfd,
input_section, relocation->r_offset,
- (!info->shared || info->no_undefined))))
+ (!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 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 != NULL
&& (h->call_stub != NULL || h->call_fp_stub != NULL)
&& !target_is_16_bit_code_p)
{
*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)
if (!local_p)
{
BFD_ASSERT (addend == 0);
- g = mips_elf_global_got_index
+ g = mips_elf_global_got_index
(elf_hash_table (info)->dynobj,
- (struct elf_link_hash_entry*) h);
+ (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)
+ else if (r_type == R_MIPS_GOT16 || r_type == R_MIPS_CALL16)
/* There's no need to create a local GOT entry here; the
calculation for a local GOT16 entry does not involve G. */
break;
g = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
abfd, g);
break;
-
+
case R_MIPS_HI16:
case R_MIPS_LO16:
case R_MIPS_GPREL16:
if ((info->shared
|| (elf_hash_table (info)->dynamic_sections_created
&& h != NULL
- && ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
- == 0)))
+ && ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
+ != 0)))
&& (input_section->flags & SEC_ALLOC) != 0)
{
/* If we're creating a shared library, or this relocation is
record in the output, and leave the job up to the dynamic
linker. */
value = addend;
- if (!mips_elf_create_dynamic_relocation (abfd,
- info,
+ if (!mips_elf_create_dynamic_relocation (abfd,
+ info,
relocation,
h,
sec,
break;
case R_MIPS16_26:
- /* The calculation for R_MIPS_26 is just the same as for an
+ /* The calculation for R_MIPS16_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;
+ value = (((addend << 2) | ((p + 4) & 0xf0000000)) + symbol) >> 2;
else
value = (mips_elf_sign_extend (addend << 2, 28) + symbol) >> 2;
value &= howto->dst_mask;
value = mips_elf_sign_extend (addend, 16) + symbol - gp;
overflowed_p = mips_elf_overflow_p (value, 16);
break;
-
+
case R_MIPS_GOT16:
+ case R_MIPS_CALL16:
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
+ value
= mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
abfd,
value);
/* Fall through. */
- case R_MIPS_CALL16:
case R_MIPS_GOT_DISP:
value = g;
overflowed_p = mips_elf_overflow_p (value, 16);
value);
overflowed_p = mips_elf_overflow_p (value, 16);
break;
-
+
case R_MIPS_GOT_OFST:
mips_elf_got_page (abfd, info, symbol + addend, &value);
overflowed_p = mips_elf_overflow_p (value, 16);
value = mips_elf_highest (addend + symbol);
value &= howto->dst_mask;
break;
-
+
case R_MIPS_SCN_DISP:
value = symbol + addend - sec->output_offset;
value &= howto->dst_mask;
static boolean
mips_elf_perform_relocation (info, howto, relocation, value,
- input_bfd, input_section,
+ input_bfd, input_section,
contents, require_jalx)
struct bfd_link_info *info;
reloc_howto_type *howto;
+--------------+--------------------------------+
! 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.
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:
+----------+------+-------------+
| | | |
+----------+--------------------+
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)
+ (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
When producing a fully linked file, the calculation is
- let R = (((A < 2) | (P & 0xf0000000) + S) >> 2)
+ let R = (((A < 2) | ((P + 4) & 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 = (((value & 0x1f0000) << 5)
+ | ((value & 0x3e00000) >> 5)
| (value & 0xffff));
-
}
else if (r_type == R_MIPS16_GPREL)
{
+--------------+--------------------------------+
! 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.
+ 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
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;
REL relocation. */
boolean rela_relocation_p = true;
int r_type = ELF32_R_TYPE (rel->r_info);
+ const char * msg = (const char *) NULL;
/* Find the relocation howto for this relocation. */
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
+ 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
/* On big-endian systems, we need to lie about the position
of the reloc. */
if (bfd_big_endian (input_bfd))
- rel->r_offset += 4;
+ rel->r_offset += 4;
}
else
howto = mips_rtype_to_howto (r_type);
REL_HDR is read before its REL_HDR2. */
rel_hdr = &elf_section_data (input_section)->rel_hdr;
if ((size_t) (rel - relocs)
- >= (rel_hdr->sh_size / rel_hdr->sh_entsize
- * bed->s->int_rels_per_ext_rel))
+ >= (NUM_SHDR_ENTRIES (rel_hdr) * 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))
{
rela_relocation_p = false;
/* Get the addend, which is stored in the input file. */
- addend = mips_elf_obtain_contents (howto,
+ addend = mips_elf_obtain_contents (howto,
rel,
input_bfd,
contents);
|| r_type == R_MIPS_GNU_REL_HI16
|| (r_type == R_MIPS_GOT16
&& mips_elf_local_relocation_p (input_bfd, rel,
- local_sections)))
+ local_sections, false)))
{
bfd_vma l;
const Elf_Internal_Rela *lo16_relocation;
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.)
+ 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);
+ lo16_relocation
+ = mips_elf_next_relocation (lo, rel, relend);
if (lo16_relocation == NULL)
return false;
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))
+ 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
+ if (r_type == R_MIPS16_GPREL
|| r_type == R_MIPS_GPREL16
|| r_type == R_MIPS_GPREL32
|| r_type == R_MIPS_LITERAL)
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. */
bfd_vma sign_bits;
bfd_vma low_bits;
bfd_vma high_bits;
-
- if (addend & 0x80000000u)
- sign_bits = 0xffffffffu;
+
+ 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))
low_bits = addend;
high_bits = sign_bits;
}
- bfd_put_32 (input_bfd, low_bits,
+ bfd_put_32 (input_bfd, low_bits,
contents + rel->r_offset);
- bfd_put_32 (input_bfd, high_bits,
+ 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,
+ input_bfd, input_section,
contents, false))
return false;
}
relocations for the same offset. In that case we are
supposed to treat the output of each relocation as the addend
for the next. */
- if (rel + 1 < relend
+ if (rel + 1 < relend
&& rel->r_offset == rel[1].r_offset
&& ELF32_R_TYPE (rel[1].r_info) != R_MIPS_NONE)
use_saved_addend_p = true;
use_saved_addend_p = false;
/* Figure out what value we are supposed to relocate. */
- switch (mips_elf_calculate_relocation (output_bfd,
+ switch (mips_elf_calculate_relocation (output_bfd,
input_bfd,
input_section,
info,
continue;
case bfd_reloc_notsupported:
- abort ();
- break;
+ msg = _("internal error: unsupported relocation error");
+ info->callbacks->warning
+ (info, msg, name, input_bfd, input_section, rel->r_offset);
+ return false;
case bfd_reloc_overflow:
if (use_saved_addend_p)
bfd_vma low_bits;
bfd_vma high_bits;
- if (value & 0x80000000u)
- sign_bits = 0xffffffffu;
+ if (value & ((bfd_vma) 1 << 31))
+ sign_bits = ((bfd_vma) 1 << 32) - 1;
else
sign_bits = 0;
low_bits = value;
high_bits = sign_bits;
}
- bfd_put_32 (input_bfd, low_bits,
+ bfd_put_32 (input_bfd, low_bits,
contents + rel->r_offset);
- bfd_put_32 (input_bfd, high_bits,
+ bfd_put_32 (input_bfd, high_bits,
contents + rel->r_offset + 4);
continue;
}
/* Actually perform the relocation. */
- if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd,
+ if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd,
input_section, contents,
require_jalx))
return false;
symbol. We mark symbols as small common if appropriate. This is
also where we undo the increment of the value for a mips16 symbol. */
-/*ARGSIGNORED*/
boolean
_bfd_mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
bfd *abfd ATTRIBUTE_UNUSED;
if (IRIX_COMPAT (abfd) == ict_irix6
&& !mips_elf_create_msym_section (abfd))
return false;
-
+
/* Create .stub section. */
- if (bfd_get_section_by_name (abfd,
+ if (bfd_get_section_by_name (abfd,
MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL)
{
s = bfd_make_section (abfd, MIPS_ELF_STUB_SECTION_NAME (abfd));
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)
{
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_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_SECTION;
}
/* 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
- (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;
- h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
+ 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;
+ }
+ 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
- (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;
+ 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;
+ }
+ 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;
return true;
}
-/* Create the .got section to hold the global offset table. */
+/* Create the .got section to hold the global offset table. */
static boolean
mips_elf_create_got_section (abfd, info)
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_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
return false;
}
elf_section_data (s)->tdata = (PTR) g;
- elf_section_data (s)->this_hdr.sh_flags
+ elf_section_data (s)->this_hdr.sh_flags
|= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
return true;
asection *s;
s = bfd_get_section_by_name (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
- if (!s)
+ if (!s)
{
s = bfd_make_section (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
if (!s
- || !bfd_set_section_flags (abfd, s,
+ || !bfd_set_section_flags (abfd, s,
SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
- | SEC_LINKER_CREATED
+ | SEC_LINKER_CREATED
| SEC_READONLY)
|| !bfd_set_section_alignment (abfd, s,
MIPS_ELF_LOG_FILE_ALIGN (abfd)))
s = bfd_get_section_by_name (abfd, MIPS_ELF_REL_DYN_SECTION_NAME (abfd));
BFD_ASSERT (s != NULL);
-
+
if (s->_raw_size == 0)
{
- /* Make room for a null element. */
+ /* Make room for a null element. */
s->_raw_size += MIPS_ELF_REL_SIZE (abfd);
++s->reloc_count;
}
}
/* Record this stub in an array of local symbol stubs for
- this BFD. */
+ this BFD. */
if (elf_tdata (abfd)->local_stubs == NULL)
{
unsigned long symcount;
asection **n;
if (elf_bad_symtab (abfd))
- symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
+ symcount = NUM_SHDR_ENTRIES (symtab_hdr);
else
symcount = symtab_hdr->sh_info;
n = (asection **) bfd_zalloc (abfd,
if (r_symndx < extsymoff)
h = NULL;
+ else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
+ {
+ (*_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];
/* We may need a local GOT entry for this relocation. We
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.
+ the segment. Similar comments apply to R_MIPS_GOT16 and
+ R_MIPS_CALL16. 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
hmips = (struct mips_elf_link_hash_entry *) h;
++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_MIPS_GOTSYM if there are
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;
break;
}
+ /* We must not create a stub for a symbol that has relocations
+ related to taking the function's address. */
+ switch (r_type)
+ {
+ default:
+ if (h != NULL)
+ {
+ struct mips_elf_link_hash_entry *mh;
+
+ mh = (struct mips_elf_link_hash_entry *) h;
+ mh->no_fn_stub = true;
+ }
+ break;
+ case R_MIPS_CALL16:
+ case R_MIPS_CALL_HI16:
+ case R_MIPS_CALL_LO16:
+ break;
+ }
+
/* If this reloc is not a 16 bit call, and it has a global
symbol, then we will need the fn_stub if there is one.
- References from a stub section do not count. */
+ References from a stub section do not count. */
if (h != NULL
&& r_type != R_MIPS16_26
&& strncmp (bfd_get_section_name (abfd, sec), FN_STUB,
/* ??? It would seem that the existing MIPS code does no sort
of reference counting or whatnot on its GOT and PLT entries,
so it is not possible to garbage collect them at this time. */
- break;
+ break;
default:
break;
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;
+ if (indmips->no_fn_stub)
+ dirmips->no_fn_stub = true;
+}
/* Adjust a symbol defined by a dynamic object and referenced by a
regular object. The current definition is in some section of the
if (! info->relocateable
&& hmips->possibly_dynamic_relocs != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
- mips_elf_allocate_dynamic_relocations (dynobj,
+ 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)
+ /* For a function, create a stub, if allowed. */
+ if (! hmips->no_fn_stub
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
if (! elf_hash_table (info)->dynamic_sections_created)
return true;
if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
{
/* We need .stub section. */
- s = bfd_get_section_by_name (dynobj,
+ s = bfd_get_section_by_name (dynobj,
MIPS_ELF_STUB_SECTION_NAME (dynobj));
BFD_ASSERT (s != NULL);
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
/* Check the mips16 stubs for a particular symbol, and see if we can
discard them. */
-/*ARGSUSED*/
static boolean
mips_elf_check_mips16_stubs (h, data)
struct mips_elf_link_hash_entry *h;
being included in the link. */
h->fn_stub->_raw_size = 0;
h->fn_stub->_cooked_size = 0;
- h->fn_stub->flags &= ~ SEC_RELOC;
+ h->fn_stub->flags &= ~SEC_RELOC;
h->fn_stub->reloc_count = 0;
h->fn_stub->flags |= SEC_EXCLUDE;
}
to 0 to prevent it from being included in the link. */
h->call_stub->_raw_size = 0;
h->call_stub->_cooked_size = 0;
- h->call_stub->flags &= ~ SEC_RELOC;
+ h->call_stub->flags &= ~SEC_RELOC;
h->call_stub->reloc_count = 0;
h->call_stub->flags |= SEC_EXCLUDE;
}
to 0 to prevent it from being included in the link. */
h->call_fp_stub->_raw_size = 0;
h->call_fp_stub->_cooked_size = 0;
- h->call_fp_stub->flags &= ~ SEC_RELOC;
+ h->call_fp_stub->flags &= ~SEC_RELOC;
h->call_fp_stub->reloc_count = 0;
h->call_fp_stub->flags |= SEC_EXCLUDE;
}
{
s = bfd_get_section_by_name (dynobj, ".interp");
BFD_ASSERT (s != NULL);
- s->_raw_size
+ s->_raw_size
= strlen (ELF_DYNAMIC_INTERPRETER (output_bfd)) + 1;
- s->contents
+ s->contents
= (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd);
}
}
if ((target != NULL
&& (target->flags & SEC_READONLY) != 0
&& (target->flags & SEC_ALLOC) != 0)
- || strcmp (outname,
+ || strcmp (outname,
MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) == 0)
reltext = true;
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
- if (strcmp (name,
+ if (strcmp (name,
MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) != 0)
s->reloc_count = 0;
}
else if (strncmp (name, ".got", 4) == 0)
{
int i;
- bfd_size_type loadable_size = 0;
- bfd_size_type local_gotno;
- struct _bfd *sub;
+ bfd_size_type loadable_size = 0;
+ bfd_size_type local_gotno;
+ bfd *sub;
- BFD_ASSERT (elf_section_data (s) != NULL);
+ BFD_ASSERT (elf_section_data (s) != NULL);
g = (struct mips_got_info *) elf_section_data (s)->tdata;
- BFD_ASSERT (g != NULL);
-
- /* Calculate the total loadable size of the output. That
- will give us the maximum number of GOT_PAGE entries
- required. */
- for (sub = info->input_bfds; sub; sub = sub->link_next)
- {
- asection *subsection;
-
- for (subsection = sub->sections;
- subsection;
- subsection = subsection->next)
- {
- if ((subsection->flags & SEC_ALLOC) == 0)
- continue;
- loadable_size += (subsection->_raw_size + 0xf) & ~0xf;
- }
- }
- loadable_size += MIPS_FUNCTION_STUB_SIZE;
-
- /* Assume there are two loadable segments consisting of
- contiguous sections. Is 5 enough? */
- local_gotno = (loadable_size >> 16) + 5;
+ BFD_ASSERT (g != NULL);
+
+ /* Calculate the total loadable size of the output. That
+ will give us the maximum number of GOT_PAGE entries
+ required. */
+ for (sub = info->input_bfds; sub; sub = sub->link_next)
+ {
+ asection *subsection;
+
+ for (subsection = sub->sections;
+ subsection;
+ subsection = subsection->next)
+ {
+ if ((subsection->flags & SEC_ALLOC) == 0)
+ continue;
+ loadable_size += (subsection->_raw_size + 0xf) & ~0xf;
+ }
+ }
+ loadable_size += MIPS_FUNCTION_STUB_SIZE;
+
+ /* Assume there are two loadable segments consisting of
+ 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);
+ g->local_gotno += local_gotno;
+ s->_raw_size += local_gotno * MIPS_ELF_GOT_SIZE (dynobj);
- /* There has to be a global GOT entry for every symbol with
- a dynamic symbol table index of DT_MIPS_GOTSYM or
- higher. Therefore, it make sense to put those symbols
- that need GOT entries at the end of the symbol table. We
- do that here. */
+ /* There has to be a global GOT entry for every symbol with
+ a dynamic symbol table index of DT_MIPS_GOTSYM or
+ 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, 1))
return false;
s->_raw_size += mips_elf_hash_table (info)->compact_rel_size;
else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (output_bfd))
== 0)
- s->_raw_size = (sizeof (Elf32_External_Msym)
+ s->_raw_size = (sizeof (Elf32_External_Msym)
* (elf_hash_table (info)->dynsymcount
+ bfd_count_sections (output_bfd)));
else if (strncmp (name, ".init", 5) != 0)
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;
+ 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))
+ if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
return false;
}
- else
- if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
- return false;
}
-
- if (reltext)
+ 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 (IRIX_COMPAT (dynobj) == ict_irix6
- && (bfd_get_section_by_name
+ && (bfd_get_section_by_name
(dynobj, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj)))
&& !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_OPTIONS, 0))
return false;
- if (bfd_get_section_by_name (dynobj,
+ if (bfd_get_section_by_name (dynobj,
MIPS_ELF_MSYM_SECTION_NAME (dynobj))
&& !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_MSYM, 0))
return false;
int i;
for (i = 0; i < 2; ++i)
- for (p = (i == 0) ? text_section_symbols : data_section_symbols;
+ for (p = (i == 0) ? text_section_symbols : data_section_symbols;
*p;
++p)
if (strcmp (*p, name) == 0)
/* All of these symbols are given type STT_SECTION by the
IRIX6 linker. */
sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
-
+
/* The IRIX linker puts these symbols in special sections. */
if (i == 0)
sym->st_shndx = SHN_MIPS_TEXT;
else
sym->st_shndx = SHN_MIPS_DATA;
-
+
break;
}
}
BFD_ASSERT (h->dynindx != -1);
- s = bfd_get_section_by_name (dynobj,
+ s = bfd_get_section_by_name (dynobj,
MIPS_ELF_STUB_SECTION_NAME (dynobj));
BFD_ASSERT (s != NULL);
/* Fill the stub. */
p = stub;
- bfd_put_32 (output_bfd, STUB_LW(output_bfd), p);
+ 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);
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);
}
/* Create a .msym entry, if appropriate. */
- smsym = bfd_get_section_by_name (dynobj,
+ smsym = bfd_get_section_by_name (dynobj,
MIPS_ELF_MSYM_SECTION_NAME (dynobj));
if (smsym)
{
/* It is undocumented what the `1' indicates, but IRIX6 uses
this value. */
msym.ms_info = ELF32_MS_INFO (mh->min_dyn_reloc_index, 1);
- bfd_mips_elf_swap_msym_out
+ bfd_mips_elf_swap_msym_out
(dynobj, &msym,
((Elf32_External_Msym *) smsym->contents) + h->dynindx);
}
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
- || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 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);
sym->st_other = STO_PROTECTED;
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)
- BFD_ASSERT (bfd_get_section_by_name (dynobj, ".rld_map")
+ 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;
}
/* Read in the current dynamic entry. */
(*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
-
+
/* Assume that we're going to modify it and write it out. */
swap_out_p = true;
switch (dyn.d_tag)
{
case DT_RELENT:
- s = (bfd_get_section_by_name
+ s = (bfd_get_section_by_name
(dynobj,
MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)));
BFD_ASSERT (s != NULL);
dyn.d_un.d_val = s->_raw_size / elemsize;
}
else
- dyn.d_un.d_val = 0;
+ dyn.d_un.d_val = 0;
break;
case DT_MIPS_TIME_STAMP:
break;
case DT_MIPS_OPTIONS:
- s = (bfd_get_section_by_name
+ s = (bfd_get_section_by_name
(output_bfd, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd)));
dyn.d_un.d_ptr = s->vma;
break;
case DT_MIPS_MSYM:
- s = (bfd_get_section_by_name
+ s = (bfd_get_section_by_name
(output_bfd, MIPS_ELF_MSYM_SECTION_NAME (output_bfd)));
dyn.d_un.d_ptr = s->vma;
break;
}
if (swap_out_p)
- (*get_elf_backend_data (dynobj)->s->swap_dyn_out)
+ (*get_elf_backend_data (dynobj)->s->swap_dyn_out)
(dynobj, &dyn, b);
}
}
/* The first entry of the global offset table will be filled at
runtime. The second entry will be used by some runtime loaders.
- This isn't the case of Irix rld. */
+ This isn't the case of Irix rld. */
if (sgot != NULL && sgot->_raw_size > 0)
{
MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0, sgot->contents);
- MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000,
+ MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000,
sgot->contents + MIPS_ELF_GOT_SIZE (output_bfd));
}
_bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
symbols. Should we do so? */
- smsym = bfd_get_section_by_name (dynobj,
+ smsym = bfd_get_section_by_name (dynobj,
MIPS_ELF_MSYM_SECTION_NAME (dynobj));
if (smsym != NULL)
{
{
long dynindx = elf_section_data (s)->dynindx;
- bfd_mips_elf_swap_msym_out
+ bfd_mips_elf_swap_msym_out
(output_bfd, &msym,
(((Elf32_External_Msym *) smsym->contents)
+ dynindx));
s->contents));
/* Clean up a dummy stub function entry in .text. */
- s = bfd_get_section_by_name (dynobj,
+ s = bfd_get_section_by_name (dynobj,
MIPS_ELF_STUB_SECTION_NAME (dynobj));
if (s != NULL)
{
}
}
+ /* 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,
+ s = bfd_get_section_by_name (dynobj,
MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
if (s != NULL && s->_raw_size > 0)
memset (s->contents, 0, MIPS_ELF_REL_SIZE (dynobj));
free (reloc_vector);
return NULL;
}
+
#define bfd_elf32_bfd_get_relocated_section_contents \
elf32_mips_get_relocated_section_contents
\f
/* ECOFF swapping routines. These are used when dealing with the
.mdebug section, which is in the ECOFF debugging format. */
-static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap =
-{
+static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
/* Symbol table magic number. */
magicSym,
/* Alignment of debugging information. E.g., 4. */
#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"