From: Siva Chandra Reddy Date: Tue, 20 Dec 2022 08:45:50 +0000 (+0000) Subject: [libc] Simplify generation of errno.h. X-Git-Tag: upstream/17.0.6~23067 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e750b86caf152c9f7a97ec5693c666806754cb6;p=platform%2Fupstream%2Fllvm.git [libc] Simplify generation of errno.h. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D140375 --- diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td index 76cc716..3afb925 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 50bbefb..0000000 --- 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 diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt index 40adef0..91ef757 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 da60aed..580a53f 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 + +#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 +#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 fe2652a..1cab22a 100644 --- a/libc/include/llvm-libc-macros/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/CMakeLists.txt @@ -1,6 +1,12 @@ add_subdirectory(linux) add_header( + generic_error_number_macros + HDR + generic-error-number-macros.h +) + +add_header( fcntl_macros HDR fcntl-macros.h 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 0000000..e652c60 --- /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