How to change code segment alignment in ELF

In the ELF binary, how to change the alignment of loadable segments? In the example below (see Right corner), I want to reduce 0x200000 to 0x40960.

  LOAD  0x000000 0x000000400000 0x0000000000400000 0x000704 0x000704 R E **0x200000**
  LOAD  0x000e10 0x000000600e10 0x0000000000600e10 0x000230 0x000238 RW  **0x200000**

Can any compiler expert (GCC or clang) provide me a solution for this?

+3
source share
1 answer

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

$ gcc foo.c && readelf -Wl ./a.out | grep LOAD
LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x0008c4 0x0008c4 RE 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

, , , ( ?). 4 x86, (, 2 ).

+5

Source: https://habr.com/ru/post/1672054/


All Articles