From: "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" Date: 2023-12-20T04:13:52+00:00 Subject: [ruby-core:115799] [Ruby master Bug#20072] free(): invalid pointer when compiled with --enable-shared --with-jemalloc Issue #20072 has been updated by kjtsanaktsidis (KJ Tsanaktsidis). I wasn't able to reproduce your crash, but there is definitely a problem - when using `--enable-shared` and `--with-jemalloc` together, the Ruby that gets built still uses libc's malloc and ignores jemalloc. This is because we pass `-ljemalloc` to the link line for `libruby.so`, but we _don't_ pass it to `ruby`. This means that the built Ruby isn't marked as needing `libjemalloc.so`: ``` root@jammy-189dc9d584290f1a:/var/ruby# readelf --dynamic ruby | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [libruby.so.3.3] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]with ``` And because the dynamic linker (at lesat the glibc one) links libraries in breadth-first order, that means that `libc.so.6` is linked before `libjemalloc.so.2`: ``` root@jammy-189dc9d584290f1a:/var/ruby# ldd ruby linux-vdso.so.1 (0x00007ffe873fb000) libruby.so.3.3 => /usr/local/lib/libruby.so.3.3 (0x00007f8870000000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f886fc00000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f887054c000) libjemalloc.so.2 => /lib/x86_64-linux-gnu/libjemalloc.so.2 (0x00007f886f800000) libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f8870512000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f886ff19000) /lib64/ld-linux-x86-64.so.2 (0x00007f8870572000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f886f400000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f886fef9000) ``` We need to pass `-ljemalloc` to the linker command line for the final Ruby executable. I'm playing around trying to find the right Autoconf magic spells for this now. ---------------------------------------- Bug #20072: free(): invalid pointer when compiled with --enable-shared --with-jemalloc https://bugs.ruby-lang.org/issues/20072#change-105745 * Author: misdoro (Mikhail Doronin) * Status: Open * Priority: Normal * Target version: 3.3 * ruby -v: ruby 3.3.0dev (2023-08-17T01:57:09Z test 5bb9462285) [x86_64-linux] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- When ruby is built with `--enable-shared --with-jemalloc` on Linux (current Gentoo, ubuntu22 in docker), running a rails app yields: ``` free(): invalid pointer Aborted ``` The issue started appearing after 5bb946228550c7f171c27725860b153a675404f3 https://github.com/ruby/ruby/commit/5bb946228550c7f171c27725860b153a675404f3 Related to https://bugs.ruby-lang.org/issues/18409 (workaround to LD_PRELOAD jemalloc from that issue works) ---Files-------------------------------- config.log (1.34 MB) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/