[lld] r296788 - Pass a callback to resolveReloc. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 11:29:28 PST 2017
Author: rafael
Date: Thu Mar 2 13:29:28 2017
New Revision: 296788
URL: http://llvm.org/viewvc/llvm-project?rev=296788&view=rev
Log:
Pass a callback to resolveReloc. NFC.
This is consistent with rest of the file and opens the way for a
relocation keeping multiple sections alive.
Modified:
lld/trunk/ELF/MarkLive.cpp
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=296788&r1=296787&r2=296788&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu Mar 2 13:29:28 2017
@@ -64,15 +64,16 @@ static typename ELFT::uint getAddend(Inp
}
template <class ELFT, class RelT>
-static ResolvedReloc resolveReloc(InputSectionBase &Sec, RelT &Rel) {
+static void resolveReloc(InputSectionBase &Sec, RelT &Rel,
+ std::function<void(ResolvedReloc)> Fn) {
SymbolBody &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
auto *D = dyn_cast<DefinedRegular>(&B);
if (!D || !D->Section)
- return {nullptr, 0};
+ return;
typename ELFT::uint Offset = D->Value;
if (D->isSection())
Offset += getAddend<ELFT>(Sec, Rel);
- return {D->Section->Repl, Offset};
+ Fn({D->Section->Repl, Offset});
}
// Calls Fn for each section that Sec refers to via relocations.
@@ -81,10 +82,10 @@ static void forEachSuccessor(InputSectio
std::function<void(ResolvedReloc)> Fn) {
if (Sec.AreRelocsRela) {
for (const typename ELFT::Rela &Rel : Sec.template relas<ELFT>())
- Fn(resolveReloc<ELFT>(Sec, Rel));
+ resolveReloc<ELFT>(Sec, Rel, Fn);
} else {
for (const typename ELFT::Rel &Rel : Sec.template rels<ELFT>())
- Fn(resolveReloc<ELFT>(Sec, Rel));
+ resolveReloc<ELFT>(Sec, Rel, Fn);
}
for (InputSectionBase *IS : Sec.DependentSections)
Fn({IS, 0});
@@ -116,7 +117,7 @@ static void scanEhFrameSection(EhInputSe
if (read32<E>(Piece.data().data() + 4) == 0) {
// This is a CIE, we only need to worry about the first relocation. It is
// known to point to the personality function.
- Enqueue(resolveReloc<ELFT>(EH, Rels[FirstRelI]));
+ resolveReloc<ELFT>(EH, Rels[FirstRelI], Enqueue);
continue;
}
// This is a FDE. The relocations point to the described function or to
@@ -127,12 +128,13 @@ static void scanEhFrameSection(EhInputSe
const RelTy &Rel = Rels[I2];
if (Rel.r_offset >= PieceEnd)
break;
- ResolvedReloc R = resolveReloc<ELFT>(EH, Rels[I2]);
- if (!R.Sec || R.Sec == &InputSection::Discarded)
- continue;
- if (R.Sec->Flags & SHF_EXECINSTR)
- continue;
- Enqueue({R.Sec, 0});
+ resolveReloc<ELFT>(EH, Rels[I2], [&](ResolvedReloc R) {
+ if (!R.Sec || R.Sec == &InputSection::Discarded)
+ return;
+ if (R.Sec->Flags & SHF_EXECINSTR)
+ return;
+ Enqueue({R.Sec, 0});
+ });
}
}
}
@@ -188,7 +190,7 @@ template <class ELFT> void elf::markLive
// the ELF spec doesn't allow a relocation to point to a deduplicated
// COMDAT section directly. Unfortunately this happens in practice (e.g.
// .eh_frame) so we need to add a check.
- if (!R.Sec || R.Sec == &InputSection::Discarded)
+ if (R.Sec == &InputSection::Discarded)
return;
// We don't gc non alloc sections.
More information about the llvm-commits
mailing list