Bug 28387 - ld: Move R_*_TLSDESC to .rela.dyn
Summary: ld: Move R_*_TLSDESC to .rela.dyn
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-25 20:26 UTC by Fangrui Song
Modified: 2021-09-25 20:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-09-25 20:26:35 UTC
Lazy R_*_TLSDESC resolving has several problems (e.g. data race) and glibc has eagerly resolved R_*_TLSDESC for all(?) supported ports: arm (PR18572)/aarch64 (PR18034)/x86 (PR27137).

It is also odd to overload .rela.plt (PLT) with TLSDESC which have quite different semantics.

Currently GNU ld still uses .rela.plt, but it probably makes sense to switch to .rela.dyn instead.

% cat x.c
extern __thread int tlsdesc;
int get(void) { return tlsdesc; }

% gcc -fpic -mtls-dialect=gnu2 -shared x.c && readelf -r a.out
...
Relocation section '.rela.plt' at offset 0x440 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000004018  000200000024 R_X86_64_TLSDESC  0000000000000000 tlsdesc + 0

% aarch64-linux-gnu-gcc -fpic -shared x.c && readelf -r a.out                                                 
...

Relocation section '.rela.plt' at offset 0x400 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000011000  000300000402 R_AARCH64_JUMP_SL 0000000000000000 __cxa_finalize + 0
000000011008  000700000402 R_AARCH64_JUMP_SL 0000000000000000 __gmon_start__ + 0
000000011010  000400000407 R_AARCH64_TLSDESC 0000000000000000 tlsdesc + 0

% arm-linux-gnueabi-gcc -fpic -mtls-dialect=gnu2 -fuse-ld=bfd -shared x.c && readelf -r a.out
...
Relocation section '.rel.plt' at offset 0x264 contains 3 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0001100c  00000316 R_ARM_JUMP_SLOT   00000000   __cxa_finalize
00011010  00000716 R_ARM_JUMP_SLOT   00000000   __gmon_start__
00011014  0000040d R_ARM_TLS_DESC    00000000   tlsdesc