Configure GDB to accept Cross-Compiled executables? - arm

I'm still a newbie to assembly language and cross-compiling etc. I've already googled the problem I'm having and seen a few similar posts but none of them solved my problem unfortunately.
We're learning ARM32 Syntax at the university and playing around with assembly code on AARCH64 machines on a uni server. So we need to cross-compile the .s files to be able to run them.
We use the command arm-linuxgnueabihf-gcc to cross-compile.
Now the system (the loader I guess) is configured properly to execute these 32-bit cross executables. When I tried to debug a 32b exec however GDB crashes with error: selected architecture armv7 is not compatible with reported target architecture aarch64
There are screenshots below that illustrate the problem. Thanks for any help!
System infos:
System info
No error with native compiler:
No error with native compiler
Error with cross-compilation:
Error with cross-compilation

Related

cross compiling C code with external libraries

Host system: x86-64 Linux, Ubuntu 20.04
Target system: aarch64 Linux, Debian 11, arm architecture: Cortex A53
I develop for an aarch64 based Linux system on matlab/simulink. This toolchain is currently worked out for Linux and Windows hosts. However due to additional IIO devices on the system it has become clear that the current approach of just hardcoding the IIO device numbers is not gonna work anymore.
Now I found libiio which works great when I compile simple programs on the target itself. However I have not managed to cross compile applications using the library.
I have been trying to cross compile the libiio library itself by making a cross compilation file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_STAGING_PREFIX /home/maud/development/stage)
set(tools /usr/aarch64-none-linux-gnu)
set(CMAKE_C_COMPILER ${tools}/bin/aarch64-none-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-none-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
when I run cmake ../ -DCMAKE_TOOLCHAIN_FILE=~/development/crosscomp.cmake
from the build folder that I made in the libiio folder it seems to work fine. But when I run make the issue starts.
[ 28%] Building C object CMakeFiles/iio.dir/dns_sd_avahi.c.o
Reaping winning child 0x55c895073d40 PID 36856
Live child 0x55c895073d40 (CMakeFiles/iio.dir/dns_sd_avahi.c.o) PID 36858
/home/maud/Downloads/libiio-master/dns_sd_avahi.c:24:10: fatal error: avahi-common/address.h: No such file or directory
24 | #include <avahi-common/address.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~
I get this error, I do have libavahi-common-dev and libavahi-client-dev installed.
But I think it wants aarch64 compiled versions of the dependencies.
And it makes me question whether this is even a feasible goal, whether what I'm doing is even going to get me to where I want to be.
Is it even possible to add a library like this to such a cross compiling toolchain?
I tried taking the .so file from the target, but it will complain about missing a bunch of other dependencies. And even then I will only have managed to build from a Linux host, building from a Windows host feels like it would require way more trouble but I could be wrong. I'm still learning a lot about how all this works.
I got it mostly working, I compiled the library localy on my ARM system, but I tore out a bunch of features that I didnt need anyway. this left me with a library that didnt have any external dependencies (like the previously mentioned avahi common/client and a bunch more), then referencing it in my makefile and inluding the the header file got it working.
Was also able to cross compile from my x86 based host.

ARM Development Studio sometime fails to load symbols from IAR ELF

I am building an ELF using IAR 9.40. (although I have had the same problem with earlier versions of IAR). I am debugging using ARM Development Studio and an ARM DStream. The target is a Cortex-R7.
The problem is that sometime when I build, the debugger works fine and other times I get the following error:
ERROR(CMD685-COR11-IMG55):
! Failed to load symbols for "MyIARApp.elf"
! Failed to read the symbols from C:\Data\MyIARApp.elf
! Failed while reading from the file {0}
I have spent ages trying to resolve the issue, bit it looks like IAR sometimes creates an ELF in a format that ARM Development Studio cannot work with. I have tried building with no --no_dwarf4 but it makes no difference.
Any ideas? Thanks.

Installing Tensorflow Lite with CMake

I am trying to install Tensorflow Lite on Raspberry Pi Zero W. I followed the steps from the official website (https://www.tensorflow.org/lite/guide/build_cmake_arm). But I get the following error message:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc
-- Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_ed1a3/fast && /usr/bin/make -f CMakeFiles/cmTC_ed1a3.dir/build.make CMakeFiles/cmTC_ed1a3.dir/build
make[1]: Entering directory '/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o
/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc -march=armv6 -mfpu=vfp -funsafe-math-optimizations -o CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o -c /home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp/testCCompiler.c
/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc: 1: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc: Syntax error: ")" unexpected
make[1]: *** [CMakeFiles/cmTC_ed1a3.dir/build.make:66: CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o] Error 2
make[1]: Leaving directory '/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_ed1a3/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:44 (project)
Configuring incomplete, errors occurred!
See also "/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeOutput.log".
See also "/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeError.log".
Does anyone know how to fix the problem?
I ran into the same problem like you!
The instructions given at https://www.tensorflow.org/lite/guide/build_cmake_arm?hl=en are not intended to be executed on the Raspberry Pi (at least the last ones).
Let me share, what I'll figured out.
Short answer:
you're trying to run a cross-compile of TensorFlow Lite for an ARM made for x86 platform on an ARM system (your Raspberry Pi). What you're trying to do actually needs to be done on an x86 platform.
(on the top of the tutorial page is a hint: "following instructions have been tested on Ubuntu 16.04.3 64-bit PC (AMD64)" which reveals that the commands have been run on x86)
Some details:
The message ‘Syntax error: "(" unexpected’ probably comes from a shell. Why is a shell trying to execute your binary? Because the kernel tried and gave up. Why did the kernel fail to run the program? Because the executable is not in a supported format -> meant to be run on x86 but was executed on ARM.
https://unix.stackexchange.com/questions/336436/syntax-error-unexpected-when-execute-a-compiled-c-program
With older TensorFlow versions it was possible to compile TF lite on the Raspberry Pi itself via the
./tensorflow-2.4.1/tensorflow/lite/tools/make/download_dependencies.sh /and build_aarch64_lib.sh scripts.
However, this scripts got removed in version 2.8 (or even with an earlier version before). See note in the Readme of the Git: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/make/README.md
Using Python for inference
Unfortunately I have no real solution how to compile / built TensorFlow Lite on the Raspberry itself. I personally ended up using Python (only needed inference) and followed this Tutorial:
https://qengineering.eu/install-tensorflow-2.7-on-raspberry-64-os.html

Building and debugging ARMV8 assembler applications on Windows

I'm trying to learn ARMV8 assembler, and am trying to build a test application on Windows. I've installed ARM DS-5 Community Edition, version 5.26.2. After much hair pulling trying to install toolchains, I finally installed the "mingw32" toolchain here: here. This seems to work - I am now able to compile and link my application (which consists of a single c file and a .s assembly file. The target created is a ".axf" file.
But I am unable to debug. I have my debugger set to "\gcc-linaro-6.3.1-2017.02-i686-mingw32_aarch64-linux-gnu\bin\aarch64-linux-gnu-gdb.exe", out of the directory where I downloaded the toolchain. gdb starts up, but I get the error below:
Error in final launch sequence
Failed to execute MI command:
-exec-run
Error message from debugger back end:
Don't know how to run. Try "help target".
Don't know how to run. Try "help target".
Any suggestions? Frankly, I don't really know what I'm doing here. I'm not sure I set up the toolchain properly. The problem is I can't find any documentation on how to do this in windows.
Thanks in advance!

"Type 'MPI_Status' could not be resolved" in Eclipse Parallel Tools Platform (Kepler)

I'm trying to get a development environment going for programming with MPI and C. I had a look around and found Eclipse Parallel Tools Platform.
I am experiencing lots of errors of the form Type 'MPI_Status' could not be resolved and other resolution errors from vanilla eclipse-ptp-kepler. I'm on Linux x86_64 (Ubuntu 12.04.3 LTS) using the helloworld MPI C example with the Linux GCC Toolchain.
Also perhaps noteworthy: Launching the default "Local C/C++ Application" Run Configuration gives Launch failed. Binary not found
Any help would be greatly appreciated! Suggestions about other development environments are welcome if you are unsure of the solution to this problem.
Thanks for reading!
MPI_Status is typically defined in mpi.h, so you'll have to make sure it's in your include path. The "launch failed" error also suggests that maybe the mpirun, mpiexec or mpicc programs are missing from your executable path. You might have to either set up an MPI implementation like OpenMPI locally and point PTP to it, or follow the directions here to set up a remote build: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.ptp.doc.user%2Fhtml%2Ftoc.html
you need to pass the flag -fopenmp to gcc to enable OpenMP, don't forget that OpenMP is a technology that needs support from the compiler; on other implementation the flag may vary, check the docs for your compiler.

Resources