DOSBox: dynamic recompilation not working on x86_64
DOSBox by default uses dynamic recompilation (core=dynamic), which supposedly improves performance. First of all PaX is overstepping, when DOSBox is used with this feature resulting in crash:
Setting excute permission on the code cache has failed
It can be fixed by using:
paxctl -c -m /usr/bin/dosbox
Even then, it isn’t working properly, it crashes very early with:
Exit to error: DRC64:Unhandled memory reference
Setting “core=normal” helps in this case, still this can downgrade performance significantly.
It turns out that dynamic recompilation works just fine, when compiled with Clang (combined with tuning PaX). Some adjustments are needed, since there are linking issues with Clang:
clang++ -g -O2 -o dosbox dosbox.o cpu/libcpu.a debug/libdebug.a dos/libdos.a fpu/libfpu.a hardware/libhardware.a gui/libgui.a ints/libints.a misc/libmisc.a shell/libshell.a hardware/serialport/libserial.a libs/gui_tk/libgui_tk.a -L/usr/lib -lSDL -lpthread -lpng -lz -lX11
cpu/libcpu.a(core_dynrec.o): In function `gen_reg_memaddr(unsigned char, void*)':
/home/melville/src/dosbox-code-0-3869-dosbox-trunk/src/cpu/./core_dynrec/risc_x64.h:88:(.text+0x272d): relocation truncated to fit: R_X86_64_32S against symbol `Segs' defined in .bss section in cpu/libcpu.a(cpu.o)
/home/melville/src/dosbox-code-0-3869-dosbox-trunk/src/cpu/./core_dynrec/risc_x64.h:88:(.text+0x139a4): relocation truncated to fit: R_X86_64_32S against symbol `cpu_regs' defined in .bss section in cpu/libcpu.a(cpu.o)
I passed additional flags to Clang in order to fix this:
CXX="clang++" CXXFLAGS="-mcmodel=medium" ./configure
To my knowledge this issue is observed on x86_64, yet I didn’t test DOSBox on i386. It applies to version 0.74 of DOSBox and sources obtained from SVN. I searched for similar issues on other distribution, but they doesn’t seem relevant. It is curious case, where switching to Clang helps. Something goes wrong, when DOSBox is compiled with GCC 4.8.2 on Alpine Edge.
(from redmine: issue id 3189, created on 2014-07-18)