[libc-commits] [libc] [libc] Set default visibility to 'hidden' and make entrypoints default (PR #97123)

via libc-commits libc-commits at lists.llvm.org
Fri Jun 28 16:22:52 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
See for visibility: https://llvm.org/docs/LangRef.html#visibility-styles

Currently we build everything with default visibility, meaning that all
internal symbols are preemptable and visible to any `.so` they're linked
into. What we want is hidden visibility for all the internal parts, and
default visibility for the API functions / exposed globals.

This patch is based on https://github.com/llvm/llvm-project/pull/97109.


---
Full diff: https://github.com/llvm/llvm-project/pull/97123.diff


2 Files Affected:

- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+1-1) 
- (modified) libc/src/__support/common.h (+4) 


``````````diff
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 3bf429381d4af..73950f9dc1ce9 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -41,6 +41,7 @@ function(_get_common_compile_options output_var flags)
 
   if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
     list(APPEND compile_options "-fpie")
+    list(APPEND compile_options "-fvisibility=hidden")
 
     if(LLVM_LIBC_FULL_BUILD)
       list(APPEND compile_options "-DLIBC_FULL_BUILD")
@@ -94,7 +95,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 53951dc131c28..5b26a5a19f7c2 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -16,6 +16,10 @@
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/properties/architectures.h"
 
+#ifndef LIBC_TARGET_ARCH_IS_GPU
+#define LLVM_LIBC_FUNCTION_ATTR [[gnu::visibility("default")]]
+#endif
+
 #ifndef LLVM_LIBC_FUNCTION_ATTR
 #define LLVM_LIBC_FUNCTION_ATTR
 #endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/97123


More information about the libc-commits mailing list