Skip to main content
Engineering, Backend

Bootstrapping Uber’s Infrastructure on arm64 with Zig

03 May 2023 / Global
Featured image for Bootstrapping Uber’s Infrastructure on arm64 with Zig
Alt text: two arrows point from a .c file: to aarch64 and x86_64 hosts. The aarch64 host invokes a command “clang main.c”, the x86_64 host invokes a command “clang -target aarch64-linux main.c”. Both invocations emit an executable, which is then launched on an aarch64 machine."
Figure 1: An input file main.c compiles to an aarch64 natively (left) or cross-compiled (right).
Alt text: “$ uname -m -o <newline> x86_64 GNU/Linux <newline> $ aarch64-linux-gnu-gcc main.c -o main && file main <newline> main: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, not stripped”
Alt text: $ clang -target aarch64-linux-gnu main.c -o main && file main <newline>  main: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, not stripped
Alt text: “$ strace -fe openat -e status=successful clang -target aarch64-linux-gnu main.c |& awk -F'"' '/aarch64-linux-gnu/{print $2}' | xargs realpath | sort -u <newline> /usr/aarch64-linux-gnu/include/bits/floatn-common.h <newline> <...> <newline> /usr/aarch64-linux-gnu/lib/Scrt1.o <newline> /usr/aarch64-linux-gnu/lib/crti.o <newline> /usr/aarch64-linux-gnu/lib/crtn.o <newline> /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 <newline> /usr/aarch64-linux-gnu/lib/libc.so <newline> /usr/aarch64-linux-gnu/lib/libc.so.6 <newline> /usr/aarch64-linux-gnu/lib/libc_nonshared.a <newline> /usr/aarch64-linux-gnu/lib/libgcc_s.so.1 <newline> /usr/lib/gcc-cross/aarch64-linux-gnu <newline> /usr/lib/gcc-cross/aarch64-linux-gnu/12/crtbeginS.o <newline> /usr/lib/gcc-cross/aarch64-linux-gnu/12/crtendS.o <newline> /usr/lib/gcc-cross/aarch64-linux-gnu/12/libgcc.a <newline> /usr/lib/gcc-cross/aarch64-linux-gnu/12/libgcc_s.so <newline>”
Alt text: “3 computers: x86_64-linux, x86_64-macos, aarch64-macos. Every computer has a corresponding archive with LLVM toolchain. Each computer is pointing an arrow to an five archives (sysroots): x86_64-linux-glibc.2.28.tar, x86_64-linux-glibc-2.31.tar, x86_64-linux-musl.tar, aarch64-linux-glibc-2.31.tar, aarch64-linux-musl.tar”
Figure 2: llvm-based toolchain requires a tarball (“sysroot”) for each host and target.
Alt text: “$ zig cc -target aarch64-linux-gnu.2.28 main.c -o main && file main <newline>  mainzig: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 2.0.0, with debug_info, not stripped”
Alt text: “3 computers: x86_64-linux, x86_64-macos, aarch64-macos, each running a corresponding Zig toolchain for their platform”.
Figure 3: Zig toolchain requires 1 toolchain per host. The same toolchain can compile to all targets.
Alt text: “$ uname -m -o <newline> x86_64 GNU/Linux <newline> $ zig cc -target aarch64-macos-none main.c -o main && file main <newline> main: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>”
Motiejus Jakštys

Motiejus Jakštys

Motiejus Jakštys is a Staff Engineer at Uber based in Vilnius. His professional interests are systems programming and cartography. Motiejus is passionate about writing software that consumes as little resources as necessary.

Laurynas Lubys

Laurynas Lubys

Laurynas Lubys is a Senior Engineer at Uber based in Vilnius. He is interested in building correct software: this includes rigorous testing, functional programming, reproducible build systems and thinking very hard about security. You might catch him debating pros and cons of programming languages and approaches.

Neringa Lukoševičiūtė

Neringa Lukoševičiūtė

Neringa Lukoševičiūtė is a Software Engineer on the Uber Infrastructure team based in Seattle. She primarily works on the arm64 project and is enthusiastic about integrating arm64-related technology into Uber’s infrastructure.

Posted by Motiejus Jakštys, Laurynas Lubys, Neringa Lukoševičiūtė