-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
s390x: Implement tls_value #4616
Conversation
#4546 introduces a |
Looking at this, I'm wondering why the whole mechanism of allowing names to be replaced externally is even necessary here. I can see where this is useful for libcalls, in case you want to substitute another library. But for something like So maybe it would be simpler to just add a feature to allow the backend to simply hard-code a symbol name? |
bjorn3 mentioned that we may need it in the JIT to perform TLS lookups |
I'm still not sure I see it - at least in the case of |
In the JIT no object files are created and it is not possible to use the libc tls implementation. My idea has been to intercept the libc function call to get the tls address and implement it in the jit, entirely avoiding libc in the process (except for a single native tls access to get a list of all jit tls values for the current thread)
Unless the jit consumer does the implementation. |
Reading the pr description it doesn't seem like the way I was planning to implement it on x86_64 will work on s390x, as on s390x the generated code already accesses the tls register, while on x86_64 this is left for the libcall that can be replaced. |
I think this also applies to the COFF TLS model, we never perform any libcall's, its all relocations. And if we want to implement it in the JIT we are also going to need to handle that separately in the JIT linker right? |
Even on Windows it would be possible to use ELF tls in the JIT.
At least a prototype can be done outside of the jit in cg_clif itself. |
So the way GD TLS works on s390x is that you 1) have a constant pool entry that contains a relocation which the linker will resolve to the GOT offset of a pair of GOT slots holding the TLS module index and offset for the target symbol; 2) load this GOT offset and pass it to There is a linker optimization in play, for the case where you don't need the full general-dynamic support, that will do two things: 1) change the relocation on the constant pool entry to directly place the TLS section offset of the target symbol there (instead of the GOT offset of the module/offset pair), and replace the call to W.r.t. implementing TLS in the JIT, I guess that depends to a large extent on what exactly should be supported. But the fact that we add the thread pointer in itself doesn't change much - if nothing better is possible, you can always implement This will require overloading This discussion is about |
For the JIT case it would probably have a value of 0, or whatever arbitrary value the JIT wants as it isn't actually necessary there. |
392b909
to
a069750
Compare
Well, the TLS relocation resolves to an offset relative to the GOT, so the value GLOBAL_OFFSET_TABLE must match how these offsets were computed. It's probably true you can choose any arbitrary value in the JIT, including zero, as long as it's used consistently. However, this just reinforces my point that the JIT will resolve this, even if to always 0. It will never be replaced by some other symbol, therefore having a replaceable name is not useful. |
a069750
to
c76a4a4
Compare
I've now updated the patch to include the @bjorn3 does this look reasonable to you? |
Implement the tls_value for s390 in the ELF general-dynamic mode. Notable differences to the x86_64 implementation are: - We use a __tls_get_offset libcall instead of __tls_get_addr. - The current thread pointer (stored in a pair of access registers) needs to be added to the result of __tls_get_offset. - __tls_get_offset has a variant ABI that requires the address of the GOT (global offset table) is passed in %r12. This means we need a new libcall entries for __tls_get_offset. In addition, we also need a way to access _GLOBAL_OFFSET_TABLE_. The latter is a "magic" symbol with a well-known name defined by the ABI and recognized by the linker. This patch introduces a new ExternalName::KnownSymbol variant to support such names (originally due to @afonso360). We also need to emit a relocation on a symbol placed in a constant pool, as well as an extra relocation on the call to __tls_get_offset required for TLS linker optimization. Needed by the cg_clif frontend.
c76a4a4
to
dd6d2b6
Compare
Hi @cfallin @bjorn3 @afonso360 as far as I can see, this version no longer has any open issues and should be good to go. (It will conflict with #4546 as it pulls it parts of that change, but that should be easy to resolve once it's in.) Is this now OK, or are there any further changes needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me; I'm not familiar with the s390x-specific conventions here but the KnownSymbol abstraction is reasonable and otherwise everything looks like I would expect. Thanks!
I think we should merge this PR first. I copied the implementation of |
Implement the tls_value for s390 in the ELF general-dynamic mode.
Notable differences to the x86_64 implementation are:
__tls_get_offset
libcall instead of__tls_get_addr
.needs to be added to the result of
__tls_get_offset
.__tls_get_offset
has a variant ABI that requires the address ofthe GOT (global offset table) is passed in %r12.
This means we need a new libcall entries for
__tls_get_offset
.In addition, we also need a way to access
_GLOBAL_OFFSET_TABLE_
.The latter is a "magic" symbol with a well-known name defined
by the ABI and recognized by the linker. This patch introduces
a new
ExternalName::KnownSymbol
variant to support such names(originally due to @afonso360).
We also need to emit a relocation on a symbol placed in a
constant pool, as well as an extra relocation on the call
to
__tls_get_offset
required for TLS linker optimization.Needed by the cg_clif frontend.