-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc] Set default visibility for LLVM functions #116686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is a follow up to 5ff3ff3 addressing the issue reported in llvm#74881.
@llvm/pr-subscribers-libc Author: Petr Hosek (petrhosek) ChangesThis is a follow up to 5ff3ff3 addressing the issue reported in #74881. Full diff: https://github.com/llvm/llvm-project/pull/116686.diff 1 Files Affected:
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 48c773fa02c176..20d6f4c4a2af82 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -18,7 +18,7 @@
#include "src/__support/macros/properties/architectures.h"
#ifndef LLVM_LIBC_FUNCTION_ATTR
-#define LLVM_LIBC_FUNCTION_ATTR
+#define LLVM_LIBC_FUNCTION_ATTR [[gnu::visibility("default")]]
#endif
// MacOS needs to be excluded because it does not support aliasing.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This produces the global visibility for the non-namespaced symbols that was accidentally regressed by 5ff3ff3.
Though, I do wonder if the diff I proposed in #74881 (comment) perhaps would have been a smaller incision than 665efe8 + 5ff3ff3 ?
One potential issue with this patch might be that users who do use -DLLVM_LIBC_FUNCTION_ATTR
may be surprised that they may need to re-set default visibility.
We probably should document LLVM_LIBC_FUNCTION_ATTR
on https://libc.llvm.org/configure.html.
Something like: diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 20d6f4c4a2af..d11a0b557570 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -18,14 +18,14 @@
#include "src/__support/macros/properties/architectures.h"
#ifndef LLVM_LIBC_FUNCTION_ATTR
-#define LLVM_LIBC_FUNCTION_ATTR [[gnu::visibility("default")]]
+#define LLVM_LIBC_FUNCTION_ATTR
#endif
// MacOS needs to be excluded because it does not support aliasing.
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
- LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
- __##name##_impl__ __asm__(#name); \
+ LLVM_LIBC_FUNCTION_ATTR [[gnu::visibility("default")]] \
+ decltype(LIBC_NAMESPACE::name) __##name##_impl__ __asm__(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
#else might avoid that, but I guess I don't know if downstream you're specifically trying to avoid default visibility on the non-namespaced symbols by setting |
I cannot think of a reason why we'd ever want to expose the internal symbols, hence the need for 665efe8 + 5ff3ff3. The question is what should be the visibility for the symbols that are part of the public API, and I don't think there's one size fits all solution, it really depends on your use case. That's why we provide the |
Right, that's exactly what bionic would need to do, too, without this PR. Once this PR lands, Bionic (and zircon, I suspect) no longer need to set
If that's the only downstream use case...and this PR fixes that use case...
agree 💯 hence #74881. |
FWIW LLVM_LIBC_FUNCTION_ATTR is used to set the default visibility in the default Bazel configuration as well: llvm-project/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl Lines 114 to 120 in 6626ed6
|
So now that's three cases where downstream users are using (Bazel is also using LLVM_LIBC_FUNCTION_ATTR to add weak linkage attributes, but I think that can be better solved by @lntue's #116160). So I think we should:
My suggestion for 1 above would look like: diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 48c773fa02c1..45ded79f061a 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -24,6 +24,7 @@
// MacOS needs to be excluded because it does not support aliasing.
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
+ [[gnu::visibility("default")]] \
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
__##name##_impl__ __asm__(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \ My suggestion for 2 (stacked on top of 1) would look like: diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 45ded79f061a..5bb08c6a1195 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -17,16 +17,11 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
-#ifndef LLVM_LIBC_FUNCTION_ATTR
-#define LLVM_LIBC_FUNCTION_ATTR
-#endif
-
// MacOS needs to be excluded because it does not support aliasing.
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
[[gnu::visibility("default")]] \
- LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
- __##name##_impl__ __asm__(#name); \
+ decltype(LIBC_NAMESPACE::name) __##name##_impl__ __asm__(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
#else (There's a few other mentions of Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not want every symbol to have default visibility without some config. This will be very, very bad for the GPU case which wants LTO to be able to internalize these symbols. Visibility only matters if we are expecting shared libraries to pick up these definitions, which not all targets do.
@jhuber6 thoughts? diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 65851f1c8657..2686655f9f0f 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -184,7 +184,6 @@ function(_get_common_compile_options output_var flags)
endif()
if (LIBC_TARGET_OS_IS_GPU)
list(APPEND compile_options "-nogpulib")
- list(APPEND compile_options "-fvisibility=hidden")
list(APPEND compile_options "-fconvergent-functions")
list(APPEND compile_options "-flto")
list(APPEND compile_options "-Wno-multi-gpu")
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 45ded79f061a..92e985964f8c 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -21,10 +21,16 @@
#define LLVM_LIBC_FUNCTION_ATTR
#endif
+#ifdef LIBC_TARGET_ARCH_IS_GPU
+#define LIBC_PUBLIC_VIS [[gnu::visibility("hidden")]]
+#else
+#define LIBC_PUBLIC_VIS [[gnu::visibility("default")]]
+#endif
+
// MacOS needs to be excluded because it does not support aliasing.
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
- [[gnu::visibility("default")]] \
+ LIBC_PUBLIC_VIS \
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
__##name##_impl__ __asm__(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \ |
If we're going this route it should put in |
This is a flawed analysis because it ignores all users that don't set I agree with @jhuber6, I think we should keep |
IMO, the default visibility of |
While you cannot build |
Closing; @petrhosek and @frobtech were able to answer the remaining questions I had related to this. |
Ah, I forgot to respond to this point yesterday. Of the three cases I cited above where the visibility is set to default downstream, NONE are using CMake. So do I want to wire up a cmake option for this? Not particularly, since it doesn't seem like downstreams that care will be able to use the resulting option. |
also, technically users can use something like |
This is a follow up to 5ff3ff3 addressing the issue reported in #74881.