From patchwork Fri Dec 20 21:54:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 103541 Return-Path: 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 A91D23858401 for ; Fri, 20 Dec 2024 21:54:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A91D23858401 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Wfa7JLnE X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id CDF2B3858D26 for ; Fri, 20 Dec 2024 21:54:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDF2B3858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CDF2B3858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734731650; cv=none; b=Mvfzi+nw6dHg4lk3sGq+pt4zqieek2JjKGbGFqW4Ae/72ZtiuZVjyb1kVgxb1Y92cO5Ri2UPrbN+eUzQWbQ6VDAPhELBwpjsOtr83cvviiU9wj0NceW0qG1YRDOLHrwOa+50P2Etm8UiO74OoL6WIh8D2hTN9uypmhrAUWJ/3zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734731650; c=relaxed/simple; bh=arv06bVOTYBKVidPguU2ypTPJkoljSNaK8y9kAQTkTs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J7O4NiDxBx9q89iJfOapsI29TLcysoQpYjl+6EukaQoh+mSt+njpUipyCLhXg+RZC5o4R56KWm+mAeuaaHhbTrbGSO8rIhJPjJp0wYB85GjC84vOp0tD/clmv48Zotjr2Lnk/pp+MLeuVr+A60YaGikuQAVQA1pO2JBN3ICkgHY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDF2B3858D26 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-725dbdf380aso2042596b3a.3 for ; Fri, 20 Dec 2024 13:54:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734731649; x=1735336449; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1uCpxxkhsiVQjkSb9sq1Cw5G5JMqYhACxeuZkMV/Fiw=; b=Wfa7JLnEomH1UHUg7g7nehiGdjqVnOmZo4USavQd7jhBD6+FPw9IzXnsNe+FAQj1Rq tHo7PJDphHSNmXq3n1x6RcwFZ9cu1H12uBVkpZlPjh5qPwATX6jYStM9M0GsXQhUrNKc w1aLfvswRm7ZMtlUe+bCoGMYLGCx8KoY1SHoPcNKRHSgJw0ZY52vhwnlVTPjpe+rtpjV gVboSrhTV9GPdgFXQF41eWDrUYot1QseTOHZVTIDenAVWRwAw6mLwCkRHJMHjs67TG1w L82hTFpGRy2tTUdl9ffjKNbVLu6jI3B7vjKp0UMMQigRhBmDNazsTx6LP06RuQ1J7F1G BX9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734731649; x=1735336449; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1uCpxxkhsiVQjkSb9sq1Cw5G5JMqYhACxeuZkMV/Fiw=; b=sGO1t95qlJRM1LsgNflCoSRb74H/iB/mgCiKnE3Yo6LCVsyQSKy8SXKH0gTfDg68lQ i3DQ1PnDKA3zOyNYT5rJ6FnA6Gty1/pM6r92EaebFwc0IiKlfvDlYZjJ4huav59SJPwM XXWIcePij2AIgL5JXw2KAIEWlVP3h4CuaykDgrR72hEkHWWMWCWsb+4icR87y/2AeKOw woWEIdg9RJL4LNDw5VmIfGabA5BjNdPlHqKQ3llOlmFXrJ4vMkeT0DMzajZU4mjEwCbT 54jMLsZ2t+AYTNo/iUxPx8lO8MxYGQRbl7RJggqXCKquXvQoZELRIk8cpdLoznWo1WQV EPdw== X-Gm-Message-State: AOJu0Ywe28ONEQ5Y6L5LxGx1/6VKY34VOKEl6J/eJxvJD6TvDSeura/J iRd/5ihMdhqaSSQCCY9rUB6wBP7vEMgeAezWdAae2KhUSFKcz0EEJhxqr8yFroGeTw== X-Gm-Gg: ASbGnct1bGSTyIpIBLOgEglJQtQu5TAY7yU+EeHEH7BdceBvx6a2+Sb4YKVOkRTmeEa hp5dqhvs4CU9tZvPf2oUOS++X+BeaRD3htfqvmF25DcYRj1xxqDz/01g1W7hTN2uGHQhjKl3U2S R0wfUkaQOg1GFVYXOxRNuNzbMoPm4XqWQVC2Lfq/Ejm+66r6UdQm7nSGyjSYT1e5HtDTfuzCySI hAZhM2p7hlF8A2+A58R44+uNWi9UyCtGuBbyybdeXKXtpUTDRnDqLtI4Nmo7/1LhzwrCls= X-Google-Smtp-Source: AGHT+IGgmiUdM9IRTQUsPmgPbRfuWTemPRA+zonuKDazDbJEQj0+ruCB/zZy45tzHAc1p/YiDRdSfw== X-Received: by 2002:a05:6a20:6f06:b0:1e0:eb49:b81b with SMTP id adf61e73a8af0-1e5e07ffc60mr9112917637.31.1734731648683; Fri, 20 Dec 2024 13:54:08 -0800 (PST) Received: from gnu-tgl-3.localdomain ([120.204.185.130]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad816187sm3576964b3a.16.2024.12.20.13.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 13:54:08 -0800 (PST) Received: from gnu-tgl-3.lan (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id B60D0C0272; Sat, 21 Dec 2024 05:54:06 +0800 (CST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: sam@gentoo.org Subject: [PATCH v2] Enable execstack tests only if compiler supports trampoline Date: Sat, 21 Dec 2024 05:54:06 +0800 Message-ID: <20241220215406.698828-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3019.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Since trampoline is required to test execstack, enable execstack tests only if compiler supports trampoline. Signed-off-by: H.J. Lu --- configure | 47 +++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 22 ++++++++++++++++++++++ elf/Makefile | 4 ++++ nptl/Makefile | 9 +++++++-- 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 73eaf0e4e7..1eb2d1e7e9 100755 --- a/configure +++ b/configure @@ -7775,6 +7775,53 @@ config_vars="$config_vars cc-option-wimplicit-fallthrough = $libc_cv_cc_wimplicit_fallthrough" +conftest_code=" +void bar (void (*callback) (void)); +int foo (void) +{ + int var = 0; + void callback (void) { var = 1; } + bar (callback); + return var; +} +" + + +cat > conftest.c <&5 +printf %s "checking support for trampolines in testing... " >&6; } +if test ${libc_cv_test_cc_trampolines+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -c -Werror conftest.c -o conftest 1>&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + libc_cv_test_cc_trampolines=yes + else + libc_cv_test_cc_trampolines=no + + fi ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cc_trampolines" >&5 +printf "%s\n" "$libc_cv_test_cc_trampolines" >&6; } + +CC="$saved_CC" + +rm -f conftest* +config_vars="$config_vars +have-test-cc-trampoline = $libc_cv_test_cc_trampolines" + saved_CC="$CC" diff --git a/configure.ac b/configure.ac index ecb51e4384..9f72a2a0ae 100644 --- a/configure.ac +++ b/configure.ac @@ -1528,6 +1528,28 @@ LIBC_CONFIG_VAR([cc-option-wimplicit-fallthrough], [$libc_cv_cc_wimplicit_fallthrough]) AC_SUBST(libc_cv_test_cc_wimplicit_fallthrough) +conftest_code=" +void bar (void (*callback) (void)); +int foo (void) +{ + int var = 0; + void callback (void) { var = 1; } + bar (callback); + return var; +} +" + +dnl Check if TEST_CC support trampolines. +LIBC_TRY_TEST_CC_COMMAND([support for trampolines], + [$conftest_code], + [-c -Werror], + libc_cv_test_cc_trampolines, + [libc_cv_test_cc_trampolines=yes], + [libc_cv_test_cc_trampolines=no] +) +LIBC_CONFIG_VAR([have-test-cc-trampoline], + [$libc_cv_test_cc_trampolines]) + dnl Check if TEST_CC supports -finput-charset=ascii. LIBC_TRY_TEST_CC_OPTION([-finput-charset=ascii], [-c -Werror -finput-charset=ascii], diff --git a/elf/Makefile b/elf/Makefile index a5a25a8370..b62836d79c 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -557,12 +557,14 @@ endif selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) ifneq ($(selinux-enabled),1) +ifeq ($(have-test-cc-trampoline),yes) tests-execstack-yes = \ tst-execstack \ tst-execstack-needed \ tst-execstack-prog \ # tests-execstack-yes endif +endif ifeq ($(have-depaudit),yes) tests += \ tst-audit14 \ @@ -1146,7 +1148,9 @@ tests-pie += vismain CFLAGS-vismain.c += $(PIE-ccflag) endif endif +ifeq ($(have-test-cc-trampoline),yes) modules-execstack-yes = tst-execstack-mod +endif extra-test-objs += $(addsuffix .os,$(strip $(modules-names))) # filtmod1.so, tst-big-note-lib.so, tst-ro-dynamic-mod.so have special diff --git a/nptl/Makefile b/nptl/Makefile index 88077e27bb..bc2e499a7c 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -474,7 +474,7 @@ tests-internal += \ tst-tls3-malloc \ tst-tls5 \ # tests-internal -ifeq ($(have-z-execstack),yes) +ifeq ($(have-z-execstack)$(have-test-cc-trampoline),yesyes) tests += tst-execstack-threads endif endif @@ -483,7 +483,6 @@ modules-names = \ tst-audit-threads-mod1 \ tst-audit-threads-mod2 \ tst-compat-forwarder-mod \ - tst-execstack-threads-mod \ tst-stack4mod \ tst-tls3mod \ tst-tls5mod \ @@ -504,6 +503,12 @@ test-extras += \ tst-cleanupx4aux \ # test-extras +ifneq ($(have-test-clang),yes) +modules-names += \ + tst-execstack-threads-mod \ + # modules-names +endif + # This test exercises compat symbols removed in glibc 2.34. ifdef have-GLIBC_2.33 tests += tst-cleanup4