@@ -1035,6 +1035,35 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
1035
1035
// space for the extra PT_LOAD even if we end up not using it.
1036
1036
void RelocationScanner::processAux (RelExpr expr, RelType type, uint64_t offset,
1037
1037
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
+
1038
1067
// If the relocation is known to be a link-time constant, we know no dynamic
1039
1068
// relocation will be created, pass the control to relocateAlloc() or
1040
1069
// relocateNonAlloc() to resolve it.
@@ -1399,16 +1428,13 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
1399
1428
}
1400
1429
}
1401
1430
1402
- // Relax relocations.
1403
- //
1404
1431
// If we know that a PLT entry will be resolved within the same ELF module, we
1405
1432
// can skip PLT access and directly jump to the destination function. For
1406
1433
// example, if we are linking a main executable, all dynamic symbols that can
1407
1434
// be resolved within the executable will actually be resolved that way at
1408
1435
// runtime, because the main executable is always at the beginning of a search
1409
1436
// 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 )) {
1412
1438
if (expr != R_GOT_PC) {
1413
1439
// The 0x8000 bit of r_addend of R_PPC_PLTREL24 is used to choose call
1414
1440
// 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) {
1426
1452
}
1427
1453
}
1428
1454
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
-
1457
1455
processAux (expr, type, offset, sym, addend);
1458
1456
}
1459
1457
0 commit comments