NetBSD Problem Report #55837
From www@netbsd.org Wed Dec 2 08:59:42 2020
Return-Path: <www@netbsd.org>
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 0A2EA1A9217
for <gnats-bugs@gnats.NetBSD.org>; Wed, 2 Dec 2020 08:59:42 +0000 (UTC)
Message-Id: <20201202085940.DAD301A923A@mollari.NetBSD.org>
Date: Wed, 2 Dec 2020 08:59:40 +0000 (UTC)
From: rokuyama.rk@gmail.com
Reply-To: rokuyama.rk@gmail.com
To: gnats-bugs@NetBSD.org
Subject: GCC 9.3 g++ generates wrong codes for hard-float arm
X-Send-Pr-Version: www-1.0
>Number: 55837
>Category: toolchain
>Synopsis: GCC 9.3 g++ generates wrong codes for hard-float arm
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: toolchain-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Dec 02 09:00:00 +0000 2020
>Closed-Date: Mon May 31 12:16:49 +0000 2021
>Last-Modified: Mon May 31 22:35:01 +0000 2021
>Originator: Rin Okuyama
>Release: 7.99.76
>Organization:
Department of Physics, Meiji University
>Environment:
NetBSD rpi0w 9.99.76 NetBSD 9.99.76 (RPI0EB) #12: Tue Dec 1 11:02:35 JST 2020 rin@latipes:/build/work/src/sys/arch/evbarm/compile/RPI0EB evbarm
>Description:
g++ from GCC 9.3 generates wrong codes for hard-float arm variants, i.e.,
earmv[5-7]hf{,eb}. The situation is much more serious on v[5-6]hf{eb},
but v7hf{,eb} is also affected. On the other hand, soft-float variants,
earmv[4-7] seem not affected as far as I can see.
For GDB on v[5-6]hf, trying to place breakpoint on non-existent symbol
causes abort:
on v7hf{,eb}:
|(gdb) b non_existent_symbol
|Function "non_existent_symbol" not defined.
|Make breakpoint pending on future shared library load? (y or [n])
on v[5-6]hf{,eb}:
|(gdb) b non_existent_symbol
|terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
|[1] Abort trap (core dumped) gdb ./hello
Or backtrace longer than one display screen cannot quit by ``q'':
on v7hf{,eb}:
|(gdb) bt
|...
|--Type <RET> for more, q to quit, c to continue without paging--q
|Quit
|(gdb)
on v[5-6]hf{,eb}:
|(gdb) bt
|...
|--Type <RET> for more, q to quit, c to continue without paging--q
|terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_QUIT'
|[1] Abort trap (core dumped) gdb atf-run atf-run.core
Note that even v7hf{,eb} is affected; we already works around similar
failure in exception handling on v7hf{,eb}. See doc/HACKS:
https://nxr.netbsd.org/xref/src/doc/HACKS#978
or toolchain/54820:
http://gnats.netbsd.org/54820
The failures do not occur on soft-float arm variants as far as I can see.
On hard-float arm variants, if whole GDB is compiled with -O0, they do not
occur. Alternatively, compiling GDB by GCC 8.4 remarkably mitigates the
problems, although GCC8 is not perfect; hack described above was initially
introduced for GCC8.
Even if the other parts of userland, shared-libs, rtld, etc., are compiled
by GCC8, the problems occur when GDB itself is compiled by GCC9.
For ATF on v[5-6]hf{,eb}, atf-run aborts like:
on v[5-6]hf{,eb}
| # atf-run | atf-report
| ...
| atf-c/detail/fs_test (3/68): 24 test cases
| eaccess: [0.021425s] Passed.
| exists: terminate called after throwing an instance of 'tools::parser::parse_error'
| what(): LONELY PARSE ERROR: 237: Unexpected token `<<EOF>>'; expected end of
|test case or test case's stdout/stderr line
|[1] Segmentation fault (core dumped) atf-run |
| Abort trap (core dumped) atf-report
| #
Many tests in /usr/tests/atf fail due to ``Failed: Test program received
signal 6 (core dumped)''.
These failures do not occur on soft-float variants. If all source codes of
ATF are compiled with -O0, these do not occur also.
>How-To-Repeat:
On earmv[5-6]hf{,eb} machines,
# gdb hello
...
(gdb) b non-existent-symbol
or
# cd /usr/tests/atf && atf-run | atf-report
The problems also occurs for COMPAT_NETBSD32 on aarch64{,eb}.
>Fix:
Exception handling is suspicious, but I haven't still figured out what
actually happens. Note that while other OS's use arm specific exception
handling, NetBSD uses normal DWARF exception handling based on libunwind.
>Release-Note:
>Audit-Trail:
From: Rin Okuyama <rokuyama.rk@gmail.com>
To: "gnats-bugs@NetBSD.org" <gnats-bugs@NetBSD.org>
Cc:
Subject: Re: toolchain/55837 (GCC 9.3 g++ generates wrong codes for hard-float
arm)
Date: Fri, 30 Apr 2021 21:29:36 +0900
I tried to compile sys/lib/libunwind with VFP instructions being disabled
forcibly with this patch:
http://www.netbsd.org/~rin/arm_unwind_20210430.patch
But the situation does not change unfortunately...
Note that patch for GCC is necessary because -mgeneral-regs-only does not
work for some C++ headers like:
----
/build/gcc9/dest/evbarm-earmv6hfeb/usr/include/g++/bits/std_abs.h: In function 'constexpr double std::abs(double)':
/build/gcc9/dest/evbarm-earmv6hfeb/usr/include/g++/bits/std_abs.h:71:17: error: argument of type 'double' not permitted with -mgeneral-regs-only
71 | abs(double __x)
----
We may need more -mgeneral-regs-only for libstdc++, c.f.:
---
% find /usr/src/external/gpl3/gcc/dist/libstdc++-v3 -name '*.cc' | \
xargs grep general-regs-only
/usr/src/external/gpl3/gcc/dist/libstdc++-v3/libsupc++/eh_personality.cc:__attribute__((target ("general-regs-only")))
/usr/src/external/gpl3/gcc/dist/libstdc++-v3/libsupc++/eh_personality.cc:__attribute__((target ("general-regs-only")))
---
Thanks,
rin
From: Rin Okuyama <rokuyama.rk@gmail.com>
To: "gnats-bugs@NetBSD.org" <gnats-bugs@NetBSD.org>
Cc:
Subject: Re: toolchain/55837 (GCC 9.3 g++ generates wrong codes for hard-float
arm)
Date: Mon, 31 May 2021 20:33:02 +0900
It turned out that this is not due to bugs in GCC, but in
libunwind for arm. I will commit fixes soon.
Thanks,
rin
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 11:41:22 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 11:41:22 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp unwind_registers.S
Log Message:
PR toolchain/55837
Misc style fixes for clarity:
- Rename lazyVFP1() and lazyVFP3() to lazyVFPv2() and lazyVFPv3(),
respectively. Note that VFPv1 was obsoleted and replaced by VFPv2.
- Introduce enum for flags.
- Add few comments.
No functional changes.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/lib/libunwind/Registers.hpp
cvs rdiff -u -r1.18 -r1.19 src/sys/lib/libunwind/unwind_registers.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 11:44:07 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 11:44:07 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp
Log Message:
PR toolchain/55837
copyFloatVectorRegister(): Assert register number is valid to make sure.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/lib/libunwind/Registers.hpp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 11:47:18 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 11:47:18 UTC 2021
Modified Files:
src/sys/lib/libunwind: unwind_registers.S
Log Message:
PR toolchain/55837
Fix for jumpto() armeb; use word-wise load for flags, instead of byte-wise one.
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/lib/libunwind/unwind_registers.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 11:50:43 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 11:50:43 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp
Log Message:
PR toolchain/55837
Fix DWARF/internal register numbers of s31 for arm.
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/lib/libunwind/Registers.hpp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 11:54:01 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 11:54:01 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp
Log Message:
PR toolchain/55837
Fix pointer arithmetic when copying s0-s31 registers for arm.
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/lib/libunwind/Registers.hpp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 11:57:28 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 11:57:28 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp
Log Message:
PR toolchain/55837
Fix logic error in copyFloatVectorRegister() for arm; copy s0-s31 or
d0-d31, not both.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/lib/libunwind/Registers.hpp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 12:12:24 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 12:12:24 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp
Log Message:
PR toolchain/55837
Bump LAST_REGISTER and LAST_RESTORE_REG to REGNO_ARM32_S31 for arm.
There are two numbering schemes for VFPv2 registers: s0-s31 and d0-d15.
The former is used by GCC, and the latter is by LLVM. Since libunwind was
derived from LLVM, it has never supported the former. This results in
crashes for GCC-compiled binaries in exception handler of C++, if it
encounters VFPv2 registers when unwinding frames.
This commit adds support for s0-s31 numbering to libunwind. I choose an
implementation in which VFPv2 registers are ``double-counted'' as s0-s31
AND d0-d15. This does not cause real problems, since the former is only
used by GCC, and the later is by LLVM. That is, different numbering
schemes cannot appear in a same frame. To make sure, assertions are added
in order to check this.
I've confirmed that no regression for ATF both for GCC- and LLVM-compiled
userlands.
To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/lib/libunwind/Registers.hpp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: rin@NetBSD.org
State-Changed-When: Mon, 31 May 2021 12:16:49 +0000
State-Changed-Why:
Fixes for libunwind were committed.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src/sys/lib/libunwind
Date: Mon, 31 May 2021 21:31:34 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 21:31:34 UTC 2021
Modified Files:
src/sys/lib/libunwind: Registers.hpp
Log Message:
PR toolchain/55837
Stop using enum for flags, as per request from joerg.
#define constants and #undef after use.
To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/lib/libunwind/Registers.hpp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55837 CVS commit: src
Date: Mon, 31 May 2021 22:33:19 +0000
Module Name: src
Committed By: rin
Date: Mon May 31 22:33:19 UTC 2021
Modified Files:
src/doc: HACKS
src/external/gpl3/gdb.old/lib/libgdb: Makefile
src/external/gpl3/gdb/lib/libgdb: Makefile
Log Message:
PR toolchain/55837
Get rid of -O0 hack for GDB for hard-float arm. This was necessary because
libunwind did not support s0-s31. Note that for *most* cases (not all!),
-O0 stops using VFP registers for general purposes.
Also note that this hack was incomplete. We had to compile every functions
with -O0, that can be unwinded. Otherwise, GDB crashed every time exceptions
were raised.
To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/doc/HACKS
cvs rdiff -u -r1.12 -r1.13 src/external/gpl3/gdb.old/lib/libgdb/Makefile
cvs rdiff -u -r1.30 -r1.31 src/external/gpl3/gdb/lib/libgdb/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.