- // HACK until closured for dlopen can run against live cache file
- int fd = my_open(sSharedCacheLoadInfo.path, O_RDONLY, 0);
- if ( fd != -1 ) {
- dyld_cache_header fileHeader;
- if ( pread(fd, &fileHeader, sizeof(fileHeader), 0) == sizeof(fileHeader) ) {
- uuid_t cacheUUID;
- sSharedCacheLoadInfo.loadAddress->getUUID(cacheUUID);
- if ( memcmp(fileHeader.uuid, cacheUUID, sizeof(uuid_t)) != 0 ) {
- if ( gLinkContext.verboseWarnings )
- dyld::log("dyld: closure %p not used because current cache on disk is not they one being used\n", mainClosureData);
- ::close(fd);
- return false;
- }
- }
- ::close(fd);
+ // If the in-memory cache doesn't have the same UUID xattr as the on-disk cache then we must
+ // have built a new cache but not rebooted. In this case, don't use dyld3.
+ const char* sharedCachePath = getStandardSharedCacheFilePath();
+ uuid_t inMemoryUUID;
+ uuid_t onDiskUUID;
+ sharedCacheUUID(inMemoryUUID);
+ if (getxattr(sharedCachePath, "cacheUUID", (void*)&onDiskUUID, sizeof(uuid_t), 0, 0) != sizeof(uuid_t)) {
+ if ( gLinkContext.verboseWarnings )
+ dyld::log("dyld: closure %p on disk cache doesn't have a UUID xattr\n", mainClosureData);
+ return false;
+ }
+ if (memcmp(&inMemoryUUID, &onDiskUUID, sizeof(uuid_t)) != 0) {
+ if ( gLinkContext.verboseWarnings )
+ dyld::log("dyld: closure %p not used because current cache on disk and in memory cache have UUID mismatches\n", mainClosureData);
+ return false;