arm-eabi-gcc 4.7升级后的问题

本文探讨了从GCC4.6升级到GCC4.7时遇到的问题,包括因默认启用-munaligned-access选项导致的bootloader无法执行及特定指令解释错误。通过调整编译选项和明确符号引用解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

某一段arm assembly code,之前用 arm-eabi-gcc 4.6版本编译。执行没问题。

但是换成GCC 4.7后有两个问题。

问题一: 生成的BOOTLOADER无法执行;

问题二: 能执行后,某段指令产生ABORT错误。


问题一:

研究GCC 4.7 compiler 升级文档(http://gcc.gnu.org/gcc-4.7/changes.html) 发现, GCC 4.7缺省编译时, 设置为-munaligned-access

•On ARM, when compiling for ARMv6 (but not ARMv6-M), ARMv7-A, ARMv7-R, or ARMv7-M, 
the new option -munaligned-access is active by default, which for some sources generates
 code that accesses memory on unaligned addresses. This requires the kernel of those 
systems to enable such accesses (controlled by CP15 register c1, refer to ARM documentation).
 Alternatively, or for compatibility with kernels where unaligned accesses are not supported,
 all code has to be compiled with -mno-unaligned-access. Upstream Linux kernel releases have
 automatically and unconditionally supported unaligned accesses as emitted by GCC due to this
 option being active since version 2.6.28.

后来在makefile中强制指定-mno-unaligned-access, 问题一解决。

STD_CCFLAGS+=-mno-unaligned-access

问题二:

原因: arm mode call 的指令编译正常。下载到Trace32里面, memory view显示正常。

但是执行到特定指令时,该arm instruction被解释成为 两条 thumb 指令, 从而导致 abort 错误。

后来发现是从thumb mode 调用 arm call 时,不能正确找到对应的 function symbol. 需要显式声明.


GCC 4.7 升级文档中,可能对应如下说明

•Link-time optimization (LTO) improvements: ◦Improved scalability and reduced memory usage. Link time optimization of Firefox now requires 3GB of RAM on a 64-bit system, while over 8GB was needed previously. Linking time has been improved, too. The serial stage of linking Firefox has been sped up by about a factor of 10.
◦Reduced size of object files and temporary storage used during linking.
◦Streaming performance (both outbound and inbound) has been improved.
◦ld -r is now supported with LTO.
◦Several bug fixes, especially in symbol table handling and merging.


具体举例说明如下。

Here is ASM code (file test.S):
===========================
  .syntax unified
  .text
  .code 32

  .global test
  .func test
test:
   nop
   bx lr
.endfunc

Here is C code (file c.c):
============================
void test (void);
int test2 (void)
{
  test();
}

Script for compilation
============================


编译过程如下

Script for compilation
============================
arm-none-eabi-gcc -c -mcpu=cortex-r4 -mthumb-interwork -Wa,-gdwarf2 -x assembler-with-cpp test.S
arm-none-eabi-gcc -c -mcpu=cortex-r4 -mthumb -mthumb-interwork -Wa,-gdwarf2 c.c
arm-none-eabi-gcc -o test.elf -mcpu=cortex-r4 -mthumb -mthumb-interwork -g -nostartfiles test.o c.o
arm-none-eabi-objdump.exe -d test.elf > test.dump


生成的汇编代码如下

生成的汇编代码如下:

===========================
Disassembly of section .text:

00008000 <test>:
    8000: e320f000 nop {0}
    8004: e12fff1e bx lr

00008008 <test2>:
    8008: b580 push {r7, lr}
    800a: af00 add r7, sp, #0
    800c: f7ff fff8 bl 8000 <test> ; !!!!!!!!!!!! <- here must be BLX not BL
    8010: 4618 mov r0, r3
    8012: bd80 pop {r7, pc}

 

解决问题后的正确代码如下:

After changing your small test to: .syntax unified .text .code 32 .global test .type test, %function .func test test: nop bx lr .endfunc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值