# porting/compiling TokuMX



## nichdiekuh (Sep 4, 2014)

Hello,

I'm pretty new to FreeBSD and I'm trying to port/build Tokumx (a MongoDB fork) on FreeBSD10. I've already fixed some issues during the build process and I'm stuck with the following error:


```
[ 47%] Building CXX object src/mongo/platform/CMakeFiles/platform.dir/backtrace.cpp.o
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp: In function 'int mongo::pal::{anonymous}::addrtosymstr(void*, char*, int)':
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:71:9: error: 'Dl_info_t' was not declared in this scope
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:71:19: error: expected ';' before 'symbolInfo'
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:72:30: error: 'symbolInfo' was not declared in this scope
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:75:13: error: 'symbolInfo' was not declared in this scope
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:87:25: error: 'symbolInfo' was not declared in this scope
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp: In function 'int mongo::pal::backtrace_emulation(void**, int)':
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:106:57: error: 'walkcontext' was not declared in this scope
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp: In function 'int mongo::pal::{anonymous}::addrtosymstr(void*, char*, int)':
/home/tokumx/mongo/src/mongo/platform/backtrace.cpp:92:5: warning: control reaches end of non-void function [-Wreturn-type]
gmake[2]: *** [src/mongo/platform/CMakeFiles/platform.dir/backtrace.cpp.o] Error 1
gmake[1]: *** [src/mongo/platform/CMakeFiles/platform.dir/all] Error 2
gmake: *** [all] Error 2
```

I'm not a C/C++ expert and I can't figure how to solve this issue. Perhaps someone here who has been working with MongoDB before might be able to assist?

Btw: I'm using GCC47, also tried GCC48 w/o without any luck.

My build instructions:

```
CC=gcc47 CPP=cpp47 CXX=g++47 cmake --disable-warnings-as-errors -D CMAKE_BUILD_TYPE=Release -D TOKU_DEBUG_PARANOID=OFF -D USE_VALGRIND=OFF -D USE_BDB=OFF -D BUILD_TESTING=OFF -D TOKUMX_DISTNAME=1.5.0 ..
gmake
```


----------



## SirDice (Sep 4, 2014)

As this is a fork of mongodb have a look at the existing databases/mongodb port.


----------



## nichdiekuh (Sep 4, 2014)

That's a good advice, I'm currently reading the diff files if there's anything that might be related to my issue. Unfortunately the patch files don't apply to the tokumx source, at least the ones I tried for SConstruct were too different.

Edit:
Ok, I have manually patched the SConstruct files but the error is still the same. The other patches don't seem to address this issue.


----------



## nichdiekuh (Sep 10, 2014)

After reading a lot of freebsd FreeBSD and cmake manual pages, I eventually compiled tokumx. Unfortunately the binary won't start because it can't detect the CPU frequency correctly:

Here's the output from: `truss mongod`

```
open("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq",O_RDONLY,0666) ERR#2 'No such file or directory'
open("/proc/cpuinfo",O_RDONLY,0666)              ERR#2 'No such file or directory'
pipe(0x7fffffffdbd0)                             = 0 (0x0)
vfork()                                          = 2342 (0x926)
fcntl(3,F_GETFL,)                                = 2 (0x2)
close(4)                                         = 0 (0x0)
fstat(3,{ mode=p--------- ,inode=1,size=0,blksize=4096 }) = 0 (0x0)
sysctl: unknown oid 'hw.cpufrequency': No such file or directory
read(3,0x804425000,4096)                         = 0 (0x0)
close(3)                                         = 0 (0x0)
wait4(2342,{ EXITED,val=1 },0x0,0x0)             = 2342 (0x926)
pipe(0x7fffffffdbd0)                             = 0 (0x0)
vfork()                                          = 2343 (0x927)
fcntl(3,F_GETFL,)                                = 2 (0x2)
close(4)                                         = 0 (0x0)
fstat(3,{ mode=p--------- ,inode=1,size=0,blksize=4096 }) = 0 (0x0)
read(3,"3100096164",4096)                        = 10 (0xa)
read(3,"\n",4096)                                = 1 (0x1)
close(3)                                         = 0 (0x0)
wait4(2343,{ EXITED,val=0 },0x0,0x0)             = 2343 (0x927)
__sysctl(0x7fffffffdc38,0x2,0x7fffffffdc34,0x7fffffffdc40,0x0,0x0) = 0 (0x0)
SIGNAL 11 (SIGSEGV)
```

I installed linprocfs and mounted it in /compat/linux/proc. I've also tried `brandelf -t Linux /usr/local/bin/mongod` but it still fails to read /proc/cpuinfo. Does anyone have an idea how to trick the mongod process into reading the correct location?


----------



## ljboiler (Sep 10, 2014)

On FreeBSD, it's dev.cpu.0.freq, not hw.cpufrequency.  That looks like a MacOSX thing.


----------



## nichdiekuh (Sep 11, 2014)

Thanks for your suggestion.  hw.cpufrequency indeed looks like OSX, but that's not the point. I don't want to change the source of TokuMX, I want the binary to read from /compat/linux/proc/cpuinfo which seems to be the obvious choice to me.
Furthermore `sysctl -a  | grep dev.cpu.0.freq` doesn't return anything on my machine. Even if I just `sysctl -a | grep freq` there's nothing related to the cpu frequency.


----------



## ljboiler (Sep 11, 2014)

> I want the binary to read from /compat/linux/proc/cpuinfo


Then you'll have to change the source code and rebuild the binary to make it do that.


----------



## SirDice (Sep 11, 2014)

nichdiekuh said:
			
		

> I don't want to change the source of TokuMX,


This is sometimes a necessary part of the porting process.


----------



## nichdiekuh (Sep 11, 2014)

Ok you guys are right - I changed the source and according to the stacktrace I got past the cpu-frequency issue. The binary still fails with a segfault and I'm running out of ideas and motivation to fix this. Here's a stacktrace on Pastebin: http://pastebin.com/rjtc4xVw


----------

