aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2009-09-30 22:21:13 +0000
committerIan Lance Taylor <ian@airs.com>2009-09-30 22:21:13 +0000
commit029ba973354c8eb02c476d3ba8c7f555344afdce (patch)
treeceb131579a7bb043a19b5bea27b391bcf57126e8
parent27a5525e751940f55974e64bdcf11f504e68d356 (diff)
downloadbinutils-029ba973354c8eb02c476d3ba8c7f555344afdce.zip
binutils-029ba973354c8eb02c476d3ba8c7f555344afdce.tar.gz
binutils-029ba973354c8eb02c476d3ba8c7f555344afdce.tar.bz2
* object.h (class Object): Remove target_ field, and target,
sized_target, and set_target methods. (Object::sized_target): Remove. (class Sized_relobj): Update declarations. Remove sized_target. * object.cc (Sized_relobj::setup): Remove target parameter. Change all callers. (Input_objects::add_object): Don't do anything with the target. (make_elf_sized_object): Add punconfigured parameter. Change all callers. Set or test parameter target. * dynobj.cc (Sized_dynobj::target): Remove target parameter. Change all callers. * parameters.cc (Parameters::set_target): Change parameter type to be non-const. (Parameters::default_target): Remove. (set_parameters_target): Change parameter type to be non-const. (parameters_force_valid_target): New function. (parameters_clear_target): New function. * parameters.h (class Parameters): Update declarations. Remove default_target method. Add sized_target and clear_target methods. Change target_ to be non-const. (set_parameters_target): Update declaration. (parameters_force_valid_target): Declare. (parameters_clear_target): Declare. * readsyms.cc (Read_symbols::do_read_symbols): Pass punconfigured as NULL if we aren't searching. (Add_symbols::run): Don't check for compatible target. * fileread.cc (Input_file::open_binary): Call parameters_force_valid_target. * gold.cc (queue_middle_tasks): Likewise. * plugin.cc (make_sized_plugin_object): Likewise. Don't call set_target on object. * dynobj.h (class Sized_dynobj): Update declarations. * archive.cc (Archive::get_elf_object_for_member): Return NULL if make_elf_object returns NULL. (Archive::include_member): Don't check whether object target is compatible. * output.cc (Output_section::add_input_section): Get target from parameters. (Output_section::relax_input_section): Likewise. * reloc.cc (Sized_relobj::do_gc_process_relocs): Get target from parameters. (Sized_relobj::do_scan_relocs): Likewise. (Sized_relobj::relocate_sections): Likewise. * resolve.cc (Symbol_table::resolve): Likewise. * symtab.cc (Symbol_table::wrap_symbol): Likewise. Remove object parameter. Change all callers. (Symbol_table::add_from_object): Get target from parameters. (Symbol_table::add_from_relobj): Don't check object target. (Symbol_table::add_from_dynobj): Likewise. (Symbol_table::define_special_symbol): Get target from parameters. * symtab.h (class Symbol_table): Update declaration. * testsuite/binary_unittest.cc (gold_testsuite): Remove target parameter. Change all callers. Clear parameter target. (Binary_test): Test target here. * testsuite/object_unittest.cc (gold_testsuite): Remove target_test_pointer parameter. Change all callers. (Object_test): Test target here.
-rw-r--r--gold/ChangeLog61
-rw-r--r--gold/archive.cc12
-rw-r--r--gold/dynobj.cc3
-rw-r--r--gold/dynobj.h2
-rw-r--r--gold/fileread.cc13
-rw-r--r--gold/gold.cc2
-rw-r--r--gold/object.cc39
-rw-r--r--gold/object.h40
-rw-r--r--gold/output.cc8
-rw-r--r--gold/parameters.cc79
-rw-r--r--gold/parameters.h39
-rw-r--r--gold/plugin.cc16
-rw-r--r--gold/readsyms.cc27
-rw-r--r--gold/reloc.cc9
-rw-r--r--gold/resolve.cc4
-rw-r--r--gold/symtab.cc18
-rw-r--r--gold/symtab.h2
-rw-r--r--gold/target.cc4
-rw-r--r--gold/testsuite/binary_unittest.cc16
-rw-r--r--gold/testsuite/object_unittest.cc21
20 files changed, 227 insertions, 188 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 8ca9b56..296765a 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,64 @@
+2009-09-30 Ian Lance Taylor <iant@google.com>
+
+ * object.h (class Object): Remove target_ field, and target,
+ sized_target, and set_target methods.
+ (Object::sized_target): Remove.
+ (class Sized_relobj): Update declarations. Remove sized_target.
+ * object.cc (Sized_relobj::setup): Remove target parameter.
+ Change all callers.
+ (Input_objects::add_object): Don't do anything with the target.
+ (make_elf_sized_object): Add punconfigured parameter. Change all
+ callers. Set or test parameter target.
+ * dynobj.cc (Sized_dynobj::target): Remove target parameter.
+ Change all callers.
+ * parameters.cc (Parameters::set_target): Change parameter type to
+ be non-const.
+ (Parameters::default_target): Remove.
+ (set_parameters_target): Change parameter type to be non-const.
+ (parameters_force_valid_target): New function.
+ (parameters_clear_target): New function.
+ * parameters.h (class Parameters): Update declarations. Remove
+ default_target method. Add sized_target and clear_target
+ methods. Change target_ to be non-const.
+ (set_parameters_target): Update declaration.
+ (parameters_force_valid_target): Declare.
+ (parameters_clear_target): Declare.
+ * readsyms.cc (Read_symbols::do_read_symbols): Pass punconfigured
+ as NULL if we aren't searching.
+ (Add_symbols::run): Don't check for compatible target.
+ * fileread.cc (Input_file::open_binary): Call
+ parameters_force_valid_target.
+ * gold.cc (queue_middle_tasks): Likewise.
+ * plugin.cc (make_sized_plugin_object): Likewise. Don't call
+ set_target on object.
+ * dynobj.h (class Sized_dynobj): Update declarations.
+ * archive.cc (Archive::get_elf_object_for_member): Return NULL if
+ make_elf_object returns NULL.
+ (Archive::include_member): Don't check whether object target is
+ compatible.
+ * output.cc (Output_section::add_input_section): Get target from
+ parameters.
+ (Output_section::relax_input_section): Likewise.
+ * reloc.cc (Sized_relobj::do_gc_process_relocs): Get target from
+ parameters.
+ (Sized_relobj::do_scan_relocs): Likewise.
+ (Sized_relobj::relocate_sections): Likewise.
+ * resolve.cc (Symbol_table::resolve): Likewise.
+ * symtab.cc (Symbol_table::wrap_symbol): Likewise. Remove object
+ parameter. Change all callers.
+ (Symbol_table::add_from_object): Get target from parameters.
+ (Symbol_table::add_from_relobj): Don't check object target.
+ (Symbol_table::add_from_dynobj): Likewise.
+ (Symbol_table::define_special_symbol): Get target from
+ parameters.
+ * symtab.h (class Symbol_table): Update declaration.
+ * testsuite/binary_unittest.cc (gold_testsuite): Remove target
+ parameter. Change all callers. Clear parameter target.
+ (Binary_test): Test target here.
+ * testsuite/object_unittest.cc (gold_testsuite): Remove
+ target_test_pointer parameter. Change all callers.
+ (Object_test): Test target here.
+
2009-09-26 Ian Lance Taylor <iant@google.com>
* testsuite/initpri1.c: Don't try to use constructor priorities if
diff --git a/gold/archive.cc b/gold/archive.cc
index 8e809e2..c3fb20f 100644
--- a/gold/archive.cc
+++ b/gold/archive.cc
@@ -564,6 +564,8 @@ Archive::get_elf_object_for_member(off_t off, bool* punconfigured)
+ "(" + member_name + ")"),
input_file, memoff, ehdr, read_size,
punconfigured);
+ if (obj == NULL)
+ return NULL;
obj->set_no_export(this->no_export());
return obj;
}
@@ -807,11 +809,6 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
{
Object *obj = p->second.obj_;
- if (!this->included_member_
- && this->searched_for()
- && !parameters->is_compatible_target(obj->target()))
- return false;
-
Read_symbols_data *sd = p->second.sd_;
if (mapfile != NULL)
mapfile->report_include_archive_member(obj->name(), sym, why);
@@ -830,9 +827,8 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
if (!this->included_member_
&& this->searched_for()
- && (obj == NULL
- ? unconfigured
- : !parameters->is_compatible_target(obj->target())))
+ && obj == NULL
+ && unconfigured)
{
if (obj != NULL)
delete obj;
diff --git a/gold/dynobj.cc b/gold/dynobj.cc
index df2afeb..48ff474 100644
--- a/gold/dynobj.cc
+++ b/gold/dynobj.cc
@@ -83,9 +83,8 @@ Sized_dynobj<size, big_endian>::Sized_dynobj(
template<int size, bool big_endian>
void
-Sized_dynobj<size, big_endian>::setup(Target *target)
+Sized_dynobj<size, big_endian>::setup()
{
- this->set_target(target);
const unsigned int shnum = this->elf_file_.shnum();
this->set_shnum(shnum);
}
diff --git a/gold/dynobj.h b/gold/dynobj.h
index f6c6538..2768c83 100644
--- a/gold/dynobj.h
+++ b/gold/dynobj.h
@@ -163,7 +163,7 @@ class Sized_dynobj : public Dynobj
// Set up the object file based on TARGET.
void
- setup(Target *target);
+ setup();
// Read the symbols.
void
diff --git a/gold/fileread.cc b/gold/fileread.cc
index bb10aa9..02f0571 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -898,15 +898,12 @@ Input_file::open_binary(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 = &parameters->target();
- else
- target = &parameters->default_target();
+ parameters_force_valid_target();
+ const Target& target(parameters->target());
- Binary_to_elf binary_to_elf(target->machine_code(),
- target->get_size(),
- target->is_big_endian(),
+ 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;
diff --git a/gold/gold.cc b/gold/gold.cc
index cb29e7d9..24542a2 100644
--- a/gold/gold.cc
+++ b/gold/gold.cc
@@ -382,7 +382,7 @@ queue_middle_tasks(const General_options& options,
// pass an empty archive to the linker and get an empty object file
// out. In order to do this we need to use a default target.
if (input_objects->number_of_input_objects() == 0)
- set_parameters_target(&parameters->default_target());
+ parameters_force_valid_target();
int thread_count = options.thread_count_middle();
if (thread_count == 0)
diff --git a/gold/object.cc b/gold/object.cc
index 1256284..4d892c8 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -336,14 +336,12 @@ Sized_relobj<size, big_endian>::~Sized_relobj()
}
// Set up an object file based on the file header. This sets up the
-// target and reads the section information.
+// section information.
template<int size, bool big_endian>
void
-Sized_relobj<size, big_endian>::setup(Target *target)
+Sized_relobj<size, big_endian>::setup()
{
- this->set_target(target);
-
const unsigned int shnum = this->elf_file_.shnum();
this->set_shnum(shnum);
}
@@ -2067,16 +2065,6 @@ Sized_relobj<size, big_endian>::do_get_global_symbol_counts(
bool
Input_objects::add_object(Object* obj)
{
- // Set the global target from the first object file we recognize.
- Target* target = obj->target();
- if (!parameters->target_valid())
- set_parameters_target(target);
- else if (target != &parameters->target())
- {
- obj->error(_("incompatible target"));
- return false;
- }
-
// Print the filename if the -t/--trace option is selected.
if (parameters->options().trace())
gold_info("%s", obj->name().c_str());
@@ -2227,7 +2215,8 @@ using namespace gold;
template<int size, bool big_endian>
Object*
make_elf_sized_object(const std::string& name, Input_file* input_file,
- off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
+ off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr,
+ bool* punconfigured)
{
Target* target = select_target(ehdr.get_e_machine(), size, big_endian,
ehdr.get_e_ident()[elfcpp::EI_OSABI],
@@ -2235,6 +2224,18 @@ make_elf_sized_object(const std::string& name, Input_file* input_file,
if (target == NULL)
gold_fatal(_("%s: unsupported ELF machine number %d"),
name.c_str(), ehdr.get_e_machine());
+
+ if (!parameters->target_valid())
+ set_parameters_target(target);
+ else if (target != &parameters->target())
+ {
+ if (punconfigured != NULL)
+ *punconfigured = true;
+ else
+ gold_error(_("%s: incompatible target"), name.c_str());
+ return NULL;
+ }
+
return target->make_elf_object<size, big_endian>(name, input_file, offset,
ehdr);
}
@@ -2337,7 +2338,7 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
#ifdef HAVE_TARGET_32_BIG
elfcpp::Ehdr<32, true> ehdr(p);
return make_elf_sized_object<32, true>(name, input_file,
- offset, ehdr);
+ offset, ehdr, punconfigured);
#else
if (punconfigured != NULL)
*punconfigured = true;
@@ -2353,7 +2354,7 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
#ifdef HAVE_TARGET_32_LITTLE
elfcpp::Ehdr<32, false> ehdr(p);
return make_elf_sized_object<32, false>(name, input_file,
- offset, ehdr);
+ offset, ehdr, punconfigured);
#else
if (punconfigured != NULL)
*punconfigured = true;
@@ -2377,7 +2378,7 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
#ifdef HAVE_TARGET_64_BIG
elfcpp::Ehdr<64, true> ehdr(p);
return make_elf_sized_object<64, true>(name, input_file,
- offset, ehdr);
+ offset, ehdr, punconfigured);
#else
if (punconfigured != NULL)
*punconfigured = true;
@@ -2393,7 +2394,7 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
#ifdef HAVE_TARGET_64_LITTLE
elfcpp::Ehdr<64, false> ehdr(p);
return make_elf_sized_object<64, false>(name, input_file,
- offset, ehdr);
+ offset, ehdr, punconfigured);
#else
if (punconfigured != NULL)
*punconfigured = true;
diff --git a/gold/object.h b/gold/object.h
index 4394318..e7d05c7 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -195,7 +195,7 @@ class Object
Object(const std::string& name, Input_file* input_file, bool is_dynamic,
off_t offset = 0)
: name_(name), input_file_(input_file), offset_(offset), shnum_(-1U),
- is_dynamic_(is_dynamic), target_(NULL), xindex_(NULL), no_export_(false)
+ is_dynamic_(is_dynamic), xindex_(NULL), no_export_(false)
{ input_file->file().add_object(); }
virtual ~Object()
@@ -222,11 +222,6 @@ class Object
pluginobj()
{ return this->do_pluginobj(); }
- // Return the target structure associated with this object.
- Target*
- target() const
- { return this->target_; }
-
// Get the file. We pass on const-ness.
Input_file*
input_file()
@@ -266,13 +261,6 @@ class Object
just_symbols() const
{ return this->input_file()->just_symbols(); }
- // Return the sized target structure associated with this object.
- // This is like the target method but it returns a pointer of
- // appropriate checked type.
- template<int size, bool big_endian>
- Sized_target<size, big_endian>*
- sized_target() const;
-
// Get the number of sections.
unsigned int
shnum() const
@@ -453,11 +441,6 @@ class Object
size_t* used) const
{ this->do_get_global_symbol_counts(symtab, defined, used); }
- // Set the target.
- void
- set_target(Target* target)
- { this->target_ = target; }
-
// Return whether this object was found in a system directory.
bool
is_in_system_directory() const
@@ -589,8 +572,6 @@ class Object
unsigned int shnum_;
// Whether this is a dynamic object.
bool is_dynamic_;
- // Target functions--may be NULL if the target is not known.
- Target* target_;
// Many sections for objects with more than SHN_LORESERVE sections.
Xindex* xindex_;
// True if exclude this object from automatic symbol export.
@@ -598,18 +579,6 @@ class Object
bool no_export_;
};
-// Implement sized_target inline for efficiency. This approach breaks
-// static type checking, but is made safe using asserts.
-
-template<int size, bool big_endian>
-inline Sized_target<size, big_endian>*
-Object::sized_target() const
-{
- gold_assert(this->target_->get_size() == size);
- gold_assert(this->target_->is_big_endian() ? big_endian : !big_endian);
- return static_cast<Sized_target<size, big_endian>*>(this->target_);
-}
-
// A regular object (ET_REL). This is an abstract base class itself.
// The implementation is the template class Sized_relobj.
@@ -1308,7 +1277,7 @@ class Sized_relobj : public Relobj
// Set up the object file based on TARGET.
void
- setup(Target *target);
+ setup();
// Return the number of symbols. This is only valid after
// Object::add_symbols has been called.
@@ -1373,11 +1342,6 @@ class Sized_relobj : public Relobj
return this->local_values_[sym].input_shndx(is_ordinary);
}
- // Return the appropriate Sized_target structure.
- Sized_target<size, big_endian>*
- sized_target()
- { return this->Object::sized_target<size, big_endian>(); }
-
// Record that local symbol SYM needs a dynamic symbol entry.
void
set_needs_output_dynsym_entry(unsigned int sym)
diff --git a/gold/output.cc b/gold/output.cc
index 4ef0a30..e3b1171 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -1895,7 +1895,7 @@ Output_section::add_input_section(Sized_relobj<size, big_endian>* object,
if (aligned_offset_in_section > offset_in_section
&& !have_sections_script
&& (sh_flags & elfcpp::SHF_EXECINSTR) != 0
- && object->target()->has_code_fill())
+ && parameters->target().has_code_fill())
{
// We need to add some fill data. Using fill_list_ when
// possible is an optimization, since we will often have fill
@@ -1907,7 +1907,7 @@ Output_section::add_input_section(Sized_relobj<size, big_endian>* object,
{
// FIXME: When relaxing, the size needs to adjust to
// maintain a constant alignment.
- std::string fill_data(object->target()->code_fill(fill_len));
+ std::string fill_data(parameters->target().code_fill(fill_len));
Output_data_const* odc = new Output_data_const(fill_data, 1);
this->input_sections_.push_back(Input_section(odc));
}
@@ -1925,7 +1925,7 @@ Output_section::add_input_section(Sized_relobj<size, big_endian>* object,
|| this->may_sort_attached_input_sections()
|| this->must_sort_attached_input_sections()
|| parameters->options().user_set_Map()
- || object->target()->may_relax())
+ || parameters->target().may_relax())
this->input_sections_.push_back(Input_section(object, shndx,
shdr.get_sh_size(),
addralign));
@@ -2041,7 +2041,7 @@ Output_section::relax_input_section(Output_relaxed_input_section *psection)
Relobj* relobj = psection->relobj();
unsigned int shndx = psection->shndx();
- gold_assert(relobj->target()->may_relax());
+ gold_assert(parameters->target().may_relax());
// This is not very efficient if we a going to relax a number of sections
// in an Output_section with lot of Input_sections.
diff --git a/gold/parameters.cc b/gold/parameters.cc
index 0164265..2a53998 100644
--- a/gold/parameters.cc
+++ b/gold/parameters.cc
@@ -59,7 +59,7 @@ Parameters::set_doing_static_link(bool doing_static_link)
}
void
-Parameters::set_target(const Target* target)
+Parameters::set_target(Target* target)
{
if (!this->target_valid())
this->target_ = target;
@@ -67,37 +67,6 @@ Parameters::set_target(const Target* target)
gold_assert(target == this->target_);
}
-// The x86_64 kernel build converts a binary file to an object file
-// using -r --format binary --oformat elf32-i386 foo.o. In order to
-// support that for gold we support determining the default target
-// choice from the output format. We recognize names that the GNU
-// linker uses.
-
-const Target&
-Parameters::default_target() const
-{
- gold_assert(this->options_valid());
- if (this->options().user_set_oformat())
- {
- const Target* target
- = select_target_by_name(this->options().oformat());
- if (target != NULL)
- return *target;
-
- gold_error(_("unrecognized output format %s"),
- this->options().oformat());
- }
-
- // The GOLD_DEFAULT_xx macros are defined by the configure script.
- const Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
- GOLD_DEFAULT_SIZE,
- GOLD_DEFAULT_BIG_ENDIAN,
- elfcpp::GOLD_DEFAULT_OSABI,
- 0);
- gold_assert(target != NULL);
- return *target;
-}
-
// Return whether TARGET is compatible with the target we are using.
bool
@@ -171,11 +140,55 @@ set_parameters_options(const General_options* options)
{ static_parameters.set_options(options); }
void
-set_parameters_target(const Target* target)
+set_parameters_target(Target* target)
{ static_parameters.set_target(target); }
void
set_parameters_doing_static_link(bool doing_static_link)
{ static_parameters.set_doing_static_link(doing_static_link); }
+// Force the target to be valid by using the default. Use the
+// --oformat option is set; this supports the x86_64 kernel build,
+// which converts a binary file to an object file using -r --format
+// binary --oformat elf32-i386 foo.o. Otherwise use the configured
+// default.
+
+void
+parameters_force_valid_target()
+{
+ if (parameters->target_valid())
+ return;
+
+ gold_assert(parameters->options_valid());
+ if (parameters->options().user_set_oformat())
+ {
+ Target* target = select_target_by_name(parameters->options().oformat());
+ if (target != NULL)
+ {
+ set_parameters_target(target);
+ return;
+ }
+
+ gold_error(_("unrecognized output format %s"),
+ parameters->options().oformat());
+ }
+
+ // The GOLD_DEFAULT_xx macros are defined by the configure script.
+ Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
+ GOLD_DEFAULT_SIZE,
+ GOLD_DEFAULT_BIG_ENDIAN,
+ elfcpp::GOLD_DEFAULT_OSABI,
+ 0);
+ gold_assert(target != NULL);
+ set_parameters_target(target);
+}
+
+// Clear the current target, for testing.
+
+void
+parameters_clear_target()
+{
+ static_parameters.clear_target();
+}
+
} // End namespace gold.
diff --git a/gold/parameters.h b/gold/parameters.h
index 921a990..88d8a87 100644
--- a/gold/parameters.h
+++ b/gold/parameters.h
@@ -29,6 +29,8 @@ namespace gold
class General_options;
class Errors;
class Target;
+template<int size, bool big_endian>
+class Sized_target;
// Here we define the Parameters class which simply holds simple
// general parameters which apply to the entire link. We use a global
@@ -61,7 +63,7 @@ class Parameters
set_options(const General_options* options);
void
- set_target(const Target* target);
+ set_target(Target* target);
void
set_doing_static_link(bool doing_static_link);
@@ -98,10 +100,20 @@ class Parameters
return *this->target_;
}
- // When we don't have an output file to associate a target, make a
- // default one, with guesses about size and endianness.
- const Target&
- default_target() const;
+ // The Sized_target of the output file. The caller must request the
+ // right size and endianness.
+ template<int size, bool big_endian>
+ Sized_target<size, big_endian>*
+ sized_target() const
+ {
+ gold_assert(this->target_valid());
+ return static_cast<Sized_target<size, big_endian>*>(this->target_);
+ }
+
+ // Clear the target, for testing.
+ void
+ clear_target()
+ { this->target_ = NULL; }
// Return true if TARGET is compatible with the current target.
bool
@@ -140,7 +152,7 @@ class Parameters
private:
Errors* errors_;
const General_options* options_;
- const Target* target_;
+ Target* target_;
bool doing_static_link_valid_;
bool doing_static_link_;
int debug_;
@@ -159,11 +171,22 @@ extern void
set_parameters_options(const General_options* options);
extern void
-set_parameters_target(const Target* target);
+set_parameters_target(Target* target);
extern void
set_parameters_doing_static_link(bool doing_static_link);
-
+
+// Ensure that the target to be valid by using the default target if
+// necessary.
+
+extern void
+parameters_force_valid_target();
+
+// Clear the current target, for testing.
+
+extern void
+parameters_clear_target();
+
// Return whether we are doing a particular debugging type. The
// argument is one of the flags from debug.h.
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 7aee46f..4df405f 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -980,17 +980,14 @@ message(int level, const char * format, ...)
static Pluginobj*
make_sized_plugin_object(Input_file* input_file, off_t offset, off_t filesize)
{
- Target* target;
Pluginobj* obj = NULL;
- if (parameters->target_valid())
- target = const_cast<Target*>(&parameters->target());
- else
- target = const_cast<Target*>(&parameters->default_target());
+ parameters_force_valid_target();
+ const Target& target(parameters->target());
- if (target->get_size() == 32)
+ if (target.get_size() == 32)
{
- if (target->is_big_endian())
+ if (target.is_big_endian())
#ifdef HAVE_TARGET_32_BIG
obj = new Sized_pluginobj<32, true>(input_file->filename(),
input_file, offset, filesize);
@@ -1009,9 +1006,9 @@ make_sized_plugin_object(Input_file* input_file, off_t offset, off_t filesize)
input_file->filename().c_str());
#endif
}
- else if (target->get_size() == 64)
+ else if (target.get_size() == 64)
{
- if (target->is_big_endian())
+ if (target.is_big_endian())
#ifdef HAVE_TARGET_64_BIG
obj = new Sized_pluginobj<64, true>(input_file->filename(),
input_file, offset, filesize);
@@ -1032,7 +1029,6 @@ make_sized_plugin_object(Input_file* input_file, off_t offset, off_t filesize)
}
gold_assert(obj != NULL);
- obj->set_target(target);
return obj;
}
diff --git a/gold/readsyms.cc b/gold/readsyms.cc
index c05d5a3..6494528 100644
--- a/gold/readsyms.cc
+++ b/gold/readsyms.cc
@@ -266,13 +266,16 @@ Read_symbols::do_read_symbols(Workqueue* workqueue)
{
// This is an ELF object.
- bool unconfigured;
+ bool unconfigured = false;
+ bool* punconfigured = (input_file->will_search_for()
+ ? &unconfigured
+ : NULL);
Object* obj = make_elf_object(input_file->filename(),
input_file, 0, ehdr, read_size,
- &unconfigured);
+ punconfigured);
if (obj == NULL)
{
- if (unconfigured && input_file->will_search_for())
+ if (unconfigured)
{
Read_symbols::incompatible_warning(this->input_argument_,
input_file);
@@ -447,7 +450,7 @@ Add_symbols::locks(Task_locker* tl)
// Add the symbols in the object to the symbol table.
void
-Add_symbols::run(Workqueue* workqueue)
+Add_symbols::run(Workqueue*)
{
Pluginobj* pluginobj = this->object_->pluginobj();
if (pluginobj != NULL)
@@ -456,21 +459,7 @@ Add_symbols::run(Workqueue* workqueue)
return;
}
- // If this file has an incompatible format, try for another file
- // with the same name.
- if (this->object_->searched_for()
- && !parameters->is_compatible_target(this->object_->target()))
- {
- Read_symbols::incompatible_warning(this->input_argument_,
- this->object_->input_file());
- Read_symbols::requeue(workqueue, this->input_objects_, this->symtab_,
- this->layout_, this->dirpath_, this->dirindex_,
- this->mapfile_, this->input_argument_,
- this->input_group_, this->next_blocker_);
- this->object_->release();
- delete this->object_;
- }
- else if (!this->input_objects_->add_object(this->object_))
+ if (!this->input_objects_->add_object(this->object_))
{
this->object_->release();
delete this->object_;
diff --git a/gold/reloc.cc b/gold/reloc.cc
index 0842a73..bfa2f1c 100644
--- a/gold/reloc.cc
+++ b/gold/reloc.cc
@@ -363,7 +363,8 @@ Sized_relobj<size, big_endian>::do_gc_process_relocs(const General_options& opti
Layout* layout,
Read_relocs_data* rd)
{
- Sized_target<size, big_endian>* target = this->sized_target();
+ Sized_target<size, big_endian>* target =
+ parameters->sized_target<size, big_endian>();
const unsigned char* local_symbols;
if (rd->local_symbols == NULL)
@@ -403,7 +404,8 @@ Sized_relobj<size, big_endian>::do_scan_relocs(const General_options& options,
Layout* layout,
Read_relocs_data* rd)
{
- Sized_target<size, big_endian>* target = this->sized_target();
+ Sized_target<size, big_endian>* target =
+ parameters->sized_target<size, big_endian>();
const unsigned char* local_symbols;
if (rd->local_symbols == NULL)
@@ -802,7 +804,8 @@ Sized_relobj<size, big_endian>::relocate_sections(
Views* pviews)
{
unsigned int shnum = this->shnum();
- Sized_target<size, big_endian>* target = this->sized_target();
+ Sized_target<size, big_endian>* target =
+ parameters->sized_target<size, big_endian>();
const Output_sections& out_sections(this->output_sections());
const std::vector<Address>& out_offsets(this->section_offsets_);
diff --git a/gold/resolve.cc b/gold/resolve.cc
index 45a4a7a..82af9b4 100644
--- a/gold/resolve.cc
+++ b/gold/resolve.cc
@@ -244,10 +244,10 @@ Symbol_table::resolve(Sized_symbol<size>* to,
unsigned int orig_st_shndx,
Object* object, const char* version)
{
- if (object->target()->has_resolve())
+ if (parameters->target().has_resolve())
{
Sized_target<size, big_endian>* sized_target;
- sized_target = object->sized_target<size, big_endian>();
+ sized_target = parameters->sized_target<size, big_endian>();
sized_target->resolve(to, sym, object, version);
return;
}
diff --git a/gold/symtab.cc b/gold/symtab.cc
index d5f699b..562e1fc 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -688,13 +688,12 @@ Symbol_table::force_local(Symbol* sym)
// option was used.
const char*
-Symbol_table::wrap_symbol(Object* object, const char* name,
- Stringpool::Key* name_key)
+Symbol_table::wrap_symbol(const char* name, Stringpool::Key* name_key)
{
// For some targets, we need to ignore a specific character when
// wrapping, and add it back later.
char prefix = '\0';
- if (name[0] == object->target()->wrap_char())
+ if (name[0] == parameters->target().wrap_char())
{
prefix = name[0];
++name;
@@ -864,7 +863,7 @@ Symbol_table::add_from_object(Object* object,
if (orig_st_shndx == elfcpp::SHN_UNDEF
&& parameters->options().any_wrap())
{
- const char* wrap_name = this->wrap_symbol(object, name, &name_key);
+ const char* wrap_name = this->wrap_symbol(name, &name_key);
if (wrap_name != name)
{
// If we see a reference to malloc with version GLIBC_2.0,
@@ -945,7 +944,7 @@ Symbol_table::add_from_object(Object* object,
was_common = false;
Sized_target<size, big_endian>* target =
- object->sized_target<size, big_endian>();
+ parameters->sized_target<size, big_endian>();
if (!target->has_make_symbol())
ret = new Sized_symbol<size>();
else
@@ -1033,7 +1032,6 @@ Symbol_table::add_from_relobj(
{
*defined = 0;
- gold_assert(size == relobj->target()->get_size());
gold_assert(size == parameters->target().get_size());
const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
@@ -1272,7 +1270,6 @@ Symbol_table::add_from_dynobj(
{
*defined = 0;
- gold_assert(size == dynobj->target()->get_size());
gold_assert(size == parameters->target().get_size());
if (dynobj->just_symbols())
@@ -1661,11 +1658,8 @@ Symbol_table::define_special_symbol(const char** pname, const char** pversion,
sym = new Sized_symbol<size>();
else
{
- gold_assert(target.get_size() == size);
- gold_assert(target.is_big_endian() ? big_endian : !big_endian);
- typedef Sized_target<size, big_endian> My_target;
- const My_target* sized_target =
- static_cast<const My_target*>(&target);
+ Sized_target<size, big_endian>* sized_target =
+ parameters->sized_target<size, big_endian>();
sym = sized_target->make_symbol();
if (sym == NULL)
return NULL;
diff --git a/gold/symtab.h b/gold/symtab.h
index b89fd66..ef8e680 100644
--- a/gold/symtab.h
+++ b/gold/symtab.h
@@ -1450,7 +1450,7 @@ class Symbol_table
// Adjust NAME and *NAME_KEY for wrapping.
const char*
- wrap_symbol(Object* object, const char*, Stringpool::Key* name_key);
+ wrap_symbol(const char* name, Stringpool::Key* name_key);
// Whether we should override a symbol, based on flags in
// resolve.cc.
diff --git a/gold/target.cc b/gold/target.cc
index 2dca98a..d971cff 100644
--- a/gold/target.cc
+++ b/gold/target.cc
@@ -73,14 +73,14 @@ Target::do_make_elf_object_implementation(
{
Sized_relobj<size, big_endian>* obj =
new Sized_relobj<size, big_endian>(name, input_file, offset, ehdr);
- obj->setup(this);
+ obj->setup();
return obj;
}
else if (et == elfcpp::ET_DYN)
{
Sized_dynobj<size, big_endian>* obj =
new Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr);
- obj->setup(this);
+ obj->setup();
return obj;
}
else
diff --git a/gold/testsuite/binary_unittest.cc b/gold/testsuite/binary_unittest.cc
index 2645e0b..b2e14df 100644
--- a/gold/testsuite/binary_unittest.cc
+++ b/gold/testsuite/binary_unittest.cc
@@ -44,8 +44,9 @@ using namespace gold;
template<int size, bool big_endian>
bool
-Sized_binary_test(Target* target)
+Sized_binary_test()
{
+ parameters_clear_target();
// We need a pretend Task.
const Task* task = reinterpret_cast<const Task*>(-1);
@@ -73,7 +74,6 @@ Sized_binary_test(Target* target)
return false;
CHECK(!object->is_dynamic());
- CHECK(object->target() == target);
CHECK(object->shnum() == 5);
CHECK(object->section_name(1) == ".data");
CHECK(object->section_flags(1) == (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE));
@@ -125,23 +125,27 @@ Binary_test(Test_report*)
int fail = 0;
#ifdef HAVE_TARGET_32_LITTLE
- if (!Sized_binary_test<32, false>(target_test_pointer_32_little))
+ if (!Sized_binary_test<32, false>())
++fail;
+ CHECK(&parameters->target() == target_test_pointer_32_little);
#endif
#ifdef HAVE_TARGET_32_BIG
- if (!Sized_binary_test<32, true>(target_test_pointer_32_big))
+ if (!Sized_binary_test<32, true>())
++fail;
+ CHECK(&parameters->target() == target_test_pointer_32_big);
#endif
#ifdef HAVE_TARGET_64_LITTLE
- if (!Sized_binary_test<64, false>(target_test_pointer_64_little))
+ if (!Sized_binary_test<64, false>())
++fail;
+ CHECK(&parameters->target() == target_test_pointer_64_little);
#endif
#ifdef HAVE_TARGET_64_BIG
- if (!Sized_binary_test<64, true>(target_test_pointer_64_big))
+ if (!Sized_binary_test<64, true>())
++fail;
+ CHECK(&parameters->target() == target_test_pointer_64_big);
#endif
return fail == 0;
diff --git a/gold/testsuite/object_unittest.cc b/gold/testsuite/object_unittest.cc
index b36997e..0451add 100644
--- a/gold/testsuite/object_unittest.cc
+++ b/gold/testsuite/object_unittest.cc
@@ -36,9 +36,9 @@ using namespace gold;
template<int size, bool big_endian>
bool
-Sized_object_test(const unsigned char* test_file, unsigned int test_file_size,
- Target* target_test_pointer)
+Sized_object_test(const unsigned char* test_file, unsigned int test_file_size)
{
+ parameters_clear_target();
// We need a pretend Task.
const Task* task = reinterpret_cast<const Task*>(-1);
Input_file input_file(task, "test.o", test_file, test_file_size);
@@ -46,7 +46,6 @@ Sized_object_test(const unsigned char* test_file, unsigned int test_file_size,
test_file, test_file_size, NULL);
CHECK(object->name() == "test.o");
CHECK(!object->is_dynamic());
- CHECK(object->target() == target_test_pointer);
CHECK(object->is_locked());
object->unlock(task);
CHECK(!object->is_locked());
@@ -67,30 +66,30 @@ Object_test(Test_report*)
#ifdef HAVE_TARGET_32_LITTLE
if (!Sized_object_test<32, false>(test_file_1_32_little,
- test_file_1_size_32_little,
- target_test_pointer_32_little))
+ test_file_1_size_32_little))
++fail;
+ CHECK(&parameters->target() == target_test_pointer_32_little);
#endif
#ifdef HAVE_TARGET_32_BIG
if (!Sized_object_test<32, true>(test_file_1_32_big,
- test_file_1_size_32_big,
- target_test_pointer_32_big))
+ test_file_1_size_32_big))
++fail;
+ CHECK(&parameters->target() == target_test_pointer_32_big);
#endif
#ifdef HAVE_TARGET_64_LITTLE
if (!Sized_object_test<64, false>(test_file_1_64_little,
- test_file_1_size_64_little,
- target_test_pointer_64_little))
+ test_file_1_size_64_little))
++fail;
+ CHECK(&parameters->target() == target_test_pointer_64_little);
#endif
#ifdef HAVE_TARGET_64_BIG
if (!Sized_object_test<64, true>(test_file_1_64_big,
- test_file_1_size_64_big,
- target_test_pointer_64_big))
+ test_file_1_size_64_big))
++fail;
+ CHECK(&parameters->target() == target_test_pointer_64_big);
#endif
return fail == 0;