2022-03-21 20:33:13 +03:00
# SPDX-License-Identifier: GPL-2.0
# Makefile for nolibc installation and tests
i n c l u d e . . / . . / s c r i p t s / M a k e f i l e . i n c l u d e
# we're in ".../tools/include/nolibc"
i f e q ( $( srctree ) , )
srctree := $( patsubst %/tools/include/,%,$( dir $( CURDIR) ) )
e n d i f
2022-05-28 18:45:44 +03:00
# when run as make -C tools/ nolibc_<foo> the arch is not set
i f e q ( $( ARCH ) , )
i n c l u d e $( srctree ) / s c r i p t s / s u b a r c h . i n c l u d e
ARCH = $( SUBARCH)
e n d i f
# OUTPUT is only set when run from the main makefile, otherwise
# it defaults to this nolibc directory.
OUTPUT ?= $( CURDIR) /
i f e q ( $( V ) , 1 )
Q =
e l s e
Q = @
e n d i f
2022-03-21 20:33:13 +03:00
nolibc_arch := $( patsubst arm64,aarch64,$( ARCH) )
arch_file := arch-$( nolibc_arch) .h
2023-05-21 12:36:33 +03:00
all_files := \
2023-05-21 12:36:34 +03:00
compiler.h \
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>
2023-07-15 21:21:08 +03:00
crt.h \
2023-05-21 12:36:33 +03:00
ctype.h \
errno.h \
nolibc.h \
signal.h \
stackprotector.h \
std.h \
stdint.h \
stdlib.h \
string.h \
sys.h \
time.h \
types.h \
unistd.h \
stdio.h \
2022-03-21 20:33:13 +03:00
# install all headers needed to support a bare-metal compiler
2022-05-28 18:45:45 +03:00
all : headers
2022-03-21 20:33:13 +03:00
2022-05-28 18:45:46 +03:00
install : help
help :
@echo "Supported targets under nolibc:"
@echo " all call \"headers\""
@echo " clean clean the sysroot"
@echo " headers prepare a sysroot in tools/include/nolibc/sysroot"
@echo " headers_standalone like \"headers\", and also install kernel headers"
@echo " help this help"
@echo ""
@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
@echo ""
@echo "Currently using the following variables:"
@echo " ARCH = $( ARCH) "
@echo " OUTPUT = $( OUTPUT) "
@echo ""
2022-03-21 20:33:13 +03:00
# Note: when ARCH is "x86" we concatenate both x86_64 and i386
headers :
$( Q) mkdir -p $( OUTPUT) sysroot
$( Q) mkdir -p $( OUTPUT) sysroot/include
$( Q) cp $( all_files) $( OUTPUT) sysroot/include/
$( Q) if [ " $( ARCH) " = "x86" ] ; then \
sed -e \
's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
arch-x86_64.h; \
sed -e \
's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
arch-i386.h; \
elif [ -e " $( arch_file) " ] ; then \
cat $( arch_file) ; \
else \
echo " Fatal: architecture $( ARCH) not yet supported by nolibc. " >& 2; \
exit 1; \
fi > $( OUTPUT) sysroot/include/arch.h
headers_standalone : headers
$( Q) $( MAKE) -C $( srctree) headers
2022-05-28 18:45:44 +03:00
$( Q) $( MAKE) -C $( srctree) headers_install INSTALL_HDR_PATH = $( OUTPUT) sysroot
2022-03-21 20:33:13 +03:00
clean :
$( call QUIET_CLEAN, nolibc) rm -rf " $( OUTPUT) sysroot "