summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2013-10-03 08:54:43 +0000
committerAlexey Samsonov <samsonov@google.com>2013-10-03 08:54:43 +0000
commit9d08d69fd4562a4433cf19eb4b96c17b34f6da2e (patch)
treea9c8dcaca15ab59ba57c34be40e46edc10c4dd14
parent198f1b340a71b26f70849db86d72f7b79fd56d03 (diff)
downloadllvm-9d08d69fd4562a4433cf19eb4b96c17b34f6da2e.tar.gz
llvm-9d08d69fd4562a4433cf19eb4b96c17b34f6da2e.tar.bz2
llvm-9d08d69fd4562a4433cf19eb4b96c17b34f6da2e.tar.xz
Remove wild .debug_aranges entries generated from unimportant labels
r191052 added emitting .debug_aranges to Clang, but this functionality is broken: it uses all MC labels added in DWARF Asm printer, including the labels for build relocations between different DWARF sections, like .Lsection_line or .Ldebug_loc0. As a result, if any DIE .debug_info would contain "DW_AT_location=0x123" attribute, .debug_aranges would also contain a range starting from 0x123, breaking tools that rely on this section. This patch fixes this by using only MC labels that corresponds to the addresses in the user program. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191884 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp16
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.cpp9
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.h7
-rw-r--r--test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll88
4 files changed, 98 insertions, 22 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index c9941086c2..afe8a7d283 100644
--- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -181,12 +181,6 @@ void CompileUnit::addLabel(DIE *Die, uint16_t Attribute, uint16_t Form,
const MCSymbol *Label) {
DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
Die->addValue(Attribute, Form, Value);
-
- SymbolCU Entry;
- Entry.CU = this;
- Entry.Sym = Label;
-
- DD->addLabel(Entry);
}
/// addLabelAddress - Add a dwarf label attribute data and value using
@@ -194,13 +188,8 @@ void CompileUnit::addLabel(DIE *Die, uint16_t Attribute, uint16_t Form,
///
void CompileUnit::addLabelAddress(DIE *Die, uint16_t Attribute,
MCSymbol *Label) {
- if (Label) {
- SymbolCU Entry;
- Entry.CU = this;
- Entry.Sym = Label;
-
- DD->addLabel(Entry);
- }
+ if (Label)
+ DD->addArangeLabel(SymbolCU(this, Label));
if (!DD->useSplitDwarf()) {
if (Label != NULL) {
@@ -221,6 +210,7 @@ void CompileUnit::addLabelAddress(DIE *Die, uint16_t Attribute,
/// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
///
void CompileUnit::addOpAddress(DIE *Die, const MCSymbol *Sym) {
+ DD->addArangeLabel(SymbolCU(this, Sym));
if (!DD->useSplitDwarf()) {
addUInt(Die, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
addLabel(Die, 0, dwarf::DW_FORM_udata, Sym);
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 587ee35beb..b8fa9743ab 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1110,8 +1110,8 @@ void DwarfDebug::finalizeModuleInfo() {
void DwarfDebug::endSections() {
// Filter labels by section.
- for (size_t n = 0; n < Labels.size(); n++) {
- const SymbolCU &SCU = Labels[n];
+ for (size_t n = 0; n < ArangeLabels.size(); n++) {
+ const SymbolCU &SCU = ArangeLabels[n];
if (SCU.Sym->isInSection()) {
// Make a note of this symbol and it's section.
const MCSection *Section = &SCU.Sym->getSection();
@@ -1138,10 +1138,7 @@ void DwarfDebug::endSections() {
}
// Insert a final terminator.
- SymbolCU Entry;
- Entry.CU = NULL;
- Entry.Sym = Sym;
- SectionMap[Section].push_back(Entry);
+ SectionMap[Section].push_back(SymbolCU(NULL, Sym));
}
}
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 7405fe12a9..423ff342ec 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -303,6 +303,7 @@ public:
/// \brief Helper used to pair up a symbol and it's DWARF compile unit.
struct SymbolCU {
+ SymbolCU(CompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
const MCSymbol *Sym;
CompileUnit *CU;
};
@@ -363,8 +364,8 @@ class DwarfDebug {
// separated by a zero byte, mapped to a unique id.
StringMap<unsigned, BumpPtrAllocator&> SourceIdMap;
- // List of all labels used in the output.
- std::vector<SymbolCU> Labels;
+ // List of all labels used in aranges generation.
+ std::vector<SymbolCU> ArangeLabels;
// Size of each symbol emitted (for those symbols that have a specific size).
DenseMap <const MCSymbol *, uint64_t> SymSize;
@@ -731,7 +732,7 @@ public:
void addTypeUnitType(DIE *Die) { TypeUnits.push_back(Die); }
/// \brief Add a label so that arange data can be generated for it.
- void addLabel(SymbolCU SCU) { Labels.push_back(SCU); }
+ void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
/// \brief For symbols that have a size designated (e.g. common symbols),
/// this tracks that size.
diff --git a/test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll b/test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll
new file mode 100644
index 0000000000..194e641214
--- /dev/null
+++ b/test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll
@@ -0,0 +1,88 @@
+; RUN: llc < %s | FileCheck %s
+
+; CHECK: .short 2 # DWARF Arange version number
+; CHECK: # Segment Size
+; CHECK-NOT: debug_loc
+; CHECK: .quad global
+; CHECK-NOT: debug_loc
+; CHECK: # ARange terminator
+
+; --- Source code ---
+; Generated with "clang -g -O1 -S -emit-llvm"
+
+; int global = 2;
+; int foo(int bar) { return bar; }
+; int foo2(int bar2) { return bar2; }
+
+; int main() {
+; return foo(2) + foo2(1) + global;
+; }
+
+
+; ModuleID = 'tmp/debug_ranges/a.cc'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@global = global i32 2, align 4
+
+; Function Attrs: nounwind readnone uwtable
+define i32 @_Z3fooi(i32 %bar) #0 {
+entry:
+ tail call void @llvm.dbg.value(metadata !{i32 %bar}, i64 0, metadata !10), !dbg !20
+ ret i32 %bar, !dbg !20
+}
+
+; Function Attrs: nounwind readnone uwtable
+define i32 @_Z4foo2i(i32 %bar2) #0 {
+entry:
+ tail call void @llvm.dbg.value(metadata !{i32 %bar2}, i64 0, metadata !13), !dbg !21
+ ret i32 %bar2, !dbg !21
+}
+
+; Function Attrs: nounwind readonly uwtable
+define i32 @main() #1 {
+entry:
+ %call = tail call i32 @_Z3fooi(i32 2), !dbg !22
+ %call1 = tail call i32 @_Z4foo2i(i32 1), !dbg !22
+ %add = add nsw i32 %call1, %call, !dbg !22
+ %0 = load i32* @global, align 4, !dbg !22, !tbaa !23
+ %add2 = add nsw i32 %add, %0, !dbg !22
+ ret i32 %add2, !dbg !22
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata) #2
+
+attributes #0 = { nounwind readnone uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readonly uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!19}
+
+!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.4 (191881)", i1 true, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !17, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [/tmp/debug_ranges/a.cc] [DW_LANG_C_plus_plus]
+!1 = metadata !{metadata !"tmp/debug_ranges/a.cc", metadata !"/"}
+!2 = metadata !{i32 0}
+!3 = metadata !{metadata !4, metadata !11, metadata !14}
+!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"foo", metadata !"foo", metadata !"_Z3fooi", i32 2, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i32 (i32)* @_Z3fooi, null, null, metadata !9, i32 2} ; [ DW_TAG_subprogram ] [line 2] [def] [foo]
+!5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/tmp/debug_ranges/a.cc]
+!6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
+!7 = metadata !{metadata !8, metadata !8}
+!8 = 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]
+!9 = metadata !{metadata !10}
+!10 = metadata !{i32 786689, metadata !4, metadata !"bar", metadata !5, i32 16777218, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [bar] [line 2]
+!11 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"foo2", metadata !"foo2", metadata !"_Z4foo2i", i32 3, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i32 (i32)* @_Z4foo2i, null, null, metadata !12, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [foo2]
+!12 = metadata !{metadata !13}
+!13 = metadata !{i32 786689, metadata !11, metadata !"bar2", metadata !5, i32 16777219, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [bar2] [line 3]
+!14 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"main", metadata !"main", metadata !"", i32 5, metadata !15, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i32 ()* @main, null, null, metadata !2, i32 5} ; [ DW_TAG_subprogram ] [line 5] [def] [main]
+!15 = metadata !{i32 786453, i32 0, null, metadata !"", 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 !8}
+!17 = metadata !{metadata !18}
+!18 = metadata !{i32 786484, i32 0, null, metadata !"global", metadata !"global", metadata !"", metadata !5, i32 1, metadata !8, i32 0, i32 1, i32* @global, null} ; [ DW_TAG_variable ] [global] [line 1] [def]
+!19 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
+!20 = metadata !{i32 2, i32 0, metadata !4, null}
+!21 = metadata !{i32 3, i32 0, metadata !11, null}
+!22 = metadata !{i32 6, i32 0, metadata !14, null}
+!23 = metadata !{metadata !"int", metadata !24}
+!24 = metadata !{metadata !"omnipotent char", metadata !25}
+!25 = metadata !{metadata !"Simple C/C++ TBAA"}