build: Compile with large inode number support where possible

On filesystems with large inode numbers, such as overlayfs, attempting
to stat() a file on a 32-bit system using legacy syscalls can fail
with EOVERFLOW. If we opt-in to more modern "large file support"
syscalls, then source code references to functions like stat() are
transparently replaced with ABIs that support large file sizes and
inode numbers, such as stat64().

This cannot safely be done globally by Linux distributions, because
some libraries expose types like `off_t` or `struct stat` in their
ABI, meaning that enabling large file support would be an incompatible
change that would cause crashes. However, SDL appears to be careful to
avoid these types in header files, so it should be OK to enable this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-05-26 16:02:15 +01:00 committed by Sam Lantinga
parent 3604ae1d1b
commit 65a3453b7f
2 changed files with 8 additions and 0 deletions

View File

@ -56,6 +56,13 @@ set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
# Enable large file support on 32-bit glibc, so that we can access files
# with large inode numbers
check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC)
if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
add_compile_definitions(PRIVATE _FILE_OFFSET_BITS=64)
endif()
# See docs/release_checklist.md
set(SDL_MAJOR_VERSION 2)
set(SDL_MINOR_VERSION 23)

View File

@ -60,6 +60,7 @@ dnl AC_CANONICAL_HOST
dnl Check for tools
AC_PROG_CC
AC_PROG_CXX
AC_SYS_LARGEFILE
AC_PROG_INSTALL
AC_PROG_MAKE_SET
PKG_PROG_PKG_CONFIG