- // Add location.
- bool addToAccelTable = false;
- DIE *VariableSpecDIE = NULL;
- bool isGlobalVariable = GV.getGlobal() != NULL;
- if (isGlobalVariable) {
- addToAccelTable = true;
- DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
- 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");
- const MCExpr *Expr =
- Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym);
- // Based on GCC's support for TLS:
- if (!DD->useSplitDwarf()) {
- // 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
- addExpr(Block, 0, dwarf::DW_FORM_udata, Expr);
- } else {
- addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
- addUInt(Block, 0, dwarf::DW_FORM_udata, DU->getAddrPoolIndex(Expr));
- }
- // 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() &&
- !GVContext.isFile() && !isSubprogramContext(GVContext)) {
- // Create specification DIE.
- VariableSpecDIE = new DIE(dwarf::DW_TAG_variable);
- addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification,
- dwarf::DW_FORM_ref4, VariableDIE);
- addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block);
- // A static member's declaration is already flagged as such.
- if (!SDMDecl.Verify())
- addFlag(VariableDIE, dwarf::DW_AT_declaration);
- addDie(VariableSpecDIE);
- } else {
- addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block);
- }
- // Add the linkage name.
- StringRef LinkageName = GV.getLinkageName();
- if (!LinkageName.empty())
- // From DWARF4: DIEs to which DW_AT_linkage_name may apply include:
- // TAG_common_block, TAG_constant, TAG_entry_point, TAG_subprogram and
- // TAG_variable.
- addString(IsStaticMember && VariableSpecDIE ?
- VariableSpecDIE : VariableDIE, dwarf::DW_AT_MIPS_linkage_name,
- GlobalValue::getRealLinkageName(LinkageName));
- } else if (const ConstantInt *CI =
- dyn_cast_or_null<ConstantInt>(GV.getConstant())) {
- // AT_const_value was added when the static member was created. To avoid
- // emitting AT_const_value multiple times, we only add AT_const_value when
- // it is not a static member.
- if (!IsStaticMember)
- addConstantValue(VariableDIE, CI, GTy.isUnsignedDIType());
- } else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) {
- addToAccelTable = true;
- // GV is a merged global.
- DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
- Value *Ptr = CE->getOperand(0);
- addOpAddress(Block, Asm->Mang->getSymbol(cast<GlobalValue>(Ptr)));
- addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
- SmallVector<Value*, 3> Idx(CE->op_begin()+1, CE->op_end());
- addUInt(Block, 0, dwarf::DW_FORM_udata,
- Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx));
- addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
- addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block);
- }