[PD-dev] weak jack linking and segfaults (was Re: Pd does not link against jack)

Roman Haefeli reduzent at gmail.com
Sat Jul 8 15:56:26 CEST 2017


On Fre, 2017-07-07 at 10:57 +0200, IOhannes m zmölnig wrote:
> On 07/07/2017 12:50 AM, Roman Haefeli wrote:
> > 
> > > 
> > > > 
> > > > When I start:
> > > > 
> > > > $ pd -jack -channels 2 
> > > > 
> > > > It segfaults.
> 
> there's actually two issues we discovered.
> - on some systems, the Pd binary ends up not being dynamically linked
> against libjack (even though "-ljack" is passed to the linker)
> - if this is the case, Pd segfaults when the jack backend is
> selected.
> 
> > 
> > 
> > Just to sum it up for others reading this. This issue appears on
> > Ubuntu
> > 16.04 and (according to a #dataflow user) on Gentoo. I had a shared
> > SSH
> > session with IOhannes and he investigated the problem. I might be
> > not
> > be able to fully explain what he found out, but it is related to
> > weak
> > linking and the way the the compiler that comes with Ubuntu 16.04
> > handles it. 
> the issue is, that jack.h declares all symbols as "weak" symbols (so
> they might be missing) from the actually used dynamic library and Pd
> can
> still load.
> if the linker has the "--as-needed" flag (which is enabled by default
> on
> Ubuntu-16.04LTS), the linker will only link against a dynamic library
> if
> the application uses at least one non-weak symbol.
> since all symbols in jack.h are declared as weak, the linker simply
> removes the dependeny on libjack, and sets all function pointers to
> NULL.
> 
> foremost, this explains why Pd is crashing in this case: Pd has been
> compiled with USEAPI_JACK, but then the "jack_client_open" function
> is
> really just a NULL-pointer.
> there is already a check for this in place, to just fail the request
> to
> open a jack device (since on OSX we have weak linking by default),
> but
> unfortunately this is only active on OSX, thus making it crash on
> e.g.
> linux.
> 
> there's a pull-request [93] on github to fix the crash.
> 
> 
> > 
> > IOhannes proposed to add the '-Wl,--no-as-needed' linker
> > flag like this:
> > 
> > $ ./configure --enable-jack LDFLAGS="-Wl,--no-as-needed"
> > 
> this is a hack for the other problem.
> 
> for the record: i consider this a workaround for systems were the
> linker
> defaults to stripping unused libraries ("--as-needed").
> 
> I don't think that Pd is the actual culprit here, and I'm currently
> investigating whether the problem is with libjack or with gcc.
> 
> esp. i'm (currently) pretty convinced that "--no-as-needed" should
> *not*
> be added by Pd's build system by default.
> 
> msdt
> IOhannes
> 
> 
> [93] https://github.com/pure-data/pure-data/pull/93

Someone from #dataflow was asking in #jack about this and reported
back:


simonvanderveldt> rdz: After some more investigation and discussion in
#jack I think the conclusion is that weakjack.h should only be included
on macOS/OS X and not on linux. If I remove that import everything
works as it should, the linking works and my jack doesn't segfault once
it's linked and I'm trying to connect to jack through Pd
<simonvanderveldt> The code already shows a conditional for the weak
jack client creation https://github.com/pure-data/pure-data/blob/master
/src/s_audio_jack.c#L311 and the additional of the weakjack.h import
was done to fix issues on mac https://github.com/pure-data/pure-
data/commit/73362cc6a57d89337815023f1ffc4ee0adc1de55
<simonvanderveldt> The other way around around, the non mac call to
jack_client_open (https://github.com/pure-data/pure-data/blob/master/sr
c/s_audio_jack.c#L341) isn't conditional which seems to indicate that
weak linking wasn't desired there
<simonvanderveldt> also falk said weakjack never really worked in
Linux, also a good pointer :P


So the question is: Why do we want Pd to have weak-linking support on
Linux at all? I don't see an advantage. I commented out the line:

#include <jack/weakjack.h>

and I was successfully compiling Pd. 

The file  /usr/include/jack/weakjack.h has some more info about this
and states:

"It is important to understand that very few clients need to do this -
if you use this feature you should have a clear reason to do so."

Roman




-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20170708/84d04b3c/attachment.sig>


More information about the Pd-dev mailing list