[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Best practice to copy(reuse) a shared object and assign it with another SONAME?



Hi mentors,

I'm wondering if there is any shared object trick that allows me to
create some "stub" shared object that reuses all symbols from another
shared object, but has different SONAME compared to the original one.

Background:

  * We have a shared object named libopenblas.so.0, with
	SONAME being libopenblas.so.0

  * This shared object provides compatible API and ABI to libblas.so.3,
    and libopenblas.so.0 can be registered as a libblas.so.3 alternative
	through update-alternatives.

  * If a program links against libblas.so.3 (which points to
    libopenblas.so.0), dpkg-shlibdeps makes the program depend on
	openblas.

  * As a workaround, openblas[1] compiled a new openblas/libblas.so.3 shared
    object (= blas object files, and linked against libopenblas.so.0),
	with SONAME being libblas.so.3 . This shared object is the real
	libblas.so.3 (alternative) provider.

Some eligible solutions could be:

  1. duplicate the original shared object and patchelf

  2. patch upstream build system to build libblas.so.3 to save space,
     as done by [1].

  3. [not sure] maybe we can simply create some "stub" shared object that
     reuses all symbols from another shared object, but has different SONAME
     compared to the original one.

I'm thinking of "3." because:

  $ readelf -sW /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
  ...
  1091: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND ctrmm_LCUN   <- comes from another .so
  1092: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strmv_NUU
  1093: 000000000001ec80   701 FUNC    GLOBAL DEFAULT   12 ssymv_
  ...

  $ readelf -sW /usr/lib/x86_64-linux-gnu/libopenblas.so.0 | grep ctrmm_LCUN
  7379: 0000000000214ea0  1658 FUNC    GLOBAL DEFAULT   12 ctrmm_LCUN   <- the real implemtantion

  So maybe it's possible to create some stub library "stub.so", which
  looks like:

  $ <magic/trick> --output=stub.so
  $ readelf -d stub.so

    NEEDED libopenblas.so.0
	SONAME libblas.so.3

  $ readelf -sW stub.so
    
	0000000000000000 ... All BLAS (fortran) ABI
	0000000000000000 ... All CBLAS ABI


Is there such "magic/trick"? Thanks in advance.

[1] https://salsa.debian.org/science-team/openblas/blob/master/debian/patches/shared-blas-lapack.patch


Reply to: