https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98751
Bug ID: 98751 Summary: libgccjit fails in DWARF 5 handling with "`.Ldebug_loc2' is already defined" asm error Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- Most of the jit.exp testsuite is failing, where the tests fail on 3rd in-process iteration, with asm errors of the form: symbol `.Ldebug_loc2' is already defined test-factorial.c.exe iteration 3 of 5: writing reproducer to ./test-factorial.c.exe.reproducer.c /tmp/libgccjit-7lPSFo/fake.s: Assembler messages: /tmp/libgccjit-7lPSFo/fake.s:145: Error: symbol `.Ldebug_loc2' is already defined ./test-factorial.c.exe: error: error invoking gcc driver FAILED: test-factorial.c.exe iteration 3 of 5: verify_code: result is NULL Adding this to set_options in jit.dg/harness.h: gcc_jit_context_set_bool_option ( ctxt, GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES, 1); allows the asm to be inspected after the test runs which has: 1st iteration: 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_loc0: 146 │ .LLST0: 2nd iteration: 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_loc1: 146 │ .LLST0: 3rd iteration: 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: 146 │ .LLST0: Note how line 145's number increments each time, and on the 3rd iteration is a duplicate, leading to failure. The bogus label is being emitted at: 31673 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); init_sections_and_labels: ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, generation); where "generations" is a static local to init_sections_and_labels that increments, and thus eventually hits the duplicate value. It looks like generations is meant to be just 0 or 1, but in libgccjit the compilation code can get repeatedly invoked an arbitrary number of times in process. If generations is meant to be just 0 or 1, should this value be reset to 0 at the end of toplev::main ? Doing so is likely to fix this bug.