Re: [PATCH] Add linker plugin API for processing plugin-added input files

2017-09-21 Thread Sriraman Tallam via gcc-patches
On Thu, Sep 21, 2017 at 5:29 PM, Cary Coutant  wrote:
>> 2017-09-21  Stephen Crane 
>>
>> * plugin-api.h: Add new hook to the plugin transfer vector to
>> support assigning plugin-generated sections to unique output
>> segments.
>> (ld_plugin_register_new_input): New hook.
>> (ld_plugin_tag): Add LDPT_REGISTER_NEW_INPUT_HOOK.
>> (ld_plugin_tv): Add tv_register_new_input.
>
> This addition to the plugin API makes sense to me, but I'd appreciate
> Sri's input.

The API looks good to me.  Could you please add a test to the gold
patch to show how you would use the new API.

Thanks
Sri

>
> -cary


Re: [PATCH] Add linker plugin API for processing plugin-added input files

2017-09-21 Thread Cary Coutant
> 2017-09-21  Stephen Crane 
>
> * plugin-api.h: Add new hook to the plugin transfer vector to
> support assigning plugin-generated sections to unique output
> segments.
> (ld_plugin_register_new_input): New hook.
> (ld_plugin_tag): Add LDPT_REGISTER_NEW_INPUT_HOOK.
> (ld_plugin_tv): Add tv_register_new_input.

This addition to the plugin API makes sense to me, but I'd appreciate
Sri's input.

-cary


[PATCH] Add linker plugin API for processing plugin-added input files

2017-09-21 Thread Stephen Crane
I'm looking to extend the linker plugin API to allow linker plugins the
chance to assign sections to segments for sections in plugin-generated
files. Currently the linker does not give the plugin the opportunity to
call the unique_segment_for_sections interface for files generated by a
plugin, since the plugin does not have access to an input handle for
such files. This new interface adds a plugin callback the linker will
call while processing newly added input files, giving the plugin a
handle to refer to that file. 

This change would be concurrent with a corresponding change to gold. See
the following email thread on the binutils mailing list for more details
on the implementation of this API change:
https://sourceware.org/ml/binutils/2017-08/msg00279.html.


include/Changelog:

2017-09-21  Stephen Crane 

* plugin-api.h: Add new hook to the plugin transfer vector to
support assigning plugin-generated sections to unique output
segments.
(ld_plugin_register_new_input): New hook.
(ld_plugin_tag): Add LDPT_REGISTER_NEW_INPUT_HOOK.
(ld_plugin_tv): Add tv_register_new_input.


I would greatly appreciate any feedback on this proposed change.
Thanks,
Stephen

commit f45d97f0ee4c202602c9951ade622caf2e27ffe2
Author: Stephen Crane 
Date:   Thu Sep 21 14:22:37 2017 -0700

Add plugin API for processing plugin-added input files

Gold plugins may wish to further process an input file added by a plugin. For
example, the plugin may need to assign a unique segment for sections in a
plugin-generated input file. This patch adds a plugin callback that the linker
will call when reading symbols from a new input file added after the
all_symbols_read event (i.e. an input file added by a plugin).

diff --git a/include/plugin-api.h b/include/plugin-api.h
index 3a3e8b456db..f081f85dfaf 100644
--- a/include/plugin-api.h
+++ b/include/plugin-api.h
@@ -365,6 +365,20 @@ enum ld_plugin_status
 (*ld_plugin_get_input_section_size) (const struct ld_plugin_section section,
  uint64_t *secsize);
 
+typedef
+enum ld_plugin_status
+(*ld_plugin_new_input_handler) (const struct ld_plugin_input_file *file);
+
+/* The linker's interface for registering the "new_input" handler. This handler
+   will be notified when a new input file has been added after the
+   all_symbols_read event, allowing the plugin to, for example, set a unique
+   segment for sections in plugin-generated input files. */
+
+typedef
+enum ld_plugin_status
+(*ld_plugin_register_new_input) (ld_plugin_new_input_handler handler);
+
+
 enum ld_plugin_level
 {
   LDPL_INFO,
@@ -407,7 +421,8 @@ enum ld_plugin_tag
   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_REGISTER_NEW_INPUT_HOOK = 31
 };
 
 /* The plugin transfer vector.  */
@@ -441,6 +456,7 @@ struct ld_plugin_tv
 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_register_new_input tv_register_new_input;
   } tv_u;
 };