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.