Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp4003866rdb; Wed, 30 Aug 2023 12:19:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCEDAFvEtnuTp1Ju5TuSk+Kk1ifpj4GG1DTlX8LRCTTJBH8Iu2U1J9FmsCOp1ndHNe5U0k X-Received: by 2002:a17:906:30d2:b0:9a2:c5a:6c9d with SMTP id b18-20020a17090630d200b009a20c5a6c9dmr2246978ejb.62.1693423148821; Wed, 30 Aug 2023 12:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693423148; cv=none; d=google.com; s=arc-20160816; b=fjt0cRo+7Ux4uTRDWHOp2p8xCdcnEtLohOPeGbqmlyfSc/1E+0C0acpl9BgIDJ1Bli rFrEv3SqJx31g4/QYLgwbs/MAJYuYU4UtM0hDDkynku9tFBWYONTqGjYU0/Up3gaJv2f e3dJz3L4VqujYH4wbCEHsnzYakhg348bgwXZBFWZhqEG6JjpyE46P1pmlWmn6L+aLoTD csN08KLUFedoqzyHMvKi4Njh3c0j9nKK3vxn8aEDrCNcIcCyUB+DFGu0ZgNxEciqDJnl 1okkV0OsqmhsqQWZ4AmUeLtZYAovL3kbeZDMRaYdWCPMyPeWcv4HZs/y/CHnbPW7HCG+ K/pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=GzDCmvc1viJNnBM0JTTnhzzvkPSQkvglIE8sVgsW85w=; fh=q1RB602wbnpeA4xEGIahT6LYjwTOYHyG2x6uZL9R6HE=; b=oFg0PMwym3wof7Elw9MsQWS4W23Ph6fYwwUrveGOlRF+D9YW0Yt+Zcs1RA9BufcN95 z0+D0j8+x4l0VV9twxYXerqy7xMyYgIE7JyE2M7pFWyvGuk3WehIL3Rwq0BaH13ca5Bn p68UCbq9UwK6fNJGAeqeXpntewCC7884lcNOwLlUveTBq4NGVnacEWnq8dduXbab5vFR a6gzrhM/i5ZeYnTL4UBpYGIwhFtE0K17MoWenQLocIMmK694sqU1VBXwOqJJjcloF2pi zZqla67lWaKbbYgi4F9Gi6Y/GDP02T9TBQxGKZe18TpMCXKsoMXI5MxDbZdW0cmYvoMy D0PA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uz30-20020a170907119e00b009a1d79a32a2si7757643ejb.1027.2023.08.30.12.18.41; Wed, 30 Aug 2023 12:19:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243901AbjH3TNm (ORCPT + 99 others); Wed, 30 Aug 2023 15:13:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242184AbjH3HXm (ORCPT ); Wed, 30 Aug 2023 03:23:42 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 168C61BB; Wed, 30 Aug 2023 00:23:37 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 37U7NBLX025225; Wed, 30 Aug 2023 09:23:11 +0200 Date: Wed, 30 Aug 2023 09:23:11 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Shuah Khan , Zhangjin Wu , Yuan Tan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 1/2] tools/nolibc: add stdarg.h header Message-ID: References: <20230827-nolibc-nostdinc-v1-0-995d1811f1f3@weissschuh.net> <20230827-nolibc-nostdinc-v1-1-995d1811f1f3@weissschuh.net> <2b6c62f1-c1f1-4f2c-ba0c-981e066f4268@t-8ch.de> <3663d244-627f-4928-ab2e-0328cd6a8fb1@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3663d244-627f-4928-ab2e-0328cd6a8fb1@t-8ch.de> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 30, 2023 at 08:21:51AM +0200, Thomas Wei?schuh wrote: > On 2023-08-29 14:12:45+0200, Willy Tarreau wrote: > > On Tue, Aug 29, 2023 at 12:16:23PM +0200, Thomas Wei?schuh wrote: > > > > OK. But then, doesn't it mean that if we don't provide our stdarg.h, > > > > the compilers' will be used ? I'm asking because we're already using > > > > va_list and va_args, for example in vfprintf() in stdio.h, which > > > > precisely includes so it must indeed come from the compiler. > > > > > > It will be used *iff* -nostdinc is *not* passed. > > > > > > I think we need to clarify the definition of the word "provided". > > > For me it means that the compiler ships an implementation of this header > > > file in the compiler-specific include directory. > > > > > > If -nostdinc is passed this include directory is not actually usable. > > > > OK I understand better now. I thought it was always usable. > > > > > If a user wants to avoid the implicit usage of any system-provided > > > headers they need to pass -nostdinc, as far as I know there is no flag > > > to keep only the compiler-specific include directories. > > > > So that means we may also have to implement our own stddef.h to move > > size_t there, and limits.h and move *MAX there as well if we want to > > support this. I'm not necessarily against this, it's just that we need > > to be consistent. > > We would have to, *iff* the goal is to provide *all* headers in nolibc. That has never been my goal (especially for those already provided by the compiler). > > Also something is puzzling me. If a normal program builds with -nostdinc, > > it means it does *not* want the libc's (nor the compiler's) headers to be > > included, probably because it comes with its own. In this case why would > > we impose ours ? For example, let's consider this tiny code snippet: > > > > $ cat arg.c > > #include > > va_list blah; > > > > $ gcc -c arg.c > > $ gcc -nostdinc -c arg.c > > arg.c:1:20: error: no include path in which to search for stdarg.h > > 1 | #include > > | ^ > > arg.c:2:1: error: unknown type name 'va_list' > > 2 | va_list blah; > > | ^~~~~~~ > > arg.c:1:1: note: 'va_list' is defined in header ''; did you forget to '#include '? > > +++ |+#include > > 1 | #include > > > > You see, that's why I'm finding it confusing that we define headers that > > are supposed *not* to be defined with -nostdinc. > > I'm confused. > > If the user doesn't want to use nolibc they should not explicitly add it > to the include path. I didn't understand that it was what you were seeking, I thought you wanted to build like above, hence my confusion, see below. > > I think we need to carefully check what is supposed to be defined and > > what not when -nostdinc is used normally so that we defined what programs > > expect and not what they expect us *not* to define. Recently we've been > > empirically fixing nolibc-test build failures but it's just a test program > > that comes with its own biases. Maybe trying to build some portable libs > > that use very little from a libc (e.g. xxhash, liblzo etc) could give us > > some hints about certain basic assumptions that we do not fulfill. > > It makes sense to figure out what is needed by larger projects from a > libc. But it feels to me like a bug vs. feature discussion. > > Making larger real-world applications work is a feature while making the > following work is a bugfix: > > $ cat nolibc.c > #include "nolibc.h" > > int main(void) > { > return 0; > } > > $ gcc -nostdinc -Isysroot/x86/include -c nolibc.c > In file included from sysroot/x86/include/nolibc.h:98, > from nolibc-test.c:1: > sysroot/x86/include/sys.h:10:10: fatal error: stdarg.h: No such file or directory > 10 | #include > | ^~~~~~~~~~ This one definitely is a bug, I totally agree. And I didn't understand this from your initial patch, my understanding was that users would want to use -nostdinc yet build using regular includes that we'd provide. > > > It's all about supporting -nostdinc. Yes, but "-nostdinc" with "-include nolibc.h". It was probably obvious to you since you were trying to make it work but I really didn't grasp it. > > But unless I'm mistaken (and my example above seems to support this), > > a normal libc doesn't build with -nostdinc. That's the point I'd like > > us to clarify. > > musl: > > $ cat /usr/lib/musl/lib/musl-gcc.specs > ... > *cc1: > %(cc1_cpu) -nostdinc -isystem /usr/lib/musl/include -isystem include%s > ... > > > dietlibc: > > $ cat Makefile > ... > DEFAULTCFLAGS=-pipe -nostdinc -D_REENTRANT $(EXTRACFLAGS) > ... OK. > klibc re-adds the compilers include path, > This is an alternative we could also use: > > $ cat Makefile > ... > NOSTDINC_FLAGS := -nostdlib -nostdinc -isystem $(shell $(CC) -print-file-name=include) > ... Another approach but not easy to pass to end-users. > There was also a longer discussion on LKML about linux/stdarg.h [0] Thanks for the link, interesting indeed! > The gcc authors argue that Linux should not ship a custom stdarg.h. > But in reality Linux, musl, dietlibc (and probably some more) today are > shipping their own stdarg.h. I think the main problem precisely is that -nostdinc excludes both the system libc's and the compiler's headers (that last point I didn't know). If there was a standard way to say "no system includes but please keep the compiler's headers as they're the only exposed interface we have" it would be much easier. So yes, I understand what you ended up on: you in fact want to be sure not to inherit from the local system headers and as a side effect you lose the compiler ones so you need to redefine them. Then of course that's fine. > > We have an interesting comment at the top of nolibc.h which says: > > > > * The available standard (but limited) include files are: > > * ctype.h, errno.h, signal.h, stdio.h, stdlib.h, string.h, time.h > > This is out of date. It's missing signal.h, stdint.h, unistd.h. Yes very likely, but I found it interesting to find this split that was done a while ago. > > * > > * In addition, the following ones are expected to be provided by the compiler: > > * float.h, stdarg.h, stddef.h > > What does "expected" mean here? > nolibc itself is perfectly fine without float.h and stddef.h. i.e. "if needed we'll use these ones". > > * The following ones which are part to the C standard are not provided: > > * assert.h, locale.h, math.h, setjmp.h, limits.h > > While true, a lot of other headers are also not provided. Sure, but these were the ones I identified by then. > > I think I draw the line based on what my compilers have always provided. > > That's definitely something we can redefine (and update the comment), > > I'm just seeking consistency, and I think you can understand :-/ > > I do understand. > > To reiterate it here explicitly, in my opinion it's a worthwhile and > consistent goal to make "nolibc usable standalone with -nostdinc" for > maximal control by the user. I agree now. I think we need to make it clear that it's for when we're including the all-in-one "nolibc.h" as an alternative to regular headers. > If not, I'd like to use the "-nostdinc -I$(cc -print-file-name=include)" > method to avoid dependencies on system header for nolibc-test > specifically. It's a bit ugly and not always easy to stuff into projects. The fact that nolibc itself isn't self-sustaining anymore with -nostdinc is a concern and I agree with addressing it like you proposed. Thanks for the clarification! Willy