+ -
当前位置:首页 → 问答吧 → 关于 ld 连接对齐函数 ALIGN() 和 NEXT()

关于 ld 连接对齐函数 ALIGN() 和 NEXT()

时间:2006-07-18

来源:互联网

SECTIONS
{
. = 0x00000000;

. = ALIGN(4);
.text :
{
cpu/pxa/start.o (.text)
*(.text)
}

. = ALIGN(4);
.rodata : { *(.rodata) }

. = ALIGN(4);
.data : { *(.data) }

. = ALIGN(4);
.got : { *(.got) }

. = ALIGN(4);
.bss : { *(.bss) }
}

上面是典型的 linker script 的片段,对于 ALIGN( ) 函数在这里的意义,
请哪位概念清晰的大侠详细说明一下!

作者: robinswan   发布时间: 2006-07-18

估计应该是指定每个section按多少字节对齐

作者: kj501   发布时间: 2006-07-19

from `info ld`:

`ALIGN(EXP)'
Return the location counter (`.') aligned to the next EXP boundary.
`ALIGN' doesn't change the value of the location counter--it just
does arithmetic on it. Here is an example which aligns the output
`.data' section to the next `0x2000' byte boundary after the
preceding section and sets a variable within the section to the
next `0x8000' boundary after the input sections:
SECTIONS { ...
.data ALIGN(0x2000): {
*(.data)
variable = ALIGN(0x8000);
}
... }

The first use of `ALIGN' in this example specifies the location of
a section because it is used as the optional ADDRESS attribute of
a section definition (*note Output Section Address::). The second
use of `ALIGN' is used to defines the value of a symbol.

The builtin function `NEXT' is closely related to `ALIGN'.

作者: crquan   发布时间: 2006-07-24

热门下载

更多