Skip to content

Commit 5cd5543

Browse files
krajMaskRay
authored andcommitted
cmake: Enable 64bit off_t on 32bit glibc systems
Pass -D_FILE_OFFSET_BITS=64 to compiler flags on 32bit glibc based systems. This will make sure that 64bit versions of LFS functions are used e.g. seek will behave same as lseek64. Also revert [1] partially because this added a cmake test to detect lseek64 but then forgot to pass the needed macro to actual compile, this test was incomplete too since libc implementations like musl has 64bit off_t by default on 32bit systems and does not bundle[2] -D_LARGEFILE64_SOURCE under -D_GNU_SOURCE like glibc, which means the compile now fails on musl because the cmake check passes but we do not have _LARGEFILE64_SOURCE defined. Using the *64 function was transitional anyways so use -D_FILE_OFFSET_BITS=64 instead [1] 8db7e5e [2] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D139752
1 parent 7e3943f commit 5cd5543

File tree

5 files changed

+5
-13
lines changed

5 files changed

+5
-13
lines changed

llvm/cmake/config-ix.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
284284
if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
285285
check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
286286
endif()
287-
set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")
288-
check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
289-
set(CMAKE_REQUIRED_DEFINITIONS "")
290287
check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
291288
check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
292289
check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
@@ -340,6 +337,11 @@ check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
340337
if( LLVM_USING_GLIBC )
341338
add_compile_definitions(_GNU_SOURCE)
342339
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
340+
# enable 64bit off_t on 32bit systems using glibc
341+
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
342+
add_compile_definitions(_FILE_OFFSET_BITS=64)
343+
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
344+
endif()
343345
endif()
344346

345347
# This check requires _GNU_SOURCE.

llvm/include/llvm/Config/config.h.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@
128128
/* Define to 1 if you have the <link.h> header file. */
129129
#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
130130

131-
/* Define to 1 if you have the `lseek64' function. */
132-
#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}
133-
134131
/* Define to 1 if you have the <mach/mach.h> header file. */
135132
#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}
136133

llvm/lib/Support/raw_ostream.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,6 @@ uint64_t raw_fd_ostream::seek(uint64_t off) {
802802
flush();
803803
#ifdef _WIN32
804804
pos = ::_lseeki64(FD, off, SEEK_SET);
805-
#elif defined(HAVE_LSEEK64)
806-
pos = ::lseek64(FD, off, SEEK_SET);
807805
#else
808806
pos = ::lseek(FD, off, SEEK_SET);
809807
#endif

llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,13 @@ write_cmake_config("config") {
139139
values += [
140140
"HAVE_FUTIMENS=1",
141141
"HAVE_LINK_H=1",
142-
"HAVE_LSEEK64=1",
143142
"HAVE_MALLINFO=1",
144143
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
145144
]
146145
} else {
147146
values += [
148147
"HAVE_FUTIMENS=",
149148
"HAVE_LINK_H=",
150-
"HAVE_LSEEK64=",
151149
"HAVE_MALLINFO=",
152150
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=",
153151
]

utils/bazel/llvm_configs/config.h.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@
128128
/* Define to 1 if you have the <link.h> header file. */
129129
#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
130130

131-
/* Define to 1 if you have the `lseek64' function. */
132-
#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}
133-
134131
/* Define to 1 if you have the <mach/mach.h> header file. */
135132
#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}
136133

0 commit comments

Comments
 (0)