This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix checking for emulated TLS in shouldAssumeDSOLocal in CodeGen
AbandonedPublic

Authored by mstorsjo on Aug 29 2022, 5:24 AM.

Details

Summary

We shouldn't just check the clang options, we also should check
Triple::hasDefaultEmulatedTLS().

This doesn't make any testable difference in this commit, because
the check for emulated TLS is within a block for
TT.isWindowsGNUEnvironment(), and hasDefaultEmulatedTLS() returns
false for any such environment - but it makes the code from
0e4cf807aeaf54a10e02176498a7df13ac722b37 / D102970 more correct and
generic.

Some mingw distributions carry a downstream patch, that enables
emulated TLS by default for mingw targets in hasDefaultEmulatedTLS()

  • and for such cases, this patch does make a difference and fixes the

detection of emulated TLS, if it is implicitly enabled.

I'm open for better suggestions on where to place the useEmulatedTLS()
helper function; it's a parallel to the preexisting
TargetMachine::useEmulatedTLS() which does the same, within llvm.

Diff Detail

Event Timeline

mstorsjo created this revision.Aug 29 2022, 5:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2022, 5:24 AM
mstorsjo requested review of this revision.Aug 29 2022, 5:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2022, 5:24 AM

Adding a few more reviewers for better opinions, but the changes look reasonable to me.

I'm not really happy with the way this implicitly ties the implementation of this function to the implementation of TargetMachine::useEmulatedTLS(). I'd prefer to just make clang always explicitly compute whether EmullatedTLS is enabled, then always set ExplicitEmulatedTLS, so the backend can't choose something different from what the frontend thinks it should be using. (So we always call hasDefaultEmulatedTLS() if we can't find an femulated-tls flag in CompilerInvocation. And the ExplicitEmulatedTLS flag in clang goes away.)

Alternatively, if you think clang really shouldn't care whether emulated TLS is enabled, we could just conservatively return false from shouldAssumeDSOLocal, and let some later optimization clean it up. Not sure what implications that has for code generation.

mstorsjo abandoned this revision.Sep 13 2022, 1:01 AM

Abandoned in favour of D132916.