[Bug 221423] gcc std::locale(LocaleName) crashes instead of throwing an exception

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Wed Aug 16 03:42:56 UTC 2017


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221423

--- Comment #9 from Mark Millard <markmi at dsl-only.net> ---
Here are lang/gcc7 and system clang compile/link results as viewed
by ldd (all under head -r322287 in a Virtual Box virtual machine):
things look good until I try my threading example. Then one
combination fails (the -rpath one!).

# g++7 -std=c++14 -Wpedantic -Wall -Wl,-rpath=/usr/local/lib/gcc7 -O2
locale_failure_test.cc

# ldd a.out
a.out:
        libstdc++.so.6 => /usr/local/lib/gcc7/libstdc++.so.6 (0x800824000)
        libm.so.5 => /lib/libm.so.5 (0x800bb8000)
        libgcc_s.so.1 => /usr/local/lib/gcc7/libgcc_s.so.1 (0x800de5000)
        libc.so.7 => /lib/libc.so.7 (0x800ffc000)

# ./a.out

Note: The above did not crash but had no output.

# g++7 -std=c++14 -Wpedantic -Wall -O2 locale_failure_test.cc

# ldd a.out
a.out:
        libstdc++.so.6 => /usr/local/lib/gcc7/libstdc++.so.6 (0x800824000)
        libm.so.5 => /lib/libm.so.5 (0x800bb8000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800de5000)
        libc.so.7 => /lib/libc.so.7 (0x800ffb000)

# ./a.out

Note: The above did not crash but had no output.

# clang++ -std=c++14 -Wpedantic -Wall -O2 locale_failure_test.cc

# ldd a.out
a.out:
        libc++.so.1 => /usr/lib/libc++.so.1 (0x800824000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x800af0000)
        libm.so.5 => /lib/libm.so.5 (0x800d0e000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800f3b000)
        libc.so.7 => /lib/libc.so.7 (0x801151000)

# ./a.out

Note: The above did not crash but had no output.


Replacing the locale line with:

                std::locale l = std::locale("NOSUCH::en_US.UTF-8");

# g++7 -std=c++14 -Wpedantic -Wall -Wl,-rpath=/usr/local/lib/gcc7 -O2
locale_failure_test.cc

# ./a.out
locale::facet::_S_create_c_locale name not valid

# g++7 -std=c++14 -Wpedantic -Wall -O2 locale_failure_test.cc

# ./a.out
locale::facet::_S_create_c_locale name not valid

# ./a.out
collate_byname<char>::collate_byname failed to construct for
NOSUCH::en_US.UTF-8

So no exception was thrown in any of the examples and the
code did not fail.


Trying instead:

# more exception_test.cc
#include <exception>

int main(void)
{
    try { throw std::exception(); }
    catch (std::exception& e) {}
    return 0;
}

# g++7 -std=c++14 -Wpedantic -Wall -Wl,-rpath=/usr/local/lib/gcc7 -O2
exception_test.cc

# ./a.out

# g++7 -std=c++14 -Wpedantic -Wall -O2 exception_test.cc

# ./a.out

# clang++ -std=c++14 -Wpedantic -Wall -O2 exception_test.cc

# ./a.out


So none of them fail.

But trying my standard-C++ program that uses C++ threads:

# g++7 -std=c++14 -Wpedantic -Wall -pthread -Wl,-rpath=/usr/local/lib/gcc7 -O2
cpp_clocks_investigation.cpp

# ldd a.out
a.out:
        libstdc++.so.6 => /usr/local/lib/gcc7/libstdc++.so.6 (0x800844000)
        libm.so.5 => /lib/libm.so.5 (0x800bd8000)
        libgcc_s.so.1 => /usr/local/lib/gcc7/libgcc_s.so.1 (0x800e05000)
        libthr.so.3 => /lib/libthr.so.3 (0x80101c000)
        libc.so.7 => /lib/libc.so.7 (0x801244000)

# ./a.out
. . . (omitted) . . .
Segmentation fault (core dumped)

# g++7 -std=c++14 -Wpedantic -Wall -pthread -O2 cpp_clocks_investigation.cpp#
ldd a.out
a.out:
        libstdc++.so.6 => /usr/local/lib/gcc7/libstdc++.so.6 (0x800844000)
        libm.so.5 => /lib/libm.so.5 (0x800bd8000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800e05000)
        libthr.so.3 => /lib/libthr.so.3 (0x80101b000)
        libc.so.7 => /lib/libc.so.7 (0x801243000)

# ./a.out
. . . (omitted) . . .
End of clock tests.

So it worked for /lib/libgcc_s.so.1 but not for
/usr/local/lib/gcc7/libgcc_s.so.1
and I must have been wrong about /lib/libcxxrt.so.1 being what mattered.

This threading example is a context where -Wl,-rpath=/usr/local/lib/gcc7
prevents correct operation because of cross library dependencies on
implementation details of the build-time context vs. the mismatched
runtime context for libthr.so.3 vs. libgcc_s.so.1 .


# clang++ -std=c++14 -Wpedantic -Wall -pthread -O2 cpp_clocks_investigation.cpp

# ldd a.out
a.out:
        libc++.so.1 => /usr/lib/libc++.so.1 (0x800844000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x800b10000)
        libm.so.5 => /lib/libm.so.5 (0x800d2e000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800f5b000)
        libthr.so.3 => /lib/libthr.so.3 (0x801171000)
        libc.so.7 => /lib/libc.so.7 (0x801399000)

# ./a.out
. . . (omitted) . . .
End of clock tests.

So this also worked. Again /lib/libthr.so.3 and /lib/libgcc_s.so.1
go together just fine.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-toolchain mailing list