forked from Imagelibrary/binutils-gdb
Add plugin functionality for link-time optimization (LTO).
include/: * plugin-api.h: New file. gold/: * configure.ac (plugins): Add --enable-plugins option. * configure: Regenerate. * config.in: Regenerate. * Makefile.am (LIBDL): New variable. (CCFILES): Add plugin.cc. (HFILES): Add plugin.h. (ldadd_var): Add LIBDL. * Makefile.in: Regenerate. * archive.cc: Include "plugin.h". (Archive::setup): Don't preread archive symbols when using a plugin. (Archive::get_file_and_offset): Add memsize parameter. Change callers. (Archive::get_elf_object_for_member): Call plugin hooks for claiming files. (Archive::include_member): Add symbols from plugin objects. * archive.h (Archive::get_file_and_offset): Add memsize parameter. * descriptors.cc (Descriptors::open): Check for file descriptors abandoned by plugins. (Descriptors::claim_for_plugin): New function. * descriptors.h (Descriptors::claim_for_plugin): New function. (Open_descriptor::is_claimed): New field. (claim_descriptor_for_plugin): New function. * fileread.cc (File_read::claim_for_plugin): New function. * fileread.h (File_read::claim_for_plugin): New function. (File_read::descriptor): New function. * gold.cc: Include "plugin.h". (queue_initial_tasks): Add task to call plugin hooks for generating new object files. * main.cc: Include "plugin.h". (main): Load plugin libraries. * object.h (Pluginobj): Declare. (Object::pluginobj): New function. (Object::do_pluginobj): New function. (Object::set_target): New function. * options.cc: Include "plugin.h". (General_options::parse_plugin): New function. (General_options::General_options): Initialize plugins_ field. (General_options::add_plugin): New function. * options.h (Plugin_manager): Declare. (General_options): Add --plugin option. (General_options::has_plugins): New function. (General_options::plugins): New function. (General_options::add_plugin): New function. (General_options::plugins_): New field. * plugin.cc: New file. * plugin.h: New file. * readsyms.cc: Include "plugin.h". (Read_symbols::do_read_symbols): Check for archive before checking for ELF file. Call plugin hooks to claim files. * resolve.cc (Symbol_table::resolve): Record when symbol is referenced from a real object file; force override when processing replacement files. * symtab.cc (Symbol::init_fields): Initialize in_real_elf_ field. (Symbol::init_base_object): Likewise. (Symbol::init_base_output_data): Likewise. (Symbol::init_base_output_segment): Likewise. (Symbol::init_base_constant): Likewise. (Symbol::init_base_undefined): Likewise. (Symbol::output_section): Assert that object is not a plugin. (Symbol_table::add_from_pluginobj): New function. (Symbol_table::sized_finalize_symbol): Treat symbols from plugins as undefined. (Symbol_table::sized_write_globals): Likewise. (Symbol_table::add_from_pluginobj): Instantiate template. * symtab.h (Sized_pluginobj): Declare. (Symbol::in_real_elf): New function. (Symbol::set_in_real_elf): New function. (Symbol::in_real_elf_): New field. (Symbol_table::add_from_pluginobj): New function. * testsuite/Makefile.am (AM_CFLAGS): New variable. (LIBDL): New variable. (LDADD): Add LIBDL. (check_PROGRAMS): Add plugin_test_1 and plugin_test_2. (check_SCRIPTS): Add plugin_test_1.sh and plugin_test_2.sh. (check_DATA): Add plugin_test_1.err and plugin_test_2.err. (MOSTLYCLEANFILES): Likewise. * testsuite/Makefile.in: Regenerate. * testsuite/plugin_test.c: New file. * testsuite/plugin_test_1.sh: New file. * testsuite/plugin_test_2.sh: New file.
This commit is contained in:
117
gold/symtab.cc
117
gold/symtab.cc
@@ -37,6 +37,7 @@
|
||||
#include "target.h"
|
||||
#include "workqueue.h"
|
||||
#include "symtab.h"
|
||||
#include "plugin.h"
|
||||
|
||||
namespace gold
|
||||
{
|
||||
@@ -73,6 +74,7 @@ Symbol::init_fields(const char* name, const char* version,
|
||||
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
|
||||
@@ -117,6 +119,7 @@ Symbol::init_base_object(const char* name, const char* version, Object* object,
|
||||
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
|
||||
@@ -133,6 +136,7 @@ Symbol::init_base_output_data(const char* name, const char* version,
|
||||
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
|
||||
@@ -150,6 +154,7 @@ Symbol::init_base_output_segment(const char* name, const char* version,
|
||||
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
|
||||
@@ -163,6 +168,7 @@ Symbol::init_base_constant(const char* name, const char* version,
|
||||
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
|
||||
@@ -177,6 +183,7 @@ Symbol::init_base_undefined(const char* name, const char* version,
|
||||
this->dynsym_index_ = -1U;
|
||||
this->source_ = IS_UNDEFINED;
|
||||
this->in_reg_ = true;
|
||||
this->in_real_elf_ = true;
|
||||
}
|
||||
|
||||
// Allocate a common symbol in the base.
|
||||
@@ -357,6 +364,7 @@ Symbol::output_section() const
|
||||
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);
|
||||
}
|
||||
@@ -973,6 +981,68 @@ Symbol_table::add_from_relobj(
|
||||
}
|
||||
}
|
||||
|
||||
// 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>
|
||||
@@ -2043,6 +2113,11 @@ Symbol_table::sized_finalize_symbol(Symbol* unsized_sym)
|
||||
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
|
||||
@@ -2261,6 +2336,8 @@ Symbol_table::sized_write_globals(const Input_objects* input_objects,
|
||||
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
|
||||
@@ -2701,6 +2778,46 @@ Symbol_table::add_from_relobj<64, true>(
|
||||
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
|
||||
template
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user