ALIGN in Linker Scripts

∥☆過路亽.° 提交于 2019-12-20 18:07:22

问题


What does the ALIGN keyword do in linker scripts? I read many tutorials about linker scripts but I cant understand what really ALIGN do. Can any one explain it simply. Thanks!


回答1:


A typical usage is

. = ALIGN(8);

This means: insert padding bytes until current location becomes aligned on 8-byte boundary. That is:

while ((current_location & 7) != 0)
  *current_location++ = padding_value;



回答2:


The ALIGN() instructions tell the linker that section(bss, text) shoul be this much aligned.

For a typical idea, you can take a look here

e.g.

    //.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



回答3:


. = ALIGN(8)

Corresponds to the following (working link script example using operators):

data = .;

. = ((data + 0x8 - 1) & ~(0x8 - 1)) - data;


来源:https://stackoverflow.com/questions/8458084/align-in-linker-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!