.debug_aranges is a DWARF index that maps addresses back to compile units. This index should contain a full list of address ranges for the compile unit. This fix verifies:
- If the DW_TAG_compile_unit has a DW_AT_ranges or a DW_AT_low_pc/DW_AT_high_pc:
- all addresses from a DW_TAG_compile_unit's DW_AT_ranges are contained in the .debug_aranges index
- all address ranges from the .debug_aranges for a compile unit are contained in the DW_AT_ranges of the DW_TAG_compile_unit
- if the DW_TAG_compile_unit doesn't have a DW_AT_ranges or a DW__AT_low_pc/DW_AT_high_pc:
- verify all ranges from any DW_TAG_subprogram DIEs are all contained in the .debug_aranges.
- Run through all .debug_line line table entries from each compile unit and make sure that the .debug_aranges contains ranges for any row addresses and also verify if the CU DW_AT_ranges/low/high pc or subprogram ranges contain the address.
Below are example errors.
When a compile unit has a DW_AT_ranges or DW_AT_low_pc/high_pc that isn't in the .debug_aranges data for that compile unit:
error: .debug_aranges[0x00000000] compile unit range [0x0000000000001000 - 0x0000000000002000) not in .debug_aranges.
When the .debug_aranges has a range that isn't in the compile unit's has a DW_AT_ranges or DW_AT_low_pc/high_pc:
error: .debug_aranges[0x00000000][1] range [0x0000000000010000 - 0x0000000000011000) not in compile unit @ 0x00000000 ranges.
When the .debug_aranges has a range that isn't in any of the compile unit's DW_TAG_subprogram's ranges and the compile unit has no DW_AT_ranges or DW_AT_low_pc/high_pc:
error: .debug_aranges[0x00000000][1] range [0x0000000000010000 - 0x0000000000011000) not in compile unit @ 0x00000000 subprogram ranges.
When we have line table rows that have addresses that don't exist in the .debug_aranges and/or the compile unit's ranges:
error: .debug_aranges[0x00000000] compile unit @ 0x00000000 line table sequence [0-2) has row[1] with address 0x0000000000002010 that is not in .debug_aranges nor in compile unit subprogram ranges. error: .debug_aranges[0x00000000] compile unit @ 0x00000000 line table sequence [0-2) has row[1] with address 0x0000000000002010 that is not in .debug_aranges nor in compile unit ranges. error: .debug_aranges[0x00000000] compile unit @ 0x00000000 line table sequence [0-2) has row[1] with address 0x0000000000002010 that is not in .debug_aranges.
I think we already have a function for this in libDebugInfoDWARF - it's used by the symbolizer to drop tombstoned addresses earlier on/at a lower level probably? (& probably doesn't handle the zero case, since that can be ambiguous)
-2 should only be used in .debug_loc (& theoretically in .debug_range but I don't think binutils ld uses it there, strangely) - so we probably shouldn't include it here?