Skip to content

Commit 874fc6b

Browse files
committed
[ELF] Move ELFT-agnostic relocation code to processAux. NFC
1 parent d0d48a9 commit 874fc6b

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

lld/ELF/Relocations.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,35 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
10351035
// space for the extra PT_LOAD even if we end up not using it.
10361036
void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
10371037
Symbol &sym, int64_t addend) const {
1038+
// We were asked not to generate PLT entries for ifuncs. Instead, pass the
1039+
// direct relocation on through.
1040+
const bool isIfunc = sym.isGnuIFunc();
1041+
if (LLVM_UNLIKELY(isIfunc) && config->zIfuncNoplt) {
1042+
std::lock_guard<std::mutex> lock(relocMutex);
1043+
sym.exportDynamic = true;
1044+
mainPart->relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type);
1045+
return;
1046+
}
1047+
1048+
if (needsGot(expr)) {
1049+
if (config->emachine == EM_MIPS) {
1050+
// MIPS ABI has special rules to process GOT entries and doesn't
1051+
// require relocation entries for them. A special case is TLS
1052+
// relocations. In that case dynamic loader applies dynamic
1053+
// relocations to initialize TLS GOT entries.
1054+
// See "Global Offset Table" in Chapter 5 in the following document
1055+
// for detailed description:
1056+
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
1057+
in.mipsGot->addEntry(*sec->file, sym, addend, expr);
1058+
} else {
1059+
sym.setFlags(NEEDS_GOT);
1060+
}
1061+
} else if (needsPlt(expr)) {
1062+
sym.setFlags(NEEDS_PLT);
1063+
} else if (LLVM_UNLIKELY(isIfunc)) {
1064+
sym.setFlags(HAS_DIRECT_RELOC);
1065+
}
1066+
10381067
// If the relocation is known to be a link-time constant, we know no dynamic
10391068
// relocation will be created, pass the control to relocateAlloc() or
10401069
// relocateNonAlloc() to resolve it.
@@ -1399,16 +1428,13 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
13991428
}
14001429
}
14011430

1402-
// Relax relocations.
1403-
//
14041431
// If we know that a PLT entry will be resolved within the same ELF module, we
14051432
// can skip PLT access and directly jump to the destination function. For
14061433
// example, if we are linking a main executable, all dynamic symbols that can
14071434
// be resolved within the executable will actually be resolved that way at
14081435
// runtime, because the main executable is always at the beginning of a search
14091436
// list. We can leverage that fact.
1410-
const bool isIfunc = sym.isGnuIFunc();
1411-
if (!sym.isPreemptible && (!isIfunc || config->zIfuncNoplt)) {
1437+
if (!sym.isPreemptible && (!sym.isGnuIFunc() || config->zIfuncNoplt)) {
14121438
if (expr != R_GOT_PC) {
14131439
// The 0x8000 bit of r_addend of R_PPC_PLTREL24 is used to choose call
14141440
// stub type. It should be ignored if optimized to R_PC.
@@ -1426,34 +1452,6 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
14261452
}
14271453
}
14281454

1429-
// We were asked not to generate PLT entries for ifuncs. Instead, pass the
1430-
// direct relocation on through.
1431-
if (LLVM_UNLIKELY(isIfunc) && config->zIfuncNoplt) {
1432-
std::lock_guard<std::mutex> lock(relocMutex);
1433-
sym.exportDynamic = true;
1434-
mainPart->relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type);
1435-
return;
1436-
}
1437-
1438-
if (needsGot(expr)) {
1439-
if (config->emachine == EM_MIPS) {
1440-
// MIPS ABI has special rules to process GOT entries and doesn't
1441-
// require relocation entries for them. A special case is TLS
1442-
// relocations. In that case dynamic loader applies dynamic
1443-
// relocations to initialize TLS GOT entries.
1444-
// See "Global Offset Table" in Chapter 5 in the following document
1445-
// for detailed description:
1446-
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
1447-
in.mipsGot->addEntry(*sec->file, sym, addend, expr);
1448-
} else {
1449-
sym.setFlags(NEEDS_GOT);
1450-
}
1451-
} else if (needsPlt(expr)) {
1452-
sym.setFlags(NEEDS_PLT);
1453-
} else if (LLVM_UNLIKELY(isIfunc)) {
1454-
sym.setFlags(HAS_DIRECT_RELOC);
1455-
}
1456-
14571455
processAux(expr, type, offset, sym, addend);
14581456
}
14591457

0 commit comments

Comments
 (0)