build valgrind for Android using NDK21

319 Views Asked by At

I am trying to build valgrind for Android. According to the official documentation AARCH64/Android is a supported platform, but the documentation on how to build was last updated to 2014.

What I am trying to do: On a WSl2 with ubuntu:

Below the configuration and the build log.

Some notes about the output:

  • it seems valgrind is supposed to be using only gcc
  • the flag -m64 is added when it shouldn't be there
  • While building I see both -m32 and -m64 flags
  • I am not able to read assembly code, but it seems the build is using x86 assembly

Questions

  • What Am I doing wrong?
  • Is it possible to build Valgrind for Android using the modern NDK?
  • What alternatives do I have?
git clone git://sourceware.org/git/valgrind.git
cd valgrind

export NDK_ROOT=/opt/ndk/android-ndk-r21e
export TOOLCHAIN_ROOT=${NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin

ANDROID_API=23
TARGET=aarch64-linux-android
PREFIX=${TARGET}${ANDROID_API}

export CC=${TOOLCHAIN_ROOT}/${PREFIX}-clang
export CXX=${TOOLCHAIN_ROOT}/${PREFIX}-clang++

export AR=${TOOLCHAIN_ROOT}/${TARGET}-ar
export LD=${TOOLCHAIN_ROOT}/${TARGET}-ld
export STRIPE=${TOOLCHAIN_ROOT}/${TARGET}-strip
export NM=${TOOLCHAIN_ROOT}/${TARGET}-nm
export RANLIB=${TOOLCHAIN_ROOT}/${TARGET}-ranlib

./autogen.sh
mkdir build && cd build
../configure --host=${TARGET} --target=${TARGET} --prefix=${PWD}/inst

Configure output:

                    Version: 3.21.0.GIT
         Maximum build arch: arm64
         Primary build arch: arm64
       Secondary build arch: arm
                   Build OS: linux
     Link Time Optimisation: no
       Primary build target: ARM64_LINUX
     Secondary build target: ARM_LINUX
           Platform variant: android
      Primary -DVGPV string: -DVGPV_arm64_linux_android=1
         Default supp files: ../xfree-3.supp ../xfree-4.supp ../bionic.supp

Build log:

[...]
make[3]: Entering directory '/home/edukaj/qcom/valgrind/build/VEX'
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -DHAVE_CONFIG_H -I. -I../../VEX -I..  -I../.. -I../../include -I../include -I../../VEX/pub -I../VEX/pub -DVGA_arm64=1 -DVGO_linux=1 -DVGP_arm64_linux=1 -DVGPV_arm64_linux_android=1  -Ipriv  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare   -Wbad-function-cast -fstrict-aliasing  -MT priv/libvex_arm64_linux_a-main_globals.o -MD -MP -MF priv/.deps/libvex_arm64_linux_a-main_globals.Tpo -c -o priv/libvex_arm64_linux_a-main_globals.o `test -f 'priv/main_globals.c' || echo '../../VEX/'`priv/main_globals.c
mv -f priv/.deps/libvex_arm64_linux_a-main_globals.Tpo priv/.deps/libvex_arm64_linux_a-main_globals.Po
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -DHAVE_CONFIG_H -I. -I../../VEX -I..  -I../.. -I../../include -I../include -I../../VEX/pub -I../VEX/pub -DVGA_arm64=1 -DVGO_linux=1 -DVGP_arm64_linux=1 -DVGPV_arm64_linux_android=1  -Ipriv  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare   -Wbad-function-cast -fstrict-aliasing  -MT priv/libvex_arm64_linux_a-main_main.o -MD -MP -MF priv/.deps/libvex_arm64_linux_a-main_main.Tpo -c -o priv/libvex_arm64_linux_a-main_main.o `test -f 'priv/main_main.c' || echo '../../VEX/'`priv/main_main.c
mv -f priv/.deps/libvex_arm64_linux_a-main_main.Tpo priv/.deps/libvex_arm64_linux_a-main_main.Po
[...]
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -DHAVE_CONFIG_H -I. -I../../VEX -I..  -I../.. -I../../include -I../include -I../../VEX/pub -I../VEX/pub -DVGA_arm=1 -DVGO_linux=1 -DVGP_arm_linux=1 -DVGPV_arm_linux_android=1  -Ipriv  -m32 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare  -marm -mcpu=cortex-a8  -Wbad-function-cast -fstrict-aliasing  -MT priv/libvex_arm_linux_a-host_ppc_defs.o -MD -MP -MF priv/.deps/libvex_arm_linux_a-host_ppc_defs.Tpo -c -o priv/libvex_arm_linux_a-host_ppc_defs.o `test -f 'priv/host_ppc_defs.c' || echo '../../VEX/'`priv/host_ppc_defs.c
mv -f priv/.deps/libvex_arm_linux_a-host_ppc_defs.Tpo priv/.deps/libvex_arm_linux_a-host_ppc_defs.Po
[...]
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare   -static  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare     -o vgdb vgdb-vgdb.o vgdb-vgdb-invoker-none.o      
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -DHAVE_CONFIG_H -I. -I../../coregrind -I..  -I../.. -I../../include -I../include -I../../VEX/pub -I../VEX/pub -DVGA_arm64=1 -DVGO_linux=1 -DVGP_arm64_linux=1 -DVGPV_arm64_linux_android=1  -I../../coregrind -DVG_LIBDIR="\"/home/edukaj/qcom/valgrind/build/inst/libexec/valgrind"\" -DVG_PLATFORM="\"arm64-linux\""  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare  -O -g -fno-omit-frame-pointer -fno-strict-aliasing -fpic -fno-builtin   -MT vgpreload_core_arm64_linux_so-vg_preloaded.o -MD -MP -MF .deps/vgpreload_core_arm64_linux_so-vg_preloaded.Tpo -c -o vgpreload_core_arm64_linux_so-vg_preloaded.o `test -f 'vg_preloaded.c' || echo '../../coregrind/'`vg_preloaded.c
../../coregrind/vg_preloaded.c:118:5: warning: inline asm clobber list contains reserved registers: X18 [-Winline-asm]
    CALL_FN_W_v(result, fn);
    ^
../include/valgrind.h:4316:10: note: expanded from macro 'CALL_FN_W_v'
         VALGRIND_ALIGN_STACK                                     \
         ^
../include/valgrind.h:4301:7: note: expanded from macro 'VALGRIND_ALIGN_STACK'
      "mov x21, sp\n\t"                    \
      ^
<inline asm>:1:1: note: instantiated into assembly here
        mov x21, sp
^
../../coregrind/vg_preloaded.c:118:5: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
    CALL_FN_W_v(result, fn);
    ^
../include/valgrind.h:4316:10: note: expanded from macro 'CALL_FN_W_v'
         VALGRIND_ALIGN_STACK                                     \
         ^
../include/valgrind.h:4301:7: note: expanded from macro 'VALGRIND_ALIGN_STACK'
      "mov x21, sp\n\t"                    \
      ^
<inline asm>:1:1: note: instantiated into assembly here
        mov x21, sp
^
1 warning generated.
mv -f .deps/vgpreload_core_arm64_linux_so-vg_preloaded.Tpo .deps/vgpreload_core_arm64_linux_so-vg_preloaded.Po
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare  -O -g -fno-omit-frame-pointer -fno-strict-aliasing -fpic -fno-builtin   -nodefaultlibs -shared -Wl,-z,interpose,-z,initfirst -nostdlib -m64   -o vgpreload_core-arm64-linux.so vgpreload_core_arm64_linux_so-vg_preloaded.o  
/opt/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang -DHAVE_CONFIG_H -I. -I../../coregrind -I..  -I../.. -I../../include -I../include -I../../VEX/pub -I../VEX/pub -DVGA_arm=1 -DVGO_linux=1 -DVGP_arm_linux=1 -DVGPV_arm_linux_android=1  -I../../coregrind -DVG_LIBDIR="\"/home/edukaj/qcom/valgrind/build/inst/libexec/valgrind"\" -DVG_PLATFORM="\"arm-linux\""  -m32 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wenum-conversion -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin -Wno-cast-align -Wno-self-assign -Wno-tautological-compare  -marm -mcpu=cortex-a8 -O -g -fno-omit-frame-pointer -fno-strict-aliasing -fpic -fno-builtin   -MT vgpreload_core_arm_linux_so-vg_preloaded.o -MD -MP -MF .deps/vgpreload_core_arm_linux_so-vg_preloaded.Tpo -c -o vgpreload_core_arm_linux_so-vg_preloaded.o `test -f 'vg_preloaded.c' || echo '../../coregrind/'`vg_preloaded.c
<inline asm>:1:41: error: expected '%<type>' or "<type>"
.pushsection ".debug_gdb_scripts", "MS",@progbits,1
                                        ^
<inline asm>:4:13: error: .popsection without corresponding .pushsection
.popsection 
            ^
2 errors generated.
make[3]: *** [Makefile:9394: vgpreload_core_arm_linux_so-vg_preloaded.o] Error 1
make[3]: Leaving directory '/home/edukaj/qcom/valgrind/build/coregrind'
make[2]: *** [Makefile:2484: all] Error 2
make[2]: Leaving directory '/home/edukaj/qcom/valgrind/build/coregrind'
make[1]: *** [Makefile:907: all-recursive] Error 1
make[1]: Leaving directory '/home/edukaj/qcom/valgrind/build'
make: *** [Makefile:770: all] Error 2
0

There are 0 best solutions below