summaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-01-20 08:07:07 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-01-20 08:07:07 +0000
commitd15717170fbaaa24dacf2afbd8c6e9d8da4e8fa3 (patch)
tree293d9bdf885519c79b6fdbe2229ad7dc3390bf5e /lib/CodeGen
parent1e1446bf84a6a36366c40f995e68ca6a460c9839 (diff)
downloadllvm-d15717170fbaaa24dacf2afbd8c6e9d8da4e8fa3.tar.gz
llvm-d15717170fbaaa24dacf2afbd8c6e9d8da4e8fa3.tar.bz2
llvm-d15717170fbaaa24dacf2afbd8c6e9d8da4e8fa3.tar.xz
Fix a DenseMap iterator invalidation bug causing lots of crashes when
type units were enabled. The crux of the issue is that the addDwarfTypeUnitType routine can end up being indirectly recursive. In this case, the reference into the dense map (TU) became invalid by the time we popped all the way back and used it to add the DIE type signature. Instead, use early return in the case where we can bypass the recursive step and creating a type unit. Then use the pointer to the new type unit to set up the DIE type signature in the case where we have to. I tried really hard to reduce a testcase for this, but it's really annoying. You have to get this to be mid-recursion when the densemap grows. Even if we got a test case for this today, it'd be very unlikely to continue exercising this pattern. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199630 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.cpp66
1 files changed, 35 insertions, 31 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index f76e898cfb..8e612c3e6e 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -3027,36 +3027,40 @@ void DwarfDebug::emitDebugStrDWO() {
void DwarfDebug::addDwarfTypeUnitType(DICompileUnit CUNode,
StringRef Identifier, DIE *RefDie,
DICompositeType CTy) {
+
const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy];
- if (!TU) {
- DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
- DwarfTypeUnit *NewTU = new DwarfTypeUnit(
- InfoHolder.getUnits().size(), UnitDie, CUNode, Asm, this, &InfoHolder);
- TU = NewTU;
- InfoHolder.addUnit(NewTU);
-
- NewTU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
- CUNode.getLanguage());
-
- MD5 Hash;
- Hash.update(Identifier);
- // ... take the least significant 8 bytes and return those. Our MD5
- // implementation always returns its results in little endian, swap bytes
- // appropriately.
- MD5::MD5Result Result;
- Hash.final(Result);
- uint64_t Signature = *reinterpret_cast<support::ulittle64_t *>(Result + 8);
- NewTU->setTypeSignature(Signature);
- if (useSplitDwarf())
- NewTU->setSkeleton(constructSkeletonTU(NewTU));
-
- NewTU->setType(NewTU->createTypeDIE(CTy));
-
- NewTU->initSection(
- useSplitDwarf()
- ? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
- : Asm->getObjFileLowering().getDwarfTypesSection(Signature));
- }
-
- CUMap.begin()->second->addDIETypeSignature(RefDie, *TU);
+ if (TU) {
+ CUMap.begin()->second->addDIETypeSignature(RefDie, *TU);
+ return;
+ }
+
+ DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
+ DwarfTypeUnit *NewTU = new DwarfTypeUnit(
+ InfoHolder.getUnits().size(), UnitDie, CUNode, Asm, this, &InfoHolder);
+ TU = NewTU;
+ InfoHolder.addUnit(NewTU);
+
+ NewTU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
+ CUNode.getLanguage());
+
+ MD5 Hash;
+ Hash.update(Identifier);
+ // ... take the least significant 8 bytes and return those. Our MD5
+ // implementation always returns its results in little endian, swap bytes
+ // appropriately.
+ MD5::MD5Result Result;
+ Hash.final(Result);
+ uint64_t Signature = *reinterpret_cast<support::ulittle64_t *>(Result + 8);
+ NewTU->setTypeSignature(Signature);
+ if (useSplitDwarf())
+ NewTU->setSkeleton(constructSkeletonTU(NewTU));
+
+ NewTU->setType(NewTU->createTypeDIE(CTy));
+
+ NewTU->initSection(
+ useSplitDwarf()
+ ? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
+ : Asm->getObjFileLowering().getDwarfTypesSection(Signature));
+
+ CUMap.begin()->second->addDIETypeSignature(RefDie, *NewTU);
}