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).
This commit is contained in:
Jan Janssen 2023-07-09 19:30:27 +02:00 committed by Luca Boccassi
parent e1819eb062
commit 7ea44f1733
3 changed files with 35 additions and 24 deletions

View file

@ -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 <limits.h>
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()

View file

@ -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 <uchar.h>
# include <wchar.h>
@ -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

View file

@ -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