NetBSD Problem Report #53810
From www@NetBSD.org Tue Dec 25 12:17:20 2018
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 22FE27A180
for <gnats-bugs@gnats.NetBSD.org>; Tue, 25 Dec 2018 12:17:20 +0000 (UTC)
Message-Id: <20181225121718.B70AE7A1E3@mollari.NetBSD.org>
Date: Tue, 25 Dec 2018 12:17:18 +0000 (UTC)
From: rokuyama@rk.phys.keio.ac.jp
Reply-To: rokuyama@rk.phys.keio.ac.jp
To: gnats-bugs@NetBSD.org
Subject: C++ exception does not work on m68k when libstdc++ is dynamicaly linked
X-Send-Pr-Version: www-1.0
>Number: 53810
>Category: toolchain
>Synopsis: C++ exception does not work on m68k when libstdc++ is dynamicaly linked
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: toolchain-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Dec 25 12:20:00 +0000 2018
>Closed-Date: Thu Feb 21 10:50:25 +0000 2019
>Last-Modified: Thu Feb 21 10:50:25 +0000 2019
>Originator: Rin Okuyama
>Release: 8.99.29
>Organization:
Department of Physics, Meiji University
>Environment:
NetBSD a1200 8.99.29 NetBSD 8.99.29 (A1200) #0: Tue Dec 25 18:50:38 JST 2018 rin@latipes:/var/build/src/sys/arch/amiga/compile/A1200 amiga
>Description:
Throwing C++ exceptions fails on m68k:
---
% cat exception.cpp
#include <stdio.h>
class Usage{};
int main(int argc, char *argv[]) {
try {
if (argc != 2)
throw Usage();
printf("%s\n", argv[1]);
return 0;
}
catch (const Usage&) {
printf("usage: %s str\n", argv[0]);
return 1;
}
}
% g++ exception.cpp
% ./a.out
terminate called after throwing an instance of 'Usage'
zsh: abort (core dumped) ./a.out
---
This code works fine if libstdc++ is statically linked:
---
% g++ -static exception.cpp
% ./a.out
usage: ./a.out str
---
This does not mean that it does not work with dynamically-linked
binaries; It also works when only libstdc++ is statically linked:
---
% ld -dynamic-linker /usr/libexec/ld.elf_so /usr/lib/crt0.o /usr/lib/crti.o /usr/lib/crtbegin.o exception.o /usr/lib/libstdc++.a -lm -lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
% ldd a.out
a.out:
-lm.0 => /usr/lib/libm.so.0
-lc.12 => /usr/lib/libc.so.12
% ./a.out
usage: ./a.out str
---
It should be a root cause for the following PRs:
toolchain/53684: atf-run fails on m68k
toolchain/53685: gdb fails on m68k
Actually, both gdb and atf-run work normally when they are statically
linked.
Note that this problem does not occur with GCC 5.5 from gcc.old in
NetBSD-current as of 20180801.
>How-To-Repeat:
Described above.
>Fix:
Not known yet.
>Release-Note:
>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@NetBSD.org
Cc: toolchain-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: re: toolchain/53810: C++ exception does not work on m68k when libstdc++ is dynamicaly linked
Date: Sat, 29 Dec 2018 08:15:21 +1100
Rin Okuyama writes:
> On archs other than m68k, libstdc++.so and C++ binaries depend on
> libgcc_s.so. On m68k, this is not the case: -shared-libgcc is
> observed in "g++ -v", but only -lgcc (not -lgcc_s) is passed to ld:
[ ..]
> Can I commit the patch?
go for it. thanks for a good diagnosis!
.mrg.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/53810 CVS commit: src/external/gpl3
Date: Fri, 28 Dec 2018 21:30:20 +0000
Module Name: src
Committed By: rin
Date: Fri Dec 28 21:30:20 UTC 2018
Modified Files:
src/external/gpl3/gcc.old/dist/gcc/config/m68k: netbsd-elf.h
src/external/gpl3/gcc/dist/gcc/config/m68k: netbsd-elf.h
Log Message:
PR toolchain/53810
PR toolchain/53684
PR toolchain/53685
No one defines TARGET_DEFAULT_CPU anymore. Use ENABLE_SHARED_LIBGCC
instead to determine whether GCC is configured for m68k or m68000.
This fixes C++ binaries on m68k, that require libgcc_s.
OK mrg
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/external/gpl3/gcc.old/dist/gcc/config/m68k/netbsd-elf.h
cvs rdiff -u -r1.12 -r1.13 \
src/external/gpl3/gcc/dist/gcc/config/m68k/netbsd-elf.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Rin Okuyama <rokuyama@rk.phys.keio.ac.jp>
To: matthew green <mrg@eterna.com.au>, gnats-bugs@NetBSD.org
Cc: toolchain-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: toolchain/53810: C++ exception does not work on m68k when
libstdc++ is dynamicaly linked
Date: Sat, 29 Dec 2018 06:38:29 +0900
On 2018/12/29 6:15, matthew green wrote:
> Rin Okuyama writes:
>> On archs other than m68k, libstdc++.so and C++ binaries depend on
>> libgcc_s.so. On m68k, this is not the case: -shared-libgcc is
>> observed in "g++ -v", but only -lgcc (not -lgcc_s) is passed to ld:
> [ ..]
>> Can I commit the patch?
>
> go for it. thanks for a good diagnosis!
Committed. Thank you for your quick response!
rin
PS
My previous message did not appear on GNATS for some reason.
I added the link for the record:
http://mail-index.netbsd.org/netbsd-bugs/2018/12/28/msg060157.html
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: toolchain/53810: C++ exception does not work on m68k when
libstdc++ is dynamicaly linked
Date: Wed, 9 Jan 2019 19:15:59 +0000
(not sent to gnats)
------
From: Rin Okuyama <rokuyama@rk.phys.keio.ac.jp>
To: toolchain-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: toolchain/53810: C++ exception does not work on m68k when
libstdc++ is dynamicaly linked
Date: Sat, 29 Dec 2018 06:09:03 +0900
On archs other than m68k, libstdc++.so and C++ binaries depend on
libgcc_s.so. On m68k, this is not the case: -shared-libgcc is
observed in "g++ -v", but only -lgcc (not -lgcc_s) is passed to ld:
% uname -p
m68k
% g++ -v hello.c
...
ld ... /tmp/cc8plluA.o -lstdc++ -lm -lgcc -lc -lgcc /usr/lib/crtend.o ...
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mcpu=68020'
% ldd a.out
a.out:
-lstdc++.8 => /usr/lib/libstdc++.so.8
-lm.0 => /usr/lib/libm.so.0
-lc.12 => /usr/lib/libc.so.12
What the difference between m68k and others? I found an answer in
external/gpl3/gcc/dist/gcc/config/m68k/netbsd-elf.h:
81 /* NetBSD/sun2 does not support shlibs, avoid using libgcc_pic. */
82 #if TARGET_DEFAULT_CPU == 0
83 #undef REAL_LIBGCC_SPEC
84 #define REAL_LIBGCC_SPEC "-lgcc"
85 #endif
This hack for m68000 does not work anymore since no one in source
tree defines TARGET_DEFAULT_CPU. Therefore, even for m68k machines,
-lgcc is used when -lgcc_s is more appropriate.
I've modified the hack as follows:
81 /* NetBSD/sun2 does not support shlibs, avoid using libgcc_pic. */
82 #ifndef ENABLE_SHARED_LIBGCC
83 #undef REAL_LIBGCC_SPEC
84 #define REAL_LIBGCC_SPEC "-lgcc"
85 #endif
Then, C++ applications on m68k get working again. Also, sun2 seems
no more broken than before (-current kernel does not boot on TME
regardless of my patch. Userland built with the patch works to
some extent on 8.0 kernel).
Can I commit the patch?
Thanks,
rin
Index: external/gpl3/gcc.old/dist/gcc/config/m68k/netbsd-elf.h
===================================================================
RCS file: /home/netbsd/src/external/gpl3/gcc.old/dist/gcc/config/m68k/netbsd-elf.h,v
retrieving revision 1.6
diff -p -u -r1.6 netbsd-elf.h
--- external/gpl3/gcc.old/dist/gcc/config/m68k/netbsd-elf.h 2 Aug 2018 00:02:57 -0000 1.6
+++ external/gpl3/gcc.old/dist/gcc/config/m68k/netbsd-elf.h 28 Dec 2018 11:29:00 -0000
@@ -79,7 +79,7 @@ along with GCC; see the file COPYING3.
#define LINK_SPEC NETBSD_LINK_SPEC_ELF
/* NetBSD/sun2 does not support shlibs, avoid using libgcc_pic. */
-#if TARGET_DEFAULT_CPU == 0
+#ifndef ENABLE_SHARED_LIBGCC
#undef REAL_LIBGCC_SPEC
#define REAL_LIBGCC_SPEC "-lgcc"
#endif
Index: external/gpl3/gcc/dist/gcc/config/m68k/netbsd-elf.h
===================================================================
RCS file: /home/netbsd/src/external/gpl3/gcc/dist/gcc/config/m68k/netbsd-elf.h,v
retrieving revision 1.12
diff -p -u -r1.12 netbsd-elf.h
--- external/gpl3/gcc/dist/gcc/config/m68k/netbsd-elf.h 2 Feb 2018 03:41:05 -0000 1.12
+++ external/gpl3/gcc/dist/gcc/config/m68k/netbsd-elf.h 28 Dec 2018 11:29:40 -0000
@@ -79,7 +79,7 @@ along with GCC; see the file COPYING3.
#define LINK_SPEC NETBSD_LINK_SPEC_ELF
/* NetBSD/sun2 does not support shlibs, avoid using libgcc_pic. */
-#if TARGET_DEFAULT_CPU == 0
+#ifndef ENABLE_SHARED_LIBGCC
#undef REAL_LIBGCC_SPEC
#define REAL_LIBGCC_SPEC "-lgcc"
#endif
State-Changed-From-To: open->closed
State-Changed-By: rin@NetBSD.org
State-Changed-When: Thu, 21 Feb 2019 10:50:25 +0000
State-Changed-Why:
fixed while ago
>Unformatted:
(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.