首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

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

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

本帖最后由 look_w 于 2017-10-24 21:14 编辑

某一段arm assembly code,之前用 arm-eabi-gcc 4.6版本编译。执行没问题。
但是换成GCC 4.7后有两个问题。
问题一: 生成的BOOTLOADER无法执行;
问题二: 能执行后,某段指令产生ABORT错误。

问题一:
研究GCC 4.7 compiler 升级文 发现, 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 升级文档中,可能对应如下说明




  • <pre code_snippet_id="157946" snippet_file_name="blog_20140115_3_8233781"
    class="java" name="code">•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.</pre><p></p>
  • <pre></pre>
  • <p></p>
  • <p></p>
  • <p>具体举例说明如下。</p>
  • <pre code_snippet_id="157946" snippet_file_name="blog_20140328_4_9178606"
    class="cpp" name="code">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
  • ============================
  • </pre>
  • <p><br>
  • 编译过程如下</p>
  • <pre code_snippet_id="157946" snippet_file_name="blog_20140328_5_4750741"
    class="cpp" name="code">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
  • </pre>
  • <p><br>
  • 生成的汇编代码如下</p>
  • <p>生成的汇编代码如下:</p>
  • <pre code_snippet_id="157946" snippet_file_name="blog_20140328_6_879284"
    class="cpp" name="code">===========================
  • 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}</pre>
  • <p> </p>
  • <p>解决问题后的正确代码如下:</p>
  • <pre code_snippet_id="157946" snippet_file_name="blog_20140115_3_617203"
    class="cpp" name="code"><p>After changing your small test to:
  •   .syntax unified
  •   .text
  •   .code 32
  •   .global test
  •   .type test, %function
  •   .func test
  • test:
  •    nop
  •    bx lr
  • .endfunc</p></pre>
  • <link rel="stylesheet" href="http://static.blog.csdn.net/public/res-min/markdown_views.css?v=2.0">
返回列表