Skip to content

Commit 4eda362

Browse files
committed
[ELF] Inline computeAddend. NFC
1 parent 6db71b8 commit 4eda362

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

lld/ELF/Relocations.cpp

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,6 @@ class RelocationScanner {
451451
template <class RelTy> RelType getMipsN32RelType(RelTy *&rel) const;
452452
template <class ELFT, class RelTy>
453453
int64_t computeMipsAddend(const RelTy &rel, RelExpr expr, bool isLocal) const;
454-
template <class ELFT, class RelTy>
455-
int64_t computeAddend(const RelTy &rel, RelExpr expr, bool isLocal) const;
456454
bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym,
457455
uint64_t relOff) const;
458456
void processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym,
@@ -497,30 +495,6 @@ int64_t RelocationScanner::computeMipsAddend(const RelTy &rel, RelExpr expr,
497495
return 0;
498496
}
499497

500-
// Returns an addend of a given relocation. If it is RELA, an addend
501-
// is in a relocation itself. If it is REL, we need to read it from an
502-
// input section.
503-
template <class ELFT, class RelTy>
504-
int64_t RelocationScanner::computeAddend(const RelTy &rel, RelExpr expr,
505-
bool isLocal) const {
506-
int64_t addend;
507-
RelType type = rel.getType(config->isMips64EL);
508-
509-
if (RelTy::IsRela) {
510-
addend = getAddend<ELFT>(rel);
511-
} else {
512-
const uint8_t *buf = sec->rawData.data();
513-
addend = target->getImplicitAddend(buf + rel.r_offset, type);
514-
}
515-
516-
if (config->emachine == EM_PPC64 && config->isPic && type == R_PPC64_TOC)
517-
addend += getPPC64TocBase();
518-
if (config->emachine == EM_MIPS)
519-
addend += computeMipsAddend<ELFT>(rel, expr, isLocal);
520-
521-
return addend;
522-
}
523-
524498
// Custom error message if Sym is defined in a discarded section.
525499
template <class ELFT>
526500
static std::string maybeReportDiscarded(Undefined &sym) {
@@ -1363,35 +1337,36 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
13631337
uint32_t symIndex = rel.getSymbol(config->isMips64EL);
13641338
Symbol &sym = sec->getFile<ELFT>()->getSymbol(symIndex);
13651339
RelType type;
1366-
1367-
// Deal with MIPS oddity.
13681340
if (config->mipsN32Abi) {
13691341
type = getMipsN32RelType(i);
13701342
} else {
13711343
type = rel.getType(config->isMips64EL);
13721344
++i;
13731345
}
1374-
13751346
// Get an offset in an output section this relocation is applied to.
13761347
uint64_t offset = getter.get(rel.r_offset);
13771348
if (offset == uint64_t(-1))
13781349
return;
13791350

1380-
// Error if the target symbol is undefined. Symbol index 0 may be used by
1381-
// marker relocations, e.g. R_*_NONE and R_ARM_V4BX. Don't error on them.
1382-
if (sym.isUndefined() && symIndex != 0 &&
1383-
maybeReportUndefined(cast<Undefined>(sym), *sec, offset))
1384-
return;
1385-
1386-
const uint8_t *relocatedAddr = sec->rawData.begin() + offset;
1387-
RelExpr expr = target->getRelExpr(type, sym, relocatedAddr);
1351+
RelExpr expr = target->getRelExpr(type, sym, sec->rawData.data() + offset);
1352+
int64_t addend =
1353+
RelTy::IsRela
1354+
? getAddend<ELFT>(rel)
1355+
: target->getImplicitAddend(sec->rawData.data() + rel.r_offset, type);
1356+
if (LLVM_UNLIKELY(config->emachine == EM_MIPS))
1357+
addend += computeMipsAddend<ELFT>(rel, expr, sym.isLocal());
1358+
else if (config->emachine == EM_PPC64 && config->isPic && type == R_PPC64_TOC)
1359+
addend += getPPC64TocBase();
13881360

13891361
// Ignore R_*_NONE and other marker relocations.
13901362
if (expr == R_NONE)
13911363
return;
13921364

1393-
// Read an addend.
1394-
int64_t addend = computeAddend<ELFT>(rel, expr, sym.isLocal());
1365+
// Error if the target symbol is undefined. Symbol index 0 may be used by
1366+
// marker relocations, e.g. R_*_NONE and R_ARM_V4BX. Don't error on them.
1367+
if (sym.isUndefined() && symIndex != 0 &&
1368+
maybeReportUndefined(cast<Undefined>(sym), *sec, offset))
1369+
return;
13951370

13961371
if (config->emachine == EM_PPC64) {
13971372
// We can separate the small code model relocations into 2 categories:

0 commit comments

Comments
 (0)