Project

General

Profile

Actions

Bug #20072

closed

free(): invalid pointer when compiled with --enable-shared --with-jemalloc

Added by misdoro (Mikhail Doronin) 12 months ago. Updated 12 months ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 3.3.0dev (2023-08-17T01:57:09Z test 5bb9462285) [x86_64-linux]
[ruby-core:115779]

Description

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)


Related issues 1 (1 open0 closed)

Related to Ruby master - Bug #19831: warning message of linker with macOS Sonoma betaOpenActions

Updated by nobu (Nobuyoshi Nakada) 12 months ago

Could you share your config.log and crash report?

Actions #2

Updated by hsbt (Hiroshi SHIBATA) 12 months ago

  • Target version set to 3.3

Updated by misdoro (Mikhail Doronin) 12 months ago

  • File config.log added

Hi Nobu, you will find the config.log attached.

Debugged it a bit deeper, it boils down to:

  • install ruby with --enable-shared --with-jemalloc
  • gem install sassc
  • running irb and require 'sassc'
    that is immediately crashing:
$ irb
irb(main):001> require 'sassc'
free(): invalid pointer
Aborted

Updated by kjtsanaktsidis (KJ Tsanaktsidis) 12 months ago

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]

And because the dynamic linker (at least 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.

Actions #5

Updated by hsbt (Hiroshi SHIBATA) 12 months ago

  • Related to Bug #19831: warning message of linker with macOS Sonoma beta added

Updated by hsbt (Hiroshi SHIBATA) 12 months ago

  • 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.

Actions #8

Updated by misdoro (Mikhail Doronin) 12 months ago

  • File deleted (config.log)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like1Like0Like1Like0Like0