From: Alan Modra <amodra@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] Re: Update objcopy's --section-alignment option
Date: Thu, 4 Apr 2024 10:33:28 +0000 (GMT) [thread overview]
Message-ID: <20240404103328.206C43858C98@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fab240554b76603775e8a0fec45c8b5808380684
commit fab240554b76603775e8a0fec45c8b5808380684
Author: Alan Modra <amodra@gmail.com>
Date: Thu Apr 4 20:48:14 2024 +1030
Re: Update objcopy's --section-alignment option
ubsan: left shift of 1 by 31 places cannot be represented in type 'int'
* 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 *obfdarg)
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)) != 0
&& alignment != bfd_section_alignment (isection)
&& change_section_address == 0
&& ! vma_set_by_user
@@ -4352,7 +4352,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
/* 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)) != 0
&& alignment != bfd_section_alignment (isection)
&& change_section_address == 0
&& ! lma_set_by_user
next reply other threads:[~2024-04-04 10:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-04 10:33 Alan Modra [this message]
2024-04-11 7:39 Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240404103328.206C43858C98@sourceware.org \
--to=amodra@sourceware.org \
--cc=binutils-cvs@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).