sd-boot: Add assert implementation

There is a ASSERT() macro from gnu-efi, but that does not show any
output to ConOut. Having to do some additional setup just to get
some debug output is tedious and outright difficult on real hardware.
This commit is contained in:
Jan Janssen
2021-08-12 09:48:37 +02:00
parent b52fafb26d
commit 7a7267bf55
3 changed files with 30 additions and 3 deletions
+15
View File
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#ifndef NDEBUG
#include <efi.h>
#include <efilib.h>
#include "util.h"
void efi_assert(const char *expr, const char *file, unsigned line, const char *function) {
log_error_stall(L"systemd-boot assertion '%a' failed at %a:%u, function %a(). Halting.", expr, file, line, function);
for (;;)
uefi_call_wrapper(BS->Stall, 1, 60 * 1000 * 1000);
}
#endif
+7 -2
View File
@@ -17,6 +17,7 @@ efi_headers = files('''
'''.split())
common_sources = '''
assert.c
disk.c
graphics.c
measure.c
@@ -219,12 +220,16 @@ if have_gnu_efi
compile_args += ['-Werror']
endif
if get_option('buildtype') == 'debug'
compile_args += ['-ggdb', '-O0']
compile_args += ['-ggdb', '-O0', '-DEFI_DEBUG']
elif get_option('buildtype') == 'debugoptimized'
compile_args += ['-ggdb', '-Og']
compile_args += ['-ggdb', '-Og', '-DEFI_DEBUG']
else
compile_args += ['-O2']
endif
if get_option('b_ndebug') == 'true' or (
get_option('b_ndebug') == 'if-release' and ['plain', 'release'].contains(get_option('buildtype')))
compile_args += ['-DNDEBUG']
endif
efi_ldflags = ['-T', efi_lds,
'-shared',
+8 -1
View File
@@ -50,7 +50,14 @@
#define CONCATENATE(x, y) XCONCATENATE(x, y)
#ifdef SD_BOOT
#define assert(expr) do {} while (false)
#ifdef NDEBUG
#define assert(expr)
#define assert_not_reached() __builtin_unreachable()
#else
void efi_assert(const char *expr, const char *file, unsigned line, const char *function) _noreturn_;
#define assert(expr) ({ _likely_(expr) ? VOID_0 : efi_assert(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); })
#define assert_not_reached() efi_assert("Code should not be reached", __FILE__, __LINE__, __PRETTY_FUNCTION__)
#endif
#endif
#if defined(static_assert)