<div dir="ltr">FWIW, Clang uses DTPOFF64 rather than DTPOFF32 here - so whatever solution you come up with/settle on should probably address that too.<br><br><div class="gmail_quote"><div dir="ltr">On Tue, May 30, 2017 at 5:27 AM George Rimar via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">grimar created this revision.<br>
Herald added a subscriber: aprantl.<br>
<br>
This is PR33173. More simple way to reproduce is below:<br>
<br>
If we have tls.c file with line<br>
<br>
__thread int a;<br>
<br>
gcc -c tls.c -g<br>
<br>
gives us R_X86_64_DTPOFF32 relocation in output:<br>
<br>
Relocation section '.rela.debug_info' at offset 0x2e0 contains 6 entries:<br>
Offset Info Type Sym. Value Sym. Name + Addend<br>
000000000006 00070000000a R_X86_64_32 0000000000000000 .debug_abbrev + 0<br>
00000000000c 000a0000000a R_X86_64_32 0000000000000000 .debug_str + 26<br>
000000000011 000a0000000a R_X86_64_32 0000000000000000 .debug_str + 54<br>
000000000015 000a0000000a R_X86_64_32 0000000000000000 .debug_str + 0<br>
000000000019 00090000000a R_X86_64_32 0000000000000000 .debug_line + 0<br>
000000000028 000d00000015 R_X86_64_DTPOFF32 0000000000000000 a + 0<br>
<br>
And run of llvm-dwarfdump tls.o would report "error: failed to compute relocation: R_X86_64_DTPOFF32"<br>
error then, because such a relocation is not supported atm.<br>
<br>
R_X86_64_DTPOFF32 calculates negative offset in the TLS block. Problem that size of TLS segment is not known<br>
here. The same applies for PR33173 where we use RelocVisitor as part of DWARFContextInMemory for building .gdb_index.<br>
TLS relocations pointing to .debug_info seems useless for index building purposes and we do not care about final value too.<br>
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<br>
if somebody needs to evaluate those TLS relocations.<br>
<br>
That is what this patch do.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D33673" rel="noreferrer" target="_blank">https://reviews.llvm.org/D33673</a><br>
<br>
Files:<br>
include/llvm/DebugInfo/DIContext.h<br>
include/llvm/Object/RelocVisitor.h<br>
lib/DebugInfo/DWARF/DWARFContext.cpp<br>
<br>
<br>
Index: lib/DebugInfo/DWARF/DWARFContext.cpp<br>
===================================================================<br>
--- lib/DebugInfo/DWARF/DWARFContext.cpp<br>
+++ lib/DebugInfo/DWARF/DWARFContext.cpp<br>
@@ -1173,7 +1173,7 @@<br>
continue;<br>
}<br>
<br>
- object::RelocVisitor V(Obj);<br>
+ object::RelocVisitor V(Obj, L ? L->getTlsSize() : 0);<br>
uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address);<br>
if (V.error()) {<br>
SmallString<32> Name;<br>
Index: include/llvm/Object/RelocVisitor.h<br>
===================================================================<br>
--- include/llvm/Object/RelocVisitor.h<br>
+++ include/llvm/Object/RelocVisitor.h<br>
@@ -35,7 +35,8 @@<br>
/// @brief Base class for object file relocation visitors.<br>
class RelocVisitor {<br>
public:<br>
- explicit RelocVisitor(const ObjectFile &Obj) : ObjToVisit(Obj) {}<br>
+ explicit RelocVisitor(const ObjectFile &Obj, uint64_t TlsSize)<br>
+ : ObjToVisit(Obj), TlsSize(TlsSize) {}<br>
<br>
// TODO: Should handle multiple applied relocations via either passing in the<br>
// previously computed value or just count paired relocations as a single<br>
@@ -56,6 +57,7 @@<br>
<br>
private:<br>
const ObjectFile &ObjToVisit;<br>
+ uint64_t TlsSize;<br>
bool HasError = false;<br>
<br>
uint64_t visitELF(uint32_t Rel, RelocationRef R, uint64_t Value) {<br>
@@ -132,6 +134,8 @@<br>
case ELF::R_X86_64_32:<br>
case ELF::R_X86_64_32S:<br>
return (Value + getELFAddend(R)) & 0xFFFFFFFF;<br>
+ case ELF::R_X86_64_DTPOFF32:<br>
+ return Value + getELFAddend(R) - TlsSize;<br>
}<br>
HasError = true;<br>
return 0;<br>
Index: include/llvm/DebugInfo/DIContext.h<br>
===================================================================<br>
--- include/llvm/DebugInfo/DIContext.h<br>
+++ include/llvm/DebugInfo/DIContext.h<br>
@@ -211,6 +211,10 @@<br>
return false;<br>
}<br>
<br>
+ /// Method returns size of TLS segment which is required for resolving TLS<br>
+ /// relocations sometimes.<br>
+ virtual uint64_t getTlsSize() const { return 0; }<br>
+<br>
/// Obtain a copy of this LoadedObjectInfo.<br>
///<br>
/// The caller is responsible for deallocation once the copy is no longer required.<br>
<br>
<br>
</blockquote></div></div>