objcopy.c: Fix bfd_copy_private_symbol_data on 32-bit hosts

Message ID 20240423141324.1156583-1-hjl.tools@gmail.com
State New
Headers
Series objcopy.c: Fix bfd_copy_private_symbol_data on 32-bit hosts |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 warning Patch is already merged

Commit Message

H.J. Lu April 23, 2024, 2:13 p.m. UTC
  Use long with bfd_copy_private_symbol_data to fix

.../binutils/objcopy.c: In
function ‘copy_object’:
.../binutils/objcopy.c:3383:17: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare]
 3383 |   for (i = 0; i < symcount; i++)
      |                 ^

on 32-bit hosts.

	PR binutils/14493
	* objcopy.c (copy_object): Use long with
	bfd_copy_private_symbol_data.
---
 binutils/objcopy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

H.J. Lu April 23, 2024, 3:30 p.m. UTC | #1
On Tue, Apr 23, 2024 at 7:13 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Use long with bfd_copy_private_symbol_data to fix
>
> .../binutils/objcopy.c: In
> function ‘copy_object’:
> .../binutils/objcopy.c:3383:17: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare]
>  3383 |   for (i = 0; i < symcount; i++)
>       |                 ^
>
> on 32-bit hosts.
>
>         PR binutils/14493
>         * objcopy.c (copy_object): Use long with
>         bfd_copy_private_symbol_data.
> ---
>  binutils/objcopy.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/binutils/objcopy.c b/binutils/objcopy.c
> index 634ebae3fc3..e8ca1374935 100644
> --- a/binutils/objcopy.c
> +++ b/binutils/objcopy.c
> @@ -3380,8 +3380,8 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
>        symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
>      }
>
> -  for (i = 0; i < symcount; i++)
> -    if (!bfd_copy_private_symbol_data (ibfd, osympp[i], obfd, osympp[i]))
> +  for (long s = 0; s < symcount; s++)
> +    if (!bfd_copy_private_symbol_data (ibfd, osympp[s], obfd, osympp[s]))
>        {
>         status = 1;
>         return false;
> --
> 2.44.0
>

Tested on Linux/x86-64 and Linux/i686.  I am checking it in.
  
Alan Modra April 23, 2024, 11:48 p.m. UTC | #2
On Tue, Apr 23, 2024 at 08:30:03AM -0700, H.J. Lu wrote:
> On Tue, Apr 23, 2024 at 7:13 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > Use long with bfd_copy_private_symbol_data to fix
> >
> > .../binutils/objcopy.c: In
> > function ‘copy_object’:
> > .../binutils/objcopy.c:3383:17: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare]
> >  3383 |   for (i = 0; i < symcount; i++)
> >       |                 ^
> >
> > on 32-bit hosts.
> >
> >         PR binutils/14493
> >         * objcopy.c (copy_object): Use long with
> >         bfd_copy_private_symbol_data.
> > ---
> >  binutils/objcopy.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/binutils/objcopy.c b/binutils/objcopy.c
> > index 634ebae3fc3..e8ca1374935 100644
> > --- a/binutils/objcopy.c
> > +++ b/binutils/objcopy.c
> > @@ -3380,8 +3380,8 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
> >        symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
> >      }
> >
> > -  for (i = 0; i < symcount; i++)
> > -    if (!bfd_copy_private_symbol_data (ibfd, osympp[i], obfd, osympp[i]))
> > +  for (long s = 0; s < symcount; s++)
> > +    if (!bfd_copy_private_symbol_data (ibfd, osympp[s], obfd, osympp[s]))
> >        {
> >         status = 1;
> >         return false;
> > --
> > 2.44.0
> >
> 
> Tested on Linux/x86-64 and Linux/i686.  I am checking it in.

Thanks.  I neglected my 32-bit --enable-targets=all build.

For anyone wondering how you can do a 32-bit build on an x86_64-linux
box, the following does the trick.

CC="gcc -m32" CXX="g++ -m32" \
~/src/binutils-gdb/configure --build=i686-linux --enable-targets=all \
--enable-gold --enable-threads --disable-gdb --disable-gdbserver --disable-sim \
--disable-readline --disable-libdecnumber --disable-libbacktrace
  

Patch

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 634ebae3fc3..e8ca1374935 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3380,8 +3380,8 @@  copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
       symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
     }
 
-  for (i = 0; i < symcount; i++)
-    if (!bfd_copy_private_symbol_data (ibfd, osympp[i], obfd, osympp[i]))
+  for (long s = 0; s < symcount; s++)
+    if (!bfd_copy_private_symbol_data (ibfd, osympp[s], obfd, osympp[s]))
       {
 	status = 1;
 	return false;