#include "target.h"
#include "workqueue.h"
#include "symtab.h"
+#include "demangle.h" // needed for --dynamic-list-cpp-new
+#include "plugin.h"
namespace gold
{
this->is_copied_from_dynobj_ = false;
this->is_forced_local_ = false;
this->is_ordinary_shndx_ = false;
+ this->in_real_elf_ = false;
}
// Return the demangled version of the symbol's name, but only
this->source_ = FROM_OBJECT;
this->in_reg_ = !object->is_dynamic();
this->in_dyn_ = object->is_dynamic();
+ this->in_real_elf_ = object->pluginobj() == NULL;
}
// Initialize the fields in the base class Symbol for a symbol defined
this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
this->source_ = IN_OUTPUT_DATA;
this->in_reg_ = true;
+ this->in_real_elf_ = true;
}
// Initialize the fields in the base class Symbol for a symbol defined
this->u_.in_output_segment.offset_base = offset_base;
this->source_ = IN_OUTPUT_SEGMENT;
this->in_reg_ = true;
+ this->in_real_elf_ = true;
}
// Initialize the fields in the base class Symbol for a symbol defined
this->init_fields(name, version, type, binding, visibility, nonvis);
this->source_ = IS_CONSTANT;
this->in_reg_ = true;
+ this->in_real_elf_ = true;
}
// Initialize the fields in the base class Symbol for an undefined
elfcpp::STV visibility, unsigned char nonvis)
{
this->init_fields(name, version, type, binding, visibility, nonvis);
+ this->dynsym_index_ = -1U;
this->source_ = IS_UNDEFINED;
this->in_reg_ = true;
+ this->in_real_elf_ = true;
}
// Allocate a common symbol in the base.
this->value_ = value;
}
+// The ""'s around str ensure str is a string literal, so sizeof works.
+#define strprefix(var, str) (strncmp(var, str, sizeof("" str "") - 1) == 0)
+
// Return true if this symbol should be added to the dynamic symbol
// table.
if (this->is_forced_local())
return false;
+ // If the symbol was forced dynamic in a --dynamic-list file, add it.
+ if (parameters->options().in_dynamic_list(this->name()))
+ return true;
+
+ // If dynamic-list-data was specified, add any STT_OBJECT.
+ if (parameters->options().dynamic_list_data()
+ && !this->is_from_dynobj()
+ && this->type() == elfcpp::STT_OBJECT)
+ return true;
+
+ // If --dynamic-list-cpp-new was specified, add any new/delete symbol.
+ // If --dynamic-list-cpp-typeinfo was specified, add any typeinfo symbols.
+ if ((parameters->options().dynamic_list_cpp_new()
+ || parameters->options().dynamic_list_cpp_typeinfo())
+ && !this->is_from_dynobj())
+ {
+ // TODO(csilvers): We could probably figure out if we're an operator
+ // new/delete or typeinfo without the need to demangle.
+ char* demangled_name = cplus_demangle(this->name(),
+ DMGL_ANSI | DMGL_PARAMS);
+ if (demangled_name == NULL)
+ {
+ // Not a C++ symbol, so it can't satisfy these flags
+ }
+ else if (parameters->options().dynamic_list_cpp_new()
+ && (strprefix(demangled_name, "operator new")
+ || strprefix(demangled_name, "operator delete")))
+ {
+ free(demangled_name);
+ return true;
+ }
+ else if (parameters->options().dynamic_list_cpp_typeinfo()
+ && (strprefix(demangled_name, "typeinfo name for")
+ || strprefix(demangled_name, "typeinfo for")))
+ {
+ free(demangled_name);
+ return true;
+ }
+ else
+ free(demangled_name);
+ }
+
// If exporting all symbols or building a shared library,
// and the symbol is defined in a regular object and is
// externally visible, we need to add it.
if (shndx != elfcpp::SHN_UNDEF && this->is_ordinary_shndx_)
{
gold_assert(!this->u_.from_object.object->is_dynamic());
+ gold_assert(this->u_.from_object.object->pluginobj() == NULL);
Relobj* relobj = static_cast<Relobj*>(this->u_.from_object.object);
return relobj->output_section(shndx);
}
template<int size, bool big_endian>
void
-Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
- const char* version)
+Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from)
{
unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
elfcpp::Sym_write<size, big_endian> esym(buf);
bool is_ordinary;
unsigned int shndx = from->shndx(&is_ordinary);
this->resolve(to, esym.sym(), shndx, is_ordinary, shndx, from->object(),
- version);
+ from->version());
if (from->in_reg())
to->set_in_reg();
if (from->in_dyn())
// NAME/NULL point to NAME/VERSION.
insdef.first->second = ret;
}
- else if (insdef.first->second != ret
- && insdef.first->second->is_undefined())
+ else if (insdef.first->second != ret)
{
// This is the unfortunate case where we already have
- // entries for both NAME/VERSION and NAME/NULL. Note
- // that we don't want to combine them if the existing
- // symbol is going to override the new one. FIXME: We
- // currently just test is_undefined, but this may not do
- // the right thing if the existing symbol is from a
- // shared library and the new one is from a regular
- // object.
-
- const Sized_symbol<size>* sym2;
- sym2 = this->get_sized_symbol<size>(insdef.first->second);
- Symbol_table::resolve<size, big_endian>(ret, sym2, version);
- this->make_forwarder(insdef.first->second, ret);
- insdef.first->second = ret;
+ // entries for both NAME/VERSION and NAME/NULL. We now
+ // see a symbol NAME/VERSION where VERSION is the
+ // default version. We have already resolved this new
+ // symbol with the existing NAME/VERSION symbol.
+
+ // It's possible that NAME/NULL and NAME/VERSION are
+ // both defined in regular objects. This can only
+ // happen if one object file defines foo and another
+ // defines foo@@ver. This is somewhat obscure, but we
+ // call it a multiple definition error.
+
+ // It's possible that NAME/NULL actually has a version,
+ // in which case it won't be the same as VERSION. This
+ // happens with ver_test_7.so in the testsuite for the
+ // symbol t2_2. We see t2_2@@VER2, so we define both
+ // t2_2/VER2 and t2_2/NULL. We then see an unadorned
+ // t2_2 in an object file and give it version VER1 from
+ // the version script. This looks like a default
+ // definition for VER1, so it looks like we should merge
+ // t2_2/NULL with t2_2/VER1. That doesn't make sense,
+ // but it's not obvious that this is an error, either.
+ // So we just punt.
+
+ // If one of the symbols has non-default visibility, and
+ // the other is defined in a shared object, then they
+ // are different symbols.
+
+ // Otherwise, we just resolve the symbols as though they
+ // were the same.
+
+ if (insdef.first->second->version() != NULL)
+ {
+ gold_assert(insdef.first->second->version() != version);
+ def = false;
+ }
+ else if (ret->visibility() != elfcpp::STV_DEFAULT
+ && insdef.first->second->is_from_dynobj())
+ def = false;
+ else if (insdef.first->second->visibility() != elfcpp::STV_DEFAULT
+ && ret->is_from_dynobj())
+ def = false;
+ else
+ {
+ const Sized_symbol<size>* sym2;
+ sym2 = this->get_sized_symbol<size>(insdef.first->second);
+ Symbol_table::resolve<size, big_endian>(ret, sym2);
+ this->make_forwarder(insdef.first->second, ret);
+ insdef.first->second = ret;
+ }
}
else
def = false;
size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
- typename Sized_relobj<size, big_endian>::Symbols* sympointers)
+ typename Sized_relobj<size, big_endian>::Symbols* sympointers,
+ size_t *defined)
{
+ *defined = 0;
+
gold_assert(size == relobj->target()->get_size());
gold_assert(size == parameters->target().get_size());
const unsigned char* p = syms;
for (size_t i = 0; i < count; ++i, p += sym_size)
{
+ (*sympointers)[i] = NULL;
+
elfcpp::Sym<size, big_endian> sym(p);
unsigned int st_name = sym.get_st_name();
if (!is_ordinary)
orig_st_shndx = elfcpp::SHN_UNDEF;
+ if (st_shndx != elfcpp::SHN_UNDEF)
+ ++*defined;
+
// A symbol defined in a section which we are not including must
// be treated as an undefined symbol.
if (st_shndx != elfcpp::SHN_UNDEF
// name from the version name. If there are two '@' characters,
// this is the default version.
const char* ver = strchr(name, '@');
+ Stringpool::Key ver_key = 0;
int namelen = 0;
// DEF: is the version default? LOCAL: is the symbol forced local?
bool def = false;
def = true;
++ver;
}
+ ver = this->namepool_.add(ver, true, &ver_key);
}
// We don't want to assign a version to an undefined symbol,
// even if it is listed in the version script. FIXME: What
// about a common symbol?
- else if (!version_script_.empty()
- && st_shndx != elfcpp::SHN_UNDEF)
- {
- // The symbol name did not have a version, but
- // the version script may assign a version anyway.
- namelen = strlen(name);
- def = true;
- // Check the global: entries from the version script.
- const std::string& version =
- version_script_.get_symbol_version(name);
- if (!version.empty())
- ver = version.c_str();
- // Check the local: entries from the version script
- if (version_script_.symbol_is_local(name))
- local = true;
- }
+ else
+ {
+ namelen = strlen(name);
+ if (!this->version_script_.empty()
+ && st_shndx != elfcpp::SHN_UNDEF)
+ {
+ // The symbol name did not have a version, but the
+ // version script may assign a version anyway.
+ std::string version;
+ if (this->version_script_.get_symbol_version(name, &version))
+ {
+ // The version can be empty if the version script is
+ // only used to force some symbols to be local.
+ if (!version.empty())
+ {
+ ver = this->namepool_.add_with_length(version.c_str(),
+ version.length(),
+ true,
+ &ver_key);
+ def = true;
+ }
+ }
+ else if (this->version_script_.symbol_is_local(name))
+ local = true;
+ }
+ }
elfcpp::Sym<size, big_endian>* psym = &sym;
unsigned char symbuf[sym_size];
psym = &sym2;
}
+ Stringpool::Key name_key;
+ name = this->namepool_.add_with_length(name, namelen, true,
+ &name_key);
+
Sized_symbol<size>* res;
- if (ver == NULL)
- {
- Stringpool::Key name_key;
- name = this->namepool_.add(name, true, &name_key);
- res = this->add_from_object(relobj, name, name_key, NULL, 0,
- false, *psym, st_shndx, is_ordinary,
- orig_st_shndx);
- if (local)
- this->force_local(res);
- }
- else
- {
- Stringpool::Key name_key;
- name = this->namepool_.add_with_length(name, namelen, true,
- &name_key);
- Stringpool::Key ver_key;
- ver = this->namepool_.add(ver, true, &ver_key);
+ res = this->add_from_object(relobj, name, name_key, ver, ver_key,
+ def, *psym, st_shndx, is_ordinary,
+ orig_st_shndx);
- res = this->add_from_object(relobj, name, name_key, ver, ver_key,
- def, *psym, st_shndx, is_ordinary,
- orig_st_shndx);
- }
+ if (local)
+ this->force_local(res);
(*sympointers)[i] = res;
}
}
+// Add a symbol from a plugin-claimed file.
+
+template<int size, bool big_endian>
+Symbol*
+Symbol_table::add_from_pluginobj(
+ Sized_pluginobj<size, big_endian>* obj,
+ const char* name,
+ const char* ver,
+ elfcpp::Sym<size, big_endian>* sym)
+{
+ unsigned int st_shndx = sym->get_st_shndx();
+
+ Stringpool::Key ver_key = 0;
+ bool def = false;
+ bool local = false;
+
+ if (ver != NULL)
+ {
+ ver = this->namepool_.add(ver, true, &ver_key);
+ }
+ // We don't want to assign a version to an undefined symbol,
+ // even if it is listed in the version script. FIXME: What
+ // about a common symbol?
+ else
+ {
+ if (!this->version_script_.empty()
+ && st_shndx != elfcpp::SHN_UNDEF)
+ {
+ // The symbol name did not have a version, but the
+ // version script may assign a version anyway.
+ std::string version;
+ if (this->version_script_.get_symbol_version(name, &version))
+ {
+ // The version can be empty if the version script is
+ // only used to force some symbols to be local.
+ if (!version.empty())
+ {
+ ver = this->namepool_.add_with_length(version.c_str(),
+ version.length(),
+ true,
+ &ver_key);
+ def = true;
+ }
+ }
+ else if (this->version_script_.symbol_is_local(name))
+ local = true;
+ }
+ }
+
+ Stringpool::Key name_key;
+ name = this->namepool_.add(name, true, &name_key);
+
+ Sized_symbol<size>* res;
+ res = this->add_from_object(obj, name, name_key, ver, ver_key,
+ def, *sym, st_shndx, true, st_shndx);
+
+ if (local)
+ this->force_local(res);
+
+ return res;
+}
+
// Add all the symbols in a dynamic object to the hash table.
template<int size, bool big_endian>
size_t sym_name_size,
const unsigned char* versym,
size_t versym_size,
- const std::vector<const char*>* version_map)
+ const std::vector<const char*>* version_map,
+ typename Sized_relobj<size, big_endian>::Symbols* sympointers,
+ size_t* defined)
{
+ *defined = 0;
+
gold_assert(size == dynobj->target()->get_size());
gold_assert(size == parameters->target().get_size());
{
elfcpp::Sym<size, big_endian> sym(p);
+ if (sympointers != NULL)
+ (*sympointers)[i] = NULL;
+
// Ignore symbols with local binding or that have
// internal or hidden visibility.
if (sym.get_st_bind() == elfcpp::STB_LOCAL
unsigned int st_shndx = dynobj->adjust_sym_shndx(i, psym->get_st_shndx(),
&is_ordinary);
+ if (st_shndx != elfcpp::SHN_UNDEF)
+ ++*defined;
+
Sized_symbol<size>* res;
if (versym == NULL)
&& res->source() == Symbol::FROM_OBJECT
&& res->object() == dynobj)
object_symbols.push_back(res);
+
+ if (sympointers != NULL)
+ (*sympointers)[i] = res;
}
this->record_weak_aliases(&object_symbols);
// If the caller didn't give us a version, see if we get one from
// the version script.
+ std::string v;
if (*pversion == NULL)
{
- const std::string& v(this->version_script_.get_symbol_version(*pname));
- if (!v.empty())
- *pversion = v.c_str();
+ if (this->version_script_.get_symbol_version(*pname, &v))
+ {
+ if (!v.empty())
+ *pversion = v.c_str();
+ }
}
if (only_if_ref)
value = 0;
shndx = elfcpp::SHN_UNDEF;
}
+ else if (symobj->pluginobj() != NULL)
+ {
+ value = 0;
+ shndx = elfcpp::SHN_UNDEF;
+ }
else if (shndx == elfcpp::SHN_UNDEF)
value = 0;
else if (!is_ordinary
}
uint64_t secoff64 = relobj->output_section_offset(shndx);
- Value_type secoff = convert_types<Value_type, uint64_t>(secoff64);
- if (sym->type() == elfcpp::STT_TLS)
- value = sym->value() + os->tls_offset() + secoff;
- else
- value = sym->value() + os->address() + secoff;
+ if (secoff64 == -1ULL)
+ {
+ // The section needs special handling (e.g., a merge section).
+ value = os->output_address(relobj, shndx, sym->value());
+ }
+ else
+ {
+ Value_type secoff =
+ convert_types<Value_type, uint64_t>(secoff64);
+ if (sym->type() == elfcpp::STT_TLS)
+ value = sym->value() + os->tls_offset() + secoff;
+ else
+ value = sym->value() + os->address() + secoff;
+ }
}
}
break;
dynsym_value = target.dynsym_value(sym);
shndx = elfcpp::SHN_UNDEF;
}
+ else if (symobj->pluginobj() != NULL)
+ shndx = elfcpp::SHN_UNDEF;
else if (in_shndx == elfcpp::SHN_UNDEF
|| (!is_ordinary
&& (in_shndx == elfcpp::SHN_ABS
elfcpp::Sym_write<size, big_endian> osym(p);
osym.put_st_name(pool->get_offset(sym->name()));
osym.put_st_value(value);
- osym.put_st_size(sym->symsize());
+ // Use a symbol size of zero for undefined symbols from shared libraries.
+ if (shndx == elfcpp::SHN_UNDEF && sym->is_from_dynobj())
+ osym.put_st_size(0);
+ else
+ osym.put_st_size(sym->symsize());
// A version script may have overridden the default binding.
if (sym->is_forced_local())
osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL, sym->type()));
// A very ugly cast.
Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
if (!dynobj->has_unknown_needed_entries())
- gold_error(_("%s: undefined reference to '%s'"),
- sym->object()->name().c_str(),
- sym->demangled_name().c_str());
+ {
+ if (sym->version())
+ gold_error(_("%s: undefined reference to '%s', version '%s'"),
+ sym->object()->name().c_str(),
+ sym->demangled_name().c_str(),
+ sym->version());
+ else
+ gold_error(_("%s: undefined reference to '%s'"),
+ sym->object()->name().c_str(),
+ sym->demangled_name().c_str());
+ }
}
}
size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
- Sized_relobj<32, true>::Symbols* sympointers);
+ Sized_relobj<32, false>::Symbols* sympointers,
+ size_t* defined);
#endif
#ifdef HAVE_TARGET_32_BIG
size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
- Sized_relobj<32, false>::Symbols* sympointers);
+ Sized_relobj<32, true>::Symbols* sympointers,
+ size_t* defined);
#endif
#ifdef HAVE_TARGET_64_LITTLE
size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
- Sized_relobj<64, true>::Symbols* sympointers);
+ Sized_relobj<64, false>::Symbols* sympointers,
+ size_t* defined);
#endif
#ifdef HAVE_TARGET_64_BIG
size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
- Sized_relobj<64, false>::Symbols* sympointers);
+ Sized_relobj<64, true>::Symbols* sympointers,
+ size_t* defined);
+#endif
+
+#ifdef HAVE_TARGET_32_LITTLE
+template
+Symbol*
+Symbol_table::add_from_pluginobj<32, false>(
+ Sized_pluginobj<32, false>* obj,
+ const char* name,
+ const char* ver,
+ elfcpp::Sym<32, false>* sym);
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+template
+Symbol*
+Symbol_table::add_from_pluginobj<32, true>(
+ Sized_pluginobj<32, true>* obj,
+ const char* name,
+ const char* ver,
+ elfcpp::Sym<32, true>* sym);
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+template
+Symbol*
+Symbol_table::add_from_pluginobj<64, false>(
+ Sized_pluginobj<64, false>* obj,
+ const char* name,
+ const char* ver,
+ elfcpp::Sym<64, false>* sym);
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+template
+Symbol*
+Symbol_table::add_from_pluginobj<64, true>(
+ Sized_pluginobj<64, true>* obj,
+ const char* name,
+ const char* ver,
+ elfcpp::Sym<64, true>* sym);
#endif
#ifdef HAVE_TARGET_32_LITTLE
size_t sym_name_size,
const unsigned char* versym,
size_t versym_size,
- const std::vector<const char*>* version_map);
+ const std::vector<const char*>* version_map,
+ Sized_relobj<32, false>::Symbols* sympointers,
+ size_t* defined);
#endif
#ifdef HAVE_TARGET_32_BIG
size_t sym_name_size,
const unsigned char* versym,
size_t versym_size,
- const std::vector<const char*>* version_map);
+ const std::vector<const char*>* version_map,
+ Sized_relobj<32, true>::Symbols* sympointers,
+ size_t* defined);
#endif
#ifdef HAVE_TARGET_64_LITTLE
size_t sym_name_size,
const unsigned char* versym,
size_t versym_size,
- const std::vector<const char*>* version_map);
+ const std::vector<const char*>* version_map,
+ Sized_relobj<64, false>::Symbols* sympointers,
+ size_t* defined);
#endif
#ifdef HAVE_TARGET_64_BIG
size_t sym_name_size,
const unsigned char* versym,
size_t versym_size,
- const std::vector<const char*>* version_map);
+ const std::vector<const char*>* version_map,
+ Sized_relobj<64, true>::Symbols* sympointers,
+ size_t* defined);
#endif
#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)