From c61afef2c8b68156463035670237b5f3bbf00b4d Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 22 May 2024 22:09:48 +0200 Subject: [PATCH] Link libpthread into the spawn_worker trampoline It apparently leads to race conditions if libpthread and libc aren't loaded at the same time. In this case a library linking against libpthread is dlopen()'ed dynamically from the trampoline. It led to interesting libc memory corruptions, like in getaddrinfo: #2 0x00007fe45328df67 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7fe4533a05d0 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:196 #3 0x00007fe453296329 in malloc_printerr (ar_ptr=0x7fe4535dc760 , ptr=, str=0x7fe4533a06d8 "double free or corruption (out)", action=3) at malloc.c:4967 #4 _int_free (av=0x7fe4535dc760 , p=, have_lock=0) at malloc.c:3843 #5 0x00007fe453283247 in _IO_new_fclose (fp=0x7fe448001d20) at iofclose.c:84 etc. on older glibc versions. Signed-off-by: Bob Weinand --- spawn_worker/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spawn_worker/build.rs b/spawn_worker/build.rs index 4ce156ca52..15d252af10 100644 --- a/spawn_worker/build.rs +++ b/spawn_worker/build.rs @@ -19,6 +19,8 @@ fn main() { builder.flag("-Wl,--no-as-needed"); } builder.link_dynamically("m"); // rust code generally requires libm. Just link against it. + // some old libc versions are unhappy if it gets linked in dynamically later on + builder.link_dynamically("pthread"); } else { builder.flag("-wd4996"); // disable deprecation warnings }