<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/tools/include/nolibc/stdlib.h, branch linux-6.2.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-6.2.y</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-6.2.y'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2023-01-09T17:36:05Z</updated>
<entry>
<title>tools/nolibc: fix missing includes causing build issues at -O0</title>
<updated>2023-01-09T17:36:05Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2023-01-09T07:54:40Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=55abdd1f5e1e07418bf4a46c233a92f83cb5ae97'/>
<id>urn:sha1:55abdd1f5e1e07418bf4a46c233a92f83cb5ae97</id>
<content type='text'>
After the nolibc includes were split to facilitate portability from
standard libcs, programs that include only what they need may miss
some symbols which are needed by libgcc. This is the case for raise()
which is needed by the divide by zero code in some architectures for
example.

Regardless, being able to include only the apparently needed files is
convenient.

Instead of trying to move all exported definitions to a single file,
since this can change over time, this patch takes another approach
consisting in including the nolibc header at the end of all standard
include files. This way their types and functions are already known
at the moment of inclusion, and including any single one of them is
sufficient to bring all the required ones.

Signed-off-by: Willy Tarreau &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/stdlib: Support overflow checking for older compiler versions</title>
<updated>2022-06-20T16:43:19Z</updated>
<author>
<name>Ammar Faizi</name>
<email>ammarfaizi2@gnuweeb.org</email>
</author>
<published>2022-05-19T17:21:15Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=1ef150cf40be986747c3fa0c0e75acaec412e85e'/>
<id>urn:sha1:1ef150cf40be986747c3fa0c0e75acaec412e85e</id>
<content type='text'>
Previously, we used __builtin_mul_overflow() to check for overflow in
the multiplication operation in the calloc() function. However, older
compiler versions don't support this built-in. This patch changes the
overflow checking mechanism to make it work on any compiler version
by using a division method to check for overflow. No functional change
intended. While in there, remove the unused variable `void *orig`.

Link: https://lore.kernel.org/lkml/20220330024114.GA18892@1wt.eu
Suggested-by: Willy Tarreau &lt;w@1wt.eu&gt;
Cc: Alviro Iskandar Setiawan &lt;alviro.iskandar@gnuweeb.org&gt;
Signed-off-by: Ammar Faizi &lt;ammarfaizi2@gnuweeb.org&gt;
Acked-by: Willy Tarreau &lt;w@1wt.eu&gt;
Reviewed-by: Alviro Iskandar Setiawan &lt;alviro.iskandar@gnuweeb.org&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`</title>
<updated>2022-04-21T00:05:46Z</updated>
<author>
<name>Ammar Faizi</name>
<email>ammarfaizi2@gnuweeb.org</email>
</author>
<published>2022-03-29T10:17:35Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=0e0ff638400be8f497a35b51a4751fd823f6bd6a'/>
<id>urn:sha1:0e0ff638400be8f497a35b51a4751fd823f6bd6a</id>
<content type='text'>
Implement basic dynamic allocator functions. These functions are
currently only available on architectures that have nolibc mmap()
syscall implemented. These are not a super-fast memory allocator,
but at least they can satisfy basic needs for having heap without
libc.

Cc: David Laight &lt;David.Laight@ACULAB.COM&gt;
Acked-by: Willy Tarreau &lt;w@1wt.eu&gt;
Signed-off-by: Ammar Faizi &lt;ammarfaizi2@gnuweeb.org&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/stdlib: only reference the external environ when inlined</title>
<updated>2022-04-21T00:05:46Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-03-23T07:18:07Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=2475d37ac30b8a850d3dd4fcbcb20895928b73fd'/>
<id>urn:sha1:2475d37ac30b8a850d3dd4fcbcb20895928b73fd</id>
<content type='text'>
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 &lt;ammarfaizi2@gnuweeb.org&gt;
Signed-off-by: Willy Tarreau &lt;w@1wt.eu&gt;
Tested-by: Ammar Faizi &lt;ammarfaizi2@gnuweeb.org&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/stdlib: add a simple getenv() implementation</title>
<updated>2022-04-21T00:05:45Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-03-21T17:33:08Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=077d0a392446981cde2e8dd23090140bdd9fb728'/>
<id>urn:sha1:077d0a392446981cde2e8dd23090140bdd9fb728</id>
<content type='text'>
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 &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/stdlib: implement abort()</title>
<updated>2022-04-21T00:05:45Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-02-07T16:23:54Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=f0f04f28d5ae483b3b354cb3b63a3bab0b00cee4'/>
<id>urn:sha1:f0f04f28d5ae483b3b354cb3b63a3bab0b00cee4</id>
<content type='text'>
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 &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/signal: move raise() to signal.h</title>
<updated>2022-04-21T00:05:45Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-02-07T16:23:51Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=99cb50ab94b2aa11c756c4ba14ef09197a7ebe7b'/>
<id>urn:sha1:99cb50ab94b2aa11c756c4ba14ef09197a7ebe7b</id>
<content type='text'>
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 &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/unistd: extract msleep(), sleep(), tcsetpgrp() to unistd.h</title>
<updated>2022-04-21T00:05:45Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-02-07T16:23:49Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=4619de344657c23101e8976b816466910dfb2759'/>
<id>urn:sha1:4619de344657c23101e8976b816466910dfb2759</id>
<content type='text'>
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 &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc: move exported functions to their own section</title>
<updated>2022-04-21T00:05:45Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-02-07T16:23:44Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=07f47ea06fe9d38c5e8d9068fba2468ed8bb8b59'/>
<id>urn:sha1:07f47ea06fe9d38c5e8d9068fba2468ed8bb8b59</id>
<content type='text'>
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_&lt;function&gt;.
This allows ld to get rid of them if unused when passed --gc-sections.

Signed-off-by: Willy Tarreau &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/nolibc/stdlib: make raise() use the lower level syscalls only</title>
<updated>2022-04-21T00:05:44Z</updated>
<author>
<name>Willy Tarreau</name>
<email>w@1wt.eu</email>
</author>
<published>2022-02-07T16:23:38Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=6e277371a5c4c73deb799aabfd5613ee3758e810'/>
<id>urn:sha1:6e277371a5c4c73deb799aabfd5613ee3758e810</id>
<content type='text'>
raise() doesn't set errno, so there's no point calling kill(), better
call sys_kill(), which also reduces the function's size.

Signed-off-by: Willy Tarreau &lt;w@1wt.eu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
</feed>
