[libc-commits] [libc] 5e750b8 - [libc] Simplify generation of errno.h.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Dec 20 11:04:22 PST 2022


Author: Siva Chandra Reddy
Date: 2022-12-20T19:04:13Z
New Revision: 5e750b86caf152c9f7a97ec5693c666806754cb6

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

LOG: [libc] Simplify generation of errno.h.

Reviewed By: lntue

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

Added: 
    libc/include/llvm-libc-macros/generic-error-number-macros.h

Modified: 
    libc/config/linux/api.td
    libc/include/CMakeLists.txt
    libc/include/errno.h.def
    libc/include/llvm-libc-macros/CMakeLists.txt

Removed: 
    libc/config/linux/errno.h.in


################################################################################
diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 76cc716d5d041..3afb92586f729 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -43,13 +43,6 @@ def NullMacro : MacroDef<"NULL"> {
   }];
 }
 
-def ErrnoMacro : MacroDef<"errno"> {
-  let Defn = [{
-    extern _Thread_local int __llvmlibc_errno;
-    #define errno __llvmlibc_errno
-  }];
-}
-
 def AssertAPI : PublicAPI<"assert.h"> {
   let Macros = [
     AssertMacro,
@@ -183,25 +176,6 @@ def TimeAPI : PublicAPI<"time.h"> {
   ];
 }
 
-def ErrnoAPI : PublicAPI<"errno.h"> {
-  let Macros = [
-    ErrnoMacro,
-    // We largely depend on linux/errno.h to give us the
-    // various error macro definitions. However, some libc
-    // implementations have chosen to provide definitions
-    // for some of the error macros to account for the ones
-    // missing in linux/errno.h. There is no harm in doing
-    // the same here if we define the macros only when they
-    // are not already defined.
-    MacroDefineIfNot<"ENOTSUP", "EOPNOTSUPP">,
-    MacroDefineIfNot<"ECANCELED", "125">,
-    MacroDefineIfNot<"EOWNERDEAD", "130">,
-    MacroDefineIfNot<"ENOTRECOVERABLE", "131">,
-    MacroDefineIfNot<"ERFKILL", "132">,
-    MacroDefineIfNot<"EHWPOISON", "133">,
-  ];
-}
-
 def SchedAPI : PublicAPI<"sched.h"> {
   let Types = ["pid_t", "size_t", "cpu_set_t"];
 }

diff  --git a/libc/config/linux/errno.h.in b/libc/config/linux/errno.h.in
deleted file mode 100644
index 50bbefb681018..0000000000000
--- a/libc/config/linux/errno.h.in
+++ /dev/null
@@ -1,11 +0,0 @@
-//===-- Linux specific errno.h definitions --------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-%%begin()
-
-#include <linux/errno.h>

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 40adef0d051eb..91ef75739178c 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -128,11 +128,9 @@ add_gen_header(
 add_gen_header(
   errno
   DEF_FILE errno.h.def
-  PARAMS
-    platform_errno=../config/${LIBC_TARGET_OS}/errno.h.in
   GEN_HDR errno.h
-  DATA_FILES
-    ../config/${LIBC_TARGET_OS}/errno.h.in
+  DEPENDS
+    .llvm-libc-macros.generic_error_number_macros
 )
 
 add_gen_header(

diff  --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index da60aed19dbde..580a53f6a7716 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -11,8 +11,39 @@
 
 #include <__llvm-libc-common.h>
 
-%%include_file(${platform_errno})
+#ifdef __linux__
 
-%%public_api()
+#include <linux/errno.h>
+
+#ifndef ERFKILL
+#define ERFKILL 132
+#endif // ERFKILL
+
+#ifndef EOWNERDEAD
+#define EOWNERDEAD 130
+#endif // EOWNERDEAD
+
+#ifndef EHWPOISON
+#define EHWPOISON 133
+#endif // EHWPOISON
+
+#ifndef ECANCELED
+#define ECANCELED 125
+#endif // ECANCELED
+
+#ifndef ENOTSUP
+#define ENOTSUP EOPNOTSUPP
+#endif // ENOTSUP
+
+#ifndef ENOTRECOVERABLE
+#define ENOTRECOVERABLE 131
+#endif // ENOTRECOVERABLE
+
+#else // __linux__
+#include <llvm-libc-macros/generic-error-number-macros.h>
+#endif
+
+extern _Thread_local int __llvmlibc_errno;
+#define errno __llvmlibc_errno
 
 #endif // LLVM_LIBC_ERRNO_H

diff  --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index fe2652a01d8dd..1cab22a8930ed 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -1,5 +1,11 @@
 add_subdirectory(linux)
 
+add_header(
+  generic_error_number_macros
+  HDR
+    generic-error-number-macros.h
+)
+
 add_header(
   fcntl_macros
   HDR

diff  --git a/libc/include/llvm-libc-macros/generic-error-number-macros.h b/libc/include/llvm-libc-macros/generic-error-number-macros.h
new file mode 100644
index 0000000000000..e652c6044d034
--- /dev/null
+++ b/libc/include/llvm-libc-macros/generic-error-number-macros.h
@@ -0,0 +1,47 @@
+//===-- Definition of generic error number macros -------------------------===//
+//
+// 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_MACROS_GENERIC_ERROR_NUMBER_MACROS_H
+#define __LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H
+
+#define EPERM 1
+#define ENOENT 2
+#define ESRCH 3
+#define EINTR 4
+#define EIO 5
+#define ENXIO 6
+#define E2BIG 7
+#define ENOEXEC 8
+#define EBADF 9
+#define ECHILD 10
+#define EAGAIN 11
+#define ENOMEM 12
+#define EACCES 13
+#define EFAULT 14
+#define ENOTBLK 15
+#define EBUSY 16
+#define EEXIST 17
+#define EXDEV 18
+#define ENODEV 19
+#define ENOTDIR 20
+#define EISDIR 21
+#define EINVAL 22
+#define ENFILE 23
+#define EMFILE 24
+#define ENOTTY 25
+#define ETXTBSY 26
+#define EFBIG 27
+#define ENOSPC 28
+#define ESPIPE 29
+#define EROFS 30
+#define EMLINK 31
+#define EPIPE 32
+#define EDOM 33
+#define ERANGE 34
+
+#endif // __LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H


        


More information about the libc-commits mailing list