[libc-commits] [libc] [libc] Export standard C symbols in the public packages for MacOS instead of namespaced C++ symbols. (PR #136100)
via libc-commits
libc-commits at lists.llvm.org
Thu Apr 17 00:39:55 PDT 2025
https://github.com/lntue created https://github.com/llvm/llvm-project/pull/136100
None
>From 10ea67ded8ff06f7a4d6d452c1f50a2c229d4347 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Thu, 17 Apr 2025 15:31:27 +0800
Subject: [PATCH] [libc] Export standard C symbols in the public packages for
MacOS instead of namespaced C++ symbols.
---
libc/src/__support/common.h | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
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