Skip to content

Commit b069122

Browse files
committed
Merge tag 'nolibc.2022.07.27a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
Pull nolibc updates from Paul McKenney: "This provides nolibc updates, perhaps most notably improved testing via the 'cd tools/include/nolibc; make headers' command. This should be considered a smoke test. More thorough testing is in the works" * tag 'nolibc.2022.07.27a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: tools/nolibc: add a help target to list supported targets tools/nolibc: make the default target build the headers tools/nolibc: fix the makefile to also work as "make -C tools ..." tools/nolibc/stdio: Add format attribute to enable printf warnings tools/nolibc/stdlib: Support overflow checking for older compiler versions
2 parents 7d9d077 + 4f8126f commit b069122

4 files changed

Lines changed: 43 additions & 8 deletions

File tree

tools/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ bpf/%: FORCE
7878
libapi: FORCE
7979
$(call descend,lib/api)
8080

81+
nolibc: FORCE
82+
$(call descend,include/nolibc)
83+
8184
nolibc_%: FORCE
8285
$(call descend,include/nolibc,$(patsubst nolibc_%,%,$@))
8386

tools/include/nolibc/Makefile

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,46 @@ ifeq ($(srctree),)
77
srctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR)))
88
endif
99

10+
# when run as make -C tools/ nolibc_<foo> the arch is not set
11+
ifeq ($(ARCH),)
12+
include $(srctree)/scripts/subarch.include
13+
ARCH = $(SUBARCH)
14+
endif
15+
16+
# OUTPUT is only set when run from the main makefile, otherwise
17+
# it defaults to this nolibc directory.
18+
OUTPUT ?= $(CURDIR)/
19+
20+
ifeq ($(V),1)
21+
Q=
22+
else
23+
Q=@
24+
endif
25+
1026
nolibc_arch := $(patsubst arm64,aarch64,$(ARCH))
1127
arch_file := arch-$(nolibc_arch).h
1228
all_files := ctype.h errno.h nolibc.h signal.h std.h stdio.h stdlib.h string.h \
1329
sys.h time.h types.h unistd.h
1430

1531
# install all headers needed to support a bare-metal compiler
16-
all:
32+
all: headers
33+
34+
install: help
35+
36+
help:
37+
@echo "Supported targets under nolibc:"
38+
@echo " all call \"headers\""
39+
@echo " clean clean the sysroot"
40+
@echo " headers prepare a sysroot in tools/include/nolibc/sysroot"
41+
@echo " headers_standalone like \"headers\", and also install kernel headers"
42+
@echo " help this help"
43+
@echo ""
44+
@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
45+
@echo ""
46+
@echo "Currently using the following variables:"
47+
@echo " ARCH = $(ARCH)"
48+
@echo " OUTPUT = $(OUTPUT)"
49+
@echo ""
1750

1851
# Note: when ARCH is "x86" we concatenate both x86_64 and i386
1952
headers:
@@ -36,7 +69,7 @@ headers:
3669

3770
headers_standalone: headers
3871
$(Q)$(MAKE) -C $(srctree) headers
39-
$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)/sysroot
72+
$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
4073

4174
clean:
4275
$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"

tools/include/nolibc/stdio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
273273
return written;
274274
}
275275

276-
static __attribute__((unused))
276+
static __attribute__((unused, format(printf, 2, 3)))
277277
int fprintf(FILE *stream, const char *fmt, ...)
278278
{
279279
va_list args;
@@ -285,7 +285,7 @@ int fprintf(FILE *stream, const char *fmt, ...)
285285
return ret;
286286
}
287287

288-
static __attribute__((unused))
288+
static __attribute__((unused, format(printf, 1, 2)))
289289
int printf(const char *fmt, ...)
290290
{
291291
va_list args;

tools/include/nolibc/stdlib.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ void *malloc(size_t len)
128128
static __attribute__((unused))
129129
void *calloc(size_t size, size_t nmemb)
130130
{
131-
void *orig;
132-
size_t res = 0;
131+
size_t x = size * nmemb;
133132

134-
if (__builtin_expect(__builtin_mul_overflow(nmemb, size, &res), 0)) {
133+
if (__builtin_expect(size && ((x / size) != nmemb), 0)) {
135134
SET_ERRNO(ENOMEM);
136135
return NULL;
137136
}
@@ -140,7 +139,7 @@ void *calloc(size_t size, size_t nmemb)
140139
* No need to zero the heap, the MAP_ANONYMOUS in malloc()
141140
* already does it.
142141
*/
143-
return malloc(res);
142+
return malloc(x);
144143
}
145144

146145
static __attribute__((unused))

0 commit comments

Comments
 (0)