When there is no .debug_addr section for some reason,
llvm-dwarfdump would print the bogus empty section name when dumping ranges
in .debug_info:
# CHECK: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000004 # CHECK-NEXT: [0x0000000000000000, 0x0000000000000001) "" # CHECK-NEXT: [0x0000000000000000, 0x0000000000000002) "")
That happens because of the code which uses 0 (zero) as a section index as a default value.
The code should use -1ULL instead because technically 0 is a valid zero section index
in ELF and -1ULL is a special constant used that means "no section available".
This is mostly a fix for the overall correctness/safety of the code, but a test case is provided too.
Could you provide the source (& compilation commands) for this assembly in a comment here so it's easier to eyeball what the input is to this test rather than reading all the assembly?
Also, does this need 3 ranges, or would two suffice (thus creating shorter assembly that might be a little easier to understand)? Anything else you can do to simplify the test case would be great.
Actually, why are there 3 ranges here, when it looks like there are only 2 functions? (ah, I see, invalid input/DWARF as you mentioned in the description - but still, could be simpler to have 2 functions rather than 3)