Skip to content

llvm backend regression: failing assertion when targetting uefi #25578

@bnuuydev

Description

@bnuuydev

Zig Version

0.16.0-dev.733+b34a13da3

Steps to Reproduce and Observed Behavior

When attempting to build anything targetting UEFI, the compiler triggers the following assertion in LLVM:

zig: /home/user/Devel/llvm-project/llvm/lib/CodeGen/MachineFunction.cpp:243: void llvm::MachineFunction::init(): Assertion `Target.isCompatibleDataLayout(getDataLayout()) && "Can't create a MachineFunction using a Module with a " "Target-incompatible DataLayout attached\n"' failed.

A simple reproduction would be with the build command zig build-exe repro.zig -target x86_64-uefi

// repro.zig
const std  = @import("std");
pub export fn EfiMain() callconv(std.os.uefi.cc) usize { return 0; }

This issue doesn't seem to present itself when using a downloaded master binary from https://ziglang.org/download, only with a self-built binary. I experienced this when LLVM 21.1.3 was built from source, although I also tried LLVM 21.1.0, with the same error. It was built with the following options:

cmake -B build -DCMAKE_INSTALL_PREFIX=$HOME/llvm21 \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_PARALLEL_LINK_JOBS=2 -G Ninja

and Zig was built with:

cmake -B build -DCMAKE_PREFIX_PATH="$HOME/llvm21" \
-DZIG_STATIC_ZLIB=ON \
-DCMAKE_BUILD_TYPE=Release

This was on an up-to-date Arch system. This has regressed since about 6 months ago, when I didn't have this issue using the same build commands.

Expected Behavior

The compiler shouldn't be failing an assertion in LLVM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behavioros-uefiregressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions