[PATCH] D60945: [ELF][X86] Allow R_386_TLS_LDO_32 and R_X86_64_DTPOFF{32,64} to preemptable local-dynamic symbols

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 21 03:51:16 PDT 2019


MaskRay created this revision.
MaskRay added a reviewer: ruiu.
Herald added subscribers: llvm-commits, atanasyan, arichardson, sdardis, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Fixes PR35242. A simplified reproduce:

  thread_local int i; int f() { return i; }

% {g++,clang++} -fPIC -shared -ftls-model=local-dynamic -fuse-ld=lld a.cc
ld.lld: error: can't create dynamic relocation R_X86_64_DTPOFF32 against symbol: i in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

In isStaticLinkTimeConstant, Syn.IsPreemptible is true so it not seen as a constant.
The error is then issued in processRelocAux.

A symbol of the local-dynamic TLS model cannot be preempted but it can
preempt symbols of the global-dynamic TLS model in other DSOs.
So it makes some sense that the variable is not static.

This patch fixes the linking error by changing getRelExpr() on
R_386_TLS_LDO_32 and R_X86_64_DTPOFF{32,64} from R_ABS to R_DTPREL.
R_PPC64_DTPREL_* and R_MIPS_TLS_DTPREL_* need similar fixes, but they are not handled in this patch.

As a bonus, we use `if (Expr == R_ABS && !Config->Shared)` to find
ld-to-le opportunities. After all R_*_DTPREL_* migrate away from R_ABS,
this will check fewer relocations.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D60945

Files:
  ELF/Arch/X86.cpp
  ELF/Arch/X86_64.cpp
  ELF/InputSection.cpp
  ELF/Relocations.cpp
  ELF/Relocations.h
  test/ELF/i386-tls-ld-preemptable.s
  test/ELF/x86-64-tls-ld-preemptable.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60945.195996.patch
Type: text/x-patch
Size: 4650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190421/03f80d21/attachment.bin>


More information about the llvm-commits mailing list