[ruby-core:115779] [Ruby master Bug#20072] free(): invalid pointer when compiled with --enable-shared --with-jemalloc

Issue #20072 has been reported by misdoro (Mikhail Doronin). ---------------------------------------- Bug #20072: free(): invalid pointer when compiled with --enable-shared --with-jemalloc https://bugs.ruby-lang.org/issues/20072 * Author: misdoro (Mikhail Doronin) * Status: Open * Priority: Normal * 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) -- https://bugs.ruby-lang.org/

Issue #20072 has been updated by nobu (Nobuyoshi Nakada). Could you share your config.log and crash report? ---------------------------------------- Bug #20072: free(): invalid pointer when compiled with --enable-shared --with-jemalloc https://bugs.ruby-lang.org/issues/20072#change-105720 * Author: misdoro (Mikhail Doronin) * Status: Open * Priority: Normal * 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) -- https://bugs.ruby-lang.org/

Issue #20072 has been updated by misdoro (Mikhail Doronin). File config.log added Hi Nobu, you will find the config.log attached. Debugged it a bit deeper, it boils down to running `irb` and running `require 'sassc'` that is immediately crashing: ``` $ irb irb(main):001> require 'sassc' free(): invalid pointer Aborted ``` ---------------------------------------- Bug #20072: free(): invalid pointer when compiled with --enable-shared --with-jemalloc https://bugs.ruby-lang.org/issues/20072#change-105739 * 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/

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/

Issue #20072 has been updated by hsbt (Hiroshi SHIBATA). Status changed from Open to Closed https://github.com/ruby/ruby/pull/9284 has been merged. #19831 is already solved. There are no warnings with the latest Xcode. ---------------------------------------- Bug #20072: free(): invalid pointer when compiled with --enable-shared --with-jemalloc https://bugs.ruby-lang.org/issues/20072#change-105749 * Author: misdoro (Mikhail Doronin) * Status: Closed * 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/

Issue #20072 has been updated by shyouhei (Shyouhei Urabe). This issue reminds me of https://github.com/ruby/ruby/pull/4627 ---------------------------------------- Bug #20072: free(): invalid pointer when compiled with --enable-shared --with-jemalloc https://bugs.ruby-lang.org/issues/20072#change-105751 * Author: misdoro (Mikhail Doronin) * Status: Closed * 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/
participants (5)
-
hsbt (Hiroshi SHIBATA)
-
kjtsanaktsidis (KJ Tsanaktsidis)
-
misdoro (Mikhail Doronin)
-
nobu (Nobuyoshi Nakada)
-
shyouhei (Shyouhei Urabe)