New plugin interface to get list of symbols wrapped with --wrap option.
authorSriraman Tallam <tmsriram@google.com>
Thu, 22 Feb 2018 21:56:46 +0000 (13:56 -0800)
committerSriraman Tallam <tmsriram@google.com>
Thu, 22 Feb 2018 21:56:46 +0000 (13:56 -0800)
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.

gold/ChangeLog
gold/options.h
gold/plugin.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/plugin_test.c
gold/testsuite/plugin_test_wrap_symbols.sh [new file with mode: 0755]
gold/testsuite/plugin_test_wrap_symbols_1.cc [new file with mode: 0644]
gold/testsuite/plugin_test_wrap_symbols_2.cc [new file with mode: 0644]
include/plugin-api.h

index 032d74bb36ea0444df2e65051c889f4430ea7ae1..64d6cba7cbdd4695f4b78d8ece4a17dac9aca997 100644 (file)
@@ -1,3 +1,16 @@
+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-02-07  Sriraman Tallam  <tmsriram@google.com>
 
        * expression.cc (Symbol_expression::set_expr_sym_in_real_elf):
index b39d5ff7bacc068513c09c19b3b573166b74e356..152b0c16bb3b507cfbbbf88f45b31e79bb3b0aad 100644 (file)
@@ -471,7 +471,11 @@ struct Struct_special : public Struct_var
                                                                          \
   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
index 566f1b7caef0fb6f17dab749fe9e4b69bee5e85d..442eda06621e0ed855510dc0c0098a9392d3ce7c 100644 (file)
@@ -170,6 +170,9 @@ get_input_section_size(const struct ld_plugin_section section,
 static enum ld_plugin_status
 register_new_input(ld_plugin_new_input_handler handler);
 
+static enum ld_plugin_status
+get_wrap_symbols(uint64_t *num_symbols, const char ***wrap_symbol_list);
+
 };
 
 #endif // ENABLE_PLUGINS
@@ -214,7 +217,7 @@ Plugin::load()
   sscanf(ver, "%d.%d", &major, &minor);
 
   // Allocate and populate a transfer vector.
-  const int tv_fixed_size = 30;
+  const int tv_fixed_size = 31;
 
   int tv_size = this->args_.size() + tv_fixed_size;
   ld_plugin_tv* tv = new ld_plugin_tv[tv_size];
@@ -352,6 +355,10 @@ Plugin::load()
   tv[i].tv_tag = LDPT_REGISTER_NEW_INPUT_HOOK;
   tv[i].tv_u.tv_register_new_input = register_new_input;
 
+  ++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;
@@ -1833,6 +1840,25 @@ get_input_section_size(const struct ld_plugin_section section,
   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
index 7ec3e8d88f8361237fcc0e09f2f30baeb43d857d..bb486edf191cf3c7d1aab895b15ba2f5b23a18c7 100644 (file)
@@ -2322,6 +2322,19 @@ plugin_test_12: export_dynamic_plugin.o gcctestdir/ld plugin_test.so export_dyna
 plugin_test_12.err: plugin_test_12
        @touch plugin_test_12.err
 
+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
index ca79238f3b9f274eac87843357669cf0b1ed42bb..ec851d56c49f2fec2e21efe100afd83525327f31 100644 (file)
@@ -535,6 +535,7 @@ 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_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 =  \
@@ -547,6 +548,7 @@ 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_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
 
@@ -568,6 +570,7 @@ 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_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.
@@ -586,6 +589,7 @@ 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_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
@@ -1215,6 +1219,7 @@ 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_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)
@@ -1958,6 +1963,13 @@ plugin_test_tls_DEPENDENCIES = libgoldtest.a ../libgold.a \
        ../../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)
@@ -2488,13 +2500,13 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.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_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 \
@@ -4150,6 +4162,15 @@ pie_copyrelocs_test$(EXEEXT): $(pie_copyrelocs_test_OBJECTS) $(pie_copyrelocs_te
 @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)
@@ -4544,6 +4565,7 @@ distclean-compile:
 @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@
@@ -5313,6 +5335,8 @@ 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_12.sh.log: plugin_test_12.sh
        @p='plugin_test_12.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
@@ -5683,6 +5707,8 @@ plugin_test_11.log: plugin_test_11$(EXEEXT)
        @p='plugin_test_11$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_12.log: plugin_test_12$(EXEEXT)
        @p='plugin_test_12$(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)
@@ -7031,6 +7057,14 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z3foov" -Wl,--export-dynamic-symbol,"_Z3foov" export_dynamic_plugin.o.syms 2>plugin_test_12.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_12.err: plugin_test_12
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   @touch plugin_test_12.err
+@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
index c6df7b6f7dfba0e5f3e4e6079c16b3002b389497..e80f92626f07bcb0f0418ccddeacb04ace0169ef 100644 (file)
@@ -68,6 +68,7 @@ static ld_plugin_get_input_section_name get_input_section_name = NULL;
 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 @@ onload(struct ld_plugin_tv *tv)
        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 @@ onload(struct ld_plugin_tv *tv)
       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 (executable)
index 0000000..2133bf0
--- /dev/null
@@ -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 (file)
index 0000000..90587ef
--- /dev/null
@@ -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 (file)
index 0000000..902cc3c
--- /dev/null
@@ -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;
+}
+}
index 03e21f4a0c445e881918a71c07b538e3a3fa1bd2..24cd695bf5c02351644e54699eede65cf1781363 100644 (file)
@@ -378,6 +378,14 @@ typedef
 enum ld_plugin_status
 (*ld_plugin_register_new_input) (ld_plugin_new_input_handler handler);
 
+/* The linker's interface for getting the list of wrapped symbols using the
+   --wrap option. This sets *NUM_SYMBOLS to number of wrapped symbols and
+   *WRAP_SYMBOL_LIST to the list of wrapped symbols. */
+
+typedef
+enum ld_plugin_status
+(*ld_plugin_get_wrap_symbols) (uint64_t *num_symbols,
+                               const char ***wrap_symbol_list);
 
 enum ld_plugin_level
 {
@@ -422,7 +430,8 @@ enum ld_plugin_tag
   LDPT_GET_SYMBOLS_V3 = 28,
   LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
   LDPT_GET_INPUT_SECTION_SIZE = 30,
-  LDPT_REGISTER_NEW_INPUT_HOOK = 31
+  LDPT_REGISTER_NEW_INPUT_HOOK = 31,
+  LDPT_GET_WRAP_SYMBOLS = 32
 };
 
 /* The plugin transfer vector.  */
@@ -457,6 +466,7 @@ struct ld_plugin_tv
     ld_plugin_get_input_section_alignment tv_get_input_section_alignment;
     ld_plugin_get_input_section_size tv_get_input_section_size;
     ld_plugin_register_new_input tv_register_new_input;
+    ld_plugin_get_wrap_symbols tv_get_wrap_symbols;
   } tv_u;
 };