问题
I am trying to implement custom loader and
want to locate two program headers(segment) for data and code with 0x1000 aligned.
I fixed some part of the default linker script and get weird results.
**Default linker script.**
. = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) &
(CONSTANT (MAXPAGESIZE) - 1));
. = DATA_SEGMENT_ALIGN (CONSTANT(MAXPAGESIZE),CONSTANT (COMMONPAGESIZE));
**Modified linker script**
. = ALIGN (0x1000);
. = DATA_SEGMENT_ALIGN(0x1000, 0x1000);
when I compiled the binary with default linker script, it is 0x200000 aligned
and have two program headers.
LOAD 0x0000000000000000 0x0000000050000000 0x0000000050000000
0x0000000000001058 0x0000000000001058 R E 200000
LOAD 0x0000000000001fe8 0x0000000050201fe8 0x0000000050201fe8
0x0000000000000028 0x00000000000000c0 RW 200000
but I get below result with modified linker script.
LOAD 0x0000000000000000 0x0000000050000000 0x0000000050000000
0x0000000000002010 0x00000000000020a8 RWE 200000
It seems that the data section and code section is mixed in one program header.
However, I want to make my program have two page aligned(0x1000) program headers
LOAD1 0x0000000050000000 ~ 0x0000000050002340 R E
LOAD2 0x0000000050003000 ~ 0x0000000050006790 RW
Please let me know some directions.
来源:https://stackoverflow.com/questions/36033006/how-can-i-get-two-page-aligned0x1000-and-separated-program-headers