[patch][rfc] Giving plugins access to gold's file views

Rafael Avila de Espindola respindola@mozilla.com
Tue Mar 22 14:57:00 GMT 2011


On 11-03-21 07:22 PM, Ian Lance Taylor wrote:
> Rafael Avila de Espindola<respindola@mozilla.com>  writes:
>
>> *) It is only possible to ask for views of the entire file. The reason
>> is that during LTO it is more efficient to merge files as we read
>> them, so I didn't see a lot of reason to add support to mapping only
>> parts of a file. In any case, I can add an offset and size argument if
>> you want.
>>
>> *) The call works when called from the claim_file hook or from the
>> all_symbols_read hook. I only tested the first one, but making it work
>> on both cases looked easy.
>>
>> *) The plugin has no guarantees of how long the view will be valid
>> for. It it wants to see the view in a subsequent callback, it has to
>> ask for it again.
>>
>> *) The "aligned" and "cache" arguments are not exposed. Since the
>> behaviour with aligned set to true is the copy in into anonymous
>> memory, the plugin can just read the file itself. The "cache" value is
>> always set to false. If the plugin claims the file, it will probably
>> use it all at once. If it doesn't and gold then asks for a cached
>> view, find_or_make_view correctly calls set_cache.
>>
>> If you are OK with this, I will finish it up (comments, interface
>> documentation and ChangeLog), split the bits that have to be committed
>> in gcc first and send an updated version for review.
>
> I'm OK with this approach.
>
> We already expose the file descriptor in the plugin interface, so this
> is just for efficiency, right?

Correct. Running strace on a link I noticed many consecutive calls to 
mmap on the same fd, one from gold, one from the plugin.

>> +  if (this->objects_.size() == handle) {
>> +    // We are being called from the claim_file hook.
>> +    const struct ld_plugin_input_file&f = this->plugin_input_file_;
>> +    offset = f.offset;
>> +    filesize = f.filesize;
>> +    input_file = this->input_file_;
>> +  } else {
>> +    // An already claimed file.
>> +    Pluginobj* obj = this->object(handle);
>> +    if (obj == NULL)
>> +      return LDPS_BAD_HANDLE;
>> +    offset = obj->offset();
>> +    filesize = obj->filesize();
>> +    input_file = obj->input_file();
>> +  }
>
> Braces need to be GNU style.

Fixed. The two patches are attached.

2010-03-22  Rafael Ávila de Espíndola <respindola@mozilla.com>

	* plugin-api.h (ld_plugin_get_view): New.
	(ld_plugin_tag): Add LDPT_GET_VIEW.
	(ld_plugin_tv): Add tv_get_view.

2010-03-22  Rafael Ávila de Espíndola <respindola@mozilla.com>

	* plugin.cc (get_view): New.
	(Plugin::load): Pass get_view to the plugin.
	(Plugin_manager::get_view): New.

> Ian

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: include.patch
Type: text/x-patch
Size: 1085 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20110322/42d82668/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gold.patch
Type: text/x-patch
Size: 2969 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20110322/42d82668/attachment-0001.bin>


More information about the Binutils mailing list