<div dir="ltr">I think that's a bit different - I Think it might be reasonable to emit that as a definiton without a location, since we have no way to describe the location but there really is a definition there.<br><br>Whereas a dllimport isn't really a definition at all - there's a definition on the dllexport side, which we should be describing.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 13, 2016 at 4:51 PM Anton Korobeynikov via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It seems we have to deal with TLS symbols in pretty similar way.<br>
<br>
Sometimes there is no relocation which could describe the location.<br>
The recent example is AArch64, see<br>
<a href="https://llvm.org/bugs/show_bug.cgi?id=21077" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=21077</a> for more information.<br>
<br>
Good thing is that we're having TLOF::getDebugThreadLocalSymbol()<br>
hook, which can be made to return nullptr in default case and we would<br>
handle it here the same way as dllimport stuff.<br>
<br>
On Sat, Jul 9, 2016 at 11:47 PM, David Majnemer via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: majnemer<br>
> Date: Sat Jul  9 15:47:48 2016<br>
> New Revision: 274986<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=274986&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=274986&view=rev</a><br>
> Log:<br>
> [COFF, Dwarf] Don't emit DW_AT_location for dllimported entities<br>
><br>
> There exists no relocation which can describe the address of a<br>
> dllimported variable: do not try to describe their location.<br>
><br>
> Added:<br>
>     llvm/trunk/test/DebugInfo/X86/dllimport.ll<br>
> Modified:<br>
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=274986&r1=274985&r2=274986&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=274986&r1=274985&r2=274986&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Sat Jul  9 15:47:48 2016<br>
> @@ -148,62 +148,69 @@ DIE *DwarfCompileUnit::getOrCreateGlobal<br>
>    // Add location.<br>
>    bool addToAccelTable = false;<br>
>    if (auto *Global = dyn_cast_or_null<GlobalVariable>(GV->getVariable())) {<br>
> -    addToAccelTable = true;<br>
> -    DIELoc *Loc = new (DIEValueAllocator) DIELoc;<br>
> -    const MCSymbol *Sym = Asm->getSymbol(Global);<br>
> -    if (Global->isThreadLocal()) {<br>
> -      if (Asm->TM.Options.EmulatedTLS) {<br>
> -        // TODO: add debug info for emulated thread local mode.<br>
> -      } else {<br>
> -        // FIXME: Make this work with -gsplit-dwarf.<br>
> -        unsigned PointerSize = Asm->getDataLayout().getPointerSize();<br>
> -        assert((PointerSize == 4 || PointerSize == 8) &&<br>
> -               "Add support for other sizes if necessary");<br>
> -        // Based on GCC's support for TLS:<br>
> -        if (!DD->useSplitDwarf()) {<br>
> -          // 1) Start with a constNu of the appropriate pointer size<br>
> -          addUInt(*Loc, dwarf::DW_FORM_data1, PointerSize == 4<br>
> -                                                  ? dwarf::DW_OP_const4u<br>
> -                                                  : dwarf::DW_OP_const8u);<br>
> -          // 2) containing the (relocated) offset of the TLS variable<br>
> -          //    within the module's TLS block.<br>
> -          addExpr(*Loc, dwarf::DW_FORM_udata,<br>
> -                  Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));<br>
> +    // We cannot describe the location of dllimport'd variables: the computation<br>
> +    // of their address requires loads from the IAT.<br>
> +    if (!Global->hasDLLImportStorageClass()) {<br>
> +      addToAccelTable = true;<br>
> +      DIELoc *Loc = new (DIEValueAllocator) DIELoc;<br>
> +      const MCSymbol *Sym = Asm->getSymbol(Global);<br>
> +      if (Global->isThreadLocal()) {<br>
> +        if (Asm->TM.Options.EmulatedTLS) {<br>
> +          // TODO: add debug info for emulated thread local mode.<br>
>          } else {<br>
> -          addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);<br>
> -          addUInt(*Loc, dwarf::DW_FORM_udata,<br>
> -                  DD->getAddressPool().getIndex(Sym, /* TLS */ true));<br>
> +          // FIXME: Make this work with -gsplit-dwarf.<br>
> +          unsigned PointerSize = Asm->getDataLayout().getPointerSize();<br>
> +          assert((PointerSize == 4 || PointerSize == 8) &&<br>
> +                 "Add support for other sizes if necessary");<br>
> +          // Based on GCC's support for TLS:<br>
> +          if (!DD->useSplitDwarf()) {<br>
> +            // 1) Start with a constNu of the appropriate pointer size<br>
> +            addUInt(*Loc, dwarf::DW_FORM_data1, PointerSize == 4<br>
> +                                                    ? dwarf::DW_OP_const4u<br>
> +                                                    : dwarf::DW_OP_const8u);<br>
> +            // 2) containing the (relocated) offset of the TLS variable<br>
> +            //    within the module's TLS block.<br>
> +            addExpr(*Loc, dwarf::DW_FORM_udata,<br>
> +                    Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));<br>
> +          } else {<br>
> +            addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);<br>
> +            addUInt(*Loc, dwarf::DW_FORM_udata,<br>
> +                    DD->getAddressPool().getIndex(Sym, /* TLS */ true));<br>
> +          }<br>
> +          // 3) followed by an OP to make the debugger do a TLS lookup.<br>
> +          addUInt(*Loc, dwarf::DW_FORM_data1,<br>
> +                  DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address<br>
> +                                        : dwarf::DW_OP_form_tls_address);<br>
>          }<br>
> -        // 3) followed by an OP to make the debugger do a TLS lookup.<br>
> -        addUInt(*Loc, dwarf::DW_FORM_data1,<br>
> -                DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address<br>
> -                                      : dwarf::DW_OP_form_tls_address);<br>
> +      } else {<br>
> +        DD->addArangeLabel(SymbolCU(this, Sym));<br>
> +        addOpAddress(*Loc, Sym);<br>
>        }<br>
> -    } else {<br>
> -      DD->addArangeLabel(SymbolCU(this, Sym));<br>
> -      addOpAddress(*Loc, Sym);<br>
> -    }<br>
><br>
> -    addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);<br>
> -    if (DD->useAllLinkageNames())<br>
> -      addLinkageName(*VariableDIE, GV->getLinkageName());<br>
> +      addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);<br>
> +      if (DD->useAllLinkageNames())<br>
> +        addLinkageName(*VariableDIE, GV->getLinkageName());<br>
> +    }<br>
>    } else if (const ConstantInt *CI =<br>
>                   dyn_cast_or_null<ConstantInt>(GV->getVariable())) {<br>
>      addConstantValue(*VariableDIE, CI, GTy);<br>
>    } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getVariable())) {<br>
> -    addToAccelTable = true;<br>
> -    // GV is a merged global.<br>
> -    DIELoc *Loc = new (DIEValueAllocator) DIELoc;<br>
>      auto *Ptr = cast<GlobalValue>(CE->getOperand(0));<br>
> -    MCSymbol *Sym = Asm->getSymbol(Ptr);<br>
> -    DD->addArangeLabel(SymbolCU(this, Sym));<br>
> -    addOpAddress(*Loc, Sym);<br>
> -    addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);<br>
> -    SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());<br>
> -    addUInt(*Loc, dwarf::DW_FORM_udata,<br>
> -            Asm->getDataLayout().getIndexedOffsetInType(Ptr->getValueType(), Idx));<br>
> -    addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);<br>
> -    addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);<br>
> +    if (!Ptr->hasDLLImportStorageClass()) {<br>
> +      addToAccelTable = true;<br>
> +      // GV is a merged global.<br>
> +      DIELoc *Loc = new (DIEValueAllocator) DIELoc;<br>
> +      MCSymbol *Sym = Asm->getSymbol(Ptr);<br>
> +      DD->addArangeLabel(SymbolCU(this, Sym));<br>
> +      addOpAddress(*Loc, Sym);<br>
> +      addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);<br>
> +      SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());<br>
> +      addUInt(*Loc, dwarf::DW_FORM_udata,<br>
> +              Asm->getDataLayout().getIndexedOffsetInType(Ptr->getValueType(),<br>
> +                                                          Idx));<br>
> +      addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);<br>
> +      addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);<br>
> +    }<br>
>    }<br>
><br>
>    if (addToAccelTable) {<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=274986&r1=274985&r2=274986&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=274986&r1=274985&r2=274986&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Sat Jul  9 15:47:48 2016<br>
> @@ -1053,14 +1053,18 @@ void DwarfUnit::constructTemplateValuePa<br>
>      if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))<br>
>        addConstantValue(ParamDIE, CI, resolve(VP->getType()));<br>
>      else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {<br>
> -      // For declaration non-type template parameters (such as global values and<br>
> -      // functions)<br>
> -      DIELoc *Loc = new (DIEValueAllocator) DIELoc;<br>
> -      addOpAddress(*Loc, Asm->getSymbol(GV));<br>
> -      // Emit DW_OP_stack_value to use the address as the immediate value of the<br>
> -      // parameter, rather than a pointer to it.<br>
> -      addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);<br>
> -      addBlock(ParamDIE, dwarf::DW_AT_location, Loc);<br>
> +      // We cannot describe the location of dllimport'd entities: the<br>
> +      // computation of their address requires loads from the IAT.<br>
> +      if (!GV->hasDLLImportStorageClass()) {<br>
> +        // For declaration non-type template parameters (such as global values<br>
> +        // and functions)<br>
> +        DIELoc *Loc = new (DIEValueAllocator) DIELoc;<br>
> +        addOpAddress(*Loc, Asm->getSymbol(GV));<br>
> +        // Emit DW_OP_stack_value to use the address as the immediate value of<br>
> +        // the parameter, rather than a pointer to it.<br>
> +        addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);<br>
> +        addBlock(ParamDIE, dwarf::DW_AT_location, Loc);<br>
> +      }<br>
>      } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {<br>
>        assert(isa<MDString>(Val));<br>
>        addString(ParamDIE, dwarf::DW_AT_GNU_template_name,<br>
><br>
> Added: llvm/trunk/test/DebugInfo/X86/dllimport.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dllimport.ll?rev=274986&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dllimport.ll?rev=274986&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/DebugInfo/X86/dllimport.ll (added)<br>
> +++ llvm/trunk/test/DebugInfo/X86/dllimport.ll Sat Jul  9 15:47:48 2016<br>
> @@ -0,0 +1,27 @@<br>
> +; RUN: llc -mtriple=i686-pc-windows-msvc -O0 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s<br>
> +<br>
> +; CHECK-NOT: DW_AT_location<br>
> +<br>
> +target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"<br>
> +target triple = "i686-pc-windows-msvc"<br>
> +<br>
> +@"\01?id@?$numpunct@D@@0HA" = available_externally dllimport global i32 0, align 4<br>
> +<br>
> +!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
> +!llvm.module.flags = !{!13, !14}<br>
> +<br>
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 272628) (llvm/trunk 272566)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)<br>
> +!1 = !DIFile(filename: "/usr/local/google/home/majnemer/Downloads/<stdin>", directory: "/usr/local/google/home/majnemer/llvm/src")<br>
> +!2 = !{}<br>
> +!3 = !{!4}<br>
> +!4 = distinct !DIGlobalVariable(name: "id", linkageName: "\01?id@?$numpunct@D@@0HA", scope: !0, file: !5, line: 4, type: !6, isLocal: false, isDefinition: true, variable: i32* @"\01?id@?$numpunct@D@@0HA", declaration: !7)<br>
> +!5 = !DIFile(filename: "/usr/local/google/home/majnemer/Downloads/t.ii", directory: "/usr/local/google/home/majnemer/llvm/src")<br>
> +!6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br>
> +!7 = !DIDerivedType(tag: DW_TAG_member, name: "id", scope: !8, file: !5, line: 2, baseType: !6, flags: DIFlagStaticMember)<br>
> +!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "numpunct<char>", file: !5, line: 2, size: 8, align: 8, elements: !9, templateParams: !10)<br>
> +!9 = !{!7}<br>
> +!10 = !{!11}<br>
> +!11 = !DITemplateTypeParameter(type: !12)<br>
> +!12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)<br>
> +!13 = !{i32 2, !"Dwarf Version", i32 3}<br>
> +!14 = !{i32 2, !"Debug Info Version", i32 3}<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
<br>
<br>
--<br>
With best regards, Anton Korobeynikov<br>
Department of Statistical Modelling, Saint Petersburg State University<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>