public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/4] MIPS/Linux/LD: Correct the definition of _gp
@ 2012-08-03 18:01 Maciej W. Rozycki
  2012-08-05  7:17 ` Richard Sandiford
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej W. Rozycki @ 2012-08-03 18:01 UTC (permalink / raw)
  To: binutils; +Cc: Richard Sandiford

Hi,

 This change fixes the problem with the special ABI-defined symbol _gp on 
Linux and other SVR4 systems on the MIPS target.  On systems that use 
binutils to link binary code this symbol is defined by LD in the relevant 
linker script being used to produce final output.

 According to the MIPS SVR4 psABI supplement, Chapter 6 "System Library", 
section "Global Data Symbols", subsection "Application Constraints":

"[...] In addition to the application-provided symbols listed in this 
section of the System V ABI, conforming applications on the MIPS processor 
architecture are also required to provide the following symbols.
[...]

extern _gp; This symbol is defined by the link editor and provides the 
            value used for the gp register for this executable or shared 
            object file."

From the definition above it is clear that _gp must have the object scope, 
as it has to uniquely identify the value intended for the gp register used 
within the executable or shared library being referred from.

 This used to be the case until a change seven years ago noted here:

http://sourceware.org/ml/binutils/2005-08/msg00045.html

changed the scope of all the symbols defined by linker scripts from object 
to global.  However a complementing change to keep the object scope of _gp 
has never followed and as a result any binaries produced with a version of 
binutils after the offending change do not conform to the MIPS SVR4 psABI 
and any shared-library code that refers to _gp may not get at the data 
intended.

 More recently a case has been found where valid application code does not 
link at all.  That case can be reduced to the following trivial example:

$ cat bar.c
int
bar ()
{
}
$ cat foo.c
int
foo ()
{
  bar ();
}
$ cat foo.ver
{
  global: foo;
  local: *;
};
$ cat test.c
int
main ()
{
  foo ();
}
$ mips-linux-gnu-gcc -fPIC -shared bar.c -o bar.so
$ mips-linux-gnu-gcc -fPIC -shared foo.c -Wl,-version-script,foo.ver -o foo.so bar.so
$ mips-linux-gnu-gcc test.c foo.so -Wl,-rpath-link=. -o test
.../mips-linux-gnu/bin/ld: .../mips-linux-gnu/libc/usr/lib/crt1.o: undefined reference to symbol '_gp'
.../mips-linux-gnu/bin/ld: note: '_gp' is defined in DSO ./bar.so so try adding it to the linker command line
./bar.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
$ 

 The link failure above and the ABI non-conformance in the first place is 
fixed with the change below, that builds on the HIDDEN linker script 
keyword defined previously.

 A change to one test case (across the three ABIs supported) was required 
as with the removal of _gp from the global scope the size of the dynamic 
symbol table has changed and, consequently, have section offsets/virtual 
addresses.  A new test case converted from the example above and other 
test suite updates will be sent separately.

 No regressions on the 23 MIPS targets I've been testing recently.  OK to 
apply?

2012-08-03  Maciej W. Rozycki  <macro@codesourcery.com>

	ld/
	* emulparams/elf32bmip.sh: Make _gp hidden.
	* emulparams/elf32bmipn32-defs.sh: Likewise.
	* emulparams/elf32mipswindiss.sh: Likewise.
	* ld/scripttempl/mips.sc: Likewise.

	ld/testsuite/
	* ld-mips-elf/rel32-o32.d: Adjust section VMAs after the removal
	of _gp from the global scope.
	* ld-mips-elf/rel32-n32.d: Likewise.
	* ld-mips-elf/rel64.d: Likewise.

  Maciej

binutils-mips-gp.diff
Index: binutils-fsf-trunk-quilt/ld/emulparams/elf32bmip.sh
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/emulparams/elf32bmip.sh	2012-07-11 17:05:22.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/emulparams/elf32bmip.sh	2012-07-11 17:18:08.201764721 +0100
@@ -33,7 +33,7 @@ OTHER_GOT_RELOC_SECTIONS="
 # of .got.
 OTHER_GOT_SYMBOLS='
   . = .;
-  _gp = ALIGN(16) + 0x7ff0;
+  HIDDEN (_gp = ALIGN (16) + 0x7ff0);
 '
 # .got.plt is only used for the PLT psABI extension.  It should not be
 # included in the .sdata block with .got, as there is no need to access
Index: binutils-fsf-trunk-quilt/ld/emulparams/elf32bmipn32-defs.sh
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/emulparams/elf32bmipn32-defs.sh	2012-07-11 17:05:22.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/emulparams/elf32bmipn32-defs.sh	2012-07-11 17:18:08.201764721 +0100
@@ -51,7 +51,7 @@ OTHER_GOT_RELOC_SECTIONS="
 # of .got.
 OTHER_GOT_SYMBOLS='
   . = .;
-  _gp = ALIGN(16) + 0x7ff0;
+  HIDDEN (_gp = ALIGN (16) + 0x7ff0);
 '
 # .got.plt is only used for the PLT psABI extension.  It should not be
 # included in the .sdata block with .got, as there is no need to access
Index: binutils-fsf-trunk-quilt/ld/emulparams/elf32mipswindiss.sh
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/emulparams/elf32mipswindiss.sh	2012-07-11 17:05:22.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/emulparams/elf32mipswindiss.sh	2012-07-11 17:18:08.201764721 +0100
@@ -12,7 +12,7 @@ MAXPAGESIZE=0x40000
 # the Diab linker.
 TEXT_START_ADDR=0x100000
 DATA_START_SYMBOLS='__DATA_ROM = .; __DATA_RAM = .;'
-SDATA_START_SYMBOLS='_SDA_BASE_ = .; _gp = . + 0x7ff0;'
+SDATA_START_SYMBOLS='_SDA_BASE_ = .; HIDDEN (_gp = . + 0x7ff0);'
 SDATA2_START_SYMBOLS='_SDA2_BASE_ = .;'
 EXECUTABLE_SYMBOLS='__HEAP_START = .; __SP_INIT = 0x800000; __SP_END = __SP_INIT - 0x20000; __HEAP_END = __SP_END; __DATA_END = _edata; __BSS_START = __bss_start; __BSS_END = _end; __HEAP_START = _end;'
 
Index: binutils-fsf-trunk-quilt/ld/scripttempl/mips.sc
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/scripttempl/mips.sc	2012-07-11 17:05:22.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/scripttempl/mips.sc	2012-07-11 17:18:08.201764721 +0100
@@ -42,7 +42,7 @@ SECTIONS
     *(.data)
     ${CONSTRUCTING+CONSTRUCTORS}
   }
-  ${RELOCATING+ _gp = ALIGN(16) + 0x8000;}
+  ${RELOCATING+ HIDDEN (_gp = ALIGN (16) + 0x8000);}
   .lit8 : {
     *(.lit8)
   }
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/rel32-o32.d
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/testsuite/ld-mips-elf/rel32-o32.d	2012-07-11 17:05:22.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/rel32-o32.d	2012-07-11 17:18:08.201764721 +0100
@@ -10,6 +10,6 @@
 [0-9a-f ]+R_MIPS_REL32     
 
 Hex dump of section '.text':
+  0x000002c0 00000000 00000000 00000000 00000000 ................
+  0x000002d0 000002d0 00000000 00000000 00000000 ................
   0x000002e0 00000000 00000000 00000000 00000000 ................
-  0x000002f0 000002f0 00000000 00000000 00000000 ................
-  0x00000300 00000000 00000000 00000000 00000000 ................
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/rel32-n32.d
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/testsuite/ld-mips-elf/rel32-n32.d	2011-10-04 15:29:04.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/rel32-n32.d	2012-07-11 17:25:07.190691311 +0100
@@ -10,6 +10,6 @@
 [0-9a-f ]+R_MIPS_REL32     
 
 Hex dump of section '.text':
-  0x000002e0 00000000 00000000 00000000 00000000 ................
-  0x000002f0 000002f0 00000000 00000000 00000000 ................
-  0x00000300 00000000 00000000 00000000 00000000 ................
+  0x000002d0 00000000 00000000 00000000 00000000 ................
+  0x000002e0 000002e0 00000000 00000000 00000000 ................
+  0x000002f0 00000000 00000000 00000000 00000000 ................
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/rel64.d
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/testsuite/ld-mips-elf/rel64.d	2011-10-04 15:29:04.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/rel64.d	2012-07-11 17:25:53.261000428 +0100
@@ -14,6 +14,6 @@
  +Type3: R_MIPS_NONE      
 
 Hex dump of section '.text':
+  0x00000430 00000000 00000000 00000000 00000000 ................
+  0x00000440 00000000 00000440 00000000 00000000 ................
   0x00000450 00000000 00000000 00000000 00000000 ................
-  0x00000460 00000000 00000460 00000000 00000000 ................
-  0x00000470 00000000 00000000 00000000 00000000 ................

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/4] MIPS/Linux/LD: Correct the definition of _gp
  2012-08-03 18:01 [PATCH 2/4] MIPS/Linux/LD: Correct the definition of _gp Maciej W. Rozycki
@ 2012-08-05  7:17 ` Richard Sandiford
  2012-08-07  0:28   ` Maciej W. Rozycki
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2012-08-05  7:17 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: binutils

"Maciej W. Rozycki" <macro@codesourcery.com> writes:
> 	ld/
> 	* emulparams/elf32bmip.sh: Make _gp hidden.
> 	* emulparams/elf32bmipn32-defs.sh: Likewise.
> 	* emulparams/elf32mipswindiss.sh: Likewise.
> 	* ld/scripttempl/mips.sc: Likewise.
>
> 	ld/testsuite/
> 	* ld-mips-elf/rel32-o32.d: Adjust section VMAs after the removal
> 	of _gp from the global scope.
> 	* ld-mips-elf/rel32-n32.d: Likewise.
> 	* ld-mips-elf/rel64.d: Likewise.

OK.

Richard

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/4] MIPS/Linux/LD: Correct the definition of _gp
  2012-08-05  7:17 ` Richard Sandiford
@ 2012-08-07  0:28   ` Maciej W. Rozycki
  0 siblings, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2012-08-07  0:28 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: binutils

On Sun, 5 Aug 2012, Richard Sandiford wrote:

> > 	ld/
> > 	* emulparams/elf32bmip.sh: Make _gp hidden.
> > 	* emulparams/elf32bmipn32-defs.sh: Likewise.
> > 	* emulparams/elf32mipswindiss.sh: Likewise.
> > 	* ld/scripttempl/mips.sc: Likewise.
> >
> > 	ld/testsuite/
> > 	* ld-mips-elf/rel32-o32.d: Adjust section VMAs after the removal
> > 	of _gp from the global scope.
> > 	* ld-mips-elf/rel32-n32.d: Likewise.
> > 	* ld-mips-elf/rel64.d: Likewise.
> 
> OK.

 I have applied this change and the two sets of test suite updates now, 
thanks.

  Maciej

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-06 22:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 18:01 [PATCH 2/4] MIPS/Linux/LD: Correct the definition of _gp Maciej W. Rozycki
2012-08-05  7:17 ` Richard Sandiford
2012-08-07  0:28   ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).