Skip to content

Commit

Permalink
Link libpthread into the spawn_worker trampoline (#452)
Browse files Browse the repository at this point in the history
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 <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi authored May 24, 2024
1 parent f63cff5 commit 347df21
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion spawn_worker/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ fn main() {
if cfg!(target_os = "linux") {
builder.flag("-Wl,--no-as-needed");
}
builder.link_dynamically("m"); // rust code generally requires libm. Just link against it.
// rust code generally requires libm. Just link against it.
builder.link_dynamically("m");
// 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
}
Expand Down

0 comments on commit 347df21

Please sign in to comment.