···11+From 8c747d3157df2830eed9205e7caf1203b345de17 Mon Sep 17 00:00:00 200122+From: Khem Raj <raj.khem@gmail.com>33+Date: Sat, 4 Feb 2023 13:54:41 -080044+Subject: [PATCH] cmake: Enable 64bit off_t on 32bit glibc systems55+66+Pass -D_FILE_OFFSET_BITS=64 to compiler flags on 32bit glibc based77+systems. This will make sure that 64bit versions of LFS functions are88+used e.g. seek will behave same as lseek64. Also revert [1] partially99+because this added a cmake test to detect lseek64 but then forgot to1010+pass the needed macro to actual compile, this test was incomplete too1111+since libc implementations like musl has 64bit off_t by default on 32bit1212+systems and does not bundle[2] -D_LARGEFILE64_SOURCE under -D_GNU_SOURCE1313+like glibc, which means the compile now fails on musl because the cmake1414+check passes but we do not have _LARGEFILE64_SOURCE defined. Using the1515+*64 function was transitional anyways so use -D_FILE_OFFSET_BITS=641616+instead1717+1818+[1] https://github.com/llvm/llvm-project/commit/8db7e5e4eed4c4e697dc3164f2c9351d8c3e942b1919+[2] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc2020+2121+Reviewed By: MaskRay2222+2323+Differential Revision: https://reviews.llvm.org/D1397522424+2525+(cherry picked from commit 5cd554303ead0f8891eee3cd6d25cb07f5a7bf67)2626+---2727+ cmake/config-ix.cmake | 13 ++++++++++---2828+ include/llvm/Config/config.h.cmake | 3 ---2929+ lib/Support/raw_ostream.cpp | 2 --3030+ 3 files changed, 10 insertions(+), 8 deletions(-)3131+3232+diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake3333+index 18977d9950ff..b558aa83fa62 1006443434+--- a/cmake/config-ix.cmake3535++++ b/cmake/config-ix.cmake3636+@@ -197,9 +197,6 @@ check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)3737+ if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )3838+ check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)3939+ endif()4040+-set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")4141+-check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)4242+-set(CMAKE_REQUIRED_DEFINITIONS "")4343+ check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)4444+ check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)4545+ check_symbol_exists(malloc_zone_statistics malloc/malloc.h4646+@@ -237,6 +234,16 @@ if( PURE_WINDOWS )4747+ check_function_exists(__main HAVE___MAIN)4848+ check_function_exists(__cmpdi2 HAVE___CMPDI2)4949+ endif()5050++5151++check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)5252++if( LLVM_USING_GLIBC )5353++# enable 64bit off_t on 32bit systems using glibc5454++ if (CMAKE_SIZEOF_VOID_P EQUAL 4)5555++ add_compile_definitions(_FILE_OFFSET_BITS=64)5656++ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")5757++ endif()5858++endif()5959++6060+ if( HAVE_DLFCN_H )6161+ if( HAVE_LIBDL )6262+ list(APPEND CMAKE_REQUIRED_LIBRARIES dl)6363+diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake6464+index e934617d7ec7..3c39c373b3c1 1006446565+--- a/include/llvm/Config/config.h.cmake6666++++ b/include/llvm/Config/config.h.cmake6767+@@ -112,9 +112,6 @@6868+ /* Define to 1 if you have the <link.h> header file. */6969+ #cmakedefine HAVE_LINK_H ${HAVE_LINK_H}7070+7171+-/* Define to 1 if you have the `lseek64' function. */7272+-#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}7373+-7474+ /* Define to 1 if you have the <mach/mach.h> header file. */7575+ #cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}7676+7777+diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp7878+index 038ad00bd608..921ab8409008 1006447979+--- a/lib/Support/raw_ostream.cpp8080++++ b/lib/Support/raw_ostream.cpp8181+@@ -677,8 +677,6 @@ uint64_t raw_fd_ostream::seek(uint64_t off) {8282+ flush();8383+ #ifdef _WIN328484+ pos = ::_lseeki64(FD, off, SEEK_SET);8585+-#elif defined(HAVE_LSEEK64)8686+- pos = ::lseek64(FD, off, SEEK_SET);8787+ #else8888+ pos = ::lseek(FD, off, SEEK_SET);8989+ #endif9090+-- 9191+2.37.19292+