Adjust debug range offsets for isWeakForLinker() functions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102127 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index dc6b998..0678242 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1384,6 +1384,11 @@
if (Ranges.empty())
return 0;
+ bool MarkFunctionBegin = false;
+ if (FunctionBeginSym &&
+ Asm->MF->getFunction()->isWeakForLinker())
+ MarkFunctionBegin = true;
+
SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin();
if (Ranges.size() > 1) {
// .debug_range section has not been laid out yet. Emit offset in
@@ -1393,8 +1398,15 @@
DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize());
for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(),
RE = Ranges.end(); RI != RE; ++RI) {
- DebugRangeSymbols.push_back(LabelsBeforeInsn.lookup(RI->first));
- DebugRangeSymbols.push_back(LabelsAfterInsn.lookup(RI->second));
+ MCSymbol *Sym = LabelsBeforeInsn.lookup(RI->first);
+ if (MarkFunctionBegin)
+ WeakDebugRangeSymbols.insert(std::make_pair(Sym, FunctionBeginSym));
+ DebugRangeSymbols.push_back(Sym);
+
+ Sym = LabelsAfterInsn.lookup(RI->second);
+ if (MarkFunctionBegin)
+ WeakDebugRangeSymbols.insert(std::make_pair(Sym, FunctionBeginSym));
+ DebugRangeSymbols.push_back(Sym);
}
DebugRangeSymbols.push_back(NULL);
DebugRangeSymbols.push_back(NULL);
@@ -3228,11 +3240,21 @@
// Start the dwarf ranges section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfRangesSection());
- for (SmallVector<const MCSymbol *, 8>::const_iterator I = DebugRangeSymbols.begin(),
- E = DebugRangeSymbols.end(); I != E; ++I) {
- if (*I)
- Asm->EmitLabelDifference(*I, TextSectionSym,
+ for (SmallVector<const MCSymbol *, 8>::const_iterator
+ I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end();
+ I != E; ++I) {
+ if (*I) {
+ const MCSymbol *Begin = TextSectionSym;
+ // If this symbol is inside linkonce section then use appropriate begin
+ // marker;
+ DenseMap<const MCSymbol *, const MCSymbol *>::iterator WI
+ = WeakDebugRangeSymbols.find(*I);
+ if (WI != WeakDebugRangeSymbols.end())
+ Begin = WI->second;
+
+ Asm->EmitLabelDifference(*I, Begin,
Asm->getTargetData().getPointerSize());
+ }
else
Asm->OutStreamer.EmitIntValue(0, Asm->getTargetData().getPointerSize(),
/*addrspace*/0);
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 698f710..b3f9745 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -197,6 +197,7 @@
DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
+ DenseMap<const MCSymbol *, const MCSymbol *> WeakDebugRangeSymbols;
/// Previous instruction's location information. This is used to determine
/// label location to indicate scope boundries in dwarf debug info.