From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17581 invoked by alias); 18 Feb 2020 12:50:22 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 17563 invoked by uid 89); 18 Feb 2020 12:50:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mail-pl1-f182.google.com Received: from mail-pl1-f182.google.com (HELO mail-pl1-f182.google.com) (209.85.214.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Feb 2020 12:50:19 +0000 Received: by mail-pl1-f182.google.com with SMTP id e8so8041369plt.9 for ; Tue, 18 Feb 2020 04:50:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pOgNKXoqNt6/v6cfIFKSBTi4Z4uPupQbi8Scko3NNWc=; b=JcorPUnNznTtnsiMkBGHL69BxCeP7HWrQ28bQOvtuvWl7AnbQCLIiOlB+Os6Ek5NKL MctdfwDChTABFN5TzUbsE+bz3k4b6ebIdNIwMJBifgDI7oxOxLzJ5pWoPIPnm9tbFI28 iYOF4ynq3XZpamyT+8l3rclzC6jrMdZBPtmPpzjUvyWKesEGcX63MHA7neBseC1i41Sq 2Hwr9F6ZAzFWz2WD8TIbB0/mUkm/pssUvEAVb96GrzN20eJao5fBdahe1BmeRpDh0Pj1 EBJfvMGNjHNIR6Uv2S05FxkU0+JNNltjY8QeBGB6BJpI//5crnU79gPi91tzNH8EmxGR OD9g== Return-Path: Received: from gnu-cfl-2.localdomain (c-73-93-86-59.hsd1.ca.comcast.net. [73.93.86.59]) by smtp.gmail.com with ESMTPSA id q187sm4342065pfq.185.2020.02.18.04.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 04:50:17 -0800 (PST) Received: from gnu-cfl-2.hsd1.ca.comcast.net (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 0E0C2C039B for ; Tue, 18 Feb 2020 04:50:16 -0800 (PST) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] plugin: Call dlclose before return in try_load_plugin Date: Tue, 18 Feb 2020 12:50:00 -0000 Message-Id: <20200218125016.140100-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00423.txt.bz2 Since plugin can be used only once in try_load_plugin, call dlclose before return. OK for master and 2.34 branch? PR binutils/25355 * plugin.c (plugin_list_entry): Remove handle. (try_load_plugin): Call dlclose before return. --- bfd/plugin.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/bfd/plugin.c b/bfd/plugin.c index 47c3439042c..84b96a20733 100644 --- a/bfd/plugin.c +++ b/bfd/plugin.c @@ -126,7 +126,6 @@ message (int level ATTRIBUTE_UNUSED, struct plugin_list_entry { /* These must be initialized for each IR object with LTO wrapper. */ - void *handle; ld_plugin_claim_file_handler claim_file; ld_plugin_all_symbols_read_handler all_symbols_read; ld_plugin_all_symbols_read_handler cleanup_handler; @@ -596,22 +595,12 @@ try_load_plugin (const char *pname, struct plugin_list_entry *plugin_list_iter, bfd *abfd, bfd_boolean build_list_p) { - void *plugin_handle = NULL; + void *plugin_handle; struct ld_plugin_tv tv[12]; int i; ld_plugin_onload onload; enum ld_plugin_status status; - - /* NB: Each object is independent. Reuse the previous plugin from - the last run will lead to wrong result. */ - if (current_plugin) - { - if (current_plugin->handle) - dlclose (current_plugin->handle); - memset (current_plugin, 0, - offsetof (struct plugin_list_entry, next)); - current_plugin = NULL; - } + int result = 0; if (plugin_list_iter) pname = plugin_list_iter->plugin_name; @@ -628,12 +617,12 @@ try_load_plugin (const char *pname, size_t length_plugin_name = strlen (pname) + 1; char *plugin_name = bfd_malloc (length_plugin_name); if (plugin_name == NULL) - return 0; + goto short_circuit; plugin_list_iter = bfd_malloc (sizeof *plugin_list_iter); if (plugin_list_iter == NULL) { free (plugin_name); - return 0; + goto short_circuit; } /* Make a copy of PNAME since PNAME from load_plugin () will be freed. */ @@ -644,13 +633,13 @@ try_load_plugin (const char *pname, plugin_list = plugin_list_iter; } - plugin_list_iter->handle = plugin_handle; + current_plugin = plugin_list_iter; if (build_list_p) - return 0; + goto short_circuit; onload = dlsym (plugin_handle, "onload"); if (!onload) - return 0; + goto short_circuit; i = 0; tv[i].tv_tag = LDPT_MESSAGE; @@ -703,28 +692,32 @@ try_load_plugin (const char *pname, tv[i].tv_tag = LDPT_NULL; tv[i].tv_u.tv_val = 0; - current_plugin = plugin_list_iter; - /* LTO plugin will call handler hooks to set up plugin handlers. */ status = (*onload)(tv); if (status != LDPS_OK) - return 0; + goto short_circuit; if (current_plugin->lto_wrapper && setup_lto_wrapper_env (current_plugin)) - return 0; + goto short_circuit; abfd->plugin_format = bfd_plugin_no; if (!current_plugin->claim_file) - return 0; + goto short_circuit; if (!try_claim (abfd)) - return 0; + goto short_circuit; abfd->plugin_format = bfd_plugin_yes; - return 1; + result = 1; + +short_circuit: + /* NB: Each object is independent. Reuse the previous plugin from + the last run will lead to wrong result. */ + dlclose (plugin_handle); + return result; } /* There may be plugin libraries in lib/bfd-plugins. */ -- 2.24.1