From 50e4cad4a009fac4ac7d3249ece620e938c2bcd7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 15 Apr 2021 22:00:44 +0200 Subject: [PATCH] Toolchain+LibC: Don't link LibC against crt0 Instead GCC should be used to automatically link against crt0 and crt0_shared depending on the type of object file that is being built. Unfortunately this requires a rebuild of the toolchain as well as everything that has been built with the old GCC. --- Toolchain/Patches/gcc.patch | 2 +- Userland/Libraries/LibC/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Toolchain/Patches/gcc.patch b/Toolchain/Patches/gcc.patch index 0373d7a32a..ee93a5fdd4 100644 --- a/Toolchain/Patches/gcc.patch +++ b/Toolchain/Patches/gcc.patch @@ -115,7 +115,7 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h +/* Files that are linked before user code. + The %s tells GCC to look for these files in the library directory. */ +#undef STARTFILE_SPEC -+#define STARTFILE_SPEC "%{static:crt0.o%s} crti.o%s %{!static: %{!fbuilding-libgcc:crt0_shared.o%s}} %{shared|pie:crtbeginS.o%s; :crtbegin.o%s}" ++#define STARTFILE_SPEC "%{!shared:crt0.o%s} crti.o%s %{shared: %{!fbuilding-libgcc:crt0_shared.o%s}} %{shared|pie:crtbeginS.o%s; :crtbegin.o%s}" + +/* Files that are linked after user code. */ +#undef ENDFILE_SPEC diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index 56454f5609..982d578704 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -87,7 +87,7 @@ set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${ASM_SOURCES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++") add_library(LibCStaticWithoutDeps STATIC ${SOURCES}) -target_link_libraries(LibCStaticWithoutDeps crt0 ssp) +target_link_libraries(LibCStaticWithoutDeps ssp) add_dependencies(LibCStaticWithoutDeps LibM LibSystem) add_custom_target(LibCStatic @@ -109,7 +109,7 @@ set_property( set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++") serenity_libc(LibC c) -target_link_libraries(LibC crt0 ssp system) +target_link_libraries(LibC ssp system) # We mark LibCStatic as a dependency of LibC because this triggers the build of the LibCStatic target add_dependencies(LibC LibM LibSystem LibCStatic)