From: Rui Ueyama Date: Sun, 26 Mar 2017 03:20:49 +0000 (+0000) Subject: De-template a few functions in which ELFT is not needed. X-Git-Tag: llvmorg-5.0.0-rc1~9158 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94e36c894e1e7961504ec7a49a9b52c85ce0213f;p=platform%2Fupstream%2Fllvm.git De-template a few functions in which ELFT is not needed. llvm-svn: 298793 --- diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index bc315a5..91e45c4 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -91,10 +91,10 @@ static bool isPreemptible(const SymbolBody &Body, uint32_t Type) { // handling in to the separate function we can simplify the code and do not // pollute `handleTlsRelocation` by ARM and MIPS `ifs` statements. template -static unsigned -handleNoRelaxTlsRelocation(GOT *Got, uint32_t Type, SymbolBody &Body, - InputSectionBase &C, typename ELFT::uint Offset, - int64_t Addend, RelExpr Expr) { +static unsigned handleNoRelaxTlsRelocation(GOT *Got, uint32_t Type, + SymbolBody &Body, + InputSectionBase &C, uint64_t Offset, + int64_t Addend, RelExpr Expr) { auto addModuleReloc = [&](uint64_t Off, bool LD) { // The Dynamic TLS Module Index Relocation can be statically resolved to 1 // if we know that we are linking an executable. For ARM we resolve the @@ -138,8 +138,6 @@ template static unsigned handleTlsRelocation(uint32_t Type, SymbolBody &Body, InputSectionBase &C, typename ELFT::uint Offset, int64_t Addend, RelExpr Expr) { - typedef typename ELFT::uint uintX_t; - if (!(C.Flags & SHF_ALLOC)) return 0; @@ -157,7 +155,7 @@ handleTlsRelocation(uint32_t Type, SymbolBody &Body, InputSectionBase &C, if (isRelExprOneOf(Expr) && Config->Shared) { if (In::Got->addDynTlsEntry(Body)) { - uintX_t Off = In::Got->getGlobalDynOffset(Body); + uint64_t Off = In::Got->getGlobalDynOffset(Body); In::RelaDyn->addReloc({Target->TlsDescRel, In::Got, Off, !IsPreemptible, &Body, 0}); } @@ -192,13 +190,13 @@ handleTlsRelocation(uint32_t Type, SymbolBody &Body, InputSectionBase &C, Target->isTlsGlobalDynamicRel(Type)) { if (Config->Shared) { if (In::Got->addDynTlsEntry(Body)) { - uintX_t Off = In::Got->getGlobalDynOffset(Body); + uint64_t Off = In::Got->getGlobalDynOffset(Body); In::RelaDyn->addReloc( {Target->TlsModuleIndexRel, In::Got, Off, false, &Body, 0}); // If the symbol is preemptible we need the dynamic linker to write // the offset too. - uintX_t OffsetOff = Off + (uintX_t)sizeof(uintX_t); + uint64_t OffsetOff = Off + Config->Wordsize; if (IsPreemptible) In::RelaDyn->addReloc({Target->TlsOffsetRel, In::Got, OffsetOff, false, &Body, 0}); @@ -239,8 +237,8 @@ handleTlsRelocation(uint32_t Type, SymbolBody &Body, InputSectionBase &C, return 0; } -template static int16_t readSignedLo16(const uint8_t *Loc) { - return read32(Loc) & 0xffff; +static int16_t readSignedLo16(const uint8_t *Loc) { + return read32(Loc, Config->Endianness) & 0xffff; } template @@ -259,7 +257,7 @@ static uint32_t getMipsPairType(const RelTy *Rel, const SymbolBody &Sym) { } } -template +template static int32_t findMipsPairedAddend(const uint8_t *Buf, const uint8_t *BufLoc, SymbolBody &Sym, const RelTy *Rel, const RelTy *End) { @@ -278,10 +276,10 @@ static int32_t findMipsPairedAddend(const uint8_t *Buf, const uint8_t *BufLoc, continue; if (RI->getSymbol(Config->IsMips64EL) != SymIndex) continue; - const endianness E = ELFT::TargetEndianness; - return ((read32(BufLoc) & 0xffff) << 16) + - readSignedLo16(Buf + RI->r_offset); + return ((read32(BufLoc, Config->Endianness) & 0xffff) << 16) + + readSignedLo16(Buf + RI->r_offset); } + warn("can't find matching " + toString(Type) + " relocation for " + toString(Rel->getType(Config->IsMips64EL))); return 0; @@ -289,7 +287,7 @@ static int32_t findMipsPairedAddend(const uint8_t *Buf, const uint8_t *BufLoc, // True if non-preemptable symbol always has the same value regardless of where // the DSO is loaded. -template static bool isAbsolute(const SymbolBody &Body) { +static bool isAbsolute(const SymbolBody &Body) { if (Body.isUndefined()) return !Body.isLocal() && Body.symbol()->isWeak(); if (const auto *DR = dyn_cast(&Body)) @@ -297,8 +295,8 @@ template static bool isAbsolute(const SymbolBody &Body) { return false; } -template static bool isAbsoluteValue(const SymbolBody &Body) { - return isAbsolute(Body) || Body.isTls(); +static bool isAbsoluteValue(const SymbolBody &Body) { + return isAbsolute(Body) || Body.isTls(); } static bool needsPlt(RelExpr Expr) { @@ -322,9 +320,9 @@ static bool isRelExpr(RelExpr Expr) { // If this function returns false, that means we need to emit a // dynamic relocation so that the relocation will be fixed at load-time. template -static bool -isStaticLinkTimeConstant(RelExpr E, uint32_t Type, const SymbolBody &Body, - InputSectionBase &S, typename ELFT::uint RelOff) { +static bool isStaticLinkTimeConstant(RelExpr E, uint32_t Type, + const SymbolBody &Body, + InputSectionBase &S, uint64_t RelOff) { // These expressions always compute a constant if (isRelExprOneOf(Body); + bool AbsVal = isAbsoluteValue(Body); bool RelE = isRelExpr(E); if (AbsVal && !RelE) return true; @@ -514,7 +512,7 @@ static RelExpr adjustExpr(SymbolBody &Body, RelExpr Expr, uint32_t Type, } else if (!Preemptible) { if (needsPlt(Expr)) Expr = fromPlt(Expr); - if (Expr == R_GOT_PC && !isAbsoluteValue(Body)) + if (Expr == R_GOT_PC && !isAbsoluteValue(Body)) Expr = Target->adjustRelaxExpr(Type, Data, Expr); } @@ -588,13 +586,16 @@ static int64_t computeAddend(const elf::ObjectFile &File, uint32_t Type = Rel.getType(Config->IsMips64EL); int64_t Addend = getAddend(Rel); const uint8_t *BufLoc = SectionData + Rel.r_offset; + if (!RelTy::IsRela) Addend += Target->getImplicitAddend(BufLoc, Type); + if (Config->EMachine == EM_MIPS) { - Addend += findMipsPairedAddend(SectionData, BufLoc, Body, &Rel, End); + Addend += findMipsPairedAddend(SectionData, BufLoc, Body, &Rel, End); if (Expr == R_MIPS_GOTREL && Body.isLocal()) Addend += File.MipsGp0; } + if (Config->Pic && Config->EMachine == EM_PPC64 && Type == R_PPC64_TOC) Addend += getPPC64TocBase(); return Addend; @@ -602,7 +603,7 @@ static int64_t computeAddend(const elf::ObjectFile &File, template static void reportUndefined(SymbolBody &Sym, InputSectionBase &S, - typename ELFT::uint Offset) { + uint64_t Offset) { if (Config->UnresolvedSymbols == UnresolvedPolicy::IgnoreAll) return; @@ -707,8 +708,6 @@ private: // space for the extra PT_LOAD even if we end up not using it. template static void scanRelocs(InputSectionBase &Sec, ArrayRef Rels) { - typedef typename ELFT::uint uintX_t; - OffsetGetter GetOffset(Sec); for (auto I = Rels.begin(), E = Rels.end(); I != E; ++I) { @@ -724,8 +723,8 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef Rels) { } // Compute the offset of this section in the output section. - uintX_t Offset = GetOffset.get(Rel.r_offset); - if (Offset == uintX_t(-1)) + uint64_t Offset = GetOffset.get(Rel.r_offset); + if (Offset == uint64_t(-1)) continue; // Report undefined symbols. The fact that we report undefined @@ -858,19 +857,19 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef Rels) { continue; In::Got->addEntry(Body); - uintX_t Off = Body.getGotOffset(); + uint64_t Off = Body.getGotOffset(); uint32_t DynType; RelExpr GotRE = R_ABS; if (Body.isTls()) { DynType = Target->TlsGotRel; GotRE = R_TLS; - } else if (!Preemptible && Config->Pic && !isAbsolute(Body)) + } else if (!Preemptible && Config->Pic && !isAbsolute(Body)) DynType = Target->RelativeRel; else DynType = Target->GotRel; // FIXME: this logic is almost duplicated above. - bool Constant = !Preemptible && !(Config->Pic && !isAbsolute(Body)); + bool Constant = !Preemptible && !(Config->Pic && !isAbsolute(Body)); if (!Constant) In::RelaDyn->addReloc( {DynType, In::Got, Off, !Preemptible, &Body, 0});