From cc54579b0b54bd349f1d69f40aa89607e32bf614 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Sat, 29 Dec 2012 10:20:22 +1100 Subject: Fix managing weak symbols. Weak symbols where not being managed correctly. The symbols table is now a class with externals and weaks as separate symtabs so the externals can be searched first then the weaks and if not found an unresolved error is raised. This was found creating a libbsdport RAP file where the drivers in the all driver table resolved to the weak symbols and so linking in nothing. Fixing the weak symbols as found in the libbsdport library triggered a new resolver bug. The object files now contain the resolver state and this is used to determine if an object file has been resolved or is currently being resolved avoiding rescursive loops with dependent object files. The resolver trace output is a little easier to read. --- rld-files.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 7 deletions(-) (limited to 'rld-files.cpp') diff --git a/rld-files.cpp b/rld-files.cpp index 75860ba..9887e48 100644 --- a/rld-files.cpp +++ b/rld-files.cpp @@ -979,7 +979,9 @@ namespace rld object::object (archive& archive_, file& name_) : image (name_), archive_ (&archive_), - valid_ (false) + valid_ (false), + resolving_ (false), + resolved_ (false) { if (!name ().is_valid ()) throw rld_error_at ("name is empty"); @@ -988,7 +990,9 @@ namespace rld object::object (const std::string& path) : image (path), archive_ (0), - valid_ (false) + valid_ (false), + resolving_ (false), + resolved_ (false) { if (!name ().is_valid ()) throw rld_error_at ("name is empty"); @@ -996,7 +1000,9 @@ namespace rld object::object () : archive_ (0), - valid_ (false) + valid_ (false), + resolving_ (false), + resolved_ (false) { } @@ -1116,7 +1122,7 @@ namespace rld rld::symbols::pointers syms; - elf ().get_symbols (syms, false, local); + elf ().get_symbols (syms, false, local, false, true); if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS) std::cout << "object:load-sym: exported: total " @@ -1132,11 +1138,31 @@ namespace rld std::cout << "object:load-sym: exported: " << sym << std::endl; sym.set_object (*this); - symbols[sym.name ()] = &sym; + symbols.add_external (sym); externals.push_back (&sym); } - elf ().get_symbols (syms, true); + elf ().get_symbols (syms, false, false, true, false); + + if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS) + std::cout << "object:load-sym: weak: total " + << syms.size () << std::endl; + + for (symbols::pointers::iterator si = syms.begin (); + si != syms.end (); + ++si) + { + symbols::symbol& sym = *(*si); + + if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS) + std::cout << "object:load-sym: weak: " << sym << std::endl; + + sym.set_object (*this); + symbols.add_weak (sym); + externals.push_back (&sym); + } + + elf ().get_symbols (syms, true, false, true, true); if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS) std::cout << "object:load-sym: unresolved: total " @@ -1215,7 +1241,7 @@ namespace rld return archive_; } - rld::symbols::table& + rld::symbols::symtab& object::unresolved_symbols () { return unresolved; @@ -1281,6 +1307,36 @@ namespace rld "' not found: " + name ().full (), "object::get-section"); } + void + object::resolve_set () + { + resolving_ = true; + } + + void + object::resolve_clear () + { + resolving_ = false; + } + + bool + object::resolving () const + { + return resolving_; + } + + void + object::resolved_set () + { + resolved_ = true; + } + + bool + object::resolved () const + { + return resolved_; + } + cache::cache () : opened (false) { -- cgit v1.2.3