2008-09-20 06:54:57 +08:00
|
|
|
// plugin.h -- plugin manager for gold -*- C++ -*-
|
|
|
|
|
2022-01-02 06:30:17 +08:00
|
|
|
// Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
2008-09-20 06:54:57 +08:00
|
|
|
// Written by Cary Coutant <ccoutant@google.com>.
|
|
|
|
|
|
|
|
// This file is part of gold.
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
// MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef GOLD_PLUGIN_H
|
|
|
|
#define GOLD_PLUGIN_H
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "object.h"
|
|
|
|
#include "plugin-api.h"
|
|
|
|
#include "workqueue.h"
|
|
|
|
|
|
|
|
namespace gold
|
|
|
|
{
|
|
|
|
|
|
|
|
class General_options;
|
|
|
|
class Input_file;
|
|
|
|
class Input_objects;
|
2011-01-25 05:48:40 +08:00
|
|
|
class Archive;
|
|
|
|
class Input_group;
|
|
|
|
class Symbol;
|
2008-09-20 06:54:57 +08:00
|
|
|
class Symbol_table;
|
|
|
|
class Layout;
|
|
|
|
class Dirsearch;
|
|
|
|
class Mapfile;
|
2011-01-25 05:48:40 +08:00
|
|
|
class Task;
|
2008-09-20 06:54:57 +08:00
|
|
|
class Task_token;
|
|
|
|
class Pluginobj;
|
2011-01-25 05:48:40 +08:00
|
|
|
class Plugin_rescan;
|
2018-03-24 01:05:38 +08:00
|
|
|
class Plugin_recorder;
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// This class represents a single plugin library.
|
|
|
|
|
|
|
|
class Plugin
|
|
|
|
{
|
|
|
|
public:
|
2008-12-06 05:34:54 +08:00
|
|
|
Plugin(const char* filename)
|
2008-09-20 06:54:57 +08:00
|
|
|
: handle_(NULL),
|
2008-12-06 05:34:54 +08:00
|
|
|
filename_(filename),
|
|
|
|
args_(),
|
2008-09-20 06:54:57 +08:00
|
|
|
claim_file_handler_(NULL),
|
|
|
|
all_symbols_read_handler_(NULL),
|
2009-10-29 02:07:25 +08:00
|
|
|
cleanup_handler_(NULL),
|
2017-12-12 06:58:38 +08:00
|
|
|
new_input_handler_(NULL),
|
2009-10-29 02:07:25 +08:00
|
|
|
cleanup_done_(false)
|
2008-09-20 06:54:57 +08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~Plugin()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Load the library and call its entry point.
|
|
|
|
void
|
|
|
|
load();
|
|
|
|
|
|
|
|
// Call the claim-file handler.
|
|
|
|
bool
|
2010-08-25 16:36:54 +08:00
|
|
|
claim_file(struct ld_plugin_input_file* plugin_input_file);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Call the all-symbols-read handler.
|
|
|
|
void
|
|
|
|
all_symbols_read();
|
|
|
|
|
2017-12-12 06:58:38 +08:00
|
|
|
// Call the new_input handler.
|
|
|
|
void
|
|
|
|
new_input(struct ld_plugin_input_file* plugin_input_file);
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Call the cleanup handler.
|
|
|
|
void
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
// Register a claim-file handler.
|
|
|
|
void
|
|
|
|
set_claim_file_handler(ld_plugin_claim_file_handler handler)
|
|
|
|
{ this->claim_file_handler_ = handler; }
|
|
|
|
|
|
|
|
// Register an all-symbols-read handler.
|
|
|
|
void
|
|
|
|
set_all_symbols_read_handler(ld_plugin_all_symbols_read_handler handler)
|
|
|
|
{ this->all_symbols_read_handler_ = handler; }
|
|
|
|
|
|
|
|
// Register a claim-file handler.
|
|
|
|
void
|
|
|
|
set_cleanup_handler(ld_plugin_cleanup_handler handler)
|
|
|
|
{ this->cleanup_handler_ = handler; }
|
|
|
|
|
2017-12-12 06:58:38 +08:00
|
|
|
// Register a new_input handler.
|
|
|
|
void
|
|
|
|
set_new_input_handler(ld_plugin_new_input_handler handler)
|
|
|
|
{ this->new_input_handler_ = handler; }
|
|
|
|
|
2008-12-06 05:34:54 +08:00
|
|
|
// Add an argument
|
|
|
|
void
|
2010-08-25 16:36:54 +08:00
|
|
|
add_option(const char* arg)
|
2008-12-06 05:34:54 +08:00
|
|
|
{
|
|
|
|
this->args_.push_back(arg);
|
|
|
|
}
|
|
|
|
|
2018-03-24 01:05:38 +08:00
|
|
|
const std::string&
|
|
|
|
filename() const
|
|
|
|
{ return this->filename_; }
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
private:
|
|
|
|
Plugin(const Plugin&);
|
|
|
|
Plugin& operator=(const Plugin&);
|
|
|
|
|
|
|
|
// The shared library handle returned by dlopen.
|
|
|
|
void* handle_;
|
|
|
|
// The argument string given to --plugin.
|
2008-12-06 05:34:54 +08:00
|
|
|
std::string filename_;
|
|
|
|
// The list of argument string given to --plugin-opt.
|
|
|
|
std::vector<std::string> args_;
|
2008-09-20 06:54:57 +08:00
|
|
|
// The plugin's event handlers.
|
|
|
|
ld_plugin_claim_file_handler claim_file_handler_;
|
|
|
|
ld_plugin_all_symbols_read_handler all_symbols_read_handler_;
|
|
|
|
ld_plugin_cleanup_handler cleanup_handler_;
|
2017-12-12 06:58:38 +08:00
|
|
|
ld_plugin_new_input_handler new_input_handler_;
|
2009-10-29 02:07:25 +08:00
|
|
|
// TRUE if the cleanup handlers have been called.
|
|
|
|
bool cleanup_done_;
|
2008-09-20 06:54:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// A manager class for plugins.
|
|
|
|
|
|
|
|
class Plugin_manager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Plugin_manager(const General_options& options)
|
2008-12-23 10:02:20 +08:00
|
|
|
: plugins_(), objects_(), deferred_layout_objects_(), input_file_(NULL),
|
2011-01-25 05:48:40 +08:00
|
|
|
plugin_input_file_(), rescannable_(), undefined_symbols_(),
|
|
|
|
any_claimed_(false), in_replacement_phase_(false), any_added_(false),
|
2011-07-14 08:55:18 +08:00
|
|
|
in_claim_file_handler_(false),
|
2009-01-15 09:29:25 +08:00
|
|
|
options_(options), workqueue_(NULL), task_(NULL), input_objects_(NULL),
|
|
|
|
symtab_(NULL), layout_(NULL), dirpath_(NULL), mapfile_(NULL),
|
2014-11-08 08:12:58 +08:00
|
|
|
this_blocker_(NULL), extra_search_path_(), lock_(NULL),
|
2018-03-24 01:05:38 +08:00
|
|
|
initialize_lock_(&lock_), defsym_defines_set_(),
|
|
|
|
recorder_(NULL)
|
2008-09-20 06:54:57 +08:00
|
|
|
{ this->current_ = plugins_.end(); }
|
|
|
|
|
|
|
|
~Plugin_manager();
|
|
|
|
|
2018-02-16 09:35:16 +08:00
|
|
|
// Returns true if the symbol name is used in the LHS of a defsym.
|
|
|
|
bool
|
|
|
|
is_defsym_def(const char* sym_name) const
|
|
|
|
{
|
|
|
|
return defsym_defines_set_.find(sym_name) != defsym_defines_set_.end();
|
|
|
|
}
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Add a plugin library.
|
|
|
|
void
|
2008-12-06 05:34:54 +08:00
|
|
|
add_plugin(const char* filename)
|
|
|
|
{ this->plugins_.push_back(new Plugin(filename)); }
|
|
|
|
|
|
|
|
// Add an argument to the current plugin.
|
|
|
|
void
|
|
|
|
add_plugin_option(const char* opt)
|
|
|
|
{
|
|
|
|
Plugin* last = this->plugins_.back();
|
|
|
|
last->add_option(opt);
|
|
|
|
}
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Load all plugin libraries.
|
|
|
|
void
|
2011-07-14 08:55:18 +08:00
|
|
|
load_plugins(Layout* layout);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Call the plugin claim-file handlers in turn to see if any claim the file.
|
|
|
|
Pluginobj*
|
2011-07-14 08:55:18 +08:00
|
|
|
claim_file(Input_file* input_file, off_t offset, off_t filesize,
|
|
|
|
Object* elf_object);
|
|
|
|
|
|
|
|
// Get the object associated with the handle and check if it is an elf object.
|
|
|
|
// If it is not a Pluginobj, it is an elf object.
|
|
|
|
Object*
|
|
|
|
get_elf_object(const void* handle);
|
|
|
|
|
|
|
|
// True if the claim_file handler of the plugins is being called.
|
|
|
|
bool
|
|
|
|
in_claim_file_handler()
|
|
|
|
{ return in_claim_file_handler_; }
|
2008-09-20 06:54:57 +08:00
|
|
|
|
2011-01-25 05:48:40 +08:00
|
|
|
// Let the plugin manager save an archive for later rescanning.
|
|
|
|
// This takes ownership of the Archive pointer.
|
|
|
|
void
|
|
|
|
save_archive(Archive*);
|
|
|
|
|
|
|
|
// Let the plugin manager save an input group for later rescanning.
|
|
|
|
// This takes ownership of the Input_group pointer.
|
|
|
|
void
|
|
|
|
save_input_group(Input_group*);
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Call the all-symbols-read handlers.
|
|
|
|
void
|
2009-01-15 09:29:25 +08:00
|
|
|
all_symbols_read(Workqueue* workqueue, Task* task,
|
|
|
|
Input_objects* input_objects, Symbol_table* symtab,
|
2011-07-14 08:55:18 +08:00
|
|
|
Dirsearch* dirpath, Mapfile* mapfile,
|
2009-01-15 09:29:25 +08:00
|
|
|
Task_token** last_blocker);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
2011-01-25 05:48:40 +08:00
|
|
|
// Tell the plugin manager that we've a new undefined symbol which
|
|
|
|
// may require rescanning.
|
|
|
|
void
|
|
|
|
new_undefined_symbol(Symbol*);
|
|
|
|
|
2008-12-24 14:17:18 +08:00
|
|
|
// Run deferred layout.
|
2008-09-20 06:54:57 +08:00
|
|
|
void
|
2008-12-24 14:17:18 +08:00
|
|
|
layout_deferred_objects();
|
|
|
|
|
|
|
|
// Call the cleanup handlers.
|
|
|
|
void
|
|
|
|
cleanup();
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Register a claim-file handler.
|
|
|
|
void
|
|
|
|
set_claim_file_handler(ld_plugin_claim_file_handler handler)
|
|
|
|
{
|
|
|
|
gold_assert(this->current_ != plugins_.end());
|
|
|
|
(*this->current_)->set_claim_file_handler(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register an all-symbols-read handler.
|
|
|
|
void
|
|
|
|
set_all_symbols_read_handler(ld_plugin_all_symbols_read_handler handler)
|
|
|
|
{
|
|
|
|
gold_assert(this->current_ != plugins_.end());
|
|
|
|
(*this->current_)->set_all_symbols_read_handler(handler);
|
|
|
|
}
|
|
|
|
|
2017-12-12 06:58:38 +08:00
|
|
|
// Register a new_input handler.
|
|
|
|
void
|
|
|
|
set_new_input_handler(ld_plugin_new_input_handler handler)
|
|
|
|
{
|
|
|
|
gold_assert(this->current_ != plugins_.end());
|
|
|
|
(*this->current_)->set_new_input_handler(handler);
|
|
|
|
}
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Register a claim-file handler.
|
|
|
|
void
|
|
|
|
set_cleanup_handler(ld_plugin_cleanup_handler handler)
|
|
|
|
{
|
|
|
|
gold_assert(this->current_ != plugins_.end());
|
|
|
|
(*this->current_)->set_cleanup_handler(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a new Pluginobj object. This is called when the plugin calls
|
|
|
|
// the add_symbols API.
|
|
|
|
Pluginobj*
|
|
|
|
make_plugin_object(unsigned int handle);
|
|
|
|
|
2011-07-14 08:55:18 +08:00
|
|
|
// Return the object associated with the given HANDLE.
|
|
|
|
Object*
|
2008-09-20 06:54:57 +08:00
|
|
|
object(unsigned int handle) const
|
|
|
|
{
|
|
|
|
if (handle >= this->objects_.size())
|
|
|
|
return NULL;
|
|
|
|
return this->objects_[handle];
|
|
|
|
}
|
|
|
|
|
2008-12-23 10:02:20 +08:00
|
|
|
// Return TRUE if any input files have been claimed by a plugin
|
|
|
|
// and we are still in the initial input phase.
|
|
|
|
bool
|
|
|
|
should_defer_layout() const
|
2011-09-20 07:19:16 +08:00
|
|
|
{ return this->any_claimed_ && !this->in_replacement_phase_; }
|
2008-12-23 10:02:20 +08:00
|
|
|
|
|
|
|
// Add a regular object to the deferred layout list. These are
|
|
|
|
// objects whose layout has been deferred until after the
|
|
|
|
// replacement files have arrived.
|
|
|
|
void
|
|
|
|
add_deferred_layout_object(Relobj* obj)
|
|
|
|
{ this->deferred_layout_objects_.push_back(obj); }
|
|
|
|
|
2009-01-15 09:29:25 +08:00
|
|
|
// Get input file information with an open (possibly re-opened)
|
|
|
|
// file descriptor.
|
|
|
|
ld_plugin_status
|
2010-08-25 16:36:54 +08:00
|
|
|
get_input_file(unsigned int handle, struct ld_plugin_input_file* file);
|
2009-01-15 09:29:25 +08:00
|
|
|
|
2011-03-23 22:13:27 +08:00
|
|
|
ld_plugin_status
|
|
|
|
get_view(unsigned int handle, const void **viewp);
|
|
|
|
|
2009-01-15 09:29:25 +08:00
|
|
|
// Release an input file.
|
|
|
|
ld_plugin_status
|
|
|
|
release_input_file(unsigned int handle);
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Add a new input file.
|
|
|
|
ld_plugin_status
|
2010-08-25 16:36:54 +08:00
|
|
|
add_input_file(const char* pathname, bool is_lib);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
2010-06-22 05:21:25 +08:00
|
|
|
// Set the extra library path.
|
|
|
|
ld_plugin_status
|
2010-08-25 16:36:54 +08:00
|
|
|
set_extra_library_path(const char* path);
|
2010-06-22 05:21:25 +08:00
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Return TRUE if we are in the replacement phase.
|
|
|
|
bool
|
|
|
|
in_replacement_phase() const
|
|
|
|
{ return this->in_replacement_phase_; }
|
|
|
|
|
2011-07-14 08:55:18 +08:00
|
|
|
Input_objects*
|
|
|
|
input_objects() const
|
|
|
|
{ return this->input_objects_; }
|
|
|
|
|
2015-02-05 01:47:28 +08:00
|
|
|
Symbol_table*
|
|
|
|
symtab()
|
|
|
|
{ return this->symtab_; }
|
|
|
|
|
2011-07-14 08:55:18 +08:00
|
|
|
Layout*
|
|
|
|
layout()
|
|
|
|
{ return this->layout_; }
|
|
|
|
|
2018-03-24 01:05:38 +08:00
|
|
|
Plugin_recorder*
|
|
|
|
recorder() const
|
|
|
|
{ return this->recorder_; }
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
private:
|
|
|
|
Plugin_manager(const Plugin_manager&);
|
|
|
|
Plugin_manager& operator=(const Plugin_manager&);
|
|
|
|
|
2011-01-25 05:48:40 +08:00
|
|
|
// Plugin_rescan is a Task which calls the private rescan method.
|
|
|
|
friend class Plugin_rescan;
|
|
|
|
|
|
|
|
// An archive or input group which may have to be rescanned if a
|
|
|
|
// plugin adds a new file.
|
|
|
|
struct Rescannable
|
|
|
|
{
|
|
|
|
bool is_archive;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
Archive* archive;
|
|
|
|
Input_group* input_group;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
Rescannable(Archive* archive)
|
|
|
|
: is_archive(true)
|
|
|
|
{ this->u.archive = archive; }
|
|
|
|
|
|
|
|
Rescannable(Input_group* input_group)
|
|
|
|
: is_archive(false)
|
|
|
|
{ this->u.input_group = input_group; }
|
|
|
|
};
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
typedef std::list<Plugin*> Plugin_list;
|
2011-07-14 08:55:18 +08:00
|
|
|
typedef std::vector<Object*> Object_list;
|
2008-12-23 10:02:20 +08:00
|
|
|
typedef std::vector<Relobj*> Deferred_layout_list;
|
2011-01-25 05:48:40 +08:00
|
|
|
typedef std::vector<Rescannable> Rescannable_list;
|
|
|
|
typedef std::vector<Symbol*> Undefined_symbol_list;
|
|
|
|
|
|
|
|
// Rescan archives for undefined symbols.
|
|
|
|
void
|
|
|
|
rescan(Task*);
|
|
|
|
|
|
|
|
// See whether the rescannable at index I defines SYM.
|
|
|
|
bool
|
|
|
|
rescannable_defines(size_t i, Symbol* sym);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// The list of plugin libraries.
|
|
|
|
Plugin_list plugins_;
|
|
|
|
// A pointer to the current plugin. Used while loading plugins.
|
|
|
|
Plugin_list::iterator current_;
|
|
|
|
|
|
|
|
// The list of plugin objects. The index of an item in this list
|
|
|
|
// serves as the "handle" that we pass to the plugins.
|
|
|
|
Object_list objects_;
|
|
|
|
|
2008-12-23 10:02:20 +08:00
|
|
|
// The list of regular objects whose layout has been deferred.
|
|
|
|
Deferred_layout_list deferred_layout_objects_;
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// The file currently up for claim by the plugins.
|
|
|
|
Input_file* input_file_;
|
|
|
|
struct ld_plugin_input_file plugin_input_file_;
|
|
|
|
|
2011-01-25 05:48:40 +08:00
|
|
|
// A list of archives and input groups being saved for possible
|
|
|
|
// later rescanning.
|
|
|
|
Rescannable_list rescannable_;
|
|
|
|
|
|
|
|
// A list of undefined symbols found in added files.
|
|
|
|
Undefined_symbol_list undefined_symbols_;
|
|
|
|
|
|
|
|
// Whether any input files have been claimed by a plugin.
|
|
|
|
bool any_claimed_;
|
|
|
|
|
|
|
|
// Set to true after the all symbols read event; indicates that we
|
|
|
|
// are processing replacement files whose symbols should replace the
|
2008-09-20 06:54:57 +08:00
|
|
|
// placeholder symbols from the Pluginobj objects.
|
|
|
|
bool in_replacement_phase_;
|
|
|
|
|
2011-01-25 05:48:40 +08:00
|
|
|
// Whether any input files or libraries were added by a plugin.
|
|
|
|
bool any_added_;
|
|
|
|
|
2011-07-14 08:55:18 +08:00
|
|
|
// Set to true when the claim_file handler of a plugin is called.
|
|
|
|
bool in_claim_file_handler_;
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
const General_options& options_;
|
|
|
|
Workqueue* workqueue_;
|
2009-01-15 09:29:25 +08:00
|
|
|
Task* task_;
|
2008-09-20 06:54:57 +08:00
|
|
|
Input_objects* input_objects_;
|
|
|
|
Symbol_table* symtab_;
|
|
|
|
Layout* layout_;
|
|
|
|
Dirsearch* dirpath_;
|
|
|
|
Mapfile* mapfile_;
|
|
|
|
Task_token* this_blocker_;
|
2010-06-22 05:21:25 +08:00
|
|
|
|
2016-11-26 04:01:42 +08:00
|
|
|
// An extra directory to search for the libraries passed by
|
2010-06-22 05:21:25 +08:00
|
|
|
// add_input_library.
|
|
|
|
std::string extra_search_path_;
|
2014-11-08 08:12:58 +08:00
|
|
|
Lock* lock_;
|
|
|
|
Initialize_lock initialize_lock_;
|
2018-02-16 09:35:16 +08:00
|
|
|
|
|
|
|
// Keep track of all symbols defined by defsym.
|
|
|
|
typedef Unordered_set<std::string> Defsym_defines_set;
|
|
|
|
Defsym_defines_set defsym_defines_set_;
|
2018-03-24 01:05:38 +08:00
|
|
|
|
|
|
|
// Class to record plugin actions.
|
|
|
|
Plugin_recorder* recorder_;
|
2008-09-20 06:54:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// An object file claimed by a plugin. This is an abstract base class.
|
|
|
|
// The implementation is the template class Sized_pluginobj.
|
|
|
|
|
|
|
|
class Pluginobj : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::vector<Symbol*> Symbols;
|
|
|
|
|
2009-01-15 09:29:25 +08:00
|
|
|
Pluginobj(const std::string& name, Input_file* input_file, off_t offset,
|
|
|
|
off_t filesize);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Fill in the symbol resolution status for the given plugin symbols.
|
|
|
|
ld_plugin_status
|
2015-02-05 01:47:28 +08:00
|
|
|
get_symbol_resolution_info(Symbol_table* symtab,
|
|
|
|
int nsyms,
|
2011-09-27 07:00:17 +08:00
|
|
|
ld_plugin_symbol* syms,
|
|
|
|
int version) const;
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Store the incoming symbols from the plugin for later processing.
|
|
|
|
void
|
|
|
|
store_incoming_symbols(int nsyms, const struct ld_plugin_symbol* syms)
|
|
|
|
{
|
|
|
|
this->nsyms_ = nsyms;
|
|
|
|
this->syms_ = syms;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return TRUE if the comdat group with key COMDAT_KEY from this object
|
|
|
|
// should be kept.
|
|
|
|
bool
|
|
|
|
include_comdat_group(std::string comdat_key, Layout* layout);
|
|
|
|
|
2009-01-15 09:29:25 +08:00
|
|
|
// Return the filename.
|
|
|
|
const std::string&
|
|
|
|
filename() const
|
|
|
|
{ return this->input_file()->filename(); }
|
|
|
|
|
|
|
|
// Return the file descriptor.
|
|
|
|
int
|
|
|
|
descriptor()
|
|
|
|
{ return this->input_file()->file().descriptor(); }
|
|
|
|
|
|
|
|
// Return the size of the file or archive member.
|
|
|
|
off_t
|
|
|
|
filesize()
|
|
|
|
{ return this->filesize_; }
|
|
|
|
|
2015-07-13 01:50:25 +08:00
|
|
|
// Return the word size of the object file.
|
|
|
|
int
|
|
|
|
elfsize() const
|
|
|
|
{ gold_unreachable(); }
|
|
|
|
|
|
|
|
// Return TRUE if this is a big-endian object file.
|
|
|
|
bool
|
|
|
|
is_big_endian() const
|
|
|
|
{ gold_unreachable(); }
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
protected:
|
|
|
|
// Return TRUE if this is an object claimed by a plugin.
|
|
|
|
virtual Pluginobj*
|
|
|
|
do_pluginobj()
|
|
|
|
{ return this; }
|
|
|
|
|
|
|
|
// The number of symbols provided by the plugin.
|
|
|
|
int nsyms_;
|
2013-10-12 05:11:49 +08:00
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// The symbols provided by the plugin.
|
|
|
|
const struct ld_plugin_symbol* syms_;
|
|
|
|
|
|
|
|
// The entries in the symbol table for the external symbols.
|
|
|
|
Symbols symbols_;
|
|
|
|
|
|
|
|
private:
|
2009-01-15 09:29:25 +08:00
|
|
|
// Size of the file (or archive member).
|
|
|
|
off_t filesize_;
|
2008-09-20 06:54:57 +08:00
|
|
|
// Map a comdat key symbol to a boolean indicating whether the comdat
|
|
|
|
// group in this object with that key should be kept.
|
|
|
|
typedef Unordered_map<std::string, bool> Comdat_map;
|
|
|
|
Comdat_map comdat_map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A plugin object, size-specific version.
|
|
|
|
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
class Sized_pluginobj : public Pluginobj
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Sized_pluginobj(const std::string& name, Input_file* input_file,
|
2009-01-15 09:29:25 +08:00
|
|
|
off_t offset, off_t filesize);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Read the symbols.
|
|
|
|
void
|
|
|
|
do_read_symbols(Read_symbols_data*);
|
|
|
|
|
|
|
|
// Lay out the input sections.
|
|
|
|
void
|
|
|
|
do_layout(Symbol_table*, Layout*, Read_symbols_data*);
|
|
|
|
|
|
|
|
// Add the symbols to the symbol table.
|
|
|
|
void
|
2009-02-14 03:04:45 +08:00
|
|
|
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
2010-03-22 22:18:24 +08:00
|
|
|
Archive::Should_include
|
2010-08-02 21:34:33 +08:00
|
|
|
do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
|
2010-03-22 22:18:24 +08:00
|
|
|
std::string* why);
|
|
|
|
|
2011-03-30 09:31:57 +08:00
|
|
|
// Iterate over global symbols, calling a visitor class V for each.
|
|
|
|
void
|
|
|
|
do_for_all_global_symbols(Read_symbols_data* sd,
|
|
|
|
Library_base::Symbol_visitor_base* v);
|
|
|
|
|
2011-04-12 08:44:48 +08:00
|
|
|
// Iterate over local symbols, calling a visitor class V for each GOT offset
|
|
|
|
// associated with a local symbol.
|
|
|
|
void
|
|
|
|
do_for_all_local_got_entries(Got_offset_list::Visitor* v) const;
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Get the size of a section.
|
|
|
|
uint64_t
|
|
|
|
do_section_size(unsigned int shndx);
|
|
|
|
|
|
|
|
// Get the name of a section.
|
|
|
|
std::string
|
2014-07-03 07:12:51 +08:00
|
|
|
do_section_name(unsigned int shndx) const;
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Return a view of the contents of a section.
|
2012-03-22 03:02:22 +08:00
|
|
|
const unsigned char*
|
|
|
|
do_section_contents(unsigned int shndx, section_size_type* plen,
|
|
|
|
bool cache);
|
2008-09-20 06:54:57 +08:00
|
|
|
|
|
|
|
// Return section flags.
|
|
|
|
uint64_t
|
|
|
|
do_section_flags(unsigned int shndx);
|
|
|
|
|
2009-08-06 04:51:56 +08:00
|
|
|
// Return section entsize.
|
|
|
|
uint64_t
|
|
|
|
do_section_entsize(unsigned int shndx);
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Return section address.
|
|
|
|
uint64_t
|
|
|
|
do_section_address(unsigned int shndx);
|
|
|
|
|
|
|
|
// Return section type.
|
|
|
|
unsigned int
|
|
|
|
do_section_type(unsigned int shndx);
|
|
|
|
|
|
|
|
// Return the section link field.
|
|
|
|
unsigned int
|
|
|
|
do_section_link(unsigned int shndx);
|
|
|
|
|
|
|
|
// Return the section link field.
|
|
|
|
unsigned int
|
|
|
|
do_section_info(unsigned int shndx);
|
|
|
|
|
|
|
|
// Return the section alignment.
|
|
|
|
uint64_t
|
|
|
|
do_section_addralign(unsigned int shndx);
|
|
|
|
|
|
|
|
// Return the Xindex structure to use.
|
|
|
|
Xindex*
|
|
|
|
do_initialize_xindex();
|
|
|
|
|
|
|
|
// Get symbol counts.
|
|
|
|
void
|
|
|
|
do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const;
|
|
|
|
|
2010-01-06 05:52:51 +08:00
|
|
|
// Get global symbols.
|
|
|
|
const Symbols*
|
|
|
|
do_get_global_symbols() const;
|
|
|
|
|
2008-09-20 06:54:57 +08:00
|
|
|
// Add placeholder symbols from a claimed file.
|
|
|
|
ld_plugin_status
|
|
|
|
add_symbols_from_plugin(int nsyms, const ld_plugin_symbol* syms);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
// This Task handles handles the "all symbols read" event hook.
|
|
|
|
// The plugin may add additional input files at this time, which must
|
|
|
|
// be queued for reading.
|
|
|
|
|
|
|
|
class Plugin_hook : public Task
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Plugin_hook(const General_options& options, Input_objects* input_objects,
|
2013-10-12 05:11:49 +08:00
|
|
|
Symbol_table* symtab, Layout* /*layout*/, Dirsearch* dirpath,
|
2008-09-20 06:54:57 +08:00
|
|
|
Mapfile* mapfile, Task_token* this_blocker,
|
|
|
|
Task_token* next_blocker)
|
|
|
|
: options_(options), input_objects_(input_objects), symtab_(symtab),
|
2013-10-12 05:11:49 +08:00
|
|
|
dirpath_(dirpath), mapfile_(mapfile),
|
2008-09-20 06:54:57 +08:00
|
|
|
this_blocker_(this_blocker), next_blocker_(next_blocker)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Plugin_hook();
|
|
|
|
|
|
|
|
// The standard Task methods.
|
|
|
|
|
|
|
|
Task_token*
|
|
|
|
is_runnable();
|
|
|
|
|
|
|
|
void
|
|
|
|
locks(Task_locker*);
|
|
|
|
|
|
|
|
void
|
|
|
|
run(Workqueue*);
|
|
|
|
|
|
|
|
std::string
|
|
|
|
get_name() const
|
|
|
|
{ return "Plugin_hook"; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const General_options& options_;
|
|
|
|
Input_objects* input_objects_;
|
|
|
|
Symbol_table* symtab_;
|
|
|
|
Dirsearch* dirpath_;
|
|
|
|
Mapfile* mapfile_;
|
|
|
|
Task_token* this_blocker_;
|
|
|
|
Task_token* next_blocker_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace gold.
|
|
|
|
|
|
|
|
#endif // !defined(GOLD_PLUGIN_H)
|