rcutorture: minor nolibc fixes
Subsystems (2)
cover rcutorture: minor nolibc fixes
While working on adding some documentation to the nolibc header provided with rcutorture, I noticed a few accidently deleted lines losing clobbered registers and some leftover spaces that I fixed. In addition, I finally added some documentation to the file, as requested by Ingo.
Willy Tarreau (3):
rcutorture/nolibc: fix the clobbered registers in the MIPS syscall
definition
rcutorture/nolibc: fix some poor indentation and alignment rcutorture/nolibc: add a bit of documentation to explain how to use
nolibc
tools/testing/selftests/rcutorture/bin/nolibc.h | 116 +++++++++++++++++++----- 1 file changed, 91 insertions(+), 25 deletions(-)
Signature · 1 line
2.9.0
PATCH 1/3 rcutorture/nolibc: fix the clobbered registers in the MIPS syscall definition
A last-minute checkpatch cleanup caused most of list of clobbered registers to be lost in the MIPS syscall definition. As it is right now the code is not used on MIPS, but it's better to fix it before it gets used.
--- tools/testing/selftests/rcutorture/bin/nolibc.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/rcutorture/bin/nolibc.h +6 -6
@@ -1006,7 +1006,7 @@ struct sys_stat_struct { : "=r"(_num), "=r"(_arg4) \ : "r"(_num) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - \ +"t0" ,"t1" ,"t2" ,"t3" ,"t4" ,"t5" ,"t6" ,"t7" ,"t8" ,"t9" \ ); \ _arg4 ? -_num : _num; \ })
@@ -1025,7 +1025,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - \ +"t0" ,"t1" ,"t2" ,"t3" ,"t4" ,"t5" ,"t6" ,"t7" ,"t8" ,"t9" \ ); \ _arg4 ? -_num : _num; \ })
@@ -1045,7 +1045,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - \ +"t0" ,"t1" ,"t2" ,"t3" ,"t4" ,"t5" ,"t6" ,"t7" ,"t8" ,"t9" \ ); \ _arg4 ? -_num : _num; \ })
@@ -1066,7 +1066,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - \ +"t0" ,"t1" ,"t2" ,"t3" ,"t4" ,"t5" ,"t6" ,"t7" ,"t8" ,"t9" \ ); \ _arg4 ? -_num : _num; \ })
@@ -1087,7 +1087,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - \ +"t0" ,"t1" ,"t2" ,"t3" ,"t4" ,"t5" ,"t6" ,"t7" ,"t8" ,"t9" \ ); \ _arg4 ? -_num : _num; \ })
@@ -1110,7 +1110,7 @@ struct sys_stat_struct { : "0"(_num), \ "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5) \ : "memory", "cc", "at", "v1", "hi", "lo", \ - \ +"t0" ,"t1" ,"t2" ,"t3" ,"t4" ,"t5" ,"t6" ,"t7" ,"t8" ,"t9" \ ); \ _arg4 ? -_num : _num; \ })
Signature · 1 line
2.9.0
PATCH 2/3 rcutorture/nolibc: fix some poor indentation and alignment
In reply to Willy TarreauA few macros had their rightmost backslash misaligned, and the pollfd struct definition resisted the previous code reindent. Nothing else changed.
--- tools/testing/selftests/rcutorture/bin/nolibc.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
tools/testing/selftests/rcutorture/bin/nolibc.h +7 -7
@@ -81,9 +81,9 @@ typedef signed long time_t;/* for poll() */ struct pollfd { -int fd; -short int events; -short int revents; +int fd; +short int events; +short int revents; };/* for select() */
@@ -239,7 +239,7 @@ struct stat { "syscall\n" \ : "=a" (_ret) \ : "0"(_num) \ -: " rcx", " r8", " r9", " r10", " r11", " memory", " cc" \ +: " rcx", " r8", " r9", " r10", " r11", " memory", " cc" \ ); \ _ret; \ })
@@ -255,7 +255,7 @@ struct stat { : "=a" (_ret) \ : "r"(_arg1), \ "0"(_num) \ - : "rcx", "r8", "r9", "r10", "r11", "memory", "cc" \ + : "rcx", "r8", "r9", "r10", "r11", "memory", "cc" \ ); \ _ret; \ })
@@ -272,7 +272,7 @@ struct stat { : "=a" (_ret) \ : "r"(_arg1), "r"(_arg2), \ "0"(_num) \ - : "rcx", "r8", "r9", "r10", "r11", "memory", "cc" \ + : "rcx", "r8", "r9", "r10", "r11", "memory", "cc" \ ); \ _ret; \ })
@@ -290,7 +290,7 @@ struct stat { : "=a" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ "0"(_num) \ - : "rcx", "r8", "r9", "r10", "r11", "memory", "cc" \ + : "rcx", "r8", "r9", "r10", "r11", "memory", "cc" \ ); \ _ret; \ })
Signature · 1 line
2.9.0
PATCH 3/3 rcutorture/nolibc: add a bit of documentation to explain how to use nolibc
In reply to Willy TarreauIngo rightfully asked for a bit more documentation in the nolibc header, so this patch adds some explanation about its purpose, how it's made, and how to use it.
--- tools/testing/selftests/rcutorture/bin/nolibc.h | 90 +++++++++++++++++++++---- 1 file changed, 78 insertions(+), 12 deletions(-)
tools/testing/selftests/rcutorture/bin/nolibc.h +78 -12
@@ -3,6 +3,84 @@* Copyright (C) 2017-2018 Willy Tarreau <[email protected]> */ +/* +* This file is designed to be used as a libc alternative for minimal programs +* with very limited requirements. It consists of a small number of syscall and +* types definitions, and the minimal startup code needed to call main(). +* All syscalls are declared as static functions so that they can be optimized +* away by the compiler when not used. +* +* Syscalls are split between 3 levels : +* - the lower level is the arch-specific syscall() definition, consisting in +* assembly code in compound expressions. These ones are called +* my_syscall0() to my_syscall6() depending on the number of arguments. The +* MIPS implementation is limited to 5 arguments. All input arguments are +* cast to a long stored in a register. These expressions always return the +* syscall's return value as a signed long value which is often either a +* pointer or the negated errno value. +* +* - the second level is mostly architecture-independent. It is made of +* static functions called sys_<name>() which rely on my_syscallN() +* depending on the syscall definition. These functions are responsible +* for exposing the appropriate types for the syscall arguments (int, +* pointers, etc) and for setting the appropriate return type (often int). +* A few of them are architecture-specific because the syscalls are not all +* mapped exactly the same between architecture. For example, some archs do +* not implement select() and need pselect6() instead, so the sys_select() +* function will have to abstract this. +* +* - the third level is the libc call definition. It exposes the lower raw +* sys_<name>() calls in a way that looks like what a libc usually does, +* takes care of specific input values, and of setting errno upon error. +* There can be minor variations compared to standard libc calls. For +* example the open() call always takes 3 args here. +* +* The errno variable is declared static and unused. This way it can be +* optimized away if not used. However this means that a program made of +* multiple C files may observe different errno values (one per C file). For +* the type of programs this project targets it usually is not a problem. The +* resulting program may even be reduced by defining the NOLIBC_IGNORE_ERRNO +* macro, in which case the errno value will never be assigned. +* +* Some stdint-like integer types are defined. These ones are valid on all +* currently supported architecture, because signs are enforced, ints are +* assumed to be 32 bits, longs the size of a pointer and long long 64 bits. +* If more architectures have to be supported, this may need to be adapted. +* +* Some macro definitions like the O_* values passed to open(), and some +* structures like the sys_stat struct depend on the architecture. +* +* The definitions start with the architecture-specific parts, which are picked +* based on what the compiler knows about the target architecture, and are +* completed with the generic code. Since it is the compiler which sets the +* target architecture, cross-compiling normally works out of the box without +* having to specify anything. +* +* Finally some very common libc-level functions are provided. It is the case +* for a few functions usually found in string.h, ctype.h, or stdlib.h. Nothing +* is currently provided regarding stdio emulation. +* +* The macro NOLIBC is always defined, so that it is possible for a program to +* check this macro to know if it is being built against and decide to disable +* some features or simply not to include some standard libc files. +* +* Ideally this file should be split in multiple files for easier long term +* maintenance, but provided as a single file as it is now, it's quite +* convenient to use. Maybe some variations involving a set of includes at the +* top could work. +* +* A simple static executable may be built this way : +* $ gcc -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ +* -static -include nolibc.h -lgcc -o hello hello.c +* +* A very useful calling convention table may be found here : +* http://man7.org/linux/man-pages/man2/syscall.2.html +* +* This doc is quite convenient though not necessarily up to date : +* https://w3challs.com/syscalls/ +* +*/ +/* some archs (at least aarch64) don't expose the regular syscalls anymore by * default, either because they have an "_at" replacement, or because there are * more modern alternatives. For now we'd rather still use them.
@@ -19,18 +97,6 @@#define NOLIBC -/* Build a static executable this way : -* $ gcc -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ -* -static -include nolibc.h -lgcc -o hello hello.c -* -* Useful calling convention table found here : -* http://man7.org/linux/man-pages/man2/syscall.2.html -* -* This doc is even better : -* https://w3challs.com/syscalls/ -*/ - -/* this way it will be removed if unused */ static int errno;
Signature · 1 line
2.9.0
Re: [PATCH 3/3] rcutorture/nolibc: add a bit of documentation to explain how to use nolibc
Quoted 7 lines · Willy Tarreau
Ingo rightfully asked for a bit more documentation in the nolibc header, so this patch adds some explanation about its purpose, how it's made, and how to use it.
Cc Ingo Molnar <[email protected]>Cc Paul E. McKenney <[email protected]>Signed-off-by Willy Tarreau <[email protected]>
Hi Willy,
This is a good summary IMO. Thanks.
And it's in good shape -- doesn't *require* any fixes.
But if you do make any changes to it, here are a few suggestions. :)
Quoted 9 lines
--- tools/testing/selftests/rcutorture/bin/nolibc.h | 90 +++++++++++++++++++++---- 1 file changed, 78 insertions(+), 12 deletions(-)tools/testing/selftests/rcutorture/bin/nolibc.h +0
-0
tools/testing/selftests/rcutorture/bin/nolibc.h line 9
Quoted 7 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +4
-0@@ -3,6 +3,84 @@* Copyright (C) 2017-2018 Willy Tarreau <[email protected]> */ +/* +* This file is designed to be used as a libc alternative for minimal programs +* with very limited requirements. It consists of a small number of syscall and +* types definitions, and the minimal startup code needed to call main().
type
tools/testing/selftests/rcutorture/bin/nolibc.h line 13
Quoted 4 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +4
-0+* All syscalls are declared as static functions so that they can be optimized +* away by the compiler when not used. +* +* Syscalls are split between 3 levels :
Instead of "between", use either "among" or "into". and then "levels:".
tools/testing/selftests/rcutorture/bin/nolibc.h line 15
Quoted 2 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +2
-0+* - the lower level is the arch-specific syscall() definition, consisting in +* assembly code in compound expressions. These ones are called
Apparently "these ones" is acceptable in UK English, not so in US English. I don't like it, but we do accept UK English here. :)
Quoted 20 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +20
-0+* my_syscall0() to my_syscall6() depending on the number of arguments. The +* MIPS implementation is limited to 5 arguments. All input arguments are +* cast to a long stored in a register. These expressions always return the +* syscall's return value as a signed long value which is often either a +* pointer or the negated errno value. +* +* - the second level is mostly architecture-independent. It is made of +* static functions called sys_<name>() which rely on my_syscallN() +* depending on the syscall definition. These functions are responsible +* for exposing the appropriate types for the syscall arguments (int, +* pointers, etc) and for setting the appropriate return type (often int). +* A few of them are architecture-specific because the syscalls are not all +* mapped exactly the same between architecture. For example, some archs do +* not implement select() and need pselect6() instead, so the sys_select() +* function will have to abstract this. +* +* - the third level is the libc call definition. It exposes the lower raw +* sys_<name>() calls in a way that looks like what a libc usually does, +* takes care of specific input values, and of setting errno upon error. +* There can be minor variations compared to standard libc calls. For
tools/testing/selftests/rcutorture/bin/nolibc.h line 45
Quoted 10 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +10
-0+* example the open() call always takes 3 args here. +* +* The errno variable is declared static and unused. This way it can be +* optimized away if not used. However this means that a program made of +* multiple C files may observe different errno values (one per C file). For +* the type of programs this project targets it usually is not a problem. The +* resulting program may even be reduced by defining the NOLIBC_IGNORE_ERRNO +* macro, in which case the errno value will never be assigned. +* +* Some stdint-like integer types are defined. These ones are valid on all
These are valid on all
(or not :)
Quoted 51 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +38
-5+* currently supported architecture, because signs are enforced, ints are +* assumed to be 32 bits, longs the size of a pointer and long long 64 bits. +* If more architectures have to be supported, this may need to be adapted. +* +* Some macro definitions like the O_* values passed to open(), and some +* structures like the sys_stat struct depend on the architecture. +* +* The definitions start with the architecture-specific parts, which are picked +* based on what the compiler knows about the target architecture, and are +* completed with the generic code. Since it is the compiler which sets the +* target architecture, cross-compiling normally works out of the box without +* having to specify anything. +* +* Finally some very common libc-level functions are provided. It is the case +* for a few functions usually found in string.h, ctype.h, or stdlib.h. Nothing +* is currently provided regarding stdio emulation. +* +* The macro NOLIBC is always defined, so that it is possible for a program to +* check this macro to know if it is being built against and decide to disable +* some features or simply not to include some standard libc files. +* +* Ideally this file should be split in multiple files for easier long term +* maintenance, but provided as a single file as it is now, it's quite +* convenient to use. Maybe some variations involving a set of includes at the +* top could work. +* +* A simple static executable may be built this way : +* $ gcc -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ +* -static -include nolibc.h -lgcc -o hello hello.c +* +* A very useful calling convention table may be found here : +* http://man7.org/linux/man-pages/man2/syscall.2.html +* +* This doc is quite convenient though not necessarily up to date : +* https://w3challs.com/syscalls/ +* +*/ +/* some archs (at least aarch64) don't expose the regular syscalls anymore by * default, either because they have an "_at" replacement, or because there are * more modern alternatives. For now we'd rather still use them. @@ -19,18 +97,6 @@#define NOLIBC -/* Build a static executable this way : -* $ gcc -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ -* -static -include nolibc.h -lgcc -o hello hello.c -* -* Useful calling convention table found here :
tools/testing/selftests/rcutorture/bin/nolibc.h line 102
Quoted 10 lines
tools/testing/selftests/rcutorture/bin/nolibc.h +0
-7-* http://man7.org/linux/man-pages/man2/syscall.2.html -* -* This doc is even better : -* https://w3challs.com/syscalls/ -*/ - -/* this way it will be removed if unused */ static int errno;
ciao. thanks.
Signature · 1 line
~Randy
Re: [PATCH 3/3] rcutorture/nolibc: add a bit of documentation to explain how to use nolibc
Hi Randy,
Quoted 3 lines · Randy Dunlap
This is a good summary IMO. Thanks.
And it's in good shape -- doesn't *require* any fixes.
But if you do make any changes to it, here are a few suggestions. :)
Thanks very much.
Quoted 5 lines
Quoted 3 lines
+ * This file is designed to be used as a libc alternative for minimal programs
+ * with very limited requirements. It consists of a small number of syscall and
+ * types definitions, and the minimal startup code needed to callmain().type
Funny, I hesitated on this one and "fixed" it :-)
Quoted 6 lines
Quoted 4 lines
+ * All syscalls are declared as static functions so that they can be optimized
+ * away by the compiler when not used.
+ *
+ * Syscalls are split between 3 levels :Instead of "between", use either "among" or "into". and then "levels:".
Will do, thanks.
Quoted 4 lines
Quoted 2 lines
+ * - the lower level is the arch-specific
syscall()definition, consisting in
+ * assembly code in compound expressions. These ones are calledApparently "these ones" is acceptable in UK English, not so in US English.
Oh I didn't know, I've used it quite a bit in the last decades, thinking it was a valid plural for "this one". It seems like I should use "These" instead, feel free to suggest otherwise.
Quoted 1 line
I don't like it, but we do accept UK English here. :)
I prefer to be corrected and to avoid using bad English, whether it's US or UK, as much as I hate to make mistakes in French.
Quoted 3 lines
Quoted 1 line
+ * Some stdint-like integer types are defined. These ones are valid on all
These are valid on all
OK, makes sense according to the point above.
Quoted 1 line
ciao. thanks.
I'm applying the changes right now to my local tree and will respin a version. Thank you!
Willy