LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2047|回复: 2

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

[复制链接]
发表于 2006-7-18 17:32:53 | 显示全部楼层 |阅读模式
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( ) 函数在这里的意义,
请哪位概念清晰的大侠详细说明一下!
发表于 2006-7-19 11:29:18 | 显示全部楼层
估计应该是指定每个section按多少字节对齐
回复 支持 反对

使用道具 举报

发表于 2006-7-23 22:03:35 | 显示全部楼层
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'.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表