Commit f97b956b authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull nolibc updates from Paul McKenney:

 - Fix selftest printf format mismatch in expect_str_buf_eq()

 - Stop using brk() and sbrk() when testing against musl, which
   implements these two functions with ENOMEM

 - Make tests use -Werror to force failure on compiler warnings

 - Add limits for the {u,}intmax_t, ulong and {u,}llong types

 - Implement strtol() and friends

 - Add facility to skip nolibc-specific tests when running against
   non-nolibc libraries

 - Implement strerror()

 - Also use strerror() on nolibc when running kselftests

* tag 'nolibc.2024.07.15a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu:
  selftests: kselftest: also use strerror() on nolibc
  tools/nolibc: implement strerror()
  selftests/nolibc: introduce condition to run tests only on nolibc
  tools/nolibc: implement strtol() and friends
  tools/nolibc: add limits for {u,}intmax_t, ulong and {u,}llong
  selftests/nolibc: run-tests.sh: use -Werror by default
  selftests/nolibc: disable brk()/sbrk() tests on musl
  selftests/nolibc: fix printf format mismatch in expect_str_buf_eq()
parents e4b2b0b1 6ca8f2e2
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -96,6 +96,10 @@ typedef uint64_t uintmax_t;
#define UINT_FAST32_MAX  SIZE_MAX
#define UINT_FAST64_MAX  UINT64_MAX

#define INTMAX_MIN       INT64_MIN
#define INTMAX_MAX       INT64_MAX
#define UINTMAX_MAX      UINT64_MAX

#ifndef INT_MIN
#define INT_MIN          (-__INT_MAX__ - 1)
#endif
@@ -110,4 +114,19 @@ typedef uint64_t uintmax_t;
#define LONG_MAX         __LONG_MAX__
#endif

#ifndef ULONG_MAX
#define ULONG_MAX         ((unsigned long)(__LONG_MAX__) * 2 + 1)
#endif

#ifndef LLONG_MIN
#define LLONG_MIN         (-__LONG_LONG_MAX__ - 1)
#endif
#ifndef LLONG_MAX
#define LLONG_MAX         __LONG_LONG_MAX__
#endif

#ifndef ULLONG_MAX
#define ULLONG_MAX         ((unsigned long long)(__LONG_LONG_MAX__) * 2 + 1)
#endif

#endif /* _NOLIBC_STDINT_H */
+10 −0
Original line number Diff line number Diff line
@@ -376,6 +376,16 @@ int setvbuf(FILE *stream __attribute__((unused)),
	return 0;
}

static __attribute__((unused))
const char *strerror(int errno)
{
	static char buf[18] = "errno=";

	i64toa_r(errno, &buf[6]);

	return buf;
}

/* make sure to include all global symbols */
#include "nolibc.h"

+109 −0
Original line number Diff line number Diff line
@@ -438,6 +438,115 @@ char *u64toa(uint64_t in)
	return itoa_buffer;
}

static __attribute__((unused))
uintmax_t __strtox(const char *nptr, char **endptr, int base, intmax_t lower_limit, uintmax_t upper_limit)
{
	const char signed_ = lower_limit != 0;
	unsigned char neg = 0, overflow = 0;
	uintmax_t val = 0, limit, old_val;
	char c;

	if (base < 0 || base > 36) {
		SET_ERRNO(EINVAL);
		goto out;
	}

	while (isspace(*nptr))
		nptr++;

	if (*nptr == '+') {
		nptr++;
	} else if (*nptr == '-') {
		neg = 1;
		nptr++;
	}

	if (signed_ && neg)
		limit = -(uintmax_t)lower_limit;
	else
		limit = upper_limit;

	if ((base == 0 || base == 16) &&
	    (strncmp(nptr, "0x", 2) == 0 || strncmp(nptr, "0X", 2) == 0)) {
		base = 16;
		nptr += 2;
	} else if (base == 0 && strncmp(nptr, "0", 1) == 0) {
		base = 8;
		nptr += 1;
	} else if (base == 0) {
		base = 10;
	}

	while (*nptr) {
		c = *nptr;

		if (c >= '0' && c <= '9')
			c -= '0';
		else if (c >= 'a' && c <= 'z')
			c = c - 'a' + 10;
		else if (c >= 'A' && c <= 'Z')
			c = c - 'A' + 10;
		else
			goto out;

		if (c >= base)
			goto out;

		nptr++;
		old_val = val;
		val *= base;
		val += c;

		if (val > limit || val < old_val)
			overflow = 1;
	}

out:
	if (overflow) {
		SET_ERRNO(ERANGE);
		val = limit;
	}
	if (endptr)
		*endptr = (char *)nptr;
	return neg ? -val : val;
}

static __attribute__((unused))
long strtol(const char *nptr, char **endptr, int base)
{
	return __strtox(nptr, endptr, base, LONG_MIN, LONG_MAX);
}

static __attribute__((unused))
unsigned long strtoul(const char *nptr, char **endptr, int base)
{
	return __strtox(nptr, endptr, base, 0, ULONG_MAX);
}

static __attribute__((unused))
long long strtoll(const char *nptr, char **endptr, int base)
{
	return __strtox(nptr, endptr, base, LLONG_MIN, LLONG_MAX);
}

static __attribute__((unused))
unsigned long long strtoull(const char *nptr, char **endptr, int base)
{
	return __strtox(nptr, endptr, base, 0, ULLONG_MAX);
}

static __attribute__((unused))
intmax_t strtoimax(const char *nptr, char **endptr, int base)
{
	return __strtox(nptr, endptr, base, INTMAX_MIN, INTMAX_MAX);
}

static __attribute__((unused))
uintmax_t strtoumax(const char *nptr, char **endptr, int base)
{
	return __strtox(nptr, endptr, base, 0, UINTMAX_MAX);
}

/* make sure to include all global symbols */
#include "nolibc.h"

+0 −8
Original line number Diff line number Diff line
@@ -168,15 +168,7 @@ static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...)

static inline void ksft_perror(const char *msg)
{
#ifndef NOLIBC
	ksft_print_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
#else
	/*
	 * nolibc doesn't provide strerror() and it seems
	 * inappropriate to add one, just print the errno.
	 */
	ksft_print_msg("%s: %d)\n", msg, errno);
#endif
}

static inline __printf(1, 2) void ksft_test_result_pass(const char *msg, ...)
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ CFLAGS_mips32be = -EB -mabi=32
CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
		$(call cc-option,-fno-stack-protector) \
		$(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR)
		$(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA)
LDFLAGS :=

REPORT  ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \
Loading