From f01879d5a6fd60dba068a9eacf8bad55e809b235 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 21 Oct 2024 09:58:26 +0200 Subject: [PATCH] Align ELF sections to 16K boundaries (-Wl,-z,max-page-size=16384) Even though the initial request was about Android, it is not only about it, but it could be the case for Linux as well (so as Apple M1/... chips) And this should not affect anything, since this is just ELFs Fixes: https://github.com/libevent/libevent/issues/1708 --- CMakeLists.txt | 5 +++++ Makefile.am | 1 + cmake/AddLinkerFlags.cmake | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 cmake/AddLinkerFlags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d631852..f216b338 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ include(CheckPrototypeDefinition) include(CheckFunctionKeywords) include(CheckConstExists) include(AddCompilerFlags) +include(AddLinkerFlags) include(VersionViaGit) event_fuzzy_version_from_git() @@ -213,6 +214,8 @@ if (EVENT__ENABLE_VERBOSE_DEBUG) add_definitions(-DUSE_DEBUG=1) endif() +add_linker_flags(-Wl,-z,max-page-size=16384) + # make it colorful under ninja-build if ("${CMAKE_GENERATOR}" STREQUAL "Ninja") add_compiler_flags(-fdiagnostics-color=always) @@ -1751,6 +1754,8 @@ message(STATUS "CMAKE_VERBOSE_MAKEFILE: ${CMAKE_VERBOSE_MAKEFILE}") message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER} (id ${CMAKE_C_COMPILER_ID}, clang ${CLANG}, GNUC ${GNUC}, version ${CMAKE_C_COMPILER_VERSION})") +message(STATUS "CMAKE_SHARED_LINKER_FLAGS:${CMAKE_SHARED_LINKER_FLAGS}") +message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "CMAKE_AR: ${CMAKE_AR}") message(STATUS "CMAKE_RANLIB: ${CMAKE_RANLIB}") message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") diff --git a/Makefile.am b/Makefile.am index 75a58a67..e9a1590d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -108,6 +108,7 @@ PLATFORM_DEPENDENT_SRC = \ CMAKE_FILES = \ cmake/AddCompilerFlags.cmake \ + cmake/AddLinkerFlags.cmake \ cmake/AddEventLibrary.cmake \ cmake/CheckConstExists.cmake \ cmake/CheckFileOffsetBits.c \ diff --git a/cmake/AddLinkerFlags.cmake b/cmake/AddLinkerFlags.cmake new file mode 100644 index 00000000..da590ee0 --- /dev/null +++ b/cmake/AddLinkerFlags.cmake @@ -0,0 +1,14 @@ +include(CheckLinkerFlag) + +macro(add_linker_flags) + foreach(flag ${ARGN}) + string(REGEX REPLACE "[-.+/:= ]" "_" _flag_esc "${flag}") + + check_linker_flag(C "${flag}" check_c_linker_flag_${_flag_esc}) + + if (check_c_linker_flag_${_flag_esc}) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag}") + endif() + endforeach() +endmacro()