https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98751
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by David Malcolm <dmalc...@gcc.gnu.org>: https://gcc.gnu.org/g:b83604c75fee324cc4767d039178cba2fbbe017e commit r11-6808-gb83604c75fee324cc4767d039178cba2fbbe017e Author: David Malcolm <dmalc...@redhat.com> Date: Tue Jan 19 19:58:23 2021 -0500 dwarf2out: reset generation count in toplev::finalize [PR98751] 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. 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.