From 0ceb56b609b17a7e3202aaf98361be90fb40955e Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 9 Aug 2016 22:25:09 +0100 Subject: [PATCH] Add strace to the stage3 chroot. --- .gitignore | 1 + ...-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch | 59 ++++++++++++++++++++++ Makefile | 22 ++++++++ 3 files changed, 82 insertions(+) create mode 100644 0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch diff --git a/.gitignore b/.gitignore index a4f9e2e..07a58de 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ stamp-* /popt-1.16/ /riscv-binutils-gdb-riscv-binutils-2.26/ /riscv-gcc-riscv-gcc-6.1.0/ +/riscv-strace-f320e1897832fd07a62e18ed288e75d8e79f4c5b/ /rpm-9571218/ /tar-1.29/ /util-linux-2.28/ diff --git a/0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch b/0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch new file mode 100644 index 0000000..6a8a671 --- /dev/null +++ b/0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch @@ -0,0 +1,59 @@ +From a0532c147d0f725bb4dd84616243ce014426eaa0 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 9 Aug 2016 22:14:43 +0100 +Subject: [PATCH] Update riscv_regs for ptrace.h from Linux 4.1.x. + +--- + syscall.c | 20 ++++++++++---------- + 1 file changed, 10 insertions(+), 10 deletions(-) + +diff --git a/syscall.c b/syscall.c +index 0b7ba64..88ed9ba 100644 +--- a/syscall.c ++++ b/syscall.c +@@ -1571,7 +1571,7 @@ get_scno(struct tcb *tcp) + # elif defined(ARC) + scno = arc_regs.scratch.r8; + #elif defined(RISCV) +- scno = riscv_regs.a7; ++ scno = riscv_regs.a[7]; + #endif + + tcp->scno = scno; +@@ -1967,12 +1967,12 @@ get_syscall_args(struct tcb *tcp) + tcp->u_arg[i] = *arc_args--; + + #elif defined(RISCV) +- tcp->u_arg[0] = riscv_regs.a0; +- tcp->u_arg[1] = riscv_regs.a1; +- tcp->u_arg[2] = riscv_regs.a2; +- tcp->u_arg[3] = riscv_regs.a3; +- tcp->u_arg[4] = riscv_regs.a4; +- tcp->u_arg[5] = riscv_regs.a5; ++ tcp->u_arg[0] = riscv_regs.a[0]; ++ tcp->u_arg[1] = riscv_regs.a[1]; ++ tcp->u_arg[2] = riscv_regs.a[2]; ++ tcp->u_arg[3] = riscv_regs.a[3]; ++ tcp->u_arg[4] = riscv_regs.a[4]; ++ tcp->u_arg[5] = riscv_regs.a[5]; + #else /* Other architecture (32bits specific) */ + for (i = 0; i < nargs; ++i) + if (upeek(tcp->pid, i*4, &tcp->u_arg[i]) < 0) +@@ -2496,11 +2496,11 @@ get_error(struct tcb *tcp) + tcp->u_rval = arc_regs.scratch.r0; + } + #elif defined(RISCV) +- if (check_errno && is_negated_errno(riscv_regs.a0)) { ++ if (check_errno && is_negated_errno(riscv_regs.a[0])) { + tcp->u_rval = -1; +- u_error = -riscv_regs.a0; ++ u_error = -riscv_regs.a[0]; + } else { +- tcp->u_rval = riscv_regs.a0; ++ tcp->u_rval = riscv_regs.a[0]; + } + #endif + tcp->u_error = u_error; +-- +2.7.4 + diff --git a/Makefile b/Makefile index 839c9be..fbbfaca 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,8 @@ BDB_VERSION = 4.5.20 NANO_VERSION = 2.6.2 GREP_VERSION = 2.25 LESS_VERSION = 481 +STRACE_COMMIT = f320e1897832fd07a62e18ed288e75d8e79f4c5b +STRACE_SHORT_COMMIT = f320e189 all: stage1 stage2 stage3 stage4 @@ -282,6 +284,7 @@ stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \ stage3-chroot/usr/bin/nano \ stage3-chroot/usr/bin/grep \ stage3-chroot/usr/bin/less \ + stage3-chroot/usr/bin/strace \ stage3-chroot/init \ stage3-disk.img @@ -730,6 +733,25 @@ less-$(LESS_VERSION).tar.gz: wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz mv $@-t $@ +# Cross-compile strace. +stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz + rm -rf strace-$(STRACE_SHORT_COMMIT) + tar -zxf $^ + cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch + cd riscv-strace-$(STRACE_COMMIT) && \ + PATH=$(ROOT)/fixed-gcc:$$PATH \ + LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \ + ./configure \ + --host=riscv64-unknown-linux-gnu \ + --prefix=/usr --libdir=/usr/lib64 + cd riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make + cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot + +strace-$(STRACE_SHORT_COMMIT).tar.gz: + rm -f $@ $@-t + wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz' + mv $@-t $@ + # Create an /init script. stage3-chroot/init: init.sh install -m 0755 $^ $@ -- 1.8.3.1