[dsymutil] Initialize the debug map before loading the main binary
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 28 Mar 2023 05:29:54 +0000 (22:29 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 28 Mar 2023 05:34:42 +0000 (22:34 -0700)
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

index 2f391c5..305a055 100644 (file)
@@ -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<DebugMap>
 MachODebugMapParser::parseOneBinary(const MachOObjectFile &MainBinary,
                                     StringRef BinaryPath) {
+  Result = std::make_unique<DebugMap>(MainBinary.getArchTriple(), BinaryPath,
+                                      MainBinary.getUuid());
   loadMainBinarySymbols(MainBinary);
-  ArrayRef<uint8_t> UUID = MainBinary.getUuid();
-  Result =
-      std::make_unique<DebugMap>(MainBinary.getArchTriple(), BinaryPath, UUID);
   MainBinaryStrings = MainBinary.getStringTableData();
   for (const SymbolRef &Symbol : MainBinary.symbols()) {
     const DataRefImpl &DRI = Symbol.getRawDataRefImpl();