This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold][patch] Set the target in make_sized_incremental_binary
> You have to call set_parameters_target after the check for whether
> target == NULL.
>
> For safety, it should also check the existing target as in object.cc:
>
> Âif (!parameters->target_valid())
> Â Âset_parameters_target(target);
> Âelse if (target != ¶meters->target())
> Â Âgold_error(_("%s: incompatible target"), this->output_name_);
Updated patch attached. I added the name of the file as a function
argument as is done in object.cc. Another option would be to add a
get_name to Output_file.
2009-12-02 Rafael Avila de Espindola <espindola@google.com>
* incremental-dump.cc (main): Update call to open_incremental_binary.
* incremental.cc (make_sized_incremental_binary): Set the target.
Error if it is incompatible.
(open_incremental_binary): Add a name argument. Pass it to
make_sized_incremental_binary.
(Incremental_checker::can_incrementally_link_output_file): Update
call to open_incremental_binary.
* incremental.h (open_incremental_binary): Add a name argument.
> Ian
>
Thanks,
--
Rafael Ãvila de EspÃndola
diff --git a/gold/incremental-dump.cc b/gold/incremental-dump.cc
index 9e750cb..bd5bdb3 100644
--- a/gold/incremental-dump.cc
+++ b/gold/incremental-dump.cc
@@ -62,7 +62,7 @@ main(int argc, char** argv)
return 1;
}
- Incremental_binary* inc = open_incremental_binary(file);
+ Incremental_binary* inc = open_incremental_binary(filename, file);
if (inc == NULL)
{
diff --git a/gold/incremental.cc b/gold/incremental.cc
index 4af4ef3..2f7dc93 100644
--- a/gold/incremental.cc
+++ b/gold/incremental.cc
@@ -320,7 +320,7 @@ namespace
template<int size, bool big_endian>
Incremental_binary*
-make_sized_incremental_binary(Output_file* file,
+make_sized_incremental_binary(const std::string& name, Output_file* file,
const elfcpp::Ehdr<size, big_endian>& ehdr)
{
Target* target = select_target(ehdr.get_e_machine(), size, big_endian,
@@ -333,6 +333,11 @@ make_sized_incremental_binary(Output_file* file,
return NULL;
}
+ if (!parameters->target_valid())
+ set_parameters_target(target);
+ else if (target != ¶meters->target())
+ gold_error(_("%s: incompatible target"), name.c_str());
+
return new Sized_incremental_binary<size, big_endian>(file, ehdr, target);
}
@@ -343,7 +348,7 @@ make_sized_incremental_binary(Output_file* file,
// should be opened.
Incremental_binary*
-open_incremental_binary(Output_file* file)
+open_incremental_binary(const std::string& name, Output_file* file)
{
off_t filesize = file->filesize();
int want = elfcpp::Elf_recognizer::max_header_size;
@@ -374,7 +379,7 @@ open_incremental_binary(Output_file* file)
{
#ifdef HAVE_TARGET_32_BIG
result = make_sized_incremental_binary<32, true>(
- file, elfcpp::Ehdr<32, true>(p));
+ name, file, elfcpp::Ehdr<32, true>(p));
#else
explain_no_incremental(_("unsupported file: 32-bit, big-endian"));
#endif
@@ -383,7 +388,7 @@ open_incremental_binary(Output_file* file)
{
#ifdef HAVE_TARGET_32_LITTLE
result = make_sized_incremental_binary<32, false>(
- file, elfcpp::Ehdr<32, false>(p));
+ name, file, elfcpp::Ehdr<32, false>(p));
#else
explain_no_incremental(_("unsupported file: 32-bit, little-endian"));
#endif
@@ -395,7 +400,7 @@ open_incremental_binary(Output_file* file)
{
#ifdef HAVE_TARGET_64_BIG
result = make_sized_incremental_binary<64, true>(
- file, elfcpp::Ehdr<64, true>(p));
+ name, file, elfcpp::Ehdr<64, true>(p));
#else
explain_no_incremental(_("unsupported file: 64-bit, big-endian"));
#endif
@@ -404,7 +409,7 @@ open_incremental_binary(Output_file* file)
{
#ifdef HAVE_TARGET_64_LITTLE
result = make_sized_incremental_binary<64, false>(
- file, elfcpp::Ehdr<64, false>(p));
+ name, file, elfcpp::Ehdr<64, false>(p));
#else
explain_no_incremental(_("unsupported file: 64-bit, little-endian"));
#endif
@@ -425,7 +430,8 @@ Incremental_checker::can_incrementally_link_output_file()
Output_file output(this->output_name_);
if (!output.open_for_modification())
return false;
- Incremental_binary* binary = open_incremental_binary(&output);
+ Incremental_binary* binary = open_incremental_binary(this->output_name_,
+ &output);
if (binary == NULL)
return false;
return binary->check_inputs(this->incremental_inputs_);
diff --git a/gold/incremental.h b/gold/incremental.h
index f6e36fa..706e562 100644
--- a/gold/incremental.h
+++ b/gold/incremental.h
@@ -220,7 +220,7 @@ class Sized_incremental_binary : public Incremental_binary
// Create an Incremental_binary object for FILE. Returns NULL is this is not
// possible, e.g. FILE is not an ELF file or has an unsupported target.
Incremental_binary*
-open_incremental_binary(Output_file* file);
+open_incremental_binary(const std::string& name, Output_file* file);
// Code invoked early during an incremental link that checks what files need
// to be relinked.