svn commit: r344655 - in stable: 11/contrib/llvm/tools/lld/ELF 11/contrib/llvm/tools/lld/ELF/Arch 12/contrib/llvm/tools/lld/ELF 12/contrib/llvm/tools/lld/ELF/Arch

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Thu, 28 Feb 2019 06:53:18 +0000 (UTC)
Author: dim
Date: Thu Feb 28 06:53:18 2019
New Revision: 344655
URL: https://svnweb.freebsd.org/changeset/base/344655

Log:
  MFC r344444:
  
  Pull in r353299 from upstream lld trunk (by George Rimar):
  
    Recommit r353293 "[LLD][ELF] - Set DF_STATIC_TLS flag for i386 target."
  
    With the following changes:
    1) Compilation fix:
    std::atomic<bool> HasStaticTlsModel = false; ->
    std::atomic<bool> HasStaticTlsModel{false};
  
    2) Adjusted the comment in code.
  
    Initial commit message:
  
    DF_STATIC_TLS flag indicates that the shared object or executable
    contains code using a static thread-local storage scheme.
  
    Patch checks if IE/LE relocations were used to check if the code uses
    a static model. If so it sets the DF_STATIC_TLS flag.
  
    Differential revision: https://reviews.llvm.org/D57749
  
  Pull in r353378 from upstream lld trunk (by George Rimar):
  
    [LLD][ELF] - Set DF_STATIC_TLS flag for X64 target
  
    This is the same as 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.
  
    Differential revision: https://reviews.llvm.org/D57821
  
  This adds support to lld for the DF_STATIC_TLS flag in shared objects,
  which signals to the dynamic linker that the shared object requires
  static thread local storage.
  
  See also:	https://reviews.freebsd.org/D19072

Modified:
  stable/12/contrib/llvm/tools/lld/ELF/Arch/X86.cpp
  stable/12/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp
  stable/12/contrib/llvm/tools/lld/ELF/Config.h
  stable/12/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/contrib/llvm/tools/lld/ELF/Arch/X86.cpp
  stable/11/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp
  stable/11/contrib/llvm/tools/lld/ELF/Config.h
  stable/11/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/contrib/llvm/tools/lld/ELF/Arch/X86.cpp
==============================================================================
--- stable/12/contrib/llvm/tools/lld/ELF/Arch/X86.cpp	Thu Feb 28 05:45:14 2019	(r344654)
+++ stable/12/contrib/llvm/tools/lld/ELF/Arch/X86.cpp	Thu Feb 28 06:53:18 2019	(r344655)
_at__at_ -70,6 +70,14 _at__at_ static bool hasBaseReg(uint8_t ModRM) { return (ModRM 
 
 RelExpr X86::getRelExpr(RelType Type, const Symbol &S,
                         const uint8_t *Loc) const {
+  // There are 4 different TLS variable models with varying degrees of
+  // flexibility and performance. LocalExec and InitialExec models are fast but
+  // less-flexible models. If they are in use, we set DF_STATIC_TLS flag in the
+  // dynamic section to let runtime know about that.
+  if (Type == R_386_TLS_LE || Type == R_386_TLS_LE_32 || Type == R_386_TLS_IE ||
+      Type == R_386_TLS_GOTIE)
+    Config->HasStaticTlsModel = true;
+
   switch (Type) {
   case R_386_8:
   case R_386_16:

Modified: stable/12/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp
==============================================================================
--- stable/12/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp	Thu Feb 28 05:45:14 2019	(r344654)
+++ stable/12/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp	Thu Feb 28 06:53:18 2019	(r344655)
_at__at_ -76,6 +76,9 _at__at_ template <class ELFT> X86_64<ELFT>::X86_64() {
 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:

Modified: stable/12/contrib/llvm/tools/lld/ELF/Config.h
==============================================================================
--- stable/12/contrib/llvm/tools/lld/ELF/Config.h	Thu Feb 28 05:45:14 2019	(r344654)
+++ stable/12/contrib/llvm/tools/lld/ELF/Config.h	Thu Feb 28 06:53:18 2019	(r344655)
_at__at_ -18,6 +18,7 _at__at_
 #include "llvm/Support/CachePruning.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Endian.h"
+#include <atomic>
 #include <vector>
 
 namespace lld {
_at__at_ -81,6 +82,7 _at__at_ struct VersionDefinition {
 // and such fields have the same name as the corresponding options.
 // Most fields are initialized by the driver.
 struct Configuration {
+  std::atomic<bool> HasStaticTlsModel{false};
   uint8_t OSABI = 0;
   llvm::CachePruningPolicy ThinLTOCachePolicy;
   llvm::StringMap<uint64_t> SectionStartMap;

Modified: stable/12/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp
==============================================================================
--- stable/12/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp	Thu Feb 28 05:45:14 2019	(r344654)
+++ stable/12/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp	Thu Feb 28 06:53:18 2019	(r344655)
_at__at_ -1282,6 +1282,8 _at__at_ template <class ELFT> void DynamicSection<ELFT>::final
   }
   if (!Config->ZText)
     DtFlags |= DF_TEXTREL;
+  if (Config->HasStaticTlsModel)
+    DtFlags |= DF_STATIC_TLS;
 
   if (DtFlags)
     addInt(DT_FLAGS, DtFlags);
Received on Thu Feb 28 2019 - 06:53:20 UTC