]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Fix build for x32
authorJan Janssen <medhefgo@web.de>
Sun, 9 Jul 2023 17:30:27 +0000 (19:30 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 10 Jul 2023 10:09:28 +0000 (11:09 +0100)
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).

meson.build
src/boot/efi/efi.h
src/boot/efi/meson.build

index 78d7c3dd5f37c997c34fba377bcf80135c63149e..adb21581e67d318a3c5977c10b74e9f4422609f1 100644 (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()
index b8d193154ea23130d63ad5d8927191d65dc15771..5c34668383f905831c0aca29e4b36e00ff4cbd01 100644 (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
index a963ce12d16c006cadabe2b5912c9d0a5d19ed07..bbffdf76c921bf07595516848fadaa43a8866c1a 100644 (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