[patch] Add plugin support for bfd

Rafael Espíndola rafael.espindola@gmail.com
Tue Apr 28 16:40:00 GMT 2009


This is an updated patch that adds plugin support to bfd. I posted a
previous version a long time ago, sorry for the delay.

The main reason to include plugin support is for doing (almost)
transparent link time optimization with llvm. With this patch it is
possible to do

$ llvm-gcc -c -emit-llvm a.c
$ llvm-gcc -c -emit-llvm b.c
$ nm b.o
00000000 T f
$ ar q b.a b.o
$ nm b.a
b.o:
00000000 T f
$ llvm-gcc -use-gold-plugin -O2 a.o b.a -o t
$ gdb t
...
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000000400330 <main+0>:    mov    $0x2a,%eax
0x0000000000400335 <main+5>:    retq

Note that nm and ar understand the llvm  bitcode format and that the
function f was extracted from the archive b.a and inlined into main.

The plugin support is implemented with a plugin target that implements
a small set of callbacks. I have tested only nm and ar. It is disable
by default. To enable configure with --enable-plugins (the same option
used by gold).

bfd/
2009-04-28  Rafael Avila de Espindola  <espindola@google.com>

        * Makefile.am (AM_CFLAGS): Add $(LFS_CFLAGS) -DBINDIR='"$(bindir)"'.
	(BFD32_BACKENDS): Add plugin.lo.
	(BFD32_BACKENDS_CFILES): Add plugin.c
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* bfd.c (struct bfd): Add plugin_data to tdata.
	(plugin_name): New.
	(bfd_plugin_set_plugin): New.
	(bfd_plugin_get_plugin): New.
	* config.bfd: Handle the plugin target.
	* configure: Regenerate.
	* configure.in: Check for --enable-plugins.
	* doc/Makefile.in: Regenerate.
	* plugin.c: New.
	* plugin.h: New.
	* targets.c (plugin_vec): New.
	(_bfd_target_vector): Add plugin_vec.

binutils/
2009-04-28  Rafael Avila de Espindola  <espindola@google.com>

	* Makefile.am (LIBDL): New.
	(LDADD): Add LIBDL.
	(objdump_LDADD): Add LIBDL.
	(ar_LDADD): Add LIBDL.
	(ranlib_LDADD): Add LIBDL.
	* Makefile.in: Regenerate.
	* ar.c (main): Handle the --plugin option.
	* configure: Regenerate.
	* configure.in: Check for --enable-plugins.
	* doc/Makefile.in: Regenerate.
	* nm.c (OPTION_PLUGIN): New.
	(long_options): Add plugin.
	(main): Handle OPTION_PLUGIN.

gas/
2009-04-28  Rafael Avila de Espindola  <espindola@google.com>

	* Makefile.am (LIBDL): New.
	(as_new_LDADD): Add LIBDL.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.in: Check for --enable-plugins.
	* doc/Makefile.in: Regenerate.

gprof/
2009-04-28  Rafael Avila de Espindola  <espindola@google.com>

	* Makefile.am (LIBDL):New.
	(gprof_LDADD): Add LIBDL.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.in: Check for --enable-plugins.

ld/
2009-04-28  Rafael Avila de Espindola  <espindola@google.com>

	* Makefile.am (LIBDL): New.
	(ld_new_LDADD): New.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.in: Check for --enable-plugins.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bfd-plugin.patch
Type: text/x-diff
Size: 80402 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20090428/e71affc8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.c
Type: text/x-csrc
Size: 47 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20090428/e71affc8/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: b.c
Type: text/x-csrc
Size: 29 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20090428/e71affc8/attachment-0002.bin>


More information about the Binutils mailing list