PowerPC64 stub names

Alan Modra amodra@gmail.com
Thu Jan 31 06:30:00 GMT 2013


This patch fixes a long-standing but innocuous bug in elf64-ppc.c.

The code in ppc_stub_name to trim off a trailing "+0" was ineffective
due to missing a "len = strlen (stub_name);" statement, or, as I do
here, use the return of sprintf to give the length.  

bfd/
	* elf64-ppc.c (ppc_stub_name): Trim off trailing "+0".
ld/testsuite/
	* ld-powerpc/tlsexe.d: Update for changed stub names.
	* ld-powerpc/tlsexe.r: Likewise.
	* ld-powerpc/tlsexetoc.d: Likewise.
	* ld-powerpc/tlsexetoc.r: Likewise.
	* ld-powerpc/tlsso.d: Likewise.
	* ld-powerpc/tlsso.r: Likewise.
	* ld-powerpc/tlstocso.d: Likewise.
	* ld-powerpc/tlstocso.r: Likewise.

Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.401
diff -u -p -r1.401 elf64-ppc.c
--- bfd/elf64-ppc.c	30 Jan 2013 22:31:31 -0000	1.401
+++ bfd/elf64-ppc.c	31 Jan 2013 04:15:48 -0000
@@ -4074,7 +4074,7 @@ ppc_stub_name (const asection *input_sec
 	       const Elf_Internal_Rela *rel)
 {
   char *stub_name;
-  bfd_size_type len;
+  ssize_t len;
 
   /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
      offsets from a sym as a branch target?  In fact, we could
@@ -4088,10 +4088,10 @@ ppc_stub_name (const asection *input_sec
       if (stub_name == NULL)
 	return stub_name;
 
-      sprintf (stub_name, "%08x.%s+%x",
-	       input_section->id & 0xffffffff,
-	       h->elf.root.root.string,
-	       (int) rel->r_addend & 0xffffffff);
+      len = sprintf (stub_name, "%08x.%s+%x",
+		     input_section->id & 0xffffffff,
+		     h->elf.root.root.string,
+		     (int) rel->r_addend & 0xffffffff);
     }
   else
     {
@@ -4100,13 +4100,13 @@ ppc_stub_name (const asection *input_sec
       if (stub_name == NULL)
 	return stub_name;
 
-      sprintf (stub_name, "%08x.%x:%x+%x",
-	       input_section->id & 0xffffffff,
-	       sym_sec->id & 0xffffffff,
-	       (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
-	       (int) rel->r_addend & 0xffffffff);
+      len = sprintf (stub_name, "%08x.%x:%x+%x",
+		     input_section->id & 0xffffffff,
+		     sym_sec->id & 0xffffffff,
+		     (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
+		     (int) rel->r_addend & 0xffffffff);
     }
-  if (stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
+  if (len > 2 && stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
     stub_name[len - 2] = 0;
   return stub_name;
 }
Index: ld/testsuite/ld-powerpc/tlsexe.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexe.d,v
retrieving revision 1.12
diff -u -p -r1.12 tlsexe.d
--- ld/testsuite/ld-powerpc/tlsexe.d	23 Nov 2012 03:28:13 -0000	1.12
+++ ld/testsuite/ld-powerpc/tlsexe.d	31 Jan 2013 04:17:31 -0000
@@ -8,7 +8,7 @@
 
 Disassembly of section \.text:
 
-.* <00000010\.plt_call\.__tls_get_addr(|_opt)\+0>:
+.* <00000010\.plt_call\.__tls_get_addr(|_opt)>:
 .*	(e9 63 00 00|00 00 63 e9) 	ld      r11,0\(r3\)
 .*	(e9 83 00 08|08 00 83 e9) 	ld      r12,8\(r3\)
 .*	(7c 60 1b 78|78 1b 60 7c) 	mr      r0,r3
Index: ld/testsuite/ld-powerpc/tlsexe.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexe.r,v
retrieving revision 1.32
diff -u -p -r1.32 tlsexe.r
--- ld/testsuite/ld-powerpc/tlsexe.r	29 Oct 2012 09:25:53 -0000	1.32
+++ ld/testsuite/ld-powerpc/tlsexe.r	31 Jan 2013 04:17:31 -0000
@@ -96,8 +96,8 @@ Symbol table '\.symtab' contains [0-9]+ 
 .* TLS +LOCAL +DEFAULT +8 le5
 .* (FUNC|NOTYPE) +LOCAL +DEFAULT +UND \.__tls_get_addr(|_opt)
 .* FILE +LOCAL +DEFAULT +ABS .*
+.* NOTYPE +LOCAL +DEFAULT +7 00000010\.plt_call\.__tls_get_addr(|_opt)
 .* OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
-.* NOTYPE +LOCAL +DEFAULT +7 00000010\.plt_call\.__tls_get_addr(|_opt)\+0
 .* NOTYPE +LOCAL +DEFAULT +7 __glink_PLTresolve
 .* GLOBAL +DEFAULT +UND gd
 .* GLOBAL +DEFAULT +9 le0
Index: ld/testsuite/ld-powerpc/tlsexetoc.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexetoc.d,v
retrieving revision 1.13
diff -u -p -r1.13 tlsexetoc.d
--- ld/testsuite/ld-powerpc/tlsexetoc.d	23 Nov 2012 03:28:13 -0000	1.13
+++ ld/testsuite/ld-powerpc/tlsexetoc.d	31 Jan 2013 04:17:31 -0000
@@ -8,7 +8,7 @@
 
 Disassembly of section \.text:
 
-.* <00000010\.plt_call\.__tls_get_addr(|_opt)\+0>:
+.* <00000010\.plt_call\.__tls_get_addr(|_opt)>:
 .*	(e9 63 00 00|00 00 63 e9) 	ld      r11,0\(r3\)
 .*	(e9 83 00 08|08 00 83 e9) 	ld      r12,8\(r3\)
 .*	(7c 60 1b 78|78 1b 60 7c) 	mr      r0,r3
Index: ld/testsuite/ld-powerpc/tlsexetoc.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexetoc.r,v
retrieving revision 1.33
diff -u -p -r1.33 tlsexetoc.r
--- ld/testsuite/ld-powerpc/tlsexetoc.r	29 Oct 2012 09:25:53 -0000	1.33
+++ ld/testsuite/ld-powerpc/tlsexetoc.r	31 Jan 2013 04:17:31 -0000
@@ -96,8 +96,8 @@ Symbol table '\.symtab' contains [0-9]+ 
 .* NOTYPE +LOCAL +DEFAULT +11 \.Lie0
 .* (FUNC|NOTYPE) +LOCAL +DEFAULT +UND \.__tls_get_addr(|_opt)
 .* FILE +LOCAL +DEFAULT +ABS .*
+.* NOTYPE +LOCAL +DEFAULT +7 00000010\.plt_call\.__tls_get_addr(|_opt)
 .* OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
-.* NOTYPE +LOCAL +DEFAULT +7 00000010\.plt_call\.__tls_get_addr(|_opt)\+0
 .* NOTYPE +LOCAL +DEFAULT +7 __glink_PLTresolve
 .* TLS +GLOBAL +DEFAULT +UND gd
 .* TLS +GLOBAL +DEFAULT +9 le0
Index: ld/testsuite/ld-powerpc/tlsso.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso.d,v
retrieving revision 1.13
diff -u -p -r1.13 tlsso.d
--- ld/testsuite/ld-powerpc/tlsso.d	15 Jan 2013 06:13:26 -0000	1.13
+++ ld/testsuite/ld-powerpc/tlsso.d	31 Jan 2013 04:17:31 -0000
@@ -8,7 +8,7 @@
 
 Disassembly of section \.text:
 
-.* <00000010\.plt_call\.__tls_get_addr(|_opt)\+0>:
+.* <00000010\.plt_call\.__tls_get_addr(|_opt)>:
 .*	(f8 41 00 28|28 00 41 f8) 	std     r2,40\(r1\)
 .*	(e9 62 80 78|78 80 62 e9) 	ld      r11,-32648\(r2\)
 .*	(7d 69 03 a6|a6 03 69 7d) 	mtctr   r11
Index: ld/testsuite/ld-powerpc/tlsso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso.r,v
retrieving revision 1.35
diff -u -p -r1.35 tlsso.r
--- ld/testsuite/ld-powerpc/tlsso.r	15 Jan 2013 06:13:26 -0000	1.35
+++ ld/testsuite/ld-powerpc/tlsso.r	31 Jan 2013 04:17:31 -0000
@@ -111,7 +111,7 @@ Symbol table '\.symtab' contains [0-9]+ 
 .* NOTYPE +LOCAL +DEFAULT +UND \.__tls_get_addr
 .* FILE +LOCAL +DEFAULT +ABS .*
 .* OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
-.* NOTYPE +LOCAL +DEFAULT +6 00000010\.plt_call\.__tls_get_addr\+0
+.* NOTYPE +LOCAL +DEFAULT +6 00000010\.plt_call\.__tls_get_addr
 .* NOTYPE +LOCAL +DEFAULT +6 __glink_PLTresolve
 .* TLS +GLOBAL +DEFAULT +UND gd
 .* TLS +GLOBAL +DEFAULT +8 le0
Index: ld/testsuite/ld-powerpc/tlstocso.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstocso.d,v
retrieving revision 1.12
diff -u -p -r1.12 tlstocso.d
--- ld/testsuite/ld-powerpc/tlstocso.d	15 Jan 2013 06:13:26 -0000	1.12
+++ ld/testsuite/ld-powerpc/tlstocso.d	31 Jan 2013 04:17:31 -0000
@@ -8,7 +8,7 @@
 
 Disassembly of section \.text:
 
-.* <00000010\.plt_call\.__tls_get_addr(|_opt)\+0>:
+.* <00000010\.plt_call\.__tls_get_addr(|_opt)>:
 .*	(f8 41 00 28|28 00 41 f8) 	std     r2,40\(r1\)
 .*	(e9 62 80 70|70 80 62 e9) 	ld      r11,-32656\(r2\)
 .*	(7d 69 03 a6|a6 03 69 7d) 	mtctr   r11
Index: ld/testsuite/ld-powerpc/tlstocso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstocso.r,v
retrieving revision 1.29
diff -u -p -r1.29 tlstocso.r
--- ld/testsuite/ld-powerpc/tlstocso.r	15 Jun 2012 15:13:37 -0000	1.29
+++ ld/testsuite/ld-powerpc/tlstocso.r	31 Jan 2013 04:17:31 -0000
@@ -107,7 +107,7 @@ Symbol table '\.symtab' contains [0-9]+ 
 .* NOTYPE +LOCAL +DEFAULT +UND \.__tls_get_addr
 .* FILE +LOCAL +DEFAULT +ABS .*
 .* OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
-.* NOTYPE +LOCAL +DEFAULT +6 00000010\.plt_call\.__tls_get_addr\+0
+.* NOTYPE +LOCAL +DEFAULT +6 00000010\.plt_call\.__tls_get_addr
 .* NOTYPE +LOCAL +DEFAULT +6 __glink_PLTresolve
 .* TLS +GLOBAL +DEFAULT +UND gd
 .* TLS +GLOBAL +DEFAULT +8 le0

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list