By Jonathan Corbet
October 2, 2008
Almost one year ago, LWN
examined
the GCC plugin mechanism - or, more exactly, the lack of such a
mechanism. Despite the increasing level of interest in adding
special-purpose modules to the GCC compiler, GCC has no API which allows
this addition to be done. So developers working on GCC extensions are
faced with the daunting prospect of patching their code directly into the
compiler. This situation looked unlikely to change; the Free Software
Foundation's fears that a plugin mechanism would be used by proprietary
extensions was just too strong. One year later, though, things look a
little different; there may be a plugin-capable GCC available in the
(relatively) near future.
There are a lot of good reasons for wanting to add plugins to the GCC
compiler. The implementation of better optimization techniques is an
obvious example, but there is more than that. The EDoc++ project has put together a
static analysis tool which performs checking of exception handling in C++
code - and generates documentation while it's at it. Mozilla uses its Dehydra tool to find
potential problems in the browser's code base. The LLVM compiler can be thought of as a sort of
GCC plugin, currently. The Middle End Lisp
Translator project is working on a Lisp-like language which, in turn,
can be used within plugins for static analysis and code transformations.
The list goes on; just about any project working on
the processing of programs can benefit from hooking into the GCC platform.
The concern that has long been expressed by the FSF (which owns the
copyrights on GCC) is that a general plugin mechanism would make it
possible for companies to traffic in binary-only GCC modules. Rather than
contribute a new analysis or optimization tool - or a new language - to the
community, companies might have an incentive to distribute their work
separately under a restrictive license. That runs very much counter to
what the FSF is trying to accomplish, so opposition from that direction is
not particularly surprising.
But the pressure for some sort of plugin API is not going away, so the GCC
developers have been thinking about ways to make it possible without
upsetting Richard Stallman. One alternative which has been discussed is to
require plugins to be written in a high-level scripting language - Python
or Perl, perhaps. Then plugins would, for all practical purposes, have to
be distributed in source form. Even if they carried a hostile license, it
would be possible to study them and learn how they actually work.
Another possibility is to take a page from the Linux kernel's book and keep
the plugin API unstable. If the API changed with every GCC release, GCC
would become a moving target which would be much harder for proprietary
vendors to keep up with. An unstable API may be the way things go in any
case - there may be no other way to allow GCC itself to continue to
progress quickly - but experience with the kernel shows that an unstable
API is not, by itself, enough to scare off a determined proprietary
software vendor. It might reduce the number of proprietary GCC modules,
but it would not eliminate them.
Alternatively, one could require plugin modules to declare their license to
the GCC core, which could then reject plugins that lack a suitable
license. Again, experience with the kernel suggests that there are limits
to how far one can get with this approach. Proprietary plugin vendors
could distribute a version of GCC with the license check patched out - or
just have their plugin lie about its license.
Yet another possibility is to not worry about the problem at all; it is not
clear that the world is full of vendors waiting for an opportunity to abuse
a GCC plugin API. As GCC developer Ian Lance Taylor puts it:
The FSF doesn't want plugins because they are concerned that people
will start distributing proprietary plugins to gcc. I personally
think this is a fear from twenty years ago which shows a lack of
understanding of today's compiler market, but, that said, the FSF
wants to cover themselves for the future as well.
Someday, perhaps, the FSF will feel sufficiently confident to allow
unrestricted plugin access to GCC, but that does not appear to be in the
cards at this time.
What does appear to be happening, though, is an attempt to enable
plugins by way of some licensing trickery. The GCC suite is covered by the
GPL, a fact which does not, in itself, affect the licensing of any program
which is compiled by GCC. But GCC is more than just the compiler; it also
includes a runtime library needed to make most GCC-compiled programs
actually run. Linking to the runtime library could cause the resulting
program to be a derived product of that library; since the runtime library
is licensed under the GPL, that could be a concern for anybody compiling
non-GPL-licensed code. To address that concern, the runtime code has long
carried an exception to the GPL:
As a special exception, you may use this file as part of a free
software library without restriction. Specifically, if other files
instantiate templates or use macros or inline functions from this
file, or you compile this file and link it with other files to
produce an executable, this file does not by itself cause the
resulting executable to be covered by the GNU General Public
License. This exception does not however invalidate any other
reasons why the executable file might be covered by the GNU General
Public License.
That is the language which enables the distribution of proprietary software
built with GCC. The plan, said to be under consideration currently,
is to change the wording of that exemption; essentially, it would no longer
apply to code compiled with the use of proprietary GCC plugins. The new
license is not finalized, but Mr. Taylor guesses it will look something like this:
[I]f you modify gcc by adding GPL-incompatible software used to
generate code, it is likely that you will not be granted any
exception to the GPL when using the runtime library. In other
words, if you 1) add an optimization pass to gcc using the
(hypothetical) plugin architecture, and 2) that optimization pass
is not licensed under a GPL-compatible license, and 3) you generate
object code using that optimization pass, and 4) you link that
generated object code with the gcc runtime library (e.g., libgcc or
libstdc++-v3), then you will not be permitted to distribute the
resulting executable except under the terms of the GPL.
The actual wording of the new runtime license has been a long time in
coming; the FSF's lawyers want to get it right so that it discourages
undesired conduct while staying out of the way for everybody else. It also
does not appear to be the FSF's highest priority at the moment. So
nobody really knows when it might become official - though there have been
notes to the list suggesting that it could happen in the near future.
What we do seem to know is that it will happen, sooner or later, and the
addition of a plugin mechanism to GCC will become possible. So the
developers are starting to think about how the API will work. There are a
couple of existing GCC plugin frameworks already, and plenty of thoughts on
how they could be improved; see, for example, this discussion for an idea of what is being
talked about. But the details are likely to be of interest mostly to GCC
hackers, while the end result will be beneficial to a much wider community
of developers and users.
(
Log in to post comments)