2008-12-05 Rafael Avila de Espindola <espindola@google.com>
authorCary Coutant <ccoutant@google.com>
Fri, 5 Dec 2008 21:34:54 +0000 (21:34 +0000)
committerCary Coutant <ccoutant@google.com>
Fri, 5 Dec 2008 21:34:54 +0000 (21:34 +0000)
* 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.

gold/ChangeLog
gold/options.cc
gold/options.h
gold/plugin.cc
gold/plugin.h
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in

index 7d0d9cc59071162e849faebb33d5023a59ff699f..fbad1ee1ab24c899d260aaeb4224d81d97baa4c2 100644 (file)
@@ -1,3 +1,20 @@
+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.
index 90fa1630e3ed6724a5e1aa06778167b3eeebc055..6b2b5cf8f7c331530f896fd18353b2562a04bb38 100644 (file)
@@ -304,6 +304,15 @@ General_options::parse_plugin(const char*, const char* arg,
 {
   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 @@ General_options::add_sysroot()
   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 f92184f6751e4e4350773d589456e82583ec6056..8d936d0218cd6b03fd8d7e120087822e4d0b80d8 100644 (file)
@@ -704,7 +704,9 @@ class General_options
 
 #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,
@@ -991,7 +993,11 @@ class General_options
 
   // 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 1b0eb014021bbf1c6627c62f4e55dbbb09a9c866..9056a3b93b59c2eb9145f451708973d352863847 100644 (file)
@@ -85,31 +85,13 @@ void
 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 @@ Plugin::load()
     (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 @@ Plugin::load()
 
   // 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 @@ Plugin::load()
   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 3f573ced27baa9c8a84455cf5b359e1388a4862a..5b6fa1fd3400a8cd74fa771714be0f7016567081 100644 (file)
@@ -48,9 +48,10 @@ class Pluginobj;
 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 @@ class Plugin
   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 @@ class 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_;
@@ -119,8 +129,16 @@ class Plugin_manager
 
   // 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 dcb8bad36b776f382f75506cc41ebe2ebca5d246..78c0529976d4f76c377d8c67d1152bb027c701c1 100644 (file)
@@ -959,7 +959,7 @@ check_SCRIPTS += plugin_test_1.sh
 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 7271bb0b52108ee478111a9ec5370558dc2143f7..bb9d0cecf14f1ded0e581f73a7e618c69f06b3fb 100644 (file)
@@ -2454,7 +2454,7 @@ uninstall-am: uninstall-info-am
 @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
This page took 0.037224 seconds and 4 git commands to generate.