From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id DF6263858C2D; Fri, 13 May 2022 02:57:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF6263858C2D Received: by mail-pl1-x635.google.com with SMTP id q18so6670887pln.12; Thu, 12 May 2022 19:57:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=G14V0tlss6yOWzfkVpbMlJx8k9M14CnSmqE2L95oi8c=; b=22ICG813oqqw/DWHiGIVU7USk8ZD1vHJ5k5bTodk4piv79/yI4EwC6duaaxbbyYu7I P4thkurbHCnR51Oc1Iygr7s4wW0tvS0GK/4QPkUxih1ckxBUG1RcEXSxt4OzBKlqzn7u Xny5YDNrWUG/2NIZoppSbU8wPqg0HjoLJbrnMutG/SvsbFZ/ZiVT14vf5fG46lOfbq2H 9B5hEnycWAOPXQCfFOrpEGN9x/VGS+t5FA+5BuFUzZHIpqIRJqISjEdi6deJ4jpFcKMt bJ1oQANLmRoLXaPRjefR4baxbfCOTDubjKH0uLAZRHa+iPoCyctoqcUuW+YlapUtac/j 66bQ== X-Gm-Message-State: AOAM531TFWB0vcmGZCz4Bk83ZMjx6HCvSZcjJtOdILP+U4vVdI0c1vpV beLNc1UIUtXZS362I15gGN6EwMYbpDU= X-Google-Smtp-Source: ABdhPJzzqVSTA/TKMbUVAGh8HVWeY4wuuXdMrKevfR2ADpRlMHFgVzu3wHaUzZREgulethI8kNDfeQ== X-Received: by 2002:a17:90b:1894:b0:1dc:103a:3ba2 with SMTP id mn20-20020a17090b189400b001dc103a3ba2mr13765188pjb.181.1652410629964; Thu, 12 May 2022 19:57:09 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:a31e:35b7:91f1:d6b4]) by smtp.gmail.com with ESMTPSA id i76-20020a62874f000000b0050dc7628132sm563170pfe.12.2022.05.12.19.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 19:57:09 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 5A28C114007B; Fri, 13 May 2022 12:27:06 +0930 (ACST) Date: Fri, 13 May 2022 12:27:06 +0930 From: Alan Modra To: Pedro Alves Cc: gdb-patches@sourceware.org, binutils@sourceware.org Subject: Re: [PATCH] Fix "gdb --write" with core files Message-ID: References: <20220512144915.3270761-1-pedro@palves.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220512144915.3270761-1-pedro@palves.net> X-Spam-Status: No, score=-3029.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 02:57:12 -0000 On Thu, May 12, 2022 at 03:49:15PM +0100, Pedro Alves wrote: > That happens because _bfd_elf_set_section_contents does this to seek > to the section's offset: > > pos = hdr->sh_offset + offset; > if (bfd_seek (abfd, pos, SEEK_SET) != 0 > || bfd_bwrite (location, count, abfd) != count) > return false; > > ... and 'hdr->sh_offset' is zero, so we seek to just OFFSET, which is > incorrect. The reason 'hdr->sh_offset' is zero is that > kernel-generated core files normally don't even have a section header > table (gdb-generated ones do, but that's more an accident than a > feature), and indeed elf_core_file_p doesn't even try to read sections > at all: I'm a little concerned about your patch keying off both_direction. In particular it seems odd to change bfd behaviour when reading depending on whether the file was opened "r" or "r+". Did you try changing pos = hdr->sh_offset + offset; to pos = section->filepos + offset; in _bfd_elf_set_section_contents? I think that should work for you, and not break ELF targets. -- Alan Modra Australia Development Lab, IBM