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]

PATCH: (official, i.e. thought-out) Re: FreeBSD Fortran Failure


In article <20010515114710L.mitchell@codesourcery.com>,
Mark Mitchell <mark@codesourcery.com> writes:

> I'm not sure if Loren's patch is correct, or not.  

No, not even close.  It was only meant to demonstrate what must be
done, in a far less portable manner than is ultimately desired, to get
the prototype in scope on FreeBSD.  I am sorry if I didn't make it
clear that it was pure hack patch not for real use.

At the time, I had no clue how it should be fixed for real.

> An alternative would be to have fixincludes munge the header.

I personally wouldn't mind it too much, but we need to be somewhat
careful.  If ftruncate() was in whatever version of POSIX we claim to
adhere to on FreeBSD, then this would be the correct choice.

However, I have a sneaking suspicion that BSD added it before POSIX
and we don't adhere to the latest published version of POSIX.

> Another would be to autoconf for an ftruncate prototype, and create
> one if it's not there.

Interestingly, this check is already done in autoconf and ftruncate is
found (see below) thus I suspect the test was done without
_POSIX_SOURCE=1 yet code in libf2c/libI77/Makefile defines
_POSIX_SOURCE=1.

; grep ftruncate ~/tmp/[...]/i386-unknown-freebsd4.2/config.cache
ac_cv_func_ftruncate=${ac_cv_func_ftruncate='yes'}

> But, I think the simplest thing would just be to explicitly cast the
> second parameter to an off_t.  Loren, would you try that, if it makes
> sense to you?

Either of these patches works to solve the issue in a more "portable"
manner (maybe both together).  However, I think the first patch, which
ensures a prototype is in scope, is the less fragile patch.  If
FreeBSD ever upgrades to POSIX 2 and/or fixes this bug, if indeed it
is a bug, then it will still work since an exact duplicate match of a
prototype is not a problem.  If the second patch is installed alone,
someone may remove the cast and see that it still works on their
environment.  There is a problem with the second patch, this is the
first unguarded use of off_t.  What if some unistd.h doesn't define it?

It might also be in order for someone to investigate (I only looked at
the cache file) and fix the autoconf test to have the same flags as
will be used at the call site.  Or, perhaps, autoconf is only looking
to be able to link the final executable.  However, I see that every
library directory under <target> is built with different flags.  And,
every sub-directory under libf2c is built with its own special
flags... ;-/

Tested by rebuilding libf2c in already bootstrapped tree.  As
discussed above, I suggest installation of only the first patch
unless it looks like other BSDs are failing in this manner and we
have faith that off_t is widely available.

2001-05-15  Loren J. Rittle  <ljrittle@acm.org>

	* libI77/endfile.c: Workaround FreeBSD/POSIX header issue by
	unconditionally adding a prototype for ftruncate().

Index: libI77/endfile.c
===================================================================
RCS file: /cvs/gcc/egcs/libf2c/libI77/endfile.c,v
retrieving revision 1.5
diff -c -r1.5 endfile.c
*** endfile.c	2001/02/26 20:23:41	1.5
--- endfile.c	2001/05/15 19:27:19
***************
*** 3,8 ****
--- 3,17 ----
  
  #include <unistd.h>
  
+ /* FreeBSD has ftruncate() but appears to be at a POSIX compliance level
+    before it was added (thus it is excluded when _POSIX_SOURCE is
+    defined while including <unistd.h>).  */
+ #if defined(_POSIX_SOURCE) && defined(__FreeBSD__)
+ #define _FTRUNCATE_DECLARED
+ int      ftruncate (int, off_t);
+ #endif
+ 
+ 
  #ifdef KR_headers
  extern char *strcpy();
  extern FILE *tmpfile();

2001-05-15  Loren J. Rittle  <ljrittle@acm.org>

	* libI77/endfile.c (t_runc): Add cast to help case where
	ftruncate() prototype is somehow missing even though autoconf
	test found it properly.

Index: libI77/endfile.c
===================================================================
RCS file: /cvs/gcc/egcs/libf2c/libI77/endfile.c,v
retrieving revision 1.5
diff -c -r1.5 endfile.c
*** endfile.c	2001/02/26 20:23:41	1.5
--- endfile.c	2001/05/15 19:58:26
***************
*** 129,135 ****
  	f__cf = b->ufd = bf;
  #else  /* !defined(HAVE_FTRUNCATE) */
  	fflush(b->ufd);
! 	rc = ftruncate(fileno(b->ufd),loc);
  #endif /* !defined(HAVE_FTRUNCATE) */
  	if (rc)
  		err(a->aerr,111,"endfile");
--- 129,135 ----
  	f__cf = b->ufd = bf;
  #else  /* !defined(HAVE_FTRUNCATE) */
  	fflush(b->ufd);
! 	rc = ftruncate(fileno(b->ufd), (off_t) loc);
  #endif /* !defined(HAVE_FTRUNCATE) */
  	if (rc)
  		err(a->aerr,111,"endfile");


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