On Wed, 14 May 2025 at 17:31, François Dumont <frs.dum...@gmail.com> wrote:
>
> On 12/05/2025 23:03, Jonathan Wakely wrote:
> > On 31/03/25 22:20 +0200, François Dumont wrote:
> >> Hi
> >>
> >> Following this previous patch
> >> https://gcc.gnu.org/pipermail/libstdc++/2024-August/059418.html I've
> >> completed it for the _Safe_unordered_container_base type and
> >> implemented the rest of the change to store the safe iterator
> >> sequence as a pointer-to-const.
> >>
> >>     libstdc++: Make debug iterator pointer sequence const [PR116369]
> >>
> >>     In revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug
> >> sequence
> >>     have been made mutable to allow attach iterators to const
> >> containers.
> >>     This change completes this fix by also declaring debug unordered
> >> container
> >>     members mutable.
> >>
> >>     Additionally the debug iterator sequence is now a
> >> pointer-to-const and so
> >>     _Safe_sequence_base _M_attach and all other methods are const
> >> qualified.
> >>     Symbols export are maintained thanks to __asm directives.
> >>
> > I can't compile this, it seems to be missing changes to
> > safe_local_iterator.tcc:
> >
> > In file included from
> > /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_local_iterator.h:444,
> >                  from
> > /home/jwakely/src/gcc/gcc/libstdc++-v3/src/c++11/debug.cc:33:
> > /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_local_iterator.tcc:
> > In member function ‘typename
> > __gnu_debug::_Distance_traits<_Iterator>::__type
> > __gnu_debug::_Safe_local_iterator<_Iterator,
> > _Sequence>::_M_get_distance_to(const
> > __gnu_debug::_Safe_local_iterator<_Iterator, _Sequence>&) const’:
> > /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_local_iterator.tcc:47:17:
> > error: there are no arguments to ‘_M_get_sequence’ that depend on a
> > template parameter, so a declaration of ‘_M_get_sequence’ must be
> > available [-Wtemplate-body]
> >    47 | _M_get_sequence()->bucket_size(bucket()),
> >       |                 ^~~~~~~~~~~~~~~
> > /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_local_iterator.tcc:47:17:
> > note: (if you use ‘-fpermissive’, G++ will accept your code, but
> > allowing the use of an undeclared name is deprecated)
> > /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_local_iterator.tcc:59:18:
> > error: there are no arguments to ‘_M_get_sequence’ that depend on a
> > template parameter, so a declaration of ‘_M_get_sequence’ must be
> > available [-Wtemplate-body]
> >    59 | -_M_get_sequence()->bucket_size(bucket()),
> >       |                  ^~~~~~~~~~~~~~~
> >
> Yes, sorry, I had already spotted this problem, but only updated the PR
> and not re-sending patch here.
>
>
> >
> >> Also available as a PR
> >>
> >> https://forge.sourceware.org/gcc/gcc-TEST/pulls/47
> >>
> >>     /** Detach all singular iterators.
> >>      *  @post for all iterators i attached to this sequence,
> >>      *   i->_M_version == _M_version.
> >>      */
> >>     void
> >> -    _M_detach_singular();
> >> +    _M_detach_singular() const
> >> + __asm("_ZN11__gnu_debug19_Safe_sequence_base18_M_detach_singularEv");
> >
> > Does this work on all targets?
>
> No idea ! I thought the symbol name used here just had to match the
> entries in config/abi/pre/gnu.ver.

That linker script is not used for all targets.

>
> It is what other usages of __asm in the lib are doing for the moment, in
> <format> header, wo target considerations.

The _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT macro is only ever defined for
powerpc64le-unknown-linux-gnu so those uses in <format> are certainly
not without target considerations. They are used on exactly one
particular target, and no others.

>
>
> > I think darwin uses __Z as the prefix
> > for mangled names.
> > It might be necessary to use a macro to do this, so that it
> > conditionally puts "_" before the name.
> >
> If it's the only "exotic" target I can indeed deal with it with a macro.
> Otherwise I might have to find another alternative.
>
> Here is an updated version considering all your other remarks.
>
>      libstdc++: Make debug iterator pointer sequence const [PR116369]
>
>      In revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug sequence
>      have been made mutable to allow attach iterators to const containers.
>      This change completes this fix by also declaring debug unordered
> container
>      members mutable.
>
>      Additionally the debug iterator sequence is now a pointer-to-const
> and so
>      _Safe_sequence_base _M_attach and all other methods are const
> qualified.
>      Symbols export are maintained thanks to __asm directives.
>
>      libstdc++-v3/ChangeLog:
>
>              PR c++/116369
>              * include/debug/safe_base.h
>              (_Safe_iterator_base::_M_sequence): Declare as
> pointer-to-const.
>              (_Safe_iterator_base::_M_attach, _M_attach_single): Take
> pointer-to-const
>              _Safe_sequence_base. Add __asm directive to preserve name
> mangling.
>              (_Safe_sequence_base::_M_detach_all, _M_detach_singular,
> _M_revalidate_singular)
>              (_M_swap, _M_get_mutex, _M_attach, _M_attach_single,
> _M_detash, _M_detash_single):
>              Add const qualifier and __asm directive to preserve name
> mangling.
>              * include/debug/safe_unordered_base.h
>              (_Safe_local_iterator_base::_M_safe_container): New.
> (_Safe_local_iterator_base::_Safe_local_iterator_base): Take
>              _Safe_unordered_container_base as pointer-to-const.
>              (_Safe_unordered_container_base::_M_attach,
> _M_attach_single): Take
>              _Safe_unordered_container_base as pointer-to-const. Add
> __asm directive to preserve
>              name mangling.
>              (_Safe_unordered_container_base::_M_local_iterators,
> _M_const_local_iterators):
>              Add mutable.
>              (_Safe_unordered_container_base::_M_detach_all, _M_swap,
> _M_attach_local)
>              (_M_attach_local_single, _M_detach_local,
> _M_detach_local_single): Add const
>              qualifier and __asm directive to preserve name mangling.
>              * include/debug/safe_iterator.h
> (_Safe_iterator<>::_M_attach, _M_attach_single):
>              Take _Safe_sequence_base as pointer-to-const.
>              (_Safe_iterator<>::_M_get_sequence): Add const_cast and
> comment about it.
>              * include/debug/safe_local_iterator.h
> (_Safe_local_iterator<>): Replace usages
>              of _M_sequence member by _M_safe_container().
>              (_Safe_local_iterator<>::_M_attach, _M_attach_single): Take
>              _Safe_unordered_container_base as pointer-to-const.
>              (_Safe_local_iterator<>::_M_get_sequence): Rename into...
>              (_Safe_local_iterator<>::_M_get_ucontainer): ...this. Add
> necessary const_cast and
>              comment to explain it.
>              * include/debug/safe_local_iterator.tcc: Adapt.
>              * include/debug/formatter.h: Adapt.
>              * include/debug/safe_sequence.h
>              (_Safe_sequence<>::_M_invalidate_if, _M_transfer_from_if):
> Add const qualifier.
>              * include/debug/safe_sequence.tcc: Adapt.
>              * src/c++11/debug.cc: Adapt to const qualification.
>              * testsuite/util/testsuite_containers.h
> (forward_members_unordered::forward_members_unordered): Add check on
> local_iterator
>              conversion to const_local_iterator.
>              (forward_members::forward_members): Add check on iterator
> conversion to
>              const_iterator.
>
> François
>

Reply via email to