Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/llvm/tools/lld/ELF/MarkLive.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
// identifiers, so we just store a std::vector instead of a multimap. | // identifiers, so we just store a std::vector instead of a multimap. | ||||
static DenseMap<StringRef, std::vector<InputSectionBase *>> CNamedSections; | static DenseMap<StringRef, std::vector<InputSectionBase *>> CNamedSections; | ||||
template <class ELFT, class RelT> | template <class ELFT, class RelT> | ||||
static void resolveReloc(InputSectionBase &Sec, RelT &Rel, | static void resolveReloc(InputSectionBase &Sec, RelT &Rel, | ||||
std::function<void(ResolvedReloc)> Fn) { | std::function<void(ResolvedReloc)> Fn) { | ||||
SymbolBody &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel); | SymbolBody &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel); | ||||
if (auto *D = dyn_cast<DefinedRegular>(&B)) { | if (auto *D = dyn_cast<DefinedRegular>(&B)) { | ||||
if (!D->Section) | auto *RelSec = dyn_cast_or_null<InputSectionBase>(D->Section); | ||||
if (!RelSec) | |||||
return; | return; | ||||
typename ELFT::uint Offset = D->Value; | typename ELFT::uint Offset = D->Value; | ||||
if (D->isSection()) | if (D->isSection()) | ||||
Offset += getAddend<ELFT>(Sec, Rel); | Offset += getAddend<ELFT>(Sec, Rel); | ||||
Fn({cast<InputSectionBase>(D->Section), Offset}); | Fn({RelSec, Offset}); | ||||
} else if (auto *U = dyn_cast<Undefined>(&B)) { | } else if (auto *U = dyn_cast<Undefined>(&B)) { | ||||
for (InputSectionBase *Sec : CNamedSections.lookup(U->getName())) | for (InputSectionBase *Sec : CNamedSections.lookup(U->getName())) | ||||
Fn({Sec, 0}); | Fn({Sec, 0}); | ||||
} | } | ||||
} | } | ||||
// Calls Fn for each section that Sec refers to via relocations. | // Calls Fn for each section that Sec refers to via relocations. | ||||
template <class ELFT> | template <class ELFT> | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | auto Enqueue = [&](ResolvedReloc R) { | ||||
R.Sec->Live = true; | R.Sec->Live = true; | ||||
// Add input section to the queue. | // Add input section to the queue. | ||||
if (InputSection *S = dyn_cast<InputSection>(R.Sec)) | if (InputSection *S = dyn_cast<InputSection>(R.Sec)) | ||||
Q.push_back(S); | Q.push_back(S); | ||||
}; | }; | ||||
auto MarkSymbol = [&](const SymbolBody *Sym) { | auto MarkSymbol = [&](const SymbolBody *Sym) { | ||||
if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym)) | if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym)) | ||||
if (auto *IS = cast_or_null<InputSectionBase>(D->Section)) | if (auto *IS = dyn_cast_or_null<InputSectionBase>(D->Section)) | ||||
Enqueue({IS, D->Value}); | Enqueue({IS, D->Value}); | ||||
}; | }; | ||||
// Add GC root symbols. | // Add GC root symbols. | ||||
MarkSymbol(Symtab<ELFT>::X->find(Config->Entry)); | MarkSymbol(Symtab<ELFT>::X->find(Config->Entry)); | ||||
MarkSymbol(Symtab<ELFT>::X->find(Config->Init)); | MarkSymbol(Symtab<ELFT>::X->find(Config->Init)); | ||||
MarkSymbol(Symtab<ELFT>::X->find(Config->Fini)); | MarkSymbol(Symtab<ELFT>::X->find(Config->Fini)); | ||||
for (StringRef S : Config->Undefined) | for (StringRef S : Config->Undefined) | ||||
Show All 37 Lines |