Skip to content

Commit

Permalink
Avoid patching symbols in the extension module
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pablogsal committed Sep 19, 2024
1 parent 8635569 commit 8be48a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/685.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix some crashes caused by interposing symbols in memray itself
7 changes: 5 additions & 2 deletions src/memray/_memray/elf_shenanigans.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cstring>
#include <mutex>
#include <set>
#include <string>
#include <sys/mman.h>
Expand Down Expand Up @@ -171,11 +172,13 @@ phdrs_callback(dl_phdr_info* info, [[maybe_unused]] size_t size, void* data) noe
patched.insert(info->dlpi_name);
}

// Get this so name once
static std::string self_so_name = "_memray.cpython-";

if (strstr(info->dlpi_name, "/ld-linux") || strstr(info->dlpi_name, "/ld-musl")
|| strstr(info->dlpi_name, "linux-vdso.so.1"))
|| strstr(info->dlpi_name, "linux-vdso.so.1") || strstr(info->dlpi_name, self_so_name.c_str()))
{
// Avoid chaos by not overwriting the symbols in the linker.
// TODO: Don't override the symbols in our shared library!
return 0;
}

Expand Down

0 comments on commit 8be48a3

Please sign in to comment.