Stream: t-compiler/help

Topic: devkita64 tls help


leo60228 (Jul 20 2020 at 13:03, on Zulip):

I'm working on a Rust target for DevkitA64 (the most popular toolchain for Nintendo Switch homebrew). DevkitA64, for historical reasons, uses soft TLS instead of hard TLS. Soft TLS is very uncommon on aarch64, and upstream LLVM doesn't support it. There's a patch adding it at https://github.com/Thog/llvm/commit/8657ba2a3b1c8433259e68040b5724f0b8118a09, but it seems too specific to upstream, but also doesn't make much sense to add to Rust's LLVM fork...

bjorn3 (Jul 20 2020 at 13:09, on Zulip):

Can you implement it in libstd instead? #[thread_local] static is nightly only, so pretty much everyone uses the thread_local! macro, which can expand to whatever code you want to implement TLS.

leo60228 (Jul 20 2020 at 13:19, on Zulip):

I'm not sure. I don't think so, but maybe? I've asked the author of that patch.

leo60228 (Jul 20 2020 at 13:36, on Zulip):

Non-ELF TLS works fine because the actual TLS code is compiled by GCC. I'm going to try and get ELF TLS working anyway, just because I feel like not doing that could lead to issues with stuff like errno later on.

leo60228 (Jul 20 2020 at 14:17, on Zulip):

Just got that patch working, for what it's worth.

eddyb (Jul 20 2020 at 16:38, on Zulip):

@leo60228 I think what @bjorn3 is referring to uses the pthread_key_create / pthread_{set,get}specific API, so if you have something like that you should be able to integrate it

leo60228 (Jul 20 2020 at 16:38, on Zulip):

I know, that works. I'm just worried about what happens when Rust tries to access TLS defined in C code.

eddyb (Jul 20 2020 at 16:38, on Zulip):

I'm not even sure we use LLVM soft TLS anywhere. maybe we should, to make #[thread_local] work everywhere

eddyb (Jul 20 2020 at 16:39, on Zulip):

ah, for like errno?

leo60228 (Jul 20 2020 at 16:39, on Zulip):

Yeah.

eddyb (Jul 20 2020 at 16:39, on Zulip):

you can pretty much ensure it never happens, I think?

eddyb (Jul 20 2020 at 16:40, on Zulip):

there's a has_elf_tls flag in the target spec that controls whether #[thread_local] even exists

Last update: Sep 28 2020 at 16:15UTC