[libc-commits] [libc] [libc] Set correct symbol visibility for baremetal build (PR #180486)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Mon Feb 9 00:38:10 PST 2026
https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/180486
We want to avoid unnecessary GOT relocations, such as when accessing symbols that are part of the embeddeding interface.
>From 258c3afde053f79a1f979e0777c127e3d84e3f61 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Sun, 8 Feb 2026 23:59:35 -0800
Subject: [PATCH] [libc] Set correct symbol visibility for baremetal build
We want to avoid unnecessary GOT relocations, such as when accessing
symbols that are part of the embeddeding interface.
---
libc/cmake/modules/CheckCompilerFeatures.cmake | 6 ++++++
libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 11 +++++++++++
2 files changed, 17 insertions(+)
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()
More information about the libc-commits
mailing list