aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/ChangeLog30
-rw-r--r--bfd/elf32-mips.c1
-rw-r--r--bfd/elf64-mips.c1
-rw-r--r--bfd/elfn32-mips.c1
-rw-r--r--bfd/elfxx-mips.c276
-rw-r--r--bfd/elfxx-mips.h4
-rw-r--r--ld/ChangeLog9
-rw-r--r--ld/emultempl/mipself.em12
-rw-r--r--ld/testsuite/ld-mips-elf/pr21334.dd2
-rw-r--r--ld/testsuite/ld-mips-elf/pr21334.s2
10 files changed, 293 insertions, 45 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 776426f..70de004 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,35 @@
2018-09-14 Maciej W. Rozycki <macro@mips.com>
+ PR ld/21375
+ * elfxx-mips.h (_bfd_mips_elf_hide_symbol): New prototype.
+ (_bfd_mips_elf_linker_flags): Update prototype.
+ * elf32-mips.c (elf_backend_hide_symbol): New macro.
+ * elf64-mips.c (elf_backend_hide_symbol): Likewise.
+ * elfn32-mips.c (elf_backend_hide_symbol): Likewise.
+ * elfxx-mips.c (mips_elf_link_hash_table): Add
+ `use_absolute_zero' and `gnu_target' members.
+ (mips_elf_record_global_got_symbol): Call
+ `_bfd_mips_elf_hide_symbol' rather than
+ `_bfd_elf_link_hash_hide_symbol'.
+ (mips_use_local_got_p): Return FALSE if the symbol is absolute.
+ (mips_elf_obtain_contents): Reorder function.
+ (mips_elf_nullify_got_load): New function.
+ (mips_elf_calculate_relocation): Add `contents' parameter.
+ Nullify GOT loads or if it is not possible, then redirect GOT
+ relocations to the `__gnu_absolute_zero' symbol, for references
+ that are supposed to resolve to zero.
+ (mips_elf_define_absolute_zero): New function.
+ (_bfd_mips_elf_check_relocs): Prepare for arrangements made in
+ `mips_elf_calculate_relocation' for references made via the GOT
+ that are supposed to resolve to zero.
+ (_bfd_mips_elf_hide_symbol): New function.
+ (_bfd_mips_elf_linker_flags): Add the `gnu_target' parameter,
+ set the `gnu_target' member of the MIPS hash table.
+ (MIPS_LIBC_ABI_ABSOLUTE): New enumeration constant.
+ (_bfd_mips_post_process_headers): Use it.
+
+2018-09-14 Maciej W. Rozycki <macro@mips.com>
+
* elfxx-mips.c (mips_elf_store_contents): New function...
(mips_elf_perform_relocation): ... factored out from here.
diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c
index 23a5712..b085744 100644
--- a/bfd/elf32-mips.c
+++ b/bfd/elf32-mips.c
@@ -2534,6 +2534,7 @@ static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
#define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
#define elf_backend_copy_indirect_symbol \
_bfd_mips_elf_copy_indirect_symbol
+#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
#define elf_backend_fixup_symbol elf32_mips_fixup_symbol
#define elf_backend_grok_prstatus elf32_mips_grok_prstatus
#define elf_backend_grok_psinfo elf32_mips_grok_psinfo
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index 7c9916f..ebf16bb 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -4772,6 +4772,7 @@ const struct elf_size_info mips_elf64_size_info =
#define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
#define elf_backend_copy_indirect_symbol \
_bfd_mips_elf_copy_indirect_symbol
+#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
#define elf_backend_ignore_discarded_relocs \
_bfd_mips_elf_ignore_discarded_relocs
#define elf_backend_mips_irix_compat elf64_mips_irix_compat
diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c
index 10e10bf..0b68a5d 100644
--- a/bfd/elfn32-mips.c
+++ b/bfd/elfn32-mips.c
@@ -4136,6 +4136,7 @@ static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
#define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
#define elf_backend_copy_indirect_symbol \
_bfd_mips_elf_copy_indirect_symbol
+#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
#define elf_backend_grok_prstatus elf32_mips_grok_prstatus
#define elf_backend_grok_psinfo elf32_mips_grok_psinfo
#define elf_backend_grok_freebsd_prstatus \
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 0573e93..dfb3601 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -455,6 +455,12 @@ struct mips_elf_link_hash_table
/* True if we already reported the small-data section overflow. */
bfd_boolean small_data_overflow_reported;
+ /* True if we use the special `__gnu_absolute_zero' symbol. */
+ bfd_boolean use_absolute_zero;
+
+ /* True if we have been configured for a GNU target. */
+ bfd_boolean gnu_target;
+
/* Shortcuts to some dynamic sections, or NULL if they are not
being used. */
asection *srelplt2;
@@ -3977,7 +3983,7 @@ mips_elf_record_global_got_symbol (struct elf_link_hash_entry *h,
{
case STV_INTERNAL:
case STV_HIDDEN:
- _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
+ _bfd_mips_elf_hide_symbol (info, h, TRUE);
break;
}
if (!bfd_elf_link_record_dynamic_symbol (info, h))
@@ -4434,6 +4440,12 @@ mips_use_local_got_p (struct bfd_link_info *info,
if (h->root.dynindx == -1)
return TRUE;
+ /* Absolute symbols, if ever they need a GOT entry, cannot ever go
+ to the local GOT, as they would be implicitly relocated by the
+ base address by the dynamic loader. */
+ if (bfd_is_abs_symbol (&h->root.root))
+ return FALSE;
+
/* Symbols that bind locally can (and in the case of forced-local
symbols, must) live in the local GOT. */
if (h->got_only_for_calls
@@ -5234,6 +5246,24 @@ mips_elf_relocation_needs_la25_stub (bfd *input_bfd, int r_type,
}
}
+/* Obtain the field relocated by RELOCATION. */
+
+static bfd_vma
+mips_elf_obtain_contents (reloc_howto_type *howto,
+ const Elf_Internal_Rela *relocation,
+ bfd *input_bfd, bfd_byte *contents)
+{
+ bfd_vma x = 0;
+ bfd_byte *location = contents + relocation->r_offset;
+ unsigned int size = bfd_get_reloc_size (howto);
+
+ /* Obtain the bytes. */
+ if (size != 0)
+ x = bfd_get (8 * size, input_bfd, location);
+
+ return x;
+}
+
/* Store the field relocated by RELOCATION. */
static void
@@ -5249,6 +5279,52 @@ mips_elf_store_contents (reloc_howto_type *howto,
bfd_put (8 * size, input_bfd, x, location);
}
+/* Try to patch a load from GOT instruction in CONTENTS pointed to by
+ RELOCATION described by HOWTO, with a move of 0 to the load target
+ register, returning TRUE if that is successful and FALSE otherwise.
+ If DOIT is FALSE, then only determine it patching is possible and
+ return status without actually changing CONTENTS.
+*/
+
+static bfd_boolean
+mips_elf_nullify_got_load (bfd *input_bfd, bfd_byte *contents,
+ const Elf_Internal_Rela *relocation,
+ reloc_howto_type *howto, bfd_boolean doit)
+{
+ int r_type = ELF_R_TYPE (input_bfd, relocation->r_info);
+ bfd_byte *location = contents + relocation->r_offset;
+ bfd_boolean nullified = TRUE;
+ bfd_vma x;
+
+ _bfd_mips_elf_reloc_unshuffle (input_bfd, r_type, FALSE, location);
+
+ /* Obtain the current value. */
+ x = mips_elf_obtain_contents (howto, relocation, input_bfd, contents);
+
+ /* Note that in the unshuffled MIPS16 encoding RX is at bits [21:19]
+ while RY is at bits [18:16] of the combined 32-bit instruction word. */
+ if (mips16_reloc_p (r_type)
+ && (((x >> 22) & 0x3ff) == 0x3d3 /* LW */
+ || ((x >> 22) & 0x3ff) == 0x3c7)) /* LD */
+ x = (0x3cd << 22) | (x & (7 << 16)) << 3; /* LI */
+ else if (micromips_reloc_p (r_type)
+ && ((x >> 26) & 0x37) == 0x37) /* LW/LD */
+ x = (0xc << 26) | (x & (0x1f << 21)); /* ADDIU */
+ else if (((x >> 26) & 0x3f) == 0x23 /* LW */
+ || ((x >> 26) & 0x3f) == 0x37) /* LD */
+ x = (0x9 << 26) | (x & (0x1f << 16)); /* ADDIU */
+ else
+ nullified = FALSE;
+
+ /* Put the value into the output. */
+ if (doit && nullified)
+ mips_elf_store_contents (howto, relocation, input_bfd, contents, x);
+
+ _bfd_mips_elf_reloc_shuffle (input_bfd, r_type, FALSE, location);
+
+ return nullified;
+}
+
/* Calculate the value produced by the RELOCATION (which comes from
the INPUT_BFD). The ADDEND is the addend to use for this
RELOCATION; RELOCATION->R_ADDEND is ignored.
@@ -5264,7 +5340,7 @@ mips_elf_store_contents (reloc_howto_type *howto,
static bfd_reloc_status_type
mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
- asection *input_section,
+ asection *input_section, bfd_byte *contents,
struct bfd_link_info *info,
const Elf_Internal_Rela *relocation,
bfd_vma addend, reloc_howto_type *howto,
@@ -5660,6 +5736,48 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
&& (target_is_16_bit_code_p
|| target_is_micromips_code_p))));
+ resolved_to_zero = (h != NULL
+ && UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->root));
+
+ switch (r_type)
+ {
+ case R_MIPS16_CALL16:
+ case R_MIPS16_GOT16:
+ case R_MIPS_CALL16:
+ case R_MIPS_GOT16:
+ case R_MIPS_GOT_PAGE:
+ case R_MIPS_GOT_DISP:
+ case R_MIPS_GOT_LO16:
+ case R_MIPS_CALL_LO16:
+ case R_MICROMIPS_CALL16:
+ case R_MICROMIPS_GOT16:
+ case R_MICROMIPS_GOT_PAGE:
+ case R_MICROMIPS_GOT_DISP:
+ case R_MICROMIPS_GOT_LO16:
+ case R_MICROMIPS_CALL_LO16:
+ if (resolved_to_zero
+ && !bfd_link_relocatable (info)
+ && mips_elf_nullify_got_load (input_bfd, contents,
+ relocation, howto, TRUE))
+ return bfd_reloc_continue;
+
+ /* Fall through. */
+ case R_MIPS_GOT_HI16:
+ case R_MIPS_CALL_HI16:
+ case R_MICROMIPS_GOT_HI16:
+ case R_MICROMIPS_CALL_HI16:
+ if (resolved_to_zero
+ && htab->use_absolute_zero
+ && bfd_link_pic (info))
+ {
+ /* Redirect to the special `__gnu_absolute_zero' symbol. */
+ h = mips_elf_link_hash_lookup (htab, "__gnu_absolute_zero",
+ FALSE, FALSE, FALSE);
+ BFD_ASSERT (h != NULL);
+ }
+ break;
+ }
+
local_p = (h == NULL || mips_use_local_got_p (info, h));
gp0 = _bfd_get_gp_value (input_bfd);
@@ -5680,10 +5798,6 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
addend = 0;
}
- resolved_to_zero = (h != NULL
- && UNDEFWEAK_NO_DYNAMIC_RELOC (info,
- &h->root));
-
/* If we haven't already determined the GOT offset, and we're going
to need it, get it now. */
switch (r_type)
@@ -6323,24 +6437,6 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
return overflowed_p ? bfd_reloc_overflow : bfd_reloc_ok;
}
-/* Obtain the field relocated by RELOCATION. */
-
-static bfd_vma
-mips_elf_obtain_contents (reloc_howto_type *howto,
- const Elf_Internal_Rela *relocation,
- bfd *input_bfd, bfd_byte *contents)
-{
- bfd_vma x = 0;
- bfd_byte *location = contents + relocation->r_offset;
- unsigned int size = bfd_get_reloc_size (howto);
-
- /* Obtain the bytes. */
- if (size != 0)
- x = bfd_get (8 * size, input_bfd, location);
-
- return x;
-}
-
/* It has been determined that the result of the RELOCATION is the
VALUE. Use HOWTO to place VALUE into the output file at the
appropriate position. The SECTION is the section to which the
@@ -8109,6 +8205,47 @@ mips_elf_make_plt_record (bfd *abfd)
return entry;
}
+/* Define the special `__gnu_absolute_zero' symbol. We only need this
+ for PIC code, as otherwise there is no load-time relocation involved
+ and local GOT entries whose value is zero at static link time will
+ retain their value at load time. */
+
+static bfd_boolean
+mips_elf_define_absolute_zero (bfd *abfd, struct bfd_link_info *info,
+ struct mips_elf_link_hash_table *htab,
+ unsigned int r_type)
+{
+ union
+ {
+ struct elf_link_hash_entry *eh;
+ struct bfd_link_hash_entry *bh;
+ }
+ hzero;
+
+ BFD_ASSERT (!htab->use_absolute_zero);
+ BFD_ASSERT (bfd_link_pic (info));
+
+ hzero.bh = NULL;
+ if (!_bfd_generic_link_add_one_symbol (info, abfd, "__gnu_absolute_zero",
+ BSF_GLOBAL, bfd_abs_section_ptr, 0,
+ NULL, FALSE, FALSE, &hzero.bh))
+ return FALSE;
+
+ BFD_ASSERT (hzero.bh != NULL);
+ hzero.eh->size = 0;
+ hzero.eh->type = STT_NOTYPE;
+ hzero.eh->other = STV_PROTECTED;
+ hzero.eh->def_regular = 1;
+ hzero.eh->non_elf = 0;
+
+ if (!mips_elf_record_global_got_symbol (hzero.eh, abfd, info, TRUE, r_type))
+ return FALSE;
+
+ htab->use_absolute_zero = TRUE;
+
+ return TRUE;
+}
+
/* Look through the relocs for a section during the first phase, and
allocate space in the global offset table and record the need for
standard MIPS and compressed procedure linkage table entries. */
@@ -8461,24 +8598,52 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
/* Fall through. */
case R_MIPS_GOT16:
- case R_MIPS_GOT_HI16:
case R_MIPS_GOT_LO16:
case R_MIPS_GOT_PAGE:
- case R_MIPS_GOT_OFST:
case R_MIPS_GOT_DISP:
+ case R_MIPS16_GOT16:
+ case R_MICROMIPS_GOT16:
+ case R_MICROMIPS_GOT_LO16:
+ case R_MICROMIPS_GOT_PAGE:
+ case R_MICROMIPS_GOT_DISP:
+ /* If we have a symbol that will resolve to zero at static link
+ time and it is used by a GOT relocation applied to code we
+ cannot relax to an immediate zero load, then we will be using
+ the special `__gnu_absolute_zero' symbol whose value is zero
+ at dynamic load time. We ignore HI16-type GOT relocations at
+ this stage, because their handling will depend entirely on
+ the corresponding LO16-type GOT relocation. */
+ if (!call_hi16_reloc_p (r_type)
+ && h != NULL
+ && bfd_link_pic (info)
+ && !htab->use_absolute_zero
+ && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
+ {
+ bfd_boolean rel_reloc;
+
+ if (!mips_elf_get_section_contents (abfd, sec, &contents))
+ return FALSE;
+
+ rel_reloc = mips_elf_rel_relocation_p (abfd, sec, relocs, rel);
+ howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, !rel_reloc);
+
+ if (!mips_elf_nullify_got_load (abfd, contents, rel, howto,
+ FALSE))
+ if (!mips_elf_define_absolute_zero (abfd, info, htab, r_type))
+ return FALSE;
+ }
+
+ /* Fall through. */
+ case R_MIPS_GOT_HI16:
+ case R_MIPS_GOT_OFST:
case R_MIPS_TLS_GOTTPREL:
case R_MIPS_TLS_GD:
case R_MIPS_TLS_LDM:
- case R_MIPS16_GOT16:
case R_MIPS16_TLS_GOTTPREL:
case R_MIPS16_TLS_GD:
case R_MIPS16_TLS_LDM:
- case R_MICROMIPS_GOT16:
case R_MICROMIPS_GOT_HI16:
- case R_MICROMIPS_GOT_LO16:
- case R_MICROMIPS_GOT_PAGE:
case R_MICROMIPS_GOT_OFST:
- case R_MICROMIPS_GOT_DISP:
case R_MICROMIPS_TLS_GOTTPREL:
case R_MICROMIPS_TLS_GD:
case R_MICROMIPS_TLS_LDM:
@@ -10280,10 +10445,10 @@ _bfd_mips_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
/* Figure out what value we are supposed to relocate. */
switch (mips_elf_calculate_relocation (output_bfd, input_bfd,
- input_section, info, rel,
- addend, howto, local_syms,
- local_sections, &value,
- &name, &cross_mode_jump_p,
+ input_section, contents,
+ info, rel, addend, howto,
+ local_syms, local_sections,
+ &value, &name, &cross_mode_jump_p,
use_saved_addend_p))
{
case bfd_reloc_continue:
@@ -12589,6 +12754,27 @@ _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info *info,
if (indmips->has_nonpic_branches)
dirmips->has_nonpic_branches = TRUE;
}
+
+/* Take care of the special `__gnu_absolute_zero' symbol and ignore attempts
+ to hide it. It has to remain global (it will also be protected) so as to
+ be assigned a global GOT entry, which will then remain unchanged at load
+ time. */
+
+void
+_bfd_mips_elf_hide_symbol (struct bfd_link_info *info,
+ struct elf_link_hash_entry *entry,
+ bfd_boolean force_local)
+{
+ struct mips_elf_link_hash_table *htab;
+
+ htab = mips_elf_hash_table (info);
+ BFD_ASSERT (htab != NULL);
+ if (htab->use_absolute_zero
+ && strcmp (entry->root.root.string, "__gnu_absolute_zero") == 0)
+ return;
+
+ _bfd_elf_link_hash_hide_symbol (info, entry, force_local);
+}
#define PDR_SIZE 32
@@ -13991,14 +14177,17 @@ _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info *info)
/* A function that the linker calls to select between all or only
32-bit microMIPS instructions, and between making or ignoring
- branch relocation checks for invalid transitions between ISA modes. */
+ branch relocation checks for invalid transitions between ISA modes.
+ Also record whether we have been configured for a GNU target. */
void
_bfd_mips_elf_linker_flags (struct bfd_link_info *info, bfd_boolean insn32,
- bfd_boolean ignore_branch_isa)
+ bfd_boolean ignore_branch_isa,
+ bfd_boolean gnu_target)
{
mips_elf_hash_table (info)->insn32 = insn32;
mips_elf_hash_table (info)->ignore_branch_isa = ignore_branch_isa;
+ mips_elf_hash_table (info)->gnu_target = gnu_target;
}
/* Structure for saying that BFD machine EXTENSION extends BASE. */
@@ -16271,13 +16460,14 @@ enum
MIPS_LIBC_ABI_MIPS_PLT,
MIPS_LIBC_ABI_UNIQUE,
MIPS_LIBC_ABI_MIPS_O32_FP64,
+ MIPS_LIBC_ABI_ABSOLUTE,
MIPS_LIBC_ABI_MAX
};
void
_bfd_mips_post_process_headers (bfd *abfd, struct bfd_link_info *link_info)
{
- struct mips_elf_link_hash_table *htab;
+ struct mips_elf_link_hash_table *htab = NULL;
Elf_Internal_Ehdr *i_ehdrp;
i_ehdrp = elf_elfheader (abfd);
@@ -16285,15 +16475,19 @@ _bfd_mips_post_process_headers (bfd *abfd, struct bfd_link_info *link_info)
{
htab = mips_elf_hash_table (link_info);
BFD_ASSERT (htab != NULL);
-
- if (htab->use_plts_and_copy_relocs && !htab->is_vxworks)
- i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_MIPS_PLT;
}
+ if (htab != NULL && htab->use_plts_and_copy_relocs && !htab->is_vxworks)
+ i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_MIPS_PLT;
+
if (mips_elf_tdata (abfd)->abiflags.fp_abi == Val_GNU_MIPS_ABI_FP_64
|| mips_elf_tdata (abfd)->abiflags.fp_abi == Val_GNU_MIPS_ABI_FP_64A)
i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_MIPS_O32_FP64;
+ /* Mark that we need support for absolute symbols in the dynamic loader. */
+ if (htab != NULL && htab->use_absolute_zero && htab->gnu_target)
+ i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_ABSOLUTE;
+
_bfd_elf_post_process_headers (abfd, link_info);
}
diff --git a/bfd/elfxx-mips.h b/bfd/elfxx-mips.h
index b8ea714..9652fbc 100644
--- a/bfd/elfxx-mips.h
+++ b/bfd/elfxx-mips.h
@@ -81,6 +81,8 @@ extern asection * _bfd_mips_elf_gc_mark_hook
extern void _bfd_mips_elf_copy_indirect_symbol
(struct bfd_link_info *, struct elf_link_hash_entry *,
struct elf_link_hash_entry *);
+extern void _bfd_mips_elf_hide_symbol
+ (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
extern bfd_boolean _bfd_mips_elf_ignore_discarded_relocs
(asection *);
extern bfd_boolean _bfd_mips_elf_is_target_special_symbol
@@ -147,7 +149,7 @@ extern bfd_boolean _bfd_mips_elf_ignore_undef_symbol
extern void _bfd_mips_elf_use_plts_and_copy_relocs
(struct bfd_link_info *);
extern void _bfd_mips_elf_linker_flags
- (struct bfd_link_info *, bfd_boolean, bfd_boolean);
+ (struct bfd_link_info *, bfd_boolean, bfd_boolean, bfd_boolean);
extern bfd_boolean _bfd_mips_elf_init_stubs
(struct bfd_link_info *,
asection *(*) (const char *, asection *, asection *));
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 528ba3c..f4f1d2e 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,4 +1,13 @@
2018-09-14 Maciej W. Rozycki <macro@mips.com>
+
+ PR ld/21375
+ * emultempl/mipself.em: Set `gnu_target' according to ${target}.
+ (mips_create_output_section_statements): Update call to
+ `_bfd_mips_elf_linker_flags'.
+ * testsuite/ld-mips-elf/pr21334.s: Use LWL rather than LW.
+ * testsuite/ld-mips-elf/pr21334.dd: Update accordingly.
+
+2018-09-14 Maciej W. Rozycki <macro@mips.com>
Maciej W. Rozycki <macro@linux-mips.org>
* ldexp.c (fold_binary): Always make the result of SEGMENT_START
diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em
index c7c1642..ec8a086c 100644
--- a/ld/emultempl/mipself.em
+++ b/ld/emultempl/mipself.em
@@ -18,6 +18,15 @@
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
+case ${target} in
+ *-*-*gnu*)
+ gnu_target=TRUE
+ ;;
+ *)
+ gnu_target=FALSE
+ ;;
+esac
+
fragment <<EOF
#include "ldctor.h"
@@ -203,7 +212,8 @@ mips_create_output_section_statements (void)
htab = elf_hash_table (&link_info);
if (is_elf_hash_table (htab) && is_mips_elf (link_info.output_bfd))
- _bfd_mips_elf_linker_flags (&link_info, insn32, ignore_branch_isa);
+ _bfd_mips_elf_linker_flags (&link_info, insn32, ignore_branch_isa,
+ ${gnu_target});
if (is_mips_elf (link_info.output_bfd))
_bfd_mips_elf_init_stubs (&link_info, mips_add_stub_section);
diff --git a/ld/testsuite/ld-mips-elf/pr21334.dd b/ld/testsuite/ld-mips-elf/pr21334.dd
index 01c3718..60f0553 100644
--- a/ld/testsuite/ld-mips-elf/pr21334.dd
+++ b/ld/testsuite/ld-mips-elf/pr21334.dd
@@ -4,7 +4,7 @@ Disassembly of section \.text:
[0-9a-f]+ <[^>]*> lui gp,0x1
[0-9a-f]+ <[^>]*> addiu gp,gp,-32736
[0-9a-f]+ <[^>]*> addu gp,gp,t9
-[0-9a-f]+ <[^>]*> lw v0,-32744\(gp\)
+[0-9a-f]+ <[^>]*> lwl v0,-32744\(gp\)
[0-9a-f]+ <[^>]*> jr ra
[0-9a-f]+ <[^>]*> addiu v0,v0,4
\.\.\.
diff --git a/ld/testsuite/ld-mips-elf/pr21334.s b/ld/testsuite/ld-mips-elf/pr21334.s
index d62c18c..7f26318 100644
--- a/ld/testsuite/ld-mips-elf/pr21334.s
+++ b/ld/testsuite/ld-mips-elf/pr21334.s
@@ -8,7 +8,7 @@ foo:
.mask 0x00000000, 0
.fmask 0x00000000, 0
.cpload $25
- lw $2, %got(bar)($28)
+ lwl $2, %got(bar)($28)
jr $31
addiu $2, $2, 4
.end foo