c - 链接器警告,将 .stack 节的开头更改 4 个字节

标签 c gcc linker warnings

我使用arm-none-eabi gcc 工具链来编译Atmel SAM4S 微 Controller 的代码。该代码有效,但我在更改 .stack 节和 .bss 节的开头时遇到了一些链接器错误。

这是我收到的警告:

c:/程序文件(x86)/gnu工具arm嵌入/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe:警告:将 .bss 节的开头更改 4 个字节 c:/程序文件(x86)/gnu工具arm嵌入/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm- none-eabi/bin/ld.exe:警告:将 .stack 节的开头更改 4 个字节 c:/程序文件(x86)/gnu工具arm嵌入/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm- none-eabi/bin/ld.exe:警告:将 .bss 节的开头更改 4 个字节 c:/程序文件(x86)/gnu工具arm嵌入/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm- none-eabi/bin/ld.exe:警告:将 .stack 节的开头更改 4 个字节 c:/程序文件(x86)/gnu工具arm嵌入/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm- none-eabi/bin/ld.exe:警告:将 .bss 节的开头更改 4 个字节 c:/程序文件(x86)/gnu工具arm嵌入/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm- none-eabi/bin/ld.exe:警告:将 .stack 部分的开头更改 4 个字节

此后,编译成功完成,我可以将代码刷新到微 Controller ,效果很好。

我应该担心这些警告吗?

编辑: 这是我的链接器脚本。它是由 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 = . ;
}

最佳答案

添加:

. = ALIGN(8);

到链接描述文件中 .bss 之前的 .relocate 部分。

关于c - 链接器警告,将 .stack 节的开头更改 4 个字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35477100/

相关文章:

c - 为什么 -freciprocal-math 在 GCC 中不安全?

c - 将windows中的linux静态库与cygwin链接起来

c++ - 如何登录页面并从中读取url内容?

c - C中的字符串和字符连接

c - 包含多个整数的结构会出现运行时错误

c - 多维数组中元素的位置 [ C ]

c - 如何构建一个嵌入 Lua 的 C 程序?

c - 共享库中的符号查找

从 c 调用 fortran 77 进行 arpack

c - 静态库中外部符号的预期签名