rems-project / sail

Sail architecture definition language
Other
631 stars 117 forks source link

POSIX-correctness of C RTS includes #359

Open nwf-msr opened 1 year ago

nwf-msr commented 1 year ago

I'm sorry to have to report this, but POSIX gonna POSIX. On a Linux box calling itself an installation of "CentOS Linux 7 (Core)", apparently we need to adhere a little more strictly to POSIX. Specifically, the use of ssize_t in https://github.com/rems-project/sail/blob/f9db302f925418fc7aef5f97440ae89e4f43ff3d/lib/rts.c#L475 seems to require that we include <sys/types.h>, and the use of struct timespec in https://github.com/rems-project/sail/blob/f9db302f925418fc7aef5f97440ae89e4f43ff3d/lib/sail.c#L1790 requires that we include <time.h>... and be targeting C11 or POSIX 1993.09 or later, and the use of CLOCK_REALTIME in https://github.com/rems-project/sail/blob/f9db302f925418fc7aef5f97440ae89e4f43ff3d/lib/sail.c#L1791 seems to specifically require POSIX 1993.09 or later.

So, I think I would like it if rts.c grew a #include <sys/types.h> and sail.c grew a #include <time.h> and had something like

#if !defined(_POSIX_C_SOURCE) || ((_POSIX_C_SOURCE - 0) < 200809L)
#  undef _POSIX_C_SOURCE
#  define _POSIX_C_SOURCE 200809L
#endif

tacked on to the top? Failing that, maybe documenting the need to pass -D_POSIX_C_SOURCE=200809L to the compiler on sufficiently old systems would suffice? That said, I'm open to suggestions.

Alasdair commented 1 year ago

I added the sys/types.h include, but I think the time.h include is already there?

nwf-msr commented 11 months ago

Whoop, sorry, I dropped the ball here. Yes, the issue isn't that time.h isn't being included, it's that it's sensitive to which version of POSIX is being requested, and on some old systems the default doesn't make CLOCK_REALTIME available.