This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] MIPS/BFD: Clean up 32-bit MIPS ELF object_p methods
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: <binutils at sourceware dot org>
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Thu, 29 Nov 2012 21:06:39 +0000
- Subject: [PATCH] MIPS/BFD: Clean up 32-bit MIPS ELF object_p methods
Hi,
Minor nit, 32-bit MIPS ELF object_p methods set some BFD properties
before finally deciding it is not compatible with the object-code format
handled by the respective backend.
This is in practice safe as bfd_preserve_restore will later on revert the
changes made to arch_info and tdata, however I think it is not
particularly clean as the condition to decide about the compatibility does
not depend on these properties to have been preset. Additionally the two
methods are not consistent with each other as one sets elf_bad_symtab/SGI
symbol sorting order only, while the other initialises all data before
giving up.
I propose therefore the change below making the two methods return right
away when the format is found incompatible. Additionally some minor
formatting adjustments are made making the two consistent with each other
(and also the 64-bit MIPS ELF version not otherwise considered here).
No regressions across the usual MIPS targets. OK to apply?
2012-11-29 Maciej W. Rozycki <macro@codesourcery.com>
bfd/
* elf32-mips.c (mips_elf32_object_p): Return right away when the
ABI is not compatible.
* elfn32-mips.c (mips_elf_n32_object_p): Likewise.
Maciej
binutils-bfd-mips32-mach.diff
Index: binutils-fsf-trunk-quilt/bfd/elf32-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elf32-mips.c 2012-11-29 11:37:24.000000000 +0000
+++ binutils-fsf-trunk-quilt/bfd/elf32-mips.c 2012-11-29 15:51:15.821422474 +0000
@@ -2145,18 +2145,17 @@ mips_elf32_object_p (bfd *abfd)
{
unsigned long mach;
+ if (ABI_N32_P (abfd))
+ return FALSE;
+
/* Irix 5 and 6 are broken. Object file symbol tables are not always
sorted correctly such that local symbols precede global symbols,
and the sh_info field in the symbol table is not always right. */
if (SGI_COMPAT (abfd))
elf_bad_symtab (abfd) = TRUE;
- if (ABI_N32_P (abfd))
- return FALSE;
-
mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
-
return TRUE;
}
Index: binutils-fsf-trunk-quilt/bfd/elfn32-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elfn32-mips.c 2012-11-29 11:37:24.000000000 +0000
+++ binutils-fsf-trunk-quilt/bfd/elfn32-mips.c 2012-11-29 15:53:08.140512045 +0000
@@ -3165,6 +3165,9 @@ mips_elf_n32_object_p (bfd *abfd)
{
unsigned long mach;
+ if (!ABI_N32_P (abfd))
+ return FALSE;
+
/* Irix 5 and 6 are broken. Object file symbol tables are not always
sorted correctly such that local symbols precede global symbols,
and the sh_info field in the symbol table is not always right. */
@@ -3173,10 +3176,6 @@ mips_elf_n32_object_p (bfd *abfd)
mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
-
- if (! ABI_N32_P(abfd))
- return FALSE;
-
return TRUE;
}