abi-aa
abi-aa copied to clipboard
[aaelf64] No static TLS 64-bit relocation with expression DTPREL(S+A)
Both clang and GCC leave out the DW_AT_location
for TLS variables ostensibly due to lack of a relocation to describe the location in the debug data.
For x86_64 DW_AT_location
is emitted as:
DW_AT_location (DW_OP_const8u 0x0, DW_OP_form_tls_address)
With the relocation:
R_X86_64_DTPOFF64
to the symbol definition.
In AArch64 the closest equivalent is R_AArch64_TLS_DTPREL
although it is marked as a dynamic relocation (normally used for the GOT entry created by the global-dynamic in the traditional dialect). If we marked this relocation as static and dynamic (and made sure that static linkers could handle it in a static context), then we could support DW_AT_location
LLVM review that removed the DW_AT_location
https://reviews.llvm.org/D43860
For example:
__thread int foo;
int main(void) {
return foo;
}
With clang -g -O2 --target=aarch64-linux-gnu
0x00000023: DW_TAG_variable
DW_AT_name ("foo")
DW_AT_type (0x0000002b "int")
DW_AT_external (true)
DW_AT_decl_file ("/path/to/tlsdbg.c")
DW_AT_decl_line (1)
With an x86_64 target
0x00000023: DW_TAG_variable
DW_AT_name ("foo")
DW_AT_type (0x00000036 "int")
DW_AT_external (true)
DW_AT_decl_file ("/path/to/tlsdbg.c")
DW_AT_decl_line (1)
DW_AT_location (DW_OP_const8u 0x0, DW_OP_GNU_push_tls_address)
The x86_64 relocs are
Relocation section '.rela.debug_info' at offset 0x400 contains 5 entries:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000000008 000000030000000a R_X86_64_32 0000000000000000 .debug_abbrev + 0
0000000000000011 000000040000000a R_X86_64_32 0000000000000000 .debug_str_offsets + 8
0000000000000015 000000070000000a R_X86_64_32 0000000000000000 .debug_line + 0
000000000000001f 000000060000000a R_X86_64_32 0000000000000000 .debug_addr + 8
000000000000002d 0000000a00000011 R_X86_64_DTPOFF64 0000000000000000 foo + 0
Note the R_X86_64_DTPOFF64