【问题标题】:cross compiled binary runs on RPi 3B not on RPi 3B+交叉编译的二进制文件在 RPi 3B 上而不是在 RPi 3B+ 上运行
【发布时间】:2021-10-26 14:24:40
【问题描述】:

我在新安装的靶心机器上尝试使用分发版附带的 arm-linux-gnuabihf-gcc 为 Raspberry Pi 3B+ 交叉编译“Hello World”。

编译:

arm-linux-gnuabihf-gcc -ohw hw.c

目标上的二进制段错误

然后我又尝试了 3 个来自 linaro 的工具链 7.5 和 10.2 和 8.3 以及 https://sourceforge.net/projects/raspberry-pi-cross-compilers/

所有相同的结果,目标上的二进制段错误

我使用了我的开发机器,它运行带有分发 arm-linux-gnuabihf- 工具链的 Buster,进行了相同的编译,它还在目标上出现了段错误。

然后,我从 Raspberry Pi 3B+ 中取出同一张 sd 卡(原始 Raspberry Pi OS 10 lite)并将其塞入 Raspberry Pi 3B。 二进制文件运行良好。

有人知道我做错了什么吗?

谢谢 朱

我尝试运行的程序:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
    return EXIT_SUCCESS;
}

Raspberry Pi 3B+ 上的调试会话

pi@raspberrypi:~ $ gdb shw
GNU gdb (Raspbian 8.2.1-2) 8.2.1
Copyright (C) 2018 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 "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 shw...done.
(gdb) info files
Symbols from "/home/pi/shw".
Local exec file:
    `/home/pi/shw', file type elf32-littlearm.
    Entry point: 0x10318
    0x00010154 - 0x0001016d is .interp
    0x00010170 - 0x00010190 is .note.ABI-tag
    0x00010190 - 0x000101b8 is .hash
    0x000101b8 - 0x000101e4 is .gnu.hash
    0x000101e4 - 0x00010234 is .dynsym
    0x00010234 - 0x00010275 is .dynstr
    0x00010276 - 0x00010280 is .gnu.version
    0x00010280 - 0x000102a0 is .gnu.version_r
    0x000102a0 - 0x000102a8 is .rel.dyn
    0x000102a8 - 0x000102c8 is .rel.plt
    0x000102c8 - 0x000102d4 is .init
    0x000102d4 - 0x00010318 is .plt
    0x00010318 - 0x00010434 is .text
    0x00010434 - 0x0001043c is .fini
    0x0001043c - 0x00010574 is .rodata
    0x00010574 - 0x0001057c is .ARM.exidx
    0x0001057c - 0x00010580 is .eh_frame
    0x00020f08 - 0x00020f0c is .init_array
    0x00020f0c - 0x00020f10 is .fini_array
    0x00020f10 - 0x00021000 is .dynamic
    0x00021000 - 0x00021020 is .got
    0x00021020 - 0x00021028 is .data
    0x00021028 - 0x0002102c is .bss
(gdb) break *0x10318
Breakpoint 1 at 0x10318: file ../sysdeps/arm/start.S, line 79.
(gdb) run
Starting program: /home/pi/shw 

Program received signal SIGSEGV, Segmentation fault.
0x0005f4de in ?? ()
(gdb) disas
No function contains program counter for selected frame.
(gdb) bt
#0  0x0005f4de in ?? ()
#1  0x0001032a in _start () at ../sysdeps/arm/start.S:113
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) info reg
r0             0x0                 0
r1             0x1                 1
r2             0xbefff704          3204445956
r3             0xbefff70c          3204445964
r4             0x0                 0
r5             0x0                 0
r6             0x10319             66329
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0xb6fff000          3070226432
r11            0x0                 0
r12            0x0                 0
sp             0xbefff6fc          0xbefff6fc
lr             0x1032b             66347
pc             0x5f4de             0x5f4de
cpsr           0x40000030          1073741872
fpscr          0x0                 0
(gdb) info thread
  Id   Target Id         Frame 
* 1    process 469 "shw" 0x0005f4de in ?? ()
pi@raspberrypi:~ $ arm-linux-gnueabihf-objdump -d shw
shw:     file format elf32-littlearm


Disassembly of section .init:

000102c8 <_init>:
   102c8:   e92d4008    push    {r3, lr}
   102cc:   eb00001d    bl  10348 <call_weak_fn>
   102d0:   e8bd8008    pop {r3, pc}

Disassembly of section .plt:

000102d4 <.plt>:
   102d4:   e52de004    push    {lr}        ; (str lr, [sp, #-4]!)
   102d8:   e59fe004    ldr lr, [pc, #4]    ; 102e4 <.plt+0x10>
   102dc:   e08fe00e    add lr, pc, lr
   102e0:   e5bef008    ldr pc, [lr, #8]!
   102e4:   00010d1c    .word   0x00010d1c

000102e8 <puts@plt>:
   102e8:   e28fc600    add ip, pc, #0, 12
   102ec:   e28cca10    add ip, ip, #16, 20 ; 0x10000
   102f0:   e5bcfd1c    ldr pc, [ip, #3356]!    ; 0xd1c

000102f4 <__libc_start_main@plt>:
   102f4:   e28fc600    add ip, pc, #0, 12
   102f8:   e28cca10    add ip, ip, #16, 20 ; 0x10000
   102fc:   e5bcfd14    ldr pc, [ip, #3348]!    ; 0xd14

00010300 <__gmon_start__@plt>:
   10300:   e28fc600    add ip, pc, #0, 12
   10304:   e28cca10    add ip, ip, #16, 20 ; 0x10000
   10308:   e5bcfd0c    ldr pc, [ip, #3340]!    ; 0xd0c

0001030c <abort@plt>:
   1030c:   e28fc600    add ip, pc, #0, 12
   10310:   e28cca10    add ip, ip, #16, 20 ; 0x10000
   10314:   e5bcfd04    ldr pc, [ip, #3332]!    ; 0xd04

Disassembly of section .text:

00010318 <_start>:
   10318:   f04f 0b00   mov.w   fp, #0
   1031c:   f04f 0e00   mov.w   lr, #0
   10320:   bc02        pop {r1}
   10322:   466a        mov r2, sp
   10324:   b404        push    {r2}
   10326:   b401        push    {r0}
   10328:   f8df c010   ldr.w   ip, [pc, #16]   ; 1033c <_start+0x24>
   1032c:   f84d cd04   str.w   ip, [sp, #-4]!
   10330:   4803        ldr r0, [pc, #12]   ; (10340 <_start+0x28>)
   10332:   4b04        ldr r3, [pc, #16]   ; (10344 <_start+0x2c>)
   10334:   f7ff efde   blx 102f4 <__libc_start_main@plt>
   10338:   f7ff efe8   blx 1030c <abort@plt>
   1033c:   00010431    .word   0x00010431
   10340:   000103d9    .word   0x000103d9
   10344:   000103f1    .word   0x000103f1

00010348 <call_weak_fn>:
   10348:   e59f3014    ldr r3, [pc, #20]   ; 10364 <call_weak_fn+0x1c>
   1034c:   e59f2014    ldr r2, [pc, #20]   ; 10368 <call_weak_fn+0x20>
   10350:   e08f3003    add r3, pc, r3
   10354:   e7932002    ldr r2, [r3, r2]
   10358:   e3520000    cmp r2, #0
   1035c:   012fff1e    bxeq    lr
   10360:   eaffffe6    b   10300 <__gmon_start__@plt>
   10364:   00010ca8    .word   0x00010ca8
   10368:   0000001c    .word   0x0000001c

0001036c <deregister_tm_clones>:
   1036c:   f241 0028   movw    r0, #4136   ; 0x1028
   10370:   f2c0 0002   movt    r0, #2
   10374:   f241 0328   movw    r3, #4136   ; 0x1028
   10378:   f2c0 0302   movt    r3, #2
   1037c:   4283        cmp r3, r0
   1037e:   d005        beq.n   1038c <deregister_tm_clones+0x20>
   10380:   f240 0300   movw    r3, #0
   10384:   f2c0 0300   movt    r3, #0
   10388:   b103        cbz r3, 1038c <deregister_tm_clones+0x20>
   1038a:   4718        bx  r3
   1038c:   4770        bx  lr
   1038e:   bf00        nop

00010390 <register_tm_clones>:
   10390:   f241 0028   movw    r0, #4136   ; 0x1028
   10394:   f2c0 0002   movt    r0, #2
   10398:   f241 0128   movw    r1, #4136   ; 0x1028
   1039c:   f2c0 0102   movt    r1, #2
   103a0:   1a0b        subs    r3, r1, r0
   103a2:   0fd9        lsrs    r1, r3, #31
   103a4:   eb01 01a3   add.w   r1, r1, r3, asr #2
   103a8:   1049        asrs    r1, r1, #1
   103aa:   d005        beq.n   103b8 <register_tm_clones+0x28>
   103ac:   f240 0300   movw    r3, #0
   103b0:   f2c0 0300   movt    r3, #0
   103b4:   b103        cbz r3, 103b8 <register_tm_clones+0x28>
   103b6:   4718        bx  r3
   103b8:   4770        bx  lr
   103ba:   bf00        nop

000103bc <__do_global_dtors_aux>:
   103bc:   b510        push    {r4, lr}
   103be:   f241 0428   movw    r4, #4136   ; 0x1028
   103c2:   f2c0 0402   movt    r4, #2
   103c6:   7823        ldrb    r3, [r4, #0]
   103c8:   b91b        cbnz    r3, 103d2 <__do_global_dtors_aux+0x16>
   103ca:   f7ff ffcf   bl  1036c <deregister_tm_clones>
   103ce:   2301        movs    r3, #1
   103d0:   7023        strb    r3, [r4, #0]
   103d2:   bd10        pop {r4, pc}

000103d4 <frame_dummy>:
   103d4:   e7dc        b.n 10390 <register_tm_clones>
   103d6:   bf00        nop

000103d8 <main>:
   103d8:   b580        push    {r7, lr}
   103da:   af00        add r7, sp, #0
   103dc:   f240 40d0   movw    r0, #1232   ; 0x4d0
   103e0:   f2c0 0001   movt    r0, #1
   103e4:   f7ff ef80   blx 102e8 <puts@plt>
   103e8:   2300        movs    r3, #0
   103ea:   4618        mov r0, r3
   103ec:   bd80        pop {r7, pc}
    ...

000103f0 <__libc_csu_init>:
   103f0:   e92d 43f8   stmdb   sp!, {r3, r4, r5, r6, r7, r8, r9, lr}
   103f4:   4607        mov r7, r0
   103f6:   4e0c        ldr r6, [pc, #48]   ; (10428 <__libc_csu_init+0x38>)
   103f8:   4d0c        ldr r5, [pc, #48]   ; (1042c <__libc_csu_init+0x3c>)
   103fa:   4688        mov r8, r1
   103fc:   447e        add r6, pc
   103fe:   4691        mov r9, r2
   10400:   447d        add r5, pc
   10402:   f7ff ef62   blx 102c8 <_init>
   10406:   1b76        subs    r6, r6, r5
   10408:   10b6        asrs    r6, r6, #2
   1040a:   d00a        beq.n   10422 <__libc_csu_init+0x32>
   1040c:   3d04        subs    r5, #4
   1040e:   2400        movs    r4, #0
   10410:   f855 3f04   ldr.w   r3, [r5, #4]!
   10414:   464a        mov r2, r9
   10416:   4641        mov r1, r8
   10418:   4638        mov r0, r7
   1041a:   3401        adds    r4, #1
   1041c:   4798        blx r3
   1041e:   42a6        cmp r6, r4
   10420:   d1f6        bne.n   10410 <__libc_csu_init+0x20>
   10422:   e8bd 83f8   ldmia.w sp!, {r3, r4, r5, r6, r7, r8, r9, pc}
   10426:   bf00        nop
   10428:   00010b0c    .word   0x00010b0c
   1042c:   00010b04    .word   0x00010b04

00010430 <__libc_csu_fini>:
   10430:   4770        bx  lr
   10432:   bf00        nop

Disassembly of section .fini:

00010434 <_fini>:
   10434:   e92d4008    push    {r3, lr}
   10438:   e8bd8008    pop {r3, pc}

【问题讨论】:

  • ldd hw 在不工作的机器上显示什么?有一个微不足道的程序段错误通常表明共享库丢失或不匹配。

标签: gcc raspberry-pi cross-compiling


【解决方案1】:

为了来世

另一个论坛的好人发现我的硬件不是我想的那样。 我只是从架子上拿了一个 Pi,没有密切注意版本。

不幸的是,它是 Pi 1B+

真丢脸。

【讨论】:

    猜你喜欢
    • 2021-02-23
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 2022-11-12
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    相关资源
    最近更新 更多