File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed
utils/bazel/llvm-project-overlay/libc Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 2121#define LLVM_LIBC_FUNCTION_ATTR
2222#endif
2323
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+
2439// MacOS needs to be excluded because it does not support aliasing.
2540#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
2641#define LLVM_LIBC_FUNCTION_IMPL (type, name, arglist ) \
42+ LLVM_LIBC_ATTR (name) \
2743 LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
2844 __##name##_impl__ __asm__ (#name); \
2945 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(
5959 srcs ,
6060 weak = False ,
6161 copts = None ,
62- local_defines = None ,
62+ local_defines = [] ,
6363 ** kwargs ):
6464 """Add target for a libc function.
6565
@@ -108,16 +108,20 @@ def libc_function(
108108 name = libc_internal_target (name ),
109109 srcs = srcs ,
110110 copts = copts ,
111+ local_defines = local_defines ,
111112 ** kwargs
112113 )
113114
114115 # This second target is the llvm libc C function with either a default or hidden visibility.
115116 # 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 )
121125 _libc_library (
122126 name = name ,
123127 hidden = True ,
You can’t perform that action at this time.
0 commit comments