-rw-r--r-- 2937 saferewrite-20250228/README-elfulator raw
The line "c sparc elfulator: diet sparc-linux-gcc -Os" in ./compilers will be skipped by default. Here's how to make this line work. Beware that unrolling via elfulator increases costs; see README-resources. All of these instructions are unprivileged, in the same account that's running saferewrite. The instructions assume that you have already set up a saferewrite environment and installed angr, and that you are in the saferewrite directory. Set up environment variables to use below: VENV=saferewrite BUILDROOT=buildroot-2024.11 DIETLIBC=dietlibc-0.35 export LIBRARY_PATH=$HOME/unicorn/build export LD_LIBRARY_PATH=$HOME/unicorn/build export CPATH=$HOME/unicorn/include Download and run buildroot to compile sparc-linux-gcc: ( cd wget https://buildroot.org/downloads/$BUILDROOT.tar.xz tar -xf $BUILDROOT.tar.xz cd $BUILDROOT echo BR2_sparc=y > configs/sparc_defconfig make sparc_defconfig time make ) Link the cross-compiler into the saferewrite environment: ln -s $HOME/$BUILDROOT/output/host/bin/* $HOME/.virtualenvs/$VENV/bin/ Test cross-compiling and running a small program: ( echo '#include <stdio.h>' echo 'int main() { puts("works"); return 0; }' ) > ok.c sparc-linux-gcc -o ok ok.c -static ./ok This should print "works". If you instead see "sparc-linux-gcc: command not found", switch to the saferewrite environment--- export PATH=$HOME/.virtualenvs/$VENV/bin:$PATH ---and then run the test again. Download and compile dietlibc (plus a SPARC patch), first for amd64 and then for 32-bit SPARC: ( cd wget https://www.fefe.de/dietlibc/$DIETLIBC.tar.xz tar -xf $DIETLIBC.tar.xz cd $DIETLIBC sed -i 's/glob /globl /' sparc/memcmp.S time make -j8 time make -j8 ARCH=sparc CROSS=sparc-linux- CFLAGS='-Os -static' all ) Link the diet program into the saferewrite environment: ln -s $HOME/$DIETLIBC/bin-sparc/diet $HOME/.virtualenvs/$VENV/bin/ Test cross-compiling and running with dietlibc: diet sparc-linux-gcc -o ok ok.c ./ok This should again print "works". Download unicorn, switch to the version that these instructions were tested with, apply a patch, and compile: cp unicorn-patch $HOME ( cd git clone https://github.com/unicorn-engine/unicorn.git cd unicorn git checkout 8a2846369c4070c948d8b1d3b84069de4a686b1c patch -p1 < ../unicorn-patch mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release time make -j8 ) Link the unicorn library into the saferewrite directory (the *PATH variables aren't enough for saferewrite to use elfulator): ln -s $HOME/unicorn/build/libunicorn* . In the saferewrite directory, compile elfulator: gcc -Os -o elfulator elfulator.c setjmp.s -lunicorn Test running a dietlibc cross-compiled executable under elfulator: ./elfulator ok `wc -c < ok` This should once again print "works".