Git Product home page Git Product logo

Comments (16)

bjorn3 avatar bjorn3 commented on July 22, 2024

Can you get a backtrace of the crash and disassembly of the function it crashes in? Basically run it in gdb, and then when it crashes run the bt and disassemble commands.

from rust.

long568 avatar long568 commented on July 22, 2024

I compiled the program by running cargo build on docker, copy it to raspberry, and then:

$ ./hinj_brain 
Hi, Ninja!
Illegal instruction
$ gdb run hinj_brain
GNU gdb (Debian 13.1-3) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
run: No such file or directory.
"/home/lo/hinj_brain/hinj_brain" is not a core dump: file format not recognized

This time I did not use once related code, but std::thread related code.
I think the problem lies in the thread-related low-level instructions. Although M2 is aarch64, maybe Apple uses some super power ? who knows ...
I will build directly on the Raspberry Pi later to test whether the thread-related code works properly and report the results here. However, installing Rust on the Raspberry Pi Zero2W is a painful and happy thing...HAHA

from rust.

long568 avatar long568 commented on July 22, 2024

I compiled the program by running cargo build on raspberry pi zero 2 w, then:

$ cargo run
Hi, Ninja!
Bye, Ninja~
Motion Service Exited.

The code works properly...

from rust.

long568 avatar long568 commented on July 22, 2024

After some researching, I found the following information:

Macbook pro
CPU: M2
Arch: ARMv8.6-A 64-bit

Raspberry pi zero 2w
CPU: Broadcom BCM2710A1
Arch: ARMv8-A 64-bit

from rust.

long568 avatar long568 commented on July 22, 2024

I installed the cross-compile tools and tested different build platforms under the same conditions.

Target System:
Raspberry Pi Zero 2 W + Raspberry Pi OS Lite 64bit

Build System:
amd64 + Ubuntu20.04 + Docker(Debian)
rustc 1.78.0 / aarch-unknown-linux-gcc 12.2.0
The program works properly.

Build System:
Macbook pro M2 + Docker(Debian)
rustc 1.78.0 / aarch-unknown-linux-gcc 12.2.0
The program got the error: Illegal instruction.

from rust.

long568 avatar long568 commented on July 22, 2024

On Mac, the cross-compilation toolchain is not installed independently, but points to the mirrored toolchain.

# which aarch64-linux-gnu-gcc                     
/usr/bin/aarch64-linux-gnu-gcc
# ls -l /usr/bin/aarch64-linux-gnu-gcc
lrwxrwxrwx 1 root root 6 Jan  8  2023 /usr/bin/aarch64-linux-gnu-gcc -> gcc-12

from rust.

bjorn3 avatar bjorn3 commented on July 22, 2024

For running in gdb, you need to do gdb path/to/executable and then enter the run command. gdb run path/to/executable isn't supported.

from rust.

long568 avatar long568 commented on July 22, 2024

For running in gdb, you need to do gdb path/to/executable and then enter the run command. gdb run path/to/executable isn't supported.

Hello, It is the log below:

$ gdb hinj_brain-mac
GNU gdb (Debian 13.1-3) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hinj_brain-mac...
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/lo/hinj_brain/hinj_brain-mac.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) 
(gdb) run
Starting program: /home/lo/hinj_brain/hinj_brain-mac 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Hi, Ninja!

Program received signal SIGILL, Illegal instruction.
core::sync::atomic::AtomicUsize::fetch_add ()
    at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/sync/atomic.rs:2667
2667	/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/sync/atomic.rs: No such file or directory.

from rust.

bjorn3 avatar bjorn3 commented on July 22, 2024

Can you run the disassemble command of gdb after the crash?

from rust.

long568 avatar long568 commented on July 22, 2024

Can you run the disassemble command of gdb after the crash?

Sure

(gdb) disassemble
Dump of assembler code for function _ZN68_$LT$alloc..sync..Arc$LT$T$C$A$GT$$u20$as$u20$core..clone..Clone$GT$5clone17h865e6c5c5e1e3ad2E:
   0x000000555555c5bc <+0>:	sub	sp, sp, #0xa0
   0x000000555555c5c0 <+4>:	str	x30, [sp, #144]
   0x000000555555c5c4 <+8>:	str	x0, [sp, #8]
   0x000000555555c5c8 <+12>:	mov	w8, #0x1                   	// #1
   0x000000555555c5cc <+16>:	str	x8, [sp, #16]
   0x000000555555c5d0 <+20>:	strb	wzr, [sp, #31]
   0x000000555555c5d4 <+24>:	str	x8, [sp, #32]
   0x000000555555c5d8 <+28>:	strb	wzr, [sp, #47]
   0x000000555555c5dc <+32>:	mov	x9, x0
   0x000000555555c5e0 <+36>:	str	x9, [sp, #56]
   0x000000555555c5e4 <+40>:	mov	x9, x0
   0x000000555555c5e8 <+44>:	str	x9, [sp, #72]
   0x000000555555c5ec <+48>:	ldr	x9, [x0]
   0x000000555555c5f0 <+52>:	mov	x10, x9
   0x000000555555c5f4 <+56>:	str	x10, [sp, #80]
   0x000000555555c5f8 <+60>:	mov	x10, x9
   0x000000555555c5fc <+64>:	str	x10, [sp, #88]
   0x000000555555c600 <+68>:	mov	x10, x9
   0x000000555555c604 <+72>:	str	x10, [sp, #96]
   0x000000555555c608 <+76>:	mov	x10, x9
   0x000000555555c60c <+80>:	str	x10, [sp, #104]
   0x000000555555c610 <+84>:	mov	x10, x9
   0x000000555555c614 <+88>:	str	x10, [sp, #112]
=> 0x000000555555c618 <+92>:	ldadd	x8, x8, [x9]
   0x000000555555c61c <+96>:	str	x8, [sp, #120]
   0x000000555555c620 <+100>:	ldr	x8, [sp, #120]
   0x000000555555c624 <+104>:	str	x8, [sp, #128]
   0x000000555555c628 <+108>:	mov	x9, #0x7fffffffffffffff    	// #9223372036854775807
   0x000000555555c62c <+112>:	subs	x8, x8, x9
   0x000000555555c630 <+116>:	b.hi	0x555555c668 <_ZN68_$LT$alloc..sync..Arc$LT$T$C$A$GT$$u20$as$u20$core..clone..Clone$GT$5clone17h865e6c5c5e1e3ad2E+172>  // b.pmore
   0x000000555555c634 <+120>:	b	0x555555c638 <_ZN68_$LT$alloc..sync..Arc$LT$T$C$A$GT$$u20$as$u20$core..clone..Clone$GT$5clone17h865e6c5c5e1e3ad2E+124>
   0x000000555555c638 <+124>:	ldr	x8, [sp, #8]
   0x000000555555c63c <+128>:	ldr	x9, [x8]
   0x000000555555c640 <+132>:	str	x9, [sp]
   0x000000555555c644 <+136>:	str	x9, [sp, #136]
   0x000000555555c648 <+140>:	add	x0, x8, #0x8
   0x000000555555c64c <+144>:	bl	0x55555648a8 <_ZN59_$LT$alloc..alloc..Global$u20$as$u20$core..clone..Clone$GT$5clone17h07dcc1458a0efa05E>
   0x000000555555c650 <+148>:	ldr	x8, [sp]
   0x000000555555c654 <+152>:	str	x8, [sp, #48]
   0x000000555555c658 <+156>:	ldr	x0, [sp, #48]
   0x000000555555c65c <+160>:	ldr	x30, [sp, #144]
   0x000000555555c660 <+164>:	add	sp, sp, #0xa0
   0x000000555555c664 <+168>:	ret
   0x000000555555c668 <+172>:	brk	#0x1
End of assembler dump.

Does ldadd is super power of Apple ?

from rust.

long568 avatar long568 commented on July 22, 2024

ldadd seems to belong to ARMv8.1-M, but not v8-a or v8.6-a ...

from rust.

bjorn3 avatar bjorn3 commented on July 22, 2024

Do you have RUSTFLAGS="-Ctarget-cpu=native" or something like that set? Maybe as env var, maybe in ~/.cargo/config.toml, maybe in .cargo/config.toml in the project directory or any parent directory?

from rust.

long568 avatar long568 commented on July 22, 2024

Do you have RUSTFLAGS="-Ctarget-cpu=native" or something like that set? Maybe as env var, maybe in ~/.cargo/config.toml, maybe in .cargo/config.toml in the project directory or any parent directory?

YES!
The .bashrc was copied from another pc...
After I removed the "-C target-cpu=native", the program works properly now, thx.

from rust.

bjorn3 avatar bjorn3 commented on July 22, 2024

-Ctarget-cpu=native produces executables which are only guaranteed to work on the local cpu. Given that removing the -Ctarget-cpu=native worked for you, I will close this as expected behavior.

from rust.

long568 avatar long568 commented on July 22, 2024

-Ctarget-cpu=native produces executables which are only guaranteed to work on the local cpu. Given that removing the -Ctarget-cpu=native worked for you, I will close this as expected behavior.

Got it.
m2 and BCM2710A1 are both aarch64, so I thought they had the same instruction set.

from rust.

bjorn3 avatar bjorn3 commented on July 22, 2024

The base instruction set is the same, but the m2 has a fair amount of newer extensions to aarch64 which improve performance, but aren't supported by older cpu's like those in the raspberry pi zero 2 w. The same happens with x86_64 which has extensions like AVX, AVX2 and AVX512 and with many other cpu architectures.

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.