From patchwork Tue Feb 28 00:06:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 62198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2715082wrd; Mon, 27 Feb 2023 16:06:53 -0800 (PST) X-Google-Smtp-Source: AK7set+i1jpEPrC8aatc5rDbQaN0a9Ejp8qYR/1VRzLvAJF4TM1iCKdnLCn0k0EdMyjyzVzGiA5U X-Received: by 2002:a50:fb85:0:b0:4af:6e95:7353 with SMTP id e5-20020a50fb85000000b004af6e957353mr1380964edq.11.1677542813331; Mon, 27 Feb 2023 16:06:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677542813; cv=none; d=google.com; s=arc-20160816; b=1KSlJnYIyz5Q6vxerQJBhvu/LGmptktxLecYmwW4WtsUOhraQ54mD6nOzJz0tketdn U48s6Wh/jKJnf79x/1N+c/p6/x6OpCbJYIxjdgmQ54sG6ec42BOqOrNywLrdTdi+z7ex B5k4702X1FQPMJeyyi4EtRDkpRnFpMUwRoIpgE8wY25ZaEcbS9uXTK7r7WWRgSBolgCQ Mp1CcVUUdjj5E24SzrJ1SvT/GPH3shb2NzhUS60XuHP3L7ZITDFNnq+e7affxi9UYyd5 Yl8VppKbP1Fwz0hcacIvsKyzAI94cvgX/Y3vBjSRIvnFpNXjDIAZ4vPjXMkDmRRQKTwB UdDw== 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=WvRRJx5V6EEREIiOZQ7Uu/QDc6+OPu/AcEGh8dFgCH0=; b=UkIl9paDIjLTCqB/YEjniw594cDwpRl31pDzO3zNr93nxg68n7ZpiwjQMTF8X1oiDi 6NOqDpUAs01mXvbgMUl8z8gjIGvncHmfe+8lIacLLhCDJ0/owHxTkmtoctLdefjbyxKN 7oKKy9V8nXC+Tdykj9mtz1/9il9ccJmUIobfPDOic8q9ejAOhGG1EPcbu7YtCTTMLjJq 3kHYZqO1kV07DyAsMjACM9RXqVjt5nTZ8mS/l8yQaHdUzn3/gkpZMe7bUwnFeq0jVYr4 VzSlsaQOHjr7cBzBtPrQjEdFau1fzEuCFTJ5bj5ZEbzeAVlHaKnY7BMKg8OhZiZi+nFM /R3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=RujPPN0z; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id d10-20020a056402078a00b004acc5e8b8f6si10054960edy.312.2023.02.27.16.06.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=RujPPN0z; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 51BB63858425 for ; Tue, 28 Feb 2023 00:06:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51BB63858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677542812; bh=WvRRJx5V6EEREIiOZQ7Uu/QDc6+OPu/AcEGh8dFgCH0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RujPPN0zzSM8Ma2+4rbjfNzcvLtIJEG9VnV4f545PksWidMEgtpMD02kEfAcBixHM +TVnjL7RsBi85tjq/sYp+WIIpaEQv32N5ptvKJJpIIqmstgI2VISZaMXbWvnABKNqU iJyba6o+mZ9XsM8hwgm37wjcJqRw1m2jVvKWwMDk= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id AA23A3858D3C for ; Tue, 28 Feb 2023 00:06:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA23A3858D3C Received: by mail-pj1-x1036.google.com with SMTP id x34so8041313pjj.0 for ; Mon, 27 Feb 2023 16:06:41 -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=WvRRJx5V6EEREIiOZQ7Uu/QDc6+OPu/AcEGh8dFgCH0=; b=l8h9s+ilOtmX7Bqf5SpMtVOq2G9LSjuHw7vDGG8f3FDMi0B18WHLwvQI/DdVIGQZUD P6RSYFyQGJ/CHqgMe4nVufmFhKF0SuFt0EQIbLjFGS21D1ZD8dho3T2K+5zKdxKOH2Cn yZcaU49adFmOlOjpWagk85xbdzlhlwxKnjuUmOXMnGy4xoj8RQzWOAcMckX9U8l5HEd3 R1TznhiAPmG2sXXQbdV5WJqNHynGAjbLKJhbGwJ2wq2MUfTycEGVqbaeav2NhWxB6MMn oUxNoEkvZmOU/4cJCD8n3tKYikyNsm1CffKw/Z8VTKHKxYo84AKnSMDzEDwmnCx6qUWA 8s5Q== X-Gm-Message-State: AO0yUKVWIp+F9N4ulQzBeI4eRYfL3aJhm3rIDFnVTxU7RQoQh+a9qWwr +kjBVvv5V6ye03INY6CyOpQ2riAd27U= X-Received: by 2002:a05:6a20:ba99:b0:c7:1f9b:19a0 with SMTP id fb25-20020a056a20ba9900b000c71f9b19a0mr1005530pzb.39.1677542799542; Mon, 27 Feb 2023 16:06:39 -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 o27-20020a637e5b000000b004fb3e5681cesm4481577pgn.20.2023.02.27.16.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:06:39 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id E20241142CE6; Tue, 28 Feb 2023 10:36:36 +1030 (ACDT) Date: Tue, 28 Feb 2023 10:36:36 +1030 To: binutils@sourceware.org Subject: Free ecoff debug info Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.4 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?1759031133156979163?= X-GMAIL-MSGID: =?utf-8?q?1759031133156979163?= This frees memory associated with the mips ecoff find_nearest_line. * elfxx-mips.x (free_ecoff_debug): New function, extracted from.. (_bfd_mips_elf_read_ecoff_info): ..here. Free ext_hdr earlier. Don't clear already NULL fdr. (struct mips_elf_find_line): Move earlier. (_bfd_mips_elf_close_and_cleanup): Call free_ecoff_debug. (_bfd_mips_elf_find_nearest_line): Likewise on error paths, and to clean up input_debug when done. diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 74a4d0d382b..35bbd86044b 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -1380,18 +1380,61 @@ _bfd_mips_elf_mkobject (bfd *abfd) MIPS_ELF_DATA); } +/* MIPS ELF uses a special find_nearest_line routine in order the + handle the ECOFF debugging information. */ + +struct mips_elf_find_line +{ + struct ecoff_debug_info d; + struct ecoff_find_line i; +}; + +/* Free ECOFF debugging info used by find_nearest_line. */ + +static void +free_ecoff_debug (struct ecoff_debug_info *debug) +{ + free (debug->line); + free (debug->external_dnr); + free (debug->external_pdr); + free (debug->external_sym); + free (debug->external_opt); + free (debug->external_aux); + free (debug->ss); + free (debug->ssext); + free (debug->external_fdr); + free (debug->external_rfd); + free (debug->external_ext); + debug->line = NULL; + debug->external_dnr = NULL; + debug->external_pdr = NULL; + debug->external_sym = NULL; + debug->external_opt = NULL; + debug->external_aux = NULL; + debug->ss = NULL; + debug->ssext = NULL; + debug->external_fdr = NULL; + debug->external_rfd = NULL; + debug->external_ext = NULL; +} + bool _bfd_mips_elf_close_and_cleanup (bfd *abfd) { - struct mips_elf_obj_tdata *tdata = mips_elf_tdata (abfd); - if (tdata != NULL && bfd_get_format (abfd) == bfd_object) + if (bfd_get_format (abfd) == bfd_object) { - BFD_ASSERT (tdata->root.object_id == MIPS_ELF_DATA); - while (tdata->mips_hi16_list != NULL) + struct mips_elf_obj_tdata *tdata = mips_elf_tdata (abfd); + if (tdata != NULL) { - struct mips_hi16 *hi = tdata->mips_hi16_list; - tdata->mips_hi16_list = hi->next; - free (hi); + BFD_ASSERT (tdata->root.object_id == MIPS_ELF_DATA); + while (tdata->mips_hi16_list != NULL) + { + struct mips_hi16 *hi = tdata->mips_hi16_list; + tdata->mips_hi16_list = hi->next; + free (hi); + } + if (tdata->find_line_info != NULL) + free_ecoff_debug (&tdata->find_line_info->d); } } return _bfd_elf_close_and_cleanup (abfd); @@ -1438,6 +1481,8 @@ _bfd_mips_elf_read_ecoff_info (bfd *abfd, asection *section, symhdr = &debug->symbolic_header; (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr); + free (ext_hdr); + ext_hdr = NULL; /* The symbolic header contains absolute file offsets and sizes to read. */ @@ -1474,23 +1519,11 @@ _bfd_mips_elf_read_ecoff_info (bfd *abfd, asection *section, READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, void *); #undef READ - debug->fdr = NULL; - return true; error_return: free (ext_hdr); - free (debug->line); - free (debug->external_dnr); - free (debug->external_pdr); - free (debug->external_sym); - free (debug->external_opt); - free (debug->external_aux); - free (debug->ss); - free (debug->ssext); - free (debug->external_fdr); - free (debug->external_rfd); - free (debug->external_ext); + free_ecoff_debug (debug); return false; } @@ -13109,15 +13142,6 @@ _bfd_mips_elf_is_target_special_symbol (bfd *abfd, asymbol *sym) return _bfd_elf_is_local_label_name (abfd, sym->name); } -/* MIPS ELF uses a special find_nearest_line routine in order the - handle the ECOFF debugging information. */ - -struct mips_elf_find_line -{ - struct ecoff_debug_info d; - struct ecoff_find_line i; -}; - bool _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols, asection *section, bfd_vma offset, @@ -13189,6 +13213,7 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols, fi->d.fdr = bfd_alloc (abfd, amt); if (fi->d.fdr == NULL) { + free_ecoff_debug (&fi->d); msec->flags = origflags; return false; } @@ -13201,13 +13226,6 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols, (*swap->swap_fdr_in) (abfd, fraw_src, fdr_ptr); mips_elf_tdata (abfd)->find_line_info = fi; - - /* Note that we don't bother to ever free this information. - find_nearest_line is either called all the time, as in - objdump -l, so the information should be saved, or it is - rarely called, as in ld error messages, so the memory - wasted is unimportant. Still, it would probably be a - good idea for free_cached_info to throw it away. */ } if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap, @@ -15079,7 +15097,10 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (! (bfd_ecoff_debug_accumulate (mdebug_handle, abfd, &debug, swap, input_bfd, &input_debug, input_swap, info))) - return false; + { + free_ecoff_debug (&input_debug); + return false; + } /* Loop through the external symbols. For each one with interesting information, try to find the symbol in @@ -15120,17 +15141,7 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info) } /* Free up the information we just read. */ - free (input_debug.line); - free (input_debug.external_dnr); - free (input_debug.external_pdr); - free (input_debug.external_sym); - free (input_debug.external_opt); - free (input_debug.external_aux); - free (input_debug.ss); - free (input_debug.ssext); - free (input_debug.external_fdr); - free (input_debug.external_rfd); - free (input_debug.external_ext); + free_ecoff_debug (&input_debug); /* Hack: reset the SEC_HAS_CONTENTS flag so that elf_link_input_bfd ignores this section. */