diff mbox

[v06,18/36] uapi linux/errqueue.h: include linux/time.h in user space

Message ID 20170806164428.2273-19-mikko.rapeli@iki.fi
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Mikko Rapeli Aug. 6, 2017, 4:44 p.m. UTC
linux/time.h conflicts with user space header time.h. Try to be compatible
with both.

Fixes userspace compilation error:

error: array type has incomplete element type
 struct timespec ts[3];

Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Soheil Hassas Yeganeh <soheil@google.com>
Cc: netdev@vger.kernel.org
---
 include/uapi/linux/errqueue.h | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Willem de Bruijn Aug. 6, 2017, 8:23 p.m. UTC | #1
On Sun, Aug 6, 2017 at 12:44 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
> linux/time.h conflicts with user space header time.h. Try to be compatible
> with both.
>
> Fixes userspace compilation error:
>
> error: array type has incomplete element type
>  struct timespec ts[3];
>
> Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: Soheil Hassas Yeganeh <soheil@google.com>
> Cc: netdev@vger.kernel.org
> ---
>  include/uapi/linux/errqueue.h | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
> index 07bdce1f444a..b310b2c6d94f 100644
> --- a/include/uapi/linux/errqueue.h
> +++ b/include/uapi/linux/errqueue.h
> @@ -3,6 +3,12 @@
>
>  #include <linux/types.h>
>
> +#ifdef __KERNEL__
> +#include <linux/time.h>
> +#else
> +#include <time.h>
> +#endif /* __KERNEL__ */

This will break applications that include <linux/time.h> manually.

I previously sent a patch to use libc-compat to make compilation succeed
when both are included in the case where <linux/time.h> is included after
<time.h>.

  https://lkml.org/lkml/2016/9/12/872

The inverse will require changes to the libc header to avoid redefining
symbols already defined by <linux/time.h>

The second patch in that 2-patch set included <linux/time.h>
unconditionally after the fix. This broke builds that also included
<time.h> in the wrong order. I did not resubmit the first patch as a
stand-alone, as it is not sufficient to avoid breakage.
Willem de Bruijn Aug. 6, 2017, 8:26 p.m. UTC | #2
On Sun, Aug 6, 2017 at 4:23 PM, Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
> On Sun, Aug 6, 2017 at 12:44 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
>> linux/time.h conflicts with user space header time.h. Try to be compatible
>> with both.
>>
>> Fixes userspace compilation error:
>>
>> error: array type has incomplete element type
>>  struct timespec ts[3];
>>
>> Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
>> Cc: Willem de Bruijn <willemb@google.com>
>> Cc: Soheil Hassas Yeganeh <soheil@google.com>
>> Cc: netdev@vger.kernel.org
>> ---
>>  include/uapi/linux/errqueue.h | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
>> index 07bdce1f444a..b310b2c6d94f 100644
>> --- a/include/uapi/linux/errqueue.h
>> +++ b/include/uapi/linux/errqueue.h
>> @@ -3,6 +3,12 @@
>>
>>  #include <linux/types.h>
>>
>> +#ifdef __KERNEL__
>> +#include <linux/time.h>
>> +#else
>> +#include <time.h>
>> +#endif /* __KERNEL__ */
>
> This will break applications that include <linux/time.h> manually.

Also, the patch title reads "include <linux/time.h> in user space",
but it includes <time.h> in that environment.
Mikko Rapeli Aug. 6, 2017, 8:56 p.m. UTC | #3
On Sun, Aug 06, 2017 at 04:23:16PM -0400, Willem de Bruijn wrote:
> On Sun, Aug 6, 2017 at 12:44 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
> > linux/time.h conflicts with user space header time.h. Try to be compatible
> > with both.
> >
> > Fixes userspace compilation error:
> >
> > error: array type has incomplete element type
> >  struct timespec ts[3];
> >
> > Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
> > Cc: Willem de Bruijn <willemb@google.com>
> > Cc: Soheil Hassas Yeganeh <soheil@google.com>
> > Cc: netdev@vger.kernel.org
> > ---
> >  include/uapi/linux/errqueue.h | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
> > index 07bdce1f444a..b310b2c6d94f 100644
> > --- a/include/uapi/linux/errqueue.h
> > +++ b/include/uapi/linux/errqueue.h
> > @@ -3,6 +3,12 @@
> >
> >  #include <linux/types.h>
> >
> > +#ifdef __KERNEL__
> > +#include <linux/time.h>
> > +#else
> > +#include <time.h>
> > +#endif /* __KERNEL__ */
> 
> This will break applications that include <linux/time.h> manually.
> I previously sent a patch to use libc-compat to make compilation succeed
> when both are included in the case where <linux/time.h> is included after
> <time.h>.
> 
>   https://lkml.org/lkml/2016/9/12/872
> 
> The inverse will require changes to the libc header to avoid redefining
> symbols already defined by <linux/time.h>
> 
> The second patch in that 2-patch set included <linux/time.h>
> unconditionally after the fix. This broke builds that also included
> <time.h> in the wrong order. I did not resubmit the first patch as a
> stand-alone, as it is not sufficient to avoid breakage.

I wasn't aware of your change, but I was about to send this to fix the
case when glibc <time.h> is included before <linux/time.h>:

https://github.com/mcfrisk/linux/commit/f3952a27b8a21c6478d26e6246055383483f6a66

but you also ran into problems where <linux/time.h> is included before
<time.h> which need fixes in libc header side.

So how to proceed with these?

I don't like leaving a few dozen non-compiling header files into uapi.

-Mikko
Mikko Rapeli Aug. 6, 2017, 8:58 p.m. UTC | #4
On Sun, Aug 06, 2017 at 04:26:50PM -0400, Willem de Bruijn wrote:
> On Sun, Aug 6, 2017 at 4:23 PM, Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> > On Sun, Aug 6, 2017 at 12:44 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
> >> linux/time.h conflicts with user space header time.h. Try to be compatible
> >> with both.
> >>
> >> Fixes userspace compilation error:
> >>
> >> error: array type has incomplete element type
> >>  struct timespec ts[3];
> >>
> >> Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
> >> Cc: Willem de Bruijn <willemb@google.com>
> >> Cc: Soheil Hassas Yeganeh <soheil@google.com>
> >> Cc: netdev@vger.kernel.org
> >> ---
> >>  include/uapi/linux/errqueue.h | 6 ++++++
> >>  1 file changed, 6 insertions(+)
> >>
> >> diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
> >> index 07bdce1f444a..b310b2c6d94f 100644
> >> --- a/include/uapi/linux/errqueue.h
> >> +++ b/include/uapi/linux/errqueue.h
> >> @@ -3,6 +3,12 @@
> >>
> >>  #include <linux/types.h>
> >>
> >> +#ifdef __KERNEL__
> >> +#include <linux/time.h>
> >> +#else
> >> +#include <time.h>
> >> +#endif /* __KERNEL__ */
> >
> > This will break applications that include <linux/time.h> manually.
> 
> Also, the patch title reads "include <linux/time.h> in user space",
> but it includes <time.h> in that environment.

Oops, missed while squashing some commits. Will fix. Thanks!

-Mikko
Willem de Bruijn Aug. 6, 2017, 9:24 p.m. UTC | #5
>> > +#ifdef __KERNEL__
>> > +#include <linux/time.h>
>> > +#else
>> > +#include <time.h>
>> > +#endif /* __KERNEL__ */
>>
>> This will break applications that include <linux/time.h> manually.
>> I previously sent a patch to use libc-compat to make compilation succeed
>> when both are included in the case where <linux/time.h> is included after
>> <time.h>.
>>
>>   https://lkml.org/lkml/2016/9/12/872
>>
>> The inverse will require changes to the libc header to avoid redefining
>> symbols already defined by <linux/time.h>
>>
>> The second patch in that 2-patch set included <linux/time.h>
>> unconditionally after the fix. This broke builds that also included
>> <time.h> in the wrong order. I did not resubmit the first patch as a
>> stand-alone, as it is not sufficient to avoid breakage.
>
> I wasn't aware of your change, but I was about to send this to fix the
> case when glibc <time.h> is included before <linux/time.h>:
>
> https://github.com/mcfrisk/linux/commit/f3952a27b8a21c6478d26e6246055383483f6a66

There are a few differences between the two. Including <time.h> does not
unconditionally define all the symbols. Some are conditional on additional
state, such as __timespec_defined.

> but you also ran into problems where <linux/time.h> is included before
> <time.h> which need fixes in libc header side.
>
> So how to proceed with these?

The libc-compat change is a good fix that can be submitted on its own.

> I don't like leaving a few dozen non-compiling header files into uapi.

I agree, but I do not see a simple solution.

Unless libc has the analogous change, including either <time.h> or
<linux/time.h> in userspace can unfortunately cause breakage.

The added include if __KERNEL__ is defined should be safe, though.
Mikko Rapeli Aug. 6, 2017, 9:33 p.m. UTC | #6
On Sun, Aug 06, 2017 at 05:24:20PM -0400, Willem de Bruijn wrote:
> >> > +#ifdef __KERNEL__
> >> > +#include <linux/time.h>
> >> > +#else
> >> > +#include <time.h>
> >> > +#endif /* __KERNEL__ */
> >>
> >> This will break applications that include <linux/time.h> manually.
> >> I previously sent a patch to use libc-compat to make compilation succeed
> >> when both are included in the case where <linux/time.h> is included after
> >> <time.h>.
> >>
> >>   https://lkml.org/lkml/2016/9/12/872
> >>
> >> The inverse will require changes to the libc header to avoid redefining
> >> symbols already defined by <linux/time.h>
> >>
> >> The second patch in that 2-patch set included <linux/time.h>
> >> unconditionally after the fix. This broke builds that also included
> >> <time.h> in the wrong order. I did not resubmit the first patch as a
> >> stand-alone, as it is not sufficient to avoid breakage.
> >
> > I wasn't aware of your change, but I was about to send this to fix the
> > case when glibc <time.h> is included before <linux/time.h>:
> >
> > https://github.com/mcfrisk/linux/commit/f3952a27b8a21c6478d26e6246055383483f6a66
> 
> There are a few differences between the two. Including <time.h> does not
> unconditionally define all the symbols. Some are conditional on additional
> state, such as __timespec_defined.

Yep, your patch seems better for libc-compat.h. Could you send it again?

> > but you also ran into problems where <linux/time.h> is included before
> > <time.h> which need fixes in libc header side.
> >
> > So how to proceed with these?
> 
> The libc-compat change is a good fix that can be submitted on its own.

Yes, please do so.

> > I don't like leaving a few dozen non-compiling header files into uapi.
> 
> I agree, but I do not see a simple solution.
> 
> Unless libc has the analogous change, including either <time.h> or
> <linux/time.h> in userspace can unfortunately cause breakage.
> 
> The added include if __KERNEL__ is defined should be safe, though.

Yes, for the kernel side, but your libc-compat change would nice for
userspace, where something will break for sure, but providing source
API compatibility is sometimes impossible.

To summarize, this change from me, and your libc-compat.c for time.h, or?

-Mikko
Willem de Bruijn Aug. 6, 2017, 9:42 p.m. UTC | #7
On Sun, Aug 6, 2017 at 5:33 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
> On Sun, Aug 06, 2017 at 05:24:20PM -0400, Willem de Bruijn wrote:
>> >> > +#ifdef __KERNEL__
>> >> > +#include <linux/time.h>
>> >> > +#else
>> >> > +#include <time.h>
>> >> > +#endif /* __KERNEL__ */
>> >>
>> >> This will break applications that include <linux/time.h> manually.
>> >> I previously sent a patch to use libc-compat to make compilation succeed
>> >> when both are included in the case where <linux/time.h> is included after
>> >> <time.h>.
>> >>
>> >>   https://lkml.org/lkml/2016/9/12/872
>> >>
>> >> The inverse will require changes to the libc header to avoid redefining
>> >> symbols already defined by <linux/time.h>
>> >>
>> >> The second patch in that 2-patch set included <linux/time.h>
>> >> unconditionally after the fix. This broke builds that also included
>> >> <time.h> in the wrong order. I did not resubmit the first patch as a
>> >> stand-alone, as it is not sufficient to avoid breakage.
>> >
>> > I wasn't aware of your change, but I was about to send this to fix the
>> > case when glibc <time.h> is included before <linux/time.h>:
>> >
>> > https://github.com/mcfrisk/linux/commit/f3952a27b8a21c6478d26e6246055383483f6a66
>>
>> There are a few differences between the two. Including <time.h> does not
>> unconditionally define all the symbols. Some are conditional on additional
>> state, such as __timespec_defined.
>
> Yep, your patch seems better for libc-compat.h. Could you send it again?

Okay. Or feel free to include it in the patchset if that helps resolve
dependencies.

>> > I don't like leaving a few dozen non-compiling header files into uapi.
>>
>> I agree, but I do not see a simple solution.
>>
>> Unless libc has the analogous change, including either <time.h> or
>> <linux/time.h> in userspace can unfortunately cause breakage.
>>
>> The added include if __KERNEL__ is defined should be safe, though.
>
> Yes, for the kernel side, but your libc-compat change would nice for
> userspace, where something will break for sure, but providing source
> API compatibility is sometimes impossible.
>
> To summarize, this change from me, and your libc-compat.c for time.h, or?

I'm still afraid that this patch as is will break builds that include
<linux/time.h> first.
Mikko Rapeli Aug. 6, 2017, 9:52 p.m. UTC | #8
On Sun, Aug 06, 2017 at 05:42:13PM -0400, Willem de Bruijn wrote:
> On Sun, Aug 6, 2017 at 5:33 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
> > On Sun, Aug 06, 2017 at 05:24:20PM -0400, Willem de Bruijn wrote:
> >> >> > +#ifdef __KERNEL__
> >> >> > +#include <linux/time.h>
> >> >> > +#else
> >> >> > +#include <time.h>
> >> >> > +#endif /* __KERNEL__ */
> >> >>
> >> >> This will break applications that include <linux/time.h> manually.
> >> >> I previously sent a patch to use libc-compat to make compilation succeed
> >> >> when both are included in the case where <linux/time.h> is included after
> >> >> <time.h>.
> >> >>
> >> >>   https://lkml.org/lkml/2016/9/12/872
> >> >>
> >> >> The inverse will require changes to the libc header to avoid redefining
> >> >> symbols already defined by <linux/time.h>
> >> >>
> >> >> The second patch in that 2-patch set included <linux/time.h>
> >> >> unconditionally after the fix. This broke builds that also included
> >> >> <time.h> in the wrong order. I did not resubmit the first patch as a
> >> >> stand-alone, as it is not sufficient to avoid breakage.
> >> >
> >> > I wasn't aware of your change, but I was about to send this to fix the
> >> > case when glibc <time.h> is included before <linux/time.h>:
> >> >
> >> > https://github.com/mcfrisk/linux/commit/f3952a27b8a21c6478d26e6246055383483f6a66
> >>
> >> There are a few differences between the two. Including <time.h> does not
> >> unconditionally define all the symbols. Some are conditional on additional
> >> state, such as __timespec_defined.
> >
> > Yep, your patch seems better for libc-compat.h. Could you send it again?
> 
> Okay. Or feel free to include it in the patchset if that helps resolve
> dependencies.

If you don't have the time, I will send tomorrow a new version of this
patch which fixes the commit topic and before that your libc-compat.h change
so both could be applied together.

Feel free to be faster :)

> >> > I don't like leaving a few dozen non-compiling header files into uapi.
> >>
> >> I agree, but I do not see a simple solution.
> >>
> >> Unless libc has the analogous change, including either <time.h> or
> >> <linux/time.h> in userspace can unfortunately cause breakage.
> >>
> >> The added include if __KERNEL__ is defined should be safe, though.
> >
> > Yes, for the kernel side, but your libc-compat change would nice for
> > userspace, where something will break for sure, but providing source
> > API compatibility is sometimes impossible.
> >
> > To summarize, this change from me, and your libc-compat.c for time.h, or?
> 
> I'm still afraid that this patch as is will break builds that include
> <linux/time.h> first.

I agree, but I also want uapi headers to cleanly compile. I know this might
break stuff on userspace side which rely on these broken header file
dependencies, but if the fix to just re-order include
statements I'm fine with it, also when the complaints hit my inbox.

If I had the CPU time, memory and disk space, I'd do a full yocto distro
build to see how badly userspace could break but I don't at home.

-Mikko
Willem de Bruijn Aug. 6, 2017, 10:03 p.m. UTC | #9
On Sun, Aug 6, 2017 at 5:52 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
> On Sun, Aug 06, 2017 at 05:42:13PM -0400, Willem de Bruijn wrote:
>> On Sun, Aug 6, 2017 at 5:33 PM, Mikko Rapeli <mikko.rapeli@iki.fi> wrote:
>> > On Sun, Aug 06, 2017 at 05:24:20PM -0400, Willem de Bruijn wrote:
>> >> >> > +#ifdef __KERNEL__
>> >> >> > +#include <linux/time.h>
>> >> >> > +#else
>> >> >> > +#include <time.h>
>> >> >> > +#endif /* __KERNEL__ */
>> >> >>
>> >> >> This will break applications that include <linux/time.h> manually.
>> >> >> I previously sent a patch to use libc-compat to make compilation succeed
>> >> >> when both are included in the case where <linux/time.h> is included after
>> >> >> <time.h>.
>> >> >>
>> >> >>   https://lkml.org/lkml/2016/9/12/872
>> >> >>
>> >> >> The inverse will require changes to the libc header to avoid redefining
>> >> >> symbols already defined by <linux/time.h>
>> >> >>
>> >> >> The second patch in that 2-patch set included <linux/time.h>
>> >> >> unconditionally after the fix. This broke builds that also included
>> >> >> <time.h> in the wrong order. I did not resubmit the first patch as a
>> >> >> stand-alone, as it is not sufficient to avoid breakage.
>> >> >
>> >> > I wasn't aware of your change, but I was about to send this to fix the
>> >> > case when glibc <time.h> is included before <linux/time.h>:
>> >> >
>> >> > https://github.com/mcfrisk/linux/commit/f3952a27b8a21c6478d26e6246055383483f6a66
>> >>
>> >> There are a few differences between the two. Including <time.h> does not
>> >> unconditionally define all the symbols. Some are conditional on additional
>> >> state, such as __timespec_defined.
>> >
>> > Yep, your patch seems better for libc-compat.h. Could you send it again?
>>
>> Okay. Or feel free to include it in the patchset if that helps resolve
>> dependencies.
>
> If you don't have the time, I will send tomorrow a new version of this
> patch which fixes the commit topic and before that your libc-compat.h change
> so both could be applied together.

Please do. Thanks!
diff mbox

Patch

diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
index 07bdce1f444a..b310b2c6d94f 100644
--- a/include/uapi/linux/errqueue.h
+++ b/include/uapi/linux/errqueue.h
@@ -3,6 +3,12 @@ 
 
 #include <linux/types.h>
 
+#ifdef __KERNEL__
+#include <linux/time.h>
+#else
+#include <time.h>
+#endif /* __KERNEL__ */
+
 struct sock_extended_err {
 	__u32	ee_errno;	
 	__u8	ee_origin;