[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 17:21:21 PDT 2023


jrtc27 added a comment.

In D159110#4626771 <https://reviews.llvm.org/D159110#4626771>, @sivachandra wrote:

> In D159110#4626744 <https://reviews.llvm.org/D159110#4626744>, @jrtc27 wrote:
>
>>> 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.
>>
>> That is, currently the code does `tp = *(void **)val;`, but it should do `tp = val;`.
>
> What I am not getting is why should we even consider a dereference operation in the `ld` case. They way I understand, this is what is happening with `ld`:
>
> 1. Store `val` (which is in `a0`) on the stack.
> 2. Load `tp` with the value stored on the stack in the above step.
>
> So, there is no dereference happening anywhere?

Oh sorry, right, it's an m constraint, so it's implicitly &val. Bleh, I had skimmed over that. Then yes, the existing code was correct, just added pointless indirection and made it XLEN-specific. This change is still the sensible way to do things.


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