From a72c27d948ee8cf542f8d38c7026876af4875e6b Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Sat, 20 Dec 2025 15:56:06 +0700 Subject: 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 --- kernel/linker.ld | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'kernel/linker.ld') 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 - - } -- cgit v1.2.3