diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -387,9 +387,12 @@ function_ref getWarningHandler() { return WarningHandler; } + enum class ContextType { DWO, MONOLITHIC }; + static std::unique_ptr - create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr, - std::string DWPName = "", + create(const object::ObjectFile &Obj, + ContextType Type = ContextType::MONOLITHIC, + const LoadedObjectInfo *L = nullptr, std::string DWPName = "", std::function RecoverableErrorHandler = WithColor::defaultErrorHandler, std::function WarningHandler = diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1411,7 +1411,7 @@ auto S = std::make_shared(); S->File = std::move(Obj.get()); - S->Context = DWARFContext::create(*S->File.getBinary()); + S->Context = DWARFContext::create(*S->File.getBinary(), ContextType::DWO); *Entry = S; auto *Ctxt = S->Context.get(); return std::shared_ptr(std::move(S), Ctxt); @@ -1652,7 +1652,9 @@ } } DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L, - function_ref HandleError, function_ref HandleWarning ) + function_ref HandleError, + function_ref HandleWarning, + DWARFContext::ContextType Type) : IsLittleEndian(Obj.isLittleEndian()), AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()), Obj(&Obj) { @@ -1735,7 +1737,13 @@ S.Data = Data; } - if (RelocatedSection == Obj.section_end()) + if (RelocatedSection != Obj.section_end() && + Type == DWARFContext::ContextType::DWO) + HandleWarning(createError( + "Creating DWO Context with relocation section for " + Name)); + + if (RelocatedSection == Obj.section_end() || + (Type == DWARFContext::ContextType::DWO)) continue; StringRef RelSecName; @@ -1772,18 +1780,10 @@ if (RelSecName == "debug_info") Map = &static_cast(InfoSections[*RelocatedSection]) .Relocs; - else if (RelSecName == "debug_info.dwo") - Map = &static_cast( - InfoDWOSections[*RelocatedSection]) - .Relocs; else if (RelSecName == "debug_types") Map = &static_cast(TypesSections[*RelocatedSection]) .Relocs; - else if (RelSecName == "debug_types.dwo") - Map = &static_cast( - TypesDWOSections[*RelocatedSection]) - .Relocs; else continue; } @@ -1966,12 +1966,12 @@ } // namespace std::unique_ptr -DWARFContext::create(const object::ObjectFile &Obj, const LoadedObjectInfo *L, - std::string DWPName, +DWARFContext::create(const object::ObjectFile &Obj, ContextType Type, + const LoadedObjectInfo *L, std::string DWPName, std::function RecoverableErrorHandler, std::function WarningHandler) { - auto DObj = - std::make_unique(Obj, L, RecoverableErrorHandler, WarningHandler); + auto DObj = std::make_unique( + Obj, L, RecoverableErrorHandler, WarningHandler, Type); return std::make_unique(std::move(DObj), std::move(DWPName), RecoverableErrorHandler, WarningHandler); diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -600,7 +600,9 @@ } } if (!Context) - Context = DWARFContext::create(*Objects.second, nullptr, Opts.DWPName); + Context = DWARFContext::create(*Objects.second, + DWARFContext::ContextType::MONOLITHIC, + nullptr, Opts.DWPName); return createModuleInfo(Objects.first, std::move(Context), ModuleName); } diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -537,7 +537,8 @@ if (auto *Obj = dyn_cast(BinOrErr->get())) { if (filterArch(*Obj)) { std::unique_ptr DICtx = - DWARFContext::create(*Obj, nullptr, "", RecoverableErrorHandler); + DWARFContext::create(*Obj, DWARFContext::ContextType::MONOLITHIC, + nullptr, "", RecoverableErrorHandler); if (!HandleObj(*Obj, *DICtx, Filename, OS)) Result = false; } @@ -549,7 +550,8 @@ auto &Obj = **MachOOrErr; if (filterArch(Obj)) { std::unique_ptr DICtx = - DWARFContext::create(Obj, nullptr, "", RecoverableErrorHandler); + DWARFContext::create(Obj, DWARFContext::ContextType::MONOLITHIC, + nullptr, "", RecoverableErrorHandler); if (!HandleObj(Obj, *DICtx, ObjName, OS)) Result = false; } diff --git a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h --- a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h +++ b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h @@ -185,7 +185,8 @@ reportError(DataOrErr.takeError(), ObjF.getFileName()); // Construct DWARFDataExtractor to handle relocations ("PC Begin" fields). - std::unique_ptr DICtx = DWARFContext::create(ObjF, nullptr); + std::unique_ptr DICtx = DWARFContext::create( + ObjF, DWARFContext::ContextType::MONOLITHIC, nullptr); DWARFDataExtractor DE(DICtx->getDWARFObj(), DICtx->getDWARFObj().getEHFrameSection(), ELFT::TargetEndianness == support::endianness::little, diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp --- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -413,8 +413,8 @@ } } - std::unique_ptr Context = - DWARFContext::create(*SymbolObj, LoadedObjInfo.get()); + std::unique_ptr Context = DWARFContext::create( + *SymbolObj, DWARFContext::ContextType::MONOLITHIC, LoadedObjInfo.get()); std::vector> SymAddr = object::computeSymbolSizes(*SymbolObj); diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -2520,7 +2520,7 @@ // DWARFContext parses whole file and finds the two errors we expect. int Errors = 0; std::unique_ptr Ctx1 = - DWARFContext::create(**Obj, nullptr, "", [&](Error E) { + DWARFContext::create(**Obj, DWARFContext::ContextType::MONOLITHIC, nullptr, "", [&](Error E) { ++Errors; consumeError(std::move(E)); });