From 0bd8479804f836c7e4c7e3b6c824cd21bd3249d3 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Thu, 5 Oct 2023 13:09:44 +0100 Subject: [PATCH] Do not patch PLT stubs for MallocStackLogging in MacOS MacOS has some memory interposition libraries that can make us crash (via stackoverflow when initializing TLS variables) if we patch them. This is because these libraries interact in a way we cannot avoid with libdyld, which in turn sets the TLS on first init. --- src/memray/_memray/macho_shenanigans.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/memray/_memray/macho_shenanigans.cpp b/src/memray/_memray/macho_shenanigans.cpp index 6c5b27e3d5..351056d8f0 100644 --- a/src/memray/_memray/macho_shenanigans.cpp +++ b/src/memray/_memray/macho_shenanigans.cpp @@ -309,6 +309,15 @@ patch_symbols_in_shared_object( << section->sectname << ")"; continue; } + // MacOS has some memory interposition libraries that can make us crash (via + // stackoverflow when initializing TLS variables) if we patch them. This is because these + // libraries interact in a way we cannot avoid with libdyld, which in turn sets the TLS + // on first init. + if (strstr(image_name, "MallocStackLogging")) { + LOG(DEBUG) << "Skipping section " << i << " (" << section->segname << ":" + << section->sectname << ")"; + continue; + } LOG(DEBUG) << "Patching section " << i << " (" << section->segname << ":" << section->sectname << ")"; patch_stubs(section, slide, dyninfo_table, restore_original);