From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from kwanyin.sergiodj.net (kwanyin.sergiodj.net [158.69.185.54]) by sourceware.org (Postfix) with ESMTPS id 63775385DC0B for ; Wed, 8 Apr 2020 00:44:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 63775385DC0B Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [binutils-gdb] PR25662, invalid sh_offset for first section in segment with phdrs From: gdb-buildbot@sergiodj.net To: gdb-testers@sourceware.org Message-Id: Date: Tue, 07 Apr 2020 20:44:42 -0400 X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-testers@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-testers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Apr 2020 00:44:46 -0000 *** TEST RESULTS FOR COMMIT d16e3d2e5b717cf83c1fe47a70e0a9f2c2024a44 *** commit d16e3d2e5b717cf83c1fe47a70e0a9f2c2024a44 Author: Alan Modra AuthorDate: Tue Mar 24 10:42:45 2020 +1030 Commit: Alan Modra CommitDate: Wed Mar 25 14:51:41 2020 +1030 PR25662, invalid sh_offset for first section in segment with phdrs PR 25662 * elf.c (assign_file_positions_for_load_sections): Adjust offset for SHT_NOBITS section if first in segment. diff --git a/bfd/ChangeLog b/bfd/ChangeLog index f273ea54e9..b4160c943a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-03-25 Alan Modra + + PR 25662 + * elf.c (assign_file_positions_for_load_sections): Adjust offset + for SHT_NOBITS section if first in segment. + 2020-03-24 H.J. Lu PR binutils/25708 diff --git a/bfd/elf.c b/bfd/elf.c index 2512b6543b..86dadea05c 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5833,10 +5833,11 @@ assign_file_positions_for_load_sections (bfd *abfd, } p->p_memsz += adjust; - if (this_hdr->sh_type != SHT_NOBITS) + if (p->p_type == PT_LOAD) { - if (p->p_type == PT_LOAD) + if (this_hdr->sh_type != SHT_NOBITS) { + off_adjust = 0; if (p->p_filesz + adjust < p->p_memsz) { /* We have a PROGBITS section following NOBITS ones. @@ -5846,10 +5847,25 @@ assign_file_positions_for_load_sections (bfd *abfd, if (!write_zeros (abfd, off, adjust)) return FALSE; } + } + /* We only adjust sh_offset in SHT_NOBITS sections + as would seem proper for their address when the + section is first in the segment. sh_offset + doesn't really have any significance for + SHT_NOBITS anyway, apart from a notional position + relative to other sections. Historically we + didn't bother with adjusting sh_offset and some + programs depend on it not being adjusted. See + pr12921 and pr25662. */ + if (this_hdr->sh_type != SHT_NOBITS || i == 0) + { off += adjust; + if (this_hdr->sh_type == SHT_NOBITS) + off_adjust += adjust; } - p->p_filesz += adjust; } + if (this_hdr->sh_type != SHT_NOBITS) + p->p_filesz += adjust; } if (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core)