[PATCH] D39444: [Support] Make the default chunk size of raw_fd_ostream to 1 GiB.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 09:41:14 PDT 2017


ruiu added inline comments.


================
Comment at: llvm/lib/Support/raw_ostream.cpp:580
   pos += Size;
+  size_t MaxWriteSize = SIZE_MAX;
 
----------------
krytarowski wrote:
> ruiu wrote:
> > krytarowski wrote:
> > > ```
> > > If the value of nbyte is greater than {SSIZE_MAX}, the result is implementation-defined.
> > > ```
> > > 
> > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html#tag_16_685
> > Ah. Then, maybe that's what Saleem observed? The existing code could make a write request that is larger than SSIZE_MAX (= 2 GiB - 1) on a 32-bit machine.
> > 
> > If so, we can just remove the ifdef for Linux and use SSIZE_T as the default MaxWriteSize.
> `SSIZE_MAX` is POSIX only (unless it was added to C++, but I don't see a reference).
> 
> NetBSD specific behavior allows length up to SSIZE_MAX:
> 
> ```
> 	/*
> 	 * Writes return ssize_t because -1 is returned on error.  Therefore
> 	 * we must restrict the length to SSIZE_MAX to avoid garbage return
> 	 * values.
> 	 */
> 	if (auio.uio_resid > SSIZE_MAX) {
> 		error = EINVAL;
> 		goto out;
> }
> ```
> 
> --- src/sys/kern/sys_generic.c
I'm not really sure if we want to deal with limitations of SSIZE_MAX instead of just calling write for each 1 GiB of data, but I addressed your concern in the new patch.


================
Comment at: llvm/lib/Support/raw_ostream.cpp:655
   seek(Offset);
   write(Ptr, Size);
   seek(Pos);
----------------
krytarowski wrote:
> The same problem here. NetBSD disallows length larger than SSIZE_MAX and it will return EINVAL.
This is not a call of ::write but write member function defined in the same class.


https://reviews.llvm.org/D39444





More information about the llvm-commits mailing list