Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2228001rwl; Sat, 1 Apr 2023 04:20:22 -0700 (PDT) X-Google-Smtp-Source: AK7set9Wj+IoUJli2hZ+Agdz6385NIp57TCjDDoK9jwItEsPXClI+3fZI2YAceZbqiEVqk8IMfM6 X-Received: by 2002:a05:6a20:89a8:b0:da:7d8a:2cc9 with SMTP id h40-20020a056a2089a800b000da7d8a2cc9mr25317141pzg.24.1680348021847; Sat, 01 Apr 2023 04:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680348021; cv=none; d=google.com; s=arc-20160816; b=SYlsnL3su9Au0gF8UxsYSSQoSC/iQayD1XIEq9Ntjid72nE9txOlY2RLrZdlLYy3ph OXvM01+7a6JsWXYHf8V13rVB03fnJTuLNU8cB+W1ZLNeQYWhJwO4sqw3PxKmZ87WERPn 7jZYvnitHP1Rwtd/DtD3yR5TNemMRVU4DsLUsSB0e7GuJkWzeasfEaV6gzRaphhTs8+1 x0RJI7m3v8XqiSru3vqte+c0NEmf2l30ZaJNjL3egrApoG/PiOH/hEivgheURDF2q0NJ kerXGVYQi7cBrm22U86m0CdY+OlRjRrC8/2xGMizRQLI/cGCMIO+S/cqDn1809bdfVY9 SVBQ== 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=QkRGH+D/GzQBChQKBVklpOIhlxyzXFLvbo4wZi7Ku0U=; b=Ca3oCbVd/EWftg2RE1uWOCpZlLyym21kyzVMDQ9QerAXsYZom4dgTzlVVf2LWuInUn NPxCNcR4DVhTpW2fWzsy4wzfpqiPvqRJv/xBNTaE7UFdL17C6qyZQ3D8qPuC3CmZcNsS mvtFT9X7kxzZJdFOdL7DGaa80WoKFUQzrFRdcq3P8Sm0xKOLfsjxhO6wmsy/vxXEyu71 H08/VPHKemvaGXyY44T8EdMEUKDGXf3sNrr3IVO2JKtZHSpgp6fMl2KcZHRWRXQEAIOT 0AqG76fQ3AyzakFiGLRWda+VZ3fUPd4KlJcmyrQM37ZMJPAnm9JLptMmIei1VfoL8r3+ QF7w== 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 r3-20020a63ce43000000b004fc2def26adsi4538559pgi.197.2023.04.01.04.20.06; Sat, 01 Apr 2023 04:20:21 -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 S229720AbjDALEm (ORCPT + 99 others); Sat, 1 Apr 2023 07:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjDALEl (ORCPT ); Sat, 1 Apr 2023 07:04:41 -0400 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E09B2527C; Sat, 1 Apr 2023 04:04:39 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 331B4XZ1015062; Sat, 1 Apr 2023 13:04:33 +0200 Date: Sat, 1 Apr 2023 13:04:33 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] tools/nolibc: validate C99 compatibility Message-ID: References: <20230328-nolibc-c99-v1-1-a8302fb19f19@weissschuh.net> <2be5dd3f-d4ca-499a-9f7e-3113b4f04412@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=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 Sat, Apr 01, 2023 at 10:33:45AM +0000, Thomas Wei?schuh wrote: > Hi Willy, > > sorry for the late response to your previous mail, I was traveling. Don't be sorry, I hardly have the time to respond between week-ends, so you're waiting for me more than the other way around! > > I just ran some tests and there's actually better to achieve what you're > > looking for. Let's just use -fno-asm, it removes the GNU-specific "asm", > > "inline", and "typeof" in favor of the "__" variants. With gcc 11.3 it > > gives me this, which is exactly what we were looking for: > > > > gcc -Os -fno-ident -fno-asynchronous-unwind-tables -fno-stack-protector -DNOLIBC_STACKPROTECTOR -mstack-protector-guard=global -fstack-protector-all -fno-asm -s -o nolibc-test \ > > -nostdlib -static -Isysroot/x86/include nolibc-test.c -lgcc > > In file included from sysroot/x86/include/stdlib.h:14, > > from sysroot/x86/include/nolibc.h:103, > > from sysroot/x86/include/errno.h:26, > > from sysroot/x86/include/stdio.h:14, > > from nolibc-test.c:15: > > sysroot/x86/include/string.h: In function 'memset': > > sysroot/x86/include/string.h:93:17: error: 'asm' undeclared (first use in this function) > > 93 | asm volatile(""); > > | ^~~ > > sysroot/x86/include/string.h:93:17: note: each undeclared identifier is reported only once for each function it appears in > > sysroot/x86/include/string.h:93:20: error: expected ';' before 'volatile' > > 93 | asm volatile(""); > > | ^~~~~~~~~ > > | ; > > sysroot/x86/include/string.h: In function 'strlen': > > sysroot/x86/include/string.h:142:17: warning: implicit declaration of function 'asm' [-Wimplicit-function-declaration] > > 142 | asm(""); > > | ^~~ > > nolibc-test.c: In function 'main': > > nolibc-test.c:898:25: error: 'asm' undeclared (first use in this function) > > 898 | asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0)); > > | ^~~ > > nolibc-test.c:898:28: error: expected ';' before 'volatile' > > 898 | asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0)); > > | ^~~~~~~~~ > > | ; > > make: *** [Makefile:128: nolibc-test] Error 1 > > > > With this, we don't need to force -std=c99 nor to build two variants, > > a single variant will catch GCCisms even with older compilers while not > > being overly annoying. > > The original goal was to have a fixed and explicit baseline that is > supported. Using -std= ensures that no deviations are accidentally > introduced. > > Using -fno-asm only prevents this specific gnu-ism. All other gnu-isms > and features from whatever the current compilers default language level > is are still allowed. > > Therefore I'm not convinced of this aproach. > > These are the aproaches I can see that reach this goal: > > * Declare C99 as baseline, build with -std=c99 > * Declare C99 and GNU89 as baseline, build with both. > * Declare C99 and GNU89 as baseline, build with -std=c99, > wait for people to complain if something breaks on gnu89 > (same as current status) > * Declare C89 as baseline, remove all C99-isms and gnu-isms > (C++ comments, "inline" and some smaller stuff), > build with -std=c89. > > Personally I think C99 is a baseline that is easy to fulfill by nolibc > and should not restrict users. I *am* affected. I do maintain some code that builds using an older version of nolibc and still builds with the current one, that builds fine on gcc 4.4..4.9 (as still present on some still supported distros such as RHEL7 which comes with gcc-4.8). I just tried to build nolibc-test with gcc-4.7 (which I still have for plenty of archs and that is ~50% faster than 11.x, something appreciable during wide range bisects) and it breaks on the size_t declared inside the for statement. We could possibly go with your 3rd proposal above (i.e. both baselines, only build with c99 and wait for reports). Or we could equally build with "-std=gnu89 -fno-asm" and make sure we stay away from any recent accidental deviation. All relevant compilers in use for a while are compatible with this because this has been the default for a very long time. By the way, it's worth noting that no single gcc version ever used c99 as a default standard. Thanks, Willy