X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gold%2Farchive.cc;h=6d259803185368ccbe3b71cda4040d90105b66d3;hb=cd6faa73f8e3b888ee8b73a733382a5587aca202;hp=23cb0be30019b9d94d30ec14aba98d8692be3065;hpb=4b95cf5c0c75d6efc1b2f96af72317aecca079f1;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/archive.cc b/gold/archive.cc index 23cb0be300..6d25980318 100644 --- a/gold/archive.cc +++ b/gold/archive.cc @@ -1,6 +1,6 @@ // archive.cc -- archive support for gold -// Copyright (C) 2006-2014 Free Software Foundation, Inc. +// Copyright (C) 2006-2015 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -930,6 +930,32 @@ Archive::count_members() return ret; } +// RAII class to ensure we unlock the object if it's a member of a +// thin archive. We can't use Task_lock_obj in Archive::include_member +// because the object file is already locked when it's opened by +// get_elf_object_for_member. + +class Thin_archive_object_unlocker +{ + public: + Thin_archive_object_unlocker(const Task *task, Object* obj) + : task_(task), obj_(obj) + { } + + ~Thin_archive_object_unlocker() + { + if (this->obj_->offset() == 0) + this->obj_->unlock(this->task_); + } + + private: + Thin_archive_object_unlocker(const Thin_archive_object_unlocker&); + Thin_archive_object_unlocker& operator=(const Thin_archive_object_unlocker&); + + const Task* task_; + Object* obj_; +}; + // Include an archive member in the link. OFF is the file offset of // the member header. WHY is the reason we are including this member. // Return true if we added the member or if we had an error, return @@ -978,6 +1004,10 @@ Archive::include_member(Symbol_table* symtab, Layout* layout, return unconfigured ? false : true; } + // If the object is an external member of a thin archive, + // unlock it when we're done here. + Thin_archive_object_unlocker unlocker(this->task_, obj); + if (mapfile != NULL) mapfile->report_include_archive_member(obj->name(), sym, why); @@ -991,31 +1021,21 @@ Archive::include_member(Symbol_table* symtab, Layout* layout, if (!input_objects->add_object(obj)) { - // If this is an external member of a thin archive, unlock the - // file. - if (obj->offset() == 0) - obj->unlock(this->task_); delete obj; + return true; } - else - { - { - if (layout->incremental_inputs() != NULL) - layout->incremental_inputs()->report_object(obj, 0, this, NULL); - Read_symbols_data sd; - obj->read_symbols(&sd); - obj->layout(symtab, layout, &sd); - obj->add_symbols(symtab, &sd, layout); - } - - // If this is an external member of a thin archive, unlock the file - // for the next task. - if (obj->offset() == 0) - obj->unlock(this->task_); - this->included_member_ = true; - } + if (layout->incremental_inputs() != NULL) + layout->incremental_inputs()->report_object(obj, 0, this, NULL); + + { + Read_symbols_data sd; + obj->read_symbols(&sd); + obj->layout(symtab, layout, &sd); + obj->add_symbols(symtab, &sd, layout); + } + this->included_member_ = true; return true; }