Bug 23517

Summary: fileread: Fails to handle short reads with vector I/O
Product: binutils Reporter: d.c.ddcc
Component: goldAssignee: Cary Coutant <ccoutant>
Status: UNCONFIRMED ---    
Severity: normal CC: d.c.ddcc, ian
Priority: P2    
Version: 2.30   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description d.c.ddcc 2018-08-13 05:34:08 UTC
On an armhf system running Ubuntu 18.04 with binutils 2.30, I occasionally receive some variant of the following error when linking code over an NFSv4 filesystem:

/usr/bin/arm-linux-gnueabihf-ld.gold: fatal error: build/opt/mongo/db/fts/fts_element_iterator.o: file too short: read only 18202 of 26977 bytes at 137446

This appears to be generated by File_read::do_readv() inside gold/fileread.cc, when the return value of readv() is smaller than expected.

ssize_t got = ::readv(this->descriptor_, iov, iov_index);
if (got != want)
  gold_fatal(_("%s: file too short: read only %zd of %zd bytes at %lld"),
	       got, want, static_cast<long long>(base + first_offset));

According to the documentation of readv(), this is not necessarily an error:

Note that it is not an error for a successful call to transfer fewer bytes than requested (see read(2) and write(2)).

As background, this situation can occur when some sort of complex page is encountered within the Linux kernel, while performing vector I/O. In fact, I receive a warning from the kernel:

WARNING: CPU: 6 PID: 937 at lib/iov_iter.c:695 copy_page_to_iter+0x2c4/0x4c4
Modules linked in: rpcsec_gss_krb5 lzo lzo_compress zram binfmt_misc spidev evdev spi_s3c64xx uio_pdrv_genirq uio exynos_gpiomem gpio_keys sch_fq_codel nfsd sit tunnel4 ip_tunnel ip_tables ipv6 extcon_usb_gpio
CPU: 6 PID: 937 Comm: arm-linux-gnuea Tainted: G        W       4.14.47-132 #1
Hardware name: ODROID-XU4
[<c0110b14>] (unwind_backtrace) from [<c010ce98>] (show_stack+0x10/0x14)
[<c010ce98>] (show_stack) from [<c08a8854>] (dump_stack+0x84/0x98)
[<c08a8854>] (dump_stack) from [<c01242cc>] (__warn+0xec/0x104)
[<c01242cc>] (__warn) from [<c0124394>] (warn_slowpath_null+0x20/0x28)
[<c0124394>] (warn_slowpath_null) from [<c046ae88>] (copy_page_to_iter+0x2c4/0x4c4)
[<c046ae88>] (copy_page_to_iter) from [<c021ebc8>] (generic_file_read_iter+0x2ac/0x8e8)
[<c021ebc8>] (generic_file_read_iter) from [<c038fb80>] (nfs_file_read+0x60/0x98)
[<c038fb80>] (nfs_file_read) from [<c0283324>] (do_iter_readv_writev+0x104/0x158)
[<c0283324>] (do_iter_readv_writev) from [<c02846a0>] (do_iter_read+0xe0/0x1a0)
[<c02846a0>] (do_iter_read) from [<c0285d58>] (vfs_readv+0x50/0x68)
[<c0285d58>] (vfs_readv) from [<c0285dc4>] (do_readv+0x54/0xdc)
[<c0285dc4>] (do_readv) from [<c010893c>] (__sys_trace_return+0x0/0x10)
---[ end trace 31bb0ea7bbe390aa ]---