linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] uapi glibc compat: fix musl libc compatibility
@ 2017-03-12 22:00 Hauke Mehrtens
  2017-03-12 22:00 ` [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel Hauke Mehrtens
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-12 22:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli, Hauke Mehrtens

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

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

* [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel
  2017-03-12 22:00 [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
@ 2017-03-12 22:00 ` Hauke Mehrtens
  2017-03-13 11:28   ` Mikko Rapeli
  2017-03-12 22:00 ` [PATCH 2/4] uapi glibc compat: fix build if libc defines IFF_ECHO Hauke Mehrtens
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-12 22:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli, Hauke Mehrtens

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(-)

diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index 44b8a6bd5fe1..7c1fead03c50 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -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,
  * or we are being included in the kernel, then define everything
  * that we need. */
-#else /* !defined(__GLIBC__) */
+#else /* defined(__KERNEL__) */
 
 /* Definitions for if.h */
 #define __UAPI_DEF_IF_IFCONF 1
@@ -208,6 +208,6 @@
 /* Definitions for xattr.h */
 #define __UAPI_DEF_XATTR		1
 
-#endif /* __GLIBC__ */
+#endif /* __KERNEL__ */
 
 #endif /* _UAPI_LIBC_COMPAT_H */
-- 
2.11.0

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

* [PATCH 2/4] uapi glibc compat: fix build if libc defines IFF_ECHO
  2017-03-12 22:00 [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
  2017-03-12 22:00 ` [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel Hauke Mehrtens
@ 2017-03-12 22:00 ` Hauke Mehrtens
  2017-03-13 11:28   ` Mikko Rapeli
  2017-03-12 22:00 ` [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC Hauke Mehrtens
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-12 22:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli, Hauke Mehrtens

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(+)

diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index 7c1fead03c50..49a8cc3138ae 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -64,9 +64,11 @@
 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
+#ifndef IFF_ECHO
 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
+#endif /* IFF_ECHO */
 
 #else /* _NET_IF_H */
 
-- 
2.11.0

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

* [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC
  2017-03-12 22:00 [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
  2017-03-12 22:00 ` [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel Hauke Mehrtens
  2017-03-12 22:00 ` [PATCH 2/4] uapi glibc compat: fix build if libc defines IFF_ECHO Hauke Mehrtens
@ 2017-03-12 22:00 ` Hauke Mehrtens
  2017-03-13 11:29   ` Mikko Rapeli
  2017-03-16  7:59   ` David Woodhouse
  2017-03-12 22:00 ` [PATCH 4/4] uapi/if_ether.h: prevent redefinition of struct ethhdr Hauke Mehrtens
  2017-03-28 12:01 ` [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
  4 siblings, 2 replies; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-12 22:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli, Hauke Mehrtens

__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(-)

diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index 49a8cc3138ae..ce2fa8a4ced6 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -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
  * that would already be defined. */
-- 
2.11.0

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

* [PATCH 4/4] uapi/if_ether.h: prevent redefinition of struct ethhdr
  2017-03-12 22:00 [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
                   ` (2 preceding siblings ...)
  2017-03-12 22:00 ` [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC Hauke Mehrtens
@ 2017-03-12 22:00 ` Hauke Mehrtens
  2017-03-13 11:31   ` Mikko Rapeli
  2017-03-28 12:01 ` [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
  4 siblings, 1 reply; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-12 22:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli

From: David Heidelberger <david.heidelberger@ixit.cz>

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 <maillist-linux@barfooze.de>
Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
Signed-off-by: Jonas Gorski <jogo@openwrt.org>
---
 include/uapi/linux/if_ether.h    |  3 +++
 include/uapi/linux/libc-compat.h | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h
index 5bc9bfd816b7..fb5ab8c1e753 100644
--- a/include/uapi/linux/if_ether.h
+++ b/include/uapi/linux/if_ether.h
@@ -22,6 +22,7 @@
 #define _UAPI_LINUX_IF_ETHER_H
 
 #include <linux/types.h>
+#include <linux/libc-compat.h>
 
 /*
  *	IEEE 802.3 Ethernet magic constants.  The frame sizes omit the preamble
@@ -142,11 +143,13 @@
  *	This is an Ethernet frame header.
  */
 
+#if __UAPI_DEF_ETHHDR
 struct ethhdr {
 	unsigned char	h_dest[ETH_ALEN];	/* destination eth addr	*/
 	unsigned char	h_source[ETH_ALEN];	/* source ether addr	*/
 	__be16		h_proto;		/* packet type ID field	*/
 } __attribute__((packed));
+#endif
 
 
 #endif /* _UAPI_LINUX_IF_ETHER_H */
diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index ce2fa8a4ced6..c92d32f213d1 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -87,6 +87,14 @@
 
 #endif /* _NET_IF_H */
 
+/* musl defines the ethhdr struct itself in its netinet/if_ether.h.
+ * Glibc just includes the kernel header and uses a different guard. */
+#if defined(_NETINET_IF_ETHER_H)
+#define __UAPI_DEF_ETHHDR		0
+#else
+#define __UAPI_DEF_ETHHDR		1
+#endif
+
 /* Coordinate with glibc netinet/in.h header. */
 #if defined(_NETINET_IN_H)
 
@@ -182,6 +190,9 @@
 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
 
+/* Definitions for if_ether.h */
+#define __UAPI_DEF_ETHHDR 		1
+
 /* Definitions for in.h */
 #define __UAPI_DEF_IN_ADDR		1
 #define __UAPI_DEF_IN_IPPROTO		1
-- 
2.11.0

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

* Re: [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel
  2017-03-12 22:00 ` [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel Hauke Mehrtens
@ 2017-03-13 11:28   ` Mikko Rapeli
  0 siblings, 0 replies; 13+ messages in thread
From: Mikko Rapeli @ 2017-03-13 11:28 UTC (permalink / raw)
  To: Hauke Mehrtens
  Cc: davem, netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux

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>

Accked-by: Mikko Rapeli <mikko.rapeli@iki.fi>

> ---
>  include/uapi/linux/libc-compat.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
> index 44b8a6bd5fe1..7c1fead03c50 100644
> --- a/include/uapi/linux/libc-compat.h
> +++ b/include/uapi/linux/libc-compat.h
> @@ -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,
>   * or we are being included in the kernel, then define everything
>   * that we need. */
> -#else /* !defined(__GLIBC__) */
> +#else /* defined(__KERNEL__) */
>  
>  /* Definitions for if.h */
>  #define __UAPI_DEF_IF_IFCONF 1
> @@ -208,6 +208,6 @@
>  /* Definitions for xattr.h */
>  #define __UAPI_DEF_XATTR		1
>  
> -#endif /* __GLIBC__ */
> +#endif /* __KERNEL__ */
>  
>  #endif /* _UAPI_LIBC_COMPAT_H */
> -- 
> 2.11.0
> 

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

* Re: [PATCH 2/4] uapi glibc compat: fix build if libc defines IFF_ECHO
  2017-03-12 22:00 ` [PATCH 2/4] uapi glibc compat: fix build if libc defines IFF_ECHO Hauke Mehrtens
@ 2017-03-13 11:28   ` Mikko Rapeli
  0 siblings, 0 replies; 13+ messages in thread
From: Mikko Rapeli @ 2017-03-13 11:28 UTC (permalink / raw)
  To: Hauke Mehrtens
  Cc: davem, netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux

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>

Acked-by: Mikko Rapeli <mikko.rapeli@iki.fi>

> ---
>  include/uapi/linux/libc-compat.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
> index 7c1fead03c50..49a8cc3138ae 100644
> --- a/include/uapi/linux/libc-compat.h
> +++ b/include/uapi/linux/libc-compat.h
> @@ -64,9 +64,11 @@
>  /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
>  #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
>  /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
> +#ifndef IFF_ECHO
>  #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
>  #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
>  #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
> +#endif /* IFF_ECHO */
>  
>  #else /* _NET_IF_H */
>  
> -- 
> 2.11.0
> 

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

* Re: [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC
  2017-03-12 22:00 ` [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC Hauke Mehrtens
@ 2017-03-13 11:29   ` Mikko Rapeli
  2017-03-16  7:59   ` David Woodhouse
  1 sibling, 0 replies; 13+ messages in thread
From: Mikko Rapeli @ 2017-03-13 11:29 UTC (permalink / raw)
  To: Hauke Mehrtens
  Cc: davem, netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux

On Sun, Mar 12, 2017 at 11:00:38PM +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.

> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>

Acked-by: Mikko Rapeli <mikko.rapeli@iki.fi>

> ---
>  include/uapi/linux/libc-compat.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
> index 49a8cc3138ae..ce2fa8a4ced6 100644
> --- a/include/uapi/linux/libc-compat.h
> +++ b/include/uapi/linux/libc-compat.h
> @@ -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
>   * that would already be defined. */
> -- 
> 2.11.0
> 

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

* Re: [PATCH 4/4] uapi/if_ether.h: prevent redefinition of struct ethhdr
  2017-03-12 22:00 ` [PATCH 4/4] uapi/if_ether.h: prevent redefinition of struct ethhdr Hauke Mehrtens
@ 2017-03-13 11:31   ` Mikko Rapeli
  0 siblings, 0 replies; 13+ messages in thread
From: Mikko Rapeli @ 2017-03-13 11:31 UTC (permalink / raw)
  To: Hauke Mehrtens
  Cc: davem, netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux

On Sun, Mar 12, 2017 at 11:00:39PM +0100, Hauke Mehrtens wrote:
> From: David Heidelberger <david.heidelberger@ixit.cz>
> 
> 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 <maillist-linux@barfooze.de>
> Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
> Signed-off-by: Jonas Gorski <jogo@openwrt.org>

Acked-by: Mikko Rapeli <mikko.rapeli@iki.fi>

> ---
>  include/uapi/linux/if_ether.h    |  3 +++
>  include/uapi/linux/libc-compat.h | 11 +++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h
> index 5bc9bfd816b7..fb5ab8c1e753 100644
> --- a/include/uapi/linux/if_ether.h
> +++ b/include/uapi/linux/if_ether.h
> @@ -22,6 +22,7 @@
>  #define _UAPI_LINUX_IF_ETHER_H
>  
>  #include <linux/types.h>
> +#include <linux/libc-compat.h>
>  
>  /*
>   *	IEEE 802.3 Ethernet magic constants.  The frame sizes omit the preamble
> @@ -142,11 +143,13 @@
>   *	This is an Ethernet frame header.
>   */
>  
> +#if __UAPI_DEF_ETHHDR
>  struct ethhdr {
>  	unsigned char	h_dest[ETH_ALEN];	/* destination eth addr	*/
>  	unsigned char	h_source[ETH_ALEN];	/* source ether addr	*/
>  	__be16		h_proto;		/* packet type ID field	*/
>  } __attribute__((packed));
> +#endif
>  
>  
>  #endif /* _UAPI_LINUX_IF_ETHER_H */
> diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
> index ce2fa8a4ced6..c92d32f213d1 100644
> --- a/include/uapi/linux/libc-compat.h
> +++ b/include/uapi/linux/libc-compat.h
> @@ -87,6 +87,14 @@
>  
>  #endif /* _NET_IF_H */
>  
> +/* musl defines the ethhdr struct itself in its netinet/if_ether.h.
> + * Glibc just includes the kernel header and uses a different guard. */
> +#if defined(_NETINET_IF_ETHER_H)
> +#define __UAPI_DEF_ETHHDR		0
> +#else
> +#define __UAPI_DEF_ETHHDR		1
> +#endif
> +
>  /* Coordinate with glibc netinet/in.h header. */
>  #if defined(_NETINET_IN_H)
>  
> @@ -182,6 +190,9 @@
>  /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
>  #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
>  
> +/* Definitions for if_ether.h */
> +#define __UAPI_DEF_ETHHDR 		1
> +
>  /* Definitions for in.h */
>  #define __UAPI_DEF_IN_ADDR		1
>  #define __UAPI_DEF_IN_IPPROTO		1
> -- 
> 2.11.0
> 

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

* Re: [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC
  2017-03-12 22:00 ` [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC Hauke Mehrtens
  2017-03-13 11:29   ` Mikko Rapeli
@ 2017-03-16  7:59   ` David Woodhouse
  2017-03-16  8:26     ` Mikko Rapeli
  1 sibling, 1 reply; 13+ messages in thread
From: David Woodhouse @ 2017-03-16  7:59 UTC (permalink / raw)
  To: Hauke Mehrtens, davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli

[-- Attachment #1: Type: text/plain, Size: 640 bytes --]

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™.

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 4938 bytes --]

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

* Re: [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC
  2017-03-16  7:59   ` David Woodhouse
@ 2017-03-16  8:26     ` Mikko Rapeli
  2017-03-17 18:17       ` Hauke Mehrtens
  0 siblings, 1 reply; 13+ messages in thread
From: Mikko Rapeli @ 2017-03-16  8:26 UTC (permalink / raw)
  To: David Woodhouse
  Cc: Hauke Mehrtens, davem, netdev, linux-kernel, jarod, jogo,
	david.heidelberger, maillist-linux

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:
> > __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

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

* Re: [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC
  2017-03-16  8:26     ` Mikko Rapeli
@ 2017-03-17 18:17       ` Hauke Mehrtens
  0 siblings, 0 replies; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-17 18:17 UTC (permalink / raw)
  To: Mikko Rapeli, David Woodhouse
  Cc: davem, netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux

On 03/16/2017 09:26 AM, Mikko Rapeli wrote:
> 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:
>>> __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.

I agree with you David.
Should I change my patch?

The check for __USE_MISC was added in this commit:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f0a3fdca794d1e68ae284ef4caefe681f7c18e89

musl does not define it, but still adds the defines which glibc adds
when __USE_MISC is set.

Hauke

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

* Re: [PATCH 0/4] uapi glibc compat: fix musl libc compatibility
  2017-03-12 22:00 [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
                   ` (3 preceding siblings ...)
  2017-03-12 22:00 ` [PATCH 4/4] uapi/if_ether.h: prevent redefinition of struct ethhdr Hauke Mehrtens
@ 2017-03-28 12:01 ` Hauke Mehrtens
  4 siblings, 0 replies; 13+ messages in thread
From: Hauke Mehrtens @ 2017-03-28 12:01 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, jarod, jogo, david.heidelberger,
	maillist-linux, mikko.rapeli

On 2017-03-12 23:00, Hauke Mehrtens wrote:
> 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

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

end of thread, other threads:[~2017-03-28 12:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 22:00 [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens
2017-03-12 22:00 ` [PATCH 1/4] uapi glibc compat: add libc compat code when not build for kernel Hauke Mehrtens
2017-03-13 11:28   ` Mikko Rapeli
2017-03-12 22:00 ` [PATCH 2/4] uapi glibc compat: fix build if libc defines IFF_ECHO Hauke Mehrtens
2017-03-13 11:28   ` Mikko Rapeli
2017-03-12 22:00 ` [PATCH 3/4] uapi glibc compat: Do not check for __USE_MISC Hauke Mehrtens
2017-03-13 11:29   ` Mikko Rapeli
2017-03-16  7:59   ` David Woodhouse
2017-03-16  8:26     ` Mikko Rapeli
2017-03-17 18:17       ` Hauke Mehrtens
2017-03-12 22:00 ` [PATCH 4/4] uapi/if_ether.h: prevent redefinition of struct ethhdr Hauke Mehrtens
2017-03-13 11:31   ` Mikko Rapeli
2017-03-28 12:01 ` [PATCH 0/4] uapi glibc compat: fix musl libc compatibility Hauke Mehrtens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).