summaryrefslogtreecommitdiff
path: root/devel/llvm70/files/lld/patch-head-r338297.diff
blob: 96e45ac1e0f5a68bb85621e0f73113ebc78fc632 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
r338297 | dim | 2018-08-24 19:48:05 +0200 (Fri, 24 Aug 2018) | 6 lines

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

Index: tools/lld/ELF/Config.h
===================================================================
--- tools/lld/ELF/Config.h	(revision 338296)
+++ tools/lld/ELF/Config.h	(revision 338297)
@@ -181,6 +181,7 @@ struct Configuration {
   bool ZCopyreloc;
   bool ZExecstack;
   bool ZHazardplt;
+  bool ZIfuncnoplt;
   bool ZInitfirst;
   bool ZKeepTextSectionPrefix;
   bool ZNodelete;
Index: tools/lld/ELF/Driver.cpp
===================================================================
--- tools/lld/ELF/Driver.cpp	(revision 338296)
+++ tools/lld/ELF/Driver.cpp	(revision 338297)
@@ -338,7 +338,8 @@ static bool getZFlag(opt::InputArgList &Args, Stri
 
 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 &
   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);
Index: tools/lld/ELF/Relocations.cpp
===================================================================
--- tools/lld/ELF/Relocations.cpp	(revision 338296)
+++ tools/lld/ELF/Relocations.cpp	(revision 338297)
@@ -366,6 +366,10 @@ static bool isStaticLinkTimeConstant(RelExpr E, Re
           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,
     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, Offse
   // 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);
Index: tools/lld/ELF/Writer.cpp
===================================================================
--- tools/lld/ELF/Writer.cpp	(revision 338296)
+++ tools/lld/ELF/Writer.cpp	(revision 338297)
@@ -1561,8 +1561,11 @@ template <class ELFT> void Writer<ELFT>::finalizeS
   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.