OSDN Git Service

PR libfortran/22298
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Nov 2005 08:44:29 +0000 (08:44 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Nov 2005 08:44:29 +0000 (08:44 +0000)
* runtime/main.c (stupid_function_name_for_static_linking): New
function.
* runtime/error.c (internal_error): Call
stupid_function_name_for_static_linking.
* libgfortran.h: Add prototype for
stupid_function_name_for_static_linking.

* gcc/testsuite/lib/target-supports.exp
(check_effective_target_static_libgfortran): New
static_libgfortran effective target.
* gcc/testsuite/gfortran.dg/static_linking_1.f: New test.
* gcc/testsuite/gfortran.dg/static_linking_1.c: New file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@106484 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/static_linking_1.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/static_linking_1.f [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp
libgfortran/ChangeLog
libgfortran/libgfortran.h
libgfortran/runtime/error.c
libgfortran/runtime/main.c

index e92490c..57c589c 100644 (file)
@@ -1,3 +1,12 @@
+2005-11-04  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR libfortran/22298
+       * gcc/testsuite/lib/target-supports.exp
+       (check_effective_target_static_libgfortran): New
+       static_libgfortran effective target.
+       * gcc/testsuite/gfortran.dg/static_linking_1.f: New test.
+       * gcc/testsuite/gfortran.dg/static_linking_1.c: New file.
+
 2005-11-04  Hans-Peter Nilsson  <hp@axis.com>
 
        * gcc.dg/pr24615.c: Guard test with { target fpic }.
 2005-11-02  Andrew Pinski  <pinskia@physics.uc.edu>
 
        PR fortran/18157
-        * gfortran.fortran-torture/compile/defined_type_1.f90: New test.
-       * gfortran.fortran-torture/compile/defined_type_2.f90: New
-       test.
-       * gfortran.fortran-torture/compile/defined_type_3.f90:
-       New test.
+       * gfortran.fortran-torture/compile/defined_type_1.f90: New test.
+       * gfortran.fortran-torture/compile/defined_type_2.f90: New test.
+       * gfortran.fortran-torture/compile/defined_type_3.f90: New test.
 
 2005-11-02  Mark Mitchell  <mark@codesourcery.com>
 
diff --git a/gcc/testsuite/gfortran.dg/static_linking_1.c b/gcc/testsuite/gfortran.dg/static_linking_1.c
new file mode 100644 (file)
index 0000000..e7d266d
--- /dev/null
@@ -0,0 +1,6 @@
+extern void f_(void);
+int main (void)
+{
+  f_();
+  return 0;
+}
diff --git a/gcc/testsuite/gfortran.dg/static_linking_1.f b/gcc/testsuite/gfortran.dg/static_linking_1.f
new file mode 100644 (file)
index 0000000..5107a07
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-require-effective-target static_libgfortran }
+! { dg-do run }
+! { dg-additional-sources static_linking_1.c }
+! { dg-options "-static" }
+!
+! This testcase checks that statically linking libgfortran with C main()
+! really calls the constructor function
+! PR libfortran/22298
+      subroutine f
+        print *, "subroutine output"
+      end
index 3116c42..38eb91a 100644 (file)
@@ -602,6 +602,59 @@ proc check_effective_target_fortran_large_int { } {
     return $et_fortran_large_int_saved
 }
 
+# Return 1 if we can statically link libgfortran, 0 otherwise.
+#
+# When the target name changes, replace the cached result.
+
+proc check_effective_target_static_libgfortran { } {
+    global et_static_libgfortran
+    global et_static_libgfortran_target_name
+    global tool
+
+    if { ![info exists et_static_libgfortran_target_name] } {
+       set et_static_libgfortran_target_name ""
+    }
+
+    # If the target has changed since we set the cached value, clear it.
+    set current_target [current_target_name]
+    if { $current_target != $et_static_libgfortran_target_name } {
+       verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
+       set et_static_libgfortran_target_name $current_target
+       if [info exists et_static_libgfortran_saved] {
+           verbose "check_effective_target_static_libgfortran: removing cached result" 2
+           unset et_static_libgfortran_saved
+       }
+    }
+
+    if [info exists et_static_libgfortran_saved] {
+       verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
+    } else {
+       set et_static_libgfortran_saved 0
+
+       # Set up, compile, and execute a test program using static linking.
+       # Include the current process ID in the file names to prevent
+       # conflicts with invocations for multiple testsuites.
+       set src static[pid].f
+        set exe static[pid].x
+
+       set f [open $src "w"]
+       puts $f "      print *, 'test'"
+       puts $f "      end"
+       close $f
+
+       verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
+       set lines [${tool}_target_compile $src $exe executable "-static"]
+       file delete $src
+
+       if [string match "" $lines] then {
+           # No error message, compilation succeeded.
+           set et_static_libgfortran_saved 1
+       }
+    }
+
+    return $et_static_libgfortran_saved
+}
+
 # Return 1 if the target supports executing AltiVec instructions, 0
 # otherwise.  Cache the result.
 
index fe10fb9..c3c5a9e 100644 (file)
@@ -1,3 +1,13 @@
+2005-11-04  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR libfortran/22298
+       * runtime/main.c (stupid_function_name_for_static_linking): New
+       function.
+       * runtime/error.c (internal_error): Call
+       stupid_function_name_for_static_linking.
+       * libgfortran.h: Add prototype for
+       stupid_function_name_for_static_linking.
+
 2005-11-01  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/14994
@@ -6,8 +16,8 @@
 
 2005-10-31  Jerry DeLisle  <jvdelisle@verizon.net>
 
-        PR libgfortran/24584
-        * io/list_read.c (free_saved): Set saved_used to zero.
+       PR libgfortran/24584
+       * io/list_read.c (free_saved): Set saved_used to zero.
 
 2005-10-30  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
index b1e9afd..791a6f8 100644 (file)
@@ -434,6 +434,9 @@ iexport_data_proto(filename);
 
 /* main.c */
 
+extern void stupid_function_name_for_static_linking (void);
+internal_proto(stupid_function_name_for_static_linking);
+
 extern void library_start (void);
 internal_proto(library_start);
 
index cdaa542..64a062a 100644 (file)
@@ -353,6 +353,13 @@ internal_error (const char *message)
   recursion_check ();
   show_locus ();
   st_printf ("Internal Error: %s\n", message);
+
+  /* This function call is here to get the main.o object file included
+     when linking statically. This works because error.o is supposed to
+     be always linked in (and the function call is in internal_error
+     because hopefully it doesn't happen too often).  */
+  stupid_function_name_for_static_linking();
+
   sys_exit (3);
 }
 
index 1186a30..cfd77f2 100644 (file)
@@ -35,6 +35,14 @@ Boston, MA 02110-1301, USA.  */
 
 #include "libgfortran.h"
 
+/* Stupid function to be sure the constructor is always linked in, even
+   in the case of static linking.  See PR libfortran/22298 for details.  */
+void
+stupid_function_name_for_static_linking (void)
+{
+  return;
+}
+
 /* This is the offset (in bytes) required to cast from logical(8)* to
    logical(4)*. and still get the same result.  Will be 0 for little-endian
    machines and 4 for big-endian machines.  */