diff --git a/meson.build b/meson.build index bc7a8f76e8..4c0dd6f8c9 100644 --- a/meson.build +++ b/meson.build @@ -3912,6 +3912,7 @@ if conf.get('ENABLE_EFI') == 1 and conf.get('HAVE_GNU_EFI') == 1 summary({ 'EFI machine type' : efi_arch[0], 'EFI CC' : '@0@'.format(' '.join(efi_cc)), + 'EFI LD' : efi_ld, 'EFI lds' : efi_lds, 'EFI crt0' : efi_crt0, 'EFI include directory' : efi_incdir}, diff --git a/meson_options.txt b/meson_options.txt index 914434e37c..4d406b3e50 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -415,7 +415,7 @@ option('efi-cc', type : 'array', description : 'the compiler to use for EFI modules') # Note that LLD does not support PE/COFF relocations # https://lists.llvm.org/pipermail/llvm-dev/2021-March/149234.html -option('efi-ld', type : 'combo', choices : ['bfd', 'gold'], +option('efi-ld', type : 'combo', choices : ['auto', 'bfd', 'gold'], description : 'the linker to use for EFI modules') option('efi-libdir', type : 'string', description : 'path to the EFI lib directory') diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index c095512bfb..d92fe0e5ec 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -48,6 +48,15 @@ if efi_cc.length() == 0 efi_cc = cc.cmd_array() endif +efi_ld = get_option('efi-ld') +if efi_ld == 'auto' + efi_ld = cc.get_linker_id().split('.')[1] + if efi_ld not in ['bfd', 'gold'] + warning('Not using @0@ as efi-ld, falling back to bfd'.format(efi_ld)) + efi_ld = 'bfd' + endif +endif + efi_libdir = '' foreach dir : [get_option('efi-libdir'), '/usr/lib/gnuefi' / efi_arch[0], @@ -256,7 +265,7 @@ foreach arg : get_option('c_args') endforeach efi_ldflags = [ - '-fuse-ld=' + get_option('efi-ld'), + '-fuse-ld=' + efi_ld, '-L', efi_libdir, '-nostdlib', '-T', efi_lds, @@ -276,7 +285,7 @@ if efi_arch[1] in ['aarch64', 'arm', 'riscv64'] efi_format = ['-O', 'binary'] else efi_ldflags += ['-pie'] - if get_option('efi-ld') == 'bfd' + if efi_ld == 'bfd' efi_ldflags += '-Wl,--no-dynamic-linker' endif efi_format = ['--target=efi-app-@0@'.format(efi_arch[1])]