diff mbox

[committed] Nios II GOT pointer initialization

Message ID 52EEC36E.70905@codesourcery.com
State New
Headers show

Commit Message

Sandra Loosemore Feb. 2, 2014, 10:15 p.m. UTC
The initial commit of the Nios II GCC backend has an ABI conformance bug 
in that it initializes the GOT pointer from _GLOBAL_OFFSET_TABLE_ rather 
than _gp_got, as specified in the ABI.  As a consequence of this, 
GCC-generated code can only address 32K of GOT rather than 64K as 
documented in the ABI.  This patch fixes that.

This patch depends on the binutils patch I posted earlier today:

https://sourceware.org/ml/binutils/2014-02/msg00009.html

as the linker was not previously defining the _gp_got symbol specified 
in the ABI document.  There's a potential compatibility issue here with 
old versions of the linker, but we'd rather have the first official 
release of GCC for Nios II implement this correctly.

-Sandra
diff mbox

Patch

Index: gcc/config/nios2/nios2.md
===================================================================
--- gcc/config/nios2/nios2.md	(revision 207406)
+++ gcc/config/nios2/nios2.md	(working copy)
@@ -1015,8 +1015,8 @@ 
   ""
   "nextpc\\t%0
 \\t1:
-\\tmovhi\\t%1, %%hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)
-\\taddi\\t%1, %1, %%lo(_GLOBAL_OFFSET_TABLE_ - 1b)"
+\\tmovhi\\t%1, %%hiadj(_gp_got - 1b)
+\\taddi\\t%1, %1, %%lo(_gp_got - 1b)"
   [(set_attr "length" "12")])
 
 ;; Read thread pointer register
Index: gcc/config/nios2/nios2.c
===================================================================
--- gcc/config/nios2/nios2.c	(revision 207406)
+++ gcc/config/nios2/nios2.c	(working copy)
@@ -667,8 +667,8 @@  nios2_function_profiler (FILE *file, int
   if (flag_pic)
     {
       fprintf (file, "\tnextpc\tr2\n");
-      fprintf (file, "\t1: movhi\tr3, %%hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)\n");
-      fprintf (file, "\taddi\tr3, r3, %%lo(_GLOBAL_OFFSET_TABLE_ - 1b)\n");
+      fprintf (file, "\t1: movhi\tr3, %%hiadj(_gp_got - 1b)\n");
+      fprintf (file, "\taddi\tr3, r3, %%lo(_gp_got - 1b)\n");
       fprintf (file, "\tadd\tr2, r2, r3\n");
       fprintf (file, "\tldw\tr2, %%call(_mcount)(r2)\n");
       fprintf (file, "\tcallr\tr2\n");
Index: libgcc/config/nios2/crti.S
===================================================================
--- libgcc/config/nios2/crti.S	(revision 207406)
+++ libgcc/config/nios2/crti.S	(working copy)
@@ -56,8 +56,8 @@  _init:
 	addi	fp, sp, 8
 #ifdef linux
 	nextpc	r22
-1:	movhi	r2, %hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)
-	addi	r2, r2, %lo(_GLOBAL_OFFSET_TABLE_ - 1b)
+1:	movhi	r2, %hiadj(_gp_got - 1b)
+	addi	r2, r2, %lo(_gp_got - 1b)
 	add	r22, r22, r2
 #endif
 	
@@ -80,8 +80,8 @@  _fini:
 	addi	fp, sp, 8
 #ifdef linux
 	nextpc	r22
-1:	movhi	r2, %hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)
-	addi	r2, r2, %lo(_GLOBAL_OFFSET_TABLE_ - 1b)
+1:	movhi	r2, %hiadj(_gp_got - 1b)
+	addi	r2, r2, %lo(_gp_got - 1b)
 	add	r22, r22, r2
 #endif