You copied the Doc URL to your clipboard.
Aligning regions to page boundaries
You can produce an ELF file with each execution region starting at a page boundary.
The linker provides the following built-in functions to help create load and execution regions on page boundaries:
AlignExpr
, to specify an address expression.GetPageSize
, to obtain the page size for use inAlignExpr
. If you useGetPageSize
, you must also use the--paged
linker command-line option.SizeOfHeaders()
, to return the size of the ELF header and Program Header table.
Note
- Alignment on an execution region causes both the load address and execution address to be aligned.
- The default page size is
. To change the page size, specify the0x8000
--pagesize
linker command-line option.
To produce an ELF file with each execution region starting on a new page, and with code starting on the next page boundary after the header information:
LR1 0x0 + SizeOfHeaders() { ER_RO +0 { *(+RO) } ER_RW AlignExpr(+0, GetPageSize()) { *(+RW) } ER_ZI AlignExpr(+0, GetPageSize()) { *(+ZI) } }
If you set up your ELF file in this way, then you can memory-map it onto an operating system in such a way that:
- RO and RW data can be given different memory protections, because they are placed in separate pages.
- The load address everything expects to run at is related to its offset in the ELF file
by specifying
SizeOfHeaders()
for the first load region.