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 **,
- boolean *));
+ boolean *, boolean));
static bfd_vma mips_elf_obtain_contents
PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *));
static boolean mips_elf_perform_relocation
static INLINE char* elf_mips_abi_name PARAMS ((bfd *));
static void mips_elf_irix6_finish_dynamic_symbol
PARAMS ((bfd *, const char *, Elf_Internal_Sym *));
+static boolean _bfd_mips_elf_mach_extends_p PARAMS ((flagword, flagword));
/* This will be used when we sort the dynamic relocation records. */
static bfd *reldyn_sorting_bfd;
flagword flags;
register asection *s;
struct elf_link_hash_entry *h;
+ struct bfd_link_hash_entry *bh;
struct mips_got_info *g;
bfd_size_type amt;
/* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
linker script because we don't want to define the symbol if we
are not creating a global offset table. */
- h = NULL;
+ bh = NULL;
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
(bfd_vma) 0, (const char *) NULL, false,
- get_elf_backend_data (abfd)->collect,
- (struct bfd_link_hash_entry **) &h)))
+ get_elf_backend_data (abfd)->collect, &bh)))
return false;
+
+ h = (struct elf_link_hash_entry *) bh;
h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
mips_elf_calculate_relocation (abfd, input_bfd, input_section, info,
relocation, addend, howto, local_syms,
local_sections, valuep, namep,
- require_jalxp)
+ require_jalxp, save_addend)
bfd *abfd;
bfd *input_bfd;
asection *input_section;
bfd_vma *valuep;
const char **namep;
boolean *require_jalxp;
+ boolean save_addend;
{
/* The eventual value we will return. */
bfd_vma value;
struct mips_elf_link_hash_entry *h = NULL;
/* True if the symbol referred to by this relocation is a local
symbol. */
- boolean local_p;
+ boolean local_p, was_local_p;
/* True if the symbol referred to by this relocation is "_gp_disp". */
boolean gp_disp_p = false;
Elf_Internal_Shdr *symtab_hdr;
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
local_p = mips_elf_local_relocation_p (input_bfd, relocation,
local_sections, false);
+ was_local_p = local_p;
if (! elf_bad_symtab (input_bfd))
extsymoff = symtab_hdr->sh_info;
else
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;
- else
- value = mips_elf_sign_extend (addend, 16) + symbol - gp;
+ /* Only sign-extend the addend if it was extracted from the
+ instruction. If the addend was separate, leave it alone,
+ otherwise we may lose significant bits. */
+ if (howto->partial_inplace)
+ addend = mips_elf_sign_extend (addend, 16);
+ value = symbol + addend - gp;
+ /* If the symbol was local, any earlier relocatable links will
+ have adjusted its addend with the gp offset, so compensate
+ for that now. Don't do it for symbols forced local in this
+ link, though, since they won't have had the gp offset applied
+ to them before. */
+ if (was_local_p)
+ value += gp0;
overflowed_p = mips_elf_overflow_p (value, 16);
break;
break;
case R_MIPS_GPREL32:
- value = (addend + symbol + gp0 - gp) & howto->dst_mask;
+ value = (addend + symbol + gp0 - gp);
+ if (!save_addend)
+ value &= howto->dst_mask;
break;
case R_MIPS_PC16:
know where the shared library will wind up at load-time. */
outrel[0].r_info = ELF_R_INFO (output_bfd, (unsigned long) indx,
R_MIPS_REL32);
+ outrel[1].r_info = ELF_R_INFO (output_bfd, (unsigned long) 0,
+ R_MIPS_NONE);
+ outrel[2].r_info = ELF_R_INFO (output_bfd, (unsigned long) 0,
+ R_MIPS_NONE);
/* Adjust the output offset of the relocation to reference the
correct location in the output file. */
case E_MIPS_MACH_4111:
return bfd_mach_mips4111;
+ case E_MIPS_MACH_4120:
+ return bfd_mach_mips4120;
+
case E_MIPS_MACH_4650:
return bfd_mach_mips4650;
+ case E_MIPS_MACH_5400:
+ return bfd_mach_mips5400;
+
+ case E_MIPS_MACH_5500:
+ return bfd_mach_mips5500;
+
case E_MIPS_MACH_SB1:
return bfd_mach_mips_sb1;
sh_offset == object size, and ld doesn't allow that. While the check
is arguably bogus for empty or SHT_NOBITS sections, it can easily be
avoided by not emitting those useless sections in the first place. */
- if ((IRIX_COMPAT (abfd) != ict_irix5 && (IRIX_COMPAT (abfd) != ict_irix6))
+ if (! SGI_COMPAT (abfd) && ! NEWABI_P(abfd)
&& (sec->flags & SEC_RELOC) != 0)
{
struct bfd_elf_section_data *esd;
&& strcmp (*namep, "__rld_obj_head") == 0)
{
struct elf_link_hash_entry *h;
+ struct bfd_link_hash_entry *bh;
/* Mark __rld_obj_head as dynamic. */
- h = NULL;
+ bh = NULL;
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, *namep, BSF_GLOBAL, *secp,
(bfd_vma) *valp, (const char *) NULL, false,
- get_elf_backend_data (abfd)->collect,
- (struct bfd_link_hash_entry **) &h)))
+ get_elf_backend_data (abfd)->collect, &bh)))
return false;
+
+ h = (struct elf_link_hash_entry *) bh;
h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
struct bfd_link_info *info;
{
struct elf_link_hash_entry *h;
+ struct bfd_link_hash_entry *bh;
flagword flags;
register asection *s;
const char * const *namep;
{
for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
{
- h = NULL;
+ bh = NULL;
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
(bfd_vma) 0, (const char *) NULL, false,
- get_elf_backend_data (abfd)->collect,
- (struct bfd_link_hash_entry **) &h)))
+ get_elf_backend_data (abfd)->collect, &bh)))
return false;
+
+ h = (struct elf_link_hash_entry *) bh;
h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_SECTION;
if (!info->shared)
{
- h = NULL;
- 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;
- }
+ const char *name;
+
+ name = SGI_COMPAT (abfd) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
+ bh = NULL;
+ if (!(_bfd_generic_link_add_one_symbol
+ (info, abfd, name, BSF_GLOBAL, bfd_abs_section_ptr,
+ (bfd_vma) 0, (const char *) NULL, false,
+ get_elf_backend_data (abfd)->collect, &bh)))
+ return false;
+
+ h = (struct elf_link_hash_entry *) bh;
h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_SECTION;
s = bfd_get_section_by_name (abfd, ".rld_map");
BFD_ASSERT (s != NULL);
- h = NULL;
- 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;
- }
+ name = SGI_COMPAT (abfd) ? "__rld_map" : "__RLD_MAP";
+ bh = NULL;
+ if (!(_bfd_generic_link_add_one_symbol
+ (info, abfd, name, BSF_GLOBAL, s,
+ (bfd_vma) 0, (const char *) NULL, false,
+ get_elf_backend_data (abfd)->collect, &bh)))
+ return false;
+
+ h = (struct elf_link_hash_entry *) bh;
h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
input_section, info, rel,
addend, howto, local_syms,
local_sections, &value,
- &name, &require_jalx))
+ &name, &require_jalx,
+ use_saved_addend_p))
{
case bfd_reloc_continue:
/* There's nothing to do. */
val = E_MIPS_ARCH_3 | E_MIPS_MACH_4111;
break;
+ case bfd_mach_mips4120:
+ val = E_MIPS_ARCH_3 | E_MIPS_MACH_4120;
+ break;
+
case bfd_mach_mips4650:
val = E_MIPS_ARCH_3 | E_MIPS_MACH_4650;
break;
+ case bfd_mach_mips5400:
+ val = E_MIPS_ARCH_4 | E_MIPS_MACH_5400;
+ break;
+
+ case bfd_mach_mips5500:
+ val = E_MIPS_ARCH_4 | E_MIPS_MACH_5500;
+ break;
+
case bfd_mach_mips5000:
case bfd_mach_mips8000:
case bfd_mach_mips10000:
return true;
}
\f
+/* Return true if machine EXTENSION is an extension of machine BASE,
+ meaning that it should be safe to link code for the two machines
+ and set the output machine to EXTENSION. EXTENSION and BASE are
+ both submasks of EF_MIPS_MACH. */
+
+static boolean
+_bfd_mips_elf_mach_extends_p (base, extension)
+ flagword base, extension;
+{
+ /* The vr5500 ISA is an extension of the core vr5400 ISA, but doesn't
+ include the multimedia stuff. It seems better to allow vr5400
+ and vr5500 code to be merged anyway, since many libraries will
+ just use the core ISA. Perhaps we could add some sort of ASE
+ flag if this ever proves a problem. */
+ return (base == 0
+ || (base == E_MIPS_MACH_5400 && extension == E_MIPS_MACH_5500)
+ || (base == E_MIPS_MACH_4100 && extension == E_MIPS_MACH_4111)
+ || (base == E_MIPS_MACH_4100 && extension == E_MIPS_MACH_4120));
+}
+
/* Merge backend specific data from an object file to the output
object file when linking. */
/* 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
- || ! old_mach
- || new_mach == old_mach
- )
+ if (new_mach == old_mach
+ || _bfd_mips_elf_mach_extends_p (new_mach, old_mach)
+ || _bfd_mips_elf_mach_extends_p (old_mach, new_mach))
{
/* 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
else
{
/* Do we need to update the mach field? */
- if (old_mach == 0 && new_mach != 0)
- elf_elfheader (obfd)->e_flags |= new_mach;
+ if (_bfd_mips_elf_mach_extends_p (old_mach, new_mach))
+ {
+ elf_elfheader (obfd)->e_flags &= ~EF_MIPS_MACH;
+ elf_elfheader (obfd)->e_flags |= new_mach;
+ }
/* Do we need to update the ISA field? */
if (new_isa > old_isa)