From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 13DEB3858D28 for ; Tue, 31 Jan 2023 04:51:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13DEB3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1031.google.com with SMTP id t12-20020a17090aae0c00b00229f4cff534so199110pjq.1 for ; Mon, 30 Jan 2023 20:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=hOI8LRyYTxQYwrm6bfAPmOicayb9mL6wnxn1UojwJoA=; b=ktdFQFDNxueFPl3qaLAJ2Apk6m8Sa5bBtDbwUfJckQtDaYVflu55Kv5v7Pp4kRlies n7Dn0FflmrToQJ/cVhvDuHDvZpPclGVV6LfbjE0q6BvutDUwHPteYSusqskJqtrZANK0 4dXI8ZqfsU2XSPLTI2W3BQOCy1T3hQS+/C0d9r/mmoMyZ01Yr1DE11zL6dA65DmF4Dyu a2UAcNNWG+4aAS8JM7eawBulr3DgsAZwKE7cLYpebrPn+4fAMKjtJMQMUj3IKtqwTkR7 /cHjO72OHRzzNROihBMUTB9HTBYRpl6wm2s6qkQ/+qRq9GxTvEJPumiNh80CNKfObH95 0n9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hOI8LRyYTxQYwrm6bfAPmOicayb9mL6wnxn1UojwJoA=; b=ub9gjaUiUFcIBAl+bCt0mlO1zJcQWFQ9moa55BBD6MpAe+1UdlUEKYmM6tuSHWEFxF SjfQrcEa604ENIqA0KKDAtYB+vxbbt+XctV4r6lnsxoWKShworePHP+SMB/mP37Zk0ix rMAQzh/SZ44eyee6Nw3Q2mVNlwSCC5FgkztEpW5+q7OkqZALvrUC8wfZKuocbubnDCHL NyFAGqSabGXIM6W2pbWFs8GD6lVJ0RR/92kZ+Irair7nBdcQpTJrqBf4ebDsjd3IcxxD lHiiudmH4xYQVdBavDpoYg7t5BoMmk4mTjsoF6lJ6GtjGmwg+uXx9xUTvSA9E6XnbHQp myQA== X-Gm-Message-State: AO0yUKVtprQGiHIfIBOzrHr/nWO6D0TS60L3Y9bf6NsdOMAtgq4IZWFA T+oIkCKD06rs91Xn8ugyEimQrJ3fc9k= X-Google-Smtp-Source: AK7set/jG+gwS+YxS5r3xU8/YwxW11xl4GiBqigbO8JfBSUQ53Pb9QSHp6d65X2eAcPLhBmfviwKUw== X-Received: by 2002:a17:902:d50a:b0:196:22d5:6583 with SMTP id b10-20020a170902d50a00b0019622d56583mr27314017plg.32.1675140695971; Mon, 30 Jan 2023 20:51:35 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id o5-20020a170902bcc500b001946a3f4d9csm461170pls.38.2023.01.30.20.51.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 20:51:35 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 513C61142E01; Tue, 31 Jan 2023 15:21:33 +1030 (ACDT) Date: Tue, 31 Jan 2023 15:21:33 +1030 From: Alan Modra To: binutils@sourceware.org Subject: PR30060, ASAN error in bfd_cache_close Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: After bfd_close nothing should access bfd memory. Now that bfd_close always tidies up even after an error, attempting to tidy the cached bfd list by calling bfd_cache_close is wrong and not needed. PR 30060 * ar.c (remove_output): Don't call bfd_cache_close. (output_bfd): Delete. * arsup.c (ar_end): Call bfd_close_all_done, not bfd_cache_close. diff --git a/binutils/ar.c b/binutils/ar.c index f8b161aaf5a..2c901ca327c 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -431,15 +431,12 @@ normalize (const char *file, bfd *abfd) static const char *output_filename = NULL; static FILE *output_file = NULL; -static bfd *output_bfd = NULL; static void remove_output (void) { if (output_filename != NULL) { - if (output_bfd != NULL) - bfd_cache_close (output_bfd); if (output_file != NULL) fclose (output_file); unlink_if_ordinary (output_filename); @@ -1272,8 +1269,6 @@ write_archive (bfd *iarch) bfd_fatal (old_name); } - output_bfd = obfd; - bfd_set_format (obfd, bfd_archive); /* Request writing the archive symbol table unless we've @@ -1303,7 +1298,6 @@ write_archive (bfd *iarch) if (!bfd_close (obfd)) bfd_fatal (old_name); - output_bfd = NULL; output_filename = NULL; /* We don't care if this fails; we might be creating the archive. */ diff --git a/binutils/arsup.c b/binutils/arsup.c index 8ffb5f34a2d..744a8d423af 100644 --- a/binutils/arsup.c +++ b/binutils/arsup.c @@ -469,8 +469,9 @@ ar_end (void) { if (obfd) { - bfd_cache_close (obfd); - unlink (bfd_get_filename (obfd)); + const char *filename = bfd_get_filename (obfd); + bfd_close_all_done (obfd); + unlink (filename); } } -- Alan Modra Australia Development Lab, IBM