summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Gavrilov <alexey.gavrilov@mail.com>2025-12-20 15:56:06 +0700
committerAlexey Gavrilov <alexey.gavrilov@mail.com>2025-12-20 15:56:06 +0700
commita72c27d948ee8cf542f8d38c7026876af4875e6b (patch)
treee2128f239a6bef112c0022b74da53a7885d4f332
parenteb6a12e18d45879ec383921f0c7378120b71d159 (diff)
Linker script refactor
In general this update touching sections for initialization and destruction of global variables. DISCARD sections added (.fini and .comment) and particular sections (.ctors, .dtors, .init, .fini) moved into more common sections (.rodata and .text) accordingly. This decision allows to save a some RAM. Signed-off-by: Alexey Gavrilov <alexey.gavrilov@mail.com>
-rw-r--r--kernel/linker.ld28
1 files changed, 18 insertions, 10 deletions
diff --git a/kernel/linker.ld b/kernel/linker.ld
index 9a0561b..3c960fa 100644
--- a/kernel/linker.ld
+++ b/kernel/linker.ld
@@ -9,6 +9,12 @@ CHECKSUM = -(MAGIC + FLAGS);
SECTIONS
{
+ /DISCARD/ :
+ {
+ *(.fini)
+ *(.comment)
+ }
+
/* It's a raw solution. */
/* Automatic generation of filling .multiboot section needs. */
.multiboot ALIGN(START_ADDR, CONSTANT(MAXPAGESIZE)) : ALIGN(CONSTANT(MAXPAGESIZE))
@@ -22,13 +28,21 @@ SECTIONS
{
_text = .;
*(.text*)
+ *(.init)
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
_etext = .;
} > REGION_TEXT
- .rodata ALIGN(CONSTANT(MAXPAGESIZE)): ALIGN(CONSTANT(MAXPAGESIZE))
+ .rodata :
{
_rodata = .;
*(.rodata*)
+ HIDDEN(__CTOR_LIST__ = .);
+ *(.ctors)
+ HIDDEN(__CTOR_END__ = .);
+ HIDDEN(__DTOR_LIST__ = .);
+ *(.dtors)
+ HIDDEN(__DTOR_END__ = .);
_erodata = .;
} > REGION_RODATA
@@ -51,14 +65,14 @@ SECTIONS
{
_stack = ABSOLUTE(.);
. += 4 * CONSTANT(MAXPAGESIZE);
- _estack = ABSOLUTE(.);
+ _estack = ABSOLUTE(.) - 1;
} > REGION_DATA
.kheap ALIGN(CONSTANT(MAXPAGESIZE)) : ALIGN(CONSTANT(MAXPAGESIZE))
{
- _startKheap = ABSOLUTE(.);
+ _kheap = ABSOLUTE(.);
. += CONSTANT(MAXPAGESIZE);
- _endKheap = ABSOLUTE(.);
+ _ekheap = ABSOLUTE(.) - 1;
} > REGION_DATA
.eh_frame :
@@ -68,10 +82,4 @@ SECTIONS
_e_eh_frame = .;
} > REGION_COMMON
- .ctors :
- {
- SORT_BY_NAME(CONSTRUCTORS)
- } > REGION_COMMON
-
-
}