This is the mail archive of the binutils@sourceware.org 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]

Fix GOT[1] for MIPS n64


The MIPS psABI reserves GOT[0] for the runtime resolver, but as an
extension, GNU ld also reserves GOT[1].  We set the top bit of GOT[1]
to indicate that it has been reserved.  The GNU dynamic loader checks
that this bit is set before using the entry; if the entry hasn't been
reserved, the resolver uses a slower fallback instead.  (FWIW, uClibc's
loader uses the entry unconditionally, presumably because it doesn't
have as much historical baggage to support.)

However, the static linker gets this wrong for n64: it sets bit 31
instead of bit 63.  The GNU dynamic loader therefore treats GOT[1]
like any other local GOT entry.

Tested on mips{,64}{,el}-linux-gnu and mips64{,el}-elf.  OK to install?

Richard


bfd/
	* elfxx-mips.c (MIPS_ELF_GNU_GOT1_MASK): New macro.
	(_bfd_mips_elf_finish_dynamic_sections): Use it instead of 0x80000000.

ld/testsuite/
	* ld-mips-elf/elf-rel-got-n64-linux.d: Expect bit 63 rather than
	bit 31 of the second GOT entry to be set.
	* ld-mips-elf/elf-rel-got-n64.d: Likewise.
	* ld-mips-elf/elf-rel-xgot-n64-linux.d: Likewise.
	* ld-mips-elf/elf-rel-xgot-n64.d: Likewise.

Index: bfd/elfxx-mips.c
===================================================================
--- bfd/elfxx-mips.c	2008-03-17 18:29:21.000000000 +0000
+++ bfd/elfxx-mips.c	2008-03-19 19:31:08.000000000 +0000
@@ -648,6 +648,12 @@ #define MINUS_TWO	(((bfd_vma)0) - 2)
 #define MIPS_RESERVED_GOTNO(INFO) \
   (mips_elf_hash_table (INFO)->is_vxworks ? 3 : 2)
 
+/* The value to write into got[1] for SVR4 targets, to identify it is
+   a GNU object.  The dynamic linker can then use got[1] to store the
+   module pointer.  */
+#define MIPS_ELF_GNU_GOT1_MASK(abfd) \
+  ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
+
 /* The offset of $gp from the beginning of the .got section.  */
 #define ELF_MIPS_GP_OFFSET(INFO) \
   (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
@@ -9230,7 +9236,7 @@ _bfd_mips_elf_finish_dynamic_sections (b
 	     runtime. The second entry will be used by some runtime loaders.
 	     This isn't the case of IRIX rld.  */
 	  MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0, sgot->contents);
-	  MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000,
+	  MIPS_ELF_PUT_WORD (output_bfd, MIPS_ELF_GNU_GOT1_MASK (output_bfd),
 			     sgot->contents + MIPS_ELF_GOT_SIZE (output_bfd));
 	}
 
@@ -9254,7 +9260,8 @@ _bfd_mips_elf_finish_dynamic_sections (b
 
 	  MIPS_ELF_PUT_WORD (output_bfd, 0, sgot->contents
 			     + index++ * MIPS_ELF_GOT_SIZE (output_bfd));
-	  MIPS_ELF_PUT_WORD (output_bfd, 0x80000000, sgot->contents
+	  MIPS_ELF_PUT_WORD (output_bfd, MIPS_ELF_GNU_GOT1_MASK (output_bfd),
+			     sgot->contents
 			     + index++ * MIPS_ELF_GOT_SIZE (output_bfd));
 
 	  if (! info->shared)
Index: ld/testsuite/ld-mips-elf/elf-rel-got-n64-linux.d
===================================================================
--- ld/testsuite/ld-mips-elf/elf-rel-got-n64-linux.d	2008-03-13 10:15:06.000000000 +0000
+++ ld/testsuite/ld-mips-elf/elf-rel-got-n64-linux.d	2008-03-19 19:31:08.000000000 +0000
@@ -294,7 +294,8 @@ Disassembly of section \.got:
 
 00000001200105e0 <_GLOBAL_OFFSET_TABLE_>:
 	\.\.\.
-   1200105ec:	80000000 	.*
+   1200105e8:	80000000 	.*
+   1200105ec:	00000000 	.*
    1200105f0:	00000001 	.*
    1200105f4:	20010000 	.*
    1200105f8:	00000001 	.*
Index: ld/testsuite/ld-mips-elf/elf-rel-got-n64.d
===================================================================
--- ld/testsuite/ld-mips-elf/elf-rel-got-n64.d	2008-03-13 10:15:06.000000000 +0000
+++ ld/testsuite/ld-mips-elf/elf-rel-got-n64.d	2008-03-19 19:31:08.000000000 +0000
@@ -293,7 +293,8 @@ Disassembly of section \.got:
 
 00000000101005e0 <_GLOBAL_OFFSET_TABLE_>:
 	\.\.\.
-    101005ec:	80000000 	.*
+    101005e8:	80000000 	.*
+    101005ec:	00000000 	.*
     101005f0:	00000000 	.*
     101005f4:	1010052c 	.*
     101005f8:	00000000 	.*
Index: ld/testsuite/ld-mips-elf/elf-rel-xgot-n64-linux.d
===================================================================
--- ld/testsuite/ld-mips-elf/elf-rel-xgot-n64-linux.d	2008-03-13 10:15:06.000000000 +0000
+++ ld/testsuite/ld-mips-elf/elf-rel-xgot-n64-linux.d	2008-03-19 19:31:08.000000000 +0000
@@ -418,7 +418,8 @@ Disassembly of section \.got:
 
 00000001200107d0 <_GLOBAL_OFFSET_TABLE_>:
 	\.\.\.
-   1200107dc:	80000000 	.*
+   1200107d8:	80000000 	.*
+   1200107dc:	00000000 	.*
    1200107e0:	00000001 	.*
    1200107e4:	20010000 	.*
    1200107e8:	00000001 	.*
Index: ld/testsuite/ld-mips-elf/elf-rel-xgot-n64.d
===================================================================
--- ld/testsuite/ld-mips-elf/elf-rel-xgot-n64.d	2008-03-13 10:15:06.000000000 +0000
+++ ld/testsuite/ld-mips-elf/elf-rel-xgot-n64.d	2008-03-19 19:31:08.000000000 +0000
@@ -417,7 +417,8 @@ Disassembly of section \.got:
 
 00000000101007d0 <_GLOBAL_OFFSET_TABLE_>:
 	\.\.\.
-    101007dc:	80000000 	.*
+    101007d8:	80000000 	.*
+    101007dc:	00000000 	.*
     101007e0:	00000000 	.*
     101007e4:	10100000 	.*
     101007e8:	00000000 	.*


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