From 568be31c9e50a7d7263417841ee1b12334529903 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 27 Mar 2023 22:29:54 -0700 Subject: [PATCH] [dsymutil] Initialize the debug map before loading the main binary Fix a crash when a warning is emitted while loading the symbols from the main binary. The warning helper assumes that the resulting debug map is initialized, but this happened after loading the main binary. Since there's no dependency between the two the initialization can be moved up. rdar://107298776 --- llvm/tools/dsymutil/MachODebugMapParser.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp index 2f391c5..305a055 100644 --- a/llvm/tools/dsymutil/MachODebugMapParser.cpp +++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp @@ -113,6 +113,8 @@ private: StringRef BinaryPath); void Warning(const Twine &Msg, StringRef File = StringRef()) { + assert(Result && + "The debug map must be initialized before calling this function"); WithColor::warning() << "(" << MachOUtils::getArchName( Result->getTriple().getArchName()) @@ -200,10 +202,9 @@ static std::string getArchName(const object::MachOObjectFile &Obj) { std::unique_ptr MachODebugMapParser::parseOneBinary(const MachOObjectFile &MainBinary, StringRef BinaryPath) { + Result = std::make_unique(MainBinary.getArchTriple(), BinaryPath, + MainBinary.getUuid()); loadMainBinarySymbols(MainBinary); - ArrayRef UUID = MainBinary.getUuid(); - Result = - std::make_unique(MainBinary.getArchTriple(), BinaryPath, UUID); MainBinaryStrings = MainBinary.getStringTableData(); for (const SymbolRef &Symbol : MainBinary.symbols()) { const DataRefImpl &DRI = Symbol.getRawDataRefImpl(); -- 2.7.4