mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-04 10:04:33 +00:00
[COFF, Dwarf] Don't emit DW_AT_location for dllimported entities
There exists no relocation which can describe the address of a dllimported variable: do not try to describe their location. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274986 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9dd11bf890
commit
01d1f77974
@ -148,62 +148,69 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
|
||||
// Add location.
|
||||
bool addToAccelTable = false;
|
||||
if (auto *Global = dyn_cast_or_null<GlobalVariable>(GV->getVariable())) {
|
||||
addToAccelTable = true;
|
||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||
const MCSymbol *Sym = Asm->getSymbol(Global);
|
||||
if (Global->isThreadLocal()) {
|
||||
if (Asm->TM.Options.EmulatedTLS) {
|
||||
// TODO: add debug info for emulated thread local mode.
|
||||
} else {
|
||||
// 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:
|
||||
if (!DD->useSplitDwarf()) {
|
||||
// 1) Start with a constNu of the appropriate pointer size
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, PointerSize == 4
|
||||
? dwarf::DW_OP_const4u
|
||||
: dwarf::DW_OP_const8u);
|
||||
// 2) containing the (relocated) offset of the TLS variable
|
||||
// within the module's TLS block.
|
||||
addExpr(*Loc, dwarf::DW_FORM_udata,
|
||||
Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
|
||||
// We cannot describe the location of dllimport'd variables: the computation
|
||||
// of their address requires loads from the IAT.
|
||||
if (!Global->hasDLLImportStorageClass()) {
|
||||
addToAccelTable = true;
|
||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||
const MCSymbol *Sym = Asm->getSymbol(Global);
|
||||
if (Global->isThreadLocal()) {
|
||||
if (Asm->TM.Options.EmulatedTLS) {
|
||||
// TODO: add debug info for emulated thread local mode.
|
||||
} else {
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
|
||||
addUInt(*Loc, dwarf::DW_FORM_udata,
|
||||
DD->getAddressPool().getIndex(Sym, /* TLS */ true));
|
||||
// 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:
|
||||
if (!DD->useSplitDwarf()) {
|
||||
// 1) Start with a constNu of the appropriate pointer size
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, PointerSize == 4
|
||||
? dwarf::DW_OP_const4u
|
||||
: dwarf::DW_OP_const8u);
|
||||
// 2) containing the (relocated) offset of the TLS variable
|
||||
// within the module's TLS block.
|
||||
addExpr(*Loc, dwarf::DW_FORM_udata,
|
||||
Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
|
||||
} else {
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
|
||||
addUInt(*Loc, dwarf::DW_FORM_udata,
|
||||
DD->getAddressPool().getIndex(Sym, /* TLS */ true));
|
||||
}
|
||||
// 3) followed by an OP to make the debugger do a TLS lookup.
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1,
|
||||
DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address
|
||||
: dwarf::DW_OP_form_tls_address);
|
||||
}
|
||||
// 3) followed by an OP to make the debugger do a TLS lookup.
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1,
|
||||
DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address
|
||||
: dwarf::DW_OP_form_tls_address);
|
||||
} else {
|
||||
DD->addArangeLabel(SymbolCU(this, Sym));
|
||||
addOpAddress(*Loc, Sym);
|
||||
}
|
||||
} else {
|
||||
DD->addArangeLabel(SymbolCU(this, Sym));
|
||||
addOpAddress(*Loc, Sym);
|
||||
}
|
||||
|
||||
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
|
||||
if (DD->useAllLinkageNames())
|
||||
addLinkageName(*VariableDIE, GV->getLinkageName());
|
||||
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
|
||||
if (DD->useAllLinkageNames())
|
||||
addLinkageName(*VariableDIE, GV->getLinkageName());
|
||||
}
|
||||
} else if (const ConstantInt *CI =
|
||||
dyn_cast_or_null<ConstantInt>(GV->getVariable())) {
|
||||
addConstantValue(*VariableDIE, CI, GTy);
|
||||
} else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getVariable())) {
|
||||
addToAccelTable = true;
|
||||
// GV is a merged global.
|
||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||
auto *Ptr = cast<GlobalValue>(CE->getOperand(0));
|
||||
MCSymbol *Sym = Asm->getSymbol(Ptr);
|
||||
DD->addArangeLabel(SymbolCU(this, Sym));
|
||||
addOpAddress(*Loc, Sym);
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
||||
SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());
|
||||
addUInt(*Loc, dwarf::DW_FORM_udata,
|
||||
Asm->getDataLayout().getIndexedOffsetInType(Ptr->getValueType(), Idx));
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
||||
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
|
||||
if (!Ptr->hasDLLImportStorageClass()) {
|
||||
addToAccelTable = true;
|
||||
// GV is a merged global.
|
||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||
MCSymbol *Sym = Asm->getSymbol(Ptr);
|
||||
DD->addArangeLabel(SymbolCU(this, Sym));
|
||||
addOpAddress(*Loc, Sym);
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
||||
SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());
|
||||
addUInt(*Loc, dwarf::DW_FORM_udata,
|
||||
Asm->getDataLayout().getIndexedOffsetInType(Ptr->getValueType(),
|
||||
Idx));
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
||||
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
|
||||
}
|
||||
}
|
||||
|
||||
if (addToAccelTable) {
|
||||
|
@ -1053,14 +1053,18 @@ void DwarfUnit::constructTemplateValueParameterDIE(
|
||||
if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
|
||||
addConstantValue(ParamDIE, CI, resolve(VP->getType()));
|
||||
else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
|
||||
// For declaration non-type template parameters (such as global values and
|
||||
// functions)
|
||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||
addOpAddress(*Loc, Asm->getSymbol(GV));
|
||||
// Emit DW_OP_stack_value to use the address as the immediate value of the
|
||||
// parameter, rather than a pointer to it.
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
|
||||
addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
|
||||
// We cannot describe the location of dllimport'd entities: the
|
||||
// computation of their address requires loads from the IAT.
|
||||
if (!GV->hasDLLImportStorageClass()) {
|
||||
// For declaration non-type template parameters (such as global values
|
||||
// and functions)
|
||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||
addOpAddress(*Loc, Asm->getSymbol(GV));
|
||||
// Emit DW_OP_stack_value to use the address as the immediate value of
|
||||
// the parameter, rather than a pointer to it.
|
||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
|
||||
addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
|
||||
}
|
||||
} else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {
|
||||
assert(isa<MDString>(Val));
|
||||
addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
|
||||
|
27
test/DebugInfo/X86/dllimport.ll
Normal file
27
test/DebugInfo/X86/dllimport.ll
Normal file
@ -0,0 +1,27 @@
|
||||
; RUN: llc -mtriple=i686-pc-windows-msvc -O0 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
|
||||
|
||||
; CHECK-NOT: DW_AT_location
|
||||
|
||||
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
|
||||
target triple = "i686-pc-windows-msvc"
|
||||
|
||||
@"\01?id@?$numpunct@D@@0HA" = available_externally dllimport global i32 0, align 4
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!13, !14}
|
||||
|
||||
!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)
|
||||
!1 = !DIFile(filename: "/usr/local/google/home/majnemer/Downloads/<stdin>", directory: "/usr/local/google/home/majnemer/llvm/src")
|
||||
!2 = !{}
|
||||
!3 = !{!4}
|
||||
!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)
|
||||
!5 = !DIFile(filename: "/usr/local/google/home/majnemer/Downloads/t.ii", directory: "/usr/local/google/home/majnemer/llvm/src")
|
||||
!6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
|
||||
!7 = !DIDerivedType(tag: DW_TAG_member, name: "id", scope: !8, file: !5, line: 2, baseType: !6, flags: DIFlagStaticMember)
|
||||
!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "numpunct<char>", file: !5, line: 2, size: 8, align: 8, elements: !9, templateParams: !10)
|
||||
!9 = !{!7}
|
||||
!10 = !{!11}
|
||||
!11 = !DITemplateTypeParameter(type: !12)
|
||||
!12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
|
||||
!13 = !{i32 2, !"Dwarf Version", i32 3}
|
||||
!14 = !{i32 2, !"Debug Info Version", i32 3}
|
Loading…
Reference in New Issue
Block a user