[llvm-dev] __builtin_thread_pointer for RISC-V

Sam Elliott via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 25 09:17:09 PDT 2020


Oh Interesting. Please may you file a bug about clang crashing? We'll try to get to it soon.

In the meantime, I hope that inline assembly helps you.

Sam

> On 25 Mar 2020, at 4:05 pm, kamlesh kumar <kamleshbhalui at gmail.com> wrote:
> 
> Thanks for your reply Sam,
> GCC rejects the builtin but clang crashes.
> 
> 
> 
> On Wed, Mar 25, 2020, 9:06 PM Sam Elliott <selliott at lowrisc.org> wrote:
> Hi kamlesh,
> 
> Does GCC provide such a builtin?
> 
> At the moment, you can write inline assembly to access the `tp` register if you need to read it directly, like so (you can directly inline this if you need to):
> 
> void* read_thread_pointer(void) {
>   void* thread_pointer;
>   asm("mov %0, tp" : "=r"(thread_pointer) : );
>   return thread_pointer;
> }
> 
> I am not entirely sure how where `tp` points to in the different thread local models. There is more information on these models in the RISC-V ELF psABI document: https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#thread-local-storage
> 
> Sam
> 
> > On 25 Mar 2020, at 12:34 pm, kamlesh kumar via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> > 
> > Hi Devs,
> > since risc-v has a register $tp which is thread pointer.
> > is it possible to have __builtin_thread_pointer for RISC-V?
> > I am not sure what could be corresponding instructions?
> > 
> > ./kamlesh
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 
> --
> Sam Elliott
> Software Developer - LLVM and OpenTitan
> lowRISC CIC
> 

--
Sam Elliott
Software Developer - LLVM and OpenTitan
lowRISC CIC



More information about the llvm-dev mailing list