Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3112171rdb; Tue, 29 Aug 2023 05:59:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCyuegPevBWkY3ajQ2DVtrjXqYDjc+V+bwWRWdJ9OMynw7Yv4JNg09EjbGNefvCW0JKS5X X-Received: by 2002:a17:90b:108d:b0:26d:a83:79cc with SMTP id gj13-20020a17090b108d00b0026d0a8379ccmr21972282pjb.11.1693313989178; Tue, 29 Aug 2023 05:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693313989; cv=none; d=google.com; s=arc-20160816; b=RaMCrIGrexoiaYFhjup4Q6kV6BNp/dA9ruJ/bZX4Hvcy64Hy5rhv2QPV7+Cna2KLJ2 qFJ6PxJN0+CT5/Rc/oe0TTfZmjvIMAX66gW5Bi23Kct/Gx3Gry9lQXZBrEyey/dYPgZA YvjzEuVYAFRC2ONsEFc3mnYZioEN5kBO2R6wb3OgwR+NFJnzc6/SrrH9hR0UzOH5TOC3 A+eB7aRcPslS+8x0cJfsKrOfxnGT64R67JthIpd29JfWCfuOiBUl5i25AKcO8H94ez/n ReU2x+ctC/kkSN6JKL1ltZ2YdA3ggqh6OEr3tP73GODn+cKeicEI/iz4UP2mQ0jR+8/4 HwtA== 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=E5JTc5mAxfUDZCmmy92Z4SztgyeG88OosA6SV6gPGtk=; fh=q1RB602wbnpeA4xEGIahT6LYjwTOYHyG2x6uZL9R6HE=; b=AA50Sg9bPmwTwNYOSIhsmwRRBD/DusJTR2R5Cp9dFplQVsKZuMT/gJq8MKZ9EhL3g+ l71shCPS8r/j4QgdpWbwN14r+81UHX0A3Gof4FFJIDV4GSJFXmY7gNpUbveoYz2rSJmB h5KmpKx7KR7j3u0bzqaXrIXC2nGLxE8hEaahraT3bT27heLnM1KxUxqDc7WyuLFHOk96 eT2QFm3ZAjvcIl4D7gRuUjDa2ZytxzjEK0Z1T61U3CfJBjsFqCutsQNxiQubdm7GmGle fJ/HQkoOYaEsuSnOK2TxZcc0NXYkMS91DZcljMx5+uwtXjVLVR6BSUnhmqqKj0EVl0gF bGeA== 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 lx17-20020a17090b4b1100b002568a675b65si13690515pjb.141.2023.08.29.05.59.32; Tue, 29 Aug 2023 05:59:49 -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 S234899AbjH2MNX (ORCPT + 99 others); Tue, 29 Aug 2023 08:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234839AbjH2MNK (ORCPT ); Tue, 29 Aug 2023 08:13:10 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 696AF1BF; Tue, 29 Aug 2023 05:13:03 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 37TCCjUv015120; Tue, 29 Aug 2023 14:12:45 +0200 Date: Tue, 29 Aug 2023 14:12:45 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 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. 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 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. > One usecase is in nolibc-test itself, where Zhangjin ran into weird > and inconsistent behavior of system includes being pulled in. > By using -nostdinc we avoid this. I see but a normal libc ought not to build with -nostdinc. I mean, we can define whatever we want once we know why we're doing it, but I think that as long as we find it confusing between those how are modifying this code, it will be very difficult to explain correctly to users. We're definitely missing some design rules I think. Maybe -nostdinc should be needed only when using -include nolibc.h for example, I don't know, but I still find that we're papering over a wider problem. > I can also see this being useful for normal users. I agree, that's also my concern actually. > > > I could not find anybody doing this differently. > > > Using builtins seems to me to be the normal way to expose compiler > > > implementation specifics. > > > > OK but it's already what the compiler does itself in its own stdarg that > > is provided. That's why I don't understand what specific case we're trying > > to cover here, I feel like we're providing an alternate stdarg in case the > > compiler doesn't provide one except that I've not seen a compiler not > > provide it (even tcc comes with it), it's like stddef. > > It's all about supporting -nostdinc. 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. > FYI stdint.h is also provided by nolibc, gcc and glibc. True but that one didn't surprise me because it came with C99 and was usually shipped by the libc when compilers targetting previous versions were used, so I didn't see this as a replacement for the compiler's definition actually. I don't know what dictates what goes in the compiler and what in the libc. I'm fine with having to redefine everything that's missing if that's needed, but as indicated above, stddef.h and limits.h are missing despite being quite common. 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 * * In addition, the following ones are expected to be provided by the compiler: * float.h, stdarg.h, stddef.h * * The following ones which are part to the C standard are not provided: * assert.h, locale.h, math.h, setjmp.h, limits.h 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 :-/ Thanks, Willy