Fix symbol resolution with linker plugins for defsym symbols.
authorSriraman Tallam <tmsriram@google.com>
Fri, 16 Feb 2018 01:35:16 +0000 (17:35 -0800)
committerSriraman Tallam <tmsriram@google.com>
Fri, 16 Feb 2018 01:35:16 +0000 (17:35 -0800)
2018-02-07  Sriraman Tallam  <tmsriram@google.com>

* expression.cc (Symbol_expression::set_expr_sym_in_real_elf):
New method.
(Unary_expression::set_expr_sym_in_real_elf): New method.
(Binary_expression::set_expr_sym_in_real_elf): New method.
(Trinary_expression::set_expr_sym_in_real_elf): New method.
* plugin.cc (get_symbol_resolution_info): Fix symbol resolution if
defined or used in defsyms.
* plugin.h (Plugin_manager::is_defsym_def): New method.
(Plugin_manager::Plugin_manager): Initialize defsym_defines_set_.
(Plugin_manager::defsym_defines_set_): New member.
(Plugin_manager::Defsym_defines_set): New typedef.
* script.cc (Script_options::set_defsym_uses_in_real_elf): New method.
(Script_options::find_defsym_defs): New method.
* script.h (Expression::set_expr_sym_in_real_elf): New method.
(Symbol_assignment::is_defsym): New method.
(Symbol_assignment::value): New method.
(Script_options::find_defsym_defs): New method.
(Script_options::set_defsym_uses_in_real_elf): New method.
* testsuite/Makefile.am (plugin_test_defsym): New test.
* testsuite/Makefile.in: Regenerate.
* testsuite/plugin_test.c: Check for new symbol resolution.
* testsuite/plugin_test_defsym.sh: New script.
* testsuite/plugin_test_defsym.c: New test source.

gold/ChangeLog
gold/expression.cc
gold/plugin.cc
gold/plugin.h
gold/script.cc
gold/script.h
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/plugin_test_defsym.c [new file with mode: 0644]
gold/testsuite/plugin_test_defsym.sh [new file with mode: 0755]

index 1c98987ef6fc005057697739cd209b487f919cd3..032d74bb36ea0444df2e65051c889f4430ea7ae1 100644 (file)
@@ -1,3 +1,29 @@
+2018-02-07  Sriraman Tallam  <tmsriram@google.com>
+
+       * expression.cc (Symbol_expression::set_expr_sym_in_real_elf):
+       New method.
+       (Unary_expression::set_expr_sym_in_real_elf): New method.
+       (Binary_expression::set_expr_sym_in_real_elf): New method.
+       (Trinary_expression::set_expr_sym_in_real_elf): New method.
+       * plugin.cc (get_symbol_resolution_info): Fix symbol resolution if
+       defined or used in defsyms.
+       * plugin.h (Plugin_manager::is_defsym_def): New method.
+       (Plugin_manager::Plugin_manager): Initialize defsym_defines_set_.
+       (Plugin_manager::defsym_defines_set_): New member.
+       (Plugin_manager::Defsym_defines_set): New typedef.
+       * script.cc (Script_options::set_defsym_uses_in_real_elf): New method.
+       (Script_options::find_defsym_defs): New method.
+       * script.h (Expression::set_expr_sym_in_real_elf): New method.
+       (Symbol_assignment::is_defsym): New method.
+       (Symbol_assignment::value): New method.
+       (Script_options::find_defsym_defs): New method.
+       (Script_options::set_defsym_uses_in_real_elf): New method.
+       * testsuite/Makefile.am (plugin_test_defsym): New test.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/plugin_test.c: Check for new symbol resolution.
+       * testsuite/plugin_test_defsym.sh: New script.
+       * testsuite/plugin_test_defsym.c: New test source.
+
 2018-02-07  Alan Modra  <amodra@gmail.com>
 
        Revert 2018-01-17  Alan Modra  <amodra@gmail.com>
index d764cc2a9d9c05cd5123835926ffc22cce2196ba..bbfaa1ee161a5fff6f1131e102f6c983f07f2487 100644 (file)
@@ -205,6 +205,14 @@ class Symbol_expression : public Expression
   uint64_t
   value(const Expression_eval_info*);
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  {
+    Symbol* sym = symtab->lookup(this->name_.c_str());
+    if (sym != NULL)
+      sym->set_in_real_elf();
+  }
+
   void
   print(FILE* f) const
   { fprintf(f, "%s", this->name_.c_str()); }
@@ -318,6 +326,10 @@ class Unary_expression : public Expression
   arg_print(FILE* f) const
   { this->arg_->print(f); }
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  { return this->arg_->set_expr_sym_in_real_elf(symtab); }
+
  private:
   Expression* arg_;
 };
@@ -437,6 +449,13 @@ class Binary_expression : public Expression
     fprintf(f, ")");
   }
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  {
+    this->left_->set_expr_sym_in_real_elf(symtab);
+    this->right_->set_expr_sym_in_real_elf(symtab);
+  }
+
  private:
   Expression* left_;
   Expression* right_;
@@ -622,6 +641,14 @@ class Trinary_expression : public Expression
   arg3_print(FILE* f) const
   { this->arg3_->print(f); }
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  {
+    this->arg1_->set_expr_sym_in_real_elf(symtab);
+    this->arg2_->set_expr_sym_in_real_elf(symtab);
+    this->arg3_->set_expr_sym_in_real_elf(symtab);
+  }
+
  private:
   Expression* arg1_;
   Expression* arg2_;
index 02fef25dda5b49d036813bb688c8ed6bd889ebd5..566f1b7caef0fb6f17dab749fe9e4b69bee5e85d 100644 (file)
@@ -580,6 +580,11 @@ Plugin_manager::all_symbols_read(Workqueue* workqueue, Task* task,
   this->mapfile_ = mapfile;
   this->this_blocker_ = NULL;
 
+  // Set symbols used in defsym expressions as seen in real ELF.
+  Layout *layout = parameters->options().plugins()->layout();
+  layout->script_options()->set_defsym_uses_in_real_elf(symtab);
+  layout->script_options()->find_defsym_defs(this->defsym_defines_set_);
+
   for (this->current_ = this->plugins_.begin();
        this->current_ != this->plugins_.end();
        ++this->current_)
@@ -989,6 +994,7 @@ Pluginobj::get_symbol_resolution_info(Symbol_table* symtab,
       return version > 2 ? LDPS_NO_SYMS : LDPS_OK;
     }
 
+  Plugin_manager* plugins = parameters->options().plugins();
   for (int i = 0; i < nsyms; i++)
     {
       ld_plugin_symbol* isym = &syms[i];
@@ -997,9 +1003,16 @@ Pluginobj::get_symbol_resolution_info(Symbol_table* symtab,
         lsym = symtab->resolve_forwards(lsym);
       ld_plugin_symbol_resolution res = LDPR_UNKNOWN;
 
-      if (lsym->is_undefined())
-        // The symbol remains undefined.
-        res = LDPR_UNDEF;
+      if (plugins->is_defsym_def(lsym->name()))
+       {
+         // The symbol is redefined via defsym.
+         res = LDPR_PREEMPTED_REG;
+       }
+      else if (lsym->is_undefined())
+       {
+          // The symbol remains undefined.
+          res = LDPR_UNDEF;
+       }
       else if (isym->def == LDPK_UNDEF
                || isym->def == LDPK_WEAKUNDEF
                || isym->def == LDPK_COMMON)
index db6093daa7730dbf2f5b919116449a37f5129b23..e64ee07bb6bf876f3be69d2ad19a2ad6318de0cd 100644 (file)
@@ -146,11 +146,18 @@ class Plugin_manager
       options_(options), workqueue_(NULL), task_(NULL), input_objects_(NULL),
       symtab_(NULL), layout_(NULL), dirpath_(NULL), mapfile_(NULL),
       this_blocker_(NULL), extra_search_path_(), lock_(NULL),
-      initialize_lock_(&lock_)
+      initialize_lock_(&lock_), defsym_defines_set_()
   { this->current_ = plugins_.end(); }
 
   ~Plugin_manager();
 
+  // 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();
+  }
+
   // Add a plugin library.
   void
   add_plugin(const char* filename)
@@ -402,6 +409,10 @@ class Plugin_manager
   std::string extra_search_path_;
   Lock* lock_;
   Initialize_lock initialize_lock_;
+
+  // Keep track of all symbols defined by defsym.
+  typedef Unordered_set<std::string> Defsym_defines_set;
+  Defsym_defines_set defsym_defines_set_;
 };
 
 
index db243cf435aa5c6eb01820706bc807df1f89e14e..3deb1ae1964fcce443fc10e2f23974769577bf6b 100644 (file)
@@ -1112,6 +1112,29 @@ Script_options::is_pending_assignment(const char* name)
   return false;
 }
 
+// Populates the set with symbols defined in defsym LHS.
+
+void Script_options::find_defsym_defs(Unordered_set<std::string>& defsym_set)
+{
+  for (Symbol_assignments::const_iterator p = this->symbol_assignments_.begin();
+       p != this->symbol_assignments_.end();
+       ++p)
+    {
+      defsym_set.insert((*p)->name());
+    }
+}
+
+void
+Script_options::set_defsym_uses_in_real_elf(Symbol_table* symtab) const
+{
+  for (Symbol_assignments::const_iterator p = this->symbol_assignments_.begin();
+       p != this->symbol_assignments_.end();
+       ++p)
+    {
+      (*p)->value()->set_expr_sym_in_real_elf(symtab);
+    }
+}
+
 // Add a symbol to be defined.
 
 void
index ec8ce8e11090e9bcd546b854f2f33042e4d6eac7..aaf825a786d95af4c2f1776941d89b3595161507 100644 (file)
@@ -129,13 +129,17 @@ class Expression
   virtual uint64_t
   value(const Expression_eval_info*) = 0;
 
+  // Sets all symbols used in expressions as seen in a real ELF object.
+  virtual void
+  set_expr_sym_in_real_elf(Symbol_table*) const
+  { return; }
+
  private:
   // May not be copied.
   Expression(const Expression&);
   Expression& operator=(const Expression&);
 };
 
-
 // Version_script_info stores information parsed from the version
 // script, either provided by --version-script or as part of a linker
 // script.  A single Version_script_info object per target is owned by
@@ -344,6 +348,14 @@ class Symbol_assignment
   void
   finalize(Symbol_table*, const Layout*);
 
+  bool
+  is_defsym() const
+  { return is_defsym_; }
+
+  Expression *
+  value() const
+  { return val_; }
+
   // Finalize the symbol value when it can refer to the dot symbol.
   void
   finalize_with_dot(Symbol_table*, const Layout*, uint64_t dot_value,
@@ -454,6 +466,13 @@ class Script_options
   bool
   define_symbol(const char* definition);
 
+  // Populates the set with symbol names used in LHS of defsym.
+  void
+  find_defsym_defs(Unordered_set<std::string>&);
+
+  // Set symbols used in defsym expressions as seen in a real ELF object.
+  void set_defsym_uses_in_real_elf(Symbol_table*) const;
+
   // Create sections required by any linker scripts.
   void
   create_script_sections(Layout*);
index 16cae8004c9cd7ed1ad163476ff4ebf3445cd104..7ec3e8d88f8361237fcc0e09f2f30baeb43d857d 100644 (file)
@@ -2332,11 +2332,22 @@ plugin_test_start_lib: unused.o plugin_start_lib_test.o plugin_start_lib_test_2.
 plugin_test_start_lib.err: plugin_test_start_lib
        @touch plugin_test_start_lib.err
 
+check_PROGRAMS += plugin_test_defsym
+check_SCRIPTS += plugin_test_defsym.sh
+check_DATA += plugin_test_defsym.err
+MOSTLYCLEANFILES += plugin_test_defsym.err
+plugin_test_defsym.syms: plugin_test_defsym.o
+       $(TEST_READELF) -sW $< >$@ 2>/dev/null
+plugin_test_defsym.o: plugin_test_defsym.c
+       $(COMPILE) -c -o $@ $<
+plugin_test_defsym: plugin_test_defsym.o plugin_test_defsym.syms gcctestdir/ld plugin_test.so
+       $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so" -Wl,--defsym,bar=foo plugin_test_defsym.syms 2>plugin_test_defsym.err
+plugin_test_defsym.err: plugin_test_defsym
+       @touch plugin_test_defsym.err
 
 plugin_start_lib_test_2.syms: plugin_start_lib_test_2.o
        $(TEST_READELF) -sW $< >$@ 2>/dev/null
 
-
 plugin_test.so: plugin_test.o gcctestdir/ld
        $(LINK) -Bgcctestdir/ -shared plugin_test.o
 plugin_test.o: plugin_test.c
index bbf8dc146bb0bd49bd694bf92bf8f6df9adce2e8..ca79238f3b9f274eac87843357669cf0b1ed42bb 100644 (file)
@@ -535,7 +535,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_10 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_11 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_12 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_defsym
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_45 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_1.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_2.sh \
@@ -546,7 +547,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_10.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_11.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_12.sh \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_defsym.sh
 
 # Test that symbols known in the IR file but not in the replacement file
 # produce an unresolved symbol error.
@@ -566,7 +568,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_10.sections \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_11.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_12.err \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_defsym.err
 # Make a copy of two_file_test_1.o, which does not define the symbol _Z4t16av.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_47 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_1.err \
@@ -583,7 +586,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_11.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_thin.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_12.err \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_defsym.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_48 = plugin_test_tls
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_49 = plugin_test_tls.sh
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_50 = plugin_test_tls.err
@@ -1211,7 +1215,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_10$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_11$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_12$(EXEEXT) \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib$(EXEEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_start_lib$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_defsym$(EXEEXT)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__EXEEXT_25 = plugin_test_tls$(EXEEXT)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_26 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ exclude_libs_test$(EXEEXT) \
@@ -1932,6 +1937,13 @@ plugin_test_8_DEPENDENCIES = libgoldtest.a ../libgold.a \
        ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
        $(am__DEPENDENCIES_1)
+plugin_test_defsym_SOURCES = plugin_test_defsym.c
+plugin_test_defsym_OBJECTS = plugin_test_defsym.$(OBJEXT)
+plugin_test_defsym_LDADD = $(LDADD)
+plugin_test_defsym_DEPENDENCIES = libgoldtest.a ../libgold.a \
+       ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+       $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+       $(am__DEPENDENCIES_1)
 plugin_test_start_lib_SOURCES = plugin_test_start_lib.c
 plugin_test_start_lib_OBJECTS = plugin_test_start_lib.$(OBJEXT)
 plugin_test_start_lib_LDADD = $(LDADD)
@@ -2475,8 +2487,8 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \
        plugin_test_10.c plugin_test_11.c plugin_test_12.c \
        plugin_test_2.c plugin_test_3.c plugin_test_4.c \
        plugin_test_5.c plugin_test_6.c plugin_test_7.c \
-       plugin_test_8.c plugin_test_start_lib.c plugin_test_tls.c \
-       pr17704a_test.c $(pr20216a_test_SOURCES) \
+       plugin_test_8.c plugin_test_defsym.c plugin_test_start_lib.c \
+       plugin_test_tls.c pr17704a_test.c $(pr20216a_test_SOURCES) \
        $(pr20216b_test_SOURCES) $(pr20216c_test_SOURCES) \
        $(pr20216d_test_SOURCES) $(pr20216e_test_SOURCES) \
        $(pr20308a_test_SOURCES) $(pr20308b_test_SOURCES) \
@@ -4108,6 +4120,15 @@ pie_copyrelocs_test$(EXEEXT): $(pie_copyrelocs_test_OBJECTS) $(pie_copyrelocs_te
 @PLUGINS_FALSE@plugin_test_8$(EXEEXT): $(plugin_test_8_OBJECTS) $(plugin_test_8_DEPENDENCIES) $(EXTRA_plugin_test_8_DEPENDENCIES) 
 @PLUGINS_FALSE@        @rm -f plugin_test_8$(EXEEXT)
 @PLUGINS_FALSE@        $(LINK) $(plugin_test_8_OBJECTS) $(plugin_test_8_LDADD) $(LIBS)
+@GCC_FALSE@plugin_test_defsym$(EXEEXT): $(plugin_test_defsym_OBJECTS) $(plugin_test_defsym_DEPENDENCIES) $(EXTRA_plugin_test_defsym_DEPENDENCIES) 
+@GCC_FALSE@    @rm -f plugin_test_defsym$(EXEEXT)
+@GCC_FALSE@    $(LINK) $(plugin_test_defsym_OBJECTS) $(plugin_test_defsym_LDADD) $(LIBS)
+@NATIVE_LINKER_FALSE@plugin_test_defsym$(EXEEXT): $(plugin_test_defsym_OBJECTS) $(plugin_test_defsym_DEPENDENCIES) $(EXTRA_plugin_test_defsym_DEPENDENCIES) 
+@NATIVE_LINKER_FALSE@  @rm -f plugin_test_defsym$(EXEEXT)
+@NATIVE_LINKER_FALSE@  $(LINK) $(plugin_test_defsym_OBJECTS) $(plugin_test_defsym_LDADD) $(LIBS)
+@PLUGINS_FALSE@plugin_test_defsym$(EXEEXT): $(plugin_test_defsym_OBJECTS) $(plugin_test_defsym_DEPENDENCIES) $(EXTRA_plugin_test_defsym_DEPENDENCIES) 
+@PLUGINS_FALSE@        @rm -f plugin_test_defsym$(EXEEXT)
+@PLUGINS_FALSE@        $(LINK) $(plugin_test_defsym_OBJECTS) $(plugin_test_defsym_LDADD) $(LIBS)
 @GCC_FALSE@plugin_test_start_lib$(EXEEXT): $(plugin_test_start_lib_OBJECTS) $(plugin_test_start_lib_DEPENDENCIES) $(EXTRA_plugin_test_start_lib_DEPENDENCIES) 
 @GCC_FALSE@    @rm -f plugin_test_start_lib$(EXEEXT)
 @GCC_FALSE@    $(LINK) $(plugin_test_start_lib_OBJECTS) $(plugin_test_start_lib_LDADD) $(LIBS)
@@ -4520,6 +4541,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_6.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_7.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_8.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_defsym.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_start_lib.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_tls.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr17704a_test.Po@am__quote@
@@ -5293,6 +5315,8 @@ plugin_test_12.sh.log: plugin_test_12.sh
        @p='plugin_test_12.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_start_lib.sh.log: plugin_test_start_lib.sh
        @p='plugin_test_start_lib.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+plugin_test_defsym.sh.log: plugin_test_defsym.sh
+       @p='plugin_test_defsym.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_tls.sh.log: plugin_test_tls.sh
        @p='plugin_test_tls.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_final_layout.sh.log: plugin_final_layout.sh
@@ -5661,6 +5685,8 @@ plugin_test_12.log: plugin_test_12$(EXEEXT)
        @p='plugin_test_12$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_start_lib.log: plugin_test_start_lib$(EXEEXT)
        @p='plugin_test_start_lib$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+plugin_test_defsym.log: plugin_test_defsym$(EXEEXT)
+       @p='plugin_test_defsym$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_tls.log: plugin_test_tls$(EXEEXT)
        @p='plugin_test_tls$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 exclude_libs_test.log: exclude_libs_test$(EXEEXT)
@@ -7010,6 +7036,14 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@           -Wl,--start-lib plugin_start_lib_test_2.syms -Wl,--end-lib 2>plugin_test_start_lib.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_start_lib.err: plugin_test_start_lib
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   @touch plugin_test_start_lib.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_defsym.syms: plugin_test_defsym.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(TEST_READELF) -sW $< >$@ 2>/dev/null
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_defsym.o: plugin_test_defsym.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(COMPILE) -c -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_defsym: plugin_test_defsym.o plugin_test_defsym.syms gcctestdir/ld plugin_test.so
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so" -Wl,--defsym,bar=foo plugin_test_defsym.syms 2>plugin_test_defsym.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_defsym.err: plugin_test_defsym
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   @touch plugin_test_defsym.err
 
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_start_lib_test_2.syms: plugin_start_lib_test_2.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(TEST_READELF) -sW $< >$@ 2>/dev/null
diff --git a/gold/testsuite/plugin_test_defsym.c b/gold/testsuite/plugin_test_defsym.c
new file mode 100644 (file)
index 0000000..3b004c6
--- /dev/null
@@ -0,0 +1,32 @@
+/* plugin_test_defsym.c -- a test case for gold
+
+   Copyright (C) 2018 onwards Free Software Foundation, Inc.
+   Written by Sriraman Tallam <tmsriram@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.  */
+
+int foo(void);
+int foo(void) {
+  return 0;
+}
+
+int bar(void);
+
+int main(void) {
+  return bar();
+}
diff --git a/gold/testsuite/plugin_test_defsym.sh b/gold/testsuite/plugin_test_defsym.sh
new file mode 100755 (executable)
index 0000000..6066f9b
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# plugin_test_defsym.sh -- a test case for the plugin API.
+
+# Copyright (C) 2018 onwards Free Software Foundation, Inc.
+# Written by Sriraman Tallam <tmsriram@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.
+
+# This file goes with plugin_test.c, a simple plug-in library that
+# exercises the basic interfaces and prints out version numbers and
+# options passed to the plugin.
+
+# This checks if the symbol resolution withe export dynamic symbol is
+# as expected.
+
+check()
+{
+    if ! grep -q "$2" "$1"
+    then
+       echo "Did not find expected output in $1:"
+       echo "   $2"
+       echo ""
+       echo "Actual output below:"
+       cat "$1"
+       exit 1
+    fi
+}
+
+check plugin_test_defsym.err "API version:"
+check plugin_test_defsym.err "gold version:"
+check plugin_test_defsym.err "plugin_test_defsym.syms: claim file hook called"
+check plugin_test_defsym.err "plugin_test_defsym.syms: bar: PREEMPTED_REG"
+check plugin_test_defsym.err "plugin_test_defsym.syms: foo: PREVAILING_DEF_REG"
+check plugin_test_defsym.err "cleanup hook called"
+
+exit 0