Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -229,7 +229,7 @@ return false; if (Target->canRelaxTls(Type, Body)) { - P->setSymbolAndType(Body->DynsymIndex, Target->getTlsGotRel(), + P->setSymbolAndType(Body->DynsymIndex, Target->TlsGotDynRel, Config->Mips64EL); P->r_offset = Body->getGotVA(); return true; @@ -319,7 +319,7 @@ else if (LazyReloc) Reloc = Target->PltRel; else if (NeedsGot) - Reloc = Body->isTls() ? Target->getTlsGotRel() : Target->GotRel; + Reloc = Body->isTls() ? Target->TlsGotDynRel : Target->GotRel; else Reloc = Target->getDynRel(Type); P->setSymbolAndType(CBP ? Body->DynsymIndex : 0, Reloc, Config->Mips64EL); Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -26,7 +26,7 @@ bool isTlsGlobalDynamicRel(unsigned Type) const; virtual unsigned getDynRel(unsigned Type) const { return Type; } virtual bool isTlsDynRel(unsigned Type, const SymbolBody &S) const; - virtual unsigned getTlsGotRel(unsigned Type = -1) const { return TlsGotRel; } + virtual unsigned getTlsGotRel(unsigned Type) const { return TlsGotDynRel; } virtual void writeGotHeader(uint8_t *Buf) const {} virtual void writeGotPltHeader(uint8_t *Buf) const {} virtual void writeGotPlt(uint8_t *Buf, uint64_t Plt) const {}; @@ -81,7 +81,7 @@ unsigned PltRel; unsigned RelativeRel; unsigned IRelativeRel; - unsigned TlsGotRel = 0; + unsigned TlsGotDynRel = 0; unsigned TlsLocalDynamicRel = 0; unsigned TlsGlobalDynamicRel = 0; unsigned TlsModuleIndexRel; Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -114,6 +114,7 @@ class X86_64TargetInfo final : public TargetInfo { public: X86_64TargetInfo(); + unsigned getTlsGotRel(unsigned Type) const override; bool isTlsDynRel(unsigned Type, const SymbolBody &S) const override; void writeGotPltHeader(uint8_t *Buf) const override; void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override; @@ -173,7 +174,7 @@ void writePltZero(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; - unsigned getTlsGotRel(unsigned Type = -1) const override; + unsigned getTlsGotRel(unsigned Type) const override; bool isTlsDynRel(unsigned Type, const SymbolBody &S) const override; bool needsCopyRel(uint32_t Type, const SymbolBody &S) const override; bool needsGot(uint32_t Type, const SymbolBody &S) const override; @@ -282,7 +283,7 @@ PltRel = R_386_JUMP_SLOT; IRelativeRel = R_386_IRELATIVE; RelativeRel = R_386_RELATIVE; - TlsGotRel = R_386_TLS_TPOFF; + TlsGotDynRel = R_386_TLS_TPOFF; TlsGlobalDynamicRel = R_386_TLS_GD; TlsLocalDynamicRel = R_386_TLS_LDM; TlsModuleIndexRel = R_386_TLS_DTPMOD32; @@ -313,7 +314,7 @@ unsigned X86TargetInfo::getTlsGotRel(unsigned Type) const { if (Type == R_386_TLS_IE) return Type; - return TlsGotRel; + return TlsGotDynRel; } bool X86TargetInfo::isTlsDynRel(unsigned Type, const SymbolBody &S) const { @@ -590,7 +591,7 @@ PltRel = R_X86_64_JUMP_SLOT; RelativeRel = R_X86_64_RELATIVE; IRelativeRel = R_X86_64_IRELATIVE; - TlsGotRel = R_X86_64_TPOFF64; + TlsGotDynRel = R_X86_64_TPOFF64; TlsLocalDynamicRel = R_X86_64_TLSLD; TlsGlobalDynamicRel = R_X86_64_TLSGD; TlsModuleIndexRel = R_X86_64_DTPMOD64; @@ -653,6 +654,13 @@ return Type == R_X86_64_GOTPCREL || needsPlt(Type, S); } +unsigned X86_64TargetInfo::getTlsGotRel(unsigned Type) const { + // No other types of TLS relocations requiring GOT should + // reach here. + assert(Type == R_X86_64_GOTTPOFF); + return R_X86_64_PC32; +} + bool X86_64TargetInfo::isTlsDynRel(unsigned Type, const SymbolBody &S) const { return Type == R_X86_64_GOTTPOFF || Type == R_X86_64_TLSGD; } @@ -786,7 +794,7 @@ 0x48, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00 // addq x@tpoff,%rax }; memcpy(Loc - 4, Inst, sizeof(Inst)); - relocateOne(Loc + 8, BufEnd, R_X86_64_TPOFF64, P + 12, SA); + relocateOne(Loc + 8, BufEnd, R_X86_64_PC32, P + 12, SA); } // In some conditions, R_X86_64_GOTTPOFF relocation can be optimized to @@ -892,9 +900,6 @@ write32le(Loc, Val); break; } - case R_X86_64_TPOFF64: - write32le(Loc, SA - P); - break; default: fatal("unrecognized reloc " + Twine(Type)); } @@ -1143,7 +1148,7 @@ IRelativeRel = R_AARCH64_IRELATIVE; GotRel = R_AARCH64_GLOB_DAT; PltRel = R_AARCH64_JUMP_SLOT; - TlsGotRel = R_AARCH64_TLS_TPREL64; + TlsGotDynRel = R_AARCH64_TLS_TPREL64; UseLazyBinding = true; PltEntrySize = 16; PltZeroSize = 32; @@ -1208,7 +1213,7 @@ if (Type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 || Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) return Type; - return TlsGotRel; + return TlsGotDynRel; } bool AArch64TargetInfo::isTlsDynRel(unsigned Type, const SymbolBody &S) const {