From: Hans Kristian Rosbach Date: Thu, 8 Aug 2019 08:38:06 +0000 (+0200) Subject: Remove BUILDFIXED and MAKEFIXED. (#375) X-Git-Tag: 1.9.9-b1~456 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74a3e05bfa71e17f5b28d5f64d35e1cbe1b71a6a;p=thirdparty%2Fzlib-ng.git Remove BUILDFIXED and MAKEFIXED. (#375) Remove BUILDFIXED support. Split out MAKEFIXED into a separate 'makefixed' util that is easy to use if we want to regenerate/verify inffixed.h. --- diff --git a/.gitignore b/.gitignore index 50e5ee6f..da5bec5b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ /examplesh /libz.so* /libz-ng.so* +/makefixed /minigzip /minigzip64 /minigzipsh diff --git a/CMakeLists.txt b/CMakeLists.txt index f1bcb116..420fc1c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -825,6 +825,9 @@ if (ZLIB_ENABLE_TESTS) add_executable(switchlevels test/switchlevels.c) configure_test_executable(switchlevels) + add_executable(makefixed tools/makefixed.c inftrees.c) + configure_test_executable(makefixed) + if(HAVE_OFF64_T) add_executable(example64 test/example.c) configure_test_executable(example64) diff --git a/Makefile.in b/Makefile.in index 69fe0116..cf107b97 100644 --- a/Makefile.in +++ b/Makefile.in @@ -85,7 +85,7 @@ PIC_OBJS = $(PIC_OBJC) all: static shared -static: example$(EXE) minigzip$(EXE) fuzzers +static: example$(EXE) minigzip$(EXE) fuzzers makefixed$(EXE) shared: examplesh$(EXE) minigzipsh$(EXE) @@ -193,6 +193,9 @@ example64.o: minigzip64.o: $(CC) $(CFLAGS) -DWITH_GZFILEOP -D_FILE_OFFSET_BITS=64 $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c +makefixed.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/makefixed.c + zlibrc.o: win32/zlib$(SUFFIX)1.rc $(RC) $(RCFLAGS) -o $@ win32/zlib$(SUFFIX)1.rc @@ -256,6 +259,12 @@ ifneq ($(STRIP),) $(STRIP) $@ endif +makefixed$(EXE): makefixed.o $(OBJG) $(STATICLIB) + $(CC) $(LDFLAGS) -o $@ makefixed.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC) +ifneq ($(STRIP),) + $(STRIP) $@ +endif + install-shared: $(SHAREDTARGET) ifneq ($(SHAREDTARGET),) -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi @@ -330,7 +339,7 @@ clean: example64$(EXE) minigzip64$(EXE) \ checksum_fuzzer$(EXE) compress_fuzzer$(EXE) example_small_fuzzer$(EXE) example_large_fuzzer$(EXE) \ example_flush_fuzzer$(EXE) example_dict_fuzzer$(EXE) minigzip_fuzzer$(EXE) \ - infcover \ + infcover makefixed$(EXE) \ $(STATICLIB) $(IMPORTLIB) $(SHAREDLIB) $(SHAREDLIBV) $(SHAREDLIBM) \ foo.gz so_locations \ _match.s maketree diff --git a/configure b/configure index 66dfefd3..5a95d59c 100755 --- a/configure +++ b/configure @@ -1347,7 +1347,7 @@ sed < $SRCDIR/Makefile.in " " > Makefile # Append header files dependences. -for file in $(ls -1 $SRCDIR/*.c $SRCDIR/test/*.c $SRCDIR/test/fuzz/*.c $SRCDIR/$ARCHDIR/*.c); do +for file in $(ls -1 $SRCDIR/*.c $SRCDIR/test/*.c $SRCDIR/test/fuzz/*.c $SRCDIR/$ARCHDIR/*.c $SRCDIR/tools/*.c); do short_name=$(echo $file | sed -e "s#$SRCDIR/##g") incs=$(grep -h include $file | sed -n 's/# *\include *"\(.*\.h\)".*/\1/p' | sort | uniq) includes=$(for i in $incs; do diff --git a/inflate.c b/inflate.c index 7d166567..ed544ba9 100644 --- a/inflate.c +++ b/inflate.c @@ -9,6 +9,7 @@ #include "inflate.h" #include "inffast.h" #include "inflate_p.h" +#include "inffixed.h" #include "memcopy.h" #include "functable.h" @@ -37,21 +38,10 @@ # define INFLATE_MARK_HOOK(strm) do {} while (0) #endif -#ifdef MAKEFIXED -# ifndef BUILDFIXED -# define BUILDFIXED -# endif -#endif - /* function prototypes */ static int inflateStateCheck(PREFIX3(stream) *strm); static int updatewindow(PREFIX3(stream) *strm, const unsigned char *end, uint32_t copy); static uint32_t syncsearch(uint32_t *have, const unsigned char *buf, uint32_t len); -#ifdef BUILDFIXED - void makefixed(void); -#else -# include "inffixed.h" -#endif static int inflateStateCheck(PREFIX3(stream) *strm) { struct inflate_state *state; @@ -199,117 +189,16 @@ int ZEXPORT PREFIX(inflatePrime)(PREFIX3(stream) *strm, int bits, int value) { /* Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. + fixed code decoding. This returns fixed tables from inffixed.h. */ void ZLIB_INTERNAL fixedtables(struct inflate_state *state) { -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - zng_inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - zng_inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#endif /* BUILDFIXED */ state->lencode = lenfix; state->lenbits = 9; state->distcode = distfix; state->distbits = 5; } -#ifdef MAKEFIXED -#include - -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: - - void makefixed(void); - - int main(void) - { - makefixed(); - return 0; - } - - Then that can be linked with zlib built with MAKEFIXED defined and run: - - a.out > inffixed.h - */ -void makefixed(void) { - unsigned low, size; - struct inflate_state state; - - fixedtables(&state); - puts(" /* inffixed.h -- table for decoding fixed codes"); - puts(" * Generated automatically by makefixed()."); - puts(" */"); - puts(""); - puts(" /* WARNING: this file should *not* be used by applications."); - puts(" It is part of the implementation of this library and is"); - puts(" subject to change. Applications should only use zlib.h."); - puts(" */"); - puts(""); - size = 1U << 9; - printf(" static const code lenfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 7) == 0) - printf("\n "); - printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, - state.lencode[low].bits, state.lencode[low].val); - if (++low == size) - break; - putchar(','); - } - puts("\n };"); - size = 1U << 5; - printf("\n static const code distfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 6) == 0) - printf("\n "); - printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, state.distcode[low].val); - if (++low == size) - break; - putchar(','); - } - puts("\n };"); -} -#endif /* MAKEFIXED */ - int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state) { /* if it hasn't been done already, allocate space for the window */ diff --git a/tools/makefixed.c b/tools/makefixed.c new file mode 100644 index 00000000..0f983bd5 --- /dev/null +++ b/tools/makefixed.c @@ -0,0 +1,89 @@ +#include +#include "zbuild.h" +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" + +// Build and return state with length and distance decoding tables and index sizes set to fixed code decoding. +void ZLIB_INTERNAL buildfixedtables(struct inflate_state *state) { + static code *lenfix, *distfix; + static code fixed[544]; + + // build fixed huffman tables + unsigned sym, bits; + static code *next; + + // literal/length table + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + zng_inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + // distance table + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + zng_inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + + +// Create fixed tables on the fly and write out a inffixed.h file that is #include'd above. +// makefixed() writes those tables to stdout, which would be piped to inffixed.h. +void makefixed(void) { + unsigned low, size; + struct inflate_state state; + + buildfixedtables(&state); + puts(" /* inffixed.h -- table for decoding fixed codes"); + puts(" * Generated automatically by makefixed()."); + puts(" */"); + puts(""); + puts(" /* WARNING: this file should *not* be used by applications."); + puts(" It is part of the implementation of this library and is"); + puts(" subject to change. Applications should only use zlib.h."); + puts(" */"); + puts(""); + size = 1U << 9; + printf(" static const code lenfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 7) == 0) + printf("\n "); + printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, + state.lencode[low].bits, state.lencode[low].val); + if (++low == size) + break; + putchar(','); + } + puts("\n };"); + size = 1U << 5; + printf("\n static const code distfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 6) == 0) + printf("\n "); + printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, state.distcode[low].val); + if (++low == size) + break; + putchar(','); + } + puts("\n };"); +} + +// The output of this application can be piped out to recreate inffixed.h +int main(void) { + makefixed(); + return 0; +} + diff --git a/zlib-ng.h b/zlib-ng.h index a66b2af1..55fc12fa 100644 --- a/zlib-ng.h +++ b/zlib-ng.h @@ -1147,7 +1147,7 @@ ZEXTERN unsigned long ZEXPORT zng_zlibCompileFlags(void); 11: 0 (reserved) One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed + 12: BUILDFIXED -- build static block decoding tables when needed (not supported by zlib-ng) 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 14,15: 0 (reserved) diff --git a/zlib.h b/zlib.h index 89135001..bd8c9733 100644 --- a/zlib.h +++ b/zlib.h @@ -1158,7 +1158,7 @@ ZEXTERN unsigned long ZEXPORT zlibCompileFlags(void); 11: 0 (reserved) One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed + 12: BUILDFIXED -- build static block decoding tables when needed (not supported by zlib-ng) 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 14,15: 0 (reserved) diff --git a/zutil.c b/zutil.c index 7553db82..223d0fcc 100644 --- a/zutil.c +++ b/zutil.c @@ -77,9 +77,6 @@ unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void) #ifdef ZLIB_WINAPI flags += 1 << 10; #endif -#ifdef BUILDFIXED - flags += 1 << 12; -#endif #ifdef DYNAMIC_CRC_TABLE flags += 1 << 13; #endif