Need to ensure the symbol table and symbol string table for the dylinker (#79728)
authorMike McLaughlin <mikem@microsoft.com>
Fri, 16 Dec 2022 05:41:28 +0000 (21:41 -0800)
committerGitHub <noreply@github.com>
Fri, 16 Dec 2022 05:41:28 +0000 (21:41 -0800)
module is part of the core dump for the dump readers. They still need
to look up the "dyld_all_image_infos" symbol.

src/coreclr/debug/dbgutil/machoreader.cpp
src/coreclr/debug/dbgutil/machoreader.h

index 399b186..07528e1 100644 (file)
@@ -372,7 +372,7 @@ MachOReader::EnumerateModules(mach_vm_address_t dyldInfoAddress)
     Trace("MOD: infoArray %p infoArrayCount %d\n", dyldInfo.infoArray, dyldInfo.infoArrayCount);
 
     // Create the dyld module info
-    if (!CreateModule(dyldInfo.dyldImageLoadAddress, dyldInfo.dyldPath))
+    if (!TryRegisterModule(dyldInfo.dyldImageLoadAddress, dyldInfo.dyldPath, true))
     {
         Trace("ERROR: Failed to read dyld header at %p\n", dyldInfo.dyldImageLoadAddress);
         return false;
@@ -393,13 +393,13 @@ MachOReader::EnumerateModules(mach_vm_address_t dyldInfoAddress)
     for (int i = 0; i < dyldInfo.infoArrayCount; i++)
     {
         // Ignore any errors and continue to next module
-        CreateModule(imageInfos[i].imageLoadAddress, imageInfos[i].imageFilePath);
+        TryRegisterModule(imageInfos[i].imageLoadAddress, imageInfos[i].imageFilePath, false);
     }
     return true;
 }
 
 bool
-MachOReader::CreateModule(const struct mach_header*    imageAddress, const char* imageFilePathAddress)
+MachOReader::TryRegisterModule(const struct mach_header* imageAddress, const char* imageFilePathAddress, bool dylinker)
 {
     std::string imagePath;
     if (!ReadString(imageFilePathAddress, imagePath))
@@ -413,6 +413,18 @@ MachOReader::CreateModule(const struct mach_header*        imageAddress, const char* im
     }
     Trace("MOD: %016llx %08x %s\n", imageAddress, module.Header().flags, imagePath.c_str());
     VisitModule(module);
+    if (dylinker)
+    {
+        // Make sure the memory for the symbol and string tables are in the core dump for our
+        // dump readers which still use this symbol to enumerate modules.
+        uint64_t dyldInfoAddress = 0;
+        if (!module.TryLookupSymbol("dyld_all_image_infos", &dyldInfoAddress))
+        {
+            Trace("ERROR: Can not find the _dyld_all_image_infos symbol\n");
+            return false;
+        }
+        Trace("MOD: dyldInfoAddress %016llx\n", dyldInfoAddress);
+    }
     return true;
 }
 
index 8650f26..19630e6 100644 (file)
@@ -55,7 +55,7 @@ public:
     bool EnumerateModules(mach_vm_address_t dyldInfoAddress);
 
 private:
-    bool CreateModule(const struct mach_header*        imageAddress, const char* imageFilePathAddress);
+    bool TryRegisterModule(const struct mach_header* imageAddress, const char* imageFilePathAddress, bool dylinker);
     bool ReadString(const char* address, std::string& str);
     virtual void VisitModule(MachOModule& module) { };
     virtual void VisitSegment(MachOModule& module, const segment_command_64& segment) { };