mirror of
https://github.com/upx/upx.git
synced 2025-08-07 22:46:51 +08:00
src: more valgrind integration
This commit is contained in:
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -353,15 +353,15 @@ jobs:
|
|||||||
- { zig_target: x86_64-macos.13-none }
|
- { zig_target: x86_64-macos.13-none }
|
||||||
- { zig_target: x86_64-windows-gnu }
|
- { zig_target: x86_64-windows-gnu }
|
||||||
env:
|
env:
|
||||||
# 2023-01-24
|
# 2023-01-26
|
||||||
ZIG_DIST_VERSION: 0.11.0-dev.1436+59d9afcb5
|
ZIG_DIST_VERSION: 0.11.0-dev.1460+e675af069
|
||||||
# for zig-cc wrapper scripts (see below):
|
# for zig-cc wrapper scripts (see below):
|
||||||
ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING
|
ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING
|
||||||
ZIG_FLAGS: ${{ matrix.zig_flags }}
|
ZIG_FLAGS: ${{ matrix.zig_flags }}
|
||||||
ZIG_PIC: ${{ matrix.zig_pic }}
|
ZIG_PIC: ${{ matrix.zig_pic }}
|
||||||
ZIG_TARGET: ${{ matrix.zig_target }}
|
ZIG_TARGET: ${{ matrix.zig_target }}
|
||||||
steps:
|
steps:
|
||||||
- name: 'Install Alpine packages'
|
- name: 'Install Alpine Linux container packages'
|
||||||
if: ${{ job.container }}
|
if: ${{ job.container }}
|
||||||
shell: sh
|
shell: sh
|
||||||
run: |
|
run: |
|
||||||
|
11
Makefile
11
Makefile
@ -8,7 +8,7 @@
|
|||||||
# mkdir -p build/release
|
# mkdir -p build/release
|
||||||
# cd build/release
|
# cd build/release
|
||||||
# cmake ../..
|
# cmake ../..
|
||||||
# cmake --build . --parallel # (or just use "make -j" instead)
|
# make -j (or use "cmake --build . --parallel")
|
||||||
|
|
||||||
CMAKE = cmake
|
CMAKE = cmake
|
||||||
UPX_CMAKE_BUILD_FLAGS += --parallel
|
UPX_CMAKE_BUILD_FLAGS += --parallel
|
||||||
@ -46,6 +46,8 @@ release: build/release
|
|||||||
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
|
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
|
|
||||||
|
# END of Makefile; extra stuff follows
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# extra builds: some pre-defined build configurations
|
# extra builds: some pre-defined build configurations
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
@ -147,12 +149,12 @@ build/extra/cross-darwin-x86_64/%: export CC = clang -target x86_64-apple-darwi
|
|||||||
build/extra/cross-darwin-x86_64/%: export CXX = clang++ -target x86_64-apple-darwin
|
build/extra/cross-darwin-x86_64/%: export CXX = clang++ -target x86_64-apple-darwin
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# advanced: generic eXtra target
|
# advanced: generic extra target
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
# usage:
|
# usage:
|
||||||
# make UPX_XTARGET=mytarget CC="my-cc -flags" CXX="my-cxx -flags"
|
# make UPX_XTARGET=my-target CC="my-cc -flags" CXX="my-cxx -flags"
|
||||||
# make UPX_XTARGET=mytarget CC="my-cc -flags" CXX="my-cxx -flags" xtarget/debug
|
# make UPX_XTARGET=my-target CC="my-cc -flags" CXX="my-cxx -flags" xtarget/debug
|
||||||
|
|
||||||
ifneq ($(UPX_XTARGET),)
|
ifneq ($(UPX_XTARGET),)
|
||||||
ifneq ($(CC),)
|
ifneq ($(CC),)
|
||||||
@ -168,7 +170,6 @@ xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug
|
|||||||
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
|
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
|
||||||
# set new default
|
# set new default
|
||||||
.DEFAULT_GOAL = xtarget/release
|
.DEFAULT_GOAL = xtarget/release
|
||||||
##$(eval .DEFAULT_GOAL = build/xtarget/$(UPX_XTARGET)/release)
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
@ -33,26 +33,28 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
TEST_CASE("raw_bytes ptr") {
|
TEST_CASE("raw_bytes ptr") {
|
||||||
upx_uint32_t *ptr = nullptr;
|
upx_uint16_t *ptr = nullptr;
|
||||||
CHECK_NOTHROW(raw_bytes(ptr, 0));
|
CHECK_NOTHROW(raw_bytes(ptr, 0));
|
||||||
CHECK_THROWS(raw_bytes(ptr, 1));
|
CHECK_THROWS(raw_bytes(ptr, 1));
|
||||||
CHECK_THROWS(raw_index_bytes(ptr, 0, 0));
|
CHECK_THROWS(raw_index_bytes(ptr, 0, 0));
|
||||||
CHECK_THROWS(raw_index_bytes(ptr, 1, 0));
|
CHECK_THROWS(raw_index_bytes(ptr, 1, 0));
|
||||||
CHECK_THROWS(raw_index_bytes(ptr, 0, 1));
|
CHECK_THROWS(raw_index_bytes(ptr, 0, 1));
|
||||||
upx_uint32_t buf[4];
|
upx_uint16_t buf[4];
|
||||||
ptr = buf;
|
ptr = buf;
|
||||||
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 1, 1), ptr) == 4u);
|
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 1, 1), ptr) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 4, 0), ptr) == 8u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("raw_bytes bounded array") {
|
TEST_CASE("raw_bytes bounded array") {
|
||||||
upx_uint32_t buf[4];
|
upx_uint16_t buf[4];
|
||||||
CHECK_NOTHROW(raw_bytes(buf, 16));
|
CHECK_NOTHROW(raw_bytes(buf, 8));
|
||||||
CHECK_THROWS(raw_bytes(buf, 17));
|
CHECK_THROWS(raw_bytes(buf, 9));
|
||||||
CHECK_NOTHROW(raw_index_bytes(buf, 4, 0));
|
CHECK_NOTHROW(raw_index_bytes(buf, 4, 0));
|
||||||
CHECK_THROWS(raw_index_bytes(buf, 4, 1));
|
CHECK_THROWS(raw_index_bytes(buf, 4, 1));
|
||||||
CHECK_NOTHROW(raw_index_bytes(buf, 3, 4));
|
CHECK_NOTHROW(raw_index_bytes(buf, 3, 2));
|
||||||
CHECK_THROWS(raw_index_bytes(buf, 3, 5));
|
CHECK_THROWS(raw_index_bytes(buf, 3, 3));
|
||||||
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 1, 1), buf) == 4u);
|
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 1, 1), buf) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 4, 0), buf) == 8u);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
13
src/conf.h
13
src/conf.h
@ -139,9 +139,12 @@ ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) == 255) // -funsigned-char
|
|||||||
# include <rangeless/include/fn.hpp>
|
# include <rangeless/include/fn.hpp>
|
||||||
#endif
|
#endif
|
||||||
#ifndef WITH_VALGRIND
|
#ifndef WITH_VALGRIND
|
||||||
#define WITH_VALGRIND 1
|
# define WITH_VALGRIND 1
|
||||||
#endif
|
#endif
|
||||||
#if (WITH_VALGRIND) && defined(__GNUC__) && !defined(__SANITIZE_ADDRESS__)
|
#if defined(__SANITIZE_ADDRESS__) || defined(_WIN32) || !defined(__GNUC__)
|
||||||
|
# undef WITH_VALGRIND
|
||||||
|
#endif
|
||||||
|
#if (WITH_VALGRIND)
|
||||||
# include <valgrind/include/valgrind/memcheck.h>
|
# include <valgrind/include/valgrind/memcheck.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -318,6 +321,12 @@ typedef upx_int64_t upx_off_t;
|
|||||||
#define CLANG_FORMAT_DUMMY_STATEMENT /*empty*/
|
#define CLANG_FORMAT_DUMMY_STATEMENT /*empty*/
|
||||||
|
|
||||||
// malloc debuggers
|
// malloc debuggers
|
||||||
|
#if !defined(VALGRIND_CHECK_MEM_IS_ADDRESSABLE)
|
||||||
|
# define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr,len) 0
|
||||||
|
#endif
|
||||||
|
#if !defined(VALGRIND_CHECK_MEM_IS_DEFINED)
|
||||||
|
# define VALGRIND_CHECK_MEM_IS_DEFINED(addr,len) 0
|
||||||
|
#endif
|
||||||
#if !defined(VALGRIND_MAKE_MEM_DEFINED)
|
#if !defined(VALGRIND_MAKE_MEM_DEFINED)
|
||||||
# define VALGRIND_MAKE_MEM_DEFINED(addr,len) 0
|
# define VALGRIND_MAKE_MEM_DEFINED(addr,len) 0
|
||||||
#endif
|
#endif
|
||||||
|
@ -172,8 +172,12 @@ template <class T>
|
|||||||
inline
|
inline
|
||||||
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
||||||
raw_bytes(T ptr, size_t size_in_bytes) {
|
raw_bytes(T ptr, size_t size_in_bytes) {
|
||||||
if very_unlikely (size_in_bytes > 0 && ptr == nullptr)
|
if (size_in_bytes > 0) {
|
||||||
throwInternalError("raw_bytes unexpected NULL ptr");
|
if very_unlikely (ptr == nullptr)
|
||||||
|
throwInternalError("raw_bytes unexpected NULL ptr");
|
||||||
|
if very_unlikely (__acc_cte(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, size_in_bytes) != 0))
|
||||||
|
throwInternalError("raw_bytes valgrind-check-mem");
|
||||||
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,23 +187,29 @@ template <class T>
|
|||||||
inline
|
inline
|
||||||
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
||||||
raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) {
|
raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) {
|
||||||
|
typedef typename std::remove_pointer<T>::type element_type;
|
||||||
if very_unlikely (ptr == nullptr)
|
if very_unlikely (ptr == nullptr)
|
||||||
throwInternalError("raw_index_bytes unexpected NULL ptr");
|
throwInternalError("raw_index_bytes unexpected NULL ptr");
|
||||||
(void) mem_size(sizeof(T), index, size_in_bytes); // assert size
|
size_in_bytes = mem_size(sizeof(element_type), index, size_in_bytes); // assert size
|
||||||
|
if very_unlikely (__acc_cte(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, size_in_bytes) != 0))
|
||||||
|
throwInternalError("raw_index_bytes valgrind-check-mem");
|
||||||
|
UNUSED(size_in_bytes);
|
||||||
return ptr + index;
|
return ptr + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// same for bounded arrays
|
// same for bounded arrays
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
inline T *raw_bytes(T (&a)[N], size_t size_in_bytes) {
|
inline T *raw_bytes(T (&a)[N], size_t size_in_bytes) {
|
||||||
if very_unlikely (size_in_bytes > mem_size(sizeof(T), N))
|
typedef T element_type;
|
||||||
|
if very_unlikely (size_in_bytes > mem_size(sizeof(element_type), N))
|
||||||
throwInternalError("raw_bytes out of range");
|
throwInternalError("raw_bytes out of range");
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
inline T *raw_index_bytes(T (&a)[N], size_t index, size_t size_in_bytes) {
|
inline T *raw_index_bytes(T (&a)[N], size_t index, size_t size_in_bytes) {
|
||||||
return raw_bytes(a, mem_size(sizeof(T), index, size_in_bytes)) + index;
|
typedef T element_type;
|
||||||
|
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
Reference in New Issue
Block a user