From Fedora Project Wiki

Revision as of 20:33, 14 November 2012 by Leamas (talk | contribs) (→‎Filtering)

Leamas's notes

Handling private libs

Guidelines basically says that private libs should be kept out of's linker path. They should also be filtered from package provides. See Filtering Private Libs

You may also end up here because of rpmlint warnings such as no-soname, private-shared-object-provides, or invalid-soname. See Common Rpmlint Issues

Lets look at the different aspects:


To display a package's soname::

   objdump -p filaname | grep SONAME

To change it, use '-Wl,-soname,<SONAME>' linker flags to gcc.


Filtering doc is at time of writing in a sad state. Unless this ticket is resolved stay away from current filtering guidelines. Instead use upstream documentation

The provides part is usually straightforward: use the %__provides_exclude_from macro to filter all libraries in the private dir:

  %global __provides_exclude_from %{_libdir}/private-lib/.*\\.so

The requires part is harder. If you filter all deps in the private dir using __requires_exclude_from you will also filter all dependencies by the private libs. This is most likely not what you want.

Alternative is to just list all libs which should be excluded. This must be done "by hand" since at the early stage when these filters are evaluated, there are no unpacked directories to scan. OTOH, we can later verify that the manual list is OK.

To filter individual object files from Requires: use something like:

  %global __requires_exclude             
  %global __requires_exclude %{__requires_exclude}|
  %global __requires_exclude %{__requires_exclude}|libraceengine.sp

To check that you really filtered all files in private lib, in %install:

   cd private-lib
   excluded=$( echo '%{__requires_exclude}' | tr '|' ':' )
   for lib in *.so; do
       if [ "${excluded/${lib}/}" = "$excluded" ]; then
           echo "ERROR: $lib not filtered in __requires_exclude" >&2
           exit 2

If simply excluding isn't enough you can roll your own find-requires e. g.,

   %define         __find_requires %{SOURCE8}

   FINDREQ=$( rpm --eval %__find_requires )
   $FINDREQ $@ | sed -e '/' -e '/' -e 's/.0d\|.1d//g'

One can redefine __find_provides the same way.


The preferred method to find the libs in the private dir is using a rpath.

To display and and change rpath use chrpath -l and chrpath -r. To replace an existing rpath with the private libs is the safest way, not depending on whatever rpath upstream sets. Note that chrpath can't add a rpath, there must already be one to work. cmake and gcc has usable options to create a rpath. Cookbook:

  cd private-lib
  for lib in *.so; do
       chrpath --replace %{_libdir}/private-lib  $lib

chrpath must be built for the architecture of the building host - chrpath.i386 doesn't work on x86_64.