Remove get_view_and_size.
This commit is contained in:
parent
ba45d2478b
commit
bae3688d8f
5 changed files with 25 additions and 54 deletions
|
@ -328,10 +328,11 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout,
|
||||||
off_t off = sarmag;
|
off_t off = sarmag;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
unsigned char hdr_buf[sizeof(Archive_header)];
|
||||||
off_t bytes;
|
off_t bytes;
|
||||||
const unsigned char* p = this->get_view_and_size(off,
|
this->input_file_->file().read_up_to(off, sizeof(Archive_header),
|
||||||
sizeof(Archive_header),
|
hdr_buf, &bytes);
|
||||||
&bytes);
|
|
||||||
if (bytes < sizeof(Archive_header))
|
if (bytes < sizeof(Archive_header))
|
||||||
{
|
{
|
||||||
if (bytes != 0)
|
if (bytes != 0)
|
||||||
|
@ -345,7 +346,8 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Archive_header* hdr = reinterpret_cast<const Archive_header*>(p);
|
const Archive_header* hdr =
|
||||||
|
reinterpret_cast<const Archive_header*>(hdr_buf);
|
||||||
std::string name;
|
std::string name;
|
||||||
off_t size = this->interpret_header(hdr, off, &name);
|
off_t size = this->interpret_header(hdr, off, &name);
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
|
@ -379,9 +381,9 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
|
||||||
|
|
||||||
// Read enough of the file to pick up the entire ELF header.
|
// Read enough of the file to pick up the entire ELF header.
|
||||||
int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
|
int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
|
||||||
|
unsigned char ehdr_buf[ehdr_size];
|
||||||
off_t bytes;
|
off_t bytes;
|
||||||
const unsigned char* p =
|
this->input_file_->file().read_up_to(memoff, ehdr_size, ehdr_buf, &bytes);
|
||||||
this->input_file_->file().get_view_and_size(memoff, ehdr_size, &bytes);
|
|
||||||
if (bytes < 4)
|
if (bytes < 4)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
|
fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
|
||||||
|
@ -395,7 +397,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
|
||||||
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
|
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
|
||||||
elfcpp::ELFMAG2, elfcpp::ELFMAG3
|
elfcpp::ELFMAG2, elfcpp::ELFMAG3
|
||||||
};
|
};
|
||||||
if (memcmp(p, elfmagic, 4) != 0)
|
if (memcmp(ehdr_buf, elfmagic, 4) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
|
fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
|
||||||
program_name, this->name().c_str(),
|
program_name, this->name().c_str(),
|
||||||
|
@ -405,7 +407,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
|
||||||
|
|
||||||
Object* obj = make_elf_object((std::string(this->input_file_->filename())
|
Object* obj = make_elf_object((std::string(this->input_file_->filename())
|
||||||
+ "(" + n + ")"),
|
+ "(" + n + ")"),
|
||||||
this->input_file_, memoff, p, bytes);
|
this->input_file_, memoff, ehdr_buf, bytes);
|
||||||
|
|
||||||
input_objects->add_object(obj);
|
input_objects->add_object(obj);
|
||||||
|
|
||||||
|
|
|
@ -101,10 +101,6 @@ class Archive
|
||||||
get_view(off_t start, off_t size)
|
get_view(off_t start, off_t size)
|
||||||
{ return this->input_file_->file().get_view(start, size); }
|
{ return this->input_file_->file().get_view(start, size); }
|
||||||
|
|
||||||
const unsigned char*
|
|
||||||
get_view_and_size(off_t start, off_t size, off_t* pbytes)
|
|
||||||
{ return this->input_file_->file().get_view_and_size(start, size, pbytes); }
|
|
||||||
|
|
||||||
// Read the archive symbol map.
|
// Read the archive symbol map.
|
||||||
void
|
void
|
||||||
read_armap(off_t start, off_t size);
|
read_armap(off_t start, off_t size);
|
||||||
|
|
|
@ -239,7 +239,7 @@ File_read::read_up_to(off_t start, off_t size, void* p, off_t* pbytes)
|
||||||
// Find an existing view or make a new one.
|
// Find an existing view or make a new one.
|
||||||
|
|
||||||
File_read::View*
|
File_read::View*
|
||||||
File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
|
File_read::find_or_make_view(off_t start, off_t size)
|
||||||
{
|
{
|
||||||
gold_assert(this->lock_count_ > 0);
|
gold_assert(this->lock_count_ > 0);
|
||||||
|
|
||||||
|
@ -254,11 +254,7 @@ File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
|
||||||
// There was an existing view at this offset.
|
// There was an existing view at this offset.
|
||||||
File_read::View* v = ins.first->second;
|
File_read::View* v = ins.first->second;
|
||||||
if (v->size() - (start - v->start()) >= size)
|
if (v->size() - (start - v->start()) >= size)
|
||||||
{
|
return v;
|
||||||
if (pbytes != NULL)
|
|
||||||
*pbytes = size;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This view is not large enough.
|
// This view is not large enough.
|
||||||
this->saved_views_.push_back(v);
|
this->saved_views_.push_back(v);
|
||||||
|
@ -277,17 +273,7 @@ File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
|
||||||
ins.first->second = v;
|
ins.first->second = v;
|
||||||
|
|
||||||
if (bytes - (start - poff) >= size)
|
if (bytes - (start - poff) >= size)
|
||||||
{
|
return v;
|
||||||
if (pbytes != NULL)
|
|
||||||
*pbytes = size;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pbytes != NULL)
|
|
||||||
{
|
|
||||||
*pbytes = bytes - (start - poff);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
_("%s: %s: file too short: read only %lld of %lld bytes at %lld\n"),
|
_("%s: %s: file too short: read only %lld of %lld bytes at %lld\n"),
|
||||||
|
@ -306,15 +292,7 @@ const unsigned char*
|
||||||
File_read::get_view(off_t start, off_t size)
|
File_read::get_view(off_t start, off_t size)
|
||||||
{
|
{
|
||||||
gold_assert(this->lock_count_ > 0);
|
gold_assert(this->lock_count_ > 0);
|
||||||
File_read::View* pv = this->find_or_make_view(start, size, NULL);
|
File_read::View* pv = this->find_or_make_view(start, size);
|
||||||
return pv->data() + (start - pv->start());
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned char*
|
|
||||||
File_read::get_view_and_size(off_t start, off_t size, off_t* pbytes)
|
|
||||||
{
|
|
||||||
gold_assert(this->lock_count_ > 0);
|
|
||||||
File_read::View* pv = this->find_or_make_view(start, size, pbytes);
|
|
||||||
return pv->data() + (start - pv->start());
|
return pv->data() + (start - pv->start());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +300,7 @@ File_view*
|
||||||
File_read::get_lasting_view(off_t start, off_t size)
|
File_read::get_lasting_view(off_t start, off_t size)
|
||||||
{
|
{
|
||||||
gold_assert(this->lock_count_ > 0);
|
gold_assert(this->lock_count_ > 0);
|
||||||
File_read::View* pv = this->find_or_make_view(start, size, NULL);
|
File_read::View* pv = this->find_or_make_view(start, size);
|
||||||
pv->lock();
|
pv->lock();
|
||||||
return new File_view(*this, pv, pv->data() + (start - pv->start()));
|
return new File_view(*this, pv, pv->data() + (start - pv->start()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,13 +87,6 @@ class File_read
|
||||||
const unsigned char*
|
const unsigned char*
|
||||||
get_view(off_t start, off_t size);
|
get_view(off_t start, off_t size);
|
||||||
|
|
||||||
// Return a view into the file starting at file offset START, for up
|
|
||||||
// to SIZE bytes. Set *PBYTES to the number of bytes read. This
|
|
||||||
// may be less than SIZE. The pointer will remain valid until the
|
|
||||||
// File_read is unlocked.
|
|
||||||
const unsigned char*
|
|
||||||
get_view_and_size(off_t start, off_t size, off_t* pbytes);
|
|
||||||
|
|
||||||
// Read data from the file into the buffer P starting at file offset
|
// Read data from the file into the buffer P starting at file offset
|
||||||
// START for SIZE bytes.
|
// START for SIZE bytes.
|
||||||
void
|
void
|
||||||
|
@ -170,7 +163,7 @@ class File_read
|
||||||
|
|
||||||
// Find or make a view into the file.
|
// Find or make a view into the file.
|
||||||
View*
|
View*
|
||||||
find_or_make_view(off_t start, off_t size, off_t* pbytes);
|
find_or_make_view(off_t start, off_t size);
|
||||||
|
|
||||||
// Clear the file views.
|
// Clear the file views.
|
||||||
void
|
void
|
||||||
|
|
|
@ -86,10 +86,11 @@ Read_symbols::run(Workqueue* workqueue)
|
||||||
|
|
||||||
// Read enough of the file to pick up the entire ELF header.
|
// Read enough of the file to pick up the entire ELF header.
|
||||||
|
|
||||||
int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
|
const int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
|
||||||
|
unsigned char ehdr_buf[ehdr_size];
|
||||||
off_t bytes;
|
off_t bytes;
|
||||||
const unsigned char* p = input_file->file().get_view_and_size(0, ehdr_size,
|
input_file->file().read_up_to(0, ehdr_size, ehdr_buf, &bytes);
|
||||||
&bytes);
|
|
||||||
if (bytes >= 4)
|
if (bytes >= 4)
|
||||||
{
|
{
|
||||||
static unsigned char elfmagic[4] =
|
static unsigned char elfmagic[4] =
|
||||||
|
@ -97,12 +98,12 @@ Read_symbols::run(Workqueue* workqueue)
|
||||||
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
|
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
|
||||||
elfcpp::ELFMAG2, elfcpp::ELFMAG3
|
elfcpp::ELFMAG2, elfcpp::ELFMAG3
|
||||||
};
|
};
|
||||||
if (memcmp(p, elfmagic, 4) == 0)
|
if (memcmp(ehdr_buf, elfmagic, 4) == 0)
|
||||||
{
|
{
|
||||||
// This is an ELF object.
|
// This is an ELF object.
|
||||||
|
|
||||||
Object* obj = make_elf_object(input_file->filename(),
|
Object* obj = make_elf_object(input_file->filename(),
|
||||||
input_file, 0, p, bytes);
|
input_file, 0, ehdr_buf, bytes);
|
||||||
|
|
||||||
// We don't have a way to record a non-archive in an input
|
// We don't have a way to record a non-archive in an input
|
||||||
// group. If this is an ordinary object file, we can't
|
// group. If this is an ordinary object file, we can't
|
||||||
|
@ -133,7 +134,7 @@ Read_symbols::run(Workqueue* workqueue)
|
||||||
|
|
||||||
if (bytes >= Archive::sarmag)
|
if (bytes >= Archive::sarmag)
|
||||||
{
|
{
|
||||||
if (memcmp(p, Archive::armag, Archive::sarmag) == 0)
|
if (memcmp(ehdr_buf, Archive::armag, Archive::sarmag) == 0)
|
||||||
{
|
{
|
||||||
// This is an archive.
|
// This is an archive.
|
||||||
Archive* arch = new Archive(this->input_argument_->file().name(),
|
Archive* arch = new Archive(this->input_argument_->file().name(),
|
||||||
|
@ -161,7 +162,8 @@ Read_symbols::run(Workqueue* workqueue)
|
||||||
if (read_input_script(workqueue, this->options_, this->symtab_,
|
if (read_input_script(workqueue, this->options_, this->symtab_,
|
||||||
this->layout_, this->dirpath_, this->input_objects_,
|
this->layout_, this->dirpath_, this->input_objects_,
|
||||||
this->input_group_, this->input_argument_, input_file,
|
this->input_group_, this->input_argument_, input_file,
|
||||||
p, bytes, this->this_blocker_, this->next_blocker_))
|
ehdr_buf, bytes, this->this_blocker_,
|
||||||
|
this->next_blocker_))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Here we have to handle any other input file types we need.
|
// Here we have to handle any other input file types we need.
|
||||||
|
|
Loading…
Add table
Reference in a new issue