[Buildroot] or1k system calls appear broken
Stafford Horne
shorne at gmail.com
Wed Dec 6 12:55:30 UTC 2017
On Wed, Dec 06, 2017 at 11:08:41PM +1030, Joel Stanley wrote:
> On Wed, Dec 6, 2017 at 11:11 AM, Stafford Horne <shorne at gmail.com> wrote:
> > I tested with this I am still getting the same error. I think I figured
> > out the issue though. The issue is busybox internally calls syscall(2).
> >
> > - in unistd.h defined something like
> > int syscall(nr, ....)
> >
> > - in syscall.c (common) implemented as
> > int syscall(nr, arg1, arg3, arg3, arg4, arg5, arg6)
> >
> > This will not work, busybox thinks syscall should have varargs calling
> > conventions. But it doesnt in the uclibc implementation so no args go through.
> >
> > Most architectures this will work. But on openrisc varargs are all sent on the
> > stack. Regular args are passed in registers.
> >
> > For openrisc I think we need a custom implementation of syscall(2).
>
> Great find! I hacked up an implementation up and did a buildroot
> build, and it passed my testcase (`strace ping 127.0.0.1`).
>
> The patch is attached. It might be a better idea to load the varargs
> directly into registers like the cx6 port does. Let me know what you
> think, and I can post it to the uclibc-ng list.
Thanks Joel, this is pretty much what I was thinking too.
> From 8ecc5c37c1db31cde93929e9d2d969872990cb7d Mon Sep 17 00:00:00 2001
> From: Joel Stanley <joel at jms.id.au>
> Date: Wed, 6 Dec 2017 12:26:21 +1030
> Subject: [PATCH] or1k: syscall: Pass arguments on the stack
>
> Busybox internally calls syscall(2).
>
> - in unistd.h defined something like
> int syscall(nr, ....)
>
> - in syscall.c (common) implemented as
> int syscall(nr, arg1, arg3, arg3, arg4, arg5, arg6)
>
> This will not work, busybox thinks syscall should have varargs calling
> conventions. But it doesnt in the uclibc implementation so no args go through.
>
> Most architectures this will work. But on openrisc varargs are all sent on the
> stack. Regular args are passed in registers.
>
> Commit message and idea from Stafford Horne <shorne at gmail.com>.
>
> Signed-off-by: Joel Stanley <joel at jms.id.au>
> ---
> libc/sysdeps/linux/or1k/Makefile.arch | 2 +-
> libc/sysdeps/linux/or1k/syscall.c | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 1 deletion(-)
> create mode 100644 libc/sysdeps/linux/or1k/syscall.c
>
> diff --git a/libc/sysdeps/linux/or1k/Makefile.arch b/libc/sysdeps/linux/or1k/Makefile.arch
> index f6758fa63fa3..191eebafde9d 100644
> --- a/libc/sysdeps/linux/or1k/Makefile.arch
> +++ b/libc/sysdeps/linux/or1k/Makefile.arch
> @@ -5,5 +5,5 @@
> # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
> #
>
> -CSRC-y := __syscall_error.c __init_brk.c brk.c sbrk.c clone.c
> +CSRC-y := __syscall_error.c __init_brk.c brk.c sbrk.c clone.c syscall.c
> SSRC-y := __longjmp.S setjmp.S or1k_clone.S
> diff --git a/libc/sysdeps/linux/or1k/syscall.c b/libc/sysdeps/linux/or1k/syscall.c
> new file mode 100644
> index 000000000000..2f4356737cf8
> --- /dev/null
> +++ b/libc/sysdeps/linux/or1k/syscall.c
I was thinking we can just update : libc/sysdeps/linux/common/syscall.c
There is not much openrisc specific about this. But it's up to Waldemar.
> @@ -0,0 +1,32 @@
> +/*
> + * Copyright (C) 2017 Joel Stanley <joel at jms.id.au>
> + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
> + */
> +
> +#include <stdarg.h>
> +#include <sys/syscall.h>
> +#include <unistd.h>
> +
> +long int syscall (long num, ...)
> +{
> + unsigned long arg1 = 0;
> + unsigned long arg2 = 0;
> + unsigned long arg3 = 0;
> + unsigned long arg4 = 0;
> + unsigned long arg5 = 0;
> + unsigned long arg6 = 0;
> + va_list arg;
> +
> + va_start (arg, num);
> + arg1 = va_arg (arg, unsigned long);
> + arg2 = va_arg (arg, unsigned long);
> + arg3 = va_arg (arg, unsigned long);
> + arg4 = va_arg (arg, unsigned long);
> + arg5 = va_arg (arg, unsigned long);
> + arg6 = va_arg (arg, unsigned long);
> + va_end (arg);
> +
> + __asm__ volatile ( "" ::: "memory" );
> +
> + return INLINE_SYSCALL_NCS(num, 6, arg1, arg2, arg3, arg4, arg5, arg6);
> +}
> --
> 2.14.1
>
This looks ok to me its pretty much what I would have written.
More information about the buildroot
mailing list