aboutsummaryrefslogtreecommitdiff
path: root/libgcc/gthr-single.h
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-09-24 23:53:59 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2024-09-27 09:16:53 +1000
commit6a4d1c374eed177eceb12a50f3b25bd20f8b347a (patch)
treeebcdd37092471cd6d3fd08aa203c1485205ec8cf /libgcc/gthr-single.h
parent6ac4e2f4b2ca9980670e7d3815a9140730df1005 (diff)
downloadgcc-6a4d1c374eed177eceb12a50f3b25bd20f8b347a.zip
gcc-6a4d1c374eed177eceb12a50f3b25bd20f8b347a.tar.gz
gcc-6a4d1c374eed177eceb12a50f3b25bd20f8b347a.tar.bz2
libgcc, libstdc++: Make declarations no longer TU-local [PR115126]
In C++20, modules streaming check for exposures of TU-local entities. In general exposing internal linkage functions in a header is liable to cause ODR violations in C++, and this is now detected in a module context. This patch goes through and removes 'static' from many declarations exposed through libstdc++ to prevent code like the following from failing: export module M; extern "C++" { #include <bits/stdc++.h> } Since gthreads is used from C as well, we need to choose whether to use 'inline' or 'static inline' depending on whether we're compiling for C or C++ (since the semantics of 'inline' are different between the languages). Additionally we need to remove static global variables, so we migrate these to function-local statics to avoid the ODR issues. There doesn't seem to be a good workaround for weakrefs, so I've left them as-is and will work around it in the modules streaming code to consider them as not TU-local. The same issue occurs in the objective-C specific parts of gthreads, but I'm not familiar with the surrounding context and we don't currently test modules with Objective C++ anyway so I've left it as-is. PR libstdc++/115126 libgcc/ChangeLog: * gthr-posix.h (__GTHREAD_ALWAYS_INLINE): New macro. (__GTHREAD_INLINE): New macro. (__gthread_active): Convert from variable to (hidden) function. (__gthread_active_p): Mark as __GTHREAD_INLINE instead of static; make visibility("hidden") when it has a static local variable. (__gthread_trigger): Mark as __GTHREAD_INLINE instead of static. (__gthread_create): Likewise. (__gthread_join): Likewise. (__gthread_detach): Likewise. (__gthread_equal): Likewise. (__gthread_self): Likewise. (__gthread_yield): Likewise. (__gthread_once): Likewise. (__gthread_key_create): Likewise. (__gthread_key_delete): Likewise. (__gthread_getspecific): Likewise. (__gthread_setspecific): Likewise. (__gthread_mutex_init_function): Likewise. (__gthread_mutex_destroy): Likewise. (__gthread_mutex_lock): Likewise. (__gthread_mutex_trylock): Likewise. (__gthread_mutex_timedlock): Likewise. (__gthread_mutex_unlock): Likewise. (__gthread_recursive_mutex_init_function): Likewise. (__gthread_recursive_mutex_lock): Likewise. (__gthread_recursive_mutex_trylock): Likewise. (__gthread_recursive_mutex_timedlock): Likewise. (__gthread_recursive_mutex_unlock): Likewise. (__gthread_recursive_mutex_destroy): Likewise. (__gthread_cond_init_function): Likewise. (__gthread_cond_broadcast): Likewise. (__gthread_cond_signal): Likewise. (__gthread_cond_wait): Likewise. (__gthread_cond_timedwait): Likewise. (__gthread_cond_wait_recursive): Likewise. (__gthread_cond_destroy): Likewise. (__gthread_rwlock_rdlock): Likewise. (__gthread_rwlock_tryrdlock): Likewise. (__gthread_rwlock_wrlock): Likewise. (__gthread_rwlock_trywrlock): Likewise. (__gthread_rwlock_unlock): Likewise. * gthr-single.h: (__GTHREAD_ALWAYS_INLINE): New macro. (__GTHREAD_INLINE): New macro. (__gthread_active_p): Mark as __GTHREAD_INLINE instead of static. (__gthread_once): Likewise. (__gthread_key_create): Likewise. (__gthread_key_delete): Likewise. (__gthread_getspecific): Likewise. (__gthread_setspecific): Likewise. (__gthread_mutex_destroy): Likewise. (__gthread_mutex_lock): Likewise. (__gthread_mutex_trylock): Likewise. (__gthread_mutex_unlock): Likewise. (__gthread_recursive_mutex_lock): Likewise. (__gthread_recursive_mutex_trylock): Likewise. (__gthread_recursive_mutex_unlock): Likewise. (__gthread_recursive_mutex_destroy): Likewise. libstdc++-v3/ChangeLog: * include/bits/shared_ptr.h (std::__is_shared_ptr): Remove unnecessary 'static'. * include/bits/unique_ptr.h (std::__is_unique_ptr): Likewise. * include/std/future (std::__create_task_state): Likewise. * include/std/shared_mutex (_GLIBCXX_GTRHW): Likewise. (__glibcxx_rwlock_init): Likewise. (__glibcxx_rwlock_timedrdlock): Likewise. (__glibcxx_rwlock_timedwrlock): Likewise. (__glibcxx_rwlock_rdlock): Likewise. (__glibcxx_rwlock_tryrdlock): Likewise. (__glibcxx_rwlock_wrlock): Likewise. (__glibcxx_rwlock_trywrlock): Likewise. (__glibcxx_rwlock_unlock): Likewise. (__glibcxx_rwlock_destroy): Likewise. (__glibcxx_rwlock_init): Likewise. * include/pstl/algorithm_impl.h (__pstl::__internal::__set_algo_cut_off): Mark inline. * include/pstl/unseq_backend_simd.h (__pstl::__unseq_backend::__lane_size): Mark inline. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Jakub Jelinek <jakub@redhat.com>
Diffstat (limited to 'libgcc/gthr-single.h')
-rw-r--r--libgcc/gthr-single.h45
1 files changed, 31 insertions, 14 deletions
diff --git a/libgcc/gthr-single.h b/libgcc/gthr-single.h
index 8ee6b17..2a799ad 100644
--- a/libgcc/gthr-single.h
+++ b/libgcc/gthr-single.h
@@ -38,6 +38,21 @@ typedef int __gthread_recursive_mutex_t;
#define __GTHREAD_MUTEX_INIT_FUNCTION(mx) do {} while (0)
#define __GTHREAD_RECURSIVE_MUTEX_INIT 0
+#ifdef __has_attribute
+# if __has_attribute(__always_inline__)
+# define __GTHREAD_ALWAYS_INLINE __attribute__((__always_inline__))
+# endif
+#endif
+#ifndef __GTHREAD_ALWAYS_INLINE
+# define __GTHREAD_ALWAYS_INLINE
+#endif
+
+#ifdef __cplusplus
+# define __GTHREAD_INLINE inline __GTHREAD_ALWAYS_INLINE
+#else
+# define __GTHREAD_INLINE static inline
+#endif
+
#define UNUSED __attribute__((__unused__))
#ifdef _LIBOBJC
@@ -207,85 +222,85 @@ __gthread_objc_condition_signal (objc_condition_t condition UNUSED)
#else /* _LIBOBJC */
-static inline int
+__GTHREAD_INLINE int
__gthread_active_p (void)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_once (__gthread_once_t *__once UNUSED, void (*__func) (void) UNUSED)
{
return 0;
}
-static inline int UNUSED
+__GTHREAD_INLINE int UNUSED
__gthread_key_create (__gthread_key_t *__key UNUSED, void (*__func) (void *) UNUSED)
{
return 0;
}
-static int UNUSED
+__GTHREAD_INLINE int UNUSED
__gthread_key_delete (__gthread_key_t __key UNUSED)
{
return 0;
}
-static inline void *
+__GTHREAD_INLINE void *
__gthread_getspecific (__gthread_key_t __key UNUSED)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_setspecific (__gthread_key_t __key UNUSED, const void *__v UNUSED)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_destroy (__gthread_mutex_t *__mutex UNUSED)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_lock (__gthread_mutex_t *__mutex UNUSED)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_trylock (__gthread_mutex_t *__mutex UNUSED)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_unlock (__gthread_mutex_t *__mutex UNUSED)
{
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_lock (__mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_trylock (__mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_unlock (__mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_destroy (__mutex);
@@ -294,5 +309,7 @@ __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
#endif /* _LIBOBJC */
#undef UNUSED
+#undef __GTHREAD_INLINE
+#undef __GTHREAD_ALWAYS_INLINE
#endif /* ! GCC_GTHR_SINGLE_H */