[binutils-gdb] mips: section .note.gnu.build-id can't be allocated in segment

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7565cfd7ad2edc1f4ba6c88c6af86e78856c5b3f

commit 7565cfd7ad2edc1f4ba6c88c6af86e78856c5b3f
Author: Alan Modra <[email protected]>
Date:   Sun May 24 14:24:36 2026 +0930

    mips: section .note.gnu.build-id can't be allocated in segment
    
    After modifying test_build_id_debuglink, mips-linux fails
    objcopy --only-keep-debug tmpdir/testprog tmpdir/testprog.debug
    with the above error.  This is due to .MIPS.abiflags and .reginfo
    being made SHT_NOBITS but the .note.gnu.build-id which follows is
    SHT_PROGBITS.  That tickles a bug in file offset tracking.
    
            * elf.c (assign_file_positions_for_load_sections): When
            resetting "off_adjust" for sections with contents following
            sections without contents, put back "off" too.

Diff:
---
 bfd/elf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bfd/elf.c b/bfd/elf.c
index dcf8f61e043..1c88c379ea0 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6335,6 +6335,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
 		{
 		  if (this_hdr->sh_type != SHT_NOBITS)
 		    {
+		      off -= off_adjust;
 		      off_adjust = 0;
 		      if (p->p_filesz + adjust < p->p_memsz)
 			{
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.