This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold][patch] Change how to specify options for the plugins
> Please add a space between "//" and "Parse".
>
>> + DEFINE_special(plugin_opt, options::TWO_DASHES, '\0',
>> + N_("pass an option to the plugin"), N_("OPTION"));
>
> Please capitalize "pass".
>
> This is OK with those changes.
I have updated the patch, but I don't have write access.
> Thanks.
>
> Ian
>
Cheers,
--
Rafael Avila de Espindola
Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047
? gold/autom4te.cache
Index: gold/options.cc
===================================================================
RCS file: /cvs/src/src/gold/options.cc,v
retrieving revision 1.79
diff -u -r1.79 options.cc
--- gold/options.cc 6 Nov 2008 07:23:31 -0000 1.79
+++ gold/options.cc 5 Dec 2008 11:23:46 -0000
@@ -304,6 +304,15 @@
{
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
@@ -650,14 +659,24 @@
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
Index: gold/options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.88
diff -u -r1.88 options.h
--- gold/options.h 6 Nov 2008 07:23:31 -0000 1.88
+++ gold/options.h 5 Dec 2008 11:23:46 -0000
@@ -704,7 +704,9 @@
#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,
@@ -989,7 +991,11 @@
// 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_;
Index: gold/plugin.cc
===================================================================
RCS file: /cvs/src/src/gold/plugin.cc,v
retrieving revision 1.3
diff -u -r1.3 plugin.cc
--- gold/plugin.cc 1 Dec 2008 19:50:48 -0000 1.3
+++ gold/plugin.cc 5 Dec 2008 11:23:46 -0000
@@ -85,31 +85,13 @@
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;
}
@@ -118,7 +100,8 @@
(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;
}
@@ -130,7 +113,7 @@
// 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;
@@ -150,11 +133,11 @@
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;
Index: gold/plugin.h
===================================================================
RCS file: /cvs/src/src/gold/plugin.h,v
retrieving revision 1.1
diff -u -r1.1 plugin.h
--- gold/plugin.h 19 Sep 2008 22:54:57 -0000 1.1
+++ gold/plugin.h 5 Dec 2008 11:23:46 -0000
@@ -48,9 +48,10 @@
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)
@@ -90,6 +91,13 @@
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&);
@@ -97,7 +105,9 @@
// 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_;
@@ -119,8 +129,16 @@
// 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
Index: gold/testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.79
diff -u -r1.79 Makefile.am
--- gold/testsuite/Makefile.am 6 Nov 2008 07:23:31 -0000 1.79
+++ gold/testsuite/Makefile.am 5 Dec 2008 11:23:46 -0000
@@ -959,7 +959,7 @@
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
Index: gold/testsuite/Makefile.in
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.in,v
retrieving revision 1.84
diff -u -r1.84 Makefile.in
--- gold/testsuite/Makefile.in 6 Nov 2008 07:23:31 -0000 1.84
+++ gold/testsuite/Makefile.in 5 Dec 2008 11:23:47 -0000
@@ -2454,7 +2454,7 @@
@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