+2015-03-03 Evgenii Stepanov <eugenis@google.com>
+
+ * plugin.h (Pluginobj::get_symbol_resolution_info): Add version
+ parameter.
+ * plugin.cc (get_symbols_v3): New function.
+ (Plugin::load): Add LDPT_GET_SYMBOLS_V3.
+ (Pluginobj::get_symbol_resolution_info): Return LDPS_NO_SYMS when using
+ new version.
+
2016-02-26 Egor Kochetov <egor.kochetov@intel.com>
Cary Coutant <ccoutant@gmail.com>
static enum ld_plugin_status
get_symbols_v2(const void *handle, int nsyms, struct ld_plugin_symbol *syms);
+static enum ld_plugin_status
+get_symbols_v3(const void *handle, int nsyms, struct ld_plugin_symbol *syms);
+
static enum ld_plugin_status
add_input_file(const char *pathname);
sscanf(ver, "%d.%d", &major, &minor);
// Allocate and populate a transfer vector.
- const int tv_fixed_size = 26;
+ const int tv_fixed_size = 27;
int tv_size = this->args_.size() + tv_fixed_size;
ld_plugin_tv* tv = new ld_plugin_tv[tv_size];
tv[i].tv_tag = LDPT_GET_SYMBOLS_V2;
tv[i].tv_u.tv_get_symbols = get_symbols_v2;
+ ++i;
+ tv[i].tv_tag = LDPT_GET_SYMBOLS_V3;
+ tv[i].tv_u.tv_get_symbols = get_symbols_v3;
+
++i;
tv[i].tv_tag = LDPT_ADD_INPUT_FILE;
tv[i].tv_u.tv_add_input_file = add_input_file;
gold_assert(this->symbols_.size() == 0);
for (int i = 0; i < nsyms; i++)
syms[i].resolution = LDPR_PREEMPTED_REG;
- return LDPS_OK;
+ return version > 2 ? LDPS_NO_SYMS : LDPS_OK;
}
for (int i = 0; i < nsyms; i++)
return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 2);
}
+// Version 3 of the above. The only difference from v2 is that it
+// returns LDPS_NO_SYMS instead of LDPS_OK for the objects we never
+// decided to include.
+
+static enum ld_plugin_status
+get_symbols_v3(const void* handle, int nsyms, ld_plugin_symbol* syms)
+{
+ gold_assert(parameters->options().has_plugins());
+ Plugin_manager* plugins = parameters->options().plugins();
+ Object* obj = plugins->object(
+ static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
+ if (obj == NULL)
+ return LDPS_ERR;
+ Pluginobj* plugin_obj = obj->pluginobj();
+ if (plugin_obj == NULL)
+ return LDPS_ERR;
+ Symbol_table* symtab = plugins->symtab();
+ return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 3);
+}
+
// Add a new (real) input file generated by a plugin.
static enum ld_plugin_status
rm -f $@
$(TEST_AR) crT $@ $^
+
+check_PROGRAMS += plugin_test_start_lib
+check_SCRIPTS += plugin_test_start_lib.sh
+check_DATA += plugin_test_start_lib.err
+MOSTLYCLEANFILES += plugin_test_start_lib.err
+plugin_test_start_lib: unused.o plugin_start_lib_test.o plugin_start_lib_test_2.syms gcctestdir/ld plugin_test.so
+ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so" plugin_start_lib_test.o \
+ -Wl,--start-lib plugin_start_lib_test_2.syms -Wl,--end-lib 2>plugin_test_start_lib.err
+plugin_test_start_lib.err: plugin_test_start_lib
+ @touch plugin_test_start_lib.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
$(LINK) -Bgcctestdir/ -shared plugin_test.o
plugin_test.o: plugin_test.c
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_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_11 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_38 = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_6.sh \
@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_11.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib.sh
# Test that symbols known in the IR file but not in the replacement file
# produce an unresolved symbol error.
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.o.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_9.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_11.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib.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_40 = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.err \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ two_file_test_1c.o \
@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_thin.a \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib.err
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_41 = plugin_test_tls
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_42 = plugin_test_tls.sh
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_43 = plugin_test_tls.err
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7$(EXEEXT) \
@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_11$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__EXEEXT_22 = plugin_test_tls$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_23 = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exclude_libs_test$(EXEEXT) \
../../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)
+plugin_test_start_lib_DEPENDENCIES = libgoldtest.a ../libgold.a \
+ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1)
plugin_test_tls_SOURCES = plugin_test_tls.c
plugin_test_tls_OBJECTS = plugin_test_tls.$(OBJEXT)
plugin_test_tls_LDADD = $(LDADD)
plugin_test_10.c plugin_test_11.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_tls.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 script_test_12i.c \
- $(script_test_2_SOURCES) script_test_3.c \
+ plugin_test_start_lib.c plugin_test_tls.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 \
+ script_test_12i.c $(script_test_2_SOURCES) script_test_3.c \
$(searched_file_test_SOURCES) start_lib_test.c \
$(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \
$(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \
@PLUGINS_FALSE@plugin_test_8$(EXEEXT): $(plugin_test_8_OBJECTS) $(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_start_lib$(EXEEXT): $(plugin_test_start_lib_OBJECTS) $(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)
+@NATIVE_LINKER_FALSE@plugin_test_start_lib$(EXEEXT): $(plugin_test_start_lib_OBJECTS) $(plugin_test_start_lib_DEPENDENCIES)
+@NATIVE_LINKER_FALSE@ @rm -f plugin_test_start_lib$(EXEEXT)
+@NATIVE_LINKER_FALSE@ $(LINK) $(plugin_test_start_lib_OBJECTS) $(plugin_test_start_lib_LDADD) $(LIBS)
+@PLUGINS_FALSE@plugin_test_start_lib$(EXEEXT): $(plugin_test_start_lib_OBJECTS) $(plugin_test_start_lib_DEPENDENCIES)
+@PLUGINS_FALSE@ @rm -f plugin_test_start_lib$(EXEEXT)
+@PLUGINS_FALSE@ $(LINK) $(plugin_test_start_lib_OBJECTS) $(plugin_test_start_lib_LDADD) $(LIBS)
@GCC_FALSE@plugin_test_tls$(EXEEXT): $(plugin_test_tls_OBJECTS) $(plugin_test_tls_DEPENDENCIES)
@GCC_FALSE@ @rm -f plugin_test_tls$(EXEEXT)
@GCC_FALSE@ $(LINK) $(plugin_test_tls_OBJECTS) $(plugin_test_tls_LDADD) $(LIBS)
@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_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)/protected_3.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_1.Po@am__quote@
@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_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_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
@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_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_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)
@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_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
+@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_start_lib_test_2.syms: plugin_start_lib_test_2.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_READELF) -sW $< >$@ 2>/dev/null
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test.so: plugin_test.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(LINK) -Bgcctestdir/ -shared plugin_test.o
--- /dev/null
+int main(void) {
+ return 0;
+}
--- /dev/null
+void foo(void);
+void foo(void) {}
static ld_plugin_add_symbols add_symbols = NULL;
static ld_plugin_get_symbols get_symbols = NULL;
static ld_plugin_get_symbols get_symbols_v2 = NULL;
+static ld_plugin_get_symbols get_symbols_v3 = NULL;
static ld_plugin_add_input_file add_input_file = NULL;
static ld_plugin_message message = NULL;
static ld_plugin_get_input_file get_input_file = NULL;
case LDPT_GET_SYMBOLS_V2:
get_symbols_v2 = entry->tv_u.tv_get_symbols;
break;
+ case LDPT_GET_SYMBOLS_V3:
+ get_symbols_v3 = entry->tv_u.tv_get_symbols;
+ break;
case LDPT_ADD_INPUT_FILE:
add_input_file = entry->tv_u.tv_add_input_file;
break;
(*message)(LDPL_INFO, "all symbols read hook called");
- if (get_symbols_v2 == NULL)
+ if (get_symbols_v3 == NULL)
{
- fprintf(stderr, "tv_get_symbols (v2) interface missing\n");
+ fprintf(stderr, "tv_get_symbols (v3) interface missing\n");
return LDPS_ERR;
}
claimed_file != NULL;
claimed_file = claimed_file->next)
{
- (*get_symbols_v2)(claimed_file->handle, claimed_file->nsyms,
- claimed_file->syms);
+ enum ld_plugin_status status = (*get_symbols_v3)(
+ claimed_file->handle, claimed_file->nsyms, claimed_file->syms);
+ if (status == LDPS_NO_SYMS)
+ {
+ (*message)(LDPL_INFO, "%s: no symbols", claimed_file->name);
+ continue;
+ }
for (i = 0; i < claimed_file->nsyms; ++i)
{
--- /dev/null
+#!/bin/sh
+
+# plugin_test_start_lib.sh -- a test case for the plugin API.
+
+# Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software
+# Foundation, Inc.
+# Written by Evgenii Stepanov <eugenis@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_1.c, a simple plug-in library that
+# exercises the basic interfaces and prints out version numbers and
+# options passed to the plugin.
+
+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_start_lib.err "API version:"
+check plugin_test_start_lib.err "gold version:"
+check plugin_test_start_lib.err "plugin_start_lib_test.o: claim file hook called"
+check plugin_test_start_lib.err "plugin_start_lib_test_2.syms: claim file hook called"
+check plugin_test_start_lib.err "plugin_start_lib_test_2.syms: claiming file, adding 1 symbols"
+check plugin_test_start_lib.err "all symbols read hook called"
+check plugin_test_start_lib.err "plugin_start_lib_test_2.syms: no symbols"
+check plugin_test_start_lib.err "cleanup hook called"
+
+exit 0
+2015-03-03 Evgenii Stepanov <eugenis@google.com>
+
+ * plugin-api.h (enum ld_plugin_tag): Add LDPT_GET_SYMBOLS_V3.
+
2016-02-26 H.J. Lu <hongjiu.lu@intel.com>
PR ld/19645
LDPT_ALLOW_SECTION_ORDERING = 24,
LDPT_GET_SYMBOLS_V2 = 25,
LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS = 26,
- LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27
+ LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27,
+ LDPT_GET_SYMBOLS_V3 = 28
};
/* The plugin transfer vector. */