Bug 1362277 - Add dyld to the SharedLibraryInformation list. r?ted draft
authorMarkus Stange <mstange@themasta.com>
Thu, 04 May 2017 23:36:17 -0400
changeset 572994 7d09db07da62b3040cacf9e07da6eba4240da3bf
parent 572993 ac5539be434da43054b840f4123f512455c6232c
child 627186 7c88e3b0bbda9063832b978dacaeccd6ee7b74f1
push id57255
push userbmo:mstange@themasta.com
push dateFri, 05 May 2017 03:37:30 +0000
reviewersted
bugs1362277
milestone55.0a1
Bug 1362277 - Add dyld to the SharedLibraryInformation list. r?ted MozReview-Commit-ID: 71MWTzFZBOe
tools/profiler/core/shared-libraries-macos.cc
--- a/tools/profiler/core/shared-libraries-macos.cc
+++ b/tools/profiler/core/shared-libraries-macos.cc
@@ -30,18 +30,66 @@ typedef segment_command mach_segment_com
 #else
 typedef mach_header_64 platform_mach_header;
 typedef segment_command_64 mach_segment_command_type;
 #define MACHO_MAGIC_NUMBER MH_MAGIC_64
 #define CMD_SEGMENT LC_SEGMENT_64
 #define seg_size uint64_t
 #endif
 
+// The definition of dyld_all_image_infos from the 10.12 dyld_images.h header.
+struct dyld_all_image_infos_v15 {
+  uint32_t                        version;        /* 1 in Mac OS X 10.4 and 10.5 */
+  uint32_t                        infoArrayCount;
+  const struct dyld_image_info*   infoArray;
+  dyld_image_notifier             notification;
+  bool                            processDetachedFromSharedRegion;
+  /* the following fields are only in version 2 (Mac OS X 10.6, iPhoneOS 2.0) and later */
+  bool                            libSystemInitialized;
+  const struct mach_header*       dyldImageLoadAddress;
+  /* the following field is only in version 3 (Mac OS X 10.6, iPhoneOS 3.0) and later */
+  void*                           jitInfo;
+  /* the following fields are only in version 5 (Mac OS X 10.6, iPhoneOS 3.0) and later */
+  const char*                     dyldVersion;
+  const char*                     errorMessage;
+  uintptr_t                       terminationFlags;
+  /* the following field is only in version 6 (Mac OS X 10.6, iPhoneOS 3.1) and later */
+  void*                           coreSymbolicationShmPage;
+  /* the following field is only in version 7 (Mac OS X 10.6, iPhoneOS 3.1) and later */
+  uintptr_t                       systemOrderFlag;
+  /* the following field is only in version 8 (Mac OS X 10.7, iPhoneOS 3.1) and later */
+  uintptr_t                       uuidArrayCount;
+  const struct dyld_uuid_info*    uuidArray;        /* only images not in dyld shared cache */
+  /* the following field is only in version 9 (Mac OS X 10.7, iOS 4.0) and later */
+  struct dyld_all_image_infos*    dyldAllImageInfosAddress;
+  /* the following field is only in version 10 (Mac OS X 10.7, iOS 4.2) and later */
+  uintptr_t                       initialImageCount;
+  /* the following field is only in version 11 (Mac OS X 10.7, iOS 4.2) and later */
+  uintptr_t                       errorKind;
+  const char*                     errorClientOfDylibPath;
+  const char*                     errorTargetDylibPath;
+  const char*                     errorSymbol;
+  /* the following field is only in version 12 (Mac OS X 10.7, iOS 4.3) and later */
+  uintptr_t                       sharedCacheSlide;
+  /* the following field is only in version 13 (Mac OS X 10.9, iOS 7.0) and later */
+  uint8_t                         sharedCacheUUID[16];
+  /* the following field is only in version 15 (macOS 10.12, iOS 10.0) and later */
+  uintptr_t                       sharedCacheBaseAddress;
+  uint64_t                        infoArrayChangeTimestamp;
+  const char*                     dyldPath;
+  mach_port_t                     notifyPorts[DYLD_MAX_PROCESS_INFO_NOTIFY_COUNT];
+#if __LP64__
+  uintptr_t                       reserved[13-(DYLD_MAX_PROCESS_INFO_NOTIFY_COUNT/2)];
+#else
+  uintptr_t                       reserved[12-DYLD_MAX_PROCESS_INFO_NOTIFY_COUNT];
+#endif
+};
+
 static
-void addSharedLibrary(const platform_mach_header* header, char *path, SharedLibraryInfo &info) {
+void addSharedLibrary(const platform_mach_header* header, const char *path, SharedLibraryInfo &info) {
   const struct load_command *cmd =
     reinterpret_cast<const struct load_command *>(header + 1);
 
   seg_size size = 0;
   unsigned long long start = reinterpret_cast<unsigned long long>(header);
   // Find the cmd segment in the macho image. It will contain the offset we care about.
   const uint8_t *uuid_bytes = nullptr;
   for (unsigned int i = 0;
@@ -117,14 +165,25 @@ SharedLibraryInfo SharedLibraryInfo::Get
     if (info->imageLoadAddress->magic != MACHO_MAGIC_NUMBER) {
       continue;
     }
 
     const platform_mach_header* header =
       reinterpret_cast<const platform_mach_header*>(info->imageLoadAddress);
 
     // Add the entry for this image.
-    addSharedLibrary(header, (char*)info->imageFilePath, sharedLibraryInfo);
+    addSharedLibrary(header, info->imageFilePath, sharedLibraryInfo);
+  }
 
+  if (aii->version >= 15) {
+    // Add the entry for dyld itself.
+    // Prior to version 15 (shipped in 10.12), it was really tricky to find
+    // out the path to dyld, so we're not going to bother on those versions
+    // of macOS. Thankfully, version 15 added the dyldPath property.
+    dyld_all_image_infos_v15* aiiv15 = (dyld_all_image_infos_v15*)aii;
+    const platform_mach_header* header =
+      reinterpret_cast<const platform_mach_header*>(aiiv15->dyldImageLoadAddress);
+    addSharedLibrary(header, aiiv15->dyldPath, sharedLibraryInfo);
   }
+
   return sharedLibraryInfo;
 }