summaryrefslogtreecommitdiff
path: root/Userland/DynamicLoader/CMakeLists.txt
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2022-05-07 18:11:00 +0200
committerAndreas Kling <kling@serenityos.org>2022-05-12 13:12:37 +0200
commitfd3e3d5e28f729c05427d1c3cfe95e1ae3f62e39 (patch)
treee441266ce2c96a9e10e81e7abe61050e58699ddc /Userland/DynamicLoader/CMakeLists.txt
parentf157ad8a35d0661804041b2b18c3bc365752a800 (diff)
downloadserenity-fd3e3d5e28f729c05427d1c3cfe95e1ae3f62e39.zip
LibC+Kernel: Prevent string functions from calling themselves
Most of the string.h and wchar.h functions are implemented quite naively at the moment, and GCC's pattern recognition pass might realize what we are trying to do, and transform them into libcalls. This is usually a useful optimization, but not when we're implementing the functions themselves :^) Relevant discussion from the GCC Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102725 This prevents the infamous recursive `strlen`. A more proper fix would be writing these functions in assembly. That would likely give a small performance boost as well ;)
Diffstat (limited to 'Userland/DynamicLoader/CMakeLists.txt')
-rw-r--r--Userland/DynamicLoader/CMakeLists.txt6
1 files changed, 6 insertions, 0 deletions
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")