From b2e223d2bcfe33de42cb7d7780b20957768ccc35 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Mon, 30 Jan 2023 15:16:11 +0100 Subject: [PATCH] DynamicLoader: Disable stack protector in some files for aarch64 build The code would access the __stack_chk_guard variable in main.cpp and LibELF/Relocation.cpp before the loader was able to relocate itself, so this commit disable the stack protector for the aarch64 build to make sure that no accesses to __stack_chk_guard are inserted. --- Userland/DynamicLoader/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/DynamicLoader/CMakeLists.txt b/Userland/DynamicLoader/CMakeLists.txt index 31d5af95d6..761dfbdc9e 100644 --- a/Userland/DynamicLoader/CMakeLists.txt +++ b/Userland/DynamicLoader/CMakeLists.txt @@ -30,6 +30,11 @@ set(SOURCES ${LOADER_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${LIBC_SOURCES1} ${LI set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -nostdlib -pie -fpic -DNO_TLS") +if ("${SERENITY_ARCH}" STREQUAL "aarch64") + # On aarch64 the stack protector would be accessed before the Loader can relocate itself. + set_source_files_properties(main.cpp ../Libraries/LibELF/Relocation.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector") +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