aports/testing/systemd-boot/0001-patch-wchar_t-for-musl.patch
Struan Robertson 70ff8dc55a testing/systemd-boot: new aport
Also package systemd-boot

Make linter happy

Call subpackage systemd-efistub instead of systemd-boot-efistub
2025-01-15 21:37:24 +00:00

119 lines
4.8 KiB
Diff

From 87e8a19b2a9a15352d849918d995cea92ba287bb Mon Sep 17 00:00:00 2001
From: Struan Robertson <contact@struanrobertson.co.uk>
Date: Mon, 16 Dec 2024 13:48:25 +0000
Subject: [PATCH] patch wchar_t for musl
---
src/boot/efi-string.c | 10 +++++-----
src/boot/efi.h | 6 +++---
src/boot/fuzz-efi-printf.c | 2 +-
src/boot/test-efi-string.c | 2 +-
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/boot/efi-string.c b/src/boot/efi-string.c
index aee98a8..314d14d 100644
--- a/src/boot/efi-string.c
+++ b/src/boot/efi-string.c
@@ -570,7 +570,7 @@ typedef struct {
bool have_field_width;
const char *str;
- const wchar_t *wstr;
+ const uint16_t *wstr;
/* For numbers. */
bool is_signed;
@@ -631,7 +631,7 @@ static bool push_str(FormatContext *ctx, SpecifierContext *sp) {
push_padding(ctx, ' ', sp->padded_len);
/* In userspace unit tests we cannot just memcpy() the wide string. */
- if (sp->wstr && sizeof(wchar_t) == sizeof(char16_t)) {
+ if (sp->wstr && sizeof(uint16_t) == sizeof(char16_t)) {
memcpy(ctx->buf + ctx->n, sp->wstr, sp->len * sizeof(*sp->wstr));
ctx->n += sp->len;
} else {
@@ -725,7 +725,7 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) {
* int in vararg functions, which is why we fetch only ints for any such types. The compiler would
* otherwise warn about fetching smaller types. */
assert_cc(sizeof(int) == 4);
- assert_cc(sizeof(wchar_t) <= sizeof(int));
+ assert_cc(sizeof(uint16_t) <= sizeof(int));
assert_cc(sizeof(intmax_t) <= sizeof(long long));
assert(ctx);
@@ -820,13 +820,13 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) {
return push_str(ctx, sp);
case 'c':
- sp->wstr = &(wchar_t){ va_arg(ctx->ap, int) };
+ sp->wstr = &(uint16_t){ va_arg(ctx->ap, int) };
sp->len = 1;
return push_str(ctx, sp);
case 's':
if (sp->long_arg) {
- sp->wstr = va_arg(ctx->ap, const wchar_t *) ?: L"(null)";
+ sp->wstr = va_arg(ctx->ap, const uint16_t *) ?: L"(null)";
sp->len = wcsnlen(sp->wstr, sp->len);
} else {
sp->str = va_arg(ctx->ap, const char *) ?: "(null)";
diff --git a/src/boot/efi.h b/src/boot/efi.h
index e104263..d6c1aa4 100644
--- a/src/boot/efi.h
+++ b/src/boot/efi.h
@@ -10,7 +10,7 @@
#if SD_BOOT
/* uchar.h/wchar.h are not suitable for freestanding environments. */
-typedef __WCHAR_TYPE__ wchar_t;
+typedef __WCHAR_TYPE__ uint16_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
@@ -22,7 +22,7 @@ assert_cc(sizeof(uint8_t) == 1);
assert_cc(sizeof(uint16_t) == 2);
assert_cc(sizeof(uint32_t) == 4);
assert_cc(sizeof(uint64_t) == 8);
-assert_cc(sizeof(wchar_t) == 2);
+assert_cc(sizeof(uint16_t) == 2);
assert_cc(sizeof(char16_t) == 2);
assert_cc(sizeof(char32_t) == 4);
assert_cc(sizeof(size_t) == sizeof(void *));
@@ -32,7 +32,7 @@ assert_cc(alignof(uint8_t) == 1);
assert_cc(alignof(uint16_t) == 2);
assert_cc(alignof(uint32_t) == 4);
assert_cc(alignof(uint64_t) == 8);
-assert_cc(alignof(wchar_t) == 2);
+assert_cc(alignof(uint16_t) == 2);
assert_cc(alignof(char16_t) == 2);
assert_cc(alignof(char32_t) == 4);
diff --git a/src/boot/fuzz-efi-printf.c b/src/boot/fuzz-efi-printf.c
index 6dee830..75017cc 100644
--- a/src/boot/fuzz-efi-printf.c
+++ b/src/boot/fuzz-efi-printf.c
@@ -45,7 +45,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
fuzz_setup_logging();
PRINTF_ONE(i->status, "%*.*s", i->field_width, (int) len, i->str);
- PRINTF_ONE(i->status, "%*.*ls", i->field_width, (int) (len / sizeof(wchar_t)), (const wchar_t *) i->str);
+ PRINTF_ONE(i->status, "%*.*ls", i->field_width, (int) (len / sizeof(uint16_t)), (const uint16_t *) i->str);
PRINTF_ONE(i->status, "%% %*.*m", i->field_width, i->precision);
PRINTF_ONE(i->status, "%*p", i->field_width, i->ptr);
diff --git a/src/boot/test-efi-string.c b/src/boot/test-efi-string.c
index b71a0c3..d2d1020 100644
--- a/src/boot/test-efi-string.c
+++ b/src/boot/test-efi-string.c
@@ -649,7 +649,7 @@ TEST(xvasprintf_status) {
test_printf_one("%-14ls %-10.0ls %-10.3ls", L"left", L"", L"chopped");
test_printf_one("%.6s", (char[]){ 'n', 'o', ' ', 'n', 'u', 'l' });
- test_printf_one("%.6ls", (wchar_t[]){ 'n', 'o', ' ', 'n', 'u', 'l' });
+ test_printf_one("%.6ls", (uint16_t[]){ 'n', 'o', ' ', 'n', 'u', 'l' });
test_printf_one("%u %u %u", 0U, 42U, 1234567890U);
test_printf_one("%i %i %i", 0, -42, -1234567890);
--
2.47.1