From patchwork Tue Jan 31 04:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 50595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2559303wrn; Mon, 30 Jan 2023 20:51:47 -0800 (PST) X-Google-Smtp-Source: AK7set+Ae8sAgwBz1+vsnnv+YstFa51tpI3fzkgLo2xxz/ZthjlRzZJldd1HnuUJlXb8bBhCvpJl X-Received: by 2002:aa7:ca42:0:b0:492:8207:f2ba with SMTP id j2-20020aa7ca42000000b004928207f2bamr2056901edt.1.1675140706893; Mon, 30 Jan 2023 20:51:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675140706; cv=none; d=google.com; s=arc-20160816; b=a11hsIN/2zN1Xe0pPZ76I24TcrWv03wrwoA+IFoO6Ntyfs9YrmFAMbjUR8MJpQWQhR h/W3ZsjmJKqJ2Xkh+2oLySysH0JpFiy/XjSrG0ud0YKKHz7p/SY29KNOkwpiOvl8xEP6 P9TlSTJpP1ccQLid/Kd/Zh28K5GJk79d1bY0SmZDrCv2q5hu+uCaZCHiNxvwVUlCDaj8 OWVyi7hMttIY/79LxgHGED8WqCdJRNREfvuyx2zTQDLes76lyhGAoIh25K4036L8kv3O mnIKMke7yO2xynPinAspEkt5Guqq8swP7Lyc4t+yD6ufg15+O9gQJJ+EOQ9N7Qh9bC+E qqkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=hOI8LRyYTxQYwrm6bfAPmOicayb9mL6wnxn1UojwJoA=; b=X6pARG2wcOPcfFg229locZqxjFp/HW+hHb3RwPspR7Bx7YXcwv1K/ueXjqHzqdmcxP 73Ps65cucxEdZXIWday/QGkMIbptvcNZzv5XPnG9+J0GoGSseiDHxT9EZB8713YnJK/Q KbqRl8YRebGe7FqdDjuTuJaL/0fc4C9G9yNCtm4AduqTJ8XREUP9C03IF4jpcEu1q/9i pFXVp2yn0ia569YqEJEVXZaRVwMCuMoutW4ftF2t1h+hb8GLz5E6n71f2PDx30Pxx02y GmeHjDE7Uk3kesdV050j5AWgZWgKiIPgVeshOdtEeJHAhgwKP9f2AbC0Q14DaizxU73J ewOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=PuXcPNlp; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z22-20020a05640235d600b004a1d6ea6a12si1293127edc.409.2023.01.30.20.51.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 20:51:46 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=PuXcPNlp; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B45963858C62 for ; Tue, 31 Jan 2023 04:51:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B45963858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675140704; bh=hOI8LRyYTxQYwrm6bfAPmOicayb9mL6wnxn1UojwJoA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PuXcPNlpKUczRCi/MnuulP8jir6J7Ii+BOLDepvOULsD9zkS9X9TA2rBZZ7oycBYm tOi3/ndoac6eYbvzFxA/5Y/HEHHNal5jnkQvRogV9iKk+BZ3LSamaUDIq9LUhUp8Q4 0app44pkYP3yqzCroWLzme8dyDHwEvvn0JhSPs3E= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 Received: by mail-pj1-x1031.google.com with SMTP id t12-20020a17090aae0c00b00229f4cff534so199110pjq.1 for ; Mon, 30 Jan 2023 20:51:37 -0800 (PST) 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-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 To: binutils@sourceware.org Subject: PR30060, ASAN error in bfd_cache_close Message-ID: MIME-Version: 1.0 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756512342179967589?= X-GMAIL-MSGID: =?utf-8?q?1756512342179967589?= 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); } }