* plugin.cc (Plugin::load): Move LDPT_MESSAGE to front of transfer
authorCary Coutant <ccoutant@google.com>
Tue, 16 Dec 2008 19:19:16 +0000 (19:19 +0000)
committerCary Coutant <ccoutant@google.com>
Tue, 16 Dec 2008 19:19:16 +0000 (19:19 +0000)
vector.
(Plugin_manager::claim_file): Create plugin object even if
plugin did not call the add_symbols callback.
(Plugin_obj::get_symbol_resolution_info): Guard against plugin
asking for more symbols than were added.
* testsuite/Makefile.am (plugin_test_1): Add test case with
no global symbols.
(empty.syms): New target.
* testsuite/Makefile.in: Regenerate.
* testsuite/plugin_test.c (claim_file_hook): Add new debug
message. Don't call add_symbols if no globals.
(all_symbols_read_hook): Don't provide replacement for empty
claimed file.

gold/ChangeLog
gold/plugin.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/plugin_test.c

index 3e1b99f7a872c9fff51b994aae1dc9952911db27..f344f502cd8b003fe002cdac4da3820496b6cd0d 100644 (file)
@@ -1,3 +1,20 @@
+2008-12-16  Cary Coutant  <ccoutant@google.com>
+
+       * plugin.cc (Plugin::load): Move LDPT_MESSAGE to front of transfer
+       vector.
+       (Plugin_manager::claim_file): Create plugin object even if
+       plugin did not call the add_symbols callback.
+       (Plugin_obj::get_symbol_resolution_info): Guard against plugin
+       asking for more symbols than were added.
+       * testsuite/Makefile.am (plugin_test_1): Add test case with
+       no global symbols.
+       (empty.syms): New target.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/plugin_test.c (claim_file_hook): Add new debug
+       message. Don't call add_symbols if no globals.
+       (all_symbols_read_hook): Don't provide replacement for empty
+       claimed file.
+
 2008-12-12  Ian Lance Taylor  <iant@google.com>
 
        * target-reloc.h (Default_scan_relocatable_relocs): Only discard
index 9056a3b93b59c2eb9145f451708973d352863847..c4e46b501adbea5d69fdbe93e68cede7aa513e94 100644 (file)
@@ -116,7 +116,13 @@ Plugin::load()
   int tv_size = this->args_.size() + tv_fixed_size;
   ld_plugin_tv *tv = new ld_plugin_tv[tv_size];
 
+  // Put LDPT_MESSAGE at the front of the list so the plugin can use it
+  // while processing subsequent entries.
   int i = 0;
+  tv[i].tv_tag = LDPT_MESSAGE;
+  tv[i].tv_u.tv_message = message;
+
+  ++i;
   tv[i].tv_tag = LDPT_API_VERSION;
   tv[i].tv_u.tv_val = LD_PLUGIN_API_VERSION;
 
@@ -164,10 +170,6 @@ Plugin::load()
   tv[i].tv_tag = LDPT_ADD_INPUT_FILE;
   tv[i].tv_u.tv_add_input_file = add_input_file;
 
-  ++i;
-  tv[i].tv_tag = LDPT_MESSAGE;
-  tv[i].tv_u.tv_message = message;
-
   ++i;
   tv[i].tv_tag = LDPT_NULL;
   tv[i].tv_u.tv_val = 0;
@@ -265,14 +267,13 @@ Plugin_manager::claim_file(Input_file* input_file, off_t offset,
     {
       if ((*this->current_)->claim_file(&this->plugin_input_file_))
         {
-          if (this->objects_.size() <= handle)
-            {
-              gold_error(_("%s: plugin claimed the file "
-                           "but did not provide any symbols"),
-                         this->plugin_input_file_.name);
-              return NULL;
-            }
-          return this->objects_[handle];
+          if (this->objects_.size() > handle)
+            return this->objects_[handle];
+
+          // If the plugin claimed the file but did not call the
+          // add_symbols callback, we need to create the Pluginobj now.
+          Pluginobj* obj = this->make_plugin_object(handle);
+          return obj;
         }
     }
 
@@ -369,7 +370,7 @@ Pluginobj::Pluginobj(const std::string& name, Input_file* input_file,
 ld_plugin_status
 Pluginobj::get_symbol_resolution_info(int nsyms, ld_plugin_symbol* syms) const
 {
-  if (this->nsyms_ == 0)
+  if (nsyms > this->nsyms_)
     return LDPS_NO_SYMS;
   for (int i = 0; i < nsyms; i++)
     {
index 78c0529976d4f76c377d8c67d1152bb027c701c1..c5f52acdb8b4dbdbeb28090dd11641a12f0ff9f7 100644 (file)
@@ -958,8 +958,8 @@ check_PROGRAMS += plugin_test_1
 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",--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: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms empty.syms gcctestdir/ld plugin_test.so
+       $(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 empty.syms 2>plugin_test_1.err
 plugin_test_1.err: plugin_test_1
        @touch plugin_test_1.err
 
@@ -985,6 +985,9 @@ two_file_test_1b.syms: two_file_test_1b.o
        $(TEST_READELF) -sW $< >$@ 2>/dev/null
 two_file_test_2.syms: two_file_test_2.o
        $(TEST_READELF) -sW $< >$@ 2>/dev/null
+empty.syms:
+       @echo "" >empty.syms
+       @echo "Symbol table" >>empty.syms
 
 endif PLUGINS
 
index bb9d0cecf14f1ded0e581f73a7e618c69f06b3fb..5509ab16cade962befc0c28975ce01f72fd0dd37 100644 (file)
@@ -1463,9 +1463,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
              exit 1;; \
          esac; \
        done; \
-       echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  testsuite/Makefile'; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  testsuite/Makefile'; \
        cd $(top_srcdir) && \
-         $(AUTOMAKE) --gnu  testsuite/Makefile
+         $(AUTOMAKE) --foreign  testsuite/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
        @case '$?' in \
@@ -2453,8 +2453,8 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@alt/thin_archive_test_4.o: thin_archive_test_4.cc
 @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",--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: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms empty.syms gcctestdir/ld plugin_test.so
+@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 empty.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
@@ -2475,6 +2475,9 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(TEST_READELF) -sW $< >$@ 2>/dev/null
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@two_file_test_2.syms: two_file_test_2.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(TEST_READELF) -sW $< >$@ 2>/dev/null
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@empty.syms:
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   @echo "" >empty.syms
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   @echo "Symbol table" >>empty.syms
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
index c60c7a1f8580335052b4c261339d89231a4c66c8..c36fee4aa63fddd8fdf2c1b1d4b045719a8b068e 100644 (file)
@@ -319,7 +319,11 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed)
     last_claimed_file->next = claimed_file;
   last_claimed_file = claimed_file;
 
-  (*add_symbols)(file->handle, nsyms, syms);
+  (*message)(LDPL_INFO, "%s: claiming file, adding %d symbols",
+             file->name, nsyms);
+
+  if (nsyms > 0)
+    (*add_symbols)(file->handle, nsyms, syms);
 
   *claimed = 1;
   return LDPS_OK;
@@ -398,6 +402,8 @@ all_symbols_read_hook(void)
        claimed_file != NULL;
        claimed_file = claimed_file->next)
     {
+      if (claimed_file->nsyms == 0)
+        continue;
       if (strlen(claimed_file->name) >= sizeof(buf))
         {
           (*message)(LDPL_FATAL, "%s: filename too long", claimed_file->name);