From patchwork Fri Jan 27 07:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 49112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp691413wrn; Thu, 26 Jan 2023 23:03:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXvAtejpkB8EY/e5XjPjfgXN4Ir/WUlUc4N/o11cTVkMtYrPFwuvqpiRITBAaahzeoFEeOi3 X-Received: by 2002:a17:907:9b06:b0:872:f259:a7ea with SMTP id kn6-20020a1709079b0600b00872f259a7eamr41540833ejc.53.1674802982682; Thu, 26 Jan 2023 23:03:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674802982; cv=none; d=google.com; s=arc-20160816; b=iQlFuiotTS9nUg+YHzC0+v1xmMlSJwxYyP55ohn3NLXElNrdynbv6pDI864LOiFD1q zCHTYBUuHTRjbrUdeH9rQgFrJWDJdgShRl80MHQ2tkzcJPqmW0XUuvBbFim/PFwXUdwt hcKn3PrrPQdtfxmWeeSYuTpiMektfEAMEB+Le8nC4rZulNbGn/LSjRoF6Mb45cy9+qtQ TjxObQL1U9TnMlZzBKlw5WwgdGUdOlu3IMMqQkCPaVuq5lLefc4/vkkDR8MVXC4RdWPB yyGgKbpD89SOue6M/f5xtc+drCLDc2x/pQp0wkaLMFsZCm5A0hSgFPuE4cUBg6bQLx9g cawQ== 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=y9vNxk7qd0Y6OSYKQTTX3pbRxC5KE58R3R9UAlcWBjc=; b=Xop7Isehe85c3CbSPXW9WZd6pO2H+uLZUCcHqWj/0pN19Hdt8rkOH3R3J2wG8cKDsF DGjm0z+FZ3WI3pp/ogrUZOxW8DMJ0FQ7kk2R9PExo91E9w0+wqZh7t/46pv4iSdkARH/ lLDpQzpEfWniMjSGCy7hjqi4axvtQZJyixJhey+N6E3TunPtWFgOVBC4RvKThiP58uP/ EqmFLwQuisllcaxflEbwThyZzREkremEUvXibQLENiVJ82o/lgaA9CxPPogf5UXv8c3X LsaeFIGsKQeNZfIaRToBQOyHiTPS1DBemQDXz35ZbFW89w5QBpn+nZUMxOiCVt16M32Z fD9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=pDSNQ8e6; 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 vs15-20020a170907138f00b007c14eabf6adsi3952101ejb.116.2023.01.26.23.03.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 23:03:02 -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=pDSNQ8e6; 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 713CB3858280 for ; Fri, 27 Jan 2023 07:02:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 713CB3858280 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674802977; bh=y9vNxk7qd0Y6OSYKQTTX3pbRxC5KE58R3R9UAlcWBjc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pDSNQ8e68WqlZKbib4tPwRMrXDQOi4w2MO2sw8AtxFuaQl/ZSvUaNto9ISr9QCk68 dRPTZKe5y3O1z0Bu6Tpo1u4v9iO9t7XIBqcpHKa6X260K9CKZV3X4X1KeWLqLh9lcj cY0qMXFtEoxq1YWZ1dlSxg9VR9xYdQfZG15Hyp0A= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id CE54E3858C33 for ; Fri, 27 Jan 2023 07:01:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE54E3858C33 Received: by mail-pg1-x535.google.com with SMTP id 36so2646276pgp.10 for ; Thu, 26 Jan 2023 23:01:59 -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=y9vNxk7qd0Y6OSYKQTTX3pbRxC5KE58R3R9UAlcWBjc=; b=XhBIxVUntDYdlZDettEfP/cMwTyq70nnhwCVV1TRjtX/OTgP4siubD9WisZ/IPUHOu 799wxX101RnMl1SvFr+D9x7X9oC7ye8okkLRhty5iFxF8FoMJ8uGw6EtSp5If7UkzN8x pks6aMKtdNHKf65Iy5mbuyFhIkRVhsSDmd1j2NIbYycd0pVj5cBNMnOcRuhrd4XU4RrP LtBx5LhWdB3RrtkMJnsI2Wzr8PTG6fSfOA40MMZvSgq+vmAMEPC5nQbTHMQnElRZ9QTr KQN3sok+LU0/m3lldxnZHj4d9t3PzO5fdqRA0J9VHs86U297dzSvn5zfiAYSdsPsAH60 CK9g== X-Gm-Message-State: AFqh2kpFKfR0nnIWIpBv4TxIfMYDyn1vjYKqRii/dsB/vFFUs3Ykk/48 eOckfv/TkjKMlvAvSwK/AeOqHVQRpZI= X-Received: by 2002:a05:6a00:1d23:b0:58d:a91d:e9f8 with SMTP id a35-20020a056a001d2300b0058da91de9f8mr32210345pfx.18.1674802918613; Thu, 26 Jan 2023 23:01:58 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:fb44:1882:a135:67f]) by smtp.gmail.com with ESMTPSA id i9-20020a628709000000b005893f281d43sm1681959pfe.27.2023.01.26.23.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 23:01:58 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 258211142E33; Fri, 27 Jan 2023 17:31:56 +1030 (ACDT) Date: Fri, 27 Jan 2023 17:31:56 +1030 To: binutils@sourceware.org Subject: Perform cleanup in bfd_close after errors Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.1 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?1756158212190019224?= X-GMAIL-MSGID: =?utf-8?q?1756158212190019224?= It seems reasonable to continue after errors in bfd_close_all_done, particularly since bfd_close_all_done is typically called on an output file after we've hit some sort of error elsewhere. The iovec test is necessary if bfd_close_all_done is to work on odd bfd's opened by bfd_create. * opncls.c (bfd_close): Call bfd_close_all_done after errors from _bfd_write_contents. (bfd_close_all_done): Call _bfd_delete_bfd after errors. Don't call iovec->bclose when iovec is NULL. diff --git a/bfd/opncls.c b/bfd/opncls.c index 9241cd1c537..6ae3af054e4 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -805,13 +805,10 @@ RETURNS bool bfd_close (bfd *abfd) { - if (bfd_write_p (abfd)) - { - if (! BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd))) - return false; - } + bool ret = (!bfd_write_p (abfd) + || BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd))); - return bfd_close_all_done (abfd); + return bfd_close_all_done (abfd) && ret; } /* @@ -839,15 +836,15 @@ RETURNS bool bfd_close_all_done (bfd *abfd) { - bool ret; + bool ret = BFD_SEND (abfd, _close_and_cleanup, (abfd)); - if (! BFD_SEND (abfd, _close_and_cleanup, (abfd))) - return false; - - ret = abfd->iovec->bclose (abfd) == 0; + if (ret && abfd->iovec != NULL) + { + ret = abfd->iovec->bclose (abfd) == 0; - if (ret) - _maybe_make_executable (abfd); + if (ret) + _maybe_make_executable (abfd); + } _bfd_delete_bfd (abfd);