]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: Add LTO support
authorJan Janssen <medhefgo@web.de>
Wed, 10 Nov 2021 12:30:23 +0000 (13:30 +0100)
committerJan Janssen <medhefgo@web.de>
Mon, 29 Nov 2021 13:41:46 +0000 (14:41 +0100)
src/boot/efi/meson.build

index 4460af61f8edb48bd68dcb8e826970228f3e15b9..9281e146ea3aec04731d9ed83534c000e38d4439 100644 (file)
@@ -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',