From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11121 Path: news.gmane.org!.POSTED!not-for-mail From: Carlos O'Donell Newsgroups: gmane.linux.kernel,gmane.linux.kernel.api,gmane.linux.lib.musl.general Subject: Re: [PATCH resent] uapi libc compat: allow non-glibc to opt out of uapi definitions Date: Wed, 8 Mar 2017 11:39:08 -0500 Organization: Red Hat Message-ID: <459a8faf-4585-5063-3d94-3a1fecfa8289@redhat.com> References: <20161111120820.GA435@nyan> <1488977188.4347.134.camel@infradead.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1488991742 22653 195.159.176.226 (8 Mar 2017 16:49:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 8 Mar 2017 16:49:02 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 Cc: "David S. Miller" , linux-api@vger.kernel.org, musl@lists.openwall.com To: David Woodhouse , Felix Janda , linux-kernel@vger.kernel.org Original-X-From: linux-kernel-owner@vger.kernel.org Wed Mar 08 17:48:58 2017 Return-path: Envelope-to: glk-linux-kernel-3@m.gmane.org Original-Received: from vger.kernel.org ([209.132.180.67]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clelh-0004rQ-8v for glk-linux-kernel-3@m.gmane.org; Wed, 08 Mar 2017 17:48:53 +0100 Original-Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753280AbdCHQsl (ORCPT ); Wed, 8 Mar 2017 11:48:41 -0500 Original-Received: from mail-qk0-f180.google.com ([209.85.220.180]:34729 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751657AbdCHQsj (ORCPT ); Wed, 8 Mar 2017 11:48:39 -0500 Original-Received: by mail-qk0-f180.google.com with SMTP id p64so75340280qke.1 for ; Wed, 08 Mar 2017 08:48:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding; bh=5vt4jGmvJWNCjmsHSph78CPP11NsiLJmlaM55RlVyD4=; b=bzNYbwBkVMpnjaTUf2+ypUyV4s9P4+v1BOewZ0TLenbkIQ8Li/AKHPRiQptBPaELOF zGYYA4v90WwhnSZeDPLosLJic5pGpT8c/3xDOI+vqawwjhVK9syN46xfFcW8lXizwrGe NrZYqg/Dgz1kZnoe+usYRBYiyMTjp0rtXej4qH47NsGgms5lmTdTD/oHnVJRIgCiZ8WP jrKXpaf50QapcfxnodeqIDHJTzhd+X2ebOMVSVggN4mUFctbJAl7qZxzkSQ+9awZXnbU lWMaA3LFnOIH8tBMVZv5SS5SlvtByHIPP7is1GyYAqz5BtBVVSF4Cq49LGzMKOxn6OJe WQWg== X-Gm-Message-State: AMke39nbGO9LTE42Zp1K1pKGs6N2fio+nzEG/k7P5bg2HSaYWCxDjSNsoZY/lt3vrdxrldbi X-Received: by 10.55.90.68 with SMTP id o65mr8546195qkb.89.1488991151312; Wed, 08 Mar 2017 08:39:11 -0800 (PST) Original-Received: from [192.168.1.200] (otwaon234vw-lp130-01-184-145-137-27.dsl.bell.ca. [184.145.137.27]) by smtp.gmail.com with ESMTPSA id i140sm2436773qke.2.2017.03.08.08.39.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2017 08:39:09 -0800 (PST) In-Reply-To: <1488977188.4347.134.camel@infradead.org> Original-Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Xref: news.gmane.org gmane.linux.kernel:2426516 gmane.linux.kernel.api:22414 gmane.linux.lib.musl.general:11121 Archived-At: On 03/08/2017 07:46 AM, David Woodhouse wrote: > On Fri, 2016-11-11 at 07:08 -0500, Felix Janda wrote: >> Currently, libc-compat.h detects inclusion of specific glibc headers, >> and defines corresponding _UAPI_DEF_* macros, which in turn are used in >> uapi headers to prevent definition of conflicting structures/constants. >> There is no such detection for other c libraries, for them the >> _UAPI_DEF_* macros are always defined as 1, and so none of the possibly >> conflicting definitions are suppressed. >> >> This patch enables non-glibc c libraries to request the suppression of >> any specific interface by defining the corresponding _UAPI_DEF_* macro >> as 0. > > Ick. It's fairly horrid for kernel headers to be reacting to __GLIBC__ > in any way. That's just wrong. > > It makes more sense for C libraries to define the __UAPI_DEF_xxx for > themselves as and when they add their own support for certain things, > and for the kernel not to have incestuous knowledge of them. > > The part you add here in the #else /* !__GLIBC__ */ part is what we > should do at *all* times. > > I understand that we'll want to grandfather in the glibc horridness, > but let's make it clear that that's what it is, by letting it set the > appropriate __UAPI_DEF_xxx macros to zero, and then continue through to > your new part. Something like this (incremental to yours): Any model we propose should be documented in the header of libc-compat.h and explain how it works to solve header inclusion order in _both_ directions. User use cases include header inclusion in _both_ directions and we should look to support that. > diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h > index c316725..7673158 100644 > --- a/include/uapi/linux/libc-compat.h > +++ b/include/uapi/linux/libc-compat.h > @@ -53,41 +53,18 @@ > > /* Coordinate with glibc net/if.h header. */ > #if defined(_NET_IF_H) && defined(__USE_MISC) > - > /* GLIBC headers included first so don't define anything > * that would already be defined. */ > - > #define __UAPI_DEF_IF_IFCONF 0 > #define __UAPI_DEF_IF_IFMAP 0 > #define __UAPI_DEF_IF_IFNAMSIZ 0 > #define __UAPI_DEF_IF_IFREQ 0 > /* 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 __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 */ > - > -#else /* _NET_IF_H */ > - > -/* Linux headers included first, and we must define everything > - * we need. The expectation is that glibc will check the > - * __UAPI_DEF_* defines and adjust appropriately. */ > - > -#define __UAPI_DEF_IF_IFCONF 1 > -#define __UAPI_DEF_IF_IFMAP 1 > -#define __UAPI_DEF_IF_IFNAMSIZ 1 > -#define __UAPI_DEF_IF_IFREQ 1 > -/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */ > -#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1 > -/* 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 > - Any header needing compat with a libc includes libc-compat.h (per the documented way the model works). With this patch any included linux kernel header that also includes libc-compat.h would immediately define all the __UAPI_DEF_* constants to 1 as-if it had defined those structures, but it has not. For example, with these two patches applied, the inclusion of linux/if.h would define __UAPI_DEF_XATTR to 1, but linux/if.h has not defined XATTR_CREATE or other constants, so a subsequent inclusion sys/xattrs.h from userspace would _not_ define XATTR_CREATE because __UAPI_DEF_XATTR set to 1 indicates the kernel has. I don't want to read into the model you are proposing and would rather you document the semantics clearly so we can all see what you mean. > #endif /* _NET_IF_H */ > > /* Coordinate with glibc netinet/in.h header. */ > #if defined(_NETINET_IN_H) > - > /* GLIBC headers included first so don't define anything > * that would already be defined. */ > #define __UAPI_DEF_IN_ADDR 0 > @@ -104,8 +81,6 @@ > * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */ > #if defined(__USE_MISC) || defined (__USE_GNU) > #define __UAPI_DEF_IN6_ADDR_ALT 0 > -#else > -#define __UAPI_DEF_IN6_ADDR_ALT 1 > #endif > #define __UAPI_DEF_SOCKADDR_IN6 0 > #define __UAPI_DEF_IPV6_MREQ 0 > @@ -113,62 +88,23 @@ > #define __UAPI_DEF_IPV6_OPTIONS 0 > #define __UAPI_DEF_IN6_PKTINFO 0 > #define __UAPI_DEF_IP6_MTUINFO 0 > - > -#else > - > -/* Linux headers included first, and we must define everything > - * we need. The expectation is that glibc will check the > - * __UAPI_DEF_* defines and adjust appropriately. */ > -#define __UAPI_DEF_IN_ADDR 1 > -#define __UAPI_DEF_IN_IPPROTO 1 > -#define __UAPI_DEF_IN_PKTINFO 1 > -#define __UAPI_DEF_IP_MREQ 1 > -#define __UAPI_DEF_SOCKADDR_IN 1 > -#define __UAPI_DEF_IN_CLASS 1 > - > -#define __UAPI_DEF_IN6_ADDR 1 > -/* We unconditionally define the in6_addr macros and glibc must > - * coordinate. */ > -#define __UAPI_DEF_IN6_ADDR_ALT 1 > -#define __UAPI_DEF_SOCKADDR_IN6 1 > -#define __UAPI_DEF_IPV6_MREQ 1 > -#define __UAPI_DEF_IPPROTO_V6 1 > -#define __UAPI_DEF_IPV6_OPTIONS 1 > -#define __UAPI_DEF_IN6_PKTINFO 1 > -#define __UAPI_DEF_IP6_MTUINFO 1 > - > #endif /* _NETINET_IN_H */ > > /* Coordinate with glibc netipx/ipx.h header. */ > #if defined(__NETIPX_IPX_H) > - > #define __UAPI_DEF_SOCKADDR_IPX 0 > #define __UAPI_DEF_IPX_ROUTE_DEFINITION 0 > #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 0 > #define __UAPI_DEF_IPX_CONFIG_DATA 0 > #define __UAPI_DEF_IPX_ROUTE_DEF 0 > - > -#else /* defined(__NETIPX_IPX_H) */ > - > -#define __UAPI_DEF_SOCKADDR_IPX 1 > -#define __UAPI_DEF_IPX_ROUTE_DEFINITION 1 > -#define __UAPI_DEF_IPX_INTERFACE_DEFINITION 1 > -#define __UAPI_DEF_IPX_CONFIG_DATA 1 > -#define __UAPI_DEF_IPX_ROUTE_DEF 1 > - > #endif /* defined(__NETIPX_IPX_H) */ > > /* Definitions for xattr.h */ > #if defined(_SYS_XATTR_H) > #define __UAPI_DEF_XATTR 0 > -#else > -#define __UAPI_DEF_XATTR 1 > #endif > > -/* 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__) */ > +#endif /* __GLIBC__ */ > > /* Definitions for if.h */ > #if !defined(__UAPI_DEF_IF_IFCONF) > @@ -260,6 +196,4 @@ > #define __UAPI_DEF_XATTR 1 > #endif > > -#endif /* __GLIBC__ */ > - > #endif /* _UAPI_LIBC_COMPAT_H */ > > > > > -- Cheers, Carlos.