this->is_defined_in_discarded_section_ = false;
this->undef_binding_set_ = false;
this->undef_binding_weak_ = false;
+ this->is_predefined_ = false;
}
// Return the demangled version of the symbol's name, but only
Symbol::init_base_output_data(const char* name, const char* version,
Output_data* od, elfcpp::STT type,
elfcpp::STB binding, elfcpp::STV visibility,
- unsigned char nonvis, bool offset_is_from_end)
+ unsigned char nonvis, bool offset_is_from_end,
+ bool is_predefined)
{
this->init_fields(name, version, type, binding, visibility, nonvis);
this->u_.in_output_data.output_data = od;
this->source_ = IN_OUTPUT_DATA;
this->in_reg_ = true;
this->in_real_elf_ = true;
+ this->is_predefined_ = is_predefined;
}
// Initialize the fields in the base class Symbol for a symbol defined
Output_segment* os, elfcpp::STT type,
elfcpp::STB binding, elfcpp::STV visibility,
unsigned char nonvis,
- Segment_offset_base offset_base)
+ Segment_offset_base offset_base,
+ bool is_predefined)
{
this->init_fields(name, version, type, binding, visibility, nonvis);
this->u_.in_output_segment.output_segment = os;
this->source_ = IN_OUTPUT_SEGMENT;
this->in_reg_ = true;
this->in_real_elf_ = true;
+ this->is_predefined_ = is_predefined;
}
// Initialize the fields in the base class Symbol for a symbol defined
void
Symbol::init_base_constant(const char* name, const char* version,
elfcpp::STT type, elfcpp::STB binding,
- elfcpp::STV visibility, unsigned char nonvis)
+ elfcpp::STV visibility, unsigned char nonvis,
+ bool is_predefined)
{
this->init_fields(name, version, type, binding, visibility, nonvis);
this->source_ = IS_CONSTANT;
this->in_reg_ = true;
this->in_real_elf_ = true;
+ this->is_predefined_ = is_predefined;
}
// Initialize the fields in the base class Symbol for an undefined
elfcpp::STB binding,
elfcpp::STV visibility,
unsigned char nonvis,
- bool offset_is_from_end)
+ bool offset_is_from_end,
+ bool is_predefined)
{
this->init_base_output_data(name, version, od, type, binding, visibility,
- nonvis, offset_is_from_end);
+ nonvis, offset_is_from_end, is_predefined);
this->value_ = value;
this->symsize_ = symsize;
}
elfcpp::STB binding,
elfcpp::STV visibility,
unsigned char nonvis,
- Segment_offset_base offset_base)
+ Segment_offset_base offset_base,
+ bool is_predefined)
{
this->init_base_output_segment(name, version, os, type, binding, visibility,
- nonvis, offset_base);
+ nonvis, offset_base, is_predefined);
this->value_ = value;
this->symsize_ = symsize;
}
Sized_symbol<size>::init_constant(const char* name, const char* version,
Value_type value, Size_type symsize,
elfcpp::STT type, elfcpp::STB binding,
- elfcpp::STV visibility, unsigned char nonvis)
+ elfcpp::STV visibility, unsigned char nonvis,
+ bool is_predefined)
{
- this->init_base_constant(name, version, type, binding, visibility, nonvis);
+ this->init_base_constant(name, version, type, binding, visibility, nonvis,
+ is_predefined);
this->value_ = value;
this->symsize_ = symsize;
}
this->symsize_ = 0;
}
+// Return an allocated string holding the symbol's name as
+// name@version. This is used for relocatable links.
+
+std::string
+Symbol::versioned_name() const
+{
+ gold_assert(this->version_ != NULL);
+ std::string ret = this->name_;
+ ret.push_back('@');
+ if (this->is_def_)
+ ret.push_back('@');
+ ret += this->version_;
+ return ret;
+}
+
// Return true if SHNDX represents a common symbol.
bool
// externally visible, we need to add it.
if ((parameters->options().export_dynamic() || parameters->options().shared())
&& !this->is_from_dynobj()
+ && !this->is_undefined()
&& this->is_externally_visible())
return true;
}
void
-Symbol_table::gc_mark_symbol_for_shlib(Symbol* sym)
+Symbol_table::gc_mark_symbol(Symbol* sym)
{
- if (!sym->is_from_dynobj()
- && sym->is_externally_visible())
+ // Add the object and section to the work list.
+ Relobj* obj = static_cast<Relobj*>(sym->object());
+ bool is_ordinary;
+ unsigned int shndx = sym->shndx(&is_ordinary);
+ if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
{
- //Add the object and section to the work list.
- Relobj* obj = static_cast<Relobj*>(sym->object());
- bool is_ordinary;
- unsigned int shndx = sym->shndx(&is_ordinary);
- if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
- {
- gold_assert(this->gc_!= NULL);
- this->gc_->worklist().push(Section_id(obj, shndx));
- }
+ gold_assert(this->gc_!= NULL);
+ this->gc_->worklist().push(Section_id(obj, shndx));
}
}
{
if (sym->in_dyn() && sym->source() == Symbol::FROM_OBJECT
&& !sym->object()->is_dynamic())
- {
- Relobj* obj = static_cast<Relobj*>(sym->object());
- bool is_ordinary;
- unsigned int shndx = sym->shndx(&is_ordinary);
- if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
- {
- gold_assert(this->gc_ != NULL);
- this->gc_->worklist().push(Section_id(obj, shndx));
- }
- }
+ this->gc_mark_symbol(sym);
}
// Make TO a symbol which forwards to FROM.
bool is_default_version = false;
bool is_forced_local = false;
+ // FIXME: For incremental links, we don't store version information,
+ // so we need to ignore version symbols for now.
+ if (parameters->incremental_update() && ver != NULL)
+ {
+ namelen = ver - name;
+ ver = NULL;
+ }
+
if (ver != NULL)
{
// The symbol name is of the form foo@VERSION or foo@@VERSION
{
memcpy(symbuf, p, sym_size);
elfcpp::Sym_write<size, big_endian> sw(symbuf);
- if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary)
+ if (orig_st_shndx != elfcpp::SHN_UNDEF
+ && is_ordinary
+ && relobj->e_type() == elfcpp::ET_REL)
{
- // Symbol values in object files are section relative.
- // This is normally what we want, but since here we are
- // converting the symbol to absolute we need to add the
- // section address. The section address in an object
+ // Symbol values in relocatable object files are section
+ // relative. This is normally what we want, but since here
+ // we are converting the symbol to absolute we need to add
+ // the section address. The section address in an object
// file is normally zero, but people can use a linker
// script to change it.
sw.put_st_value(sym.get_st_value()
is_default_version, *psym, st_shndx,
is_ordinary, orig_st_shndx);
- // If building a shared library using garbage collection, do not
- // treat externally visible symbols as garbage.
- if (parameters->options().gc_sections()
- && parameters->options().shared())
- this->gc_mark_symbol_for_shlib(res);
-
if (is_forced_local)
this->force_local(res);
+ // Do not treat this symbol as garbage if this symbol will be
+ // exported to the dynamic symbol table. This is true when
+ // building a shared library or using --export-dynamic and
+ // the symbol is externally visible.
+ if (parameters->options().gc_sections()
+ && res->is_externally_visible()
+ && !res->is_from_dynobj()
+ && (parameters->options().shared()
+ || parameters->options().export_dynamic()))
+ this->gc_mark_symbol(res);
+
if (is_defined_in_discarded_section)
res->set_is_defined_in_discarded_section();
return;
}
+ // FIXME: For incremental links, we don't store version information,
+ // so we need to ignore version symbols for now.
+ if (parameters->incremental_update())
+ versym = NULL;
+
if (versym != NULL && versym_size / 2 < count)
{
dynobj->error(_("too few symbol versions"));
// Add a symbol from a incremental object file.
template<int size, bool big_endian>
-Symbol*
+Sized_symbol<size>*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
return NULL;
*pname = oldsym->name();
- if (!is_default_version)
+ if (is_default_version)
+ *pversion = this->namepool_.add(*pversion, true, NULL);
+ else
*pversion = oldsym->version();
}
else
return NULL;
sym->init_output_data(name, version, od, value, symsize, type, binding,
- visibility, nonvis, offset_is_from_end);
+ visibility, nonvis, offset_is_from_end,
+ defined == PREDEFINED);
if (oldsym == NULL)
{
return sym;
}
- if (Symbol_table::should_override_with_special(oldsym, defined))
+ if (Symbol_table::should_override_with_special(oldsym, type, defined))
this->override_with_special(oldsym, sym);
if (resolve_oldsym)
return NULL;
sym->init_output_segment(name, version, os, value, symsize, type, binding,
- visibility, nonvis, offset_base);
+ visibility, nonvis, offset_base,
+ defined == PREDEFINED);
if (oldsym == NULL)
{
return sym;
}
- if (Symbol_table::should_override_with_special(oldsym, defined))
+ if (Symbol_table::should_override_with_special(oldsym, type, defined))
this->override_with_special(oldsym, sym);
if (resolve_oldsym)
return NULL;
sym->init_constant(name, version, value, symsize, type, binding, visibility,
- nonvis);
+ nonvis, defined == PREDEFINED);
if (oldsym == NULL)
{
}
if (force_override
- || Symbol_table::should_override_with_special(oldsym, defined))
+ || Symbol_table::should_override_with_special(oldsym, type, defined))
this->override_with_special(oldsym, sym);
if (resolve_oldsym)
unsigned int* pindex, off_t* poff)
{
sym->set_symtab_index(*pindex);
- pool->add(sym->name(), false, NULL);
+ if (sym->version() == NULL || !parameters->options().relocatable())
+ pool->add(sym->name(), false, NULL);
+ else
+ pool->add(sym->versioned_name(), true, NULL);
++*pindex;
*poff += elfcpp::Elf_sizes<size>::sym_size;
}
typename elfcpp::Elf_types<size>::Elf_Addr sym_value = sym->value();
typename elfcpp::Elf_types<size>::Elf_Addr dynsym_value = sym_value;
elfcpp::STB binding = sym->binding();
+
+ // If --no-gnu-unique is set, change STB_GNU_UNIQUE to STB_GLOBAL.
+ if (binding == elfcpp::STB_GNU_UNIQUE
+ && !parameters->options().gnu_unique())
+ binding = elfcpp::STB_GLOBAL;
+
switch (sym->source())
{
case Symbol::FROM_OBJECT:
unsigned char* p) const
{
elfcpp::Sym_write<size, big_endian> osym(p);
- osym.put_st_name(pool->get_offset(sym->name()));
+ if (sym->version() == NULL || !parameters->options().relocatable())
+ osym.put_st_name(pool->get_offset(sym->name()));
+ else
+ osym.put_st_name(pool->get_offset(sym->versioned_name()));
osym.put_st_value(value);
// Use a symbol size of zero for undefined symbols from shared libraries.
if (shndx == elfcpp::SHN_UNDEF && sym->is_from_dynobj())
size_t relnum, off_t reloffset) const
{
gold_assert(sym->has_warning());
+
+ // We don't want to issue a warning for a relocation against the
+ // symbol in the same object file in which the symbol is defined.
+ if (sym->object() == relinfo->object)
+ return;
+
Warning_table::const_iterator p = this->warnings_.find(sym->name());
gold_assert(p != this->warnings_.end());
gold_warning_at_location(relinfo, relnum, reloffset,
#ifdef HAVE_TARGET_32_LITTLE
template
-Symbol*
+Sized_symbol<32>*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
#ifdef HAVE_TARGET_32_BIG
template
-Symbol*
+Sized_symbol<32>*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
#ifdef HAVE_TARGET_64_LITTLE
template
-Symbol*
+Sized_symbol<64>*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
#ifdef HAVE_TARGET_64_BIG
template
-Symbol*
+Sized_symbol<64>*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,