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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 90ABD3858018 for ; Wed, 20 Jan 2021 01:01:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 90ABD3858018 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-373-_yr01VwxMkWgdUTkXs_CRw-1; Tue, 19 Jan 2021 20:01:40 -0500 X-MC-Unique: _yr01VwxMkWgdUTkXs_CRw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C20D8066E9 for ; Wed, 20 Jan 2021 01:01:39 +0000 (UTC) Received: from t470.redhat.com (ovpn-112-159.phx2.redhat.com [10.3.112.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FB6E27C5B; Wed, 20 Jan 2021 01:01:38 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Subject: [committed] dwarf2out: reset generation count in toplev::finalize [PR98751] Date: Tue, 19 Jan 2021 20:01:34 -0500 Message-Id: <20210120010134.166516-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.2 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_LOW, RCVD_IN_MSPIKE_H3, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2021 01:01:44 -0000 PR debug/98751 reports an issue in which most of libgccjit's tests fails in DWARF 5 handling with `.Ldebug_loc2' is already defined" asm errors. The bogus label is being emitted at the 3rd in-process iteration, at: 31673 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); which on the initial iteration emits: 145 │ .Ldebug_loc0: on the 2nd iteration: 145 │ .Ldebug_loc1: and on the 3rd iteration: 145 │ .Ldebug_loc2: which is a duplicate of a label emitted earlier: 138 │ .section .debug_loclists,"",@progbits 139 │ .long .Ldebug_loc3-.Ldebug_loc2 140 │ .Ldebug_loc2: 141 │ .value 0x5 142 │ .byte 0x8 143 │ .byte 0 144 │ .long 0 145 │ .Ldebug_loc2: The issue seems to be that init_sections_and_labels creates the label ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, generation); where "generation" is a static local to init_sections_and_labels that increments, and thus eventually hits the duplicate value. It appears that this value is intended to be either 0 or 1, but in the libgccjit case the compilation code can be invoked an arbitrary number of times in-process, and hence can eventually lead to a label name collision. This patch adds code to dwarf2out_c_finalize (called by toplev::finalize in libgccjit) to reset the generation counts, fixing the issue. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Takes jit.sum from: FAIL: 70->0 (-70) PASS: 5734->11979 (+6245) Given that Jakub independently came up with a near-identical patch I've gone ahead and pushed this to master as r11-6808-gb83604c75fee324cc4767d039178cba2fbbe017e. gcc/ChangeLog: PR debug/98751 * dwarf2out.c (output_line_info): Rename static variable "generation", moving it out of the function to... (output_line_info_generation): New. (init_sections_and_labels): Likewise, renaming the variable to... (init_sections_and_labels_generation): New. (dwarf2out_c_finalize): Reset the new variables. --- gcc/dwarf2out.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 8b6890a5097..93e5d15e20a 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -12709,22 +12709,27 @@ output_one_line_info_table (dw_line_info_table *table) dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); } +static unsigned int output_line_info_generation; + /* Output the source line number correspondence information. This information goes into the .debug_line section. */ static void output_line_info (bool prologue_only) { - static unsigned int generation; char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES]; char p1[MAX_ARTIFICIAL_LABEL_BYTES], p2[MAX_ARTIFICIAL_LABEL_BYTES]; bool saw_one = false; int opc; - ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, generation); - ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, generation); - ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, generation); - ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, generation++); + ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, + output_line_info_generation); + ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, + output_line_info_generation); + ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, + output_line_info_generation); + ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, + output_line_info_generation++); if (!XCOFF_DEBUGGING_INFO) { @@ -28589,6 +28594,10 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug) macinfo_label_base += macinfo_label_base_adj; } +/* As init_sections_and_labels may get called multiple times, have a + generation count for labels. */ +static unsigned init_sections_and_labels_generation; + /* Initialize the various sections and labels for dwarf output and prefix them with PREFIX if non-NULL. Returns the generation (zero based number of times function was called). */ @@ -28596,10 +28605,6 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug) static unsigned init_sections_and_labels (bool early_lto_debug) { - /* As we may get called multiple times have a generation count for - labels. */ - static unsigned generation = 0; - if (early_lto_debug) { if (!dwarf_split_debug_info) @@ -28634,7 +28639,7 @@ init_sections_and_labels (bool early_lto_debug) SECTION_DEBUG | SECTION_EXCLUDE, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label, DEBUG_SKELETON_ABBREV_SECTION_LABEL, - generation); + init_sections_and_labels_generation); /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in the main .o, but the skeleton_line goes into the split @@ -28644,14 +28649,14 @@ init_sections_and_labels (bool early_lto_debug) SECTION_DEBUG | SECTION_EXCLUDE, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label, DEBUG_SKELETON_LINE_SECTION_LABEL, - generation); + init_sections_and_labels_generation); debug_str_offsets_section = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION, SECTION_DEBUG | SECTION_EXCLUDE, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label, DEBUG_SKELETON_INFO_SECTION_LABEL, - generation); + init_sections_and_labels_generation); debug_str_dwo_section = get_section (DEBUG_LTO_STR_DWO_SECTION, DEBUG_STR_DWO_SECTION_FLAGS, NULL); @@ -28667,7 +28672,8 @@ init_sections_and_labels (bool early_lto_debug) debug_line_section = get_section (DEBUG_LTO_LINE_SECTION, SECTION_DEBUG | SECTION_EXCLUDE, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, - DEBUG_LINE_SECTION_LABEL, generation); + DEBUG_LINE_SECTION_LABEL, + init_sections_and_labels_generation); debug_str_section = get_section (DEBUG_LTO_STR_SECTION, DEBUG_STR_SECTION_FLAGS @@ -28711,7 +28717,7 @@ init_sections_and_labels (bool early_lto_debug) SECTION_DEBUG, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label, DEBUG_SKELETON_ABBREV_SECTION_LABEL, - generation); + init_sections_and_labels_generation); /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in the main .o, but the skeleton_line goes into the @@ -28721,13 +28727,13 @@ init_sections_and_labels (bool early_lto_debug) SECTION_DEBUG | SECTION_EXCLUDE, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label, DEBUG_SKELETON_LINE_SECTION_LABEL, - generation); + init_sections_and_labels_generation); debug_str_offsets_section = get_section (DEBUG_DWO_STR_OFFSETS_SECTION, SECTION_DEBUG | SECTION_EXCLUDE, NULL); ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label, DEBUG_SKELETON_INFO_SECTION_LABEL, - generation); + init_sections_and_labels_generation); debug_loc_section = get_section (dwarf_version >= 5 ? DEBUG_DWO_LOCLISTS_SECTION : DEBUG_DWO_LOC_SECTION, @@ -28767,31 +28773,37 @@ init_sections_and_labels (bool early_lto_debug) } ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, - DEBUG_ABBREV_SECTION_LABEL, generation); + DEBUG_ABBREV_SECTION_LABEL, + init_sections_and_labels_generation); ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, - DEBUG_INFO_SECTION_LABEL, generation); + DEBUG_INFO_SECTION_LABEL, + init_sections_and_labels_generation); info_section_emitted = false; ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, - DEBUG_LINE_SECTION_LABEL, generation); + DEBUG_LINE_SECTION_LABEL, + init_sections_and_labels_generation); /* There are up to 4 unique ranges labels per generation. See also output_rnglists. */ ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, - DEBUG_RANGES_SECTION_LABEL, generation * 4); + DEBUG_RANGES_SECTION_LABEL, + init_sections_and_labels_generation * 4); if (dwarf_version >= 5 && dwarf_split_debug_info) ASM_GENERATE_INTERNAL_LABEL (ranges_base_label, DEBUG_RANGES_SECTION_LABEL, - 1 + generation * 4); + 1 + init_sections_and_labels_generation * 4); ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label, - DEBUG_ADDR_SECTION_LABEL, generation); + DEBUG_ADDR_SECTION_LABEL, + init_sections_and_labels_generation); ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, (dwarf_strict && dwarf_version < 5) ? DEBUG_MACINFO_SECTION_LABEL - : DEBUG_MACRO_SECTION_LABEL, generation); + : DEBUG_MACRO_SECTION_LABEL, + init_sections_and_labels_generation); ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, - generation); + init_sections_and_labels_generation); - ++generation; - return generation - 1; + ++init_sections_and_labels_generation; + return init_sections_and_labels_generation - 1; } /* Set up for Dwarf output at the start of compilation. */ @@ -32379,6 +32391,8 @@ dwarf2out_c_finalize (void) base_types.release (); XDELETEVEC (producer_string); producer_string = NULL; + output_line_info_generation = 0; + init_sections_and_labels_generation = 0; } #include "gt-dwarf2out.h" -- 2.26.2