免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 792 | 回复: 0
打印 上一主题 下一主题

.align 5之类的知识 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:41 |只看该作者 |倒序浏览
经常会看到arm-linux汇编中有如下的指令:

.align n

它的含义就是使得下面的代码按一定规则对齐

.align n 指令的对齐值有两种方案:n  2^n 

各种平台最初的汇编器一般都不是gas,采取方案12的都很多,gas的目标是取代原来的汇编器,必然要保持和原来汇编器的兼容,因此在gas中如何解释.align指令会显得有些混乱,原因在于保持兼容。

  arm-linux是按照2^n的方案对齐的,需要说明的是这个对齐和ld-script里的对齐不同,不是一会事。下面的英文就不同平台的对齐进行了说明:

  版本2.11.92.0.12gasinfo(Mandrake 8.2上的)这样说:

  The way the required alignment is specified varies from system to system. For the a29k, hppa, m68k, m88k, w65, sparc, and Hitachi SH, and i386 using ELF format, the first expression is the alignment request in bytes. For example `.align 8' advances the location counter until it is a multiple of 8. If the location counter is already a multiple of 8, no change is needed.

  For other systems, including the i386 using a.out format, and the arm and strongarm, it is the number of low-order zero bits the location counter must have after advancement. For example `.align 3' advances the location counter until it a multiple of 8. If the location counter is already a multiple of 8, no change is needed.

  从这段文字来看,ARM.align 5就是25次方对齐,也就是4字节对齐,通过反汇编也可以看出对齐方式:

  .align 5

  stmfd sp!, {r0 - r3, lr}

  mov r0, ip

  ldmfd sp!, {r0 - r3, pc}^

  .align 5

  stmfd sp!, {r0 - r3, lr}

  mov r0, ip

  mov ip, r0

  ldmfd sp!, {r0 - r3, pc}^

  反汇编:

  00000000 <.text>:

  0: e92d400f stmdb sp!, {r0, r1, r2, r3, lr}

  4: e1a0000c mov r0, ip

  8: e8fd800f ldmia sp!, {r0, r1, r2, r3, pc}^

  ...

  20: e92d400f stmdb sp!, {r0, r1, r2, r3, lr}

  24: e1a0000c mov r0, ip

  28: e1a0c000 mov ip, r0

  2c: e8fd800f ldmia sp!, {r0, r1, r2, r3, pc}^

  30: e1a00000 nop (mov r0,r0)

  34: e1a00000 nop (mov r0,r0)

  38: e1a00000 nop (mov r0,r0)

  3c: e1a00000 nop (mov r0,r0)

  一些忠告:

  In the future, everytime when you build an elf file, you need meantime created your map file. And then you will avoid mistakes like this align.

  Also, please also pick up some linker script knowlege part. For embedded system, we frequently play the linker script to tune an image, for example, align some special section and so on for protection or/and cache purpose. wish helpful

   

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

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP