From ccb8b4d4fe4385ec6750d38ca4d860ce4892a64f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 11 Mar 2016 12:14:02 +0000 Subject: [PATCH] Remember the input section of locals. This is already a simplification, but will allow much more. llvm-svn: 263224 --- lld/ELF/InputFiles.cpp | 2 +- lld/ELF/OutputSections.cpp | 20 ++++++++++++++------ lld/ELF/OutputSections.h | 9 --------- lld/ELF/Symbols.h | 7 +++++-- lld/ELF/Writer.cpp | 14 +------------- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 6060de6..30e2c70 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -292,7 +292,7 @@ template SymbolBody *elf::ObjectFile::createSymbolBody(const Elf_Sym *Sym) { unsigned char Binding = Sym->getBinding(); if (Binding == STB_LOCAL) - return new (Alloc) LocalSymbol(*Sym); + return new (Alloc) LocalSymbol(*Sym, getSection(*Sym)); StringRef Name = check(Sym->getName(this->StringTable)); diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 19e9103..05f1b9c 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -267,12 +267,20 @@ template void RelocationSection::writeTo(uint8_t *Buf) { if (IsRela) { uintX_t VA = 0; - if (Rel.UseSymVA) - VA = Sym->getVA(); - else if (Rel.TargetSec) - VA = Rel.TargetSec->getOffset(Rel.OffsetInTargetSec) + - Rel.TargetSec->OutSec->getVA(); - reinterpret_cast(P)->r_addend = Rel.Addend + VA; + uintX_t Addend = Rel.Addend; + if (Rel.UseSymVA) { + if (auto *L = dyn_cast>(Sym)) { + uintX_t Pos = L->Sym.st_value; + if (L->Sym.getType() == STT_SECTION) { + Pos += Addend; + Addend = 0; + } + VA = L->Section->OutSec->getVA() + L->Section->getOffset(Pos); + } else { + VA = Sym->getVA(); + } + } + reinterpret_cast(P)->r_addend = Addend + VA; } P->r_offset = Rel.getOffset(); diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index f9e4a53..b4db5b8 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -186,8 +186,6 @@ template struct DynamicReloc { InputSectionBase *OffsetSec = nullptr; uintX_t OffsetInSec = 0; bool UseSymVA = false; - InputSectionBase *TargetSec = nullptr; - uintX_t OffsetInTargetSec = 0; uintX_t Addend = 0; DynamicReloc(uint32_t Type, OffsetKind OKind, SymbolBody *Sym) @@ -202,13 +200,6 @@ template struct DynamicReloc { : Type(Type), OKind(Off_Sec), Sym(Sym), OffsetSec(OffsetSec), OffsetInSec(OffsetInSec), UseSymVA(UseSymVA), Addend(Addend) {} - DynamicReloc(uint32_t Type, InputSectionBase *OffsetSec, - uintX_t OffsetInSec, InputSectionBase *TargetSec, - uintX_t OffsetInTargetSec, uintX_t Addend) - : Type(Type), OKind(Off_Sec), OffsetSec(OffsetSec), - OffsetInSec(OffsetInSec), TargetSec(TargetSec), - OffsetInTargetSec(OffsetInTargetSec), Addend(Addend) {} - uintX_t getOffset() const; }; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index d76be4f..bb6b9fa 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -310,12 +310,15 @@ template class LocalSymbol : public DefinedElf { typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; public: - LocalSymbol(const Elf_Sym &Sym) - : DefinedElf(SymbolBody::DefinedLocalKind, "", Sym) {} + LocalSymbol(const Elf_Sym &Sym, InputSectionBase *Section) + : DefinedElf(SymbolBody::DefinedLocalKind, "", Sym), + Section(Section) {} static bool classof(const SymbolBody *S) { return S->kind() == SymbolBody::DefinedLocalKind; } + + InputSectionBase *Section; }; // This class represents a symbol defined in an archive file. It is diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index cb51fd5..7c5c336 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -474,20 +474,8 @@ void Writer::scanRelocs( (uintX_t)getPPC64TocBase() + Addend}); continue; } - if (!Body.isLocal()) { - Out::RelaDyn->addReloc( - {Target->RelativeRel, &C, RI.r_offset, true, &Body, Addend}); - continue; - } - const Elf_Sym &Sym = cast>(Body).Sym; - InputSectionBase *Section = File.getSection(Sym); - uintX_t Offset = Sym.st_value; - if (Sym.getType() == STT_SECTION) { - Offset += Addend; - Addend = 0; - } Out::RelaDyn->addReloc( - {Target->RelativeRel, &C, RI.r_offset, Section, Offset, Addend}); + {Target->RelativeRel, &C, RI.r_offset, true, &Body, Addend}); } } -- 2.7.4