diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2022-05-07 18:11:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-05-12 13:12:37 +0200 |
commit | fd3e3d5e28f729c05427d1c3cfe95e1ae3f62e39 (patch) | |
tree | e441266ce2c96a9e10e81e7abe61050e58699ddc /Userland/Libraries/LibC | |
parent | f157ad8a35d0661804041b2b18c3bc365752a800 (diff) | |
download | serenity-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/Libraries/LibC')
-rw-r--r-- | Userland/Libraries/LibC/CMakeLists.txt | 5 |
1 files changed, 5 insertions, 0 deletions
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) |