[libc-commits] [libc] 134e9d1 - [libc][NFC] Move sys/mman entrypoints to the default build configs.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Jan 11 08:53:34 PST 2022


Author: Siva Chandra Reddy
Date: 2022-01-11T16:51:10Z
New Revision: 134e9d1914db341f72b1caca0e342b6c563c8698

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

LOG: [libc][NFC] Move sys/mman entrypoints to the default build configs.

Specifically, mmap and munmap have been moved to the default build list
of entrypoints. To support this, certain deps and includes have been
adjusted. The use of errno in some cases has been updated.

Added: 
    

Modified: 
    libc/config/linux/aarch64/entrypoints.txt
    libc/config/linux/x86_64/entrypoints.txt
    libc/loader/linux/x86_64/CMakeLists.txt
    libc/loader/linux/x86_64/start.cpp
    libc/src/CMakeLists.txt
    libc/src/sys/mman/linux/mmap.cpp
    libc/src/sys/mman/linux/munmap.cpp
    libc/src/sys/mman/mmap.h
    libc/src/sys/mman/munmap.h
    libc/src/unistd/linux/write.cpp
    libc/test/ErrnoSetterMatcher.h
    libc/test/src/CMakeLists.txt
    libc/test/src/sys/mman/linux/mmap_test.cpp
    libc/test/src/unistd/write_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index c0072c6190750..7b9027efa3360 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -169,15 +169,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.trunc
     libc.src.math.truncf
     libc.src.math.truncl
-)
 
-if(LLVM_LIBC_FULL_BUILD)
-  list(APPEND TARGET_LIBC_ENTRYPOINTS
     # sys/mman.h entrypoints
     libc.src.sys.mman.mmap
     libc.src.sys.mman.munmap
-  )
-endif()
+)
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
   ${TARGET_LIBC_ENTRYPOINTS}

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 38586a4eddce7..3cca89338702f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -75,6 +75,10 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.strtoll
     libc.src.stdlib.strtoul
     libc.src.stdlib.strtoull
+
+    # sys/mman.h entrypoints
+    libc.src.sys.mman.mmap
+    libc.src.sys.mman.munmap
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
@@ -203,10 +207,6 @@ if(LLVM_LIBC_FULL_BUILD)
     # libc.src.signal.sigfillset
     # libc.src.signal.signal
 
-    # sys/mman.h entrypoints
-    libc.src.sys.mman.mmap
-    libc.src.sys.mman.munmap
-
     # threads.h entrypoints
     libc.src.threads.call_once
     libc.src.threads.cnd_broadcast

diff  --git a/libc/loader/linux/x86_64/CMakeLists.txt b/libc/loader/linux/x86_64/CMakeLists.txt
index 75b8a23802e7b..c8fa53bf3d753 100644
--- a/libc/loader/linux/x86_64/CMakeLists.txt
+++ b/libc/loader/linux/x86_64/CMakeLists.txt
@@ -7,7 +7,6 @@ add_loader_object(
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
     libc.src.string.memcpy
-    libc.src.sys.mman.mmap
   COMPILE_OPTIONS
     -fno-omit-frame-pointer
     -ffreestanding # To avoid compiler warnings about calling the main function.

diff  --git a/libc/loader/linux/x86_64/start.cpp b/libc/loader/linux/x86_64/start.cpp
index 55ae003919270..774f01b543216 100644
--- a/libc/loader/linux/x86_64/start.cpp
+++ b/libc/loader/linux/x86_64/start.cpp
@@ -11,7 +11,6 @@
 #include "include/sys/syscall.h"
 #include "src/__support/OSUtil/syscall.h"
 #include "src/string/memcpy.h"
-#include "src/sys/mman/mmap.h"
 
 #include <asm/prctl.h>
 #include <linux/auxvec.h>

diff  --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index 006bf5c7563be..99faf794c1356 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -8,6 +8,10 @@ add_subdirectory(math)
 add_subdirectory(string)
 add_subdirectory(stdlib)
 
+if(${LIBC_TARGET_OS} STREQUAL "linux")
+  add_subdirectory(sys)
+endif()
+
 if(NOT LLVM_LIBC_FULL_BUILD)
   return()
 endif()
@@ -17,8 +21,6 @@ endif()
 # add_subdirectory(assert)
 # add_subdirectory(signal)
 add_subdirectory(stdio)
-# TODO: Add this target conditional to the target OS.
-add_subdirectory(sys)
 add_subdirectory(threads)
 add_subdirectory(time)
 add_subdirectory(unistd)

diff  --git a/libc/src/sys/mman/linux/mmap.cpp b/libc/src/sys/mman/linux/mmap.cpp
index 0447ef1298915..6ae482a8409ad 100644
--- a/libc/src/sys/mman/linux/mmap.cpp
+++ b/libc/src/sys/mman/linux/mmap.cpp
@@ -8,12 +8,12 @@
 
 #include "src/sys/mman/mmap.h"
 
-#include "include/sys/syscall.h"          // For syscall numbers.
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-#include "src/errno/llvmlibc_errno.h"
 
+#include <errno.h>
 #include <linux/param.h> // For EXEC_PAGESIZE.
+#include <sys/syscall.h> // For syscall numbers.
 
 namespace __llvm_libc {
 
@@ -53,7 +53,7 @@ LLVM_LIBC_FUNCTION(void *, mmap,
   // return value corresponding to a location in the last page is an error
   // value.
   if (ret_val < 0 && ret_val > -EXEC_PAGESIZE) {
-    llvmlibc_errno = -ret_val;
+    errno = -ret_val;
     return MAP_FAILED;
   }
 

diff  --git a/libc/src/sys/mman/linux/munmap.cpp b/libc/src/sys/mman/linux/munmap.cpp
index 7801a637f23f1..2abeb3134242b 100644
--- a/libc/src/sys/mman/linux/munmap.cpp
+++ b/libc/src/sys/mman/linux/munmap.cpp
@@ -8,10 +8,11 @@
 
 #include "src/sys/mman/munmap.h"
 
-#include "include/sys/syscall.h"          // For syscall numbers.
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-#include "src/errno/llvmlibc_errno.h"
+
+#include <errno.h>
+#include <sys/syscall.h>          // For syscall numbers.
 
 namespace __llvm_libc {
 
@@ -24,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, munmap, (void *addr, size_t size)) {
   // A negative return value indicates an error with the magnitude of the
   // value being the error code.
   if (ret_val < 0) {
-    llvmlibc_errno = -ret_val;
+    errno = -ret_val;
     return -1;
   }
 

diff  --git a/libc/src/sys/mman/mmap.h b/libc/src/sys/mman/mmap.h
index c7aa404f65857..9f7fd8b9196b4 100644
--- a/libc/src/sys/mman/mmap.h
+++ b/libc/src/sys/mman/mmap.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SYS_MMAN_MMAP_H
 #define LLVM_LIBC_SRC_SYS_MMAN_MMAP_H
 
-#include "include/sys/mman.h" // For size_t and off_t
+#include <sys/mman.h> // For size_t and off_t
 
 namespace __llvm_libc {
 

diff  --git a/libc/src/sys/mman/munmap.h b/libc/src/sys/mman/munmap.h
index ba272dc45e15f..fa11d67823f62 100644
--- a/libc/src/sys/mman/munmap.h
+++ b/libc/src/sys/mman/munmap.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SYS_MMAN_MUNMAP_H
 #define LLVM_LIBC_SRC_SYS_MMAN_MUNMAP_H
 
-#include "include/sys/mman.h" // For size_t.
+#include <sys/mman.h> // For size_t.
 
 namespace __llvm_libc {
 

diff  --git a/libc/src/unistd/linux/write.cpp b/libc/src/unistd/linux/write.cpp
index 3554e3030943b..0eaa632e57673 100644
--- a/libc/src/unistd/linux/write.cpp
+++ b/libc/src/unistd/linux/write.cpp
@@ -11,14 +11,15 @@
 #include "include/sys/syscall.h"          // For syscall numbers.
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-#include "src/errno/llvmlibc_errno.h"
+
+#include <errno.h>
 
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) {
   long ret = __llvm_libc::syscall(SYS_write, fd, buf, count);
   if (ret < 0) {
-    llvmlibc_errno = -ret;
+    errno = -ret;
     return -1;
   }
   return ret;

diff  --git a/libc/test/ErrnoSetterMatcher.h b/libc/test/ErrnoSetterMatcher.h
index 7f8311bfd5e6c..007b2e6c0ae17 100644
--- a/libc/test/ErrnoSetterMatcher.h
+++ b/libc/test/ErrnoSetterMatcher.h
@@ -9,9 +9,10 @@
 #ifndef LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
 #define LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
 
-#include "src/errno/llvmlibc_errno.h"
 #include "utils/UnitTest/Test.h"
 
+#include <errno.h>
+
 namespace __llvm_libc {
 namespace testing {
 
@@ -42,8 +43,8 @@ template <typename T> class ErrnoSetterMatcher : public Matcher<T> {
 
   bool match(T Got) {
     ActualReturn = Got;
-    ActualErrno = llvmlibc_errno;
-    llvmlibc_errno = 0;
+    ActualErrno = errno;
+    errno = 0;
     return Got == ExpectedReturn && ActualErrno == ExpectedErrno;
   }
 };

diff  --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index d9b184e3790c5..96bc7e6c2bc77 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -34,6 +34,10 @@ add_subdirectory(math)
 add_subdirectory(string)
 add_subdirectory(stdlib)
 
+if(${LIBC_TARGET_OS} STREQUAL "linux")
+  add_subdirectory(sys)
+endif()
+
 if(NOT LLVM_LIBC_FULL_BUILD)
   return()
 endif()
@@ -43,7 +47,6 @@ endif()
 # add_subdirectory(assert)
 # add_subdirectory(signal)
 add_subdirectory(stdio)
-add_subdirectory(sys)
 add_subdirectory(threads)
 add_subdirectory(time)
 add_subdirectory(unistd)

diff  --git a/libc/test/src/sys/mman/linux/mmap_test.cpp b/libc/test/src/sys/mman/linux/mmap_test.cpp
index 5311427ad522d..a1a0a0879442b 100644
--- a/libc/test/src/sys/mman/linux/mmap_test.cpp
+++ b/libc/test/src/sys/mman/linux/mmap_test.cpp
@@ -6,23 +6,23 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "include/errno.h"
-#include "include/sys/mman.h"
-#include "src/errno/llvmlibc_errno.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"
 #include "test/ErrnoSetterMatcher.h"
 #include "utils/UnitTest/Test.h"
 
+#include <errno.h>
+#include <sys/mman.h>
+
 using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
 using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
 
 TEST(LlvmLibcMMapTest, NoError) {
   size_t alloc_size = 128;
-  llvmlibc_errno = 0;
+  errno = 0;
   void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
                                  MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-  EXPECT_EQ(0, llvmlibc_errno);
+  EXPECT_EQ(0, errno);
   EXPECT_NE(addr, MAP_FAILED);
 
   int *array = reinterpret_cast<int *>(addr);
@@ -34,7 +34,7 @@ TEST(LlvmLibcMMapTest, NoError) {
 }
 
 TEST(LlvmLibcMMapTest, Error_InvalidSize) {
-  llvmlibc_errno = 0;
+  errno = 0;
   void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
                                  MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   EXPECT_THAT(addr, Fails(EINVAL, MAP_FAILED));

diff  --git a/libc/test/src/unistd/write_test.cpp b/libc/test/src/unistd/write_test.cpp
index 56243846083af..43914e87ef652 100644
--- a/libc/test/src/unistd/write_test.cpp
+++ b/libc/test/src/unistd/write_test.cpp
@@ -6,12 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "include/errno.h"
 #include "src/unistd/write.h"
 #include "test/ErrnoSetterMatcher.h"
 #include "utils/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
+#include <errno.h>
+
 TEST(LlvmLibcUniStd, WriteBasic) {
   using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
   constexpr const char *HELLO = "hello";


        


More information about the libc-commits mailing list