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 @@ -388,7 +388,7 @@ function_ref getWarningHandler() { return WarningHandler; } static std::unique_ptr - create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr, + create(const object::ObjectFile &Obj, bool IsDWOContext = false, const LoadedObjectInfo *L = nullptr, std::string DWPName = "", std::function RecoverableErrorHandler = WithColor::defaultErrorHandler, 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(), true); *Entry = S; auto *Ctxt = S->Context.get(); return std::shared_ptr(std::move(S), Ctxt); @@ -1652,7 +1652,7 @@ } } DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L, - function_ref HandleError, function_ref HandleWarning ) + function_ref HandleError, function_ref HandleWarning, bool IsDWOContext) : IsLittleEndian(Obj.isLittleEndian()), AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()), Obj(&Obj) { @@ -1735,7 +1735,8 @@ S.Data = Data; } - if (RelocatedSection == Obj.section_end()) + if (RelocatedSection == Obj.section_end() || + (IsDWOContext && !Name.contains(".dwo"))) continue; StringRef RelSecName; @@ -1966,12 +1967,12 @@ } // namespace std::unique_ptr -DWARFContext::create(const object::ObjectFile &Obj, const LoadedObjectInfo *L, +DWARFContext::create(const object::ObjectFile &Obj, bool IsDWOContext, const LoadedObjectInfo *L, std::string DWPName, std::function RecoverableErrorHandler, std::function WarningHandler) { auto DObj = - std::make_unique(Obj, L, RecoverableErrorHandler, WarningHandler); + std::make_unique(Obj, L, RecoverableErrorHandler, WarningHandler, IsDWOContext); 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,7 @@ } } if (!Context) - Context = DWARFContext::create(*Objects.second, nullptr, Opts.DWPName); + Context = DWARFContext::create(*Objects.second, false, 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,7 @@ if (auto *Obj = dyn_cast(BinOrErr->get())) { if (filterArch(*Obj)) { std::unique_ptr DICtx = - DWARFContext::create(*Obj, nullptr, "", RecoverableErrorHandler); + DWARFContext::create(*Obj, false, nullptr, "", RecoverableErrorHandler); if (!HandleObj(*Obj, *DICtx, Filename, OS)) Result = false; } @@ -549,7 +549,7 @@ auto &Obj = **MachOOrErr; if (filterArch(Obj)) { std::unique_ptr DICtx = - DWARFContext::create(Obj, nullptr, "", RecoverableErrorHandler); + DWARFContext::create(Obj, false, 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, false, nullptr); DWARFDataExtractor DE(DICtx->getDWARFObj(), DICtx->getDWARFObj().getEHFrameSection(), ELFT::TargetEndianness == support::endianness::little,