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; @@ -283,7 +284,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; @@ -314,7 +315,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 { @@ -591,7 +592,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; @@ -654,6 +655,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; } @@ -787,7 +795,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 @@ -893,9 +901,6 @@ write32le(Loc, Val); break; } - case R_X86_64_TPOFF64: - write32le(Loc, SA - P); - break; default: fatal("unrecognized reloc " + Twine(Type)); } @@ -1144,7 +1149,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; @@ -1206,10 +1211,9 @@ } unsigned AArch64TargetInfo::getTlsGotRel(unsigned Type) const { - if (Type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 || - Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) + assert(Type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 || + Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC); return Type; - return TlsGotRel; } bool AArch64TargetInfo::isTlsDynRel(unsigned Type, const SymbolBody &S) const { Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -377,7 +377,7 @@ if (CBP || Dynrel) { uint32_t DynType; if (CBP) - DynType = Body->isTls() ? Target->getTlsGotRel() : Target->GotRel; + DynType = Body->isTls() ? Target->TlsGotDynRel : Target->GotRel; else DynType = Target->RelativeRel; Out::RelaDyn->addReloc(