summaryrefslogtreecommitdiff
path: root/rld-files.cpp
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2012-12-29 10:20:22 +1100
committerChris Johns <chrisj@rtems.org>2012-12-29 10:20:22 +1100
commitcc54579b0b54bd349f1d69f40aa89607e32bf614 (patch)
tree8d5fef66763090ebab459497d7302d0111b8e988 /rld-files.cpp
parent0123e92cdeb732ae20c3a69047c7d05877cb0318 (diff)
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.
Diffstat (limited to 'rld-files.cpp')
-rw-r--r--rld-files.cpp70
1 files changed, 63 insertions, 7 deletions
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)
{