1 //===-- DWARFContext.cpp --------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFContext.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/StringSwitch.h"
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/Support/Compression.h"
15 #include "llvm/Support/Dwarf.h"
16 #include "llvm/Support/Format.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/raw_ostream.h"
21 using namespace dwarf;
22 using namespace object;
24 typedef DWARFDebugLine::LineTable DWARFLineTable;
26 DWARFContext::~DWARFContext() {
27 DeleteContainerPointers(CUs);
28 DeleteContainerPointers(TUs);
29 DeleteContainerPointers(DWOCUs);
32 static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef Data,
33 bool LittleEndian, bool GnuStyle) {
34 OS << "\n." << Name << " contents:\n";
35 DataExtractor pubNames(Data, LittleEndian, 0);
37 while (pubNames.isValidOffset(offset)) {
38 OS << "length = " << format("0x%08x", pubNames.getU32(&offset));
39 OS << " version = " << format("0x%04x", pubNames.getU16(&offset));
40 OS << " unit_offset = " << format("0x%08x", pubNames.getU32(&offset));
41 OS << " unit_size = " << format("0x%08x", pubNames.getU32(&offset)) << '\n';
43 OS << "Offset Linkage Kind Name\n";
45 OS << "Offset Name\n";
47 while (offset < Data.size()) {
48 uint32_t dieRef = pubNames.getU32(&offset);
51 OS << format("0x%8.8x ", dieRef);
53 PubIndexEntryDescriptor desc(pubNames.getU8(&offset));
54 OS << format("%-8s", dwarf::GDBIndexEntryLinkageString(desc.Linkage))
55 << ' ' << format("%-8s", dwarf::GDBIndexEntryKindString(desc.Kind))
58 OS << '\"' << pubNames.getCStr(&offset) << "\"\n";
63 void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
64 if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) {
65 OS << ".debug_abbrev contents:\n";
66 getDebugAbbrev()->dump(OS);
69 if (DumpType == DIDT_All || DumpType == DIDT_Info) {
70 OS << "\n.debug_info contents:\n";
71 for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i)
72 getCompileUnitAtIndex(i)->dump(OS);
75 if (DumpType == DIDT_All || DumpType == DIDT_Types) {
76 OS << "\n.debug_types contents:\n";
77 for (unsigned i = 0, e = getNumTypeUnits(); i != e; ++i)
78 getTypeUnitAtIndex(i)->dump(OS);
81 if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
82 OS << "\n.debug_loc contents:\n";
83 getDebugLoc()->dump(OS);
86 if (DumpType == DIDT_All || DumpType == DIDT_Frames) {
87 OS << "\n.debug_frame contents:\n";
88 getDebugFrame()->dump(OS);
92 if (DumpType == DIDT_All || DumpType == DIDT_Aranges) {
93 OS << "\n.debug_aranges contents:\n";
94 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
95 DWARFDebugArangeSet set;
96 while (set.extract(arangesData, &offset))
100 uint8_t savedAddressByteSize = 0;
101 if (DumpType == DIDT_All || DumpType == DIDT_Line) {
102 OS << "\n.debug_line contents:\n";
103 for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) {
104 DWARFCompileUnit *cu = getCompileUnitAtIndex(i);
105 savedAddressByteSize = cu->getAddressByteSize();
106 unsigned stmtOffset =
107 cu->getCompileUnitDIE()->getAttributeValueAsSectionOffset(
108 cu, DW_AT_stmt_list, -1U);
109 if (stmtOffset != -1U) {
110 DataExtractor lineData(getLineSection().Data, isLittleEndian(),
111 savedAddressByteSize);
112 DWARFDebugLine::DumpingState state(OS);
113 DWARFDebugLine::parseStatementTable(lineData, &getLineSection().Relocs, &stmtOffset, state);
118 if (DumpType == DIDT_All || DumpType == DIDT_Str) {
119 OS << "\n.debug_str contents:\n";
120 DataExtractor strData(getStringSection(), isLittleEndian(), 0);
122 uint32_t strOffset = 0;
123 while (const char *s = strData.getCStr(&offset)) {
124 OS << format("0x%8.8x: \"%s\"\n", strOffset, s);
129 if (DumpType == DIDT_All || DumpType == DIDT_Ranges) {
130 OS << "\n.debug_ranges contents:\n";
131 // In fact, different compile units may have different address byte
132 // sizes, but for simplicity we just use the address byte size of the last
133 // compile unit (there is no easy and fast way to associate address range
134 // list and the compile unit it describes).
135 DataExtractor rangesData(getRangeSection(), isLittleEndian(),
136 savedAddressByteSize);
138 DWARFDebugRangeList rangeList;
139 while (rangeList.extract(rangesData, &offset))
143 if (DumpType == DIDT_All || DumpType == DIDT_Pubnames)
144 dumpPubSection(OS, "debug_pubnames", getPubNamesSection(),
145 isLittleEndian(), false);
147 if (DumpType == DIDT_All || DumpType == DIDT_Pubtypes)
148 dumpPubSection(OS, "debug_pubtypes", getPubTypesSection(),
149 isLittleEndian(), false);
151 if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames)
152 dumpPubSection(OS, "debug_gnu_pubnames", getGnuPubNamesSection(),
153 isLittleEndian(), true /* GnuStyle */);
155 if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes)
156 dumpPubSection(OS, "debug_gnu_pubtypes", getGnuPubTypesSection(),
157 isLittleEndian(), true /* GnuStyle */);
159 if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo) {
160 const DWARFDebugAbbrev *D = getDebugAbbrevDWO();
162 OS << "\n.debug_abbrev.dwo contents:\n";
163 getDebugAbbrevDWO()->dump(OS);
167 if (DumpType == DIDT_All || DumpType == DIDT_InfoDwo)
168 if (getNumDWOCompileUnits()) {
169 OS << "\n.debug_info.dwo contents:\n";
170 for (unsigned i = 0, e = getNumDWOCompileUnits(); i != e; ++i)
171 getDWOCompileUnitAtIndex(i)->dump(OS);
174 if (DumpType == DIDT_All || DumpType == DIDT_StrDwo)
175 if (!getStringDWOSection().empty()) {
176 OS << "\n.debug_str.dwo contents:\n";
177 DataExtractor strDWOData(getStringDWOSection(), isLittleEndian(), 0);
179 uint32_t strDWOOffset = 0;
180 while (const char *s = strDWOData.getCStr(&offset)) {
181 OS << format("0x%8.8x: \"%s\"\n", strDWOOffset, s);
182 strDWOOffset = offset;
186 if (DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo)
187 if (!getStringOffsetDWOSection().empty()) {
188 OS << "\n.debug_str_offsets.dwo contents:\n";
189 DataExtractor strOffsetExt(getStringOffsetDWOSection(), isLittleEndian(), 0);
191 uint64_t size = getStringOffsetDWOSection().size();
192 while (offset < size) {
193 OS << format("0x%8.8x: ", offset);
194 OS << format("%8.8x\n", strOffsetExt.getU32(&offset));
199 const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
203 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
205 Abbrev.reset(new DWARFDebugAbbrev());
206 Abbrev->parse(abbrData);
210 const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
212 return AbbrevDWO.get();
214 DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0);
215 AbbrevDWO.reset(new DWARFDebugAbbrev());
216 AbbrevDWO->parse(abbrData);
217 return AbbrevDWO.get();
220 const DWARFDebugLoc *DWARFContext::getDebugLoc() {
224 DataExtractor LocData(getLocSection().Data, isLittleEndian(), 0);
225 Loc.reset(new DWARFDebugLoc(getLocSection().Relocs));
226 // assume all compile units have the same address byte size
227 if (getNumCompileUnits())
228 Loc->parse(LocData, getCompileUnitAtIndex(0)->getAddressByteSize());
232 const DWARFDebugAranges *DWARFContext::getDebugAranges() {
234 return Aranges.get();
236 Aranges.reset(new DWARFDebugAranges());
237 Aranges->generate(this);
238 return Aranges.get();
241 const DWARFDebugFrame *DWARFContext::getDebugFrame() {
243 return DebugFrame.get();
245 // There's a "bug" in the DWARFv3 standard with respect to the target address
246 // size within debug frame sections. While DWARF is supposed to be independent
247 // of its container, FDEs have fields with size being "target address size",
248 // which isn't specified in DWARF in general. It's only specified for CUs, but
249 // .eh_frame can appear without a .debug_info section. Follow the example of
250 // other tools (libdwarf) and extract this from the container (ObjectFile
251 // provides this information). This problem is fixed in DWARFv4
252 // See this dwarf-discuss discussion for more details:
253 // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
254 DataExtractor debugFrameData(getDebugFrameSection(), isLittleEndian(),
256 DebugFrame.reset(new DWARFDebugFrame());
257 DebugFrame->parse(debugFrameData);
258 return DebugFrame.get();
261 const DWARFLineTable *
262 DWARFContext::getLineTableForCompileUnit(DWARFCompileUnit *cu) {
264 Line.reset(new DWARFDebugLine(&getLineSection().Relocs));
266 unsigned stmtOffset =
267 cu->getCompileUnitDIE()->getAttributeValueAsSectionOffset(
268 cu, DW_AT_stmt_list, -1U);
269 if (stmtOffset == -1U)
270 return 0; // No line table for this compile unit.
272 // See if the line table is cached.
273 if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
276 // We have to parse it first.
277 DataExtractor lineData(getLineSection().Data, isLittleEndian(),
278 cu->getAddressByteSize());
279 return Line->getOrParseLineTable(lineData, stmtOffset);
282 void DWARFContext::parseCompileUnits() {
284 const DataExtractor &DIData = DataExtractor(getInfoSection().Data,
285 isLittleEndian(), 0);
286 while (DIData.isValidOffset(offset)) {
287 OwningPtr<DWARFCompileUnit> CU(new DWARFCompileUnit(
288 getDebugAbbrev(), getInfoSection().Data, getAbbrevSection(),
289 getRangeSection(), getStringSection(), StringRef(), getAddrSection(),
290 &getInfoSection().Relocs, isLittleEndian()));
291 if (!CU->extract(DIData, &offset)) {
294 CUs.push_back(CU.take());
295 offset = CUs.back()->getNextUnitOffset();
299 void DWARFContext::parseTypeUnits() {
300 const TypeSectionMap &Sections = getTypesSections();
301 for (TypeSectionMap::const_iterator I = Sections.begin(), E = Sections.end();
304 const DataExtractor &DIData =
305 DataExtractor(I->second.Data, isLittleEndian(), 0);
306 while (DIData.isValidOffset(offset)) {
307 OwningPtr<DWARFTypeUnit> TU(new DWARFTypeUnit(
308 getDebugAbbrev(), I->second.Data, getAbbrevSection(),
309 getRangeSection(), getStringSection(), StringRef(), getAddrSection(),
310 &I->second.Relocs, isLittleEndian()));
311 if (!TU->extract(DIData, &offset))
313 TUs.push_back(TU.take());
314 offset = TUs.back()->getNextUnitOffset();
319 void DWARFContext::parseDWOCompileUnits() {
321 const DataExtractor &DIData =
322 DataExtractor(getInfoDWOSection().Data, isLittleEndian(), 0);
323 while (DIData.isValidOffset(offset)) {
324 OwningPtr<DWARFCompileUnit> DWOCU(new DWARFCompileUnit(
325 getDebugAbbrevDWO(), getInfoDWOSection().Data, getAbbrevDWOSection(),
326 getRangeDWOSection(), getStringDWOSection(),
327 getStringOffsetDWOSection(), getAddrSection(),
328 &getInfoDWOSection().Relocs, isLittleEndian()));
329 if (!DWOCU->extract(DIData, &offset)) {
332 DWOCUs.push_back(DWOCU.take());
333 offset = DWOCUs.back()->getNextUnitOffset();
338 struct OffsetComparator {
339 bool operator()(const DWARFCompileUnit *LHS,
340 const DWARFCompileUnit *RHS) const {
341 return LHS->getOffset() < RHS->getOffset();
343 bool operator()(const DWARFCompileUnit *LHS, uint32_t RHS) const {
344 return LHS->getOffset() < RHS;
346 bool operator()(uint32_t LHS, const DWARFCompileUnit *RHS) const {
347 return LHS < RHS->getOffset();
352 DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
356 DWARFCompileUnit **CU =
357 std::lower_bound(CUs.begin(), CUs.end(), Offset, OffsetComparator());
358 if (CU != CUs.end()) {
364 DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) {
365 // First, get the offset of the compile unit.
366 uint32_t CUOffset = getDebugAranges()->findAddress(Address);
367 // Retrieve the compile unit.
368 return getCompileUnitForOffset(CUOffset);
371 static bool getFileNameForCompileUnit(DWARFCompileUnit *CU,
372 const DWARFLineTable *LineTable,
374 bool NeedsAbsoluteFilePath,
375 std::string &FileName) {
378 !LineTable->getFileNameByIndex(FileIndex, NeedsAbsoluteFilePath,
381 if (NeedsAbsoluteFilePath && sys::path::is_relative(FileName)) {
382 // We may still need to append compilation directory of compile unit.
383 SmallString<16> AbsolutePath;
384 if (const char *CompilationDir = CU->getCompilationDir()) {
385 sys::path::append(AbsolutePath, CompilationDir);
387 sys::path::append(AbsolutePath, FileName);
388 FileName = AbsolutePath.str();
393 static bool getFileLineInfoForCompileUnit(DWARFCompileUnit *CU,
394 const DWARFLineTable *LineTable,
396 bool NeedsAbsoluteFilePath,
397 std::string &FileName,
398 uint32_t &Line, uint32_t &Column) {
399 if (CU == 0 || LineTable == 0)
401 // Get the index of row we're looking for in the line table.
402 uint32_t RowIndex = LineTable->lookupAddress(Address);
405 // Take file number and line/column from the row.
406 const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
407 if (!getFileNameForCompileUnit(CU, LineTable, Row.File,
408 NeedsAbsoluteFilePath, FileName))
415 DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
416 DILineInfoSpecifier Specifier) {
417 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
420 std::string FileName = "<invalid>";
421 std::string FunctionName = "<invalid>";
424 if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
425 // The address may correspond to instruction in some inlined function,
426 // so we have to build the chain of inlined functions and take the
427 // name of the topmost function in it.
428 const DWARFDebugInfoEntryInlinedChain &InlinedChain =
429 CU->getInlinedChainForAddress(Address);
430 if (InlinedChain.DIEs.size() > 0) {
431 const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
432 if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U))
436 if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
437 const DWARFLineTable *LineTable = getLineTableForCompileUnit(CU);
438 const bool NeedsAbsoluteFilePath =
439 Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
440 getFileLineInfoForCompileUnit(CU, LineTable, Address,
441 NeedsAbsoluteFilePath,
442 FileName, Line, Column);
444 return DILineInfo(StringRef(FileName), StringRef(FunctionName),
448 DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
450 DILineInfoSpecifier Specifier) {
451 DILineInfoTable Lines;
452 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
456 std::string FunctionName = "<invalid>";
457 if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
458 // The address may correspond to instruction in some inlined function,
459 // so we have to build the chain of inlined functions and take the
460 // name of the topmost function in it.
461 const DWARFDebugInfoEntryInlinedChain &InlinedChain =
462 CU->getInlinedChainForAddress(Address);
463 if (InlinedChain.DIEs.size() > 0) {
464 const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
465 if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U))
470 // If the Specifier says we don't need FileLineInfo, just
471 // return the top-most function at the starting address.
472 if (!Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
474 std::make_pair(Address, DILineInfo("<invalid>", FunctionName, 0, 0)));
478 const DWARFLineTable *LineTable = getLineTableForCompileUnit(CU);
479 const bool NeedsAbsoluteFilePath =
480 Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
482 // Get the index of row we're looking for in the line table.
483 std::vector<uint32_t> RowVector;
484 if (!LineTable->lookupAddressRange(Address, Size, RowVector))
487 uint32_t NumRows = RowVector.size();
488 for (uint32_t i = 0; i < NumRows; ++i) {
489 uint32_t RowIndex = RowVector[i];
490 // Take file number and line/column from the row.
491 const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
492 std::string FileName = "<invalid>";
493 getFileNameForCompileUnit(CU, LineTable, Row.File,
494 NeedsAbsoluteFilePath, FileName);
495 Lines.push_back(std::make_pair(
496 Row.Address, DILineInfo(FileName, FunctionName, Row.Line, Row.Column)));
502 DIInliningInfo DWARFContext::getInliningInfoForAddress(uint64_t Address,
503 DILineInfoSpecifier Specifier) {
504 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
506 return DIInliningInfo();
508 const DWARFDebugInfoEntryInlinedChain &InlinedChain =
509 CU->getInlinedChainForAddress(Address);
510 if (InlinedChain.DIEs.size() == 0)
511 return DIInliningInfo();
513 DIInliningInfo InliningInfo;
514 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0;
515 const DWARFLineTable *LineTable = 0;
516 for (uint32_t i = 0, n = InlinedChain.DIEs.size(); i != n; i++) {
517 const DWARFDebugInfoEntryMinimal &FunctionDIE = InlinedChain.DIEs[i];
518 std::string FileName = "<invalid>";
519 std::string FunctionName = "<invalid>";
522 // Get function name if necessary.
523 if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
524 if (const char *Name = FunctionDIE.getSubroutineName(InlinedChain.U))
527 if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
528 const bool NeedsAbsoluteFilePath =
529 Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
531 // For the topmost frame, initialize the line table of this
532 // compile unit and fetch file/line info from it.
533 LineTable = getLineTableForCompileUnit(CU);
534 // For the topmost routine, get file/line info from line table.
535 getFileLineInfoForCompileUnit(CU, LineTable, Address,
536 NeedsAbsoluteFilePath,
537 FileName, Line, Column);
539 // Otherwise, use call file, call line and call column from
540 // previous DIE in inlined chain.
541 getFileNameForCompileUnit(CU, LineTable, CallFile,
542 NeedsAbsoluteFilePath, FileName);
546 // Get call file/line/column of a current DIE.
548 FunctionDIE.getCallerFrame(InlinedChain.U, CallFile, CallLine,
552 DILineInfo Frame(StringRef(FileName), StringRef(FunctionName),
554 InliningInfo.addFrame(Frame);
559 static bool consumeCompressedDebugSectionHeader(StringRef &data,
560 uint64_t &OriginalSize) {
561 // Consume "ZLIB" prefix.
562 if (!data.startswith("ZLIB"))
564 data = data.substr(4);
565 // Consume uncompressed section size (big-endian 8 bytes).
566 DataExtractor extractor(data, false, 8);
568 OriginalSize = extractor.getU64(&Offset);
571 data = data.substr(Offset);
575 DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
576 IsLittleEndian(Obj->isLittleEndian()),
577 AddressSize(Obj->getBytesInAddress()) {
579 for (object::section_iterator i = Obj->begin_sections(),
580 e = Obj->end_sections();
581 i != e; i.increment(ec)) {
585 i->getContents(data);
587 name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes.
589 // Check if debug info section is compressed with zlib.
590 if (name.startswith("zdebug_")) {
591 uint64_t OriginalSize;
592 if (!zlib::isAvailable() ||
593 !consumeCompressedDebugSectionHeader(data, OriginalSize))
595 OwningPtr<MemoryBuffer> UncompressedSection;
596 if (zlib::uncompress(data, UncompressedSection, OriginalSize) !=
599 // Make data point to uncompressed section contents and save its contents.
600 name = name.substr(1);
601 data = UncompressedSection->getBuffer();
602 UncompressedSections.push_back(UncompressedSection.take());
606 StringSwitch<StringRef *>(name)
607 .Case("debug_info", &InfoSection.Data)
608 .Case("debug_abbrev", &AbbrevSection)
609 .Case("debug_loc", &LocSection.Data)
610 .Case("debug_line", &LineSection.Data)
611 .Case("debug_aranges", &ARangeSection)
612 .Case("debug_frame", &DebugFrameSection)
613 .Case("debug_str", &StringSection)
614 .Case("debug_ranges", &RangeSection)
615 .Case("debug_pubnames", &PubNamesSection)
616 .Case("debug_pubtypes", &PubTypesSection)
617 .Case("debug_gnu_pubnames", &GnuPubNamesSection)
618 .Case("debug_gnu_pubtypes", &GnuPubTypesSection)
619 .Case("debug_info.dwo", &InfoDWOSection.Data)
620 .Case("debug_abbrev.dwo", &AbbrevDWOSection)
621 .Case("debug_str.dwo", &StringDWOSection)
622 .Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
623 .Case("debug_addr", &AddrSection)
624 // Any more debug info sections go here.
628 if (name == "debug_ranges") {
629 // FIXME: Use the other dwo range section when we emit it.
630 RangeDWOSection = data;
632 } else if (name == "debug_types") {
633 // Find debug_types data by section rather than name as there are
634 // multiple, comdat grouped, debug_types sections.
635 TypesSections[*i].Data = data;
638 section_iterator RelocatedSection = i->getRelocatedSection();
639 if (RelocatedSection == Obj->end_sections())
642 StringRef RelSecName;
643 RelocatedSection->getName(RelSecName);
644 RelSecName = RelSecName.substr(
645 RelSecName.find_first_not_of("._")); // Skip . and _ prefixes.
647 // TODO: Add support for relocations in other sections as needed.
648 // Record relocations for the debug_info and debug_line sections.
649 RelocAddrMap *Map = StringSwitch<RelocAddrMap*>(RelSecName)
650 .Case("debug_info", &InfoSection.Relocs)
651 .Case("debug_loc", &LocSection.Relocs)
652 .Case("debug_info.dwo", &InfoDWOSection.Relocs)
653 .Case("debug_line", &LineSection.Relocs)
656 if (RelSecName != "debug_types")
658 // Find debug_types relocs by section rather than name as there are
659 // multiple, comdat grouped, debug_types sections.
660 Map = &TypesSections[*RelocatedSection].Relocs;
663 if (i->begin_relocations() != i->end_relocations()) {
664 uint64_t SectionSize;
665 RelocatedSection->getSize(SectionSize);
666 for (object::relocation_iterator reloc_i = i->begin_relocations(),
667 reloc_e = i->end_relocations();
668 reloc_i != reloc_e; reloc_i.increment(ec)) {
670 reloc_i->getOffset(Address);
672 reloc_i->getType(Type);
673 uint64_t SymAddr = 0;
674 // ELF relocations may need the symbol address
676 object::symbol_iterator Sym = reloc_i->getSymbol();
677 Sym->getAddress(SymAddr);
680 object::RelocVisitor V(Obj->getFileFormatName());
681 // The section address is always 0 for debug sections.
682 object::RelocToApply R(V.visit(Type, *reloc_i, 0, SymAddr));
684 SmallString<32> Name;
685 error_code ec(reloc_i->getTypeName(Name));
687 errs() << "Aaaaaa! Nameless relocation! Aaaaaa!\n";
689 errs() << "error: failed to compute relocation: "
694 if (Address + R.Width > SectionSize) {
695 errs() << "error: " << R.Width << "-byte relocation starting "
696 << Address << " bytes into section " << name << " which is "
697 << SectionSize << " bytes long.\n";
701 errs() << "error: can't handle a relocation of more than 8 bytes at "
705 DEBUG(dbgs() << "Writing " << format("%p", R.Value)
706 << " at " << format("%p", Address)
707 << " with width " << format("%d", R.Width)
709 Map->insert(std::make_pair(Address, std::make_pair(R.Width, R.Value)));
715 DWARFContextInMemory::~DWARFContextInMemory() {
716 DeleteContainerPointers(UncompressedSections);
719 void DWARFContextInMemory::anchor() { }