From 4937352761525de4b034e5f0152261ff5e7552f3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 1 Mar 2024 14:14:28 +0000 Subject: [PATCH] makefile: add asan --- Makefile | 21 +++++++++++++++++++++ scripts/hyprlandStaticAsan.diff | 21 +++++++++++++++++++++ scripts/waylandStatic.diff | 23 +++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 scripts/hyprlandStaticAsan.diff create mode 100644 scripts/waylandStatic.diff diff --git a/Makefile b/Makefile index 9c5e94d5..c893a16a 100644 --- a/Makefile +++ b/Makefile @@ -106,3 +106,24 @@ man: --variable=section:1 \ --from rst \ --to man > ./docs/hyprctl.1 + +asan: + @echo -en "!!WARNING!!\nOnly run this in the TTY.\n" + @pidof Hyprland > /dev/null && echo -ne "Refusing to run with Hyprland running.\n" || echo "" + @pidof Hyprland > /dev/null && exit 1 || echo "" + + rm -rf ./wayland + git reset --hard + + git clone --recursive https://gitlab.freedesktop.org/wayland/wayland + cd wayland && patch -p1 < ../scripts/waylandStatic.diff && meson setup build --buildtype=debug -Db_sanitize=address -Ddocumentation=false && ninja -C build && cd .. + cp ./wayland/build/src/libwayland-server.a . + @echo "Wayland done" + + patch -p1 < ./scripts/hyprlandStaticAsan.diff + cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DWITH_ASAN:STRING=True -DUSE_TRACY:STRING=False -DUSE_TRACY_GPU:STRING=False -S . -B ./build -G Ninja + cmake --build ./build --config Debug --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + @echo "Hyprland done" + + ASAN_OPTIONS="detect_odr_violation=0,log_path=asan.log" HYPRLAND_NO_CRASHREPORTER=1 ./build/Hyprland + diff --git a/scripts/hyprlandStaticAsan.diff b/scripts/hyprlandStaticAsan.diff new file mode 100644 index 00000000..5499f793 --- /dev/null +++ b/scripts/hyprlandStaticAsan.diff @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 857e21de..122d6a78 100755 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -101,7 +101,7 @@ message(STATUS "Checking deps...") + find_package(Threads REQUIRED) + find_package(PkgConfig REQUIRED) + find_package(OpenGL REQUIRED) +-pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2) # we do not check for wlroots, as we provide it ourselves ++pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2 libffi) # we do not check for wlroots, as we provide it ourselves + + file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") + +@@ -121,6 +121,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) + message(STATUS "Enabling ASan") + + target_link_libraries(Hyprland asan) ++ target_link_libraries(Hyprland ${CMAKE_SOURCE_DIR}/libwayland-server.a) + target_compile_options(Hyprland PUBLIC -fsanitize=address) + endif() + \ No newline at end of file diff --git a/scripts/waylandStatic.diff b/scripts/waylandStatic.diff new file mode 100644 index 00000000..04aeda23 --- /dev/null +++ b/scripts/waylandStatic.diff @@ -0,0 +1,23 @@ +diff --git a/src/meson.build b/src/meson.build +index 5d04334..6645eec 100644 +--- a/src/meson.build ++++ b/src/meson.build +@@ -170,7 +170,7 @@ if get_option('libraries') + error('We probably need to bump the SONAME of libwayland-server and -client') + endif + +- wayland_server = library( ++ wayland_server = static_library( + 'wayland-server', + sources: [ + wayland_server_protocol_core_h, +@@ -180,9 +180,6 @@ if get_option('libraries') + 'wayland-shm.c', + 'event-loop.c' + ], +- # To avoid an unnecessary SONAME bump, wayland 1.x.y produces +- # libwayland-server.so.0.x.y. +- version: '.'.join(['0', wayland_version[1], wayland_version[2]]), + dependencies: [ + epoll_dep, + ffi_dep,