Thread (15 messages) 15 messages, 4 authors, 2025-01-06

Re: [PATCH v2 1/5] elf: Define note name macros

From: Baoquan He <hidden>
Date: 2025-01-06 06:06:59
Also in: kexec, linux-mm, linux-s390, lkml

On 01/06/25 at 02:07pm, Akihiko Odaki wrote:
On 2025/01/06 11:21, Baoquan He wrote:
quoted
On 01/04/25 at 11:38pm, Akihiko Odaki wrote:
quoted
elf.h had a comment saying:
quoted
Notes used in ET_CORE. Architectures export some of the arch register
sets using the corresponding note types via the PTRACE_GETREGSET and
PTRACE_SETREGSET requests.
The note name for these types is "LINUX", except NT_PRFPREG that is
named "CORE".
However, NT_PRSTATUS is also named "CORE". It is also unclear what
"these types" refers to.

To fix these problems, define a name for each note type. The added
definitions are macros so the kernel and userspace can directly refer to
them.

Signed-off-by: Akihiko Odaki <redacted>
---
  include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
  1 file changed, 83 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
index b44069d29cec..014b705b97d7 100644
--- a/include/uapi/linux/elf.h
+++ b/include/uapi/linux/elf.h
@@ -372,8 +372,6 @@ typedef struct elf64_shdr {
   * Notes used in ET_CORE. Architectures export some of the arch register sets
   * using the corresponding note types via the PTRACE_GETREGSET and
   * PTRACE_SETREGSET requests.
- * The note name for these types is "LINUX", except NT_PRFPREG that is named
- * "CORE".
   */
  #define NT_PRSTATUS	1
  #define NT_PRFPREG	2
@@ -460,9 +458,91 @@ typedef struct elf64_shdr {
  #define NT_LOONGARCH_HW_BREAK	0xa05   /* LoongArch hardware breakpoint registers */
  #define NT_LOONGARCH_HW_WATCH	0xa06   /* LoongArch hardware watchpoint registers */
-/* Note types with note name "GNU" */
+/* Note used in ET_EXEC and ET_DYN. */
  #define NT_GNU_PROPERTY_TYPE_0	5
+/* Note names */
+#define NN_PRSTATUS	"CORE"
+#define NN_PRFPREG	"CORE"
+#define NN_PRPSINFO	"CORE"
+#define NN_TASKSTRUCT	"CORE"
+#define NN_AUXV	"CORE"
+#define NN_SIGINFO	"CORE"
+#define NN_FILE	"CORE"
+#define NN_PRXFPREG	"LINUX"
No objection to make them clearer. Thanks for the effort.

Wondering where below arch specific macros are used. So you just
added all NN_xxx for the corresponding NT_xxx? Not sure if this is
needed if we don't use them at all in the current kernel.
Indeed I just added all NN_xxx. The kernel won't use the macros that are
defined as "LINUX"; fs/binfmt_elf.c uses "LINUX" by default as the notes
named "CORE" or "GNU" are exceptional.

Userspace applications may still be interested in these macros as
demonstrated in:
https://lore.kernel.org/r/Z3f7zJwu8bu8HYln@e133380.arm.com (local)

These macros also serve as documentation; correcting and clarifying the
documentation is the main purpose of this series.
I see, thanks. Then the overall series looks good to me.

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help