[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patches] SPARC64 dynamic linker crash undoing prelinking



I have committed this patch to EGLIBC trunk to fix a SPARC64 dynamic 
linker bug.  The bug and fix are explained in more detail at 
<http://sourceware.org/ml/libc-alpha/2009-02/msg00044.html>.

Index: sysdeps/sparc/sparc64/dl-machine.h
===================================================================
--- sysdeps/sparc/sparc64/dl-machine.h	(revision 7930)
+++ sysdeps/sparc/sparc64/dl-machine.h	(working copy)
@@ -352,7 +352,7 @@
 	    {
 	      if (__builtin_expect (rela->r_addend, 0) != 0)
 		{
-                  Elf64_Addr slot = ((rela->r_offset + 0x400
+		  Elf64_Addr slot = ((rela->r_offset + l->l_addr + 0x400
 				      - (Elf64_Addr) plt)
 				     / 0x1400) * 0x1400
 				    + (Elf64_Addr) plt - 0x400;
@@ -360,20 +360,23 @@
 		  unsigned int first_ldx = *(unsigned int *)(slot + 12);
 		  Elf64_Addr ptr = slot + (first_ldx & 0xfff) + 4;
 
-		  *(Elf64_Addr *) rela->r_offset
+		  *(Elf64_Addr *) (rela->r_offset + l->l_addr)
 		    = (Elf64_Addr) plt
-		      - (slot + ((rela->r_offset - ptr) / 8) * 24 + 4);
+		      - (slot + ((rela->r_offset + l->l_addr - ptr) / 8) * 24
+			 + 4);
 		  ++rela;
 		  continue;
 		}
 
-	      *(unsigned int *) rela->r_offset
-		= 0x03000000 | (rela->r_offset - (Elf64_Addr) plt);
-	      *(unsigned int *) (rela->r_offset + 4)
-		= 0x30680000 | ((((Elf64_Addr) plt + 32
-				  - rela->r_offset - 4) >> 2) & 0x7ffff);
-	      __asm __volatile ("flush %0" : : "r" (rela->r_offset));
-	      __asm __volatile ("flush %0+4" : : "r" (rela->r_offset));
+	      *(unsigned int *) (rela->r_offset + l->l_addr)
+		= 0x03000000 | (rela->r_offset + l->l_addr - (Elf64_Addr) plt);
+	      *(unsigned int *) (rela->r_offset + l->l_addr + 4)
+		= 0x30680000 | ((((Elf64_Addr) plt + 32 - rela->r_offset
+				  - l->l_addr - 4) >> 2) & 0x7ffff);
+	      __asm __volatile ("flush %0" : : "r" (rela->r_offset
+						    + l->l_addr));
+	      __asm __volatile ("flush %0+4" : : "r" (rela->r_offset
+						      + l->l_addr));
 	      ++rela;
 	    }
 	}
Index: ChangeLog.eglibc
===================================================================
--- ChangeLog.eglibc	(revision 7930)
+++ ChangeLog.eglibc	(working copy)
@@ -1,3 +1,8 @@
+2009-02-14  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
+
+	* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_runtime_setup):
+	Adjust rela->r_offset by l->l_addr when rewriting PLT.
+
 2009-01-26  Julian Brown  <julian@xxxxxxxxxxxxxxxx>
 
 	* elf/Makefile ($(objpfx)ld.so): Add sed pattern to recognize text

-- 
Joseph S. Myers
joseph@xxxxxxxxxxxxxxxx