From f2ae4b2bd03c98446d25729a4483b35e515a08d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Coudert?= Date: Fri, 4 Nov 2005 08:44:29 +0000 Subject: re PR libfortran/22298 (libgfortran init() constructor isn't called if executable is statically linked) 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. * 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. From-SVN: r106484 --- libgfortran/runtime/error.c | 7 +++++++ libgfortran/runtime/main.c | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'libgfortran/runtime') diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index cdaa542..64a062a 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -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); } diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c index 1186a30..cfd77f2 100644 --- a/libgfortran/runtime/main.c +++ b/libgfortran/runtime/main.c @@ -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. */ -- cgit v1.1