From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id 91DEA385AC2C; Sun, 4 Sep 2022 19:49:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91DEA385AC2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662320966; bh=QmxS/28KoXx1Q8xdIlPND8mlNV338RtQmNiH+ZNyodU=; h=From:To:Subject:Date:From; b=YmrdZ8OHX7Mf5nLhijweAdPhUKcKCRRYNpeZspnBWjsoV29joILpq/Bc5D0Y3Iscb HE911vSbyUz1NxITBcQgi4QtA2Qd60l1BADqfhmIeBrji2WQND3jftOhuKUl09e4jC cp/JErloN0E5A2HdnTHv4NRdoqGZpKgj/1FpvEsA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2395] [libsanitizer, Darwin] Fix bootstrap after recent merge. X-Act-Checkin: gcc X-Git-Author: Iain Sandoe X-Git-Refname: refs/heads/master X-Git-Oldrev: 8293a9632c46c8f3f9d531c09194aa8738944927 X-Git-Newrev: af9587ff0f261b8810a179a1369ae5a51dae99da Message-Id: <20220904194926.91DEA385AC2C@sourceware.org> Date: Sun, 4 Sep 2022 19:49:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:af9587ff0f261b8810a179a1369ae5a51dae99da commit r13-2395-gaf9587ff0f261b8810a179a1369ae5a51dae99da Author: Iain Sandoe Date: Sun Sep 4 20:22:21 2022 +0100 [libsanitizer, Darwin] Fix bootstrap after recent merge. The latest merge to libsanitizer includes changes to handle macOS 13+. However, these changes are incompatible with GCC and so we need to find an alternate solution. To restore bootstrap back this change out until the alternate can be found. Diff: --- .../sanitizer_common/sanitizer_procmaps_mac.cpp | 62 ++++------------------ 1 file changed, 10 insertions(+), 52 deletions(-) diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp index 4b0e6781976..ba4259acd46 100644 --- a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp @@ -146,8 +146,13 @@ static bool IsDyldHdr(const mach_header *hdr) { // until we hit a Mach header matching dyld instead. These recurse // calls are expensive, but the first memory map generation occurs // early in the process, when dyld is one of the only images loaded, -// so it will be hit after only a few iterations. These assumptions don't hold -// on macOS 13+ anymore (dyld itself has moved into the shared cache). +// so it will be hit after only a few iterations. These assumptions don't +// hold on macOS 13+ anymore (dyld itself has moved into the shared cache). + +// FIXME: Unfortunately, the upstream revised version to deal with macOS 13+ +// is incompatible with GCC and also uses APIs not available on earlier +// systems which we support; backed out for now. + static mach_header *GetDyldImageHeaderViaVMRegion() { vm_address_t address = 0; @@ -171,64 +176,17 @@ static mach_header *GetDyldImageHeaderViaVMRegion() { } } -extern "C" { -struct dyld_shared_cache_dylib_text_info { - uint64_t version; // current version 2 - // following fields all exist in version 1 - uint64_t loadAddressUnslid; - uint64_t textSegmentSize; - uuid_t dylibUuid; - const char *path; // pointer invalid at end of iterations - // following fields all exist in version 2 - uint64_t textSegmentOffset; // offset from start of cache -}; -typedef struct dyld_shared_cache_dylib_text_info - dyld_shared_cache_dylib_text_info; - -extern bool _dyld_get_shared_cache_uuid(uuid_t uuid); -extern const void *_dyld_get_shared_cache_range(size_t *length); -extern int dyld_shared_cache_iterate_text( - const uuid_t cacheUuid, - void (^callback)(const dyld_shared_cache_dylib_text_info *info)); -} // extern "C" - -static mach_header *GetDyldImageHeaderViaSharedCache() { - uuid_t uuid; - bool hasCache = _dyld_get_shared_cache_uuid(uuid); - if (!hasCache) - return nullptr; - - size_t cacheLength; - __block uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength); - CHECK(cacheStart && cacheLength); - - __block mach_header *dyldHdr = nullptr; - int res = dyld_shared_cache_iterate_text( - uuid, ^(const dyld_shared_cache_dylib_text_info *info) { - CHECK_GE(info->version, 2); - mach_header *hdr = - (mach_header *)(cacheStart + info->textSegmentOffset); - if (IsDyldHdr(hdr)) - dyldHdr = hdr; - }); - CHECK_EQ(res, 0); - - return dyldHdr; -} - const mach_header *get_dyld_hdr() { if (!dyld_hdr) { // On macOS 13+, dyld itself has moved into the shared cache. Looking it up // via vm_region_recurse_64() causes spins/hangs/crashes. + // FIXME: find a way to do this compatible with GCC. if (GetMacosAlignedVersion() >= MacosVersion(13, 0)) { - dyld_hdr = GetDyldImageHeaderViaSharedCache(); - if (!dyld_hdr) { VReport(1, - "Failed to lookup the dyld image header in the shared cache on " - "macOS 13+ (or no shared cache in use). Falling back to " + "looking up the dyld image header in the shared cache on " + "macOS 13+ is not yet supported. Falling back to " "lookup via vm_region_recurse_64().\n"); dyld_hdr = GetDyldImageHeaderViaVMRegion(); - } } else { dyld_hdr = GetDyldImageHeaderViaVMRegion(); }