[PATCH]: Add sparc gotdata reloc infrastructure.

David Miller davem@davemloft.net
Sun Apr 13 06:23:00 GMT 2008


This adds enough infrastructure for binutils to support gotdata
relocations on Sparc.  It doesn't yet, however, add code to perform
the code optimizations possible using these relocations.  I will add
those later as a follow-on patch.

Basically the idea with these things is that the compiler can emit
(assuming %l7 == &_GLOBAL_OFFSET_TABLE_[0]):

	sethi	%gdop_hix22(symbol), %reg1
	xor	%reg1, %gdop_lox10(symbol), %reg1
	ld	[%l7 + %reg1], %reg2, %gdop(symbol)

Those three instruction will cause the assembler to generate
relocations R_SPARC_GOTDATA_OP_HIX22, R_SPARC_GOTDATA_OP_LOX10, and
R_SPARC_GOTDATA_OP respectively.

When the linker sees this, and it knows that the symbol in the final
object is within +/- 2GB of _GLOBAL_OFFSET_TABLE_ and it knows the
final relative offset, it can transform the above into:

	sethi	%hix22(symbol - _GLOBAL_OFFSET_TABLE_), %reg1
	xor	%reg1, %lox10(symbol - _GLOBAL_OFFSET_TABLE_), %reg1
	add	%l7, %reg1, %reg2

For now, however, the BFD linker simply leaves this as a normal full
unoptimized GOT sequence.

I plan next to add support to GCC so that it can emit the above
sequences.  I will also add similar unoptimized, and eventual
optimized, support for gotdata relocs into my gold sparc target.

Regression tested on sparc{,64}-unknown-linux-gnu

bfd/

2008-04-12  David S. Miller  <davem@davemloft.net>

	* reloc.c (BFD_RELOC_SPARC_GOTDATA_HIX22,
	BFD_RELOC_SPARC_GOTDATA_LOX10, BFD_RELOC_SPARC_GOTDATA_OP_HIX22,
	BFD_RELOC_SPARC_GOTDATA_OP_LOX10, BFD_RELOC_SPARC_GOTDATA_OP): New.
	* libbfd.h: Regnerate.
	* bfd-in2.h: Regenerate.
	* elfxx-sparc.c (_bfd_sparc_elf_howto_table): Add entries for
	GOTDATA relocations.
	(sparc_reloc_map): Likewise.
	(_bfd_sparc_elf_check_relocs): Handle R_SPARC_GOTDATA_* like
	R_SPARC_GOT*.
	(_bfd_sparc_elf_gc_sweep_hook): Likewise.
	(_bfd_sparc_elf_relocate_section): Transform R_SPARC_GOTDATA_HIX22,
	R_SPARC_GOTDATA_LOX10, R_SPARC_GOTDATA_OP_HIX22, and
	R_SPARC_GOTDATA_OP_LOX10 into the equivalent R_SPARC_GOT* reloc.
	Simply ignore R_SPARC_GOTDATA_OP relocations.

Index: bfd/reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.173
diff -u -p -r1.173 reloc.c
--- bfd/reloc.c	20 Feb 2008 15:17:56 -0000	1.173
+++ bfd/reloc.c	12 Apr 2008 09:37:00 -0000
@@ -1830,6 +1830,16 @@ ENUMX
   BFD_RELOC_SPARC_UA32
 ENUMX
   BFD_RELOC_SPARC_UA64
+ENUMX
+  BFD_RELOC_SPARC_GOTDATA_HIX22
+ENUMX
+  BFD_RELOC_SPARC_GOTDATA_LOX10
+ENUMX
+  BFD_RELOC_SPARC_GOTDATA_OP_HIX22
+ENUMX
+  BFD_RELOC_SPARC_GOTDATA_OP_LOX10
+ENUMX
+  BFD_RELOC_SPARC_GOTDATA_OP
 ENUMDOC
   SPARC ELF relocations.  There is probably some overlap with other
   relocation types already defined.
Index: bfd/libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.202
diff -u -p -r1.202 libbfd.h
--- bfd/libbfd.h	28 Mar 2008 06:49:44 -0000	1.202
+++ bfd/libbfd.h	12 Apr 2008 09:37:00 -0000
@@ -862,6 +862,11 @@ static const char *const bfd_reloc_code_
   "BFD_RELOC_SPARC_UA16",
   "BFD_RELOC_SPARC_UA32",
   "BFD_RELOC_SPARC_UA64",
+  "BFD_RELOC_SPARC_GOTDATA_HIX22",
+  "BFD_RELOC_SPARC_GOTDATA_LOX10",
+  "BFD_RELOC_SPARC_GOTDATA_OP_HIX22",
+  "BFD_RELOC_SPARC_GOTDATA_OP_LOX10",
+  "BFD_RELOC_SPARC_GOTDATA_OP",
   "BFD_RELOC_SPARC_BASE13",
   "BFD_RELOC_SPARC_BASE22",
   "BFD_RELOC_SPARC_10",
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.442
diff -u -p -r1.442 bfd-in2.h
--- bfd/bfd-in2.h	28 Mar 2008 06:49:44 -0000	1.442
+++ bfd/bfd-in2.h	12 Apr 2008 09:36:59 -0000
@@ -2399,6 +2399,11 @@ relocation types already defined.  */
   BFD_RELOC_SPARC_UA16,
   BFD_RELOC_SPARC_UA32,
   BFD_RELOC_SPARC_UA64,
+  BFD_RELOC_SPARC_GOTDATA_HIX22,
+  BFD_RELOC_SPARC_GOTDATA_LOX10,
+  BFD_RELOC_SPARC_GOTDATA_OP_HIX22,
+  BFD_RELOC_SPARC_GOTDATA_OP_LOX10,
+  BFD_RELOC_SPARC_GOTDATA_OP,
 
 /* I think these are specific to SPARC a.out (e.g., Sun 4).  */
   BFD_RELOC_SPARC_BASE13,
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.39
diff -u -p -r1.39 elfxx-sparc.c
--- bfd/elfxx-sparc.c	25 Mar 2008 18:56:01 -0000	1.39
+++ bfd/elfxx-sparc.c	12 Apr 2008 09:37:00 -0000
@@ -258,7 +258,12 @@ static reloc_howto_type _bfd_sparc_elf_h
   HOWTO(R_SPARC_TLS_DTPOFF32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF32",FALSE,0,0xffffffff,TRUE),
   HOWTO(R_SPARC_TLS_DTPOFF64,0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF64",FALSE,0,MINUS_ONE,TRUE),
   HOWTO(R_SPARC_TLS_TPOFF32,0,0, 0,FALSE,0,complain_overflow_dont,   bfd_elf_generic_reloc,  "R_SPARC_TLS_TPOFF32",FALSE,0,0x00000000,TRUE),
-  HOWTO(R_SPARC_TLS_TPOFF64,0,0, 0,FALSE,0,complain_overflow_dont,   bfd_elf_generic_reloc,  "R_SPARC_TLS_TPOFF64",FALSE,0,0x00000000,TRUE)
+  HOWTO(R_SPARC_TLS_TPOFF64,0,0, 0,FALSE,0,complain_overflow_dont,   bfd_elf_generic_reloc,  "R_SPARC_TLS_TPOFF64",FALSE,0,0x00000000,TRUE),
+  HOWTO(R_SPARC_GOTDATA_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_GOTDATA_HIX22",FALSE,0,0x003fffff, FALSE),
+  HOWTO(R_SPARC_GOTDATA_LOX10,0,2,0,FALSE,0,complain_overflow_dont,  sparc_elf_lox10_reloc,  "R_SPARC_GOTDATA_LOX10",FALSE,0,0x000003ff, FALSE),
+  HOWTO(R_SPARC_GOTDATA_OP_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_GOTDATA_OP_HIX22",FALSE,0,0x003fffff, FALSE),
+  HOWTO(R_SPARC_GOTDATA_OP_LOX10,0,2,0,FALSE,0,complain_overflow_dont,  sparc_elf_lox10_reloc,  "R_SPARC_GOTDATA_OP_LOX10",FALSE,0,0x000003ff, FALSE),
+  HOWTO(R_SPARC_GOTDATA_OP,0,0, 0,FALSE,0,complain_overflow_dont,   bfd_elf_generic_reloc,  "R_SPARC_GOTDATA_OP",FALSE,0,0x00000000,TRUE),
 };
 static reloc_howto_type sparc_vtinherit_howto =
   HOWTO (R_SPARC_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_SPARC_GNU_VTINHERIT", FALSE,0, 0, FALSE);
@@ -349,6 +354,11 @@ static const struct elf_reloc_map sparc_
   { BFD_RELOC_SPARC_H44, R_SPARC_H44 },
   { BFD_RELOC_SPARC_M44, R_SPARC_M44 },
   { BFD_RELOC_SPARC_L44, R_SPARC_L44 },
+  { BFD_RELOC_SPARC_GOTDATA_HIX22, R_SPARC_GOTDATA_HIX22 },
+  { BFD_RELOC_SPARC_GOTDATA_LOX10, R_SPARC_GOTDATA_LOX10 },
+  { BFD_RELOC_SPARC_GOTDATA_OP_HIX22, R_SPARC_GOTDATA_OP_HIX22 },
+  { BFD_RELOC_SPARC_GOTDATA_OP_LOX10, R_SPARC_GOTDATA_OP_LOX10 },
+  { BFD_RELOC_SPARC_GOTDATA_OP, R_SPARC_GOTDATA_OP },
   { BFD_RELOC_SPARC_REGISTER, R_SPARC_REGISTER },
   { BFD_RELOC_VTABLE_INHERIT, R_SPARC_GNU_VTINHERIT },
   { BFD_RELOC_VTABLE_ENTRY, R_SPARC_GNU_VTENTRY },
@@ -1178,6 +1188,10 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, 
 	case R_SPARC_GOT10:
 	case R_SPARC_GOT13:
 	case R_SPARC_GOT22:
+	case R_SPARC_GOTDATA_HIX22:
+	case R_SPARC_GOTDATA_LOX10:
+	case R_SPARC_GOTDATA_OP_HIX22:
+	case R_SPARC_GOTDATA_OP_LOX10:
 	case R_SPARC_TLS_GD_HI22:
 	case R_SPARC_TLS_GD_LO10:
 	  /* This symbol requires a global offset table entry.  */
@@ -1190,6 +1204,10 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, 
 	      case R_SPARC_GOT10:
 	      case R_SPARC_GOT13:
 	      case R_SPARC_GOT22:
+	      case R_SPARC_GOTDATA_HIX22:
+	      case R_SPARC_GOTDATA_LOX10:
+	      case R_SPARC_GOTDATA_OP_HIX22:
+	      case R_SPARC_GOTDATA_OP_LOX10:
 		tls_type = GOT_NORMAL;
 		break;
 	      case R_SPARC_TLS_GD_HI22:
@@ -1622,6 +1640,10 @@ _bfd_sparc_elf_gc_sweep_hook (bfd *abfd,
 	case R_SPARC_GOT10:
 	case R_SPARC_GOT13:
 	case R_SPARC_GOT22:
+	case R_SPARC_GOTDATA_HIX22:
+	case R_SPARC_GOTDATA_LOX10:
+	case R_SPARC_GOTDATA_OP_HIX22:
+	case R_SPARC_GOTDATA_OP_LOX10:
 	  if (h != NULL)
 	    {
 	      if (h->got.refcount > 0)
@@ -2606,6 +2628,20 @@ _bfd_sparc_elf_relocate_section (bfd *ou
 
       switch (r_type)
 	{
+	case R_SPARC_GOTDATA_HIX22:
+	case R_SPARC_GOTDATA_LOX10:
+	case R_SPARC_GOTDATA_OP_HIX22:
+	case R_SPARC_GOTDATA_OP_LOX10:
+	  /* We don't support these code transformation optimizations
+	     yet, so just leave the sequence alone and treat as
+	     GOT22/GOT10.  */
+	  if (r_type == R_SPARC_GOTDATA_HIX22
+	      || r_type == R_SPARC_GOTDATA_OP_HIX22)
+	    r_type = R_SPARC_GOT22;
+	  else
+	    r_type = R_SPARC_GOT10;
+	  /* Fall through. */
+
 	case R_SPARC_GOT10:
 	case R_SPARC_GOT13:
 	case R_SPARC_GOT22:
@@ -3256,6 +3292,11 @@ _bfd_sparc_elf_relocate_section (bfd *ou
 	    }
 	  continue;
 
+	case R_SPARC_GOTDATA_OP:
+	  /* We don't support gotdata code transformation optimizations
+	     yet, so simply leave the sequence as-is.  */
+	  continue;
+
 	case R_SPARC_TLS_IE_LD:
 	case R_SPARC_TLS_IE_LDX:
 	  if (! info->shared && (h == NULL || h->dynindx == -1))

gas/

2008-04-12  David S. Miller  <davem@davemloft.net>

	* config/tc-sparc.c (sparc_ip): Add support for gotdata mnemonics
	and relocation generation.
	(tc_gen_reloc): Likewise.

Index: gas/config/tc-sparc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sparc.c,v
retrieving revision 1.69
diff -u -p -r1.69 tc-sparc.c
--- gas/config/tc-sparc.c	17 Oct 2007 16:45:55 -0000	1.69
+++ gas/config/tc-sparc.c	12 Apr 2008 09:37:00 -0000
@@ -1860,7 +1860,7 @@ sparc_ip (str, pinsn)
 	    case '\0':		/* End of args.  */
 	      if (s[0] == ',' && s[1] == '%')
 		{
-		  static const struct tls_ops
+		  static const struct ops
 		  {
 		    /* The name as it appears in assembler.  */
 		    char *name;
@@ -1868,10 +1868,10 @@ sparc_ip (str, pinsn)
 		    int len;
 		    /* The reloc this pseudo-op translates to.  */
 		    int reloc;
-		    /* 1 if call.  */
-		    int call;
+		    /* 1 if tls call.  */
+		    int tls_call;
 		  }
-		  tls_ops[] =
+		  ops[] =
 		  {
 		    { "tgd_add", 7, BFD_RELOC_SPARC_TLS_GD_ADD, 0 },
 		    { "tgd_call", 8, BFD_RELOC_SPARC_TLS_GD_CALL, 1 },
@@ -1881,13 +1881,14 @@ sparc_ip (str, pinsn)
 		    { "tie_ldx", 7, BFD_RELOC_SPARC_TLS_IE_LDX, 0 },
 		    { "tie_ld", 6, BFD_RELOC_SPARC_TLS_IE_LD, 0 },
 		    { "tie_add", 7, BFD_RELOC_SPARC_TLS_IE_ADD, 0 },
+		    { "gdop", 4, BFD_RELOC_SPARC_GOTDATA_OP, 0 },
 		    { NULL, 0, 0, 0 }
 		  };
-		  const struct tls_ops *o;
+		  const struct ops *o;
 		  char *s1;
 		  int npar = 0;
 
-		  for (o = tls_ops; o->name; o++)
+		  for (o = ops; o->name; o++)
 		    if (strncmp (s + 2, o->name, o->len) == 0)
 		      break;
 		  if (o->name == NULL)
@@ -1899,14 +1900,14 @@ sparc_ip (str, pinsn)
 		      return special_case;
 		    }
 
-		  if (! o->call && the_insn.reloc != BFD_RELOC_NONE)
+		  if (! o->tls_call && the_insn.reloc != BFD_RELOC_NONE)
 		    {
 		      as_bad (_("Illegal operands: %%%s cannot be used together with other relocs in the insn ()"),
 			      o->name);
 		      return special_case;
 		    }
 
-		  if (o->call
+		  if (o->tls_call
 		      && (the_insn.reloc != BFD_RELOC_32_PCREL_S2
 			  || the_insn.exp.X_add_number != 0
 			  || the_insn.exp.X_add_symbol
@@ -2328,6 +2329,10 @@ sparc_ip (str, pinsn)
 		      { "tie_lo10", 8, BFD_RELOC_SPARC_TLS_IE_LO10, 0, 0 },
 		      { "tle_hix22", 9, BFD_RELOC_SPARC_TLS_LE_HIX22, 0, 0 },
 		      { "tle_lox10", 9, BFD_RELOC_SPARC_TLS_LE_LOX10, 0, 0 },
+		      { "gdop_hix22", 10, BFD_RELOC_SPARC_GOTDATA_OP_HIX22,
+			0, 0 },
+		      { "gdop_lox10", 10, BFD_RELOC_SPARC_GOTDATA_OP_LOX10,
+			0, 0 },
 		      { NULL, 0, 0, 0, 0 }
 		    };
 		    const struct ops *o;
@@ -3445,6 +3450,9 @@ tc_gen_reloc (section, fixp)
     case BFD_RELOC_SPARC_TLS_LE_LOX10:
     case BFD_RELOC_SPARC_TLS_DTPOFF32:
     case BFD_RELOC_SPARC_TLS_DTPOFF64:
+    case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
+    case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
+    case BFD_RELOC_SPARC_GOTDATA_OP:
       code = fixp->fx_r_type;
       break;
     default:

gas/testsuite/
	
2008-04-12  David S. Miller  <davem@davemloft.net>

	* gas/sparc/gotops32.d: New.
	* gas/sparc/gotops32.s: Likewise.
	* gas/sparc/gotops64.d: Likewise.
	* gas/sparc/gotops64.s: Likewise.
	* gas/sparc/sparc.exp: Run new gotdata tests.
	
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ gas/testsuite/gas/sparc/gotop32.d	2008-04-12 02:22:06.000000000 -0700
@@ -0,0 +1,15 @@
+#as: -Av7
+#objdump: -dr
+#name: sparc gotop
+
+.*: +file format .*sparc.*
+
+Disassembly of section .text:
+
+0+ <foo>:
+   0:	23 00 00 00 	sethi  %hi\(0\), %l1
+			0: R_SPARC_GOTDATA_OP_HIX22	.data
+   4:	a2 1c 60 00 	xor  %l1, 0, %l1
+			4: R_SPARC_GOTDATA_OP_LOX10	.data
+   8:	e4 05 c0 11 	ld  \[ %l7 \+ %l1 \], %l2
+			8: R_SPARC_GOTDATA_OP	.data
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ gas/testsuite/gas/sparc/gotop32.s	2008-04-12 02:16:07.000000000 -0700
@@ -0,0 +1,9 @@
+# sparc gotop
+
+	.data
+sym:	.word	0
+
+	.text
+foo:	sethi	%gdop_hix22(sym), %l1
+	xor	%l1, %gdop_lox10(sym), %l1
+	ld	[%l7 + %l1], %l2, %gdop(sym)
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ gas/testsuite/gas/sparc/gotop64.d	2008-04-12 02:21:57.000000000 -0700
@@ -0,0 +1,15 @@
+#as: -64 -Av9
+#objdump: -dr
+#name: sparc64 gotop
+
+.*: +file format .*sparc.*
+
+Disassembly of section .text:
+
+0+ <foo>:
+   0:	23 00 00 00 	sethi  %hi\(0\), %l1
+			0: R_SPARC_GOTDATA_OP_HIX22	.data
+   4:	a2 1c 60 00 	xor  %l1, 0, %l1
+			4: R_SPARC_GOTDATA_OP_LOX10	.data
+   8:	e4 5d c0 11 	ldx  \[ %l7 \+ %l1 \], %l2
+			8: R_SPARC_GOTDATA_OP	.data
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ gas/testsuite/gas/sparc/gotop64.s	2008-04-12 02:16:15.000000000 -0700
@@ -0,0 +1,9 @@
+# sparc64 gotop
+
+	.data
+sym:	.word	0
+
+	.text
+foo:	sethi	%gdop_hix22(sym), %l1
+	xor	%l1, %gdop_lox10(sym), %l1
+	ldx	[%l7 + %l1], %l2, %gdop(sym)
Index: gas/testsuite/gas/sparc/sparc.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/sparc/sparc.exp,v
retrieving revision 1.12
diff -u -p -r1.12 sparc.exp
--- gas/testsuite/gas/sparc/sparc.exp	28 Aug 2007 13:21:56 -0000	1.12
+++ gas/testsuite/gas/sparc/sparc.exp	12 Apr 2008 09:37:00 -0000
@@ -25,13 +25,15 @@ proc sparc_elf_setup { } {
 
 if [istarget sparc*-*-*] {
     run_dump_test "synth"
-    # The next three tests are ELF only.
+    # The next four tests are ELF only.
     sparc_elf_setup
     run_dump_test "unalign"
     sparc_elf_setup
     run_dump_test "pcrel"
     sparc_elf_setup
     run_dump_test "plt"
+    sparc_elf_setup
+    run_dump_test "gotop32"
     if [gas_64_check] {
 	run_dump_test "asi"
 	run_dump_test "membar"
@@ -46,6 +48,7 @@ if [istarget sparc*-*-*] {
 	run_dump_test "reloc64"
 	run_dump_test "pcrel64"
 	run_dump_test "plt64"
+	run_dump_test "gotop64"
     }
     run_dump_test "v9branch1"
     run_dump_test "v9branch2"

ld/testsuite/

2008-04-12  David S. Miller  <davem@davemloft.net>

	* ld-sparc/gotop32.dd: New.
	* ld-sparc/gotop32.rd: Likewise.
	* ld-sparc/gotop32.s: Likewise.
	* ld-sparc/gotop32.sd: Likewise.
	* ld-sparc/gotop32.td: Likewise.
	* ld-sparc/gotop64.dd: Likewise.
	* ld-sparc/gotop64.rd: Likewise.
	* ld-sparc/gotop64.s: Likewise.
	* ld-sparc/gotop64.sd: Likewise.
	* ld-sparc/gotop64.td: Likewise.
	* ld-sparc/sparc.exp: Run new gotdata tests.

Index: ld/testsuite/ld-sparc/sparc.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-sparc/sparc.exp,v
retrieving revision 1.9
diff -u -p -r1.9 sparc.exp
--- ld/testsuite/ld-sparc/sparc.exp	6 Jul 2007 14:09:45 -0000	1.9
+++ ld/testsuite/ld-sparc/sparc.exp	13 Apr 2008 06:04:57 -0000
@@ -89,6 +89,11 @@ set sparctests {
     {"32-bit: TLS in debug sections" "-melf32_sparc"
      "--32" {tlsg32.s}
      {{objdump -sj.debug_foobar tlsg32.sd}} "tlsg32"}
+    {"32-bit: GOTDATA relocations" "-shared -melf32_sparc"
+     "--32 -K PIC" {gotop32.s}
+     {{readelf -WSsrl gotop32.rd} {objdump -drj.text gotop32.dd}
+      {objdump -sj.got gotop32.sd} {objdump -sj.data gotop32.td}}
+     "libgotop32.so"}
 }
 set sparc64tests {
     {"64-bit: TLS -fpic -shared transitions" "-shared -melf64_sparc"
@@ -113,6 +118,11 @@ set sparc64tests {
     {"64-bit: TLS in debug sections" "-melf64_sparc"
      "--64 -Av9" {tlsg64.s}
      {{objdump -sj.debug_foobar tlsg64.sd}} "tlsg64"}
+    {"64-bit: GOTDATA relocations" "-shared -melf64_sparc"
+     "--64 -K PIC" {gotop64.s}
+     {{readelf -WSsrl gotop64.rd} {objdump -drj.text gotop64.dd}
+      {objdump -sj.got gotop64.sd} {objdump -sj.data gotop64.td}}
+     "libgotop64.so"}
 }
 
 if { ![istarget "sparc64-*-elf*"] } {
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop32.dd	2008-04-12 22:50:36.000000000 -0700
@@ -0,0 +1,28 @@
+#source: gotop32.s
+#as: --32 -K PIC
+#ld: -shared -melf32_sparc
+#objdump: -drj.text
+#target: sparc*-*-*
+
+.*: +file format elf32-sparc
+
+Disassembly of section .text:
+00001000 <foo-0x8>:
+ +1000:	81 c3 e0 08 	retl *
+ +1004:	ae 03 c0 17 	add  %o7, %l7, %l7
+
+00001008 <foo>:
+ +1008:	9d e3 bf 98 	save  %sp, -104, %sp
+ +100c:	2f 00 00 44 	sethi  %hi\(0x11000\), %l7
+ +1010:	7f ff ff fc 	call  1000 <_.*>
+ +1014:	ae 05 e0 60 	add  %l7, 0x60, %l7	! 11060 <.*>
+ +1018:	01 00 00 00 	nop *
+ +101c:	23 00 00 04 	sethi  %hi\(0x1000\), %l1
+ +1020:	01 00 00 00 	nop *
+ +1024:	a2 1c 60 04 	xor  %l1, 4, %l1
+ +1028:	01 00 00 00 	nop *
+ +102c:	f0 05 c0 11 	ld  \[ %l7 \+ %l1 \], %i0
+ +1030:	01 00 00 00 	nop *
+ +1034:	81 c7 e0 08 	ret 
+ +1038:	81 e8 00 00 	restore 
+#pass
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop32.rd	2008-04-12 22:45:20.000000000 -0700
@@ -0,0 +1,70 @@
+#source: gotop32.s
+#as: --32 -K PIC
+#ld: -shared -melf32_sparc
+#readelf: -WSsrl
+#target: sparc*-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 0+ +0 +0 +0
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+1000 0+ +AX +0 +0 4096
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+12000 0+2000 0+70 08 +WA +3 +0 +4
+ +\[[ 0-9]+\] .got +PROGBITS +0+12070 0+2070 0+8 04 +WA +0 +0 +4
+ +\[[ 0-9]+\] .data +PROGBITS +0+13000 0+3000 0+1000 00 +WA +0 +0 4096
+ +\[[ 0-9]+\] .shstrtab +.*
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x1000
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz MemSiz +Flg Align
+ +LOAD +0x0+ 0x0+ 0x0+ 0x0+2000 0x0+2000 R E 0x10000
+ +LOAD +0x0+2000 0x0+12000 0x0+12000 0x0+2000 0x0+2000 RW +0x10000
+ +DYNAMIC +0x0+2000 0x0+12000 0x0+12000 0x0+70 0x0+70 RW +0x4
+#...
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
+ Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_SPARC_GLOB_DAT +0+13000 +sym \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION LOCAL +DEFAULT +5 *
+.* SECTION LOCAL +DEFAULT +7 *
+.* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
+.* FUNC +GLOBAL DEFAULT +5 foo
+.* NOTYPE +GLOBAL DEFAULT +ABS _edata
+.* NOTYPE +GLOBAL DEFAULT +ABS _end
+.* NOTYPE +GLOBAL DEFAULT +8 sym
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION LOCAL +DEFAULT +1 *
+.* SECTION LOCAL +DEFAULT +2 *
+.* SECTION LOCAL +DEFAULT +3 *
+.* SECTION LOCAL +DEFAULT +4 *
+.* SECTION LOCAL +DEFAULT +5 *
+.* SECTION LOCAL +DEFAULT +6 *
+.* SECTION LOCAL +DEFAULT +7 *
+.* SECTION LOCAL +DEFAULT +8 *
+.* OBJECT +LOCAL +HIDDEN +ABS _DYNAMIC
+.* OBJECT +LOCAL +HIDDEN +ABS _PROCEDURE_LINKAGE_TABLE_
+.* OBJECT +LOCAL +HIDDEN +ABS _GLOBAL_OFFSET_TABLE_
+.* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
+.* FUNC +GLOBAL DEFAULT +5 foo
+.* NOTYPE +GLOBAL DEFAULT +ABS _edata
+.* NOTYPE +GLOBAL DEFAULT +ABS _end
+.* NOTYPE +GLOBAL DEFAULT +8 sym
+
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop32.s	2008-04-12 22:16:03.000000000 -0700
@@ -0,0 +1,28 @@
+	.data
+	.align	4096
+	.globl	sym
+sym:	.word	0x12345678
+
+	.text
+	.align	4096
+.LLGETPC0:
+	retl
+	add	%o7, %l7, %l7
+
+	.globl	foo
+	.type	foo,#function
+	.proc	04
+foo:
+	save	%sp, -104, %sp
+	sethi	%hi(_GLOBAL_OFFSET_TABLE_-4), %l7
+	call	.LLGETPC0
+	add	%l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
+	nop
+	sethi	%gdop_hix22(sym), %l1
+	nop
+	xor	%l1, %gdop_lox10(sym), %l1
+	nop
+	ld	[%l7 + %l1], %i0, %gdop(sym)
+	nop
+	ret
+	restore
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop32.sd	2008-04-12 22:37:21.000000000 -0700
@@ -0,0 +1,10 @@
+#source: gotop32.s
+#as: --32 -K PIC
+#ld: -shared -melf32_sparc
+#objdump: -sj.got
+#target: sparc*-*-*
+
+.*: +file format elf32-sparc
+
+Contents of section .got:
+ 12070 00012000 00000000                    .*
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop32.td	2008-04-12 22:40:47.000000000 -0700
@@ -0,0 +1,12 @@
+#source: gotop32.s
+#as: --32 -K PIC
+#ld: -shared -melf32_sparc
+#objdump: -sj.data
+#target: sparc*-*-*
+
+.*: +file format elf32-sparc
+
+Contents of section .data:
+ 13000 12345678 00000000 00000000 00000000  .*
+ 13010 00000000 00000000 00000000 00000000  .*
+#pass
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop64.dd	2008-04-12 23:02:31.000000000 -0700
@@ -0,0 +1,28 @@
+#source: gotop64.s
+#as: --64 -K PIC
+#ld: -shared -melf64_sparc
+#objdump: -drj.text
+#target: sparc*-*-*
+
+.*: +file format elf64-sparc
+
+Disassembly of section .text:
+0000000000001000 <foo-0x8>:
+ +1000:	81 c3 e0 08 	retl *
+ +1004:	ae 03 c0 17 	add  %o7, %l7, %l7
+
+0000000000001008 <foo>:
+ +1008:	9d e3 bf 60 	save  %sp, -160, %sp
+ +100c:	2f 00 04 04 	sethi  %hi\(0x101000\), %l7
+ +1010:	7f ff ff fc 	call  1000 <_.*>
+ +1014:	ae 05 e0 d0 	add  %l7, 0xd0, %l7	! 1010d0 <.*>
+ +1018:	01 00 00 00 	nop *
+ +101c:	23 00 00 08 	sethi  %hi\(0x2000\), %l1
+ +1020:	01 00 00 00 	nop *
+ +1024:	a2 1c 60 08 	xor  %l1, 8, %l1
+ +1028:	01 00 00 00 	nop *
+ +102c:	f0 5d c0 11 	ldx  \[ %l7 \+ %l1 \], %i0
+ +1030:	01 00 00 00 	nop *
+ +1034:	81 c7 e0 08 	ret 
+ +1038:	81 e8 00 00 	restore 
+#pass
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop64.rd	2008-04-12 22:59:05.000000000 -0700
@@ -0,0 +1,70 @@
+#source: gotop64.s
+#as: --64 -K PIC
+#ld: -shared -melf64_sparc
+#readelf: -WSsrl
+#target: sparc*-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 0+ +0 +0 +0
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+1000 0+ +AX +0 +0 4096
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+102000 0+2000 0+e0 10 +WA +3 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+1020e0 0+20e0 0+10 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .data +PROGBITS +0+103000 0+3000 0+1000 00 +WA +0 +0 4096
+ +\[[ 0-9]+\] .shstrtab +.*
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x1000
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD +0x0+ 0x0+ 0x0+ 0x0+2000 0x0+2000 R E 0x100000
+ +LOAD +0x0+2000 0x0+102000 0x0+102000 0x0+2000 0x0+2000 RW +0x100000
+ +DYNAMIC +0x0+2000 0x0+102000 0x0+102000 0x0+e0 0x0+e0 RW +0x8
+#...
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_SPARC_GLOB_DAT +0+103000 +sym \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION LOCAL +DEFAULT +5 *
+.* SECTION LOCAL +DEFAULT +7 *
+.* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
+.* FUNC +GLOBAL DEFAULT +5 foo
+.* NOTYPE +GLOBAL DEFAULT +ABS _edata
+.* NOTYPE +GLOBAL DEFAULT +ABS _end
+.* NOTYPE +GLOBAL DEFAULT +8 sym
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION LOCAL +DEFAULT +1 *
+.* SECTION LOCAL +DEFAULT +2 *
+.* SECTION LOCAL +DEFAULT +3 *
+.* SECTION LOCAL +DEFAULT +4 *
+.* SECTION LOCAL +DEFAULT +5 *
+.* SECTION LOCAL +DEFAULT +6 *
+.* SECTION LOCAL +DEFAULT +7 *
+.* SECTION LOCAL +DEFAULT +8 *
+.* OBJECT +LOCAL +HIDDEN +ABS _DYNAMIC
+.* OBJECT +LOCAL +HIDDEN +ABS _PROCEDURE_LINKAGE_TABLE_
+.* OBJECT +LOCAL +HIDDEN +ABS _GLOBAL_OFFSET_TABLE_
+.* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
+.* FUNC +GLOBAL DEFAULT +5 foo
+.* NOTYPE +GLOBAL DEFAULT +ABS _edata
+.* NOTYPE +GLOBAL DEFAULT +ABS _end
+.* NOTYPE +GLOBAL DEFAULT +8 sym
+
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop64.s	2008-04-12 22:15:54.000000000 -0700
@@ -0,0 +1,28 @@
+	.data
+	.align	4096
+	.globl	sym
+sym:	.word	0x12345678
+
+	.text
+	.align	4096
+.LLGETPC0:
+	retl
+	add	%o7, %l7, %l7
+
+	.globl	foo
+	.type	foo,#function
+	.proc	04
+foo:
+	save	%sp, -160, %sp
+	sethi	%hi(_GLOBAL_OFFSET_TABLE_-4), %l7
+	call	.LLGETPC0
+	add	%l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
+	nop
+	sethi	%gdop_hix22(sym), %l1
+	nop
+	xor	%l1, %gdop_lox10(sym), %l1
+	nop
+	ldx	[%l7 + %l1], %i0, %gdop(sym)
+	nop
+	ret
+	restore
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop64.sd	2008-04-12 23:03:11.000000000 -0700
@@ -0,0 +1,10 @@
+#source: gotop64.s
+#as: --64 -K PIC
+#ld: -shared -melf64_sparc
+#objdump: -sj.got
+#target: sparc*-*-*
+
+.*: +file format elf64-sparc
+
+Contents of section .got:
+ 1020e0 00000000 00102000 00000000 00000000  .*
--- /dev/null	2008-03-03 20:22:44.000000000 -0800
+++ ld/testsuite/ld-sparc/gotop64.td	2008-04-12 23:03:50.000000000 -0700
@@ -0,0 +1,12 @@
+#source: gotop64.s
+#as: --64 -K PIC
+#ld: -shared -melf64_sparc
+#objdump: -sj.data
+#target: sparc*-*-*
+
+.*: +file format elf64-sparc
+
+Contents of section .data:
+ 103000 12345678 00000000 00000000 00000000  .*
+ 103010 00000000 00000000 00000000 00000000  .*
+#pass



More information about the Binutils mailing list