aboutsummaryrefslogtreecommitdiff
path: root/ld/plugin.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-07-04 08:55:04 -0700
committerH.J. Lu <hjl.tools@gmail.com>2016-07-04 08:55:20 -0700
commitc3e1c28ebfdb20ff4498bcc792228283b903d393 (patch)
treead03cee00b4e79c0ca3c9cbbf7a864253fc4ed2d /ld/plugin.c
parent1dc8bf195d2c4d382e0d6d371f16ebfe83573acc (diff)
downloadgdb-c3e1c28ebfdb20ff4498bcc792228283b903d393.zip
gdb-c3e1c28ebfdb20ff4498bcc792228283b903d393.tar.gz
gdb-c3e1c28ebfdb20ff4498bcc792228283b903d393.tar.bz2
Warn and return for duplicated plugin
If a plugin has been loaded already, we should warn and return, instead of adding it on the plugin list. PR ld/20321 * plugin.c (plugin_opt_plugin): Warn and return if plugin has been loaded already. * testsuite/ld-plugin/lto.exp: Run PR ld/20321 test. * testsuite/ld-plugin/pr20321.c: New file.
Diffstat (limited to 'ld/plugin.c')
-rw-r--r--ld/plugin.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ld/plugin.c b/ld/plugin.c
index 4c161d1..924b59c 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -237,6 +237,7 @@ void
plugin_opt_plugin (const char *plugin)
{
plugin_t *newplug;
+ plugin_t *curplug = plugins_list;
newplug = xmalloc (sizeof *newplug);
memset (newplug, 0, sizeof *newplug);
@@ -245,6 +246,18 @@ plugin_opt_plugin (const char *plugin)
if (!newplug->dlhandle)
einfo (_("%P%F: %s: error loading plugin: %s\n"), plugin, dlerror ());
+ /* Check if plugin has been loaded already. */
+ while (curplug)
+ {
+ if (newplug->dlhandle == curplug->dlhandle)
+ {
+ einfo (_("%P: %s: duplicated plugin\n"), plugin);
+ free (newplug);
+ return;
+ }
+ curplug = curplug->next;
+ }
+
/* Chain on end, so when we run list it is in command-line order. */
*plugins_tail_chain_ptr = newplug;
plugins_tail_chain_ptr = &newplug->next;