lkml.org 
[lkml]   [2016]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
SubjectRe: Missing include file in include/uapi/linux/errqueue.h?
On Sun, Jul 10, 2016 at 9:56 AM, Willem de Bruijn <willemb@google.com> wrote:
> On Sun, Jul 10, 2016 at 1:43 AM, Brooks Moses <bmoses@google.com> wrote:
>> On Sat, Jul 9, 2016 at 10:36 AM, Brooks Moses <bmoses@google.com> wrote:
>>> I've been attempting to qualify the Linux 4.5.2 user-space headers for
>>> a toolchain release, and ran into what looks like a missing include
>>> file in include/uapi/linux/errqueue.h. In particular,
>>> https://github.com/torvalds/linux/commit/f24b9be5957b38bb420b838115040dc2031b7d0c
>>> adds the following to this file:
>>>
>>> +struct scm_timestamping {
>>> + struct timespec ts[3];
>>> +};
>>>
>>> However, struct timespec is defined in time.h, which isn't included
>>> either in 4.5.2 or in current head. Is this simply a missing #include
>>> line,
>
> It is. I missed that in my original patch.
>
>> or am I misunderstanding something?
>>
>> As a followup: Unfortunately the obvious fix -- adding "#include
>> <linux/time.h>" -- causes other problems, since linux/time.h is
>> incompatible with the glibc time.h such that including both of them
>> into the same compilation unit causes errors about redefined types.
>
> If these conflicts between libc and uapi time.h can be resolved through
> include/uapi/linux/libc-compat.h, then we can apply the obvious fix of
> including linux/time.h in linux/errqueue.h.

The below patch (bar whitespace mangling by gmail) avoids redefinition
conflicts for me if linux/time.h is included after time.h. The other direction
would also require changes to the userspace headers, as stated in
libc-compat.h.

>> And we, at least, have some programs that want to include
>> linux/errqueue.h and (glibc's) time.h. The fix of adding "#include
>> <time.h>" to linux/errqueue.h seems to work for us, but I'm not sure
>> that won't cause problems in the other direction for other people.
>
> That breaks kernel compilation.

A simpler other option is to explicitly include either of the time.h
files depending on the environment, similar to uapi/linux/lightnvm.h.

timespec itself is also explicitly defined in uapi/linux/coda.h, but that
won't avoid redefinition if time.h is included afterwards.

The rough libc-compat.h patch:

diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
index 07bdce1..6b1cdc6 100644
--- a/include/uapi/linux/errqueue.h
+++ b/include/uapi/linux/errqueue.h
@@ -2,6 +2,7 @@
#define _UAPI_LINUX_ERRQUEUE_H

#include <linux/types.h>
+#include <linux/time.h>

struct sock_extended_err {
__u32 ee_errno;
diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index e4f048e..ef33ea9 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -146,6 +146,16 @@
#define __UAPI_DEF_XATTR 1
#endif

+#if defined(_TIME_H)
+#define __UAPI_DEF_TIMESPEC 0
+#define __UAPI_DEF_ITIMERSPEC 0
+#define __UAPI_DEF_ABSTIME 0
+#else
+#define __UAPI_DEF_TIMESPEC 1
+#define __UAPI_DEF_ITIMERSPEC 1
+#define __UAPI_DEF_ABSTIME 1
+#endif /* _TIME_H */
+
/* If we did not see any headers from any supported C libraries,
* or we are being included in the kernel, then define everything
* that we need. */
@@ -182,6 +192,11 @@
/* Definitions for xattr.h */
#define __UAPI_DEF_XATTR 1

+/* Definitions for time.h */
+#define __UAPI_DEF_TIMESPEC 1
+#define __UAPI_DEF_ITIMERSPEC 1
+#define __UAPI_DEF_ABSTIME 1
+
#endif /* __GLIBC__ */

#endif /* _UAPI_LIBC_COMPAT_H */
diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h
index e75e1b6..7129c54 100644
--- a/include/uapi/linux/time.h
+++ b/include/uapi/linux/time.h
@@ -1,9 +1,10 @@
#ifndef _UAPI_LINUX_TIME_H
#define _UAPI_LINUX_TIME_H

+#include <linux/libc-compat.h>
#include <linux/types.h>

-
+#if __UAPI_DEF_TIMESPEC
#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC
struct timespec {
@@ -11,6 +12,7 @@ struct timespec {
long tv_nsec; /* nanoseconds */
};
#endif
+#endif

struct timeval {
__kernel_time_t tv_sec; /* seconds */
@@ -31,10 +33,12 @@ struct timezone {
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2

+#if __UAPI_DEF_TIMESPEC
struct itimerspec {
struct timespec it_interval; /* timer period */
struct timespec it_value; /* timer expiration */
};
+#endif

struct itimerval {
struct timeval it_interval; /* timer interval */
@@ -64,6 +68,8 @@ struct itimerval {
/*
* The various flags for setting POSIX.1b interval timers:
*/
+#if __UAPI_DEF_ABSTIME
#define TIMER_ABSTIME 0x01
+#endif

#endif /* _UAPI_LINUX_TIME_H */
\
 
 \ /
  Last update: 2016-07-10 18:01    [W:0.036 / U:5.544 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site