From patchwork Thu Jul 20 14:40:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1810510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=J3S/4cnN; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6FjB2hCyz1yYm for ; Fri, 21 Jul 2023 00:40:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B45F0385482D for ; Thu, 20 Jul 2023 14:40:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B45F0385482D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689864027; bh=qaudXxF2EcZR9GNFoCFrzEGUZ/dW9G9hVp50Dkq4jBc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=J3S/4cnNeO5NRziLomsdGu3FuFvH32ExWN3bGl8u0wBui1u0v7tK0nyvSuhZxhog1 5jk60pzisMb01k+6yPgAft5LTcPVBYAEayiF0lDFrkNbM9Lwq4VDClrTn1/q/013Vw IxzPt3ysacTtVhnsipysUwkuGBjL+Coyq5bqvEEU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by sourceware.org (Postfix) with ESMTPS id 11AFC385B522 for ; Thu, 20 Jul 2023 14:40:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11AFC385B522 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-1b056276889so669770fac.2 for ; Thu, 20 Jul 2023 07:40:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689864006; x=1690468806; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qaudXxF2EcZR9GNFoCFrzEGUZ/dW9G9hVp50Dkq4jBc=; b=QyZ9gW62YPgF9q/teg65NC0GTmG/sEhW/vTcGiEELouPB/f+7tbL2Tk94oMQ/e7Sqy GoqL378iOWycwMZek1rgljsUsKF5wqEv8QspmqKlWkzp5vzNBfMthek9lr1ALOjFDk7c jCsSnH0r4fxm8IZtBzk1CktaRzFpwHHMaxgiL7JVPn1hlqxNow49qt3LUXN4C6IULQRA v8LPiOlNZ1wifizXOaWN1B/k6h/RuCqle9wt+/RbsXF9lPF0SdMXqNcv0CCzIZxMS0yl SWZzfgLqXK+ENp3jMRv1rB/29fSQfwabKcpHd5B+Ou9oHNrj/F1bkZaYeZXGuei7fJpF AwkQ== X-Gm-Message-State: ABy/qLa1gStBrhDijsn2dVafN0s6j5zvVTwVzoQnor8SIFi9klbyeXMZ U3qAG0qev1ET3DSaPRpDRQ/AbHvXJyL1L30C+4OJQQ== X-Google-Smtp-Source: APBJJlHCBO+E8sKPpM+k9ro/PDu7D4RK+JyTsPx5xrrcf+C40mFV8bCdZuQvzra/+E8iuxt40koPXA== X-Received: by 2002:a05:6871:829:b0:1b4:66e6:cf51 with SMTP id q41-20020a056871082900b001b466e6cf51mr2155272oap.15.1689864005734; Thu, 20 Jul 2023 07:40:05 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d4d2:3fa:b3f3:5805:c527]) by smtp.gmail.com with ESMTPSA id x2-20020a056870740200b001a663e49523sm546889oam.36.2023.07.20.07.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 07:40:05 -0700 (PDT) To: libc-alpha@sourceware.org, Frederic Berat , Siddhesh Poyarekar , Florian Weimer Subject: [PATCH] scripts: Fix fortify checks if compiler does not support _FORTIFY_SOURCE=3 Date: Thu, 20 Jul 2023 11:40:01 -0300 Message-Id: <20230720144001.2088610-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The 30379efad1 added _FORTIFY_SOURCE checks without check if compiler does support all used fortify levels. This patch fixes it by first checking at configure time the maximum support fortify level and using it instead of a pre-defined one. Checked on x86_64 with gcc 11, 12, and 13. Reviewed-by: Siddhesh Poyarekar Tested-by: Florian Weimer --- Makefile | 4 ++-- Rules | 4 ++-- configure | 28 ++++++++++++---------------- configure.ac | 13 +++++++------ scripts/check-installed-headers.sh | 11 +++++++---- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index f324df7a1f..c6d4817a9e 100644 --- a/Makefile +++ b/Makefile @@ -545,7 +545,7 @@ tests-special += $(objpfx)check-installed-headers-c.out libof-check-installed-headers-c := testsuite $(objpfx)check-installed-headers-c.out: \ scripts/check-installed-headers.sh $(headers) - $(SHELL) $(..)scripts/check-installed-headers.sh c \ + $(SHELL) $(..)scripts/check-installed-headers.sh c $(supported-fortify) \ "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \ $(headers) > $@; \ $(evaluate-test) @@ -555,7 +555,7 @@ tests-special += $(objpfx)check-installed-headers-cxx.out libof-check-installed-headers-cxx := testsuite $(objpfx)check-installed-headers-cxx.out: \ scripts/check-installed-headers.sh $(headers) - $(SHELL) $(..)scripts/check-installed-headers.sh c++ \ + $(SHELL) $(..)scripts/check-installed-headers.sh c++ $(supported-fortify) \ "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \ $(headers) > $@; \ $(evaluate-test) diff --git a/Rules b/Rules index 5e945d7347..279ae490ac 100644 --- a/Rules +++ b/Rules @@ -85,7 +85,7 @@ tests-special += $(objpfx)check-installed-headers-c.out libof-check-installed-headers-c := testsuite $(objpfx)check-installed-headers-c.out: \ $(..)scripts/check-installed-headers.sh $(headers) - $(SHELL) $(..)scripts/check-installed-headers.sh c \ + $(SHELL) $(..)scripts/check-installed-headers.sh c $(supported-fortify) \ "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \ $(headers) > $@; \ $(evaluate-test) @@ -97,7 +97,7 @@ tests-special += $(objpfx)check-installed-headers-cxx.out libof-check-installed-headers-cxx := testsuite $(objpfx)check-installed-headers-cxx.out: \ $(..)scripts/check-installed-headers.sh $(headers) - $(SHELL) $(..)scripts/check-installed-headers.sh c++ \ + $(SHELL) $(..)scripts/check-installed-headers.sh c++ $(supported-fortify) \ "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \ $(headers) > $@; \ $(evaluate-test) diff --git a/configure b/configure index c02c0b5825..14e2ecce28 100755 --- a/configure +++ b/configure @@ -7610,9 +7610,9 @@ fi no_fortify_source="-Wp,-U_FORTIFY_SOURCE" fortify_source="${no_fortify_source}" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_dynamic_object_size" >&5 -printf %s "checking for __builtin_dynamic_object_size... " >&6; } -if test ${libc_cv___builtin_dynamic_object_size+y} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for maximum supported _FORTIFY_SOURCE level" >&5 +printf %s "checking for maximum supported _FORTIFY_SOURCE level... " >&6; } +if test ${libc_cv_supported_fortify_source+y} then : printf %s "(cached) " >&6 else $as_nop @@ -7630,30 +7630,24 @@ __builtin_dynamic_object_size("", 0) _ACEOF if ac_fn_c_try_link "$LINENO" then : - libc_cv___builtin_dynamic_object_size=yes - if test "$enable_fortify_source" = yes -then : - enable_fortify_source=3 -fi + libc_cv_supported_fortify_source=3 else $as_nop - libc_cv___builtin_dynamic_object_size=no - if test "$enable_fortify_source" = yes -then : - enable_fortify_source=2 -fi + libc_cv_supported_fortify_source=2 fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv___builtin_dynamic_object_size" >&5 -printf "%s\n" "$libc_cv___builtin_dynamic_object_size" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_supported_fortify_source" >&5 +printf "%s\n" "$libc_cv_supported_fortify_source" >&6; } case $enable_fortify_source in #( + yes) : + libc_cv_fortify_source=yes enable_fortify_source=$libc_cv_supported_fortify_source ;; #( 1|2) : libc_cv_fortify_source=yes ;; #( 3) : - if test "$libc_cv___builtin_dynamic_object_size" = yes + if test $libc_cv_supported_fortify_source = 3 then : libc_cv_fortify_source=yes else $as_nop @@ -7673,6 +7667,8 @@ fi +config_vars="$config_vars +supported-fortify = $libc_cv_supported_fortify_source" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the assembler requires one version per symbol" >&5 printf %s "checking whether the assembler requires one version per symbol... " >&6; } diff --git a/configure.ac b/configure.ac index 09553541fb..ff35bf4d6b 100644 --- a/configure.ac +++ b/configure.ac @@ -1578,17 +1578,17 @@ dnl support it no_fortify_source="-Wp,-U_FORTIFY_SOURCE" fortify_source="${no_fortify_source}" -AC_CACHE_CHECK([for __builtin_dynamic_object_size], [libc_cv___builtin_dynamic_object_size], [ +AC_CACHE_CHECK([for maximum supported _FORTIFY_SOURCE level], + [libc_cv_supported_fortify_source], [ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_dynamic_object_size("", 0)])], - [libc_cv___builtin_dynamic_object_size=yes - AS_IF([test "$enable_fortify_source" = yes], [enable_fortify_source=3])], - [libc_cv___builtin_dynamic_object_size=no - AS_IF([test "$enable_fortify_source" = yes], [enable_fortify_source=2])]) + [libc_cv_supported_fortify_source=3], + [libc_cv_supported_fortify_source=2]) ]) AS_CASE([$enable_fortify_source], + [yes], [libc_cv_fortify_source=yes enable_fortify_source=$libc_cv_supported_fortify_source], [1|2], [libc_cv_fortify_source=yes], - [3], [AS_IF([test "$libc_cv___builtin_dynamic_object_size" = yes], + [3], [AS_IF([test $libc_cv_supported_fortify_source = 3], [libc_cv_fortify_source=yes], [AC_MSG_ERROR([Compiler doesn't provide necessary support for _FORTIFY_SOURCE=3])])], [libc_cv_fortify_source=no]) @@ -1601,6 +1601,7 @@ AC_SUBST(enable_fortify_source) AC_SUBST(libc_cv_fortify_source) AC_SUBST(no_fortify_source) AC_SUBST(fortify_source) +LIBC_CONFIG_VAR([supported-fortify], [$libc_cv_supported_fortify_source]) dnl Starting with binutils 2.35, GAS can attach multiple symbol versions dnl to one symbol (PR 23840). diff --git a/scripts/check-installed-headers.sh b/scripts/check-installed-headers.sh index 23506a2514..ee9f534ab0 100644 --- a/scripts/check-installed-headers.sh +++ b/scripts/check-installed-headers.sh @@ -29,11 +29,12 @@ cxx_modes="-std=c++98 -std=gnu++98 -std=c++11 -std=gnu++11" # These are probably the most commonly used three. lib_modes="-D_DEFAULT_SOURCE=1 -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=700" -# Also check for fortify modes, since it might be enabled as default. -fortify_modes="1 2 3" +# Also check for fortify modes, since it might be enabled as default. The +# maximum value to be checked is define by maximum_fortify argument. +fortify_modes="" if [ $# -lt 3 ]; then - echo "usage: $0 c|c++ \"compile command\" header header header..." >&2 + echo "usage: $0 c|c++ maximum_fortify \"compile command\" header header header..." >&2 exit 2 fi case "$1" in @@ -50,6 +51,8 @@ case "$1" in exit 2;; esac shift +fortify_modes=$(seq -s' ' 1 $1) +shift cc_cmd="$1" shift trap "rm -f '$cih_test_c'" 0 @@ -104,7 +107,6 @@ EOF for lang_mode in "" $lang_modes; do for lib_mode in "" $lib_modes; do for fortify_mode in "" $fortify_modes; do - echo :::: $lang_mode $lib_mode $fortify_mode if [ -z "$lib_mode" ]; then expanded_lib_mode='/* default library mode */' else @@ -114,6 +116,7 @@ EOF if [ ! -z $fortify_mode ]; then fortify_mode="#define _FORTIFY_SOURCE $fortify_mode" fi + echo :::: $lang_mode $lib_mode $fortify_mode cat >"$cih_test_c" <