comparison gcc/plugin.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Support for GCC plugin mechanism. 1 /* Support for GCC plugin mechanism.
2 Copyright (C) 2009-2018 Free Software Foundation, Inc. 2 Copyright (C) 2009-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify 6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
229 (path) names. */ 229 (path) names. */
230 if (*slot) 230 if (*slot)
231 { 231 {
232 plugin = (struct plugin_name_args *) *slot; 232 plugin = (struct plugin_name_args *) *slot;
233 if (strcmp (plugin->full_name, plugin_name)) 233 if (strcmp (plugin->full_name, plugin_name))
234 error ("plugin %s was specified with different paths:\n%s\n%s", 234 error ("plugin %qs was specified with different paths: %qs and %qs",
235 plugin->base_name, plugin->full_name, plugin_name); 235 plugin->base_name, plugin->full_name, plugin_name);
236 return; 236 return;
237 } 237 }
238 238
239 plugin = XCNEW (struct plugin_name_args); 239 plugin = XCNEW (struct plugin_name_args);
288 ++len; 288 ++len;
289 } 289 }
290 290
291 if (!key_start) 291 if (!key_start)
292 { 292 {
293 error ("malformed option -fplugin-arg-%s (missing -<key>[=<value>])", 293 error ("malformed option %<-fplugin-arg-%s%>: "
294 "missing %<-<key>[=<value>]%>",
294 arg); 295 arg);
295 return; 296 return;
296 } 297 }
297 298
298 /* If the option doesn't contain the 'value' part, LEN is the KEY_LEN. 299 /* If the option doesn't contain the 'value' part, LEN is the KEY_LEN.
351 352
352 plugin->argv[plugin->argc - 1].key = key; 353 plugin->argv[plugin->argc - 1].key = key;
353 plugin->argv[plugin->argc - 1].value = value; 354 plugin->argv[plugin->argc - 1].value = value;
354 } 355 }
355 else 356 else
356 error ("plugin %s should be specified before -fplugin-arg-%s " 357 error ("plugin %s should be specified before %<-fplugin-arg-%s%> "
357 "in the command line", name, arg); 358 "in the command line", name, arg);
358 359
359 /* We don't need the plugin's name anymore. Just release it. */ 360 /* We don't need the plugin's name anymore. Just release it. */
360 XDELETEVEC (name); 361 XDELETEVEC (name);
361 } 362 }
698 RTLD_GLOBAL which is useful to plugins which themselves call 699 RTLD_GLOBAL which is useful to plugins which themselves call
699 dlopen. */ 700 dlopen. */
700 dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL); 701 dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);
701 if (!dl_handle) 702 if (!dl_handle)
702 { 703 {
703 error ("cannot load plugin %s\n%s", plugin->full_name, dlerror ()); 704 error ("cannot load plugin %s: %s", plugin->full_name, dlerror ());
704 return false; 705 return false;
705 } 706 }
706 707
707 /* Clear any existing error. */ 708 /* Clear any existing error. */
708 dlerror (); 709 dlerror ();
709 710
710 /* Check the plugin license. */ 711 /* Check the plugin license. */
711 if (dlsym (dl_handle, str_license) == NULL) 712 if (dlsym (dl_handle, str_license) == NULL)
712 fatal_error (input_location, 713 fatal_error (input_location,
713 "plugin %s is not licensed under a GPL-compatible license\n" 714 "plugin %s is not licensed under a GPL-compatible license"
714 "%s", plugin->full_name, dlerror ()); 715 " %s", plugin->full_name, dlerror ());
715 716
716 PTR_UNION_AS_VOID_PTR (plugin_init_union) = 717 PTR_UNION_AS_VOID_PTR (plugin_init_union)
717 dlsym (dl_handle, str_plugin_init_func_name); 718 = dlsym (dl_handle, str_plugin_init_func_name);
718 plugin_init = PTR_UNION_AS_CAST_PTR (plugin_init_union); 719 plugin_init = PTR_UNION_AS_CAST_PTR (plugin_init_union);
719 720
720 if ((err = dlerror ()) != NULL) 721 if ((err = dlerror ()) != NULL)
721 { 722 {
722 dlclose(dl_handle); 723 dlclose(dl_handle);
723 error ("cannot find %s in plugin %s\n%s", str_plugin_init_func_name, 724 error ("cannot find %s in plugin %s: %s", str_plugin_init_func_name,
724 plugin->full_name, err); 725 plugin->full_name, err);
725 return false; 726 return false;
726 } 727 }
727 728
728 /* Call the plugin-provided initialization routine with the arguments. */ 729 /* Call the plugin-provided initialization routine with the arguments. */
729 if ((*plugin_init) (plugin, &gcc_version)) 730 if ((*plugin_init) (plugin, &gcc_version))
730 { 731 {
731 dlclose(dl_handle); 732 dlclose(dl_handle);
732 error ("fail to initialize plugin %s", plugin->full_name); 733 error ("failed to initialize plugin %s", plugin->full_name);
733 return false; 734 return false;
734 } 735 }
735 /* leak dl_handle on purpose to ensure the plugin is loaded for the 736 /* leak dl_handle on purpose to ensure the plugin is loaded for the
736 entire run of the compiler. */ 737 entire run of the compiler. */
737 return true; 738 return true;
1001 const char* 1002 const char*
1002 default_plugin_dir_name (void) 1003 default_plugin_dir_name (void)
1003 { 1004 {
1004 if (!plugindir_string) 1005 if (!plugindir_string)
1005 fatal_error (input_location, 1006 fatal_error (input_location,
1006 "-iplugindir <dir> option not passed from the gcc driver"); 1007 "%<-iplugindir%> <dir> option not passed from the gcc driver");
1007 return plugindir_string; 1008 return plugindir_string;
1008 } 1009 }