This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
plugins: dlopen should use RTLD_GLOBAL
- From: Basile STARYNKEVITCH <basile at starynkevitch dot net>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 09 Jul 2009 17:03:11 +0200
- Subject: plugins: dlopen should use RTLD_GLOBAL
Hello All,
The attached patch to trunk rev149419 is adding RTLD_GLOBAL to dlopen's
flag.
It is needed for meta-plugins (e.g. MELT), with the following scenario.
cc1 loads a plugin, eg melt.so. This plugin defines an exported
variable, eg melt_curalz, and later this plugin (melt.so) dlopen-s
itself another module, e.g. warmelt-first.so. This other module
warmelt_first.so refers to the exported variable melt_curalz defined in
the first plugin melt.so. To have this work, all the symbols defined by
the first plugin melt.so should get global scope. This is what
RTLD_GLOBAL does.
gcc/ChangeLog:
2009-07-09 Basile Starynkevitch <basile@starynkevitch.net>
* plugin.c (try_init_one_plugin): passes RTLD_GLOBAL to dlopen.
Ok for trunk?
[we could also wrap with a #ifdef RTLD_GLOBAL if you want; I feel that
all the platforms on which we want plugins with GCC have it.]
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c (revision 149419)
+++ gcc/plugin.c (working copy)
@@ -592,7 +592,11 @@ try_init_one_plugin (struct plugin_name_args *plug
char *err;
PTR_UNION_TYPE (plugin_init_func) plugin_init_union;
- dl_handle = dlopen (plugin->full_name, RTLD_NOW);
+ /* We use RTLD_NOW to accelerate binding and detect any mismatch
+ between the API expected by the plugin and the GCC API; we use
+ RTLD_GLOBAL which is useful for meta-plugins, i.e. those plugins
+ which themselves call dlopen. */
+ dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);
if (!dl_handle)
{
error ("Cannot load plugin %s\n%s", plugin->full_name, dlerror ());