template<int size, bool big_endian>
void
-Symbol::init_base(const char* name, const char* version, Object* object,
- const elfcpp::Sym<size, big_endian>& sym,
- unsigned int st_shndx, bool is_ordinary)
+Symbol::init_base_object(const char* name, const char* version, Object* object,
+ const elfcpp::Sym<size, big_endian>& sym,
+ unsigned int st_shndx, bool is_ordinary)
{
this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
sym.get_st_visibility(), sym.get_st_nonvis());
// in an Output_data.
void
-Symbol::init_base(const char* name, Output_data* od, elfcpp::STT type,
- elfcpp::STB binding, elfcpp::STV visibility,
- unsigned char nonvis, bool offset_is_from_end)
+Symbol::init_base_output_data(const char* name, Output_data* od,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis,
+ bool offset_is_from_end)
{
this->init_fields(name, NULL, type, binding, visibility, nonvis);
this->u_.in_output_data.output_data = od;
// in an Output_segment.
void
-Symbol::init_base(const char* name, Output_segment* os, elfcpp::STT type,
- elfcpp::STB binding, elfcpp::STV visibility,
- unsigned char nonvis, Segment_offset_base offset_base)
+Symbol::init_base_output_segment(const char* name, Output_segment* os,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis,
+ Segment_offset_base offset_base)
{
this->init_fields(name, NULL, type, binding, visibility, nonvis);
this->u_.in_output_segment.output_segment = os;
// as a constant.
void
-Symbol::init_base(const char* name, elfcpp::STT type,
- elfcpp::STB binding, elfcpp::STV visibility,
- unsigned char nonvis)
+Symbol::init_base_constant(const char* name, elfcpp::STT type,
+ elfcpp::STB binding, elfcpp::STV visibility,
+ unsigned char nonvis)
+{
+ this->init_fields(name, NULL, type, binding, visibility, nonvis);
+ this->source_ = IS_CONSTANT;
+ this->in_reg_ = true;
+}
+
+// Initialize the fields in the base class Symbol for an undefined
+// symbol.
+
+void
+Symbol::init_base_undefined(const char* name, elfcpp::STT type,
+ elfcpp::STB binding, elfcpp::STV visibility,
+ unsigned char nonvis)
{
this->init_fields(name, NULL, type, binding, visibility, nonvis);
- this->source_ = CONSTANT;
+ this->source_ = IS_UNDEFINED;
this->in_reg_ = true;
}
template<int size>
template<bool big_endian>
void
-Sized_symbol<size>::init(const char* name, const char* version, Object* object,
- const elfcpp::Sym<size, big_endian>& sym,
- unsigned int st_shndx, bool is_ordinary)
+Sized_symbol<size>::init_object(const char* name, const char* version,
+ Object* object,
+ const elfcpp::Sym<size, big_endian>& sym,
+ unsigned int st_shndx, bool is_ordinary)
{
- this->init_base(name, version, object, sym, st_shndx, is_ordinary);
+ this->init_base_object(name, version, object, sym, st_shndx, is_ordinary);
this->value_ = sym.get_st_value();
this->symsize_ = sym.get_st_size();
}
template<int size>
void
-Sized_symbol<size>::init(const char* name, Output_data* od,
- Value_type value, Size_type symsize,
- elfcpp::STT type, elfcpp::STB binding,
- elfcpp::STV visibility, unsigned char nonvis,
- bool offset_is_from_end)
-{
- this->init_base(name, od, type, binding, visibility, nonvis,
- offset_is_from_end);
+Sized_symbol<size>::init_output_data(const char* name, Output_data* od,
+ Value_type value, Size_type symsize,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility,
+ unsigned char nonvis,
+ bool offset_is_from_end)
+{
+ this->init_base_output_data(name, od, type, binding, visibility, nonvis,
+ offset_is_from_end);
this->value_ = value;
this->symsize_ = symsize;
}
template<int size>
void
-Sized_symbol<size>::init(const char* name, Output_segment* os,
- Value_type value, Size_type symsize,
- elfcpp::STT type, elfcpp::STB binding,
- elfcpp::STV visibility, unsigned char nonvis,
- Segment_offset_base offset_base)
+Sized_symbol<size>::init_output_segment(const char* name, Output_segment* os,
+ Value_type value, Size_type symsize,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility,
+ unsigned char nonvis,
+ Segment_offset_base offset_base)
{
- this->init_base(name, os, type, binding, visibility, nonvis, offset_base);
+ this->init_base_output_segment(name, os, type, binding, visibility, nonvis,
+ offset_base);
this->value_ = value;
this->symsize_ = symsize;
}
template<int size>
void
-Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
- elfcpp::STT type, elfcpp::STB binding,
- elfcpp::STV visibility, unsigned char nonvis)
+Sized_symbol<size>::init_constant(const char* name, Value_type value,
+ Size_type symsize, elfcpp::STT type,
+ elfcpp::STB binding, elfcpp::STV visibility,
+ unsigned char nonvis)
{
- this->init_base(name, type, binding, visibility, nonvis);
+ this->init_base_constant(name, type, binding, visibility, nonvis);
this->value_ = value;
this->symsize_ = symsize;
}
+// Initialize the fields in Sized_symbol for an undefined symbol.
+
+template<int size>
+void
+Sized_symbol<size>::init_undefined(const char* name, elfcpp::STT type,
+ elfcpp::STB binding, elfcpp::STV visibility,
+ unsigned char nonvis)
+{
+ this->init_base_undefined(name, type, binding, visibility, nonvis);
+ this->value_ = 0;
+ this->symsize_ = 0;
+}
+
// Allocate a common symbol.
template<int size>
if (parameters->options().shared() || parameters->options().relocatable())
return false;
- // If the symbol is not from an object file, then it is defined, and
- // known.
+ // If the symbol is not from an object file, and is not undefined,
+ // 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 (this->source_ != IS_UNDEFINED)
+ return true;
+ }
+ else
+ {
+ // 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 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
return this->u_.in_output_data.output_data->output_section();
case IN_OUTPUT_SEGMENT:
- case CONSTANT:
+ case IS_CONSTANT:
+ case IS_UNDEFINED:
return NULL;
default:
case IN_OUTPUT_DATA:
gold_assert(this->output_section() == os);
break;
- case CONSTANT:
+ case IS_CONSTANT:
this->source_ = IN_OUTPUT_DATA;
this->u_.in_output_data.output_data = os;
this->u_.in_output_data.offset_is_from_end = false;
break;
case IN_OUTPUT_SEGMENT:
+ case IS_UNDEFINED:
default:
gold_unreachable();
}
}
}
- ret->init(name, version, object, sym, st_shndx, is_ordinary);
+ ret->init_object(name, version, object, sym, st_shndx, is_ordinary);
ins.first->second = ret;
if (def)
return NULL;
gold_assert(version == NULL || oldsym != NULL);
- sym->init(name, od, value, symsize, type, binding, visibility, nonvis,
- offset_is_from_end);
+ sym->init_output_data(name, od, value, symsize, type, binding, visibility,
+ nonvis, offset_is_from_end);
if (oldsym == NULL)
{
return NULL;
gold_assert(version == NULL || oldsym != NULL);
- sym->init(name, os, value, symsize, type, binding, visibility, nonvis,
- offset_base);
+ sym->init_output_segment(name, os, value, symsize, type, binding,
+ visibility, nonvis, offset_base);
if (oldsym == NULL)
{
return NULL;
gold_assert(version == NULL || version == name || oldsym != NULL);
- sym->init(name, value, symsize, type, binding, visibility, nonvis);
+ sym->init_constant(name, value, symsize, type, binding, visibility, nonvis);
if (oldsym == NULL)
{
return p->second;
}
+// Add any undefined symbols named on the command line.
+
+void
+Symbol_table::add_undefined_symbols_from_command_line()
+{
+ if (parameters->options().any_undefined())
+ {
+ if (parameters->target().get_size() == 32)
+ {
+#if defined(HAVE_TARGET_32_LITTL) || defined(HAVE_TARGET_32_BIG)
+ this->do_add_undefined_symbols_from_command_line<32>();
+#else
+ gold_unreachable();
+#endif
+ }
+ else if (parameters->target().get_size() == 64)
+ {
+#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
+ this->do_add_undefined_symbols_from_command_line<64>();
+#else
+ gold_unreachable();
+#endif
+ }
+ else
+ gold_unreachable();
+ }
+}
+
+template<int size>
+void
+Symbol_table::do_add_undefined_symbols_from_command_line()
+{
+ for (options::String_set::const_iterator p =
+ parameters->options().undefined_begin();
+ p != parameters->options().undefined_end();
+ ++p)
+ {
+ const char* name = p->c_str();
+
+ if (this->lookup(name) != NULL)
+ continue;
+
+ const char* version = NULL;
+
+ Sized_symbol<size>* sym;
+ Sized_symbol<size>* oldsym;
+ if (parameters->target().is_big_endian())
+ {
+#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
+ sym = this->define_special_symbol<size, true>(&name, &version,
+ false, &oldsym);
+#else
+ gold_unreachable();
+#endif
+ }
+ else
+ {
+#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
+ sym = this->define_special_symbol<size, false>(&name, &version,
+ false, &oldsym);
+#else
+ gold_unreachable();
+#endif
+ }
+
+ gold_assert(oldsym == NULL);
+
+ sym->init_undefined(name, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
+ elfcpp::STV_DEFAULT, 0);
+ ++this->saw_undefined_;
+ }
+}
+
// Set the dynamic symbol indexes. INDEX is the index of the first
// global dynamic symbol. Pointers to the symbols are stored into the
// vector SYMS. The names are added to DYNPOOL. This returns an
}
break;
- case Symbol::CONSTANT:
+ case Symbol::IS_CONSTANT:
value = sym->value();
break;
+ case Symbol::IS_UNDEFINED:
+ value = 0;
+ break;
+
default:
gold_unreachable();
}
shndx = elfcpp::SHN_ABS;
break;
- case Symbol::CONSTANT:
+ case Symbol::IS_CONSTANT:
shndx = elfcpp::SHN_ABS;
break;
+ case Symbol::IS_UNDEFINED:
+ shndx = elfcpp::SHN_UNDEF;
+ break;
+
default:
gold_unreachable();
}
// section.
IN_OUTPUT_SEGMENT,
// Symbol value is constant.
- CONSTANT
+ IS_CONSTANT,
+ // Symbol is undefined.
+ IS_UNDEFINED
};
// When the source is IN_OUTPUT_SEGMENT, we need to describe what
{
bool is_ordinary;
if (this->source_ != FROM_OBJECT)
- return true;
+ return this->source_ != IS_UNDEFINED;
unsigned int shndx = this->shndx(&is_ordinary);
return (is_ordinary
? shndx != elfcpp::SHN_UNDEF
is_undefined() const
{
bool is_ordinary;
- return (this->source_ == FROM_OBJECT
- && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
- && is_ordinary);
+ return ((this->source_ == FROM_OBJECT
+ && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
+ && is_ordinary)
+ || this->source_ == IS_UNDEFINED);
}
// Return whether this is a weak undefined symbol.
bool
is_weak_undefined() const
- {
- bool is_ordinary;
- return (this->source_ == FROM_OBJECT
- && this->binding() == elfcpp::STB_WEAK
- && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
- && is_ordinary);
- }
+ { return this->is_undefined() && this->binding() == elfcpp::STB_WEAK; }
// Return whether this is an absolute symbol.
bool
is_absolute() const
{
bool is_ordinary;
- return (this->source_ == FROM_OBJECT
- && this->shndx(&is_ordinary) == elfcpp::SHN_ABS
- && !is_ordinary);
+ return ((this->source_ == FROM_OBJECT
+ && this->shndx(&is_ordinary) == elfcpp::SHN_ABS
+ && !is_ordinary)
+ || this->source_ == IS_CONSTANT);
}
// Return whether this is a common symbol.
// index rather than a special code.
template<int size, bool big_endian>
void
- init_base(const char *name, const char* version, Object* object,
- const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
- bool is_ordinary);
+ init_base_object(const char *name, const char* version, Object* object,
+ const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
+ bool is_ordinary);
// Initialize fields for an Output_data.
void
- init_base(const char* name, Output_data*, elfcpp::STT, elfcpp::STB,
- elfcpp::STV, unsigned char nonvis, bool offset_is_from_end);
+ init_base_output_data(const char* name, Output_data*, elfcpp::STT,
+ elfcpp::STB, elfcpp::STV, unsigned char nonvis,
+ bool offset_is_from_end);
// Initialize fields for an Output_segment.
void
- init_base(const char* name, Output_segment* os, elfcpp::STT type,
- elfcpp::STB binding, elfcpp::STV visibility,
- unsigned char nonvis, Segment_offset_base offset_base);
+ init_base_output_segment(const char* name, Output_segment* os,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis,
+ Segment_offset_base offset_base);
// Initialize fields for a constant.
void
- init_base(const char* name, elfcpp::STT type, elfcpp::STB binding,
- elfcpp::STV visibility, unsigned char nonvis);
+ init_base_constant(const char* name, elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis);
+
+ // Initialize fields for an undefined symbol.
+ void
+ init_base_undefined(const char* name, elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis);
// Override existing symbol.
template<int size, bool big_endian>
// index rather than a special code.
template<bool big_endian>
void
- init(const char *name, const char* version, Object* object,
- const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
- bool is_ordinary);
+ init_object(const char *name, const char* version, Object* object,
+ const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
+ bool is_ordinary);
// Initialize fields for an Output_data.
void
- init(const char* name, Output_data*, Value_type value, Size_type symsize,
- elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
- bool offset_is_from_end);
+ init_output_data(const char* name, Output_data*, Value_type value,
+ Size_type symsize, elfcpp::STT, elfcpp::STB, elfcpp::STV,
+ unsigned char nonvis, bool offset_is_from_end);
// Initialize fields for an Output_segment.
void
- init(const char* name, Output_segment*, Value_type value, Size_type symsize,
- elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
- Segment_offset_base offset_base);
+ init_output_segment(const char* name, Output_segment*, Value_type value,
+ Size_type symsize, elfcpp::STT, elfcpp::STB, elfcpp::STV,
+ unsigned char nonvis, Segment_offset_base offset_base);
// Initialize fields for a constant.
void
- init(const char* name, Value_type value, Size_type symsize,
- elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
+ init_constant(const char* name, Value_type value, Size_type symsize,
+ elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
+
+ // Initialize fields for an undefined symbol.
+ void
+ init_undefined(const char* name, elfcpp::STT, elfcpp::STB, elfcpp::STV,
+ unsigned char nonvis);
// Override existing symbol.
template<bool big_endian>
void
detect_odr_violations(const Task*, const char* output_file_name) const;
+ // Add any undefined symbols named on the command line to the symbol
+ // table.
+ void
+ add_undefined_symbols_from_command_line();
+
// SYM is defined using a COPY reloc. Return the dynamic object
// where the original definition was found.
Dynobj*
elfcpp::STV visibility, unsigned char nonvis,
bool only_if_ref, bool force_override);
+ // Add any undefined symbols named on the command line to the symbol
+ // table, sized version.
+ template<int size>
+ void
+ do_add_undefined_symbols_from_command_line();
+
// Allocate the common symbols, sized version.
template<int size>
void