Bug 16803 - 32-bit linker fails on large file with “File truncated” message
Summary: 32-bit linker fails on large file with “File truncated” message
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-03 07:02 UTC by Maria Guseva
Modified: 2014-04-04 04:44 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (250 bytes, patch)
2014-04-03 07:02 UTC, Maria Guseva
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maria Guseva 2014-04-03 07:02:57 UTC
Created attachment 7524 [details]
Proposed patch

While linking large file (~2 Gb) with 32-bit ld the following error occurred:

ld: final link failed: File truncated

Linking the same with 64-bit linker is fine. 
The failure happened due to call of bfd_seek() function with incorrect negative value of argument "position".  The "position" value is incorrectly calculated in _bfd_elf_set_section_contents() with overflow in local variable of type long:

  bfd_signed_vma pos;
  [...]
  pos = hdr->sh_offset + offset;
  if (bfd_seek (abfd, pos, SEEK_SET) != 0

Both terms of this calculation are of type long long. The result value also is used as long long argument in bfd_seek() call.  Using the signed 32-bit type for intermediate result seems to be a bug and causes incorrect processing of large files. 
Proposed patch is attached.
Comment 1 Sourceware Commits 2014-04-03 10:44:19 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  1b6aeedbb8e8f6c65d228f0dab3dab522d2517bb (commit)
      from  92b1b67865c719e83d12578e584ca5e20d172eac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit 1b6aeedbb8e8f6c65d228f0dab3dab522d2517bb
Author: Maria Guseva <m.guseva@samsung.com>
Date:   Thu Apr 3 11:42:05 2014 +0100

    This fixes a problem building large (> 2Gb) binaries on 32-bit hosts.  Using a
    long type instead of long long meant that bfd_seek (SET) could be called with a
    negative offset.
    
    	PR ld/16803
    	* elf.c (_bfd_elf_set_section_contents): Use correct type to hold
    	file position.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog |    6 ++++++
 bfd/elf.c     |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
Comment 2 Alan Modra 2014-04-04 04:44:07 UTC
Patch applied.