Fixes 61932.
The core issue I found is that DISubprogram operations usually use getUnit, while its DIE uses getScope. Once these two are associated with different CUs, associated DIEs may use another CU.
I found that even under llc version 15.0.7, DW_AT_low_pc and DW_AT_high_pc are still placed under the wrong CU. The D136039 just reflected this error to other locations. And this "Cannot represent a difference across sections" error only occurs on x86/x86-64.
$ llc -O0 -mtriple=x86_64-unknown-unknown -filetype=obj test.ll $ llvm-dwarfdump --debug-info --verbose test.o 0x0000000b: DW_TAG_compile_unit [1] * ... DW_AT_low_pc [DW_FORM_addr] (0x0000000000000070 ".text") DW_AT_high_pc [DW_FORM_data4] (0x00000000) 0x00000080: DW_TAG_namespace [5] * (0x0000004b) ... 0x00000085: DW_TAG_structure_type [6] * (0x00000080) ... 0x0000008c: DW_TAG_subprogram [9] * (0x00000085) DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000 ".text") DW_AT_high_pc [DW_FORM_data4] (0x00000062) ... 0x000000a5: DW_TAG_lexical_block [10] * (0x0000008c) DW_AT_low_pc [DW_FORM_addr] (0x0000000000000030 ".text") DW_AT_high_pc [DW_FORM_data4] (0x0000001e) ... 0x000000fe: DW_TAG_compile_unit [1] * ... DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000 ".text") <--- This should be in another CU. DW_AT_high_pc [DW_FORM_data4] (0x00000062) <--- This should be in another CU. ...
Could you explain more about when/how/why these are ever different CUs? (when would the scope have a different CU from the subprogram itself)