NetBSD Problem Report #52756

From www@NetBSD.org  Thu Nov 23 09:30:28 2017
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 3CF057A1B7
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 23 Nov 2017 09:30:28 +0000 (UTC)
Message-Id: <20171123093027.7DDC67A1F1@mollari.NetBSD.org>
Date: Thu, 23 Nov 2017 09:30:27 +0000 (UTC)
From: n54@gmx.com
Reply-To: n54@gmx.com
To: gnats-bugs@NetBSD.org
Subject: sysctl(2) in C++ constructor does not work any more
X-Send-Pr-Version: www-1.0

>Number:         52756
>Category:       lib
>Synopsis:       sysctl(2) in C++ constructor does not work any more
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 23 09:35:00 +0000 2017
>Closed-Date:    Thu Nov 23 16:33:30 +0000 2017
>Last-Modified:  Thu Nov 23 16:35:00 +0000 2017
>Originator:     Kamil Rytarowski
>Release:        NetBSD 8.99.7 amd64
>Organization:
TNF
>Environment:
NetBSD chieftec 8.99.7 NetBSD 8.99.7 (GENERIC) #8: Tue Nov 21 08:36:07 CET 2017  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
>Description:
sysctl(2) calls inside C++ lamda constructos no longer work.

It might be related to __cxa_atexit() changes.


This used to work in the past. Confirmed to work on:

NetBSD rugged 8.99.1 NetBSD 8.99.1 (GENERIC) #7: Mon Jul  3 15:56:30 CEST 2017  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
>How-To-Repeat:
/* g++ std=c++11 prog.c */


#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <machine/cpu.h>
#include <iostream>
#include <stdlib.h>
#include <err.h>

const int fpu_present = []() -> int {
  int mib[2];
  int error;
  size_t len;                                                                                                                                                                                 
  int val;

  len = sizeof(val);
  mib[0] = CTL_MACHDEP;
  mib[1] = CPU_FPU_PRESENT;

  error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
  if (error)
    errx(EXIT_FAILURE, "sysctl");

  return val;
}();

int
main(int argc, char **argv)
{
	std::cout << "fpu_present=" << fpu_present << std::endl;

	return 0;
}

>Fix:
N/A

>Release-Note:

>Audit-Trail:
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: lib/52756: sysctl(2) in C++ constructor does not work any more
Date: Thu, 23 Nov 2017 10:58:57 -0500

 On Nov 23,  9:35am, n54@gmx.com (n54@gmx.com) wrote:
 -- Subject: lib/52756: sysctl(2) in C++ constructor does not work any more


 CPU_FPU_PRESENT only exists in the header file, fixing the test prints
 No such file or directory as expected. If I change the test to use
 CPU_FPU_SAVE, it works: 

 /* g++ std=c++11 prog.c */

 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #include <machine/cpu.h>
 #include <iostream>
 #include <stdlib.h>
 #include <err.h>

 const int fpu_save = []() -> int {
   int mib[2];
   int error;
   size_t len;                                                                                                                                                                                 
   int val;

   len = sizeof(val);
   mib[0] = CTL_MACHDEP;
   mib[1] = CPU_FPU_SAVE;

   error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
   if (error == -1)
     err(EXIT_FAILURE, "sysctl");

   return val;
 }();

 int
 main(int argc, char **argv)
 {
         std::cout << "fpu_save=" << fpu_save << std::endl;

         return 0;
 }

From: Kamil Rytarowski <n54@gmx.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/52756: sysctl(2) in C++ constructor does not work any more
Date: Thu, 23 Nov 2017 17:15:48 +0100

 This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
 --jhP2EspnvroHmBUqKOGxpJbiOl7vDLd4B
 Content-Type: multipart/mixed; boundary="PrUuAgMVVoLd8e0suWrNrrImfJwoQlrlQ";
  protected-headers="v1"
 From: Kamil Rytarowski <n54@gmx.com>
 To: gnats-bugs@NetBSD.org
 Message-ID: <a18bf514-eb9a-5103-8b01-b3cccaed7451@gmx.com>
 Subject: Re: lib/52756: sysctl(2) in C++ constructor does not work any more
 References: <pr-lib-52756@gnats.netbsd.org>
  <20171123093027.7DDC67A1F1@mollari.NetBSD.org>
  <20171123160002.2864B7A1E5@mollari.NetBSD.org>
 In-Reply-To: <20171123160002.2864B7A1E5@mollari.NetBSD.org>

 --PrUuAgMVVoLd8e0suWrNrrImfJwoQlrlQ
 Content-Type: text/plain; charset=utf-8
 Content-Language: en-US
 Content-Transfer-Encoding: quoted-printable

 On 23.11.2017 17:00, Christos Zoulas wrote:
 > The following reply was made to PR lib/52756; it has been noted by GNAT=
 S.
 >=20
 > From: christos@zoulas.com (Christos Zoulas)
 > To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org,=20
 > 	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
 > Cc:=20
 > Subject: Re: lib/52756: sysctl(2) in C++ constructor does not work any =
 more
 > Date: Thu, 23 Nov 2017 10:58:57 -0500
 >=20
 >  On Nov 23,  9:35am, n54@gmx.com (n54@gmx.com) wrote:
 >  -- Subject: lib/52756: sysctl(2) in C++ constructor does not work any =
 more
 > =20
 > =20
 >  CPU_FPU_PRESENT only exists in the header file, fixing the test prints=

 >  No such file or directory as expected. If I change the test to use
 >  CPU_FPU_SAVE, it works:=20
 >=20
 commit 41bd1c16bd04af5cafa8c96defd0d342eeda4b82
 Author: maya <maya@NetBSD.org>
 Date:   Mon Oct 9 17:49:27 2017 +0000

     GC i386_fpu_present. no FPU x86 is not supported.

     Also delete newly unused send_sigill


 We should revert it at least the sysctl(2) entry.


 --PrUuAgMVVoLd8e0suWrNrrImfJwoQlrlQ--

 --jhP2EspnvroHmBUqKOGxpJbiOl7vDLd4B
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename="signature.asc"

 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2

 iQIcBAEBCAAGBQJaFvQ7AAoJEEuzCOmwLnZs5+0P/3I1gItIlfZPl7ZDXfDMWsRZ
 LOnh8LtXKbIOHWY4Gi7yVY5r0z873zlVbm6MyAzNYauCAw4bygnBSKBjd9TbnDhe
 yWtE3OimgOW1bwJHbBFgwqiKKl+JXTWnk7eNfNB46GMaNCU7woPeglBPttgLkRyH
 L63BbQvFq3qHIFzat/TIS+HQLHjklNpjnxuod1gcyVoXTs6bN+kJKhhjPBJJyCnC
 plFvg3LO8S3cfh6/b2+RkPWuFmQLNNtP4wlA2/bob26E+SY6qnWorbYWNCoHTomX
 Gnvt+SikZH+TEgrRUzkQfehLWrztZMRhrc32m8Kf5tKK7j14gFLNW6orLp9v4ryi
 6iky5pFqAltwobQ+E0u6KMJmkTkvjm4MjwfCGL0LZFXVkyI1FwwOOy61jhy9Xs0X
 aUxQJYFRr0hpdptar2No7qCQJAe1gXibR/aEgD7IzX/bi6rhQGiElsiV3jQXPD8M
 xrHCdO55M8s2qZ+VlE+kH8JoPpA1H15Wd7w3MvTQOlhj8eOQd943CWNFiqUzKGHw
 Gj5pX+/jaQDkUe7MKaMMQUHfFqZ5bKggjupXk93mxXHgq/cDNaG1aWVq17xuBcDk
 RIsvfxBx1EhPHlJviVVMEWywwmpiIDshTArbkrAE3Ved6kVWJLCKuV8A9Odwt1+k
 aphuX1Ngbwl71AVGYwQt
 =cHkn
 -----END PGP SIGNATURE-----

 --jhP2EspnvroHmBUqKOGxpJbiOl7vDLd4B--

State-Changed-From-To: open->closed
State-Changed-By: kamil@NetBSD.org
State-Changed-When: Thu, 23 Nov 2017 17:33:30 +0100
State-Changed-Why:
Real cause for this breakage has been addressed - removal of sysctl(2) entry.
It has been restored for compatibility purposes.


From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52756 CVS commit: src/sys/arch/x86
Date: Thu, 23 Nov 2017 16:30:50 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Thu Nov 23 16:30:50 UTC 2017

 Modified Files:
 	src/sys/arch/x86/include: cpu.h
 	src/sys/arch/x86/x86: x86_machdep.c

 Log Message:
 Restore removed sysctl(2) x86 entry: fpu_present

 Hardcode it to 1 for now on i386 and amd64.

 This unbreaks software that used it (e.g. LLDB).

 Removal noted by <christos>

 PR lib/52756 by myself


 To generate a diff of this commit:
 cvs rdiff -u -r1.80 -r1.81 src/sys/arch/x86/include/cpu.h
 cvs rdiff -u -r1.101 -r1.102 src/sys/arch/x86/x86/x86_machdep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.