[libc-commits] [libc] [libc] Add LIBC_NAMESPACE_HIDDEN_DECL macro (PR #97109)
via libc-commits
libc-commits at lists.llvm.org
Fri Jun 28 13:30:56 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (PiJoules)
<details>
<summary>Changes</summary>
This defines to LIBC_NAMESPACE with
`__attribute__((visibility("hidden")))` so all the symbols under it have hidden visibility. Individual namespace declarations can opt-in to use this. This is useful for baremetal where we can avoid GOT entries for globals.
---
Full diff: https://github.com/llvm/llvm-project/pull/97109.diff
3 Files Affected:
- (modified) libc/src/__support/macros/config.h (+4)
- (modified) libc/src/stdlib/rand_util.cpp (+3-2)
- (modified) libc/src/stdlib/rand_util.h (+3-2)
``````````diff
diff --git a/libc/src/__support/macros/config.h b/libc/src/__support/macros/config.h
index 6390c7992325d..0380c8d6c8b89 100644
--- a/libc/src/__support/macros/config.h
+++ b/libc/src/__support/macros/config.h
@@ -27,4 +27,8 @@
#define LIBC_HAS_FEATURE(f) 0
#endif
+// Declare a LIBC_NAMESPACE with hidden visibility. This can be used on a
+// case-by-case basis where sets of symbols within this declaration are hidden.
+#define LIBC_NAMESPACE_HIDDEN_DECL [[gnu::visibility("hidden")]] LIBC_NAMESPACE
+
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H
diff --git a/libc/src/stdlib/rand_util.cpp b/libc/src/stdlib/rand_util.cpp
index ff3478db70003..1f3e03679ba19 100644
--- a/libc/src/stdlib/rand_util.cpp
+++ b/libc/src/stdlib/rand_util.cpp
@@ -9,11 +9,12 @@
#include "src/stdlib/rand_util.h"
#include "src/__support/CPP/atomic.h"
#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
-namespace LIBC_NAMESPACE {
+namespace LIBC_NAMESPACE_HIDDEN_DECL {
// C standard 7.10p2: If 'rand' is called before 'srand' it is to
// proceed as if the 'srand' function was called with a value of '1'.
cpp::Atomic<unsigned long> rand_next = 1;
-} // namespace LIBC_NAMESPACE
+} // namespace LIBC_NAMESPACE_HIDDEN_DECL
diff --git a/libc/src/stdlib/rand_util.h b/libc/src/stdlib/rand_util.h
index 5d7febf8248d8..2de48f035d784 100644
--- a/libc/src/stdlib/rand_util.h
+++ b/libc/src/stdlib/rand_util.h
@@ -11,14 +11,15 @@
#include "src/__support/CPP/atomic.h"
#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
-namespace LIBC_NAMESPACE {
+namespace LIBC_NAMESPACE_HIDDEN_DECL {
// The ISO C standard does not explicitly require thread-safe behavior for the
// generic `rand()` function. Some implementations expect it however, so we
// provide it here.
extern cpp::Atomic<unsigned long> rand_next;
-} // namespace LIBC_NAMESPACE
+} // namespace LIBC_NAMESPACE_HIDDEN_DECL
#endif // LLVM_LIBC_SRC_STDLIB_RAND_UTIL_H
``````````
</details>
https://github.com/llvm/llvm-project/pull/97109
More information about the libc-commits
mailing list