nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From 8c747d3157df2830eed9205e7caf1203b345de17 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 4 Feb 2023 13:54:41 -0800
4Subject: [PATCH] cmake: Enable 64bit off_t on 32bit glibc systems
5
6Pass -D_FILE_OFFSET_BITS=64 to compiler flags on 32bit glibc based
7systems. This will make sure that 64bit versions of LFS functions are
8used e.g. seek will behave same as lseek64. Also revert [1] partially
9because this added a cmake test to detect lseek64 but then forgot to
10pass the needed macro to actual compile, this test was incomplete too
11since libc implementations like musl has 64bit off_t by default on 32bit
12systems and does not bundle[2] -D_LARGEFILE64_SOURCE under -D_GNU_SOURCE
13like glibc, which means the compile now fails on musl because the cmake
14check passes but we do not have _LARGEFILE64_SOURCE defined. Using the
15*64 function was transitional anyways so use -D_FILE_OFFSET_BITS=64
16instead
17
18[1] https://github.com/llvm/llvm-project/commit/8db7e5e4eed4c4e697dc3164f2c9351d8c3e942b
19[2] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc
20
21Reviewed By: MaskRay
22
23Differential Revision: https://reviews.llvm.org/D139752
24
25(cherry picked from commit 5cd554303ead0f8891eee3cd6d25cb07f5a7bf67)
26---
27 cmake/config-ix.cmake | 13 ++++++++++---
28 include/llvm/Config/config.h.cmake | 3 ---
29 lib/Support/raw_ostream.cpp | 2 --
30 3 files changed, 10 insertions(+), 8 deletions(-)
31
32diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
33index 18977d9950ff..b558aa83fa62 100644
34--- a/cmake/config-ix.cmake
35+++ b/cmake/config-ix.cmake
36@@ -197,9 +197,6 @@ check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)
37 if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
38 check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
39 endif()
40-set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")
41-check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
42-set(CMAKE_REQUIRED_DEFINITIONS "")
43 check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
44 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
45 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
46@@ -237,6 +234,16 @@ if( PURE_WINDOWS )
47 check_function_exists(__main HAVE___MAIN)
48 check_function_exists(__cmpdi2 HAVE___CMPDI2)
49 endif()
50+
51+check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
52+if( LLVM_USING_GLIBC )
53+# enable 64bit off_t on 32bit systems using glibc
54+ if (CMAKE_SIZEOF_VOID_P EQUAL 4)
55+ add_compile_definitions(_FILE_OFFSET_BITS=64)
56+ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
57+ endif()
58+endif()
59+
60 if( HAVE_DLFCN_H )
61 if( HAVE_LIBDL )
62 list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
63diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
64index e934617d7ec7..3c39c373b3c1 100644
65--- a/include/llvm/Config/config.h.cmake
66+++ b/include/llvm/Config/config.h.cmake
67@@ -112,9 +112,6 @@
68 /* Define to 1 if you have the <link.h> header file. */
69 #cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
70
71-/* Define to 1 if you have the `lseek64' function. */
72-#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}
73-
74 /* Define to 1 if you have the <mach/mach.h> header file. */
75 #cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}
76
77diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
78index 038ad00bd608..921ab8409008 100644
79--- a/lib/Support/raw_ostream.cpp
80+++ b/lib/Support/raw_ostream.cpp
81@@ -677,8 +677,6 @@ uint64_t raw_fd_ostream::seek(uint64_t off) {
82 flush();
83 #ifdef _WIN32
84 pos = ::_lseeki64(FD, off, SEEK_SET);
85-#elif defined(HAVE_LSEEK64)
86- pos = ::lseek64(FD, off, SEEK_SET);
87 #else
88 pos = ::lseek(FD, off, SEEK_SET);
89 #endif
90--
912.37.1
92