From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17716 invoked by alias); 3 Aug 2012 18:01:27 -0000 Received: (qmail 17702 invoked by uid 22791); 3 Aug 2012 18:01:26 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Aug 2012 18:01:00 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SxMBH-0002FD-Ew from Maciej_Rozycki@mentor.com ; Fri, 03 Aug 2012 11:00:59 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 3 Aug 2012 11:00:59 -0700 Received: from [172.30.4.177] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Fri, 3 Aug 2012 19:00:57 +0100 Date: Fri, 03 Aug 2012 18:01:00 -0000 From: "Maciej W. Rozycki" To: CC: Richard Sandiford Subject: [PATCH 2/4] MIPS/Linux/LD: Correct the definition of _gp Message-ID: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00065.txt.bz2 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 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 ................