Address range lists are contained in a separate section called .debug_ranges.
In short it contains start/end address range pairs.
zero/zero pair means the end of range list. Values of this section
in object files are relocatable.
Perviously LLD would generate wrong output if relocation applied
was against discarded section. LLD would write addend of relocation in that case,
what produced broken ranges, like (0x00000000 - [Addend value]), for example.
According to DWARF specification, it is safe to produce range entries with
same begining and end address: "A range list entry (but not a base address selection or end of list entry) whose beginning and
ending addresses are equal has no effect because the size of the range covered by such an
entry is zero"
GNU LD in such case produces stub entry with start/end = 1.
(https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=e4067dbb2a3368dbf908b39c5435c84d51abc9f3)
I suggest to do the same. I am planning to use it for .gdb_index, D31424 description contains information about issue I faced,
this patch should fix it and that allows to use relocated output for generating .gdb_index section in final without additional parsing
of relocations.
Probably we want to do the same for other debug sections (but place zero instead of 1, that is what ld do, though I did not investigate that deeper),
but now I faced problems only with .debug_ranges, so patch changes behavior for that section only.
Should be called isInDiscardedSection, because it is working with a symbol not a section. "isDiscardedSection" suggests to me that it is asking if a section has been discarded or not, and so would take an InputSection or section index.