From 3c86dcc39c3b7e0d4958196319d66a8aeaca19ec Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 09:56:32 +0200 Subject: [PATCH 01/10] sd-boot: Save and restore console attributes This also only writes the message on a new line if we aren't at the beginning of one already. --- src/boot/efi/util.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 9128c507c8..eb9745ce27 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -493,14 +493,21 @@ void log_error_stall(const CHAR16 *fmt, ...) { assert(fmt); + INT32 attr = ST->ConOut->Mode->Attribute; ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTRED|EFI_BACKGROUND_BLACK); - Print(L"\n"); + if (ST->ConOut->Mode->CursorColumn > 0) + Print(L"\n"); + va_start(args, fmt); VPrint(fmt, args); va_end(args); + Print(L"\n"); + ST->ConOut->SetAttribute(ST->ConOut, attr); + + /* Give the user a chance to see the message. */ BS->Stall(3 * 1000 * 1000); } From 1224d57ba533c8cda8a5b610588b7032b07492e1 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 10:56:17 +0200 Subject: [PATCH 02/10] sd-boot: Always compile with -ffreestanding and -fshort-wchar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not a hosted environment and we should not pretend otherwise if -ffreestanding is not supported. With EFI strings being in UCS2, it is not supported to build without -fshort-wchar as gcc/clang default to a w_char_t size of 4 bytes. This also makes the charset for wide chars explicit on gcc. This way we get a nice error message if anyone ever tries to add 💩 to strings. --- src/boot/efi/meson.build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index e6bb7d7c6a..5108cfa59e 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -197,11 +197,10 @@ if have_gnu_efi compile_args = cc.get_supported_arguments( basic_disabled_warnings + possible_common_cc_flags + [ - '-ffreestanding', '-fno-stack-protector', '-fno-strict-aliasing', '-fpic', - '-fshort-wchar', + '-fwide-exec-charset=UCS2', '-Wall', '-Wextra', '-Wsign-compare', @@ -209,6 +208,8 @@ if have_gnu_efi ) + [ '-nostdlib', '-std=gnu99', + '-ffreestanding', + '-fshort-wchar', '-isystem', efi_incdir, '-isystem', efi_incdir / gnu_efi_path_arch, '-I', fundamental_path, From a8a7723ba9d76bd97dd9ef882c772644bd241d3b Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 11:07:39 +0200 Subject: [PATCH 03/10] sd-boot: Move flags helpers to macro-fundamental.h --- src/basic/macro.h | 7 ------- src/fundamental/macro-fundamental.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/basic/macro.h b/src/basic/macro.h index 03a0d061b8..aa04039e80 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -328,13 +328,6 @@ static inline int __coverity_check_and_return__(int condition) { ans; \ }) -#define UPDATE_FLAG(orig, flag, b) \ - ((b) ? ((orig) | (flag)) : ((orig) & ~(flag))) -#define SET_FLAG(v, flag, b) \ - (v) = UPDATE_FLAG(v, flag, b) -#define FLAGS_SET(v, flags) \ - ((~(v) & (flags)) == 0) - #define SWAP_TWO(x, y) do { \ typeof(x) _t = (x); \ (x) = (y); \ diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index ed527adb77..44af0bd0a0 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -306,3 +306,10 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { (l <= SIZE_MAX - (ali - 1)), /* overflow? */ \ ((l) + (ali) - 1) & ~((ali) - 1), \ VOID_0) + +#define UPDATE_FLAG(orig, flag, b) \ + ((b) ? ((orig) | (flag)) : ((orig) & ~(flag))) +#define SET_FLAG(v, flag, b) \ + (v) = UPDATE_FLAG(v, flag, b) +#define FLAGS_SET(v, flags) \ + ((~(v) & (flags)) == 0) From 785b5fcf5f692a1b3788cee2fb0f076ca78572c0 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 12:17:31 +0200 Subject: [PATCH 04/10] sd-boot: Use FLAGS_SET --- src/boot/efi/boot.c | 10 +++++----- src/boot/efi/cpio.c | 2 +- src/boot/efi/drivers.c | 2 +- src/boot/efi/util.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index db0c22d405..b2b763beee 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -551,7 +551,7 @@ static EFI_STATUS reboot_into_firmware(void) { UINT64 osind = 0; EFI_STATUS err; - if (!(get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) + if (!FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) return log_error_status_stall(EFI_UNSUPPORTED, L"Reboot to firmware interface not supported."); (void) efivar_get_uint64_le(EFI_GLOBAL_GUID, L"OsIndications", &osind); @@ -924,7 +924,7 @@ static BOOLEAN menu_run( case KEYPRESS(0, SCAN_F10, 0): /* HP and Lenovo. */ case KEYPRESS(0, SCAN_DELETE, 0): /* Same as F2. */ case KEYPRESS(0, SCAN_ESC, 0): /* HP. */ - if (get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) { + if (FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) { firmware_setup = TRUE; /* Let's make sure the user really wants to do this. */ status = PoolPrint(L"Press Enter to reboot into firmware interface."); @@ -1590,7 +1590,7 @@ static void config_load_entries( if (f->FileName[0] == '.') continue; - if (f->Attribute & EFI_FILE_DIRECTORY) + if (FLAGS_SET(f->Attribute, EFI_FILE_DIRECTORY)) continue; if (!endswith_no_case(f->FileName, L".conf")) @@ -2046,7 +2046,7 @@ static void config_entry_add_linux( if (f->FileName[0] == '.') continue; - if (f->Attribute & EFI_FILE_DIRECTORY) + if (FLAGS_SET(f->Attribute, EFI_FILE_DIRECTORY)) continue; if (!endswith_no_case(f->FileName, L".efi")) continue; @@ -2352,7 +2352,7 @@ static void config_load_all_entries( config_entry_add_loader_auto(config, loaded_image->DeviceHandle, root_dir, loaded_image_path, L"auto-efi-default", '\0', L"EFI Default Loader", NULL); - if (config->auto_firmware && (get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) + if (config->auto_firmware && FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) config_entry_add_call(config, L"auto-reboot-to-firmware-setup", L"Reboot Into Firmware Interface", diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index bb7c988031..1818fbedd0 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -375,7 +375,7 @@ EFI_STATUS pack_cpio( if (dirent->FileName[0] == '.') continue; - if (dirent->Attribute & EFI_FILE_DIRECTORY) + if (FLAGS_SET(dirent->Attribute, EFI_FILE_DIRECTORY)) continue; if (match_suffix && !endswith_no_case(dirent->FileName, match_suffix)) continue; diff --git a/src/boot/efi/drivers.c b/src/boot/efi/drivers.c index 3ae8f0dde7..4bb4dedaa0 100644 --- a/src/boot/efi/drivers.c +++ b/src/boot/efi/drivers.c @@ -103,7 +103,7 @@ EFI_STATUS load_drivers( if (dirent->FileName[0] == '.') continue; - if (dirent->Attribute & EFI_FILE_DIRECTORY) + if (FLAGS_SET(dirent->Attribute, EFI_FILE_DIRECTORY)) continue; if (!endswith_no_case(dirent->FileName, EFI_MACHINE_TYPE_NAME L".efi")) continue; diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index eb9745ce27..4d981ca7e5 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -741,7 +741,7 @@ EFI_STATUS open_directory( err = get_file_info_harder(dir, &file_info, NULL); if (EFI_ERROR(err)) return err; - if (!(file_info->Attribute & EFI_FILE_DIRECTORY)) + if (!FLAGS_SET(file_info->Attribute, EFI_FILE_DIRECTORY)) return EFI_LOAD_ERROR; *ret = TAKE_PTR(dir); From ff9d65f6ffa72a28911ce53bcb7ac5dd277e218a Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 12:25:41 +0200 Subject: [PATCH 05/10] sd-boot: Move optional header verification into verify_pe --- src/boot/efi/pe.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c index 6aecfe4526..e87b720dfa 100644 --- a/src/boot/efi/pe.c +++ b/src/boot/efi/pe.c @@ -122,7 +122,8 @@ static inline BOOLEAN verify_pe(const struct PeFileHeader *pe) { return CompareMem(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 && pe->FileHeader.Machine == TARGET_MACHINE_TYPE && pe->FileHeader.NumberOfSections > 0 && - pe->FileHeader.NumberOfSections <= MAX_SECTIONS; + pe->FileHeader.NumberOfSections <= MAX_SECTIONS && + IN_SET(pe->OptionalHeader.Magic, OPTHDR32_MAGIC, OPTHDR64_MAGIC); } static inline UINTN section_table_offset(const struct DosFileHeader *dos, const struct PeFileHeader *pe) { @@ -182,15 +183,8 @@ EFI_STATUS pe_alignment_info( return EFI_LOAD_ERROR; *ret_entry_point_address = pe->OptionalHeader.AddressOfEntryPoint; - - if (pe->OptionalHeader.Magic == OPTHDR32_MAGIC) { - *ret_size_of_image = pe->OptionalHeader.SizeOfImage; - *ret_section_alignment = pe->OptionalHeader.SectionAlignment; - } else if (pe->OptionalHeader.Magic == OPTHDR64_MAGIC) { - *ret_size_of_image = pe->OptionalHeader.SizeOfImage; - *ret_section_alignment = pe->OptionalHeader.SectionAlignment; - } else - return EFI_UNSUPPORTED; + *ret_size_of_image = pe->OptionalHeader.SizeOfImage; + *ret_section_alignment = pe->OptionalHeader.SectionAlignment; return EFI_SUCCESS; } From 65ff3d2626b6838b6c709eba6c6333c85f6c8d3b Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 12:33:43 +0200 Subject: [PATCH 06/10] sd-boot: Check for existence of required pe sections --- src/boot/efi/boot.c | 40 +++++++++++++++++++++++++--------------- src/boot/efi/stub.c | 7 +++++-- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index b2b763beee..296efdd489 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -2026,16 +2026,23 @@ static void config_entry_add_linux( return; for (;;) { + enum { + SECTION_CMDLINE, + SECTION_OSREL, + _SECTION_MAX, + }; + + static const CHAR8* const sections[_SECTION_MAX + 1] = { + [SECTION_CMDLINE] = (const CHAR8 *) ".cmdline", + [SECTION_OSREL] = (const CHAR8 *) ".osrel", + NULL, + }; + _cleanup_freepool_ CHAR16 *os_name_pretty = NULL, *os_name = NULL, *os_id = NULL, *os_version = NULL, *os_version_id = NULL, *os_build_id = NULL, *os_image_version = NULL; _cleanup_freepool_ CHAR8 *content = NULL; - const CHAR8 *sections[] = { - (CHAR8 *)".osrel", - (CHAR8 *)".cmdline", - NULL - }; - UINTN offs[ELEMENTSOF(sections)-1] = {}; - UINTN szs[ELEMENTSOF(sections)-1] = {}; + UINTN offs[_SECTION_MAX] = {}; + UINTN szs[_SECTION_MAX] = {}; CHAR8 *line; UINTN pos = 0; CHAR8 *key, *value; @@ -2054,11 +2061,11 @@ static void config_entry_add_linux( continue; /* look for .osrel and .cmdline sections in the .efi binary */ - err = pe_file_locate_sections(linux_dir, f->FileName, sections, offs, szs); - if (EFI_ERROR(err)) + err = pe_file_locate_sections(linux_dir, f->FileName, (const CHAR8**) sections, offs, szs); + if (EFI_ERROR(err) || szs[SECTION_OSREL] == 0) continue; - err = file_read(linux_dir, f->FileName, offs[0], szs[0], &content, NULL); + err = file_read(linux_dir, f->FileName, offs[SECTION_OSREL], szs[SECTION_OSREL], &content, NULL); if (EFI_ERROR(err)) continue; @@ -2122,21 +2129,24 @@ static void config_entry_add_linux( path, os_image_version ?: (os_version ?: (os_version_id ? : os_build_id))); + config_entry_parse_tries(entry, L"\\EFI\\Linux", f->FileName, L".efi"); + + if (szs[SECTION_CMDLINE] == 0) + continue; + FreePool(content); content = NULL; /* read the embedded cmdline file */ - err = file_read(linux_dir, f->FileName, offs[1], szs[1], &content, NULL); + err = file_read(linux_dir, f->FileName, offs[SECTION_CMDLINE], szs[SECTION_CMDLINE], &content, NULL); if (!EFI_ERROR(err)) { /* chomp the newline */ - if (content[szs[1]-1] == '\n') - content[szs[1]-1] = '\0'; + if (content[szs[SECTION_CMDLINE] - 1] == '\n') + content[szs[SECTION_CMDLINE] - 1] = '\0'; entry->options = stra_to_str(content); } - - config_entry_parse_tries(entry, L"\\EFI\\Linux", f->FileName, L".efi"); } } } diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 256aa21827..52d26e7cd2 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -154,7 +154,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { _SECTION_MAX, }; - const CHAR8* const sections[] = { + static const CHAR8* const sections[_SECTION_MAX + 1] = { [SECTION_CMDLINE] = (const CHAR8*) ".cmdline", [SECTION_LINUX] = (const CHAR8*) ".linux", [SECTION_INITRD] = (const CHAR8*) ".initrd", @@ -187,8 +187,11 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { return log_error_status_stall(err, L"Error getting a LoadedImageProtocol handle: %r", err); err = pe_memory_locate_sections(loaded_image->ImageBase, (const CHAR8**) sections, addrs, szs); - if (EFI_ERROR(err)) + if (EFI_ERROR(err) || szs[SECTION_LINUX] == 0) { + if (!EFI_ERROR(err)) + err = EFI_NOT_FOUND; return log_error_status_stall(err, L"Unable to locate embedded .linux section: %r", err); + } /* Show splash screen as early as possible */ graphics_splash((const UINT8*) loaded_image->ImageBase + addrs[SECTION_SPLASH], szs[SECTION_SPLASH], NULL); From 1f6f233f8714e36f7623b6af08dc3154c3b390f8 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 12:39:16 +0200 Subject: [PATCH 07/10] sd-stub: Fix possible memory leak --- src/boot/efi/stub.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 52d26e7cd2..4de23792b5 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -172,6 +172,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { UINTN addrs[_SECTION_MAX] = {}; UINTN szs[_SECTION_MAX] = {}; CHAR8 *cmdline = NULL; + _cleanup_freepool_ CHAR8 *cmdline_owned = NULL; EFI_STATUS err; InitializeLib(image, sys_table); @@ -204,18 +205,13 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { /* if we are not in secure boot mode, or none was provided, accept a custom command line and replace the built-in one */ if ((!secure_boot_enabled() || cmdline_len == 0) && loaded_image->LoadOptionsSize > 0 && *(CHAR16 *) loaded_image->LoadOptions > 0x1F) { - CHAR16 *options; - CHAR8 *line; - - options = (CHAR16 *)loaded_image->LoadOptions; cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8); - line = AllocatePool(cmdline_len); - if (!line) + cmdline = cmdline_owned = AllocatePool(cmdline_len); + if (!cmdline) return log_oom(); for (UINTN i = 0; i < cmdline_len; i++) - line[i] = options[i]; - cmdline = line; + cmdline[i] = ((CHAR16 *) loaded_image->LoadOptions)[i]; /* Let's measure the passed kernel command line into the TPM. Note that this possibly * duplicates what we already did in the boot menu, if that was already used. However, since From f8a738bbc059071a7f218fd787ff6096fca90b82 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Mon, 1 Nov 2021 10:36:12 +0100 Subject: [PATCH 08/10] sd-boot: Add some link flags These flags are used by gnu-efi. Adding --no-undefined even allows us to drop the no-undefined-symbols.sh test in favor of immediate compile time errors. --- src/boot/efi/meson.build | 10 +++------- src/boot/efi/no-undefined-symbols.sh | 9 --------- 2 files changed, 3 insertions(+), 16 deletions(-) delete mode 100755 src/boot/efi/no-undefined-symbols.sh diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index 5108cfa59e..dd42e20fbd 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -258,6 +258,9 @@ if have_gnu_efi '-shared', '-Bsymbolic', '-nostdlib', + '--no-undefined', + '--warn-common', + '--fatal-warnings', '-znocombreloc', '--build-id=sha1', '-L', efi_libdir, @@ -292,7 +295,6 @@ if have_gnu_efi systemd_boot_efi_name = 'systemd-boot@0@.efi'.format(EFI_MACHINE_TYPE_NAME) stub_elf_name = 'linux@0@.elf.stub'.format(EFI_MACHINE_TYPE_NAME) stub_efi_name = 'linux@0@.efi.stub'.format(EFI_MACHINE_TYPE_NAME) - no_undefined_symbols = find_program('no-undefined-symbols.sh') efi_stubs = [] foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects, false], @@ -326,12 +328,6 @@ if have_gnu_efi install_dir : bootlibdir) efi_stubs += [[so, stub]] - - if want_tests != 'false' - test('no-undefined-symbols-' + tuple[0], - no_undefined_symbols, - args : so) - endif endforeach ############################################################ diff --git a/src/boot/efi/no-undefined-symbols.sh b/src/boot/efi/no-undefined-symbols.sh deleted file mode 100755 index 8bdb16accf..0000000000 --- a/src/boot/efi/no-undefined-symbols.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eu -set -o pipefail - -if nm -D -u "${1:?}" | grep ' U '; then - echo "Undefined symbols detected!" - exit 1 -fi From 1840dfc327805dbc7b8f729e090c129019b08cca Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 2 Nov 2021 10:21:19 +0100 Subject: [PATCH 09/10] sd-boot: Detect supported compile args This brings the final list of compiler arguments more in line with how meson does things. In particular, --buildtype=plain will not add any optimizations on its own (and would have to be provided through CFLAGS=). --- src/boot/efi/meson.build | 47 ++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index dd42e20fbd..a0f9243b5b 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -45,6 +45,12 @@ stub_sources = ''' cpio.c '''.split() +if ['ia32', 'x86_64'].contains(efi_arch) + stub_sources += 'linux_x86.c' +else + stub_sources += 'linux.c' +endif + if conf.get('ENABLE_EFI') == 1 and get_option('gnu-efi') != 'false' efi_cc = get_option('efi-cc') if efi_cc.length() == 0 @@ -218,11 +224,7 @@ if have_gnu_efi '-include', efi_config_h, '-include', version_h, ] - if ['ia32', 'x86_64'].contains(efi_arch) - stub_sources += 'linux_x86.c' - else - stub_sources += 'linux.c' - endif + if efi_arch == 'x86_64' compile_args += ['-mno-red-zone', '-mno-sse', @@ -231,29 +233,36 @@ if have_gnu_efi compile_args += ['-mno-sse', '-mno-mmx'] elif efi_arch == 'arm' - if cc.has_argument('-mgeneral-regs-only') - compile_args += ['-mgeneral-regs-only'] - endif - - if cc.has_argument('-mfpu=none') - compile_args += ['-mfpu=none'] - endif + compile_args += cc.get_supported_arguments([ + '-mgeneral-regs-only', + '-mfpu=none' + ]) endif - if get_option('werror') == true + + # We are putting the efi_cc command line together ourselves, so make sure to pull any + # relevant compiler flags from meson/CFLAGS as povided by the user or distro. + + if get_option('werror') compile_args += ['-Werror'] endif - if get_option('buildtype') == 'debug' - compile_args += ['-ggdb', '-O0', '-DEFI_DEBUG'] - elif get_option('buildtype') == 'debugoptimized' - compile_args += ['-ggdb', '-Og', '-DEFI_DEBUG'] - else - compile_args += ['-O2'] + if get_option('debug') + compile_args += ['-ggdb', '-DEFI_DEBUG'] + endif + if get_option('optimization') != '0' + compile_args += ['-O' + get_option('optimization')] 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 + foreach arg : get_option('c_args') + if arg in ['-Werror', '-g', '-ggdb', '-O1', '-O2', '-O3', '-Og', '-Os', '-DNDEBUG'] + message('Using "@0@" from c_args for EFI compiler'.format(arg)) + compile_args += arg + endif + endforeach + efi_ldflags = ['-T', efi_lds, '-shared', '-Bsymbolic', From d1da89000467387c90967558f481235dc66f347c Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 2 Nov 2021 10:47:41 +0100 Subject: [PATCH 10/10] sd-boot: Fix efi_arch checks efi_arch is set to whatever meson returns from host_machine.cpu_family() and gnu_efi_arch is then set accordingly. On x86, efi_arch == x86 and gnu_efi_arch == ia32. Surprisingly, compilation worked (without disabling some instruction sets) and nobody ever complained about systemd-bootia32.efi not working. --- src/boot/efi/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index a0f9243b5b..40b0ab0dbd 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -45,7 +45,7 @@ stub_sources = ''' cpio.c '''.split() -if ['ia32', 'x86_64'].contains(efi_arch) +if efi_arch in ['x86', 'x86_64'] stub_sources += 'linux_x86.c' else stub_sources += 'linux.c' @@ -229,7 +229,7 @@ if have_gnu_efi compile_args += ['-mno-red-zone', '-mno-sse', '-mno-mmx'] - elif efi_arch == 'ia32' + elif efi_arch == 'x86' compile_args += ['-mno-sse', '-mno-mmx'] elif efi_arch == 'arm'