From patchwork Mon Jul 4 14:53:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Kilroy X-Patchwork-Id: 12905462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13167C43334 for ; Mon, 4 Jul 2022 14:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SoZWZ8g9ZNL/i6ZVJ7GXsJiG3/5g0I0QcIjcQWUWBRA=; b=FyB19Vy25Ki1Al MFtKes7pNBMh8Smb/SrXEtJmyXdVB2moLhgtuW6UVer5xnSBRAZ1LzSAzAIPHwLP/TDh0qU0l26oW IF/WHJidiHhZ+lMkyHqkmfaXua2eGlIvVvy4Jde0RUDR2wVGoO0hAJ+O8ySrLUFWGV+JJl+Bnb4j7 RIWSO6yaEF+JPVKcztZblB5s1lyKiQE4+NOqiX+IuyHJhcvRZt/S4Jo12uGDNP4jGgkahG7My5GJ6 caEefIs9ZKu9OiQgCZ+4YnuOLFnQkYNyVuZokgPl0IHGNEecJOD2n1QZePej3lUKJVM5/zChy18Xn 2KyG3Ud/Ov47rR4Z6dRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8NUY-009XiW-JC; Mon, 04 Jul 2022 14:56:02 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8NUU-009Xgq-LQ for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 14:56:00 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 99143150C; Mon, 4 Jul 2022 07:55:57 -0700 (PDT) Received: from e124483.cambridge.arm.com (e124483.cambridge.arm.com [10.1.29.145]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2F8D63F792; Mon, 4 Jul 2022 07:55:53 -0700 (PDT) From: Andrew Kilroy To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org Cc: Andrew Kilroy , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Tom Rix , linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 5/8] perf libunwind: Feature check for libunwind ptrauth callback Date: Mon, 4 Jul 2022 15:53:29 +0100 Message-Id: <20220704145333.22557-6-andrew.kilroy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704145333.22557-1-andrew.kilroy@arm.com> References: <20220704145333.22557-1-andrew.kilroy@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_075558_900332_B3FEB056 X-CRM114-Status: GOOD ( 16.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch prepares for a version of libunwind that is capable of unwinding stacks with pointer authentication. Without this change, anyone compiling perf would have to depend on a very new version of libunwind that has the callback to supply it with pointer authentication masks. This patch detects if libunwind is recent enough, and if so, sets a pre-processor flag that will be used in a subsequent commit to call libunwind appropriately. If libunwind is not recent enough, the pre-processor flag is not set. Signed-off-by: Andrew Kilroy --- tools/build/Makefile.feature | 2 ++ tools/build/feature/Makefile | 4 +++ tools/build/feature/test-all.c | 5 ++++ .../feature/test-libunwind-arm64-ptrauth.c | 26 +++++++++++++++++++ tools/perf/Makefile.config | 10 +++++++ 5 files changed, 47 insertions(+) create mode 100644 tools/build/feature/test-libunwind-arm64-ptrauth.c diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 888a0421d43b..a894101342fc 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -90,6 +90,7 @@ FEATURE_TESTS_EXTRA := \ libunwind-x86_64 \ libunwind-arm \ libunwind-aarch64 \ + libunwind-arm64-ptrauth \ libunwind-debug-frame \ libunwind-debug-frame-arm \ libunwind-debug-frame-aarch64 \ @@ -128,6 +129,7 @@ FEATURE_DISPLAY ?= \ libpython \ libcrypto \ libunwind \ + libunwind-arm64-ptrauth\ libdw-dwarf-unwind \ zlib \ lzma \ diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 7c2a17e23c30..ac23175d5bcb 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -45,6 +45,7 @@ FILES= \ test-libunwind-aarch64.bin \ test-libunwind-debug-frame-arm.bin \ test-libunwind-debug-frame-aarch64.bin \ + test-libunwind-arm64-ptrauth.bin \ test-pthread-attr-setaffinity-np.bin \ test-pthread-barrier.bin \ test-stackprotector-all.bin \ @@ -193,6 +194,9 @@ $(OUTPUT)test-libunwind-debug-frame-arm.bin: $(OUTPUT)test-libunwind-debug-frame-aarch64.bin: $(BUILD) -lelf -lunwind-aarch64 +$(OUTPUT)test-libunwind-arm64-ptrauth.bin: + $(BUILD) # -lunwind provided by $(FEATURE_CHECK_LDFLAGS-libunwind-arm64-ptrauth) + $(OUTPUT)test-libaudit.bin: $(BUILD) -laudit diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 5ffafb967b6e..86780c5c78e5 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -66,6 +66,10 @@ # include "test-libunwind.c" #undef main +#define main main_test_libunwind_arm64_ptrauth +# include "test-libunwind-arm64-ptrauth.c" +#undef main + #define main main_test_libslang # include "test-libslang.c" #undef main @@ -186,6 +190,7 @@ int main(int argc, char *argv[]) main_test_libelf_gelf_getnote(); main_test_libelf_getshdrstrndx(); main_test_libunwind(); + main_test_libunwind_arm64_ptrauth(); main_test_libslang(); main_test_libbfd(); main_test_libbfd_buildid(); diff --git a/tools/build/feature/test-libunwind-arm64-ptrauth.c b/tools/build/feature/test-libunwind-arm64-ptrauth.c new file mode 100644 index 000000000000..51650ceef90e --- /dev/null +++ b/tools/build/feature/test-libunwind-arm64-ptrauth.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +static unw_word_t get_insn_mask(unw_addr_space_t addr_space, void *unwind_info_ptr) +{ + return 0; +} + +// This feature test is intending to check if the version +// of the available libunwind library is one that has the +// ptrauth_insn_mask callback function. +// If it doesn't this feature check should fail to compile. +static unw_accessors_t accessors = { + .ptrauth_insn_mask = get_insn_mask, +}; + +int main(void) +{ + unw_addr_space_t addr_space = unw_create_addr_space(&accessors, 0); + + if (addr_space) + return 0; + + return 0; +} diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 73e0762092fe..2578b1d1a502 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -133,6 +133,8 @@ FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS) FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS) FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) +FEATURE_CHECK_CFLAGS-libunwind-arm64-ptrauth = $(LIBUNWIND_CFLAGS) +FEATURE_CHECK_LDFLAGS-libunwind-arm64-ptrauth = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64 @@ -677,6 +679,14 @@ ifndef NO_LIBUNWIND $(call detected,CONFIG_LOCAL_LIBUNWIND) endif + ifeq ($(have_libunwind), 1) + $(call feature_check,libunwind-arm64-ptrauth) + ifneq ($(feature-libunwind-arm64-ptrauth),1) + CFLAGS += -DNO_LIBUNWIND_ARM64_PTRAUTH + msg := $(warning libunwind cannot produce user stacks in the presence of pointer authentication.); + endif + endif + ifneq ($(have_libunwind), 1) NO_LIBUNWIND := 1 endif