From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27291 invoked by alias); 27 Nov 2019 18:16:39 -0000 Mailing-List: contact dwz-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: dwz-owner@sourceware.org Received: (qmail 27281 invoked by uid 89); 27 Nov 2019 18:16:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=16384 X-Spam-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: mx1.suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Date: Tue, 01 Jan 2019 00:00:00 -0000 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com Subject: [committed] Fix assertion 'off == cu_size' in recompute_abbrevs Message-ID: <20191127181632.GA30773@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-q4/txt/msg00086.txt.bz2 Hi, With an executable from PR25024, we manage to reproduce PR24764: ... $ dwz -l0 clang-offload-bundler-10.0.0-0.20190817snap5.fc30.x86_64.debug dwz: dwz.c:9920: recompute_abbrevs: Assertion `off == cu_size' failed. Aborted (core dumped) ... The problem is that the cu_size as computed during recompute_abbrevs is not the same as was computed before during compute_abbrevs. I tracked down the first DIE in the CU that has a different size, at 0xdf615: ... <5>: Abbrev Number: 65 (DW_TAG_formal_parameter) DW_AT_type : <0xe33be> DW_AT_artificial : 1 ... Using a debug patch, we can track the size of the DIE during compute_abbrevs: ... init_new_die_offsets: intracusize: 2 init_new_die_offsets: start die_size: 0 init_new_die_offsets: add DIE code size to die_size: 1 init_new_die_offsets: add nr_refs * intracusize to die_size: 3 update_new_die_offsets: die_size: 3 update_new_die_offsets: die_size: 3 finalize_new_die_offsets: die_size: 3 ... and recompute_abbrevs: ... init_new_die_offsets: intracusize: 3 init_new_die_offsets: start die_size: 0 init_new_die_offsets: add DIE code size to die_size: 1 init_new_die_offsets: add nr_refs * intracusize to die_size: 4 update_new_die_offsets: die_size: 4 update_new_die_offsets: die_size: 4 update_new_die_offsets: die_size: 4 finalize_new_die_offsets: die_size: 4 ... The difference starts in init_new_die_offsets, when adding intracusize, which is different for compute_abbrevs and recompute_abbrevs (2 vs. 3). The code in recompute_abbrevs that calculates intracusize for the relevant init_new_die_offsets call is: ... /* Need to be conservatively high estimate, as update_new_die_offsets relies on the offsets always decreasing. cu_size at this point is the size we will end up with in the end, but if cu_size is sufficiently close (from bottom) to some uleb128 boundary (say 16384), init_new_die_offsets might return off above that boundary and then update_new_die_offsets might fail its assertions on reference to DIEs that crossed the uleb128 boundary. */ intracusize = size_of_uleb128 (2 * cu_size); off = init_new_die_offsets (cu->cu_die, headersz, intracusize); ... where the '2 * cu_size' is the result of commit d16aa5e "Fix up recompute_abbrevs if cu_size is close below an uleb128 boundary and init_new_die_offsets would return offset above that uleb128 boundary": ... - intracusize = size_of_uleb128 (cu_size); + intracusize = size_of_uleb128 (2 * cu_size); ... Reverting commit d16aa5e gets us an intracusize of 2 in recompute_abbrevs, and fixes the assert. However, doing so reintroduces the assertion that was fixed by the commit (at least, provided commit a4668e1 "Fix assertion failure in create_import_tree" is also reverted): ... $ dwz -l0 inkview.debug dwz: dwz.c:8527: update_new_die_offsets: Assertion \ `die->u.p2.die_intracu_udata_size >= intracu_udata_size' failed. Aborted (core dumped) ... Fix the 'off == cu_size' assert (without introducing the regression for inkview.debug) by: - saving the intracusize used for the call to init_new_die_offsets in compute_abbrevs, and - reusing the saved intracusize for the call to init_new_die_offsets in recompute_abbrevs. Also tested with clang and CheckerOptionHandlingAnalyzerPlugin.so, for which this PR also triggered. Committed to trunk. Thanks, - Tom Fix assertion 'off == cu_size' in recompute_abbrevs 2019-11-27 Tom de Vries PR dwz/24764 * dwz.c (struct dw_cu): Add initial_intracusize field. (compute_abbrevs): Initalize initial_intracusize. (recompute_abbrevs): Use initial_intracusize. --- dwz.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dwz.c b/dwz.c index 8d62444..36b54d8 100644 --- a/dwz.c +++ b/dwz.c @@ -689,6 +689,9 @@ struct dw_cu unsigned int cu_chunk; /* Form chosen for intra-cu references. */ enum dwarf_form cu_intracu_form; + /* Intracusize argument to init_new_die_offsets. Set in compute_abbrevs, + used in recompute_abbrevs. */ + unsigned int initial_intracusize; }; /* Internal representation of a debugging information entry (DIE). @@ -8737,6 +8740,7 @@ compute_abbrevs (DSO *dso) intracusize = i; } while (1); + cu->initial_intracusize = intracusize; off = init_new_die_offsets (cu->cu_die, headersz, intracusize); do { @@ -9889,14 +9893,7 @@ recompute_abbrevs (dw_cu_ref cu, unsigned int cu_size) } else { - /* Need to be conservatively high estimate, as update_new_die_offsets - relies on the offsets always decreasing. cu_size at this point is - the size we will end up with in the end, but if cu_size is - sufficiently close (from bottom) to some uleb128 boundary (say - 16384), init_new_die_offsets might return off above that boundary - and then update_new_die_offsets might fail its assertions on - reference to DIEs that crossed the uleb128 boundary. */ - intracusize = size_of_uleb128 (2 * cu_size); + intracusize = cu->initial_intracusize; off = init_new_die_offsets (cu->cu_die, headersz, intracusize); do