From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 8D64F384AB61; Thu, 11 Apr 2024 07:39:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D64F384AB61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712821183; bh=wr0RxHc240coMkaNiOzmvz6r8qhUjtGTTxle/WDsCCA=; h=From:To:Subject:Date:From; b=CcqbE0ZLTGQBVXjZB+/dEEbfogFw51E1uUhUxK9Vhs1MSxJu5hCa4kf5T2KC+Cy7j GvCVJ1/hMxiCUauJcvAbjIVE9VIP+pSrk8MwWoQm/GOIkYg3o6jDvX92+tA8UEBrBf G7P01mHGG3xuJ0gtn6WQDedPiyX1NBF17q+9OjXI= 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] Re: Update objcopy's --section-alignment option X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: bf649e72d3d5bc0784080438f550095d71769904 X-Git-Newrev: ef70c9e7b26ec5e95b073944a9ed19d495c4fe88 Message-Id: <20240411073943.8D64F384AB61@sourceware.org> Date: Thu, 11 Apr 2024 07:39:43 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Def70c9e7b26e= c5e95b073944a9ed19d495c4fe88 commit ef70c9e7b26ec5e95b073944a9ed19d495c4fe88 Author: Alan Modra Date: Thu Apr 11 13:12:21 2024 +0930 Re: Update objcopy's --section-alignment option =20 ubsan: shift exponent 255 is too large for 64-bit type =20 I should have known oss-fuzz wouldn't be satisfied so easily. The pef format allows quite silly section alignments in object files. =20 * objcopy.c (setup_section): Limit shift exponent when checking vma and lma for alignment. Diff: --- binutils/objcopy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/binutils/objcopy.c b/binutils/objcopy.c index d9abfdfbb39..d91ba123c01 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4340,7 +4340,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obf= darg) and the VMA was not set by the user and the section does not have relocations associated with it then warn the user. */ - if ((osection->vma & (((bfd_vma) 1 << alignment) - 1)) !=3D 0 + if (osection->vma !=3D 0 + && (alignment >=3D sizeof (bfd_vma) * CHAR_BIT + || (osection->vma & (((bfd_vma) 1 << alignment) - 1)) !=3D 0) && alignment !=3D bfd_section_alignment (isection) && change_section_address =3D=3D 0 && ! vma_set_by_user @@ -4352,7 +4354,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obf= darg) /* Similar check for a non-aligned LMA. FIXME: Since this is only an LMA, maybe it does not matter if it is not aligned ? */ - if ((osection->lma & (((bfd_vma) 1 << alignment) - 1)) !=3D 0 + if (osection->lma !=3D 0 + && (alignment >=3D sizeof (bfd_vma) * CHAR_BIT + || (osection->lma & (((bfd_vma) 1 << alignment) - 1)) !=3D 0) && alignment !=3D bfd_section_alignment (isection) && change_section_address =3D=3D 0 && ! lma_set_by_user