42#ifdef HAVE_DL_ITERATE_PHDR
46 #ifdef HAVE_SYS_LINK_H
56 #define S_IFLNK 0120000
59 #define S_IFMT 0170000
61 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
65#define __builtin_prefetch(p, r, l)
66#define unlikely(x) (x)
68#define unlikely(x) __builtin_expect(!!(x), 0)
71#if !defined(HAVE_DECL_STRNLEN) || !HAVE_DECL_STRNLEN
80 for (i = 0; i < maxlen; ++i)
86#define strnlen xstrnlen
115#define readlink xreadlink
119#ifndef HAVE_DL_ITERATE_PHDR
123#define dl_phdr_info x_dl_phdr_info
124#define dl_iterate_phdr x_dl_iterate_phdr
129 const char *dlpi_name;
133dl_iterate_phdr (
int (*callback) (
struct dl_phdr_info *,
148#if BACKTRACE_ELF_SIZE != 32 && BACKTRACE_ELF_SIZE != 64
149#error "Unknown BACKTRACE_ELF_SIZE"
185#undef NT_GNU_BUILD_ID
186#undef ELFCOMPRESS_ZLIB
187#undef ELFCOMPRESS_ZSTD
195#if BACKTRACE_ELF_SIZE == 32
258#define EF_PPC64_ABI 3
273#define SHN_UNDEF 0x0000
274#define SHN_LORESERVE 0xFF00
275#define SHN_XINDEX 0xFFFF
277#define SHT_PROGBITS 1
282#define SHF_COMPRESSED 0x800
284#if BACKTRACE_ELF_SIZE == 32
291 unsigned char st_info;
292 unsigned char st_other;
321#define NT_GNU_BUILD_ID 3
323#if BACKTRACE_ELF_SIZE == 32
344#define ELFCOMPRESS_ZLIB 1
345#define ELFCOMPRESS_ZSTD 2
357 ".debug_str_offsets",
426 const unsigned char *memory,
size_t memory_size,
off_t offset,
438 if ((uint64_t) offset + size > (uint64_t) memory_size)
443 view->view.
data = (
const void *) (memory + offset);
467 static const uint32_t crc32_table[256] =
469 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
470 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
471 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
472 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
473 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
474 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
475 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
476 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
477 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
478 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
479 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
480 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
481 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
482 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
483 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
484 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
485 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
486 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
487 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
488 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
489 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
490 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
491 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
492 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
493 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
494 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
495 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
496 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
497 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
498 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
499 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
500 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
501 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
502 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
503 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
504 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
505 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
506 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
507 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
508 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
509 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
510 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
511 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
512 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
513 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
514 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
515 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
516 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
517 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
518 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
519 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
522 const unsigned char *end;
525 for (end = buf + len; buf < end; ++ buf)
526 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
540 if (fstat (descriptor, &st) < 0)
550 ret =
elf_crc32 (0, (
const unsigned char *) file_view.
data, st.st_size);
583 bdata.full_callback = callback;
592 error_callback (
data,
"no debug info in ELF executable (make sure to compile with -g)", -1);
619 const uintptr_t *key = (
const uintptr_t *) vkey;
637 const unsigned char *symtab_data,
size_t symtab_size,
638 const unsigned char *strtab,
size_t strtab_size,
645 size_t elf_symbol_count;
646 size_t elf_symbol_size;
651 sym_count = symtab_size /
sizeof (
b_elf_sym);
655 elf_symbol_count = 0;
656 for (i = 0; i < sym_count; ++i, ++sym)
666 elf_symbol_size = elf_symbol_count *
sizeof (
struct elf_symbol);
670 if (elf_symbols == NULL)
675 for (i = 0; i < sym_count; ++i, ++sym)
684 if (sym->
st_name >= strtab_size)
691 elf_symbols[j].
name = (
const char *) strtab + sym->
st_name;
712 sdata->symbols = elf_symbols;
713 sdata->count = elf_symbol_count;
724 if (!
state->threaded)
771 if (!
state->threaded)
806 callback (
data, addr, NULL, 0, 0);
818 if (lstat (filename, &st) < 0)
843 rl = readlink (filename, buf, len);
849 if ((
size_t) rl < len - 1)
860#define SYSTEM_BUILD_ID_DIR "/usr/lib/debug/.build-id/"
870 const char *buildid_data,
size_t buildid_size,
875 const size_t prefix_len = strlen (prefix);
876 const char *
const suffix =
".debug";
877 const size_t suffix_len = strlen (suffix);
885 len = prefix_len + buildid_size * 2 + suffix_len + 2;
887 if (bd_filename == NULL)
891 memcpy (t, prefix, prefix_len);
893 for (i = 0; i < buildid_size; i++)
898 b = (
unsigned char) buildid_data[i];
899 nib = (b & 0xf0) >> 4;
900 *t++ = nib < 10 ?
'0' + nib :
'a' + nib - 10;
902 *t++ = nib < 10 ?
'0' + nib :
'a' + nib - 10;
906 memcpy (t, suffix, suffix_len);
907 t[suffix_len] =
'\0';
926 size_t prefix_len,
const char *prefix2,
size_t prefix2_len,
927 const char *debuglink_name,
930 size_t debuglink_len;
936 debuglink_len = strlen (debuglink_name);
937 try_len = prefix_len + prefix2_len + debuglink_len + 1;
942 memcpy (
try, prefix, prefix_len);
943 memcpy (
try + prefix_len, prefix2, prefix2_len);
944 memcpy (
try + prefix_len + prefix2_len, debuglink_name, debuglink_len);
945 try[prefix_len + prefix2_len + debuglink_len] =
'\0';
959 const char *filename,
960 const char *debuglink_name,
987 if (new_buf[0] ==
'/')
991 slash = strrchr (filename,
'/');
1000 clen = slash - filename + strlen (new_buf) + 1;
1005 memcpy (c, filename, slash - filename);
1006 memcpy (c + (slash - filename), new_buf, strlen (new_buf));
1007 c[slash - filename + strlen (new_buf)] =
'\0';
1023 slash = strrchr (filename,
'/');
1033 prefix_len = slash - filename;
1038 if (ddescriptor >= 0)
1047 strlen (
".debug/"), debuglink_name,
1049 if (ddescriptor >= 0)
1058 strlen (
"/usr/lib/debug/"), prefix,
1059 prefix_len, debuglink_name,
1061 if (ddescriptor >= 0)
1065 if (alc != NULL && alc_len > 0)
1075 const char *filename,
1076 const char *debuglink_name,
1086 if (ddescriptor < 0)
1089 if (debuglink_crc != 0)
1094 if (got_crc != debuglink_crc)
1120 uint64_t *pval,
unsigned int *pbits)
1123 const unsigned char *pin;
1139#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \
1140 && defined(__ORDER_BIG_ENDIAN__) \
1141 && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \
1142 || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
1146#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1147 next = __builtin_bswap32 (next);
1156 val |= (uint64_t)next << bits;
1174 const unsigned char *pinend,
1175 uint64_t *pval,
unsigned int *pbits)
1178 const unsigned char *pin;
1193#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \
1194 && defined(__ORDER_BIG_ENDIAN__) \
1195 && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \
1196 || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
1200#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1201 next = __builtin_bswap32 (next);
1216 val >>= (pinend - pin) * 8;
1217 bits -= (pinend - pin) * 8;
1232 const unsigned char *pinend,
1233 uint64_t *pval,
unsigned int *pbits)
1235 const unsigned char *pin;
1236 unsigned int stream_start;
1241 stream_start = (
unsigned int)*pin;
1251 while ((((uintptr_t)pin) & 3) != 0)
1254 val |= (uint64_t)*pin;
1260 val |= (uint64_t)*pin;
1269 *pbits -= __builtin_clz (stream_start) - (
sizeof (
unsigned int) - 1) * 8 + 1;
1311#define ZLIB_HUFFMAN_TABLE_SIZE (1024)
1315#define ZLIB_HUFFMAN_VALUE_MASK 0x01ff
1316#define ZLIB_HUFFMAN_BITS_SHIFT 9
1317#define ZLIB_HUFFMAN_BITS_MASK 0x7
1318#define ZLIB_HUFFMAN_SECONDARY_SHIFT 12
1326#define ZLIB_TABLE_SIZE \
1327 (2 * ZLIB_HUFFMAN_TABLE_SIZE * sizeof (uint16_t) \
1328 + (286 + 30) * sizeof (uint16_t) \
1329 + (286 + 30) * sizeof (unsigned char))
1331#define ZLIB_TABLE_CODELEN_OFFSET \
1332 (2 * ZLIB_HUFFMAN_TABLE_SIZE * sizeof (uint16_t) \
1333 + (286 + 30) * sizeof (uint16_t))
1335#define ZLIB_TABLE_WORK_OFFSET \
1336 (2 * ZLIB_HUFFMAN_TABLE_SIZE * sizeof (uint16_t))
1338#ifdef BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE
1342static size_t final_next_secondary;
1363 size_t next_secondary;
1368 next = (
uint16_t *) (((
unsigned char *) zdebug_table)
1372 for (i = 0; i < codes_len; ++i)
1380 if (
count[codes[i]] == 0)
1382 start[codes[i]] = i;
1387 next[prev[codes[i]]] = i;
1402 for (j = 1; j <= 8; ++j)
1422 for (i = 0; i < jcnt; ++i)
1445 for (
ind = code;
ind < 0x100;
ind += 1 << j)
1481 incr = 1U << (j - 1);
1482 while ((code & incr) != 0)
1499 for (j = 9; j < 16; j++)
1512 firstcode[j - 9] = code;
1515 for (k = 0; k < j; ++k)
1517 if ((jcnt & (1U << k)) != 0)
1522 bit = 1U << (j - k - 1);
1523 for (m = 0; m < j - k; ++m, bit >>= 1)
1525 if ((code & bit) == 0)
1551 for (j = 15; j >= 9; j--)
1557 size_t secondary_bits;
1564 code = firstcode[j - 9];
1568 for (i = 0; i < jcnt; ++i)
1574 if ((code & 0xff) != primary)
1580 primary = code & 0xff;
1582 tprimary = table[primary];
1594 secondary = next_secondary;
1595 secondary_bits = j - 8;
1596 next_secondary += 1 << secondary_bits;
1597 table[primary] = (secondary
1615 if (
unlikely (secondary_bits < j - 8))
1627 for (
ind = code >> 8;
1628 ind < (1U << secondary_bits);
1629 ind += 1U << (j - 8))
1631 if (
unlikely (table[secondary + 0x100 +
ind] != 0))
1636 table[secondary + 0x100 +
ind] = tval;
1642 incr = 1U << (j - 1);
1643 while ((code & incr) != 0)
1655#ifdef BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE
1656 final_next_secondary = next_secondary;
1662#ifdef BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE
1669static unsigned char codes[288];
1676 for (i = 0; i <= 143; ++i)
1678 for (i = 144; i <= 255; ++i)
1680 for (i = 256; i <= 279; ++i)
1682 for (i = 280; i <= 287; ++i)
1686 fprintf (stderr,
"elf_zlib_inflate_table failed\n");
1687 exit (EXIT_FAILURE);
1690 printf (
"static const uint16_t elf_zlib_default_table[%#zx] =\n",
1691 final_next_secondary + 0x100);
1693 for (i = 0; i < final_next_secondary + 0x100; i += 8)
1698 for (j = i; j < final_next_secondary + 0x100 && j < i + 8; ++j)
1699 printf (
" %#x,", table[j]);
1705 for (i = 0; i < 32; ++i)
1709 fprintf (stderr,
"elf_zlib_inflate_table failed\n");
1710 exit (EXIT_FAILURE);
1713 printf (
"static const uint16_t elf_zlib_default_dist_table[%#zx] =\n",
1714 final_next_secondary + 0x100);
1716 for (i = 0; i < final_next_secondary + 0x100; i += 8)
1721 for (j = i; j < final_next_secondary + 0x100 && j < i + 8; ++j)
1722 printf (
" %#x,", table[j]);
1737 0xd00, 0xe50, 0xe10, 0xf18, 0xd10, 0xe70, 0xe30, 0x1230,
1738 0xd08, 0xe60, 0xe20, 0x1210, 0xe00, 0xe80, 0xe40, 0x1250,
1739 0xd04, 0xe58, 0xe18, 0x1200, 0xd14, 0xe78, 0xe38, 0x1240,
1740 0xd0c, 0xe68, 0xe28, 0x1220, 0xe08, 0xe88, 0xe48, 0x1260,
1741 0xd02, 0xe54, 0xe14, 0xf1c, 0xd12, 0xe74, 0xe34, 0x1238,
1742 0xd0a, 0xe64, 0xe24, 0x1218, 0xe04, 0xe84, 0xe44, 0x1258,
1743 0xd06, 0xe5c, 0xe1c, 0x1208, 0xd16, 0xe7c, 0xe3c, 0x1248,
1744 0xd0e, 0xe6c, 0xe2c, 0x1228, 0xe0c, 0xe8c, 0xe4c, 0x1268,
1745 0xd01, 0xe52, 0xe12, 0xf1a, 0xd11, 0xe72, 0xe32, 0x1234,
1746 0xd09, 0xe62, 0xe22, 0x1214, 0xe02, 0xe82, 0xe42, 0x1254,
1747 0xd05, 0xe5a, 0xe1a, 0x1204, 0xd15, 0xe7a, 0xe3a, 0x1244,
1748 0xd0d, 0xe6a, 0xe2a, 0x1224, 0xe0a, 0xe8a, 0xe4a, 0x1264,
1749 0xd03, 0xe56, 0xe16, 0xf1e, 0xd13, 0xe76, 0xe36, 0x123c,
1750 0xd0b, 0xe66, 0xe26, 0x121c, 0xe06, 0xe86, 0xe46, 0x125c,
1751 0xd07, 0xe5e, 0xe1e, 0x120c, 0xd17, 0xe7e, 0xe3e, 0x124c,
1752 0xd0f, 0xe6e, 0xe2e, 0x122c, 0xe0e, 0xe8e, 0xe4e, 0x126c,
1753 0xd00, 0xe51, 0xe11, 0xf19, 0xd10, 0xe71, 0xe31, 0x1232,
1754 0xd08, 0xe61, 0xe21, 0x1212, 0xe01, 0xe81, 0xe41, 0x1252,
1755 0xd04, 0xe59, 0xe19, 0x1202, 0xd14, 0xe79, 0xe39, 0x1242,
1756 0xd0c, 0xe69, 0xe29, 0x1222, 0xe09, 0xe89, 0xe49, 0x1262,
1757 0xd02, 0xe55, 0xe15, 0xf1d, 0xd12, 0xe75, 0xe35, 0x123a,
1758 0xd0a, 0xe65, 0xe25, 0x121a, 0xe05, 0xe85, 0xe45, 0x125a,
1759 0xd06, 0xe5d, 0xe1d, 0x120a, 0xd16, 0xe7d, 0xe3d, 0x124a,
1760 0xd0e, 0xe6d, 0xe2d, 0x122a, 0xe0d, 0xe8d, 0xe4d, 0x126a,
1761 0xd01, 0xe53, 0xe13, 0xf1b, 0xd11, 0xe73, 0xe33, 0x1236,
1762 0xd09, 0xe63, 0xe23, 0x1216, 0xe03, 0xe83, 0xe43, 0x1256,
1763 0xd05, 0xe5b, 0xe1b, 0x1206, 0xd15, 0xe7b, 0xe3b, 0x1246,
1764 0xd0d, 0xe6b, 0xe2b, 0x1226, 0xe0b, 0xe8b, 0xe4b, 0x1266,
1765 0xd03, 0xe57, 0xe17, 0xf1f, 0xd13, 0xe77, 0xe37, 0x123e,
1766 0xd0b, 0xe67, 0xe27, 0x121e, 0xe07, 0xe87, 0xe47, 0x125e,
1767 0xd07, 0xe5f, 0xe1f, 0x120e, 0xd17, 0xe7f, 0xe3f, 0x124e,
1768 0xd0f, 0xe6f, 0xe2f, 0x122e, 0xe0f, 0xe8f, 0xe4f, 0x126e,
1769 0x290, 0x291, 0x292, 0x293, 0x294, 0x295, 0x296, 0x297,
1770 0x298, 0x299, 0x29a, 0x29b, 0x29c, 0x29d, 0x29e, 0x29f,
1771 0x2a0, 0x2a1, 0x2a2, 0x2a3, 0x2a4, 0x2a5, 0x2a6, 0x2a7,
1772 0x2a8, 0x2a9, 0x2aa, 0x2ab, 0x2ac, 0x2ad, 0x2ae, 0x2af,
1773 0x2b0, 0x2b1, 0x2b2, 0x2b3, 0x2b4, 0x2b5, 0x2b6, 0x2b7,
1774 0x2b8, 0x2b9, 0x2ba, 0x2bb, 0x2bc, 0x2bd, 0x2be, 0x2bf,
1775 0x2c0, 0x2c1, 0x2c2, 0x2c3, 0x2c4, 0x2c5, 0x2c6, 0x2c7,
1776 0x2c8, 0x2c9, 0x2ca, 0x2cb, 0x2cc, 0x2cd, 0x2ce, 0x2cf,
1777 0x2d0, 0x2d1, 0x2d2, 0x2d3, 0x2d4, 0x2d5, 0x2d6, 0x2d7,
1778 0x2d8, 0x2d9, 0x2da, 0x2db, 0x2dc, 0x2dd, 0x2de, 0x2df,
1779 0x2e0, 0x2e1, 0x2e2, 0x2e3, 0x2e4, 0x2e5, 0x2e6, 0x2e7,
1780 0x2e8, 0x2e9, 0x2ea, 0x2eb, 0x2ec, 0x2ed, 0x2ee, 0x2ef,
1781 0x2f0, 0x2f1, 0x2f2, 0x2f3, 0x2f4, 0x2f5, 0x2f6, 0x2f7,
1782 0x2f8, 0x2f9, 0x2fa, 0x2fb, 0x2fc, 0x2fd, 0x2fe, 0x2ff,
1787 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1788 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1789 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1790 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1791 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1792 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1793 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1794 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1795 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1796 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1797 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1798 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1799 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1800 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1801 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1802 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1803 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1804 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1805 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1806 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1807 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1808 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1809 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1810 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1811 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1812 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1813 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1814 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1815 0x800, 0x810, 0x808, 0x818, 0x804, 0x814, 0x80c, 0x81c,
1816 0x802, 0x812, 0x80a, 0x81a, 0x806, 0x816, 0x80e, 0x81e,
1817 0x801, 0x811, 0x809, 0x819, 0x805, 0x815, 0x80d, 0x81d,
1818 0x803, 0x813, 0x80b, 0x81b, 0x807, 0x817, 0x80f, 0x81f,
1826 unsigned char *pout,
size_t sout)
1828 unsigned char *porigout;
1829 const unsigned char *pinend;
1830 unsigned char *poutend;
1837 poutend = pout + sout;
1838 while ((pinend - pin) > 4)
1846 if (
unlikely ((pin[0] & 0xf) != 8))
1859 if (
unlikely ((pin[1] & 0x20) != 0))
1866 val = (pin[0] << 8) | pin[1];
1879 while ((((uintptr_t) pin) & 3) != 0)
1881 val |= (uint64_t)*pin << bits;
1900 type = (val >> 1) & 3;
1933 len = pin[0] | (pin[1] << 8);
1934 lenc = pin[2] | (pin[3] << 8);
1943 if (
unlikely (len > (
unsigned int) (pinend - pin)
1944 || len > (
unsigned int) (poutend - pout)))
1950 memcpy (pout, pin, len);
1955 while ((((uintptr_t) pin) & 3) != 0)
1957 val |= (uint64_t)*pin << bits;
1976 unsigned char codebits[19];
1977 unsigned char *plenbase;
1978 unsigned char *plen;
1979 unsigned char *plenend;
1987 nlit = (val & 0x1f) + 257;
1989 ndist = (val & 0x1f) + 1;
1991 nclen = (val & 0xf) + 4;
1994 if (
unlikely (nlit > 286 || ndist > 30))
2004 memset(&codebits[0], 0, 19);
2012 codebits[16] = val & 7;
2013 codebits[17] = (val >> 3) & 7;
2014 codebits[18] = (val >> 6) & 7;
2015 codebits[0] = (val >> 9) & 7;
2022 codebits[8] = val & 7;
2032 codebits[7] = val & 7;
2039 codebits[9] = val & 7;
2046 codebits[6] = val & 7;
2053 codebits[10] = val & 7;
2060 codebits[5] = val & 7;
2070 codebits[11] = val & 7;
2077 codebits[4] = val & 7;
2084 codebits[12] = val & 7;
2091 codebits[3] = val & 7;
2098 codebits[13] = val & 7;
2108 codebits[2] = val & 7;
2115 codebits[14] = val & 7;
2122 codebits[1] = val & 7;
2129 codebits[15] = val & 7;
2143 plenbase = (((
unsigned char *) zdebug_table)
2146 plenend = plen + nlit + ndist;
2147 while (plen < plenend)
2156 t = zdebug_table[val & 0xff];
2191 c = 3 + (val & 0x3);
2194 if (
unlikely ((
unsigned int) (plenend - plen) < c))
2226 c = 3 + (val & 0x7);
2229 if (
unlikely ((
unsigned int) (plenend - plen) < c))
2272 c = 11 + (val & 0x7f);
2275 if (
unlikely ((
unsigned int) (plenend - plen) < c))
2281 memset (plen, 0, c);
2309 tlit = zdebug_table;
2326 t = tlit[val & 0xff];
2338 t = tlit[v + 0x100 + ((val >> 8) & ((1U << b) - 1))];
2360 else if (lit == 256)
2373 len = lit - 257 + 3;
2374 else if (lit == 285)
2391 extra = (lit >> 2) + 1;
2392 len = (lit & 3) << extra;
2394 len += ((1U << (extra - 1)) - 1) << 3;
2395 len += val & ((1U << extra) - 1);
2403 t = tdist[val & 0xff];
2415 t = tdist[v + 0x100 + ((val >> 8) & ((1U << b) - 1))];
2436 if (
unlikely ((
unsigned int) (poutend - pout) < len))
2442 memset (pout, pout[-1], len);
2464 extra = (dist >> 1) + 1;
2465 dist = (dist & 1) << extra;
2467 dist += ((1U << (extra - 1)) - 1) << 2;
2468 dist += val & ((1U << extra) - 1);
2476 if (
unlikely ((
unsigned int) (pout - porigout) < dist))
2482 if (
unlikely ((
unsigned int) (poutend - pout) < len))
2490 memcpy (pout, pout - dist, len);
2499 copy = len < dist ? len : dist;
2500 memcpy (pout, pout - dist, copy);
2527 const unsigned char *uncompressed,
2528 size_t uncompressed_size)
2532 const unsigned char *p;
2538 for (i = 0; i < 4; i++)
2539 cksum = (cksum << 8) | checkbytes[i];
2547 hsz = uncompressed_size;
2550 for (i = 0; i < 5552; i += 16)
2630 for (i = 0; i < hsz; ++i)
2639 if (
unlikely ((s2 << 16) + s1 != cksum))
2653 uint16_t *zdebug_table,
unsigned char *pout,
2673#define ZSTD_TABLE_SIZE \
2674 (2 * 512 * sizeof (struct elf_zstd_fse_baseline_entry) \
2675 + 256 * sizeof (struct elf_zstd_fse_baseline_entry) \
2676 + 2048 * sizeof (uint16_t) \
2677 + 512 * sizeof (uint16_t) + 256 * sizeof (uint32_t))
2679#define ZSTD_TABLE_LITERAL_FSE_OFFSET (0)
2681#define ZSTD_TABLE_MATCH_FSE_OFFSET \
2682 (512 * sizeof (struct elf_zstd_fse_baseline_entry))
2684#define ZSTD_TABLE_OFFSET_FSE_OFFSET \
2685 (ZSTD_TABLE_MATCH_FSE_OFFSET \
2686 + 512 * sizeof (struct elf_zstd_fse_baseline_entry))
2688#define ZSTD_TABLE_HUFFMAN_OFFSET \
2689 (ZSTD_TABLE_OFFSET_FSE_OFFSET \
2690 + 256 * sizeof (struct elf_zstd_fse_baseline_entry))
2692#define ZSTD_TABLE_WORK_OFFSET \
2693 (ZSTD_TABLE_HUFFMAN_OFFSET + 2048 * sizeof (uint16_t))
2721 uint16_t *zdebug_table,
int maxidx,
2724 const unsigned char *pin;
2738 norm = (int16_t *) zdebug_table;
2739 next = zdebug_table + 256;
2751 while ((((uintptr_t) pin) & 3) != 0)
2753 val |= (uint64_t)*pin << bits;
2761 accuracy_log = (val & 0xf) + 5;
2762 if (accuracy_log > *table_bits)
2767 *table_bits = accuracy_log;
2775 remaining = (1 << accuracy_log) + 1;
2779 threshold = 1 << accuracy_log;
2782 bits_needed = accuracy_log + 1;
2790 while (remaining > 1 && idx <= maxidx)
2806 while ((val & 0xfff) == 0xfff)
2814 while ((val & 3) == 3)
2833 for (; idx < zidx; idx++)
2840 max = (2 * threshold - 1) - remaining;
2841 if ((val & (threshold - 1)) < max)
2845 val >>= bits_needed - 1;
2846 bits -= bits_needed - 1;
2852 if (
count >= (int32_t) threshold)
2853 count -= (int32_t) max;
2854 val >>= bits_needed;
2855 bits -= bits_needed;
2868 norm[idx] = (int16_t)
count;
2873 while (remaining < threshold)
2895 for (; idx <= maxidx; idx++)
2916 table_size = 1 << table_bits;
2917 high_threshold = table_size - 1;
2918 for (i = 0; i < idx; i++)
2927 table[high_threshold].
symbol = (
unsigned char) i;
2934 step = (table_size >> 1) + (table_size >> 3) + 3;
2935 mask = table_size - 1;
2936 for (i = 0; i < idx; i++)
2942 for (j = 0; j <
n; j++)
2944 table[pos].
symbol = (
unsigned char) i;
2945 pos = (pos + step) &
mask;
2946 while (
unlikely (pos > high_threshold))
2947 pos = (pos + step) &
mask;
2956 for (i = 0; i < table_size; i++)
2964 next_state = next[sym];
2967 if (next_state == 0)
2972 high_bit = 31 - __builtin_clz (next_state);
2974 bits = table_bits - high_bit;
2975 table[i].
bits = (
unsigned char) bits;
2976 table[i].
base = (
uint16_t) ((next_state << bits) - table_size);
2984#define ZSTD_ENCODE_BASELINE_BITS(baseline, basebits) \
2985 ((uint32_t)(baseline) | ((uint32_t)(basebits) << 24))
2987#define ZSTD_DECODE_BASELINE(baseline_basebits) \
2988 ((uint32_t)(baseline_basebits) & 0xffffff)
2990#define ZSTD_DECODE_BASEBITS(baseline_basebits) \
2991 ((uint32_t)(baseline_basebits) >> 24)
2997#define ZSTD_LITERAL_LENGTH_BASELINE_OFFSET (16)
3026#define ZSTD_MATCH_LENGTH_BASELINE_OFFSET (32)
3086 count = 1U << table_bits;
3087 pfse = fse_table +
count;
3088 pbaseline = baseline_table +
count;
3089 while (pfse > fse_table)
3091 unsigned char symbol;
3142 count = 1U << table_bits;
3143 pfse = fse_table +
count;
3144 pbaseline = baseline_table +
count;
3145 while (pfse > fse_table)
3147 unsigned char symbol;
3205 count = 1U << table_bits;
3206 pfse = fse_table +
count;
3207 pbaseline = baseline_table +
count;
3208 while (pfse > fse_table)
3210 unsigned char symbol;
3246#ifdef BACKTRACE_GENERATE_ZSTD_FSE_TABLES
3254static int16_t lit[36] =
3256 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
3257 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
3261static int16_t match[53] =
3263 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
3264 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3265 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
3269static int16_t offset[29] =
3271 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
3272 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1
3283 for (i = 0; i < size; i += 3)
3288 for (j = 0; j < 3 && i + j < size; ++j)
3289 printf (
" { %u, %d, %d, %d },", table[i + j].
baseline,
3310 fprintf (stderr,
"elf_zstd_build_fse failed\n");
3311 exit (EXIT_FAILURE);
3316 fprintf (stderr,
"elf_zstd_make_literal_baseline_fse failed\n");
3317 exit (EXIT_FAILURE);
3320 printf (
"static const struct elf_zstd_fse_baseline_entry "
3321 "elf_zstd_lit_table[64] =\n");
3322 print_table (lit_baseline,
3323 sizeof lit_baseline /
sizeof lit_baseline[0]);
3329 fprintf (stderr,
"elf_zstd_build_fse failed\n");
3330 exit (EXIT_FAILURE);
3335 fprintf (stderr,
"elf_zstd_make_match_baseline_fse failed\n");
3336 exit (EXIT_FAILURE);
3339 printf (
"static const struct elf_zstd_fse_baseline_entry "
3340 "elf_zstd_match_table[64] =\n");
3341 print_table (match_baseline,
3342 sizeof match_baseline /
sizeof match_baseline[0]);
3348 fprintf (stderr,
"elf_zstd_build_fse failed\n");
3349 exit (EXIT_FAILURE);
3354 fprintf (stderr,
"elf_zstd_make_offset_baseline_fse failed\n");
3355 exit (EXIT_FAILURE);
3358 printf (
"static const struct elf_zstd_fse_baseline_entry "
3359 "elf_zstd_offset_table[32] =\n");
3360 print_table (offset_baseline,
3361 sizeof offset_baseline /
sizeof offset_baseline[0]);
3374 { 0, 0, 4, 0 }, { 0, 0, 4, 16 }, { 1, 0, 5, 32 },
3375 { 3, 0, 5, 0 }, { 4, 0, 5, 0 }, { 6, 0, 5, 0 },
3376 { 7, 0, 5, 0 }, { 9, 0, 5, 0 }, { 10, 0, 5, 0 },
3377 { 12, 0, 5, 0 }, { 14, 0, 6, 0 }, { 16, 1, 5, 0 },
3378 { 20, 1, 5, 0 }, { 22, 1, 5, 0 }, { 28, 2, 5, 0 },
3379 { 32, 3, 5, 0 }, { 48, 4, 5, 0 }, { 64, 6, 5, 32 },
3380 { 128, 7, 5, 0 }, { 256, 8, 6, 0 }, { 1024, 10, 6, 0 },
3381 { 4096, 12, 6, 0 }, { 0, 0, 4, 32 }, { 1, 0, 4, 0 },
3382 { 2, 0, 5, 0 }, { 4, 0, 5, 32 }, { 5, 0, 5, 0 },
3383 { 7, 0, 5, 32 }, { 8, 0, 5, 0 }, { 10, 0, 5, 32 },
3384 { 11, 0, 5, 0 }, { 13, 0, 6, 0 }, { 16, 1, 5, 32 },
3385 { 18, 1, 5, 0 }, { 22, 1, 5, 32 }, { 24, 2, 5, 0 },
3386 { 32, 3, 5, 32 }, { 40, 3, 5, 0 }, { 64, 6, 4, 0 },
3387 { 64, 6, 4, 16 }, { 128, 7, 5, 32 }, { 512, 9, 6, 0 },
3388 { 2048, 11, 6, 0 }, { 0, 0, 4, 48 }, { 1, 0, 4, 16 },
3389 { 2, 0, 5, 32 }, { 3, 0, 5, 32 }, { 5, 0, 5, 32 },
3390 { 6, 0, 5, 32 }, { 8, 0, 5, 32 }, { 9, 0, 5, 32 },
3391 { 11, 0, 5, 32 }, { 12, 0, 5, 32 }, { 15, 0, 6, 0 },
3392 { 18, 1, 5, 32 }, { 20, 1, 5, 32 }, { 24, 2, 5, 32 },
3393 { 28, 2, 5, 32 }, { 40, 3, 5, 32 }, { 48, 4, 5, 32 },
3394 { 65536, 16, 6, 0 }, { 32768, 15, 6, 0 }, { 16384, 14, 6, 0 },
3400 { 3, 0, 6, 0 }, { 4, 0, 4, 0 }, { 5, 0, 5, 32 },
3401 { 6, 0, 5, 0 }, { 8, 0, 5, 0 }, { 9, 0, 5, 0 },
3402 { 11, 0, 5, 0 }, { 13, 0, 6, 0 }, { 16, 0, 6, 0 },
3403 { 19, 0, 6, 0 }, { 22, 0, 6, 0 }, { 25, 0, 6, 0 },
3404 { 28, 0, 6, 0 }, { 31, 0, 6, 0 }, { 34, 0, 6, 0 },
3405 { 37, 1, 6, 0 }, { 41, 1, 6, 0 }, { 47, 2, 6, 0 },
3406 { 59, 3, 6, 0 }, { 83, 4, 6, 0 }, { 131, 7, 6, 0 },
3407 { 515, 9, 6, 0 }, { 4, 0, 4, 16 }, { 5, 0, 4, 0 },
3408 { 6, 0, 5, 32 }, { 7, 0, 5, 0 }, { 9, 0, 5, 32 },
3409 { 10, 0, 5, 0 }, { 12, 0, 6, 0 }, { 15, 0, 6, 0 },
3410 { 18, 0, 6, 0 }, { 21, 0, 6, 0 }, { 24, 0, 6, 0 },
3411 { 27, 0, 6, 0 }, { 30, 0, 6, 0 }, { 33, 0, 6, 0 },
3412 { 35, 1, 6, 0 }, { 39, 1, 6, 0 }, { 43, 2, 6, 0 },
3413 { 51, 3, 6, 0 }, { 67, 4, 6, 0 }, { 99, 5, 6, 0 },
3414 { 259, 8, 6, 0 }, { 4, 0, 4, 32 }, { 4, 0, 4, 48 },
3415 { 5, 0, 4, 16 }, { 7, 0, 5, 32 }, { 8, 0, 5, 32 },
3416 { 10, 0, 5, 32 }, { 11, 0, 5, 32 }, { 14, 0, 6, 0 },
3417 { 17, 0, 6, 0 }, { 20, 0, 6, 0 }, { 23, 0, 6, 0 },
3418 { 26, 0, 6, 0 }, { 29, 0, 6, 0 }, { 32, 0, 6, 0 },
3419 { 65539, 16, 6, 0 }, { 32771, 15, 6, 0 }, { 16387, 14, 6, 0 },
3420 { 8195, 13, 6, 0 }, { 4099, 12, 6, 0 }, { 2051, 11, 6, 0 },
3426 { 1, 0, 5, 0 }, { 61, 6, 4, 0 }, { 509, 9, 5, 0 },
3427 { 32765, 15, 5, 0 }, { 2097149, 21, 5, 0 }, { 5, 3, 5, 0 },
3428 { 125, 7, 4, 0 }, { 4093, 12, 5, 0 }, { 262141, 18, 5, 0 },
3429 { 8388605, 23, 5, 0 }, { 29, 5, 5, 0 }, { 253, 8, 4, 0 },
3430 { 16381, 14, 5, 0 }, { 1048573, 20, 5, 0 }, { 1, 2, 5, 0 },
3431 { 125, 7, 4, 16 }, { 2045, 11, 5, 0 }, { 131069, 17, 5, 0 },
3432 { 4194301, 22, 5, 0 }, { 13, 4, 5, 0 }, { 253, 8, 4, 16 },
3433 { 8189, 13, 5, 0 }, { 524285, 19, 5, 0 }, { 2, 1, 5, 0 },
3434 { 61, 6, 4, 16 }, { 1021, 10, 5, 0 }, { 65533, 16, 5, 0 },
3435 { 268435453, 28, 5, 0 }, { 134217725, 27, 5, 0 }, { 67108861, 26, 5, 0 },
3436 { 33554429, 25, 5, 0 }, { 16777213, 24, 5, 0 },
3449 const unsigned char *pin;
3451 unsigned char *weights;
3467 weights = (
unsigned char *) zdebug_table;
3476 const unsigned char *pfse;
3477 const unsigned char *pback;
3480 unsigned int state1, state2;
3484 scratch = zdebug_table;
3503 pback = pin + hdr - 1;
3508 bits -= fse_table_bits;
3509 state1 = (val >>
bits) & ((1U << fse_table_bits) - 1);
3510 bits -= fse_table_bits;
3511 state2 = (val >>
bits) & ((1U << fse_table_bits) - 1);
3522 pt = &fse_table[state1];
3532 weights[
count + 1] = (
unsigned char) fse_table[state2].
symbol;
3545 v = (val >>
bits) & (((uint64_t)1 << pt->
bits) - 1);
3548 state1 = pt->
base + v;
3559 pt = &fse_table[state2];
3569 weights[
count + 1] = (
unsigned char) fse_table[state1].
symbol;
3582 v = (val >>
bits) & (((uint64_t)1 << pt->
bits) - 1);
3585 state2 = pt->
base + v;
3609 for (i = 0; i <
count; i += 2)
3615 weights[i] = b >> 4;
3616 weights[i + 1] = b & 0xf;
3620 weight_mark = (
uint32_t *) (weights + 256);
3621 memset (weight_mark, 0, 13 *
sizeof (
uint32_t));
3623 for (i = 0; i <
count; ++i)
3635 weight_mask += 1U << (w - 1);
3643 table_bits = 32 - __builtin_clz (weight_mask);
3656 left = ((
uint32_t)1 << table_bits) - weight_mask;
3662 high_bit = 31 - __builtin_clz (left);
3663 if (((
uint32_t)1 << high_bit) != left)
3675 weights[
count] = high_bit + 1;
3677 ++weight_mark[high_bit + 1];
3680 if (weight_mark[1] < 2 || (weight_mark[1] & 1) != 0)
3693 for (i = 0; i < table_bits; ++i)
3698 next += weight_mark[i + 1] << i;
3699 weight_mark[i + 1] = cur;
3703 for (i = 0; i <
count; ++i)
3705 unsigned char weight;
3711 weight = weights[i];
3715 length = 1U << (weight - 1);
3716 tval = (i << 8) | (table_bits + 1 - weight);
3717 start = weight_mark[weight];
3718 for (j = 0; j < length; ++j)
3719 table[start + j] = tval;
3720 weight_mark[weight] += length;
3724 *ptable_bits = (int)table_bits;
3738 const unsigned char *pinend,
3739 unsigned char *pout,
3740 unsigned char *poutend,
3743 int *phuffman_table_bits,
3744 unsigned char **pplit)
3746 const unsigned char *pin;
3747 unsigned char *plit;
3753 unsigned int huffman_table_bits;
3754 uint64_t huffman_mask;
3765 if ((hdr & 3) == 0 || (hdr & 3) == 1)
3771 raw = (hdr & 3) == 0;
3773 switch ((hdr >> 2) & 3)
3776 regenerated_size = hdr >> 3;
3784 regenerated_size = (hdr >> 4) + ((
uint32_t)(*pin) << 4);
3793 regenerated_size = ((hdr >> 4)
3803 if (
unlikely ((
size_t)(poutend - pout) < regenerated_size))
3809 plit = poutend - regenerated_size;
3813 if (
unlikely (pin + regenerated_size >= pinend))
3818 memcpy (plit, pin, regenerated_size);
3819 pin += regenerated_size;
3828 memset (plit, *pin, regenerated_size);
3840 switch ((hdr >> 2) & 3)
3848 regenerated_size = (hdr >> 4) | ((
uint32_t)(*pin & 0x3f) << 4);
3851 streams = ((hdr >> 2) & 3) == 0 ? 1 : 4;
3859 regenerated_size = (((
uint32_t)hdr >> 4)
3862 compressed_size = (((
uint32_t)pin[1] >> 2)
3873 regenerated_size = (((
uint32_t)hdr >> 4)
3875 | (((
uint32_t)pin[1] & 0x3f) << 12));
3876 compressed_size = (((
uint32_t)pin[1] >> 6)
3887 if (
unlikely (pin + compressed_size > pinend))
3893 pinend = pin + compressed_size;
3896 if (
unlikely ((
size_t)(poutend - pout) < regenerated_size))
3902 plit = poutend - regenerated_size;
3906 total_streams_size = compressed_size;
3909 const unsigned char *ptable;
3915 phuffman_table_bits))
3918 if (
unlikely (total_streams_size < (
size_t)(ptable - pin)))
3924 total_streams_size -= ptable - pin;
3930 if (
unlikely (*phuffman_table_bits == 0))
3940 huffman_table_bits = (
unsigned int)*phuffman_table_bits;
3941 huffman_mask = ((uint64_t)1 << huffman_table_bits) - 1;
3945 const unsigned char *pback;
3946 const unsigned char *pbackend;
3951 pback = pin + total_streams_size - 1;
3961 if (regenerated_size >= 64)
3963 unsigned char *plitstart;
3964 unsigned char *plitstop;
3967 plitstop = plit + regenerated_size - 64;
3968 while (plit < plitstop)
3980 t = huffman_table[(val >> (
bits - huffman_table_bits))
3986 t = huffman_table[(val >> (
bits - huffman_table_bits))
3992 t = huffman_table[(val >> (
bits - huffman_table_bits))
4001 t = huffman_table[(val >> (
bits - huffman_table_bits))
4009 regenerated_size -= plit - plitstart;
4012 for (i = 0; i < regenerated_size; ++i)
4021 t = huffman_table[(val << (huffman_table_bits -
bits))
4030 t = huffman_table[(val >> (
bits - huffman_table_bits))
4042 uint32_t stream_size1, stream_size2, stream_size3, stream_size4;
4044 const unsigned char *pback1, *pback2, *pback3, *pback4;
4045 const unsigned char *pbackend1, *pbackend2, *pbackend3, *pbackend4;
4046 uint64_t val1, val2, val3, val4;
4047 unsigned int bits1, bits2, bits3, bits4;
4048 unsigned char *plit1, *plit2, *plit3, *plit4;
4067 tot = stream_size1 + stream_size2 + stream_size3;
4068 if (
unlikely (tot > total_streams_size - 6))
4073 stream_size4 = total_streams_size - 6 - tot;
4075 pback1 = pin + stream_size1 - 1;
4078 pback2 = pback1 + stream_size2;
4079 pbackend2 = pback1 + 1;
4081 pback3 = pback2 + stream_size3;
4082 pbackend3 = pback2 + 1;
4084 pback4 = pback3 + stream_size4;
4085 pbackend4 = pback3 + 1;
4096 regenerated_stream_size = (regenerated_size + 3) / 4;
4099 plit2 = plit1 + regenerated_stream_size;
4100 plit3 = plit2 + regenerated_stream_size;
4101 plit4 = plit3 + regenerated_stream_size;
4103 regenerated_stream_size4 = regenerated_size - regenerated_stream_size * 3;
4109 limit = regenerated_stream_size4 <= 64 ? 0 : regenerated_stream_size4 - 64;
4126 t1 = huffman_table[(val1 >> (bits1 - huffman_table_bits))
4128 t2 = huffman_table[(val2 >> (bits2 - huffman_table_bits))
4130 t3 = huffman_table[(val3 >> (bits3 - huffman_table_bits))
4132 t4 = huffman_table[(val4 >> (bits4 - huffman_table_bits))
4153 while (bits1 > 11 && bits2 > 11 && bits3 > 11 && bits4 > 11);
4156 while (i < regenerated_stream_size)
4160 use4 = i < regenerated_stream_size4;
4174 if (
unlikely (bits1 < huffman_table_bits))
4176 t1 = huffman_table[(val1 << (huffman_table_bits - bits1))
4178 if (
unlikely (bits1 < (t1 & 0xff)))
4185 t1 = huffman_table[(val1 >> (bits1 - huffman_table_bits))
4188 if (
unlikely (bits2 < huffman_table_bits))
4190 t2 = huffman_table[(val2 << (huffman_table_bits - bits2))
4192 if (
unlikely (bits2 < (t2 & 0xff)))
4199 t2 = huffman_table[(val2 >> (bits2 - huffman_table_bits))
4202 if (
unlikely (bits3 < huffman_table_bits))
4204 t3 = huffman_table[(val3 << (huffman_table_bits - bits3))
4206 if (
unlikely (bits3 < (t3 & 0xff)))
4213 t3 = huffman_table[(val3 >> (bits3 - huffman_table_bits))
4218 if (
unlikely (bits4 < huffman_table_bits))
4220 t4 = huffman_table[(val4 << (huffman_table_bits - bits4))
4222 if (
unlikely (bits4 < (t4 & 0xff)))
4229 t4 = huffman_table[(val4 >> (bits4 - huffman_table_bits))
4269 const unsigned char **ppin,
4270 const unsigned char *pinend,
4286 decode->table_bits = predef_bits;
4303 if (!conv (&entry, 0, table))
4315 decode->table_bits = table_bits;
4319 if (!conv (fse_table,
decode->table_bits, table))
4346 unsigned char *zdebug_table,
unsigned char *pout,
4349 const unsigned char *pinend;
4350 unsigned char *poutstart;
4351 unsigned char *poutend;
4359 int huffman_table_bits;
4366 uint64_t content_size;
4371 poutend = pout + sout;
4373 literal_decode.
table = NULL;
4378 match_decode.
table = NULL;
4383 offset_decode.
table = NULL;
4389 huffman_table_bits = 0;
4393 repeated_offset1 = 1;
4394 repeated_offset2 = 4;
4395 repeated_offset3 = 8;
4424 if (
unlikely ((hdr & (1 << 5)) == 0))
4430 if (
unlikely ((hdr & (1 << 3)) != 0))
4441 has_checksum = (hdr & (1 << 2)) != 0;
4450 content_size = (uint64_t) *pin++;
4458 content_size = (((uint64_t) pin[0]) | (((uint64_t) pin[1]) << 8)) + 256;
4467 content_size = ((uint64_t) pin[0]
4468 | (((uint64_t) pin[1]) << 8)
4469 | (((uint64_t) pin[2]) << 16)
4470 | (((uint64_t) pin[3]) << 24));
4479 content_size = ((uint64_t) pin[0]
4480 | (((uint64_t) pin[1]) << 8)
4481 | (((uint64_t) pin[2]) << 16)
4482 | (((uint64_t) pin[3]) << 24)
4483 | (((uint64_t) pin[4]) << 32)
4484 | (((uint64_t) pin[5]) << 40)
4485 | (((uint64_t) pin[6]) << 48)
4486 | (((uint64_t) pin[7]) << 56));
4494 if (
unlikely (content_size != (
size_t) content_size
4495 || (
size_t) content_size != sout))
4518 last_block = block_hdr & 1;
4519 block_type = (block_hdr >> 1) & 3;
4520 block_size = block_hdr >> 3;
4531 if (
unlikely ((
size_t) block_size > (
size_t) (poutend - pout)))
4536 memcpy (pout, pin, block_size);
4548 if (
unlikely ((
size_t) block_size > (
size_t) (poutend - pout)))
4553 memset (pout, *pin, block_size);
4560 const unsigned char *pblockend;
4561 unsigned char *plitstack;
4562 unsigned char *plit;
4564 unsigned char seq_hdr;
4567 const unsigned char *pback;
4570 unsigned int literal_state;
4571 unsigned int offset_state;
4572 unsigned int match_state;
4575 if (
unlikely ((
size_t) block_size > (
size_t) (pinend - pin)))
4581 pblockend = pin + block_size;
4587 scratch, huffman_table,
4588 &huffman_table_bits,
4592 literal_count = poutend - plit;
4597 seq_count = seq_hdr;
4598 else if (seq_hdr < 255)
4605 seq_count = ((seq_hdr - 128) << 8) + *pin;
4615 seq_count = *pin + (pin[1] << 8) + 0x7f00;
4637 literal_fse_table, 9, pfn,
4646 offset_fse_table, 8, pfn,
4655 match_fse_table, 9, pfn,
4660 pback = pblockend - 1;
4665 literal_state = ((val >>
bits)
4671 offset_state = ((val >>
bits)
4677 match_state = ((val >>
bits)
4700 pt = &offset_decode.
table[offset_state];
4703 offset_bits = pt->
bits;
4704 offset_base = pt->
base;
4708 need = offset_basebits;
4715 add = (val >>
bits) & ((1U << 16) - 1);
4724 add += (val >>
bits) & ((1U << need) - 1);
4727 offset = offset_baseline +
add;
4729 pt = &match_decode.
table[match_state];
4732 match_bits = pt->
bits;
4733 match_base = pt->
base;
4741 add = (val >>
bits) & ((1U << need) - 1);
4744 match = match_baseline +
add;
4746 pt = &literal_decode.
table[literal_state];
4749 literal_bits = pt->
bits;
4750 literal_base = pt->
base;
4758 add = (val >>
bits) & ((1U << need) - 1);
4761 literal = literal_baseline +
add;
4764 if (offset_basebits > 1)
4766 repeated_offset3 = repeated_offset2;
4767 repeated_offset2 = repeated_offset1;
4768 repeated_offset1 = offset;
4777 offset = repeated_offset1;
4780 offset = repeated_offset2;
4781 repeated_offset2 = repeated_offset1;
4782 repeated_offset1 = offset;
4785 offset = repeated_offset3;
4786 repeated_offset3 = repeated_offset2;
4787 repeated_offset2 = repeated_offset1;
4788 repeated_offset1 = offset;
4791 offset = repeated_offset1 - 1;
4792 repeated_offset3 = repeated_offset2;
4793 repeated_offset2 = repeated_offset1;
4794 repeated_offset1 = offset;
4800 if (seq < seq_count)
4809 need = literal_bits;
4813 literal_state = literal_base + v;
4822 match_state = match_base + v;
4831 offset_state = offset_base + v;
4838 if (
unlikely ((
size_t)(poutend - pout) < literal))
4844 if (
unlikely (literal_count < literal))
4850 literal_count -= literal;
4884 if (
unlikely ((
size_t)(plit - pout) < literal))
4889 while (literal > move)
4891 memcpy (pout, plit, move);
4898 memcpy (pout, plit, literal);
4907 if (
unlikely ((
size_t)(poutend - pout) < match))
4913 if (
unlikely ((
size_t)(pout - poutstart) < offset))
4919 if (offset >= match)
4921 memcpy (pout, pout - offset, match);
4930 copy = match < offset ? match : offset;
4931 memcpy (pout, pout - offset, copy);
4941 if (literal_count > 0 && plit != pout)
4943 if (
unlikely ((
size_t)(poutend - pout)
4950 if ((
size_t)(plit - pout) < literal_count)
4955 while (literal_count > move)
4957 memcpy (pout, plit, move);
4960 literal_count -= move;
4964 memcpy (pout, plit, literal_count);
4967 pout += literal_count;
5008#define ZDEBUG_TABLE_SIZE \
5009 (ZLIB_TABLE_SIZE > ZSTD_TABLE_SIZE ? ZLIB_TABLE_SIZE : ZSTD_TABLE_SIZE)
5021 const unsigned char *compressed,
size_t compressed_size,
5024 unsigned char **uncompressed,
size_t *uncompressed_size)
5030 *uncompressed = NULL;
5031 *uncompressed_size = 0;
5037 if (compressed_size < 12 || memcmp (compressed,
"ZLIB", 4) != 0)
5041 for (i = 0; i < 8; i++)
5042 sz = (sz << 8) | compressed[i + 4];
5044 if (*uncompressed != NULL && *uncompressed_size >= sz)
5054 zdebug_table, po, sz))
5058 *uncompressed_size = sz;
5074 const unsigned char *compressed,
size_t compressed_size,
5077 unsigned char **uncompressed,
size_t *uncompressed_size)
5084 *uncompressed = NULL;
5085 *uncompressed_size = 0;
5094 memcpy (&chdr, compressed,
sizeof (
b_elf_chdr));
5098 if (*uncompressed != NULL && *uncompressed_size >= chdr.
ch_size)
5106 po = (
unsigned char *) alc;
5114 zdebug_table, po, chdr.
ch_size))
5121 (
unsigned char *)zdebug_table, po,
5132 *uncompressed_size = chdr.
ch_size;
5137 if (alc != NULL && alc_len > 0)
5147 const unsigned char *compressed,
5148 size_t compressed_size,
5150 void *
data,
unsigned char **uncompressed,
5151 size_t *uncompressed_size)
5158 if (zdebug_table == NULL)
5162 uncompressed, uncompressed_size);
5173 const unsigned char *compressed,
5174 size_t compressed_size,
5176 void *
data,
unsigned char *uncompressed,
5177 size_t uncompressed_size)
5179 unsigned char *zdebug_table;
5184 if (zdebug_table == NULL)
5187 zdebug_table, uncompressed, uncompressed_size);
5194#define LZMA_STATES (12)
5199#define LZMA_POS_STATES (16)
5203#define LZMA_DIST_STATES (4)
5207#define LZMA_DIST_SLOTS (64)
5211#define LZMA_DIST_MODEL_START (4)
5214#define LZMA_DIST_MODEL_END (14)
5217#define LZMA_FULL_DISTANCES (128)
5220#define LZMA_ALIGN_SIZE (16)
5224#define LZMA_LEN_LOW_SYMBOLS (8)
5225#define LZMA_LEN_MID_SYMBOLS (8)
5226#define LZMA_LEN_HIGH_SYMBOLS (256)
5229#define LZMA_LITERAL_CODERS_MAX (16)
5230#define LZMA_LITERAL_CODER_SIZE (0x300)
5239#define LZMA_PROB_IS_MATCH_LEN (LZMA_STATES * LZMA_POS_STATES)
5240#define LZMA_PROB_IS_REP_LEN LZMA_STATES
5241#define LZMA_PROB_IS_REP0_LEN LZMA_STATES
5242#define LZMA_PROB_IS_REP1_LEN LZMA_STATES
5243#define LZMA_PROB_IS_REP2_LEN LZMA_STATES
5244#define LZMA_PROB_IS_REP0_LONG_LEN (LZMA_STATES * LZMA_POS_STATES)
5245#define LZMA_PROB_DIST_SLOT_LEN (LZMA_DIST_STATES * LZMA_DIST_SLOTS)
5246#define LZMA_PROB_DIST_SPECIAL_LEN (LZMA_FULL_DISTANCES - LZMA_DIST_MODEL_END)
5247#define LZMA_PROB_DIST_ALIGN_LEN LZMA_ALIGN_SIZE
5248#define LZMA_PROB_MATCH_LEN_CHOICE_LEN 1
5249#define LZMA_PROB_MATCH_LEN_CHOICE2_LEN 1
5250#define LZMA_PROB_MATCH_LEN_LOW_LEN (LZMA_POS_STATES * LZMA_LEN_LOW_SYMBOLS)
5251#define LZMA_PROB_MATCH_LEN_MID_LEN (LZMA_POS_STATES * LZMA_LEN_MID_SYMBOLS)
5252#define LZMA_PROB_MATCH_LEN_HIGH_LEN LZMA_LEN_HIGH_SYMBOLS
5253#define LZMA_PROB_REP_LEN_CHOICE_LEN 1
5254#define LZMA_PROB_REP_LEN_CHOICE2_LEN 1
5255#define LZMA_PROB_REP_LEN_LOW_LEN (LZMA_POS_STATES * LZMA_LEN_LOW_SYMBOLS)
5256#define LZMA_PROB_REP_LEN_MID_LEN (LZMA_POS_STATES * LZMA_LEN_MID_SYMBOLS)
5257#define LZMA_PROB_REP_LEN_HIGH_LEN LZMA_LEN_HIGH_SYMBOLS
5258#define LZMA_PROB_LITERAL_LEN \
5259 (LZMA_LITERAL_CODERS_MAX * LZMA_LITERAL_CODER_SIZE)
5264#define LZMA_PROB_IS_MATCH_OFFSET 0
5265#define LZMA_PROB_IS_REP_OFFSET \
5266 (LZMA_PROB_IS_MATCH_OFFSET + LZMA_PROB_IS_MATCH_LEN)
5267#define LZMA_PROB_IS_REP0_OFFSET \
5268 (LZMA_PROB_IS_REP_OFFSET + LZMA_PROB_IS_REP_LEN)
5269#define LZMA_PROB_IS_REP1_OFFSET \
5270 (LZMA_PROB_IS_REP0_OFFSET + LZMA_PROB_IS_REP0_LEN)
5271#define LZMA_PROB_IS_REP2_OFFSET \
5272 (LZMA_PROB_IS_REP1_OFFSET + LZMA_PROB_IS_REP1_LEN)
5273#define LZMA_PROB_IS_REP0_LONG_OFFSET \
5274 (LZMA_PROB_IS_REP2_OFFSET + LZMA_PROB_IS_REP2_LEN)
5275#define LZMA_PROB_DIST_SLOT_OFFSET \
5276 (LZMA_PROB_IS_REP0_LONG_OFFSET + LZMA_PROB_IS_REP0_LONG_LEN)
5277#define LZMA_PROB_DIST_SPECIAL_OFFSET \
5278 (LZMA_PROB_DIST_SLOT_OFFSET + LZMA_PROB_DIST_SLOT_LEN)
5279#define LZMA_PROB_DIST_ALIGN_OFFSET \
5280 (LZMA_PROB_DIST_SPECIAL_OFFSET + LZMA_PROB_DIST_SPECIAL_LEN)
5281#define LZMA_PROB_MATCH_LEN_CHOICE_OFFSET \
5282 (LZMA_PROB_DIST_ALIGN_OFFSET + LZMA_PROB_DIST_ALIGN_LEN)
5283#define LZMA_PROB_MATCH_LEN_CHOICE2_OFFSET \
5284 (LZMA_PROB_MATCH_LEN_CHOICE_OFFSET + LZMA_PROB_MATCH_LEN_CHOICE_LEN)
5285#define LZMA_PROB_MATCH_LEN_LOW_OFFSET \
5286 (LZMA_PROB_MATCH_LEN_CHOICE2_OFFSET + LZMA_PROB_MATCH_LEN_CHOICE2_LEN)
5287#define LZMA_PROB_MATCH_LEN_MID_OFFSET \
5288 (LZMA_PROB_MATCH_LEN_LOW_OFFSET + LZMA_PROB_MATCH_LEN_LOW_LEN)
5289#define LZMA_PROB_MATCH_LEN_HIGH_OFFSET \
5290 (LZMA_PROB_MATCH_LEN_MID_OFFSET + LZMA_PROB_MATCH_LEN_MID_LEN)
5291#define LZMA_PROB_REP_LEN_CHOICE_OFFSET \
5292 (LZMA_PROB_MATCH_LEN_HIGH_OFFSET + LZMA_PROB_MATCH_LEN_HIGH_LEN)
5293#define LZMA_PROB_REP_LEN_CHOICE2_OFFSET \
5294 (LZMA_PROB_REP_LEN_CHOICE_OFFSET + LZMA_PROB_REP_LEN_CHOICE_LEN)
5295#define LZMA_PROB_REP_LEN_LOW_OFFSET \
5296 (LZMA_PROB_REP_LEN_CHOICE2_OFFSET + LZMA_PROB_REP_LEN_CHOICE2_LEN)
5297#define LZMA_PROB_REP_LEN_MID_OFFSET \
5298 (LZMA_PROB_REP_LEN_LOW_OFFSET + LZMA_PROB_REP_LEN_LOW_LEN)
5299#define LZMA_PROB_REP_LEN_HIGH_OFFSET \
5300 (LZMA_PROB_REP_LEN_MID_OFFSET + LZMA_PROB_REP_LEN_MID_LEN)
5301#define LZMA_PROB_LITERAL_OFFSET \
5302 (LZMA_PROB_REP_LEN_HIGH_OFFSET + LZMA_PROB_REP_LEN_HIGH_LEN)
5304#define LZMA_PROB_TOTAL_COUNT \
5305 (LZMA_PROB_LITERAL_OFFSET + LZMA_PROB_LITERAL_LEN)
5310#if LZMA_PROB_TOTAL_COUNT != 1846 + (1 << 4) * 0x300
5311 #error Wrong number of LZMA probabilities
5317#define LZMA_IS_MATCH(state, pos) \
5318 (LZMA_PROB_IS_MATCH_OFFSET + (state) * LZMA_POS_STATES + (pos))
5319#define LZMA_IS_REP(state) \
5320 (LZMA_PROB_IS_REP_OFFSET + (state))
5321#define LZMA_IS_REP0(state) \
5322 (LZMA_PROB_IS_REP0_OFFSET + (state))
5323#define LZMA_IS_REP1(state) \
5324 (LZMA_PROB_IS_REP1_OFFSET + (state))
5325#define LZMA_IS_REP2(state) \
5326 (LZMA_PROB_IS_REP2_OFFSET + (state))
5327#define LZMA_IS_REP0_LONG(state, pos) \
5328 (LZMA_PROB_IS_REP0_LONG_OFFSET + (state) * LZMA_POS_STATES + (pos))
5329#define LZMA_DIST_SLOT(dist, slot) \
5330 (LZMA_PROB_DIST_SLOT_OFFSET + (dist) * LZMA_DIST_SLOTS + (slot))
5331#define LZMA_DIST_SPECIAL(dist) \
5332 (LZMA_PROB_DIST_SPECIAL_OFFSET + (dist))
5333#define LZMA_DIST_ALIGN(dist) \
5334 (LZMA_PROB_DIST_ALIGN_OFFSET + (dist))
5335#define LZMA_MATCH_LEN_CHOICE \
5336 LZMA_PROB_MATCH_LEN_CHOICE_OFFSET
5337#define LZMA_MATCH_LEN_CHOICE2 \
5338 LZMA_PROB_MATCH_LEN_CHOICE2_OFFSET
5339#define LZMA_MATCH_LEN_LOW(pos, sym) \
5340 (LZMA_PROB_MATCH_LEN_LOW_OFFSET + (pos) * LZMA_LEN_LOW_SYMBOLS + (sym))
5341#define LZMA_MATCH_LEN_MID(pos, sym) \
5342 (LZMA_PROB_MATCH_LEN_MID_OFFSET + (pos) * LZMA_LEN_MID_SYMBOLS + (sym))
5343#define LZMA_MATCH_LEN_HIGH(sym) \
5344 (LZMA_PROB_MATCH_LEN_HIGH_OFFSET + (sym))
5345#define LZMA_REP_LEN_CHOICE \
5346 LZMA_PROB_REP_LEN_CHOICE_OFFSET
5347#define LZMA_REP_LEN_CHOICE2 \
5348 LZMA_PROB_REP_LEN_CHOICE2_OFFSET
5349#define LZMA_REP_LEN_LOW(pos, sym) \
5350 (LZMA_PROB_REP_LEN_LOW_OFFSET + (pos) * LZMA_LEN_LOW_SYMBOLS + (sym))
5351#define LZMA_REP_LEN_MID(pos, sym) \
5352 (LZMA_PROB_REP_LEN_MID_OFFSET + (pos) * LZMA_LEN_MID_SYMBOLS + (sym))
5353#define LZMA_REP_LEN_HIGH(sym) \
5354 (LZMA_PROB_REP_LEN_HIGH_OFFSET + (sym))
5355#define LZMA_LITERAL(code, size) \
5356 (LZMA_PROB_LITERAL_OFFSET + (code) * LZMA_LITERAL_CODER_SIZE + (size))
5363 size_t *poffset, uint64_t *val)
5375 if (
unlikely (off >= compressed_size))
5380 b = compressed[off];
5381 v |= (b & 0x7f) << (i * 7);
5383 if ((b & 0x80) == 0)
5403 size_t compressed_size,
size_t *poffset,
5406 if (*prange < (1U << 24))
5408 if (
unlikely (*poffset >= compressed_size))
5416 *pcode += compressed[*poffset];
5433 bound = (*prange >> 11) * (
uint32_t) *prob;
5437 *prob += ((1U << 11) - *prob) >> 5;
5444 *prob -= *prob >> 5;
5461 for (i = 0; i <
bits; i++)
5465 bit =
elf_lzma_bit (compressed, compressed_size, probs + sym, poffset,
5470 return sym - (1 <<
bits);
5478 size_t compressed_size,
uint16_t *probs,
5488 for (i = 0; i <
bits; i++)
5492 bit =
elf_lzma_bit (compressed, compressed_size, probs + sym, poffset,
5506 uint16_t *probs,
int is_rep,
unsigned int pos_state,
5514 probs_choice = probs + (is_rep
5517 if (
elf_lzma_bit (compressed, compressed_size, probs_choice, poffset,
5520 probs_choice = probs + (is_rep
5523 if (
elf_lzma_bit (compressed, compressed_size, probs_choice,
5524 poffset, prange, pcode))
5526 probs_sym = probs + (is_rep
5534 probs_sym = probs + (is_rep
5543 probs_sym = probs + (is_rep
5551 poffset, prange, pcode);
5563 size_t compressed_size,
unsigned char check,
5564 uint16_t *probs,
unsigned char *uncompressed,
5565 size_t uncompressed_size,
size_t *poffset)
5568 size_t block_header_offset;
5569 size_t block_header_size;
5570 unsigned char block_flags;
5571 uint64_t header_compressed_size;
5572 uint64_t header_uncompressed_size;
5573 unsigned char lzma2_properties;
5577 size_t uncompressed_offset;
5578 size_t dict_start_offset;
5588 block_header_offset = off;
5591 if (
unlikely (off >= compressed_size))
5596 block_header_size = (compressed[off] + 1) * 4;
5597 if (
unlikely (off + block_header_size > compressed_size))
5604 block_flags = compressed[off + 1];
5605 if (
unlikely ((block_flags & 0x3c) != 0))
5614 header_compressed_size = 0;
5615 if ((block_flags & 0x40) != 0)
5619 &header_compressed_size))
5625 header_uncompressed_size = 0;
5626 if ((block_flags & 0x80) != 0)
5630 &header_uncompressed_size))
5638 if (
unlikely ((block_flags & 0x3) != 0))
5644 if (
unlikely (off + 2 >= block_header_offset + block_header_size))
5651 if (
unlikely (compressed[off] != 0x21))
5659 if (
unlikely (compressed[off] != 1))
5666 lzma2_properties = compressed[off];
5669 if (
unlikely (lzma2_properties > 40))
5679 crc_offset = block_header_offset + block_header_size - 4;
5680 if (
unlikely (crc_offset + 4 > compressed_size))
5685 for (; off < crc_offset; off++)
5687 if (compressed[off] != 0)
5695 computed_crc =
elf_crc32 (0, compressed + block_header_offset,
5696 block_header_size - 4);
5697 stream_crc = ((
uint32_t)compressed[off]
5698 | ((
uint32_t)compressed[off + 1] << 8)
5699 | ((
uint32_t)compressed[off + 2] << 16)
5700 | ((
uint32_t)compressed[off + 3] << 24));
5701 if (
unlikely (computed_crc != stream_crc))
5710 uncompressed_offset = 0;
5711 dict_start_offset = 0;
5716 while (off < compressed_size)
5718 unsigned char control;
5723 control = compressed[off];
5731 if (control == 1 || control >= 0xe0)
5734 dict_start_offset = uncompressed_offset;
5754 if (
unlikely (off + 2 > compressed_size))
5760 chunk_size = compressed[off] << 8;
5761 chunk_size += compressed[off + 1];
5766 if (
unlikely (off + chunk_size > compressed_size))
5771 if (
unlikely (uncompressed_offset + chunk_size > uncompressed_size))
5777 memcpy (uncompressed + uncompressed_offset, compressed + off,
5779 uncompressed_offset += chunk_size;
5784 size_t uncompressed_chunk_start;
5785 size_t uncompressed_chunk_size;
5786 size_t compressed_chunk_size;
5792 if (
unlikely (off + 4 >= compressed_size))
5798 uncompressed_chunk_start = uncompressed_offset;
5800 uncompressed_chunk_size = (control & 0x1f) << 16;
5801 uncompressed_chunk_size += compressed[off] << 8;
5802 uncompressed_chunk_size += compressed[off + 1];
5803 ++uncompressed_chunk_size;
5805 compressed_chunk_size = compressed[off + 2] << 8;
5806 compressed_chunk_size += compressed[off + 3];
5807 ++compressed_chunk_size;
5818 if (control >= 0xc0)
5820 unsigned char props;
5824 if (
unlikely (off >= compressed_size))
5829 props = compressed[off];
5831 if (
unlikely (props > (4 * 5 + 4) * 9 + 8))
5837 while (props >= 9 * 5)
5856 if (control >= 0xa0)
5863 memset (&dist, 0,
sizeof dist);
5872 if (
unlikely (off + 5 > compressed_size))
5881 code = (((
uint32_t)compressed[off + 1] << 24)
5882 + ((
uint32_t)compressed[off + 2] << 16)
5883 + ((
uint32_t)compressed[off + 3] << 8)
5889 limit = off + compressed_chunk_size;
5891 while (*poffset < limit)
5893 unsigned int pos_state;
5896 == (uncompressed_chunk_start
5897 + uncompressed_chunk_size)))
5903 pos_state = ((uncompressed_offset - dict_start_offset)
5908 poffset, &range, &code))
5914 poffset, &range, &code))
5924 poffset, &range, &code))
5928 poffset, &range, &code))
5932 poffset, &range, &code))
5934 next_dist = dist[3];
5939 next_dist = dist[2];
5945 next_dist = dist[1];
5949 dist[0] = next_dist;
5957 poffset, &range, &code))
5962 lstate = short_rep ? 9 : 8;
5970 probs, 1, pos_state, poffset,
5989 probs, 0, pos_state, poffset,
5993 dist_state = len - 2;
6003 dist[0] = dist_slot;
6008 limit = (dist_slot >> 1) - 1;
6009 dist[0] = 2 + (dist_slot & 1);
6030 for (i = 0; i < limit - 4; i++)
6040 mask = -(code >> 31);
6041 code += range &
mask;
6059 - dict_start_offset < dist[0] + 1))
6064 if (
unlikely (uncompressed_offset + len > uncompressed_size))
6074 memset (uncompressed + uncompressed_offset,
6075 uncompressed[uncompressed_offset - 1],
6077 uncompressed_offset += len;
6079 else if (dist[0] + 1 >= len)
6081 memcpy (uncompressed + uncompressed_offset,
6082 uncompressed + uncompressed_offset - dist[0] - 1,
6084 uncompressed_offset += len;
6092 copy = len < dist[0] + 1 ? len : dist[0] + 1;
6093 memcpy (uncompressed + uncompressed_offset,
6094 (uncompressed + uncompressed_offset
6098 uncompressed_offset += copy;
6112 if (uncompressed_offset > 0)
6113 prev = uncompressed[uncompressed_offset - 1];
6116 low = prev >> (8 - lc);
6117 high = (((uncompressed_offset - dict_start_offset)
6123 lit_probs, 8, poffset, &range,
6129 unsigned int match_bit;
6133 if (uncompressed_offset >= dist[0] + 1)
6134 match = uncompressed[uncompressed_offset - dist[0] - 1];
6141 match_bit = match & bit;
6143 idx = bit + match_bit + sym;
6146 lit_probs + idx, poffset,
6157 while (sym < 0x100);
6160 if (
unlikely (uncompressed_offset >= uncompressed_size))
6166 uncompressed[uncompressed_offset] = (
unsigned char) sym;
6167 ++uncompressed_offset;
6170 else if (lstate <= 9)
6186 off = (off + 3) &~ (
size_t) 3;
6187 if (
unlikely (off > compressed_size))
6201 if (
unlikely (off + 4 > compressed_size))
6206 computed_crc =
elf_crc32 (0, uncompressed, uncompressed_offset);
6207 stream_crc = ((
uint32_t)compressed[off]
6208 | ((
uint32_t)compressed[off + 1] << 8)
6209 | ((
uint32_t)compressed[off + 2] << 16)
6210 | ((
uint32_t)compressed[off + 3] << 24));
6211 if (computed_crc != stream_crc)
6221 if (
unlikely (off + 8 > compressed_size))
6231 if (
unlikely (off + 32 > compressed_size))
6258 const unsigned char *compressed,
size_t compressed_size,
6260 unsigned char **uncompressed,
size_t *uncompressed_size)
6264 unsigned char check;
6269 size_t footer_offset;
6270 size_t index_offset;
6271 uint64_t index_compressed_size;
6272 uint64_t index_uncompressed_size;
6275 size_t compressed_block_size;
6281 if (
unlikely (compressed_size < header_size + footer_size))
6288 if (
unlikely (memcmp (compressed,
"\375" "7zXZ\0", 6) != 0))
6301 check = compressed[7];
6309 computed_crc =
elf_crc32 (0, compressed + 6, 2);
6310 stream_crc = ((
uint32_t)compressed[8]
6313 | ((
uint32_t)compressed[11] << 24));
6314 if (
unlikely (computed_crc != stream_crc))
6325 offset = compressed_size;
6326 if (
unlikely (memcmp (compressed + offset - 2,
"YZ", 2) != 0))
6335 if (
unlikely (compressed[offset - 2] != 0
6336 || compressed[offset - 1] !=
check))
6345 index_size = ((
size_t)compressed[offset - 4]
6346 | ((
size_t)compressed[offset - 3] << 8)
6347 | ((
size_t)compressed[offset - 2] << 16)
6348 | ((
size_t)compressed[offset - 1] << 24));
6349 index_size = (index_size + 1) * 4;
6353 computed_crc =
elf_crc32 (0, compressed + offset, 6);
6354 stream_crc = ((
uint32_t)compressed[offset - 4]
6355 | ((
uint32_t)compressed[offset - 3] << 8)
6356 | ((
uint32_t)compressed[offset - 2] << 16)
6357 | ((
uint32_t)compressed[offset - 1] << 24));
6358 if (
unlikely (computed_crc != stream_crc))
6366 if (
unlikely (offset < index_size + header_size))
6372 footer_offset = offset;
6373 offset -= index_size;
6374 index_offset = offset;
6377 if (
unlikely (compressed[offset] != 0))
6386 if (
unlikely (compressed[offset] == 0))
6388 *uncompressed = NULL;
6389 *uncompressed_size = 0;
6392 if (
unlikely (compressed[offset] != 1))
6401 &index_compressed_size))
6404 &index_uncompressed_size))
6408 offset = (offset + 3) &~ (
size_t) 3;
6411 computed_crc =
elf_crc32 (0, compressed + index_offset,
6412 offset - index_offset);
6413 stream_crc = ((
uint32_t)compressed[offset]
6414 | ((
uint32_t)compressed[offset + 1] << 8)
6415 | ((
uint32_t)compressed[offset + 2] << 16)
6416 | ((
uint32_t)compressed[offset + 3] << 24));
6417 if (
unlikely (computed_crc != stream_crc))
6425 if (
unlikely (offset != footer_offset))
6437 *uncompressed = mem;
6438 *uncompressed_size = index_uncompressed_size;
6455 mem, index_uncompressed_size, &offset))
6462 compressed_block_size = offset - 12;
6463 if (
unlikely (compressed_block_size
6464 != ((index_compressed_size + 3) &~ (
size_t) 3)))
6472 offset = (offset + 3) &~ (
size_t) 3;
6473 if (
unlikely (offset != index_offset))
6489 const unsigned char *compressed,
6490 size_t compressed_size,
6492 void *
data,
unsigned char **uncompressed,
6493 size_t *uncompressed_size)
6508 const unsigned char *memory,
size_t memory_size,
6512 fileline *fileline_fn,
int *found_sym,
int *found_dwarf,
6513 struct dwarf_data **fileline_entry,
int exe,
int debuginfo,
6514 const char *with_buildid_data,
uint32_t with_buildid_size)
6520 unsigned int shstrndx;
6522 int shdrs_view_valid;
6528 int names_view_valid;
6530 unsigned int symtab_shndx;
6531 unsigned int dynsym_shndx;
6536 int symtab_view_valid;
6538 int strtab_view_valid;
6540 int buildid_view_valid;
6541 const char *buildid_data;
6544 int debuglink_view_valid;
6545 const char *debuglink_name;
6548 int debugaltlink_view_valid;
6549 const char *debugaltlink_name;
6550 const char *debugaltlink_buildid_data;
6551 uint32_t debugaltlink_buildid_size;
6552 struct elf_view gnu_debugdata_view;
6553 int gnu_debugdata_view_valid;
6554 size_t gnu_debugdata_size;
6555 unsigned char *gnu_debugdata_uncompressed;
6556 size_t gnu_debugdata_uncompressed_size;
6561 int debug_view_valid;
6562 unsigned int using_debug_view;
6565 unsigned char split_debug_view_valid[
DEBUG_MAX];
6576 shdrs_view_valid = 0;
6577 names_view_valid = 0;
6578 symtab_view_valid = 0;
6579 strtab_view_valid = 0;
6580 buildid_view_valid = 0;
6581 buildid_data = NULL;
6583 debuglink_view_valid = 0;
6584 debuglink_name = NULL;
6586 debugaltlink_view_valid = 0;
6587 debugaltlink_name = NULL;
6588 debugaltlink_buildid_data = NULL;
6589 debugaltlink_buildid_size = 0;
6590 gnu_debugdata_view_valid = 0;
6591 gnu_debugdata_size = 0;
6592 debug_view_valid = 0;
6593 memset (&split_debug_view_valid[0], 0,
sizeof split_debug_view_valid);
6601 memcpy (&ehdr, ehdr_view.
view.
data,
sizeof ehdr);
6619#if BACKTRACE_ELF_SIZE == 32
6620#define BACKTRACE_ELFCLASS ELFCLASS32
6622#define BACKTRACE_ELFCLASS ELFCLASS64
6641 if (exe && ehdr.e_type ==
ET_DYN)
6644 shoff = ehdr.e_shoff;
6645 shnum = ehdr.e_shnum;
6646 shstrndx = ehdr.e_shstrndx;
6661 shnum = shdr->sh_size;
6665 shstrndx = shdr->sh_link;
6685 if (shnum == 0 || shstrndx == 0)
6698 shdrs_view_valid = 1;
6703 shstrhdr = &shdrs[shstrndx - 1];
6704 shstr_size = shstrhdr->
sh_size;
6710 names_view_valid = 1;
6716 memset (sections, 0,
sizeof sections);
6717 memset (zsections, 0,
sizeof zsections);
6720 for (i = 1; i < shnum; ++i)
6723 unsigned int sh_name;
6727 shdr = &shdrs[i - 1];
6735 if (sh_name >= shstr_size)
6754 if (
name[0] ==
'.' &&
name[1] ==
'z')
6770 if ((!debuginfo || with_buildid_data != NULL)
6771 && !buildid_view_valid
6772 && strcmp (
name,
".note.gnu.build-id") == 0)
6778 data, &buildid_view))
6781 buildid_view_valid = 1;
6785 && strncmp (note->
name,
"GNU", 4) == 0
6788 buildid_data = ¬e->
name[0] + ((note->
namesz + 3) & ~ 3);
6789 buildid_size = note->
descsz;
6792 if (with_buildid_size != 0)
6794 if (buildid_size != with_buildid_size)
6797 if (memcmp (buildid_data, with_buildid_data, buildid_size) != 0)
6804 && !debuglink_view_valid
6805 && strcmp (
name,
".gnu_debuglink") == 0)
6807 const char *debuglink_data;
6812 data, &debuglink_view))
6815 debuglink_view_valid = 1;
6816 debuglink_data = (
const char *) debuglink_view.
view.
data;
6818 crc_offset = (crc_offset + 3) & ~3;
6819 if (crc_offset + 4 <= shdr->
sh_size)
6821 debuglink_name = debuglink_data;
6822 debuglink_crc = *(
const uint32_t*)(debuglink_data + crc_offset);
6826 if (!debugaltlink_view_valid
6827 && strcmp (
name,
".gnu_debugaltlink") == 0)
6829 const char *debugaltlink_data;
6830 size_t debugaltlink_name_len;
6834 data, &debugaltlink_view))
6837 debugaltlink_view_valid = 1;
6838 debugaltlink_data = (
const char *) debugaltlink_view.
view.
data;
6839 debugaltlink_name = debugaltlink_data;
6840 debugaltlink_name_len =
strnlen (debugaltlink_data, shdr->
sh_size);
6841 if (debugaltlink_name_len < shdr->sh_size)
6844 debugaltlink_name_len += 1;
6846 debugaltlink_buildid_data
6847 = debugaltlink_data + debugaltlink_name_len;
6848 debugaltlink_buildid_size = shdr->
sh_size - debugaltlink_name_len;
6853 && !gnu_debugdata_view_valid
6854 && strcmp (
name,
".gnu_debugdata") == 0)
6858 data, &gnu_debugdata_view))
6861 gnu_debugdata_size = shdr->
sh_size;
6862 gnu_debugdata_view_valid = 1;
6869 && strcmp (
name,
".opd") == 0)
6889 if (symtab_shndx == 0)
6890 symtab_shndx = dynsym_shndx;
6891 if (symtab_shndx != 0)
6894 unsigned int strtab_shndx;
6898 symtab_shdr = &shdrs[symtab_shndx - 1];
6899 strtab_shndx = symtab_shdr->
sh_link;
6900 if (strtab_shndx >= shnum)
6903 "ELF symbol table strtab link out of range", 0);
6906 strtab_shdr = &shdrs[strtab_shndx - 1];
6912 symtab_view_valid = 1;
6918 strtab_view_valid = 1;
6937 symtab_view_valid = 0;
6938 strtab_view_valid = 0;
6946 shdrs_view_valid = 0;
6948 names_view_valid = 0;
6952 if (buildid_data != NULL)
6963 if (debuglink_view_valid)
6965 if (debugaltlink_view_valid)
6967 ret =
elf_add (
state,
"", d, NULL, 0, base_address, opd,
6969 found_dwarf, NULL, 0, 1, NULL, 0);
6972 else if (descriptor >= 0)
6978 if (buildid_view_valid)
6981 buildid_view_valid = 0;
6984 if (debuglink_name != NULL)
6996 if (debugaltlink_view_valid)
6998 ret =
elf_add (
state,
"", d, NULL, 0, base_address, opd,
7000 found_dwarf, NULL, 0, 1, NULL, 0);
7003 else if (descriptor >= 0)
7009 if (debuglink_view_valid)
7012 debuglink_view_valid = 0;
7016 if (debugaltlink_name != NULL)
7028 found_dwarf, &fileline_altlink, 0, 1,
7029 debugaltlink_buildid_data, debugaltlink_buildid_size);
7031 debugaltlink_view_valid = 0;
7040 if (debugaltlink_view_valid)
7043 debugaltlink_view_valid = 0;
7046 if (gnu_debugdata_view_valid)
7051 ((
const unsigned char *)
7054 &gnu_debugdata_uncompressed,
7055 &gnu_debugdata_uncompressed_size);
7058 gnu_debugdata_view_valid = 0;
7062 ret =
elf_add (
state, filename, -1, gnu_debugdata_uncompressed,
7065 found_dwarf, NULL, 0, 0, NULL, 0);
7066 if (ret >= 0 && descriptor >= 0)
7090 if (sections[i].size != 0)
7092 if (min_offset == 0 || sections[i].offset < min_offset)
7093 min_offset = sections[i].
offset;
7095 if (end > max_offset)
7097 debug_size += sections[i].
size;
7099 if (zsections[i].size != 0)
7101 if (min_offset == 0 || zsections[i].offset < min_offset)
7102 min_offset = zsections[i].
offset;
7103 end = zsections[i].
offset + zsections[i].
size;
7104 if (end > max_offset)
7106 debug_size += zsections[i].
size;
7109 if (min_offset == 0 || max_offset == 0)
7111 if (descriptor >= 0)
7122 if (max_offset - min_offset < 0x20000000
7123 || max_offset - min_offset < debug_size + 0x10000)
7129 debug_view_valid = 1;
7133 memset (&split_debug_view[0], 0,
sizeof split_debug_view);
7138 if (sections[i].
size != 0)
7139 dsec = §ions[i];
7140 else if (zsections[i].
size != 0)
7141 dsec = &zsections[i];
7147 &split_debug_view[i]))
7149 split_debug_view_valid[i] = 1;
7151 if (sections[i].
size != 0)
7152 sections[i].
data = ((
const unsigned char *)
7153 split_debug_view[i].view.data);
7155 zsections[i].
data = ((
const unsigned char *)
7156 split_debug_view[i].view.data);
7161 if (descriptor >= 0)
7168 using_debug_view = 0;
7169 if (debug_view_valid)
7173 if (sections[i].
size == 0)
7174 sections[i].
data = NULL;
7177 sections[i].
data = ((
const unsigned char *) debug_view.
view.
data
7178 + (sections[i].
offset - min_offset));
7182 if (zsections[i].
size == 0)
7183 zsections[i].
data = NULL;
7185 zsections[i].
data = ((
const unsigned char *) debug_view.
view.
data
7186 + (zsections[i].
offset - min_offset));
7192 zdebug_table = NULL;
7195 if (sections[i].
size == 0 && zsections[i].
size > 0)
7197 unsigned char *uncompressed_data;
7198 size_t uncompressed_size;
7200 if (zdebug_table == NULL)
7205 if (zdebug_table == NULL)
7209 uncompressed_data = NULL;
7210 uncompressed_size = 0;
7212 zsections[i].
size, zdebug_table,
7214 &uncompressed_data, &uncompressed_size))
7216 sections[i].
data = uncompressed_data;
7217 sections[i].
size = uncompressed_size;
7220 if (split_debug_view_valid[i])
7224 split_debug_view_valid[i] = 0;
7229 if (zdebug_table != NULL)
7233 zdebug_table = NULL;
7240 unsigned char *uncompressed_data;
7241 size_t uncompressed_size;
7246 if (zdebug_table == NULL)
7251 if (zdebug_table == NULL)
7255 uncompressed_data = NULL;
7256 uncompressed_size = 0;
7259 &uncompressed_data, &uncompressed_size))
7261 sections[i].
data = uncompressed_data;
7262 sections[i].
size = uncompressed_size;
7265 if (debug_view_valid)
7267 else if (split_debug_view_valid[i])
7270 split_debug_view_valid[i] = 0;
7274 if (zdebug_table != NULL)
7278 if (debug_view_valid && using_debug_view == 0)
7281 debug_view_valid = 0;
7302 if (shdrs_view_valid)
7304 if (names_view_valid)
7306 if (symtab_view_valid)
7308 if (strtab_view_valid)
7310 if (debuglink_view_valid)
7312 if (debugaltlink_view_valid)
7314 if (gnu_debugdata_view_valid)
7316 if (buildid_view_valid)
7318 if (debug_view_valid)
7322 if (split_debug_view_valid[i])
7327 if (descriptor >= 0)
7357 const char *filename;
7367 if (
info->dlpi_name == NULL ||
info->dlpi_name[0] ==
'\0')
7383 filename =
info->dlpi_name;
7385 pd->
data, &does_not_exist);
7390 base_address.
m =
info->dlpi_addr;
7391 if (
elf_add (pd->
state, filename, descriptor, NULL, 0, base_address, NULL,
7393 &found_dwarf, NULL, 0, 0, NULL, 0))
7427 memset (&zero_base_address, 0,
sizeof zero_base_address);
7428 ret =
elf_add (
state, filename, descriptor, NULL, 0, zero_base_address,
7430 &found_dwarf, NULL, 1, 0, NULL, 0);
7446 if (!
state->threaded)
7450 else if (
state->syminfo_fn == NULL)
7462 if (!
state->threaded)
7463 *fileline_fn =
state->fileline_fn;
7467 if (*fileline_fn == NULL || *fileline_fn ==
elf_nodebug)
7468 *fileline_fn = elf_fileline_fn;
void * backtrace_alloc(struct backtrace_state *state ATTRIBUTE_UNUSED, size_t size, backtrace_error_callback error_callback, void *data)
void backtrace_free(struct backtrace_state *state ATTRIBUTE_UNUSED, void *p, size_t size ATTRIBUTE_UNUSED, backtrace_error_callback error_callback ATTRIBUTE_UNUSED, void *data ATTRIBUTE_UNUSED)
void(* backtrace_syminfo_callback)(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize)
void(* backtrace_error_callback)(void *data, const char *msg, int errnum)
int(* backtrace_full_callback)(void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
static void error_callback(void *data, const char *msg, int errnum)
int main(int argc, char **argv)
int backtrace_dwarf_add(struct backtrace_state *state, struct libbacktrace_base_address base_address, const struct dwarf_sections *dwarf_sections, int is_bigendian, struct dwarf_data *fileline_altlink, backtrace_error_callback error_callback, void *data, fileline *fileline_fn, struct dwarf_data **fileline_entry)
struct libbacktrace_base_address base_address
static int elf_symbol_compare(const void *v1, const void *v2)
#define LZMA_DIST_SLOT(dist, slot)
#define ZSTD_DECODE_BASEBITS(baseline_basebits)
static int elf_open_debugfile_by_debuglink(struct backtrace_state *state, const char *filename, const char *debuglink_name, uint32_t debuglink_crc, backtrace_error_callback error_callback, void *data)
static void elf_nosyms(struct backtrace_state *state ATTRIBUTE_UNUSED, uintptr_t addr ATTRIBUTE_UNUSED, backtrace_syminfo_callback callback ATTRIBUTE_UNUSED, backtrace_error_callback error_callback, void *data)
static int elf_uncompress_lzma_block(const unsigned char *compressed, size_t compressed_size, unsigned char check, uint16_t *probs, unsigned char *uncompressed, size_t uncompressed_size, size_t *poffset)
static int elf_open_debugfile_by_buildid(struct backtrace_state *state, const char *buildid_data, size_t buildid_size, backtrace_error_callback error_callback, void *data)
#define ZDEBUG_TABLE_SIZE
static const struct elf_zstd_fse_baseline_entry elf_zstd_offset_table[32]
static int elf_try_debugfile(struct backtrace_state *state, const char *prefix, size_t prefix_len, const char *prefix2, size_t prefix2_len, const char *debuglink_name, backtrace_error_callback error_callback, void *data)
#define LZMA_REP_LEN_CHOICE2
#define LZMA_IS_REP2(state)
static uint32_t elf_crc32(uint32_t crc, const unsigned char *buf, size_t len)
#define LZMA_DIST_MODEL_END
static const uint32_t elf_zstd_match_length_base[]
static int phdr_callback(struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, void *pdata)
#define ZSTD_DECODE_BASELINE(baseline_basebits)
static void elf_syminfo(struct backtrace_state *state, uintptr_t addr, backtrace_syminfo_callback callback, backtrace_error_callback error_callback ATTRIBUTE_UNUSED, void *data)
#define LZMA_IS_MATCH(state, pos)
static int elf_zlib_verify_checksum(const unsigned char *checkbytes, const unsigned char *uncompressed, size_t uncompressed_size)
static uint32_t elf_crc32_file(struct backtrace_state *state, int descriptor, backtrace_error_callback error_callback, void *data)
static const uint16_t elf_zlib_default_table[0x170]
struct backtrace_state * state
#define ZLIB_HUFFMAN_BITS_MASK
#define LZMA_REP_LEN_CHOICE
static void elf_add_syminfo_data(struct backtrace_state *state, struct elf_syminfo_data *edata)
static int elf_zstd_read_fse(const unsigned char **ppin, const unsigned char *pinend, uint16_t *zdebug_table, int maxidx, struct elf_zstd_fse_entry *table, int *table_bits)
#define LZMA_MATCH_LEN_CHOICE2
static int elf_add(struct backtrace_state *state, const char *filename, int descriptor, const unsigned char *memory, size_t memory_size, struct libbacktrace_base_address base_address, struct elf_ppc64_opd_data *caller_opd, backtrace_error_callback error_callback, void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf, struct dwarf_data **fileline_entry, int exe, int debuginfo, const char *with_buildid_data, uint32_t with_buildid_size)
static int elf_zstd_make_offset_baseline_fse(const struct elf_zstd_fse_entry *fse_table, int table_bits, struct elf_zstd_fse_baseline_entry *baseline_table)
static int elf_zstd_read_literals(const unsigned char **ppin, const unsigned char *pinend, unsigned char *pout, unsigned char *poutend, uint16_t *scratch, uint16_t *huffman_table, int *phuffman_table_bits, unsigned char **pplit)
static int elf_initialize_syminfo(struct backtrace_state *state, struct libbacktrace_base_address base_address, const unsigned char *symtab_data, size_t symtab_size, const unsigned char *strtab, size_t strtab_size, backtrace_error_callback error_callback, void *data, struct elf_syminfo_data *sdata, struct elf_ppc64_opd_data *opd)
static size_t xstrnlen(const char *s, size_t maxlen)
#define LZMA_IS_REP0(state)
#define LZMA_REP_LEN_HIGH(sym)
static int elf_symbol_search(const void *vkey, const void *ventry)
static int elf_get_view(struct backtrace_state *state, int descriptor, const unsigned char *memory, size_t memory_size, off_t offset, uint64_t size, backtrace_error_callback error_callback, void *data, struct elf_view *view)
#define ZLIB_TABLE_WORK_OFFSET
#define ZLIB_HUFFMAN_SECONDARY_SHIFT
struct backtrace_view view
#define ZSTD_MATCH_LENGTH_BASELINE_OFFSET
static int elf_nodebug(struct backtrace_state *state, uintptr_t pc, backtrace_full_callback callback, backtrace_error_callback error_callback, void *data)
static int elf_is_symlink(const char *filename)
static int elf_fetch_bits_backward(const unsigned char **ppin, const unsigned char *pinend, uint64_t *pval, unsigned int *pbits)
b_elf_wxword sh_addralign
#define LZMA_DIST_MODEL_START
static const uint32_t elf_zstd_literal_length_base[]
#define LZMA_DIST_SPECIAL(dist)
static uint32_t elf_lzma_integer(const unsigned char *compressed, size_t compressed_size, uint16_t *probs, uint32_t bits, size_t *poffset, uint32_t *prange, uint32_t *pcode)
static int elf_zstd_make_match_baseline_fse(const struct elf_zstd_fse_entry *fse_table, int table_bits, struct elf_zstd_fse_baseline_entry *baseline_table)
#define ZSTD_TABLE_MATCH_FSE_OFFSET
#define ZSTD_TABLE_WORK_OFFSET
#define LZMA_MATCH_LEN_HIGH(sym)
static void elf_release_view(struct backtrace_state *state, struct elf_view *view, backtrace_error_callback error_callback, void *data)
#define LZMA_REP_LEN_MID(pos, sym)
static int elf_zstd_decompress(const unsigned char *pin, size_t sin, unsigned char *zdebug_table, unsigned char *pout, size_t sout)
struct elf_symbol * symbols
#define BACKTRACE_ELFCLASS
#define LZMA_IS_REP(state)
#define ZSTD_TABLE_HUFFMAN_OFFSET
#define ZSTD_TABLE_LITERAL_FSE_OFFSET
static int elf_fetch_backward_init(const unsigned char **ppin, const unsigned char *pinend, uint64_t *pval, unsigned int *pbits)
int backtrace_uncompress_zdebug(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, backtrace_error_callback error_callback, void *data, unsigned char **uncompressed, size_t *uncompressed_size)
static int elf_zlib_inflate_table(unsigned char *codes, size_t codes_len, uint16_t *zdebug_table, uint16_t *table)
static char * elf_readlink(struct backtrace_state *state, const char *filename, backtrace_error_callback error_callback, void *data, size_t *plen)
static const char *const dwarf_section_names[DEBUG_MAX]
struct elf_syminfo_data * next
static uint32_t elf_lzma_len(const unsigned char *compressed, size_t compressed_size, uint16_t *probs, int is_rep, unsigned int pos_state, size_t *poffset, uint32_t *prange, uint32_t *pcode)
const char * exe_filename
#define ZSTD_LITERAL_LENGTH_BASELINE_OFFSET
static int elf_lzma_varint(const unsigned char *compressed, size_t compressed_size, size_t *poffset, uint64_t *val)
#define LZMA_MATCH_LEN_CHOICE
int backtrace_uncompress_lzma(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, backtrace_error_callback error_callback, void *data, unsigned char **uncompressed, size_t *uncompressed_size)
static int elf_zstd_unpack_seq_decode(int mode, const unsigned char **ppin, const unsigned char *pinend, const struct elf_zstd_fse_baseline_entry *predef, int predef_bits, uint16_t *scratch, int maxidx, struct elf_zstd_fse_baseline_entry *table, int table_bits, int(*conv)(const struct elf_zstd_fse_entry *, int, struct elf_zstd_fse_baseline_entry *), struct elf_zstd_seq_decode *decode)
static int elf_lzma_bit(const unsigned char *compressed, size_t compressed_size, uint16_t *prob, size_t *poffset, uint32_t *prange, uint32_t *pcode)
static int elf_uncompress_zdebug(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, uint16_t *zdebug_table, backtrace_error_callback error_callback, void *data, unsigned char **uncompressed, size_t *uncompressed_size)
static uint32_t elf_lzma_reverse_integer(const unsigned char *compressed, size_t compressed_size, uint16_t *probs, uint32_t bits, size_t *poffset, uint32_t *prange, uint32_t *pcode)
#define ZLIB_TABLE_CODELEN_OFFSET
#define LZMA_IS_REP1(state)
static int elf_find_debugfile_by_debuglink(struct backtrace_state *state, const char *filename, const char *debuglink_name, backtrace_error_callback error_callback, void *data)
#define LZMA_IS_REP0_LONG(state, pos)
static int elf_uncompress_chdr(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, uint16_t *zdebug_table, backtrace_error_callback error_callback, void *data, unsigned char **uncompressed, size_t *uncompressed_size)
#define LZMA_PROB_TOTAL_COUNT
int backtrace_uncompress_zstd(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, backtrace_error_callback error_callback, void *data, unsigned char *uncompressed, size_t uncompressed_size)
static const struct elf_zstd_fse_baseline_entry elf_zstd_match_table[64]
static int elf_zlib_inflate_and_verify(const unsigned char *pin, size_t sin, uint16_t *zdebug_table, unsigned char *pout, size_t sout)
static int elf_zstd_make_literal_baseline_fse(const struct elf_zstd_fse_entry *fse_table, int table_bits, struct elf_zstd_fse_baseline_entry *baseline_table)
#define LZMA_LITERAL(code, size)
static int elf_zstd_build_fse(const int16_t *, int, uint16_t *, int, struct elf_zstd_fse_entry *)
#define LZMA_MATCH_LEN_MID(pos, sym)
static void elf_uncompress_failed(void)
#define ZSTD_TABLE_OFFSET_FSE_OFFSET
#define ZLIB_HUFFMAN_VALUE_MASK
const struct elf_zstd_fse_baseline_entry * table
#define ZSTD_ENCODE_BASELINE_BITS(baseline, basebits)
#define SYSTEM_BUILD_ID_DIR
#define ZLIB_HUFFMAN_TABLE_SIZE
backtrace_error_callback error_callback
static const struct elf_zstd_fse_baseline_entry elf_zstd_lit_table[64]
static const uint16_t elf_zlib_default_dist_table[0x100]
#define ZLIB_HUFFMAN_BITS_SHIFT
static int elf_zlib_inflate(const unsigned char *pin, size_t sin, uint16_t *zdebug_table, unsigned char *pout, size_t sout)
#define LZMA_REP_LEN_LOW(pos, sym)
static int elf_fetch_bits(const unsigned char **ppin, const unsigned char *pinend, uint64_t *pval, unsigned int *pbits)
#define LZMA_DIST_ALIGN(dist)
#define __builtin_prefetch(p, r, l)
static void elf_lzma_range_normalize(const unsigned char *compressed, size_t compressed_size, size_t *poffset, uint32_t *prange, uint32_t *pcode)
int backtrace_initialize(struct backtrace_state *state, const char *filename, int descriptor, backtrace_error_callback error_callback, void *data, fileline *fileline_fn)
static int elf_zstd_read_huff(const unsigned char **ppin, const unsigned char *pinend, uint16_t *zdebug_table, uint16_t *table, int *ptable_bits)
#define LZMA_MATCH_LEN_LOW(pos, sym)
static int elf_uncompress_lzma(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, backtrace_error_callback error_callback, void *data, unsigned char **uncompressed, size_t *uncompressed_size)
void backtrace_syminfo_to_full_callback(void *data, uintptr_t pc, const char *symname, uintptr_t symval ATTRIBUTE_UNUSED, uintptr_t symsize ATTRIBUTE_UNUSED)
void backtrace_syminfo_to_full_error_callback(void *data, const char *msg, int errnum)
void backtrace_qsort(void *base, size_t count, size_t size, int(*compar)(const void *, const void *))
void backtrace_release_view(struct backtrace_state *state, struct backtrace_view *view, backtrace_error_callback error_callback, void *data)
#define ATTRIBUTE_FALLTHROUGH
#define backtrace_atomic_load_pointer(p)
int(* fileline)(struct backtrace_state *state, uintptr_t pc, backtrace_full_callback callback, backtrace_error_callback error_callback, void *data)
#define libbacktrace_add_base(pc, base)
const unsigned char * data[DEBUG_MAX]
int backtrace_close(int descriptor, backtrace_error_callback error_callback, void *data)
#define libbacktrace_using_fdpic()
#define backtrace_atomic_store_pointer(p, v)
int backtrace_get_view(struct backtrace_state *state, int descriptor, off_t offset, uint64_t size, backtrace_error_callback error_callback, void *data, struct backtrace_view *view)
int backtrace_open(const char *filename, backtrace_error_callback error_callback, void *data, int *does_not_exist)
#define __sync_bool_compare_and_swap(A, B, C)
static fr_radius_decode_fail_t decode(TALLOC_CTX *ctx, fr_pair_list_t *reply, uint8_t *response_code, bio_handle_t *h, request_t *request, bio_request_t *u, uint8_t const request_authenticator[static RADIUS_AUTH_VECTOR_LENGTH], uint8_t *data, size_t data_len)
Decode response packet data, extracting relevant information and validating the packet.
const unsigned char * data
fr_aka_sim_id_type_t type
void check(const char *name, int index, const struct info *all, int want_lineno, const char *want_function, const char *want_file, int *failed)
const char * base(const char *p)
static const char * names[8]
Functions to help with cleanup.
#define add(_type, _out, _in)