Project

General

Profile

Actions

Bug #7354

open

std::locale("") does not work properly

Added by Denis Kozadaev about 7 years ago. Updated over 6 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Category:
lib - userland libraries
Start date:
2016-09-02
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:
External Bug:

Description

We have a small program:

witch% cat main.cpp 
#include <locale>
#include <iostream>

int
main(void)
{

    std::locale loc = std::locale("");
    std::cout<<loc.name()<<std::endl;

    return (0);
}

Let compile it and run:
witch% g++ -g -O0 -o tst main.cpp 
witch% ./tst 
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
zsh: IOT instruction (core dumped)  ./tst

This error does not depend of the locale except C/POSIX,
my current locale is en_US.UTF-8:
witch% locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8" 
LC_NUMERIC="en_US.UTF-8" 
LC_TIME="en_US.UTF-8" 
LC_COLLATE="en_US.UTF-8" 
LC_MONETARY="en_US.UTF-8" 
LC_MESSAGES="en_US.UTF-8" 
LC_ALL=en_US.UTF-8

Now, let change it to C or POSIX:
witch% LC_ALL=C ./tst
C
witch% LC_ALL=POSIX ./tst
C

So, it works, now let recompile it using Sun CC:
witch% CC -g -o tst main.cpp 
witch% ./tst 
en_US.UTF-8

and (wow!) It works correctly!
Let see in the deep core of libstdc++ :)
witch% gdb tst tst-7045.core 
Core was generated by `./tst'.
Program terminated with signal SIGABRT, Aborted.
#0  0xfed6fa07 in _lwp_kill () from /lib/libc.so.1
[Current thread is 3 (Thread 1 (LWP 1))]
(gdb) up
#1  0xfed67972 in thr_kill () from /lib/libc.so.1
(gdb) 
#2  0xfed055cb in raise () from /lib/libc.so.1
(gdb) 
#3  0xfece01ce in abort () from /lib/libc.so.1
(gdb) 
#4  0xfeeb2e45 in __gnu_cxx::__verbose_terminate_handler ()
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/libsupc++/vterminate.cc:95
95        abort();
(gdb) 
#5  0xfeeaf9b7 in __cxxabiv1::__terminate (handler=0xfeeb2cc0 <__gnu_cxx::__verbose_terminate_handler()>)
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/libsupc++/eh_terminate.cc:47
47          handler ();
(gdb) 
#6  0xfeeafa50 in std::terminate ()
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/libsupc++/eh_terminate.cc:57
57      __terminate (get_terminate ());
(gdb) 
#7  0xfeeafcee in __cxxabiv1::__cxa_throw (obj=0x8062140, tinfo=0xfef5e36c <typeinfo for std::runtime_error>, dest=
    0xfeed1200 <std::runtime_error::~runtime_error()>)
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/libsupc++/eh_throw.cc:87
87      std::terminate ();
(gdb) 
#8  0xfef17daf in std::__throw_runtime_error (__s=0xfef2cc80 "locale::facet::_S_create_c_locale name not valid")
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/src/c++11/functexcept.cc:107
107      { _GLIBCXX_THROW_OR_ABORT(runtime_error(_(__s))); }
(gdb) 
#9  0xfeed9006 in std::locale::facet::_S_create_c_locale (__cloc=@0x8046e00: 0x0, __s=<optimized out>) at c++locale.cc:218
218    c++locale.cc: No such file or directory.
(gdb) 
#10 0xfeecf9e9 in std::locale::_Impl::_Impl (this=0x80618e0, __s=0x8047340 "en_US.UTF-8", __refs=1)
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/src/c++98/localename.cc:182
182        locale::facet::_S_create_c_locale(__cloc, __s);
(gdb) 
#11 0xfeed0c1e in std::locale::locale (this=0x8046eb8, __s=<optimized out>)
    at /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/libstdc++-v3/src/c++98/localename.cc:54
54              _M_impl = new _Impl(__env, 1);
(gdb) 
#12 0x0805129b in main () at main.cpp:8
8        std::locale loc = std::locale("");
(gdb)

Unfortunately, I have not found that file c++locale.cc, what does it do?
the system:
SunOS witch 5.11 illumos-69f14d1 i86pc i386 i86pc
gcc, as you see, is 4.9.4 (openindiana)
witch% g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/lto-wrapper
Target: i386-pc-solaris2.11
Configured with: /jenkins/jobs/oi-userland/workspace/components/developer/gcc49/gcc-4.9.4/configure CC=/usr/gcc/4.9/bin/gcc CXX=/usr/gcc/4.9/bin/g++ F77=/usr/gcc/4.9/bin/gfortran FC=/usr/gcc/4.9/bin/gfortran CFLAGS='-g -O2' CXXFLAGS=' ' FFLAGS=' ' FCFLAGS= LDFLAGS=-m32 PKG_CONFIG_PATH=/usr/lib/pkgconfig --prefix=/usr/gcc/4.9 --mandir=/usr/gcc/4.9/share/man --bindir=/usr/gcc/4.9/bin --libdir=/usr/gcc/4.9/lib --sbindir=/usr/gcc/4.9/sbin --sbindir=/usr/gcc/4.9/bin --libdir=/usr/gcc/4.9/lib --libexecdir=/usr/gcc/4.9/lib --host i386-pc-solaris2.11 --build i386-pc-solaris2.11 --target i386-pc-solaris2.11 --with-boot-ldflags=-R/usr/gcc/4.9/lib --enable-plugins --enable-objc-gc --enable-languages=c,c++,fortran,lto,objc --without-gnu-ld --with-ld=/usr/bin/ld --with-build-time-tools=/usr/gnu/i386-pc-solaris2.11/bin --disable-libitm --enable-install-libiberty --with-gnu-as --with-as=/usr/bin/gas LDFLAGS=-R/usr/gcc/4.9/lib
Thread model: posix
gcc version 4.9.4 (GCC) 

Sun CC:
witch% CC -V
CC: Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21

Thanks to Igor Kozhukhov, he hits this bug in DilOS.

Actions #1

Updated by Yuri Pankov over 6 years ago

Guessing from the description, this seems to be a problem in libstdc++, not something we can fix in illumos-gate.

Actions #2

Updated by Yuri Pankov over 6 years ago

  • Status changed from New to Feedback
Actions #3

Updated by Julian Wiesener over 6 years ago

That problem is way older than illumos and has been repoted multiple time since 2004. Afaik there had been a few that did started to work on that but noone ever finished.

The latest updates are at:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41495

If illumos now have the POSIX.1-2008 APIs now, there might be a realistic chance to get that fixed.

Actions #4

Updated by Julian Wiesener over 6 years ago

Illumos-site seems has been fixed: https://illumos.topicbox.com/groups/developer/discussions/Td23a09ce01f2967f

Still needs someone who picks up the gcc stl part

Actions

Also available in: Atom PDF