From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id A19433857832; Fri, 29 Jul 2022 13:58:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A19433857832 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Re: PR16005, avr linker crash on a particular instruction sequence with --relax X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 76a4c1e063fabb45d15597a6dd17813e92875a43 X-Git-Newrev: 10948fb9fd66c029d59c97e04556ab827076336c Message-Id: <20220729135827.A19433857832@sourceware.org> Date: Fri, 29 Jul 2022 13:58:27 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2022 13:58:27 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D10948fb9fd66= c029d59c97e04556ab827076336c commit 10948fb9fd66c029d59c97e04556ab827076336c Author: Alan Modra Date: Fri Jul 29 22:35:13 2022 +0930 Re: PR16005, avr linker crash on a particular instruction sequence with= --relax =20 The last patch wasn't so clever. The contents in fact have already been read, just not cached where relax_delete_bytes expects them. relax_delete_bytes also modifies relocs and syms, so they should be cached too. =20 PR 16005 * elf32-avr.c (elf32_avr_relax_delete_bytes): Revert last chang= e. (elf32_avr_relax_section): Cache contents, relocs and syms before calling relax_delete_bytes. Diff: --- bfd/elf32-avr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c index 3a1d238e707..8c003d0553b 100644 --- a/bfd/elf32-avr.c +++ b/bfd/elf32-avr.c @@ -1927,9 +1927,6 @@ elf32_avr_relax_delete_bytes (bfd *abfd, symtab_hdr =3D &elf_tdata (abfd)->symtab_hdr; sec_shndx =3D _bfd_elf_section_from_bfd_section (abfd, sec); contents =3D elf_section_data (sec)->this_hdr.contents; - if (contents =3D=3D NULL - && !bfd_malloc_and_get_section (abfd, sec, &contents)) - return false; relax_info =3D get_avr_relax_info (sec); =20 toaddr =3D sec->size; @@ -3071,6 +3068,10 @@ elf32_avr_relax_section (bfd *abfd, "at address 0x%x deleted.\n", (int) dot + insn_size); =20 + elf_section_data (sec)->relocs =3D internal_relocs; + elf_section_data (sec)->this_hdr.contents =3D contents; + symtab_hdr->contents =3D (unsigned char *) isymbuf; + /* Delete two bytes of data. */ if (!elf32_avr_relax_delete_bytes (abfd, sec, irel->r_offset + insn_size, 2,