【问题标题】:linker warning, changing start of section .stack by 4 bytes链接器警告,将 .stack 节的开头更改 4 个字节
【发布时间】:2016-05-30 08:40:18
【问题描述】:

我使用 arm-none-eabi gcc 工具链为 Atmel SAM4S 微控制器编译代码。该代码有效,但我收到一些关于更改节 .stack 和节 .bss 的开始的链接器错误。

这是我收到的警告:

c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .stack by 4 bytes c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .stack by 4 bytes c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .stack by 4 bytes

在此之后,编译成功完成,我可以将代码刷写到微控制器中,效果很好。

我应该担心这些警告吗?

编辑: 这是我的链接器脚本。它由 Atmel 提供,也就是说,我并不完全了解所有内容。我试图阅读 ALIGN 命令,但我仍然不太确定它在此脚本中的作用。

在我的 Makefile 中,我有 LD 标志 --warn-section-align -Wl。如果我删除它,我不会收到警告。如果提供链接描述文件,这是否安全?

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)

/* Memory Spaces Definitions */
MEMORY
{
rom (rx)  : ORIGIN = 0x00400000, LENGTH = 0x00080000 /* flash, 512K */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 /* sram, 128K */
}

/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = 0x3000;

/* Section Definitions */
SECTIONS
{
.text :
{
    . = ALIGN(4);
    _sfixed = .;
    KEEP(*(.vectors .vectors.*))
    *(.text .text.* .gnu.linkonce.t.*)
    *(.glue_7t) *(.glue_7)
    *(.rodata .rodata* .gnu.linkonce.r.*)
    *(.ARM.extab* .gnu.linkonce.armextab.*)

    /* Support C constructors, and C destructors in both user code
       and the C library. This also provides support for C++ code. */
    . = ALIGN(4);
    KEEP(*(.init))
    . = ALIGN(4);
    __preinit_array_start = .;
    KEEP (*(.preinit_array))
    __preinit_array_end = .;

    . = ALIGN(4);
    __init_array_start = .;
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array))
    __init_array_end = .;

    . = ALIGN(0x4);
    KEEP (*crtbegin.o(.ctors))
    KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*crtend.o(.ctors))

    . = ALIGN(4);
    KEEP(*(.fini))

    . = ALIGN(4);
    __fini_array_start = .;
    KEEP (*(.fini_array))
    KEEP (*(SORT(.fini_array.*)))
    __fini_array_end = .;

    KEEP (*crtbegin.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*crtend.o(.dtors))

    . = ALIGN(4);
    _efixed = .;            /* End of text section */
} > rom

/* .ARM.exidx is sorted, so has to go in its own output section.  */
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
  *(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > rom
PROVIDE_HIDDEN (__exidx_end = .);

. = ALIGN(4);
_etext = .;

.relocate : AT (_etext)
{
    . = ALIGN(4);
    _srelocate = .;
    *(.ramfunc .ramfunc.*);
    *(.data .data.*);
    . = ALIGN(4);
    _erelocate = .;
} > ram

/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
    . = ALIGN(4);
    _sbss = . ;
    _szero = .;
    *(.bss .bss.*)
    *(COMMON)
    . = ALIGN(4);
    _ebss = . ;
    _ezero = .;
} > ram

/* stack section */
.stack (NOLOAD):
{
    . = ALIGN(8);
     _sstack = .;
    . = . + STACK_SIZE;
    . = ALIGN(8);
    _estack = .;
} > ram

. = ALIGN(4);
_end = . ;
}

【问题讨论】:

  • 链接描述文件有问题。也许对齐。
  • 我该如何进一步调查?
  • 检查链接器脚本以查看节的位置,并检查链接器映射文件以查看它们的实际位置。
  • 所有警告都在说(这是由于一个参数)是必须在部分之间创建一些间隙,因为前一个部分没有与新部分完全在同一边界上结束正在启动。建议去掉那个参数

标签: c gcc linker warnings


【解决方案1】:

添加:

. = ALIGN(8);

到链接器脚本中.bss 之前的.relocate 部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    相关资源
    最近更新 更多