summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2013-06-28 20:05:11 +0000
committerDavid Blaikie <dblaikie@gmail.com>2013-06-28 20:05:11 +0000
commit59eaa3874663f80ce111a4781b8f1db82995210c (patch)
tree996e6895665112c7efb69fd8480b323e7cad5c29 /lib
parent95e72c90e4e2ee64e12d898f6495e796ebcadaf8 (diff)
downloadllvm-59eaa3874663f80ce111a4781b8f1db82995210c.tar.gz
llvm-59eaa3874663f80ce111a4781b8f1db82995210c.tar.bz2
llvm-59eaa3874663f80ce111a4781b8f1db82995210c.tar.xz
DebugInfo: PR14728: TLS support
Based on GCC's output for TLS variables (OP_constNu, x@dtpoff, OP_lo_user), this implements debug info support for TLS in ELF. Verified that this output is correct/sufficient on Linux (using gold - if you're using binutils-ld, you'll need something with the fix for http://sourceware.org/bugzilla/show_bug.cgi?id=15685 in it). Support on non-ELF is sort of "arbitrary" at the moment - if Apple folks want to discuss (or just go ahead & implement) how this should work in MachO, etc, I'm open. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185203 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp21
-rw-r--r--lib/CodeGen/TargetLoweringObjectFileImpl.cpp4
-rw-r--r--lib/Target/TargetLoweringObjectFile.cpp6
3 files changed, 28 insertions, 3 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 6bd4f08604..339a5d2752 100644
--- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -27,6 +27,7 @@
#include "llvm/Target/Mangler.h"
#include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetRegisterInfo.h"
using namespace llvm;
@@ -1351,7 +1352,23 @@ void CompileUnit::createGlobalVariableDIE(const MDNode *N) {
if (isGlobalVariable) {
addToAccelTable = true;
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
- addOpAddress(Block, Asm->Mang->getSymbol(GV.getGlobal()));
+ const MCSymbol *Sym = Asm->Mang->getSymbol(GV.getGlobal());
+ if (GV.getGlobal()->isThreadLocal()) {
+ // FIXME: Make this work with -gsplit-dwarf.
+ unsigned PointerSize = Asm->getDataLayout().getPointerSize();
+ assert((PointerSize == 4 || PointerSize == 8) &&
+ "Add support for other sizes if necessary");
+ // Based on GCC's support for TLS:
+ // 1) Start with a constNu of the appropriate pointer size
+ addUInt(Block, 0, dwarf::DW_FORM_data1,
+ PointerSize == 4 ? dwarf::DW_OP_const4u : dwarf::DW_OP_const8u);
+ // 2) containing the (relocated) address of the TLS variable
+ addLabel(Block, 0, dwarf::DW_FORM_udata,
+ Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
+ // 3) followed by a custom OP to tell the debugger about TLS (presumably)
+ addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_lo_user);
+ } else
+ addOpAddress(Block, Sym);
// Do not create specification DIE if context is either compile unit
// or a subprogram.
if (GVContext && GV.isDefinition() && !GVContext.isCompileUnit() &&
@@ -1413,8 +1430,6 @@ void CompileUnit::createGlobalVariableDIE(const MDNode *N) {
if (GV.getLinkageName() != "" && GV.getName() != GV.getLinkageName())
addAccelName(GV.getLinkageName(), AddrDIE);
}
-
- return;
}
/// constructSubrangeDIE - Construct subrange DIE from DISubrange.
diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 7e7359a8fe..69d55913ca 100644
--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -401,6 +401,10 @@ TargetLoweringObjectFileELF::InitializeELF(bool UseInitArray_) {
SectionKind::getDataRel());
}
+const MCSymbolRefExpr *TargetLoweringObjectFileELF::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
+ return MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
+}
+
//===----------------------------------------------------------------------===//
// MachO
//===----------------------------------------------------------------------===//
diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp
index f5121e34f7..fc50aa5192 100644
--- a/lib/Target/TargetLoweringObjectFile.cpp
+++ b/lib/Target/TargetLoweringObjectFile.cpp
@@ -317,3 +317,9 @@ getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
}
}
}
+
+const MCSymbolRefExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
+ // FIXME: It's not clear what, if any, default this should have - perhaps a
+ // null return could mean 'no location' & we should just do that here.
+ return MCSymbolRefExpr::Create(Sym, *Ctx);
+}