* [PATCH] MIPS/BFD: Handle MIPS16 GOT16 and GPREL16 relocs correctly
@ 2010-07-26 10:51 Maciej W. Rozycki
2010-07-27 18:45 ` Richard Sandiford
0 siblings, 1 reply; 3+ messages in thread
From: Maciej W. Rozycki @ 2010-07-26 10:51 UTC (permalink / raw)
To: binutils; +Cc: Richard Sandiford, Catherine Moore, gnu-mips-sgxx
Hi,
While making microMIPS changes I have come across several places where
MIPS16 GOT16 and GPREL16 relocs are not recognised where their standard
MIPS counterpars are. This is a bug, because MIPS16 relocs are by
definition handled the same as their standard MIPS counterparts and
separate relocs have only been defined because of the odd different layout
of relocatable fields in MIPS16 instructions.
Regression-tested succesfully on mips-sde-elf and mips-linux-gnu targets.
2010-07-26 Maciej W. Rozycki <macro@codesourcery.com>
bfd/
* elfxx-mips.h: Include "elf/mips.h".
(gprel16_reloc_p): New inline function.
* elfxx-mips.c (_bfd_mips_elf_check_relocs)
[R_MIPS16_GOT16, R_MIPS_GOT16, R_MIPS_GOT_HI16, R_MIPS_GOT_LO16]:
Use got16_reloc_p.
(_bfd_mips_elf_relocate_section)[bfd_reloc_overflow]: Use
gprel16_reloc_p.
* elf32-mips.c (mips_info_to_howto_rel): Likewise.
* elfn32-mips.c (mips_info_to_howto_rel): Likewise.
OK to apply?
Maciej
binutils-mips-gp16.diff
Index: binutils-fsf-trunk-quilt/bfd/elfxx-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elfxx-mips.c 2010-07-24 02:25:04.000000000 +0100
+++ binutils-fsf-trunk-quilt/bfd/elfxx-mips.c 2010-07-24 02:25:13.000000000 +0100
@@ -7727,7 +7727,7 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, FALSE);
addend = mips_elf_read_rel_addend (abfd, rel,
howto, contents);
- if (r_type == R_MIPS_GOT16)
+ if (got16_reloc_p (r_type))
mips_elf_add_lo16_rel_addend (abfd, rel, rel_end,
contents, &addend);
else
@@ -9196,7 +9196,7 @@ _bfd_mips_elf_relocate_section (bfd *out
BFD_ASSERT (htab != NULL);
BFD_ASSERT (name != NULL);
if (!htab->small_data_overflow_reported
- && (howto->type == R_MIPS_GPREL16
+ && (gprel16_reloc_p (howto->type)
|| howto->type == R_MIPS_LITERAL))
{
msg = _("small-data section exceeds 64KB;"
Index: binutils-fsf-trunk-quilt/bfd/elf32-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elf32-mips.c 2010-07-24 02:25:04.000000000 +0100
+++ binutils-fsf-trunk-quilt/bfd/elf32-mips.c 2010-07-24 02:25:13.000000000 +0100
@@ -1422,8 +1422,7 @@ mips_info_to_howto_rel (bfd *abfd, arele
when we do the relocation, because the symbol manipulations done
by the linker may cause us to lose track of the input BFD. */
if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
- && (r_type == (unsigned int) R_MIPS_GPREL16
- || r_type == (unsigned int) R_MIPS_LITERAL))
+ && (gprel16_reloc_p (r_type) || r_type == (unsigned int) R_MIPS_LITERAL))
cache_ptr->addend = elf_gp (abfd);
}
Index: binutils-fsf-trunk-quilt/bfd/elfxx-mips.h
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elfxx-mips.h 2010-07-24 02:25:04.000000000 +0100
+++ binutils-fsf-trunk-quilt/bfd/elfxx-mips.h 2010-07-24 02:25:13.000000000 +0100
@@ -21,6 +21,7 @@
#include "elf/common.h"
#include "elf/internal.h"
+#include "elf/mips.h"
extern bfd_boolean _bfd_mips_elf_new_section_hook
(bfd *, asection *);
@@ -153,6 +154,12 @@ extern const struct bfd_elf_special_sect
extern bfd_boolean _bfd_mips_elf_common_definition (Elf_Internal_Sym *);
+static inline bfd_boolean
+gprel16_reloc_p (unsigned int r_type)
+{
+ return r_type == R_MIPS_GPREL16 || r_type == R_MIPS16_GPREL;
+}
+
#define elf_backend_common_definition _bfd_mips_elf_common_definition
#define elf_backend_name_local_section_symbols \
_bfd_mips_elf_name_local_section_symbols
Index: binutils-fsf-trunk-quilt/bfd/elfn32-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elfn32-mips.c 2010-07-24 02:25:13.000000000 +0100
+++ binutils-fsf-trunk-quilt/bfd/elfn32-mips.c 2010-07-24 02:25:13.000000000 +0100
@@ -2259,8 +2259,7 @@ mips_info_to_howto_rel (bfd *abfd, arele
when we do the relocation, because the symbol manipulations done
by the linker may cause us to lose track of the input BFD. */
if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
- && (r_type == (unsigned int) R_MIPS_GPREL16
- || r_type == (unsigned int) R_MIPS_LITERAL))
+ && (gprel16_reloc_p (r_type) || r_type == (unsigned int) R_MIPS_LITERAL))
cache_ptr->addend = elf_gp (abfd);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MIPS/BFD: Handle MIPS16 GOT16 and GPREL16 relocs correctly
2010-07-26 10:51 [PATCH] MIPS/BFD: Handle MIPS16 GOT16 and GPREL16 relocs correctly Maciej W. Rozycki
@ 2010-07-27 18:45 ` Richard Sandiford
2010-07-27 21:28 ` Maciej W. Rozycki
0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2010-07-27 18:45 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: binutils, Catherine Moore, gnu-mips-sgxx
"Maciej W. Rozycki" <macro@codesourcery.com> writes:
> 2010-07-26 Maciej W. Rozycki <macro@codesourcery.com>
>
> bfd/
> * elfxx-mips.h: Include "elf/mips.h".
> (gprel16_reloc_p): New inline function.
> * elfxx-mips.c (_bfd_mips_elf_check_relocs)
> [R_MIPS16_GOT16, R_MIPS_GOT16, R_MIPS_GOT_HI16, R_MIPS_GOT_LO16]:
> Use got16_reloc_p.
> (_bfd_mips_elf_relocate_section)[bfd_reloc_overflow]: Use
> gprel16_reloc_p.
> * elf32-mips.c (mips_info_to_howto_rel): Likewise.
> * elfn32-mips.c (mips_info_to_howto_rel): Likewise.
OK, thanks. No idea how I managed to miss the GOT16 one. ;-(
Richard
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MIPS/BFD: Handle MIPS16 GOT16 and GPREL16 relocs correctly
2010-07-27 18:45 ` Richard Sandiford
@ 2010-07-27 21:28 ` Maciej W. Rozycki
0 siblings, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2010-07-27 21:28 UTC (permalink / raw)
To: Richard Sandiford; +Cc: binutils, Catherine Moore, gnu-mips-sgxx
On Tue, 27 Jul 2010, Richard Sandiford wrote:
> > * elfxx-mips.h: Include "elf/mips.h".
> > (gprel16_reloc_p): New inline function.
> > * elfxx-mips.c (_bfd_mips_elf_check_relocs)
> > [R_MIPS16_GOT16, R_MIPS_GOT16, R_MIPS_GOT_HI16, R_MIPS_GOT_LO16]:
> > Use got16_reloc_p.
> > (_bfd_mips_elf_relocate_section)[bfd_reloc_overflow]: Use
> > gprel16_reloc_p.
> > * elf32-mips.c (mips_info_to_howto_rel): Likewise.
> > * elfn32-mips.c (mips_info_to_howto_rel): Likewise.
>
> OK, thanks. No idea how I managed to miss the GOT16 one. ;-(
That's a merge error of some kind probably. Overall we're under-tested.
:( No surprise given the number of corner cases. And MIPS16 support
seems to suffer particularly badly -- we've got just a couple of test
cases AFAICT. And the GCC or GDB test suites do not cover binutils
functionality too well -- regressions of this kind if they happen there,
mostly trigger by accident.
Maciej
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-27 21:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-26 10:51 [PATCH] MIPS/BFD: Handle MIPS16 GOT16 and GPREL16 relocs correctly Maciej W. Rozycki
2010-07-27 18:45 ` Richard Sandiford
2010-07-27 21:28 ` Maciej W. Rozycki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).