https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128953
Bug ID: 128953
Summary: _GLIBCXX_USE_COPY_FILE_RANGE is never defined on
glibc: configure test uses loff_t without including
<sys/types.h>
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: trian0323 at gmail dot com
Target Milestone: ---
r14-1569 added copy_file_range support to std::filesystem::copy_file, guarded
by _GLIBCXX_USE_COPY_FILE_RANGE. GLIBCXX_CHECK_FILESYSTEM_DEPS in
libstdc++-v3/acinclude.m4 defines that macro when this test program compiles:
#include <unistd.h>
copy_file_range(1, (loff_t*)nullptr, 2, (loff_t*)nullptr, 1, 0);
The (loff_t*) casts were added in r14-2191 (PR 110462). On glibc, loff_t is
declared only in <sys/types.h>, not in <unistd.h> (glibc declares
copy_file_range with __off64_t*), so the test always fails to compile and
configure reports "checking for copy_file_range that can copy files... no".
Reproducer (the exact test program from acinclude.m4):
$ cat t.cc
#include <unistd.h>
int main() { copy_file_range(1, (loff_t*)nullptr, 2, (loff_t*)nullptr, 1, 0);
}
$ g++ -c t.cc
t.cc:2:34: error: 'loff_t' was not declared in this scope; did you mean
'off_t'?
Adding "#include <sys/types.h>" makes it compile. Without the casts (the form
used before r14-2191) it compiles and links as well, so copy_file_range itself
is available in glibc.
Tested with gcc version 14.2.1 20250110 (Red Hat 14.2.1-11),
Target: x86_64-redhat-linux, glibc 2.28.
As a result the copy_file_range code path in src/filesystem/ops-common.h is
compiled out of the library. This is not specific to one distribution; the
installed bits/c++config.h says the same in all packages I checked:
RHEL 8 gcc-toolset-14-libstdc++-devel-14.2.1-11.el8_10 /* #undef
_GLIBCXX_USE_COPY_FILE_RANGE */
Fedora 41 libstdc++-devel-14.2.1-3.fc41 /* #undef
_GLIBCXX_USE_COPY_FILE_RANGE */
Debian libstdc++-14-dev 14.4.0-4 /* #undef
_GLIBCXX_USE_COPY_FILE_RANGE */
Debian libstdc++-15-dev 15.3.0-5 /* #undef
_GLIBCXX_USE_COPY_FILE_RANGE */
Observable effect: strace of std::filesystem::copy_file built with GCC 14 on
XFS with reflink enabled shows only sendfile(2). No copy_file_range(2) is
issued and no reflink is created. libstdc++_nonshared.a has an undefined
reference to sendfile but none to copy_file_range.
The test is identical in acinclude.m4 on the releases/gcc-14, releases/gcc-15
and releases/gcc-16 branches and on trunk (checked in the sources, not built).
Suggested fix, either of:
- add "#include <sys/types.h>" to the test program, or
- cast to (off_t*) instead of (loff_t*). The filesystem library is built
with _FILE_OFFSET_BITS=64, so off_t is 64-bit there, and musl's off_t is
always 64-bit.
ops-common.h also uses loff_t for the copy_file_range call, so whichever
header provides it in the configure test should be included there too.