Zig build-obj creates 2 object files

Hello,
When building object files with zig build-obj test.zig, I get two object files test.o and test.o.o.
My question is why are there 2 files and what are the differences between these 2 files.
Thank you.

Using strace -f zig build-ob test.zig:

  • zig build-obj saves test.o.o
  • forks itself and exec linker zig ld.lld that outputs test.o from input test.o.o
    the actual link command line is:
zig "ld.lld" "-r" "--error-limit=0" "--image-base=16777216" "--eh-frame-hdr" "-znow" "-m" "elf_x86_64" "-static" "-o" "test.o" "test.o.o"

I don’t know why there is a linking step. But if this step is required, the initial process must remove test.o.o

2 Likes