Skip to content

Commit

Permalink
cmake: Enable 64bit off_t on 32bit glibc systems
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 5cd5543)
  • Loading branch information
kraj authored and tru committed Feb 5, 2023
1 parent 2ed18bf commit a468d19
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
8 changes: 5 additions & 3 deletions llvm/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
endif()
set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")
check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
set(CMAKE_REQUIRED_DEFINITIONS "")
check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
Expand Down Expand Up @@ -340,6 +337,11 @@ check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
if( LLVM_USING_GLIBC )
add_compile_definitions(_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
# enable 64bit off_t on 32bit systems using glibc
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
add_compile_definitions(_FILE_OFFSET_BITS=64)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
endif()
endif()

# This check requires _GNU_SOURCE.
Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@
/* Define to 1 if you have the <link.h> header file. */
#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}

/* Define to 1 if you have the `lseek64' function. */
#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}

/* Define to 1 if you have the <mach/mach.h> header file. */
#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}

Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Support/raw_ostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,6 @@ uint64_t raw_fd_ostream::seek(uint64_t off) {
flush();
#ifdef _WIN32
pos = ::_lseeki64(FD, off, SEEK_SET);
#elif defined(HAVE_LSEEK64)
pos = ::lseek64(FD, off, SEEK_SET);
#else
pos = ::lseek(FD, off, SEEK_SET);
#endif
Expand Down
2 changes: 0 additions & 2 deletions llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,13 @@ write_cmake_config("config") {
values += [
"HAVE_FUTIMENS=1",
"HAVE_LINK_H=1",
"HAVE_LSEEK64=1",
"HAVE_MALLINFO=1",
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
]
} else {
values += [
"HAVE_FUTIMENS=",
"HAVE_LINK_H=",
"HAVE_LSEEK64=",
"HAVE_MALLINFO=",
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=",
]
Expand Down
3 changes: 0 additions & 3 deletions utils/bazel/llvm_configs/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@
/* Define to 1 if you have the <link.h> header file. */
#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}

/* Define to 1 if you have the `lseek64' function. */
#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}

/* Define to 1 if you have the <mach/mach.h> header file. */
#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}

Expand Down

0 comments on commit a468d19

Please sign in to comment.