Skip to content

[libc] Disable hidden visibility for LIBC_NAMESPACE with GCC #98549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

petrhosek
Copy link
Member

@petrhosek petrhosek commented Jul 11, 2024

GCC emits a warning when using the visibility attribute which needs to be diagnosed and addressed, but this change should unbreak the GCC build as a temporary workaround.

The issue is tracked as #98548.

GCC emits a warning when using the visibility attribute which needs
to be diagnosed and addressed, but this change should unbreak the GCC
build as a temporary workaround.
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2024

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

Changes

GCC emits a warning when using the visibility attribute which needs to be diagnosed and addressed, but this change should unbreak the GCC build as a temporary workaround.


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

1 Files Affected:

  • (modified) libc/src/__support/macros/config.h (+6)
diff --git a/libc/src/__support/macros/config.h b/libc/src/__support/macros/config.h
index 5c3ec634449f8..23436365cc544 100644
--- a/libc/src/__support/macros/config.h
+++ b/libc/src/__support/macros/config.h
@@ -28,6 +28,7 @@
 #define LIBC_HAS_FEATURE(f) 0
 #endif
 
+#ifndef __GNUC__
 // Declare a LIBC_NAMESPACE with hidden visibility. `namespace
 // LIBC_NAMESPACE_DECL {` should be used around all declarations and definitions
 // for libc internals as opposed to just `namespace LIBC_NAMESPACE {`. This
@@ -37,5 +38,10 @@
 // dynamic relocations. This does not affect the public C symbols which are
 // controlled independently via `LLVM_LIBC_FUNCTION_ATTR`.
 #define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] LIBC_NAMESPACE
+#else
+// TODO(#98548): GCC emits a warning when using the visibility attribute which
+// needs to be diagnosed and addressed.
+#define LIBC_NAMESPACE_DECL LIBC_NAMESPACE
+#endif
 
 #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H

@@ -28,6 +28,7 @@
#define LIBC_HAS_FEATURE(f) 0
#endif

#ifndef __GNUC__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think clang also define this macro. Probably #ifdef __clang__ is safer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -28,6 +28,7 @@
#define LIBC_HAS_FEATURE(f) 0
#endif

#ifndef __GNUC__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__GNUC__ is defined by many compilers, including Clang.
You need #ifdef __clang__ here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -28,6 +28,7 @@
#define LIBC_HAS_FEATURE(f) 0
#endif

#ifndef __GNUC__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't clang define __GNUC__ for compatibility? Would it be better to instead use #ifdef __clang__ instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 11, 2024

What is the warning? This should work in C++17 as far as I know https://godbolt.org/z/j94hxsTGa.

@michaelrj-google
Copy link
Contributor

What is the warning? This should work in C++17 as far as I know https://godbolt.org/z/j94hxsTGa.

From the buildbot:

/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/big_int.h: In instantiation of ‘constexpr __llvm_libc_19_0_0_git::cpp::array<word, N> __llvm_libc_19_0_0_git::multiword::shift(__llvm_libc_19_0_0_git::cpp::array<word, N>, size_t) [with Direction direction = __llvm_libc_19_0_0_git::multiword::RIGHT; bool is_signed = false; word = long unsigned int; long unsigned int N = 5; size_t = long unsigned int]’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/big_int.h:760:61:   required from ‘constexpr __llvm_libc_19_0_0_git::BigInt<Bits, Signed, WordType> __llvm_libc_19_0_0_git::BigInt<Bits, Signed, WordType>::operator>>(size_t) const [with long unsigned int Bits = 320; bool Signed = false; WordType = long unsigned int; size_t = long unsigned int]’
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/float_to_string.h:390:29:   required from here
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/big_int.h:281:28: error: ‘__llvm_libc_19_0_0_git::multiword::shift<__llvm_libc_19_0_0_git::multiword::RIGHT, false, long unsigned int, 5>(__llvm_libc_19_0_0_git::cpp::array<long unsigned int, 5>, size_t)::<lambda(size_t)>’ declared with greater visibility than the type of its field ‘__llvm_libc_19_0_0_git::multiword::shift<__llvm_libc_19_0_0_git::multiword::RIGHT, false, long unsigned int, 5>(__llvm_libc_19_0_0_git::cpp::array<long unsigned int, 5>, size_t)::<lambda(size_t)>::<array capture>’ [-Werror=attributes]
  281 |   const auto safe_get_at = [&](size_t index) -> word {
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  282 |     // return appropriate value when accessing out of bound elements.
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  283 |     const int i = at(index);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
  284 |     if (i < 0)
      |     ~~~~~~~~~~              
  285 |       return 0;
      |       ~~~~~~~~~             
  286 |     if (i >= int(N))
      |     ~~~~~~~~~~~~~~~~        
  287 |       return is_neg ? -1 : 0;
      |       ~~~~~~~~~~~~~~~~~~~~~~~
  288 |     return array[i];
      |     ~~~~~~~~~~~~~~~~        
  289 |   };
      |   ~                         

@petrhosek petrhosek merged commit 53cc24d into llvm:main Jul 11, 2024
4 of 5 checks passed
@petrhosek petrhosek deleted the libc-namespace-decl-clang branch July 12, 2024 07:27
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
)

GCC emits a warning when using the visibility attribute which needs to
be diagnosed and addressed, but this change should unbreak the GCC build
as a temporary workaround.

The issue is tracked as llvm#98548.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants