From 6455852a2894553a62e04f0b0d6496c1d493ab7a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 16 Oct 2015 22:51:43 +0000 Subject: [PATCH] ELF2: Treat IsMips64EL as a global configuration. If one file is MIPS64EL, all files are MIPS64EL, and vice versa. We do not have to look up MIPS-ness for each file. Currently we do not support 64-bit MIPS, so the config value is always false. llvm-svn: 250566 --- lld/ELF/Config.h | 1 + lld/ELF/InputSection.cpp | 5 ++--- lld/ELF/OutputSections.cpp | 11 +++++------ lld/ELF/Writer.cpp | 5 ++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index b28877e3e22c..8028a6e3e443 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -50,6 +50,7 @@ struct Configuration { bool DiscardNone; bool EnableNewDtags; bool ExportDynamic; + bool Mips64EL = false; bool NoInhibitExec; bool NoUndefined; bool Shared; diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 8a0a5898e03d..7aa9e7ea560f 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -48,10 +48,9 @@ void InputSection::relocate( iterator_range *> Rels, const ObjectFile &File, uintX_t BaseAddr) { typedef Elf_Rel_Impl RelType; - bool IsMips64EL = File.getObj().isMips64EL(); for (const RelType &RI : Rels) { - uint32_t SymIndex = RI.getSymbol(IsMips64EL); - uint32_t Type = RI.getType(IsMips64EL); + uint32_t SymIndex = RI.getSymbol(Config->Mips64EL); + uint32_t Type = RI.getType(Config->Mips64EL); // Handle relocations for local symbols -- they never get // resolved so we don't allocate a SymbolBody. diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 0f7862a8163d..780f561fdac2 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -103,20 +103,19 @@ RelocationSection::RelocationSection(bool IsRela) template void RelocationSection::writeTo(uint8_t *Buf) { const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); - bool IsMips64EL = Relocs[0].C.getFile()->getObj().isMips64EL(); for (const DynamicReloc &Rel : Relocs) { auto *P = reinterpret_cast(Buf); Buf += EntrySize; const InputSection &C = Rel.C; const Elf_Rel &RI = Rel.RI; - uint32_t SymIndex = RI.getSymbol(IsMips64EL); + uint32_t SymIndex = RI.getSymbol(Config->Mips64EL); const ObjectFile &File = *C.getFile(); SymbolBody *Body = File.getSymbolBody(SymIndex); if (Body) Body = Body->repl(); - uint32_t Type = RI.getType(IsMips64EL); + uint32_t Type = RI.getType(Config->Mips64EL); bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body); bool CanBePreempted = canBePreempted(Body, NeedsGot); @@ -128,21 +127,21 @@ template void RelocationSection::writeTo(uint8_t *Buf) { else Addend += getLocalRelTarget(File, RI); } - P->setSymbolAndType(0, Target->getRelativeReloc(), IsMips64EL); + P->setSymbolAndType(0, Target->getRelativeReloc(), Config->Mips64EL); } if (NeedsGot) { P->r_offset = Out::Got->getEntryAddr(*Body); if (CanBePreempted) P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), - Target->getGotReloc(), IsMips64EL); + Target->getGotReloc(), Config->Mips64EL); } else { if (IsRela) Addend += static_cast(RI).r_addend; P->r_offset = RI.r_offset + C.OutSec->getVA() + C.OutSecOff; if (CanBePreempted) P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), Type, - IsMips64EL); + Config->Mips64EL); } if (IsRela) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 2a910c1e604d..164171b9d77d 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -172,11 +172,10 @@ void Writer::scanRelocs( iterator_range *> Rels) { typedef Elf_Rel_Impl RelType; const ObjectFile &File = *C.getFile(); - bool IsMips64EL = File.getObj().isMips64EL(); for (const RelType &RI : Rels) { - uint32_t SymIndex = RI.getSymbol(IsMips64EL); + uint32_t SymIndex = RI.getSymbol(Config->Mips64EL); SymbolBody *Body = File.getSymbolBody(SymIndex); - uint32_t Type = RI.getType(IsMips64EL); + uint32_t Type = RI.getType(Config->Mips64EL); // Set "used" bit for --as-needed. if (Body && Body->isUndefined() && !Body->isWeak())