[lld] [LLD][AArch64] Handle R_AARCH64_TLS_DTPREL64 in non-alloc sections (PR #183962)
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 12 18:46:12 PDT 2026
igorkudrin wrote:
> Do you have an example that a thread-locaal variable doesn't have a symbol table entry?
>
> While an executable can have multiple local symbols of the same name, local symbols are grouped starting with a STT_FILE symbol, which could be used to resolve ambiguity.
>
> Internal linkage TLS variables still lower to local symbols. There is no lost information.
>
> Perhaps inaccurate location information happens with struct member access (`struct A { int a, b; };`).
You are right, they have symtab entries. However, as compilers often do not generate the `DW_AT_linkage_name` for these variables, the debugger would need to calculate it itself, which might be a really complex task:
- The symbol name has to be reconstructed, taking into account whether the variable is declared inside a subroutine, namespace, or CU.
- There may be several variables with the same name in a function, so a suffix should be added. Or maybe not, if some of these variables are automatic and do not have symtab entries.
- There may be variables with the same name with internal linkage, so their symtab entries will also have the same names. The debugger can try to track such variables, assuming the order in the symbol table matches the debug info; this is not guaranteed because the linker can rearrange input sections.
- As the symbol table is not required to run a program, it can be stripped, totally or partially.
Knowing the linkage name can be beneficial for global variables that can be interposed. But for the basic scenario, when the debugger simply needs to find the location of the variable, it is overcomplicated. The symtab entry contains the offset of the variable in the module's TLS data, and exactly the same value is stored in the `DW_AT_location` attribute of the variable's DIE, followed by `DW_OP_GNU_push_tls_address` / `DW_OP_form_tls_address`. It is so much easier for the debugger to just read the location expression for the corresponding attribute of the variable's DIE, than to try to acquire the same information through the symtab.
https://github.com/llvm/llvm-project/pull/183962
More information about the llvm-commits
mailing list