From e7de85a1a3ee98990bc322e19db10fcbd3a4aa19 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 28 Apr 2026 12:28:52 +0200 Subject: [PATCH] ARM LZ4: prevent compilation of functions using malloc/free They were discarded by the linker GC as they weren't used so far, but better be safe... --- armsrc/Makefile | 2 +- common/lz4/lz4.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/armsrc/Makefile b/armsrc/Makefile index bbc26c8f9..2a684295c 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -108,7 +108,7 @@ include Standalone/Makefile.inc #the lz4 source files required for decompressing the fpga config at run time SRC_LZ4 = lz4.c #additional defines required to compile lz4 -LZ4_CFLAGS = -DLZ4_MEMORY_USAGE=8 +LZ4_CFLAGS = -DLZ4_MEMORY_USAGE=8 -DLZ4_HEAPMODE=0 APP_CFLAGS += $(LZ4_CFLAGS) # lz4 includes: APP_CFLAGS += -I../common/lz4 diff --git a/common/lz4/lz4.c b/common/lz4/lz4.c index bfa4e6294..0242c26fc 100644 --- a/common/lz4/lz4.c +++ b/common/lz4/lz4.c @@ -1390,6 +1390,7 @@ int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targe * Streaming functions ********************************/ +#if (LZ4_HEAPMODE) LZ4_stream_t *LZ4_createStream(void) { LZ4_stream_t *const lz4s = (LZ4_stream_t *)ALLOC(sizeof(LZ4_stream_t)); LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ @@ -1398,6 +1399,7 @@ LZ4_stream_t *LZ4_createStream(void) { LZ4_initStream(lz4s, sizeof(*lz4s)); return lz4s; } +#endif #ifndef _MSC_VER /* for some reason, Visual fails the aligment test on 32-bit x86 : it reports an aligment of 8-bytes, @@ -1432,12 +1434,14 @@ void LZ4_resetStream_fast(LZ4_stream_t *ctx) { LZ4_prepareTable(&(ctx->internal_donotuse), 0, byU32); } +#if (LZ4_HEAPMODE) int LZ4_freeStream(LZ4_stream_t *LZ4_stream) { if (!LZ4_stream) return 0; /* support free on NULL */ DEBUGLOG(5, "LZ4_freeStream %p", LZ4_stream); FREEMEM(LZ4_stream); return (0); } +#endif #define HASH_UNIT sizeof(reg_t) @@ -2229,6 +2233,7 @@ int LZ4_decompress_fast_doubleDict(const char *src, char *dst, int originalSize, /*===== streaming decompression functions =====*/ +#if (LZ4_HEAPMODE) LZ4_streamDecode_t *LZ4_createStreamDecode(void) { LZ4_streamDecode_t *lz4s = (LZ4_streamDecode_t *) ALLOC_AND_ZERO(sizeof(LZ4_streamDecode_t)); LZ4_STATIC_ASSERT(LZ4_STREAMDECODESIZE >= sizeof(LZ4_streamDecode_t_internal)); /* A compilation error here means LZ4_STREAMDECODESIZE is not large enough */ @@ -2240,6 +2245,7 @@ int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream) { FREEMEM(LZ4_stream); return 0; } +#endif /*! LZ4_setStreamDecode() : * Use this function to instruct where to find the dictionary. @@ -2430,10 +2436,12 @@ int LZ4_resetStreamState(void *state, char *inputBuffer) { return 0; } +#if (LZ4_HEAPMODE) void *LZ4_create(char *inputBuffer) { (void)inputBuffer; return LZ4_createStream(); } +#endif char *LZ4_slideInputBuffer(void *state) { /* avoid const char * -> char * conversion warning */