Better handling of archive open/close and begin/end.

This commit is contained in:
Chris Johns 2012-11-18 07:37:02 +11:00
parent 065ac15a40
commit f1cf3a9dd3

View File

@ -546,11 +546,14 @@ namespace rld
archive::~archive () archive::~archive ()
{ {
end ();
close (); close ();
} }
void void
archive::begin () archive::begin ()
{
if (references () == 1)
{ {
elf ().begin (name ().full (), fd ()); elf ().begin (name ().full (), fd ());
@ -561,10 +564,12 @@ namespace rld
throw rld::error ("Not an archive.", throw rld::error ("Not an archive.",
"archive-begin:" + name ().full ()); "archive-begin:" + name ().full ());
} }
}
void void
archive::end () archive::end ()
{ {
if (references () == 1)
elf ().end (); elf ().end ();
} }
@ -875,9 +880,6 @@ namespace rld
void void
object::open () object::open ()
{ {
if (rld::verbose () >= RLD_VERBOSE_TRACE)
std::cout << "object::open: " << name ().full () << std::endl;
if (archive_) if (archive_)
archive_->open (); archive_->open ();
else else
@ -887,14 +889,17 @@ namespace rld
void void
object::close () object::close ()
{ {
if (rld::verbose () >= RLD_VERBOSE_TRACE)
std::cout << "object::close: " << name ().full () << std::endl;
if (archive_) if (archive_)
{
archive_->end ();
archive_->close (); archive_->close ();
}
else else
{
end ();
image::close (); image::close ();
} }
}
void void
object::begin () object::begin ()
@ -1215,6 +1220,13 @@ namespace rld
void void
cache::load_symbols (rld::symbols::table& symbols, bool local) cache::load_symbols (rld::symbols::table& symbols, bool local)
{ {
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << "cache:load-sym: object files: " << objects_.size ()
<< std::endl;
try
{
archives_begin ();
for (objects::iterator oi = objects_.begin (); for (objects::iterator oi = objects_.begin ();
oi != objects_.end (); oi != objects_.end ();
++oi) ++oi)
@ -1227,6 +1239,18 @@ namespace rld
obj->close (); obj->close ();
} }
} }
catch (...)
{
archives_end ();
throw;
}
archives_end ();
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << "cache:load-sym: symbols: " << symbols.size ()
<< std::endl;
}
void void
cache::output_unresolved_symbols (std::ostream& out) cache::output_unresolved_symbols (std::ostream& out)