From owner-svn-src-head@freebsd.org Thu Feb 21 18:41:43 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6394A14EC041; Thu, 21 Feb 2019 18:41:43 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 065DB87E64; Thu, 21 Feb 2019 18:41:43 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA31221889; Thu, 21 Feb 2019 18:41:42 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1LIfgha085607; Thu, 21 Feb 2019 18:41:42 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1LIfgw8085603; Thu, 21 Feb 2019 18:41:42 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201902211841.x1LIfgw8085603@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Thu, 21 Feb 2019 18:41:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344444 - in head/contrib/llvm/tools/lld/ELF: . Arch X-SVN-Group: head X-SVN-Commit-Author: dim X-SVN-Commit-Paths: in head/contrib/llvm/tools/lld/ELF: . Arch X-SVN-Commit-Revision: 344444 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 065DB87E64 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; NEURAL_HAM_LONG(-1.00)[-0.999,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Feb 2019 18:41:43 -0000 Author: dim Date: Thu Feb 21 18:41:41 2019 New Revision: 344444 URL: https://svnweb.freebsd.org/changeset/base/344444 Log: 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 HasStaticTlsModel = false; -> std::atomic 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 MFC after: 1 week Modified: head/contrib/llvm/tools/lld/ELF/Arch/X86.cpp head/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp head/contrib/llvm/tools/lld/ELF/Config.h head/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp Modified: head/contrib/llvm/tools/lld/ELF/Arch/X86.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Arch/X86.cpp Thu Feb 21 17:31:33 2019 (r344443) +++ head/contrib/llvm/tools/lld/ELF/Arch/X86.cpp Thu Feb 21 18:41:41 2019 (r344444) @@ -70,6 +70,14 @@ 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: head/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp Thu Feb 21 17:31:33 2019 (r344443) +++ head/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp Thu Feb 21 18:41:41 2019 (r344444) @@ -76,6 +76,9 @@ template X86_64::X86_64() { template RelExpr X86_64::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: head/contrib/llvm/tools/lld/ELF/Config.h ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Config.h Thu Feb 21 17:31:33 2019 (r344443) +++ head/contrib/llvm/tools/lld/ELF/Config.h Thu Feb 21 18:41:41 2019 (r344444) @@ -18,6 +18,7 @@ #include "llvm/Support/CachePruning.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/Endian.h" +#include #include namespace lld { @@ -81,6 +82,7 @@ struct VersionDefinition { // and such fields have the same name as the corresponding options. // Most fields are initialized by the driver. struct Configuration { + std::atomic HasStaticTlsModel{false}; uint8_t OSABI = 0; llvm::CachePruningPolicy ThinLTOCachePolicy; llvm::StringMap SectionStartMap; Modified: head/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp Thu Feb 21 17:31:33 2019 (r344443) +++ head/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp Thu Feb 21 18:41:41 2019 (r344444) @@ -1282,6 +1282,8 @@ template void DynamicSection::final } if (!Config->ZText) DtFlags |= DF_TEXTREL; + if (Config->HasStaticTlsModel) + DtFlags |= DF_STATIC_TLS; if (DtFlags) addInt(DT_FLAGS, DtFlags);