[libc-commits] [PATCH] D159110: [libc] Fix set_thread_ptr call in rv32 start up code
Jessica Clarke via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Aug 29 16:58:19 PDT 2023
jrtc27 added a comment.
In D159110#4626682 <https://reviews.llvm.org/D159110#4626682>, @sivachandra wrote:
> In D159110#4626672 <https://reviews.llvm.org/D159110#4626672>, @jrtc27 wrote:
>
>> In D159110#4626668 <https://reviews.llvm.org/D159110#4626668>, @sivachandra wrote:
>>
>>> For my knowledge, what is wrong with a `tp` load in the existing code?
>>
>> Well it's the difference between `x = p` and `x = *p`. Only one is ever the right thing to do. Like I said, "it's doing a load not a move, so is setting tp to whatever the first pointer in the static TLS block happens to be", i.e. you're reading in the first `sizeof(void *)` bytes of data from `.tdata` (or `.tbss`) and using that as the thread pointer, not the region of memory that just got mapped for the thread pointer.
>
> Shouldn't the `ld` operation overwrite `tp` and not read from `tp`? The assembly looks like this: https://godbolt.org/z/PTqfTcshv
Yes, it writes to `tp` (which is currently junk / 0), with the result of `*(void *)val`, where `val` points into the allocated TLS region, at the first byte of the static TLS block within it. Therefore it does exactly what I have now twice said it does.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D159110/new/
https://reviews.llvm.org/D159110
More information about the libc-commits
mailing list