]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: fix ia32 build with clang
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 May 2025 11:37:43 +0000 (13:37 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 19 May 2025 15:00:28 +0000 (16:00 +0100)
After 668d915a4bea202e739a9bd3f895c7269f320659, the build fails:
[7/14] Linking target src/boot/systemd-bootia32.elf
FAILED: src/boot/systemd-bootia32.elf
clang  -o src/boot/systemd-bootia32.elf src/boot/systemd-bootia32.elf.p/boot.c.o src/boot/systemd-bootia32.elf.p/line-edit.c.o src/boot/systemd-bootia32.elf.p/bcd.c.o -Wl,--as-needed -Wl,--no-undefined -pie -fstack-protector src/boot/libefiia32.a -nostdlib -static-pie -Wl,--entry=efi_main -Wl,--fatal-warnings -Wl,-static,-pie,--no-dynamic-linker,-z,text -z common-page-size=4096 -z max-page-size=4096 -z noexecstack -z relro -z separate-code -Wl,-z,nopack-relative-relocs -fcf-protection=none -fno-asynchronous-unwind-tables -fno-exceptions -fno-unwind-tables -fno-sanitize=all -Wno-unused-command-line-argument -m32
/usr/sbin/ld: src/boot/libefiia32.a.p/console.c.o: in function `console_set_mode':
/home/zbyszek/src/systemd-work/build-clang/../src/boot/console.c:267:(.text+0xb8f): undefined reference to `__moddi3'
/usr/sbin/ld: src/boot/libefiia32.a.p/console.c.o: in function `get_auto_mode':
/home/zbyszek/src/systemd-work/build-clang/../src/boot/console.c:228:(.text+0xf18): undefined reference to `__udivdi3'
/usr/sbin/ld: src/boot/libefiia32.a.p/efi-string.c.o: in function `push_num':
/home/zbyszek/src/systemd-work/build-clang/../src/boot/efi-string.c:695:(.text+0x3c1a): undefined reference to `__moddi3'
/usr/sbin/ld: /home/zbyszek/src/systemd-work/build-clang/../src/boot/efi-string.c:696:(.text+0x3c54): undefined reference to `__divdi3'
/usr/sbin/ld: /home/zbyszek/src/systemd-work/build-clang/../src/boot/efi-string.c:702:(.text+0x3cda): undefined reference to `__umoddi3'
/usr/sbin/ld: /home/zbyszek/src/systemd-work/build-clang/../src/boot/efi-string.c:703:(.text+0x3d0a): undefined reference to `__udivdi3'
/usr/sbin/ld: src/boot/libefiia32.a.p/ticks.c.o: in function `time_usec':
/home/zbyszek/src/systemd-work/build-clang/../src/boot/ticks.c:110:(.text+0x9d): undefined reference to `__udivdi3'
/usr/sbin/ld: src/boot/libefiia32.a.p/ticks.c.o: in function `ticks_freq_arch':
/home/zbyszek/src/systemd-work/build-clang/../src/boot/ticks.c:46:(.text+0x394): undefined reference to `__udivdi3'
/usr/sbin/ld: /home/zbyszek/src/systemd-work/build-clang/../src/boot/ticks.c:49:(.text+0x3ce): undefined reference to `__udivdi3'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Restore the use of -lgcc for 32-bit builds.

(FWIW, neither --rtlib=compiler-rt nor --rtlib=libgcc help.)

src/boot/meson.build

index 42201af9092ad5a48153f9463ec31166aa5f282b..570ea2079e3366810fa44bd0f97ab75948e1d35e 100644 (file)
@@ -205,9 +205,15 @@ efi_c_ld_args = [
         '-z', 'separate-code',
 ]
 
-# Check if the compiler is GCC and then we link to lgcc in that case only
-if cc.get_id() == 'gcc'
-    efi_c_ld_args += ['-lgcc']
+linker_sanity_code = 'void a(void) {}; void _start(void) { a(); }'
+linker_sanity_args = ['-nostdlib', '-Wl,--fatal-warnings']
+
+# Check if libgcc is available and then use it. It is needed for gcc builds
+# and for ia32 builds with clang.
+if cc.links(linker_sanity_code,
+            name : 'libgcc is available',
+            args : [linker_sanity_args, '-lgcc'])
+        efi_c_ld_args += ['-lgcc']
 endif
 
 efi_c_ld_args += cc.get_supported_link_arguments(
@@ -261,8 +267,6 @@ efi_arch_c_ld_args = {
         'x86'    : ['-m32'],
 }
 
-linker_sanity_code = 'void a(void) {}; void _start(void) { a(); }'
-linker_sanity_args = ['-nostdlib', '-Wl,--fatal-warnings']
 if not cc.links(linker_sanity_code,
                 name : 'linker supports -static-pie',
                 args : [linker_sanity_args, '-static-pie'])