1 /* [Legacy] environment-based interface for loading high-level plugins.
2 Copyright (C) 2009 Free Software Foundation, Inc.
6 Authors: Grigori Fursin <grigori.fursin@inria.fr>, Cupertino Miranda
7 <cupertinomiranda@gmail.com>, Zbigniew Chamski <zbigniew.chamski@gmail.com>.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
31 #include "options.h" /* flag_ici */
32 #include "gcc-plugin.h"
34 #include "highlev-plugin-internal.h"
35 #include "feature-internal.h" /* init_features() */
41 /* plugin initialization/cleanup function type */
42 typedef void (*start_stop_func
) (void);
46 start_stop_func function_ptr
;
47 plugin_callback_func callback_ptr
;
50 /* pointers to initialization/cleanup functions */
51 start_stop_func ici_plugin_start
= NULL
;
53 /* report any errors encountered during a dl* operation */
54 static inline bool check_for_dlerror (void)
60 fprintf (stderr
, "Plugin manager error: DLerror: %s ...\n", dlError
);
67 /* load the ICI plugin shared library file named 'dynlib_file'.
68 Return 0 if successful, and 1 otherwise. */
70 load_ici_plugin_file (char *dynlib_file
)
74 dl_symbol_t dl_symbol
;
76 if (getenv ("ICI_VERBOSE") != NULL
)
77 fprintf (stderr
, "ICI: loading plugin ...\n");
79 dlhandle
= dlopen (dynlib_file
, RTLD_LAZY
);
80 error
|= check_for_dlerror ();
82 /* assignment of data pointers to function pointers is forbidden in strict
83 ANSI mode - use a union to work around this dlsym() issue. */
85 /* plugin initialization function */
86 dl_symbol
.data_ptr
= dlsym (dlhandle
, "start");
87 ici_plugin_start
= dl_symbol
.function_ptr
;
88 error
|= check_for_dlerror ();
90 /* plugin cleanup function */
91 dl_symbol
.data_ptr
= dlsym (dlhandle
, "stop");
92 register_callback (dynlib_file
, PLUGIN_FINISH
, dl_symbol
.callback_ptr
, NULL
);
93 error
|= check_for_dlerror ();
95 /* if init and cleanup functions are correctly resolverd, initialize the feature list */
103 /* load a plugin speficied by envariable ICI_PLUGIN if either -fici was
104 given on the command line or envariable ICI_USE is set to '1'. */
105 void load_ici_plugin (void)
107 char *ici_use
= getenv ("ICI_USE");
109 if ((ici_use
!= NULL
) && (ici_use
[0] == '1'))
114 char *dynlib_file
= getenv ("ICI_PLUGIN");
115 if (dynlib_file
!= NULL
)
117 if ((load_ici_plugin_file (dynlib_file
) == 0) && ici_plugin_start
)
125 fprintf (stderr
, "ICI error: Environment variable ICI_PLUGIN is not defined ...\n");