19

ALIGN 关键字在链接描述文件中的作用是什么?我阅读了许多有关链接器脚本的教程,但我无法理解 ALIGN 的真正作用。谁能简单解释一下。谢谢!

4

3 回答 3

28

一个典型的用法是

. = ALIGN(8);

这意味着:插入填充字节,直到当前位置在 8 字节边界上对齐。那是:

while ((current_location & 7) != 0)
  *current_location++ = padding_value;
于 2011-12-11T04:20:45.893 回答
5

ALIGN() 指令告诉链接器 section(bss, text) 应该如此对齐。

一个典型的想法,可以看这里(4.6.3《输出部分说明》)

例如

    //.data is aligned by word size on the 32-bit architecture and direct it to the data section
For a 32-bit machine, it typically needs to be word aligned 

        .data : ALIGN(4) 
        {
           *(.data*)
        } > data_sdram
于 2018-09-14T09:43:50.983 回答
1

. =对齐(8)

对应于以下内容(使用运算符的工作链接脚本示例):

data = .;

. = ((data + 0x8 - 1) & ~(0x8 - 1)) - data;
于 2018-09-13T14:05:23.660 回答