diff mbox series

Add more ptrace constants for AArch64 and PowerPC

Message ID alpine.DEB.2.22.394.2102082217240.2739371@digraph.polyomino.org.uk
State New
Headers show
Series Add more ptrace constants for AArch64 and PowerPC | expand

Commit Message

Joseph Myers Feb. 8, 2021, 10:18 p.m. UTC
Linux 5.10 adds PTRACE_PEEKMTETAGS and PTRACE_POKEMTETAGS for AArch64.
Adding those shows up that glibc is also missing PTRACE_SYSEMU and
PTRACE_SYSEMU_SINGLESTEP, for AArch64 (where they were added to Linux
in 5.3) and for PowerPC (where they were added in Linux 4.20); it
already has those two defines for x86.  Add all those defines to
glibc's headers.

Tested with build-many-glibcs.py for aarch64-linux-gnu and
powerpc-linux-gnu.

Comments

Dmitry V. Levin Feb. 8, 2021, 10:42 p.m. UTC | #1
On Mon, Feb 08, 2021 at 10:18:41PM +0000, Joseph Myers wrote:
> Linux 5.10 adds PTRACE_PEEKMTETAGS and PTRACE_POKEMTETAGS for AArch64.
> Adding those shows up that glibc is also missing PTRACE_SYSEMU and
> PTRACE_SYSEMU_SINGLESTEP, for AArch64 (where they were added to Linux
> in 5.3) and for PowerPC (where they were added in Linux 4.20); it
> already has those two defines for x86.  Add all those defines to
> glibc's headers.

LGTM, thanks.

Just for the record, PTRACE_PEEKMTETAGS and PTRACE_POKEMTETAGS were
introduced by Linux kernel commit v5.10-rc1~49^2~9^2~8.
Vaseeharan Vinayagamoorthy Feb. 12, 2021, 12:50 p.m. UTC | #2
After this patch, the following errors are seen when building gdbserver:

In file included from …/install/aarch64-none-linux-gnu/libc/usr/include/sys/ptrace.h:86:3: error: expected identifier before numeric constant
   86 |   PTRACE_SYSEMU = 31,
      |   ^~~~~~~~~~~~~
…/install/aarch64-none-linux-gnu/libc/usr/include/sys/ptrace.h:86:3: error: expected ‘}’ before numeric constant

In file included from …/src/binutils-gdb--gdb/gdbserver/../gdb/nat/aarch64-linux-hw-point.c:27:
…/install/aarch64-none-linux-gnu/libc/usr/include/sys/ptrace.h:30:1: note: to match this ‘{’
   30 | {
      | ^
In file included from …/src/binutils-gdb--gdb/gdbserver/../gdb/nat/aarch64-linux-hw-point.c:26:
…/install/aarch64-none-linux-gnu/libc/usr/include/sys/ptrace.h:86:3: error: expected unqualified-id before numeric constant
   86 |   PTRACE_SYSEMU = 31,
      |   ^~~~~~~~~~~~~

In file included from …/src/binutils-gdb--gdb/gdbserver/../gdb/nat/aarch64-linux-hw-point.c:27:
…/src/binutils-gdb--gdb/gdbserver/../gdb/nat/aarch64-linux-hw-point.c: In function ‘void aarch64_linux_set_debug_regs(aarch64_debug_reg_state*, int, int)’:
…/src/binutils-gdb--gdb/gdbserver/../gdb/nat/aarch64-linux-hw-point.c:694:15: error: ‘PTRACE_SETREGSET’ was not declared in this scope
  694 |   if (ptrace (PTRACE_SETREGSET, tid,
      |               ^~~~~~~~~~~~~~~~

My build/host/target setup is:
Build: x86_64 (CentOS Linux 7)
Host: x86_64 (CentOS Linux 7)
Target: aarch64-none-linux-gnu / aarch64_be-none-linux-gnu


Kind regards
Vasee

On 08/02/2021, 22:19, "Libc-alpha on behalf of Joseph Myers" <libc-alpha-bounces@sourceware.org on behalf of joseph@codesourcery.com> wrote:

    Linux 5.10 adds PTRACE_PEEKMTETAGS and PTRACE_POKEMTETAGS for AArch64.
    Adding those shows up that glibc is also missing PTRACE_SYSEMU and
    PTRACE_SYSEMU_SINGLESTEP, for AArch64 (where they were added to Linux
    in 5.3) and for PowerPC (where they were added in Linux 4.20); it
    already has those two defines for x86.  Add all those defines to
    glibc's headers.

    Tested with build-many-glibcs.py for aarch64-linux-gnu and
    powerpc-linux-gnu.

    diff --git a/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h b/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
    index 806178af0e..de26da0023 100644
    --- a/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
    +++ b/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
    @@ -82,6 +82,22 @@ enum __ptrace_request
       PTRACE_SYSCALL = 24,
     #define PT_SYSCALL PTRACE_SYSCALL

    +  /* Continue and stop at the next syscall, it will not be executed.  */
    +  PTRACE_SYSEMU = 31,
    +#define PT_SYSEMU PTRACE_SYSEMU
    +
    +  /* Single step the process, the next syscall will not be executed.  */
    +  PTRACE_SYSEMU_SINGLESTEP = 32,
    +#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP
    +
    +  /* Read MTE tags.  */
    +  PTRACE_PEEKMTETAGS = 33,
    +#define PT_PEEKMTETAGS PTRACE_PEEKMTETAGS
    +
    +  /* Write MTE tags.  */
    +  PTRACE_POKEMTETAGS = 34,
    +#define PT_POKEMTETAGS PTRACE_POKEMTETAGS
    +
       /* Set ptrace filter options.  */
       PTRACE_SETOPTIONS = 0x4200,
     #define PT_SETOPTIONS PTRACE_SETOPTIONS
    diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h b/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
    index 00730cf5d3..032c91e817 100644
    --- a/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
    +++ b/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
    @@ -70,6 +70,8 @@ __BEGIN_DECLS
     # undef PTRACE_SYSCALL_INFO_ENTRY
     # undef PTRACE_SYSCALL_INFO_EXIT
     # undef PTRACE_SYSCALL_INFO_SECCOMP
    +# undef PTRACE_SYSEMU
    +# undef PTRACE_SYSEMU_SINGLESTEP
     # undef PTRACE_TRACEME
     #endif

    @@ -188,6 +190,14 @@ enum __ptrace_request
       PTRACE_SETVSRREGS = 28,
     #define PT_SETVSRREGS PTRACE_SETVSRREGS

    +  /* Continue and stop at the next syscall, it will not be executed.  */
    +  PTRACE_SYSEMU = 29,
    +#define PT_SYSEMU PTRACE_SYSEMU
    +
    +  /* Single step the process, the next syscall will not be executed.  */
    +  PTRACE_SYSEMU_SINGLESTEP = 30,
    +#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP
    +
       /* Execute process until next taken branch.  */
       PTRACE_SINGLEBLOCK = 256,
     #define PT_STEPBLOCK PTRACE_SINGLEBLOCK

    -- 
    Joseph S. Myers
    joseph@codesourcery.com
Joseph Myers Feb. 12, 2021, 7:25 p.m. UTC | #3
On Fri, 12 Feb 2021, Vaseeharan Vinayagamoorthy via Libc-alpha wrote:

> After this patch, the following errors are seen when building gdbserver:
> 
> In file included from …/install/aarch64-none-linux-gnu/libc/usr/include/sys/ptrace.h:86:3: error: expected identifier before numeric constant
>    86 |   PTRACE_SYSEMU = 31,
>       |   ^~~~~~~~~~~~~

That looks like the kernel and glibc ptrace headers have been included 
together, something that may not work because they define the same 
constants.  We could make the AArch64 header in glibc undefine a series of 
macros like the powerpc one does, to allow some cases of this to work.
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h b/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
index 806178af0e..de26da0023 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
@@ -82,6 +82,22 @@  enum __ptrace_request
   PTRACE_SYSCALL = 24,
 #define PT_SYSCALL PTRACE_SYSCALL
 
+  /* Continue and stop at the next syscall, it will not be executed.  */
+  PTRACE_SYSEMU = 31,
+#define PT_SYSEMU PTRACE_SYSEMU
+
+  /* Single step the process, the next syscall will not be executed.  */
+  PTRACE_SYSEMU_SINGLESTEP = 32,
+#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP
+
+  /* Read MTE tags.  */
+  PTRACE_PEEKMTETAGS = 33,
+#define PT_PEEKMTETAGS PTRACE_PEEKMTETAGS
+
+  /* Write MTE tags.  */
+  PTRACE_POKEMTETAGS = 34,
+#define PT_POKEMTETAGS PTRACE_POKEMTETAGS
+
   /* Set ptrace filter options.  */
   PTRACE_SETOPTIONS = 0x4200,
 #define PT_SETOPTIONS PTRACE_SETOPTIONS
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h b/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
index 00730cf5d3..032c91e817 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
@@ -70,6 +70,8 @@  __BEGIN_DECLS
 # undef PTRACE_SYSCALL_INFO_ENTRY
 # undef PTRACE_SYSCALL_INFO_EXIT
 # undef PTRACE_SYSCALL_INFO_SECCOMP
+# undef PTRACE_SYSEMU
+# undef PTRACE_SYSEMU_SINGLESTEP
 # undef PTRACE_TRACEME
 #endif
 
@@ -188,6 +190,14 @@  enum __ptrace_request
   PTRACE_SETVSRREGS = 28,
 #define PT_SETVSRREGS PTRACE_SETVSRREGS
 
+  /* Continue and stop at the next syscall, it will not be executed.  */
+  PTRACE_SYSEMU = 29,
+#define PT_SYSEMU PTRACE_SYSEMU
+
+  /* Single step the process, the next syscall will not be executed.  */
+  PTRACE_SYSEMU_SINGLESTEP = 30,
+#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP
+
   /* Execute process until next taken branch.  */
   PTRACE_SINGLEBLOCK = 256,
 #define PT_STEPBLOCK PTRACE_SINGLEBLOCK