public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations
@ 2005-02-08  3:34 Maciej W. Rozycki
  2005-02-09  9:23 ` Thiemo Seufer
  0 siblings, 1 reply; 5+ messages in thread
From: Maciej W. Rozycki @ 2005-02-08  3:34 UTC (permalink / raw)
  To: binutils; +Cc: Maciej W. Rozycki

Hello,

 According to the SVR4 MIPS ABI supplement and the "64-bit ELF Object File 
Specification" document R_MIPS_LITERAL relocations are only defined for 
local symbols.  BFD currently allows them for all symbols.

 Here is a fix -- tested for the mips64-linux-gnu, mipsel-linux-gnu and 
mips64el-elf targets with no regressions.

2005-02-07  Maciej W. Rozycki  <macro@mips.com>

	* elf32-mips.c (_bfd_mips_elf32_gprel16_reloc): Reject 
	R_MIPS_LITERAL relocations for external symbols.
	* elf64-mips.c (mips_elf64_literal_reloc): Likewise.
	* elfn32-mips.c (mips_elf_literal_reloc): Likewise.

 OK to apply (or should we have mips_elf_literal_reloc() calling 
_bfd_mips_elf32_gprel16_reloc() after the check for elf32-mips.c now)?

  Maciej

binutils-2.15.94-20050202-mips-bfd-literal.patch
diff -up --recursive --new-file binutils-2.15.94-20050202.macro/bfd/elf32-mips.c binutils-2.15.94-20050202/bfd/elf32-mips.c
--- binutils-2.15.94-20050202.macro/bfd/elf32-mips.c	2004-06-29 13:46:30.000000000 +0000
+++ binutils-2.15.94-20050202/bfd/elf32-mips.c	2005-02-07 15:36:52.000000000 +0000
@@ -770,6 +770,17 @@ _bfd_mips_elf32_gprel16_reloc (bfd *abfd
   bfd_reloc_status_type ret;
   bfd_vma gp;
 
+  /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
+  if (reloc_entry->howto->type == R_MIPS_LITERAL
+      && output_bfd != NULL
+      && (symbol->flags & BSF_SECTION_SYM) == 0
+      && (symbol->flags & BSF_LOCAL) != 0)
+    {
+      *error_message = (char *)
+	_("literal relocation occurs for an external symbol");
+      return bfd_reloc_outofrange;
+    }
+
   if (output_bfd != NULL)
     relocatable = TRUE;
   else
diff -up --recursive --new-file binutils-2.15.94-20050202.macro/bfd/elf64-mips.c binutils-2.15.94-20050202/bfd/elf64-mips.c
--- binutils-2.15.94-20050202.macro/bfd/elf64-mips.c	2005-01-31 23:13:24.000000000 +0000
+++ binutils-2.15.94-20050202/bfd/elf64-mips.c	2005-02-07 15:29:28.000000000 +0000
@@ -1543,14 +1543,14 @@ mips_elf64_literal_reloc (bfd *abfd, are
   bfd_reloc_status_type ret;
   bfd_vma gp;
 
-  /* If we're relocating, and this is an external symbol, we don't
-     want to change anything.  */
+  /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
   if (output_bfd != NULL
       && (symbol->flags & BSF_SECTION_SYM) == 0
       && (symbol->flags & BSF_LOCAL) != 0)
     {
-      reloc_entry->address += input_section->output_offset;
-      return bfd_reloc_ok;
+      *error_message = (char *)
+	_("literal relocation occurs for an external symbol");
+      return bfd_reloc_outofrange;
     }
 
   /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
diff -up --recursive --new-file binutils-2.15.94-20050202.macro/bfd/elfn32-mips.c binutils-2.15.94-20050202/bfd/elfn32-mips.c
--- binutils-2.15.94-20050202.macro/bfd/elfn32-mips.c	2004-12-09 06:32:41.000000000 +0000
+++ binutils-2.15.94-20050202/bfd/elfn32-mips.c	2005-02-07 15:29:16.000000000 +0000
@@ -1348,6 +1348,16 @@ mips_elf_literal_reloc (bfd *abfd, arele
   bfd_reloc_status_type ret;
   bfd_vma gp;
 
+  /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
+  if (output_bfd != NULL
+      && (symbol->flags & BSF_SECTION_SYM) == 0
+      && (symbol->flags & BSF_LOCAL) != 0)
+    {
+      *error_message = (char *)
+	_("literal relocation occurs for an external symbol");
+      return bfd_reloc_outofrange;
+    }
+
   /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
   if (output_bfd != NULL)
     relocatable = TRUE;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations
  2005-02-08  3:34 [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations Maciej W. Rozycki
@ 2005-02-09  9:23 ` Thiemo Seufer
  2005-02-11  3:50   ` Maciej W. Rozycki
  0 siblings, 1 reply; 5+ messages in thread
From: Thiemo Seufer @ 2005-02-09  9:23 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: binutils

Maciej W. Rozycki wrote:
> Hello,
> 
>  According to the SVR4 MIPS ABI supplement and the "64-bit ELF Object File 
> Specification" document R_MIPS_LITERAL relocations are only defined for 
> local symbols.  BFD currently allows them for all symbols.
> 
>  Here is a fix -- tested for the mips64-linux-gnu, mipsel-linux-gnu and 
> mips64el-elf targets with no regressions.
> 
> 2005-02-07  Maciej W. Rozycki  <macro@mips.com>
> 
> 	* elf32-mips.c (_bfd_mips_elf32_gprel16_reloc): Reject 
> 	R_MIPS_LITERAL relocations for external symbols.
> 	* elf64-mips.c (mips_elf64_literal_reloc): Likewise.
> 	* elfn32-mips.c (mips_elf_literal_reloc): Likewise.
> 
>  OK to apply (or should we have mips_elf_literal_reloc() calling 
> _bfd_mips_elf32_gprel16_reloc() after the check for elf32-mips.c now)?

The idea was to give R_MIPS_LITERAL its own handler function because its
values are supposed to get merged. I didn't do so for elf32-mips.c
because there's a weird special casing of _bfd_mips_elf32_gprel16_reloc
in elfxx-mips.c

Btw, R_MIPS16_GPREL seems also to have inconsistencies.


Thiemo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations
  2005-02-09  9:23 ` Thiemo Seufer
@ 2005-02-11  3:50   ` Maciej W. Rozycki
  2005-02-11 14:18     ` Thiemo Seufer
  0 siblings, 1 reply; 5+ messages in thread
From: Maciej W. Rozycki @ 2005-02-11  3:50 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils

On Wed, 9 Feb 2005, Thiemo Seufer wrote:

> > 2005-02-07  Maciej W. Rozycki  <macro@mips.com>
> > 
> > 	* elf32-mips.c (_bfd_mips_elf32_gprel16_reloc): Reject 
> > 	R_MIPS_LITERAL relocations for external symbols.
> > 	* elf64-mips.c (mips_elf64_literal_reloc): Likewise.
> > 	* elfn32-mips.c (mips_elf_literal_reloc): Likewise.
> > 
> >  OK to apply (or should we have mips_elf_literal_reloc() calling 
> > _bfd_mips_elf32_gprel16_reloc() after the check for elf32-mips.c now)?
> 
> The idea was to give R_MIPS_LITERAL its own handler function because its
> values are supposed to get merged. I didn't do so for elf32-mips.c
> because there's a weird special casing of _bfd_mips_elf32_gprel16_reloc
> in elfxx-mips.c

 Well, that looks scary and fragile and is probably well worth 
investigation.

> Btw, R_MIPS16_GPREL seems also to have inconsistencies.

 What specifically?  I'm currently having a look into the MIPS16 
relocation stuff, so I may as well investigate this problem.

 Finally, what about the patch -- is it OK or is there anything wrong with 
it?

  Maciej

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations
  2005-02-11  3:50   ` Maciej W. Rozycki
@ 2005-02-11 14:18     ` Thiemo Seufer
  2005-02-12  0:24       ` Maciej W. Rozycki
  0 siblings, 1 reply; 5+ messages in thread
From: Thiemo Seufer @ 2005-02-11 14:18 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: binutils

Maciej W. Rozycki wrote:
> On Wed, 9 Feb 2005, Thiemo Seufer wrote:
> 
> > > 2005-02-07  Maciej W. Rozycki  <macro@mips.com>
> > > 
> > > 	* elf32-mips.c (_bfd_mips_elf32_gprel16_reloc): Reject 
> > > 	R_MIPS_LITERAL relocations for external symbols.
> > > 	* elf64-mips.c (mips_elf64_literal_reloc): Likewise.
> > > 	* elfn32-mips.c (mips_elf_literal_reloc): Likewise.
> > > 
> > >  OK to apply (or should we have mips_elf_literal_reloc() calling 
> > > _bfd_mips_elf32_gprel16_reloc() after the check for elf32-mips.c now)?
> > 
> > The idea was to give R_MIPS_LITERAL its own handler function because its
> > values are supposed to get merged. I didn't do so for elf32-mips.c
> > because there's a weird special casing of _bfd_mips_elf32_gprel16_reloc
> > in elfxx-mips.c
> 
>  Well, that looks scary and fragile and is probably well worth 
> investigation.
> 
> > Btw, R_MIPS16_GPREL seems also to have inconsistencies.
> 
>  What specifically?  I'm currently having a look into the MIPS16 
> relocation stuff, so I may as well investigate this problem.

This was already addressed.

>  Finally, what about the patch -- is it OK or is there anything wrong with 
> it?

The patch is ok, I only hoped for some means to get rid of that scary
part in elfxx-mips.c. :-)


Thiemo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations
  2005-02-11 14:18     ` Thiemo Seufer
@ 2005-02-12  0:24       ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2005-02-12  0:24 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils

On Fri, 11 Feb 2005, Thiemo Seufer wrote:

> The patch is ok, I only hoped for some means to get rid of that scary
> part in elfxx-mips.c. :-)

 I'll see if I am able to have a look into it.

  Maciej

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-02-11 22:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-08  3:34 [PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations Maciej W. Rozycki
2005-02-09  9:23 ` Thiemo Seufer
2005-02-11  3:50   ` Maciej W. Rozycki
2005-02-11 14:18     ` Thiemo Seufer
2005-02-12  0:24       ` 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).