[uclibc-ng-devel,3/4] nds32: Use new common syscall() implementation

Message ID 20171214062909.8602-4-shorne@gmail.com
State Accepted
Headers show
Series
  • Use varargs for common syscall() implementation
Related show

Commit Message

Stafford Horne Dec. 14, 2017, 6:29 a.m.
Traditionally nds32 has had a generic syscall implementation supporting
varargs.

During an audit it was found that this implementation seems to duplicate
the new common implementation and is no longer needed.

Signed-off-by: Stafford Horne <shorne@gmail.com>
---
 libc/sysdeps/linux/nds32/Makefile.arch |  4 ++--
 libc/sysdeps/linux/nds32/syscall.c     | 28 ----------------------------
 2 files changed, 2 insertions(+), 30 deletions(-)
 delete mode 100644 libc/sysdeps/linux/nds32/syscall.c

Comments

Waldemar Brodkorb Dec. 26, 2017, 10:44 a.m. | #1
Hi Stafford,
Stafford Horne wrote,

> Traditionally nds32 has had a generic syscall implementation supporting
> varargs.
> 
> During an audit it was found that this implementation seems to duplicate
> the new common implementation and is no longer needed.

nds32 syscall is special. I get following compile error:
libc/sysdeps/linux/common/syscall.c: In function 'syscall':
libc/sysdeps/linux/common/syscall.c:27:2: warning: implicit
declaration of function 'internal_syscall_ncs6'
[-Wimplicit-function-declaration]
  return INLINE_SYSCALL_NCS(sysnum, 6, arg1, arg2, arg3, arg4, arg5,
arg6);
  ^
In file included from ./include/sys/syscall.h:33:0,
                 from libc/sysdeps/linux/common/syscall.c:8:
./include/bits/syscalls-common.h:49:39: error: '__err' undeclared
(first use in this function)
     __res = INTERNAL_SYSCALL_NCS(num, __err, nr, args);  \

Not sure if we should touch nds32.

best regards
 Waldemar
Stafford Horne Dec. 26, 2017, 12:43 p.m. | #2
Hello,

On Tue, Dec 26, 2017 at 7:44 PM, Waldemar Brodkorb <wbx@uclibc-ng.org> wrote:
>
> Hi Stafford,
> Stafford Horne wrote,
>
> > Traditionally nds32 has had a generic syscall implementation supporting
> > varargs.
> >
> > During an audit it was found that this implementation seems to duplicate
> > the new common implementation and is no longer needed.
>
> nds32 syscall is special. I get following compile error:
> libc/sysdeps/linux/common/syscall.c: In function 'syscall':
> libc/sysdeps/linux/common/syscall.c:27:2: warning: implicit
> declaration of function 'internal_syscall_ncs6'
> [-Wimplicit-function-declaration]
>   return INLINE_SYSCALL_NCS(sysnum, 6, arg1, arg2, arg3, arg4, arg5,
> arg6);
>   ^
> In file included from ./include/sys/syscall.h:33:0,
>                  from libc/sysdeps/linux/common/syscall.c:8:
> ./include/bits/syscalls-common.h:49:39: error: '__err' undeclared
> (first use in this function)
>      __res = INTERNAL_SYSCALL_NCS(num, __err, nr, args);  \
>
> Not sure if we should touch nds32.

Looking at :
  libc/sysdeps/linux/nds32/bits/syscalls.h

It may be easy to add, but maybe we can leave this for the maintainers to reply.

-Stafford
Waldemar Brodkorb Jan. 7, 2018, 7:10 p.m. | #3
Hi,
vincentc@andestech.com wrote,

> Dear all:
> Stafford is right. internal_syscall_ncs6 is able to define in libc/sysdeps/linux/nds32/bits/syscalls.h like the following.
> 
> #define internal_syscall_ncs6(name, err, arg1, arg2, arg3, arg4, arg5, arg6)            \
>   ({                                                                    \
>        register long __res  __asm__("$r0");                                     \
>        register long __no   __asm__("$r0") = (long) (name);                             \
>        register long __arg1 __asm__("$r1") = (long) (arg1);                             \
>        register long __arg2 __asm__("$r2") = (long) (arg2);                             \
>        register long __arg3 __asm__("$r3") = (long) (arg3);                             \
>        register long __arg4 __asm__("$r4") = (long) (arg4);                             \
>        register long __arg5 __asm__("$r5") = (long) (arg5);                             \
>        __asm__ volatile (                                               \
>         "addi10.sp\t  #-4\n\t"                                                  \
>         CFI_ADJUST_CFA_OFFSET(4)"\n\t"                                          \
>         "push\t %7\n\t"                                                         \
>         CFI_ADJUST_CFA_OFFSET(4)"\n\t"                                          \
>        __issue_syscall (LIB_SYSCALL)                                            \
>         "pop\t %7\n\t"                                                  \
>         CFI_ADJUST_CFA_OFFSET(-4)"\n\t"                                         \
>         "addi10.sp\t  #4\n\t"                                           \
>         CFI_ADJUST_CFA_OFFSET(-4)"\n\t"                                         \
>        __asm__ volatile (                                                       \
>        __issue_syscall (LIB_SYSCALL)                                            \
>        : "=r" (__res)         /* output operands  */                                    \
>        : "r" (__no)           /* input operands  */                             \
>        , "r" (__arg1)         /* input operands  */                                     \
>        , "r" (__arg2)         /* input operands  */                                     \
>        , "r" (__arg3)         /* input operands  */                                     \
>        , "r" (__arg4)         /* input operands  */                                     \
>        , "r" (__arg5)         /* input operands  */                                     \
>        , "r" (arg6)         /* input operands  */                                       \
>        : __SYSCALL_CLOBBERS); /* list of clobbered registers  */                        \
>         __res;                                                          \
>   })
> 
> The value of argument "name" is the number of specified syscall.
> This syscall will be sent to kernel later through sys_syscall by "__issue_syscall (LIB_SYSCALL)".
> 

When testing Stafford patch from:
https://github.com/stffrdhrn/uclibc-ng.git -> branch gen-syscall

I added a missing ); before the second __asm__ volatile.

I get:
/home/wbx/nds32/toolchain_andes-ag101p_uclibc-ng_nds32le/usr/bin/nds32le-openadk-linux-uclibc-gcc
-c libc/sysdeps/linux/common/syscall.c -o
libc/sysdeps/linux/common/syscall.os -Wall -Wstrict-prototypes
-Wstrict-aliasing -funsigned-char -fno-builtin -fno-asm
-fmerge-all-constants -std=gnu99 -fno-stack-protector -nostdinc
-I./include -I./include -include libc-symbols.h
-I./libc/sysdeps/linux/nds32 -I./libc/sysdeps/linux
-I./ldso/ldso/nds32 -I./ldso/include -I. -Os -fstrict-aliasing
-fwrapv -fno-ident -mcpu=n13 -Os -pipe -fomit-frame-pointer
-fno-unwind-tables -fno-asynchronous-unwind-tables
-D__USE_STDIO_FUTEXES__ -DHAVE_FORCED_UNWIND -D_LIBC_REENTRANT
-I./libpthread/nptl -I./libpthread/nptl
-I./libpthread/nptl/sysdeps/unix/sysv/linux/nds32
-I./libpthread/nptl/sysdeps/nds32 -I./libpthread/nptl/sysdeps/nds32
-I./libpthread/nptl/sysdeps/unix/sysv/linux
-I./libpthread/nptl/sysdeps/unix/sysv/linux
-I./libpthread/nptl/sysdeps/pthread
-I./libpthread/nptl/sysdeps/pthread/bits
-I./libpthread/nptl/sysdeps/generic -I./libc/sysdeps/linux/common
-isystem
/home/wbx/nds32/toolchain_andes-ag101p_uclibc-ng_nds32le/usr/lib/gcc/nds32le-openadk-linux-uclibc/4.9.4/include-fixed
-isystem
/home/wbx/nds32/toolchain_andes-ag101p_uclibc-ng_nds32le/usr/lib/gcc/nds32le-openadk-linux-uclibc/4.9.4/include
-I/home/wbx/nds32/target_andes-ag101p_uclibc-ng_nds32le/usr/include/
-DNDEBUG -DIN_LIB=libc -DPIC -fPIC -MT
libc/sysdeps/linux/common/syscall.os -MD -MP -MF
libc/sysdeps/linux/common/.syscall.os.dep
{standard input}: Assembler messages:
{standard input}:62: Error: Unrecognized operand/register, smw.adm
$r-1,[$sp],$r-1,0.
{standard input}:65: Error: Unrecognized operand/register, lmw.bim
$r-1,[$sp],$r-1,0.
Makerules:369: recipe for target
'libc/sysdeps/linux/common/syscall.os' failed

Ideas?

best regards
 Waldemar

Patch

diff --git a/libc/sysdeps/linux/nds32/Makefile.arch b/libc/sysdeps/linux/nds32/Makefile.arch
index d5cdddbfa..caf163844 100644
--- a/libc/sysdeps/linux/nds32/Makefile.arch
+++ b/libc/sysdeps/linux/nds32/Makefile.arch
@@ -1,7 +1,7 @@ 
 # Copyright (C) 2016 Andes Technology, Inc.
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 
-CSRC-y := brk.c prctl.c mremap.c syscall.c
-SSRC-y := setjmp.S __longjmp.S bsd-setjmp.S bsd-_setjmp.S clone.S vfork.S sysdep.S syscall.S
+CSRC-y := brk.c prctl.c mremap.c
+SSRC-y := setjmp.S __longjmp.S bsd-setjmp.S bsd-_setjmp.S clone.S vfork.S sysdep.S
 CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c swapcontext.c
 SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += getcontext.S setcontext.S
diff --git a/libc/sysdeps/linux/nds32/syscall.c b/libc/sysdeps/linux/nds32/syscall.c
deleted file mode 100644
index 2c949ef3a..000000000
--- a/libc/sysdeps/linux/nds32/syscall.c
+++ /dev/null
@@ -1,28 +0,0 @@ 
-/*
- *  Copyright (C) 2017 Andes Technology, Inc.
- *  Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
-
-#include <errno.h>
-#include <stdarg.h>
-#include <sys/syscall.h>
-#include <sysdep.h>
-#include <unistd.h>
-long int syscall (long int __sysno, ...)
-{
-
-	int result;
-	unsigned long arg1,arg2,arg3,arg4,arg5,arg6;
-	va_list arg;
-	va_start (arg, __sysno);
-	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" );
-	result = INLINE_SYSCALL(syscall,7,__sysno,arg1,arg2,arg3,arg4,arg5,arg6);
-	return result;
-}