NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/52756: sysctl(2) in C++ constructor does not work any more

>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:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 23 09:35:00 +0000 2017
>Originator:     Kamil Rytarowski
>Release:        NetBSD 8.99.7 amd64
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
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
/* 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;

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

	return 0;


Home | Main Index | Thread Index | Old Index