Bug 19123 - libbfd fails to handle > 2GB elf file on 32bit architectures
Summary: libbfd fails to handle > 2GB elf file on 32bit architectures
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-13 13:40 UTC by riku.voipio
Modified: 2015-10-15 12:00 UTC (History)
1 user (show)

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


Attachments
use file_ptr for seek position in elf files (626 bytes, patch)
2015-10-13 13:40 UTC, riku.voipio
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description riku.voipio 2015-10-13 13:40:02 UTC
Created attachment 8708 [details]
use file_ptr for seek position in elf files

Build of chrome fails on arm-linux-gnueabi plaftorm with error from strip:

strip:debian/chromium/usr/lib/chromium/chromium: File truncated

objcopy, objdump etc all fail same way. This is because the binary is over 2GB and libbfd uses a signed 32bit variable for passing seek locations:

bfd_signed_vma where = i_ehdrp->e_shoff;

The minimal fix is s/bfd_signed_vma/bfd_vma/ but considering "where" is only ever used as input for bfd_seek, and bfd_seek is defined as:

bfd_seek (bfd *abfd, file_ptr position, int direction)

Using file_ptr directly saves from some casts and makes some checks pointless. Attached patch that fixes that does it, and fixes chrome build for me. objdump, strip and objcopy handle the +2GB binary now fine. 

Patch is against 2.25.1 from Debian
Comment 1 Sourceware Commits 2015-10-15 11:57:55 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit b32a5c16f100c53fd9c0c22464f863eeeec6087a
Author: Riku Voipio <riku.voipio@iki.fi>
Date:   Thu Oct 15 12:56:55 2015 +0100

    Use the file_ptr type when calling bfd_seek.
    
    	PR ld/19123
    	* elfcore.h (elf_core_file_p): Use the file_ptr type to hold the
    	offset for bfd_seek.
    	* elfcode.h (elf_object_p): Likewise.
Comment 2 Nick Clifton 2015-10-15 12:00:42 UTC
Hi Riku,

> use file_ptr for seek position in elf files

Thanks very much for this patch.  I have checked it in along with this changelog entry.  Please let us know if you encounter any other problems like this.

Cheers
  Nick

bfd/ChangeLog
 2015-10-15  Riku Voipio  <riku.voipio@iki.fi>

	PR ld/19123
	* elfcore.h (elf_core_file_p): Use the file_ptr type to hold the
	offset for bfd_seek.
	* elfcode.h (elf_object_p): Likewise.