[PATCH 5/8] perf libunwind: Feature check for libunwind ptrauth callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <andrew.kilroy@xxxxxxx>
---
 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 <libunwind.h>
+
+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
-- 
2.17.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux