Use parameters to track whether we are doing a static link. Fix up

final_value_is_known for weak undefined symbols.  Pointed out by Cary
Coutant.
This commit is contained in:
Ian Lance Taylor 2007-09-28 06:36:25 +00:00
parent fe6fbf8b6e
commit b3b74ddc6e
5 changed files with 79 additions and 7 deletions

View File

@ -160,6 +160,9 @@ queue_middle_tasks(const General_options& options,
Layout* layout,
Workqueue* workqueue)
{
// Now we have seen all the input files.
set_parameters_doing_static_link(!input_objects->any_dynamic());
// Define some sections and symbols needed for a dynamic link. This
// handles some cases we want to see before we read the relocs.
layout->create_initial_dynamic_sections(input_objects, symtab);

View File

@ -31,7 +31,8 @@ namespace gold
// Initialize the parameters from the options.
Parameters::Parameters(const General_options* options)
: is_size_and_endian_valid_(false), size_(0), is_big_endian_(false),
: is_doing_static_link_valid_(false), doing_static_link_(false),
is_size_and_endian_valid_(false), size_(0), is_big_endian_(false),
optimization_level_(options->optimization_level())
{
if (options->is_shared())
@ -42,6 +43,15 @@ Parameters::Parameters(const General_options* options)
this->output_file_type_ = OUTPUT_EXECUTABLE;
}
// Set whether we are doing a static link.
void
Parameters::set_doing_static_link(bool doing_static_link)
{
this->doing_static_link_ = doing_static_link;
this->is_doing_static_link_valid_ = true;
}
// Set the size and endianness.
void
@ -76,6 +86,16 @@ initialize_parameters(const General_options* options)
parameters = static_parameters = new Parameters(options);
}
// Set whether we are doing a static link.
void
set_parameters_doing_static_link(bool doing_static_link)
{
static_parameters->set_doing_static_link(doing_static_link);
}
// Set the size and endianness.
void
set_parameters_size_and_endianness(int size, bool is_big_endian)
{

View File

@ -56,6 +56,16 @@ class Parameters
output_is_object() const
{ return this->output_file_type_ == OUTPUT_OBJECT; }
// Whether we are doing a static link--a link in which none of the
// input files are shared libraries. This is only known after we
// have seen all the input files.
bool
doing_static_link() const
{
gold_assert(this->is_doing_static_link_valid_);
return this->doing_static_link_;
}
// The size of the output file we are generating. This should
// return 32 or 64.
int
@ -78,6 +88,10 @@ class Parameters
optimization_level() const
{ return this->optimization_level_; }
// Set whether we are doing a static link.
void
set_doing_static_link(bool doing_static_link);
// Set the size and endianness.
void
set_size_and_endianness(int size, bool is_big_endian);
@ -96,6 +110,10 @@ class Parameters
// The type of the output file.
Output_file_type output_file_type_;
// Whether the doing_static_link_ field is valid.
bool is_doing_static_link_valid_;
// Whether we are doing a static link.
bool doing_static_link_;
// Whether the size_ and is_big_endian_ fields are valid.
bool is_size_and_endian_valid_;
// The size of the output file--32 or 64.
@ -115,6 +133,9 @@ extern void initialize_parameters(const General_options*);
// Set the size and endianness of the global parameters variable.
extern void set_parameters_size_and_endianness(int size, bool is_big_endian);
// Set whether we are doing a static link.
extern void set_parameters_doing_static_link(bool doing_static_link);
} // End namespace gold.
#endif // !defined(GOLD_PARAMATERS_H)

View File

@ -187,6 +187,39 @@ Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
this->symsize_ = symsize;
}
// Return true if the final value of this symbol is known at link
// time.
bool
Symbol::final_value_is_known() const
{
// If we are not generating an executable, then no final values are
// known, since they will change at runtime.
if (!parameters->output_is_executable())
return false;
// If the symbol is not from an object file, then it is defined, and
// known.
if (this->source_ != FROM_OBJECT)
return true;
// If the symbol is from a dynamic object, then the final value is
// not known.
if (this->object()->is_dynamic())
return false;
// If the symbol is not undefined (it is defined or common), then
// the final value is known.
if (!this->is_undefined())
return true;
// If the symbol is undefined, then whether the final value is known
// depends on whether we are doing a static link. If we are doing a
// dynamic link, then the final value could be filled in at runtime.
// This could reasonably be the case for a weak undefined symbol.
return parameters->doing_static_link();
}
// Class Symbol_table.
Symbol_table::Symbol_table()

View File

@ -341,12 +341,7 @@ class Symbol
// Return true if the final value of this symbol is known at link
// time.
bool
final_value_is_known() const
{
if (parameters->output_is_shared())
return false;
return this->source_ != FROM_OBJECT || !this->object()->is_dynamic();
}
final_value_is_known() const;
// Return whether this is a defined symbol (not undefined or
// common).