问题描述
为什么在链接描述文件的每个输出节的开头和结尾使用ALIGN(4)语句? 是否在每个部分之间创建某种间距?
SECTIONS
{
/* The startup code goes first into internal flash */
.interrupts :
{
__VECTOR_TABLE = .;
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
.flash_config :
{
. = ALIGN(4);
KEEP(*(.FlashConfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(4);
} > m_flash_config
/* The program code and other data goes into internal flash */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants,strings,etc.) */
*(.rodata*) /* .rodata* sections (constants,etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
} > m_text
解决方法
免责声明:我不是编译器或链接程序开发人员,这只是我的印象和经验。
完成对齐后,对32位处理器的内存访问要快得多,其中某些处理器甚至无法访问未对齐的宽字。 ARM不是那种AFAIK。
但是,编译器会在布局其代码和数据时假定各节正确对齐,最后将它们链接起来。因此,链接描述文件必须满足该假定。