Cross compiled hello world hangs on aarch64

Hi,

I'm trying to get rust working on an IMX8 based aarch64 SOC running a buildroot generated Linux image. I've followed the general instructions for cross compiling for ARM.

rustup target add aarch64-unknown-linux-gnu

Set up my .cargo/config like this, using the linker from the buildroot:

[target.aarch64-unknown-linux-gnu]
linker = "/home/land//buildroot/output/host/bin/aarch64-none-linux-gnu-ld

I created a hello world cargo project and build it using:

cargo build --target=aarch64-unknown-linux-gnu

This runs fine and creates a binary that I copy over to the target system. When I run it, it hangs, using 100% CPU.

I've tried attaching a gdb session and print a backtrace. It doesn't seem to be stuck at a single place, but this is a common backtrace when I press ctrl-c:

0x0000007f90287d40 in pthread_mutex_lock () from /lib64/libpthread.so.0
(gdb) bt
#0  0x0000007f90287d40 in pthread_mutex_lock () from /lib64/libpthread.so.0
#1  0x000000558f766448 in std::sys::unix::mutex::Mutex::lock ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/std/src/sys/unix/mutex.rs:63
#2  std::sys_common::mutex::StaticMutex::lock ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/std/src/sys_common/mutex.rs:29
#3  std::sys::unix::args::imp::really_init ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/std/src/sys/unix/args.rs:93
#4  std::sys::unix::args::imp::ARGV_INIT_ARRAY::init_wrapper ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/std/src/sys/unix/args.rs:123

Running an strace on the binary, the output ends with the following and then just stops:

mprotect(0x5578510000, 4096, PROT_READ) = 0
mprotect(0x7f9d9e7000, 4096, PROT_READ) = 0
set_tid_address(0x7f9d9df0e0)           = 7295
set_robust_list(0x7f9d9df0f0, 24)       = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f9d93eef8, sa_mask=[], sa_flags=SA_SIGINFO}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f9d93efb8, sa_mask=[], sa_flags=SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0

<NO MORE OUTPUT, EVEN THOUGH THE PROCESS KEEPS RUNNING >

Should I expect cross-compiling for a generic aarch64 Linux like this to just work? Did I miss something obvious?

Any ideas on how to debug this and find out what's going wrong? I've tried both debug and release builds and they seem to behave in the same way.

Instead of specifying the -ld executable, specify the -gcc executable. Hope this helps!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.