NetBSD Problem Report #52942

From martin@duskware.de  Tue Jan 23 10:41:46 2018
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 956727A178
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 23 Jan 2018 10:41:46 +0000 (UTC)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: libunwind failure in atf c++ internal test
X-Send-Pr-Version: 3.95

>Number:         52942
>Category:       lib
>Synopsis:       libunwind failure in atf c++ internal test
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    joerg
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 23 10:45:00 +0000 2018
>Last-Modified:  Tue Jan 23 11:16:17 +0000 2018
>Originator:     Martin Husemann
>Release:        NetBSD 8.99.12
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD space-truckin.duskware.de 8.99.12 NetBSD 8.99.12 (SUNXI) #18: Mon Jan 22 12:01:55 CET 2018 martin@night-owl.duskware.de:/usr/src/sys/arch/evbarm/compile/SUNXI evbarm
Architecture: earmv7hfeb
Machine: evbarm
>Description:

On big endian arm the atf internal test case
/usr/tests/atf/atf-c++/detailtext_test::to_type fails.

This part of the test is equivalent to something like:

--8<--
#include <iostream>
#include <sstream>
#include <string>

template <class T>
T test(std::string &str)
{
	T value;
	std::istringstream ss(str);

	ss >> value;

	std::cout << "value: " << value << "\n";
	if (ss.eof())
		std::cout << "eof()\n";
	if (ss.fail())
		std::cout << "fail()\n";
	if (ss.bad())
		std::cout << "bad()\n";
	if (!ss.eof() || (ss.eof() && (ss.fail() || ss.bad())))
		throw std::runtime_error("Cannot convert string to requested type");

	return value;
}

int main(void)
{
	int v;
	std::string str("   ");

	try {
		v = test<int>(str);
		return 10+v;
	} catch (const std::runtime_error &) {
		return 1;
	} catch (const std::exception& atfu_e) {
		return 2;
	} catch (...) {
		return 3;
	}
	return 4;
}
-->8--

It takes a string of a few blanks, tries to convert it to int with the atf
internal to_type<T> macro and checks that std::runtime_error exception
is raised.

This all works fine, but when throwing the exception libunwind fails to 
identify the proper handler and instead we end up aborting the program.

A step in between is:

(gdb) p *this
$11 = {fInfo = {data_base = 0, start_ip = 0, end_ip = 0, lsda = 0, 
    handler = 0, extra_args = 0, unwind_info = 0}, fRegisters = {reg = {
      2147358504, 2, 3336, 2035255504, 2031280304, 2147358832, 2147358504, 
      1126902528, 2031280280, 2147358864, 2147359688, 2147359604, 2147359608, 
      2147358496, 2033402552, 2033402552, 1611530768}, flags = 0, fpreg = {
      4096, 3737629, 4096, 141991618805760, 3737629, 4294967296, 0, 
      18446744073709551615, 1516702867, 2059950152923217920, 1516167243, 
      166604820, 0, 272617096740, 8737718594714180144, 9222838037128289060, 
      9222837624811427840, 8735362066417344140, 0, 9222838066931178400, 
      240552312831, 9222838034980929599, 8097581722283038920, 47455248, 
      8746342322110809088, 9222835889533701120, 8746359914296857600, 
      1885396800, 8098065455859687188, 8097717407004491776, 0, 
      8746364312343356160}}, fAddressSpace = @0x7942ea6c, 
  fUnwindInfoMissing = false, fIsSignalFrame = false}
#0  _Unwind::UnwindCursor<_Unwind::LocalAddressSpace, _Unwind::Registers_arm32>::setInfoBasedOnIPRegister (this=this@entry=0x7ffe1870, 
    isReturnAddress=isReturnAddress@entry=false)
    at /usr/src/sys/lib/libunwind/UnwindCursor.hpp:118
#1  0x7933434c in unwind_phase1 (exc=0x7912e098, cursor=...)
    at /usr/src/sys/lib/libunwind/libunwind.cxx:31
#2  _Unwind_RaiseException (exc=exc@entry=0x7912e098)
    at /usr/src/sys/lib/libunwind/libunwind.cxx:201
#3  0x794f89a8 in __cxxabiv1::__cxa_throw (obj=0x7912e0b0, tinfo=0x432b2b00, 
    dest=<optimized out>)
    at /usr/src/external/gpl3/gcc.old/dist/libstdc++-v3/libsupc++/eh_throw.cc:82
#4  0x02d574c0 in atf::text::to_type<int> (str=...)
    at /usr/src/external/bsd/atf/dist/atf-c++/detail/text.hpp:154
#5  0x02d50390 in (anonymous namespace)::atfu_tc_to_type::body (
    this=<optimized out>)
    at /usr/src/external/bsd/atf/dist/atf-c++/detail/text_test.cpp:361
#6  0x795e43a8 in atf::tests::tc_impl::wrap_body (tc=<optimized out>)
    at /usr/src/external/bsd/atf/dist/atf-c++/tests.cpp:157
#7  0x795a8488 in atf_tc_run (tc=0x791121f4, resfile=<optimized out>)
    at /usr/src/external/bsd/atf/dist/atf-c/tc.c:1024
#8  0x795d884c in atf::tests::tc::run (this=this@entry=0x791220e8, resfile=...)
    at /usr/src/external/bsd/atf/dist/atf-c++/tests.cpp:280

The tinfo value passed in #3 is correct on entry to __cxxabiv1::__cxa_throw,
however we end up like this:

#3  0x794f8a50 in __cxxabiv1::__terminate (handler=<optimized out>)
    at /usr/src/external/gpl3/gcc.old/dist/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x794f8aec in std::terminate ()
    at /usr/src/external/gpl3/gcc.old/dist/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5  0x794f89b4 in __cxxabiv1::__cxa_throw (obj=0x7912e0b0, tinfo=0x432b2b00, 
    dest=<optimized out>)
    at /usr/src/external/gpl3/gcc.old/dist/libstdc++-v3/libsupc++/eh_throw.cc:87
#6  0x02d574c0 in atf::text::to_type<int> (str=...)
    at /usr/src/external/bsd/atf/dist/atf-c++/detail/text.hpp:154


The simple test program above does not exhibit this issue, and all works
fine on little endian arm.


>How-To-Repeat:

cd /usr/tests/atf/atf-c++/detail
./text_test to_type

>Fix:
n/a

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: lib-bug-people->joerg
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Tue, 23 Jan 2018 11:16:17 +0000
Responsible-Changed-Why:
Over to maintainer


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.