From: Jan Janssen Date: Wed, 10 Nov 2021 12:30:23 +0000 (+0100) Subject: sd-boot: Add LTO support X-Git-Tag: v250-rc1~39^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b848b7e166e476d7113e4ac836212e23b0ae4525;p=thirdparty%2Fsystemd.git sd-boot: Add LTO support --- diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index 4460af61f8e..9281e146ea3 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -244,9 +244,12 @@ if get_option('b_ndebug') == 'true' or ( get_option('b_ndebug') == 'if-release' and get_option('buildtype') in ['plain', 'release']) efi_cflags += ['-DNDEBUG'] endif +if get_option('b_lto') + efi_cflags += ['-flto'] +endif foreach arg : get_option('c_args') - if arg in ['-Werror', '-g', '-ggdb', '-O1', '-O2', '-O3', '-Og', '-Os', '-DNDEBUG'] + if arg in ['-Werror', '-g', '-ggdb', '-O1', '-O2', '-O3', '-Og', '-Os', '-DNDEBUG', '-flto', '-fno-lto'] message('Using "@0@" from c_args for EFI compiler'.format(arg)) efi_cflags += arg endif @@ -256,7 +259,6 @@ efi_ldflags = [ '-fuse-ld=' + get_option('efi-ld'), '-L', efi_libdir, '-nostdlib', - '-shared', '-T', efi_lds, '-Wl,--build-id=sha1', '-Wl,--fatal-warnings', @@ -267,11 +269,16 @@ efi_ldflags = [ efi_crt0, ] if efi_arch[1] in ['aarch64', 'arm', 'riscv64'] + efi_ldflags += ['-shared', '-fwhole-program'] # Aarch64, ARM32 and 64bit RISC-V don't have an EFI capable objcopy. # Use 'binary' instead, and add required symbols manually. efi_ldflags += ['-Wl,--defsym=EFI_SUBSYSTEM=0xa'] efi_format = ['-O', 'binary'] else + efi_ldflags += ['-pie'] + if get_option('efi-ld') == 'bfd' + efi_ldflags += '-Wl,--no-dynamic-linker' + endif efi_format = ['--target=efi-app-@0@'.format(efi_arch[1])] endif @@ -325,7 +332,7 @@ foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects tuple[0], input : tuple[2], output : tuple[0], - command : [efi_cc, '-o', '@OUTPUT@', efi_ldflags, tuple[2], '-lefi', '-lgnuefi', '-lgcc'], + command : [efi_cc, '-o', '@OUTPUT@', efi_ldflags, efi_cflags, tuple[2], '-lefi', '-lgnuefi', '-lgcc'], install : tuple[3], install_dir : bootlibdir) @@ -334,6 +341,7 @@ foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects input : so, output : tuple[1], command : [objcopy, + '-j', '.bss*', '-j', '.data', '-j', '.dynamic', '-j', '.dynsym',