tools/nolibc: add new crt.h with _start_c
authorZhangjin Wu <falcon@tinylab.org>
Sat, 15 Jul 2023 18:21:08 +0000 (02:21 +0800)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Aug 2023 02:40:22 +0000 (04:40 +0200)
commit17336755150b19a697079f9c3945eff7882a77c5
tree344e4d18d559c3aa8a554afb0c53806f8dbcd307
parentaf93807eaef689a4964fdec085c77c24b49a5560
tools/nolibc: add new crt.h with _start_c

As the environ and _auxv support added for nolibc, the assembly _start
function becomes more and more complex and therefore makes the porting
of nolibc to new architectures harder and harder.

To simplify portability, this C version of _start_c() is added to do
most of the assembly start operations in C, which reduces the complexity
a lot and will eventually simplify the porting of nolibc to the new
architectures.

The new _start_c() only requires a stack pointer argument, it will find
argc, argv, envp/environ and _auxv for us, and then call main(),
finally, it exit() with main's return status. With this new _start_c(),
the future new architectures only require to add very few assembly
instructions.

As suggested by Thomas, users may use a different signature of main
(e.g. void main(void)), a _nolibc_main alias is added for main to
silence the warning about potential conflicting types.

As suggested by Willy, the code is carefully polished for both smaller
size and better readability with local variables and the right types.

Suggested-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/lkml/20230715095729.GC24086@1wt.eu/
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/90fdd255-32f4-4caf-90ff-06456b53dac3@t-8ch.de/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
tools/include/nolibc/Makefile
tools/include/nolibc/crt.h [new file with mode: 0644]