New plugin interface to get list of symbols wrapped with --wrap option.

2018-02-22  Sriraman Tallam  <tmsriram@google.com>

	* plugin.cc (get_wrap_symbols): New plugin interface.
	(load): Add get_wrap_symbols to transfer vector.
	* plugin-api.h (ld_plugin_get_wrap_symbols): New plugin interface.
	* testsuite/plugin_test.c (onload): Call and check get_wrap_symbols
	interface.
	* testsuite/plugin_test_wrap_symbols.sh: New test script.
	* testsuite/plugin_test_wrap_symbols_1.cc: New file.
	* testsuite/plugin_test_wrap_symbols_2.cc: New file.
	* testsuite/Makefile.am (plugin_test_wrap_symbols): New test.
	* testsuite/Makefile.in: Regenerate.

(cherry picked from commit 0b65c07b97c43e8891c2e14061270878a85222c8)
diff --git a/gold/ChangeLog b/gold/ChangeLog
index b6d08fc6..5a69fd9 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,4 +1,21 @@
 2018-04-27  Sriraman Tallam  <tmsriram@google.com>
+
+	Apply from master:
+	2018-02-22  Sriraman Tallam  <tmsriram@google.com>
+
+	* plugin.cc (get_wrap_symbols): New plugin interface.
+	(load): Add get_wrap_symbols to transfer vector.
+	* plugin-api.h (ld_plugin_get_wrap_symbols): New plugin interface.
+	* testsuite/plugin_test.c (onload): Call and check get_wrap_symbols
+	interface.
+	* testsuite/plugin_test_wrap_symbols.sh: New test script.
+	* testsuite/plugin_test_wrap_symbols_1.cc: New file.
+	* testsuite/plugin_test_wrap_symbols_2.cc: New file.
+	* testsuite/Makefile.am (plugin_test_wrap_symbols): New test.
+	* testsuite/Makefile.in: Regenerate.
+
+2018-04-27  Sriraman Tallam  <tmsriram@google.com>
+
 	Apply from master:
 	2018-02-07  Sriraman Tallam  <tmsriram@google.com>
 
diff --git a/gold/options.h b/gold/options.h
index c22004a..dcd5cc0 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -471,7 +471,11 @@
 									  \
   options::String_set::const_iterator					  \
   varname__##_end() const						  \
-  { return this->varname__##_.value.end(); }
+  { return this->varname__##_.value.end(); }                              \
+                                                                          \
+  options::String_set::size_type                                          \
+  varname__##_size() const                                                \
+  { return this->varname__##_.value.size(); }                             \
 
 // When you have a list of possible values (expressed as string)
 // After helparg__ should come an initializer list, like
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 0284162..3ebba62 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -167,6 +167,9 @@
 get_input_section_size(const struct ld_plugin_section section,
                        uint64_t* secsize);
 
+static enum ld_plugin_status
+get_wrap_symbols(uint64_t *num_symbols, const char ***wrap_symbol_list);
+
 };
 
 #endif // ENABLE_PLUGINS
@@ -211,7 +214,7 @@
   sscanf(ver, "%d.%d", &major, &minor);
 
   // Allocate and populate a transfer vector.
-  const int tv_fixed_size = 29;
+  const int tv_fixed_size = 30;
 
   int tv_size = this->args_.size() + tv_fixed_size;
   ld_plugin_tv* tv = new ld_plugin_tv[tv_size];
@@ -346,6 +349,10 @@
   tv[i].tv_u.tv_get_input_section_size = get_input_section_size;
 
   ++i;
+  tv[i].tv_tag = LDPT_GET_WRAP_SYMBOLS;
+  tv[i].tv_u.tv_get_wrap_symbols = get_wrap_symbols;
+
+  ++i;
   tv[i].tv_tag = LDPT_NULL;
   tv[i].tv_u.tv_val = 0;
 
@@ -1808,6 +1815,25 @@
   return LDPS_OK;
 }
 
+static enum ld_plugin_status
+get_wrap_symbols(uint64_t *count, const char ***wrap_symbols)
+{
+  gold_assert(parameters->options().has_plugins());
+  *count = parameters->options().wrap_size();
+
+  if (*count == 0)
+    return LDPS_OK;
+
+  *wrap_symbols = new const char *[*count];
+  int i = 0;
+  for (options::String_set::const_iterator
+       it = parameters->options().wrap_begin();
+       it != parameters->options().wrap_end(); ++it, ++i) {
+    (*wrap_symbols)[i] = it->c_str();
+  }
+  return LDPS_OK;
+}
+
 
 // Specify the ordering of sections in the final layout. The sections are
 // specified as (handle,shndx) pairs in the two arrays in the order in
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 9b7b6be..29609f3 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -2308,6 +2308,19 @@
 	$(TEST_AR) crT $@ $^
 
 
+check_PROGRAMS += plugin_test_wrap_symbols
+check_SCRIPTS += plugin_test_wrap_symbols.sh
+check_DATA += plugin_test_wrap_symbols.err
+MOSTLYCLEANFILES += plugin_test_wrap_symbols.err
+plugin_test_wrap_symbols_1.o: plugin_test_wrap_symbols_1.cc
+	$(COMPILE) -c -o $@ $<
+plugin_test_wrap_symbols_2.o: plugin_test_wrap_symbols_2.cc
+	$(COMPILE) -c -o $@ $<
+plugin_test_wrap_symbols: plugin_test_wrap_symbols_1.o plugin_test_wrap_symbols_2.o gcctestdir/ld plugin_test.so
+	$(CXXLINK) -Bgcctestdir/ -Wl,--plugin,"./plugin_test.so" -Wl,--wrap=hello,--wrap=jello plugin_test_wrap_symbols_1.o plugin_test_wrap_symbols_2.o 2>plugin_test_wrap_symbols.err
+plugin_test_wrap_symbols.err: plugin_test_wrap_symbols
+	@touch plugin_test_wrap_symbols.err
+
 check_PROGRAMS += plugin_test_start_lib
 check_SCRIPTS += plugin_test_start_lib.sh
 check_DATA += plugin_test_start_lib.err
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 5a82886..7a44d2e 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -522,6 +522,7 @@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_8 \
 @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_wrap_symbols \
 @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 =  \
@@ -533,6 +534,7 @@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_7.sh \
 @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_wrap_symbols.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_start_lib.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_defsym.sh
 
@@ -553,6 +555,7 @@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_9b.err \
 @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_wrap_symbols.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.
@@ -570,6 +573,7 @@
 @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_thin.a \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_wrap_symbols.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
@@ -1179,6 +1183,7 @@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_8$(EXEEXT) \
 @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_wrap_symbols$(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)
@@ -1914,6 +1919,13 @@
 	../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1)
+plugin_test_wrap_symbols_SOURCES = plugin_test_wrap_symbols.c
+plugin_test_wrap_symbols_OBJECTS = plugin_test_wrap_symbols.$(OBJEXT)
+plugin_test_wrap_symbols_LDADD = $(LDADD)
+plugin_test_wrap_symbols_DEPENDENCIES = libgoldtest.a ../libgold.a \
+	../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1)
 pr17704a_test_SOURCES = pr17704a_test.c
 pr17704a_test_OBJECTS = pr17704a_test.$(OBJEXT)
 pr17704a_test_LDADD = $(LDADD)
@@ -2437,13 +2449,13 @@
 	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_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) \
-	$(pr20308c_test_SOURCES) $(pr20308d_test_SOURCES) \
-	$(pr20308e_test_SOURCES) pr20976.c pr22266.c \
-	$(protected_1_SOURCES) $(protected_2_SOURCES) \
+	plugin_test_tls.c plugin_test_wrap_symbols.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) $(pr20308c_test_SOURCES) \
+	$(pr20308d_test_SOURCES) $(pr20308e_test_SOURCES) pr20976.c \
+	pr22266.c $(protected_1_SOURCES) $(protected_2_SOURCES) \
 	$(relro_now_test_SOURCES) $(relro_script_test_SOURCES) \
 	$(relro_strip_test_SOURCES) $(relro_test_SOURCES) \
 	$(script_test_1_SOURCES) script_test_11.c script_test_12.c \
@@ -4090,6 +4102,15 @@
 @TLS_FALSE@plugin_test_tls$(EXEEXT): $(plugin_test_tls_OBJECTS) $(plugin_test_tls_DEPENDENCIES) $(EXTRA_plugin_test_tls_DEPENDENCIES) 
 @TLS_FALSE@	@rm -f plugin_test_tls$(EXEEXT)
 @TLS_FALSE@	$(LINK) $(plugin_test_tls_OBJECTS) $(plugin_test_tls_LDADD) $(LIBS)
+@GCC_FALSE@plugin_test_wrap_symbols$(EXEEXT): $(plugin_test_wrap_symbols_OBJECTS) $(plugin_test_wrap_symbols_DEPENDENCIES) $(EXTRA_plugin_test_wrap_symbols_DEPENDENCIES) 
+@GCC_FALSE@	@rm -f plugin_test_wrap_symbols$(EXEEXT)
+@GCC_FALSE@	$(LINK) $(plugin_test_wrap_symbols_OBJECTS) $(plugin_test_wrap_symbols_LDADD) $(LIBS)
+@NATIVE_LINKER_FALSE@plugin_test_wrap_symbols$(EXEEXT): $(plugin_test_wrap_symbols_OBJECTS) $(plugin_test_wrap_symbols_DEPENDENCIES) $(EXTRA_plugin_test_wrap_symbols_DEPENDENCIES) 
+@NATIVE_LINKER_FALSE@	@rm -f plugin_test_wrap_symbols$(EXEEXT)
+@NATIVE_LINKER_FALSE@	$(LINK) $(plugin_test_wrap_symbols_OBJECTS) $(plugin_test_wrap_symbols_LDADD) $(LIBS)
+@PLUGINS_FALSE@plugin_test_wrap_symbols$(EXEEXT): $(plugin_test_wrap_symbols_OBJECTS) $(plugin_test_wrap_symbols_DEPENDENCIES) $(EXTRA_plugin_test_wrap_symbols_DEPENDENCIES) 
+@PLUGINS_FALSE@	@rm -f plugin_test_wrap_symbols$(EXEEXT)
+@PLUGINS_FALSE@	$(LINK) $(plugin_test_wrap_symbols_OBJECTS) $(plugin_test_wrap_symbols_LDADD) $(LIBS)
 @DEFAULT_TARGET_X86_64_FALSE@pr17704a_test$(EXEEXT): $(pr17704a_test_OBJECTS) $(pr17704a_test_DEPENDENCIES) $(EXTRA_pr17704a_test_DEPENDENCIES) 
 @DEFAULT_TARGET_X86_64_FALSE@	@rm -f pr17704a_test$(EXEEXT)
 @DEFAULT_TARGET_X86_64_FALSE@	$(LINK) $(pr17704a_test_OBJECTS) $(pr17704a_test_LDADD) $(LIBS)
@@ -4477,6 +4498,7 @@
 @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)/plugin_test_wrap_symbols.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr17704a_test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr20216a_test-pr20216_def.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr20216a_test-pr20216_main.Po@am__quote@
@@ -5241,6 +5263,8 @@
 	@p='plugin_test_10.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_11.sh.log: plugin_test_11.sh
 	@p='plugin_test_11.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+plugin_test_wrap_symbols.sh.log: plugin_test_wrap_symbols.sh
+	@p='plugin_test_wrap_symbols.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
@@ -5603,6 +5627,8 @@
 	@p='plugin_test_10$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_11.log: plugin_test_11$(EXEEXT)
 	@p='plugin_test_11$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+plugin_test_wrap_symbols.log: plugin_test_wrap_symbols$(EXEEXT)
+	@p='plugin_test_wrap_symbols$(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)
@@ -6951,6 +6977,14 @@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_thin.a: two_file_test_1.o two_file_test_1b.o two_file_test_2.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	rm -f $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(TEST_AR) crT $@ $^
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_wrap_symbols_1.o: plugin_test_wrap_symbols_1.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(COMPILE) -c -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_wrap_symbols_2.o: plugin_test_wrap_symbols_2.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(COMPILE) -c -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_wrap_symbols: plugin_test_wrap_symbols_1.o plugin_test_wrap_symbols_2.o gcctestdir/ld plugin_test.so
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(CXXLINK) -Bgcctestdir/ -Wl,--plugin,"./plugin_test.so" -Wl,--wrap=hello,--wrap=jello plugin_test_wrap_symbols_1.o plugin_test_wrap_symbols_2.o 2>plugin_test_wrap_symbols.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_wrap_symbols.err: plugin_test_wrap_symbols
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	@touch plugin_test_wrap_symbols.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_start_lib: unused.o plugin_start_lib_test.o plugin_start_lib_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_start_lib_test.o \
 @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
diff --git a/gold/testsuite/plugin_test.c b/gold/testsuite/plugin_test.c
index e8c8a5d..c6c9923 100644
--- a/gold/testsuite/plugin_test.c
+++ b/gold/testsuite/plugin_test.c
@@ -68,6 +68,7 @@
 static ld_plugin_get_input_section_contents get_input_section_contents = NULL;
 static ld_plugin_update_section_order update_section_order = NULL;
 static ld_plugin_allow_section_ordering allow_section_ordering = NULL;
+static ld_plugin_get_wrap_symbols get_wrap_symbols = NULL;
 
 #define MAXOPTS 10
 
@@ -158,6 +159,9 @@
 	case LDPT_ALLOW_SECTION_ORDERING:
 	  allow_section_ordering = *entry->tv_u.tv_allow_section_ordering;
 	  break;
+	case LDPT_GET_WRAP_SYMBOLS:
+	  get_wrap_symbols = *entry->tv_u.tv_get_wrap_symbols;
+	  break;
         default:
           break;
         }
@@ -247,6 +251,28 @@
       return LDPS_ERR;
     }
 
+  if (get_wrap_symbols == NULL)
+    {
+      fprintf(stderr, "tv_get_wrap_symbols interface missing\n");
+      return LDPS_ERR;
+    }
+  else
+    {
+      const char **wrap_symbols;
+      uint64_t count = 0;
+      if (get_wrap_symbols(&count, &wrap_symbols) == LDPS_OK)
+	{
+	  (*message)(LDPL_INFO, "Number of wrap symbols = %lu", count);
+	  for (; count > 0; --count)
+            (*message)(LDPL_INFO, "Wrap symbol %s", wrap_symbols[count - 1]);
+	}
+      else
+	{
+          fprintf(stderr, "tv_get_wrap_symbols interface call failed\n");
+          return LDPS_ERR;
+	}
+    }
+
   return LDPS_OK;
 }
 
diff --git a/gold/testsuite/plugin_test_wrap_symbols.sh b/gold/testsuite/plugin_test_wrap_symbols.sh
new file mode 100755
index 0000000..2133bf0
--- /dev/null
+++ b/gold/testsuite/plugin_test_wrap_symbols.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# plugin_test_wrap_symbols.sh -- a test case for the plugin API.
+
+# Copyright (C) 2017 onwards Free Software Foundation, Inc.
+# Written by Teresa Johnson <tejohnson@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 get_wrap_symbols plugin interface works 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_wrap_symbols.err "API version:"
+check plugin_test_wrap_symbols.err "gold version:"
+check plugin_test_wrap_symbols.err "Number of wrap symbols = 2"
+check plugin_test_wrap_symbols.err "Wrap symbol hello"
+check plugin_test_wrap_symbols.err "Wrap symbol jello"
+check plugin_test_wrap_symbols.err "cleanup hook called"
+
+exit 0
diff --git a/gold/testsuite/plugin_test_wrap_symbols_1.cc b/gold/testsuite/plugin_test_wrap_symbols_1.cc
new file mode 100644
index 0000000..90587ef
--- /dev/null
+++ b/gold/testsuite/plugin_test_wrap_symbols_1.cc
@@ -0,0 +1,40 @@
+/* plugin_test_wrap_symbols -- a test case for gold
+
+   Copyright (C) 2017 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.  */
+
+extern "C" {
+int __real_hello();
+int __wrap_hello()
+{
+  return __real_hello();
+}
+int hello();
+int __real_jello();
+int __wrap_jello()
+{
+  return __real_jello();
+}
+int jello();
+int main()
+{
+  return 0;
+}
+}
diff --git a/gold/testsuite/plugin_test_wrap_symbols_2.cc b/gold/testsuite/plugin_test_wrap_symbols_2.cc
new file mode 100644
index 0000000..902cc3c
--- /dev/null
+++ b/gold/testsuite/plugin_test_wrap_symbols_2.cc
@@ -0,0 +1,33 @@
+/* plugin_test_wrap_symbols -- a test case for gold
+
+   Copyright (C) 2017 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.  */
+
+extern "C" {
+int hello()
+{
+  return 0;
+}
+
+int jello()
+{
+  return 0;
+}
+}
diff --git a/include/plugin-api.h b/include/plugin-api.h
index 3a3e8b4..e14db1e 100644
--- a/include/plugin-api.h
+++ b/include/plugin-api.h
@@ -365,6 +365,11 @@
 (*ld_plugin_get_input_section_size) (const struct ld_plugin_section section,
                                      uint64_t *secsize);
 
+typedef
+enum ld_plugin_status
+(*ld_plugin_get_wrap_symbols) (uint64_t *num_symbols,
+                               const char ***wrap_symbol_list);
+
 enum ld_plugin_level
 {
   LDPL_INFO,
@@ -407,7 +412,8 @@
   LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27,
   LDPT_GET_SYMBOLS_V3 = 28,
   LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
-  LDPT_GET_INPUT_SECTION_SIZE = 30
+  LDPT_GET_INPUT_SECTION_SIZE = 30,
+  LDPT_GET_WRAP_SYMBOLS = 32
 };
 
 /* The plugin transfer vector.  */
@@ -441,6 +447,7 @@
     ld_plugin_unique_segment_for_sections tv_unique_segment_for_sections;
     ld_plugin_get_input_section_alignment tv_get_input_section_alignment;
     ld_plugin_get_input_section_size tv_get_input_section_size;
+    ld_plugin_get_wrap_symbols tv_get_wrap_symbols;
   } tv_u;
 };