From: Jan Janssen Date: Sun, 5 Jun 2022 15:35:03 +0000 (+0200) Subject: boot: Stop linking against libefi.a X-Git-Tag: v253-rc1~22^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1d278ad7d4635eed33bad73dd3fbd563d3ce0209;p=thirdparty%2Fsystemd.git boot: Stop linking against libefi.a libefi.a just provided the c helper API that was slowly removed. As we do not depend on anything provided by it anymore, it is safe to drop now. Since the ST/BS/RT pointers are very convenient and needed everywhere, they are retained and initialized by us. --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 8d0d547a898..f3d009bee85 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -2748,3 +2748,8 @@ out: } DEFINE_EFI_MAIN_FUNCTION(run, "systemd-boot", /*wait_for_debugger=*/false); + +/* Fedora has a heavily patched gnu-efi that supports elf constructors. It calls into _entry instead. */ +EFI_STATUS _entry(EFI_HANDLE image, EFI_SYSTEM_TABLE *system_table) { + return efi_main(image, system_table); +} diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c index 860dfc00b2c..22923d60f62 100644 --- a/src/boot/efi/efi-string.c +++ b/src/boot/efi/efi-string.c @@ -901,7 +901,7 @@ _used_ int memcmp(const void *p1, const void *p2, size_t n) { return 0; } -_used_ _weak_ void *memcpy(void * restrict dest, const void * restrict src, size_t n) { +_used_ void *memcpy(void * restrict dest, const void * restrict src, size_t n) { if (!dest || !src || n == 0) return dest; @@ -928,7 +928,7 @@ _used_ _weak_ void *memcpy(void * restrict dest, const void * restrict src, size return dest; } -_used_ _weak_ void *memset(void *p, int c, size_t n) { +_used_ void *memset(void *p, int c, size_t n) { if (!p || n == 0) return p; diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index eaa50e0e697..d5a8f14788e 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -295,23 +295,6 @@ if efi_arch[1] == 'arm' efi_ldflags += ['-Wl,--no-wchar-size-warning'] endif -if run_command('grep', '-q', '__CTOR_LIST__', efi_lds, check: false).returncode() == 0 - # fedora has a patched gnu-efi that adds support for ELF constructors. - # If ld is called by gcc something about these symbols breaks, resulting - # in sd-boot freezing when gnu-efi runs the constructors. Force defining - # them seems to work around this. - efi_ldflags += [ - '-Wl,--defsym=_init_array=0', - '-Wl,--defsym=_init_array_end=0', - '-Wl,--defsym=_fini_array=0', - '-Wl,--defsym=_fini_array_end=0', - '-Wl,--defsym=__CTOR_LIST__=0', - '-Wl,--defsym=__CTOR_END__=0', - '-Wl,--defsym=__DTOR_LIST__=0', - '-Wl,--defsym=__DTOR_END__=0', - ] -endif - if cc.get_id() == 'clang' and cc.version().split('.')[0].to_int() <= 10 # clang <= 10 doesn't pass -T to the linker and then even complains about it being unused efi_ldflags += ['-Wl,-T,' + efi_lds, '-Wno-unused-command-line-argument'] @@ -445,7 +428,6 @@ foreach tuple : [['systemd-boot@0@.@1@', systemd_boot_objects, false, 'systemd-b efi_cflags, efi_ldflags, '@INPUT@', - '-lefi', '-lgnuefi', '-lgcc'], install : tuple[2], diff --git a/src/boot/efi/secure-boot.c b/src/boot/efi/secure-boot.c index 952e92923e7..c8a3957b1e1 100644 --- a/src/boot/efi/secure-boot.c +++ b/src/boot/efi/secure-boot.c @@ -124,7 +124,7 @@ EFI_STATUS secure_boot_enroll_at(EFI_FILE *root_dir, const char16_t *path) { out_deallocate: for (size_t i = 0; i < ELEMENTSOF(sb_vars); i++) - FreePool(sb_vars[i].buffer); + free(sb_vars[i].buffer); return err; } diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index e2b5b6f5370..1dfc702acda 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -418,3 +418,8 @@ static EFI_STATUS run(EFI_HANDLE image) { } DEFINE_EFI_MAIN_FUNCTION(run, "systemd-stub", /*wait_for_debugger=*/false); + +/* See comment in boot.c. */ +EFI_STATUS _entry(EFI_HANDLE image, EFI_SYSTEM_TABLE *system_table) { + return efi_main(image, system_table); +} diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 51cc3cc6b40..0658eae98ec 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -180,8 +180,13 @@ void hexdump(const char16_t *prefix, const void *data, size_t size); #endif #define DEFINE_EFI_MAIN_FUNCTION(func, identity, wait_for_debugger) \ + EFI_SYSTEM_TABLE *ST; \ + EFI_BOOT_SERVICES *BS; \ + EFI_RUNTIME_SERVICES *RT; \ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *system_table) { \ - InitializeLib(image, system_table); \ + ST = system_table; \ + BS = system_table->BootServices; \ + RT = system_table->RuntimeServices; \ notify_debugger((identity), (wait_for_debugger)); \ EFI_STATUS err = func(image); \ log_wait(); \