From d5237e224eee40dc5dd323f3f1d751c40368cb01 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 1 Nov 2021 04:08:01 +0400 Subject: [PATCH] Make -Wl,-z,now work on older systems --- CMakeLists.txt | 3 ++ external/qt/CMakeLists.txt | 2 + external/qt/qt6/CMakeLists.txt | 2 + linux_xcb_helper/CMakeLists.txt | 19 ++++++++++ linux_xcb_helper/linux_xcb_helper.cpp | 53 +++++++++++++++++++++++++++ options_linux.cmake | 1 + 6 files changed, 80 insertions(+) create mode 100644 linux_xcb_helper/CMakeLists.txt create mode 100644 linux_xcb_helper/linux_xcb_helper.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b0f6b..0b7cd88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ # https://github.com/desktop-app/legal/blob/master/LEGAL add_subdirectory(external) +if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED) + add_subdirectory(linux_xcb_helper) +endif() if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 0633ebb..96dba52 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -290,6 +290,8 @@ else() endif() target_link_libraries(external_qt INTERFACE + desktop-app::linux_xcb_helper + $ desktop-app::linux_gtk_helper $ desktop-app::linux_glib_helper diff --git a/external/qt/qt6/CMakeLists.txt b/external/qt/qt6/CMakeLists.txt index b1a2910..8e55268 100644 --- a/external/qt/qt6/CMakeLists.txt +++ b/external/qt/qt6/CMakeLists.txt @@ -264,6 +264,8 @@ else() endif() target_link_libraries(external_qt INTERFACE + desktop-app::linux_xcb_helper + $ desktop-app::linux_gtk_helper $ desktop-app::linux_glib_helper diff --git a/linux_xcb_helper/CMakeLists.txt b/linux_xcb_helper/CMakeLists.txt new file mode 100644 index 0000000..f1f46c2 --- /dev/null +++ b/linux_xcb_helper/CMakeLists.txt @@ -0,0 +1,19 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +add_library(linux_xcb_helper STATIC) +init_target(linux_xcb_helper "(external)") +add_library(desktop-app::linux_xcb_helper ALIAS linux_xcb_helper) + +nice_target_sources(linux_xcb_helper ${CMAKE_CURRENT_SOURCE_DIR} +PRIVATE + linux_xcb_helper.cpp +) + +target_link_libraries(linux_xcb_helper +PUBLIC + ${CMAKE_DL_LIBS} +) diff --git a/linux_xcb_helper/linux_xcb_helper.cpp b/linux_xcb_helper/linux_xcb_helper.cpp new file mode 100644 index 0000000..e056830 --- /dev/null +++ b/linux_xcb_helper/linux_xcb_helper.cpp @@ -0,0 +1,53 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#include +#include +#include +#include + +unsigned int xcb_send_request_with_fds( + xcb_connection_t *c, + int flags, + struct iovec *vector, + const xcb_protocol_request_t *req, + unsigned int num_fds, + int *fds) { + const auto send_request_with_fds = reinterpret_cast(dlsym(RTLD_NEXT, "xcb_send_request_with_fds")); + + if (!dlerror()) { + return send_request_with_fds(c, flags, vector, req, num_fds, fds); + } + + const auto send_fd = reinterpret_cast( + dlsym(RTLD_NEXT, "xcb_send_fd")); + + if (dlerror()) { + abort(); + } + + const auto send_request = reinterpret_cast(dlsym(RTLD_NEXT, "xcb_send_request")); + + if (dlerror()) { + abort(); + } + + for (int i = 0; i != num_fds; ++i) { + send_fd(c, fds[i]); + } + + return send_request(c, flags, vector, req); +} diff --git a/options_linux.cmake b/options_linux.cmake index 5ef401a..c3fce09 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -112,6 +112,7 @@ if (NOT DESKTOP_APP_USE_PACKAGED) -rdynamic -fwhole-program -Wl,-z,relro + -Wl,-z,now -pie ) endif()