This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] MIPS/ELF: Fixes for external R_MIPS_LITERAL relocations


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]