Skip to content

Commit 347df21

Browse files
authored
Link libpthread into the spawn_worker trampoline (#452)
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 <main_arena>, ptr=<optimized out>, str=0x7fe4533a06d8 "double free or corruption (out)", action=3) at malloc.c:4967 #4 _int_free (av=0x7fe4535dc760 <main_arena>, p=<optimized out>, 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 <[email protected]>
1 parent f63cff5 commit 347df21

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

spawn_worker/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ fn main() {
1818
if cfg!(target_os = "linux") {
1919
builder.flag("-Wl,--no-as-needed");
2020
}
21-
builder.link_dynamically("m"); // rust code generally requires libm. Just link against it.
21+
// rust code generally requires libm. Just link against it.
22+
builder.link_dynamically("m");
23+
// some old libc versions are unhappy if it gets linked in dynamically later on
24+
builder.link_dynamically("pthread");
2225
} else {
2326
builder.flag("-wd4996"); // disable deprecation warnings
2427
}

0 commit comments

Comments
 (0)