[PATCH] Fix failure of 32-bit linker on large files
Maria Guseva
m.guseva@samsung.com
Thu Apr 3 09:21:00 GMT 2014
Hi all,
I've found that while linking pretty large files the bfd_seek() function may
be called with incorrect negative value of argument "position". The
"position" value is negative due to overflow in local variable of type long.
That happens in _bfd_elf_set_section_contents():
bfd_signed_vma pos;
[...]
pos = hdr->sh_offset + offset;
if (bfd_seek (abfd, pos, SEEK_SET) != 0
Both addends are of long long type, the result is used as long long as well.
Using the long type for intermediate result seems to be a bug. That leads
32-bit linker to fail for large (~2Gb) files. The Bugzilla entry for this:
https://sourceware.org/bugzilla/show_bug.cgi?id=16803
Proposed patch is attached.
Regards,
Maria
PR ld/16803
Fixed integer overflow.
* elf.c (_bfd_elf_set_section_contents): Fixed type of local
variable.
diff --git a/bfd/elf.c b/bfd/elf.c
index 3ded683..2fee9ac 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7800,7 +7800,7 @@ _bfd_elf_set_section_contents (bfd *abfd,
bfd_size_type count)
{
Elf_Internal_Shdr *hdr;
- bfd_signed_vma pos;
+ file_ptr pos;
if (! abfd->output_has_begun
&& ! _bfd_elf_compute_section_file_positions (abfd, NULL))
More information about the Binutils
mailing list