Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Aug 2018 17:48:05 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r338297 - projects/clang700-import/contrib/llvm/tools/lld/ELF
Message-ID:  <201808241748.w7OHm5SD097425@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Fri Aug 24 17:48:05 2018
New Revision: 338297
URL: https://svnweb.freebsd.org/changeset/base/338297

Log:
  Apply r338251 ("Preserve relocations against ifuncs when -zifunc-noplt
  is specified") on top of lld 7.0.0.  This is to prepare for another
  merge from head.
  
  Obtained from:	https://github.com/markjdb/freebsd-dev/commit/02f35faa6df364769b9223746b99e3c7ba05c5dd

Modified:
  projects/clang700-import/contrib/llvm/tools/lld/ELF/Config.h
  projects/clang700-import/contrib/llvm/tools/lld/ELF/Driver.cpp
  projects/clang700-import/contrib/llvm/tools/lld/ELF/Relocations.cpp
  projects/clang700-import/contrib/llvm/tools/lld/ELF/Writer.cpp

Modified: projects/clang700-import/contrib/llvm/tools/lld/ELF/Config.h
==============================================================================
--- projects/clang700-import/contrib/llvm/tools/lld/ELF/Config.h	Fri Aug 24 15:01:58 2018	(r338296)
+++ projects/clang700-import/contrib/llvm/tools/lld/ELF/Config.h	Fri Aug 24 17:48:05 2018	(r338297)
@@ -181,6 +181,7 @@ struct Configuration {
   bool ZCopyreloc;
   bool ZExecstack;
   bool ZHazardplt;
+  bool ZIfuncnoplt;
   bool ZInitfirst;
   bool ZKeepTextSectionPrefix;
   bool ZNodelete;

Modified: projects/clang700-import/contrib/llvm/tools/lld/ELF/Driver.cpp
==============================================================================
--- projects/clang700-import/contrib/llvm/tools/lld/ELF/Driver.cpp	Fri Aug 24 15:01:58 2018	(r338296)
+++ projects/clang700-import/contrib/llvm/tools/lld/ELF/Driver.cpp	Fri Aug 24 17:48:05 2018	(r338297)
@@ -338,7 +338,8 @@ static bool getZFlag(opt::InputArgList &Args, StringRe
 
 static bool isKnown(StringRef S) {
   return S == "combreloc" || S == "copyreloc" || S == "defs" ||
-         S == "execstack" || S == "hazardplt" || S == "initfirst" ||
+         S == "execstack" || S == "hazardplt" || S == "ifunc-noplt" ||
+         S == "initfirst" ||
          S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
          S == "nocombreloc" || S == "nocopyreloc" || S == "nodelete" ||
          S == "nodlopen" || S == "noexecstack" ||
@@ -843,6 +844,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args
   Config->ZCopyreloc = getZFlag(Args, "copyreloc", "nocopyreloc", true);
   Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);
   Config->ZHazardplt = hasZOption(Args, "hazardplt");
+  Config->ZIfuncnoplt = hasZOption(Args, "ifunc-noplt");
   Config->ZInitfirst = hasZOption(Args, "initfirst");
   Config->ZKeepTextSectionPrefix = getZFlag(
       Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);

Modified: projects/clang700-import/contrib/llvm/tools/lld/ELF/Relocations.cpp
==============================================================================
--- projects/clang700-import/contrib/llvm/tools/lld/ELF/Relocations.cpp	Fri Aug 24 15:01:58 2018	(r338296)
+++ projects/clang700-import/contrib/llvm/tools/lld/ELF/Relocations.cpp	Fri Aug 24 17:48:05 2018	(r338297)
@@ -366,6 +366,10 @@ static bool isStaticLinkTimeConstant(RelExpr E, RelTyp
           R_TLSLD_HINT>(E))
     return true;
 
+  // The computation involves output from the ifunc resolver.
+  if (Sym.isGnuIFunc() && Config->ZIfuncnoplt)
+    return false;
+
   // These never do, except if the entire file is position dependent or if
   // only the low bits are used.
   if (E == R_GOT || E == R_PLT || E == R_TLSDESC)
@@ -816,6 +820,10 @@ static void processRelocAux(InputSectionBase &Sec, Rel
     Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});
     return;
   }
+  if (Sym.isGnuIFunc() && Config->ZIfuncnoplt) {
+    InX::RelaDyn->addReloc(Type, &Sec, Offset, &Sym, Addend, R_ADDEND, Type);
+    return;
+  }
   bool CanWrite = (Sec.Flags & SHF_WRITE) || !Config->ZText;
   if (CanWrite) {
     // R_GOT refers to a position in the got, even if the symbol is preemptible.
@@ -985,7 +993,7 @@ static void scanReloc(InputSectionBase &Sec, OffsetGet
   // all dynamic symbols that can be resolved within the executable will
   // actually be resolved that way at runtime, because the main exectuable
   // is always at the beginning of a search list. We can leverage that fact.
-  if (Sym.isGnuIFunc())
+  if (Sym.isGnuIFunc() && !Config->ZIfuncnoplt)
     Expr = toPlt(Expr);
   else if (!Sym.IsPreemptible && Expr == R_GOT_PC && !isAbsoluteValue(Sym))
     Expr = Target->adjustRelaxExpr(Type, RelocatedAddr, Expr);

Modified: projects/clang700-import/contrib/llvm/tools/lld/ELF/Writer.cpp
==============================================================================
--- projects/clang700-import/contrib/llvm/tools/lld/ELF/Writer.cpp	Fri Aug 24 15:01:58 2018	(r338296)
+++ projects/clang700-import/contrib/llvm/tools/lld/ELF/Writer.cpp	Fri Aug 24 17:48:05 2018	(r338297)
@@ -1561,8 +1561,11 @@ template <class ELFT> void Writer<ELFT>::finalizeSecti
   applySynthetic({InX::EhFrame},
                  [](SyntheticSection *SS) { SS->finalizeContents(); });
 
-  for (Symbol *S : Symtab->getSymbols())
+  for (Symbol *S : Symtab->getSymbols()) {
     S->IsPreemptible |= computeIsPreemptible(*S);
+    if (S->isGnuIFunc() && Config->ZIfuncnoplt)
+      S->ExportDynamic = true;
+  }
 
   // Scan relocations. This must be done after every symbol is declared so that
   // we can correctly decide if a dynamic relocation is needed.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808241748.w7OHm5SD097425>