Skip to content

Potential cache issue leading to inconsistent #23869

Closed
@Grazfather

Description

@Grazfather

Zig Version

0.14.0

(Built on M1 mac running Sonoma 14.2.1)

Steps to Reproduce and Observed Behavior

While trying to build a image for a microcontroller, with a custom entry point, I noticed that my build was not consistently producing a binary with the same header.

If I have commit A, which works, B, removes where we set the Build.Step.Compile.entry symbol, and then C, which re-adds it, I can sometimes build B and yield a binary with the entrypoint still set according to the entry field.

This behaviour is inconsistent, and sometimes hard (for others) to reproduce.

I have a repro branch in microzig called build_bug.
You can try to repro by cloning the repo and running the following from the examples/raspberrypi/rp2xxxx directory.

#!/bin/bash
set -x
rm -r zig-local/ zig-global/
git switch --quiet --detach build_bug^^ # Good
zig build -Dexample=ram_b --release=small --global-cache-dir "$PWD/zig-global" --cache-dir "$PWD/zig-local"
readelf -h zig-out/firmware/ram_blinky.elf | grep Entry
git switch --quiet --detach build_bug^ # Bad?
zig build -Dexample=ram_b --release=small --global-cache-dir "$PWD/zig-global" --cache-dir "$PWD/zig-local"
readelf -h zig-out/firmware/ram_blinky.elf | grep Entry
git switch --quiet build_bug # Good
zig build -Dexample=ram_b --release=small --global-cache-dir "$PWD/zig-global" --cache-dir "$PWD/zig-local"
readelf -h zig-out/firmware/ram_blinky.elf | grep Entry
git switch --quiet --detach build_bug^ # Bad?
zig build -Dexample=ram_b --release=small --global-cache-dir "$PWD/zig-global" --cache-dir "$PWD/zig-local"
readelf -h zig-out/firmware/ram_blinky.elf | grep Entry

Expected Behavior

Expected output is

Entry point address:               0x20000001
Entry point address:               0x20000645
Entry point address:               0x20000001
Entry point address:               0x20000645

But I sometimes get

Entry point address:               0x20000001
Entry point address:               0x20000001
Entry point address:               0x20000001
Entry point address:               0x20000001

Which suggests that it's not always using the entry field in the Compile step which changes across each commit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorlinking

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions