From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 72998386F038 for ; Tue, 29 Sep 2020 08:24:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 72998386F038 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-198-APXoj8r6MBy35J5rKKmbRA-1; Tue, 29 Sep 2020 04:24:20 -0400 X-MC-Unique: APXoj8r6MBy35J5rKKmbRA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A6291882FD6; Tue, 29 Sep 2020 08:24:19 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-37.ams2.redhat.com [10.36.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 155535D9CA; Tue, 29 Sep 2020 08:24:18 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 08T8OGDO008372; Tue, 29 Sep 2020 10:24:17 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 08T8OFQn008371; Tue, 29 Sep 2020 10:24:15 +0200 Date: Tue, 29 Sep 2020 10:24:15 +0200 From: Jakub Jelinek To: Mark Wielaard Cc: dwz@sourceware.org Subject: Re: [PATCH] Add write_sleb129 and size_of_sleb128 for writing DW_FORM_implicit_const Message-ID: <20200929082415.GW2176@tucnak> Reply-To: Jakub Jelinek References: <20200928073647.4629-1-mark@klomp.org> MIME-Version: 1.0 In-Reply-To: <20200928073647.4629-1-mark@klomp.org> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Tue, 29 Sep 2020 08:24:23 -0000 On Mon, Sep 28, 2020 at 09:36:47AM +0200, Mark Wielaard wrote: > 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. Besides s/129/128 in the title as mentioned by Florian: > * 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); \ The parens above are unnecessary. > + valv >>= 7; \ > + more = !((((valv == 0) && ((c & 0x40) == 0)) \ > + || ((valv == -1) && ((c & 0x40) != 0)))); \ And this has even more unnecessary parens. Either more = ((valv != 0 || (c & 0x40) != 0) \ && (valv != -1 || (c & 0x40) == 0)); \ or perhaps more = (valv + (uint64_t) 1 > 1 \ || ((c ^ valv) & 0x40) != 0); \ ? > +/* 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); Ditto. > + val >>= 7; > + size++; > + } > + while (!(((val == 0) && ((b & 0x40) == 0)) > + || ((val == -1) && ((b & 0x40) != 0)))); Ditto. Otherwise LGTM. Jakub