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

undefined reference to thread local variable in generic function #73088

Closed
Freax13 opened this issue Jun 7, 2020 · 3 comments
Closed

undefined reference to thread local variable in generic function #73088

Freax13 opened this issue Jun 7, 2020 · 3 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. F-thread_local `#![feature(thread_local)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Freax13
Copy link
Contributor

Freax13 commented Jun 7, 2020

I tried this code:

#![feature(thread_local)]

#[thread_local]
static FOO: usize = 0;

fn generic_fn<T>() {
    println!("{}", FOO);
}

fn main() {
    generic_fn::<u32>();
}

I expected to see this happen: the code compiles and runs

Instead, this happened: the linker fails with "undefined reference to `bug_thread_local::FOO'"

Meta

rustc --version --verbose:

rustc 1.46.0-nightly (118b50524 2020-06-06)
binary: rustc
commit-hash: 118b50524b79e565f017e08bce9b90a16c63634f
commit-date: 2020-06-06
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0
backtrace

   Compiling bug_thread_local v0.1.0 (/coding/rust/bugs/bug_thread_local)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.15r157f46nq5mrlc.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.1bura74fpes4wgex.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.1wbud65q9h6ajgnf.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.46em5a1xf4kr89y6.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.4gwkhmnlmutobbpo.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.4ibtg096vtr9owgz.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.4ohtqtdpema17ct9.rcgu.o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.56dvc5ml437kyb48.rcgu.o" "-o" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698" "/coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.2zba00a95gi8ssj6.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/coding/rust/bugs/bug_thread_local/target/debug/deps" "-L" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-e57211332ec73a2f.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-419d4801030b1e5f.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-cfc1286528e69dbf.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-bb34cb18a72ef92e.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-06bd58cc4eea83a6.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-a5f6d70e9e31f670.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-9d8ebec41dc1a913.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-d4969954aa8384d6.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-f0a7e8cab2b30e63.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-95ea48ddc44a311b.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-7932c3ccaf0b0992.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-68f423c59dc48a40.rlib" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-54580c7798bf2225.rlib" "-Wl,--end-group" "/home/freax13/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-b5efcd4dc107fc39.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: /usr/bin/ld: /coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698.4gwkhmnlmutobbpo.rcgu.o: in function `bug_thread_local::generic_fn':
          /coding/rust/bugs/bug_thread_local/src/main.rs:7: undefined reference to `bug_thread_local::FOO'
          /usr/bin/ld: /coding/rust/bugs/bug_thread_local/target/debug/deps/bug_thread_local-c8ea200706a99698: hidden symbol `_ZN16bug_thread_local3FOO17h1facba36a04dea80E' isn't defined
          /usr/bin/ld: final link failed: bad value
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: could not compile `bug_thread_local`.

To learn more, run the command again with --verbose.

@Freax13 Freax13 added the C-bug Category: This is a bug. label Jun 7, 2020
@jonas-schievink
Copy link
Contributor

Might be fixed by #73033

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries A-thread-locals Area: Thread local storage (TLS) F-thread_local `#![feature(thread_local)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 7, 2020
@Amanieu
Copy link
Member

Amanieu commented Jun 8, 2020

#73065 actually

@jonas-schievink
Copy link
Contributor

#73065 was merged, can this be closed?

@Amanieu Amanieu closed this as completed Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. F-thread_local `#![feature(thread_local)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants