Skip to content

Commit f351172

Browse files
authored
[libc] Export standard C symbols in the public packages for MacOS instead of namespaced C++ symbols. (#136100)
1 parent d41bd1f commit f351172

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

libc/src/__support/common.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,27 @@
3737

3838
#define LLVM_LIBC_ATTR(name) EXPAND_THEN_SECOND(LLVM_LIBC_FUNCTION_ATTR_##name)
3939

40-
// MacOS needs to be excluded because it does not support aliasing.
41-
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
40+
// At the moment, [[gnu::alias()]] is not supported on MacOS, and it is needed
41+
// to cleanly export and alias the C++ symbol `LIBC_NAMESPACE::func` with the C
42+
// symbol `func`. So for public packaging on MacOS, we will only export the C
43+
// symbol. Moreover, a C symbol `func` in macOS is mangled as `_func`.
44+
#if defined(LIBC_COPT_PUBLIC_PACKAGING)
45+
#ifndef __APPLE__
4246
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
4347
LLVM_LIBC_ATTR(name) \
4448
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
4549
__##name##_impl__ __asm__(#name); \
4650
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
4751
type __##name##_impl__ arglist
48-
#else
52+
#else // __APPLE__
53+
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
54+
LLVM_LIBC_ATTR(name) \
55+
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) name asm("_" #name); \
56+
type name arglist
57+
#endif // __APPLE__
58+
#else // LIBC_COPT_PUBLIC_PACKAGING
4959
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) type name arglist
50-
#endif
60+
#endif // LIBC_COPT_PUBLIC_PACKAGING
5161

5262
// This extra layer of macro allows `name` to be a macro to rename a function.
5363
#define LLVM_LIBC_FUNCTION(type, name, arglist) \

0 commit comments

Comments
 (0)