From fdcdaf596ae45f739c6e1c1aba04524b1c5d46f8 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 14 Feb 2024 15:14:47 +0100 Subject: [PATCH] all: pacify clang-tidy, CI and cmake updates --- .clang-format | 2 +- .github/workflows/ci.yml | 6 ++++-- CMakeLists.txt | 7 ++++++- misc/cmake/functions.cmake | 20 ++++++++++++++++++++ misc/make/Makefile-extra.mk | 6 ++++++ misc/valgrind/musl.supp | 3 +++ src/check/dt_cxxlib.cpp | 4 ++-- src/pefile.cpp | 1 + src/util/cxxlib.h | 2 +- 9 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.clang-format b/.clang-format index 7cdeb70f..d052c8fc 100644 --- a/.clang-format +++ b/.clang-format @@ -15,7 +15,7 @@ AttributeMacros: - XSPAN_DELETED_FUNCTION - may_throw EmptyLineBeforeAccessModifier: Leave -# IndentPPDirectives: AfterHash # TODO +# IndentPPDirectives: AfterHash # TODO later SortIncludes: false SpaceAfterCStyleCast: true Standard: Cpp03 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51ae115c..a04f06a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -191,8 +191,10 @@ jobs: - { os: macos-11, gcc: gcc-10, gxx: 'g++-10', testsuite: true, ctest: true } - { os: macos-12, gcc: gcc-11, gxx: 'g++-11', testsuite: true, ctest: true } - { os: macos-13, gcc: gcc-12, gxx: 'g++-12', testsuite: true, xcode_version: 14.3.1 } - - { os: macos-13, testsuite: true } # use default Xcode-15.0 - - { os: macos-14, testsuite: true } + - { os: macos-13, testsuite: true } # use default Xcode-15 + # { os: macos-14, gcc: gcc-13, gxx: 'g++-13', testsuite: true } # gcc-13: INTERNAL ERROR in ld64 + # { os: macos-14, gcc: gcc-13, gxx: 'g++-13', testsuite: true, xcode_version: 14.3.1 } # gcc-13: MISSING HEADER FILES + - { os: macos-14, gcc: gcc-12, gxx: 'g++-12', testsuite: true } # => use gcc-12 for now env: UPX_CONFIG_EXPECT_THREADS: 'ON' steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index b4977fb8..47ec7598 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,7 +256,7 @@ if(Threads_FOUND) set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE") try_compile(result "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}" - OUTPUT_VARIABLE output) + CXX_STANDARD 17 OUTPUT_VARIABLE output) if(NOT result) # failed; under MinGW be sure to use the posix-threads and NOT the win32-threads version #message(STATUS "Threads FAILED: ${output}") # debug output from try_compile @@ -326,6 +326,7 @@ if(MSVC_FRONTEND) else() target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror}) endif() +upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2) endif() # UPX_CONFIG_DISABLE_BZIP2 set(t upx_vendor_ucl) @@ -337,6 +338,7 @@ if(MSVC_FRONTEND) else() target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror}) endif() +upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL) set(t upx_vendor_zlib) upx_compile_target_debug_with_O2(${t}) @@ -350,6 +352,7 @@ if(MSVC_FRONTEND) else() target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror}) endif() +upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB) if(NOT UPX_CONFIG_DISABLE_ZSTD) set(t upx_vendor_zstd) @@ -361,6 +364,7 @@ if(MSVC_FRONTEND) else() target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror}) endif() +upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD) endif() # UPX_CONFIG_DISABLE_ZSTD set(t upx) @@ -403,6 +407,7 @@ if(MSVC_FRONTEND) else() target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror}) endif() +upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX) #*********************************************************************** # test diff --git a/misc/cmake/functions.cmake b/misc/cmake/functions.cmake index 4cc6d3fb..4f39407c 100644 --- a/misc/cmake/functions.cmake +++ b/misc/cmake/functions.cmake @@ -197,6 +197,26 @@ function(upx_add_definitions) # ARGV; needs include(CheckCCompilerFlag) endif() endfunction() +function(upx_add_target_extra_compile_options) # ARGV + set(t "${ARGV0}") + list(REMOVE_AT ARGV 0) + foreach(var_name ${ARGV}) + if(NOT DEFINED ${var_name}) + elseif(",${${var_name}}," STREQUAL ",,") + else() + set(flags "${${var_name}}") + if(NOT flags MATCHES ";") # NOTE: split into list from string only if not already a list + if(${CMAKE_VERSION} VERSION_GREATER "3.8.99") + separate_arguments(flags NATIVE_COMMAND "${flags}") + else() + separate_arguments(flags) + endif() + endif() + target_compile_options(${t} PRIVATE "${flags}") + endif() + endforeach() +endfunction() + # compile a target with -O2 optimization even in Debug build function(upx_compile_target_debug_with_O2) # ARGV foreach(t ${ARGV}) diff --git a/misc/make/Makefile-extra.mk b/misc/make/Makefile-extra.mk index 005f2434..a7bc3054 100644 --- a/misc/make/Makefile-extra.mk +++ b/misc/make/Makefile-extra.mk @@ -276,6 +276,12 @@ build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_ build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_WSTRICT) build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_WERROR) build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_SELF_PACK_TEST) +# pass UPX extra compile options from environment/make to cmake; see CMakeLists.txt +build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2) +build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL) +build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX) +build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB) +build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD) endif # GNU make bug work-around diff --git a/misc/valgrind/musl.supp b/misc/valgrind/musl.supp index bb539ddb..d85db386 100644 --- a/misc/valgrind/musl.supp +++ b/misc/valgrind/musl.supp @@ -1,4 +1,7 @@ +# # valgrind suppressions for musl libc +# Copyright (C) Markus Franz Xaver Johannes Oberhumer +# # musl malloc { diff --git a/src/check/dt_cxxlib.cpp b/src/check/dt_cxxlib.cpp index bb3c435c..98ccb4d0 100644 --- a/src/check/dt_cxxlib.cpp +++ b/src/check/dt_cxxlib.cpp @@ -261,8 +261,8 @@ struct Z2_X2 : public X2 { **************************************************************************/ TEST_CASE("Deleter") { - LE16 *o = {}; // object - LE32 *a = {}; // array + LE16 *o = nullptr; // object + LE32 *a = nullptr; // array { const upx::ObjectDeleter o_deleter{&o, 1}; o = new LE16; diff --git a/src/pefile.cpp b/src/pefile.cpp index f6333f5b..d2f0a6e0 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1239,6 +1239,7 @@ void PeFile::Export::build(char *newbase, unsigned newoffs) { edir.addrtable = newoffs + ptr_diff_bytes(functionp, newbase); edir.ordinaltable = newoffs + ptr_diff_bytes(ordinalp, newbase); + assert(ordinals != nullptr); // pacify clang-tidy memcpy(ordinalp, ordinals, 2 * edir.names); edir.name = newoffs + ptr_diff_bytes(enamep, newbase); diff --git a/src/util/cxxlib.h b/src/util/cxxlib.h index 55560b35..6b2f8ca8 100644 --- a/src/util/cxxlib.h +++ b/src/util/cxxlib.h @@ -179,7 +179,7 @@ forceinline Result ptr_static_cast(const From *ptr) noexcept { return static_cast(static_cast(ptr)); } -// helper classes so we don't leak memory on exceptions +// helper classes so we don't leak memory on exceptions; NOT thread-safe template // T is "Type **" struct ObjectDeleter final { static_assert(std::is_pointer_v);