From ddf1babfe19150c1e9a697e2e3fe82a56a009a3a Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 31 Aug 2024 02:23:08 +0300 Subject: [PATCH] Kernel: Cleanup constructor calls --- kernel/arch/i686/boot.S | 7 +++---- kernel/arch/i686/crti.S | 8 -------- kernel/arch/i686/crtn.S | 8 -------- kernel/arch/i686/linker.ld | 6 ++++++ kernel/arch/x86_64/boot.S | 7 +++---- kernel/arch/x86_64/crti.S | 8 -------- kernel/arch/x86_64/crtn.S | 8 -------- kernel/arch/x86_64/linker.ld | 6 ++++++ 8 files changed, 18 insertions(+), 40 deletions(-) diff --git a/kernel/arch/i686/boot.S b/kernel/arch/i686/boot.S index 8b1a4733..0c9c6c6a 100644 --- a/kernel/arch/i686/boot.S +++ b/kernel/arch/i686/boot.S @@ -216,12 +216,11 @@ higher_half: # call global constuctors call _init - movl $__init_array_start, %ebx + movl $g_init_array_start, %ebx jmp 2f - 1: movl (%ebx), %eax - call *%eax + 1: call *(%ebx) addl $4, %ebx - 2: cmpl $__init_array_end, %ebx + 2: cmpl $g_init_array_end, %ebx jne 1b # call to the kernel itself (clear ebp for stacktrace) diff --git a/kernel/arch/i686/crti.S b/kernel/arch/i686/crti.S index 96130d42..64945d13 100644 --- a/kernel/arch/i686/crti.S +++ b/kernel/arch/i686/crti.S @@ -14,11 +14,3 @@ _fini: pushl %ebp movl %esp, %ebp /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ - -.section .init_array -.global __init_array_start -__init_array_start: - -.section .fini_array -.global __fini_array_start -__fini_array_start: diff --git a/kernel/arch/i686/crtn.S b/kernel/arch/i686/crtn.S index 106f4c1c..9adcd820 100644 --- a/kernel/arch/i686/crtn.S +++ b/kernel/arch/i686/crtn.S @@ -8,11 +8,3 @@ /* gcc will nicely put the contents of crtend.o's .fini section here. */ popl %ebp ret - -.section .init_array -.global __init_array_end -__init_array_end: - -.section .fini_array -.global __fini_array_end -__fini_array_end: diff --git a/kernel/arch/i686/linker.ld b/kernel/arch/i686/linker.ld index 09869cbe..3a4b22bd 100644 --- a/kernel/arch/i686/linker.ld +++ b/kernel/arch/i686/linker.ld @@ -30,6 +30,12 @@ SECTIONS { *(.rodata.*) } + .init_array ALIGN(4K) : AT(ADDR(.init_array) - KERNEL_OFFSET) + { + g_init_array_start = .; + *(.init_array) + g_init_array_end = .; + } .data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET) { g_kernel_writable_start = .; diff --git a/kernel/arch/x86_64/boot.S b/kernel/arch/x86_64/boot.S index 25d9950d..bd897427 100644 --- a/kernel/arch/x86_64/boot.S +++ b/kernel/arch/x86_64/boot.S @@ -216,12 +216,11 @@ higher_half: # call global constuctors call _init - movq $__init_array_start, %rbx + movq $g_init_array_start, %rbx jmp 2f - 1: movq (%rbx), %rax - call *%rax + 1: call *(%rbx) addq $8, %rbx - 2: cmpq $__init_array_end, %rbx + 2: cmpq $g_init_array_end, %rbx jne 1b # call to the kernel itself (clear rbp for stacktrace) diff --git a/kernel/arch/x86_64/crti.S b/kernel/arch/x86_64/crti.S index 91808154..7c9624cc 100644 --- a/kernel/arch/x86_64/crti.S +++ b/kernel/arch/x86_64/crti.S @@ -14,11 +14,3 @@ _fini: pushq %rbp movq %rsp, %rbp /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ - -.section .init_array -.global __init_array_start -__init_array_start: - -.section .fini_array -.global __fini_array_start -__fini_array_start: diff --git a/kernel/arch/x86_64/crtn.S b/kernel/arch/x86_64/crtn.S index 8f3bdab2..5d6f1e9a 100644 --- a/kernel/arch/x86_64/crtn.S +++ b/kernel/arch/x86_64/crtn.S @@ -8,11 +8,3 @@ /* gcc will nicely put the contents of crtend.o's .fini section here. */ popq %rbp ret - -.section .init_array -.global __init_array_end -__init_array_end: - -.section .fini_array -.global __fini_array_end -__fini_array_end: diff --git a/kernel/arch/x86_64/linker.ld b/kernel/arch/x86_64/linker.ld index 954a9200..650e5a0c 100644 --- a/kernel/arch/x86_64/linker.ld +++ b/kernel/arch/x86_64/linker.ld @@ -30,6 +30,12 @@ SECTIONS { *(.rodata.*) } + .init_array ALIGN(4K) : AT(ADDR(.init_array) - KERNEL_OFFSET) + { + g_init_array_start = .; + *(.init_array) + g_init_array_end = .; + } .data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET) { g_kernel_writable_start = .;