LibC: Remove libssp_nonshared.a

__stack_chk_fail_local, which libssp_nonshared.a provides, is a relic of
i386 times and is not used on modern architectures.
This commit is contained in:
Dan Klishch 2024-04-26 22:12:19 -04:00 committed by Andrew Kaster
parent f60a02fc78
commit ce5813d6ab
6 changed files with 24 additions and 39 deletions

View file

@ -9,15 +9,6 @@ function(serenity_set_implicit_links target_name)
# slightly outdated stub in the sysroot, but have not yet installed the freshly
# built LibC.
target_link_libraries(${target_name} PRIVATE LibC)
# Same goes for -lssp_nonshared, which is required during build time but is not
# yet installed in the sysroot. However, we just want to add the link directory
# and a dependency here, since actually linking the library is decided on by
# passing one of the -fstack-protector options.
# -lssp is contained inside LibC, so that case is handled by the above and a linker
# script.
target_link_directories(${target_name} PRIVATE "$<TARGET_FILE_DIR:ssp_nonshared>")
add_dependencies(${target_name} ssp_nonshared)
endfunction()
function(serenity_install_headers target_name)

View file

@ -87,7 +87,7 @@ new file mode 100644
index 0000000000000000000000000000000000000000..10c6f16fbe13eab36bab8f6896f8e2a6ae48df02
--- /dev/null
+++ b/gcc/config/serenity.h
@@ -0,0 +1,48 @@
@@ -0,0 +1,50 @@
+/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_SERENITY
+#define TARGET_SERENITY 1
@ -110,6 +110,8 @@ index 0000000000000000000000000000000000000000..10c6f16fbe13eab36bab8f6896f8e2a6
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "%{shared|static-pie|!no-pie:crtendS.o%s; :crtend.o%s} crtn.o%s"
+
+#define TARGET_LIBC_PROVIDES_SSP
+
+#undef LINK_SPEC
+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!static: %{rdynamic:-export-dynamic} -dynamic-linker /usr/lib/Loader.so}"
+

View file

@ -39,7 +39,6 @@ if (("${SERENITY_ARCH}" STREQUAL "aarch64") OR ("${SERENITY_ARCH}" STREQUAL "ris
endif()
set_source_files_properties(../Libraries/LibC/ssp.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
set_source_files_properties(../Libraries/LibC/ssp_nonshared.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
# Prevent GCC from removing null checks by marking the `FILE*` argument non-null
set_source_files_properties(../Libraries/LibC/stdio.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-fputc -fno-builtin-fputs -fno-builtin-fwrite")

View file

@ -148,12 +148,6 @@ add_custom_command(
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crtn> ${CMAKE_INSTALL_PREFIX}/usr/lib/crtn.o
)
set_source_files_properties (ssp_nonshared.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
add_library(ssp_nonshared STATIC ssp_nonshared.cpp)
add_dependencies(ssp_nonshared install_libc_headers)
target_link_libraries(ssp_nonshared PRIVATE NoCoverage)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libssp_nonshared.a DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/lib/)
set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ASM_SOURCES})
# Prevent GCC from removing null checks by marking the `FILE*` argument non-null
@ -176,3 +170,24 @@ file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libpthread.so" "INPU
file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libdl.so" "INPUT(libc.so)")
file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libm.so" "INPUT(libc.so)")
file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libssp.so" "INPUT(libc.so)")
# ===== Compatibility with the GCC toolchain without TARGET_LIBC_PROVIDES_SSP =====
# FIXME: Remove this on the next GCC toolchain version bump
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_custom_target(create_compat_ssp_libraries)
add_dependencies(Loader.so create_compat_ssp_libraries)
add_custom_command(TARGET create_compat_ssp_libraries
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -E remove libssp.so
COMMAND "${CMAKE_AR}" cr libssp.a
WORKING_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
add_custom_command(TARGET create_compat_ssp_libraries
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -E remove libssp_nonshared.a
COMMAND "${CMAKE_AR}" cr libssp_nonshared.a
WORKING_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
endif()

View file

@ -1,20 +0,0 @@
/*
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/internals.h>
#if defined __SSP__ || defined __SSP_ALL__
# error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
#endif
extern "C" {
__attribute__((noreturn)) void __stack_chk_fail_local()
{
__stack_chk_fail();
}
} // extern "C"

View file

@ -1,11 +1,9 @@
set(SOURCES
UBSanitizer.cpp
../LibC/ssp.cpp
../LibC/ssp_nonshared.cpp
)
set_source_files_properties(../LibC/ssp.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
set_source_files_properties(../LibC/ssp_nonshared.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
serenity_libc(LibUBSanitizer ubsan)