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

IOhannes m zmölnig zmoelnig at iem.at
Fri Jul 7 10:57:05 CEST 2017


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20170707/559faaa7/attachment-0001.sig>


More information about the Pd-dev mailing list