From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 5C0253858C32; Thu, 4 Apr 2024 04:30:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C0253858C32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712205009; bh=3wI5d9SOTrVOmpZX0z3P8VRKGzBXlvlNUnE8/nAWqvk=; h=From:To:Subject:Date:From; b=k9zSZb0ZV8i75j6b7uw4f9sPISrShKkj985VnibsOt4ZJQW0SKz0YfsYRF3/cokM+ y+5d+Y+VLw++drovlH2ZMbFKsP6WcL+PwyEVTA/E31lX/hkqy30VJk+wfz4JEj5Pr2 HkMNIE+nbOGkURMJmLcyaoLDEvh921b8WLKK+VIo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: binutils-cvs@sourceware.org Subject: [binutils-gdb] Memory corruption with USE_MMAP X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 0ab0435fe672b76f0efb8814594b65c8e968d983 X-Git-Newrev: b43b352837ea11af64ea83754b06f0e8d335706e Message-Id: <20240404043009.5C0253858C32@sourceware.org> Date: Thu, 4 Apr 2024 04:30:09 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db43b352837ea= 11af64ea83754b06f0e8d335706e commit b43b352837ea11af64ea83754b06f0e8d335706e Author: Alan Modra Date: Thu Apr 4 14:39:14 2024 +1030 Memory corruption with USE_MMAP =20 mips64-linux-gnuabi64 +FAIL: GOT page 4 (two files) mipsel-linux-gnu +FAIL: GOT page 4 (two files) mipsisa32el-linux-gnu +FAIL: GOT page 4 (two files) mips-linux-gnu +FAIL: GOT page 4 (two files) powerpc64-freebsd +FAIL: relocatable relaxing large powerpc64le-linux-gnu +FAIL: relocatable relaxing large powerpc64-linux-gnu +FAIL: relocatable relaxing large powerpc-eabisim +FAIL: relocatable relaxing large powerpc-eabivle +FAIL: relocatable relaxing large powerpc-freebsd +FAIL: relocatable relaxing large powerpcle-elf +FAIL: relocatable relaxing large powerpc-linux-gnu +FAIL: relocatable relaxing large =20 * elflink.c (bfd_elf_final_link): Heed bed->use_mmap when sizing buffers, not just USE_MMAP. Diff: --- bfd/elflink.c | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index dd7ae1705b6..fa1f1273d15 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12490,18 +12490,23 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_in= fo *info) section, so that we know the sizes of the reloc sections. We also figure out some maximum sizes. */ #ifdef USE_MMAP - /* Mmap is used only if section size >=3D the minimum mmap section - size. The initial max_contents_size value covers all sections - smaller than the minimum mmap section size. It may be increased - for compressed or linker created sections or sections whose - rawsize !=3D size. max_external_reloc_size covers all relocation - sections smaller than the minimum mmap section size. */ - max_contents_size =3D _bfd_minimum_mmap_size; - max_external_reloc_size =3D _bfd_minimum_mmap_size; -#else - max_contents_size =3D 0; - max_external_reloc_size =3D 0; + if (bed->use_mmap) + { + /* Mmap is used only if section size >=3D the minimum mmap section + size. The initial max_contents_size value covers all sections + smaller than the minimum mmap section size. It may be increased + for compressed or linker created sections or sections whose + rawsize !=3D size. max_external_reloc_size covers all relocation + sections smaller than the minimum mmap section size. */ + max_contents_size =3D _bfd_minimum_mmap_size; + max_external_reloc_size =3D _bfd_minimum_mmap_size; + } + else #endif + { + max_contents_size =3D 0; + max_external_reloc_size =3D 0; + } max_internal_reloc_count =3D 0; max_sym_count =3D 0; max_sym_shndx_count =3D 0; @@ -12538,9 +12543,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_inf= o *info) #ifdef USE_MMAP /* Mmap is used only on non-compressed, non-linker created sections whose rawsize =3D=3D size. */ - if (sec->compress_status !=3D COMPRESS_SECTION_NONE - || (sec->flags & SEC_LINKER_CREATED) !=3D 0 - || sec->rawsize !=3D sec->size) + if (!bed->use_mmap + || sec->compress_status !=3D COMPRESS_SECTION_NONE + || (sec->flags & SEC_LINKER_CREATED) !=3D 0 + || sec->rawsize !=3D sec->size) #endif { if (sec->rawsize > max_contents_size) @@ -12592,17 +12598,20 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_in= fo *info) =20 if ((sec->flags & SEC_RELOC) !=3D 0) { -#ifndef USE_MMAP - size_t ext_size =3D 0; +#ifdef USE_MMAP + if (!bed->use_mmap) +#endif + { + size_t ext_size =3D 0; =20 - if (esdi->rel.hdr !=3D NULL) - ext_size =3D esdi->rel.hdr->sh_size; - if (esdi->rela.hdr !=3D NULL) - ext_size +=3D esdi->rela.hdr->sh_size; + if (esdi->rel.hdr !=3D NULL) + ext_size =3D esdi->rel.hdr->sh_size; + if (esdi->rela.hdr !=3D NULL) + ext_size +=3D esdi->rela.hdr->sh_size; =20 - if (ext_size > max_external_reloc_size) - max_external_reloc_size =3D ext_size; -#endif + if (ext_size > max_external_reloc_size) + max_external_reloc_size =3D ext_size; + } if (sec->reloc_count > max_internal_reloc_count) max_internal_reloc_count =3D sec->reloc_count; }