public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* bfd/vmsutil.c file timestamp calculations
       [not found] <20090121115805.8321.qmail@sourceware.org>
@ 2009-05-06  0:54 ` Douglas B Rupp
  2009-05-06  1:48   ` Cary Coutant
  0 siblings, 1 reply; 5+ messages in thread
From: Douglas B Rupp @ 2009-05-06  0:54 UTC (permalink / raw)
  To: nickc; +Cc: binutils

VMS stores file timestamps in local time with 100 nsec precision, so I 
really need to figure out a way to do this correctly for a cross 
compiler to work with the VMS debugger.

I can use the external symbols timezone and daylight instead of 
tm_gmtoff, if that's portable.  Not sure what do do about the other 
followup patch to this file that removed st_mtim.tv_nsec.  Is there a 
macro I can test or will I have to add some configure machinery? 
Looking for some advice here.

--Doug

nickc@sourceware.org wrote:
> CVSROOT:	/cvs/src
> Module name:	src
> Changes by:	nickc@sourceware.org	2009-01-21 11:58:05
> 
> Modified files:
> 	bfd            : ChangeLog vmsutil.c 
> 
> Log message:
> 	PR 9769
> 	* vmsutil.c (vms_file_stats_name): Remove use of unsupported
> 	tm_gmtoff field in struct tm.
> 
> Patches:
> http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4431&r2=1.4432
> http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/vmsutil.c.diff?cvsroot=src&r1=1.1&r2=1.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bfd/vmsutil.c file timestamp calculations
  2009-05-06  0:54 ` bfd/vmsutil.c file timestamp calculations Douglas B Rupp
@ 2009-05-06  1:48   ` Cary Coutant
  2009-05-06  3:03     ` Douglas B Rupp
  2009-05-12  1:38     ` Restore bfd/vmsutil.c GMT adjustment [PATCH] Douglas B Rupp
  0 siblings, 2 replies; 5+ messages in thread
From: Cary Coutant @ 2009-05-06  1:48 UTC (permalink / raw)
  To: Douglas B Rupp; +Cc: nickc, binutils

> I can use the external symbols timezone and daylight instead of tm_gmtoff,
> if that's portable.  Not sure what do do about the other followup patch to
> this file that removed st_mtim.tv_nsec.  Is there a macro I can test or will
> I have to add some configure machinery? Looking for some advice here.

The st_mtim field in a struct timeval is a Sun extension, and is
available in newer versions of glibc if you define _BSD_SOURCE before
including <stat.h>. I think you'll need a configure test for it, and
fall back to setting the nanosecond component to 0 in its absence.

For tm_gmtoff in a struct tm, you can use a configure test for that,
too, but you also need to define _BSD_SOURCE to get it.

As far as I can tell, the timezone symbol should be portable (it's
listed as SVID 3 and POSIX); just call tzset() to initialize it if you
don't call some other time conversion function first. The daylight
symbol is obsolete, and it wouldn't tell you whether or not DST is in
effect anyway -- you'd need to call localtime() with your time_t value
and check tm_isdst.

Are you sure you need to correct for daylight saving time? What does
"local time" mean on VMS? Does it change when DST goes in and out of
effect? The timezone variable will give you the number of seconds west
of GMT for your standard timezone -- the same value whether DST is in
effect or not.

-cary

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bfd/vmsutil.c file timestamp calculations
  2009-05-06  1:48   ` Cary Coutant
@ 2009-05-06  3:03     ` Douglas B Rupp
  2009-05-12  1:38     ` Restore bfd/vmsutil.c GMT adjustment [PATCH] Douglas B Rupp
  1 sibling, 0 replies; 5+ messages in thread
From: Douglas B Rupp @ 2009-05-06  3:03 UTC (permalink / raw)
  To: Cary Coutant; +Cc: nickc, binutils

Cary Coutant wrote:

> Are you sure you need to correct for daylight saving time? What does
> "local time" mean on VMS? Does it change when DST goes in and out of
> effect? The timezone variable will give you the number of seconds west
> of GMT for your standard timezone -- the same value whether DST is in
> effect or not.

Unfortunately yes, it needs to be corrected for DST. I have to reset the 
system time on VMS manually when DST goes into effect.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Restore bfd/vmsutil.c GMT adjustment [PATCH]
  2009-05-06  1:48   ` Cary Coutant
  2009-05-06  3:03     ` Douglas B Rupp
@ 2009-05-12  1:38     ` Douglas B Rupp
  2009-07-01 15:03       ` Nick Clifton
  1 sibling, 1 reply; 5+ messages in thread
From: Douglas B Rupp @ 2009-05-12  1:38 UTC (permalink / raw)
  To: binutils; +Cc: Cary Coutant

[-- Attachment #1: Type: text/plain, Size: 111 bytes --]

Taking into account the very helpful comments of Cary Coutant, the 
following patch is submitted for comment.


[-- Attachment #2: vmsutil.diff.txt --]
[-- Type: text/plain, Size: 5877 bytes --]

	* bfd/bfd.m4 (BFD_HAVE_TIME_TYPE_MEMBER,
	BFD_HAVE_SYS_STAT_TYPE_MEMBER): New config functions.
	* bfd/configure.in: Use them.
	* bfd/configure: Regenerate.
	* bfd/config.in: Regnerate.
	* bfd/vmsutil.c: Include sysdep.h, remove ansidecl.h.
	#define _BSD_SOURCE. Add comments.
	(vms_file_stats_name): Calculate creation date based on available
	runtime data. Return 1 for version instead of 0.

Index: bfd/bfd.m4
===================================================================
RCS file: /cvs/src/src/bfd/bfd.m4,v
retrieving revision 1.4
diff -u -p -r1.4 bfd.m4
--- bfd/bfd.m4	13 Jul 2005 21:19:13 -0000	1.4
+++ bfd/bfd.m4	12 May 2009 00:39:56 -0000
@@ -40,3 +40,41 @@ AC_DEFUN([BFD_HAVE_SYS_PROCFS_TYPE_MEMBE
  AC_MSG_RESULT($bfd_cv_have_sys_procfs_type_member_$1_$2)
 ])
 
+dnl Check for existence of member $2 in type $1 in time.h
+
+AC_DEFUN([BFD_HAVE_TIME_TYPE_MEMBER],
+[AC_MSG_CHECKING([for $1.$2 in time.h])
+ AC_CACHE_VAL(bfd_cv_have_time_type_member_$2,
+   [AC_TRY_COMPILE([
+#define _BSD_SOURCE 1
+#include <time.h>],
+      [$1 avar; void* aref = (void*) &avar.$2],
+      bfd_cv_have_time_type_member_$2=yes,
+      bfd_cv_have_time_type_member_$2=no
+   )])
+ if test $bfd_cv_have_time_type_member_$2 = yes; then
+   AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z]), 1,
+	     [Define if <time.h> has $1.$2.])
+ fi
+ AC_MSG_RESULT($bfd_cv_have_time_type_member_$2)
+])
+
+dnl Check for existence of member $2.$3 in type $1 in sys/stat.h
+
+AC_DEFUN([BFD_HAVE_SYS_STAT_TYPE_MEMBER],
+[AC_MSG_CHECKING([for $1.$2.$3 in sys/stat.h])
+ AC_CACHE_VAL(bfd_cv_have_sys_stat_type_member_$2_$3,
+   [AC_TRY_COMPILE([
+#define _BSD_SOURCE 1
+#include <sys/stat.h>],
+      [$1 avar; void* aref = (void*) &avar.$2.$3],
+      bfd_cv_have_sys_stat_type_member_$2_$3=yes,
+      bfd_cv_have_sys_stat_type_member_$2_$3=no
+   )])
+ if test $bfd_cv_have_sys_stat_type_member_$2_$3 = yes; then
+   AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z])[_]translit($3, [a-z], [A-Z]), 1,
+	     [Define if <sys/stat.h> has $1.$2.$3])
+ fi
+ AC_MSG_RESULT($bfd_cv_have_sys_stat_type_member_$2_$3)
+])
+
Index: bfd/configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.260
diff -u -p -r1.260 configure.in
--- bfd/configure.in	17 Apr 2009 13:46:16 -0000	1.260
+++ bfd/configure.in	12 May 2009 00:40:01 -0000
@@ -183,7 +183,7 @@ AC_SUBST(BFD_HOSTPTR_T)
 BFD_CC_FOR_BUILD
 
 AC_CHECK_HEADERS(alloca.h stddef.h string.h strings.h stdlib.h time.h unistd.h)
-AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h)
+AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h sys/stat.h)
 GCC_HEADER_STDINT(bfd_stdint.h)
 AC_HEADER_TIME
 AC_HEADER_DIRENT
@@ -209,6 +209,17 @@ AC_CHECK_DECLS(strstr)
 AC_CHECK_DECLS(snprintf)
 AC_CHECK_DECLS(vsnprintf)
 
+# Support for VMS timestamps via cross compile
+
+if test "$ac_cv_header_time_h" = yes; then
+  BFD_HAVE_TIME_TYPE_MEMBER(struct tm, tm_gmtoff)
+fi
+
+if test "$ac_cv_header_sys_stat_h" = yes; then
+    BFD_HAVE_SYS_STAT_TYPE_MEMBER(struct stat, st_mtim, tv_sec)
+    BFD_HAVE_SYS_STAT_TYPE_MEMBER(struct stat, st_mtim, tv_nsec)
+fi
+
 # Link in zlib if we can.  This allows us to read compressed debug sections.
 # This is used only by compress.c.
 AC_SEARCH_LIBS(zlibVersion, z, [AC_CHECK_HEADERS(zlib.h)])
Index: bfd/vmsutil.c
===================================================================
RCS file: /cvs/src/src/bfd/vmsutil.c,v
retrieving revision 1.3
diff -u -p -r1.3 vmsutil.c
--- bfd/vmsutil.c	20 Feb 2009 18:53:12 -0000	1.3
+++ bfd/vmsutil.c	12 May 2009 01:23:54 -0000
@@ -17,9 +17,16 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#include "ansidecl.h"
+#include "sysdep.h"
 #include "vmsutil.h"
 
+/* 
+   The purspose of the two alternate versions below is to have one that
+   works for native VMS and one that works on an NFS mounted filesystem
+   (Unix Server/VMS client). The main issue being to generated the special
+   VMS file timestamps for the debug info.
+*/
+
 #ifdef VMS
 #define __NEW_STARLET 1
 #include <vms/starlet.h>
@@ -90,6 +97,7 @@ to_vms_file_spec (char *filespec)
 }
 
 #else
+#define _BSD_SOURCE 1
 #include <sys/stat.h>
 #include <time.h>
 #define VMS_EPOCH_OFFSET 35067168000000000LL
@@ -237,14 +245,46 @@ vms_file_stats_name (const char *filenam
   return 0;
 #else
   struct stat buff;
+  struct tm *ts;
+  long long gmtoff, secs, nsecs;
 
   if ((stat (filename, &buff)) != 0)
      return 1;
 
   if (cdt)
     {
-      *cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
-                         + VMS_EPOCH_OFFSET;
+      ts = localtime (&buff.st_mtime);
+
+#ifdef HAVE_TM_GMTOFF
+	gmtoff = ts->tm_gmtoff;
+#else
+	{
+	  extern long timezone;
+
+	  if (ts->tm_isdst == 1)
+	    gmtoff = -(timezone - 3600);
+	  else
+	    gmtoff = -timezone;
+	}
+#endif
+
+#ifdef HAVE_ST_MTIM_TV_SEC
+      secs = buff.st_mtim.tv_sec;
+#else
+      secs = buff.st_mtime;
+#endif
+
+#ifdef HAVE_ST_MTIM_TV_NSEC
+      nsecs = buff.st_mtim.tv_nsec;
+#else
+      nsecs = 0;
+#endif
+
+      /* VMS timestamps are stored in local time to 100 nsec accuracy, but by
+	 experiment I found timestamps truncated to (at least) microseconds
+	 on an NFS mounted filesystem, hence the adjustment below. DBR. */
+      *cdt = ((secs + gmtoff) * VMS_GRANULARITY_FACTOR)
+              + (nsecs / 1000 * 10) + VMS_EPOCH_OFFSET;
     }
 
   if (siz)
@@ -253,8 +293,11 @@ vms_file_stats_name (const char *filenam
   if (rfo)
     *rfo = 2; /* Stream LF format.  */
 
+  /* Returning a file version of 0 is never correct for debug info, version 1
+     will be correct if file editing is done only on the Unix side. If editing
+     is done on the VMS side, then its TBD. */
   if (ver)
-    *ver = 0;
+    *ver = 1;
 
   return 0;
 #endif

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Restore bfd/vmsutil.c GMT adjustment [PATCH]
  2009-05-12  1:38     ` Restore bfd/vmsutil.c GMT adjustment [PATCH] Douglas B Rupp
@ 2009-07-01 15:03       ` Nick Clifton
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Clifton @ 2009-07-01 15:03 UTC (permalink / raw)
  To: Douglas B Rupp; +Cc: binutils, Cary Coutant

Hi Douglas,

> Taking into account the very helpful comments of Cary Coutant, the 
> following patch is submitted for comment.

Thank you for submitting this patch and sorry taking so long to review 
it.  The patch is good, so I have gone ahead and checked it into the 
sources.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-01 15:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20090121115805.8321.qmail@sourceware.org>
2009-05-06  0:54 ` bfd/vmsutil.c file timestamp calculations Douglas B Rupp
2009-05-06  1:48   ` Cary Coutant
2009-05-06  3:03     ` Douglas B Rupp
2009-05-12  1:38     ` Restore bfd/vmsutil.c GMT adjustment [PATCH] Douglas B Rupp
2009-07-01 15:03       ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).