summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gold/archive.cc18
-rw-r--r--gold/archive.h4
-rw-r--r--gold/fileread.cc32
-rw-r--r--gold/fileread.h9
-rw-r--r--gold/readsyms.cc16
5 files changed, 25 insertions, 54 deletions
diff --git a/gold/archive.cc b/gold/archive.cc
index f7194f8fea0..5ab3696c7c8 100644
--- a/gold/archive.cc
+++ b/gold/archive.cc
@@ -328,10 +328,11 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout,
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)
@@ -345,7 +346,8 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout,
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())
@@ -379,9 +381,9 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
// 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"),
@@ -395,7 +397,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
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(),
@@ -405,7 +407,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
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);
diff --git a/gold/archive.h b/gold/archive.h
index 7fa1d11ae80..7ebdf47e689 100644
--- a/gold/archive.h
+++ b/gold/archive.h
@@ -101,10 +101,6 @@ class Archive
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);
diff --git a/gold/fileread.cc b/gold/fileread.cc
index a39d530ab87..ee2ae73f61b 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -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.
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);
@@ -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.
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);
@@ -277,17 +273,7 @@ File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
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"),
@@ -306,15 +292,7 @@ const unsigned char*
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());
}
@@ -322,7 +300,7 @@ File_view*
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()));
}
diff --git a/gold/fileread.h b/gold/fileread.h
index a77721d47bb..781031aef55 100644
--- a/gold/fileread.h
+++ b/gold/fileread.h
@@ -87,13 +87,6 @@ class File_read
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
@@ -170,7 +163,7 @@ class File_read
// 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
diff --git a/gold/readsyms.cc b/gold/readsyms.cc
index 58e3385131b..5c5594daabe 100644
--- a/gold/readsyms.cc
+++ b/gold/readsyms.cc
@@ -86,10 +86,11 @@ Read_symbols::run(Workqueue* workqueue)
// 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] =
@@ -97,12 +98,12 @@ Read_symbols::run(Workqueue* workqueue)
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
@@ -133,7 +134,7 @@ Read_symbols::run(Workqueue* workqueue)
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(),
@@ -161,7 +162,8 @@ Read_symbols::run(Workqueue* workqueue)
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.