[libc-commits] [libc] f351172 - [libc] Export standard C symbols in the public packages for MacOS instead of namespaced C++ symbols. (#136100)
via libc-commits
libc-commits at lists.llvm.org
Thu Apr 17 01:02:47 PDT 2025
Author: lntue
Date: 2025-04-17T16:02:44+08:00
New Revision: f351172d4a840dfbf533319b62925747a10b762f
URL: https://github.com/llvm/llvm-project/commit/f351172d4a840dfbf533319b62925747a10b762f
DIFF: https://github.com/llvm/llvm-project/commit/f351172d4a840dfbf533319b62925747a10b762f.diff
LOG: [libc] Export standard C symbols in the public packages for MacOS instead of namespaced C++ symbols. (#136100)
Added:
Modified:
libc/src/__support/common.h
Removed:
################################################################################
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 42e8a79187fac..15209b76978af 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -37,17 +37,27 @@
#define LLVM_LIBC_ATTR(name) EXPAND_THEN_SECOND(LLVM_LIBC_FUNCTION_ATTR_##name)
-// MacOS needs to be excluded because it does not support aliasing.
-#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
+// At the moment, [[gnu::alias()]] is not supported on MacOS, and it is needed
+// to cleanly export and alias the C++ symbol `LIBC_NAMESPACE::func` with the C
+// symbol `func`. So for public packaging on MacOS, we will only export the C
+// symbol. Moreover, a C symbol `func` in macOS is mangled as `_func`.
+#if defined(LIBC_COPT_PUBLIC_PACKAGING)
+#ifndef __APPLE__
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
LLVM_LIBC_ATTR(name) \
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
__##name##_impl__ __asm__(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
-#else
+#else // __APPLE__
+#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
+ LLVM_LIBC_ATTR(name) \
+ LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) name asm("_" #name); \
+ type name arglist
+#endif // __APPLE__
+#else // LIBC_COPT_PUBLIC_PACKAGING
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) type name arglist
-#endif
+#endif // LIBC_COPT_PUBLIC_PACKAGING
// This extra layer of macro allows `name` to be a macro to rename a function.
#define LLVM_LIBC_FUNCTION(type, name, arglist) \
More information about the libc-commits
mailing list