Description
Zig Version
0.14.0-dev.2370+5c6b25d9b
Steps to Reproduce and Observed Behavior
In recent versions of Zig (since v0.11?) there is some unintuitive behaviour when using .addAssemblyFile()
as opposed to not using it.
When not using .addAssemblyFile()
the variables that are export
ed from your .zig
files are present in the resulting binary. For example a multiboot header: https://github.com/andrewrk/HellOS/blob/68efb199d96bcd1c104e54c21bd8802f2612ec68/hellos.zig#L14`
However, if you make use of addAssemblyFile()
then the export
ed variables will be removed unless they are referenced in your assembly file. (Which is a particular nuisance for multiboot headers, as there is no reason to reference it.)
This behaviour is NOT seen in Debug builds.
This does not appear to be an issue with the final linking step, but rather an earlier step, as the data is missing from the .o
file.
If this is the intended behaviour, then please accept my apologies; it wasn't intuitive to me.
Rough steps to reproduce
- Start with a project that
export
s some data that is otherwise unreferenced - Build with ReleaseSmall, and search for data
hexdump .zig-cache/o/*/Proj.o | grep -i 'b002'
; you should find it - Add an empty assembly file with
.addAssemblyFile()
- Build with ReleaseSmall again; the data should now be missing
Expected Behavior
export
ed variables in .zig
source files should be present in the final binary, regardless of whether addAssemblyFile()
was used.
I hope that the above is clear. If not, I will try to put together a test case, in the future. For now though, I wanted to get this written down while it's fresh in my mind, and also on the off chance that someone is able to easily understand why this is happening.