[vlc-devel] [PATCH] bank: enable static modules for mach-o binaries

Alexandre Janniaux ajanni at videolabs.io
Thu Mar 12 16:55:06 CET 2020


Actually forget about the «however» part, it was already
the case in static build.

Regards,
--
Alexandre Janniaux
Videolabs

On Thu, Mar 12, 2020 at 04:40:37PM +0100, Alexandre Janniaux wrote:
> Hi,
>
> I checked whether it was working for MacOSX and I was able to
> define static modules by adding the following ugly but self
> contained snippet in the darwinvlc.m file:
>
> ```
> int foo(int (*set)(void*,void*,int,...), void*bar)
> {
>     fprintf(stderr, "OK\n");
>     abort();
> }
>
> __attribute__((visibility("default")))
> extern int (*vlc_static_modules[])(int (*)(void*,void*,int,...), void*);
>
> int (*vlc_static_modules[])(int (*)(void*,void*,int,...), void*) =
> {
>     foo,
>     NULL,
> };
> ```
>
> It also create archives correctly in iOS, but I haven't
> checked TVOS.
>
> However, it would fail if the symbols are not defined when
> linking the static archive to the binary or to dynamic VLCKit.
>
> I assumed it could be considered more of a feature than a bug
> as LibVLC cannot work without the mandatory modules anyway.
>
> Regards,
> --
> Alexandre Janniaux
> Videolabs
>
> On Thu, Mar 12, 2020 at 04:35:40PM +0100, Alexandre Janniaux wrote:
> > Static modules are available by overriding the vlc_static_modules
> > symbol in the executable. To avoid exposing this feature by forcing the
> > user to declare this symbol regardless of whether it was needed or not,
> > it was only defined on ELF binaries which supports the weak attributes
> > or when dynamic plugins are disabled as it becomes the only (thus
> > mandatory) way to define plugins.
> >
> > Mach-O objects are also capable to define weak symbols, like defined
> > for the VLC_WEAK symbol in the vlc_common.h file so also allow this
> > mechanism when producing Mach-O objects.
> >
> > It is particularly useful to ship battery-included LibVLC builds and
> > still allow external plugins in paths controlled by the application
> > using the library.
> > ---
> >  src/Makefile.am    | 2 +-
> >  src/modules/bank.c | 7 ++++++-
> >  2 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/Makefile.am b/src/Makefile.am
> > index 2b4dfcb7dd..bf2cb7e40d 100644
> > --- a/src/Makefile.am
> > +++ b/src/Makefile.am
> > @@ -543,7 +543,7 @@ $(libvlccore_la_OBJECTS): libvlccore_objc.la
> >  libvlccore_objc_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-arc
> >  libvlccore_objc_la_LDFLAGS = -static
> >  libvlccore_la_LIBADD += libvlccore_objc.la
> > -libvlccore_la_LDFLAGS +=  -Wl,-framework,Foundation -Xlinker -install_name -Xlinker @rpath/libvlccore.dylib
> > +libvlccore_la_LDFLAGS +=  -Wl,-framework,Foundation -Xlinker -install_name -Xlinker @rpath/libvlccore.dylib -Wl,-U,_vlc_static_modules
> >  endif
> >
> >  libvlc_win32_rc.$(OBJEXT): libvlc_win32_rc.rc $(top_srcdir)/extras/package/win32/libvlc.dll.manifest
> > diff --git a/src/modules/bank.c b/src/modules/bank.c
> > index 36c4b30cdd..a880eea6e9 100644
> > --- a/src/modules/bank.c
> > +++ b/src/modules/bank.c
> > @@ -172,7 +172,12 @@ static vlc_plugin_t *module_InitStatic(vlc_plugin_cb entry)
> >      return lib;
> >  }
> >
> > -#if defined(__ELF__) || !HAVE_DYNAMIC_PLUGINS
> > +/* With weak linking in __ELF__, there is no need to provide a definition
> > + * of vlc_static_modules at build time and it will be evaluated to NULL if
> > + * not provided at runtime. However, although __MACH__ implies the same runtime
> > + * consequences for weak linking, it will still require the definition to exist
> > + * at build time. To workaround this, we add -Wl,-U,vlc_static_modules. */
> > +#if defined(__ELF__) || defined(__MACH__) || !HAVE_DYNAMIC_PLUGINS
> >  VLC_WEAK
> >  extern vlc_plugin_cb vlc_static_modules[];
> >
> > --
> > 2.25.1
> >


More information about the vlc-devel mailing list