From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8659 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?UnViZW4gV2luaXN0w7ZyZmVy?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: musl and kernel headers [was Re: system-images 1.4.2: od is broken; bzip2 is missing] Date: Tue, 13 Oct 2015 16:16:30 +0200 Message-ID: <561D123E.1040107@bluewin.ch> References: <5612925A.4070402@landley.net> <20151006014426.GL8645@brightrain.aerifal.cx> <20151008165808.GZ8645@brightrain.aerifal.cx> <20151009194641.GI8645@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------030006090805090802090404" X-Trace: ger.gmane.org 1444745821 7604 80.91.229.3 (13 Oct 2015 14:17:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Oct 2015 14:17:01 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8671-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 13 16:17:01 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Zm0Nu-0000mS-EE for gllmg-musl@m.gmane.org; Tue, 13 Oct 2015 16:16:58 +0200 Original-Received: (qmail 24099 invoked by uid 550); 13 Oct 2015 14:16:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24081 invoked from network); 13 Oct 2015 14:16:50 -0000 User-Agent: Postbox 4.0.5 (Windows/20150923) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:8659 Archived-At: This is a multi-part message in MIME format. --------------030006090805090802090404 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit I just have modified the Alpine Linux kernel header patches to use them with the 4.2.3 version. (Not sure if that is a good idea, but why not try it...) So I am wondering right now, if they haven't solved the problem already you're discussing about. http://git.alpinelinux.org/cgit/aports/tree/main/linux-headers There is a patch for libc-compat.h... Maybe it helps, otherwise ignore my "interruption". ;-) Ruben Denys Vlasenko schrieb: > On Fri, Oct 9, 2015 at 9:46 PM, Rich Felker wrote: >>> Looking at kernel's libc-compat.h, it looks like you can get away >>> with using __UAPI_DEF_foo's like this? >>> >>> >>> #if defined(__UAPI_DEF_SOCKADDR_IN)&& __UAPI_DEF_SOCKADDR_IN == 1 >>> /* kernel already defined the struct, do nothing */ >>> #else >>> struct sockaddr_in { >>> ... >>> }; >> This would address the case where the kernel header is included first, >> but it's not a case I or most of the musl community wants to support, >> because there's no guarantee that the kernel's definitions of these >> structures will actually be compatible with use elsewhere in the libc >> headers, etc. > > If kernel's definition does not match yours, there is a much > bigger problem than "includes do not compile": > kernel and userspace definitions of these structs *must* match > (modulo harmless things like different typedef names for field types). > > So in this case either kernel or libc would need to be fixed. > >> The other direction, suppressing kernel headers' definition of the >> structs, is what we want to work, but they've restricted their logic >> for that to only work when __GLIBC__ is defined. :( > > Yes, you will have to do by hand the thing which kernel > automagically does for glibc - namely, define to 0: > >>> #undef __UAPI_DEF_SOCKADDR_IN >>> /* tell kernel to not define the struct */ >>> #define __UAPI_DEF_SOCKADDR_IN 0 >>> #endif > >> We could do something like this but then we would need to keep up with >> the list of all the __UAPI defines we need to suppress unwanted kernel >> definitions. > > Looking at libc-compat.h, this list is at the moment only about > 13 defines long: > > #define __UAPI_DEF_IN_ADDR 0 > #define __UAPI_DEF_IN_IPPROTO 0 > #define __UAPI_DEF_IN_PKTINFO 0 > #define __UAPI_DEF_IP_MREQ 0 > #define __UAPI_DEF_SOCKADDR_IN 0 > #define __UAPI_DEF_IN_CLASS 0 > #define __UAPI_DEF_IN6_ADDR 0 > #define __UAPI_DEF_SOCKADDR_IN6 0 > #define __UAPI_DEF_IPV6_MREQ 0 > #define __UAPI_DEF_IPPROTO_V6 0 > #define __UAPI_DEF_IPV6_OPTIONS 0 > #define __UAPI_DEF_IN6_PKTINFO 0 > #define __UAPI_DEF_IP6_MTUINFO 0 > > >> What if we could get the kernel to change the #if defined(__GLIBC__) >> to #if defined(__GLIBC__) || defined(__UAPI_DONTNEED_DEFS) or similar, >> so that there would only be one macro we need to define, and the >> kernel would then use the same logic it uses with glibc to suppress >> all of these. > > Or ask kernel to remove "define to 0" glibc hack and ask glibc to > do its own job. Why one libc should have preferential treatment? > > Or ask kernel to stop using structures with userspace names. > This should not be that hard: > > struct __kernel_sockaddr_in {...} > #if __KERNEL__ > # define sockaddr_in __kernel_sockaddr_in > #endif --------------030006090805090802090404 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit I just have modified the Alpine Linux kernel header patches to use them with the 4.2.3 version.
(Not sure if that is a good idea, but why not try it...)

So I am wondering right now, if they haven't solved the problem already you're discussing about.

http://git.alpinelinux.org/cgit/aports/tree/main/linux-headers

There is a patch for libc-compat.h...

Maybe it helps, otherwise ignore my "interruption". ;-)


Ruben



Denys Vlasenko schrieb:
On Fri, Oct 9, 2015 at 9:46 PM, Rich Felker <dalias@aerifal.cx> wrote:
Looking at kernel's libc-compat.h, it looks like you can get away
with using __UAPI_DEF_foo's like this?


#if  defined(__UAPI_DEF_SOCKADDR_IN) && __UAPI_DEF_SOCKADDR_IN == 1
/* kernel already defined the struct, do nothing */
#else
struct sockaddr_in {
        ...
};
This would address the case where the kernel header is included first,
but it's not a case I or most of the musl community wants to support,
because there's no guarantee that the kernel's definitions of these
structures will actually be compatible with use elsewhere in the libc
headers, etc.

If kernel's definition does not match yours, there is a much
bigger problem than "includes do not compile":
kernel and userspace definitions of these structs *must* match
(modulo harmless things like different typedef names for field types).

So in this case either kernel or libc would need to be fixed.

The other direction, suppressing kernel headers' definition of the
structs, is what we want to work, but they've restricted their logic
for that to only work when __GLIBC__ is defined. :(

Yes, you will have to do by hand the thing which kernel
automagically does for glibc - namely, define to 0:

#undef __UAPI_DEF_SOCKADDR_IN
/* tell kernel to not define the struct */
#define __UAPI_DEF_SOCKADDR_IN 0
#endif

We could do something like this but then we would need to keep up with
the list of all the __UAPI defines we need to suppress unwanted kernel
definitions.

Looking at libc-compat.h, this list is at the moment only about
13 defines long:

#define __UAPI_DEF_IN_ADDR              0
#define __UAPI_DEF_IN_IPPROTO           0
#define __UAPI_DEF_IN_PKTINFO           0
#define __UAPI_DEF_IP_MREQ              0
#define __UAPI_DEF_SOCKADDR_IN          0
#define __UAPI_DEF_IN_CLASS             0
#define __UAPI_DEF_IN6_ADDR             0
#define __UAPI_DEF_SOCKADDR_IN6         0
#define __UAPI_DEF_IPV6_MREQ            0
#define __UAPI_DEF_IPPROTO_V6           0
#define __UAPI_DEF_IPV6_OPTIONS         0
#define __UAPI_DEF_IN6_PKTINFO          0
#define __UAPI_DEF_IP6_MTUINFO          0


What if we could get the kernel to change the #if defined(__GLIBC__)
to #if defined(__GLIBC__) || defined(__UAPI_DONTNEED_DEFS) or similar,
so that there would only be one macro we need to define, and the
kernel would then use the same logic it uses with glibc to suppress
all of these.

Or ask kernel to remove "define to 0" glibc hack and ask glibc to
do its own job. Why one libc should have preferential treatment?

Or ask kernel to stop using structures with userspace names.
This should not be that hard:

struct __kernel_sockaddr_in {...}
#if __KERNEL__
# define sockaddr_in __kernel_sockaddr_in
#endif

--------------030006090805090802090404--