From c2c12e9dc5df09622b7900e358a7ce7de9a3cebe Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 11 Aug 2021 16:25:02 +0200 Subject: [PATCH] LibC+DynamicLoader: Prevent GCC from removing null checks GCC implements `fputc`, `fputs` and `fwrite` as builtin functions, whose `FILE*` argument is implicitly marked `__attribute__((nonnull))`. This causes our `VERIFY(stream)` statements to be removed. This does not happen with Clang, as they do not use the `nonnull` attribute in this way. --- Userland/DynamicLoader/CMakeLists.txt | 2 ++ Userland/Libraries/LibC/CMakeLists.txt | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Userland/DynamicLoader/CMakeLists.txt b/Userland/DynamicLoader/CMakeLists.txt index 95d2436d693..baa0829862c 100644 --- a/Userland/DynamicLoader/CMakeLists.txt +++ b/Userland/DynamicLoader/CMakeLists.txt @@ -31,6 +31,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -nodefaultlibs -nostdlib -pie set_source_files_properties (../Libraries/LibC/ssp.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") add_executable(Loader.so ${SOURCES}) diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index fc37efe40b2..9589f976715 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -115,6 +115,9 @@ if (NOT USE_CLANG_TOOLCHAIN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++") endif() +# Prevent GCC from removing null checks by marking the `FILE*` argument non-null +set_source_files_properties(stdio.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-fputc -fno-builtin-fputs -fno-builtin-fwrite") + add_library(LibCStaticWithoutDeps STATIC ${SOURCES}) target_link_libraries(LibCStaticWithoutDeps ssp) add_dependencies(LibCStaticWithoutDeps LibM LibSystem LibUBSanitizer)