Bug 14625

Summary: [2.23/2.24 regression] ar: File truncated
Product: binutils Reporter: Matthias Klose <doko>
Component: binutilsAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: amodra, hjl.tools
Priority: P2    
Version: 2.23   
Target Milestone: 2.27   
Host: Target:
Build: Last reconfirmed:

Description Matthias Klose 2012-09-25 22:34:16 UTC
seen with a webkit-1.91 build on x86_64-linux-gnu, works with 2.22 from the release branch, fails with the 2.23 branch and trunk.

ar: .libs/libWebCore.a: File truncated
make[1]: *** [libWebCore.la] Error 1

to reproduce with the tarball from
http://people.debian.org/~doko/tmp/build.tar.xz

mkdir -p .libs
rm -f .libs/libWebCore.a
sh ar.sh
Comment 1 Alan Modra 2012-09-26 02:23:17 UTC
You're running into archive.c:2661
	  /* Catch an attempt to grow an archive past its 4Gb limit.  */
	  if (archive_member_file_ptr != (file_ptr) offset)
	    {
	      bfd_set_error (bfd_error_file_truncated);
	      return FALSE;
	    }
	  if (!bfd_write_bigendian_4byte_int (arch, offset))
	    return FALSE;

Previous versions of binutils created invalid armaps.  We can't do much about this problem without changing archive format for x86_64.  I suppose that is a possibility.

If you just want an archive for packaging purposes as distinct from using the archive as a linker input, then you can work around this problem by disabling the armap with ar's S option.

I'm closing this bug report as invalid since the archive format simply doesn't support such large archives.  Please take any discussion (patches!) regarding changing archive format to the binutils list.
Comment 2 Sourceware Commits 2016-05-25 16:49:20 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e6cc316af931911da20249e19f9342e5cf8aeeff

commit e6cc316af931911da20249e19f9342e5cf8aeeff
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed May 25 09:46:47 2016 -0700

    Enable 64-bit archives in ar and ranlib
    
    Since existing ld and gold support the 64-bit (MIPS) ELF archives, we
    can use the 64-bit (MIPS) ELF archives as 64-bit archives.  Since the
    plugin target is used to create archive in plugin-enabled ar, we need
    a way to enable 64-bit archives in the plugin target.  This patch adds
    --enable-64-bit-archive to bfd to force 64-bit archives in ar and
    ranlib.  Since both 64-bit MIPS and s390 ELF targets currently use
    64-bit archives, 64-bit archives are enabled by default for them.
    64-bit archive is generated automatically if the archive is too big.
    
    Tested on Linux/x86 and Linux/x86-64 with existing ld and gold.
    
    bfd/
    
    	PR binutils/14625
    	* archive.c (bfd_slurp_armap): Replace
    	bfd_elf64_archive_slurp_armap with
    	_bfd_archive_64_bit_slurp_armap.
    	(bsd_write_armap): Call _bfd_archive_64_bit_write_armap if
    	BFD64 is defined and the archive is too big.
    	(coff_write_armap): Likewise.
    	* archive64.c (bfd_elf64_archive_slurp_armap): Renamed to ...
    	(_bfd_archive_64_bit_slurp_armap): This.
    	(bfd_elf64_archive_write_armap): Renamed to ...
    	(_bfd_archive_64_bit_write_armap): This.
    	* configure.ac: Add --enable-64-bit-archive.
    	(want_64_bit_archive): New.  Set to true by default for 64-bit
    	MIPS and s390 ELF targets.
    	(USE_64_BIT_ARCHIVE): New AC_DEFINE.
    	* config.in: Regenerated.
    	* configure: Likewise.
    	* elf64-mips.c (bfd_elf64_archive_functions): Removed.
    	(bfd_elf64_archive_slurp_armap): Likewise.
    	(bfd_elf64_archive_write_armap): Likewise.
    	(bfd_elf64_archive_slurp_extended_name_table): Likewise.
    	(bfd_elf64_archive_construct_extended_name_table): Likewise.
    	(bfd_elf64_archive_truncate_arname): Likewise.
    	(bfd_elf64_archive_read_ar_hdr): Likewise.
    	(bfd_elf64_archive_write_ar_hdr): Likewise.
    	(bfd_elf64_archive_openr_next_archived_file): Likewise.
    	(bfd_elf64_archive_get_elt_at_index): Likewise.
    	(bfd_elf64_archive_generic_stat_arch_elt): Likewise.
    	(bfd_elf64_archive_update_armap_timestamp): Likewise.
    	* elf64-s390.c (bfd_elf64_archive_functions): Removed.
    	(bfd_elf64_archive_slurp_armap): Likewise.
    	(bfd_elf64_archive_write_armap): Likewise.
    	(bfd_elf64_archive_slurp_extended_name_table): Likewise.
    	(bfd_elf64_archive_construct_extended_name_table): Likewise.
    	(bfd_elf64_archive_truncate_arname): Likewise.
    	(bfd_elf64_archive_read_ar_hdr): Likewise.
    	(bfd_elf64_archive_write_ar_hdr): Likewise.
    	(bfd_elf64_archive_openr_next_archived_file): Likewise.
    	(bfd_elf64_archive_get_elt_at_index): Likewise.
    	(bfd_elf64_archive_generic_stat_arch_elt): Likewise.
    	(bfd_elf64_archive_update_armap_timestamp): Likewise.
    	* elfxx-target.h (TARGET_BIG_SYM): Use _bfd_archive_64_bit on
    	BFD_JUMP_TABLE_ARCHIVE if USE_64_BIT_ARCHIVE is defined and
    	bfd_elfNN_archive_functions isn't defined.
    	(TARGET_LITTLE_SYM): Likewise.
    	* libbfd-in.h (_bfd_archive_64_bit_slurp_armap): New prototype.
    	(_bfd_archive_64_bit_write_armap): Likewise.
    	(_bfd_archive_64_bit_slurp_extended_name_table): New macro.
    	(_bfd_archive_64_bit_construct_extended_name_table): Likewise.
    	(_bfd_archive_64_bit_truncate_arname): Likewise.
    	(_bfd_archive_64_bit_read_ar_hdr): Likewise.
    	(_bfd_archive_64_bit_write_ar_hdr): Likewise.
    	(_bfd_archive_64_bit_openr_next_archived_file): Likewise.
    	(_bfd_archive_64_bit_get_elt_at_index): Likewise.
    	(_bfd_archive_64_bit_generic_stat_arch_elt): Likewise.
    	(_bfd_archive_64_bit_update_armap_timestamp): Likewise.
    	* libbfd.h: Regenerated.
    	* plugin.c (plugin_vec): Use _bfd_archive_64_bit on
    	BFD_JUMP_TABLE_ARCHIVE if USE_64_BIT_ARCHIVE is defined.
    
    binutils/
    
    	PR binutils/14625
    	* NEWS: Mention --enable-64-bit-archive.
Comment 3 H.J. Lu 2016-05-25 17:08:26 UTC
Reopened.
Comment 4 H.J. Lu 2016-05-25 17:09:04 UTC
Fixed for 2.27.
Comment 5 Sourceware Commits 2016-12-23 13:55:16 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=865422fafaf387745b2979d47b6f448d28e0edb8

commit 865422fafaf387745b2979d47b6f448d28e0edb8
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Dec 22 13:12:07 2016 +1030

    hppa-linux-gnu-ranlib: libcpp.a: File format not recognized
    
    This stops an --enable-targets selection affecting the main target in
    regards to forcing 64-bit archives.  It also means mips64 and s390x
    will revert to binutils-2.25 and binutils-2.26 behaviour of not
    forcing 64-bit archives at least in the common case when plugins were
    enabled.
    
    	PR binutils/20464
    	PR binutils/14625
    	* configure.ac: Revert 2016-05-25 configure change setting
    	want_64_bit_archive for mips64 and s390x.  Revise USE_64_BIT_ARCHIVE
    	description.
    	* configure: Regenerate.
    	* config.in: Regenerate.
Comment 6 Sourceware Commits 2016-12-23 14:37:20 UTC
The binutils-2_28-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c525439b57708cbf0871ebd9a81be5d6016a144b

commit c525439b57708cbf0871ebd9a81be5d6016a144b
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Dec 22 13:12:07 2016 +1030

    hppa-linux-gnu-ranlib: libcpp.a: File format not recognized
    
    This stops an --enable-targets selection affecting the main target in
    regards to forcing 64-bit archives.  It also means mips64 and s390x
    will revert to binutils-2.25 and binutils-2.26 behaviour of not
    forcing 64-bit archives at least in the common case when plugins were
    enabled.
    
    	PR binutils/20464
    	PR binutils/14625
    	* configure.ac: Revert 2016-05-25 configure change setting
    	want_64_bit_archive for mips64 and s390x.  Revise USE_64_BIT_ARCHIVE
    	description.
    	* configure: Regenerate.
    	* config.in: Regenerate.