Bug 17422 - binutils should support more than one plugin in lib/bfd-plugins and load the right one
Summary: binutils should support more than one plugin in lib/bfd-plugins and load the ...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Markus Trippelsdorf
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-22 10:08 UTC by Markus Trippelsdorf
Modified: 2014-09-24 10:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
more than one plugin patch (1012 bytes, patch)
2014-09-22 17:33 UTC, Markus Trippelsdorf
Details | Diff
handle more than one plugin patch (1.03 KB, patch)
2014-09-22 19:21 UTC, Markus Trippelsdorf
Details | Diff
handle more than one plugin patch (1.03 KB, patch)
2014-09-22 20:41 UTC, Markus Trippelsdorf
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2014-09-22 10:08:54 UTC
Currently binutils automatically loads the plugin it finds in:
/usr/x86_64-pc-linux-gnu/binutils-bin/lib/bfd-plugins .

When the user places more than one plugin in that directory
only the one that comes first alphabetically gets loaded:

LLVMgold.so
liblto_plugin.so.0.0.0

In this case the LLVMgold plugin always gets loaded.

It would be better if binutils would pick the appropriate plugin
automatically based on the content it encounters.

 - Normal ELF files with special lto sections in the case of gcc.
 - LLVM bitcode in the other case: http://llvm.org/docs/BitCodeFormat.html
Comment 1 Markus Trippelsdorf 2014-09-22 15:23:53 UTC
I have it working locally by moving the logic in bfd_plugin_object_p
from bfd/plugin.c up to try_load_plugin.
Comment 2 Markus Trippelsdorf 2014-09-22 17:33:36 UTC
Created attachment 7802 [details]
more than one plugin patch

Here's the patch that I'm currently testing.
Comment 3 Markus Trippelsdorf 2014-09-22 19:21:08 UTC
Created attachment 7803 [details]
handle more than one plugin patch

New version, that passes the test suite. 
(Former version didn't handle mixed lto/vanilla archives).
Comment 4 hubicka 2014-09-22 19:52:14 UTC
Actually I think gold&ld could be updated to load multiple plugins at once
and let different plugins to claim different object files. That way we ought
to be able to link program that contains LTO objects from multiple compilers
(such as GCC and LLVM or different versions of same copmiler).
Even code quality should not be that bad given that resolution info will
give quite precise idea about the interfaces from each of LTO blobs.

Honza
Comment 5 Markus Trippelsdorf 2014-09-22 20:12:58 UTC
(In reply to hubicka from comment #4)
> Actually I think gold&ld could be updated to load multiple plugins at once
> and let different plugins to claim different object files. That way we ought
> to be able to link program that contains LTO objects from multiple compilers
> (such as GCC and LLVM or different versions of same copmiler).
> Even code quality should not be that bad given that resolution info will
> give quite precise idea about the interfaces from each of LTO blobs.

Yes. That would be nice indeed. 
But in the meantime having not to worry anymore about the ar/nm/ranlib
issue is a first step. (I currently switch between plugins by hand). 
Mixed LLVM/gcc archives are of course not supported yet.
Comment 6 Markus Trippelsdorf 2014-09-22 20:41:12 UTC
Created attachment 7804 [details]
handle more than one plugin patch

> Mixed LLVM/gcc archives are of course not supported yet.

Actually mixed LLVM/gcc archives are quite easy to support.
Patch updated.
Comment 7 Markus Trippelsdorf 2014-09-23 07:07:40 UTC
Patch posted: https://sourceware.org/ml/binutils/2014-09/msg00191.html
Comment 8 cvs-commit@gcc.gnu.org 2014-09-24 09:35:32 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  e44f5bef12a54b9c1cc24a5783dedde6f158ad15 (commit)
      from  71b9b91bce45aa220e0b48e7c2f70021c86e8594 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e44f5bef12a54b9c1cc24a5783dedde6f158ad15

commit e44f5bef12a54b9c1cc24a5783dedde6f158ad15
Author: Markus Trippelsdorf <markus@trippelsdorf.de>
Date:   Wed Sep 24 18:04:53 2014 +0930

    BFD: Add support for more than one plugin in lib/bfd-plugins
    
    ar, nm and ranlib currently lack the ability to handle more than one
    plugin in lib/bfd-plugins. This patch reshuffles the logic in plugin.c
    to add this functionality. One can now place both llvm and gcc plugins
    in this directory and have them loaded automatically.
    Mixed gcc/llvm archives are also supported (but not very useful until
    ld.bfd and ld.gold also would load multiple plugins and use them to
    claim different object files).
    
    	PR 17422
    	* plugin.c (try_claim): New function. Moved from
    	bfd_plugin_object_p.
    	(try_load_plugin): Pass through bfd. Add test.
    	(load_plugin): Pass through bfd.
    	(bfd_plugin_object_p): Move logic to try_claim.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog |    9 +++++
 bfd/plugin.c  |  106 +++++++++++++++++++++++++++++----------------------------
 2 files changed, 63 insertions(+), 52 deletions(-)
Comment 9 Markus Trippelsdorf 2014-09-24 10:41:36 UTC
Fixed.