From 0fad26312dcbd91571e75db615551d63825fab7d Mon Sep 17 00:00:00 2001 From: Thierry Streiff Date: Tue, 30 Jun 2020 15:35:14 +0200 Subject: [PATCH] Fix issue #102 by better selecting the library objectfile to merge: select only objectfiles defining globally at least one yet unresolved symbol --- ppci/binutils/linker.py | 2 +- ppci/binutils/objectfile.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ppci/binutils/linker.py b/ppci/binutils/linker.py index 41a98258..fa2fad2f 100644 --- a/ppci/binutils/linker.py +++ b/ppci/binutils/linker.py @@ -390,7 +390,7 @@ def add_missing_symbols_from_libraries(self, libraries): for library in libraries: self.logger.debug("scanning library for symbols %s", library) for obj in library: - has_sym = any(map(obj.has_symbol, undefined_symbols)) + has_sym = any(map(obj.is_defined_global, undefined_symbols)) if has_sym: self.logger.debug( "Using object file %s from library", obj diff --git a/ppci/binutils/objectfile.py b/ppci/binutils/objectfile.py index 037458d4..68205182 100644 --- a/ppci/binutils/objectfile.py +++ b/ppci/binutils/objectfile.py @@ -58,6 +58,11 @@ def defined(self): def is_global(self): return self.binding == "global" + @property + def is_defined_global(self): + """ Test if the symbol in defined and global. """ + return self.value is not None and self.binding == "global" + @property def is_function(self): """ Test if this symbol is a function. """ @@ -250,6 +255,11 @@ def has_symbol(self, name): """ Check if this object file has a symbol with name 'name' """ return name in self.symbol_map + def is_defined_global(self, name): + """ Test if the symbol "name" is defined and global in "self" """ + sym = self.symbol_map.get(name) + return sym and sym.is_defined_global + def get_symbol(self, name): """ Get a symbol """ return self.symbol_map[name]