From 5576e9c4c515b148c3a2e4472fce84b7d1b43716 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 19 Jan 2022 19:12:50 +0100 Subject: Kernel+Toolchain: Use `.init_array` section for global constructors Before this change, our dynamic linker's global constructor handler relied on the GNU linker implicitly including the content of `.ctors` section inside `.init_array`. The mold linker does not do this, so global constructors would fail to be called in the mold-built userland. There is no point in sticking to `.ctors`, as most other systems already use the superior `.init_array` scheme. This commit changes the kernel linker script to not discard this new section, and enables it by default in our toolchain. --- Kernel/linker.ld | 2 ++ Ports/gcc/package.sh | 2 +- Toolchain/BuildIt.sh | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/linker.ld b/Kernel/linker.ld index 17c57d0d88..1bed3df22f 100644 --- a/Kernel/linker.ld +++ b/Kernel/linker.ld @@ -59,10 +59,12 @@ SECTIONS { start_heap_ctors = .; *libkernel_heap.a:*(.ctors) + *libkernel_heap.a:*(.init_array) end_heap_ctors = .; start_ctors = .; *(.ctors) + *(.init_array) end_ctors = .; *(.rodata*) diff --git a/Ports/gcc/package.sh b/Ports/gcc/package.sh index 49c33ba648..39eedd4c09 100755 --- a/Ports/gcc/package.sh +++ b/Ports/gcc/package.sh @@ -2,7 +2,7 @@ port=gcc version=11.2.0 useconfigure=true -configopts=("--target=${SERENITY_ARCH}-pc-serenity" "--with-sysroot=/" "--with-build-sysroot=${SERENITY_INSTALL_ROOT}" "--with-newlib" "--enable-languages=c,c++" "--disable-lto" "--disable-nls" "--enable-shared" "--enable-default-pie" "--enable-host-shared" "--enable-threads=posix") +configopts=("--target=${SERENITY_ARCH}-pc-serenity" "--with-sysroot=/" "--with-build-sysroot=${SERENITY_INSTALL_ROOT}" "--with-newlib" "--enable-languages=c,c++" "--disable-lto" "--disable-nls" "--enable-shared" "--enable-default-pie" "--enable-host-shared" "--enable-threads=posix" "--enable-initfini-array") files="https://ftpmirror.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz gcc-${version}.tar.xz d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b" makeopts=("all-gcc" "all-target-libgcc" "all-target-libstdc++-v3" "-j$(nproc)") installopts=("DESTDIR=${SERENITY_INSTALL_ROOT}" "install-gcc" "install-target-libgcc" "install-target-libstdc++-v3") diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh index ad495016e7..9aad304327 100755 --- a/Toolchain/BuildIt.sh +++ b/Toolchain/BuildIt.sh @@ -379,6 +379,7 @@ pushd "$DIR/Build/$ARCH" --enable-default-pie \ --enable-lto \ --enable-threads=posix \ + --enable-initfini-array \ ${TRY_USE_LOCAL_TOOLCHAIN:+"--quiet"} || exit 1 echo "XXX build gcc and libgcc" -- cgit v1.2.3