https://github.com/adrian-prantl updated 
https://github.com/llvm/llvm-project/pull/130209

>From 1dc911414f8bf6441fec6384de046f45e7049870 Mon Sep 17 00:00:00 2001
From: Adrian Prantl <apra...@apple.com>
Date: Thu, 6 Mar 2025 16:33:35 -0800
Subject: [PATCH] [lldb] Objective-C runtime: Work around a bug in the shared
 cache builder

where it can overflow a 2GB offset by just a little bit by applying a
heuristic.

rdar://145888306
---
 .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp         | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index ff17028e6662a..c91a29ace1f68 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -458,7 +458,14 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void 
*objc_opt_ro_ptr,
 
         if (objc_opt->version == 16)
         {
-            const objc_clsopt_v16_t* clsopt = (const 
objc_clsopt_v16_t*)((uint8_t *)objc_opt + 
objc_opt_v16->largeSharedCachesClassOffset);
+            int32_t large_offset = objc_opt_v16->largeSharedCachesClassOffset;
+            const objc_clsopt_v16_t* clsopt = (const 
objc_clsopt_v16_t*)((uint8_t *)objc_opt + large_offset);
+            // Work around a bug in some version shared cache builder where 
the offset overflows 2GiB (rdar://146432183).
+            uint32_t unsigned_offset = (uint32_t)large_offset;
+            if (unsigned_offset > 0x7fffffff && unsigned_offset < 0x82000000) {
+               clsopt = (const objc_clsopt_v16_t*)((uint8_t *)objc_opt + 
unsigned_offset);
+               DEBUG_PRINTF("warning: applying largeSharedCachesClassOffset 
overflow workaround!\n");
+            }
             const size_t max_class_infos = 
class_infos_byte_size/sizeof(ClassInfo);
 
             DEBUG_PRINTF("max_class_infos = %llu\n", 
(uint64_t)max_class_infos);

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to