The first bug was already reported three years ago:
http://marc.info/?l=openbsd-bugs&m=135732012310459
std::ifstream has a bug when linked with libpthread:
$ cat t1.cpp
#include <iostream>
#include <fstream>
int
main(void)
{
std::ifstream fin("/");
std::cout << (!fin ? "BUG" : "OK") << std::endl;
}
$ c++ t1.cpp -o t1
$ ./t1
OK
$ c++ t1.cpp -o t1 -lpthread
$ ./t1
BUG
And another one I stumbled upon yesterday:
$ cat t2.cpp
#include <iostream>
#include <fstream>
int
main(void)
{
std::ifstream fin("/tmp/nonexistent.txt");
if (!fin.is_open())
std::cout << "is_open failed!" << std::endl;
if(fin) {
std::cout << "OK!" << std::endl;
} else {
std::cout << "KO :(" << std::endl;
}
}
$ c++ t2.cpp -o t2
$ ./t2
is_open failed!
OK!
Both work fine with g++-4.9.3p3:
$ eg++ t1.cpp -o t1 -lpthread
$ ./t1
OK
$ eg++ t2.cpp -o t2
$ ./t2
is_open failed!
KO :(
The libpthread one breaks building CMake on arm:
---8<---
[100%] Built target pseudo_emulator
make -f Tests/RunCMake/CMakeFiles/pseudo_iwyu.dir/build.make
Tests/RunCMake/CMakeFiles/pseudo_iwyu.dir/depend
cd /usr/ports/pobj/cmake-3.4.1/build-arm &&
/usr/ports/pobj/cmake-3.4.1/build-arm/Bootstrap.cmk/cmake -E cmake_depends
"Unix Makefiles" /usr/ports/pobj/cmake-3.4.1/cmake-3.4.1
/usr/ports/pobj/cmake-3.4.1/cmake-3.4.1/Tests/RunCMake
/usr/ports/pobj/cmake-3.4.1/build-arm
/usr/ports/pobj/cmake-3.4.1/build-arm/Tests/RunCMake
/usr/ports/pobj/cmake-3.4.1/build-arm/Tests/RunCMake/CMakeFiles/pseudo_iwyu.dir/DependInfo.cmake
--color=
make -f Tests/RunCMake/CMakeFiles/pseudo_iwyu.dir/build.make
Tests/RunCMake/CMakeFiles/pseudo_iwyu.dir/build
[100%] Built target pseudo_iwyu
/usr/ports/pobj/cmake-3.4.1/build-arm/Bootstrap.cmk/cmake -E
cmake_progress_start /usr/ports/pobj/cmake-3.4.1/build-arm/CMakeFiles 0
make -f CMakeFiles/Makefile2 preinstall
Install the project...
bin/cmake -P cmake_install.cmake
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/ports/pobj/cmake-3.4.1/build-arm/share/cmake
---8<---
Because the code is as follows:
// Install tree has "<prefix>/bin/cmake" and "<prefix><CMAKE_DATA_DIR>".
std::string dir = cmSystemTools::GetFilenamePath(exe_dir);
cmSystemToolsCMakeRoot = dir + CMAKE_DATA_DIR;
if(!cmSystemTools::FileExists(
(cmSystemToolsCMakeRoot+"/Modules/CMake.cmake").c_str()))
{
// Build tree has "<build>/bin[/<config>]/cmake" and
// "<build>/CMakeFiles/CMakeSourceDir.txt".
std::string src_dir_txt = dir + "/CMakeFiles/CMakeSourceDir.txt";
cmsys::ifstream fin(src_dir_txt.c_str());
std::string src_dir;
if(fin && cmSystemTools::GetLineFromStream(fin, src_dir) &&
cmSystemTools::FileIsDirectory(src_dir))
{
cmSystemToolsCMakeRoot = src_dir;
}
else
{
dir = cmSystemTools::GetFilenamePath(dir);
src_dir_txt = dir + "/CMakeFiles/CMakeSourceDir.txt";
cmsys::ifstream fin2(src_dir_txt.c_str());
if(fin2 && cmSystemTools::GetLineFromStream(fin2, src_dir) &&
cmSystemTools::FileIsDirectory(src_dir))
{
cmSystemToolsCMakeRoot = src_dir;
}
}
}
...And cmake is linked with -lpthread.
dmesg:
OpenBSD 5.9-beta (GENERIC) #163: Wed Jan 6 23:40:16 AEDT 2016
[email protected]:/usr/src/sys/arch/armv7/compile/GENERIC
real mem = 536870912 (512MB)
avail mem = 518381568 (494MB)
warning: no entropy supplied by boot loader
mainbus0 at root
cpu0 at mainbus0: ARM Cortex A8 R3 rev 2 (ARMv7 core)
cpu0: DC enabled IC enabled WB disabled EABT branch prediction enabled
cpu0: 32KB(64b/l,4way) I-cache, 32KB(64b/l,4way) wr-back D-cache
omap0 at mainbus0: TI AM335x BeagleBone
prcm0 at omap0 rev 0.2
sitaracm0 at omap0: control module, rev 1.0
intc0 at omap0 rev 5.0
edma0 at omap0 rev 0.0
dmtimer0 at omap0 rev 3.1
dmtimer1 at omap0 rev 3.1
omdog0 at omap0 rev 0.1
omgpio0 at omap0: rev 0.1
gpio0 at omgpio0: 32 pins
omgpio1 at omap0: rev 0.1
gpio1 at omgpio1: 32 pins
omgpio2 at omap0: rev 0.1
gpio2 at omgpio2: 32 pins
omgpio3 at omap0: rev 0.1
gpio3 at omgpio3: 32 pins
omap0: device tiiic unit 0 not configured
omap0: device tiiic unit 1 not configured
omap0: device tiiic unit 2 not configured
ommmc0 at omap0
sdmmc0 at ommmc0
ommmc1 at omap0
sdmmc1 at ommmc1
com0 at omap0: ti16750, 64 byte fifo
com0: console
cpsw0 at omap0: version 1.12 (0), address 78:a5:04:ca:1e:52
ukphy0 at cpsw0 phy 0: Generic IEEE 802.3u media interface, rev. 1: OUI
0x0001f0, model 0x000f
scsibus0 at sdmmc1: 2 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0: <SD/MMC, Drive #01, > SCSI2 0/direct fixed
sd0: 3688MB, 512 bytes/sector, 7553024 sectors
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
boot device: sd0
root on sd0a (39e9e648761e0797.a) swap on sd0b dump on sd0b