All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libgpiod: Fix build failure with musl
@ 2021-12-09 10:58 Viresh Kumar
  2021-12-09 11:59 ` Viresh Kumar
  2021-12-09 15:16 ` Andy Shevchenko
  0 siblings, 2 replies; 7+ messages in thread
From: Viresh Kumar @ 2021-12-09 10:58 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Viresh Kumar, Vincent Guittot, linux-gpio, Kent Gibson, Arnd Bergmann

Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
and hence we get redefinition errors during build as <linux/ioctl.h>,
included via <uapi/gpio.h>, defines them again.

Fix this by undefining the macros between both the includes, document it
all in musl-compat.h as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 lib/internal.h    |  1 +
 lib/musl-compat.h | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 lib/musl-compat.h

diff --git a/lib/internal.h b/lib/internal.h
index 32f36b5cd4cf..89c94cdd8ef6 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -8,6 +8,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include "musl-compat.h"
 #include "uapi/gpio.h"
 
 /* For internal library use only. */
diff --git a/lib/musl-compat.h b/lib/musl-compat.h
new file mode 100644
index 000000000000..69787de86f7c
--- /dev/null
+++ b/lib/musl-compat.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/* SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <bgolaszewski@baylibre.com> */
+
+#ifndef __LIBGPIOD_MUSL_COMPAT_H__
+#define __LIBGPIOD_MUSL_COMPAT_H__
+
+/*
+ * Musl's <sys/ioctl.h> (<bits/ioctl.h>) also defines below macros, un-define
+ * them before adding the ones via <linux/gpio.h> to avoid build failures.
+ */
+
+#undef _IOWR
+#undef _IOR
+#undef _IOW
+#undef _IOC
+#undef _IO
+
+#endif /* __LIBGPIOD_MUSL_COMPAT_H__ */
-- 
2.31.1.272.g89b43f80a514


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

* Re: [PATCH] libgpiod: Fix build failure with musl
  2021-12-09 10:58 [PATCH] libgpiod: Fix build failure with musl Viresh Kumar
@ 2021-12-09 11:59 ` Viresh Kumar
  2021-12-09 15:16 ` Andy Shevchenko
  1 sibling, 0 replies; 7+ messages in thread
From: Viresh Kumar @ 2021-12-09 11:59 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Vincent Guittot, linux-gpio, Kent Gibson, Arnd Bergmann

On 09-12-21, 16:28, Viresh Kumar wrote:
> Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
> and hence we get redefinition errors during build as <linux/ioctl.h>,
> included via <uapi/gpio.h>, defines them again.
> 
> Fix this by undefining the macros between both the includes, document it
> all in musl-compat.h as well.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  lib/internal.h    |  1 +
>  lib/musl-compat.h | 18 ++++++++++++++++++
>  2 files changed, 19 insertions(+)
>  create mode 100644 lib/musl-compat.h

This one is scrapped, please have a look at V2.

-- 
viresh

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

* Re: [PATCH] libgpiod: Fix build failure with musl
  2021-12-09 10:58 [PATCH] libgpiod: Fix build failure with musl Viresh Kumar
  2021-12-09 11:59 ` Viresh Kumar
@ 2021-12-09 15:16 ` Andy Shevchenko
  2021-12-09 18:32   ` Bartosz Golaszewski
  1 sibling, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2021-12-09 15:16 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linus Walleij, Bartosz Golaszewski, Vincent Guittot,
	open list:GPIO SUBSYSTEM, Kent Gibson, Arnd Bergmann

On Thu, Dec 9, 2021 at 5:15 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
> and hence we get redefinition errors during build as <linux/ioctl.h>,
> included via <uapi/gpio.h>, defines them again.
>
> Fix this by undefining the macros between both the includes, document it
> all in musl-compat.h as well.

Is it only me who wonders why it should be fixed here?

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] libgpiod: Fix build failure with musl
  2021-12-09 15:16 ` Andy Shevchenko
@ 2021-12-09 18:32   ` Bartosz Golaszewski
  2021-12-10  3:38     ` Viresh Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2021-12-09 18:32 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Viresh Kumar, Linus Walleij, Vincent Guittot,
	open list:GPIO SUBSYSTEM, Kent Gibson, Arnd Bergmann

On Thu, Dec 9, 2021 at 4:17 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Thu, Dec 9, 2021 at 5:15 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >
> > Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
> > and hence we get redefinition errors during build as <linux/ioctl.h>,
> > included via <uapi/gpio.h>, defines them again.
> >
> > Fix this by undefining the macros between both the includes, document it
> > all in musl-compat.h as well.
>
> Is it only me who wonders why it should be fixed here?
>
> --
> With Best Regards,
> Andy Shevchenko

No, I'm wondering the same. I see these musl compat issues being
"fixed" in half the embedded linux projects. Looks to me musl
introduces these issues, doesn't it? Any reason for it? Can it be
fixed in the library?

Bart

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

* Re: [PATCH] libgpiod: Fix build failure with musl
  2021-12-09 18:32   ` Bartosz Golaszewski
@ 2021-12-10  3:38     ` Viresh Kumar
  2021-12-10 10:58       ` Viresh Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2021-12-10  3:38 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, Linus Walleij, Vincent Guittot,
	open list:GPIO SUBSYSTEM, Kent Gibson, Arnd Bergmann

On 09-12-21, 19:32, Bartosz Golaszewski wrote:
> On Thu, Dec 9, 2021 at 4:17 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Thu, Dec 9, 2021 at 5:15 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > >
> > > Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
> > > and hence we get redefinition errors during build as <linux/ioctl.h>,
> > > included via <uapi/gpio.h>, defines them again.
> > >
> > > Fix this by undefining the macros between both the includes, document it
> > > all in musl-compat.h as well.
> >
> > Is it only me who wonders why it should be fixed here?
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
> 
> No, I'm wondering the same. I see these musl compat issues being
> "fixed" in half the embedded linux projects. Looks to me musl
> introduces these issues, doesn't it? Any reason for it? Can it be
> fixed in the library?

Not sure if I can go fix musl here :)

Btw, another thing that will work better is if we do this:

diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
index eaaea3d8e6b4..ebf6b5312cc0 100644
--- a/include/uapi/linux/gpio.h
+++ b/include/uapi/linux/gpio.h
@@ -12,8 +12,8 @@
 #define _UAPI_GPIO_H_

 #include <linux/const.h>
-#include <linux/ioctl.h>
 #include <linux/types.h>
+#include <sys/ioctl.h>

 /*
  * The maximum size of name and label arrays.



That will fix it properly as well, no undef issues on any library
then. Some of the files in uapi already do this.

-- 
viresh

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

* Re: [PATCH] libgpiod: Fix build failure with musl
  2021-12-10  3:38     ` Viresh Kumar
@ 2021-12-10 10:58       ` Viresh Kumar
  2021-12-10 13:34         ` Bartosz Golaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2021-12-10 10:58 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, Linus Walleij, Vincent Guittot,
	open list:GPIO SUBSYSTEM, Kent Gibson, Arnd Bergmann

On 10-12-21, 09:08, Viresh Kumar wrote:
> On 09-12-21, 19:32, Bartosz Golaszewski wrote:
> > On Thu, Dec 9, 2021 at 4:17 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > >
> > > On Thu, Dec 9, 2021 at 5:15 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > > >
> > > > Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
> > > > and hence we get redefinition errors during build as <linux/ioctl.h>,
> > > > included via <uapi/gpio.h>, defines them again.
> > > >
> > > > Fix this by undefining the macros between both the includes, document it
> > > > all in musl-compat.h as well.
> > >
> > > Is it only me who wonders why it should be fixed here?
> > >
> > > --
> > > With Best Regards,
> > > Andy Shevchenko
> > 
> > No, I'm wondering the same. I see these musl compat issues being
> > "fixed" in half the embedded linux projects. Looks to me musl
> > introduces these issues, doesn't it? Any reason for it? Can it be
> > fixed in the library?
> 
> Not sure if I can go fix musl here :)
> 
> Btw, another thing that will work better is if we do this:
> 
> diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
> index eaaea3d8e6b4..ebf6b5312cc0 100644
> --- a/include/uapi/linux/gpio.h
> +++ b/include/uapi/linux/gpio.h
> @@ -12,8 +12,8 @@
>  #define _UAPI_GPIO_H_
> 
>  #include <linux/const.h>
> -#include <linux/ioctl.h>
>  #include <linux/types.h>
> +#include <sys/ioctl.h>
> 
>  /*
>   * The maximum size of name and label arrays.
> 
> 
> 
> That will fix it properly as well, no undef issues on any library
> then. Some of the files in uapi already do this.

This got fixed somehow after I played a bit with the toolchain for
musl. Abandoning this change for now.

-- 
viresh

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

* Re: [PATCH] libgpiod: Fix build failure with musl
  2021-12-10 10:58       ` Viresh Kumar
@ 2021-12-10 13:34         ` Bartosz Golaszewski
  0 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2021-12-10 13:34 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Andy Shevchenko, Linus Walleij, Vincent Guittot,
	open list:GPIO SUBSYSTEM, Kent Gibson, Arnd Bergmann

On Fri, Dec 10, 2021 at 11:58 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 10-12-21, 09:08, Viresh Kumar wrote:
> > On 09-12-21, 19:32, Bartosz Golaszewski wrote:
> > > On Thu, Dec 9, 2021 at 4:17 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > >
> > > > On Thu, Dec 9, 2021 at 5:15 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > > > >
> > > > > Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
> > > > > and hence we get redefinition errors during build as <linux/ioctl.h>,
> > > > > included via <uapi/gpio.h>, defines them again.
> > > > >
> > > > > Fix this by undefining the macros between both the includes, document it
> > > > > all in musl-compat.h as well.
> > > >
> > > > Is it only me who wonders why it should be fixed here?
> > > >
> > > > --
> > > > With Best Regards,
> > > > Andy Shevchenko
> > >
> > > No, I'm wondering the same. I see these musl compat issues being
> > > "fixed" in half the embedded linux projects. Looks to me musl
> > > introduces these issues, doesn't it? Any reason for it? Can it be
> > > fixed in the library?
> >
> > Not sure if I can go fix musl here :)
> >
> > Btw, another thing that will work better is if we do this:
> >
> > diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
> > index eaaea3d8e6b4..ebf6b5312cc0 100644
> > --- a/include/uapi/linux/gpio.h
> > +++ b/include/uapi/linux/gpio.h
> > @@ -12,8 +12,8 @@
> >  #define _UAPI_GPIO_H_
> >
> >  #include <linux/const.h>
> > -#include <linux/ioctl.h>
> >  #include <linux/types.h>
> > +#include <sys/ioctl.h>
> >
> >  /*
> >   * The maximum size of name and label arrays.
> >
> >
> >
> > That will fix it properly as well, no undef issues on any library
> > then. Some of the files in uapi already do this.
>
> This got fixed somehow after I played a bit with the toolchain for
> musl. Abandoning this change for now.
>

Good, because the commit that introduces this <sys/ioctl.h> include in
some uapi headers looks like this:

commit 607ca46e97a1b6594b29647d98a32d545c24bdff
Author: David Howells <dhowells@redhat.com>
Date:   Sat Oct 13 10:46:48 2012 +0100

    UAPI: (Scripted) Disintegrate include/linux

    Signed-off-by: David Howells <dhowells@redhat.com>
    Acked-by: Arnd Bergmann <arnd@arndb.de>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>
    Acked-by: Michael Kerrisk <mtk.manpages@gmail.com>
    Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Acked-by: Dave Jones <davej@redhat.com>

and is 68737 lines long.

No idea what the author meant honestly and why this was acked as it
is. I can't find any discussion on that anymore.

Bart

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

end of thread, other threads:[~2021-12-10 13:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 10:58 [PATCH] libgpiod: Fix build failure with musl Viresh Kumar
2021-12-09 11:59 ` Viresh Kumar
2021-12-09 15:16 ` Andy Shevchenko
2021-12-09 18:32   ` Bartosz Golaszewski
2021-12-10  3:38     ` Viresh Kumar
2021-12-10 10:58       ` Viresh Kumar
2021-12-10 13:34         ` Bartosz Golaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.