This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Warn and return for duplicated plugin
- From: H.J.Lu <hjl at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 4 Jul 2016 15:57:30 -0000
- Subject: [binutils-gdb] Warn and return for duplicated plugin
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c3e1c28ebfdb20ff4498bcc792228283b903d393
commit c3e1c28ebfdb20ff4498bcc792228283b903d393
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Mon Jul 4 08:55:04 2016 -0700
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.
Diff:
---
ld/ChangeLog | 8 ++++++++
ld/plugin.c | 13 +++++++++++++
ld/testsuite/ld-plugin/lto.exp | 3 +++
ld/testsuite/ld-plugin/pr20321.c | 4 ++++
4 files changed, 28 insertions(+)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 248e66e..7e24b95 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
+2016-07-04 H.J. Lu <hongjiu.lu@intel.com>
+
+ 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.
+
2016-07-04 Nick Clifton <nickc@redhat.com>
* scripttempl/ft32.sc (__PMSIZE_): If not defined, set to 256K.
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;
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 80bc469..2ecb4d0 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -198,6 +198,9 @@ set lto_link_tests [list \
[list "Build libpr20267b.a" \
"$plug_opt" "-flto $lto_no_fat" \
{pr20267b.c} {} "libpr20267b.a"] \
+ [list "Build pr20321" \
+ "-Wl,-plugin,$plug_so" "-flto" \
+ {pr20321.c} {} "pr20321" "c" ".*: duplicated plugin"] \
]
if { [at_least_gcc_version 4 7] } {
diff --git a/ld/testsuite/ld-plugin/pr20321.c b/ld/testsuite/ld-plugin/pr20321.c
new file mode 100644
index 0000000..8488f4e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr20321.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}