#include <sys/uio.h>
#include "filenames.h"
+#include "parameters.h"
#include "options.h"
#include "dirsearch.h"
+#include "target.h"
+#include "binary.h"
#include "fileread.h"
namespace gold
return this->descriptor_ >= 0;
}
-// Open the file for testing purposes.
+// Open the file with the contents in memory.
bool
File_read::open(const Task* task, const std::string& name,
: file_()
{
this->input_argument_ =
- new Input_file_argument(name, false, "", Position_dependent_options());
+ new Input_file_argument(name, false, "", false,
+ Position_dependent_options());
bool ok = file_.open(task, name, contents, size);
gold_assert(ok);
}
const char*
Input_file::name() const
-{ return this->input_argument_->name(); }
+{
+ return this->input_argument_->name();
+}
+
+// Return whether we are only reading symbols.
+
+bool
+Input_file::just_symbols() const
+{
+ return this->input_argument_->just_symbols();
+}
// Open the file.
n1 += this->input_argument_->name();
std::string n2;
if (options.is_static()
- || this->input_argument_->options().do_static_search())
+ || !this->input_argument_->options().Bdynamic())
n1 += ".a";
else
{
}
// Now that we've figured out where the file lives, try to open it.
- if (!this->file_.open(task, name))
+
+ General_options::Object_format format =
+ this->input_argument_->options().format_enum();
+ bool ok;
+ if (format == General_options::OBJECT_FORMAT_ELF)
+ ok = this->file_.open(task, name);
+ else
+ {
+ gold_assert(format == General_options::OBJECT_FORMAT_BINARY);
+ ok = this->open_binary(options, task, name);
+ }
+
+ if (!ok)
{
gold_error(_("cannot open %s: %s"),
name.c_str(), strerror(errno));
return true;
}
+// Open a file for --format binary.
+
+bool
+Input_file::open_binary(const General_options&,
+ const Task* task, const std::string& name)
+{
+ // In order to open a binary file, we need machine code, size, and
+ // endianness. We may not have a valid target at this point, in
+ // which case we use the default target.
+ const Target* target;
+ if (parameters->target_valid())
+ target = ¶meters->target();
+ else
+ target = ¶meters->default_target();
+
+ Binary_to_elf binary_to_elf(target->machine_code(),
+ target->get_size(),
+ target->is_big_endian(),
+ name);
+ if (!binary_to_elf.convert(task))
+ return false;
+ return this->file_.open(task, name, binary_to_elf.converted_data_leak(),
+ binary_to_elf.converted_size());
+}
+
} // End namespace gold.