This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[committed] MIPS: Preset EF_MIPS_ABI2 with n32 ELF objects
- From: "Maciej W. Rozycki" <macro at mips dot com>
- To: <binutils at sourceware dot org>
- Cc: Djordje Todorovic <djordje dot todorovic at rt-rk dot com>
- Date: Mon, 23 Oct 2017 15:43:44 +0100
- Subject: [committed] MIPS: Preset EF_MIPS_ABI2 with n32 ELF objects
- Authentication-results: sourceware.org; auth=none
From: Maciej W. Rozycki <macro@imgtec.com>
Fix a bug in MIPS n32 ELF object file generation and make such objects
consistent with the n32 BFD requested, by presetting the EF_MIPS_ABI2
flag in the `e_flags' member of the newly created ELF file header, as it
is this flag that tells n32 objects apart from o32 objects.
This flag will then stay set through to output file generation for
writers such as GAS or GDB's `generate-core-file' command. Readers will
overwrite the whole of `e_flags' along with the rest of the ELF file
header in `elf_swap_ehdr_in' and then verify in `mips_elf_n32_object_p'
that the flag is still set before accepting an input file as an n32
object.
The issue was discovered with GDB's `generate-core-file' command making
o32 core files out of n32 debuggees.
bfd/
* elfn32-mips.c (mips_elf_n32_mkobject): New prototype and
function.
(bfd_elf32_mkobject): Use `mips_elf_n32_mkobject' rather than
`_bfd_mips_elf_mkobject'.
gas/
* config/tc-mips.c (mips_elf_final_processing): Don't set
EF_MIPS_ABI2 in `e_flags'.
---
I considered implementing this in `bfd_elf32_mkcorefile' only, however I
concluded setting the flag in `bfd_elf32_mkobject' for all objects would
be cleaner as it is inherent to n32 objects.
Regression-tested with my usual binutils MIPS targets, and also natively
with GDB and the `mips-mti-linux-gnu' target across the three ABIs (o32,
n32, n64). Applied.
Maciej
---
bfd/elfn32-mips.c | 19 ++++++++++++++++++-
gas/config/tc-mips.c | 4 +---
2 files changed, 19 insertions(+), 4 deletions(-)
binutils-mips-bfd-n32-e-flags-abi2-init.diff
Index: binutils/bfd/elfn32-mips.c
===================================================================
--- binutils.orig/bfd/elfn32-mips.c 2017-10-21 19:32:31.333279119 +0100
+++ binutils/bfd/elfn32-mips.c 2017-10-22 01:43:53.460896961 +0100
@@ -84,6 +84,8 @@ static bfd_boolean elf_n32_mips_grok_fre
(bfd *, Elf_Internal_Note *);
static irix_compat_t elf_n32_mips_irix_compat
(bfd *);
+static bfd_boolean mips_elf_n32_mkobject
+ (bfd *);
extern const bfd_target mips_elf32_n_be_vec;
extern const bfd_target mips_elf32_n_le_vec;
@@ -3643,6 +3645,21 @@ elf_n32_mips_irix_compat (bfd *abfd)
return ict_none;
}
+/* Make an n32 MIPS object. We need to set the n32 ABI flag in
+ `e_flags' to tell the object apart from an o32 object. */
+
+static bfd_boolean
+mips_elf_n32_mkobject (bfd *abfd)
+{
+ bfd_boolean ret;
+
+ ret = _bfd_mips_elf_mkobject (abfd);
+ if (ret)
+ elf_elfheader (abfd)->e_flags |= EF_MIPS_ABI2;
+
+ return ret;
+}
+
/* 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 = {
@@ -3775,7 +3792,7 @@ static const struct ecoff_debug_swap mip
#define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
#define bfd_elf32_bfd_print_private_bfd_data \
_bfd_mips_elf_print_private_bfd_data
-#define bfd_elf32_mkobject _bfd_mips_elf_mkobject
+#define bfd_elf32_mkobject mips_elf_n32_mkobject
/* Support for SGI-ish mips targets using n32 ABI. */
Index: binutils/gas/config/tc-mips.c
===================================================================
--- binutils.orig/gas/config/tc-mips.c 2017-10-21 19:32:31.360855476 +0100
+++ binutils/gas/config/tc-mips.c 2017-10-22 01:42:51.167424227 +0100
@@ -19140,10 +19140,8 @@ mips_elf_final_processing (void)
else
elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
}
- else if (mips_abi == N32_ABI)
- elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
- /* Nothing to do for N64_ABI. */
+ /* Nothing to do for N32_ABI or N64_ABI. */
if (mips_32bitmode)
elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;