File tree 2 files changed +26
-6
lines changed
utils/bazel/llvm-project-overlay/libc
2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 21
21
#define LLVM_LIBC_FUNCTION_ATTR
22
22
#endif
23
23
24
+ // Allow each function `func` to have extra attributes specified by defining:
25
+ // `LLVM_LIBC_FUNCTION_ATTR_func` macro, which should always start with
26
+ // "LLVM_LIBC_EMPTY, "
27
+ //
28
+ // For examples:
29
+ // #define LLVM_LIBC_FUNCTION_ATTR_memcpy LLVM_LIBC_EMPTY, [[gnu::weak]]
30
+ // #define LLVM_LIBC_FUNCTION_ATTR_memchr LLVM_LIBC_EMPTY, [[gnu::weak]] \
31
+ // [[gnu::visibility("default")]]
32
+ #define LLVM_LIBC_EMPTY
33
+
34
+ #define GET_SECOND (first, second, ...) second
35
+ #define EXPAND_THEN_SECOND (name ) GET_SECOND(name, LLVM_LIBC_EMPTY)
36
+
37
+ #define LLVM_LIBC_ATTR (name ) EXPAND_THEN_SECOND(LLVM_LIBC_FUNCTION_ATTR_##name)
38
+
24
39
// MacOS needs to be excluded because it does not support aliasing.
25
40
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
26
41
#define LLVM_LIBC_FUNCTION_IMPL (type, name, arglist ) \
42
+ LLVM_LIBC_ATTR (name) \
27
43
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
28
44
__##name##_impl__ __asm__ (#name); \
29
45
decltype (LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ def libc_function(
59
59
srcs ,
60
60
weak = False ,
61
61
copts = None ,
62
- local_defines = None ,
62
+ local_defines = [] ,
63
63
** kwargs ):
64
64
"""Add target for a libc function.
65
65
@@ -108,16 +108,20 @@ def libc_function(
108
108
name = libc_internal_target (name ),
109
109
srcs = srcs ,
110
110
copts = copts ,
111
+ local_defines = local_defines ,
111
112
** kwargs
112
113
)
113
114
114
115
# This second target is the llvm libc C function with either a default or hidden visibility.
115
116
# All other functions are hidden.
116
- func_attrs = ["__attribute__((visibility(\" default\" )))" ]
117
- if weak :
118
- func_attrs = func_attrs + ["__attribute__((weak))" ]
119
- local_defines = local_defines or ["LIBC_COPT_PUBLIC_PACKAGING" ]
120
- local_defines = local_defines + ["LLVM_LIBC_FUNCTION_ATTR='%s'" % " " .join (func_attrs )]
117
+ func_attrs = [
118
+ "LLVM_LIBC_FUNCTION_ATTR_" + name + "='LLVM_LIBC_EMPTY, [[gnu::weak]]'" ,
119
+ ] if weak else []
120
+
121
+ local_defines = (local_defines
122
+ + ["LIBC_COPT_PUBLIC_PACKAGING" ]
123
+ + ["LLVM_LIBC_FUNCTION_ATTR='[[gnu::visibility(\" default\" )]]'" ]
124
+ + func_attrs )
121
125
_libc_library (
122
126
name = name ,
123
127
hidden = True ,
You can’t perform that action at this time.
0 commit comments