From patchwork Wed Feb 8 23:13:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 54633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3740717wrn; Wed, 8 Feb 2023 15:13:26 -0800 (PST) X-Google-Smtp-Source: AK7set9xHGkiFdP2Wa1FnQEZLF6U3lcMAm2TlHcKGnvyWLTS2DP36pwV009NQS88T6JPmfv/L6cG X-Received: by 2002:a17:906:7f98:b0:884:3174:119d with SMTP id f24-20020a1709067f9800b008843174119dmr10714822ejr.14.1675898006172; Wed, 08 Feb 2023 15:13:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675898006; cv=none; d=google.com; s=arc-20160816; b=t9Nupb1ih9UGFepghRwsyvw8N+LVatSDOwkUlt/ByDWyQuqdb1/3z9dBzcaDytJN2s tyEzih+ZrpI8I5CF59EtJIFVsWHJRvKadQC7pV3gXIgFnnxXRoTCnEwXPEcb5NENVDTy qF/P1aUqRY3SHWxlP0vLiixqo3+xz8I5lKuEYZDqhStaL9sxbD6dApnuUiMXWK86irvL SrQmPxzhTV3L9INkTBpwT/CFayDxjVVBINYCAuv+PKqnDRNLc0YS9S0JD2MlMOpoWX+g 2sIqmoYVb4dDA41DL9n5gI3kquWAzs9pt/A9mzjUEDUVDtHcO6hLnWO3wqCmoMqas0uF p5nw== 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=2X1+ljGAfpsEg3LibmokOF0UZR8HfFC5pbJOyLrK3Rc=; b=G4Ko+Rv2RbeSVdio3FJMtYqOnpY0FvImL/ZrSd1k///bOiX/Dxm3qNHo1XMbdDsyXV Wv19r9XwA/RsQF32QsiN2J5VlGvWX0suWNcy99axJW7lFyGDmVjoj/MmnrVGVnyzJsM/ EN7y+nRHaTTGbhVjVw5dWGUc8bvMUB4FIp0UQiK2pc2kKH9Dp4lQDvXwHLWpo8kGOFVs SAmuMVOLsuRnjy4E/Z/Z48bGCw6sCYXtyc+o6jgfVuLcCcufUpbIYL96/ZIJFByUFzK6 SfLkMcC4SKrjNAv2VRNLMQwBvhg8Dd+0UyybG4wRXdaLx5n/FCWCUhS7Ffz1mmKBJbNY AiMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MN0VTHrq; 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 fb23-20020a1709073a1700b0088e6b7aff33si179324ejc.631.2023.02.08.15.13.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 15:13:26 -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=MN0VTHrq; 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 B2F753858017 for ; Wed, 8 Feb 2023 23:13:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2F753858017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675898002; bh=2X1+ljGAfpsEg3LibmokOF0UZR8HfFC5pbJOyLrK3Rc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MN0VTHrqjkgwpYym28SHamk6UQe3dGCahjcEbsKMTd5UzyVr5pe/NcSfWnAOo8uUH PmgNIBqGoG9LTZCyJ7ibphub5PPJ6KhL9EzzDHPTrhWimUC1DyInfWTL7BM2T4pSIT gYOkkqvkbZ670QzYgJi4qoXvYuzExTvYEZ7METTU= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 067383858D39 for ; Wed, 8 Feb 2023 23:13:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 067383858D39 Received: by mail-pj1-x102b.google.com with SMTP id ki19-20020a17090ae91300b00232cba666bbso748128pjb.2 for ; Wed, 08 Feb 2023 15:13:13 -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=2X1+ljGAfpsEg3LibmokOF0UZR8HfFC5pbJOyLrK3Rc=; b=JRHZ2lE3k7zqRJuORhfs9cWyqQjF5I5Q3dTUlb0bVfPcCKWsgQt22/mkQiaPEBwSHh kINNegn9gIbgeRQjAndcTpHvDK2O1tElLqKZQ9qgeGvp5bB84wNZJZjH9X02EA1ZvBcf zGQd4IbBpYAUeqSC5LQL/qscMHdXU46eJW5nCuKtCe3hW8qDf8E6M4KQBKwfLmvLfejd Z0kBBxTzMftT2rGasajGDR8osL+7McN9GSGKZU8kbJkYo5eZ6zYIhwWTlRpXQg2aeDij O8iC4Krlnm9Ft/7k0y/z9w1gBElr0C1xG68Sd15VfBp7zC6dLGj4Fg6JGuU0rhz96lfF 2M6Q== X-Gm-Message-State: AO0yUKVa1J5MmsOByXpYDsu9Z3DQLeifmIhMx65sylwzjLe/rS2mclpa 88Wi/gH9EgiN1sZFkxXt6x7OMn3qXWI= X-Received: by 2002:a17:902:ec90:b0:198:dae9:5f58 with SMTP id x16-20020a170902ec9000b00198dae95f58mr3713831plg.14.1675897992587; Wed, 08 Feb 2023 15:13:12 -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 c5-20020a170902d90500b001948ff5cc32sm9522276plz.215.2023.02.08.15.13.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 15:13:12 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 473551142D73; Thu, 9 Feb 2023 09:43:09 +1030 (ACDT) Date: Thu, 9 Feb 2023 09:43:09 +1030 To: binutils@sourceware.org Subject: Clear cached file size when bfd changed to BFD_IN_MEMORY Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.6 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?1757306427762605237?= X-GMAIL-MSGID: =?utf-8?q?1757306427762605237?= If file size is calculated by bfd_get_file_size, as it is by _bfd_alloc_and_read calls in coff_object_p, then it is cached and when pe_ILF_build_a_bfd converts an archive entry over to BFD_IN_MEMORY, the file size is no longer valid. Found when attempting objdump -t on a very small (27 bytes) ILF file and hitting the pr24707 fix (commit 781152ec18f5). So, clear file size when setting BFD_IN_MEMORY on bfds that may have been read. (It's not necessary in writable bfds, because caching is ignored by bfd_get_size when bfd_write_p.) I also think the PR 24707 fix is no longer neeeded. All of the testcases in that PR and in PR24712 are caught earlier by file size checks when reading the symbols from file. So I'm reverting that fix, which just compared the size of an array of symbol pointers against file size. That's only valid if on-disk symbols are larger than a host pointer, so the test is better done in format-specific code. bfd/ * coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Clear cached file size when making a BFD_IN_MEMORY bfd. * opncls.c (bfd_make_readable): Likewise. * peicode.h (pe_ILF_build_a_bfd): Likewise. binutils/ PR 24707 * objdump.c (slurp_symtab): Revert PR24707 fix. Tidy. (slurp_dynamic_symtab): Tidy. diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c index 61dc05e805d..45b3f760f55 100644 --- a/bfd/coff-alpha.c +++ b/bfd/coff-alpha.c @@ -2174,6 +2174,7 @@ alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos, nbfd->iostream = bim; nbfd->iovec = &_bfd_memory_iovec; nbfd->origin = 0; + nbfd->size = 0; BFD_ASSERT (! nbfd->cacheable); return nbfd; diff --git a/bfd/opncls.c b/bfd/opncls.c index 6ae3af054e4..4dbd30d2fe9 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -987,6 +987,7 @@ bfd_make_readable (bfd *abfd) abfd->symcount = 0; abfd->outsymbols = 0; abfd->tdata.any = 0; + abfd->size = 0; bfd_section_list_clear (abfd); bfd_check_format (abfd, bfd_object); diff --git a/bfd/peicode.h b/bfd/peicode.h index 22ffec989f2..fef7d0dd69b 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -1105,6 +1105,7 @@ pe_ILF_build_a_bfd (bfd * abfd, abfd->iovec = &_bfd_memory_iovec; abfd->where = 0; abfd->origin = 0; + abfd->size = 0; obj_sym_filepos (abfd) = 0; /* Now create a symbol describing the imported value. */ diff --git a/binutils/objdump.c b/binutils/objdump.c index 9e76684c071..4292c23a9ab 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -994,45 +994,22 @@ dump_headers (bfd *abfd) static asymbol ** slurp_symtab (bfd *abfd) { - asymbol **sy = NULL; - long storage; - + symcount = 0; if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) - { - symcount = 0; - return NULL; - } + return NULL; - storage = bfd_get_symtab_upper_bound (abfd); + long storage = bfd_get_symtab_upper_bound (abfd); if (storage < 0) { - non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd)); + non_fatal (_("failed to read symbol table from: %s"), + bfd_get_filename (abfd)); bfd_fatal (_("error message was")); } - if (storage) - { - off_t filesize = bfd_get_file_size (abfd); - - /* qv PR 24707. */ - if (filesize > 0 - && filesize < storage - /* The MMO file format supports its own special compression - technique, so its sections can be larger than the file size. */ - && bfd_get_flavour (abfd) != bfd_target_mmo_flavour) - { - bfd_nonfatal_message (bfd_get_filename (abfd), abfd, NULL, - _("error: symbol table size (%#lx) " - "is larger than filesize (%#lx)"), - storage, (long) filesize); - exit_status = 1; - symcount = 0; - return NULL; - } - - sy = (asymbol **) xmalloc (storage); - } + if (storage == 0) + return NULL; + asymbol **sy = (asymbol **) xmalloc (storage); symcount = bfd_canonicalize_symtab (abfd, sy); if (symcount < 0) bfd_fatal (bfd_get_filename (abfd)); @@ -1044,26 +1021,24 @@ slurp_symtab (bfd *abfd) static asymbol ** slurp_dynamic_symtab (bfd *abfd) { - asymbol **sy = NULL; - long storage; - - storage = bfd_get_dynamic_symtab_upper_bound (abfd); + dynsymcount = 0; + long storage = bfd_get_dynamic_symtab_upper_bound (abfd); if (storage < 0) { if (!(bfd_get_file_flags (abfd) & DYNAMIC)) { non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd)); exit_status = 1; - dynsymcount = 0; return NULL; } bfd_fatal (bfd_get_filename (abfd)); } - if (storage) - sy = (asymbol **) xmalloc (storage); + if (storage == 0) + return NULL; + asymbol **sy = (asymbol **) xmalloc (storage); dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); if (dynsymcount < 0) bfd_fatal (bfd_get_filename (abfd));