off_t off = sarmag;
while (true)
{
+ unsigned char hdr_buf[sizeof(Archive_header)];
off_t bytes;
- const unsigned char* p = this->get_view_and_size(off,
- sizeof(Archive_header),
- &bytes);
+ this->input_file_->file().read_up_to(off, sizeof(Archive_header),
+ hdr_buf, &bytes);
+
if (bytes < sizeof(Archive_header))
{
if (bytes != 0)
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;
off_t size = this->interpret_header(hdr, off, &name);
if (name.empty())
// Read enough of the file to pick up the entire ELF header.
int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
+ unsigned char ehdr_buf[ehdr_size];
off_t bytes;
- const unsigned char* p =
- this->input_file_->file().get_view_and_size(memoff, ehdr_size, &bytes);
+ this->input_file_->file().read_up_to(memoff, ehdr_size, ehdr_buf, &bytes);
if (bytes < 4)
{
fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
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"),
program_name, this->name().c_str(),
Object* obj = make_elf_object((std::string(this->input_file_->filename())
+ "(" + n + ")"),
- this->input_file_, memoff, p, bytes);
+ this->input_file_, memoff, ehdr_buf, bytes);
input_objects->add_object(obj);
get_view(off_t start, off_t 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.
void
read_armap(off_t start, off_t size);
// Find an existing view or make a new one.
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);
// There was an existing view at this offset.
File_read::View* v = ins.first->second;
if (v->size() - (start - v->start()) >= size)
- {
- if (pbytes != NULL)
- *pbytes = size;
- return v;
- }
+ return v;
// This view is not large enough.
this->saved_views_.push_back(v);
ins.first->second = v;
if (bytes - (start - poff) >= size)
- {
- if (pbytes != NULL)
- *pbytes = size;
- return v;
- }
-
- if (pbytes != NULL)
- {
- *pbytes = bytes - (start - poff);
- return v;
- }
+ return v;
fprintf(stderr,
_("%s: %s: file too short: read only %lld of %lld bytes at %lld\n"),
File_read::get_view(off_t start, off_t size)
{
gold_assert(this->lock_count_ > 0);
- File_read::View* pv = this->find_or_make_view(start, size, NULL);
- 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);
+ File_read::View* pv = this->find_or_make_view(start, size);
return pv->data() + (start - pv->start());
}
File_read::get_lasting_view(off_t start, off_t size)
{
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();
return new File_view(*this, pv, pv->data() + (start - pv->start()));
}
const unsigned char*
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
// START for SIZE bytes.
void
// Find or make a view into the file.
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.
void
// 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;
- const unsigned char* p = input_file->file().get_view_and_size(0, ehdr_size,
- &bytes);
+ input_file->file().read_up_to(0, ehdr_size, ehdr_buf, &bytes);
+
if (bytes >= 4)
{
static unsigned char elfmagic[4] =
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
elfcpp::ELFMAG2, elfcpp::ELFMAG3
};
- if (memcmp(p, elfmagic, 4) == 0)
+ if (memcmp(ehdr_buf, elfmagic, 4) == 0)
{
// This is an ELF object.
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
// group. If this is an ordinary object file, we can't
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.
Archive* arch = new Archive(this->input_argument_->file().name(),
if (read_input_script(workqueue, this->options_, this->symtab_,
this->layout_, this->dirpath_, this->input_objects_,
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;
// Here we have to handle any other input file types we need.