This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

static-after-extern tests vs. mips explicit relocs


The testsuite has several tests of the form:

        extern void foo (...);
        int main () { ... foo (...); ... };
        static void foo (...) { ... }

where foo() is some well-known library function.  main() gets
compiled on the assumption that foo() is external, meaning that
builtin optimisations can be applied.  The static definition of
foo() then makes sure that the right calls are made.

Unfortunately, explicit-reloc mips code can't handle this sort of
thing.  Since foo() is external while compiling main(), we generate
code like:

        lw $25,%call16(foo)($gp)
        jalr $25

and R_MIPS_CALL16 can't be validly applied to local symbols.
Perhaps a sympathetic linker might do the right thing anyway,
but neither the irix nor GNU lds seem to.

FWIW, the irix linker seems to turn the R_MIPS_CALL16 into an
R_MIPS_GOT16 and then applies the semantics for local symbols.
$25 is then loaded with the address of the 16k page containing
foo(), not foo() itself.  GNU ld just moans.

The tests work OK when using macros.  The assembler will realise
that foo is static and generate the right call sequences.

So, is it OK to apply the patch below to force -mno-explicit-relocs
in these cases?  I haven't tried to narrow the condition down to hosted
configurations: it'd be nice to have some no-explicit-reloc tests anyway.

In one case (string-opt-16.c) there's a static definition of
link_error() after an external definition.  As far as I can tell,
making the definition global shouldn't affect the integrity of
the case.

Tested on mipsel-linux-gnu and mips-sgi-irix6.5.  OK to install?

Richard


	* lib/target-supports.exp (static_after_extern): New procedure.
	* lib/c-torture.exp: Include target-supports.exp.
	* gcc.c-torture/execute/string-opt-16.c (link_error): Make global.
	* gcc.c-torture/execute/string-opt-{3,4,17,18,19,asm-1}.x: New files.
	* gcc.c-torture/execute/builtin-noret-{1,2}.x: New files.
	* gcc.dg/no-builtin-1.c: Use -mno-explicit-relocs on MIPS targets.

Index: testsuite/lib/target-supports.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/target-supports.exp,v
retrieving revision 1.4
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.4 target-supports.exp
*** testsuite/lib/target-supports.exp	27 Sep 2002 02:14:12 -0000	1.4
--- testsuite/lib/target-supports.exp	7 May 2003 18:02:52 -0000
*************** proc check_alias_available { testfile } 
*** 112,114 ****
--- 112,124 ----
  
      return $alias_available_saved
  }
+ 
+ # Some optimization tests declare an external library function X, use it
+ # in some test function, then declare a static implementation of X.
+ # Not all targets can support this.
+ proc static_after_extern {} {
+     if {[istarget "mips*-*-*"]} {
+ 	uplevel {set additional_flags "-mno-explicit-relocs"}
+     }
+     return 0
+ }
Index: testsuite/lib/c-torture.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/c-torture.exp,v
retrieving revision 1.17
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.17 c-torture.exp
*** testsuite/lib/c-torture.exp	25 May 2002 03:40:20 -0000	1.17
--- testsuite/lib/c-torture.exp	7 May 2003 18:02:52 -0000
*************** # bug-dejagnu@gnu.org.
*** 20,25 ****
--- 20,26 ----
  # This file was written by Rob Savoye. (rob@cygnus.com)
  
  load_lib file-format.exp
+ load_lib target-supports.exp
  
  # The default option list can be overridden by
  # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
Index: testsuite/gcc.c-torture/execute/string-opt-16.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c,v
retrieving revision 1.2
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.2 string-opt-16.c
*** testsuite/gcc.c-torture/execute/string-opt-16.c	21 Jan 2003 19:43:53 -0000	1.2
--- testsuite/gcc.c-torture/execute/string-opt-16.c	7 May 2003 18:02:52 -0000
*************** #else
*** 38,44 ****
  /* When not optimizing, the above tests may generate references to
     the function link_error, but should never actually call it.  */
  __attribute__ ((noinline))
! static void
  link_error ()
  {
    abort ();
--- 38,44 ----
  /* When not optimizing, the above tests may generate references to
     the function link_error, but should never actually call it.  */
  __attribute__ ((noinline))
! void
  link_error ()
  {
    abort ();
Index: testsuite/gcc.dg/no-builtin-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/no-builtin-1.c,v
retrieving revision 1.1
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.1 no-builtin-1.c
*** testsuite/gcc.dg/no-builtin-1.c	18 Nov 2001 03:30:57 -0000	1.1
--- testsuite/gcc.dg/no-builtin-1.c	7 May 2003 18:02:52 -0000
***************
*** 2,7 ****
--- 2,8 ----
  /* Origin: Joseph Myers <jsm28@cam.ac.uk>.  */
  /* { dg-do run } */
  /* { dg-options "-fno-builtin-abs" } */
+ /* { dg-options "-fno-builtin-abs -mno-explicit-relocs" { target mips*-*-* } } */
  
  /* GCC normally handles abs and labs as built-in functions even without
     optimization.  So test that with -fno-builtin-abs, labs is so handled
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/string-opt-17.x	Wed May  7 12:53:55 2003
***************
*** 0 ****
--- 1,2 ----
+ # There's a static implementation of memset() after an extern use.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/string-opt-18.x	Wed May  7 12:53:55 2003
***************
*** 0 ****
--- 1,2 ----
+ # There are static implementations of stpcpy() and mempcpy() after extern uses.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/string-opt-19.x	Wed May  7 12:53:55 2003
***************
*** 0 ****
--- 1,2 ----
+ # There are static implementations of bcopy() and memmove() after extern uses.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/string-opt-3.x	Wed May  7 12:53:55 2003
***************
*** 0 ****
--- 1,2 ----
+ # There are static implementations of various functions after extern uses.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/string-opt-4.x	Wed May  7 12:53:55 2003
***************
*** 0 ****
--- 1,2 ----
+ # There are static implementations of index() and strchr() after extern uses.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/string-opt-asm-1.x	Wed May  7 12:53:55 2003
***************
*** 0 ****
--- 1,2 ----
+ # There's a static implementation strstr() after an extern use.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtin-noret-1.x	Wed May  7 19:00:57 2003
***************
*** 0 ****
--- 1,2 ----
+ # There are static implementations of _exit and _Exit after extern uses.
+ return [static_after_extern]
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtin-noret-2.x	Wed May  7 19:00:51 2003
***************
*** 0 ****
--- 1,2 ----
+ # There are static implementations of _exit and _Exit after extern uses.
+ return [static_after_extern]


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