How to change alignment of code segment in ELF

风流意气都作罢 提交于 2019-11-30 22:30:29

I don't know if you really want to do that but you can change the max page size with ld -z max-page-size=4096:

$ gcc foo.c && readelf -Wl ./a.out | grep LOAD 
LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x0008c4 0x0008c4 R E 0x200000
LOAD 0x0008c8 0x00000000006008c8 0x00000000006008c8 0x000250 0x000260 RW  0x200000
$ gcc foo.c -Wl,-z,max-page-size=4096 && readelf -Wl ./a.out | grep LOAD 
LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x0008c4 0x0008c4 R E 0x1000
LOAD 0x0008c8 0x00000000004018c8 0x00000000004018c8 0x000250 0x000260 RW  0x1000

Apparently, the reason is that the linker tries to align the segments to the maximum page size available on you architecture (on you CPU?). The standard default page size is 4KiB on x86 but greater pages exist (such as 2MiB pages).

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