Skip to content

Allow use of dragonfly locale code so non-C locales work. - #56

Open
Bill-Sommerfeld wants to merge 4 commits into
illumos:il-14_2_0from
Bill-Sommerfeld:il-14_2_0_bug7354
Open

Bill-Sommerfeld wants to merge 4 commits into
illumos:il-14_2_0from
Bill-Sommerfeld:il-14_2_0_bug7354

Conversation

@Bill-Sommerfeld

Copy link
Copy Markdown

This tweaks the libstdc++ configure script to let you pass --enable-clocale=dragonfly to select the dragonfly locale code; this will only work on illumos if you also have the illumos-gate changes in https://code.illumos.org/c/illumos-gate/+/4242

The ctype_members.cc patch is from Jonathan Perkin's patch in pkgsrc-extra and is needed to avoid undefined symbols.

From Jonathan Perkin's patch in pkgsrc-extra
@Bill-Sommerfeld
Bill-Sommerfeld marked this pull request as ready for review May 18, 2025 00:44
Bill-Sommerfeld added a commit to Bill-Sommerfeld/oi-userland that referenced this pull request Feb 10, 2026
The generic locale implementation chosen naturally by gcc's configure
throws an exception if a locale other than "C" is selected.  We can do
better.

Use the DragonflyBSD locale support with a few minor changes.

From my illumos-gcc pull request, illumos/gcc#56
Bill-Sommerfeld added a commit to Bill-Sommerfeld/oi-userland that referenced this pull request Feb 10, 2026
The generic locale implementation chosen naturally by gcc's configure
throws an exception if a locale other than "C" is selected.  We can do
better.

Use the DragonflyBSD locale support with a few minor changes.

From my illumos-gcc pull request, illumos/gcc#56
AndWac pushed a commit to OpenIndiana/oi-userland that referenced this pull request Feb 10, 2026
The generic locale implementation chosen naturally by gcc's configure
throws an exception if a locale other than "C" is selected.  We can do
better.

Use the DragonflyBSD locale support with a few minor changes.

From my illumos-gcc pull request, illumos/gcc#56
encoded characters.  C++'s locale interface can only cope with a
single char or a single wchar_t.
@hebasto

hebasto commented Oct 1, 2026

Copy link
Copy Markdown

On distros where GCC is already configured with --enable-clocale=dragonfly (OmniOS, OpenIndiana), the ~ctype() destructor passes garbage to freelocale().

Here is an MRE:

// test.cpp
#include <iostream>
#include <locale>
#include <stdexcept>
int main()
{
    try {
        std::locale("");
    } catch (const std::runtime_error& e) {
        std::cout << e.what() << '\n';
    }
}

It fails reproducibly as follows:

$ g++ -std=c++20 test.cpp -o test
$ LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test
sh: line 4: 813: Memory fault(coredump)

Stack trace from the core dump:

C++ symbol demangling enabled
debugging core file of test (64-bit) from omnios
file: test
initial argv: ./test
threading model: native threads
status: process terminated by SIGSEGV (Segmentation Fault), addr=fffffc7fedb052c1
fffffc7fffdf9940 libc.so.1`freelocale+0x11()
fffffc7fffdf9960 libstdc++.so.6.0.34`std::ctype<char>::~ctype+0x11()
fffffc7fffdf99b0 libstdc++.so.6.0.34`std::locale::_Impl::~_Impl+0x282()
fffffc7fffdf99d0 libstdc++.so.6.0.34`std::locale::~locale+0x56()
fffffc7fffdf9a00 main+0x26()
fffffc7fffdf9a30 _start_crt+0x87()
fffffc7fffdf9a40 _start+0x18()

@Bill-Sommerfeld

Copy link
Copy Markdown
Author

On distros where GCC is already configured with --enable-clocale=dragonfly (OmniOS, OpenIndiana), the ~ctype() destructor passes garbage to freelocale().

It appears that this is due to missing member initializers in the ctype<char>::ctype constructors in .../config/os/solaris/ctype_configure_char.cc; the member _M_c_locale_ctype is initialized on other platforms but not in the implementation in that file.

Fix looks straightforward.

@Bill-Sommerfeld

Copy link
Copy Markdown
Author

The fix pending in openindiana avoids the crash:

testrunner@openindiana:/tmp$ unset LD_PRELOAD_64
testrunner@openindiana:/tmp$ LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test
Segmentation Fault         (core dumped) LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test
testrunner@openindiana:/tmp$ export LD_PRELOAD_64=/rpool/oi-userland/components/developer/gcc-14/build/prototype/i386/usr/gcc/14/lib/amd64/libstdc++.so.6.0.33
testrunner@openindiana:/tmp$ LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test

AndWac pushed a commit to OpenIndiana/oi-userland that referenced this pull request Oct 3, 2026
As reported in illumos/gcc#56 (comment)

testrunner@openindiana:/tmp$ unset LD_PRELOAD_64
testrunner@openindiana:/tmp$ LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test
Segmentation Fault         (core dumped) LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test
testrunner@openindiana:/tmp$ export LD_PRELOAD_64=/rpool/oi-userland/components/developer/gcc-14/build/amd64/x86_64-pc-solaris2.11/libstdc++-v3/src/.libs/libstdc++.so.6.0.33
testrunner@openindiana:/tmp$ LANG=C.UTF-8 LD_PRELOAD=libumem.so.1 UMEM_DEBUG=guards ./test

Also add patch 1003-clean-up-lconv.patch to address code review comments
@Bill-Sommerfeld

Copy link
Copy Markdown
Author

Sorry for the delay in adding the ctype initialization fix to this pull request.

@rmustacc

rmustacc commented Nov 8, 2026

Copy link
Copy Markdown

@Bill-Sommerfeld and @ citrus-it do we have final gcc tests for this? I presume we want to keep this as the full set of four commits that we move from release to release and not squash anything?

@citrus-it

Copy link
Copy Markdown
Member

@Bill-Sommerfeld and @ citrus-it do we have final gcc tests for this? I presume we want to keep this as the full set of four commits that we move from release to release and not squash anything?

I've been doing some work with gcc16 and trying to get the testsuite in better shape for us in general, for example properly handling the difference in output with -msave-args. As part of that I found some locale bugs that we probably should fix here too. The first one is something that gcc fixed for glibc in 2024, but they didn't deal with the dragonfly variant. Together these improve test results for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants