From patchwork Tue Jul 26 20:38:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 106936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 7EBACB6F8D for ; Wed, 27 Jul 2011 06:38:29 +1000 (EST) Received: (qmail 1331 invoked by alias); 26 Jul 2011 20:38:27 -0000 Received: (qmail 1269 invoked by uid 22791); 26 Jul 2011 20:38:26 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Jul 2011 20:38:11 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6QKcBmd023724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Jul 2011 16:38:11 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6QKcAUD011564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Jul 2011 16:38:11 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p6QKcAKM026165; Tue, 26 Jul 2011 22:38:10 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p6QKc9bj026163; Tue, 26 Jul 2011 22:38:09 +0200 Date: Tue, 26 Jul 2011 22:38:09 +0200 From: Jakub Jelinek To: Richard Henderson , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix one .debug_macro bug and fix -g3 on non-HAVE_AS_DWARF2_DEBUG_LINE (both .debug_macro and .debug_macinfo) Message-ID: <20110726203809.GZ2687@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! I've noticed that -g3 (both old .debug_macinfo and new .debug_macro) doesn't work correctly when HAVE_AS_DWARF2_DEBUG_LINE isn't defined, because the .debug_line section is emitted before .debug_mac{ro,info} and thus if any DW_MACINFO_start_file/DW_MACRO_GNU_start_file ops need a file that wasn't seen so far, it will reference a .debug_line filename table entry that isn't present. Fixed by the second and third hunk, by just emitting .debug_line after .debug_macro/.debug_macinfo. With that I've discovered that lookup_filename assumes that the string it is called in is kept around, as it stores just the pointer and not a copy of that string. It seems all other places that call lookup_filename already call it with somehow persistent string and before my .debug_macro patch so did output_macinfo, because it never freed the malloced strings. The reason I've added the freeing was that I sometimes reuse the pointers for something else (the transparent_include group names) and valgrind etc. would be unhappy about unreachable malloced blocks not being freed, albeit so close to the end of the compilation. Instead of copying the string always the following patch just copies it if it stored that pointer (first hunk). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-07-26 Jakub Jelinek * dwarf2out.c (output_macinfo_op): Ensure fd->filename points to GC allocated copy of the string. (dwarf2out_finish): Emit .debug_macinfo or .debug_macro sections before .debug_line, not after it. Jakub --- gcc/dwarf2out.c.jj 2011-07-25 11:28:32.000000000 +0200 +++ gcc/dwarf2out.c 2011-07-26 16:19:56.000000000 +0200 @@ -20552,11 +20552,15 @@ output_macinfo_op (macinfo_entry *ref) size_t len; struct indirect_string_node *node; char label[MAX_ARTIFICIAL_LABEL_BYTES]; + struct dwarf_file_data *fd; switch (ref->code) { case DW_MACINFO_start_file: - file_num = maybe_emit_file (lookup_filename (ref->info)); + fd = lookup_filename (ref->info); + if (fd->filename == ref->info) + fd->filename = ggc_strdup (fd->filename); + file_num = maybe_emit_file (fd); dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); dw2_asm_output_data_uleb128 (ref->lineno, "Included from line number %lu", @@ -22637,6 +22641,16 @@ dwarf2out_finish (const char *filename) output_ranges (); } + /* Have to end the macro section. */ + if (debug_info_level >= DINFO_LEVEL_VERBOSE) + { + switch_to_section (debug_macinfo_section); + ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); + if (!VEC_empty (macinfo_entry, macinfo_table)) + output_macinfo (); + dw2_asm_output_data (1, 0, "End compilation unit"); + } + /* Output the source line correspondence table. We must do this even if there is no line information. Otherwise, on an empty translation unit, we will generate a present, but empty, @@ -22648,16 +22662,6 @@ dwarf2out_finish (const char *filename) if (! DWARF2_ASM_LINE_DEBUG_INFO) output_line_info (); - /* Have to end the macro section. */ - if (debug_info_level >= DINFO_LEVEL_VERBOSE) - { - switch_to_section (debug_macinfo_section); - ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); - if (!VEC_empty (macinfo_entry, macinfo_table)) - output_macinfo (); - dw2_asm_output_data (1, 0, "End compilation unit"); - } - /* If we emitted any DW_FORM_strp form attribute, output the string table too. */ if (debug_str_hash)