0003-define-user_pac_mask-if-needed.patch 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From 52a747a316042e70a22acb489df9e51bfc6bf2d5 Mon Sep 17 00:00:00 2001
  2. From: Markus Mayer <mmayer@broadcom.com>
  3. Date: Fri, 21 Feb 2025 11:19:34 -0800
  4. Subject: [PATCH] aarch64: define struct user_pac_mask if needed
  5. On Aarch64, Linux is using Pointer Authentication Code (PAC) for pointer
  6. authentication.[1] The struct "user_pac_mask" has been part of the Linux
  7. kernel since version 5.0 as part of this feature. However, older kernels
  8. do not define it.
  9. Therefore, we want to check if the definition is present in the kernel
  10. headers and provide one if it isn't. This ensures two things:
  11. * elfutils will continue to compile against kernel headers from 4.x
  12. * binaries built against older kernel headers will still be fully
  13. functional if used on a newer system
  14. For reference, the build error that is being avoided looks like this:
  15. [...]
  16. CC aarch64_initreg.o
  17. aarch64_initreg.c: In function 'aarch64_set_initial_registers_tid':
  18. aarch64_initreg.c:61:24: error: storage size of 'pac_mask' isn't known
  19. struct user_pac_mask pac_mask;
  20. ^~~~~~~~
  21. aarch64_initreg.c:61:24: warning: unused variable 'pac_mask' [-Wunused-variable]
  22. make[4]: *** [Makefile:831: aarch64_initreg.o] Error 1
  23. make[3]: *** [Makefile:547: all-recursive] Error 1
  24. make[2]: *** [Makefile:463: all] Error 2
  25. [1] https://docs.kernel.org/arch/arm64/pointer-authentication.html
  26. https://sourceware.org/bugzilla/show_bug.cgi?id=32684
  27. Fixes: 64e3b451ad2c ("aarch64: extend dwfl_thread_state_registers to handle PAC")
  28. Signed-off-by: Markus Mayer <mmayer@broadcom.com>
  29. Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
  30. Upstream: https://sourceware.org/git/?p=elfutils.git;a=commit;h=52a747a316042e70a22acb489df9e51bfc6bf2d5
  31. ---
  32. backends/aarch64_initreg.c | 21 +++++++++++++++++++++
  33. configure.ac | 8 ++++++++
  34. 2 files changed, 29 insertions(+)
  35. diff --git a/backends/aarch64_initreg.c b/backends/aarch64_initreg.c
  36. index 5ec45ea60..a6badbb45 100644
  37. --- a/backends/aarch64_initreg.c
  38. +++ b/backends/aarch64_initreg.c
  39. @@ -47,6 +47,27 @@
  40. #define BACKEND aarch64_
  41. #include "libebl_CPU.h"
  42. +/*
  43. + * pointer authentication masks (NT_ARM_PAC_MASK)
  44. + *
  45. + * Defined by Linux kernel headers since Linux 5.0. Define it here if kernel
  46. + * headers are older than that, to ensure this file builds regardless.
  47. + */
  48. +#if defined(__aarch64__) && defined(__linux__)
  49. +
  50. +#ifndef NT_ARM_PAC_MASK
  51. +#define NT_ARM_PAC_MASK 0x406
  52. +#endif
  53. +
  54. +#ifndef HAVE_USER_PACK_MASK
  55. +struct user_pac_mask {
  56. + __u64 data_mask;
  57. + __u64 insn_mask;
  58. +};
  59. +#endif
  60. +
  61. +#endif /* __aarch64__ && __linux__ */
  62. +
  63. bool
  64. aarch64_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
  65. ebl_tid_registers_t *setfunc __attribute__ ((unused)),
  66. diff --git a/configure.ac b/configure.ac
  67. index e57d39275..3298f7fc7 100644
  68. --- a/configure.ac
  69. +++ b/configure.ac
  70. @@ -777,6 +777,14 @@ if test "$sys_user_has_user_regs" = "yes"; then
  71. [Define to 1 if <sys/user.h> defines struct user_regs_struct])
  72. fi
  73. +AC_CHECK_TYPE([struct user_pac_mask],
  74. + [has_user_pac_mask=yes], [has_user_pac_mask=no],
  75. + [[#include <asm/ptrace.h>]])
  76. +if test "$has_user_pac_mask" = "yes"; then
  77. + AC_DEFINE(HAVE_USER_PACK_MASK, 1,
  78. + [Defined if struct user_pac_mask exists.])
  79. +fi
  80. +
  81. # On a 64-bit host where can can use $CC -m32, we'll run two sets of tests.
  82. utrace_BIARCH
  83. CC_BIARCH="$CC $utrace_biarch"
  84. --
  85. 2.43.5