Skip to content

race condition when building glibc stubs #13160

@motiejus

Description

@motiejus

Summary: multiple zig invocations can stumble upon each other when they are creating glibc stubs.

Steps to reproduce

main.c

int main() {}

Command: run zig c++ many times in parallel:

until ! sh -c 'rm -fr ~/.cache/zig /tmp/main-*; for i in `seq 100`; do echo "zig c++ -target x86_64-linux-gnu.2.28 main.c -o /tmp/main-$i |& cat"; done | xargs -P100 -I{} bash -eo pipefail -c "{}"'; do date; done

And get an error message similar to this (more examples of error messages later in the issue):

/home/user/.cache/zig/o/f4abebc517abb01aedecbd5f414572c4/m.s:2740:22: error: expected a '@' in the name
.symver fabsf32, fabs

It takes me between 5 and 60 minutes to reproduce on a 96-core machine. It took a few hours on an 8-core laptop.

If we trim everything after that last fabs (i.e. where the error message says), the file is 65536 bytes long, suggesting an unfinished write by another zig.

Cursory look at glibc.zig shows no collaboration between multiple zig invocations that want to build the same stubs. That's perhaps the issue, but I didn't (yet) have a chance to dig into this deeper.

Other messages that I saw when running this test. I ran the command overnight (without the `-eo pipefail`, so it would keep going after errors). Here are a few selected ones:
Details
ld.lld: error: /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/all.map:1: unexpected EOF
ld.lld: error: /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/all.map:1: unexpected EOF
warning(compilation): failed to write cache manifest: Unexpected
<many more warnings exactly like above>
error(compilation): /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/pthread.s:1:1: unable to build C object: FileNotFound
error: unable to build glibc shared objects: BuildingLibCObjectFailed
warning(compilation): failed to write cache manifest: Unexpected
<many more warnings exactly like above>
zig: error: clang integrated assembler command failed with exit code 135 (use -v to see invocation)
clang version 14.0.6 (git@github.com:ziglang/zig-bootstrap.git 73fba22053d7668fa2448a13b32c772f95c6e1c6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user
zig: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
zig: error: clang integrated assembler command failed with exit code 135 (use -v to see invocation)
clang version 14.0.6 (git@github.com:ziglang/zig-bootstrap.git 73fba22053d7668fa2448a13b32c772f95c6e1c6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user
zig: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
ld.lld: error: /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/all.map:1: unexpected EOF
ld.lld: error: /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/all.map:1: unexpected EOF
warning(compilation): failed to write cache manifest: Unexpected
zig: error: clang integrated assembler command failed with exit code 135 (use -v to see invocation)
clang version 14.0.6 (git@github.com:ziglang/zig-bootstrap.git 73fba22053d7668fa2448a13b32c772f95c6e1c6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user
zig: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
warning(compilation): failed to write cache manifest: Unexpected
ld.lld: error: /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/all.map:1: unexpected EOF
ld.lld: error: /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/all.map:1: unexpected EOF
warning(compilation): failed to write cache manifest: Unexpected
<many more warnings exactly like above>
zig: error: clang integrated assembler command failed with exit code 135 (use -v to see invocation)
clang version 14.0.6 (git@github.com:ziglang/zig-bootstrap.git 73fba22053d7668fa2448a13b32c772f95c6e1c6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user
zig: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
warning(compilation): failed to write cache manifest: Unexpected
warning(compilation): failed to write cache manifest: Unexpected
error(compilation): /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/c.s:1:1: unable to build C object: FileNotFound
error: unable to build glibc shared objects: BuildingLibCObjectFailed
warning(compilation): failed to write cache manifest: Unexpected
error(compilation): /home/user/.cache/zig/o/c341a8cf346804bb91c0fc09dd1b917e/pthread.s:1:1: unable to build C object: FileNotFound
error: unable to build glibc shared objects: BuildingLibCObjectFailed
warning(compilation): failed to write cache manifest: Unexpected
<many more warnings exactly like above>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.os-linuxLinux

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions