How to compile strace for use on an Android phone (running an ARM CPU)

The instructions are very precise, following them you get your statically linked strace.

Just to be safe (in case the original source disappears), I'll back up the instructions for myself:

  1. Prerequisite: you already have the cross compiler downloaded from the CodeSourcery GNU toolchain site, make sure you select ARM GNU/Linux, and IA32 GNU/Linux.
  2. Download the strace source distribution from the SourceForge strace project.
  3. Extract the strace package on your linux machine.
  4. Set your compiler information:
    export CC=your_cross_compiler_folder/bin/arm-none-linux-gnueabi-gcc
    export STRIP=your_cross_compiler_folder/bin/arm-none-linux-gnueabi-strip
    export CFLAGS="-O2 -static"
    Note: CFLAGS is by default -g -O2, but we need static linking and (optionally) no debug information. You can even leave out -static, but in that case you'll have to ship the compiled executable with all the referenced shared libs from the cross compiler!
  5. Add your_cross_compiler_folder/bin into your $PATH.
  6. Change your current folder to the strace folder (where you extracted the source), use command:
    ./configure --host=arm-linux
    Optionally you might want to specify a prefix with --prefix=/data/local.
  7. Compile:
    make
  8. Verify the result (eg. static linking) with the command:
    file strace
    You shall see:
    strace: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, statically linked, not stripped
  9. Optionally you can strip symbols from it with:
    $STRIP strace
    (if you only need the executable)
    Or package it into a TGZ:
    tmpdir="$(mktemp -d)"
    mkdir -p "$tmpdir/data/local"
    make install-strip prefix="$tmpdir/data/local"
    dir="$(dirname "$(pwd)")"
    packagefile="$dir/$(basename "$(pwd)")-bin.tgz"
    cd "$tmpdir"
    fakeroot -- sh -c "chmod -R a+rX,u+w,go-w data && chown -R root:root data && tar czf \"$packagefile\" data"
    cd "$dir"
    rm -rf "$tmpdir"
Done, you have another powerful tool for your Android.

P.S.: I've made a few changes (imho optimizations) to the original instructions.

Update (2013.05.23): I've reapplied the same instructions to compile strace v4.7 with Sourcery CodeBench Lite 2013.05-24. I installed the latter with the linux installer (arm-2013.05-24-arm-none-linux-gnueabi.bin) in my user home directory on a 32-bit Ubuntu 10.10 (x86) server. I've attached the compiled TGZ package that you can simply extract into your filesystem and it'll put all strace files into /data/local.

AttachmentSize
strace-4.7-arm-bin.tgz378.33 KB
Syndicate content