addObjCopy() producing zero padding at start of binary

I am trying to create small riscv:32 binaries using zig for an embedded system and have a problem with objcopy.
My build.zig uses addObjCopy() to create a binary from the ELF build artefact, but it (sometimes) gets zero padded at the start. This seems to come and go depending on the program size.

It definitely seems to be an addObjCopy() issue as using GNU objcopy on the ELF works fine.

Source code and explanation at: GitHub - ringtailsoftware/zig-objcopy-problem

Any ideas?


tigerbeetle uses llvm-objcopy as their workaround:

So I think for now using a non-zig objcopy is the easiest solution, until the Zig version has been improved.

1 Like