[Library] Update zlibng (#1255)

* Update zlibng

* Set cmake path more directly in zlibng to hopefully fix an issue with the build on drone

* I'm dumb, missing / in path

* Mackal helps with a dumb gitignore issue

* Adding all the files, not sure what's ignoring them and im tired of looking

* Some tweaks to zlibng build to hopefully get it to build properly. works on msvc now
This commit is contained in:
Alex
2021-02-23 17:00:26 -08:00
committed by GitHub
parent e6dee96266
commit 2957f5084d
184 changed files with 21431 additions and 11703 deletions
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
set -ux
cd "$CODECOV_DIR"
python -m codecov --required --flags "$CODECOV_FLAGS" --name "$CODECOV_NAME" --gcov-exec="$CODECOV_EXEC"
if [ $? -ne 0 ]; then
sleep 30
python -m codecov --required --flags "$CODECOV_FLAGS" --name "$CODECOV_NAME" --gcov-exec="$CODECOV_EXEC" --tries=25
fi
exit $?
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
# Canonicalize CHOST.
# In particular, converts Debian multiarch tuples into GNU triplets.
# See also
# https://wiki.debian.org/Multiarch/Tuples
# https://wiki.gentoo.org/wiki/CHOST
# If you need an architecture not listed here, file a bug at github.com/zlib-ng/zlib-ng
# and work around the problem by dropping libtool's much more comprehensive config.sub
# on top of this file, see
# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
case "$1" in
*-*-linux-gnu*) echo $1;;
i686-linux-gnu*|x86_64-linux-gnu*) echo $1 | sed 's/-linux-gnu/-pc-linux-gnu/';;
*-linux-gnu*) echo $1 | sed 's/-linux-gnu/-unknown-linux-gnu/';;
*) echo $1;;
esac
+177
View File
@@ -0,0 +1,177 @@
/* crc32.c -- output crc32 tables
* Copyright (C) 1995-2006, 2010, 2011, 2012, 2016, 2018 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <stdio.h>
#include <inttypes.h>
#include "zbuild.h"
#include "deflate.h"
#include "crc32_p.h"
static uint32_t crc_table[8][256];
static uint32_t crc_comb[GF2_DIM][GF2_DIM];
static void gf2_matrix_square(uint32_t *square, const uint32_t *mat);
static void make_crc_table(void);
static void make_crc_combine_table(void);
static void print_crc_table(void);
static void print_crc_combine_table(void);
static void write_table(const uint32_t *, int);
/* ========================================================================= */
static void gf2_matrix_square(uint32_t *square, const uint32_t *mat) {
int n;
for (n = 0; n < GF2_DIM; n++)
square[n] = gf2_matrix_times(mat, mat[n]);
}
/* =========================================================================
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The first table is simply the CRC of all possible eight bit values. This is
all the information needed to generate CRCs on data a byte at a time for all
combinations of CRC register values and incoming bytes. The remaining tables
allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes.
*/
static void make_crc_table(void) {
int n, k;
uint32_t c;
uint32_t poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static const unsigned char p[] = {0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26};
/* make exclusive-or pattern from polynomial (0xedb88320) */
poly = 0;
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
poly |= (uint32_t)1 << (31 - p[n]);
/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
c = (uint32_t)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
}
/* generate crc for each value followed by one, two, and three zeros,
and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) {
c = crc_table[0][n];
crc_table[4][n] = ZSWAP32(c);
for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c;
crc_table[k + 4][n] = ZSWAP32(c);
}
}
}
static void make_crc_combine_table(void) {
int n, k;
/* generate zero operators table for crc32_combine() */
/* generate the operator to apply a single zero bit to a CRC -- the
first row adds the polynomial if the low bit is a 1, and the
remaining rows shift the CRC right one bit */
k = GF2_DIM - 3;
crc_comb[k][0] = 0xedb88320UL; /* CRC-32 polynomial */
uint32_t row = 1;
for (n = 1; n < GF2_DIM; n++) {
crc_comb[k][n] = row;
row <<= 1;
}
/* generate operators that apply 2, 4, and 8 zeros to a CRC, putting
the last one, the operator for one zero byte, at the 0 position */
gf2_matrix_square(crc_comb[k + 1], crc_comb[k]);
gf2_matrix_square(crc_comb[k + 2], crc_comb[k + 1]);
gf2_matrix_square(crc_comb[0], crc_comb[k + 2]);
/* generate operators for applying 2^n zero bytes to a CRC, filling out
the remainder of the table -- the operators repeat after GF2_DIM
values of n, so the table only needs GF2_DIM entries, regardless of
the size of the length being processed */
for (n = 1; n < k; n++)
gf2_matrix_square(crc_comb[n], crc_comb[n - 1]);
}
static void write_table(const uint32_t *table, int k) {
int n;
for (n = 0; n < k; n++)
printf("%s0x%08" PRIx32 "%s", n % 5 ? "" : " ",
(uint32_t)(table[n]),
n == k - 1 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
}
static void print_crc_table(void) {
int k;
printf("#ifndef CRC32_TBL_H_\n");
printf("#define CRC32_TBL_H_\n\n");
printf("/* crc32_tbl.h -- tables for rapid CRC calculation\n");
printf(" * Generated automatically by makecrct.c\n */\n\n");
/* print CRC table */
printf("static const uint32_t ");
printf("crc_table[8][256] =\n{\n {\n");
write_table(crc_table[0], 256);
for (k = 1; k < 8; k++) {
printf(" },\n {\n");
write_table(crc_table[k], 256);
}
printf(" }\n};\n\n");
printf("#endif /* CRC32_TBL_H_ */\n");
}
static void print_crc_combine_table(void) {
int k;
printf("#ifndef CRC32_COMB_TBL_H_\n");
printf("#define CRC32_COMB_TBL_H_\n\n");
printf("/* crc32_comb_tbl.h -- zero operators table for CRC combine\n");
printf(" * Generated automatically by makecrct.c\n */\n\n");
/* print zero operator table */
printf("static const uint32_t ");
printf("crc_comb[%d][%d] =\n{\n {\n", GF2_DIM, GF2_DIM);
write_table(crc_comb[0], GF2_DIM);
for (k = 1; k < GF2_DIM; k++) {
printf(" },\n {\n");
write_table(crc_comb[k], GF2_DIM);
}
printf(" }\n};\n\n");
printf("#endif /* CRC32_COMB_TBL_H_ */\n");
}
// The output of this application can be piped out to recreate crc32.h
int main(int argc, char *argv[]) {
if (argc > 1 && strcmp(argv[1], "-c") == 0) {
make_crc_combine_table();
print_crc_combine_table();
} else {
make_crc_table();
print_crc_table();
}
return 0;
}
+89
View File
@@ -0,0 +1,89 @@
#include <stdio.h>
#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 Z_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_tbl.h file that is #include'd above.
// makefixed() writes those tables to stdout, which would be piped to inffixed_tbl.h.
void makefixed(void) {
unsigned low, size;
struct inflate_state state;
memset(&state, 0, sizeof(state));
buildfixedtables(&state);
puts("/* inffixed_tbl.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("\nstatic 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_tbl.h
int main(void) {
makefixed();
return 0;
}
+147
View File
@@ -0,0 +1,147 @@
/* maketrees.c -- output static huffman trees
* Copyright (C) 1995-2017 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <stdio.h>
#include "zbuild.h"
#include "deflate.h"
#include "trees.h"
static ct_data static_ltree[L_CODES+2];
/* The static literal tree. Since the bit lengths are imposed, there is no
* need for the L_CODES extra codes used during heap construction. However
* The codes 286 and 287 are needed to build a canonical tree (see zng_tr_init).
*/
static ct_data static_dtree[D_CODES];
/* The static distance tree. (Actually a trivial tree since all codes use 5 bits.)
*/
static unsigned char dist_code[DIST_CODE_LEN];
/* Distance codes. The first 256 values correspond to the distances 3 .. 258,
* the last 256 values correspond to the top 8 bits of the 15 bit distances.
*/
static unsigned char length_code[MAX_MATCH-MIN_MATCH+1];
/* length code for each normalized match length (0 == MIN_MATCH) */
static int base_length[LENGTH_CODES];
/* First normalized length for each code (0 = MIN_MATCH) */
static int base_dist[D_CODES];
/* First normalized distance for each code (0 = distance of 1) */
static void tr_static_init(void) {
int n; /* iterates over tree elements */
int bits; /* bit counter */
int length; /* length value */
int code; /* code value */
int dist; /* distance index */
uint16_t bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
for (code = 0; code < LENGTH_CODES-1; code++) {
base_length[code] = length;
for (n = 0; n < (1 << extra_lbits[code]); n++) {
length_code[length++] = (unsigned char)code;
}
}
Assert(length == 256, "tr_static_init: length != 256");
/* Note that the length 255 (match length 258) can be represented in two different
* ways: code 284 + 5 bits or code 285, so we overwrite length_code[255] to use the best encoding:
*/
length_code[length-1] = (unsigned char)code;
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0;
for (code = 0; code < 16; code++) {
base_dist[code] = dist;
for (n = 0; n < (1 << extra_dbits[code]); n++) {
dist_code[dist++] = (unsigned char)code;
}
}
Assert(dist == 256, "tr_static_init: dist != 256");
dist >>= 7; /* from now on, all distances are divided by 128 */
for ( ; code < D_CODES; code++) {
base_dist[code] = dist << 7;
for (n = 0; n < (1 << (extra_dbits[code]-7)); n++) {
dist_code[256 + dist++] = (unsigned char)code;
}
}
Assert(dist == 256, "tr_static_init: 256+dist != 512");
/* Construct the codes of the static literal tree */
for (bits = 0; bits <= MAX_BITS; bits++)
bl_count[bits] = 0;
n = 0;
while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
/* Codes 286 and 287 do not exist, but we must include them in the tree construction
* to get a canonical Huffman tree (longest code all ones)
*/
gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
/* The static distance tree is trivial: */
for (n = 0; n < D_CODES; n++) {
static_dtree[n].Len = 5;
static_dtree[n].Code = (uint16_t)bi_reverse((unsigned)n, 5);
}
}
# define SEPARATOR(i, last, width) \
((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width)-1 ? ",\n" : ", "))
static void gen_trees_header() {
int i;
printf("#ifndef TREES_TBL_H_\n");
printf("#define TREES_TBL_H_\n\n");
printf("/* header created automatically with maketrees.c */\n\n");
printf("Z_INTERNAL const ct_data static_ltree[L_CODES+2] = {\n");
for (i = 0; i < L_CODES+2; i++) {
printf("{{%3u},{%u}}%s", static_ltree[i].Code, static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
}
printf("Z_INTERNAL const ct_data static_dtree[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) {
printf("{{%2u},{%u}}%s", static_dtree[i].Code, static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
}
printf("const unsigned char Z_INTERNAL zng_dist_code[DIST_CODE_LEN] = {\n");
for (i = 0; i < DIST_CODE_LEN; i++) {
printf("%2u%s", dist_code[i], SEPARATOR(i, DIST_CODE_LEN-1, 20));
}
printf("const unsigned char Z_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = {\n");
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
printf("%2u%s", length_code[i], SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
}
printf("Z_INTERNAL const int base_length[LENGTH_CODES] = {\n");
for (i = 0; i < LENGTH_CODES; i++) {
printf("%d%s", base_length[i], SEPARATOR(i, LENGTH_CODES-1, 20));
}
printf("Z_INTERNAL const int base_dist[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) {
printf("%5d%s", base_dist[i], SEPARATOR(i, D_CODES-1, 10));
}
printf("#endif /* TREES_TBL_H_ */\n");
}
// The output of this application can be piped out to recreate trees.h
int main(void) {
tr_static_init();
gen_trees_header();
return 0;
}