Subject: toolchain/26631: Cross-building on FreeBSD 5.2.1 fails
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <lminder@gmx.net>
List: netbsd-bugs
Date: 08/12/2004 16:25:36
>Number:         26631
>Category:       toolchain
>Synopsis:       Cross-building on FreeBSD 5.2.1 fails
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 12 18:51:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Lorenz Minder
>Release:        2.0 Beta
>Organization:
>Environment:
NetBSD dhcppc1 2.0_BETA NetBSD 2.0_BETA (MYKERNEL) #1: Thu Aug 12 00:05:00 CEST 2004  lorinder@lorenzdesktop:/usr/home/lorinder/tmp/netbsd-src/sys/arch/i386/compile/obj/MYKERNEL i386
>Description:
When trying to  "./build.sh -m i386 tools" on FreeBSD 5, this fails with

/home/lorinder/tmp/netbsd-src/usr.bin/stat/stat.c:710: error: structure has no member named `st_birthtimensec'

The problem is that FreeBSD's version of struct stat has st_birthtime but not st_birthtimensec defined, yet the code assumes that if st_birthtime is present, then so is st_birthtimensec.
>How-To-Repeat:
Execute the aforementioned command on FreeBSD 5. (Googling suggests that FreeBSD 4 is unaffected).
>Fix:
Here's a patch (mangled through the webinterface, sorry). It sets nsecs=0 if this field is not present, assuming that extra precision is non needed. Maybe a better workaround would be to disable this codeblock altogether if not both st_birthtime and st_birthtimensec are present, not sure.

Index: tools/compat/configure.ac
===================================================================
RCS file: /cvsroot/src/tools/compat/configure.ac,v
retrieving revision 1.42.2.2
diff -u -r1.42.2.2 configure.ac
--- tools/compat/configure.ac   25 Jul 2004 07:50:06 -0000      1.42.2.2
+++ tools/compat/configure.ac   11 Aug 2004 23:04:08 -0000
@@ -98,8 +98,9 @@
 [#include <sys/types.h>
 #include <dirent.h>])
 AC_CHECK_MEMBERS([struct stat.st_flags, struct stat.st_gen,
-       struct stat.st_birthtime, struct stat.st_atim,
-       struct stat.st_mtimensec],,, [#include <sys/stat.h>])
+       struct stat.st_birthtime, struct stat.st_birthtimensec,
+       struct stat.st_atim, struct stat.st_mtimensec],,,
+       [#include <sys/stat.h>])

 # Global variable decls.
 AC_CHECK_DECLS([optind, optreset],,, [
Index: usr.bin/stat/stat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/stat/stat.c,v
retrieving revision 1.17.2.2
diff -u -r1.17.2.2 stat.c
--- usr.bin/stat/stat.c 22 Jun 2004 07:22:16 -0000      1.17.2.2
+++ usr.bin/stat/stat.c 11 Aug 2004 23:04:16 -0000
@@ -707,7 +707,11 @@
                if (!gottime) {
                        gottime = 1;
                        secs = st->st_birthtime;
+#if HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
                        nsecs = st->st_birthtimensec;
+#else
+                       nsecs = 0;
+#endif /* HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC */
                }
 #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
                small = (sizeof(secs) == 4);

>Release-Note:
>Audit-Trail:
>Unformatted: