[PATCH] D133759: [Support] Access threadIndex via a wrapper function

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 23:15:19 PDT 2022


mstorsjo added a comment.

In D133759#3788555 <https://reviews.llvm.org/D133759#3788555>, @MaskRay wrote:

> Interesting. I did not know this limitation.

It's of course a very subtle area; for "proper" DLL linkage, you'd use dllexport/dllimport, and if you combine dllexport/import with `thread_local`, then MSVC errors out with this error:

  error C2492: 'tlsVar': data with thread storage duration may not have dll interface 

Clang gives this error:

  error: 'tlsVar' cannot be thread local when declared 'dllexport'

(And the same for `dllimport` too.) Clang does give these same errors also if using `-femulated-tls`, even if the linkage technically would work there. GCC doesn't error out on either of them (and the linkage does work out in the end, as it uses emulated TLS - but there's other potential pitfalls wrt TLS across object files there, due to their handling of weak linkage).

However, the mingw dylib build doesn't rely on explicit dllexport/imports, but on implicit autoimports, and then we don't get errors at that level at all, but only at linkage time:

  ld.lld: error: unable to automatically import from _ZN4llvm8parallel11threadIndexE with relocation type IMAGE_REL_AMD64_SECREL in liblldELF.a(Relocations.cpp.obj)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133759/new/

https://reviews.llvm.org/D133759



More information about the llvm-commits mailing list