Fixup for r167558: Store raw pointer (instead of reference) to RelocMap in DIContext. This is needed to prevent crashes because of dangling reference if the clients don't provide RelocMap to DIContext constructor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167728 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2012-11-12 14:25:36 +00:00
parent 30d8f0e977
commit 4c0ae9066f
5 changed files with 30 additions and 22 deletions

View File

@ -109,7 +109,7 @@ public:
StringRef lineSection = StringRef(), StringRef lineSection = StringRef(),
StringRef stringSection = StringRef(), StringRef stringSection = StringRef(),
StringRef rangeSection = StringRef(), StringRef rangeSection = StringRef(),
const RelocAddrMap &Map = RelocAddrMap()); const RelocAddrMap *Map = 0);
virtual void dump(raw_ostream &OS) = 0; virtual void dump(raw_ostream &OS) = 0;

View File

@ -20,7 +20,7 @@ DIContext *DIContext::getDWARFContext(bool isLittleEndian,
StringRef lineSection, StringRef lineSection,
StringRef stringSection, StringRef stringSection,
StringRef rangeSection, StringRef rangeSection,
const RelocAddrMap &Map) { const RelocAddrMap *Map) {
return new DWARFContextInMemory(isLittleEndian, infoSection, abbrevSection, return new DWARFContextInMemory(isLittleEndian, infoSection, abbrevSection,
aRangeSection, lineSection, stringSection, aRangeSection, lineSection, stringSection,
rangeSection, Map); rangeSection, Map);

View File

@ -26,7 +26,7 @@ namespace llvm {
/// methods that a concrete implementation provides. /// methods that a concrete implementation provides.
class DWARFContext : public DIContext { class DWARFContext : public DIContext {
bool IsLittleEndian; bool IsLittleEndian;
const RelocAddrMap &RelocMap; const RelocAddrMap *RelocMap;
SmallVector<DWARFCompileUnit, 1> CUs; SmallVector<DWARFCompileUnit, 1> CUs;
OwningPtr<DWARFDebugAbbrev> Abbrev; OwningPtr<DWARFDebugAbbrev> Abbrev;
@ -39,7 +39,7 @@ class DWARFContext : public DIContext {
/// Read compile units from the debug_info section and store them in CUs. /// Read compile units from the debug_info section and store them in CUs.
void parseCompileUnits(); void parseCompileUnits();
protected: protected:
DWARFContext(bool isLittleEndian, const RelocAddrMap &Map) : DWARFContext(bool isLittleEndian, const RelocAddrMap *Map) :
IsLittleEndian(isLittleEndian), RelocMap(Map) {} IsLittleEndian(isLittleEndian), RelocMap(Map) {}
public: public:
virtual void dump(raw_ostream &OS); virtual void dump(raw_ostream &OS);
@ -73,7 +73,7 @@ public:
DILineInfoSpecifier Specifier = DILineInfoSpecifier()); DILineInfoSpecifier Specifier = DILineInfoSpecifier());
bool isLittleEndian() const { return IsLittleEndian; } bool isLittleEndian() const { return IsLittleEndian; }
const RelocAddrMap &relocMap() const { return RelocMap; } const RelocAddrMap *relocMap() const { return RelocMap; }
virtual StringRef getInfoSection() = 0; virtual StringRef getInfoSection() = 0;
virtual StringRef getAbbrevSection() = 0; virtual StringRef getAbbrevSection() = 0;
@ -113,7 +113,7 @@ public:
StringRef lineSection, StringRef lineSection,
StringRef stringSection, StringRef stringSection,
StringRef rangeSection, StringRef rangeSection,
const RelocAddrMap &Map = RelocAddrMap()) const RelocAddrMap *Map = 0)
: DWARFContext(isLittleEndian, Map), : DWARFContext(isLittleEndian, Map),
InfoSection(infoSection), InfoSection(infoSection),
AbbrevSection(abbrevSection), AbbrevSection(abbrevSection),

View File

@ -100,16 +100,20 @@ DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr,
switch (Form) { switch (Form) {
case DW_FORM_addr: case DW_FORM_addr:
case DW_FORM_ref_addr: { case DW_FORM_ref_addr: {
RelocAddrMap::const_iterator AI bool InRelocMap = false;
= cu->getContext().relocMap().find(*offset_ptr); if (const RelocAddrMap *RelocMap = cu->getContext().relocMap()) {
if (AI != cu->getContext().relocMap().end()) { RelocAddrMap::const_iterator AI = RelocMap->find(*offset_ptr);
const std::pair<uint8_t, int64_t> &R = AI->second; if (AI != RelocMap->end()) {
Value.uval = R.second; const std::pair<uint8_t, int64_t> &R = AI->second;
*offset_ptr += R.first; Value.uval = R.second;
} else *offset_ptr += R.first;
InRelocMap = true;
}
}
if (!InRelocMap)
Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize()); Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize());
}
break; break;
}
case DW_FORM_exprloc: case DW_FORM_exprloc:
case DW_FORM_block: case DW_FORM_block:
Value.uval = data.getULEB128(offset_ptr); Value.uval = data.getULEB128(offset_ptr);
@ -148,13 +152,17 @@ DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr,
Value.sval = data.getSLEB128(offset_ptr); Value.sval = data.getSLEB128(offset_ptr);
break; break;
case DW_FORM_strp: { case DW_FORM_strp: {
RelocAddrMap::const_iterator AI bool InRelocMap = false;
= cu->getContext().relocMap().find(*offset_ptr); if (const RelocAddrMap *RelocMap = cu->getContext().relocMap()) {
if (AI != cu->getContext().relocMap().end()) { RelocAddrMap::const_iterator AI = RelocMap->find(*offset_ptr);
const std::pair<uint8_t, int64_t> &R = AI->second; if (AI != RelocMap->end()) {
Value.uval = R.second; const std::pair<uint8_t, int64_t> &R = AI->second;
*offset_ptr += R.first; Value.uval = R.second;
} else *offset_ptr += R.first;
InRelocMap = true;
}
}
if (!InRelocMap)
Value.uval = data.getU32(offset_ptr); Value.uval = data.getU32(offset_ptr);
break; break;
} }

View File

@ -162,7 +162,7 @@ static void DumpInput(const StringRef &Filename) {
DebugLineSection, DebugLineSection,
DebugStringSection, DebugStringSection,
DebugRangesSection, DebugRangesSection,
RelocMap)); &RelocMap));
if (Address == -1ULL) { if (Address == -1ULL) {
outs() << Filename outs() << Filename
<< ":\tfile format " << Obj->getFileFormatName() << "\n\n"; << ":\tfile format " << Obj->getFileFormatName() << "\n\n";