#include "elfcpp.h"
#include "fileread.h"
+#include "readsyms.h"
#include "symtab.h"
#include "object.h"
#include "archive.h"
const char Archive::arfmag[2] = { '`', '\n' };
-// Get a view into the underlying file.
-
-const unsigned char*
-Archive::get_view(off_t start, off_t size)
-{
- return this->input_file_->file().get_view(start, size);
-}
-
// Set up the archive: read the symbol map and the extended name
// table.
// Numbers in the armap are always big-endian.
const elfcpp::Elf_Word* pword = reinterpret_cast<const elfcpp::Elf_Word*>(p);
- unsigned int nsyms = elfcpp::read_elf_word<true>(pword);
+ unsigned int nsyms = elfcpp::Swap<32, true>::readval(pword);
++pword;
// Note that the addition is in units of sizeof(elfcpp::Elf_Word).
for (unsigned int i = 0; i < nsyms; ++i)
{
this->armap_[i].name = pnames;
- this->armap_[i].offset = elfcpp::read_elf_word<true>(pword);
+ this->armap_[i].offset = elfcpp::Swap<32, true>::readval(pword);
pnames += strlen(pnames) + 1;
++pword;
}
this->extended_names_.assign(px, extended_size);
}
+ // This array keeps track of which symbols are for archive elements
+ // which we have already included in the link.
+ this->seen_.resize(nsyms);
+
// Opening the file locked it. Unlock it now.
this->input_file_->file().unlock();
}
// may be satisfied by other objects in the archive.
void
-Archive::add_symbols(Symbol_table* symtab, Layout* layout,
- Input_objects* input_objects)
+Archive::add_symbols(const General_options& options, Symbol_table* symtab,
+ Layout* layout, Input_objects* input_objects)
{
- size_t armap_size = this->armap_.size();
- std::vector<bool> seen;
- seen.resize(this->armap_.size());
- seen.clear();
+ const size_t armap_size = this->armap_.size();
bool added_new_object;
do
off_t last = -1;
for (size_t i = 0; i < armap_size; ++i)
{
- if (seen[i])
+ if (this->seen_[i])
continue;
if (this->armap_[i].offset == last)
{
- seen[i] = true;
+ this->seen_[i] = true;
continue;
}
Symbol* sym = symtab->lookup(this->armap_[i].name);
if (sym == NULL)
continue;
- else if (sym->shnum() != elfcpp::SHN_UNDEF)
+ else if (!sym->is_undefined())
{
- seen[i] = true;
+ this->seen_[i] = true;
continue;
}
else if (sym->binding() == elfcpp::STB_WEAK)
// We want to include this object in the link.
last = this->armap_[i].offset;
- this->include_member(symtab, layout, input_objects, last);
+ this->include_member(options, symtab, layout, input_objects, last);
+ this->seen_[i] = true;
added_new_object = true;
}
}
// the member header.
void
-Archive::include_member(Symbol_table* symtab, Layout* layout,
- Input_objects* input_objects, off_t off)
+Archive::include_member(const General_options& options, Symbol_table* symtab,
+ Layout* layout, Input_objects* input_objects,
+ off_t off)
{
std::string n;
this->read_header(off, &n);
Read_symbols_data sd;
obj->read_symbols(&sd);
- obj->layout(layout, &sd);
+ obj->layout(options, symtab, layout, &sd);
obj->add_symbols(symtab, &sd);
}
{
public:
Add_archive_symbols_locker(Task_token& token, Workqueue* workqueue,
- Archive* archive)
- : blocker_(token, workqueue), archlock_(*archive)
+ File_read& file)
+ : blocker_(token, workqueue), filelock_(file)
{ }
private:
Task_locker_block blocker_;
- Task_locker_obj<Archive> archlock_;
+ Task_locker_obj<File_read> filelock_;
};
Task_locker*
{
return new Add_archive_symbols_locker(*this->next_blocker_,
workqueue,
- this->archive_);
+ this->archive_->file());
}
void
Add_archive_symbols::run(Workqueue*)
{
- this->archive_->add_symbols(this->symtab_, this->layout_,
+ this->archive_->add_symbols(this->options_, this->symtab_, this->layout_,
this->input_objects_);
+
+ if (this->input_group_ != NULL)
+ this->input_group_->add_archive(this->archive_);
+ else
+ {
+ // We no longer need to know about this archive.
+ delete this->archive_;
+ }
}
} // End namespace gold.