Skip to content
Snippets Groups Projects
  • Nathaniel Shead's avatar
    6a4d1c37
    libgcc, libstdc++: Make declarations no longer TU-local [PR115126] · 6a4d1c37
    Nathaniel Shead authored
    
    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: default avatarNathaniel Shead <nathanieloshead@gmail.com>
    Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
    Reviewed-by: default avatarJakub Jelinek <jakub@redhat.com>
    6a4d1c37
    History
    libgcc, libstdc++: Make declarations no longer TU-local [PR115126]
    Nathaniel Shead authored
    
    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: default avatarNathaniel Shead <nathanieloshead@gmail.com>
    Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
    Reviewed-by: default avatarJakub Jelinek <jakub@redhat.com>