From 6209d3ee3dd29dfabab8b3d49908fa59b4b91714 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 5 Apr 2023 02:39:44 +0200 Subject: [PATCH] tools: clean unwanted ELF flags from binaries Fixes warnings on old Android, such as: linker : /data/data/com.wireguard.android/code_cache/bin/wg-quick: unsupported flags DT_FLAGS_1=0x8000001 linker : /data/data/com.wireguard.android/code_cache/bin/wg: unsupported flags DT_FLAGS_1=0x8000001 Reported-by: L.W.Reek Signed-off-by: Jason A. Donenfeld --- .gitmodules | 3 +++ tunnel/tools/CMakeLists.txt | 13 +++++++++++++ tunnel/tools/elf-cleaner | 1 + 3 files changed, 17 insertions(+) create mode 160000 tunnel/tools/elf-cleaner diff --git a/.gitmodules b/.gitmodules index 46c0abd5..e649c866 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "tunnel/tools/wireguard-tools"] path = tunnel/tools/wireguard-tools url = https://git.zx2c4.com/wireguard-tools +[submodule "tunnel/tools/elf-cleaner"] + path = tunnel/tools/elf-cleaner + url = https://github.com/termux/termux-elf-cleaner diff --git a/tunnel/tools/CMakeLists.txt b/tunnel/tools/CMakeLists.txt index 577a8623..da91da76 100644 --- a/tunnel/tools/CMakeLists.txt +++ b/tunnel/tools/CMakeLists.txt @@ -28,3 +28,16 @@ add_custom_target(libwg-go.so WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib DESTDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} BUILDDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../generated-src ) + +# Strip unwanted ELF sections to prevent DT_FLAGS_1 warnings on old Android versions +file(GLOB ELF_CLEANER_SOURCES elf-cleaner/*.c elf-cleaner/*.cpp) +add_custom_target(elf-cleaner COMMENT "Building elf-cleaner" VERBATIM COMMAND "${CMAKE_C_COMPILER}" + -O2 -DPACKAGE_NAME="elf-cleaner" -DPACKAGE_VERSION="" -DCOPYRIGHT="" + -o "${CMAKE_CURRENT_BINARY_DIR}/elf-cleaner" ${ELF_CLEANER_SOURCES} +) +add_custom_command(TARGET libwg.so POST_BUILD VERBATIM COMMAND "${CMAKE_CURRENT_BINARY_DIR}/elf-cleaner" + --api-level "${ANDROID_NATIVE_API_LEVEL}" "$") +add_dependencies(libwg.so elf-cleaner) +add_custom_command(TARGET libwg-quick.so POST_BUILD VERBATIM COMMAND "${CMAKE_CURRENT_BINARY_DIR}/elf-cleaner" + --api-level "${ANDROID_NATIVE_API_LEVEL}" "$") +add_dependencies(libwg-quick.so elf-cleaner) diff --git a/tunnel/tools/elf-cleaner b/tunnel/tools/elf-cleaner new file mode 160000 index 00000000..7efc0509 --- /dev/null +++ b/tunnel/tools/elf-cleaner @@ -0,0 +1 @@ +Subproject commit 7efc05090675ec6161b7def862728086a26c3b1f