From 48cf70c06ae6085ff3d1f8b28e323f153cff23c6 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sun, 25 Dec 2022 15:13:41 -0800
Subject: [PATCH] build: 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. lseek 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 during actual compile, this test was incomplete too
since libc implementations like musl has 64-bit off_t by default on 32-bit
systems and does not bundle -D_LARGEFILE64_SOURCE [2] 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. Moreover,
Using the *64 function was transitional anyways so use
-D_FILE_OFFSET_BITS=64 instead

[1] https://github.com/llvm/llvm-project/commit/8db7e5e4eed4c4e697dc3164f2c9351d8c3e942b
[2] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 utils/bazel/llvm-project-overlay/llvm/config.bzl               | 1 -
 .../llvm-project-overlay/llvm/include/llvm/Config/config.h     | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm-project-overlay/llvm/config.bzl
index 5507f80efa0b..b15ec9e1bb39 100644
--- a/utils/bazel/llvm-project-overlay/llvm/config.bzl
+++ b/utils/bazel/llvm-project-overlay/llvm/config.bzl
@@ -48,7 +48,6 @@ posix_defines = [
 linux_defines = posix_defines + [
     "_GNU_SOURCE",
     "HAVE_LINK_H=1",
-    "HAVE_LSEEK64=1",
     "HAVE_MALLINFO=1",
     "HAVE_SBRK=1",
     "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
index 8a30957b6120..6a68ac040bb8 100644
--- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
+++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
@@ -144,9 +144,6 @@
 /* Define to 1 if you have the <link.h> header file. */
 /* HAVE_LINK_H defined in Bazel */
 
-/* Define to 1 if you have the `lseek64' function. */
-/* HAVE_LSEEK64 defined in Bazel */
-
 /* Define to 1 if you have the <mach/mach.h> header file. */
 /* HAVE_MACH_MACH_H defined in Bazel */
 
