[libc-commits] [libc] [libc] Set default visibility for LLVM functions (PR #116686)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Nov 19 13:20:47 PST 2024


jhuber6 wrote:

> @jhuber6 thoughts?
> 
> ```diff
> 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 `config.json` and also allow users to specify via CMake.

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


More information about the libc-commits mailing list