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]

[Patch] Don't provide lstat gfortran intrinsic if target doesn't support lstat.


Hello,

On win32 targets, the use of constructor attribute to initialize
library causes problems when libgfortran is used in projects that
require the native (MS) linker.

Although the library links without error to a MSVC-compiled main, the
constructors are not run at startup, and so the project crashes because,
eg, std I/O connections are not initialized properly.

Building libgfortran as a dll remove the interoperability problem,
because then the library, as a self-contained executable image, takes
cares of its own initialization.

Building libgfortan as dll would also be very nice for people who don't
use MS compiler :).

However. there is one obstacle preventing libgfortan.dll: an undefined
reference to the lstat function in intrinsics/stat.c. As I indicated
above, windows dlls are self-contained and self-contained to the point
that they do  not allow undefined references. POSIX style symlinks
are not supported on windows so there is no need for lstat intrinsic.
Get rid
of the reference and building libgfortran.dll is simple.

This patch tests for a target lstat() function and avoids creating a
gfortran intrinsic if it does't exist. OK for mainline?


2006-10-20  Danny Smith  <dannysmith@users.sourceforge.net>

	* configure.ac: Test for lstat.
	* configure: Regenerate.
	* config.h.in: Regenerate.
	* instrinsics/stat.c: Don't create fortran lstat intrinsics if
	lstat is not available.
 

Index: intrinsics/stat.c
===================================================================
--- intrinsics/stat.c	(revision 117900)
+++ intrinsics/stat.c	(working copy)
@@ -30,6 +30,7 @@
 
 #include "config.h"
 #include "libgfortran.h"
+#include "ansidecl.h"
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
@@ -65,7 +66,7 @@
 
 static void
 stat_i4_sub_0 (char *name, gfc_array_i4 *sarray, GFC_INTEGER_4 *status,
-	       gfc_charlen_type name_len, int is_lstat)
+	       gfc_charlen_type name_len, int is_lstat ATTRIBUTE_UNUSED)
 {
   int val;
   char *str;
@@ -88,9 +89,11 @@
   memcpy (str, name, name_len);
   str[name_len] = '\0';
 
+#ifdef HAVE_LSTAT
   if (is_lstat)
     val = lstat(str, &sb);
   else
+#endif
     val = stat(str, &sb);
 
   if (val == 0)
@@ -164,7 +167,7 @@
 }
 iexport(stat_i4_sub);
 
-
+#ifdef HAVE_LSTAT
 extern void lstat_i4_sub (char *, gfc_array_i4 *, GFC_INTEGER_4 *,
 			 gfc_charlen_type);
 iexport_proto(lstat_i4_sub);
@@ -176,12 +179,11 @@
   stat_i4_sub_0 (name, sarray, status, name_len, 1);
 }
 iexport(lstat_i4_sub);
-
-
+#endif /* HAVE_LSTAT */
 
 static void
 stat_i8_sub_0 (char *name, gfc_array_i8 *sarray, GFC_INTEGER_8 *status,
-	       gfc_charlen_type name_len, int is_lstat)
+	       gfc_charlen_type name_len, int is_lstat ATTRIBUTE_UNUSED)
 {
   int val;
   char *str;
@@ -204,9 +206,11 @@
   memcpy (str, name, name_len);
   str[name_len] = '\0';
 
+#ifdef HAVE LSTAT
   if (is_lstat)
     val = lstat(str, &sb);
   else
+#endif
     val = stat(str, &sb);
 
   if (val == 0)
@@ -281,7 +285,7 @@
 
 iexport(stat_i8_sub);
 
-
+#ifdef HAVE_LSTAT
 extern void lstat_i8_sub (char *, gfc_array_i8 *, GFC_INTEGER_8 *,
 			 gfc_charlen_type);
 iexport_proto(lstat_i8_sub);
@@ -294,7 +298,7 @@
 }
 
 iexport(lstat_i8_sub);
-
+#endif /* HAVE_LSTAT */
 
 extern GFC_INTEGER_4 stat_i4 (char *, gfc_array_i4 *,
gfc_charlen_type);
 export_proto(stat_i4);
@@ -329,6 +333,7 @@
    CHARACTER(len=*), INTENT(IN) :: FILE
    INTEGER, INTENT(OUT), :: SARRAY(13)  */
 
+#ifdef HAVE_LSTAT
 extern GFC_INTEGER_4 lstat_i4 (char *, gfc_array_i4 *,
gfc_charlen_type);
 export_proto(lstat_i4);
 
@@ -350,7 +355,7 @@
   lstat_i8_sub (name, sarray, &val, name_len);
   return val;
 }
-
+#endif /* HAVE_LSTAT */
 
 
 /* SUBROUTINE FSTAT(UNIT, SARRAY, STATUS)
Index: configure.ac
===================================================================
--- configure.ac	(revision 117900)
+++ configure.ac	(working copy)
@@ -172,7 +172,7 @@
 AC_CHECK_FUNCS(getrusage times mkstemp strtof strtold snprintf
ftruncate chsize)
 AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink
perror)
 AC_CHECK_FUNCS(sleep time ttyname signal alarm ctime clock access fork
execl)
-AC_CHECK_FUNCS(wait setmode)
+AC_CHECK_FUNCS(wait setmode lstat)
 
 # Check for types
 AC_CHECK_TYPES([intptr_t])


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