From patchwork Tue Mar 28 20:09:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 76242 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2476596vqo; Tue, 28 Mar 2023 13:10:41 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+c/RdAAZqQz5/y+7gD2fbU7HehOBDropAFCk5kiX2JDtG9c+RMBVmq87YN8SL3McaFxbz X-Received: by 2002:a05:6402:1841:b0:4fc:782c:dca3 with SMTP id v1-20020a056402184100b004fc782cdca3mr17382837edy.28.1680034241477; Tue, 28 Mar 2023 13:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680034241; cv=none; d=google.com; s=arc-20160816; b=rAsETYCYLnXEfm2xhSnpNnljcxN3zNiLNw5eIIPqLxZr5FVc/G+I9Z+drWUwoHexmx 1No6LX3b+fcTtL0lvnK1pDmrDwMpo30+5bDVXcEnm3F0A55PcSLpVpXDMh/dVJt8A0Vi FjVed+9JLapjqrRqhpCKdDgQaZ3+SnZrDQ4ZmfQ035GzhBygrPt6+gTcBydi9/nNSrHC N85/f9jIs0T7ZbMyNEUrab7wPui1Cipd4rEeVBJyFPpS6/z2v8S+nYLHVbOnwCwFj0ig bfJ9vY5d5JHl2VlFPPcW3J5l0z9cmcYFDm+qfdhdt1JE6lBAk6MMLqtJMjYsU8+5lXOC IHsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=zrWcQG0z8hbX6PKohD5J18IV0meIS0g2rOvaRDTUR1E=; b=P1C9AKSvQHIwK0kK2MwOb/5moqd0Rc4ivJsvLjVMm/OEb4poSa0so6gVo6+OjVnlqJ EOYjh3hDAlAYUm6jpbG+moGjlAZdWW+JcKhJM55bC8VObIydDdqXI5hs8SDJlz4JFb/X oYfrEgpy9LCae9T9q8JXq2uiF5Ij6SWYW3R6dDbxfAc3ItO/suI8oknXic+RVTfeNk41 PiZR4g06alHZJQ8WriKq6sCi0qiIMrY6qwlRTroMT0Y/cJrN34kpVis2zxb9PLaMkddk S0f1xdK0Eyph4e06a8zVQdgKGpq6+T7+Vit39T/E32F7tKZp4BWW3JlTBAfP2fLzQCzP a85g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OOW9s8R7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w10-20020aa7da4a000000b004acd3188052si31604806eds.558.2023.03.28.13.10.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 13:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OOW9s8R7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25D9A385B501 for ; Tue, 28 Mar 2023 20:10:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25D9A385B501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680034240; bh=zrWcQG0z8hbX6PKohD5J18IV0meIS0g2rOvaRDTUR1E=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OOW9s8R7CU6+nOKszmqyWC9RfWKhdCcN9nWUKVoP3Br3HY5NHbx8piOdmEB1FjKxX ozvKv+wUqJyHSZtSylyjfcxEdYJ85jIDk8uedvRrc0Cp/D4D9RZAzhqp9W7tttKDZx uYpiQ/4ErItuvcbzBkBe7FWo+IFsIcoIX+wjbTno= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 456B33858C54 for ; Tue, 28 Mar 2023 20:09:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 456B33858C54 Received: by mail-pg1-x52b.google.com with SMTP id y19so7961464pgk.5 for ; Tue, 28 Mar 2023 13:09:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680034193; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zrWcQG0z8hbX6PKohD5J18IV0meIS0g2rOvaRDTUR1E=; b=ecd8CNNOp83hGO2e3p3PyLHGJMIC5Kg8WSxSN9on/Imiw0aHzRg8e33tiLfGacomhT 7mScnmSxaq/7hazjz5VxKPsU5H0mxmr2myr1oN/99aY2AcTD6ppk3BoKYS8lQ/xn3czB Q+FeAvZKX3XifglLDsM31SaSIYAYwmwaJsQhTjHD6ropDHfWqmdI04ODiFC92Q+9iCQ/ Fo9ZKZo0XunWQY73L0TK0Ji3gy1U8g1q9Zvdu8azdsF4PZuk9/qfz3SeetOzKQU+Xqiy /aFpKgyHkvalGg79ce/QaQkd1rXSfjznBGWdJqzVDwvHJMIFL21PAdS0ZTgEZSeRa3Su 9F0Q== X-Gm-Message-State: AAQBX9dDo1kjpSlml2mDRC3Tc+WidzQhJixP/cQvoclcyVr1InkAbcEf 5hjYlBP6Oc7U85JTRcdKHt9i57wZEQzUmU3/FtatiamEKbxBWendA0c= X-Received: by 2002:aa7:88c9:0:b0:5f1:b1:6dc4 with SMTP id k9-20020aa788c9000000b005f100b16dc4mr8255969pff.3.1680034193280; Tue, 28 Mar 2023 13:09:53 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 28 Mar 2023 13:09:42 -0700 Message-ID: Subject: libbacktrace patch committed: Tweaks to zstd decompression To: gcc-patches X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761643584490668737?= X-GMAIL-MSGID: =?utf-8?q?1761643584490668737?= In looking over the recently committed support for zstd decompression in libbacktrace, I found a few minor cases that needed fixing. Bootstrapped and tested on x86_64-pc-linux-gnu. Committed to mainline. Ian * elf.c (elf_zstd_read_fse): Call elf_fetch_bits after reading bits, not before. Add unlikely for error case. (elf_zstd_offset_table): Regenerate. (elf_zstd_read_huff): Clear 13 entries in weight_mark, not 12. (elf_zstd_read_literals): For a single stream adjust by total_streams_size, not compressed_size. 2e71f05403c36d25216107a7ae43c7055a282d73 diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index efd509bba6b..665b3dd1a53 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -2806,18 +2806,18 @@ elf_zstd_read_fse (const unsigned char **ppin, const unsigned char *pinend, while ((val & 0xfff) == 0xfff) { zidx += 3 * 6; - if (!elf_fetch_bits (&pin, pinend, &val, &bits)) - return 0; val >>= 12; bits -= 12; + if (!elf_fetch_bits (&pin, pinend, &val, &bits)) + return 0; } while ((val & 3) == 3) { zidx += 3; - if (!elf_fetch_bits (&pin, pinend, &val, &bits)) - return 0; val >>= 2; bits -= 2; + if (!elf_fetch_bits (&pin, pinend, &val, &bits)) + return 0; } /* We have at least 13 bits here, don't need to fetch. */ zidx += val & 3; @@ -2947,7 +2947,7 @@ elf_zstd_build_fse (const int16_t *norm, int idx, uint16_t *next, pos = (pos + step) & mask; } } - if (pos != 0) + if (unlikely (pos != 0)) { elf_uncompress_failed (); return 0; @@ -3423,17 +3423,17 @@ static const struct elf_zstd_fse_baseline_entry elf_zstd_match_table[64] = static const struct elf_zstd_fse_baseline_entry elf_zstd_offset_table[32] = { - { 1, 0, 5, 0 }, { 64, 6, 4, 0 }, { 512, 9, 5, 0 }, - { 32768, 15, 5, 0 }, { 2097152, 21, 5, 0 }, { 8, 3, 5, 0 }, - { 128, 7, 4, 0 }, { 4096, 12, 5, 0 }, { 262144, 18, 5, 0 }, - { 8388608, 23, 5, 0 }, { 32, 5, 5, 0 }, { 256, 8, 4, 0 }, - { 16384, 14, 5, 0 }, { 1048576, 20, 5, 0 }, { 4, 2, 5, 0 }, - { 128, 7, 4, 16 }, { 2048, 11, 5, 0 }, { 131072, 17, 5, 0 }, - { 4194304, 22, 5, 0 }, { 16, 4, 5, 0 }, { 256, 8, 4, 16 }, - { 8192, 13, 5, 0 }, { 524288, 19, 5, 0 }, { 2, 1, 5, 0 }, - { 64, 6, 4, 16 }, { 1024, 10, 5, 0 }, { 65536, 16, 5, 0 }, - { 268435456, 28, 5, 0 }, { 134217728, 27, 5, 0 }, { 67108864, 26, 5, 0 }, - { 33554432, 25, 5, 0 }, { 16777216, 24, 5, 0 }, + { 1, 0, 5, 0 }, { 61, 6, 4, 0 }, { 509, 9, 5, 0 }, + { 32765, 15, 5, 0 }, { 2097149, 21, 5, 0 }, { 5, 3, 5, 0 }, + { 125, 7, 4, 0 }, { 4093, 12, 5, 0 }, { 262141, 18, 5, 0 }, + { 8388605, 23, 5, 0 }, { 29, 5, 5, 0 }, { 253, 8, 4, 0 }, + { 16381, 14, 5, 0 }, { 1048573, 20, 5, 0 }, { 1, 2, 5, 0 }, + { 125, 7, 4, 16 }, { 2045, 11, 5, 0 }, { 131069, 17, 5, 0 }, + { 4194301, 22, 5, 0 }, { 13, 4, 5, 0 }, { 253, 8, 4, 16 }, + { 8189, 13, 5, 0 }, { 524285, 19, 5, 0 }, { 2, 1, 5, 0 }, + { 61, 6, 4, 16 }, { 1021, 10, 5, 0 }, { 65533, 16, 5, 0 }, + { 268435453, 28, 5, 0 }, { 134217725, 27, 5, 0 }, { 67108861, 26, 5, 0 }, + { 33554429, 25, 5, 0 }, { 16777213, 24, 5, 0 }, }; /* Read a zstd Huffman table and build the decoding table in *TABLE, reading @@ -3618,7 +3618,7 @@ elf_zstd_read_huff (const unsigned char **ppin, const unsigned char *pinend, } weight_mark = (uint32_t *) (weights + 256); - memset (weight_mark, 0, 12 * sizeof (uint32_t)); + memset (weight_mark, 0, 13 * sizeof (uint32_t)); weight_mask = 0; for (i = 0; i < count; ++i) { @@ -3685,7 +3685,7 @@ elf_zstd_read_huff (const unsigned char **ppin, const unsigned char *pinend, /* Change WEIGHT_MARK from a count of weights to the index of the first symbol for that weight. We shift the indexes to also store how many we - hae seen so far, below. */ + have seen so far, below. */ { uint32_t next; @@ -3766,7 +3766,7 @@ elf_zstd_read_literals (const unsigned char **ppin, { int raw; - /* Raw_literals_Block or RLE_Literals_Block */ + /* Raw_Literals_Block or RLE_Literals_Block */ raw = (hdr & 3) == 0; @@ -3948,7 +3948,7 @@ elf_zstd_read_literals (const unsigned char **ppin, unsigned int bits; uint32_t i; - pback = pin + compressed_size - 1; + pback = pin + total_streams_size - 1; pbackend = pin; if (!elf_fetch_backward_init (&pback, pbackend, &val, &bits)) return 0;