* options.cc (General_options::parse_plugin_opt): New.
(General_options::add_plugin): The argument now is just the filename.
(General_options::add_plugin_option): New.
* options.h (plugin_opt): New.
(add_plugin): Change argument name.
(add_plugin_option): New.
* plugin.cc (Plugin::load): Don't parse the plugin option.
* plugin.h (Plugin::Plugin): Rename argument. Init filename_.
(Plugin::add_option): New.
(Plugin::args_): Change type.
(Plugin::filename_): New.
(Plugin_manager::add_plugin_option): New.
* testsuite/Makefile.am (plugin_test_1): Use new syntax.
* testsuite/Makefile.in: Regenerate.
+2008-12-05 Rafael Avila de Espindola <espindola@google.com>
+
+ * options.cc (General_options::parse_plugin_opt): New.
+ (General_options::add_plugin): The argument now is just the filename.
+ (General_options::add_plugin_option): New.
+ * options.h (plugin_opt): New.
+ (add_plugin): Change argument name.
+ (add_plugin_option): New.
+ * plugin.cc (Plugin::load): Don't parse the plugin option.
+ * plugin.h (Plugin::Plugin): Rename argument. Init filename_.
+ (Plugin::add_option): New.
+ (Plugin::args_): Change type.
+ (Plugin::filename_): New.
+ (Plugin_manager::add_plugin_option): New.
+ * testsuite/Makefile.am (plugin_test_1): Use new syntax.
+ * testsuite/Makefile.in: Regenerate.
+
2008-12-05 Cary Coutant <ccoutant@google.com>
* layout.cc (Layout::include_section): Check for SHF_EXCLUDE.
{
this->add_plugin(arg);
}
+
+// Parse --plugin-opt.
+
+void
+General_options::parse_plugin_opt(const char*, const char* arg,
+ Command_line*)
+{
+ this->add_plugin_option(arg);
+}
#endif // ENABLE_PLUGINS
void
free(canonical_sysroot);
}
-// Add a plugin and its arguments to the list of plugins.
+// Add a plugin to the list of plugins.
void
-General_options::add_plugin(const char* arg)
+General_options::add_plugin(const char* filename)
{
if (this->plugins_ == NULL)
this->plugins_ = new Plugin_manager(*this);
- this->plugins_->add_plugin(arg);
+ this->plugins_->add_plugin(filename);
+}
+
+// Add a plugin option to a plugin.
+
+void
+General_options::add_plugin_option(const char* arg)
+{
+ if (this->plugins_ == NULL)
+ gold_fatal("--plugin-opt requires --plugin.");
+ this->plugins_->add_plugin_option(arg);
}
// Set up variables and other state that isn't set up automatically by
#ifdef ENABLE_PLUGINS
DEFINE_special(plugin, options::TWO_DASHES, '\0',
- N_("Load a plugin library"), N_("PLUGIN[,ARG,...]"));
+ N_("Load a plugin library"), N_("PLUGIN"));
+ DEFINE_special(plugin_opt, options::TWO_DASHES, '\0',
+ N_("Pass an option to the plugin"), N_("OPTION"));
#endif
DEFINE_bool(preread_archive_symbols, options::TWO_DASHES, '\0', false,
// Add a plugin and its arguments to the list of plugins.
void
- add_plugin(const char* arg);
+ add_plugin(const char *filename);
+
+ // Add a plugin option.
+ void
+ add_plugin_option(const char* opt);
// Whether to mark the stack as executable.
Execstack execstack_status_;
Plugin::load()
{
#ifdef ENABLE_PLUGINS
- std::string filename;
- std::vector<std::string> args;
-
- // Parse the filename and arguments, each separated by commas.
- // FIXME: Temporarily allowing semicolon as an argument separator
- // so args can be passed through gcc's -Wl,... option, which
- // breaks arguments at the commas.
- const char* p = this->args_;
- int n = strcspn(p, ",;");
- filename.assign(p, n);
- p += n;
- while (*p == ',' || *p == ';')
- {
- ++p;
- n = strcspn(p, ",;");
- args.push_back(std::string(p, n));
- p += n;
- }
-
// Load the plugin library.
// FIXME: Look for the library in standard locations.
- this->handle_ = dlopen(filename.c_str(), RTLD_NOW);
+ this->handle_ = dlopen(this->filename_.c_str(), RTLD_NOW);
if (this->handle_ == NULL)
{
- gold_error(_("%s: could not load plugin library"), filename.c_str());
+ gold_error(_("%s: could not load plugin library"),
+ this->filename_.c_str());
return;
}
(dlsym(this->handle_, "onload"));
if (onload == NULL)
{
- gold_error(_("%s: could not find onload entry point"), filename.c_str());
+ gold_error(_("%s: could not find onload entry point"),
+ this->filename_.c_str());
return;
}
// Allocate and populate a transfer vector.
const int tv_fixed_size = 11;
- int tv_size = args.size() + tv_fixed_size;
+ int tv_size = this->args_.size() + tv_fixed_size;
ld_plugin_tv *tv = new ld_plugin_tv[tv_size];
int i = 0;
else
tv[i].tv_u.tv_val = LDPO_EXEC;
- for (unsigned int j = 0; j < args.size(); ++j)
+ for (unsigned int j = 0; j < this->args_.size(); ++j)
{
++i;
tv[i].tv_tag = LDPT_OPTION;
- tv[i].tv_u.tv_string = args[j].c_str();
+ tv[i].tv_u.tv_string = this->args_[j].c_str();
}
++i;
class Plugin
{
public:
- Plugin(const char* args)
+ Plugin(const char* filename)
: handle_(NULL),
- args_(args),
+ filename_(filename),
+ args_(),
claim_file_handler_(NULL),
all_symbols_read_handler_(NULL),
cleanup_handler_(NULL)
set_cleanup_handler(ld_plugin_cleanup_handler handler)
{ this->cleanup_handler_ = handler; }
+ // Add an argument
+ void
+ add_option(const char *arg)
+ {
+ this->args_.push_back(arg);
+ }
+
private:
Plugin(const Plugin&);
Plugin& operator=(const Plugin&);
// The shared library handle returned by dlopen.
void* handle_;
// The argument string given to --plugin.
- const char* args_;
+ std::string filename_;
+ // The list of argument string given to --plugin-opt.
+ std::vector<std::string> args_;
// The plugin's event handlers.
ld_plugin_claim_file_handler claim_file_handler_;
ld_plugin_all_symbols_read_handler all_symbols_read_handler_;
// Add a plugin library.
void
- add_plugin(const char* args)
- { this->plugins_.push_back(new Plugin(args)); }
+ 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);
+ }
// Load all plugin libraries.
void
check_DATA += plugin_test_1.err
MOSTLYCLEANFILES += plugin_test_1.err
plugin_test_1: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms gcctestdir/ld plugin_test.so
- $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so;_Z4f13iv" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms 2>plugin_test_1.err
+ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms 2>plugin_test_1.err
plugin_test_1.err: plugin_test_1
@touch plugin_test_1.err
@GCC_TRUE@@NATIVE_LINKER_TRUE@ test -d alt || mkdir -p alt
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_1: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms gcctestdir/ld plugin_test.so
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so;_Z4f13iv" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms 2>plugin_test_1.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms 2>plugin_test_1.err
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_1.err: plugin_test_1
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ @touch plugin_test_1.err
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_2: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_shared_2.so gcctestdir/ld plugin_test.so