Skip to content

Commit

Permalink
Klib linker scripts: use ELF segments with appropriate permissions
Browse files Browse the repository at this point in the history
This change amends the linker scripts for the klibs so that each
klib ELF file has 3 segments: a text segment with read and execute
permissions, a data segment with read-only permissions, and a data
segment with read/write permissions. This avoids mapping an entire
klib image with both write and execute permissions when the kernel
loads a klib.
In addition, the SECTIONS directive in the linker scripts has been
fixed so that all the read-only input sections are mapped to the
.text and .rodata output sections; this decreases the size of the
klib ELF files.
  • Loading branch information
francescolavra committed Mar 23, 2024
1 parent f01a617 commit c641f82
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/aarch64/klib.lds
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ OUTPUT_FORMAT("elf64-littleaarch64")

ENTRY(init)

PHDRS
{
text PT_LOAD FLAGS(5); /* R E */
rodata PT_LOAD FLAGS(4); /* R */
data PT_LOAD FLAGS(6); /* RW */
}

SECTIONS
{
. = SIZEOF_HEADERS;
.text : { *(.text)}
.rodata : { *(.rodata)}
.text : { *(.text) *(.text.*) } :text
. = ALIGN(4096);
.rodata : { *(.rodata) *(.rodata.*) } :rodata

.data ALIGN(4096) : { *(.data) *(.data.*) }
.bss ALIGN(32): { *(.bss) *(.bss.*) }
. = ALIGN(4096);
.data : { *(.data) *(.data.*) } :data
.bss : { *(.bss) *(.bss.*) } :data

/DISCARD/ : { *(.interp) }
}
17 changes: 13 additions & 4 deletions src/riscv64/klib.lds
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ OUTPUT_FORMAT("elf64-littleriscv")

ENTRY(init)

PHDRS
{
text PT_LOAD FLAGS(5); /* R E */
rodata PT_LOAD FLAGS(4); /* R */
data PT_LOAD FLAGS(6); /* RW */
}

SECTIONS
{
. = SIZEOF_HEADERS;
.text : { *(.text)}
.rodata : { *(.rodata)}
.text : { *(.text) *(.text.*) } :text
. = ALIGN(4096);
.rodata : { *(.rodata) *(.rodata.*) } :rodata

.data ALIGN(4096) : { *(.data) *(.data.*) }
.bss ALIGN(32): { *(.bss) *(.bss.*) }
. = ALIGN(4096);
.data : { *(.data) *(.data.*) } :data
.bss : { *(.bss) *(.bss.*) } :data

/DISCARD/ : { *(.interp) }
}
17 changes: 13 additions & 4 deletions src/x86_64/klib.lds
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ OUTPUT_FORMAT("elf64-x86-64")

ENTRY(init)

PHDRS
{
text PT_LOAD FLAGS(5); /* R E */
rodata PT_LOAD FLAGS(4); /* R */
data PT_LOAD FLAGS(6); /* RW */
}

SECTIONS
{
. = SIZEOF_HEADERS;
.text : { *(.text)}
.rodata : { *(.rodata)}
.text : { *(.text) *(.text.*) } :text
. = ALIGN(4096);
.rodata : { *(.rodata) *(.rodata.*) } :rodata

.data ALIGN(4096) : { *(.data) *(.data.*) }
.bss ALIGN(32): { *(.bss) *(.bss.*) }
. = ALIGN(4096);
.data : { *(.data) *(.data.*) } :data
.bss : { *(.bss) *(.bss.*) } :data

/DISCARD/ : { *(.interp) }
}

0 comments on commit c641f82

Please sign in to comment.