From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 730B73857C59 for ; Mon, 28 Sep 2020 07:37:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 730B73857C59 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 65CF03000A21; Mon, 28 Sep 2020 09:37:15 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 1CD114708673; Mon, 28 Sep 2020 09:37:15 +0200 (CEST) From: Mark Wielaard To: dwz@sourceware.org Cc: Mark Wielaard Subject: [PATCH] Add write_sleb129 and size_of_sleb128 for writing DW_FORM_implicit_const Date: Mon, 28 Sep 2020 09:36:47 +0200 Message-Id: <20200928073647.4629-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2020 07:37:19 -0000 We were writing out the DW_FORM_implicit_const value as uleb128, but it should be written out as sleb128 (as we already read it). I'll merge this into my experimental DW_FORM_implicit_const patch. The DW_FORM_implicit_const value is a signed 64bit sleb128 number. * dwz.c (write_sleb128): New macro. (size_of_sleb128): New function. --- dwz.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/dwz.c b/dwz.c index d730f98..e772954 100644 --- a/dwz.c +++ b/dwz.c @@ -399,6 +399,25 @@ typedef struct } \ while (0) +#define write_sleb128(ptr, val) \ + do \ + { \ + int64_t valv = (val); \ + bool more; \ + do \ + { \ + unsigned char c = (valv & 0x7f); \ + valv >>= 7; \ + more = !((((valv == 0) && ((c & 0x40) == 0)) \ + || ((valv == -1) && ((c & 0x40) != 0)))); \ + if (more) \ + c |= 0x80; \ + *ptr++ = c; \ + } \ + while (more); \ + } \ + while (0) + /* Macro to skip a uleb128 or sleb128 number and update ptr to the end of the number. */ #define skip_leb128(ptr) \ @@ -8991,6 +9010,24 @@ size_of_uleb128 (uint64_t val) return size; } +/* Return number of bytes needed to encode VAL using + sleb128. */ +static unsigned int +size_of_sleb128 (int64_t val) +{ + unsigned int size = 0; + unsigned char b; + do + { + b = (val & 0x7f); + val >>= 7; + size++; + } + while (!(((val == 0) && ((b & 0x40) == 0)) + || ((val == -1) && ((b & 0x40) != 0)))); + return size; +} + /* Hash table mapping original file IDs to new ids. */ static htab_t line_htab; /* Current new maximum file ID. */ @@ -11011,7 +11048,7 @@ compute_abbrevs (DSO *dso) uint64_t value = arr[i]->attr[j].value; arr[i]->attr[j].value = line_htab_lookup (cu, value); } - abbrev_size += size_of_uleb128 (arr[i]->attr[j].value); + abbrev_size += size_of_sleb128 (arr[i]->attr[j].value); } } abbrev_size += 2; @@ -11104,7 +11141,7 @@ write_abbrev (void) write_uleb128 (ptr, arr[i]->attr[j].attr); write_uleb128 (ptr, arr[i]->attr[j].form); if (arr[i]->attr[j].form == DW_FORM_implicit_const) - write_uleb128 (ptr, arr[i]->attr[j].value); + write_sleb128 (ptr, arr[i]->attr[j].value); } *ptr++ = 0; *ptr++ = 0; -- 2.18.4