[csw-devel] SF.net SVN: gar:[20977] csw/mgar/gar/v2/lib/python

chninkel at users.sourceforge.net chninkel at users.sourceforge.net
Sat May 4 11:30:42 CEST 2013


Revision: 20977
          http://gar.svn.sourceforge.net/gar/?rev=20977&view=rev
Author:   chninkel
Date:     2013-05-04 09:30:42 +0000 (Sat, 04 May 2013)
Log Message:
-----------
rework soname-unused to use elfdump data instead of ldd output

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/dependency_checks.py
    csw/mgar/gar/v2/lib/python/package_checks_test.py
    csw/mgar/gar/v2/lib/python/testdata/cadaver_stats.py

Modified: csw/mgar/gar/v2/lib/python/dependency_checks.py
===================================================================
--- csw/mgar/gar/v2/lib/python/dependency_checks.py	2013-05-04 08:43:13 UTC (rev 20976)
+++ csw/mgar/gar/v2/lib/python/dependency_checks.py	2013-05-04 09:30:42 UTC (rev 20977)
@@ -171,55 +171,41 @@
           pkgname, messenger)
       orphan_sonames.extend(orphan_sonames_tmp)
 
-    sonames_unused = set()
-    ldd_info = pkg_data['ldd_info'][binary_info["path"]]
-    for ldd_response in ldd_info:
-      if (ldd_response['state'] == 'soname-unused'
-          and ldd_response['soname'] not in BASE_SOLARIS_LIBRARIES
-          and ldd_response['soname'] in binary_info['needed sonames']):
-        sonames_unused.add(ldd_response['soname'])
-        messenger.Message(
-          "Binary %s links to library %s but doesn't seem to use any"
-          " of its symbols. It usually happens because superfluous"
-          " libraries were added to the linker options, either because"
-          " of the configure script itself or because of the"
-          " \"pkg-config --libs\" output of one the dependency."
-          % ("/" + binary_info["path"], ldd_response['soname']))
-        error_mgr.ReportError(
-            pkgname, "soname-unused",
-            "%s is needed by %s but never used"
-             % (ldd_response['soname'], "/" + binary_info["path"]))
-
-    # Even when direct binding is enabled, some symbols might not be
-    # directly bound because the library explicitely requested the symbol
-    # not to be drectly bound to.
-    # For example, libc.so.1 does it for symbol sigaction, free, malloc...
-    # So we consider that direct binding is enabled if at least one
-    # symbol is directly bound to because that definitely means that
-    # -B direct or -z direct was used.
+    # Some common information gathering for
+    # "direct bind" and "soname unused" checks
     binary_elf_info = pkg_data["binaries_elf_info"][binary_info["path"]]
-    libs = set(binary_info["needed sonames"])
 
-    # we skip the standard Solaris libraries: a lot of plugins only
-    # link to non directly bindable symbols of libc.so.1, librt.so.1
-    # which trigger false positives.
-    # Direct binding really matters for opencsw libraries so it's
-    # easier and riskless to just skip theses libraries
-    libs.difference_update(BASE_SOLARIS_LIBRARIES)
-
+    needed_libs = set(binary_info["needed sonames"])
     db_libs = set()
+    really_needed_libs = set()
     for syminfo in binary_elf_info['symbol table']:
-      if (syminfo['shndx'] == 'UNDEF' and syminfo['flags']
-          and 'D' in syminfo['flags'] and 'B' in syminfo['flags']):
+      if (syminfo['soname'] is not None and
+          syminfo['flags'] is not None):
+        really_needed_libs.add(syminfo['soname'])
+        # Even when direct binding is enabled, some symbols might not be
+        # directly bound because the library explicitely requested the symbol
+        # not to be directly bound to.
+        # So we consider that direct binding is enabled if at least one
+        # symbol is directly bound to the library
+        if (syminfo['shndx'] == 'UNDEF' and 'B' in syminfo['flags']):
           db_libs.add(syminfo['soname'])
-    no_db_libs = libs.difference(db_libs)
 
-    # no symbol used means no way to detect if direct binding was
-    # enabled so we must ignore the libraries which were linked
-    # without being used
-    no_db_libs.difference_update(sonames_unused)
 
+    # Direct bind check
+
+    if really_needed_libs:
+      no_db_libs = really_needed_libs.difference(db_libs)
+    else:
+      no_db_libs = needed_libs
+    # we skip the standard Solaris libraries for "direct binding"
+    # as a lot of plugins only link to non directly bindable symbols
+    # of libc.so.1, librt.so.1 which trigger false positives.
+    # This check really matters for opencsw libraries so it's
+    # easier and riskless to just skip theses libraries
+    no_db_libs.difference_update(BASE_SOLARIS_LIBRARIES)
+
     if no_db_libs:
+      no_db_libs = sorted(no_db_libs)
       messenger.Message(
         "No symbol of binary %s is directly bound against the following"
         " libraries: %s. Please make sure the binaries are compiled using"
@@ -231,7 +217,42 @@
           "%s is not directly bound to soname %s"
            % ("/" + binary_info["path"], soname))
 
+    # Unused soname check
 
+    if really_needed_libs:
+      unused_libs = needed_libs.difference(really_needed_libs)
+      # we skip the standard Solaris libraries for "unused soname"
+      # as base solaris libraries are often linked by default by
+      # build system and such dependency is harmless
+      unused_libs.difference_update(BASE_SOLARIS_LIBRARIES)
+
+      if unused_libs:
+        unused_libs = sorted(unused_libs)
+        messenger.Message(
+          "Although it is linked against, binary %s doesn't use any symbols"
+          " of the following libraries: %s. It usually happens because"
+          " superfluous libraries were added to the linker options, either"
+          " because of the configure script itself or because of the"
+          " \"pkg-config --libs\" output of one the dependency."
+          % ("/" + binary_info["path"], ", ".join(unused_libs)))
+        for soname in unused_libs:
+          error_mgr.ReportError(
+            pkgname, "soname-unused",
+            "%s is needed by %s but never used"
+            % (soname, "/" + binary_info["path"]))
+
+    else:
+      # No "really needed libs" means either:
+      #  - 1. the binary was entirely static.
+      #  - 2. symbol information table was not present,
+      #
+      # Case 1 implies that we do not have any linking error possible
+      # Case 2 implies that we will not able to know against which
+      # library a symbol is linked, so we will not able to check
+      # if no symbol of a library is not used.
+      # We should then emulate ldd but that will not be for today...
+      pass
+
     for version_dep in binary_elf_info['version needed']:
       if (version_dep['soname'] in ALLOWED_VERSION_DEPENDENCIES and
           not version_dep['version'] in

Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py	2013-05-04 08:43:13 UTC (rev 20976)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py	2013-05-04 09:30:42 UTC (rev 20977)
@@ -1474,8 +1474,7 @@
       self.error_mgr_mock.NeedFile(
           mox.IsA(str), mox.IsA(str), mox.IsA(str))
 
-    for soname in [ 'libcurses.so.1', 'libz.so.1', 'libssl.so.1.0.0',
-		    'libcrypto.so.1.0.0', 'libexpat.so.1' ]:
+    for soname in [ 'libintl.so.8' ]:
       self.error_mgr_mock.ReportError(
         'CSWcadaver', 'soname-unused',
         soname + ' is needed by /opt/csw/bin/cadaver but never used')
@@ -1516,8 +1515,8 @@
       self.error_mgr_mock.GetPkgByPath(common_path).AndReturn([u"CSWcommon"])
 
     for soname in [ 'libnsl.so.1', 'libpam.so.1', 'libsocket.so.1', 'librt.so.1',
-		    'libsendfile.so.1', 'libssl.so.1.0.0', 'libcrypto.so.1.0.0',
-		    'libc.so.1' ]:
+        'libsendfile.so.1', 'libssl.so.1.0.0', 'libcrypto.so.1.0.0',
+        'libc.so.1' ]:
       self.error_mgr_mock.NeedFile(
           mox.IsA(str), mox.IsA(str), mox.IsA(str))
 
@@ -1569,8 +1568,8 @@
       self.error_mgr_mock.NeedFile(
           mox.IsA(str), mox.IsA(str), mox.IsA(str))
 
-    for soname in ['libsendfile.so.1', 'libssl.so.1.0.0', 'libcrypto.so.1.0.0',
-        'libpam.so.1']:
+    for soname in ['libcrypto.so.1.0.0', 'libpam.so.1', 'libsendfile.so.1',
+        'libssl.so.1.0.0']:
       self.error_mgr_mock.ReportError(
         'CSWvsftpd',
         'no-direct-binding',

Modified: csw/mgar/gar/v2/lib/python/testdata/cadaver_stats.py
===================================================================
--- csw/mgar/gar/v2/lib/python/testdata/cadaver_stats.py	2013-05-04 08:43:13 UTC (rev 20976)
+++ csw/mgar/gar/v2/lib/python/testdata/cadaver_stats.py	2013-05-04 09:30:42 UTC (rev 20977)
@@ -87,11 +87,6 @@
                                                                  {'bind': 'GLOB',
                                                                   'flags': 'DBL',
                                                                   'shndx': 'UNDEF',
-                                                                  'soname': 'libintl.so.8',
-                                                                  'symbol': 'foo'},
-                                                                 {'bind': 'GLOB',
-                                                                  'flags': 'DBL',
-                                                                  'shndx': 'UNDEF',
                                                                   'soname': 'libneon.so.27',
                                                                   'symbol': 'foo'},
                                                                  {'bind': 'GLOB',

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list