From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 591313858434 for ; Thu, 10 Nov 2022 18:08:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 591313858434 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668103687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zgcj+BZTZrBBW9OeKMTq5Sq07JXDRSrDc8fEluA84tg=; b=GaHmQ5CDmsw3Kf9WclDFnRzWD+gQcyVqGvlwhjUHd+YfKXbaCuTBv03PVEntrGOpFsO4N/ HkSWId0HX6j1efXfznHfBnss833HhGUuecGDLg9iyrvlTGUiURJoFNJwg8Sb826qqWUZ8Q QBSkvIug0R0GaNg1cZ2QMwiSKDUlrc4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-7PvBiJz5OTOQq2SLbd39_w-1; Thu, 10 Nov 2022 13:08:06 -0500 X-MC-Unique: 7PvBiJz5OTOQq2SLbd39_w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0330E8027F5; Thu, 10 Nov 2022 18:08:06 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E64E40C6DC8; Thu, 10 Nov 2022 18:08:04 +0000 (UTC) From: Florian Weimer To: Zack Weinberg via Gcc Cc: c-std-porting@lists.linux.dev, autoconf@gnu.org, cfe-commits@lists.llvm.org, Zack Weinberg , Frederic Berat Subject: Re: How can Autoconf help with the transition to stricter compilation defaults? References: <24ed5604-305a-4343-a1b6-a789e4723849@app.fastmail.com> Date: Thu, 10 Nov 2022 19:08:02 +0100 In-Reply-To: <24ed5604-305a-4343-a1b6-a789e4723849@app.fastmail.com> (Zack Weinberg via Gcc's message of "Thu, 10 Nov 2022 12:16:20 -0500") Message-ID: <87v8nmsmwt.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * Zack Weinberg via Gcc: > I=E2=80=99m the closest thing Autoconf has to a lead maintainer at presen= t. > > It=E2=80=99s come to my attention (via https://lwn.net/Articles/913505/ a= nd > https://fedoraproject.org/wiki/Changes/PortingToModernC) that GCC and > Clang both plan to disable several =E2=80=9Clegacy=E2=80=9D C language fe= atures by > default in a near-future release (GCC 14, Clang 16) (see the Fedora > wiki link for a list). I understand that this change potentially > breaks a lot of old dusty code, and in particular that > Autoconf-generated configure scripts use constructs that may *silently > give the wrong answer to a probe* when a stricter compiler is in use. Thank you for reaching out. The c-std-porting list isn't even bootstrapped yet, the Fedora documentation is still in flux, and the Fedora oversight body just approved working on this in the Fedora context. That LWN article caught me a bit off guard. Anyway, based on a limited attempt to get this fixed about three years ago, I expect that many of the problematic packages have not had their configure scripts regenerated using autoconf for a decade or more. This means that as an autoconf maintainer, you unfortunately won't be able to help us much. > Nobody has a whole lot of time to work on Autoconf at present, but I > would like to ask, anyway, what Autoconf could potentially do to make > this transition easier. I=E2=80=99m already aware that the test code Aut= oconf > 2.71 uses to probe for C89/C99/C11 support is broken; this has been > fixed in development trunk to the extent it is possible for me to test > it with GCC 12 (commit: > ). Thanks, these changes are going to be helpful to get a clean run from our Fedora tester. I also noticed some issues in the automake test suite, and I hope Frederic can have a look at them: automake: Port to modern C > Several other places using K&R function definitions and/or > unprototyped function declarations (including the ubiquitously used > AC_CHECK_FUNC) have also been fixed on trunk, > . One reason I hesitate to recommend wide testing with -Werror=3D=E2=80=A6 is= that it is actually impossible to model future GCC behavior with -Werror=3D=E2= =80=A6 options today. I very much doubt that the AC_CHECK_FUNC change [that is, () =E2=86=92 (void)] will ever be required by real GCC. I'm worried th= at some of this -Werror=3D=E2=80=A6 testing merely introduces unnecessary chur= n. These changes help maintainers who wnat to build their packages with CC=3D"gcc -Werror=3D=E2=80=A6" or something like that, so I guess they stil= l make sense for autoconf. But perhaps not as a general model for everyone else. > The biggest remaining (potential) problem, that I=E2=80=99m aware of, is = that > AC_CHECK_FUNC unconditionally declares the function we=E2=80=99re probing= for > as =E2=80=98char NAME (void)=E2=80=99, and asks the compiler to call it w= ith no > arguments, regardless of what its prototype actually is. It is not > clear to me whether this will still work with the planned changes to > the compilers. Both GCC 12 and Clang 14 have on-by-default warnings > triggered by =E2=80=98extern char memcpy(void);=E2=80=99 (or any other st= andard > library function whose prototype is coded into the compiler) and this > already causes problems for people who run configure scripts with > CC=3D'cc -Werror'. I think t his approach is actually the most portable approach, at least as far as GCC is concerned. GCC treats a function as a compiler built-in only if the declared prototype matches its expectations. I doubt there are any such functions returning char, which makes this declaration a good choice. I do not expect any medium-term changes to the situation here. The warning will stay, it will not turn into an error. > Unfortunately this is very hard to fix =E2=80=94 we would > have to build a comprehensive list of library functions into Autoconf, > mapping each to either its documented prototype or to a header where > it ought to be declared; in the latter case we would also have to make > e.g. AC_CHECK_FUNCS([getaddrinfo]) imply AC_CHECK_HEADERS([sys/types.h > sys/socket.h netdb.h]) which might mess up configure scripts that > aren=E2=80=99t expecting headers to be probed at that point. Once you include the header, you also need to know function parameters, otherwise you won't be able to form a valid call. Python setuptools/distutils tried to do something along this lines, but I can't see how it can work, as explained here: Unclear how CCompiler.has_function works for functions with parameters The char-returning prototype does not seem so bad in the end. The function is actually called and the result returned from main, so it's even compatible with LTO. > How important do you think it is for this to be fixed? In isolation? Not important at all. Maybe it would make sense to fix this as part of some other feature, like bulk probing for function support, with multiple functions in one compiler/linker invocation. That is, enhance the toolchain to support more efficient execution of autoconf scripts and their probes. > Are there any other changes you would like to see in a near-future > Autoconf 2.72 in order to make this transition easier? I appreciate the thought, but as I said initially: the bulk of the problem is with software which we cannot simply autoreconf, so changes in future autoconf behavior are of limited help unfortunately. Even if we can autoreconf, there are popular aclocal.m4/autoconf-archive fragments that get copied around. For example, there is a stack direction test that I not-quite-fixed in libiberty that exist in various forms in many projects: I said not-quited fixed because even though I fixed the C99 compatibility issues in libiberty, the test still gives the wrong result on x86-64 because it compares the address of independent objects from different stack frames, which gives indeterminate results with optimization GCC. But fortunately, the stack direction test is only used for implementing alloca emulation, and we don't need that when building with GCC. (Curiously, many of the non-GCC find_statck_direction variants have already been fixed for C99 compatibility.) Probably the most challenging aspect of all this is to avoid getting sucked into these little side quests. > p.s. GCC and Clang folks: As long as you=E2=80=99re changing the defaults= out > from under people, Hmph, I wouldn't frame it this way. We are aware of GCC's special role as the system compiler. We're trying to upstream the changes to sources before flipping the compiler default. (The burden of being a system compiler and all that.) A 25-year transition period evidently wasn't enough, so some effort is still needed. We may conclude that removing these extensions is too costly even in 2024. > can you please also remove the last few predefined > user-namespace macros (-Dlinux, -Dunix, -Darm, etc) from all the > -std=3DgnuXX modes? That's a good point, I'll think about how we can instrument GCC to support tracking that. We won't be able help with -Darm on the Fedora side (the AArch64 port doesn't have that, and there's no longer a Fedora 32-bit Arm port), but -Dlinux and -Dunix we can help with. Thanks, Florian