Message ID | 20230711131105.19203-1-alx@kernel.org |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C6463854E8C for <patchwork@sourceware.org>; Tue, 11 Jul 2023 13:12:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C6463854E8C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689081128; bh=PKzLcaJIe8kqsd7LVoHznzt6iOrRvzKc5eMcX4a82AY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=buPajuCJ5uEFVmQOeXw6MP3RFSlJ5hGnqjjBBECU/egGYTsOfm9IQac+h4bYQ9ihr GmYy0xhAEOv27ykGwDvsBYXVvcdzebhRK01iaQJAHwQizz9FL6Ptqo9Eti/3QNbL3G EXrRKYJNhVVZwgrUy/wl01nPRY842znHtNVdqSGw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by sourceware.org (Postfix) with ESMTPS id 461E6385840A for <libc-alpha@sourceware.org>; Tue, 11 Jul 2023 13:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 461E6385840A Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8D4E1614AC; Tue, 11 Jul 2023 13:11:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 472CCC433C7; Tue, 11 Jul 2023 13:11:38 +0000 (UTC) To: libc-alpha@sourceware.org Cc: Alejandro Colomar <alx@kernel.org>, Florian Weimer <fweimer@redhat.com>, Xi Ruoyao <xry111@xry111.site>, Sam James <sam@gentoo.org>, Richard Biener <rguenth@gcc.gnu.org>, Andrew Pinski <apinski@marvell.com> Subject: [RFC v1 0/2] Use -fno-delete-null-pointer-checks to build glibc Date: Tue, 11 Jul 2023 15:11:04 +0200 Message-Id: <20230711131105.19203-1-alx@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5328; i=alx@kernel.org; h=from:subject; bh=Pe5XH7Xq3abnaQqc7cOkZtnSYIDwBjMgUwQkfrn+npI=; b=owEBbQKS/ZANAwAKAZ6MGvu+/9syAcsmYgBkrVTZO9AfQ8NAFhTWfbn553ITmckgqu0NGiiVg h2CYuG76raJAjMEAAEKAB0WIQTqOofwpOugMORd8kCejBr7vv/bMgUCZK1U2QAKCRCejBr7vv/b MqFfD/4t3TBb5Kr2aaVoP+nqkEz+KuyUaMMyO4Ynrr52vKB5Qx5La0aHD5Iz71H3ORgdL6WDLcQ aPm/Aw4bi+MAYxPP86z+zo9HRsvXwICx1B04a5WwnoBxmWdJfcqQZLBBzkDQM+F08e7usIzqRs8 kbYMRWs+C2cJiqhIqj6DOE9GQqdgq9+OqAejK+RjfiaraovekvblIAquRTNFqDccdgSa34U6p7L T+nsxCQ0oG4ToawUcJB9MvdRUElWGz48ETDi7ClwDvg4VMTDvRc4+B53wgst3vylJU+1qkZnc1F aA/XZYisNDGEmDnh90biwtIooi+MVMcivPIXlBMbHh4iGHyrJPWmraRgQzYroQniDAsvRdPXrSd TvCAOZLIL8YU1KebjNQepYRZtpXklzBYV+XatkIDKkBCbOPXZszuJLzXMJZ10PdHS8PB/SihvNi CTtMTbmd47z5jsTllz57M+VNvn6EGO4ih4SzXBwnSyIljjv8i2eG5cuLVX9TDgMgiDH4lXdiL2P q+mkEAE8fve33eFuEfDIddlj2QLvT7+4MYCa/wgBeqpFnlvQL5Gn13fgf0GMfewDcydEFbFoYG7 Lxum89bfvy+926cuvYRHYEltIsjtP2Pe9c5cn0aHco9FWBx9HwffQVojHaVwRpocezAbNd3A8/J uB6zb6LTpLt82/w== X-Developer-Key: i=alx@kernel.org; a=openpgp; fpr=A9348594CE31283A826FBDD8D57633D441E25BB5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Alejandro Colomar via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Alejandro Colomar <alx@kernel.org> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Use -fno-delete-null-pointer-checks to build glibc
|
|
Message
Alejandro Colomar
July 11, 2023, 1:11 p.m. UTC
Hi, Glibc currently undefines __nonnull internally, to avoid compiler optimizations that would make glibc unsafe. The attribute is only present in installed headers, but for internal code an #undef is used. Xi is trying to improve the consistency in uses of __nonnull in the installed headers, to avoid special cases in GCC's fanalyzer. That prompted the question of whether the attribute is safe, as the compiler is known to optimize too much based on it. Florian reported that there's -fno-delete-null-pointer-checks to tell the compiler to not optimize, and only warn about incorrect uses of null pointers. Another idea arised from that: it would be good if glibc used __nonnull internally to get more warnings. We only need to take care to prevent the compiler optimizations. While I was trying to do that change, which seemed trivial (see this patch set), I uncovered what seems some circular dependencies in the glibc header files (see the build log below). Could you please have a look at it? Thanks, Alex ---- (re)Build log ---- $ make make -r PARALLELMFLAGS="" -C ../nonnull objdir=`pwd` all make[1]: Entering directory '/home/alx/src/gnu/glibc/nonnull' type "make help" for help with common glibc makefile targets make subdir=csu -C csu ..=../ subdir_lib make subdir=iconv -C iconv ..=../ subdir_lib make[2]: Entering directory '/home/alx/src/gnu/glibc/nonnull/iconv' gcc gconv_conf.c -c -std=gnu11 -fgnu89-inline -fno-delete-null-pointer-checks -g -O2 -Wall -Wwrite-strings -Wundef -Werror -fmerge-all-constants -frounding-math -fno-stack-protector -fno-common -Wp,-U_FORTIFY_SOURCE -Wstrict-prototypes -Wold-style-definition -fmath-errno -fPIE -DGCONV_PATH='"/opt/gnu/glibc/nonnull/lib/gconv"' -ftls-model=initial-exec -I../include -I/home/alx/src/gnu/glibc/.tmp/iconv -I/home/alx/src/gnu/glibc/.tmp -I../sysdeps/unix/sysv/linux/x86_64/64 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/x86/include -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/x86/nptl -I../sysdeps/unix/sysv/linux/wordsize-64 -I../sysdeps/x86_64/nptl -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux -I../sysdeps/nptl -I../sysdeps/pthread -I../sysdeps/gnu -I../sysdeps/unix/inet -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../sysdeps/unix -I../sysdeps/posix -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../sysdeps/x86_64 -I../sysdeps/x86/include -I../sysdeps/x86 -I../sysdeps/ieee754/float128 -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I.. -I../libio -I. -D_LIBC_REENTRANT -include /home/alx/src/gnu/glibc/.tmp/libc-modules.h -DMODULE_NAME=libc -include ../include/libc-symbols.h -DPIC -DTOP_NAMESPACE=glibc -o /home/alx/src/gnu/glibc/.tmp/iconv/gconv_conf.o -MD -MP -MF /home/alx/src/gnu/glibc/.tmp/iconv/gconv_conf.o.dt -MT /home/alx/src/gnu/glibc/.tmp/iconv/gconv_conf.o In file included from ../include/sys/cdefs.h:10, from ../include/features.h:503, from ../assert/assert.h:35, from ../include/assert.h:1, from gconv_conf.c:19: ../include/dirent.h:53:17: error: expected ‘)’ before numeric constant 53 | __nonnull (4) attribute_hidden; | ^ ../misc/sys/cdefs.h:401:69: note: in definition of macro ‘__attribute_nonnull__’ 401 | # define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params)) | ^~~~~~ ../include/dirent.h:53:6: note: in expansion of macro ‘__nonnull’ 53 | __nonnull (4) attribute_hidden; | ^~~~~~~~~ ../misc/sys/cdefs.h:401:76: error: expected ‘,’ or ‘;’ before ‘)’ token 401 | # define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params)) | ^ ../misc/sys/cdefs.h:407:28: note: in expansion of macro ‘__attribute_nonnull__’ 407 | # define __nonnull(params) __attribute_nonnull__ (params) | ^~~~~~~~~~~~~~~~~~~~~ ../include/dirent.h:53:6: note: in expansion of macro ‘__nonnull’ 53 | __nonnull (4) attribute_hidden; | ^~~~~~~~~ make[2]: *** [../o-iterator.mk:9: /home/alx/src/gnu/glibc/.tmp/iconv/gconv_conf.o] Error 1 make[2]: Leaving directory '/home/alx/src/gnu/glibc/nonnull/iconv' make[1]: *** [Makefile:484: iconv/subdir_lib] Error 2 make[1]: Leaving directory '/home/alx/src/gnu/glibc/nonnull' make: *** [Makefile:9: all] Error 2 --- Build log end ---- Alejandro Colomar (2): Makeconfig: Use one line per token Makeconfig: Compile glibc with -fno-delete-null-pointer-checks Makeconfig | 18 +++++++++++++----- include/sys/cdefs.h | 6 ------ 2 files changed, 13 insertions(+), 11 deletions(-) Range-diff against v0: -: ---------- > 1: 55d7caa944 Makeconfig: Use one line per token -: ---------- > 2: efb21da36c Makeconfig: Compile glibc with -fno-delete-null-pointer-checks
Comments
* Alejandro Colomar via Libc-alpha: > In file included from ../include/sys/cdefs.h:10, > from ../include/features.h:503, > from ../assert/assert.h:35, > from ../include/assert.h:1, > from gconv_conf.c:19: > ../include/dirent.h:53:17: error: expected ‘)’ before numeric constant > 53 | __nonnull (4) attribute_hidden; > | ^ This is a typo, it should be __nonnull ((4)). The __nonnull redefinition simply hides it for now. Thanks, Florian
On 2023-07-11 15:18, Florian Weimer wrote: > * Alejandro Colomar via Libc-alpha: > >> In file included from ../include/sys/cdefs.h:10, >> from ../include/features.h:503, >> from ../assert/assert.h:35, >> from ../include/assert.h:1, >> from gconv_conf.c:19: >> ../include/dirent.h:53:17: error: expected ‘)’ before numeric constant >> 53 | __nonnull (4) attribute_hidden; >> | ^ > > This is a typo, it should be __nonnull ((4)). > > The __nonnull redefinition simply hides it for now. Thanks. I'll fix it. Cheers, Alex > > Thanks, > Florian >
On Tue, 2023-07-11 at 15:11 +0200, Alejandro Colomar wrote: > Florian reported that there's -fno-delete-null-pointer-checks to tell > the compiler to not optimize, and only warn about incorrect uses of null > pointers. One potential problem is -fno-delete-null-pointer-checks not only disables optimizations based on __nonnull, but also disables the optimizations based on other provable non-null pointer values. So maybe we should run a benchmark to see if there is some severe degradation, if there is any we may fix it by moving null checks away from hot paths.
On 2023-07-11 15:22, Xi Ruoyao wrote: > On Tue, 2023-07-11 at 15:11 +0200, Alejandro Colomar wrote: >> Florian reported that there's -fno-delete-null-pointer-checks to tell >> the compiler to not optimize, and only warn about incorrect uses of null >> pointers. > > One potential problem is -fno-delete-null-pointer-checks not only > disables optimizations based on __nonnull, but also disables the > optimizations based on other provable non-null pointer values. So maybe > we should run a benchmark to see if there is some severe degradation, if > there is any we may fix it by moving null checks away from hot paths. > Sure; I don't know how to run those, so I'll provide the patches, and will let any of you run the benchmarks (or point me to some documentation to learn how to run them). Cheers, Alex