For reference for other newbies like me, there is this RFC about xplat TLS https://sel4.atlassian.net/browse/RFC-3 which gives a useful context.


From: Devel <devel-bounces@sel4.systems> on behalf of Alexandre Mutel <alexandre_mutel@live.com>
Sent: Saturday, November 23, 2019 13:58
To: devel@sel4.systems <devel@sel4.systems>
Subject: Re: [seL4] Understand how TLS is setup in the root server for x64
 
Never mind, I discovered that I in order to access a TLS variable you need to call `seL4_TCB_SetTLSBase` on seL4_CapInitThreadTCB first in the root server, as I'm trying to work on a bare bone usage of seL4 to better understand it, this part was not obvious from the existing more complex samples!

From: Devel <devel-bounces@sel4.systems> on behalf of Alexandre Mutel <alexandre_mutel@live.com>
Sent: Friday, November 22, 2019 22:12
To: devel@sel4.systems <devel@sel4.systems>
Subject: [seL4] Understand how TLS is setup in the root server for x64
 
Hello!

I'm trying to understand how the TLS is setup for the root server on x64 (to access for example the IPC buffer)
but I'm failing to connect the pieces and how the server is correctly setting the FS register.

For example the sel4_Send function is codegen like this (using -ftls-model=local-exec)

Function: seL4_Send
push      r15
mov       rdx,0FFFFFFFFFFFFFFFDh
push      rbx
mov       rax,[fs:0]
mov       r10,[rax+8]
mov       r8,[rax+10h]
mov       r9,[rax+18h]
mov       r15,[rax+20h]
mov       rbx,rsp
syscall
mov       rsp,rbx
pop       rbx
pop       r15
ret

The instruction `mov       rax,[fs:0]`  is accessing the seL4_IPCBuffer* and the the executable has a TLS segments of 8 bytes for the pointer. all good.
Now, I'm failing to find in the codebase where the ELF loader is actually detecting the TLS segment and the according setup with the TLS register.
And I'm wondering if the setup for the codegen is not wrong on my side (e.g the local-exec is not working), so that instead of having a FS register
it would be a direct memory access.

Does anyone have a clue about this?
Thank you!