[libc-commits] [libc] 547e345 - [libc] Make libc_errno point to internal errno for non-public builds.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Mon Mar 13 21:22:14 PDT 2023


Author: Siva Chandra Reddy
Date: 2023-03-14T04:21:56Z
New Revision: 547e3456660000a16fc5c2a2f819f1a2b5d35b5d

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

LOG: [libc] Make libc_errno point to internal errno for non-public builds.

The macro llvmlibc_errno has also been removed. This change completes
the switch to using a hermetic errno for unit tests.

Fixes #61037

Reviewed By: lntue

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

Added: 
    

Modified: 
    libc/src/errno/CMakeLists.txt
    libc/src/errno/libc_errno.cpp
    libc/src/errno/libc_errno.h
    libc/test/CMakeLists.txt
    libc/test/ErrnoSetterMatcher.h

Removed: 
    libc/src/errno/llvmlibc_errno.h


################################################################################
diff  --git a/libc/src/errno/CMakeLists.txt b/libc/src/errno/CMakeLists.txt
index 61b56047ce0a4..2fa1381a70cc6 100644
--- a/libc/src/errno/CMakeLists.txt
+++ b/libc/src/errno/CMakeLists.txt
@@ -4,7 +4,6 @@ add_entrypoint_object(
     libc_errno.cpp
   HDRS
     libc_errno.h     # Include this
-    llvmlibc_errno.h # DEPRECATED: Will be removed soon
   DEPENDS
     libc.include.errno
 )

diff  --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index 98a76c2cbcf49..b8c276cb853fb 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -9,9 +9,9 @@
 namespace __llvm_libc {
 
 extern "C" {
+#ifdef LIBC_COPT_PUBLIC_PACKAGING
 // TODO: Declare __llvmlibc_errno only under LIBC_COPT_PUBLIC_PACKAGING and
 // __llvmlibc_internal_errno otherwise.
-//
 // In overlay mode, this will be an unused thread local variable as libc_errno
 // will resolve to errno from the system libc's errno.h. In full build mode
 // however, libc_errno will resolve to this thread local variable via the errno
@@ -19,7 +19,9 @@ extern "C" {
 // TODO: Use a macro to distinguish full build and overlay build which can be
 //       used to exclude __llvmlibc_errno under overlay build.
 thread_local int __llvmlibc_errno;
+#else
 thread_local int __llvmlibc_internal_errno;
+#endif
 } // extern "C"
 
 } // namespace __llvm_libc

diff  --git a/libc/src/errno/libc_errno.h b/libc/src/errno/libc_errno.h
index 586d88feba906..28f8d0d13e736 100644
--- a/libc/src/errno/libc_errno.h
+++ b/libc/src/errno/libc_errno.h
@@ -29,7 +29,7 @@ extern thread_local int __llvmlibc_internal_errno;
 // libc_errno, this header file will be "shipped" via an add_entrypoint_object
 // target. At which point libc_errno, should point to __llvmlibc_internal_errno
 // if LIBC_COPT_PUBLIC_PACKAGING is not defined.
-#define libc_errno errno
+#define libc_errno __llvm_libc::__llvmlibc_internal_errno
 
 } // namespace __llvm_libc
 #endif

diff  --git a/libc/src/errno/llvmlibc_errno.h b/libc/src/errno/llvmlibc_errno.h
deleted file mode 100644
index eb1f66c2e4080..0000000000000
--- a/libc/src/errno/llvmlibc_errno.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for errno -------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H
-#define LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H
-
-#include <errno.h>
-
-// DEPRECATED: Use libc_errno from libc_errno.h instead. This macro is only
-// present to facilitate gradual transition (as in, in multiple simple patches)
-// to libc_errno.
-// TODO: After all of libc/src and libc/test is switched over to use libc_errno,
-// remove this macro and header file.
-#define llvmlibc_errno errno
-
-#endif // LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H

diff  --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index fc9df9c670cb7..d325aac68f523 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -9,6 +9,8 @@ add_header_library(
   errno_setter_matcher
   HDRS
     ErrnoSetterMatcher.h
+  DEPENDS
+    libc.src.errno.errno
 )
 
 add_custom_target(check-libc)

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


        


More information about the libc-commits mailing list