[PATCH] D33673: [Object/RelocVisitor] - Add support for R_X86_64_DTPOFF32 relocation.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed May 31 08:32:30 PDT 2017


FWIW, Clang uses DTPOFF64 rather than DTPOFF32 here - so whatever solution
you come up with/settle on should probably address that too.

On Tue, May 30, 2017 at 5:27 AM George Rimar via Phabricator <
reviews at reviews.llvm.org> wrote:

> grimar created this revision.
> Herald added a subscriber: aprantl.
>
> This is PR33173. More simple way to reproduce is below:
>
> If we have tls.c file with line
>
>   __thread int a;
>
> gcc -c tls.c -g
>
> gives us R_X86_64_DTPOFF32 relocation in output:
>
>   Relocation section '.rela.debug_info' at offset 0x2e0 contains 6 entries:
>     Offset          Info           Type           Sym. Value    Sym. Name
> + Addend
>   000000000006  00070000000a R_X86_64_32       0000000000000000
> .debug_abbrev + 0
>   00000000000c  000a0000000a R_X86_64_32       0000000000000000 .debug_str
> + 26
>   000000000011  000a0000000a R_X86_64_32       0000000000000000 .debug_str
> + 54
>   000000000015  000a0000000a R_X86_64_32       0000000000000000 .debug_str
> + 0
>   000000000019  00090000000a R_X86_64_32       0000000000000000
> .debug_line + 0
>   000000000028  000d00000015 R_X86_64_DTPOFF32 0000000000000000 a + 0
>
> And run of llvm-dwarfdump tls.o would report "error: failed to compute
> relocation: R_X86_64_DTPOFF32"
> error then, because such a relocation is not supported atm.
>
> R_X86_64_DTPOFF32 calculates negative offset in the TLS block. Problem
> that size of TLS segment is not known
> here. The same applies for PR33173 where we use RelocVisitor as part of
> DWARFContextInMemory for building .gdb_index.
> TLS relocations pointing to .debug_info seems useless for index building
> purposes and we do not care about final value too.
> So far it seems reasonable to have some value by default for TLS size,
> like 0 in this patch and some API that can be used in theory
> if somebody needs to evaluate those TLS relocations.
>
> That is what this patch do.
>
>
> https://reviews.llvm.org/D33673
>
> Files:
>   include/llvm/DebugInfo/DIContext.h
>   include/llvm/Object/RelocVisitor.h
>   lib/DebugInfo/DWARF/DWARFContext.cpp
>
>
> 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;
> 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: 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.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170531/5ab6532f/attachment.html>


More information about the llvm-commits mailing list