Page MenuHomeFreeBSD

D16748.id46783.diff
No OneTemporary

D16748.id46783.diff

Index: contrib/llvm/tools/lld/ELF/Config.h
===================================================================
--- contrib/llvm/tools/lld/ELF/Config.h
+++ contrib/llvm/tools/lld/ELF/Config.h
@@ -155,6 +155,7 @@
bool ZCombreloc;
bool ZExecstack;
bool ZHazardplt;
+ bool ZIfuncnoplt;
bool ZNocopyreloc;
bool ZNodelete;
bool ZNodlopen;
Index: contrib/llvm/tools/lld/ELF/Driver.cpp
===================================================================
--- contrib/llvm/tools/lld/ELF/Driver.cpp
+++ contrib/llvm/tools/lld/ELF/Driver.cpp
@@ -669,6 +669,7 @@
Config->ZCombreloc = !hasZOption(Args, "nocombreloc");
Config->ZExecstack = hasZOption(Args, "execstack");
Config->ZHazardplt = hasZOption(Args, "hazardplt");
+ Config->ZIfuncnoplt = hasZOption(Args, "ifunc-noplt");
Config->ZNocopyreloc = hasZOption(Args, "nocopyreloc");
Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNodlopen = hasZOption(Args, "nodlopen");
Index: contrib/llvm/tools/lld/ELF/Relocations.cpp
===================================================================
--- contrib/llvm/tools/lld/ELF/Relocations.cpp
+++ contrib/llvm/tools/lld/ELF/Relocations.cpp
@@ -374,6 +374,9 @@
R_PPC_PLT_OPD, R_TLSDESC_CALL, R_TLSDESC_PAGE, R_HINT>(E))
return true;
+ 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)
@@ -921,7 +924,9 @@
// Strenghten or relax a PLT access.
//
// GNU ifunc symbols must be accessed via PLT because their addresses
- // are determined by runtime.
+ // are determined by runtime. If the -z ifunc-noplt option is specified,
+ // we permit the optimization of ifunc calls by omitting the PLT entry
+ // and preserving relocations at ifunc call sites.
//
// On the other hand, if we know that a PLT entry will be resolved within
// the same ELF module, we can skip PLT access and directly jump to the
@@ -929,7 +934,7 @@
// 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 (!Preemptible && Expr == R_GOT_PC && !isAbsoluteValue(Sym))
Expr =
@@ -1034,6 +1039,16 @@
continue;
}
+ // Preserve relocations against ifuncs if we were asked to do so.
+ if (Sym.isGnuIFunc() && Config->ZIfuncnoplt) {
+ if (Config->IsRela)
+ InX::RelaDyn->addReloc({Type, &Sec, Offset, false, &Sym, Addend});
+ else
+ // Preserve the existing addend.
+ InX::RelaDyn->addReloc({Type, &Sec, Offset, false, &Sym, 0});
+ continue;
+ }
+
// If the output being produced is position independent, the final value
// is still not known. In that case we still need some help from the
// dynamic linker. We can however do better than just copying the incoming
Index: contrib/llvm/tools/lld/ELF/Writer.cpp
===================================================================
--- contrib/llvm/tools/lld/ELF/Writer.cpp
+++ contrib/llvm/tools/lld/ELF/Writer.cpp
@@ -1400,8 +1400,11 @@
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.

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 8, 1:39 AM (4 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31064342
Default Alt Text
D16748.id46783.diff (3 KB)

Event Timeline