From d14eb24925362e30a1f362e99c93a127757aa471 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Mon, 27 Feb 2023 15:58:42 +0100 Subject: [PATCH 1/2] boot: Fix data model detection for ARM For whatever reason, ARM does not define __ILP32__. --- src/boot/efi/efi-string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/efi/efi-string.h b/src/boot/efi/efi-string.h index 410bfd8ef5..4df37a8505 100644 --- a/src/boot/efi/efi-string.h +++ b/src/boot/efi/efi-string.h @@ -126,7 +126,7 @@ _gnu_printf_(2, 0) _warn_unused_result_ char16_t *xvasprintf_status(EFI_STATUS s /* inttypes.h is provided by libc instead of the compiler and is not supposed to be used in freestanding * environments. We could use clang __*_FMT*__ constants for this, bug gcc does not have them. :( */ -# if defined(__ILP32__) +# if defined(__ILP32__) || defined(__arm__) # define PRI64_PREFIX "ll" # elif defined(__LP64__) # define PRI64_PREFIX "l" From ce7180b6804888698bea2656b7d8436c05872730 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Mon, 27 Feb 2023 18:43:07 +0100 Subject: [PATCH 2/2] boot: Provide div0 handlers for ARM This is a cleaner approach to 59833064742310bfccf028b0278811ba5cff8dcf. --- src/boot/efi/log.c | 22 ++++++++++++++++++++-- src/boot/efi/util.c | 6 ------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/boot/efi/log.c b/src/boot/efi/log.c index 4d8ad93716..9cbbb3a933 100644 --- a/src/boot/efi/log.c +++ b/src/boot/efi/log.c @@ -5,12 +5,16 @@ static unsigned log_count = 0; -void efi_assert(const char *expr, const char *file, unsigned line, const char *function) { - log_error("systemd-boot assertion '%s' failed at %s:%u@%s. Halting.", expr, file, line, function); +_noreturn_ static void freeze(void) { for (;;) BS->Stall(60 * 1000 * 1000); } +void efi_assert(const char *expr, const char *file, unsigned line, const char *function) { + log_error("systemd-boot assertion '%s' failed at %s:%u@%s. Halting.", expr, file, line, function); + freeze(); +} + EFI_STATUS log_internal(EFI_STATUS status, const char *format, ...) { assert(format); @@ -39,3 +43,17 @@ void log_wait(void) { BS->Stall(MIN(4u, log_count) * 2500 * 1000); log_count = 0; } + +#if defined(__ARM_EABI__) +/* These override the (weak) div0 handlers from libgcc as they would otherwise call raise() instead. */ + +_used_ _noreturn_ int __aeabi_idiv0(int return_value) { + log_error("Division by zero."); + freeze(); +} + +_used_ _noreturn_ long long __aeabi_ldiv0(long long return_value) { + log_error("Division by zero."); + freeze(); +} +#endif diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 19c4788b8f..588d60dd06 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -629,9 +629,3 @@ void *find_configuration_table(const EFI_GUID *guid) { return NULL; } - -/* libgcc's __aeabi_ldiv0 intrinsic will call raise() on division by zero, so we - * need to provide one ourselves for now. */ -_used_ _noreturn_ int raise(int sig) { - assert_not_reached(); -}