Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile errors occur when the global cache is cleaned/wiped/deleted but the local cache is not because it has dangling references to global cache files #10158

Open
uhthomas opened this issue Nov 16, 2021 · 12 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@uhthomas
Copy link

uhthomas commented Nov 16, 2021

Zig Version

0.9.0-dev.1414+cde3dd365

Steps to Reproduce

Using bazel-zig-cc@361fc42b, build a cgo project with zig cc and pure = off.

go_binary(
    name = "some",
    embed = [":some_lib"],
    goarch = "amd64",
    goos = "linux",
    pure = "off",
    visibility = ["//visibility:public"],
)

Expected Behavior

It should build.

Actual Behavior

(11:17:01) ERROR: /private/var/tmp/_bazel_thomas/b6a3c999aae05297a54a9aa13d7a50c3/external/io_bazel_rules_go/BUILD.bazel:44:7: GoStdlib external/io_bazel_rules_go/stdlib_/pkg failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder stdlib -sdk external/go_sdk -installsuffix linux_amd64 -out bazel-out/darwin-fastbuild-ST-64800c94ce45/bin/external/io_bazel_rules_go/stdlib_

Use --sandbox_debug to see verbose messages from the sandbox
# runtime/cgo
WARNING: flock not found, proceeding unsafely.
If build fails, retry it.
ld.lld: error: cannot open /var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T//bazel-zig-cc/o/fdb8c1e82b0cc8d72c53e7cb12c0ef9b/Scrt1.o: No such file or directory
ld.lld: error: cannot open /var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T//bazel-zig-cc/o/1e260ac65a7a7021ed17a6f508533e22/crti.o: No such file or directory
ld.lld: error: cannot open /var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T//bazel-zig-cc/o/965602877839941573a56b32b0c704a7/crtn.o: No such file or directory
@uhthomas uhthomas added the bug Observed behavior contradicts documented or intended behavior label Nov 16, 2021
@andrewrk andrewrk added the zig cc Zig as a drop-in C compiler feature label Nov 20, 2021
@andrewrk andrewrk added this to the 0.9.0 milestone Nov 20, 2021
@andrewrk
Copy link
Member

Duplicate of #9439.

@andrewrk
Copy link
Member

andrewrk commented Dec 4, 2021

btw what is going on here?

WARNING: flock not found, proceeding unsafely.

zig is relying on flock() for correctness; is there some reason it's unable to call flock()?

@uhthomas
Copy link
Author

uhthomas commented Dec 6, 2021

Sorry @andrewrk, please ignore that warning. This is generated by the shell script wrapper as part of the Zig CC rules for Bazel.

https://git.sr.ht/~motiejus/bazel-zig-cc/tree/e4798822241ce838ab880817acb1cca4011510c0/item/toolchain/defs.bzl#L201

@andrewrk
Copy link
Member

andrewrk commented Dec 7, 2021

#9439 is fixed in 274555b. However, I'm not 100% sure this issue is resolved, and I have more cache system improvements planned, so I'm re-opening it now. I will double-check Scrt1.o and friends along with these improvements and check back in with this issue.

@andrewrk andrewrk reopened this Dec 7, 2021
@uhthomas
Copy link
Author

uhthomas commented Dec 9, 2021

I've just been playing with 0.9.0-dev.1926+803178353 and things are looking way better, but I'm seeing some new (related?) issues. I'm building on a macOS x86-64 host targeting macOS x86-64.

ERROR: /Users/thomas/<REDACTED>_test failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix darwin_amd64 -buildmode pie -arc ... (remaining 33 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
external/go_sdk/pkg/tool/darwin_amd64/link: running /private/var/tmp/_bazel_thomas/b6a3c999aae05297a54a9aa13d7a50c3/external/zig_sdk/tools/c++ failed: exit status 1
warning: unsupported linker arg: -S
warning: unsupported linker arg: --compress-debug-sections
warning: unsupported linker arg: zlib-gnu
warning(link): framework not found for '-framework CoreFoundation'
warning(link): framework not found for '-framework Security'
warning(link): Framework search paths:
error(link): undefined reference to symbol '_CFStringCreateWithBytes'
error(link):   first referenced in '/private/var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T/go-link-3249669388/go.o'
error: UndefinedSymbolReference

link: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/link: exit status 2

@motiejus
Copy link
Contributor

motiejus commented Dec 9, 2021

Possibly a shot in the dark, but you may be missing --sysroot in zig cc. See this: #10299 (comment)

@andrewrk
Copy link
Member

This fix is possibly related to this issue: 77836e0

@uhthomas
Copy link
Author

I imagine the original issue for this is probably resolved. I haven't seen it in a long time, but also have been using a caching strategy where each invocation of Zig CC starts from scratch. I am still seeing the error mentioned in #10158 (comment) though.

(10:13:05) ERROR: <REDACTED>/BUILD.bazel:10:8: GoLink <REDACTED>_test failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix darwin_amd64 -buildmode pie -arc ... (remaining 35 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
external/go_sdk/pkg/tool/darwin_amd64/link: running /private/var/tmp/_bazel_thomas/b6a3c999aae05297a54a9aa13d7a50c3/external/zig_sdk/tools/c++ failed: exit status 1
warning: unsupported linker arg: -S
warning: unsupported linker arg: --compress-debug-sections
warning: unsupported linker arg: zlib-gnu
warning(link): framework not found for '-framework CoreFoundation'
warning(link): framework not found for '-framework Security'
warning(link): Framework search paths:
error(link): undefined reference to symbol '_CFStringCreateWithBytes'
error(link):   first referenced in '/private/var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T/go-link-758804375/go.o'
error: UndefinedSymbolReference

link: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/link: exit status 2

I'll do some testing with a shared cache again and see how things go 😄

@andrewrk
Copy link
Member

This looks like trying to cross compile something that depends on the symbol _CFStringCreateWithBytes without linking CoreFoundation, which is where the symbol is provided. This is working as designed, and is not a problem with zig's cache system.

The only improvement to make here on zig's end would be:

error: framework not found for '-framework CoreFoundation'
info: searched for CoreFoundation in these paths: [...]
error: framework not found for '-framework Security'
info: searched for Security in these paths: [...]

...and then stop there, instead of mentioning undefined symbols.

However since you mentioned that your host and target are both x86_64-macos, I have to ask, what -target argument are you passing to zig? If you do not pass -target then you are building natively and I expect zig to pick up the CoreFoundation from your host system. However if you are passing -target x86_64-macos then this is a cross-compiled build, and the above error messages are correct. In such case you could resolve the issue by using the host framework definitions by adding --sysroot $(xcrun --show-sdk-path) to the zig cc command line.

@andrewrk
Copy link
Member

Ahhh you know what I bet I know what happened for the original issue that you reported.

@andrewrk andrewrk changed the title Zig CC link errors (Scrt1.o and crtn.o not found) compile errors occur when the global cache is cleaned/wiped/deleted but the local cache is not because it has dangling references to global cache files Dec 10, 2021
@andrewrk andrewrk added frontend Tokenization, parsing, AstGen, Sema, and Liveness. and removed zig cc Zig as a drop-in C compiler feature labels Dec 10, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.9.1 Dec 10, 2021
@uhthomas
Copy link
Author

Hmm, I'm not so sure that conclusion is correct. The ZIG_LOCAL_CACHE_DIR and ZIG_GLOBAL_CACHE_DIR environment variables were and always have been identical.

https://git.sr.ht/~motiejus/bazel-zig-cc/tree/361fc42b2e1282ed078bf9c1ad281642e19858d4/item/toolchain/defs.bzl#L191

motiejus added a commit to motiejus/zig that referenced this issue Dec 11, 2021
If `-framework` is requested, but not found, the linker will err
instead of creating a strange executable.

ziglang#10299 (comment)

Refs ziglang#9542
Refs ziglang#10299
Refs ziglang#10158
charleskorn added a commit to charleskorn/zig-cgo-libs that referenced this issue Jan 5, 2022
@andrewrk andrewrk modified the milestones: 0.9.1, 0.10.0 Feb 3, 2022
@uhthomas
Copy link
Author

Looks like this issue still shows up occasionally.

Version 0.10.0-dev.1393+291f5055f.

Example:

ld.lld: error: cannot open /var/folders/3k/z0djtwqd4s5_xrwz0nlgfx700000gp/T//bazel-zig-cc/o/577b5020915dd149714a9b44041a9be8/Scrt1.o: No such file or directory
ld.lld: error: cannot open /var/folders/3k/z0djtwqd4s5_xrwz0nlgfx700000gp/T//bazel-zig-cc/o/ee268b08503a370b073e628082bd0a9d/crti.o: No such file or directory
ld.lld: error: cannot open /var/folders/3k/z0djtwqd4s5_xrwz0nlgfx700000gp/T//bazel-zig-cc/o/3ae3c7caf4ea05e4f0be12ff06b54095/crtn.o: No such file or directory

@andrewrk andrewrk removed this from the 0.10.0 milestone Sep 14, 2022
@andrewrk andrewrk added this to the 0.11.0 milestone Sep 14, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.16.0 Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants