From 568a1f74913d7524650015297648f51f85bc2809 Mon Sep 17 00:00:00 2001 From: Andre McCurdy Date: Wed, 16 May 2018 18:03:53 -0700 Subject: strace: fix ARM Thumb build with frame pointers enabled Replace the previous (incomplete) workaround with better solution backported from upstream. (From OE-Core rev: b038a6e418d723a0a413219e9882cdd7f3804625) Signed-off-by: Andre McCurdy Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- ...aw_syscall.h-avoid-r7-specified-register-.patch | 74 ++++++++++++++++++++++ meta/recipes-devtools/strace/strace_4.22.bb | 16 ++--- 2 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 meta/recipes-devtools/strace/strace/0001-linux-arm-raw_syscall.h-avoid-r7-specified-register-.patch (limited to 'meta/recipes-devtools/strace') diff --git a/meta/recipes-devtools/strace/strace/0001-linux-arm-raw_syscall.h-avoid-r7-specified-register-.patch b/meta/recipes-devtools/strace/strace/0001-linux-arm-raw_syscall.h-avoid-r7-specified-register-.patch new file mode 100644 index 0000000000..8584291ba8 --- /dev/null +++ b/meta/recipes-devtools/strace/strace/0001-linux-arm-raw_syscall.h-avoid-r7-specified-register-.patch @@ -0,0 +1,74 @@ +From 0c75ebaad09d6d3f2395dfe6160904af883dd0d9 Mon Sep 17 00:00:00 2001 +From: Andre McCurdy +Date: Tue, 15 May 2018 15:34:39 -0700 +Subject: [PATCH] linux/arm/raw_syscall.h: avoid r7 specified register + variables with Thumb + +If Thumb code is being generated and frame pointers are enabled, the +Thumb frame pointer in r7 clashes with any local variable which may +need to be assigned to r7 (e.g. the syscall NR when making a raw +syscall). + +With gcc, the double use of r7 results in a build error, e.g. + + strace-4.22/tests/inject-nf.c:86:1: error: r7 cannot be used in asm here + +With clang, the double use of r7 can result in the compiler silently +generating broken code which crashes at run time due to frame pointer +corruption: + + https://bugs.llvm.org/show_bug.cgi?id=34165 + +In most cases the problem isn't visible as frame pointers will be +disabled automatically due to optimisation level. However to handle +cases where frame pointers are enabled (e.g. when CFLAGS etc are set +to support a debug build, etc) provide a version of raw_syscall_0 +which manually saves and restores the frame pointer value in r7 +to a temporary register before setting up the syscall NR in r7 +and invoking the syscall. + +* linux/arm/raw_syscall.h (raw_syscall_0) [__thumb__]: Provide +an alternative version. + +Upstream-Status: Backport + +Signed-off-by: Andre McCurdy +--- + linux/arm/raw_syscall.h | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/linux/arm/raw_syscall.h b/linux/arm/raw_syscall.h +index 69c7e23..ec534ec 100644 +--- a/linux/arm/raw_syscall.h ++++ b/linux/arm/raw_syscall.h +@@ -36,12 +36,27 @@ static inline kernel_ulong_t + raw_syscall_0(const kernel_ulong_t nr, kernel_ulong_t *err) + { + *err = 0; ++ ++#ifdef __thumb__ /* && FRAME_POINTERS_ENABLED */ ++ ++ register kernel_ulong_t rt; ++ register kernel_ulong_t r0 __asm__("r0"); ++ __asm__ __volatile__("mov %1,r7; mov r7,%2; swi 0x0; mov r7,%1" ++ : "=r"(r0), "=&r"(rt) ++ : "r"(nr) ++ : "memory"); ++ ++#else ++ + register kernel_ulong_t r7 __asm__("r7") = nr; + register kernel_ulong_t r0 __asm__("r0"); + __asm__ __volatile__("swi 0x0" + : "=r"(r0) + : "r"(r7) + : "memory"); ++ ++#endif ++ + return r0; + } + # define raw_syscall_0 raw_syscall_0 +-- +1.9.1 + diff --git a/meta/recipes-devtools/strace/strace_4.22.bb b/meta/recipes-devtools/strace/strace_4.22.bb index 947b3f7bf6..99691f87c3 100644 --- a/meta/recipes-devtools/strace/strace_4.22.bb +++ b/meta/recipes-devtools/strace/strace_4.22.bb @@ -14,21 +14,13 @@ SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \ file://mips-SIGEMT.patch \ file://0001-caps-abbrev.awk-fix-gawk-s-path.patch \ file://0001-tests-sigaction-Check-for-mips-and-alpha-before-usin.patch \ + file://0001-linux-arm-raw_syscall.h-avoid-r7-specified-register-.patch \ " SRC_URI[md5sum] = "7a2a7d7715da6e6834bc65bd09bace1c" SRC_URI[sha256sum] = "068cd09264c95e4d591bbcd3ea08f99a693ed8663cd5169b0fdad72eb5bdb39d" inherit autotools ptest bluetooth -EXTRA_OECONF += "--enable-mpers=no" - -CFLAGS_append_libc-musl = " -Dsigcontext_struct=sigcontext" -# otherwise strace-4.22/tests/inject-nf.c fails to build as discussed here: -# http://lists.openembedded.org/pipermail/openembedded-core/2018-May/150647.html -DEBUG_OPTIMIZATION_remove = "${@bb.utils.contains('PTEST_ENABLED', '1', '-fno-omit-frame-pointer', '', d)}" - -RDEPENDS_${PN}-ptest += "make coreutils grep gawk sed" - PACKAGECONFIG_class-target ??= "\ ${@bb.utils.contains('DISTRO_FEATURES', 'bluetooth', 'bluez', '', d)} \ " @@ -36,6 +28,10 @@ PACKAGECONFIG_class-target ??= "\ PACKAGECONFIG[bluez] = "ac_cv_header_bluetooth_bluetooth_h=yes,ac_cv_header_bluetooth_bluetooth_h=no,${BLUEZ}" PACKAGECONFIG[libunwind] = "--with-libunwind,--without-libunwind,libunwind" +EXTRA_OECONF += "--enable-mpers=no" + +CFLAGS_append_libc-musl = " -Dsigcontext_struct=sigcontext" + TESTDIR = "tests" do_install_append() { @@ -61,5 +57,7 @@ do_install_ptest() { ${D}/${PTEST_PATH}/${TESTDIR}/Makefile } +RDEPENDS_${PN}-ptest += "make coreutils grep gawk sed" + BBCLASSEXTEND = "native" TOOLCHAIN = "gcc" -- cgit v1.2.3-54-g00ecf