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 3AF46385800D for ; Fri, 5 Mar 2021 00:34:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3AF46385800D 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 librem (deer0x15.wildebeest.org [172.31.17.151]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 757CF304319F; Fri, 5 Mar 2021 01:34:10 +0100 (CET) Received: by librem (Postfix, from userid 1000) id 7664AC1869; Fri, 5 Mar 2021 01:32:56 +0100 (CET) Date: Fri, 5 Mar 2021 01:32:56 +0100 From: Mark Wielaard To: Tom de Vries Cc: dwz@sourceware.org, jakub@redhat.com Subject: Re: [PATCH] Fix .debug_line reference above end of section Message-ID: <20210305003256.GM3014@wildebeest.org> References: <20210302135713.GA22526@delia> <20210304003357.GL3014@wildebeest.org> <9bda5bfa-b2dc-84e5-df99-0c62929b934b@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9bda5bfa-b2dc-84e5-df99-0c62929b934b@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, 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: Fri, 05 Mar 2021 00:34:14 -0000 Hi Tom, On Thu, Mar 04, 2021 at 09:33:43AM +0100, Tom de Vries wrote: > On 3/4/21 1:33 AM, Mark Wielaard wrote: > > I was unable to replicate this, so it is a little harder to comment in > > this. I don't fully understand why this happens, is this because of > > something in the input file or because we move all DIEs with file > > attributes? > > > > This is because all the DIEs from the input file that are written into > the unoptimized multifile don't have any attributes referring to the > file table. > > > Would it be possible to attach the various temp files to the bug > > report? > > > > Done. Thanks. It turns out I was confused because I was using eu-readelf and that doesn't handle DWARF Units which contain zero DIEs. I'll write a patch for elfutils. > > This does look technically OK. write_multifile_line does handle line_htab == NULL > > correctly and sets up multi_line_off which will be used to write the > > DW_AT_stmt_list. > > > > But if the CU doesn't have a DW_AT_stmt_list this will produce an > > unnecessary line table (stub). > > Ack. The fix is conservative. > > > I cannot immediately see whether this > > is an odd corner case that normally wouldn't happen in practice or if > > that could happen more often. > > I've seen this error before, so it's not completely cornercase. I tried to come up with something different, but your fix is much simpler. So please push what you have. This is what I came up with, which makes sure there always is a line_htab, even if it is empty. But even in write_unit_die we don't yet know if there will be actual files. So we still end up writing the DW_AT_stmt_list with the current multi_line_off, so we must produce a debug_line entry anyway. diff --git a/dwz.c b/dwz.c index af1c5af..c493c1d 100644 --- a/dwz.c +++ b/dwz.c @@ -9929,6 +9929,16 @@ line_eq (const void *p, const void *q) return s1->file->time == s2->file->time && s1->file->size == s2->file->size; } +static htab_t +line_htab_create (void) +{ + htab_t htab = htab_try_create (50, line_hash, line_eq, NULL); + if (htab == NULL) + dwz_oom (); + max_line_id = 1; + return htab; +} + /* Map original file ID to new file ID. */ static unsigned int line_htab_lookup (dw_cu_ref cu, unsigned int id) @@ -9947,12 +9957,7 @@ line_htab_lookup (dw_cu_ref cu, unsigned int id) if (le.file->dir) h = iterative_hash (le.file->dir, strlen (le.file->dir) + 1, h); if (line_htab == NULL) - { - line_htab = htab_try_create (50, line_hash, line_eq, NULL); - if (line_htab == NULL) - dwz_oom (); - max_line_id = 1; - } + line_htab = line_htab_create (); le.hash = h; slot = htab_find_slot_with_hash (line_htab, &le, h, INSERT); if (slot == NULL) @@ -12222,7 +12227,11 @@ write_unit_die (unsigned char *ptr, dw_die_ref die, dw_die_ref origin) assert (p && (form == DW_FORM_sec_offset || form == DW_FORM_data4)); if (wr_multifile) - write_32 (ptr, multi_line_off); + { + write_32 (ptr, multi_line_off); + if (line_htab == NULL) + line_htab = line_htab_create (); + } else if (op_multifile) write_32 (ptr, 0); else Cheers, Mark