diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 3f5328b3e5..cae9bb2fd0 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -486,6 +486,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(TARGET_STRING "") + + # Prevent naively implemented string functions (like strlen) from being "optimized" into a call to themselves. + set_source_files_properties(MiniStdlib.cpp + PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns") + add_link_options(LINKER:-z,pack-relative-relocs) else() # Assume Clang add_compile_options(-Waddress-of-packed-member) diff --git a/Userland/DynamicLoader/CMakeLists.txt b/Userland/DynamicLoader/CMakeLists.txt index eaaf9b075e..55c86fc19e 100644 --- a/Userland/DynamicLoader/CMakeLists.txt +++ b/Userland/DynamicLoader/CMakeLists.txt @@ -36,6 +36,12 @@ set_source_files_properties (../Libraries/LibC/ssp.cpp PROPERTIES COMPILE_FLAGS # 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") +# Prevent naively implemented string functions (like strlen) from being "optimized" into a call to themselves. +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set_source_files_properties(../Libraries/LibC/string.cpp ../Libraries/LibC/wchar.cpp + PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns") +endif() + add_executable(Loader.so ${SOURCES}) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index 2842d32fe0..9485cc602d 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -142,6 +142,11 @@ set_source_files_properties(stdio.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-fpu # Add in the `posix_memalign` symbol to avoid breaking existing binaries. set_source_files_properties(stdlib.cpp PROPERTIES COMPILE_FLAGS "-DSERENITY_LIBC_SHOW_POSIX_MEMALIGN") +# Prevent naively implemented string functions (like strlen) from being "optimized" into a call to themselves. +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set_source_files_properties(string.cpp wchar.cpp PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns") +endif() + add_library(LibCStaticWithoutDeps STATIC ${SOURCES}) target_link_libraries(LibCStaticWithoutDeps PUBLIC ssp LibTimeZone PRIVATE NoCoverage) add_dependencies(LibCStaticWithoutDeps LibM LibSystem LibUBSanitizer)