From 95ecdfbfcbf508919652a0254ee2b8c6572a949e Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Thu, 3 Mar 2016 11:36:36 -0800 Subject: get_symbols() plugin API tweak to support --start-lib/--end-lib. Let the plugin know that a file is not being included in the link by returning LDPS_NO_SYMS from get_symbols(). include/ * plugin-api.h (enum ld_plugin_tag): Add LDPT_GET_SYMBOLS_V3. gold/ * 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. --- gold/plugin.cc | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'gold/plugin.cc') diff --git a/gold/plugin.cc b/gold/plugin.cc index c01e4cd..4aeb3ea 100644 --- a/gold/plugin.cc +++ b/gold/plugin.cc @@ -112,6 +112,9 @@ 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); static enum ld_plugin_status @@ -199,7 +202,7 @@ Plugin::load() 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]; @@ -277,6 +280,10 @@ Plugin::load() 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; @@ -937,7 +944,7 @@ Pluginobj::get_symbol_resolution_info(Symbol_table* symtab, 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++) @@ -1545,6 +1552,26 @@ get_symbols_v2(const void* handle, int nsyms, ld_plugin_symbol* syms) 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(reinterpret_cast(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 -- cgit v1.1