jackaudio / jack2

jack2 codebase
GNU General Public License v2.0
2.21k stars 376 forks source link

GCC upgrade (4.9.4 to 7.3.0) and JACK issues #349

Open tokiclover opened 6 years ago

tokiclover commented 6 years ago

I upgraded a Gentoo system from GCC-4.9.4 to GCC-7.3.0. I won't report the details, but JACK does no function properly. libjack.so segfaults for simple operations like client connection or automatic client renaming.

A typical error when trying to connect to JACK is:

alsa_in -j playback_calp -d calp -q1 -v
WARNING: buffer size does not match: (requested 2048, got 12000)
WARNING: period size does not match: (requested 1024, got 6000)
selected sample format: 16bit
[1]    30144 segmentation fault  alsa_in -j playback_calp -d calp -q1 -v

with this segmentation fault:

May 20 10:35:42 localhost kernel: alsa_in[30147]: segfault at 7fc640bcb08e ip 00007fc63f758488 sp 00007fc63fe2ae20 error 4 in libjack.so.0.1.0[7fc63f73f000+3a000]

When trying to test JACK with jack_test, I got this:

jack_test -t 300 -v
Verbose mode is activated...
Jack server is said being in non-realtime mode...
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-* Start jack server stress test  *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Register a client using jack_client_open()...
trying to load the "inprocess" server internal client 
"inprocess" server internal client loaded
jack_get_internal_client_name returns inprocess
jack_internal_client_handle returns correct handle
jack_internal_client_unload done first time returns correct value
jack_internal_client_unload done second time returns correct value
trying to register a new jackd client with name jack_test using jack_client_new()...
jack_client_new: deprecated
Client name = jack_test conflits with another running client
Cannot connect to the server
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for -1, skipping unlock
valid : a second client with the same name cannot be registered
trying to register a new jackd client with name jack_test using jack_client_open()...
Cannot open shm segment /jack-1000-0 (No such file or directory)
Map shared memory segments exception
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for 0, skipping unlock
!!! ERROR !!! Jackd server automatic renaming feature does not work!
trying to register a new jackd client with maximum possible client name size...
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL" is too long to be used as a JACK client name.
Please use 63 characters or less
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for -1, skipping unlock
!!! ERROR !!! opening a client with maximum possible client name size does not work!
Testing name... ok
!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = 0).
Init callback has been successfully called from thread = ec28700. (msg from callback)
Sample rate : 48000.
error : port_name is empty (msg from callback)
Can't register a port with a NULL portname... ok.
[1]    11530 segmentation fault  jack_test -t 300 -v

with this segmentation fault:

May 20 10:38:42 localhost kernel: jack_test[30190]: segfault at 7f2c2ac9c096 ip 00007f2c2983c465 sp 00007ffcbb734870 error 4 in libjack.so.0.1.0[7f2c2982d000+3a000]

JACK is built with ALSA, dBus, FFADO, samplerate, PAM, readline and sndfile support. libjack.so is only linked to GLibc GCC and ALSA:

ldd /usr/lib/libjack.so
   linux-vdso.so.1 (0x00007ffdbf8d3000)
   libpthread.so.0 => /lib64/libpthread.so.0 (0x00007faef37fa000)
   librt.so.1 => /lib64/librt.so.1 (0x00007faef35f1000)
   libdbus-1.so.3 => /usr/lib64/libdbus-1.so.3 (0x00007faef339c000)
   libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libstdc++.so.6 (0x00007faef2f62000)
   libgcc_s.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libgcc_s.so.1 (0x00007faef2d4b000)
   libc.so.6 => /lib64/libc.so.6 (0x00007faef297a000)
   /lib64/ld-linux-x86-64.so.2 (0x00007faef3c57000)
   libm.so.6 => /lib64/libm.so.6 (0x00007faef2636000)

GCC-5.x.y transitioned to c++11 standard as a g++ default. So, GCC-7.3.0 compiles JACK to c++11 in the absence of a -std=STANDARD argument to g++. But there is no argument whatsoever passed to the C++ compiler. Should I add anything to CXXFLAGS? The compilation and linkage goes fine without any error.

falkTX commented 6 years ago

Was jack built with gcc7? gcc4 to gcc5 changed the c++ ABI, so applications compiled with gcc4 cannot load plugins or external c++ modules made with gcc >= 5. I recommend you to rebuild jack and applications that use it, then see if the issue still happens. let me know how that goes, thank you.

tokiclover commented 6 years ago

As you can see above (libjack.so library linkage), JACK was recompiled with GCC-7.3.0 as all packages linked against libstdc++.so.

tokiclover commented 6 years ago

This what happen a client, alsa_out here, try to connect to JACK:

gdb -- alsa_out

(gdb) run -j playback_palp -d palp -q1
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/bin/alsa_out -j playback_palp -d palp -q1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff7fb5700 (LWP 28469)]
[New Thread 0x7ffff7f34700 (LWP 28475)]
selected sample format: float
[New Thread 0x7ffff7eb3700 (LWP 28484)]

Thread 4 "alsa_out" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7eb3700 (LWP 28484)]
Jack::JackClient::WaitSync (this=0x555555779df0) at ../common/JackClient.cpp:626
626 ../common/JackClient.cpp: No such file or directory.

../common/JackClient.cpp:

 623 inline bool JackClient::WaitSync()                                              
 624 {                                                                               
 625     // Suspend itself: wait on the input synchro                                
 626     if (GetGraphManager()->SuspendRefNum(GetClientControl(), fSynchroTable, 0x7FFFFFFF) < 0) {
 627         jack_error("SuspendRefNum error");                                      
 628         return false;                                                           
 629     } else {                                                                    
 630         return true;                                                            
 631     }                                                                           
 632 
aduviviers commented 4 years ago

This issue is already a bit old, but I got a same or similar problem when (finally) switching from Jack 1 to Jack 2 (1.9.13) on my Gentoo system (GCC 9.2), with all Jack clients crashing.

On my system it seems it was caused by having enabled LTO optimizations by default. Disabling LTO for jack2 build fixed all the crashes, it's working fine without it. It seems it also works correctly when building jack2 with LTO using Clang 9 instead of GCC.

So it looks like it may be the same cause as #485

Did you by change had LTO enabled when this happened ? (Note: Jack v1 was working correctly when built with LTO)

SudoNova commented 4 years ago

Maybe this one can help: https://gist.github.com/SudoNova/89a17c8e8d3e62b6ed0a17d06a877053 Also:

=================================================================
                        Package Settings
=================================================================

media-sound/jack2-1.9.14::gentoo was built with the following:
USE="alsa classic dbus ieee1394 libsamplerate metadata opus pam readline sndfile -doc" PYTHON_SINGLE_TARGET="python3_8"
CFLAGS="-O2 -march=native -mtune=native -malign-data=cacheline -mtls-dialect=gnu2 -mfpmath=both -fPIC -fuse-linker-plugin -flto=auto -flto-compression-level=0 -flto-partition=balanced -pthread -ftracer -ftree-vectorize -floop-unroll-and-jam -ftree-loop-distribution -ftree-loop-ivcanon -fpredictive-commoning -floop-interchange -fgraphite-identity -floop-nest-optimize -fno-math-errno -fno-trapping-math -fipa-pta -fno-plt -ggdb3 -fdevirtualize-at-ltrans -fno-semantic-interposition -fweb -falign-functions=32:13:16 -falign-loops=32:13:16 -falign-jumps=32:13:16 -falign-labels=32:13:16 -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fno-common -fstack-protector-explicit -fdiagnostics-color=always"
CXXFLAGS="-O2 -march=native -mtune=native -malign-data=cacheline -mtls-dialect=gnu2 -mfpmath=both -fPIC -fuse-linker-plugin -flto=auto -flto-compression-level=0 -flto-partition=balanced -pthread -ftracer -ftree-vectorize -floop-unroll-and-jam -ftree-loop-distribution -ftree-loop-ivcanon -fpredictive-commoning -floop-interchange -fgraphite-identity -floop-nest-optimize -fno-math-errno -fno-trapping-math -fipa-pta -fno-plt -ggdb3 -fdevirtualize-at-ltrans -fno-semantic-interposition -fweb -falign-functions=32:13:16 -falign-loops=32:13:16 -falign-jumps=32:13:16 -falign-labels=32:13:16 -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fgcse-sm -fgcse-las -fgcse-after-reload -fno-common -fstack-protector-explicit -fdiagnostics-color=always -fvisibility-inlines-hidden 
LDFLAGS="-Wl,-O2 -Wl,--as-needed -Wl,-z,combreloc -Wl,-z,now -Wl,-z,relro -Wl,--sort-common -pthread"

I know those flags are overkill, but I can compile with whatever flag you advise to narrow down the problem, if needed.