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

TLS error when using Zig toolchain with Rust #12833

Open
purkhusid opened this issue Sep 13, 2022 · 8 comments
Open

TLS error when using Zig toolchain with Rust #12833

purkhusid opened this issue Sep 13, 2022 · 8 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@purkhusid
Copy link

purkhusid commented Sep 13, 2022

Zig Version

0.10.0-dev.3838+77f31ebbb

Steps to Reproduce

I'm testing using Zig as a C/C++ toolchain using Bazel and rules_rust(https://github.com/bazelbuild/rules_rust)

@motiejus Has created a very useful project that allows you to replace the host toolchains with hermetic toolchains
that are supplied by Zig: https://sr.ht/~motiejus/bazel-zig-cc/

The toolchain seems to mostly work with Rust but I get an error when I compile projects that use async-stream:

/workspace/bazel_output_base/execroot/monorepo/bazel-out/k8-opt-exec-2B5CBBC6/bin/external/cargo__async-stream-impl-0.3.3/libasync_stream_impl-1922333755.so: cannot allocate memory in static TLS block

I wanted to see if there were any known issues with Zig and the TLS or Rust and Zig?

I've been trying to create a minimal reproduction but I'm having a hard time doing so, will post it here in a comment if I manage to create it.

Expected Behavior

The compilation should be successful.

Actual Behavior

Fails with an error:

/workspace/bazel_output_base/execroot/monorepo/bazel-out/k8-opt-exec-2B5CBBC6/bin/external/cargo__async-stream-impl-0.3.3/libasync_stream_impl-1922333755.so: cannot allocate memory in static TLS block
@purkhusid purkhusid added the bug Observed behavior contradicts documented or intended behavior label Sep 13, 2022
@motiejus
Copy link
Contributor

motiejus commented Sep 13, 2022

Zig Version

0.9.1

Are you sure? bazel-zig-cc barely works with this version, if at all (there were so many things fixed since 0.9.1) You can find out the zig version in your Bazel workspace by running:

$ bazel run @zig_sdk//:zig version

Also, the report as-is is not very helpful to Zig developers. You will have a much higher chance of getting this prioritized if you add all the intermediate commands that produced libasync_stream_impl-1922333755.so. You can get those with bazel build -s --sandbox_debug <...> . Ideally, in a form that they can easily reproduce the error without cargo and bazel.

@purkhusid
Copy link
Author

purkhusid commented Sep 13, 2022

@motiejus I was wrong on the Zig version. Updated the issue.
I've been trying to extract the commands but they are hidden behind a bunch of rules_rust specific stuff. I'll update if I can isolate it.

@Cloudef
Copy link
Contributor

Cloudef commented Nov 2, 2022

I had the same problem, though not with zig-bazel. 0.8.1 release of zig seems to work, anything more recent than that has this issue.

@lifthrasiir
Copy link
Contributor

It seems that #16152 is a likely reason for this bug, because errno.c was added as a part of glibc 2.34 import in 0.9.0. I can't fully confirm if it's indeed the case because there is no other clue available though.

@fieryboa
Copy link

I seem to have the same issue, although with a different crate instead.
Error:

 /home/developer/.cache/bazel/_bazel_developer/13769b04368bf914c441ec6c2a733f7d/execroot/engine/bazel-out/k8-opt-exec-2B5CBBC6/bin/external/crate_index__serde_derive-1.0.163/libserde_derive-1817460194.so: cannot allocate memory in static TLS block

I managed to isolate the subcommand used to compile libserde_derive-1817460194.so,

SUBCOMMAND: # @crate_index__serde_derive-1.0.163//:serde_derive [action 'Compiling Rust proc-macro serde_derive v1.0.163 (18 files)', configuration: a169d5b64dd3bbfc6ec4aff779cf2660d473c39666ef9744c05fdfa10b6f1a20, execution platform: @local_config_platform//:host]
(cd /home/developer/.cache/bazel/_bazel_developer/13769b04368bf914c441ec6c2a733f7d/execroot/engine && \
  exec env - \
    BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
    CARGO_CFG_TARGET_ARCH=x86_64 \
    CARGO_CFG_TARGET_OS=linux \
    CARGO_CRATE_NAME=serde_derive \
    CARGO_MANIFEST_DIR='${pwd}/external/crate_index__serde_derive-1.0.163' \
    CARGO_PKG_AUTHORS='' \
    CARGO_PKG_DESCRIPTION='' \
    CARGO_PKG_HOMEPAGE='' \
    CARGO_PKG_NAME=serde_derive \
    CARGO_PKG_VERSION=1.0.163 \
    CARGO_PKG_VERSION_MAJOR=1 \
    CARGO_PKG_VERSION_MINOR=0 \
    CARGO_PKG_VERSION_PATCH=163 \
    CARGO_PKG_VERSION_PRE='' \
    SYSROOT=bazel-out/k8-fastbuild/bin/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain \
  bazel-out/k8-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper --arg-file bazel-out/k8-fastbuild/bin/external/crate_index__proc-macro2-1.0.58/proc-macro2_build_script.linksearchpaths --arg-file bazel-out/k8-fastbuild/bin/external/crate_index__quote-1.0.27/quote_build_script.linksearchpaths --subst 'pwd=${pwd}' -- bazel-out/k8-fastbuild/bin/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain/bin/rustc external/crate_index__serde_derive-1.0.163/src/lib.rs '--crate-name=serde_derive' '--crate-type=proc-macro' '--error-format=human' '--codegen=metadata=-1817460194' '--codegen=extra-filename=-1817460194' '--out-dir=bazel-out/k8-fastbuild/bin/external/crate_index__serde_derive-1.0.163' '--codegen=opt-level=0' '--codegen=debuginfo=0' '--remap-path-prefix=${pwd}=' '--emit=dep-info,link' '--color=always' '--target=x86_64-unknown-linux-gnu' --cfg 'feature="default"' -L bazel-out/k8-fastbuild/bin/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain/lib/rustlib/x86_64-unknown-linux-gnu/lib '--cap-lints=allow' '--codegen=linker=external/zig_sdk/tools/x86_64-linux-gnu.2.31/c++' --codegen 'link-args=-shared -ldl -lpthread -ldl -lpthread -ldl -lpthread -fno-lto' '--extern=proc_macro2=bazel-out/k8-fastbuild/bin/external/crate_index__proc-macro2-1.0.58/libproc_macro2-561358450.rlib' '--extern=quote=bazel-out/k8-fastbuild/bin/external/crate_index__quote-1.0.27/libquote-3465368223.rlib' '--extern=syn=bazel-out/k8-fastbuild/bin/external/crate_index__syn-2.0.16/libsyn-366149195.rlib' '-Ldependency=bazel-out/k8-fastbuild/bin/external/crate_index__unicode-ident-1.0.8' '-Ldependency=bazel-out/k8-fastbuild/bin/external/crate_index__proc-macro2-1.0.58' '-Ldependency=bazel-out/k8-fastbuild/bin/external/crate_index__quote-1.0.27' '-Ldependency=bazel-out/k8-fastbuild/bin/external/crate_index__syn-2.0.16')

Does this help in finding out the issue?

@fieryboa
Copy link

Hey guys, any updates?

@mantielero
Copy link

I am having a similar issue with zig v0.11.0. In my case is when I use the toolchain with the Nim lang.

I manage to compile a library without errors. But when I try to use it I get:

[FATAL][FMICAPI] Could not load the DLL: /tmp/fmucktmpnfCC8V/binaries/linux64/values.so: cannot allocate memory in static TLS block
[FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for ME.

(this is an FMU file which includes values.so created with Zig)

@mantielero
Copy link

mantielero commented Dec 21, 2023

Further more, here you have two jobs in Github Action. The one in windows is working fine. The one in 'ubuntu-latest' shows the error message. I have the same behavior in my machine (running ArchLinux).

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
Projects
None yet
Development

No branches or pull requests

7 participants