[PATCH] Build filesystem library with large file support

Jonathan Wakely jwakely@redhat.com
Fri Oct 4 15:08:00 GMT 2019


Enable AC_SYS_LARGEFILE to set the macros needed for large file APIs to
be used by default. We do not want to define those macros in the
public headers that users include. The values of the macros are copied
to a separate file that is only included by the filesystem sources
during the build, and then the macros in <bits/c++config.h> are renamed
so that they don't have any effect in user code including our headers.

Also use larger type for result of filesystem::file_size to avoid
truncation of large values on 32-bit systems (PR 91947).

	PR libstdc++/81091
	PR libstdc++/91947
	* configure.ac: Use AC_SYS_LARGEFILE to enable 64-bit file APIs.
	* config.h.in: Regenerate:
	* configure: Regenerate:
	* include/Makefile.am (${host_builddir}/largefile-config.h): New
	target to generate config header for filesystem library.
	(${host_builddir}/c++config.h): Rename macros for large file support.
	* include/Makefile.in: Regenerate.
	* src/c++17/fs_dir.cc: Include new config header.
	* src/c++17/fs_ops.cc: Likewise.
	(filesystem::file_size): Use uintmax_t for size.
	* src/filesystem/dir.cc: Include new config header.
	* src/filesystem/ops.cc: Likewise.
	(experimental::filesystem::file_size): Use uintmax_t for size.

Tested x86_64-linux, i686-linux, powerpv64le-linux. I've verified that
a 10gb file has its size correctly reported on 32-bit x86 now.

Committed to trunk.

-------------- next part --------------
commit c483318c3948a91086e6cf978dd58eafc78564c3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 2 15:16:51 2019 +0100

    Build filesystem library with large file support
    
    Enable AC_SYS_LARGEFILE to set the macros needed for large file APIs to
    be used by default. We do not want to define those macros in the
    public headers that users include. The values of the macros are copied
    to a separate file that is only included by the filesystem sources
    during the build, and then the macros in <bits/c++config.h> are renamed
    so that they don't have any effect in user code including our headers.
    
    Also use larger type for result of filesystem::file_size to avoid
    truncation of large values on 32-bit systems (PR 91947).
    
            PR libstdc++/81091
            PR libstdc++/91947
            * configure.ac: Use AC_SYS_LARGEFILE to enable 64-bit file APIs.
            * config.h.in: Regenerate:
            * configure: Regenerate:
            * include/Makefile.am (${host_builddir}/largefile-config.h): New
            target to generate config header for filesystem library.
            (${host_builddir}/c++config.h): Rename macros for large file support.
            * include/Makefile.in: Regenerate.
            * src/c++17/fs_dir.cc: Include new config header.
            * src/c++17/fs_ops.cc: Likewise.
            (filesystem::file_size): Use uintmax_t for size.
            * src/filesystem/dir.cc: Include new config header.
            * src/filesystem/ops.cc: Likewise.
            (experimental::filesystem::file_size): Use uintmax_t for size.

diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index ad4ae0c3b7d..154819acefe 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -83,6 +83,8 @@ AC_PROG_CC
 AC_PROG_CXX
 CXXFLAGS="$save_CXXFLAGS"
 
+AC_SYS_LARGEFILE
+
 # Runs configure.host, and assorted other critical bits.  Sets
 # up critical shell variables.
 GLIBCXX_CONFIGURE
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index b8b786d9260..3e9540ca047 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -1014,6 +1014,7 @@ allstamped = \
 # catenation.
 allcreated = \
 	${host_builddir}/c++config.h \
+	${host_builddir}/largefile-config.h \
 	${thread_host_headers} \
 	${pch_build}
 
@@ -1237,10 +1238,29 @@ stamp-float128:
 	echo 'undef _GLIBCXX_USE_FLOAT128' > stamp-float128
 endif
 
+# This header is not installed, it's only used to build libstdc++ itself.
+${host_builddir}/largefile-config.h: ${CONFIG_HEADER} \
+				     ${glibcxx_srcdir}/include/bits/c++config
+	@echo '#if defined _GLIBCXX_CXX_CONFIG_H || defined _FEATURES_H' > $@
+	@echo '# error "This file must be included before any others"' >> $@
+	@echo '#endif' >> $@
+	@echo >> $@
+	@echo '/* Enable large inode numbers on Mac OS X 10.5.  */' >> $@
+	@echo '#ifndef _DARWIN_USE_64_BIT_INODE' >> $@
+	@echo '# define _DARWIN_USE_64_BIT_INODE 1' >> $@
+	@echo '#endif' >> $@
+	@echo >> $@
+	@echo '/* Number of bits in a file offset, on hosts where this is settable. */' >> $@
+	@grep '_FILE_OFFSET_BITS' ${CONFIG_HEADER} >> $@
+	@echo >> $@
+	@echo '/* Define for large files, on AIX-style hosts. */' >> $@
+	@grep '_LARGE_FILES' ${CONFIG_HEADER} >> $@
+
 # NB: The non-empty default ldbl_compat works around an AIX sed
 # oddity, see libstdc++/31957 for details.
 ${host_builddir}/c++config.h: ${CONFIG_HEADER} \
 			      ${glibcxx_srcdir}/include/bits/c++config \
+			      ${host_builddir}/largefile-config.h \
 			      stamp-${host_alias} \
 			      ${toplevel_srcdir}/gcc/DATESTAMP \
 			      stamp-namespace-version \
@@ -1278,6 +1298,9 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \
 	    -e 's/PACKAGE/_GLIBCXX_PACKAGE/g' \
 	    -e 's/VERSION/_GLIBCXX_VERSION/g' \
 	    -e 's/WORDS_/_GLIBCXX_WORDS_/g' \
+	    -e 's/_DARWIN_USE_64_BIT_INODE/_GLIBCXX_DARWIN_USE_64_BIT_INODE/g' \
+	    -e 's/_FILE_OFFSET_BITS/_GLIBCXX_FILE_OFFSET_BITS/g' \
+	    -e 's/_LARGE_FILES/_GLIBCXX_LARGE_FILES/g' \
 	    -e 's/ICONV_CONST/_GLIBCXX_ICONV_CONST/g' \
 	    -e '/[	 ]_GLIBCXX_LONG_DOUBLE_COMPAT[	 ]/d' \
 	    < ${CONFIG_HEADER} >> $@ ;\
diff --git a/libstdc++-v3/src/c++17/fs_dir.cc b/libstdc++-v3/src/c++17/fs_dir.cc
index d8c48f6d6d8..bcbcd7ba6b3 100644
--- a/libstdc++-v3/src/c++17/fs_dir.cc
+++ b/libstdc++-v3/src/c++17/fs_dir.cc
@@ -26,6 +26,7 @@
 # define _GLIBCXX_USE_CXX11_ABI 1
 #endif
 
+#include <bits/largefile-config.h>
 #include <filesystem>
 #include <utility>
 #include <stack>
diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index d8064819d36..2541530e784 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -28,6 +28,7 @@
 # define NEED_DO_SPACE
 #endif
 
+#include <bits/largefile-config.h>
 #include <filesystem>
 #include <functional>
 #include <ostream>
@@ -950,7 +951,7 @@ fs::file_size(const path& p, error_code& ec) noexcept
     S(const stat_type& st) : type(make_file_type(st)), size(st.st_size) { }
     S() : type(file_type::not_found) { }
     file_type type;
-    size_t size;
+    uintmax_t size;
   };
   auto s = do_stat(p, ec, [](const auto& st) { return S{st}; }, S{});
   if (s.type == file_type::regular)
diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
index 3e6e598fa64..ac3bd3aafb3 100644
--- a/libstdc++-v3/src/filesystem/dir.cc
+++ b/libstdc++-v3/src/filesystem/dir.cc
@@ -26,6 +26,7 @@
 # define _GLIBCXX_USE_CXX11_ABI 1
 #endif
 
+#include <bits/largefile-config.h>
 #include <experimental/filesystem>
 
 #ifndef _GLIBCXX_HAVE_DIRENT_H
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index 36b5d2c24f6..8687fcdc297 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -28,6 +28,7 @@
 # define NEED_DO_SPACE
 #endif
 
+#include <bits/largefile-config.h>
 #include <experimental/filesystem>
 #include <functional>
 #include <ostream>
@@ -806,7 +807,7 @@ fs::file_size(const path& p, error_code& ec) noexcept
     S(const stat_type& st) : type(make_file_type(st)), size(st.st_size) { }
     S() : type(file_type::not_found) { }
     file_type type;
-    size_t size;
+    uintmax_t size;
   };
   auto s = do_stat(p, ec, [](const auto& st) { return S{st}; }, S{});
   if (s.type == file_type::regular)


More information about the Gcc-patches mailing list