[libc-commits] [libc] ea70e6f - [libc] Fix compilation on 32-bit systems

Mikhail R. Gadelha via libc-commits libc-commits at lists.llvm.org
Wed Aug 16 05:52:54 PDT 2023


Author: Mikhail R. Gadelha
Date: 2023-08-16T09:52:41-03:00
New Revision: ea70e6f9a9f0b97b8693292cb3976a0e72234418

URL: https://github.com/llvm/llvm-project/commit/ea70e6f9a9f0b97b8693292cb3976a0e72234418
DIFF: https://github.com/llvm/llvm-project/commit/ea70e6f9a9f0b97b8693292cb3976a0e72234418.diff

LOG: [libc] Fix compilation on 32-bit systems

This fixes the following compilation error: no known conversion from 'off_t *'
(aka 'long long *') to 'long' for 5th argument.

Since pointers are 32-bit long anyway, casting it to long shouldn't be a
problem. Tested on rv32.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D157792

Added: 
    

Modified: 
    libc/src/unistd/linux/lseek.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/unistd/linux/lseek.cpp b/libc/src/unistd/linux/lseek.cpp
index 6fb6091f0a7ef1..87900e2f8c08f5 100644
--- a/libc/src/unistd/linux/lseek.cpp
+++ b/libc/src/unistd/linux/lseek.cpp
@@ -23,14 +23,15 @@ LLVM_LIBC_FUNCTION(off_t, lseek, (int fd, off_t offset, int whence)) {
 #ifdef SYS_lseek
   int ret = __llvm_libc::syscall_impl<int>(SYS_lseek, fd, offset, whence);
   result = ret;
-#elif defined(SYS_llseek)
-  long ret = __llvm_libc::syscall_impl(SYS_llseek, fd,
-                                       (long)(((uint64_t)(offset)) >> 32),
-                                       (long)offset, &result, whence);
-  result = ret;
+#elif defined(SYS_llseek) || defined(SYS__llseek)
+#ifdef SYS_llseek
+  constexpr long LLSEEK_SYSCALL_NO = SYS_llseek;
 #elif defined(SYS__llseek)
-  int ret = __llvm_libc::syscall_impl<int>(SYS__llseek, fd, offset >> 32,
-                                           offset, &result, whence);
+  constexpr long LLSEEK_SYSCALL_NO = SYS__llseek;
+#endif
+  uint64_t offset_64 = static_cast<uint64_t>(offset);
+  int ret = __llvm_libc::syscall_impl<int>(
+      LLSEEK_SYSCALL_NO, fd, offset_64 >> 32, offset_64, &result, whence);
 #else
 #error "lseek, llseek and _llseek syscalls not available."
 #endif


        


More information about the libc-commits mailing list