From 10771e02fad7904b0861e6864c9fdb6a6a3ce31c Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Wed, 24 Jul 2019 16:57:34 +0200 Subject: [PATCH] Treat PowerPC 64 LE as a separate architecture That seems to be the easiest way to properly handle the fact that PPC64LE does not have a meaningful m32 personality. * configure.ac: Move AC_C_BIGENDIAN before arch detection; determine powerpc64/powerpc64le arch based on $ac_cv_c_bigendian value. * linux/dummy.h [POWERPC64LE] (sys_oldselect): Redirect to printargs. * linux/powerpc64le/arch_defs_.h: New file. * linux/powerpc64le/arch_regs.c: Likewise. * linux/powerpc64le/arch_rt_sigframe.c: Likewise. * linux/powerpc64le/errnoent.h: Likewise. * linux/powerpc64le/get_error.c: Likewise. * linux/powerpc64le/get_scno.c: Likewise. * linux/powerpc64le/get_syscall_args.c: Likewise. * linux/powerpc64le/ioctls_arch0.h: Likewise. * linux/powerpc64le/ioctls_inc0.h: Likewise. * linux/powerpc64le/raw_syscall.h: Likewise. * linux/powerpc64le/rt_sigframe.h: Likewise. * linux/powerpc64le/set_error.c: Likewise. * linux/powerpc64le/set_scno.c: Likewise. * linux/powerpc64le/syscallent.h: Likewise. * linux/powerpc64le/userent.h: Likewise. * Makefile.am (EXTRA_DIST): Add them. * tests/ipc_msg.c: Check for POWERPC64LE definition in addition to POWERPC64. * util.c (getllval): Add check for POWERPC64LE definition in addition to POWERPC64. * strace.1.in (.SH MULTIPLE PERSONALITY SUPPORT): Mention that only big endian PowerPC 64 has mpers support. Co-Authored-by: Dmitry V. Levin --- Makefile.am | 15 +++++++++++++++ configure.ac | 18 +++++++++++++++--- linux/powerpc64le/arch_defs_.h | 9 +++++++++ linux/powerpc64le/arch_regs.c | 1 + linux/powerpc64le/arch_rt_sigframe.c | 12 ++++++++++++ linux/powerpc64le/errnoent.h | 1 + linux/powerpc64le/get_error.c | 1 + linux/powerpc64le/get_scno.c | 14 ++++++++++++++ linux/powerpc64le/get_syscall_args.c | 1 + linux/powerpc64le/ioctls_arch0.h | 1 + linux/powerpc64le/ioctls_inc0.h | 1 + linux/powerpc64le/raw_syscall.h | 1 + linux/powerpc64le/rt_sigframe.h | 1 + linux/powerpc64le/set_error.c | 1 + linux/powerpc64le/set_scno.c | 1 + linux/powerpc64le/syscallent.h | 1 + linux/powerpc64le/userent.h | 1 + strace.1.in | 2 +- tests/ipc_msg.c | 4 ++-- util.c | 4 ++-- 20 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 linux/powerpc64le/arch_defs_.h create mode 100644 linux/powerpc64le/arch_regs.c create mode 100644 linux/powerpc64le/arch_rt_sigframe.c create mode 100644 linux/powerpc64le/errnoent.h create mode 100644 linux/powerpc64le/get_error.c create mode 100644 linux/powerpc64le/get_scno.c create mode 100644 linux/powerpc64le/get_syscall_args.c create mode 100644 linux/powerpc64le/ioctls_arch0.h create mode 100644 linux/powerpc64le/ioctls_inc0.h create mode 100644 linux/powerpc64le/raw_syscall.h create mode 100644 linux/powerpc64le/rt_sigframe.h create mode 100644 linux/powerpc64le/set_error.c create mode 100644 linux/powerpc64le/set_scno.c create mode 100644 linux/powerpc64le/syscallent.h create mode 100644 linux/powerpc64le/userent.h diff --git a/Makefile.am b/Makefile.am index 0fa7f25d..25a81f2c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -720,6 +720,21 @@ EXTRA_DIST = \ linux/powerpc64/syscallent.h \ linux/powerpc64/syscallent1.h \ linux/powerpc64/userent.h \ + linux/powerpc64le/arch_defs_.h \ + linux/powerpc64le/arch_regs.c \ + linux/powerpc64le/arch_rt_sigframe.c \ + linux/powerpc64le/errnoent.h \ + linux/powerpc64le/get_error.c \ + linux/powerpc64le/get_scno.c \ + linux/powerpc64le/get_syscall_args.c \ + linux/powerpc64le/ioctls_arch0.h \ + linux/powerpc64le/ioctls_inc0.h \ + linux/powerpc64le/raw_syscall.h \ + linux/powerpc64le/rt_sigframe.h \ + linux/powerpc64le/set_error.c \ + linux/powerpc64le/set_scno.c \ + linux/powerpc64le/syscallent.h \ + linux/powerpc64le/userent.h \ linux/ptrace_pokeuser.c \ linux/raw_syscall.h \ linux/riscv/arch_defs_.h \ diff --git a/configure.ac b/configure.ac index 3394357b..0bd49b6b 100644 --- a/configure.ac +++ b/configure.ac @@ -48,6 +48,8 @@ AC_SUBST([COPYRIGHT_YEAR], [copyright_year]) AC_DEFINE([MANPAGE_DATE], "[manpage_date]", [Date]) AC_SUBST([MANPAGE_DATE], [manpage_date]) +AC_C_BIGENDIAN + AC_MSG_CHECKING([for supported architecture]) arch_m32= arch_mx32= @@ -126,8 +128,19 @@ powerpc*) # error 32 bit #endif], [], arch=powerpc64, arch=powerpc) if test "$arch" = "powerpc64"; then - arch_m32=powerpc - AC_DEFINE([POWERPC64], 1, [Define for the PowerPC64 architecture.]) + # $ac_cv_c_bigendian is defined by AC_C_BIGENDIAN + case "$ac_cv_c_bigendian" in + no) + arch=powerpc64le + AC_DEFINE([POWERPC64LE], 1, + [Define for the little endian PowerPC64 architecture.]) + ;; + *) + arch_m32=powerpc + AC_DEFINE([POWERPC64], 1, + [Define for the big endian PowerPC64 architecture.]) + ;; + esac fi ;; riscv*) @@ -243,7 +256,6 @@ esac AC_DEFINE_UNQUOTED([ENABLE_ARM_OABI], [$enable_arm_oabi], [Define to 1 if you want OABI support on ARM EABI.]) -AC_C_BIGENDIAN AC_C_TYPEOF AC_TYPE_UID_T diff --git a/linux/powerpc64le/arch_defs_.h b/linux/powerpc64le/arch_defs_.h new file mode 100644 index 00000000..494672a0 --- /dev/null +++ b/linux/powerpc64le/arch_defs_.h @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2019 The strace developers. + * All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#define HAVE_ARCH_OLD_SELECT 1 +#define HAVE_ARCH_DEDICATED_ERR_REG 1 diff --git a/linux/powerpc64le/arch_regs.c b/linux/powerpc64le/arch_regs.c new file mode 100644 index 00000000..8c4a45d6 --- /dev/null +++ b/linux/powerpc64le/arch_regs.c @@ -0,0 +1 @@ +#include "../powerpc/arch_regs.c" diff --git a/linux/powerpc64le/arch_rt_sigframe.c b/linux/powerpc64le/arch_rt_sigframe.c new file mode 100644 index 00000000..d5d12676 --- /dev/null +++ b/linux/powerpc64le/arch_rt_sigframe.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2017-2018 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +FUNC_GET_RT_SIGFRAME_ADDR +{ + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) ? sp : 0; +} diff --git a/linux/powerpc64le/errnoent.h b/linux/powerpc64le/errnoent.h new file mode 100644 index 00000000..945ce853 --- /dev/null +++ b/linux/powerpc64le/errnoent.h @@ -0,0 +1 @@ +#include "../powerpc64/errnoent.h" diff --git a/linux/powerpc64le/get_error.c b/linux/powerpc64le/get_error.c new file mode 100644 index 00000000..c7fc341d --- /dev/null +++ b/linux/powerpc64le/get_error.c @@ -0,0 +1 @@ +#include "../powerpc64/get_error.c" diff --git a/linux/powerpc64le/get_scno.c b/linux/powerpc64le/get_scno.c new file mode 100644 index 00000000..6624614a --- /dev/null +++ b/linux/powerpc64le/get_scno.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2015-2018 The strace developers. + * All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +/* Return codes: 1 - ok, 0 - ignore, other - error. */ +static int +arch_get_scno(struct tcb *tcp) +{ + tcp->scno = ppc_regs.gpr[0]; + return 1; +} diff --git a/linux/powerpc64le/get_syscall_args.c b/linux/powerpc64le/get_syscall_args.c new file mode 100644 index 00000000..281eb606 --- /dev/null +++ b/linux/powerpc64le/get_syscall_args.c @@ -0,0 +1 @@ +#include "../powerpc64/get_syscall_args.c" diff --git a/linux/powerpc64le/ioctls_arch0.h b/linux/powerpc64le/ioctls_arch0.h new file mode 100644 index 00000000..14d0c0b1 --- /dev/null +++ b/linux/powerpc64le/ioctls_arch0.h @@ -0,0 +1 @@ +#include "../powerpc64/ioctls_arch0.h" diff --git a/linux/powerpc64le/ioctls_inc0.h b/linux/powerpc64le/ioctls_inc0.h new file mode 100644 index 00000000..a89fa3c0 --- /dev/null +++ b/linux/powerpc64le/ioctls_inc0.h @@ -0,0 +1 @@ +#include "../powerpc64/ioctls_inc0.h" diff --git a/linux/powerpc64le/raw_syscall.h b/linux/powerpc64le/raw_syscall.h new file mode 100644 index 00000000..f1800fc5 --- /dev/null +++ b/linux/powerpc64le/raw_syscall.h @@ -0,0 +1 @@ +#include "../powerpc64/raw_syscall.h" diff --git a/linux/powerpc64le/rt_sigframe.h b/linux/powerpc64le/rt_sigframe.h new file mode 100644 index 00000000..cd8902f4 --- /dev/null +++ b/linux/powerpc64le/rt_sigframe.h @@ -0,0 +1 @@ +#include "../powerpc64/rt_sigframe.h" diff --git a/linux/powerpc64le/set_error.c b/linux/powerpc64le/set_error.c new file mode 100644 index 00000000..207ffe9a --- /dev/null +++ b/linux/powerpc64le/set_error.c @@ -0,0 +1 @@ +#include "../powerpc64/set_error.c" diff --git a/linux/powerpc64le/set_scno.c b/linux/powerpc64le/set_scno.c new file mode 100644 index 00000000..d3f6479a --- /dev/null +++ b/linux/powerpc64le/set_scno.c @@ -0,0 +1 @@ +#include "../powerpc64/set_scno.c" diff --git a/linux/powerpc64le/syscallent.h b/linux/powerpc64le/syscallent.h new file mode 100644 index 00000000..785a81b0 --- /dev/null +++ b/linux/powerpc64le/syscallent.h @@ -0,0 +1 @@ +#include "../powerpc64/syscallent.h" diff --git a/linux/powerpc64le/userent.h b/linux/powerpc64le/userent.h new file mode 100644 index 00000000..1f711811 --- /dev/null +++ b/linux/powerpc64le/userent.h @@ -0,0 +1 @@ +#include "../powerpc64/userent.h" diff --git a/strace.1.in b/strace.1.in index 56728371..4100427e 100644 --- a/strace.1.in +++ b/strace.1.in @@ -1039,7 +1039,7 @@ l l. Architecture ABIs supported x86_64 i386, x32 (when built as an x86_64 application); i386 (when built as an x32 application) AArch64 ARM 32-bit EABI -PowerPC 64-bit PowerPC 32-bit +PowerPC 64-bit BE PowerPC 32-bit RISC-V 64-bit RISC-V 32-bit s390x s390 SPARC 64-bit SPARC 32-bit diff --git a/tests/ipc_msg.c b/tests/ipc_msg.c index b12f4af3..2290d818 100644 --- a/tests/ipc_msg.c +++ b/tests/ipc_msg.c @@ -26,12 +26,12 @@ * which led to segmentation fault. */ #undef TEST_MSGCTL_BOGUS_ADDR -#if defined __GLIBC__ && defined POWERPC64 +#if defined __GLIBC__ && (defined POWERPC64 || defined POWERPC64LE) # if !(defined __GLIBC_MINOR__) \ || ((__GLIBC__ << 16) + __GLIBC_MINOR__ < (2 << 16) + 23) # define TEST_MSGCTL_BOGUS_ADDR 0 # endif -#endif /* __GLIBC__ && POWERPC64 */ +#endif /* __GLIBC__ && (POWERPC64 || POWERPC64LE) */ #ifndef TEST_MSGCTL_BOGUS_ADDR # define TEST_MSGCTL_BOGUS_ADDR 1 diff --git a/util.c b/util.c index 2349ec15..814f78c4 100644 --- a/util.c +++ b/util.c @@ -159,10 +159,10 @@ getllval(struct tcb *tcp, unsigned long long *val, int arg_no) #if SIZEOF_KERNEL_LONG_T > 4 # ifndef current_klongsize if (current_klongsize < SIZEOF_KERNEL_LONG_T) { -# if defined(AARCH64) || defined(POWERPC64) +# if defined(AARCH64) || defined(POWERPC64) || defined(POWERPC64LE) /* Align arg_no to the next even number. */ arg_no = (arg_no + 1) & 0xe; -# endif /* AARCH64 || POWERPC64 */ +# endif /* AARCH64 || POWERPC64 || POWERPC64LE */ *val = ULONG_LONG(tcp->u_arg[arg_no], tcp->u_arg[arg_no + 1]); arg_no += 2; } else -- 2.40.0