Skip to content

Commit dd33f9c

Browse files
author
Siva Chandra Reddy
committed
[libc] Make the errno macro resolve to the thread local variable directly.
With modern architectures having a thread pointer and language supporting thread locals, there is no reason to use a function intermediary to access the thread local errno value. The entrypoint corresponding to errno has been replaced with an object library as there is no formal entrypoint for errno anymore. Reviewed By: jeffbailey, michaelrj Differential Revision: https://reviews.llvm.org/D120920
1 parent fa8293b commit dd33f9c

File tree

28 files changed

+67
-120
lines changed

28 files changed

+67
-120
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ set(TARGET_LIBC_ENTRYPOINTS
1717
libc.src.ctype.tolower
1818
libc.src.ctype.toupper
1919

20-
# errno.h entrypoints
21-
libc.src.errno.__errno_location
22-
2320
# fcntl.h entrypoints
2421
libc.src.fcntl.creat
2522
libc.src.fcntl.open

libc/config/linux/api.td

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ def NullMacro : MacroDef<"NULL"> {
4444

4545
def ErrnoMacro : MacroDef<"errno"> {
4646
let Defn = [{
47-
#ifdef __cplusplus
48-
extern "C"
49-
#endif
50-
int *__errno_location();
51-
#define errno (*__errno_location())
47+
extern _Thread_local int __llvmlibc_errno;
48+
#define errno __llvmlibc_errno
5249
}];
5350
}
5451

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ set(TARGET_LIBC_ENTRYPOINTS
1717
libc.src.ctype.tolower
1818
libc.src.ctype.toupper
1919

20-
# errno.h entrypoints
21-
libc.src.errno.__errno_location
22-
2320
# fcntl.h entrypoints
2421
libc.src.fcntl.creat
2522
libc.src.fcntl.open

libc/include/__llvm-libc-common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#undef _Alignof
3030
#define _Alignof alignof
3131

32+
#undef _Thread_local
33+
#define _Thread_local thread_local
34+
3235
#else // not __cplusplus
3336

3437
#undef __BEGIN_C_DECLS

libc/spec/llvm_libc_ext.td

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
3333
]
3434
>;
3535

36-
HeaderSpec Errno = HeaderSpec<
37-
"errno.h",
38-
[], // Macros
39-
[], // Types
40-
[], // Enumerations
41-
[
42-
FunctionSpec<
43-
"__errno_location",
44-
RetValSpec<IntPtr>,
45-
[ArgSpec<VoidType>]
46-
47-
>,
48-
]
49-
>;
50-
5136
let Headers = [
5237
String,
5338
Assert,
54-
Errno,
5539
];
5640
}

libc/src/__support/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_header_library(
2222
DEPENDS
2323
.ctype_utils
2424
libc.include.errno
25-
libc.src.errno.__errno_location
25+
libc.src.errno.errno
2626
libc.src.__support.CPP.standalone_cpp
2727
)
2828

@@ -43,7 +43,7 @@ add_header_library(
4343
.ctype_utils
4444
.high_precision_decimal
4545
libc.include.errno
46-
libc.src.errno.__errno_location
46+
libc.src.errno.errno
4747
libc.src.__support.CPP.standalone_cpp
4848
libc.src.__support.FPUtil.fputil
4949
)

libc/src/__support/FPUtil/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ add_header_library(
2121
libc.include.fenv
2222
libc.src.__support.common
2323
libc.src.__support.CPP.standalone_cpp
24-
libc.src.errno.__errno_location
24+
libc.src.errno.errno
2525
)
2626

2727
add_header_library(

libc/src/__support/File/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ add_object_library(
55
HDRS
66
file.h
77
DEPENDS
8-
libc.src.errno.__errno_location
8+
libc.include.errno
9+
libc.src.errno.errno
910
)

libc/src/errno/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
if (LLVM_LIBC_FULL_BUILD)
2-
add_entrypoint_object(
3-
__errno_location
2+
add_object_library(
3+
errno
44
SRCS
5-
__errno_location.cpp
5+
errno.cpp
66
HDRS
7-
__errno_location.h
87
llvmlibc_errno.h
98
)
109
else()
11-
add_entrypoint_object(
12-
__errno_location
10+
add_object_library(
11+
errno
1312
SRCS
1413
dummy_errno.cpp
1514
HDRS

libc/src/errno/__errno_location.cpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)