cranelift: Add COFF TLS Support#4546
Conversation
The gs register is not allocatable by regalloc, so it doesn't need to be marked as usable. |
| value: 0, | ||
| size: 32, | ||
| // TODO: Is this correct? | ||
| kind: SymbolKind::Tls, |
There was a problem hiding this comment.
I did expect it to not be correct.
There was a problem hiding this comment.
Looks like object doesn't distinguish between text, data and tls for COFF: https://github.com/gimli-rs/object/blob/404ae26dac1eafc82ecad4f02ba8ccda57f7cb27/src/write/coff.rs#L597 And I couldn't find anywhere COFF distinguishes between data and tls undefined symbols.
|
Thanks a lot for working on this! |
produces an object file for which and |
|
I managed to run a small tls example on windows! 🎉 #![feature(thread_local)]
use std::cell::Cell;
#[thread_local]
static FOO: Cell<u8> = Cell::new(42);
fn main() {
assert_eq!(FOO.get(), 42);
std::thread::spawn(|| {
FOO.set(43);
assert_eq!(FOO.get(), 43);
}).join();
assert_eq!(FOO.get(), 42);
} |
That's really cool! I'm going to try and compile |
9cc2c07 to
5e62aa9
Compare
1374636 to
4a17b3a
Compare
|
Rebased this on top of With this rebase we've also lost the lookup function. But we can add it later when we need it in the JIT, is this okay @bjorn3 ? |
|
Fine with me. |
|
Do you both feel this is ready for merge, then? I've glanced over it and it looks reasonable to me, but I'm not at all familiar with how thread-local storage works on any platform. |
|
Yes, this should be ready to merge! |
👋 Hey,
This PR is an initial draft at adding support for resolving TLS variables in COFF file formats (Windows). This is the current main blocker on having
cg_clifworking on windows.There are still some pending issues in this PR:
gsregister as used?_tls_indexsymbol. No idea if it is correct or not.It is my understanding (mostly based on #1885) that we still need to add COFF TLS support to the
objectcrate for this to become functional.I'm going to look into modifying the object crate to see how easy/hard its going to be to add support for this, but would really appreciate any help.
Based on my tests compiling
cranelift/filetests/filetests/isa/x64/tls_coff.clifwe emit pretty much the equivalent machine code and relocations as rustc does.Disassembly of rustc output:
Disassembly of tls_coff.clif output:
I think the only difference there is the target of the relocation, because in the
tls_coffexample I didn't name the symbol.cc: @bjorn3 @cfallin
cc: #1885