From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id DAE7D3858C62 for ; Wed, 12 Jul 2023 10:56:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DAE7D3858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7E2AB22506; Wed, 12 Jul 2023 10:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689159377; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hzb4bTEGT44QceahYvyoXfjXyAy6NPreodBrwxeI0iU=; b=rtUKdSt9WvBBEIR6VTJn3hw01d55uRJQtfqkHAOV4HIkGzPFJTRLFKfa5LIhgJN43ZtCRO Q8Zz1kJOtglhO6jCyNDv+E1n1XvFx+YHuXdgrmS0Iko7jn3sLWO/psLmZRnnqPogciJJza 86G6nQ1XZK8/eaIRrDStbMvdJ+X+a/c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689159377; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hzb4bTEGT44QceahYvyoXfjXyAy6NPreodBrwxeI0iU=; b=kKL4if9JNjQq79ePHLbvzARmziHYI+AlLYjGW9+tPBAgZDDy6aLrFJwzMlPGMTZsvxa45x Je/AL0U19K14akBw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 338B02C142; Wed, 12 Jul 2023 10:56:17 +0000 (UTC) Date: Wed, 12 Jul 2023 10:56:17 +0000 (UTC) From: Richard Biener To: Alejandro Colomar cc: libc-alpha@sourceware.org, Florian Weimer , Xi Ruoyao , Sam James , Richard Biener , Andrew Pinski Subject: Re: [RFC v1 2/2] Makeconfig: Compile glibc with -fno-delete-null-pointer-checks In-Reply-To: <20230711131105.19203-3-alx@kernel.org> Message-ID: References: <20230711131105.19203-1-alx@kernel.org> <20230711131105.19203-3-alx@kernel.org> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 11 Jul 2023, Alejandro Colomar wrote: > Don't undefine __nonnull to prevent compiler optimizations. Instead, > tell the compiler to not optimize based on the attribute, via the > appropriate flag. I'll note that using -fno-delete-null-pointer-checks doesn't work (anymore?) to preserve the nullptr check in int __attribute__((nonnull)) foo (int *p) { if (p) return *p; return 0; } so the documentation of 'nonnull' which says @item The compiler may also perform optimizations based on the knowledge that certain function arguments cannot be null. These optimizations can be disabled by the @option{-fno-delete-null-pointer-checks} option. @xref{Optimize Options}. isn't accurate. I checked trunk, GCC 12 and GCC 7 here. For trunk the offending function is nonnull_arg_p where we probably want to preserve its behavior but some callers fail to check flag_delete_null_pointer_checks when they are not only issueing diagnostics. Richard. > Link: > Reported-by: Florian Weimer > Cc: Xi Ruoyao > Cc: Sam James > Cc: Richard Biener > Cc: Andrew Pinski > Signed-off-by: Alejandro Colomar > --- > Makeconfig | 1 + > include/sys/cdefs.h | 6 ------ > 2 files changed, 1 insertion(+), 6 deletions(-) > > diff --git a/Makeconfig b/Makeconfig > index 369a596e79..ecbe30e53f 100644 > --- a/Makeconfig > +++ b/Makeconfig > @@ -1045,6 +1045,7 @@ CPPFLAGS = $(config-extra-cppflags) $(CPPFLAGS-config) \ > > override CFLAGS = -std=gnu11 \ > -fgnu89-inline \ > + -fno-delete-null-pointer-checks \ > $(config-extra-cflags) \ > $(filter-out %frame-pointer,$(+cflags)) \ > $(+gccwarn-c) \ > diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h > index b84ad34a70..e4a8dd7844 100644 > --- a/include/sys/cdefs.h > +++ b/include/sys/cdefs.h > @@ -10,12 +10,6 @@ > #include > > #ifndef _ISOMAC > -/* The compiler will optimize based on the knowledge the parameter is > - not NULL. This will omit tests. A robust implementation cannot allow > - this so when compiling glibc itself we ignore this attribute. */ > -# undef __nonnull > -# define __nonnull(params) > - > extern void __chk_fail (void) __attribute__ ((__noreturn__)); > libc_hidden_proto (__chk_fail) > rtld_hidden_proto (__chk_fail) > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)