[PATCH] riscv: Fix RV32 libthread_db THREAD_SELF register layout

Shengwen Cheng shengwen1997.tw@gmail.com
Wed Jun 24 11:13:49 GMT 2026


Hi Jeff, Peter,

Thanks for taking a look.  That is much cleaner.

REGISTER uses the ## preprocessing operator to concatenate its first
argument with _thread_db_register in the exported descriptor symbol name:

  # define REGISTER(bits, size, regofs, bias) \
    DB_DEFINE_DESC (_thread_db_register##bits, size, \
                    (uint32_t)(bias), (regofs));

So passing __riscv_xlen directly would produce
_thread_db_register__riscv_xlen, rather than _thread_db_register32 or
_thread_db_register64.

Let me send a v2 using a small wrapper macro so __riscv_xlen is passed
to REGISTER as the actual register size:

  # define DB_THREAD_SELF_REGISTER(bits) \
    REGISTER (bits, bits, 4 * bits / 8, - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
  # define DB_THREAD_SELF DB_THREAD_SELF_REGISTER (__riscv_xlen)

This keeps the compact form while preserving the expected
_thread_db_register32 / _thread_db_register64 descriptor names.

Shengwen


More information about the Libc-alpha mailing list