Search code examples
embedded-linuxexecutablebinaryfilesyoctobitbake

Why is my app a different size on my yocto build server compared to what is installed on target?


I am using Yocto to create custom linux images for an embedded project. I have discovered something strange recently and am having trouble wrapping my head around the issue. One of the applications contained in the image is custom software, let's call the application foo. After a successful build on the yocto build server, the built, cross-compiled foo executable can be found in the tmp/work/armv7at2hf-neon-fslc-linux-gnueabi/foo/1.0.0-r0/git directory. The size of the foo executable (obtained using ls -al) on the build server is 40978880 bytes.

The image can be ran on target hardware by flashing an SD card w/ the generated image tar.gz file. After flashing an SD card and booting the image on the target, I navigate to the directory in which foo was installed. On the target, I again obtain the size of the executable using ls -al and I find that the size of the foo executable has shrunk and is 38585152 bytes. Despite the executable size shrinking, the application works fine.

This change in size is unacceptable because it prevents me from being able to do a sha256 verification of the foo executable during the application launch process. The verification fails since foo on the build server is not byte for byte identical to the foo executable that is installed on the target. The size difference has left me baffled. Especially since all the other files that my layer installs on the rootfs have the same size on both the build server and the target.

What could be causing this difference regarding the size of the foo executable?


Solution

  • You are not comparing the deployable artifacts, the deployable binaries are in packages-split/ directory. Once do_compile is finished, the binary contains debug info and symbols, usually needed for debugging not for running. So there are additional steps that are exectuted, one of them is to install it into staging area which will be image/ dir inside the recipe workdir. Then do_package task will divide the files in image/ into output packages ( ipks/rpms ) in packages-split folder, after running strip operations to ensure debug info and symbols are packages into debug packages, the final binary is then inside packages-split/<PN> and it will be under same path as it is on target like /usr/bin it will be in packages-split/<name>/usr/bin and this is the binary you should be checksumming