1 // fileread.cc -- read files for gold
3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
36 #include "filenames.h"
39 #include "parameters.h"
41 #include "dirsearch.h"
44 #include "descriptors.h"
45 #include "gold-threads.h"
49 struct iovec
{ void* iov_base
; size_t iov_len
; };
51 readv(int, const iovec
*, int)
60 // Class File_read::View.
62 File_read::View::~View()
64 gold_assert(!this->is_locked());
65 switch (this->data_ownership_
)
67 case DATA_ALLOCATED_ARRAY
:
71 if (::munmap(const_cast<unsigned char*>(this->data_
), this->size_
) != 0)
72 gold_warning(_("munmap failed: %s"), strerror(errno
));
73 File_read::current_mapped_bytes
-= this->size_
;
83 File_read::View::lock()
89 File_read::View::unlock()
91 gold_assert(this->lock_count_
> 0);
96 File_read::View::is_locked()
98 return this->lock_count_
> 0;
103 // A lock for the File_read static variables.
104 static Lock
* file_counts_lock
= NULL
;
105 static Initialize_lock
file_counts_initialize_lock(&file_counts_lock
);
107 // The File_read static variables.
108 unsigned long long File_read::total_mapped_bytes
;
109 unsigned long long File_read::current_mapped_bytes
;
110 unsigned long long File_read::maximum_mapped_bytes
;
112 File_read::~File_read()
114 gold_assert(this->token_
.is_writable());
115 if (this->is_descriptor_opened_
)
117 release_descriptor(this->descriptor_
, true);
118 this->descriptor_
= -1;
119 this->is_descriptor_opened_
= false;
122 this->clear_views(CLEAR_VIEWS_ALL
);
128 File_read::open(const Task
* task
, const std::string
& name
)
130 gold_assert(this->token_
.is_writable()
131 && this->descriptor_
< 0
132 && !this->is_descriptor_opened_
133 && this->name_
.empty());
136 this->descriptor_
= open_descriptor(-1, this->name_
.c_str(),
139 if (this->descriptor_
>= 0)
141 this->is_descriptor_opened_
= true;
143 if (::fstat(this->descriptor_
, &s
) < 0)
144 gold_error(_("%s: fstat failed: %s"),
145 this->name_
.c_str(), strerror(errno
));
146 this->size_
= s
.st_size
;
147 gold_debug(DEBUG_FILES
, "Attempt to open %s succeeded",
148 this->name_
.c_str());
149 this->token_
.add_writer(task
);
152 return this->descriptor_
>= 0;
155 // Open the file with the contents in memory.
158 File_read::open(const Task
* task
, const std::string
& name
,
159 const unsigned char* contents
, off_t size
)
161 gold_assert(this->token_
.is_writable()
162 && this->descriptor_
< 0
163 && !this->is_descriptor_opened_
164 && this->name_
.empty());
166 this->whole_file_view_
= new View(0, size
, contents
, 0, false,
167 View::DATA_NOT_OWNED
);
168 this->add_view(this->whole_file_view_
);
170 this->token_
.add_writer(task
);
174 // Reopen a descriptor if necessary.
177 File_read::reopen_descriptor()
179 if (!this->is_descriptor_opened_
)
181 this->descriptor_
= open_descriptor(this->descriptor_
,
184 if (this->descriptor_
< 0)
185 gold_fatal(_("could not reopen file %s"), this->name_
.c_str());
186 this->is_descriptor_opened_
= true;
190 // Release the file. This is called when we are done with the file in
196 gold_assert(this->is_locked());
198 if (!parameters
->options_valid() || parameters
->options().stats())
200 file_counts_initialize_lock
.initialize();
201 Hold_optional_lock
hl(file_counts_lock
);
202 File_read::total_mapped_bytes
+= this->mapped_bytes_
;
203 File_read::current_mapped_bytes
+= this->mapped_bytes_
;
204 if (File_read::current_mapped_bytes
> File_read::maximum_mapped_bytes
)
205 File_read::maximum_mapped_bytes
= File_read::current_mapped_bytes
;
208 this->mapped_bytes_
= 0;
210 // Only clear views if there is only one attached object. Otherwise
211 // we waste time trying to clear cached archive views. Similarly
212 // for releasing the descriptor.
213 if (this->object_count_
<= 1)
215 this->clear_views(CLEAR_VIEWS_NORMAL
);
216 if (this->is_descriptor_opened_
)
218 release_descriptor(this->descriptor_
, false);
219 this->is_descriptor_opened_
= false;
223 this->released_
= true;
229 File_read::lock(const Task
* task
)
231 gold_assert(this->released_
);
232 this->token_
.add_writer(task
);
233 this->released_
= false;
239 File_read::unlock(const Task
* task
)
242 this->token_
.remove_writer(task
);
245 // Return whether the file is locked.
248 File_read::is_locked() const
250 if (!this->token_
.is_writable())
252 // The file is not locked, so it should have been released.
253 gold_assert(this->released_
);
257 // See if we have a view which covers the file starting at START for
258 // SIZE bytes. Return a pointer to the View if found, NULL if not.
259 // If BYTESHIFT is not -1U, the returned View must have the specified
260 // byte shift; otherwise, it may have any byte shift. If VSHIFTED is
261 // not NULL, this sets *VSHIFTED to a view which would have worked if
262 // not for the requested BYTESHIFT.
264 inline File_read::View
*
265 File_read::find_view(off_t start
, section_size_type size
,
266 unsigned int byteshift
, File_read::View
** vshifted
) const
268 if (vshifted
!= NULL
)
271 // If we have the whole file mmapped, and the alignment is right,
273 if (this->whole_file_view_
)
274 if (byteshift
== -1U || byteshift
== 0)
275 return this->whole_file_view_
;
277 off_t page
= File_read::page_offset(start
);
279 unsigned int bszero
= 0;
280 Views::const_iterator p
= this->views_
.upper_bound(std::make_pair(page
- 1,
283 while (p
!= this->views_
.end() && p
->first
.first
<= page
)
285 if (p
->second
->start() <= start
286 && (p
->second
->start() + static_cast<off_t
>(p
->second
->size())
287 >= start
+ static_cast<off_t
>(size
)))
289 if (byteshift
== -1U || byteshift
== p
->second
->byteshift())
291 p
->second
->set_accessed();
295 if (vshifted
!= NULL
&& *vshifted
== NULL
)
296 *vshifted
= p
->second
;
305 // Read SIZE bytes from the file starting at offset START. Read into
309 File_read::do_read(off_t start
, section_size_type size
, void* p
)
312 if (this->whole_file_view_
!= NULL
)
314 bytes
= this->size_
- start
;
315 if (static_cast<section_size_type
>(bytes
) >= size
)
317 memcpy(p
, this->whole_file_view_
->data() + start
, size
);
323 this->reopen_descriptor();
324 bytes
= ::pread(this->descriptor_
, p
, size
, start
);
325 if (static_cast<section_size_type
>(bytes
) == size
)
330 gold_fatal(_("%s: pread failed: %s"),
331 this->filename().c_str(), strerror(errno
));
336 gold_fatal(_("%s: file too short: read only %lld of %lld bytes at %lld"),
337 this->filename().c_str(),
338 static_cast<long long>(bytes
),
339 static_cast<long long>(size
),
340 static_cast<long long>(start
));
343 // Read data from the file.
346 File_read::read(off_t start
, section_size_type size
, void* p
)
348 const File_read::View
* pv
= this->find_view(start
, size
, -1U, NULL
);
351 memcpy(p
, pv
->data() + (start
- pv
->start() + pv
->byteshift()), size
);
355 this->do_read(start
, size
, p
);
358 // Add a new view. There may already be an existing view at this
359 // offset. If there is, the new view will be larger, and should
360 // replace the old view.
363 File_read::add_view(File_read::View
* v
)
365 std::pair
<Views::iterator
, bool> ins
=
366 this->views_
.insert(std::make_pair(std::make_pair(v
->start(),
372 // There was an existing view at this offset. It must not be large
373 // enough. We can't delete it here, since something might be using
374 // it; we put it on a list to be deleted when the file is unlocked.
375 File_read::View
* vold
= ins
.first
->second
;
376 gold_assert(vold
->size() < v
->size());
377 if (vold
->should_cache())
382 this->saved_views_
.push_back(vold
);
384 ins
.first
->second
= v
;
387 // Make a new view with a specified byteshift, reading the data from
391 File_read::make_view(off_t start
, section_size_type size
,
392 unsigned int byteshift
, bool cache
)
394 gold_assert(size
> 0);
396 // Check that start and end of the view are within the file.
397 if (start
> this->size_
398 || (static_cast<unsigned long long>(size
)
399 > static_cast<unsigned long long>(this->size_
- start
)))
400 gold_fatal(_("%s: attempt to map %lld bytes at offset %lld exceeds "
401 "size of file; the file may be corrupt"),
402 this->filename().c_str(),
403 static_cast<long long>(size
),
404 static_cast<long long>(start
));
406 off_t poff
= File_read::page_offset(start
);
408 section_size_type psize
= File_read::pages(size
+ (start
- poff
));
410 if (poff
+ static_cast<off_t
>(psize
) >= this->size_
)
412 psize
= this->size_
- poff
;
413 gold_assert(psize
>= size
);
419 unsigned char* p
= new unsigned char[psize
+ byteshift
];
420 memset(p
, 0, byteshift
);
421 this->do_read(poff
, psize
, p
+ byteshift
);
422 v
= new File_read::View(poff
, psize
, p
, byteshift
, cache
,
423 View::DATA_ALLOCATED_ARRAY
);
427 this->reopen_descriptor();
428 void* p
= ::mmap(NULL
, psize
, PROT_READ
, MAP_PRIVATE
,
429 this->descriptor_
, poff
);
431 gold_fatal(_("%s: mmap offset %lld size %lld failed: %s"),
432 this->filename().c_str(),
433 static_cast<long long>(poff
),
434 static_cast<long long>(psize
),
437 this->mapped_bytes_
+= psize
;
439 const unsigned char* pbytes
= static_cast<const unsigned char*>(p
);
440 v
= new File_read::View(poff
, psize
, pbytes
, 0, cache
,
449 // Find a View or make a new one, shifted as required by the file
450 // offset OFFSET and ALIGNED.
453 File_read::find_or_make_view(off_t offset
, off_t start
,
454 section_size_type size
, bool aligned
, bool cache
)
456 unsigned int byteshift
;
461 unsigned int target_size
= (!parameters
->target_valid()
463 : parameters
->target().get_size());
464 byteshift
= offset
& ((target_size
/ 8) - 1);
466 // Set BYTESHIFT to the number of dummy bytes which must be
467 // inserted before the data in order for this data to be
470 byteshift
= (target_size
/ 8) - byteshift
;
473 // If --map-whole-files is set, make sure we have a
474 // whole file view. Options may not yet be ready, e.g.,
475 // when reading a version script. We then default to
476 // --no-map-whole-files.
477 if (this->whole_file_view_
== NULL
478 && parameters
->options_valid()
479 && parameters
->options().map_whole_files())
480 this->whole_file_view_
= this->make_view(0, this->size_
, 0, cache
);
482 // Try to find a View with the required BYTESHIFT.
483 File_read::View
* vshifted
;
484 File_read::View
* v
= this->find_view(offset
+ start
, size
,
485 aligned
? byteshift
: -1U,
494 // If VSHIFTED is not NULL, then it has the data we need, but with
495 // the wrong byteshift.
499 gold_assert(aligned
);
501 unsigned char* pbytes
= new unsigned char[v
->size() + byteshift
];
502 memset(pbytes
, 0, byteshift
);
503 memcpy(pbytes
+ byteshift
, v
->data() + v
->byteshift(), v
->size());
505 File_read::View
* shifted_view
=
506 new File_read::View(v
->start(), v
->size(), pbytes
, byteshift
,
507 cache
, View::DATA_ALLOCATED_ARRAY
);
509 this->add_view(shifted_view
);
513 // Make a new view. If we don't need an aligned view, use a
514 // byteshift of 0, so that we can use mmap.
515 return this->make_view(offset
+ start
, size
,
516 aligned
? byteshift
: 0,
520 // Get a view into the file.
523 File_read::get_view(off_t offset
, off_t start
, section_size_type size
,
524 bool aligned
, bool cache
)
526 File_read::View
* pv
= this->find_or_make_view(offset
, start
, size
,
528 return pv
->data() + (offset
+ start
- pv
->start() + pv
->byteshift());
532 File_read::get_lasting_view(off_t offset
, off_t start
, section_size_type size
,
533 bool aligned
, bool cache
)
535 File_read::View
* pv
= this->find_or_make_view(offset
, start
, size
,
538 return new File_view(*this, pv
,
540 + (offset
+ start
- pv
->start() + pv
->byteshift())));
543 // Use readv to read COUNT entries from RM starting at START. BASE
544 // must be added to all file offsets in RM.
547 File_read::do_readv(off_t base
, const Read_multiple
& rm
, size_t start
,
550 unsigned char discard
[File_read::page_size
];
551 iovec iov
[File_read::max_readv_entries
* 2];
552 size_t iov_index
= 0;
554 off_t first_offset
= rm
[start
].file_offset
;
555 off_t last_offset
= first_offset
;
557 for (size_t i
= 0; i
< count
; ++i
)
559 const Read_multiple_entry
& i_entry(rm
[start
+ i
]);
561 if (i_entry
.file_offset
> last_offset
)
563 size_t skip
= i_entry
.file_offset
- last_offset
;
564 gold_assert(skip
<= sizeof discard
);
566 iov
[iov_index
].iov_base
= discard
;
567 iov
[iov_index
].iov_len
= skip
;
573 iov
[iov_index
].iov_base
= i_entry
.buffer
;
574 iov
[iov_index
].iov_len
= i_entry
.size
;
577 want
+= i_entry
.size
;
579 last_offset
= i_entry
.file_offset
+ i_entry
.size
;
582 this->reopen_descriptor();
584 gold_assert(iov_index
< sizeof iov
/ sizeof iov
[0]);
586 if (::lseek(this->descriptor_
, base
+ first_offset
, SEEK_SET
) < 0)
587 gold_fatal(_("%s: lseek failed: %s"),
588 this->filename().c_str(), strerror(errno
));
590 ssize_t got
= ::readv(this->descriptor_
, iov
, iov_index
);
593 gold_fatal(_("%s: readv failed: %s"),
594 this->filename().c_str(), strerror(errno
));
596 gold_fatal(_("%s: file too short: read only %zd of %zd bytes at %lld"),
597 this->filename().c_str(),
598 got
, want
, static_cast<long long>(base
+ first_offset
));
601 // Read several pieces of data from the file.
604 File_read::read_multiple(off_t base
, const Read_multiple
& rm
)
606 size_t count
= rm
.size();
610 // Find up to MAX_READV_ENTRIES consecutive entries which are
611 // less than one page apart.
612 const Read_multiple_entry
& i_entry(rm
[i
]);
613 off_t i_off
= i_entry
.file_offset
;
614 off_t end_off
= i_off
+ i_entry
.size
;
616 for (j
= i
+ 1; j
< count
; ++j
)
618 if (j
- i
>= File_read::max_readv_entries
)
620 const Read_multiple_entry
& j_entry(rm
[j
]);
621 off_t j_off
= j_entry
.file_offset
;
622 gold_assert(j_off
>= end_off
);
623 off_t j_end_off
= j_off
+ j_entry
.size
;
624 if (j_end_off
- end_off
>= File_read::page_size
)
630 this->read(base
+ i_off
, i_entry
.size
, i_entry
.buffer
);
633 File_read::View
* view
= this->find_view(base
+ i_off
,
637 this->do_readv(base
, rm
, i
, j
- i
);
640 const unsigned char* v
= (view
->data()
641 + (base
+ i_off
- view
->start()
642 + view
->byteshift()));
643 for (size_t k
= i
; k
< j
; ++k
)
645 const Read_multiple_entry
& k_entry(rm
[k
]);
646 gold_assert((convert_to_section_size_type(k_entry
.file_offset
649 <= convert_to_section_size_type(end_off
651 memcpy(k_entry
.buffer
,
652 v
+ (k_entry
.file_offset
- i_off
),
662 // Mark all views as no longer cached.
665 File_read::clear_view_cache_marks()
667 // Just ignore this if there are multiple objects associated with
668 // the file. Otherwise we will wind up uncaching and freeing some
669 // views for other objects.
670 if (this->object_count_
> 1)
673 for (Views::iterator p
= this->views_
.begin();
674 p
!= this->views_
.end();
676 p
->second
->clear_cache();
677 for (Saved_views::iterator p
= this->saved_views_
.begin();
678 p
!= this->saved_views_
.end();
683 // Remove all the file views. For a file which has multiple
684 // associated objects (i.e., an archive), we keep accessed views
685 // around until next time, in the hopes that they will be useful for
689 File_read::clear_views(Clear_views_mode mode
)
691 bool keep_files_mapped
= (parameters
->options_valid()
692 && parameters
->options().keep_files_mapped());
693 Views::iterator p
= this->views_
.begin();
694 while (p
!= this->views_
.end())
697 if (p
->second
->is_locked() || p
->second
->is_permanent_view())
698 should_delete
= false;
699 else if (mode
== CLEAR_VIEWS_ALL
)
700 should_delete
= true;
701 else if (p
->second
->should_cache() && keep_files_mapped
)
702 should_delete
= false;
703 else if (this->object_count_
> 1
704 && p
->second
->accessed()
705 && mode
!= CLEAR_VIEWS_ARCHIVE
)
706 should_delete
= false;
708 should_delete
= true;
712 if (p
->second
== this->whole_file_view_
)
713 this->whole_file_view_
= NULL
;
716 // map::erase invalidates only the iterator to the deleted
718 Views::iterator pe
= p
;
720 this->views_
.erase(pe
);
724 p
->second
->clear_accessed();
729 Saved_views::iterator q
= this->saved_views_
.begin();
730 while (q
!= this->saved_views_
.end())
732 if (!(*q
)->is_locked())
735 q
= this->saved_views_
.erase(q
);
739 gold_assert(mode
!= CLEAR_VIEWS_ALL
);
745 // Print statistical information to stderr. This is used for --stats.
748 File_read::print_stats()
750 fprintf(stderr
, _("%s: total bytes mapped for read: %llu\n"),
751 program_name
, File_read::total_mapped_bytes
);
752 fprintf(stderr
, _("%s: maximum bytes mapped for read at one time: %llu\n"),
753 program_name
, File_read::maximum_mapped_bytes
);
758 File_view::~File_view()
760 gold_assert(this->file_
.is_locked());
761 this->view_
->unlock();
766 // Create a file for testing.
768 Input_file::Input_file(const Task
* task
, const char* name
,
769 const unsigned char* contents
, off_t size
)
772 this->input_argument_
=
773 new Input_file_argument(name
, Input_file_argument::INPUT_FILE_TYPE_FILE
,
774 "", false, Position_dependent_options());
775 bool ok
= this->file_
.open(task
, name
, contents
, size
);
779 // Return the position dependent options in force for this file.
781 const Position_dependent_options
&
782 Input_file::options() const
784 return this->input_argument_
->options();
787 // Return the name given by the user. For -lc this will return "c".
790 Input_file::name() const
792 return this->input_argument_
->name();
795 // Return whether this file is in a system directory.
798 Input_file::is_in_system_directory() const
800 if (this->is_in_sysroot())
802 return parameters
->options().is_in_system_directory(this->filename());
805 // Return whether we are only reading symbols.
808 Input_file::just_symbols() const
810 return this->input_argument_
->just_symbols();
813 // Return whether this is a file that we will search for in the list
817 Input_file::will_search_for() const
819 return (!IS_ABSOLUTE_PATH(this->input_argument_
->name())
820 && (this->input_argument_
->is_lib()
821 || this->input_argument_
->is_searched_file()
822 || this->input_argument_
->extra_search_path() != NULL
));
825 // Return the file last modification time. Calls gold_fatal if the stat
826 // system call failed.
829 File_read::get_mtime()
831 struct stat file_stat
;
832 this->reopen_descriptor();
834 if (fstat(this->descriptor_
, &file_stat
) < 0)
835 gold_fatal(_("%s: stat failed: %s"), this->name_
.c_str(),
837 #ifdef HAVE_STAT_ST_MTIM
838 return Timespec(file_stat
.st_mtim
.tv_sec
, file_stat
.st_mtim
.tv_nsec
);
840 return Timespec(file_stat
.st_mtime
, 0);
844 // Try to find a file in the extra search dirs. Returns true on success.
847 try_extra_search_path(int* pindex
, const Input_file_argument
* input_argument
,
848 std::string filename
, std::string
* found_name
,
849 std::string
* namep
) {
850 if (input_argument
->extra_search_path() == NULL
)
853 std::string name
= input_argument
->extra_search_path();
854 if (!IS_DIR_SEPARATOR (name
[name
.length() - 1]))
858 struct stat dummy_stat
;
859 if (*pindex
> 0 || ::stat(name
.c_str(), &dummy_stat
) < 0)
862 *found_name
= filename
;
867 // Find the actual file.
868 // If the filename is not absolute, we assume it is in the current
869 // directory *except* when:
870 // A) input_argument_->is_lib() is true;
871 // B) input_argument_->is_searched_file() is true; or
872 // C) input_argument_->extra_search_path() is not empty.
873 // In each, we look in extra_search_path + library_path to find
874 // the file location, rather than the current directory.
877 find_file(const Dirsearch
& dirpath
, int* pindex
,
878 const Input_file_argument
* input_argument
, bool* is_in_sysroot
,
879 std::string
* found_name
, std::string
* namep
)
883 // Case 1: name is an absolute file, just try to open it
884 // Case 2: name is relative but is_lib is false, is_searched_file is false,
885 // and extra_search_path is empty
886 if (IS_ABSOLUTE_PATH(input_argument
->name())
887 || (!input_argument
->is_lib()
888 && !input_argument
->is_searched_file()
889 && input_argument
->extra_search_path() == NULL
))
891 name
= input_argument
->name();
896 // Case 3: is_lib is true or is_searched_file is true
897 else if (input_argument
->is_lib()
898 || input_argument
->is_searched_file())
901 if (input_argument
->is_lib())
904 n1
+= input_argument
->name();
905 if (parameters
->options().is_static()
906 || !input_argument
->options().Bdynamic())
915 n1
= input_argument
->name();
917 if (try_extra_search_path(pindex
, input_argument
, n1
, found_name
, namep
))
920 if (!n2
.empty() && try_extra_search_path(pindex
, input_argument
, n2
,
924 // It is not in the extra_search_path.
925 name
= dirpath
.find(n1
, n2
, is_in_sysroot
, pindex
);
928 gold_error(_("cannot find %s%s"),
929 input_argument
->is_lib() ? "-l" : "",
930 input_argument
->name());
933 if (n2
.empty() || name
[name
.length() - 1] == 'o')
940 // Case 4: extra_search_path is not empty
943 gold_assert(input_argument
->extra_search_path() != NULL
);
945 if (try_extra_search_path(pindex
, input_argument
, input_argument
->name(),
949 // extra_search_path failed, so check the normal search-path.
953 name
= dirpath
.find(input_argument
->name(), "",
954 is_in_sysroot
, &index
);
957 gold_error(_("cannot find %s"),
958 input_argument
->name());
969 Input_file::open(const Dirsearch
& dirpath
, const Task
* task
, int *pindex
)
972 if (!find_file(dirpath
, pindex
, this->input_argument_
, &this->is_in_sysroot_
,
973 &this->found_name_
, &name
))
976 // Now that we've figured out where the file lives, try to open it.
978 General_options::Object_format format
=
979 this->input_argument_
->options().format_enum();
981 if (format
== General_options::OBJECT_FORMAT_ELF
)
983 ok
= this->file_
.open(task
, name
);
984 this->format_
= FORMAT_ELF
;
988 gold_assert(format
== General_options::OBJECT_FORMAT_BINARY
);
989 ok
= this->open_binary(task
, name
);
990 this->format_
= FORMAT_BINARY
;
995 gold_error(_("cannot open %s: %s"),
996 name
.c_str(), strerror(errno
));
997 this->format_
= FORMAT_NONE
;
1004 // Open a file for --format binary.
1007 Input_file::open_binary(const Task
* task
, const std::string
& name
)
1009 // In order to open a binary file, we need machine code, size, and
1010 // endianness. We may not have a valid target at this point, in
1011 // which case we use the default target.
1012 parameters_force_valid_target();
1013 const Target
& target(parameters
->target());
1015 Binary_to_elf
binary_to_elf(target
.machine_code(),
1017 target
.is_big_endian(),
1019 if (!binary_to_elf
.convert(task
))
1021 return this->file_
.open(task
, name
, binary_to_elf
.converted_data_leak(),
1022 binary_to_elf
.converted_size());
1025 } // End namespace gold.