* [binutils-gdb] Re: Update objcopy's --section-alignment option
@ 2024-04-11 7:39 Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2024-04-11 7:39 UTC (permalink / raw)
To: binutils-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ef70c9e7b26ec5e95b073944a9ed19d495c4fe88
commit ef70c9e7b26ec5e95b073944a9ed19d495c4fe88
Author: Alan Modra <amodra@gmail.com>
Date: Thu Apr 11 13:12:21 2024 +0930
Re: Update objcopy's --section-alignment option
ubsan: shift exponent 255 is too large for 64-bit type
I should have known oss-fuzz wouldn't be satisfied so easily. The pef
format allows quite silly section alignments in object files.
* 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 *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 & (((bfd_vma) 1 << alignment) - 1)) != 0
+ if (osection->vma != 0
+ && (alignment >= sizeof (bfd_vma) * CHAR_BIT
+ || (osection->vma & (((bfd_vma) 1 << alignment) - 1)) != 0)
&& alignment != bfd_section_alignment (isection)
&& change_section_address == 0
&& ! vma_set_by_user
@@ -4352,7 +4354,9 @@ 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 & (((bfd_vma) 1 << alignment) - 1)) != 0
+ if (osection->lma != 0
+ && (alignment >= sizeof (bfd_vma) * CHAR_BIT
+ || (osection->lma & (((bfd_vma) 1 << alignment) - 1)) != 0)
&& alignment != bfd_section_alignment (isection)
&& change_section_address == 0
&& ! lma_set_by_user
^ permalink raw reply [flat|nested] 2+ messages in thread
* [binutils-gdb] Re: Update objcopy's --section-alignment option
@ 2024-04-04 10:33 Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2024-04-04 10:33 UTC (permalink / raw)
To: binutils-cvs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-11 7:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 7:39 [binutils-gdb] Re: Update objcopy's --section-alignment option Alan Modra
-- strict thread matches above, loose matches on Subject: below --
2024-04-04 10:33 Alan Modra
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).