[PATCH] D57821: [LLD][ELF] - Set DF_STATIC_TLS flag for X64 target

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 6 07:33:49 PST 2019


grimar created this revision.
grimar added a reviewer: ruiu.
Herald added subscribers: krytarowski, arichardson.
Herald added a reviewer: espindola.

This is the same as D57749 <https://reviews.llvm.org/D57749>, but for x64 target.

"ELF Handling For Thread-Local Storage" p41 says (https://www.akkadia.org/drepper/tls.pdf):
R_X86_64_GOTTPOFF relocation is used for IE TLS models.
Hence if linker sees this relocation we should add DF_STATIC_TLS flag.
This is the relocation which FreeBSD was interested in initially I think (https://reviews.freebsd.org/D19072)

For LE model (p49), the R_X86_64_TPOFF32 is used.
But linkers do not allow to use it for DSO, for example, LLD would report:
"error: relocation R_X86_64_TPOFF32 cannot be used against symbol var; recompile with -fPIC"
So seems we only want to catch the R_X86_64_GOTTPOFF?


https://reviews.llvm.org/D57821

Files:
  ELF/Arch/X86_64.cpp
  test/ELF/x86_64-static-tls-model.s


Index: test/ELF/x86_64-static-tls-model.s
===================================================================
--- /dev/null
+++ test/ELF/x86_64-static-tls-model.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+
+## In this test R_X86_64_GOTTPOFF is a IE relocation (static TLS model),
+## test check we add STATIC_TLS flag.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t1 -shared
+# RUN: llvm-readobj -dynamic-table %t1 | FileCheck %s
+
+# CHECK: DynamicSection [
+# CHECK: FLAGS STATIC_TLS
+
+.section ".tdata", "awT", @progbits
+.globl var
+var:
+
+movq var at GOTTPOFF(%rip), %rax # R_X86_64_GOTTPOFF
+movl %fs:0(%rax), %eax
Index: ELF/Arch/X86_64.cpp
===================================================================
--- ELF/Arch/X86_64.cpp
+++ ELF/Arch/X86_64.cpp
@@ -81,6 +81,9 @@
 template <class ELFT>
 RelExpr X86_64<ELFT>::getRelExpr(RelType Type, const Symbol &S,
                                  const uint8_t *Loc) const {
+  if (Type == R_X86_64_GOTTPOFF)
+    Config->HasStaticTlsModel = true;
+
   switch (Type) {
   case R_X86_64_8:
   case R_X86_64_16:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57821.185553.patch
Type: text/x-patch
Size: 1110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190206/e896b334/attachment.bin>


More information about the llvm-commits mailing list