[libc-commits] [libc] [libc] Set correct symbol visibility for baremetal build (PR #180486)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 9 00:38:34 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Petr Hosek (petrhosek)
<details>
<summary>Changes</summary>
We want to avoid unnecessary GOT relocations, such as when accessing symbols that are part of the embeddeding interface.
---
Full diff: https://github.com/llvm/llvm-project/pull/180486.diff
2 Files Affected:
- (modified) libc/cmake/modules/CheckCompilerFeatures.cmake (+6)
- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+11)
``````````diff
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index 4d50d81e0ce45..a7b4669914671 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -141,6 +141,12 @@ message(STATUS "Compiler features available: ${AVAILABLE_COMPILER_FEATURES}")
### Compiler Feature Detection ###
+# clang-8+
+check_cxx_compiler_flag("-Xclang -fapply-global-visibility-to-externs" LIBC_CC_SUPPORTS_APPLY_GLOBAL_VISIBILITY_TO_EXTERNS)
+
+# clang-12+
+check_cxx_compiler_flag("-fdirect-access-external-data" LIBC_CC_SUPPORTS_DIRECT_ACCESS_EXTERNAL_DATA)
+
# clang-8+, gcc-12+
check_cxx_compiler_flag("-ftrivial-auto-var-init=pattern" LIBC_CC_SUPPORTS_PATTERN_INIT)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 98fc0206daa44..6f15c9d500f22 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -211,6 +211,17 @@ function(_get_common_compile_options output_var flags)
endif()
endif()
+ if (LIBC_TARGET_OS_IS_BAREMETAL)
+ list(APPEND compile_options "-fvisibility=hidden")
+ list(APPEND compile_options "-fvisibility-inlines-hidden")
+ if (LIBC_CC_SUPPORTS_APPLY_GLOBAL_VISIBILITY_TO_EXTERNS)
+ list(APPEND compile_options "SHELL:-Xclang -fapply-global-visibility-to-externs")
+ endif()
+ if (LIBC_CC_SUPPORTS_DIRECT_ACCESS_EXTERNAL_DATA)
+ list(APPEND compile_options "-fdirect-access-external-data")
+ endif()
+ endif()
+
if(LIBC_COMPILER_HAS_FIXED_POINT)
list(APPEND compile_options "-ffixed-point")
endif()
``````````
</details>
https://github.com/llvm/llvm-project/pull/180486
More information about the libc-commits
mailing list