Index: include/llvm/DebugInfo/DIContext.h =================================================================== --- include/llvm/DebugInfo/DIContext.h +++ include/llvm/DebugInfo/DIContext.h @@ -211,6 +211,10 @@ return false; } + /// Method returns size of TLS segment which is required for resolving TLS + /// relocations sometimes. + virtual uint64_t getTlsSize() const { return 0; } + /// Obtain a copy of this LoadedObjectInfo. /// /// The caller is responsible for deallocation once the copy is no longer required. Index: include/llvm/Object/RelocVisitor.h =================================================================== --- include/llvm/Object/RelocVisitor.h +++ include/llvm/Object/RelocVisitor.h @@ -35,7 +35,8 @@ /// @brief Base class for object file relocation visitors. class RelocVisitor { public: - explicit RelocVisitor(const ObjectFile &Obj) : ObjToVisit(Obj) {} + explicit RelocVisitor(const ObjectFile &Obj, uint64_t TlsSize) + : ObjToVisit(Obj), TlsSize(TlsSize) {} // TODO: Should handle multiple applied relocations via either passing in the // previously computed value or just count paired relocations as a single @@ -56,6 +57,7 @@ private: const ObjectFile &ObjToVisit; + uint64_t TlsSize; bool HasError = false; uint64_t visitELF(uint32_t Rel, RelocationRef R, uint64_t Value) { @@ -132,6 +134,8 @@ case ELF::R_X86_64_32: case ELF::R_X86_64_32S: return (Value + getELFAddend(R)) & 0xFFFFFFFF; + case ELF::R_X86_64_DTPOFF32: + return Value + getELFAddend(R) - TlsSize; } HasError = true; return 0; Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1173,7 +1173,7 @@ continue; } - object::RelocVisitor V(Obj); + object::RelocVisitor V(Obj, L ? L->getTlsSize() : 0); uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address); if (V.error()) { SmallString<32> Name;