This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New Patch to fix MIPS -mno-shared with multi-got...


Daniel Jacobowitz wrote:
On Fri, Mar 04, 2005 at 11:42:33AM -0800, David Daney wrote:

Attached is what I hope is the final version of the patch. I had to bzip2 it because the testcase is a bit large.


If you don't mind, could you try to do something like the multi-GOT
test for TLS?  It's smaller, easier to edit and proofread, and requires
less constant maintenance.

I don't really dig 100k linker tests.


Thanks for the pointer. You shamed me into creating a more compact version of the test case.



Tested on i686-linux -> mipsel-linux cross with make -k check no regressions found.


bfd ChangeLog:
2005-03-04  David Daney <ddaney@avtrex.com>

    * elfxx-mips.c (mips_elf_calculate_relocation): Handle special
    '__gnu_local_gp' symbol used by gas -mno-shared.

gas ChangeLog:
2005-03-04  David Daney <ddaney@avtrex.com>

    * config/tc-mips.c (macro_build_lui): Use '__gnu_local_gp' instead
    of '_gp' for -mno-shared optimization.
    (s_cpload): Ditto.
    (s_abicalls): Document it in the comment.
    (md_show_usage): Document the -mno-shared option.


gas/testsuite ChangeLog: 2005-03-04 David Daney <ddaney@avtrex.com>

    * gas/mips/elf-rel23b.d: Use '__gnu_local_gp' instead
    of '_gp' for -mno-shared optimization.
    * gas/mips/elf-rel25a.d: Ditto.

ld/testsuite ChangeLog:
2005-03-04  David Daney <ddaney@avtrex.com>

    * ld-mips-elf/multi-got-no-shared{-1.s, -2.s, .d}: New test.
    * ld-mips-elf/mips-elf.exp: Run it.

If O.K. I can try to commit as it appears that I have CVS write access (although never tested with binutils).


David Daney.
? bfd/doc/bfd.info
? gas/doc/as.info
? ld/testsuite/ld-mips-elf/t
? ld/testsuite/ld-mips-elf/t.dump
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.125
diff -c -p -r1.125 elfxx-mips.c
*** bfd/elfxx-mips.c	2 Mar 2005 21:23:20 -0000	1.125
--- bfd/elfxx-mips.c	4 Mar 2005 21:49:54 -0000
*************** mips_elf_calculate_relocation (bfd *abfd
*** 3646,3651 ****
--- 3646,3654 ----
    bfd_boolean local_p, was_local_p;
    /* TRUE if the symbol referred to by this relocation is "_gp_disp".  */
    bfd_boolean gp_disp_p = FALSE;
+   /* TRUE if the symbol referred to by this relocation is
+      "__gnu_local_gp".  */
+   bfd_boolean gnu_local_gp_p = FALSE;
    Elf_Internal_Shdr *symtab_hdr;
    size_t extsymoff;
    unsigned long r_symndx;
*************** mips_elf_calculate_relocation (bfd *abfd
*** 3742,3747 ****
--- 3745,3756 ----
  
  	  gp_disp_p = TRUE;
  	}
+       /* See if this is the special _gp symbol.  Note that such a
+ 	 symbol must always be a global symbol.  */
+       else if (strcmp (*namep, "__gnu_local_gp") == 0)
+ 	gnu_local_gp_p = TRUE;
+ 
+ 
        /* If this symbol is defined, calculate its address.  Note that
  	 _gp_disp is a magic symbol, always implicitly defined by the
  	 linker, so it's inappropriate to check to see whether or not
*************** mips_elf_calculate_relocation (bfd *abfd
*** 3956,3961 ****
--- 3965,3973 ----
        break;
      }
  
+   if (gnu_local_gp_p)
+     symbol = gp;
+   
    /* Figure out what kind of relocation is being performed.  */
    switch (r_type)
      {
Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.290
diff -c -p -r1.290 tc-mips.c
*** gas/config/tc-mips.c	4 Mar 2005 09:51:07 -0000	1.290
--- gas/config/tc-mips.c	4 Mar 2005 21:49:56 -0000
*************** macro_build_lui (expressionS *ep, int re
*** 3393,3405 ****
    else
      {
        assert (ep->X_op == O_symbol);
!       /* _gp_disp is a special case, used from s_cpload.  _gp is used
! 	 if mips_no_shared.  */
        assert (mips_pic == NO_PIC
  	      || (! HAVE_NEWABI
  		  && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
  	      || (! mips_in_shared
! 		  && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp") == 0));
        *r = BFD_RELOC_HI16_S;
      }
  
--- 3393,3406 ----
    else
      {
        assert (ep->X_op == O_symbol);
!       /* _gp_disp is a special case, used from s_cpload.
! 	 __gnu_local_gp is used if mips_no_shared.  */
        assert (mips_pic == NO_PIC
  	      || (! HAVE_NEWABI
  		  && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
  	      || (! mips_in_shared
! 		  && strcmp (S_GET_NAME (ep->X_add_symbol),
!                              "__gnu_local_gp") == 0));
        *r = BFD_RELOC_HI16_S;
      }
  
*************** s_abicalls (int ignore ATTRIBUTE_UNUSED)
*** 11819,11830 ****
     The .cpload argument is normally $25 == $t9.
  
     The -mno-shared option changes this to:
! 	lui	$gp,%hi(_gp)
! 	addiu	$gp,$gp,%lo(_gp)
     and the argument is ignored.  This saves an instruction, but the
     resulting code is not position independent; it uses an absolute
!    address for _gp.  Thus code assembled with -mno-shared can go into
!    an ordinary executable, but not into a shared library.  */
  
  static void
  s_cpload (int ignore ATTRIBUTE_UNUSED)
--- 11820,11831 ----
     The .cpload argument is normally $25 == $t9.
  
     The -mno-shared option changes this to:
! 	lui	$gp,%hi(__gnu_local_gp)
! 	addiu	$gp,$gp,%lo(__gnu_local_gp)
     and the argument is ignored.  This saves an instruction, but the
     resulting code is not position independent; it uses an absolute
!    address for __gnu_local_gp.  Thus code assembled with -mno-shared
!    can go into an ordinary executable, but not into a shared library.  */
  
  static void
  s_cpload (int ignore ATTRIBUTE_UNUSED)
*************** s_cpload (int ignore ATTRIBUTE_UNUSED)
*** 11852,11858 ****
    in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
  
    ex.X_op = O_symbol;
!   ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" : "_gp");
    ex.X_op_symbol = NULL;
    ex.X_add_number = 0;
  
--- 11853,11860 ----
    in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
  
    ex.X_op = O_symbol;
!   ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
!                                          "__gnu_local_gp");
    ex.X_op_symbol = NULL;
    ex.X_add_number = 0;
  
*************** MIPS options:\n\
*** 14118,14123 ****
--- 14120,14127 ----
  -non_shared		do not generate position independent code\n\
  -xgot			assume a 32 bit GOT\n\
  -mpdr, -mno-pdr		enable/disable creation of .pdr sections\n\
+ -mshared, -mno-shared   disable/enable .cpload optimization for\n\
+                         non-shared code\n\
  -mabi=ABI		create ABI conformant object file for:\n"));
  
    first = 1;
Index: gas/testsuite/gas/mips/elf-rel23b.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/elf-rel23b.d,v
retrieving revision 1.1
diff -c -p -r1.1 elf-rel23b.d
*** gas/testsuite/gas/mips/elf-rel23b.d	10 Dec 2004 19:48:42 -0000	1.1
--- gas/testsuite/gas/mips/elf-rel23b.d	4 Mar 2005 21:49:56 -0000
*************** Disassembly of section \.text:
*** 10,16 ****
  0+00 <.*>:
  .*:	0380282d 	move	\$5,\$28
  .*:	3c1c0000 	lui	\$28,0x0
! 			.*: R_MIPS_HI16	_gp
  .*:	279c0000 	addiu	\$28,\$28,0
! 			.*: R_MIPS_LO16	_gp
  .*:	00000000 	nop
--- 10,16 ----
  0+00 <.*>:
  .*:	0380282d 	move	\$5,\$28
  .*:	3c1c0000 	lui	\$28,0x0
! 			.*: R_MIPS_HI16	__gnu_local_gp
  .*:	279c0000 	addiu	\$28,\$28,0
! 			.*: R_MIPS_LO16	__gnu_local_gp
  .*:	00000000 	nop
Index: gas/testsuite/gas/mips/elf-rel25a.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/elf-rel25a.d,v
retrieving revision 1.2
diff -c -p -r1.2 elf-rel25a.d
*** gas/testsuite/gas/mips/elf-rel25a.d	13 Dec 2004 13:02:10 -0000	1.2
--- gas/testsuite/gas/mips/elf-rel25a.d	4 Mar 2005 21:49:56 -0000
*************** Disassembly of section \.text:
*** 9,15 ****
  
  0+00 <.*>:
  .*:	3c1c0000 	lui	\$28,0x0
! 			.*: R_MIPS_HI16	_gp
  .*:	279c0000 	addiu	\$28,\$28,0
! 			.*: R_MIPS_LO16	_gp
  #pass
--- 9,15 ----
  
  0+00 <.*>:
  .*:	3c1c0000 	lui	\$28,0x0
! 			.*: R_MIPS_HI16	__gnu_local_gp
  .*:	279c0000 	addiu	\$28,\$28,0
! 			.*: R_MIPS_LO16	__gnu_local_gp
  #pass
Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.28
diff -c -p -r1.28 mips-elf.exp
*** ld/testsuite/ld-mips-elf/mips-elf.exp	2 Mar 2005 21:22:57 -0000	1.28
--- ld/testsuite/ld-mips-elf/mips-elf.exp	4 Mar 2005 21:49:57 -0000
*************** run_dump_test "branch-misc-1"
*** 35,40 ****
--- 35,41 ----
  # the "traditional" emulations.
  if { $linux_gnu } {
      run_dump_test "multi-got-1"
+     run_dump_test "multi-got-no-shared"
  }
  
  if $has_newabi {
Index: ld/testsuite/ld-mips-elf/multi-got-no-shared-1.s
===================================================================
RCS file: ld/testsuite/ld-mips-elf/multi-got-no-shared-1.s
diff -N ld/testsuite/ld-mips-elf/multi-got-no-shared-1.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-mips-elf/multi-got-no-shared-1.s	4 Mar 2005 21:49:57 -0000
***************
*** 0 ****
--- 1,29 ----
+ 	.macro  one_sym count
+ 	.globl  sym_1_\count
+ sym_1_\count:
+         la      $2, sym_1_\count
+ 	.endm
+ 
+ 	
+ 	.text
+ 	.globl	func1
+ 	.ent	func1
+ func1:
+ 	.frame	$sp,0,$31
+ 	.set noreorder
+ 	.cpload	$25
+ 	.set reorder
+ 	.cprestore 8
+ 	.set noreorder
+ 
+ 	.irp    thou,0,1,2,3,4,5,6,7,8
+ 	.irp    hund,0,1,2,3,4,5,6,7,8,9
+ 	.irp    tens,0,1,2,3,4,5,6,7,8,9
+ 	.irp    ones,0,1,2,3,4,5,6,7,8,9
+ 	one_sym \thou\hund\tens\ones
+ 	.endr
+ 	.endr
+ 	.endr
+ 	.endr
+ 
+ 	.end	func1
Index: ld/testsuite/ld-mips-elf/multi-got-no-shared-2.s
===================================================================
RCS file: ld/testsuite/ld-mips-elf/multi-got-no-shared-2.s
diff -N ld/testsuite/ld-mips-elf/multi-got-no-shared-2.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-mips-elf/multi-got-no-shared-2.s	4 Mar 2005 21:49:57 -0000
***************
*** 0 ****
--- 1,27 ----
+ 	.macro  one_sym count
+ 	.globl  sym_2_\count
+ sym_2_\count:
+         la      $2, sym_2_\count
+ 	.endm
+ 
+ 	.text
+ 	.ent	func2
+ func2:
+ 	.frame	$sp,0,$31
+ 	.set noreorder
+ 	.cpload	$25
+ 	.set reorder
+ 	.cprestore 8
+ 	.set noreorder
+ 
+ 	.irp    thou,0,1,2,3,4,5,6,7,8
+ 	.irp    hund,0,1,2,3,4,5,6,7,8,9
+ 	.irp    tens,0,1,2,3,4,5,6,7,8,9
+ 	.irp    ones,0,1,2,3,4,5,6,7,8,9
+ 	one_sym \thou\hund\tens\ones
+ 	.endr
+ 	.endr
+ 	.endr
+ 	.endr
+ 
+ 	.end	func2
Index: ld/testsuite/ld-mips-elf/multi-got-no-shared.d
===================================================================
RCS file: ld/testsuite/ld-mips-elf/multi-got-no-shared.d
diff -N ld/testsuite/ld-mips-elf/multi-got-no-shared.d
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-mips-elf/multi-got-no-shared.d	4 Mar 2005 21:49:57 -0000
***************
*** 0 ****
--- 1,18 ----
+ #name: MIPS multi-got-no-shared
+ #as: -EB -32 -KPIC -mno-shared
+ #source: multi-got-no-shared-1.s
+ #source: multi-got-no-shared-2.s
+ #ld: -melf32btsmip --entry func1
+ #objdump: -D -j .text --prefix-addresses --show-raw-insn
+ 
+ .*: +file format.*
+ 
+ Disassembly of section \.text:
+ 004000b0 <[^>]*> 3c1c1000 	lui	gp,0x1000
+ 004000b4 <[^>]*> 279c7ff0 	addiu	gp,gp,32752
+ 004000b8 <[^>]*> afbc0008 	sw	gp,8\(sp\)
+ #...
+ 00408d60 <[^>]*> 3c1c1002 	lui	gp,0x1002
+ 00408d64 <[^>]*> 279c9960 	addiu	gp,gp,-26272
+ 00408d68 <[^>]*> afbc0008 	sw	gp,8\(sp\)
+ #pass

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]