Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build broken on MacOS due to tv_nsec #1230

Closed
veripoolbot opened this issue Oct 14, 2017 · 5 comments
Closed

Build broken on MacOS due to tv_nsec #1230

veripoolbot opened this issue Oct 14, 2017 · 5 comments
Assignees
Labels
area: configure/compiling Issue involves configuring or compilating Verilator itself resolution: fixed Closed; fixed

Comments

@veripoolbot
Copy link
Contributor


Author Name: Jeff Bush (@jbush001)
Original Redmine Issue: 1230 from https://www.veripool.org

Original Assignee: Wilson Snyder (@wsnyder)


After change 5bc2f87, the build fails on MacOS (Command line tools 9.0, macOS Sierra 10.12):

../V3File.cpp:82:34: error: no member named 'st_ctim' in 'stat'
         time_t cnstime() const { return VL_STAT_CTIME_NSEC(m_stat); } // Nanoseconds
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
../V3File.cpp:38:43: note: expanded from macro 'VL_STAT_CTIME_NSEC'
1. define VL_STAT_CTIME_NSEC(stat) ((stat).st_ctim.tv_nsec) // Nanoseconds
                                    ~~~~~~ ^
../V3File.cpp:84:34: error: no member named 'st_mtim' in 'stat'
         time_t mnstime() const { return VL_STAT_MTIME_NSEC(m_stat); } // Nanoseconds
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
...
</code>

Looking in /usr/include/sys/stat.h, it appears setting _DARWIN_C_SOURCE might fix this (not sure what other side effects it might have):

#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
#define st_atime st_atimespec.tv_sec
#define st_mtime st_mtimespec.tv_sec
#define st_ctime st_ctimespec.tv_sec
#define st_birthtime st_birthtimespec.tv_sec
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Jeff Bush (@jbush001)
Original Date: 2017-10-14T11:23:13Z


The other thing is that the V3File is checking the 'st_mtime' macro for the presence of the fields st_ctim and st_mtim. This macro is defined on MacOS. There might be a more portable way to check for the presence of these fields.

#ifdef st_mtime // Linux 2.6
1. define VL_STAT_CTIME_NSEC(stat) ((stat).st_ctim.tv_nsec) // Nanoseconds
1. define VL_STAT_MTIME_NSEC(stat) ((stat).st_mtim.tv_nsec) // Nanoseconds
#else
1. define VL_STAT_CTIME_NSEC(stat) (0)
1. define VL_STAT_MTIME_NSEC(stat) (0)
#endif

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Jeff Bush (@jbush001)
Original Date: 2017-10-14T11:25:58Z


Removing that define does fix the build error:

+++ b/src/V3File.cpp
@@ -34,7 +34,7 @@
 # define INFILTER_PIPE  // Allow pipe filtering.  Needs fork()
 #endif
 
-#ifdef st_mtime // Linux 2.6
+#if 0
 # define VL_STAT_CTIME_NSEC(stat) ((stat).st_ctim.tv_nsec) // Nanoseconds
 # define VL_STAT_MTIME_NSEC(stat) ((stat).st_mtim.tv_nsec) // Nanoseconds
 #else
</code>

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Jeff Bush (@jbush001)
Original Date: 2017-10-14T11:56:11Z


From http://man7.org/linux/man-pages/man2/stat.2.html:

"Nanosecond timestamps were standardized in POSIX.1-2008, and,
starting with version 2.12, glibc exposes the nanosecond component
names if _POSIX_C_SOURCE is defined with the value 200809L or
greater, or _XOPEN_SOURCE is defined with the value 700 or greater.
Up to and including glibc 2.19, the definitions of the nanoseconds
components are also defined if _BSD_SOURCE or _SVID_SOURCE is
defined."

I've confirmed that checking the _BSD_SOURCE macro fixes the problem on MacOS:

--- a/src/V3File.cpp
+++ b/src/V3File.cpp
@@ -34,7 +34,7 @@
 # define INFILTER_PIPE  // Allow pipe filtering.  Needs fork()
 #endif
 
-#ifdef st_mtime // Linux 2.6
+#ifdef _BSD_SOURCE
 # define VL_STAT_CTIME_NSEC(stat) ((stat).st_ctim.tv_nsec) // Nanoseconds
 # define VL_STAT_MTIME_NSEC(stat) ((stat).st_mtim.tv_nsec) // Nanoseconds
 #else
</code>

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2017-10-14T13:03:51Z


Thanks. The reliable thing to do is run an experiment in configure, which I should have done in the first place.

Fixed in git towards 3.914.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2017-10-14T20:22:42Z


In 3.914.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: configure/compiling Issue involves configuring or compilating Verilator itself resolution: fixed Closed; fixed
Projects
None yet
Development

No branches or pull requests

2 participants