justinfrankel / WDL

WDL (by Cockos) mirror
http://www.cockos.com/wdl
418 stars 57 forks source link

swell-linux: ensure LD lazily binds symbols #22

Closed zx2c4 closed 6 months ago

zx2c4 commented 6 months ago

On newer toolchains that by default set -Wl,-z,now, such as Gentoo's 23.0 toolchain, setting PRELOAD_GDK causes swell's dlopen() to fail with an error like:

Error loading '/opt/REAPER/libSwell.so': /opt/REAPER/libSwell.so: undefined symbol: gdk_x11_window_get_xid

This is because -z,now, according to the man page, "When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is loaded by dlopen, instead of deferring function call resolution to the point when the function is first called." This is basically the opposite of what swell's preloading feature wants.

This can be overridden by setting -z,lazy, which according to the man page, "When generating an executable or shared library, mark it to tell the dynamic linker to defer function call resolution to the point when the function is called (lazy binding), rather than at load time."

So pass -Wl,-z,lazy in the preloading case, so that it works no matter what the toolchain defaults are.

zx2c4 commented 6 months ago

@cfillion I don't know if @justinfrankel usually uses Github for sending patches. Should I hang tight here, or would it make sense for me to drop something in the REAPER forums?

zx2c4 commented 6 months ago

Oh, thanks for merging. The reason I was wondering was because I noticed all the commits are in the form of "{message} - from {hash}", which made me think maybe there's a better way to submit patches and then you have something automatic that extracts commits from some private cockos repo and pushes them here. Anyway, Gentoo is now using this as of https://github.com/gentoo/gentoo/commit/d81e904c7818b8e5017630958243770b7fe4fc56