Skip to content

Commit

Permalink
Do not override symbols in the muslc linker
Browse files Browse the repository at this point in the history
To avoid deadlocks and infinite recursion, we need to avoid patching
symbols inside the linker shared objects. We have been diligently doing
this with the GNU linker ("ld-linux") but not for the muslc linker
("ld-musl"). This has been working by chance because we use our
recursion guards in many of the symbols we patch, including dlopen.

The fact that we override dlopen and we use the guard was preventing a
deadlock when using native traces in muslc, as fetching native traces
ends adquiring a lock that it's shared by dlopen itself. Now that we do
not patch dlopen, there is nothing preventing memray to try to fetch
native traces in the inner calls to calloc() and that tries to adquire
the dlopen lock which is not re-entrant.

The proper fix is to avoid patching inside the muslc linker as we do for
Linux.

Signed-off-by: Pablo Galindo <[email protected]>
  • Loading branch information
pablogsal authored and godlygeek committed Feb 8, 2024
1 parent 725b967 commit 6fbadf7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/memray/_memray/elf_shenanigans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ phdrs_callback(dl_phdr_info* info, [[maybe_unused]] size_t size, void* data) noe
patched.insert(info->dlpi_name);
}

if (strstr(info->dlpi_name, "/ld-linux") || strstr(info->dlpi_name, "linux-vdso.so.1")) {
if (strstr(info->dlpi_name, "/ld-linux") || strstr(info->dlpi_name, "/ld-musl")
|| strstr(info->dlpi_name, "linux-vdso.so.1"))
{
// 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 6fbadf7

Please sign in to comment.