Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 950965 - media-libs/sdl2-mixer: causes games-arcade/cdogs-sdl to segfault *if* sdl2-mixer is built with cmake
Summary: media-libs/sdl2-mixer: causes games-arcade/cdogs-sdl to segfault *if* sdl2-mi...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Games
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-09 00:29 UTC by Ionen Wolkens
Modified: 2025-03-09 12:12 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (from a test chroot) (emerge-info.txt,6.04 KB, text/plain)
2025-03-09 00:41 UTC, Ionen Wolkens
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ionen Wolkens gentoo-dev 2025-03-09 00:29:19 UTC
I don't know if it is just me (no other bug report yet?), but when I tried to bump games-arcade/cdogs-sdl, both the new and in-tree version segfaulted on startup, and then was fine if I downgraded to sdl2-mixer-2.6.3-r1.

Given the main change between 2.6.3-r1 and 2.8+ ebuilds was cmake, I tried to copy the 2.6.3-r1 ebuild to 2.8.1-r1 and built that.. and it no longer segfaults.

Haven't spent more time on this, but that would imply there is something different between how autotools and cmake build it that is causing this, or maybe ebuild options at most.

Audio driver used doesn't seem to matter, happens with SDL_AUDIODRIVER=dummy too.

[ebuild   R    ] media-libs/sdl2-mixer-2.8.1::gentoo  USE="mp3 vorbis wav -flac -fluidsynth -gme -midi -mod -modplug -opus -playtools -stb -timidity -tremor -wavpack -xmp" ABI_X86="(64) -32 (-x32)" 0 KiB

Backtrace:

20250308-191333 INFO  [MAIN ] [cdogs.c:294] main(): Starting game
Thread 1 "cdogs-sdl" received signal SIGSEGV, Segmentation fault.
0x00007fffef4c50cb in ?? ()
(gdb) bt
#0  0x00007fffef4c50cb in ?? ()
#1  0x00007ffff7eb9da5 in MPG123_Close ()
    at /tmp/portage/media-libs/sdl2-mixer-2.8.1/work/SDL2_mixer-2.8.1/src/codecs/music_mpg123.c:510
#2  0x00007ffff7ecb8e7 in close_music ()
    at /tmp/portage/media-libs/sdl2-mixer-2.8.1/work/SDL2_mixer-2.8.1/src/music.c:1428
#3  0x00007ffff7ec829d in Mix_CloseAudio ()
    at /tmp/portage/media-libs/sdl2-mixer-2.8.1/work/SDL2_mixer-2.8.1/src/mixer.c:1410
#4  0x00005555555e2f6b in SoundClose (s=s@entry=0x555555698d20 <gSoundDevice>, 
    waitForSoundsComplete=waitForSoundsComplete@entry=false)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/cdogs/sounds.c:269
#5  0x00005555555e3a94 in SoundClose (s=0x555555698d20 <gSoundDevice>, waitForSoundsComplete=false)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/cdogs/sounds.c:252
#6  SoundReopen (s=0x555555698d20 <gSoundDevice>)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/cdogs/sounds.c:295
#7  0x000055555559a8dc in EventPoll (handlers=0x5555556744a0 <gEventHandlers>, ticks=33, onEvent=onEvent@entry=0x0)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/cdogs/events.c:89
#8  0x0000555555564aee in LoopRunnerRunInner (ctx=ctx@entry=0x7fffffffc910)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/game_loop.c:209
#9  0x0000555555564db8 in LoopRunnerRun (l=l@entry=0x7fffffffca60)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/game_loop.c:333
#10 0x000055555555abd8 in main (argc=<optimized out>, argv=<optimized out>)
    at /tmp/portage/games-arcade/cdogs-sdl-2.2.0/work/cdogs-sdl-2.2.0/src/cdogs.c:295

Thought it was related to mpg123 at first, but if I replace cdogs-sdl's only mp3 file, then I just get this instead:

Thread 1 "cdogs-sdl" received signal SIGSEGV, Segmentation fault.
0x00007fffe8f437e0 in ?? ()
(gdb) bt
#0  0x00007fffe8f437e0 in ?? ()
#1  0x00007ffff7ebaf84 in OGG_Seek (context=0x5555585c0190, time=0)
    at /tmp/portage/media-libs/sdl2-mixer-2.8.1/work/SDL2_mixer-2.8.1/src/codecs/music_ogg.c:453
#2  0x00007ffff7ebac32 in OGG_Play (context=0x5555585c0190, play_count=-1)
    at /tmp/portage/media-libs/sdl2-mixer-2.8.1/work/SDL2_mixer-2.8.1/src/codecs/music_ogg.c:357
<...>
Comment 1 Ionen Wolkens gentoo-dev 2025-03-09 00:41:02 UTC
Created attachment 920382 [details]
emerge --info (from a test chroot)
Comment 2 Larry the Git Cow gentoo-dev 2025-03-09 00:51:26 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8200c211e98eeb70582bee3468801ba2a16ad34e

commit 8200c211e98eeb70582bee3468801ba2a16ad34e
Author:     Ionen Wolkens <ionen@gentoo.org>
AuthorDate: 2025-03-09 00:42:53 +0000
Commit:     Ionen Wolkens <ionen@gentoo.org>
CommitDate: 2025-03-09 00:50:27 +0000

    games-arcade/cdogs-sdl: add 2.3.0
    
    With a sdl2-mixer upper bound for now wrt bug #950965.
    
    Bug: https://bugs.gentoo.org/950965
    Signed-off-by: Ionen Wolkens <ionen@gentoo.org>

 games-arcade/cdogs-sdl/Manifest               |  1 +
 games-arcade/cdogs-sdl/cdogs-sdl-2.3.0.ebuild | 54 +++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 02:09:38 UTC
Just as a quick first comment: was/am hoping to use the examples/ stuff for a smoke test in src_test in sdl2-mixer but unfortunately with some random samples I found online at least, doesn't reproduce the issue.
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 02:58:59 UTC
(In reply to Ionen Wolkens from comment #0)
> I don't know if it is just me (no other bug report yet?),

Reproduced.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 08:37:43 UTC
I think the ov_time_seek FP gets corrupted.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 09:49:59 UTC
On the last hit in OGG_Seek before the crash:
```
(gdb) bt
#0  OGG_Seek (context=context@entry=0x555558b11f40, time=time@entry=0) at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/codecs/music_ogg.c:447
#1  0x00007ffff7da6b0e in OGG_Play (context=0x555558b11f40, play_count=1) at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/codecs/music_ogg.c:357
#2  0x00007ffff7dc8350 in Mix_LoadMusic_RW (src=src@entry=0x555558580bb0, freesrc=0, freesrc@entry=1, spec=spec@entry=0x7fffffff5ca0, audio_buf=audio_buf@entry=0x55555920d6f8,
    audio_len=audio_len@entry=0x55555920d700) at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/mixer.c:703
#3  0x00007ffff7dc9045 in Mix_LoadWAV_RW (src=0x555558580bb0, freesrc=1) at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/mixer.c:839
#4  0x00007ffff7dc9323 in Mix_LoadWAV (file=<optimized out>) at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/mixer.c:912
#5  0x00005555555e641f in SoundLoad (sounds=<optimized out>, name=0x7fffffff81b0 "ammo_low.ogg", path=0x7fffffff6e10 "/usr/share/cdogs-sdl/sounds/ammo_low.ogg")
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:151
#6  SoundLoadDir (sounds=0x5555581acf20, path=path@entry=0x7fffffffb200 "/usr/share/cdogs-sdl/sounds", prefix=prefix@entry=0x0)
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:238
#7  0x00005555555e69e3 in SoundLoadDir (sounds=<optimized out>, path=0x7fffffffb200 "/usr/share/cdogs-sdl/sounds", prefix=0x0)
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:201
#8  SoundInitialize (device=device@entry=0x5555556a1be0 <gSoundDevice>, path=path@entry=0x555555620b14 "sounds")
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:196
#9  0x0000555555556b7f in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs.c:213
(gdb) n
453         result = vorbis.ov_time_seek(&music->vf, time);
(gdb) p vorbis
$3 = {
  loaded = 1,
  handle = 0x555557282380,
  ov_clear = 0x7ffff68f2170 <ov_clear>,
  ov_info = 0x7ffff68f8d00 <ov_info>,
  ov_comment = 0x7ffff68f99ab <ov_comment>,
  ov_open_callbacks = 0x7ffff68f5224 <ov_open_callbacks>,
  ov_pcm_total = 0x7ffff68f374c <ov_pcm_total>,
  ov_read = 0x7ffff68fab63 <ov_read>,
  ov_time_seek = 0x7ffff68f7d89 <ov_time_seek>,
  ov_time_tell = 0x7ffff68f897c <ov_time_tell>,
  ov_time_total = 0x7ffff68f77b2 <ov_time_total>,
  ov_pcm_seek = 0x7ffff68f6850 <ov_pcm_seek>,
  ov_pcm_tell = 0x7ffff68f8907 <ov_pcm_tell>
}
```

Then again:
```
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
3       breakpoint     keep y   0x00007ffff7da61dc in OGG_Seek at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/codecs/music_ogg.c:447
        breakpoint already hit 318 times
(gdb) n
453         result = vorbis.ov_time_seek(&music->vf, time);
(gdb) n

Thread 1 "cdogs-sdl" received signal SIGSEGV, Segmentation fault.
0x00007ffff68f7d89 in ?? ()
(gdb) p vorbis
$4 = {
  loaded = 0,
  handle = 0x555557282380,
  ov_clear = 0x7ffff68f2170,
  ov_info = 0x7ffff68f8d00,
  ov_comment = 0x7ffff68f99ab,
  ov_open_callbacks = 0x7ffff68f5224,
  ov_pcm_total = 0x7ffff68f374c,
  ov_read = 0x7ffff68fab63,
  ov_time_seek = 0x7ffff68f7d89,
  ov_time_tell = 0x7ffff68f897c,
  ov_time_total = 0x7ffff68f77b2,
  ov_pcm_seek = 0x7ffff68f6850,
  ov_pcm_tell = 0x7ffff68f8907
}
```

The addresses are the same, so does it get dlclose'd or something?
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 09:51:09 UTC
Yes:
```
Thread 1 "cdogs-sdl" hit Breakpoint 5, __dlclose (handle=0x55555727f250) at dlclose.c:25
25      {
(gdb) bt
#0  __dlclose (handle=0x55555727f250) at dlclose.c:25
#1  0x00007ffff7da5eee in OGG_Unload () at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/codecs/music_ogg.c:120
#2  0x00007ffff7dd164d in unload_music () at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/music.c:1459
#3  0x00007ffff7dc4d5c in Mix_Quit () at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/mixer.c:283
#4  0x00005555555e5e35 in SoundClose (s=s@entry=0x5555556a1be0 <gSoundDevice>, waitForSoundsComplete=waitForSoundsComplete@entry=false)
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:267
#5  0x00005555555e6a38 in SoundClose (s=0x5555556a1be0 <gSoundDevice>, waitForSoundsComplete=false) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:252
#6  SoundReopen (s=0x5555556a1be0 <gSoundDevice>) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:295
#7  0x000055555559a96c in EventPoll (handlers=0x55555567d360 <gEventHandlers>, ticks=33, onEvent=onEvent@entry=0x0)
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/events.c:89
#8  0x00005555555619be in LoopRunnerRunInner (ctx=ctx@entry=0x7fffffffc1f0) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/game_loop.c:209
#9  0x0000555555561c88 in LoopRunnerRun (l=l@entry=0x7fffffffc370) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/game_loop.c:333
#10 0x0000555555556f35 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs.c:295
(gdb) c
Continuing.

Thread 1 "cdogs-sdl" hit Breakpoint 5, __dlclose (handle=0x7ffff78114c0) at dlclose.c:25
25      {
(gdb) bt
#0  __dlclose (handle=0x7ffff78114c0) at dlclose.c:25
#1  0x00007ffff7da444d in MPG123_Unload () at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/codecs/music_mpg123.c:131
#2  0x00007ffff7dd164d in unload_music () at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/music.c:1459
#3  0x00007ffff7dc4d5c in Mix_Quit () at /usr/src/debug/media-libs/sdl2-mixer-2.8.1/SDL2_mixer-2.8.1/src/mixer.c:283
#4  0x00005555555e5e35 in SoundClose (s=s@entry=0x5555556a1be0 <gSoundDevice>, waitForSoundsComplete=waitForSoundsComplete@entry=false)
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:267
#5  0x00005555555e6a38 in SoundClose (s=0x5555556a1be0 <gSoundDevice>, waitForSoundsComplete=false) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:252
#6  SoundReopen (s=0x5555556a1be0 <gSoundDevice>) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/sounds.c:295
#7  0x000055555559a96c in EventPoll (handlers=0x55555567d360 <gEventHandlers>, ticks=33, onEvent=onEvent@entry=0x0)
    at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs/events.c:89
#8  0x00005555555619be in LoopRunnerRunInner (ctx=ctx@entry=0x7fffffffc1f0) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/game_loop.c:209
#9  0x0000555555561c88 in LoopRunnerRun (l=l@entry=0x7fffffffc370) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/game_loop.c:333
#10 0x0000555555556f35 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/games-arcade/cdogs-sdl-2.2.0/cdogs-sdl-2.2.0/src/cdogs.c:295
(gdb) c
Continuing.
[Thread 0x7fffae5fe6c0 (LWP 859859) exited]
[New Thread 0x7fffae5fe6c0 (LWP 859897)]

Thread 1 "cdogs-sdl" received signal SIGSEGV, Segmentation fault.
0x00007ffff68f7d89 in ?? ()
(gdb)
```
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 09:54:55 UTC
The next question is what changed between the CMake vs autotools build.. I'd *assumed* that we were always forcing linking w/ autotools and we're not in CMake, but no.

```
sdl2-mixer-2.6.3-r1.ebuild:56:          --disable-music-mod-modplug-shared
sdl2-mixer-2.6.3-r1.ebuild:60:          --disable-music-midi-fluidsynth-shared
sdl2-mixer-2.6.3-r1.ebuild:66:          --disable-music-ogg-vorbis-shared
sdl2-mixer-2.6.3-r1.ebuild:68:          --disable-music-ogg-tremor-shared
sdl2-mixer-2.6.3-r1.ebuild:71:          --disable-music-flac-libflac-shared
sdl2-mixer-2.6.3-r1.ebuild:74:          --disable-music-mp3-mpg123-shared
sdl2-mixer-2.6.3-r1.ebuild:76:          --disable-music-opus-shared
```

And in CMake, the default is to keep doing dlopen as well, unless SDLMIXER_DEPS_SHARED is set or overridden for individual libs.
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 09:58:42 UTC
In master for sdl-mixer:
```
cmake_dependent_option(SDLMIXER_DEPS_SHARED "Load dependencies dynamically" ON PLATFORM_SUPPORTS_SHARED OFF)
```

But the default changed in https://github.com/libsdl-org/SDL_mixer/commit/8179d845fa27bc6889a08e2932a1529dbc34cd75, and in the SDL2 branch, it's ON.
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 10:05:22 UTC
This wfm:
```
--- a/media-libs/sdl2-mixer/sdl2-mixer-2.8.1.ebuild
+++ b/media-libs/sdl2-mixer/sdl2-mixer-2.8.1.ebuild
@@ -72,6 +72,7 @@ multilib_src_configure() {
                -DSDL2MIXER_WAVPACK=$(usex wavpack)
                -DSDL2MIXER_SAMPLES=$(usex playtools)
                -DSDL2MIXER_SAMPLES_INSTALL=$(usex playtools)
+               -DSDL2MIXER_DEPS_SHARED=OFF
        )
        cmake_src_configure
 }
```

I thought cdogs-sdl may be wrong here (to call Mix_Quit twice), but https://wiki.libsdl.org/SDL2_mixer/Mix_Quit says "You can safely call Mix_Init() to reload various codec support after this call."

But it does say "For that reason, it's considered best practices to have a single Mix_Init and Mix_Quit call in your program. While this isn't required, be aware of the risks of deviating from that behavior."

If I set breakpoints on Mix_{Init,Quit} with patched sdl2-mixer with above (shouldn't matter), it looks balanced (Init/Quit/Init/Init) so I think this is just "dlclose is terrible" (b/c you can't assume libraries can safely be opened+closed repeatedly) rather than a cdogs-sdl bug.
Comment 11 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-03-09 10:09:13 UTC
(I don't get why it's okay for it to try use it with loaded=0 in https://bugs.gentoo.org/950965#c6 but I think it's clear that the mechanism is brittle. Might be an sdl2-mixer bug there but it falls within that "don't be expected if it breaks" thing too perhaps, so not going to pursue that.)
Comment 12 Ionen Wolkens gentoo-dev 2025-03-09 12:12:55 UTC
Interesting, thanks for debugging it.

As far as dlopen goes, I always try avoid it either way myself. Feel it doesn't make that much sense on Gentoo where we don't need these to be runtime-optional (at best it acts as pseudo lazy bindings for startup times).