On Thu, Aug 11 2022, Stuart Henderson <[email protected]> wrote:
> Moving from ports@.
>
> Quick intro:
>
> A library (gstreamer1) uses functions from another library (libsoup)
> which exists in two incompatible versions (libsoup-2.4.so.XX and
> libsoup-3.0.so.XX).
>
> Other software calling gstreamer might use one or other of these two
> libsoups for its own purposes, so gstreamer has been written to work
> with either version of libsoup, but it needs to know which it should
> use.
>
> the text below from my ports@ mail follows on:
>
>> gstreamer is supposed to detect a libsoup which is already loaded into the
>> address space (by using dlopen() with RTLD_NOLOAD to test this) and adapts
>> itself to use the appropriate libsoup API+ABI. It does this specifically
>> to avoid this type of conflict. Only if it can't find a copy of libsoup2
>> or libsoup3 already loaded does it use its own preference order (libsoup3
>> by default) and dlopen()s it (via g_module_open) itself.
>> 
>> (see gst_soup_load_library() in ext/soup/gstsouploader.c from
>> gstreamer1/plugins-good).
>> 
>> But we don't have RTLD_NOLOAD so this trick doesn't work...
>
> ... gstreamer code for this is at
> https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/subprojects/gst-plugins-good/ext/soup/gstsouploader.c#L146
>
> Brad pointed me at a diff from guenther@ adding RTLD_NOLOAD (and
> RTLD_NODELETE, written before semarie's version of RTLD_NODELETE):
> https://marc.info/?l=openbsd-tech&m=162068525021512&w=2
>
> With this applied and gstreamer1-plugins-good rebuilt, the code in
> gst_soup_load_library works as expected.
>
> I've included the rebased diff below and added a simple regress test
> that I wrote, loosely based on the rtld_nodelete test plus what
> gstreamer1 is doing.
>
> Looking around some other ports (it's difficult to do a proper search
> because it shows up in rust's translated version of dlfcn.h for various
> OS which ends up vendored into various trees) I see some optional use
> in a few ports e.g. asterisk ("Check to see if the given resource is
> loaded") and vlc (I think this is trying to load a linux v4l2 library
> only if not already loaded but allow it to fail gracefully).
>
> Is this something we want?

I think so.  The code looks good, would support a valid (IMO) use case
and would get us rid of a few patches and possibly blocking problems in
ports.

ok jca@

(I'm not sure it would help in the audio/quodlibet case, even after
patching the hardcoded sonames.)

One tweak below,

[...]

> Index: regress/libexec/ld.so/noload/test1/Makefile
> ===================================================================
> RCS file: regress/libexec/ld.so/noload/test1/Makefile
> diff -N regress/libexec/ld.so/noload/test1/Makefile
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ regress/libexec/ld.so/noload/test1/Makefile       11 Aug 2022 09:38:48 
> -0000
> @@ -0,0 +1,32 @@
> +# $OpenBSD$
> +
> +.include <bsd.obj.mk>
> +
> +PROG =       test1
> +
> +LIBADIR !=   if test -d ${.CURDIR}/../liba/${__objdir}; then \
> +                     echo "${.CURDIR}/../liba/${__objdir}";  \
> +             else                                            \
> +                     echo "${.CURDIR}/../liba";              \
> +             fi
> +
> +LIBBDIR !=   if test -d ${.CURDIR}/../libb/${__objdir}; then \
> +                     echo "${.CURDIR}/../libb/${__objdir}";  \
> +             else                                            \
> +                     echo "${.CURDIR}/../libb";              \
> +             fi
> +
> +LIBANAME =   ${LIBADIR}/liba.so.0.0
> +LIBBNAME =   ${LIBBDIR}/libb.so.0.0
> +
> +CFLAGS +=    -DLIBANAME=\"${LIBANAME}\" \
> +             -DLIBBNAME=\"${LIBBNAME}\"
> +
> +REGRESS_TARGETS += run-regress
> +
> +run-regress: ${PROG}
> +     if ${PROG} | grep found; then echo failed; exit 1; fi
> +     LD_PRELOAD=${LIBANAME} ${PROG} | grep ${LIBANAME}.found
> +     LD_PRELOAD=${LIBBNAME} ${PROG} | grep ${LIBBNAME}.found
> +
> +.include <bsd.regress.mk>

This fails if . is not in PATH, could you please use ./${PROG}?

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to