diff options
author | Eric Christopher <echristo@gmail.com> | 2013-09-13 00:35:05 +0000 |
---|---|---|
committer | Eric Christopher <echristo@gmail.com> | 2013-09-13 00:35:05 +0000 |
commit | 8f1a9299de0333c8c310b7580ea63ba5b7a3c400 (patch) | |
tree | 40132d335c7326d6c6092d5abae513490d58c08f | |
parent | 5704d640abd96f8614ad4be555fcf1049c500bcd (diff) | |
download | external_llvm-8f1a9299de0333c8c310b7580ea63ba5b7a3c400.zip external_llvm-8f1a9299de0333c8c310b7580ea63ba5b7a3c400.tar.gz external_llvm-8f1a9299de0333c8c310b7580ea63ba5b7a3c400.tar.bz2 |
Add initial support for handling gnu style pubnames accepted by some
versions of gold. This support is designed to allow gold to produce
gdb_index sections similar to the accelerator tables and consumable
by gdb.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190649 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Support/Dwarf.h | 23 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 115 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.h | 10 | ||||
-rw-r--r-- | test/DebugInfo/X86/gnu-public-names.ll | 126 |
4 files changed, 265 insertions, 9 deletions
diff --git a/include/llvm/Support/Dwarf.h b/include/llvm/Support/Dwarf.h index a31c3f1..a1ed1d1 100644 --- a/include/llvm/Support/Dwarf.h +++ b/include/llvm/Support/Dwarf.h @@ -791,6 +791,17 @@ const char *AtomTypeString(unsigned Atom); // Constants for the GNU pubnames/pubtypes extensions supporting gdb index. enum GDBIndex { + // The full index looks like this for each symbol: + // + // 0-23 CU index + // 24-27 reserved + // 28-30 symbol kind + // 31 0 == global, 1 == static + // + // where each entry refers to the CU and some attributes about the symbol. + + // Attributes kinds for the index. + // Special value to indicate no attributes are present. GDB_INDEX_SYMBOL_KIND_NONE = 0, GDB_INDEX_SYMBOL_KIND_TYPE = 1, @@ -800,7 +811,17 @@ enum GDBIndex { // 3 unused bits. GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5, GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6, - GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7 + GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7, + + // Index values are defined via the set of CUs that define the + // symbol. For the pubnames/pubtypes extensions we need the + // various shifts and masks. + GDB_INDEX_SYMBOL_STATIC_SHIFT = 31, + GDB_INDEX_SYMBOL_STATIC_MASK = 1, + GDB_INDEX_SYMBOL_KIND_SHIFT = 28, + GDB_INDEX_SYMBOL_KIND_MASK = 7, + GDB_INDEX_CU_BITSIZE = 24, + GDB_INDEX_CU_MASK = ((1 << GDB_INDEX_CU_BITSIZE) - 1) }; /// GDBIndexTypeString - Return the string for the specified index type. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index f155647..4f62ab9 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -68,6 +68,11 @@ GenerateCUHash("generate-cu-hash", cl::Hidden, cl::desc("Add the CU hash as the dwo_id."), cl::init(false)); +static cl::opt<bool> +GenerateGnuPubSections("generate-gnu-dwarf-pub-sections", cl::Hidden, + cl::desc("Generate GNU-style pubnames and pubtypes"), + cl::init(false)); + namespace { enum DefaultOnOff { Default, @@ -768,6 +773,12 @@ CompileUnit *DwarfDebug::constructCompileUnit(const MDNode *N) { // skeleton CU and so we don't need to duplicate it here. if (!useSplitDwarf() && !CompilationDir.empty()) NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir); + + // Flag to let the linker know we have emitted new style pubnames. Only + // emit it here if we don't have a skeleton CU for split dwarf. + if (!useSplitDwarf() && GenerateGnuPubSections) + NewCU->addFlag(Die, dwarf::DW_AT_GNU_pubnames); + if (DIUnit.isOptimized()) NewCU->addFlag(Die, dwarf::DW_AT_APPLE_optimized); @@ -1149,8 +1160,8 @@ void DwarfDebug::endModule() { // Emit the pubnames and pubtypes sections if requested. if (HasDwarfPubSections) { - emitDebugPubNames(); - emitDebugPubTypes(); + emitDebugPubNames(GenerateGnuPubSections ? true : false); + emitDebugPubTypes(GenerateGnuPubSections ? true : false); } // Finally emit string information into a string table. @@ -1933,7 +1944,11 @@ void DwarfDebug::emitSectionLabels() { if (HasDwarfPubSections) { emitSectionSym(Asm, TLOF.getDwarfPubNamesSection()); emitSectionSym(Asm, TLOF.getDwarfPubTypesSection()); + } else if (GenerateGnuPubSections) { + emitSectionSym(Asm, TLOF.getDwarfGnuPubNamesSection()); + emitSectionSym(Asm, TLOF.getDwarfGnuPubTypesSection()); } + DwarfStrSectionSym = emitSectionSym(Asm, TLOF.getDwarfStrSection(), "info_string"); if (useSplitDwarf()) { @@ -2292,11 +2307,83 @@ void DwarfDebug::emitAccelTypes() { AT.Emit(Asm, SectionBegin, &InfoHolder); } +// Public name handling. +// The format for the various pubnames: +// +// dwarf pubnames - offset/name pairs where the offset is the offset into the CU +// for the DIE that is named. +// +// gnu pubnames - offset/index value/name tuples where the offset is the offset +// into the CU and the index value is computed according to the type of value +// for the DIE that is named. +// +// For type units the offset is the offset of the skeleton DIE. For split dwarf +// it's the offset within the debug_info/debug_types dwo section, however, the +// reference in the pubname header doesn't change. + +/// computeIndexValue - Compute the gdb index value for the DIE and CU. +static uint8_t computeIndexValue(CompileUnit *CU, DIE *Die) { +#define UPDATE_VALUE(CURRENT, VALUE) \ + { \ + (CURRENT) |= (((VALUE) & dwarf::GDB_INDEX_SYMBOL_KIND_MASK) \ + << dwarf::GDB_INDEX_SYMBOL_KIND_SHIFT); \ + } + +#define UPDATE_STATIC(CURRENT, IS_STATIC) \ + { \ + (CURRENT) |= (((IS_STATIC) & dwarf::GDB_INDEX_SYMBOL_STATIC_MASK) \ + << dwarf::GDB_INDEX_SYMBOL_STATIC_SHIFT); \ + } + + // Compute the Attributes for the Die. + uint32_t Value = dwarf::GDB_INDEX_SYMBOL_KIND_NONE; + bool External = + Die->findAttribute(dwarf::DW_AT_external) != NULL ? true : false; + + switch (Die->getTag()) { + case dwarf::DW_TAG_class_type: + case dwarf::DW_TAG_structure_type: + case dwarf::DW_TAG_union_type: + case dwarf::DW_TAG_enumeration_type: + case dwarf::DW_TAG_typedef: + case dwarf::DW_TAG_base_type: + case dwarf::DW_TAG_subrange_type: + UPDATE_VALUE(Value, dwarf::GDB_INDEX_SYMBOL_KIND_TYPE); + UPDATE_STATIC(Value, 1); + break; + case dwarf::DW_TAG_namespace: + UPDATE_VALUE(Value, dwarf::GDB_INDEX_SYMBOL_KIND_TYPE); + break; + case dwarf::DW_TAG_subprogram: + UPDATE_VALUE(Value, dwarf::GDB_INDEX_SYMBOL_KIND_FUNCTION); + UPDATE_STATIC(Value, !External); + break; + case dwarf::DW_TAG_constant: + case dwarf::DW_TAG_variable: + UPDATE_VALUE(Value, dwarf::GDB_INDEX_SYMBOL_KIND_VARIABLE); + UPDATE_STATIC(Value, !External); + break; + case dwarf::DW_TAG_enumerator: + UPDATE_VALUE(Value, dwarf::GDB_INDEX_SYMBOL_KIND_VARIABLE); + UPDATE_STATIC(Value, 1); + break; + default: + break; + } + // We don't need to add the CU into the bitmask for two reasons: + // a) the pubnames/pubtypes sections are per-cpu, and + // b) the linker wouldn't understand it anyhow. + // so go ahead and make it 1 byte by shifting it down. + return Value >> dwarf::GDB_INDEX_CU_BITSIZE; +} + /// emitDebugPubNames - Emit visible names into a debug pubnames section. /// -void DwarfDebug::emitDebugPubNames() { +void DwarfDebug::emitDebugPubNames(bool GnuStyle) { const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection(); - const MCSection *PSec = Asm->getObjFileLowering().getDwarfPubNamesSection(); + const MCSection *PSec = + GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection() + : Asm->getObjFileLowering().getDwarfPubNamesSection(); typedef DenseMap<const MDNode*, CompileUnit*> CUMapType; for (CUMapType::iterator I = CUMap.begin(), E = CUMap.end(); I != E; ++I) { @@ -2309,6 +2396,7 @@ void DwarfDebug::emitDebugPubNames() { // Start the dwarf pubnames section. Asm->OutStreamer.SwitchSection(PSec); + // Emit the header. Asm->OutStreamer.AddComment("Length of Public Names Info"); Asm->EmitLabelDifference(Asm->GetTempSymbol("pubnames_end", ID), Asm->GetTempSymbol("pubnames_begin", ID), 4); @@ -2327,15 +2415,21 @@ void DwarfDebug::emitDebugPubNames() { Asm->GetTempSymbol(ISec->getLabelBeginName(), ID), 4); + // Emit the pubnames for this compilation unit. const StringMap<DIE*> &Globals = TheCU->getGlobalNames(); for (StringMap<DIE*>::const_iterator GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { const char *Name = GI->getKeyData(); - const DIE *Entity = GI->second; + DIE *Entity = GI->second; Asm->OutStreamer.AddComment("DIE offset"); Asm->EmitInt32(Entity->getOffset()); + if (GnuStyle) { + Asm->OutStreamer.AddComment("Index value"); + Asm->EmitInt8(computeIndexValue(TheCU, Entity)); + } + if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name"); Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1)); @@ -2347,7 +2441,7 @@ void DwarfDebug::emitDebugPubNames() { } } -void DwarfDebug::emitDebugPubTypes() { +void DwarfDebug::emitDebugPubTypes(bool GnuStyle) { const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection(); const MCSection *PSec = Asm->getObjFileLowering().getDwarfPubTypesSection(); @@ -2390,6 +2484,11 @@ void DwarfDebug::emitDebugPubTypes() { Asm->OutStreamer.AddComment("DIE offset"); Asm->EmitInt32(Entity->getOffset()); + if (GnuStyle) { + Asm->OutStreamer.AddComment("Index value"); + Asm->EmitInt8(computeIndexValue(TheCU, Entity)); + } + if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name"); @@ -2651,6 +2750,10 @@ CompileUnit *DwarfDebug::constructSkeletonCU(const CompileUnit *CU) { if (!CompilationDir.empty()) NewCU->addLocalString(Die, dwarf::DW_AT_comp_dir, CompilationDir); + // Flag to let the linker know we have emitted new style pubnames. + if (GenerateGnuPubSections) + NewCU->addFlag(Die, dwarf::DW_AT_GNU_pubnames); + SkeletonHolder.addUnit(NewCU); SkeletonCUs.push_back(NewCU); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index c702180..5a03e9f 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -533,10 +533,16 @@ private: void emitAccelTypes(); /// \brief Emit visible names into a debug pubnames section. - void emitDebugPubNames(); + /// \param GnuStyle determines whether or not we want to emit + /// additional information into the table ala newer gcc for gdb + /// index. + void emitDebugPubNames(bool GnuStyle = false); /// \brief Emit visible types into a debug pubtypes section. - void emitDebugPubTypes(); + /// \param GnuStyle determines whether or not we want to emit + /// additional information into the table ala newer gcc for gdb + /// index. + void emitDebugPubTypes(bool GnuStyle = false); /// \brief Emit visible names into a debug str section. void emitDebugStr(); diff --git a/test/DebugInfo/X86/gnu-public-names.ll b/test/DebugInfo/X86/gnu-public-names.ll new file mode 100644 index 0000000..68af3a1 --- /dev/null +++ b/test/DebugInfo/X86/gnu-public-names.ll @@ -0,0 +1,126 @@ +; RUN: llc -mtriple=x86_64-pc-linux-gnu -generate-gnu-dwarf-pub-sections -o - %s | FileCheck %s +; ModuleID = 'dwarf-public-names.cpp' +; +; Generated from: +; +; struct C { +; void member_function(); +; static int static_member_function(); +; static int static_member_variable; +; }; +; +; int C::static_member_variable = 0; +; +; void C::member_function() { +; static_member_variable = 0; +; } +; +; int C::static_member_function() { +; return static_member_variable; +; } +; +; C global_variable; +; +; int global_function() { +; return -1; +; } +; +; namespace ns { +; void global_namespace_function() { +; global_variable.member_function(); +; } +; int global_namespace_variable = 1; +; } + + +; CHECK: .byte 32 # Index value +; CHECK-NEXT: .asciz "global_namespace_variable" # External Name +; CHECK: .byte 48 # Index value +; CHECK: .asciz "global_namespace_function" # External Name +; CHECK: .byte 176 # Index value +; CHECK: .asciz "static_member_function" # External Name +; CHECK: .byte 32 # Index value +; CHECK: .asciz "global_variable" # External Name +; CHECK: .byte 48 # Index value +; CHECK: .asciz "global_function" # External Name +; CHECK: .byte 176 # Index value +; CHECK: .asciz "member_function" # External Name + +%struct.C = type { i8 } + +@_ZN1C22static_member_variableE = global i32 0, align 4 +@global_variable = global %struct.C zeroinitializer, align 1 +@_ZN2ns25global_namespace_variableE = global i32 1, align 4 + +define void @_ZN1C15member_functionEv(%struct.C* %this) nounwind uwtable align 2 { +entry: + %this.addr = alloca %struct.C*, align 8 + store %struct.C* %this, %struct.C** %this.addr, align 8 + call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr}, metadata !28), !dbg !30 + %this1 = load %struct.C** %this.addr + store i32 0, i32* @_ZN1C22static_member_variableE, align 4, !dbg !31 + ret void, !dbg !32 +} + +declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone + +define i32 @_ZN1C22static_member_functionEv() nounwind uwtable align 2 { +entry: + %0 = load i32* @_ZN1C22static_member_variableE, align 4, !dbg !33 + ret i32 %0, !dbg !33 +} + +define i32 @_Z15global_functionv() nounwind uwtable { +entry: + ret i32 -1, !dbg !34 +} + +define void @_ZN2ns25global_namespace_functionEv() nounwind uwtable { +entry: + call void @_ZN1C15member_functionEv(%struct.C* @global_variable), !dbg !35 + ret void, !dbg !36 +} + +attributes #0 = { nounwind uwtable } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} + +!0 = metadata !{i32 786449, metadata !37, i32 4, metadata !"clang version 3.3 (http://llvm.org/git/clang.git a09cd8103a6a719cb2628cdf0c91682250a17bd2) (http://llvm.org/git/llvm.git 47d03cec0afca0c01ae42b82916d1d731716cd20)", i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !2, metadata !24, metadata !24, metadata !""} ; [ DW_TAG_compile_unit ] [/usr2/kparzysz/s.hex/t/dwarf-public-names.cpp] [DW_LANG_C_plus_plus] +!1 = metadata !{i32 0} +!2 = metadata !{metadata !3, metadata !18, metadata !19, metadata !20} +!3 = metadata !{i32 786478, metadata !4, null, metadata !"member_function", metadata !"member_function", metadata !"_ZN1C15member_functionEv", i32 9, metadata !5, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (%struct.C*)* @_ZN1C15member_functionEv, null, metadata !12, metadata !1, i32 9} ; [ DW_TAG_subprogram ] [line 9] [def] [member_function] +!4 = metadata !{i32 786473, metadata !37} ; [ DW_TAG_file_type ] +!5 = metadata !{i32 786453, i32 0, null, i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !6, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!6 = metadata !{null, metadata !7} +!7 = metadata !{i32 786447, i32 0, null, i32 0, i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !8} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from C] +!8 = metadata !{i32 786451, metadata !37, null, metadata !"C", i32 1, i64 8, i64 8, i32 0, i32 0, null, metadata !9, i32 0, null, null, null} ; [ DW_TAG_structure_type ] [C] [line 1, size 8, align 8, offset 0] [def] [from ] +!9 = metadata !{metadata !10, metadata !12, metadata !14} +!10 = metadata !{i32 786445, metadata !37, metadata !8, metadata !"static_member_variable", i32 4, i64 0, i64 0, i64 0, i32 4096, metadata !11, null} ; [ DW_TAG_member ] [static_member_variable] [line 4, size 0, align 0, offset 0] [static] [from int] +!11 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed] +!12 = metadata !{i32 786478, metadata !4, metadata !8, metadata !"member_function", metadata !"member_function", metadata !"_ZN1C15member_functionEv", i32 2, metadata !5, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 false, null, null, i32 0, metadata !13, i32 2} ; [ DW_TAG_subprogram ] [line 2] [member_function] +!13 = metadata !{i32 786468} ; [ DW_TAG_base_type ] [line 0, size 0, align 0, offset 0] +!14 = metadata !{i32 786478, metadata !4, metadata !8, metadata !"static_member_function", metadata !"static_member_function", metadata !"_ZN1C22static_member_functionEv", i32 3, metadata !15, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 false, null, null, i32 0, metadata !17, i32 3} ; [ DW_TAG_subprogram ] [line 3] [static_member_function] +!15 = metadata !{i32 786453, i32 0, null, i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !16, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!16 = metadata !{metadata !11} +!17 = metadata !{i32 786468} ; [ DW_TAG_base_type ] [line 0, size 0, align 0, offset 0] +!18 = metadata !{i32 786478, metadata !4, null, metadata !"static_member_function", metadata !"static_member_function", metadata !"_ZN1C22static_member_functionEv", i32 13, metadata !15, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_ZN1C22static_member_functionEv, null, metadata !14, metadata !1, i32 13} ; [ DW_TAG_subprogram ] [line 13] [def] [static_member_function] +!19 = metadata !{i32 786478, metadata !4, metadata !4, metadata !"global_function", metadata !"global_function", metadata !"_Z15global_functionv", i32 19, metadata !15, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_Z15global_functionv, null, null, metadata !1, i32 19} ; [ DW_TAG_subprogram ] [line 19] [def] [global_function] +!20 = metadata !{i32 786478, metadata !4, metadata !21, metadata !"global_namespace_function", metadata !"global_namespace_function", metadata !"_ZN2ns25global_namespace_functionEv", i32 24, metadata !22, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void ()* @_ZN2ns25global_namespace_functionEv, null, null, metadata !1, i32 24} ; [ DW_TAG_subprogram ] [line 24] [def] [global_namespace_function] +!21 = metadata !{i32 786489, null, metadata !"ns", metadata !4, i32 23} ; [ DW_TAG_namespace ] [/usr2/kparzysz/s.hex/t/dwarf-public-names.cpp] +!22 = metadata !{i32 786453, i32 0, null, i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !23, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!23 = metadata !{null} +!24 = metadata !{metadata !25, metadata !26, metadata !27} +!25 = metadata !{i32 786484, i32 0, metadata !8, metadata !"static_member_variable", metadata !"static_member_variable", metadata !"_ZN1C22static_member_variableE", metadata !4, i32 7, metadata !11, i32 0, i32 1, i32* @_ZN1C22static_member_variableE, metadata !10} ; [ DW_TAG_variable ] [static_member_variable] [line 7] [def] +!26 = metadata !{i32 786484, i32 0, null, metadata !"global_variable", metadata !"global_variable", metadata !"", metadata !4, i32 17, metadata !8, i32 0, i32 1, %struct.C* @global_variable, null} ; [ DW_TAG_variable ] [global_variable] [line 17] [def] +!27 = metadata !{i32 786484, i32 0, metadata !21, metadata !"global_namespace_variable", metadata !"global_namespace_variable", metadata !"_ZN2ns25global_namespace_variableE", metadata !4, i32 27, metadata !11, i32 0, i32 1, i32* @_ZN2ns25global_namespace_variableE, null} ; [ DW_TAG_variable ] [global_namespace_variable] [line 27] [def] +!28 = metadata !{i32 786689, metadata !3, metadata !"this", metadata !4, i32 16777225, metadata !29, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 9] +!29 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !8} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from C] +!30 = metadata !{i32 9, i32 0, metadata !3, null} +!31 = metadata !{i32 10, i32 0, metadata !3, null} +!32 = metadata !{i32 11, i32 0, metadata !3, null} +!33 = metadata !{i32 14, i32 0, metadata !18, null} +!34 = metadata !{i32 20, i32 0, metadata !19, null} +!35 = metadata !{i32 25, i32 0, metadata !20, null} +!36 = metadata !{i32 26, i32 0, metadata !20, null} +!37 = metadata !{metadata !"dwarf-public-names.cpp", metadata !"/usr2/kparzysz/s.hex/t"} |