Search code examples
linuxgitlabvalgrindesp8266docker-image

Valgrind analysis in 32-bit elf file on 64-bit Linux Docker machine


I would like to use Valgrind tool for ESP8266 code & memory analysis.

I am trying to use it in Gitlab's job, the .elf file is 32-bits and is compiled in another job using platformio, ok with that.

In the Valgrind job, I am trying to use different docker images (which all are 64-bits), but I see similar errors when running Valgrind. I have been facing architecture issues because the .elf file is 32-bits and the image 64-bits, and then I am facing and issue with memcheck.

The commands running in the job are these ones:

  • uname --machine

    x86_64

  • apt-get update && apt-get install -y valgrind valgrind-dbg g++ libc6-dbg

    Installation is OK.

  • dpkg-query -L valgrind

    Many directories are shown: /usr/bin/valgrind /usr/include/valgrind /usr/lib/valgrind /usr/share/doc/valgrind (...)

  • export VALGRIND_LIB="/usr/lib/valgrind/"

  • export CFLAGS=-m32

  • file firmware.elf

    firmware.elf: ELF 32-bit LSB executable, Tensilica Xtensa, version 1 (SYSV), statically linked, with debug_info, not stripped

  • linux32 --32bit valgrind --force-arch=i386 --leak-check=full ./firmware.elf

    I have run this command with & without linux32 --32bit --force-arch=i386

    When running the last command, I see 3 different errors depending on the docker image I am using:

  1. image: vowstar/esp8266. valgrind: wrong ELF executable class (eg. 32-bit instead of 64-bit) valgrind: ./firmware.elf: cannot execute binary file

  2. image: i386/ubuntu. valgrind: executable is not for this architecture valgrind: ./firmware.elf: cannot execute binary file

  3. image: espressif/idf. valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory

Seems like the third image goes further, but I am unable to install memcheck.

Any easier way to use Valgrind in a docker image?

I know there are some similar questions about this, but nothing worked for me:

valgrind not building 32 bit rpm on 64 bit machine

Ubuntu: valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory

How to compile a 32-bit binary on a 64-bit linux machine with gcc/cmake


Solution

  • ESP8266 has no MMU capable of virtual memory, so it's not possible to run dynamic linker on it, so it's not possible to run valgrind on ESP8266.