From 31f04385cdfbaf65d3cbb7f3925711d0c7933a9a Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Tue, 2 Apr 2024 20:52:53 +0530 Subject: [PATCH 1/3] chore: switch build system to cmake There are multiple benefits of using CMake over Autotools like: - CMake is much more modern and requires much less lines of code as compared to doing the same thing in autotools - Autotools is years of bad decisions, generating a long 50k+ lines of bash script to generate the Makefiles definitely isn't a good idea and is really slow as well as makes debugging the build process very difficult - Existing projects using termux-elf-cleaner using CMake should benefit from this. --- .../attach_termux_elf_cleaner_to_release.yml | 14 ++- .github/workflows/build.yml | 23 ++-- .gitignore | 8 ++ CMakeLists.txt | 38 ++++++ Makefile.am | 24 ---- configure.ac | 43 ------- tests/.gitignore | 1 + tests/Makefile.am | 62 ---------- tests/api-21.at | 109 ------------------ tests/api-24.at | 81 ------------- tests/atlocal.in | 21 ---- tests/elf-cleaner.at | 33 ------ tests/test.sh | 54 +++++++++ tests/threads.at | 39 ------- tests/tls-alignment.at | 81 ------------- 15 files changed, 119 insertions(+), 512 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile.am delete mode 100644 configure.ac create mode 100644 tests/.gitignore delete mode 100644 tests/Makefile.am delete mode 100644 tests/api-21.at delete mode 100644 tests/api-24.at delete mode 100644 tests/atlocal.in delete mode 100644 tests/elf-cleaner.at create mode 100755 tests/test.sh delete mode 100644 tests/threads.at delete mode 100644 tests/tls-alignment.at diff --git a/.github/workflows/attach_termux_elf_cleaner_to_release.yml b/.github/workflows/attach_termux_elf_cleaner_to_release.yml index 7ae5261..3135f70 100644 --- a/.github/workflows/attach_termux_elf_cleaner_to_release.yml +++ b/.github/workflows/attach_termux_elf_cleaner_to_release.yml @@ -22,12 +22,18 @@ jobs: echo "The versionName '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html." exit 1 fi + - name: Install required packages + run: | + sudo apt update + sudo apt upgrade + sudo apt install cmake ninja-build - name: Build run: | - autoreconf -vfi - mkdir build && cd build - ../configure - make + cmake . -Bbuild -GNinja + ninja -C build/ + - name: Test + run: | + ninja -C build/ test - name: Attach termux-elf-cleaner to release uses: termux/upload-release-action@v4.1.0 with: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b3fd6f..8de0a08 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,22 +12,15 @@ jobs: with: ref: ${{ env.GITHUB_REF }} - - name: Prepare + - name: Install required packages run: | - autoreconf -vfi - mkdir build - - - name: Configure - run: | - cd build - ../configure - - - name: Make + sudo apt update + sudo apt upgrade + sudo apt install cmake ninja-build + - name: Build run: | - cd build - make - + cmake . -Bbuild -GNinja + ninja -C build/ - name: Test run: | - cd build - make check + ninja -C build/ test diff --git a/.gitignore b/.gitignore index 1354835..0328db1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,16 @@ elf-cleaner # In case of out-of-src build in a directory build/: build/ +# Some people prefer to use this as build directory +out/ + +# Used for editor integration (completions, etc) +compile_commands.json + *~ +# Generated files from old autotools +# Although we no longer use autotools, some contributors might still be having it in their trees Makefile.in aclocal.m4 autom4te.cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a4fb37c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) + +set(VERSION_MAJOR 3) +set(VERSION_MINOR 0) +set(VERSION_PATCH 0) + +set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") + +set(ARCHES aarch64;arm;i686;x86_64) +set(APIS 21;24) + +project(elf-cleaner + LANGUAGES C CXX + VERSION ${VERSION} +) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(PACKAGE_NAME "termux-elf-cleaner" CACHE STRING "Name of the package") + +add_executable("${PACKAGE_NAME}" + elf-cleaner.cpp + arghandling.c +) + +target_compile_definitions("${PACKAGE_NAME}" + PRIVATE "COPYRIGHT=\"Copyright (C) 2022-2024 Termux and contributors.\"" + PRIVATE "PACKAGE_VERSION=\"${VERSION}\"" + PRIVATE "PACKAGE_NAME=\"${PACKAGE_NAME}\"" +) + +enable_testing() +add_test( + NAME "tests" + COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/tests/test.sh ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}" + ) diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index e24ec7b..0000000 --- a/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with termux-elf-cleaner. If not, see -# . - -SUBDIRS = tests -AM_CXXFLAGS = -std=c++20 -Wall -Wextra -pedantic -pthread - -bin_PROGRAMS = termux-elf-cleaner - -termux_elf_cleaner_SOURCES = elf-cleaner.cpp arghandling.c diff --git a/configure.ac b/configure.ac deleted file mode 100644 index f8d6692..0000000 --- a/configure.ac +++ /dev/null @@ -1,43 +0,0 @@ -dnl Autoconf script for termux-elf-cleaner -dnl To rebuild the 'configure' script from this, execute the command -dnl autoconf -dnl in the directory containing this script. -dnl -dnl Copyright (C) 2022-2023 Termux -dnl -dnl This file is part of termux-elf-cleaner. -dnl -dnl termux-elf-cleaner is free software: you can redistribute it -dnl and/or modify it under the terms of the GNU General Public -dnl License as published by the Free Software Foundation, either -dnl version 3 of the License, or (at your option) any later version. -dnl -dnl termux-elf-cleaner is distributed in the hope that it will be -dnl useful, but WITHOUT ANY WARRANTY; without even the implied -dnl warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -dnl See the GNU General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License -dnl along with termux-elf-cleaner. If not, see -dnl . - -AC_PREREQ([2.69]) -AC_INIT([termux-elf-cleaner], [2.2.1], [support@termux.dev]) - -AM_INIT_AUTOMAKE([foreign]) - -AC_PROG_MAKE_SET -AC_PROG_CC -AC_PROG_CXX -AC_LANG(C++) - -copyright="Copyright (C) 2022-2023 Termux." -AC_DEFINE_UNQUOTED(COPYRIGHT, ["$copyright"], - [Short copyright string for this version of termux-elf-cleaner.]) - -AC_CONFIG_TESTDIR(tests) -AM_MISSING_PROG([AUTOM4TE], [autom4te]) - -AC_CONFIG_FILES([Makefile tests/Makefile tests/atlocal]) - -AC_OUTPUT diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..9ed3b07 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +*.test diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index e2e661b..0000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,62 +0,0 @@ -# Makefile for termux-elf-cleaner regression tests. - -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -TESTSUITE_FRAGMENTS = api-21.at api-24.at tls-alignment.at \ -elf-cleaner.at threads.at - -EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 - -DISTCLEANFILES = atconfig $(check_SCRIPTS) -MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) -CLEANFILES = - -## ------------ ## -## package.m4. ## -## ------------ ## - -$(builddir)/package.m4: $(top_srcdir)/configure.ac - { \ - echo '# Signature of the current package.'; \ - echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \ - echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \ - echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \ - echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \ - } >$(builddir)/package.m4 - -## ------------ ## -## Test suite. ## -## ------------ ## - -TESTSUITE_AT = elf-cleaner.at - -TESTSUITE = $(builddir)/testsuite - -AUTOTEST = $(AUTOM4TE) --language=autotest -$(TESTSUITE): package.m4 $(TESTSUITE_FRAGMENTS) $(TESTSUITE_AT) - $(AUTOTEST) -I$(srcdir) $(TESTSUITE_AT) -o $@.tmp - mv $@.tmp $@ - -clean-local: - test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean - -check-local: $(TESTSUITE) atlocal - $(SHELL) $(TESTSUITE) $(TESTSUITEFLAGS) - -check-full: - FULL_TEST=1 $(MAKE) check diff --git a/tests/api-21.at b/tests/api-21.at deleted file mode 100644 index f431059..0000000 --- a/tests/api-21.at +++ /dev/null @@ -1,109 +0,0 @@ -# Process this file with autom4te to create testsuite. -*- Autotest -*- - -# Test suite for termux-elf-cleaner. -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -# Ensure that programs cleaned for api level 21 have the DT_FLAGS we -# expect - -AT_BANNER([API level 21]) - -AT_SETUP([aarch64]) -AT_KEYWORDS([dynamic-section api-21 aarch64]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-aarch64-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 21 curl-7.83.1-aarch64-original], -[0], -[AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Removing the DT_RUNPATH dynamic section entry from 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Removing the DT_VERNEEDNUM dynamic section entry from 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Removing the DT_VERNEED dynamic section entry from 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Removing the DT_VERSYM dynamic section entry from 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 1 in 'curl-7.83.1-aarch64-original' -AT_PACKAGE_NAME: Removing the DT_GNU_HASH dynamic section entry from 'curl-7.83.1-aarch64-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-aarch64-original ${top_srcdir}/tests/curl-7.83.1-aarch64-api21-cleaned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([arm]) -AT_KEYWORDS([dynamic-section api-21 arm]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-arm-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 21 curl-7.83.1-arm-original], -[0], -[AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Removing the DT_RUNPATH dynamic section entry from 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Removing the DT_VERNEEDNUM dynamic section entry from 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Removing the DT_VERNEED dynamic section entry from 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Removing the DT_VERSYM dynamic section entry from 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 1 in 'curl-7.83.1-arm-original' -AT_PACKAGE_NAME: Removing the DT_GNU_HASH dynamic section entry from 'curl-7.83.1-arm-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-arm-original ${top_srcdir}/tests/curl-7.83.1-arm-api21-cleaned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([i686]) -AT_KEYWORDS([dynamic-section api-21 i686]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-i686-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 21 curl-7.83.1-i686-original], -[0], -[AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Removing the DT_RUNPATH dynamic section entry from 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Removing the DT_VERNEEDNUM dynamic section entry from 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Removing the DT_VERNEED dynamic section entry from 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Removing the DT_VERSYM dynamic section entry from 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 1 in 'curl-7.83.1-i686-original' -AT_PACKAGE_NAME: Removing the DT_GNU_HASH dynamic section entry from 'curl-7.83.1-i686-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-i686-original ${top_srcdir}/tests/curl-7.83.1-i686-api21-cleaned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([x86_64]) -AT_KEYWORDS([dynamic-section api-21 x86_64]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-x86_64-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 21 curl-7.83.1-x86_64-original], -[0], -[AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Removing version section from 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Removing the DT_RUNPATH dynamic section entry from 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Removing the DT_VERNEEDNUM dynamic section entry from 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Removing the DT_VERNEED dynamic section entry from 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Removing the DT_VERSYM dynamic section entry from 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 1 in 'curl-7.83.1-x86_64-original' -AT_PACKAGE_NAME: Removing the DT_GNU_HASH dynamic section entry from 'curl-7.83.1-x86_64-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-x86_64-original ${top_srcdir}/tests/curl-7.83.1-x86_64-api21-cleaned -], -[0], -[]) -AT_CLEANUP diff --git a/tests/api-24.at b/tests/api-24.at deleted file mode 100644 index 318aef4..0000000 --- a/tests/api-24.at +++ /dev/null @@ -1,81 +0,0 @@ -# Process this file with autom4te to create testsuite. -*- Autotest -*- - -# Test suite for termux-elf-cleaner. -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -# Ensure that programs cleaned for api level 24 have the DT_FLAGS we -# expect - -AT_BANNER([API level 24]) - -AT_SETUP([aarch64]) -AT_KEYWORDS([dynamic-section api-24 aarch64]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-aarch64-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 24 curl-7.83.1-aarch64-original], -[0], -[AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 9 in 'curl-7.83.1-aarch64-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-aarch64-original ${top_srcdir}/tests/curl-7.83.1-aarch64-api24-cleaned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([arm]) -AT_KEYWORDS([dynamic-section api-24 arm]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-arm-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 24 curl-7.83.1-arm-original], -[0], -[AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 9 in 'curl-7.83.1-arm-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-arm-original ${top_srcdir}/tests/curl-7.83.1-arm-api24-cleaned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([i686]) -AT_KEYWORDS([dynamic-section api-24 i686]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-i686-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 24 curl-7.83.1-i686-original], -[0], -[AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 9 in 'curl-7.83.1-i686-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-i686-original ${top_srcdir}/tests/curl-7.83.1-i686-api24-cleaned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([x86_64]) -AT_KEYWORDS([dynamic-section api-24 x86_64]) -AT_CHECK([cp ${top_srcdir}/tests/curl-7.83.1-x86_64-original . -${abs_top_builddir}/termux-elf-cleaner --api-level 24 curl-7.83.1-x86_64-original], -[0], -[AT_PACKAGE_NAME: Replacing unsupported DF_1_* flags 134217737 with 9 in 'curl-7.83.1-x86_64-original' -]) -AT_CHECK([ -cmp --silent curl-7.83.1-x86_64-original ${top_srcdir}/tests/curl-7.83.1-x86_64-api24-cleaned -], -[0], -[]) -AT_CLEANUP diff --git a/tests/atlocal.in b/tests/atlocal.in deleted file mode 100644 index c9f322d..0000000 --- a/tests/atlocal.in +++ /dev/null @@ -1,21 +0,0 @@ -# @configure_input@ -*- shell-script -*- -# Configurable variable values for termux-elf-cleaner test suite. -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -PATH=@abs_builddir@:@abs_top_builddir@:$top_srcdir:$srcdir:$PATH diff --git a/tests/elf-cleaner.at b/tests/elf-cleaner.at deleted file mode 100644 index fb1b140..0000000 --- a/tests/elf-cleaner.at +++ /dev/null @@ -1,33 +0,0 @@ -# Process this file with autom4te to create testsuite. -*- Autotest -*- - -# Test suite for termux-elf-cleaner. -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - - -AT_INIT -AT_TESTED([termux-elf-cleaner]) -AT_COLOR_TESTS - -m4_include([api-21.at]) - -m4_include([api-24.at]) - -m4_include([tls-alignment.at]) - -m4_include([threads.at]) diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..2d425cb --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,54 @@ +#!/usr/bin/bash +set -e +if [ $# != 2 ]; then + echo "Usage path/to/test.sh " + exit 1 +fi + +archs=('arm' 'aarch64' 'i686' 'x86_64') +apis=('21' '24') +progname="$(basename "$1")" + +for arch in "${archs[@]}"; do + for api in "${apis[@]}"; do + basefile="$2/tests/curl-7.83.1-${arch}" + if [ "${api}" = "21" ]; then + expected_logs="${progname}: Removing version section from '${basefile}-api${api}.test' +${progname}: Removing version section from '${basefile}-api${api}.test' +${progname}: Removing the DT_RUNPATH dynamic section entry from '${basefile}-api${api}.test' +${progname}: Removing the DT_VERNEEDNUM dynamic section entry from '${basefile}-api${api}.test' +${progname}: Removing the DT_VERNEED dynamic section entry from '${basefile}-api${api}.test' +${progname}: Removing the DT_VERSYM dynamic section entry from '${basefile}-api${api}.test' +${progname}: Replacing unsupported DF_1_* flags 134217737 with 1 in '${basefile}-api${api}.test' +${progname}: Removing the DT_GNU_HASH dynamic section entry from '${basefile}-api${api}.test'" + elif [ "${api}" = "24" ]; then + expected_logs="${progname}: Replacing unsupported DF_1_* flags 134217737 with 9 in '${basefile}-api${api}.test'" + else + echo "Unknown API level ${api}" + exit 1 + fi + cp "${basefile}"{-original,"-api${api}".test} + if [ "$("$1" --api-level "${api}" "${basefile}-api${api}.test")" != "${expected_logs}" ]; then + echo "Failed to remove version section from ${basefile}-api${api}.test" + exit 1 + fi + done +done + +for arch in "${archs[@]}"; do + basefile="$2/tests/valgrind-3.19.0-${arch}" + if [ "${arch}" = "aarch64" ] || [ "${arch}" = "x86_64" ]; then + expected_logs="${progname}: Changing TLS alignment for '${basefile}.test' to 64, instead of 8" + elif [ "${arch}" = "arm" ] || [ "${arch}" = "i686" ]; then + expected_logs="${progname}: Changing TLS alignment for '${basefile}.test' to 32, instead of 8" + else + echo "Unknown architecture ${arch}" + exit 1 + fi + cp "${basefile}"{-original,.test} + if [ "$("$1" "${basefile}.test")" != "${expected_logs}" ]; then + echo "Failed to remove version section from ${basefile}.test" + exit 1 + fi + diff "${basefile}"{-tls-aligned,.test} +done diff --git a/tests/threads.at b/tests/threads.at deleted file mode 100644 index a9ff45b..0000000 --- a/tests/threads.at +++ /dev/null @@ -1,39 +0,0 @@ -# Process this file with autom4te to create testsuite. -*- Autotest -*- - -# Test suite for termux-elf-cleaner. -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -# Ensure that termux-elf-cleaner can run on several threads - -AT_BANNER([Multiple threads]) - -AT_SETUP([Parallel on 100 files]) -AT_KEYWORDS([dynamic-section api-24 aarch64]) -AT_CHECK([ -for i in $(seq 1 100); do - cp ${top_srcdir}/tests/curl-7.83.1-aarch64-original curl-7.83.1-aarch64-original-$i -done -${abs_top_builddir}/termux-elf-cleaner --api-level 24 --quiet --jobs 4 curl-7.83.1-aarch64-original-* -for i in $(seq 1 100); do - cmp --silent curl-7.83.1-aarch64-original-$i ${top_srcdir}/tests/curl-7.83.1-aarch64-api24-cleaned -done -], -[0], -[]) -AT_CLEANUP diff --git a/tests/tls-alignment.at b/tests/tls-alignment.at deleted file mode 100644 index 893a498..0000000 --- a/tests/tls-alignment.at +++ /dev/null @@ -1,81 +0,0 @@ -# Process this file with autom4te to create testsuite. -*- Autotest -*- - -# Test suite for termux-elf-cleaner. -# Copyright 2022 Termux - -# This file is part of termux-elf-cleaner. - -# termux-elf-cleaner is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. - -# termux-elf-cleaner is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -# Ensure that patching of under-aligned TLS segment in program header -# works - -AT_BANNER([TLS segment alignment]) - -AT_SETUP([aarch64]) -AT_KEYWORDS([program-header TLS aarch64]) -AT_CHECK([cp ${top_srcdir}/tests/valgrind-3.19.0-aarch64-original . -${abs_top_builddir}/termux-elf-cleaner valgrind-3.19.0-aarch64-original], -[0], -[AT_PACKAGE_NAME: Changing TLS alignment for 'valgrind-3.19.0-aarch64-original' to 64, instead of 8 -]) -AT_CHECK([ -cmp --silent valgrind-3.19.0-aarch64-original ${top_srcdir}/tests/valgrind-3.19.0-aarch64-tls-aligned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([arm]) -AT_KEYWORDS([program-header TLS arm]) -AT_CHECK([cp ${top_srcdir}/tests/valgrind-3.19.0-arm-original . -${abs_top_builddir}/termux-elf-cleaner valgrind-3.19.0-arm-original], -[0], -[AT_PACKAGE_NAME: Changing TLS alignment for 'valgrind-3.19.0-arm-original' to 32, instead of 8 -]) -AT_CHECK([ -cmp --silent valgrind-3.19.0-arm-original ${top_srcdir}/tests/valgrind-3.19.0-arm-tls-aligned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([i686]) -AT_KEYWORDS([program-header TLS i686]) -AT_CHECK([cp ${top_srcdir}/tests/valgrind-3.19.0-i686-original . -${abs_top_builddir}/termux-elf-cleaner valgrind-3.19.0-i686-original], -[0], -[AT_PACKAGE_NAME: Changing TLS alignment for 'valgrind-3.19.0-i686-original' to 32, instead of 8 -]) -AT_CHECK([ -cmp --silent valgrind-3.19.0-i686-original ${top_srcdir}/tests/valgrind-3.19.0-i686-tls-aligned -], -[0], -[]) -AT_CLEANUP - -AT_SETUP([x86_64]) -AT_KEYWORDS([program-header TLS x86_64]) -AT_CHECK([cp ${top_srcdir}/tests/valgrind-3.19.0-x86_64-original . -${abs_top_builddir}/termux-elf-cleaner valgrind-3.19.0-x86_64-original], -[0], -[AT_PACKAGE_NAME: Changing TLS alignment for 'valgrind-3.19.0-x86_64-original' to 64, instead of 8 -]) -AT_CHECK([ -cmp --silent valgrind-3.19.0-x86_64-original ${top_srcdir}/tests/valgrind-3.19.0-x86_64-tls-aligned -], -[0], -[]) -AT_CLEANUP From 07e013844c0315636e686754e77ab853b39a6cae Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Wed, 3 Apr 2024 11:01:34 +0530 Subject: [PATCH 2/3] split tests as requested by Grimler --- CMakeLists.txt | 32 ++++++++++++++++++--- tests/test-dynamic-section.sh | 45 +++++++++++++++++++++++++++++ tests/test-tls-alignment.sh | 37 ++++++++++++++++++++++++ tests/test.sh | 54 ----------------------------------- 4 files changed, 110 insertions(+), 58 deletions(-) create mode 100755 tests/test-dynamic-section.sh create mode 100755 tests/test-tls-alignment.sh delete mode 100755 tests/test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index a4fb37c..a205a35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,32 @@ target_compile_definitions("${PACKAGE_NAME}" PRIVATE "PACKAGE_NAME=\"${PACKAGE_NAME}\"" ) + enable_testing() -add_test( - NAME "tests" - COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/tests/test.sh ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}" - ) + +# Dynamic section tests +foreach(arch ${ARCHES}) + foreach(api ${APIS}) + add_test( + NAME "dynamic-section-${arch}-api${api}" + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-dynamic-section.sh + ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME} + ${CMAKE_CURRENT_SOURCE_DIR} + curl-7.83.1 + ${arch} + ${api} + ) + endforeach() +endforeach() + +# TLS alignment tests +foreach(arch ${ARCHES}) + add_test( + NAME "tls-alignment-${arch}-api${api}" + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-tls-alignment.sh + ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME} + ${CMAKE_CURRENT_SOURCE_DIR} + valgrind-3.19.0 + ${arch} + ) +endforeach() diff --git a/tests/test-dynamic-section.sh b/tests/test-dynamic-section.sh new file mode 100755 index 0000000..44f3a83 --- /dev/null +++ b/tests/test-dynamic-section.sh @@ -0,0 +1,45 @@ +#!/usr/bin/bash +set -e + +if [ $# != 5 ]; then + echo "Usage path/to/test-dynamic-section.sh " + exit 1 +fi + +elf_cleaner="$1" +source_dir="$2" +binary_name="$3" +arch="$4" +api="$5" + +progname="$(basename "$elf_cleaner")" +basefile="$source_dir/tests/$binary_name-$arch" +origfile="$basefile-original" +testfile="$basefile-api$api.test" +expectedfile="$basefile-api$api-cleaned" + +if [ "$api" = "21" ]; then + expected_logs="$progname: Removing version section from '$testfile' +$progname: Removing version section from '$testfile' +$progname: Removing the DT_RUNPATH dynamic section entry from '$testfile' +$progname: Removing the DT_VERNEEDNUM dynamic section entry from '$testfile' +$progname: Removing the DT_VERNEED dynamic section entry from '$testfile' +$progname: Removing the DT_VERSYM dynamic section entry from '$testfile' +$progname: Replacing unsupported DF_1_* flags 134217737 with 1 in '$testfile' +$progname: Removing the DT_GNU_HASH dynamic section entry from '$testfile'" +elif [ "$api" = "24" ]; then + expected_logs="$progname: Replacing unsupported DF_1_* flags 134217737 with 9 in '$testfile'" +else + echo "Unknown API level $api" + exit 1 +fi + +cp "$origfile" "$testfile" +if [ "$("$elf_cleaner" --api-level "$api" "$testfile")" != "$expected_logs" ]; then + echo "Logs do not match for $testfile" + exit 1 +fi +if not cmp -s "$testfile" "$expectedfile"; then + echo "Expected and actual files differ for $testfile" + exit 1 +fi diff --git a/tests/test-tls-alignment.sh b/tests/test-tls-alignment.sh new file mode 100755 index 0000000..5bc74f7 --- /dev/null +++ b/tests/test-tls-alignment.sh @@ -0,0 +1,37 @@ +#!/usr/bin/bash +set -e + +if [ $# != 4 ]; then + echo "Usage path/to/test-dynamic-section.sh " + exit 1 +fi + +elf_cleaner="$1" +source_dir="$2" +binary_name="$3" +arch="$4" + +progname="$(basename "$elf_cleaner")" +basefile="$source_dir/tests/$binary_name-$arch" +origfile="$basefile-original" +testfile="$basefile.test" +expectedfile="$basefile-tls-aligned" + +if [ "$arch" = "aarch64" ] || [ "$arch" = "x86_64" ]; then + expected_logs="$progname: Changing TLS alignment for '$testfile' to 64, instead of 8" +elif [ "$arch" = "arm" ] || [ "$arch" = "i686" ]; then + expected_logs="$progname: Changing TLS alignment for '$testfile' to 32, instead of 8" +else + echo "Unknown architecture $arch" + exit 1 +fi + +cp "$origfile" "$testfile" +if [ "$("$elf_cleaner" "$testfile")" != "$expected_logs" ]; then + echo "Logs do not match for $testfile" + exit 1 +fi +if not cmp -s "$testfile" "$expectedfile"; then + echo "Expected and actual files differ for $testfile" + exit 1 +fi diff --git a/tests/test.sh b/tests/test.sh deleted file mode 100755 index 2d425cb..0000000 --- a/tests/test.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/bash -set -e -if [ $# != 2 ]; then - echo "Usage path/to/test.sh " - exit 1 -fi - -archs=('arm' 'aarch64' 'i686' 'x86_64') -apis=('21' '24') -progname="$(basename "$1")" - -for arch in "${archs[@]}"; do - for api in "${apis[@]}"; do - basefile="$2/tests/curl-7.83.1-${arch}" - if [ "${api}" = "21" ]; then - expected_logs="${progname}: Removing version section from '${basefile}-api${api}.test' -${progname}: Removing version section from '${basefile}-api${api}.test' -${progname}: Removing the DT_RUNPATH dynamic section entry from '${basefile}-api${api}.test' -${progname}: Removing the DT_VERNEEDNUM dynamic section entry from '${basefile}-api${api}.test' -${progname}: Removing the DT_VERNEED dynamic section entry from '${basefile}-api${api}.test' -${progname}: Removing the DT_VERSYM dynamic section entry from '${basefile}-api${api}.test' -${progname}: Replacing unsupported DF_1_* flags 134217737 with 1 in '${basefile}-api${api}.test' -${progname}: Removing the DT_GNU_HASH dynamic section entry from '${basefile}-api${api}.test'" - elif [ "${api}" = "24" ]; then - expected_logs="${progname}: Replacing unsupported DF_1_* flags 134217737 with 9 in '${basefile}-api${api}.test'" - else - echo "Unknown API level ${api}" - exit 1 - fi - cp "${basefile}"{-original,"-api${api}".test} - if [ "$("$1" --api-level "${api}" "${basefile}-api${api}.test")" != "${expected_logs}" ]; then - echo "Failed to remove version section from ${basefile}-api${api}.test" - exit 1 - fi - done -done - -for arch in "${archs[@]}"; do - basefile="$2/tests/valgrind-3.19.0-${arch}" - if [ "${arch}" = "aarch64" ] || [ "${arch}" = "x86_64" ]; then - expected_logs="${progname}: Changing TLS alignment for '${basefile}.test' to 64, instead of 8" - elif [ "${arch}" = "arm" ] || [ "${arch}" = "i686" ]; then - expected_logs="${progname}: Changing TLS alignment for '${basefile}.test' to 32, instead of 8" - else - echo "Unknown architecture ${arch}" - exit 1 - fi - cp "${basefile}"{-original,.test} - if [ "$("$1" "${basefile}.test")" != "${expected_logs}" ]; then - echo "Failed to remove version section from ${basefile}.test" - exit 1 - fi - diff "${basefile}"{-tls-aligned,.test} -done From 8449d0f3319a0f40b347b2c9654390def21ea5a5 Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Wed, 3 Apr 2024 11:23:10 +0530 Subject: [PATCH 3/3] add thread tests --- CMakeLists.txt | 8 ++++++++ tests/test-threads.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 tests/test-threads.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index a205a35..bec1258 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,3 +60,11 @@ foreach(arch ${ARCHES}) ${arch} ) endforeach() + +# Thread test +add_test( + NAME "thread" + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-threads.sh + ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME} + ${CMAKE_CURRENT_SOURCE_DIR} + ) diff --git a/tests/test-threads.sh b/tests/test-threads.sh new file mode 100755 index 0000000..85722a5 --- /dev/null +++ b/tests/test-threads.sh @@ -0,0 +1,33 @@ +#!/usr/bin/bash +set -e + +if [ $# != 2 ]; then + echo "Usage path/to/test-threads.sh " + exit 1 +fi + +elf_cleaner="$1" +source_dir="$2" + +for i in {1..100}; do + for arch in aarch64 arm i686 x86_64; do + for api in 21 24; do + cp "$source_dir/tests/curl-7.83.1-$arch-original" "$source_dir/tests/curl-8.83.1-$arch-api$api-threads-$i.test" + done + done +done + +for api in 21 24; do + "$elf_cleaner" --api-level "$api" --quiet --jobs 4 "$source_dir/tests/curl-8.83.1-"*"-api$api-threads"*".test" +done + +for i in {1..100}; do + for arch in aarch64 arm i686 x86_64; do + for api in 21 24; do + if not cmp -s "$source_dir/tests/curl-7.83.1-$arch-api$api-cleaned" "$source_dir/tests/curl-8.83.1-$arch-api$api-threads-$i.test"; then + echo "Expected and actual files differ for $source_dir/tests/curl-8.83.1-$arch-threads-$i.test" + exit 1 + fi + done + done +done