#I don't understand what i need for static init

6 messages · Page 1 of 1 (latest)

shadow rock
#

I am trying to get static initialization to work but with little to no success
I've built my toolchain according to https://wiki.osdev.org/GCC_Cross-Compiler but i've swapped the target for x86_64-none-elf

I have the following cmake build file ```cmake
project (kernel CXX ASM)

add_executable(kernel
kmain.cpp
memory.hpp
)

target_compile_options(kernel PRIVATE "-ffreestanding"
"-Wall" "-Wextra" "-fno-exceptions" "-fno-rtti")

target_link_options(kernel PRIVATE "-ffreestanding" "-nostdlib" "-nostartfiles" "-nodefaultlibs" -T ${CMAKE_SOURCE_DIR}/toolchain/linker.ld)

target_include_directories(kernel PRIVATE ${limine_INCLUDE_DIR})
target_link_libraries(kernel)

install(TARGETS kernel DESTINATION ${ISO_SYSROOT}/boot)

calm ploverBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

shadow rock
#

the issue is i get the following linking error /opt/gcc-x86_64-elf/bin/x86_64-none-elf-g++ --sysroot=/opt/gcc-x86_64-elf -ffreestanding -nostdlib -nostartfiles -nodefaultlibs -T /home/iulian/dev/BadOS/toolchain/linker.ld CMakeFiles/kernel.dir/kmain.cpp.obj -o kernel CMakeFiles/kernel.dir/kmain.cpp.obj: in function `_Z41__static_initialization_and_destruction_0v': kmain.cpp:(.text+0xc0): relocation truncated to fit: R_X86_64_32 against `.bss' /opt/cross/x86_64-none-elf/bin/ld: kmain.cpp:(.text+0xca): undefined reference to `__dso_handle' kmain.cpp:(.text+0xcf): relocation truncated to fit: R_X86_64_32 against `.bss' kmain.cpp:(.text+0xd4): relocation truncated to fit: R_X86_64_32 against symbol `_ZN5helloD1Ev' defined in .text._ZN5helloD2Ev[_ZN5helloD5Ev] section in CMakeFiles/kernel.dir/kmain.cpp.obj /opt/cross/x86_64-none-elf/bin/ld: kmain.cpp:(.text+0xd9): undefined reference to `__cxa_atexit' /opt/cross/x86_64-none-elf/bin/ld: kernel: hidden symbol `__dso_handle' isn't defined /opt/cross/x86_64-none-elf/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status make[2]: *** [kernel/CMakeFiles/kernel.dir/build.make:100: kernel/kernel] Error 1 make[2]: Leaving directory '/home/iulian/dev/BadOS/build' make[1]: *** [CMakeFiles/Makefile2:174: kernel/CMakeFiles/kernel.dir/all] Error 2 make[1]: Leaving directory '/home/iulian/dev/BadOS/build' make: *** [Makefile:136: all] Error 2

#

passing both crtbegin and crtend manually with the _init and _fini function defined as ```c
attribute((used, section(".init")))
extern "C" void _init()
{

}

attribute((used, section(".fini")))
extern "C" void _fini()
{

}``` still fails

#

i have no idea what's wrong even the smalles of guidance would help