From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 206C43858C98; Thu, 4 Apr 2024 10:33:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 206C43858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712226808; bh=IIdTb9TAgZPRBhJda+WzuLP21ANAYUz/LX5aFoLKdlo=; h=From:To:Subject:Date:From; b=UCe9Z1IiTMUos7jxWcVMOafyXK9vuBQkY85GYPg8z+QxWjnNClpAsLfMgWgQuJvaR JlfaBRCGf0FoS/9oGlpLqbTYlBApljnKCFaaELGDbwbzCVP3r/fzOVAM++rsZWvxrm m8bNYgRTwL2isNpoIMP+73QVOyTTh7gBYhFSiZEs= 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: 1bc2544b895f001cef00c9d71e70557dacb8ee55 X-Git-Newrev: fab240554b76603775e8a0fec45c8b5808380684 Message-Id: <20240404103328.206C43858C98@sourceware.org> Date: Thu, 4 Apr 2024 10:33:28 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfab240554b76= 603775e8a0fec45c8b5808380684 commit fab240554b76603775e8a0fec45c8b5808380684 Author: Alan Modra Date: Thu Apr 4 20:48:14 2024 +1030 Re: Update objcopy's --section-alignment option =20 ubsan: left shift of 1 by 31 places cannot be represented in type 'int' =20 * objcopy.c (setup_section): Avoid undefined behaviour when checking vma and lma for alignment. Diff: --- binutils/objcopy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 77ab9080946..d9abfdfbb39 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4340,7 +4340,7 @@ 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 & ((1 << alignment) - 1) + if ((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 +4352,7 @@ 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 & ((1 << alignment) - 1) + if ((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