this->has_warning_ = false;
this->is_copied_from_dynobj_ = false;
this->is_forced_local_ = false;
+ this->is_ordinary_shndx_ = false;
}
// Return the demangled version of the symbol's name, but only
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)
+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());
this->u_.from_object.object = object;
- // FIXME: Handle SHN_XINDEX.
- this->u_.from_object.shndx = sym.get_st_shndx();
+ this->u_.from_object.shndx = st_shndx;
+ this->is_ordinary_shndx_ = is_ordinary;
this->source_ = FROM_OBJECT;
this->in_reg_ = !object->is_dynamic();
this->in_dyn_ = object->is_dynamic();
// 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, const char* version,
+ 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->init_fields(name, version, type, binding, visibility, nonvis);
this->u_.in_output_data.output_data = od;
this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
this->source_ = IN_OUTPUT_DATA;
// 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, const char* version,
+ 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->init_fields(name, version, type, binding, visibility, nonvis);
this->u_.in_output_segment.output_segment = os;
this->u_.in_output_segment.offset_base = offset_base;
this->source_ = IN_OUTPUT_SEGMENT;
// 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, const char* version,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis)
+{
+ this->init_fields(name, version, 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, const char* version,
+ 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->init_fields(name, version, type, binding, visibility, nonvis);
+ 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)
+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);
+ 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, const char* version,
+ 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, version, 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, const char* version,
+ 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, version, 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, const char* version,
+ 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, version, 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, const char* version,
+ elfcpp::STT type, elfcpp::STB binding,
+ elfcpp::STV visibility, unsigned char nonvis)
+{
+ this->init_base_undefined(name, version, 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
case FROM_OBJECT:
{
unsigned int shndx = this->u_.from_object.shndx;
- if (shndx != elfcpp::SHN_UNDEF && shndx < elfcpp::SHN_LORESERVE)
+ if (shndx != elfcpp::SHN_UNDEF && this->is_ordinary_shndx_)
{
gold_assert(!this->u_.from_object.object->is_dynamic());
Relobj* relobj = static_cast<Relobj*>(this->u_.from_object.object);
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();
}
Symbol_table::Symbol_table(unsigned int count,
const Version_script_info& version_script)
: saw_undefined_(0), offset_(0), table_(count), namepool_(),
- forwarders_(), commons_(), forced_locals_(), warnings_(),
+ forwarders_(), commons_(), tls_commons_(), forced_locals_(), warnings_(),
version_script_(version_script)
{
namepool_.reserve(count);
{
unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
elfcpp::Sym_write<size, big_endian> esym(buf);
- // We don't bother to set the st_name field.
+ // We don't bother to set the st_name or the st_shndx field.
esym.put_st_value(from->value());
esym.put_st_size(from->symsize());
esym.put_st_info(from->binding(), from->type());
esym.put_st_other(from->visibility(), from->nonvis());
- esym.put_st_shndx(from->shndx());
- this->resolve(to, esym.sym(), esym.sym(), from->object(), version);
+ bool is_ordinary;
+ unsigned int shndx = from->shndx(&is_ordinary);
+ this->resolve(to, esym.sym(), shndx, is_ordinary, shndx, from->object(),
+ version);
if (from->in_reg())
to->set_in_reg();
if (from->in_dyn())
++name;
}
- if (parameters->options().is_wrap_symbol(name))
+ if (parameters->options().is_wrap(name))
{
// Turn NAME into __wrap_NAME.
std::string s;
const char* const real_prefix = "__real_";
const size_t real_prefix_length = strlen(real_prefix);
if (strncmp(name, real_prefix, real_prefix_length) == 0
- && parameters->options().is_wrap_symbol(name + real_prefix_length))
+ && parameters->options().is_wrap(name + real_prefix_length))
{
// Turn __real_NAME into NAME.
std::string s;
// Add one symbol from OBJECT to the symbol table. NAME is symbol
// name and VERSION is the version; both are canonicalized. DEF is
-// whether this is the default version.
+// whether this is the default version. ST_SHNDX is the symbol's
+// section index; IS_ORDINARY is whether this is a normal section
+// rather than a special code.
// If DEF is true, then this is the definition of a default version of
// a symbol. That means that any lookup of NAME/NULL and any lookup
// Note that entries in the hash table will never be marked as
// forwarders.
//
-// SYM and ORIG_SYM are almost always the same. ORIG_SYM is the
-// symbol exactly as it existed in the input file. SYM is usually
-// that as well, but can be modified, for instance if we determine
-// it's in a to-be-discarded section.
+// ORIG_ST_SHNDX and ST_SHNDX are almost always the same.
+// ORIG_ST_SHNDX is the section index in the input file, or SHN_UNDEF
+// for a special section code. ST_SHNDX may be modified if the symbol
+// is defined in a section being discarded.
template<int size, bool big_endian>
Sized_symbol<size>*
Stringpool::Key version_key,
bool def,
const elfcpp::Sym<size, big_endian>& sym,
- const elfcpp::Sym<size, big_endian>& orig_sym)
+ unsigned int st_shndx,
+ bool is_ordinary,
+ unsigned int orig_st_shndx)
{
+ // Print a message if this symbol is being traced.
+ if (parameters->options().is_trace_symbol(name))
+ {
+ if (orig_st_shndx == elfcpp::SHN_UNDEF)
+ gold_info(_("%s: reference to %s"), object->name().c_str(), name);
+ else
+ gold_info(_("%s: definition of %s"), object->name().c_str(), name);
+ }
+
// For an undefined symbol, we may need to adjust the name using
// --wrap.
- if (orig_sym.get_st_shndx() == elfcpp::SHN_UNDEF
- && parameters->options().any_wrap_symbols())
+ if (orig_st_shndx == elfcpp::SHN_UNDEF
+ && parameters->options().any_wrap())
{
const char* wrap_name = this->wrap_symbol(object, name, &name_key);
if (wrap_name != name)
was_undefined = ret->is_undefined();
was_common = ret->is_common();
- this->resolve(ret, sym, orig_sym, object, version);
+ this->resolve(ret, sym, st_shndx, is_ordinary, orig_st_shndx, object,
+ version);
if (def)
{
was_undefined = ret->is_undefined();
was_common = ret->is_common();
- this->resolve(ret, sym, orig_sym, object, version);
+ this->resolve(ret, sym, st_shndx, is_ordinary, orig_st_shndx, object,
+ version);
ins.first->second = ret;
}
else
}
}
- ret->init(name, version, object, sym);
+ ret->init_object(name, version, object, sym, st_shndx, is_ordinary);
ins.first->second = ret;
if (def)
// Keep track of common symbols, to speed up common symbol
// allocation.
if (!was_common && ret->is_common())
- this->commons_.push_back(ret);
+ {
+ if (ret->type() != elfcpp::STT_TLS)
+ this->commons_.push_back(ret);
+ else
+ this->tls_commons_.push_back(ret);
+ }
if (def)
ret->set_is_default();
Sized_relobj<size, big_endian>* relobj,
const unsigned char* syms,
size_t count,
+ size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
typename Sized_relobj<size, big_endian>::Symbols* sympointers)
for (size_t i = 0; i < count; ++i, p += sym_size)
{
elfcpp::Sym<size, big_endian> sym(p);
- elfcpp::Sym<size, big_endian>* psym = &sym;
- unsigned int st_name = psym->get_st_name();
+ unsigned int st_name = sym.get_st_name();
if (st_name >= sym_name_size)
{
relobj->error(_("bad global symbol name offset %u at %zu"),
const char* name = sym_names + st_name;
+ bool is_ordinary;
+ unsigned int st_shndx = relobj->adjust_sym_shndx(i + symndx_offset,
+ sym.get_st_shndx(),
+ &is_ordinary);
+ unsigned int orig_st_shndx = st_shndx;
+ if (!is_ordinary)
+ orig_st_shndx = elfcpp::SHN_UNDEF;
+
// A symbol defined in a section which we are not including must
// be treated as an undefined symbol.
- unsigned char symbuf[sym_size];
- elfcpp::Sym<size, big_endian> sym2(symbuf);
- unsigned int st_shndx = psym->get_st_shndx();
if (st_shndx != elfcpp::SHN_UNDEF
- && st_shndx < elfcpp::SHN_LORESERVE
+ && is_ordinary
&& !relobj->is_section_included(st_shndx))
- {
- memcpy(symbuf, p, sym_size);
- elfcpp::Sym_write<size, big_endian> sw(symbuf);
- sw.put_st_shndx(elfcpp::SHN_UNDEF);
- psym = &sym2;
- }
+ st_shndx = elfcpp::SHN_UNDEF;
// In an object file, an '@' in the name separates the symbol
// name from the version name. If there are two '@' characters,
// even if it is listed in the version script. FIXME: What
// about a common symbol?
else if (!version_script_.empty()
- && psym->get_st_shndx() != elfcpp::SHN_UNDEF)
+ && st_shndx != elfcpp::SHN_UNDEF)
{
// The symbol name did not have a version, but
// the version script may assign a version anyway.
local = true;
}
+ elfcpp::Sym<size, big_endian>* psym = &sym;
+ unsigned char symbuf[sym_size];
+ elfcpp::Sym<size, big_endian> sym2(symbuf);
if (just_symbols)
{
- if (psym != &sym2)
- memcpy(symbuf, p, sym_size);
+ memcpy(symbuf, p, sym_size);
elfcpp::Sym_write<size, big_endian> sw(symbuf);
- sw.put_st_shndx(elfcpp::SHN_ABS);
- if (st_shndx != elfcpp::SHN_UNDEF
- && st_shndx < elfcpp::SHN_LORESERVE)
+ if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary)
{
// Symbol values in object files are section relative.
// This is normally what we want, but since here we are
// 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(sym2.get_st_value()
- + relobj->section_address(st_shndx));
+ sw.put_st_value(sym.get_st_value()
+ + relobj->section_address(orig_st_shndx));
}
+ st_shndx = elfcpp::SHN_ABS;
+ is_ordinary = false;
psym = &sym2;
}
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, sym);
+ false, *psym, st_shndx, is_ordinary,
+ orig_st_shndx);
if (local)
this->force_local(res);
}
ver = this->namepool_.add(ver, true, &ver_key);
res = this->add_from_object(relobj, name, name_key, ver, ver_key,
- def, *psym, sym);
+ def, *psym, st_shndx, is_ordinary,
+ orig_st_shndx);
}
(*sympointers)[i] = res;
|| sym.get_st_visibility() == elfcpp::STV_HIDDEN)
continue;
- unsigned int st_name = sym.get_st_name();
+ // A protected symbol in a shared library must be treated as a
+ // normal symbol when viewed from outside the shared library.
+ // Implement this by overriding the visibility here.
+ elfcpp::Sym<size, big_endian>* psym = &sym;
+ unsigned char symbuf[sym_size];
+ elfcpp::Sym<size, big_endian> sym2(symbuf);
+ if (sym.get_st_visibility() == elfcpp::STV_PROTECTED)
+ {
+ memcpy(symbuf, p, sym_size);
+ elfcpp::Sym_write<size, big_endian> sw(symbuf);
+ sw.put_st_other(elfcpp::STV_DEFAULT, sym.get_st_nonvis());
+ psym = &sym2;
+ }
+
+ unsigned int st_name = psym->get_st_name();
if (st_name >= sym_name_size)
{
dynobj->error(_("bad symbol name offset %u at %zu"),
const char* name = sym_names + st_name;
+ bool is_ordinary;
+ unsigned int st_shndx = dynobj->adjust_sym_shndx(i, psym->get_st_shndx(),
+ &is_ordinary);
+
Sized_symbol<size>* res;
if (versym == NULL)
Stringpool::Key name_key;
name = this->namepool_.add(name, true, &name_key);
res = this->add_from_object(dynobj, name, name_key, NULL, 0,
- false, sym, sym);
+ false, *psym, st_shndx, is_ordinary,
+ st_shndx);
}
else
{
// linker will generate.
if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
- && sym.get_st_shndx() != elfcpp::SHN_UNDEF)
+ && st_shndx != elfcpp::SHN_UNDEF)
{
// This symbol should not be visible outside the object.
continue;
{
// This symbol does not have a version.
res = this->add_from_object(dynobj, name, name_key, NULL, 0,
- false, sym, sym);
+ false, *psym, st_shndx, is_ordinary,
+ st_shndx);
}
else
{
// version definition symbol. These symbols exist to
// support using -u to pull in particular versions. We
// do not want to record a version for them.
- if (sym.get_st_shndx() == elfcpp::SHN_ABS
+ if (st_shndx == elfcpp::SHN_ABS
+ && !is_ordinary
&& name_key == version_key)
res = this->add_from_object(dynobj, name, name_key, NULL, 0,
- false, sym, sym);
+ false, *psym, st_shndx, is_ordinary,
+ st_shndx);
else
{
const bool def = (!hidden
- && (sym.get_st_shndx()
- != elfcpp::SHN_UNDEF));
+ && st_shndx != elfcpp::SHN_UNDEF);
res = this->add_from_object(dynobj, name, name_key, version,
- version_key, def, sym, sym);
+ version_key, def, *psym, st_shndx,
+ is_ordinary, st_shndx);
}
}
}
// Note that it is possible that RES was overridden by an
- // earlier object, in which case it can be aliased here.
- if (sym.get_st_shndx() != elfcpp::SHN_UNDEF
- && sym.get_st_type() == elfcpp::STT_OBJECT
+ // earlier object, in which case it can't be aliased here.
+ if (st_shndx != elfcpp::SHN_UNDEF
+ && is_ordinary
+ && psym->get_st_type() == elfcpp::STT_OBJECT
&& res->source() == Symbol::FROM_OBJECT
&& res->object() == dynobj)
object_symbols.push_back(res);
Weak_alias_sorter<size>::operator()(const Sized_symbol<size>* s1,
const Sized_symbol<size>* s2) const
{
- if (s1->shndx() != s2->shndx())
- return s1->shndx() < s2->shndx();
+ bool is_ordinary;
+ unsigned int s1_shndx = s1->shndx(&is_ordinary);
+ gold_assert(is_ordinary);
+ unsigned int s2_shndx = s2->shndx(&is_ordinary);
+ gold_assert(is_ordinary);
+ if (s1_shndx != s2_shndx)
+ return s1_shndx < s2_shndx;
+
if (s1->value() != s2->value())
return s1->value() < s2->value();
if (s1->binding() != s2->binding())
typename std::vector<Sized_symbol<size>*>::const_iterator q;
for (q = p + 1; q != symbols->end(); ++q)
{
- if ((*q)->shndx() != from_sym->shndx()
+ bool dummy;
+ if ((*q)->shndx(&dummy) != from_sym->shndx(&dummy)
|| (*q)->value() != from_sym->value())
break;
if (sym == NULL)
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, version, od, value, symsize, type, binding,
+ visibility, nonvis, offset_is_from_end);
if (oldsym == NULL)
{
if (binding == elfcpp::STB_LOCAL
|| this->version_script_.symbol_is_local(name))
this->force_local(sym);
+ else if (version != NULL)
+ sym->set_is_default();
return sym;
}
if (sym == 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, version, os, value, symsize, type, binding,
+ visibility, nonvis, offset_base);
if (oldsym == NULL)
{
if (binding == elfcpp::STB_LOCAL
|| this->version_script_.symbol_is_local(name))
this->force_local(sym);
+ else if (version != NULL)
+ sym->set_is_default();
return sym;
}
if (sym == NULL)
return NULL;
- gold_assert(version == NULL || version == name || oldsym != NULL);
- sym->init(name, value, symsize, type, binding, visibility, nonvis);
+ sym->init_constant(name, version, value, symsize, type, binding, visibility,
+ nonvis);
if (oldsym == NULL)
{
&& (binding == elfcpp::STB_LOCAL
|| this->version_script_.symbol_is_local(name)))
this->force_local(sym);
+ else if (version != NULL
+ && (name != version || value != 0))
+ sym->set_is_default();
return sym;
}
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, version, 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
{
case Symbol::FROM_OBJECT:
{
- unsigned int shndx = sym->shndx();
+ bool is_ordinary;
+ unsigned int shndx = sym->shndx(&is_ordinary);
// FIXME: We need some target specific support here.
- if (shndx >= elfcpp::SHN_LORESERVE
+ if (!is_ordinary
&& shndx != elfcpp::SHN_ABS
&& shndx != elfcpp::SHN_COMMON)
{
}
else if (shndx == elfcpp::SHN_UNDEF)
value = 0;
- else if (shndx == elfcpp::SHN_ABS || shndx == elfcpp::SHN_COMMON)
+ else if (!is_ordinary
+ && (shndx == elfcpp::SHN_ABS || shndx == elfcpp::SHN_COMMON))
value = sym->value();
else
{
case Symbol::IN_OUTPUT_DATA:
{
Output_data* od = sym->output_data();
- value = sym->value() + od->address();
+ value = sym->value();
+ if (sym->type() != elfcpp::STT_TLS)
+ value += od->address();
+ else
+ {
+ Output_section* os = od->output_section();
+ gold_assert(os != NULL);
+ value += os->tls_offset() + (od->address() - os->address());
+ }
if (sym->offset_is_from_end())
value += od->data_size();
}
case Symbol::IN_OUTPUT_SEGMENT:
{
Output_segment* os = sym->output_segment();
- value = sym->value() + os->vaddr();
+ value = sym->value();
+ if (sym->type() != elfcpp::STT_TLS)
+ value += os->vaddr();
switch (sym->offset_base())
{
case Symbol::SEGMENT_START:
}
break;
- case Symbol::CONSTANT:
+ case Symbol::IS_CONSTANT:
value = sym->value();
break;
+ case Symbol::IS_UNDEFINED:
+ value = 0;
+ break;
+
default:
gold_unreachable();
}
void
Symbol_table::write_globals(const Input_objects* input_objects,
const Stringpool* sympool,
- const Stringpool* dynpool, Output_file* of) const
+ const Stringpool* dynpool,
+ Output_symtab_xindex* symtab_xindex,
+ Output_symtab_xindex* dynsym_xindex,
+ Output_file* of) const
{
switch (parameters->size_and_endianness())
{
#ifdef HAVE_TARGET_32_LITTLE
case Parameters::TARGET_32_LITTLE:
this->sized_write_globals<32, false>(input_objects, sympool,
- dynpool, of);
+ dynpool, symtab_xindex,
+ dynsym_xindex, of);
break;
#endif
#ifdef HAVE_TARGET_32_BIG
case Parameters::TARGET_32_BIG:
this->sized_write_globals<32, true>(input_objects, sympool,
- dynpool, of);
+ dynpool, symtab_xindex,
+ dynsym_xindex, of);
break;
#endif
#ifdef HAVE_TARGET_64_LITTLE
case Parameters::TARGET_64_LITTLE:
this->sized_write_globals<64, false>(input_objects, sympool,
- dynpool, of);
+ dynpool, symtab_xindex,
+ dynsym_xindex, of);
break;
#endif
#ifdef HAVE_TARGET_64_BIG
case Parameters::TARGET_64_BIG:
this->sized_write_globals<64, true>(input_objects, sympool,
- dynpool, of);
+ dynpool, symtab_xindex,
+ dynsym_xindex, of);
break;
#endif
default:
Symbol_table::sized_write_globals(const Input_objects* input_objects,
const Stringpool* sympool,
const Stringpool* dynpool,
+ Output_symtab_xindex* symtab_xindex,
+ Output_symtab_xindex* dynsym_xindex,
Output_file* of) const
{
const Target& target = parameters->target();
{
case Symbol::FROM_OBJECT:
{
- unsigned int in_shndx = sym->shndx();
+ bool is_ordinary;
+ unsigned int in_shndx = sym->shndx(&is_ordinary);
// FIXME: We need some target specific support here.
- if (in_shndx >= elfcpp::SHN_LORESERVE
+ if (!is_ordinary
&& in_shndx != elfcpp::SHN_ABS
&& in_shndx != elfcpp::SHN_COMMON)
{
shndx = elfcpp::SHN_UNDEF;
}
else if (in_shndx == elfcpp::SHN_UNDEF
- || in_shndx == elfcpp::SHN_ABS
- || in_shndx == elfcpp::SHN_COMMON)
+ || (!is_ordinary
+ && (in_shndx == elfcpp::SHN_ABS
+ || in_shndx == elfcpp::SHN_COMMON)))
shndx = in_shndx;
else
{
gold_assert(os != NULL);
shndx = os->out_shndx();
+ if (shndx >= elfcpp::SHN_LORESERVE)
+ {
+ if (sym_index != -1U)
+ symtab_xindex->add(sym_index, shndx);
+ if (dynsym_index != -1U)
+ dynsym_xindex->add(dynsym_index, shndx);
+ shndx = elfcpp::SHN_XINDEX;
+ }
+
// In object files symbol values are section
// relative.
if (parameters->options().relocatable())
case Symbol::IN_OUTPUT_DATA:
shndx = sym->output_data()->out_shndx();
+ if (shndx >= elfcpp::SHN_LORESERVE)
+ {
+ if (sym_index != -1U)
+ symtab_xindex->add(sym_index, shndx);
+ if (dynsym_index != -1U)
+ dynsym_xindex->add(dynsym_index, shndx);
+ shndx = elfcpp::SHN_XINDEX;
+ }
break;
case Symbol::IN_OUTPUT_SEGMENT:
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();
}
const Input_objects* input_objects,
Symbol* sym) const
{
+ bool dummy;
if (sym->source() == Symbol::FROM_OBJECT
&& sym->object()->is_dynamic()
- && sym->shndx() == elfcpp::SHN_UNDEF
+ && sym->shndx(&dummy) == elfcpp::SHN_UNDEF
&& sym->binding() != elfcpp::STB_WEAK
&& !parameters->options().allow_shlib_undefined()
&& !parameters->target().is_defined_by_abi(sym)
void
Symbol_table::write_section_symbol(const Output_section *os,
+ Output_symtab_xindex* symtab_xindex,
Output_file* of,
off_t offset) const
{
{
#ifdef HAVE_TARGET_32_LITTLE
case Parameters::TARGET_32_LITTLE:
- this->sized_write_section_symbol<32, false>(os, of, offset);
+ this->sized_write_section_symbol<32, false>(os, symtab_xindex, of,
+ offset);
break;
#endif
#ifdef HAVE_TARGET_32_BIG
case Parameters::TARGET_32_BIG:
- this->sized_write_section_symbol<32, true>(os, of, offset);
+ this->sized_write_section_symbol<32, true>(os, symtab_xindex, of,
+ offset);
break;
#endif
#ifdef HAVE_TARGET_64_LITTLE
case Parameters::TARGET_64_LITTLE:
- this->sized_write_section_symbol<64, false>(os, of, offset);
+ this->sized_write_section_symbol<64, false>(os, symtab_xindex, of,
+ offset);
break;
#endif
#ifdef HAVE_TARGET_64_BIG
case Parameters::TARGET_64_BIG:
- this->sized_write_section_symbol<64, true>(os, of, offset);
+ this->sized_write_section_symbol<64, true>(os, symtab_xindex, of,
+ offset);
break;
#endif
default:
template<int size, bool big_endian>
void
Symbol_table::sized_write_section_symbol(const Output_section* os,
+ Output_symtab_xindex* symtab_xindex,
Output_file* of,
off_t offset) const
{
osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
elfcpp::STT_SECTION));
osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
- osym.put_st_shndx(os->out_shndx());
+
+ unsigned int shndx = os->out_shndx();
+ if (shndx >= elfcpp::SHN_LORESERVE)
+ {
+ symtab_xindex->add(os->symtab_index(), shndx);
+ shndx = elfcpp::SHN_XINDEX;
+ }
+ osym.put_st_shndx(shndx);
of->write_output_view(offset, sym_size, pov);
}
// want to run this in a general Task for better
// performance, we will need one Task for object, plus
// appropriate locking to ensure that we don't conflict with
- // other uses of the object.
+ // other uses of the object. Also note, one_addr2line is not
+ // currently thread-safe.
Task_lock_obj<Object> tl(task, locs->object);
+ // 16 is the size of the object-cache that one_addr2line should use.
std::string lineno = Dwarf_line_info::one_addr2line(
- locs->object, locs->shndx, locs->offset);
+ locs->object, locs->shndx, locs->offset, 16);
if (!lineno.empty())
line_nums.insert(lineno);
}
fprintf(stderr, " %s\n", it2->c_str());
}
}
+ // We only call one_addr2line() in this function, so we can clear its cache.
+ Dwarf_line_info::clear_addr2line_cache();
}
// Warnings functions.
Sized_relobj<32, false>* relobj,
const unsigned char* syms,
size_t count,
+ size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
Sized_relobj<32, true>::Symbols* sympointers);
Sized_relobj<32, true>* relobj,
const unsigned char* syms,
size_t count,
+ size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
Sized_relobj<32, false>::Symbols* sympointers);
Sized_relobj<64, false>* relobj,
const unsigned char* syms,
size_t count,
+ size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
Sized_relobj<64, true>::Symbols* sympointers);
Sized_relobj<64, true>* relobj,
const unsigned char* syms,
size_t count,
+ size_t symndx_offset,
const char* sym_names,
size_t sym_name_size,
Sized_relobj<64, false>::Symbols* sympointers);