The code from libc-compat.h depends on some glibc specific defines and
causes compile problems with the musl libc. These patches remove some
of the glibc dependencies. With these patches the LEDE (OpenWrt) base
user space applications can be build with unmodified kernel headers and
musl libc.
This was compile tested with the user space from LEDE (OpenWrt) with
musl 1.1.16, glibc 2.25 and uClibc-ng 1.0.22.
David Heidelberger (1):
uapi/if_ether.h: prevent redefinition of struct ethhdr
Hauke Mehrtens (3):
uapi glibc compat: add libc compat code when not build for kernel
uapi glibc compat: fix build if libc defines IFF_ECHO
uapi glibc compat: Do not check for __USE_MISC
include/uapi/linux/if_ether.h | 3 +++
include/uapi/linux/libc-compat.h | 25 +++++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
--
2.11.0
Instead of checking if this header file is used in the glibc, check if
iti is not used in kernel context, this way it will also work with
other libc implementations like musl.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
include/uapi/linux/libc-compat.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
@@ -48,8 +48,8 @@#ifndef _UAPI_LIBC_COMPAT_H#define _UAPI_LIBC_COMPAT_H-/* We have included glibc headers... */-#if defined(__GLIBC__)+/* We have included libc headers... */+#if !defined(__KERNEL__)/* Coordinate with glibc net/if.h header. */#if defined(_NET_IF_H) && defined(__USE_MISC)
@@ -168,7 +168,7 @@/* If we did not see any headers from any supported C libraries,*orwearebeingincludedinthekernel,thendefineeverything*thatweneed.*/-#else /* !defined(__GLIBC__) */+#else /* defined(__KERNEL__) *//* Definitions for if.h */#define __UAPI_DEF_IF_IFCONF 1
From: Mikko Rapeli <hidden> Date: 2017-03-13 11:28:20
On Sun, Mar 12, 2017 at 11:00:36PM +0100, Hauke Mehrtens wrote:
Instead of checking if this header file is used in the glibc, check if
iti is not used in kernel context, this way it will also work with
other libc implementations like musl.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
@@ -48,8 +48,8 @@#ifndef _UAPI_LIBC_COMPAT_H#define _UAPI_LIBC_COMPAT_H-/* We have included glibc headers... */-#if defined(__GLIBC__)+/* We have included libc headers... */+#if !defined(__KERNEL__)/* Coordinate with glibc net/if.h header. */#if defined(_NET_IF_H) && defined(__USE_MISC)
@@ -168,7 +168,7 @@/* If we did not see any headers from any supported C libraries,*orwearebeingincludedinthekernel,thendefineeverything*thatweneed.*/-#else /* !defined(__GLIBC__) */+#else /* defined(__KERNEL__) *//* Definitions for if.h */#define __UAPI_DEF_IF_IFCONF 1
musl 1.1.15 defines IFF_ECHO and the other net_device_flags options.
When a user application includes linux/if.h and net/if.h the compile
will fail.
Activate __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO only when
it is needed. This should also make this work in case glibc will add
these defines.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
include/uapi/linux/libc-compat.h | 2 ++
1 file changed, 2 insertions(+)
From: Mikko Rapeli <hidden> Date: 2017-03-13 11:29:08
On Sun, Mar 12, 2017 at 11:00:37PM +0100, Hauke Mehrtens wrote:
musl 1.1.15 defines IFF_ECHO and the other net_device_flags options.
When a user application includes linux/if.h and net/if.h the compile
will fail.
Activate __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO only when
it is needed. This should also make this work in case glibc will add
these defines.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
__USE_MISC is glibc specific and not available in musl libc. Only do
this check when glibc is used. This fixes a problem with musl libc.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
include/uapi/linux/libc-compat.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -51,8 +51,8 @@/* We have included libc headers... */#if !defined(__KERNEL__)-/* Coordinate with glibc net/if.h header. */-#if defined(_NET_IF_H) && defined(__USE_MISC)+/* Coordinate with libc net/if.h header. */+#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))/* GLIBC headers included first so don't define anything*thatwouldalreadybedefined.*/
@@ -51,8 +51,8 @@/* We have included libc headers... */#if !defined(__KERNEL__)-/* Coordinate with glibc net/if.h header. */-#if defined(_NET_IF_H) && defined(__USE_MISC)+/* Coordinate with libc net/if.h header. */+#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))/* GLIBC headers included first so don't define anything*thatwouldalreadybedefined.*/
From: David Woodhouse <dwmw2@infradead.org> Date: 2017-03-16 07:59:37
On Sun, 2017-03-12 at 23:00 +0100, Hauke Mehrtens wrote:
__USE_MISC is glibc specific and not available in musl libc. Only do
this check when glibc is used. This fixes a problem with musl libc.
...
-/* Coordinate with glibc net/if.h header. */
-#if defined(_NET_IF_H) && defined(__USE_MISC)
+/* Coordinate with libc net/if.h header. */
+#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))
I *really* don't like building up a plethora of knowledge about
specific libc implementations in the kernel. As a general rule, if we
have *anything* that depends on __GLIBC__ then we are Doing It Wrong™.
From: Mikko Rapeli <hidden> Date: 2017-03-16 08:26:58
On Thu, Mar 16, 2017 at 07:59:12AM +0000, David Woodhouse wrote:
On Sun, 2017-03-12 at 23:00 +0100, Hauke Mehrtens wrote:
quoted
__USE_MISC is glibc specific and not available in musl libc. Only do
this check when glibc is used. This fixes a problem with musl libc.
...
-/* Coordinate with glibc net/if.h header. */
-#if defined(_NET_IF_H) && defined(__USE_MISC)
+/* Coordinate with libc net/if.h header. */
+#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))
I *really* don't like building up a plethora of knowledge about
specific libc implementations in the kernel. As a general rule, if we
have *anything* that depends on __GLIBC__ then we are Doing It Wrong™.
Kernel does not depend on glibc but uapi headers check for some defintions
so that userspace code can include both libc and kernel header files
without compiler errors.
This interface between kernel and libc header files is messy due to long
history of copying header files from kernel to libc implementations etc
and thus this kind of ifdef magic with in depth knowledge of various
libc's defintions is currently unavoidable.
-Mikko
On Thu, Mar 16, 2017 at 07:59:12AM +0000, David Woodhouse wrote:
quoted
On Sun, 2017-03-12 at 23:00 +0100, Hauke Mehrtens wrote:
quoted
__USE_MISC is glibc specific and not available in musl libc. Only do
this check when glibc is used. This fixes a problem with musl libc.
...
-/* Coordinate with glibc net/if.h header. */
-#if defined(_NET_IF_H) && defined(__USE_MISC)
+/* Coordinate with libc net/if.h header. */
+#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))
I *really* don't like building up a plethora of knowledge about
specific libc implementations in the kernel. As a general rule, if we
have *anything* that depends on __GLIBC__ then we are Doing It Wrong™.
Kernel does not depend on glibc but uapi headers check for some defintions
so that userspace code can include both libc and kernel header files
without compiler errors.
This interface between kernel and libc header files is messy due to long
history of copying header files from kernel to libc implementations etc
and thus this kind of ifdef magic with in depth knowledge of various
libc's defintions is currently unavoidable.
From: David Heidelberger <redacted>
Musl provides its own ethhdr struct definition. Add a guard to prevent
its definition of the appropriate musl header has already been included.
Signed-off-by: John Spencer <redacted>
Tested-by: David Heidelberger <redacted>
Signed-off-by: Jonas Gorski <redacted>
---
include/uapi/linux/if_ether.h | 3 +++
include/uapi/linux/libc-compat.h | 11 +++++++++++
2 files changed, 14 insertions(+)
From: Mikko Rapeli <hidden> Date: 2017-03-13 11:31:22
On Sun, Mar 12, 2017 at 11:00:39PM +0100, Hauke Mehrtens wrote:
From: David Heidelberger <redacted>
Musl provides its own ethhdr struct definition. Add a guard to prevent
its definition of the appropriate musl header has already been included.
Signed-off-by: John Spencer <redacted>
Tested-by: David Heidelberger <redacted>
Signed-off-by: Jonas Gorski <redacted>
The code from libc-compat.h depends on some glibc specific defines and
causes compile problems with the musl libc. These patches remove some
of the glibc dependencies. With these patches the LEDE (OpenWrt) base
user space applications can be build with unmodified kernel headers and
musl libc.
This was compile tested with the user space from LEDE (OpenWrt) with
musl 1.1.16, glibc 2.25 and uClibc-ng 1.0.22.
David Heidelberger (1):
uapi/if_ether.h: prevent redefinition of struct ethhdr
Hauke Mehrtens (3):
uapi glibc compat: add libc compat code when not build for kernel
uapi glibc compat: fix build if libc defines IFF_ECHO
uapi glibc compat: Do not check for __USE_MISC
include/uapi/linux/if_ether.h | 3 +++
include/uapi/linux/libc-compat.h | 25 +++++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
Did I send this to the correct maintainer? I am unsure through which
maintainer this should go. I saw that some patches for the libc-compat.h
file went trough David Miller, so I tried the same.
Hauke