From: Jan Janssen Date: Sun, 9 Jul 2023 17:30:27 +0000 (+0200) Subject: boot: Fix build for x32 X-Git-Tag: v254-rc2~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7ea44f1733821f7d79f08236c565638eef18782d;p=thirdparty%2Fsystemd.git boot: Fix build for x32 When building on a x32 system we need to explicitly pass `-m64` to get the right ABI as the kernel and EFI are still 64bit. For this to actually work, a suitable multilib compiler, 32bit libc headers and libgcc need to be installed (similar to ia32 builds on x86_64). --- diff --git a/meson.build b/meson.build index 78d7c3dd5f3..adb21581e67 100644 --- a/meson.build +++ b/meson.build @@ -2132,12 +2132,14 @@ elif get_option('bootloader') == 'true' and efi_arch == '' endif efi_arch_alt = '' +efi_cpu_family_alt = '' if efi_arch == 'x64' and cc.links(''' #include int main(int argc, char *argv[]) { return __builtin_popcount(argc - CHAR_MAX); }''', args : ['-m32', '-march=i686'], name : '32bit build possible') efi_arch_alt = 'ia32' + efi_cpu_family_alt = 'x86' endif have_pyelftools = pymod.find_installation('python3', required : false, modules : ['elftools']).found() diff --git a/src/boot/efi/efi.h b/src/boot/efi/efi.h index b8d193154ea..5c34668383f 100644 --- a/src/boot/efi/efi.h +++ b/src/boot/efi/efi.h @@ -26,6 +26,10 @@ assert_cc(sizeof(char16_t) == 2); assert_cc(sizeof(char32_t) == 4); assert_cc(sizeof(size_t) == sizeof(void *)); assert_cc(sizeof(size_t) == sizeof(uintptr_t)); + +# if defined(__x86_64__) && defined(__ILP32__) +# error Building for x64 requires -m64 on x32 ABI. +# endif #else # include # include @@ -41,7 +45,7 @@ typedef size_t EFI_TPL; typedef uint64_t EFI_LBA; typedef uint64_t EFI_PHYSICAL_ADDRESS; -#if defined(__x86_64__) +#if defined(__x86_64__) && !defined(__ILP32__) # define EFIAPI __attribute__((ms_abi)) #else # define EFIAPI diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index a963ce12d16..bbffdf76c92 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -203,29 +203,20 @@ if cc.get_id() == 'clang' efi_c_ld_args += '-Wno-unused-command-line-argument' endif -if host_machine.cpu_family() == 'arm' - # libgcc is not compiled with -fshort-wchar, but it does not use it anyways, - # so it's fine to link against it. - efi_c_ld_args += '-Wl,--no-wchar-size-warning' -endif - -efi_c_args_primary = [efi_c_args, '-DEFI_MACHINE_TYPE_NAME="' + efi_arch + '"'] -efi_c_args_alt = [efi_c_args, '-DEFI_MACHINE_TYPE_NAME="' + efi_arch_alt + '"'] -efi_c_ld_args_primary = efi_c_ld_args -efi_c_ld_args_alt = efi_c_ld_args - efi_arch_c_args = { 'aarch64' : ['-mgeneral-regs-only'], 'arm' : ['-mgeneral-regs-only'], - 'x86_64' : ['-march=x86-64', '-mno-red-zone', '-mgeneral-regs-only'], - 'x86' : ['-march=i686', '-mgeneral-regs-only', '-malign-double'], + # Pass -m64/32 explicitly to make building on x32 work. + 'x86_64' : ['-m64', '-march=x86-64', '-mno-red-zone', '-mgeneral-regs-only'], + 'x86' : ['-m32', '-march=i686', '-mgeneral-regs-only', '-malign-double'], +} +efi_arch_c_ld_args = { + # libgcc is not compiled with -fshort-wchar, but it does not use it anyways, + # so it's fine to link against it. + 'arm' : ['-Wl,--no-wchar-size-warning'], + 'x86_64' : ['-m64'], + 'x86' : ['-m32'], } -efi_c_args_primary += efi_arch_c_args.get(host_machine.cpu_family(), []) - -if efi_arch_alt == 'ia32' - efi_c_args_alt += ['-m32', efi_arch_c_args['x86']] - efi_c_ld_args_alt += '-m32' -endif ############################################################ @@ -282,15 +273,29 @@ efi_elf_binaries = [] efi_archspecs = [ { 'arch' : efi_arch, - 'c_args' : efi_c_args_primary, - 'link_args' : efi_c_ld_args_primary, + 'c_args' : [ + efi_c_args, + '-DEFI_MACHINE_TYPE_NAME="' + efi_arch + '"', + efi_arch_c_args.get(host_machine.cpu_family(), []), + ], + 'link_args' : [ + efi_c_ld_args, + efi_arch_c_ld_args.get(host_machine.cpu_family(), []), + ], }, ] if efi_arch_alt != '' efi_archspecs += { 'arch' : efi_arch_alt, - 'c_args' : efi_c_args_alt, - 'link_args' : efi_c_ld_args_alt, + 'c_args' : [ + efi_c_args, + '-DEFI_MACHINE_TYPE_NAME="' + efi_arch_alt + '"', + efi_arch_c_args.get(efi_cpu_family_alt, []), + ], + 'link_args' : [ + efi_c_ld_args, + efi_arch_c_ld_args.get(efi_cpu_family_alt, []), + ], } endif