| 37d62758 | 29-Mar-2022 |
Ammar Faizi <ammarfaizi2@gnuweeb.org> |
tools/nolibc: Replace `asm` with `__asm__`
Replace `asm` with `__asm__` to support compilation with -std flag. Using `asm` with -std flag makes GCC think `asm()` is a function call instead of an inl
tools/nolibc: Replace `asm` with `__asm__`
Replace `asm` with `__asm__` to support compilation with -std flag. Using `asm` with -std flag makes GCC think `asm()` is a function call instead of an inline assembly.
GCC doc says:
For the C language, the `asm` keyword is a GNU extension. When writing C code that can be compiled with `-ansi` and the `-std` options that select C dialects without GNU extensions, use `__asm__` instead of `asm`.
Link: https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html Reported-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org> Acked-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 5312aaa5 | 29-Mar-2022 |
Ammar Faizi <ammarfaizi2@gnuweeb.org> |
tools/nolibc: x86-64: Update System V ABI document link
The old link no longer works, update it.
Acked-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-b
tools/nolibc: x86-64: Update System V ABI document link
The old link no longer works, update it.
Acked-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 2475d37a | 23-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/stdlib: only reference the external environ when inlined
When building with gcc at -O0 we're seeing link errors due to the "environ" variable being referenced by getenv(). The problem i
tools/nolibc/stdlib: only reference the external environ when inlined
When building with gcc at -O0 we're seeing link errors due to the "environ" variable being referenced by getenv(). The problem is that at -O0 gcc will not inline getenv() and will not drop the external reference. One solution would be to locally declare the variable as weak, but then it would appear in all programs even those not using it, and would be confusing to users of getenv() who would forget to set environ to envp.
An alternate approach used in this patch consists in always inlining the outer part of getenv() that references this extern so that it's always dropped when not used. The biggest part of the function was now moved to a new function called _getenv() that's still not inlined by default.
Reported-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: Willy Tarreau <w@1wt.eu> Tested-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 96980b83 | 23-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/string: do not use __builtin_strlen() at -O0
clang wants to use strlen() for __builtin_strlen() at -O0. We don't really care about -O0 but it at least ought to build, so let's make sure
tools/nolibc/string: do not use __builtin_strlen() at -O0
clang wants to use strlen() for __builtin_strlen() at -O0. We don't really care about -O0 but it at least ought to build, so let's make sure we don't choke on this, by dropping the optimizationn for constant strings in this case.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 24326164 | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc: add a makefile to install headers
This provides a target "headers_standalone" which installs the nolibc's arch-specific headers with "arch.h" taken from the current arch (or a concaten
tools/nolibc: add a makefile to install headers
This provides a target "headers_standalone" which installs the nolibc's arch-specific headers with "arch.h" taken from the current arch (or a concatenation of both i386 and x86_64 for arch=x86), then installs kernel headers. This creates a convenient sysroot which is directly usable by a bare-metal compiler to create any executable.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 96d2a131 | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/types: add poll() and waitpid() flag definitions
- POLLIN etc were missing, so poll() could only be used with timeouts. - WNOHANG was not defined and is convenient to check if a child i
tools/nolibc/types: add poll() and waitpid() flag definitions
- POLLIN etc were missing, so poll() could only be used with timeouts. - WNOHANG was not defined and is convenient to check if a child is still running
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 54abe359 | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/sys: add syscall definition for getppid()
This is essentially for completeness as it's not the most often used in regtests.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul
tools/nolibc/sys: add syscall definition for getppid()
This is essentially for completeness as it's not the most often used in regtests.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 0e7b4929 | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/string: add strcmp() and strncmp()
We need these functions all the time, including when checking environment variables and parsing command-line arguments. These implementations were opt
tools/nolibc/string: add strcmp() and strncmp()
We need these functions all the time, including when checking environment variables and parsing command-line arguments. These implementations were optimized to show optimal code size on a wide range of compilers (22 bytes return included for strcmp(), 33 for strncmp()).
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| bd845a19 | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/stdio: add support for '%p' to vfprintf()
%p remains quite useful in test code, and the code path can easily be merged with the existing "%x" thus only adds ~50 bytes, thus let's add it
tools/nolibc/stdio: add support for '%p' to vfprintf()
%p remains quite useful in test code, and the code path can easily be merged with the existing "%x" thus only adds ~50 bytes, thus let's add it.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 077d0a39 | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/stdlib: add a simple getenv() implementation
This implementation relies on an extern definition of the environ variable, that the caller must declare and initialize from envp.
Signed-o
tools/nolibc/stdlib: add a simple getenv() implementation
This implementation relies on an extern definition of the environ variable, that the caller must declare and initialize from envp.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 170b230d | 21-Mar-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/stdio: make printf(%s) accept NULL
It's often convenient to support this, especially in test programs where a NULL may correspond to an allocation error or a non-existing value. Let's m
tools/nolibc/stdio: make printf(%s) accept NULL
It's often convenient to support this, especially in test programs where a NULL may correspond to an allocation error or a non-existing value. Let's make printf("%s") support being passed a NULL. In this case it prints "(null)" like glibc's printf().
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| f0f04f28 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/stdlib: implement abort()
libgcc uses it for certain divide functions, so it must be exported. Like for memset() we do that in its own section so that the linker can strip it when not n
tools/nolibc/stdlib: implement abort()
libgcc uses it for certain divide functions, so it must be exported. Like for memset() we do that in its own section so that the linker can strip it when not needed.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| c4486e97 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc: also mention how to build by just setting the include path
Now that a few basic include files are provided, some simple portable programs may build, which will save them from having to
tools/nolibc: also mention how to build by just setting the include path
Now that a few basic include files are provided, some simple portable programs may build, which will save them from having to surround their includes with #ifndef NOLIBC. This patch mentions how to proceed, and enumerates the list of files that are covered.
A comprehensive list of required include files is available here:
https://en.cppreference.com/w/c/header
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| cec15053 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/time: create time.h with time()
The time() syscall is used by a few simple applications, and is trivial to implement based on gettimeofday() that we already have. Let's create the file
tools/nolibc/time: create time.h with time()
The time() syscall is used by a few simple applications, and is trivial to implement based on gettimeofday() that we already have. Let's create the file to ease porting and provide the function. It never returns any error, though it may segfault in case of invalid pointer, like other implementations relying on gettimeofday().
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 99cb50ab | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/signal: move raise() to signal.h
This function is normally found in signal.h, and providing the file eases porting of existing programs. Let's move it there.
Signed-off-by: Willy Tarre
tools/nolibc/signal: move raise() to signal.h
This function is normally found in signal.h, and providing the file eases porting of existing programs. Let's move it there.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 180a9797 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/unistd: add usleep()
This call is trivial to implement based on select() to complete sleep() and msleep(), let's add it.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E.
tools/nolibc/unistd: add usleep()
This call is trivial to implement based on select() to complete sleep() and msleep(), let's add it.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 4619de34 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/unistd: extract msleep(), sleep(), tcsetpgrp() to unistd.h
These functions are normally provided by unistd.h. For ease of porting, let's create the file and move them there.
Signed-off
tools/nolibc/unistd: extract msleep(), sleep(), tcsetpgrp() to unistd.h
These functions are normally provided by unistd.h. For ease of porting, let's create the file and move them there.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 45a794bf | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/errno: extract errno.h from sys.h
This allows us to provide a minimal errno.h to ease porting applications that use it.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. M
tools/nolibc/errno: extract errno.h from sys.h
This allows us to provide a minimal errno.h to ease porting applications that use it.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 8d304a37 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/string: export memset() and memmove()
"clang -Os" and "gcc -Ofast" without -ffreestanding may ignore memset() and memmove(), hoping to provide their builtin equivalents, and finally not
tools/nolibc/string: export memset() and memmove()
"clang -Os" and "gcc -Ofast" without -ffreestanding may ignore memset() and memmove(), hoping to provide their builtin equivalents, and finally not find them. Thus we must export these functions for these rare cases. Note that as they're set in their own sections, they will be eliminated by the linker if not used. In addition, they do not prevent gcc from identifying them and replacing them with the shorter "rep movsb" or "rep stosb" when relevant.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 023033fe | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/types: define PATH_MAX and MAXPATHLEN
These ones are often used and commonly set by applications to fallback values. Let's fix them both to agree on PATH_MAX=4096 by default, as is alre
tools/nolibc/types: define PATH_MAX and MAXPATHLEN
These ones are often used and commonly set by applications to fallback values. Let's fix them both to agree on PATH_MAX=4096 by default, as is already present in linux/limits.h.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| dffeb81a | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/arch: mark the _start symbol as weak
By doing so we can link together multiple C files that have been compiled with nolibc and which each have a _start symbol.
Signed-off-by: Willy Tar
tools/nolibc/arch: mark the _start symbol as weak
By doing so we can link together multiple C files that have been compiled with nolibc and which each have a _start symbol.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| 07f47ea0 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc: move exported functions to their own section
Some functions like raise() and memcpy() are permanently exported because they're needed by libgcc on certain platforms. However most of th
tools/nolibc: move exported functions to their own section
Some functions like raise() and memcpy() are permanently exported because they're needed by libgcc on certain platforms. However most of the time they are not needed and needlessly take space.
Let's move them to their own sub-section, called .text.nolibc_<function>. This allows ld to get rid of them if unused when passed --gc-sections.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| d9390de6 | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/string: add tiny versions of strncat() and strlcat()
While these functions are often dangerous, forcing the user to work around their absence is often much worse. Let's provide small ve
tools/nolibc/string: add tiny versions of strncat() and strlcat()
While these functions are often dangerous, forcing the user to work around their absence is often much worse. Let's provide small versions of each of them. The respective sizes in bytes on a few architectures are:
strncat(): x86:0x33 mips:0x68 arm:0x3c strlcat(): x86:0x25 mips:0x4c arm:0x2c
The two are quite different, and strncat() is even different from strncpy() in that it limits the amount of data it copies and will always terminate the output by one zero, while strlcat() will always limit the total output to the specified size and will put a zero if possible.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| b312eb0b | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/string: add strncpy() and strlcpy()
These are minimal variants. strncpy() always fills the destination for <size> chars, while strlcpy() copies no more than <size> including the zero an
tools/nolibc/string: add strncpy() and strlcpy()
These are minimal variants. strncpy() always fills the destination for <size> chars, while strlcpy() copies no more than <size> including the zero and returns the source's length. The respective sizes on various archs are:
strncpy(): x86:0x1f mips:0x30 arm:0x20 strlcpy(): x86:0x17 mips:0x34 arm:0x1a
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|
| d76232ff | 07-Feb-2022 |
Willy Tarreau <w@1wt.eu> |
tools/nolibc/string: slightly simplify memmove()
The direction test inside the loop was not always completely optimized, resulting in a larger than necessary function. This change adds a direction v
tools/nolibc/string: slightly simplify memmove()
The direction test inside the loop was not always completely optimized, resulting in a larger than necessary function. This change adds a direction variable that is set out of the loop. Now the function is down to 48 bytes on x86, 32 on ARM and 68 on mips. It's worth noting that other approaches were attempted (including relying on the up and down functions) but they were only slightly beneficial on x86 and cost more on others.
Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
show more ...
|