How to compile systemd for use with arm64 devices?

I get some weird errors compiling systemd-git on an arm64 device.

  1. What errors are you getting? We can’t help you without knowing what issues you have.
  2. Why do you need to compile systemd yourself? Systemd is in the repository.
  3. Why do you need the -git version of systemd?
1 Like

Weird. doh! :crazy_face:

I know them - wacky errors I out of nowhere!? Usually caused by my own incompetence :grin:

3 Likes

Basically because of this glitch I have to compile systemd manually.

https://aur.archlinux.org/systemd-git.git
Use this PKGBUILD file.

FAILED: src/boot/efi/systemd-bootaa64.elf
/usr/bin/cc -o src/boot/efi/systemd-bootaa64.elf -DGNU_EFI_USE_MS_ABI -DSD_BOOT -ffreestanding -fshort-wchar -fvisibility=hidden -I /home/daiaji/systemd-git/src/systemd/src/fundamental -
I /home/daiaji/systemd-git/src/systemd/src/boot/efi -include src/boot/efi/efi_config.h -include version.h -isystem /usr/include/efi/aarch64 -isystem /usr/include/efi -std=gnu11 -Wall -We
xtra -Wno-format-signedness -Wno-missing-field-initializers -Wno-unused-parameter -Wdate-time -Wendif-labels -Werror=format=2 -Werror=implicit-function-declaration -Werror=incompatible-p
ointer-types -Werror=int-conversion -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=undef -Wfloat-equal -Wimplici
t-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2
-Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wno-unused-result -ftrivial-auto-var-init=zero -fno-stack-protector -fno-strict-aliasing -fpic -fwide-
exec-charset=UCS2 -O2 -fuse-ld=bfd -L /usr/lib -nostdlib -T /usr/lib/elf_aarch64_efi.lds -Wl,--build-id=sha1 -Wl,--fatal-warnings -Wl,--no-undefined -Wl,--warn-common -Wl,-Bsymbolic -z n
ocombreloc /usr/lib/crt0-efi-aarch64.o -shared -Wl,--defsym=EFI_SUBSYSTEM=0xa src/boot/efi/bootspec-fundamental.c.o src/boot/efi/efivars-fundamental.c.o src/boot/efi/sha256.c.o src/boot/
efi/string-util-fundamental.c.o src/boot/efi/assert.c.o src/boot/efi/devicetree.c.o src/boot/efi/disk.c.o src/boot/efi/efi-string.c.o src/boot/efi/graphics.c.o src/boot/efi/initrd.c.o sr
c/boot/efi/measure.c.o src/boot/efi/pe.c.o src/boot/efi/secure-boot.c.o src/boot/efi/ticks.c.o src/boot/efi/util.c.o src/boot/efi/boot.c.o src/boot/efi/console.c.o src/boot/efi/drivers.c
.o src/boot/efi/random-seed.c.o src/boot/efi/shim.c.o src/boot/efi/xbootldr.c.o src/boot/efi/bcd.c.o -lefi -lgnuefi -lgcc
lto1: fatal error: bytecode stream in file '/usr/lib/libefi.a' generated with LTO version 11.0 instead of the expected 12.0
compilation terminated.
lto-wrapper: fatal error: /usr/bin/cc returned 1 exit status
compilation terminated.
/usr/bin/ld.bfd: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
[12/2389] Generating src/boot/efi/linuxaa64.elf.stub with a custom command
FAILED: src/boot/efi/linuxaa64.elf.stub
/usr/bin/cc -o src/boot/efi/linuxaa64.elf.stub -DGNU_EFI_USE_MS_ABI -DSD_BOOT -ffreestanding -fshort-wchar -fvisibility=hidden -I /home/daiaji/systemd-git/src/systemd/src/fundamental -I
/home/daiaji/systemd-git/src/systemd/src/boot/efi -include src/boot/efi/efi_config.h -include version.h -isystem /usr/include/efi/aarch64 -isystem /usr/include/efi -std=gnu11 -Wall -Wext
ra -Wno-format-signedness -Wno-missing-field-initializers -Wno-unused-parameter -Wdate-time -Wendif-labels -Werror=format=2 -Werror=implicit-function-declaration -Werror=incompatible-poi
nter-types -Werror=int-conversion -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=undef -Wfloat-equal -Wimplicit-
fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -W
strict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wno-unused-result -ftrivial-auto-var-init=zero -fno-stack-protector -fno-strict-aliasing -fpic -fwide-ex
ec-charset=UCS2 -O2 -fuse-ld=bfd -L /usr/lib -nostdlib -T /usr/lib/elf_aarch64_efi.lds -Wl,--build-id=sha1 -Wl,--fatal-warnings -Wl,--no-undefined -Wl,--warn-common -Wl,-Bsymbolic -z noc
ombreloc /usr/lib/crt0-efi-aarch64.o -shared -Wl,--defsym=EFI_SUBSYSTEM=0xa src/boot/efi/bootspec-fundamental.c.o src/boot/efi/efivars-fundamental.c.o src/boot/efi/sha256.c.o src/boot/ef
i/string-util-fundamental.c.o src/boot/efi/assert.c.o src/boot/efi/devicetree.c.o src/boot/efi/disk.c.o src/boot/efi/efi-string.c.o src/boot/efi/graphics.c.o src/boot/efi/initrd.c.o src/
boot/efi/measure.c.o src/boot/efi/pe.c.o src/boot/efi/secure-boot.c.o src/boot/efi/ticks.c.o src/boot/efi/util.c.o src/boot/efi/cpio.c.o src/boot/efi/splash.c.o src/boot/efi/stub.c.o src
/boot/efi/linux.c.o -lefi -lgnuefi -lgcc
lto1: fatal error: bytecode stream in file '/usr/lib/libefi.a' generated with LTO version 11.0 instead of the expected 12.0
compilation terminated.
lto-wrapper: fatal error: /usr/bin/cc returned 1 exit status
compilation terminated.
/usr/bin/ld.bfd: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
[17/2389] Compiling C object src/basic/libbasic-compress.a.p/compress.c.o
ninja: build stopped: subcommand failed.
==> ERROR: A failure occurred in build().
Aborting...

I have built the systemd-git packages. They were built with the libs in the unstable branch. I have no clue what branch you are on or if the libs has changed with you branch.

Here is the packages I built and also I included the modified PKGBUILD in a tarball for a aarch64 build for your reference or if the packages don’t work for your branch you are on and you do not want to switch branches you can rebuild them.

md5sum systemd-git.tar 
053028e0b6f8dbf404fd8ac40be460fa  systemd-git.tar

Files:

systemd-git.tar
systemd-git-251.r58694.b33c2757d8-1-aarch64.pkg.tar.zst
systemd-libs-git-251.r58694.b33c2757d8-1-aarch64.pkg.tar.zst
systemd-resolvconf-git-251.r58694.b33c2757d8-1-aarch64.pkg.tar.zst
systemd-sysvcompat-git-251.r58694.b33c2757d8-1-aarch64.pkg.tar.zst

https://drive.google.com/file/d/1Z96TN2xi1iT3rHUq7GPAQAbTkSmWLA2d/view?usp=sharing

1 Like

git+https://github.com/yuwata/systemd.git#branch=network-lifetime-fix

Thanks for the PKGBUILD file you provided. I compiled this branch that has not been merged.

I noticed that there seem to be some additional parameters in the PKGBUILD file. Do you need these additional parameters to compile systemd for arm64 devices, or is it a bug in systemd?

I had tried to compile systems-git from AUR and ran into pretty much the same compile issues you did so I then looked at arch-arm’s systemd PKGBUILD and added their compile flags and their $CARCH statement for aarch64.

  LDFLAGS+=" -Wl,-fuse-ld=bfd"
  CFLAGS+=" -fno-lto"
  CXXFLAGS+=" -fno-lto"

  [[ $CARCH == "aarch64" ]] && gnu_efi="true" || gnu_efi="false"

This just means you have a compiler version mismatch (as the error message says). Either building with gcc11 or rebuilding gnu-efi with the compiler you’re using to build sd-boot should do the trick (arch already did a rebuild for gnu-efi for this reason).

The gnu-efi in the software sources should probably be recompiled.
@Strit

We get gnu-efi directly from Arch Linux ARM, which in turn just rebuilds the Arch Linux x64 PKGBUILD.

The problem seems to be that Arch Linu x64 updated the PKGBUILD after they updated their GCC to 12, while Arch Linux ARM only made the switch to GCC 12 much later, after the gnu-efi package was already rebuilt.

Should it now wait for upstream to rebuild the gnu-efi package?
The page for Arch Linux ARM doesn’t even have a button to mark the package as obsolete.

Or you can write to the Arch Linux ARM team and tell them about the issue.