Binutils causes abnormally large, non-working binaries since 2.43

Bastiaan Timmer basjetimmer@yahoo.com
Fri Mar 7 21:40:30 GMT 2025


On 07-03-2025 12:25, Jan Beulich wrote:
> That commit touching objcopy.c only (as to what's relevant for the writing
> of object files), there must be a use of objcopy or strip somewhere. The
> build logs you provided, however, don't have any indication thereof. Gcc
> would use objcopy when passed -gsplit-dwarf, but that doesn't even look to
> be potentially applicable here (iirc split debug info is only an option
> with ELF).
>
> Further I tried both Cygwin and MinGW objcopy on a random (small) object,
> without passing any --section-alignment option of course. That didn't
> change the object at all. If I pass --section-alignment, I can see the
> provided value taking effect. I wonder whether that's really intended for
> COFF objects; it looks to me as if it's solely intended for COFF/PE
> binaries.
>
> Would you mind trying with the simple patch below? If that makes a
> difference, we'd then still need to understand how objcopy (or strip)
> comes into play here in the first place. Depending on where it's used and
> how, this or another change may be warranted.
>
> Jan
>
> --- a/binutils/objcopy.c
> +++ b/binutils/objcopy.c
> @@ -4301,7 +4301,8 @@ setup_section (bfd *ibfd, sec_ptr isecti
>       alignment = p->alignment;
>     else if (pe_section_alignment != (bfd_vma) -1
>   	   && bfd_get_flavour (ibfd) == bfd_target_coff_flavour
> -	   && bfd_get_flavour (obfd) == bfd_target_coff_flavour)
> +	   && bfd_get_flavour (obfd) == bfd_target_coff_flavour
> +	   && bfd_pei_p (obfd))
>       {
>         alignment = power_of_two (pe_section_alignment);
>   

Thank you for taking the time to look into this further.

Looking at the PKGBUILD (a small configuration file, that is used on 
Arch Linux to build packages), I see the packaging-step runs:

      find "${pkgdir}/usr/${_arch}" -name '*.exe' -exec ${_arch}-strip {} \;
      find "${pkgdir}/usr/${_arch}" -name '*.dll' -exec ${_arch}-strip 
--strip-unneeded {} \;
      find "${pkgdir}/usr/${_arch}" -name '*.a' -o -name '*.dll' | xargs 
${_arch}-strip -g

Where `${_arch}-strip' would expand to 'x86_64-w64-mingw32-strip' (or 
similar for i686). Would that explain the apparent use of objcopy? For 
reference, the PKGBUILD can be found here: 
https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=mingw-w64-openssl

I have built two versions of mingw-w64-openssl, one with the upstream 
2.44 version of binutils (I had only tried up until 2.43 before), and 
one with version 2.44 with your patch applied. I am happy to report your 
tiny patch also appears to solve the issues. The size of the openssl 
libraries is back to normal when compiled with 2.44_patched, and 
binaries linked to these openssl libraries successfully run on Windows.

I have opened a bug about this issue about two weeks ago (here: 
https://sourceware.org/bugzilla/show_bug.cgi?id=32732). I assume this 
info is useful there, maybe you want to chime in? Or, of course, I'd be 
happy to report these latest findings myself if you prefer.

Thanks again!

Bas


More information about the Binutils mailing list