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

[PATCH 2/2] avoid failure on symbol provided by application



From: Yuanjie Huang <yuanjie.huang@windriver.com>

Undefined symbols in a library can be provided by the application
that links to the library, such as `logsink' in libmultipath.so.0.
This fix checks the type of object in which the symbol is needed
and the existence of the symbol in application, when a symbol
cannot be provided by libraries. It prevents false alarm on absence
of symbols.

Signed-off-by: Yuanjie Huang <yuanjie.huang@windriver.com>
---
 src/mklibs | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/mklibs b/src/mklibs
index 1f3d60f..b898b61 100755
--- a/src/mklibs
+++ b/src/mklibs
@@ -133,9 +133,9 @@ class Symbol(object):
         return '@'.join(ret)
 
 class UndefinedSymbol(Symbol):
-    def __init__(self, name, weak, version, library):
+    def __init__(self, name, weak, version, library, object):
         super(UndefinedSymbol, self).__init__(name, version, library)
-        self.weak, self.library = weak, library
+        self.weak, self.library, self.object = weak, library, object
 
 def symbol_is_blacklisted(name):
     # The ARM Embedded ABI spec states symbols under this namespace as
@@ -152,6 +152,11 @@ def undefined_symbols(obj):
 
     output = command("mklibs-readelf", "--print-symbols-undefined", obj)
 
+    if len(obj) > len(dest_path) and obj[:len(dest_path)] == dest_path:
+        object = obj[len(dest_path) + 1:-len('-so-stripped')]
+    else:
+        object = obj
+
     result = []
     for line in output:
         name, weak_string, version_string, library_string = line.split()[:4]
@@ -171,7 +176,7 @@ def undefined_symbols(obj):
         if library_string.lower() != 'none':
             library = library_string
 
-        result.append(UndefinedSymbol(name, weak, version, library))
+        result.append(UndefinedSymbol(name, weak, version, library, object))
 
     return result
 
@@ -498,12 +503,13 @@ while 1:
                      and re.search("^ps_", str(symbol)))
                 and not (re.search("ld-linux.so.3$", str(symbol)))
                 and not (re.search("^__gnu_local_gp", str(symbol)))):
-                debug(DEBUG_SPAM, "needed_symbols adding %s, weak: %s" % (symbol, symbol.weak))
+                debug(DEBUG_SPAM, "needed_symbols adding %s, weak: %s, for %s" % (symbol, symbol.weak, obj))
                 needed_symbols[str(symbol)] = symbol
         libraries.update(library_depends(obj))
 
     # calculate what symbols are present in small_libs and available_libs
     present_symbols = {}
+    present_symbol_progs = {}
     checked_libs = small_libs
     checked_libs.extend(available_libs)
     checked_libs.append(ldlib)
@@ -513,6 +519,12 @@ while 1:
             names = symbol.base_names()
             for name in names:
                 present_symbols[name] = symbol
+            if not so_pattern.match(lib):
+                debug(DEBUG_SPAM, "present_symbol_progs adding %s, from executable %s" % (' '.join(names), lib))
+                for name in names:
+                    progs = present_symbol_progs.get(name, set())
+                    progs.add(lib)
+                    present_symbol_progs[name] = progs
 
     # are we finished?
     num_unresolved = 0
@@ -568,6 +580,14 @@ while 1:
     for name in needed_symbols:
         if not name in symbol_provider:
             if not needed_symbols[name].weak:
+                # WORKAROUND: Undefined symbols in a library can be provided by the application
+                # that links to the library. So if the object which requires the symbol is a library
+                # and some application can provide the symbol, the undefined symbol is skipped.
+                symbol = needed_symbols[name]
+                if so_pattern.match(symbol.object) and present_symbol_progs.get(name, None):
+                    debug(DEBUG_SPAM, "symbol %s in library %s is provided by executable %s" \
+                          % (name, symbol.object, ' '.join(present_symbol_progs[name])))
+                    continue
                 raise Exception("No library provides non-weak %s" % name)
         else:
             lib = symbol_provider[name]
-- 
1.9.1



Reply to: