Skip to content

zig build-lib sometimes creates truncated or malformed archives #25129

@cerisier

Description

@cerisier

Zig Version

0.15.1

Steps to Reproduce and Observed Behavior

It seems that since zig 0.15, archives created by zig build-lib on linux are "sometimes" not valid.
Trying to link such library with clang fails with the following error:

Archive::children failed: truncated or malformed archive (offset to next archive member past the end of the archive after member library.o)

Same with any of the llvm binaries such as llvm-ar tv library.o.

After investigation, it seems that objects files in the archives are not always an even number of bytes long.
Resulting in an archive that is an odd number of bytes long.

% wc -c library.o
    2340477 library.o

Sadly, I am not able to provide a minimal repro as this happens only with 1 module which has many internal dependencies...

Reverting to 0.14 and we never encounter this error anymore tho.

Expected Behavior

The ar file format specificiations specifies that:

If the data for an archive member ends at an odd byte offset, then a padding byte with value 0x0A is used to position the next archive header on an even byte offset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions