From patchwork Mon May 14 13:36:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 912931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477640-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XZYeRY40"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40l1vF36GMz9s0q for ; Mon, 14 May 2018 23:36:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=ZS67OMyOx+sF g8nCh5hsDpgg7jxMzKTP9DiewUxVo3cRChuovfREysZSVkXSCarfhN6rcpZsi1rz 6Y8Vz0+7cSMvOrVJG7rbF3bFbumLwiQbsY2nz4XZCPGU49Ba+/Gf63FjavOACOwH /0zV47mS85niigA0IhM1KqlDPxx1U34= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=GXWI6goxQhj5mZ6eMD mNzU8rPdM=; b=XZYeRY40BY6N4aIdTK2rQCAEiooBh50NOqzvm6Aqb8htdOwC+K 3KYhgeEPyK0eGKAb8Ktpd8v0ezdDUP9S58mlHKzgLlSP8IEhVFAE6ADcRDKqSptx 0Y+Omm95rY0sjXLRC0JUojm2IoUNp0qs89ANCZyRZxJQZMS4hqotLZj/E= Received: (qmail 112817 invoked by alias); 14 May 2018 13:36:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 112475 invoked by uid 89); 14 May 2018 13:36:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 May 2018 13:36:32 +0000 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 AADD1302BB04; Mon, 14 May 2018 15:36:30 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id A4573413CD4B; Mon, 14 May 2018 15:36:30 +0200 (CEST) From: Mark Wielaard To: gcc-patches@gcc.gnu.org Cc: Mark Wielaard Subject: [PATCH] DWARF calculate the number of indexed addresses. Date: Mon, 14 May 2018 15:36:24 +0200 Message-Id: <1526304984-22682-1-git-send-email-mark@klomp.org> The length in the .debug_addr unit header was calculated using the number of elements in the addr_index_table. This is wrong because the entries in the table are refcounted and only those with a refcount > 0 are actually put in the index. Add a helper function count_index_addrs to get the correct number of addresses in the index. gcc/ChangeLog: * dwarf2out.c (count_index_addrs): New function. (dwarf2out_finish): Use count_index_addrs to calculate addrs_length. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 9c1d7c4..c05bfe4 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -28898,6 +28898,19 @@ output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index) return 1; } +/* A helper function for dwarf2out_finish. Counts the number + of indexed addresses. Must match the logic of the functions + output_addr_table_entry above. */ +int +count_index_addrs (addr_table_entry **slot, unsigned int *last_idx) +{ + addr_table_entry *entry = *slot; + + if (entry->refcount > 0) + *last_idx += 1; + return 1; +} + /* Produce the .debug_addr section. */ static void @@ -31393,8 +31406,12 @@ dwarf2out_finish (const char *) DWARF5 specifies a small header when address tables are used. */ if (dwarf_version >= 5) { - unsigned long addrs_length - = addr_index_table->elements () * DWARF2_ADDR_SIZE + 4; + unsigned int last_idx = 0; + unsigned long addrs_length; + + addr_index_table->traverse_noresize + (&last_idx); + addrs_length = last_idx * DWARF2_ADDR_SIZE + 4; if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) dw2_asm_output_data (4, 0xffffffff,