Memo for Cross Compile

4 minute read

vmstat

sudo apt install gettext autopoint
git clone https://gitlab.com/procps-ng/procps
cd procps
# git checkout 813cefe9 -b build
./autogen.sh
sed -i 's/AC_FUNC_MALLOC//g' configure.ac
sed -i 's/AC_FUNC_REALLOC//g' configure.ac
./configure --host=mipsel-linux --without-ncurses
make

ls .libs
free  pgrep  pidof  pkill  pmap  tload  uptime  vmstat  w

file .libs/vmstat
.libs/vmstat: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

trace-cmd

git clone https://github.com/rostedt/trace-cmd
cd trace-cmd
git checkout 9836b78 -b build
CC=mipsel-linux-gcc make
file tracecmd/trace-cmd
tracecmd/trace-cmd: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

systemtap

wget -c https://sourceware.org/systemtap/ftp/releases/systemtap-4.7.tar.gz
tar xvf systemtap-4.7.tar.gz
cd systemtap-4.7
./configure --host=mipsel-linux --without-avahi --disable-monitor
make
file stap
stap: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped
file staprun/staprun
staprun/staprun: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

sysstat

git clone https://github.com/sysstat/sysstat
cd sysstat
# git checkout 37d9210 -b build
./configure --host=mipsel-linux
make
ls iostat pidstat sar mpstat
file iostat
iostat: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, stripped

util-linux

git clone https://github.com/util-linux/util-linux
cd util-linux
# git checkout 6080329 -b build
./autogen.sh
./configure --host=mipsel-linux --without-python --without-systemd \
			--without-tinfo --disable-libblkid --disable-libuuid
make
file mkfs
mkfs: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

fio

git clone https://github.com/axboe/fio
git checkout bdf99b6 -b build
cd fio
# git checkout 5b991967 -b build
./configure --cpu=mips --cc=mipsel-linux-gcc --disable-xnvme
sed -i 's/oslib\/linux-dev-lookup.c engines\/io_uring.c engines\/nvme.c/oslib\/linux-dev-lookup.c/g' Makefile
make fio
file fio
fio: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

e2fsprogs

wget -c https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.46.5/e2fsprogs-1.46.5.tar.xz
tar xvf e2fsprogs-1.46.5.tar.xz
cd e2fsprogs-1.46.5
./configure --host=mipsel-linux
make
file misc/mke2fs
misc/mke2fs: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

bash

wget -c https://ftp.gnu.org/gnu/bash/bash-5.2.21.tar.gz
./configure --host=mipsel-linux
make

file bash
bash: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped

awk

wget -c https://ftp.gnu.org/gnu/gawk/gawk-5.3.0.tar.xz
./configure --host=mipsel-linux
make

file gawk
gawk: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped

perf

cd linux-6.1.68/tools/perf

export PATH=/usr/local/mips/mipsel-buildroot-linux-gnu/bin:$PATH
export MIPSEL_SYSROOT=/usr/local/mips/mipsel-buildroot-linux-gnu/mipsel-buildroot-linux-gnu/sysroot
make ARCH=mips CROSS_COMPILE=mipsel-linux- CFLAGS="--sysroot=${MIPSEL_SYSROOT}"

Auto-detecting system features:
...                                   dwarf: [ on  ]
...                      dwarf_getlocations: [ on  ]
...                                   glibc: [ on  ]
...                                  libbfd: [ on  ]
...                          libbfd-buildid: [ on  ]
...                                  libcap: [ OFF ]
...                                  libelf: [ on  ]
...                                 libnuma: [ OFF ]
...                  numa_num_possible_cpus: [ OFF ]
...                                 libperl: [ OFF ]
...                               libpython: [ OFF ]
...                               libcrypto: [ OFF ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ OFF ]
...                               get_cpuid: [ OFF ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ OFF ]

file perf
perf: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped

perl

wget -c https://www.cpan.org/src/5.0/perl-5.38.2.tar.gz
wget -c https://github.com/arsv/perl-cross/raw/releases/perl-cross-1.5.2.tar.gz

cd perl-5.38.2

tar --strip-components=1 -zxf ../perl-cross-1.5.2.tar.gz
./configure --target=mipsel-linux -Duseshrplib
make

file perl libperl.so
perl:       ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped
libperl.so: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, with debug_info, not stripped

lsof

git clone --depth 1 https://github.com/lsof-org/lsof
git checkout 932a0b3 -b build
export LSOF_CC="/usr/local/mips/mipsel-buildroot-linux-gnu/bin/mipsel-linux-gcc"
export LSOF_HOST="mipsel-linux"
export LINUX_CLIB="-DGLIBCV=2"
export LSOF_INCLUDE="/usr/local/mips/mipsel-buildroot-linux-gnu/usr/include"

./Configure linux
make

file lsof
lsof: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped

stress-ng

git clone --depth 1 https://github.com/ColinIanKing/stress-ng
git checkout e5dbc51 -b build
CC=mipsel-linux-gcc make

file stress-ng
stress-ng: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped

pcstat

wget -c https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
git clone --depth 1 https://github.com/tobert/pcstat
git checkout 9987e01 -b build

env GOOS=linux GOARCH=mipsle go build
file pcstat
pcstat: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, Go BuildID=Wy2VZqI6vqn54825sVhO/W7eVeNmrb0RxAKSIXX6y/QVRqLs2LVlxCQhjtf5AG/KSZnSGVME7Cx52C144Qi, with debug_info, not stripped

strace

git clone --depth 1 https://github.com/strace/strace
git checkout 9c5b28d -b build
./bootstrap
./configure --host=mipsel-linux
file src/strace
src/strace: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, with debug_info, not stripped

openssl

git clone https://github.com/openssl/openssl.git
git checkout openssl-3.0.8
export PATH=/opt/toolchain/aarch64/gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu/bin:$PATH
./config linux-aarch64 no-shared enable-devcryptoeng --libdir=lib
sed -i 's/CROSS_COMPILE=/CROSS_COMPILE=aarch64-linux-gnu-/g' Makefile
make
file apps/openssl
apps/openssl: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=5069392ee2f8463afac3b561659e94767f38a5c5, for GNU/Linux 3.7.0, with debug_info, not stripped