mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-07 08:34:59 +00:00
Do not pass the SymbolTable to writeResult.
The SymbolTable is always accessible as Symtab<ELFT>::X, so no need to pass it as an argument. llvm-svn: 278091
This commit is contained in:
parent
9bd6241106
commit
84907c5143
@ -588,5 +588,5 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
|
||||
MS->splitIntoPieces();
|
||||
}
|
||||
|
||||
writeResult<ELFT>(&Symtab);
|
||||
writeResult<ELFT>();
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ public:
|
||||
typedef typename ELFT::Sym Elf_Sym;
|
||||
typedef typename ELFT::SymRange Elf_Sym_Range;
|
||||
typedef typename ELFT::Rela Elf_Rela;
|
||||
Writer(SymbolTable<ELFT> &S) : Symtab(S) {}
|
||||
void run();
|
||||
|
||||
private:
|
||||
@ -79,7 +78,6 @@ private:
|
||||
void addStartStopSymbols(OutputSectionBase<ELFT> *Sec);
|
||||
OutputSectionBase<ELFT> *findSection(StringRef Name);
|
||||
|
||||
SymbolTable<ELFT> &Symtab;
|
||||
std::vector<Phdr> Phdrs;
|
||||
|
||||
uintX_t FileSize;
|
||||
@ -110,7 +108,7 @@ template <class ELFT> static bool needsInterpSection() {
|
||||
!Config->DynamicLinker.empty();
|
||||
}
|
||||
|
||||
template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
||||
template <class ELFT> void elf::writeResult() {
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
typedef typename ELFT::Ehdr Elf_Ehdr;
|
||||
|
||||
@ -213,7 +211,7 @@ template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
||||
Out<ELFT>::ElfHeader = &ElfHeader;
|
||||
Out<ELFT>::ProgramHeaders = &ProgramHeaders;
|
||||
|
||||
Writer<ELFT>(*Symtab).run();
|
||||
Writer<ELFT>().run();
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
@ -273,8 +271,7 @@ template <class ELFT> void Writer<ELFT>::run() {
|
||||
error(EC, "failed to write to the output file");
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
static void reportUndefined(SymbolTable<ELFT> &Symtab, SymbolBody *Sym) {
|
||||
template <class ELFT> static void reportUndefined(SymbolBody *Sym) {
|
||||
if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore)
|
||||
return;
|
||||
|
||||
@ -346,7 +343,7 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
|
||||
if (!Out<ELFT>::SymTab)
|
||||
return;
|
||||
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
|
||||
Symtab.getObjectFiles()) {
|
||||
Symtab<ELFT>::X->getObjectFiles()) {
|
||||
const char *StrTab = F->getStringTable().data();
|
||||
for (SymbolBody *B : F->getLocalSymbols()) {
|
||||
auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
|
||||
@ -504,15 +501,15 @@ void PhdrEntry<ELFT>::add(OutputSectionBase<ELFT> *Sec) {
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
static Symbol *addOptionalSynthetic(SymbolTable<ELFT> &Table, StringRef Name,
|
||||
static Symbol *addOptionalSynthetic(StringRef Name,
|
||||
OutputSectionBase<ELFT> *Sec,
|
||||
typename ELFT::uint Val) {
|
||||
SymbolBody *S = Table.find(Name);
|
||||
SymbolBody *S = Symtab<ELFT>::X->find(Name);
|
||||
if (!S)
|
||||
return nullptr;
|
||||
if (!S->isUndefined() && !S->isShared())
|
||||
return S->symbol();
|
||||
return Table.addSynthetic(Name, Sec, Val);
|
||||
return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
|
||||
}
|
||||
|
||||
// The beginning and the ending of .rel[a].plt section are marked
|
||||
@ -525,10 +522,10 @@ template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
|
||||
if (isOutputDynamic<ELFT>() || !Out<ELFT>::RelaPlt)
|
||||
return;
|
||||
StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
|
||||
addOptionalSynthetic(Symtab, S, Out<ELFT>::RelaPlt, 0);
|
||||
addOptionalSynthetic(S, Out<ELFT>::RelaPlt, 0);
|
||||
|
||||
S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end";
|
||||
addOptionalSynthetic(Symtab, S, Out<ELFT>::RelaPlt,
|
||||
addOptionalSynthetic(S, Out<ELFT>::RelaPlt,
|
||||
DefinedSynthetic<ELFT>::SectionEnd);
|
||||
}
|
||||
|
||||
@ -540,12 +537,12 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||
// so that it points to an absolute address which is relative to GOT.
|
||||
// See "Global Data Symbols" in Chapter 6 in the following document:
|
||||
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
|
||||
Symtab.addSynthetic("_gp", Out<ELFT>::Got, MipsGPOffset);
|
||||
Symtab<ELFT>::X->addSynthetic("_gp", Out<ELFT>::Got, MipsGPOffset);
|
||||
|
||||
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
|
||||
// start of function and 'gp' pointer into GOT.
|
||||
Symbol *Sym =
|
||||
addOptionalSynthetic(Symtab, "_gp_disp", Out<ELFT>::Got, MipsGPOffset);
|
||||
addOptionalSynthetic("_gp_disp", Out<ELFT>::Got, MipsGPOffset);
|
||||
if (Sym)
|
||||
ElfSym<ELFT>::MipsGpDisp = Sym->body();
|
||||
|
||||
@ -553,8 +550,7 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||
// pointer. This symbol is used in the code generated by .cpload pseudo-op
|
||||
// in case of using -mno-shared option.
|
||||
// https://sourceware.org/ml/binutils/2004-12/msg00094.html
|
||||
addOptionalSynthetic(Symtab, "__gnu_local_gp", Out<ELFT>::Got,
|
||||
MipsGPOffset);
|
||||
addOptionalSynthetic("__gnu_local_gp", Out<ELFT>::Got, MipsGPOffset);
|
||||
}
|
||||
|
||||
// In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
|
||||
@ -570,14 +566,14 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||
// Given that the symbol is effectively unused, we just create a dummy
|
||||
// hidden one to avoid the undefined symbol error.
|
||||
if (!Config->Relocatable)
|
||||
Symtab.addIgnored("_GLOBAL_OFFSET_TABLE_");
|
||||
Symtab<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
|
||||
|
||||
// __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
|
||||
// static linking the linker is required to optimize away any references to
|
||||
// __tls_get_addr, so it's not defined anywhere. Create a hidden definition
|
||||
// to avoid the undefined symbol error.
|
||||
if (!isOutputDynamic<ELFT>())
|
||||
Symtab.addIgnored("__tls_get_addr");
|
||||
Symtab<ELFT>::X->addIgnored("__tls_get_addr");
|
||||
|
||||
// If linker script do layout we do not need to create any standart symbols.
|
||||
if (ScriptConfig->HasContents)
|
||||
@ -585,15 +581,15 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||
|
||||
auto Define = [this](StringRef S, DefinedRegular<ELFT> *&Sym1,
|
||||
DefinedRegular<ELFT> *&Sym2) {
|
||||
Sym1 = Symtab.addIgnored(S, STV_DEFAULT);
|
||||
Sym1 = Symtab<ELFT>::X->addIgnored(S, STV_DEFAULT);
|
||||
|
||||
// The name without the underscore is not a reserved name,
|
||||
// so it is defined only when there is a reference against it.
|
||||
assert(S.startswith("_"));
|
||||
S = S.substr(1);
|
||||
if (SymbolBody *B = Symtab.find(S))
|
||||
if (SymbolBody *B = Symtab<ELFT>::X->find(S))
|
||||
if (B->isUndefined())
|
||||
Sym2 = Symtab.addAbsolute(S, STV_DEFAULT);
|
||||
Sym2 = Symtab<ELFT>::X->addAbsolute(S, STV_DEFAULT);
|
||||
};
|
||||
|
||||
Define("_end", ElfSym<ELFT>::End, ElfSym<ELFT>::End2);
|
||||
@ -619,7 +615,7 @@ void Writer<ELFT>::forEachRelSec(
|
||||
std::function<void(InputSectionBase<ELFT> &, const typename ELFT::Shdr &)>
|
||||
Fn) {
|
||||
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
|
||||
Symtab.getObjectFiles()) {
|
||||
Symtab<ELFT>::X->getObjectFiles()) {
|
||||
for (InputSectionBase<ELFT> *C : F->getSections()) {
|
||||
if (isDiscarded(C))
|
||||
continue;
|
||||
@ -644,7 +640,7 @@ void Writer<ELFT>::forEachRelSec(
|
||||
|
||||
template <class ELFT> void Writer<ELFT>::createSections() {
|
||||
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
|
||||
Symtab.getObjectFiles()) {
|
||||
Symtab<ELFT>::X->getObjectFiles()) {
|
||||
for (InputSectionBase<ELFT> *C : F->getSections()) {
|
||||
if (isDiscarded(C)) {
|
||||
reportDiscarded(C);
|
||||
@ -686,7 +682,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
||||
// Even the author of gold doesn't remember why gold behaves that way.
|
||||
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
|
||||
if (isOutputDynamic<ELFT>())
|
||||
Symtab.addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0);
|
||||
Symtab<ELFT>::X->addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0);
|
||||
|
||||
// Define __rel[a]_iplt_{start,end} symbols if needed.
|
||||
addRelIpltSymbols();
|
||||
@ -712,13 +708,13 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
||||
|
||||
// Now that we have defined all possible symbols including linker-
|
||||
// synthesized ones. Visit all symbols to give the finishing touches.
|
||||
for (Symbol *S : Symtab.getSymbols()) {
|
||||
for (Symbol *S : Symtab<ELFT>::X->getSymbols()) {
|
||||
SymbolBody *Body = S->body();
|
||||
|
||||
// We only report undefined symbols in regular objects. This means that we
|
||||
// will accept an undefined reference in bitcode if it can be optimized out.
|
||||
if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak())
|
||||
reportUndefined<ELFT>(Symtab, Body);
|
||||
reportUndefined<ELFT>(Body);
|
||||
|
||||
if (!includeInSymtab<ELFT>(*Body))
|
||||
continue;
|
||||
@ -861,13 +857,12 @@ template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
|
||||
auto Define = [&](StringRef Start, StringRef End,
|
||||
OutputSectionBase<ELFT> *OS) {
|
||||
if (OS) {
|
||||
this->Symtab.addSynthetic(Start, OS, 0);
|
||||
this->Symtab.addSynthetic(End, OS, DefinedSynthetic<ELFT>::SectionEnd);
|
||||
Symtab<ELFT>::X->addSynthetic(Start, OS, 0);
|
||||
Symtab<ELFT>::X->addSynthetic(End, OS,
|
||||
DefinedSynthetic<ELFT>::SectionEnd);
|
||||
} else {
|
||||
addOptionalSynthetic(this->Symtab, Start,
|
||||
(OutputSectionBase<ELFT> *)nullptr, 0);
|
||||
addOptionalSynthetic(this->Symtab, End,
|
||||
(OutputSectionBase<ELFT> *)nullptr, 0);
|
||||
addOptionalSynthetic(Start, (OutputSectionBase<ELFT> *)nullptr, 0);
|
||||
addOptionalSynthetic(End, (OutputSectionBase<ELFT> *)nullptr, 0);
|
||||
}
|
||||
};
|
||||
|
||||
@ -892,12 +887,13 @@ void Writer<ELFT>::addStartStopSymbols(OutputSectionBase<ELFT> *Sec) {
|
||||
StringSaver Saver(Alloc);
|
||||
StringRef Start = Saver.save("__start_" + S);
|
||||
StringRef Stop = Saver.save("__stop_" + S);
|
||||
if (SymbolBody *B = Symtab.find(Start))
|
||||
if (SymbolBody *B = Symtab<ELFT>::X->find(Start))
|
||||
if (B->isUndefined())
|
||||
Symtab.addSynthetic(Start, Sec, 0);
|
||||
if (SymbolBody *B = Symtab.find(Stop))
|
||||
Symtab<ELFT>::X->addSynthetic(Start, Sec, 0);
|
||||
if (SymbolBody *B = Symtab<ELFT>::X->find(Stop))
|
||||
if (B->isUndefined())
|
||||
Symtab.addSynthetic(Stop, Sec, DefinedSynthetic<ELFT>::SectionEnd);
|
||||
Symtab<ELFT>::X->addSynthetic(Stop, Sec,
|
||||
DefinedSynthetic<ELFT>::SectionEnd);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
@ -1280,10 +1276,10 @@ template <class ELFT> void Writer<ELFT>::writeBuildId() {
|
||||
Out<ELFT>::BuildId->writeBuildId(Regions);
|
||||
}
|
||||
|
||||
template void elf::writeResult<ELF32LE>(SymbolTable<ELF32LE> *Symtab);
|
||||
template void elf::writeResult<ELF32BE>(SymbolTable<ELF32BE> *Symtab);
|
||||
template void elf::writeResult<ELF64LE>(SymbolTable<ELF64LE> *Symtab);
|
||||
template void elf::writeResult<ELF64BE>(SymbolTable<ELF64BE> *Symtab);
|
||||
template void elf::writeResult<ELF32LE>();
|
||||
template void elf::writeResult<ELF32BE>();
|
||||
template void elf::writeResult<ELF64LE>();
|
||||
template void elf::writeResult<ELF64BE>();
|
||||
|
||||
template struct elf::PhdrEntry<ELF32LE>;
|
||||
template struct elf::PhdrEntry<ELF32BE>;
|
||||
|
@ -23,7 +23,7 @@ template <class ELFT> class OutputSectionBase;
|
||||
template <class ELFT> class InputSectionBase;
|
||||
template <class ELFT> class ObjectFile;
|
||||
template <class ELFT> class SymbolTable;
|
||||
template <class ELFT> void writeResult(SymbolTable<ELFT> *Symtab);
|
||||
template <class ELFT> void writeResult();
|
||||
template <class ELFT> void markLive();
|
||||
template <class ELFT> bool isOutputDynamic();
|
||||
template <class ELFT> bool isRelroSection(OutputSectionBase<ELFT> *Sec);
|
||||
|
Loading…
Reference in New Issue
Block a user