This is an archive of the discontinued LLVM Phabricator instance.

Support for the mno-tls-direct-seg-refs flag
ClosedPublic

Authored by nruslan on Oct 10 2018, 11:57 AM.

Details

Summary

Allows to disable direct TLS segment access (%fs or %gs). GCC supports a similar flag, it can be useful in some circumstances, e.g. when a thread context block needs to be updated directly from user space. More info and specific use cases: https://bugs.llvm.org/show_bug.cgi?id=16145

There is another revision for LLVM as well.

Related: D53103

Diff Detail

Repository
rC Clang

Event Timeline

nruslan created this revision.Oct 10 2018, 11:57 AM
nruslan added a reviewer: Restricted Project.Oct 10 2018, 11:59 AM
hans added a comment.Oct 11 2018, 7:15 AM

Looking good, just a few minor comments.

docs/ClangCommandLineReference.rst
2241 ↗(On Diff #169063)

This file is automatically generated based on the options .td files, so no need to update it here.

include/clang/Driver/CC1Options.td
195 ↗(On Diff #169063)

Could mno_tls_direct_seg_refs be used as a cc1 flag instead?

include/clang/Driver/Options.td
2177

Maybe add (default) to the help text to indicate this is the default?

nruslan updated this revision to Diff 169224.Oct 11 2018, 9:11 AM
nruslan marked 3 inline comments as done.

@hans , @craig.topper : Updated the patch with all requested changes

docs/ClangCommandLineReference.rst
2241 ↗(On Diff #169063)

ok

include/clang/Driver/CC1Options.td
195 ↗(On Diff #169063)

done

include/clang/Driver/Options.td
2177

done

@hans, @craig.topper : If everything is fine, can someone check in the clang and llvm patches on my behalf? I do not have commit access.

@nruslan This patchset is still pending review so be patient, I landed D53103 as it was reviewed and accepted by the code owner, on which this patch depends on. That said it LGTM, it's simple enough as it just forwards the argument to the backend, but still would rather have the X86 code owner sign off on this as well.

craig.topper accepted this revision.Oct 17 2018, 10:50 PM

LGTM with that one style comment fixed.

lib/Driver/ToolChains/Clang.cpp
1743

minor - I think this line should be lined up with the start of the arguments to hasFlags on the previous line.

This revision is now accepted and ready to land.Oct 17 2018, 10:50 PM

If the author doesn't mind I can just apply the style fix after patching and then rebuild and run all the relevant tests (or would you prefer to do that?). Seems easier than a new revision for an indentation change on one line.

If the author doesn't mind I can just apply the style fix after patching and then rebuild and run all the relevant tests (or would you prefer to do that?). Seems easier than a new revision for an indentation change on one line.

@kristina : Thank you! Sure, that is fine. Go ahead.

By the way, out of curiosity is this for anything specific (alternative libc or some user-mode-scheduling implementation)? Not nitpicking, just curious since it's an interesting topic in general and it's frustrating that the architecture is so limited in terms of registers that can be used for TLS/related data unlike newer ARM/ARM64 architectures.

Also FWIW %gs is generally free to use under x86_64 Linux which is where I usually place my thread control blocks which doesn't interfere with libc which uses %fs. (Just started build/test job, waiting on that for now)

nruslan added a comment.EditedOct 18 2018, 7:07 AM

By the way, out of curiosity is this for anything specific (alternative libc or some user-mode-scheduling implementation)? Not nitpicking, just curious since it's an interesting topic in general and it's frustrating that the architecture is so limited in terms of registers that can be used for TLS/related data unlike newer ARM/ARM64 architectures.

Also FWIW %gs is generally free to use under x86_64 Linux which is where I usually place my thread control blocks which doesn't interfere with libc which uses %fs. (Just started build/test job, waiting on that for now)

@kristina : Yes, there are some recent use cases mentioned in the bug report (see the link above). Also, I know that it was used for x86 (32-bit only) Xen guests where it would be recommended to compile an OS with this flag. I also used it in my fork of the NPTL pthread library in VirtuOS to support M:N threading model: http://sigops.org/sosp/sosp13/papers/p116-nikolaev.pdf

%gs is free in x86-64 Linux user space. AFAIK, it is used for per-CPU data in kernel and Win64.

This revision was automatically updated to reflect the committed changes.

@kristina : Thank you very much for taking care of the patchsets!