Skip to content

Commit 8be48a3

Browse files
committed
Avoid patching symbols in the extension module
The fact that patching ourselves had not raised problems so far its really an outstanding fact in this universe. Unfortunately seems that with the latest toolchain + GCC there is something that causes memray to point the d_original entry of the hooks pointing to itself, which should never happen. To fix this resiliently, avoid patching ourselves by getting our own name in the extension module and then avoiding that shared object. Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent 8635569 commit 8be48a3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

news/685.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix some crashes caused by interposing symbols in memray itself

src/memray/_memray/elf_shenanigans.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <cstring>
2+
#include <mutex>
23
#include <set>
34
#include <string>
45
#include <sys/mman.h>
@@ -171,11 +172,13 @@ phdrs_callback(dl_phdr_info* info, [[maybe_unused]] size_t size, void* data) noe
171172
patched.insert(info->dlpi_name);
172173
}
173174

175+
// Get this so name once
176+
static std::string self_so_name = "_memray.cpython-";
177+
174178
if (strstr(info->dlpi_name, "/ld-linux") || strstr(info->dlpi_name, "/ld-musl")
175-
|| strstr(info->dlpi_name, "linux-vdso.so.1"))
179+
|| strstr(info->dlpi_name, "linux-vdso.so.1") || strstr(info->dlpi_name, self_so_name.c_str()))
176180
{
177181
// Avoid chaos by not overwriting the symbols in the linker.
178-
// TODO: Don't override the symbols in our shared library!
179182
return 0;
180183
}
181184

0 commit comments

Comments
 (0)